[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Recycling the lua_load() output
- From: Michal Kottman <k0mpjut0r@...>
- Date: Wed, 12 Jan 2011 22:13:45 +0100
On Wed, 2011-01-12 at 12:57 -0800, Murray S. Kucherawy wrote:
> I’d like to read a Lua script, compile it with lua_load(), and then
> have it around to re-use in any number of future states. So I create
> a first lua_State handle, compile the script with lua_load(), then use
> lua_dump() to get the compiled version back out and discard this
> lua_State.
> Then for each future lua_State I create, use lua_load() but this time
> pass the output of lua_dump() as its input, and then use lua_pcall()
> to execute it.
> Does that sound right?
I'm not sure why you would like to do that instead of keeping the Lua
state alive, storing the function in a global/registry/etc. and calling
it repeatedly, or just load the function again in each of the new states
(compiling is really fast in Lua), but yes, apart from that it sounds
right :)
Just make sure that the function that you are dumping doesn't have any
upvalues (they won't be saved by lua_dump() nor restored by lua_load()).
If you really need them, take a look at Pluto [1], a heavy-duty
serialization library.
[1] http://lua-users.org/wiki/PlutoLibrary