lua-users home
lua-l archive

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


Ok, so I wil create a Hash with the name and the function loaded in the stack by the luaL_load. I know there is some functions called readChunck or something similar that only reads the chunck and return it, so that I do not need to read from the stack.

Thanks!

2009/9/19 Peter Cawley <lua@corsix.org>
On Sat, Sep 19, 2009 at 5:16 PM, zweifel <zweifel@gmail.com> wrote:
> hmm, these are a good solution when I just want to run the script once.
>
> But in my case I do want to run the Lua script every frame. I just wanted to
> know if I should bother with a hash_table and luaL_loadbuffer or just use
> luaL_dofile because Lua already does some caching of files that was already
> read before.

If you want to run a script multiple times, then load it once
(lua_load, luaL_loadbuffer, luaL_loadfile, etc.), save the result (a
Lua function) somewhere, and then run it (lua_call / lua_pcall)
multiple times. You should assume that reading a file is expensive,
and that the parsing done by lua_load (and other load functions which
all call lua_load) is also expensive - avoid calling any load function
per frame, and avoid even more load functions which read files.



--
God$ g++ -o earth earth.cpp -O3 -lanimals -lplants -lvirus

http://fog.neopages.org/