[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Eval a Lua expression
- From: Eugen-Andrei Gavriloaie <shiretu@...>
- Date: Thu, 3 Apr 2008 03:44:31 +0300
On Apr 3, 2008, at 2:58 AM, Peter Harris wrote:
So, if I do a lua_pcall(...) right here, it will execute
On Wed, Apr 2, 2008 at 6:58 PM, Eugen-Andrei Gavriloaie wrote:
Here is what I know so far:
3. Adding custom made functionality represented by c++ functions
6. Now, the cloudy part for me is what is happening when I do a
You understand what lua_pushcfuntion does, right? luaL_loadstring()
does the same thing, except with the contents of a lua function.
When luaL_loadstring() is done, you can lua_pcall() the function and
it will run and then be garbage collected.
Or you can
lua_setglobal() to give it a name so it won't be garbage collected. Or
you can do anything else that you can normally do with a function
sitting on the lua stack.
What would happen if we do a second luaL_loadfile(...) on the
same lua_State? replacing the previous one or appending? Same
with the luaL_loadstring(...)
luaL_loadfile() does the same thing as luaL_loadstring(), except with
a file instead of a string literal.
 the function itself will be garbage collected, not any variables
that the function may set when you lua_pcall() it. In your
luaL_loadfile() case, that means the tables will still be there when
the file (function) is garbage collected. In other cases, it might
include creating other functions, and other things.
Thank you for the insights! Very helpful!