lua-users home
lua-l archive

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


On Mon, Aug 09, 2004 at 07:54:50AM +0000, Jacek Pop?awski wrote:
> My game calls in each frame some Lua functions. One of reason to use Lua is
> that I can change behaviour of game without recompiling, and even without
> restarting it. When I change something in file with function I just load that
> file again, with following code:
> 
> int result=luaL_loadfile(L,filename);
> (...)
> int result=lua_pcall(L,0,0,0);
> 
> Do I lose something this way? When I run script once it puts function
> definition somewhere, what happen if I run script second time? Is any memory
> lost? Is function defined once or twice?

Functions are just variables which contain function values, i.e. these
two lines are equivalent:

function foo() ... end
foo = function() ... end

Functions are garbage-collected just like other objects. So, if there's
only one reference to the function (i.e. you never assigned the
function value to another variable, as in bar = foo), and you
overwrite it, the old version will be freed eventually.

-- Jamie Webb