On Wed, Mar 25, 2015 at 12:26 PM, Soni L. <fakedme+lj@xxxxxxxxx> wrote: > > > On 25/03/15 04:20 PM, Ryan Gonzalez wrote: > > You mean you're trying to pass a coroutine to a C function? That's pretty > much impossible. Unless I'm misreading your message. > > BTW, I like your Google+ profile picture. :) > > On Wed, Mar 25, 2015 at 2:14 PM, Soni L. <fakedme+lj@xxxxxxxxx> wrote: >> >> >> >> On 25/03/15 04:04 PM, Coda Highland wrote: >>> >>> On Wed, Mar 25, 2015 at 8:29 AM, Soni L. <fakedme+lj@xxxxxxxxx> wrote: >>>> >>>> Why can't I pass coroutines thru the FFI as lua_State*s? >>> >>> Simply put, the FFI is not intended to interact with Lua at all. >>> Accessing the Lua state while an FFI call is on the stack is undefined >>> behavior and is very likely to blow up in your face. >>> >>> (Accessing a DIFFERENT global Lua state via FFI is perfectly safe, as >>> the LuaJIT interpreter is reentrant.) >>> >>> /s/ Adam >>> >> So... I can't have custom userdata? :/ >> >> Hmm... What about adding custom userdata creation to the FFI? (for both >> heavy and light userdatum) >> > > > > -- > Ryan > [ERROR]: Your autotools build scripts are 200 lines longer than your > program. Something’s wrong. > http://kirbyfan64.github.io/ > > > Well, technically... > > I would use a Lua function (e.g. function f(L) <something> = > C.lua_newuserdata(L, <something>); return 1; end), cast it to a C function, > then use FFI to register the function, then call it to generate a custom > userdata. That sounds very inefficient. You should prefer to either exclusively use the FFI (and therefore cdata) or exclusively use Lua code (and therefore use tables) -- LuaJIT is tuned around these two behaviors, and using the Lua C API is comparatively very slow. (If you REALLY MUST use what you describe, then use the Lua C API instead of trying to make the FFI do it.) /s/ Adam