lua-users home
lua-l archive

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


In C:

lua_load / luaL_loadfile loads your script into Lua without executing it; the script is left as a function on the top of the stack. 

http://www.lua.org/manual/5.1/manual.html#luaL_loadfile

You can store this function in a handy location (such as in LUA_REGISTRYINDEX, LUA_ENVIRONINDEX etc), and lua_pcall it multiple times (assuming that everything happens in one lua_State).  If you're going to do it straightaway, just lua_pushvalue() the function before each lua_pcall but the last.

In Lua:

local buttonscript, err = loadfile("mybuttonscript.out")
if not buttonscript then print(err) else
for i = 1, 5 do
buttonscript()
end
end

HTH



On May 4, 2008, at 11:48 AM, Mario wrote:
Hi all,

i am using lua for my GUI on an embedded hardware. I have some common
scripts for buttons, sliders etc. Typically a GUI screen is based on
these scripts and some of these scripts are multiple loaded (if i have 5
buttons, the button script is loaded 5 times).

Now i have a problem with the loading/parsing speed of these scripts. In
the first step, i have precompiled the lua scripts, which give me a 2-3x
faster loading. In the next step, i am thinking about avoiding the
multiple loading/parsing of the scripts (e.g. the 5 buttons).

Is it possible to clone a lua state and will that be faster than loading?

Thank you in advance.
Regards Mario

Be seeing you

grrr waaa
www.grahamwakefield.net