lua-users home
lua-l archive

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


> > do you mean I can load a script called "melee.lua" and then call
> > 
> > lua_getglobal(L, "melee.lua");
> > lua_pcall(L, ...);
> 
> luaL_loadfile(L, "melee.lua");
> lua_pcall(L, ...);

And you can also do this to cache:

luaL_loadfile(L, "melee.lua");
lua_pushvalue(L,-1);
lua_setglobal(L, "melee.lua");

then later

lua_getglobal(L, "melee.lua");
lua_pcall(L, ...);

These can be combined into:

int run_script(const char* name)
{
	int rc;
	lua_getglobal(L,name);
	if (lua_isnil(L,-1))
	{
		rc=luaL_loadfile(L,name);
		if (rc!=0) return rc;
		lua_pushvalue(L,-1);
		lua_setglobal(L,name);
	}
	rc=lua_pcall(L,...);
	return rc;
}