lua-users home
lua-l archive

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


Locals defined outside a function, but used inside the function, are
stored as upvalues for that function.  They won't be GC'd until the
functions that use them are GC'd.

-Kevin

> 
> Hello.
> My application requires some configuration info ( Uh !!! ). 
> Usually, I do that by defining one lua table structured to 
> meet the particular requirement, and one or two ´visible´ ( 
> interface ) functions to exploit the table data. To not 
> polute the name space, I try to declare as many objects as 
> possible as locals to the module. An example
> -- module bla_bla : stores data for ...
> local datatable = {
>         -- config stuff here ...
> }
> local auxiliary_func = function( bla, bla )
>  --
> end
> -- use this function to get ... the params are ... 
> mainAccessFunc = function( foo, bar )
>    -- exploit the datatable contents, may be calling 
> auxiliary_func ... etc end
> -- use this function to validate .. the params are ... 
> anotherAccessFunc = function( bar, foo )
> --- etc
> end
> So one can ´require´ or ´load´ the module, but only the interface
> function(s) are in the global space.
> Of course, it´s not any novelty. And of course, it works.
> What is scaring  me is
> Why the local objects are not collected ? where are they 
> stored ? I am asking to satisfy my curiosity, and to learn a 
> bit more. Marcelo PS searching the internet, I fall once and 
> again to scripting language pages. I allways pay a bit of 
> attention, comparing them on the fly with Lua. Sometimes, 
> some features are appealing. But after a few minutes, I 
> counterbalance the nice
> feature(s) against Lua´s sintax, grammar, power, speed, small 
> footprint, etc and ´come back´ to Lua Thanks to the team. 
> They give us a hard to beat tool !!!
> 
> 
>