lua-users home
lua-l archive

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



If I call luaL_loadstring(), passing it a pointer to a compiled-in static data buffer containing compiled Lua bytecode (rather than Lua source), does the Lua state make and ultimately use a copy of the data in my buffer?

I assume it does, in order to leave me free to dispose of my copy of the bytecode afterwards, but if so, is there I way I can tell the Lua state to use _my_ buffer of bytecode and not to make its own copy?

I am looking for a way to include pre-compiled Lua code inside my Lua binary, but in such a way that this bytecode doesn't end up in memory twice (e.g. once on the heap as part of the Lua state and once in the initialised data section as part of the Lua binary).

The idea is to be able to convert Lua programs into a single executable containing the Lua runtime, all needed C libraries statically linked in, and all needed Lua sources built-in, but precompiled to save time and space. The memory wasted through having two copies of the Lua bytecode, though trivial on PCs, would surely be worth saving on low-RAM embedded devices such as routers (e.g. Linksys WRT54G) and phone-PDAs (e.g. HTC Wizard).