🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lua, LuaBind, coroutines

Started by
6 comments, last by Endurion 21 years, 1 month ago
Hi, i''m just implementing a game with heavy scripting via Lua (5.0). I''m using LuaBind to bind functions and classes to lua. Since i also want to use "movie" scripting (scripts that need to be suspended and resumed) i worked myself into coroutines. Everything works with some workarounds (having a wait command, a selectitem command, and so on), but i''m having a (small) problem: Luabind allows me to call functions and encapsulates translating c++ objects to lua objects (tables), but luabind refuses to work with coroutines in the called code (because the return values differ). In other words the function i am calling is starting a coroutine which will be suspended via yield. Is there some way to get both at the same time?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Advertisement
Both what?
Sorry, i probably didn''t make myself clear.

I meant both methods combined; luabind:call_function lets me call functions with translated object parameters, but won''t run when the lua script suspends the coroutine (different return types).
So i either use lua_dostring or similar with coroutines or luabind with scripts that don''t have coroutines.

I''d like to have both together, calling coroutines with luabind.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

It is hard to understand exactly what you are trying to do.

You have C++ objects, and you have Lua coroutines. What sort of interaction is taking place here?

If you have a Lua script that calls a method on a C++ object which then calls a Lua script that tries to yield, that won''t work because you can''t yield inside of a C function (Lua has no way of saving the actual state of the program).
Let''s take an example:

I used luabind to make my c++ classes known to lua.
If i now want to use one of my classes as parameter to a lua function i need to call lua via luabind (so luabind will internally translate my c++ class to the lua equivalent).
Luabind function calls force me to have a fixed return parameter, which collides with the standard lua do_string, which will return an extra parameter, if the script inside yielded. Therefor, with my implemenation i can either pass my objects directly as parameters OR have a lua coroutine yielding, but i cannot have both at the same time.

It''s not that bad after all, it works pretty good, i just have to work around with a FindClass function.

But if someone has found a way, i''d be happy to hear about it.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Write your own bindings for your class maybe.
We are working on supporting threads/coroutines with call_function/call_member. Please redirect luabind questions to our mailing list:
http://lists.sourceforge.net/lists/listinfo/luabind-user

--
Daniel Wallin
Well, now that''s a good reply!
Thanks for the info, i''ll be waiting for the luabind group to finish their task

Good work so far! I''m pretty impressed by the ease luabind works although VC almost chokes on the heavy templating

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement