intfiction.org

The Interactive Fiction Community Forum
It is currently Mon Nov 12, 2018 4:11 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Tue Feb 20, 2018 8:23 pm 
Offline

Joined: Tue Jul 28, 2015 1:05 pm
Posts: 1325
There have been many posts over the years about how to communicate between inform and JavaScript. There has been talk of adding gestalt codes for certain interpreters, etc.

What would it take to do the following?
-Add a new string output channel for glk (similar to the main channel, the left hand status line, and so on)
-Instruct standard interpreters to ignore it (like a status line that just never gets seen)
-add an empty function to the JavaScript interpreter quixe that hackers can fill in
-add a new command in inform that prints to this channel.

From posts over several years, this would seem to be in demand, and would cut out the necessity of redoing this over and over again for each new interpreter. It would basically be a channel that the author could use to pass things through glk that aren’t intended to be seen, and would have many applications.

I don’t mind working on this, but I can’t change Inform itself, which is the biggest problem. I have done all of the above for the existing channel used for the right hand status line, but it shows up weird in non-hacked games.

_________________
-My IFDB name is Mathbrush, and I'm @MathBrush on Twitter.

The rough draft of my book on IF history and criticism is available at https://www.dropbox.com/s/xd2isl3tk7dxt97/learning-text.pdf?dl=0


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Feb 20, 2018 9:44 pm 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2545
It wouldn't take too much. The difficult part will be modifying Quixe, not Inform.

First, you'd create a new type of stream. Write the functions for creating a new stream object, and then hook into glk_stream_close to handle closing the stream and sending the text to the JS engine for running. (Ideally going through the GlkOte interface so that it will work remotely, across frames etc.)

To get data back, you'd create a new type of event. Write functions for requesting the event, passing in a block of memory like for line input. Then your glk_select handler just has to handle the new event when it comes in.

The Inform side is easy because the compiler is future ready, you can call Glulxe and Glk functions which it doesn't know exist.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Feb 20, 2018 11:11 pm 
Offline

Joined: Tue Jul 28, 2015 1:05 pm
Posts: 1325
Dannii,

This sounds very interesting! Could you give me a sample of Inform code that might call a Glk function it doesn't know yet? I feel comfortable poking around with javascript, even if it takes a few weeks or months.

_________________
-My IFDB name is Mathbrush, and I'm @MathBrush on Twitter.

The rough draft of my book on IF history and criticism is available at https://www.dropbox.com/s/xd2isl3tk7dxt97/learning-text.pdf?dl=0


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Feb 21, 2018 12:08 am 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2545
Here's an I6 file showing how to call new Glk functions: https://github.com/curiousdannii/if/blo ... e-text.inf

I haven't written an I7 extension for that, but it's just a matter of adding phrases which call I6 code.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Mar 22, 2018 10:34 pm 
Offline

Joined: Tue Jul 28, 2015 1:05 pm
Posts: 1325
I feel like I almost have the loop, but I'm not there. I need to intercept a new stream somewhere, but where?

There seems like a gap in my understanding with regard to glkote_update in glkote.js. That seems to be the master function that all sorts of streams come through.

It takes an input. However, it gets renamed to glk.update, which only ever gets called once, in quixe.js, with empty arguments. So I think I have a fundamental misunderstanding. When do args get passed to glkote_update by an outside function?

Edit: Oh, I see, glkote_update gets renamed to glkote.update which gets called by glk.update. So I passed that hurdle. On to the next!

_________________
-My IFDB name is Mathbrush, and I'm @MathBrush on Twitter.

The rough draft of my book on IF history and criticism is available at https://www.dropbox.com/s/xd2isl3tk7dxt97/learning-text.pdf?dl=0


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Mar 22, 2018 11:22 pm 
Offline

Joined: Tue Jul 28, 2015 1:05 pm
Posts: 1325
Okay, here's my next question: In Dannii's example, and in this example: http://www.firthworks.com/roger/informfaq/ii.html

glk functions are called by something of the form glk($0023, 0, 0, 0, 3, 0);. Apparently the 23 means this corresponds to glk_window_open.

But glk_window_open is only defined by glkapi.js, and never called by Quixe at all. So what part of the code takes glk($0023, 0, 0, 3, 0) and translates it into javascript for Quixe?

_________________
-My IFDB name is Mathbrush, and I'm @MathBrush on Twitter.

The rough draft of my book on IF history and criticism is available at https://www.dropbox.com/s/xd2isl3tk7dxt97/learning-text.pdf?dl=0


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Mar 22, 2018 11:32 pm 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2545
Right, that's the dispatch layer. https://github.com/erkyrath/quixe/blob/ ... i_dispa.js

You'd need to add a new line to the big array in the middle of the function.

What are the definitions of the new functions you're defining? I can help you with figuring out what lines to add.

Also do you have a reserved block of codes/selectors/etc yet? You could use some of mine if you want. Could even put up a public specification on my website if you don't have anything better for that.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Thu Mar 22, 2018 11:47 pm 
Offline

Joined: Tue Jul 28, 2015 1:05 pm
Posts: 1325
@Dannii What I want is to output a string into a new channel.

Then I want to find the place in the javascript side where it checks what channel is being inputted to. For instance, I know glkote_update is where the argument is checked to see what type it is (an update, a retry, an error, a pass) in a big switch statement.

So my goal is to find where the channel is checked in the javascript, and intercept that, with something like this (this is all made up):

Code:

function someupdate(arg){

...

if (arg.streamtype == whatever_stream) {
    perform_javascript_input(arg.input);
  }

...

}


function perform_javascript_input(input_text){
return;
}


I would leave the perform_javascript_input() function blank until I needed to do something with it.

So to answer your question, I just want to write a string to a new channel that isn't being used for something else. It's possibly I've completely misunderstood everything, but this is where I'm at right now.

_________________
-My IFDB name is Mathbrush, and I'm @MathBrush on Twitter.

The rough draft of my book on IF history and criticism is available at https://www.dropbox.com/s/xd2isl3tk7dxt97/learning-text.pdf?dl=0


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Mar 23, 2018 12:23 am 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2545
Okay, my advice would be to handle all of the stream stuff before GlkOte gets involved, as GlkOte as it is now doesn't know about streams, not really. So you'd open up a js stream, send text to it, and close it with glk_stream_close, which can then just append the code to the GlkOte update data.

Things to do:

  • Add a new stream type around line 2760 of glkapi.js
  • Make a new glk_stream_open_javascript function based on one of the existing stream functions, glk_stream_open_memory is probably simplest
  • Edit the gli_put_* functions to handle accepting text on the js stream
  • Edit glk_stream_close to handle closing the javascript stream

Doing this is quite involved sorry, but I think it's the best way to do JS handling. Up to you if you think it's worth it. Vorple does it a somewhat simpler way, through hacking the file system.

I want to do this myself one day, but I'm not there yet.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Mar 23, 2018 12:42 am 
Offline

Joined: Tue Jul 28, 2015 1:05 pm
Posts: 1325
This really does sound involved! But it's something I've been dreaming of, so I'll keep trying. Thanks!

_________________
-My IFDB name is Mathbrush, and I'm @MathBrush on Twitter.

The rough draft of my book on IF history and criticism is available at https://www.dropbox.com/s/xd2isl3tk7dxt97/learning-text.pdf?dl=0


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group