lua-users home
lua-l archive

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



Am 30.11.2012 um 18:00 schrieb Kevin Martin:


On 30 Nov 2012, at 11:15, Philipp Kraus wrote:

What do I return here? A reference to the lua function run !?


Exactly, each script defines a run function and returns it.

The C++ side then assigns that returned function a name - the name of the script seems sensible.


I do this in another example like:

lua_getglobal(m_lua, "main");

This will be exactly the same except instead of main, you will use the name used in lua_setglobal when you loaded the script.

This way you will have one Lua state, with all the scripts loaded, and the ability to call whichever you need to.

However, you need to make sure your scripts don't write any global variables, otherwise the different scripts may interfere with each other.

Thanks for your answer. No I would like to use only local variables, because the globales should be stored out of the Lua script.

Thanks also to all for your great answers

Phil