[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua Performance questions
- From: Peter Cawley <lua@...>
- Date: Sat, 19 Sep 2009 17:24:50 +0100
On Sat, Sep 19, 2009 at 5:16 PM, zweifel <firstname.lastname@example.org> 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.