lua-users home
lua-l archive

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

On Mon, Mar 17, 2014 at 9:04 PM,  <> wrote:
> Hi Sean,
> sorry for being inexact...
> I am in search of a way to create a variable in the scope of a
> function which is persistent i.e. does not loose it content over
> several calls of its funtion.
> best regards,
> mcc

You want to use an upvalue.

Something like this:

local fn
    local staticvar = 3
    fn = function() staticvar = staticvar + 1 end

/s/ Adam