lua-users home
lua-l archive

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



Leigh, assuming I have the jist of your question, functions are first
class values in Lua, which means they are objects like anything else.

function foo()
 ...
end

foo = nil -- will release the function body (then GC)

Functions are just closures of Lua code assigned to a variable name.

I put some more details in the tutorial:
http://lua-users.org/wiki/FunctionsTutorial

You could however just define your functions in a table and delete this,
e.g.

config = {
   width = 640,
   height = 480
}

function config.foo()
  ...
end

-- if none of table contents are referenced anywhere else, this will
delete
-- the functions as well.
config = nil  

Regards,
Nick



> -----Original Message-----
> From: Leigh McRae [mailto:leigh.mcrae@rockstartoronto.com]
> Sent: Wednesday, October 22, 2003 7:06 AM
> To: Lua list
> Subject: One time scripts
> 
> Using lua 4.01 and only one Lua_State, does anyone know how to make a
lua
> script be a one time only?  I have some config files I use lua for and
I
> can
> set any of the tables in the script to nil but I still have the code
> around.
> I need a way to kick everything out that the file had.
> 
> Leigh McRae
> Lead Programmer
> Rockstar Games Toronto
> www.rockstargames.com