lua-users home
lua-l archive

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


I'm creating a game editor which load scripts writen by the user. But, every time the user changes the script, this script needs to be updated. To do that, my program would have to "unload"(delete) that previous script, and load it again (the updated version). I wasn't able to find any resource about it. This is something like what I'm intended to do:


lua_State *lua = luaL_newstate();
luaL_openlibs(lua);
luaL_loadfile(lua, "./start.lua");
if (lua_pcall(lua, 0, 0, 0) != LUA_OK) {
printf("Fail to load script.\n");
}

// Test if the script was loaded correctly. Result is OK.
lua_getglobal(lua, "function");
if (lua_pcall(lua, 0, 0, 0) != LUA_OK) {
printf("Function called.\n");
};

// !!!Delete the chunk here!!!

// Test again, now the result can not be OK, since the chunk was deleted!
lua_getglobal(lua, "function");
if (lua_pcall(lua, 0, 0, 0) != LUA_OK) {
printf("Function called.\n");
};

Thanks...


2014-03-03 9:06 GMT-03:00 Felipe Ferreira da Silva <felipefsdev@gmail.com>:
I'm creating a game editor which load scripts writen by the user. But, every time the user changes the script, this script needs to be updated. To do that, my program would have to "unload"(delete) that previous script, and load it again (the updated version). I wasn't able to find any resource about it. This is something like what I'm intended to do:


lua_State *lua = luaL_newstate();
luaL_openlibs(lua);
luaL_loadfile(lua, "./start.lua");
if (lua_pcall(lua, 0, 0, 0) != LUA_OK) {
printf("Fail to load script.\n");
}

// Test if the script was loaded correctly. Result is OK.
lua_getglobal(BWindowHandler->lua, "function");
if (lua_pcall(BWindowHandler->lua, 0, 0, 0) != LUA_OK) {
printf("Function called.\n");
};

// !!!Delete the chunk here!!!

// Test again, now the result can not be OK, since the chunk was deleted!
lua_getglobal(BWindowHandler->lua, "function");
if (lua_pcall(BWindowHandler->lua, 0, 0, 0) != LUA_OK) {
printf("Function called.\n");
};


Thanks...
--
- Felipe Ferreira da Silva



--
- Felipe Ferreira da Silva