lua-users home
lua-l archive

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


Hi,

you can precompile lua text source by calling lua_dump and safely put it into shared memory. it will produce binary chunk which then can be converted to lua function by calling lua_load on it. you cannot reuse result of lua_load since global table _G is pushed as upvalue to the resulting function, i.e. is not reusable.

On Wed, 18 Oct 2023 at 21:36, Keith Cancel <admin@keith.pro> wrote:
Hello,

I was looking at the source code trying to see if there was a way
maybe to achieve something similar to lua_load(), but at compile time.
Basically, I want to bunch a shared code to only occupy the memory
once instead of creating copies for each new lua VM instance. I
basically just want that code in ROM that can be executed by each new
instance without having to copy it over first.

While I am not super familiar with the Lua internals. Looking at the
source code I did not see any obvious or easy methods to achieve that
if I were to patch the code. Is that assessment correct or am I
missing something?  It looks like the chunk is pushed on the stack.
Does the stack need to be contiguous or can it be linked from
different sections of memory like a linked list?

Thanks,
Keith