How can I link to callback functions in Lua such that the callbacks will be updated when the scripts are reloaded?
Posted
by
Raptormeat
on Game Development
See other posts from Game Development
or by Raptormeat
Published on 2012-05-04T18:23:21Z
Indexed on
2012/06/03
22:48 UTC
Read the original article
Hit count: 240
I'm implementing Lua scripting in my game using LuaBind, and one of the things I'm not clear on is the logistics of reloading the scripts live ingame.
Currently, using the LuaBind C++ class luabind::object
, I save references to Lua callbacks directly in the classes that use them. Then I can use luabind::call_function
using that object in order to call the Lua code from the C++ code.
I haven't tested this yet, but my assumption is that if I reload the scripts, then all the functions will be redefined, BUT the references to the OLD functions will still exist in the form of the luabind::object
held by the C++ code. I would like to be able to swap out the old for the new without manually having to manage this for every script hook in the game.
How best to change this so the process works?
My first thought is to not save a reference to the function directly, but maybe save the function name instead, and grab the function by name every time we want to call it. I'm looking for better ideas!
© Game Development or respective owner