You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ok, I really could use some help using coroutines/threads in LuaD.
To begin with, if I create a coroutine like this:
lua.doString(`foo = coroutine.create(...)`);
How do I get the lua_State* or LuaState associated with it?
There is no LuaState conversion. You can't LuaObject.to!LuaState, and you can't LuaObject.to!lua_State* either. So you have to push the object and use the C function lua_tothread instead.
Turns out for whatever reason LuaObject doesn't expose its push method. It's marked as private. So you must push pushValue instead.
It took me some time but I was able to do it using this code:
Now I got the thread, but there is no way to lua_resume from LuaD, so another C function has to be called.
int status = lua_resume(foo_c_thread, 0);
The lack of support so far was kind of frustrating but everything went well so far and I could use part of the library. But then I had to lua_yield from a function.
For lua_yield to work properly, its return value must be returned by the C function calling it. So something like this:
extern(C) int foo_calls_me(lua_State* L) {
return lua_yield(L, 0);
}
Sure there must be a way I could do this with a D function, right?
Well, no. There is not.
LuaD will handle the returning values of D functions and C functions that don't comply with that signature, and that means it will either return 0 or some other calculated value that has nothing to do with lua_yield.
Well, at least I could reuse LuaD amazing templating code to turn that alien lua_State* into typed arguments, right?
Nope. Same reason as LuaObject.push, the extremely convenient functionWrapper is marked as private. Even argsError is marked as private. Everything is private here. This sucks D:
TL;DR: coroutine support please.
The text was updated successfully, but these errors were encountered:
Indeed LuaD contains an intermediate layer of template code that operates on the Lua stack, but these primitives are intended to be internal. The goal of the library is to abstract away the Lua stack with higher level expressions, without sacrificing performance.
Coroutines are indeed a blind spot in the LuaD interface.
Until they are properly supported I recommend using the C API (exposed in the luad.c package) for functions that operate on coroutines, as mixing the C API and the LuaD API within the same function can be hazardous. Function pointers with the signature extern(C) int function(lua_State*) are given special handling in the LuaD API so it's possible to mix the two APIs at function level.
Ok, I really could use some help using coroutines/threads in LuaD.
To begin with, if I create a coroutine like this:
How do I get the
lua_State*
orLuaState
associated with it?There is no LuaState conversion. You can't
LuaObject.to!LuaState
, and you can'tLuaObject.to!lua_State*
either. So you have to push the object and use the C functionlua_tothread
instead.Turns out for whatever reason
LuaObject
doesn't expose itspush
method. It's marked as private. So you must pushpushValue
instead.It took me some time but I was able to do it using this code:
Now I got the thread, but there is no way to
lua_resume
from LuaD, so another C function has to be called.The lack of support so far was kind of frustrating but everything went well so far and I could use part of the library. But then I had to
lua_yield
from a function.For
lua_yield
to work properly, its return value must be returned by the C function calling it. So something like this:Sure there must be a way I could do this with a D function, right?
Well, no. There is not.
LuaD will handle the returning values of D functions and C functions that don't comply with that signature, and that means it will either
return 0
or some other calculated value that has nothing to do withlua_yield
.Well, at least I could reuse LuaD amazing templating code to turn that alien
lua_State*
into typed arguments, right?Nope. Same reason as
LuaObject.push
, the extremely convenientfunctionWrapper
is marked asprivate
. EvenargsError
is marked as private. Everything is private here. This sucks D:TL;DR: coroutine support please.
The text was updated successfully, but these errors were encountered: