lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Fri, Jan 31, 2014 at 3:11 PM, Milind Gupta <milind.gupta@gmail.com> wrote:
I get an error saying I cannot yield across C-call boundary. That is probably because the script I execute is loaded with loadstring. I even tried making modules of the scripts and requiring them. That also did not work.

So we can't use coroutines across modules? Any way we can do this?

This is not a problem, but it must be accounted for. In short, because C only has a single stack, it cannot continue from a call into lua, which could then yield into another state and then call into C, because it will lose C context.

Therefore, you need to create a continuation function, which splits your C function in two and requires you to package your state variables in a context object. I'm probably botching this, but essentially, I think that's correct.

http://www.lua.org/manual/5.2/manual.html#4.7 is your friend, but this sort of thing all but requires Programming In Lua, 3rd Edition. 5.1 cannot do this without the help of... copas? I can't remember. LuaJIT can do this, but I believe that it is different than in Lua 5.2 (don't know for sure).

--Andrew