lua-users home
lua-l archive

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


foo = namespace
    function setX(value) x = value end
    bar = namespace
        setX(999)
        x=x-111
        -- this would display 888
        print(x)
    end
    -- this would display 999, not 888
    print(x)
end

Note that this is not the same as a do/end block since a do block can still assign values to a global variable and the namespace/end block would return a table that contains the result of executing the block, so after running this block I could then do this:

--- output is 888
print(foo.bar.x)

-- output is 999
print(foo.x)

-- output is nil
print(x)