lua-users home
lua-l archive

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


Alex Sandro Queiroz e Silva wrote:
Hallo,

vol-lua@kokezaru.net wrote:

Hi, everyone.

I've been reading this list for quite a while, silently
lurking, and have been using LUA on and off for a little
while.  I've embedded it in a few projects, however, I've
come across something which seems easy enough, however,
I've been unable to implement it.  Using luaL_loadbuffer,
I'm loading a chunk of LUA code from a string.  I need to
be able to save ('cache') this pre-compiled code so that it
may be re-executed.  How do I save the index to that code
once it's been pushed onto the stack by luaL_loadbuffer,
and how do I call this code from that index?

Thanks!


    Store it in a table with lua_settable().

Well, thank you.  After realizing to myself that I
am an idiot for asking this question, because every
value is on the stack before being assigned somewhere,
I pondered your response.  Which would execute faster?
Storing the function in a table, or simply creating
a global function?  These functions are going to be
called millions of times, and thus, optimization is
key here.

Thanks!