Skip to main content
gamedev.net
🔒 Locked

LUA: Separate scripts/scopes

Started by Vexator 0 replies 1.2k views
Original Post
Vexator
Vexator
I want to be able to work with several lua scripts. If several scripts have functions or variables with the same names, I have to make sure they do not override each other. As far as I understand, I need several lua states and/or threads for this, but I could not find all the info I need, neither in the lua nor in the luabind docs. What I'd like to have when I'm finished is sth like this:
Script *pScript = AddScript( "script.lua" );
ExecuteScript( pScript, "Update" );
Each script should have its own set of variables and functions, and all scripts should have access to a global set of variables. How can I achieve this? Any recommended reads on this apart from the official docs? Thank you!
Wunderwerk Engine is an OpenGL-based, shader-driven, cross-platform game engine. It is targeted at aspiring game designers who have been kept from realizing their ideas due to lacking programming skills.

blog.wunderwerk-engine.com
pp000
pp000
You can make a class like this:
class Script {    lua_State* L;public:    Script() {         L = lua_open();    }    void AddScript(char* file) {        luaL_dofile(L, file);    }    void Execute(char* functionname) {        lua_getglobal(L, functionname);        lua_call(L, 0, 0);        lua_pop(L, 0);    }}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.