I am using the Lua "C" API function luaL_loadbuffer()
to run Lua code.
I have a small handful of Lua chunks that I am calling many, many times. But every time I call luaL_loadbuffer()
the chunk gets recompiled. This seems hugely inefficient. Most of the code referenced by the chunk is precompiled, but why do I need to recompile the chunk itself every time? How can I avoid this recompilation?
Can I pass a precompiled chunk to luaL_loadbuffer()
?
Can I make a full copy of the returned Lua stack and re-use it?
Is there some other clever approach?