[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Performance questions
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 23 Sep 2009 10:26:30 -0300
> > 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;
}