mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-21 21:20:04 +00:00
added startScript()
This commit is contained in:
parent
c5de584762
commit
d32dd4c319
@ -10,10 +10,21 @@ void LuaManager::init() {
|
|||||||
lua_State *L = luaL_newstate();
|
lua_State *L = luaL_newstate();
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
|
|
||||||
if (luaL_dostring(L, "print(\"Hello from Lua!\")")) {
|
static LuaThread *startScript(const char *script) {
|
||||||
|
lua_State *L = lua_newthread(globalState);
|
||||||
|
LuaThread *T = new LuaThread(L, luaL_ref(L, LUA_REGISTRYINDEX));
|
||||||
|
|
||||||
|
if (luaL_dostring(L, script)) {
|
||||||
std::cout << "Lua error: " << lua_tostring(L, -1) << std::endl;
|
std::cout << "Lua error: " << lua_tostring(L, -1) << std::endl;
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
globalState = L;
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaManager::init() {
|
||||||
|
globalState = luaL_newstate();
|
||||||
|
luaL_openlibs(globalState);
|
||||||
|
|
||||||
|
delete startScript("print(\"Hello from Lua!\")");
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,7 @@ struct LuaThread {
|
|||||||
int ref;
|
int ref;
|
||||||
|
|
||||||
LuaThread(lua_State *L, int ref) : L(L), ref(ref) {}
|
LuaThread(lua_State *L, int ref) : L(L), ref(ref) {}
|
||||||
|
~LuaThread() {
|
||||||
|
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||||
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user