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