lua-users home
lua-l archive

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


On 3/17/2014 10:04 PM, meino.cramer@gmx.de wrote:
> 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.

One way:

do
    local persist = 0
    function myfunction()
       persist = persist + 1
       return persist
    end
end

"persist" exists only for that function, and will keep its value between calls.

Tim