Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/lua
- function methods_getparam(self,...)
- local _ = {...};
- if (_[1] == self) then table.remove(_,1); end
- return unpack(_)
- end
- host = {}
- host.new = function(id, name)
- local self = {}
- self[id] = {}
- self[id].name = name or "default"
- self.GetIdByName = function(...)
- -- local _ = {...}; if (_[1] == self) then table.remove(_,1); end
- -- local searchname = unpack(_)
- local searchname = methods_getparam(self,...)
- for id,t in pairs(self) do
- print(id,t.name)
- end
- return id
- end
- self.SetName = function(...)
- -- local _ = {...}; if (_[1] == self) then table.remove(_,1); end
- -- local id, newname = unpack(_)
- local id, newname = methods_getparam(self,...)
- self[id].name = newname
- end
- self.GetName = function(...)
- -- local _ = {...}; if (_[1] == self) then table.remove(_,1); end
- -- local id = unpack(_)
- local id = methods_getparam(self,...)
- return self[id].name or false
- end
- return self
- end
- hosts = host.new(5)
- print(hosts.GetName(5))
- print(hosts:GetName(5))
- hosts.SetName(5,"asd")
- print(hosts.GetName(5))
- print(hosts:GetName(5))
- hosts:SetName(5,"qwe")
- print(hosts.GetName(5))
- print(hosts:GetName(5))
Advertisement
Add Comment
Please, Sign In to add comment