Is it possible to yield/resume a io cothread as part of an extension?

View: New views
2 Messages — Rating Filter:   Alert me  

Is it possible to yield/resume a io cothread as part of an extension?

by daveb13579 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm interested in replacing Lua in a program I maintain, for various reasons, so I'm in the market for a language that supports embedding in the following way (as lua does..):

- I would like to register a function which suspends the IOState interpretation.   For example, I'd like to embed IO in a program that does a lot of message passing;  I want a "read_message()" function accessible in IO that returns control to the C code (the caller of IoState_doCString_)

- The C implementation of read_message must arrange to call IOState_resume when a message becomes available (with possible cancellation support, i guess)

- There probably needs to be a way to get notification when the IOState terminates.

It seems likely that IO supports this-- but the docs on extensions are too rudimentary to figure it out.  I decided not to wade into the implementation of IO just yet...

A pointer to an example (if it can be done) would be really great!

thanks,
dave



Re: Is it possible to yield/resume a io cothread as part of an extension?

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2009-04-20, at 3:14 PM, daveb13579 wrote:
> I'm interested in replacing Lua in a program I maintain, for various  
> reasons, so I'm in the market for a language that supports embedding  
> in the following way (as lua does..):
>
> - I would like to register a function which suspends the IOState  
> interpretation.   For example, I'd like to embed IO in a program  
> that does a lot of message passing;  I want a "read_message()"  
> function accessible in IO that returns control to the C code (the  
> caller of IoState_doCString_)

This is how normal Io bindings work. Io uses the C stack so it can  
easily integrate with C libs.

> - The C implementation of read_message must arrange to call  
> IOState_resume when a message becomes available (with possible  
> cancellation support, i guess)

It would be easier if you can return to Io instead. But if you need to  
pause and resume Io coroutines, you can do that from C.

> - There probably needs to be a way to get notification when the  
> IOState terminates.

There is an IoState callback for this.