Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print ("Closure Lua!")
- function CreateUser()
- local _name = "Qugurun"
- return {
- setName = function(n)
- _name = n
- end,
- getName = function()
- return _name
- end
- }
- end
- local user1 = CreateUser()
- local user2 = CreateUser()
- user1.setName("Laimadoo")
- print(user1.getName()) --> Laimadoo
- print(user2.getName()) --> Qugurun
- print(user2._name) --> nil
- for k,v in pairs(user1) do
- print(k,v) --> getName function: ...
- --> setName function: ...
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement