Skip to content

Instantly share code, notes, and snippets.

@eddix
Created March 20, 2013 01:45
Show Gist options
  • Select an option

  • Save eddix/5201691 to your computer and use it in GitHub Desktop.

Select an option

Save eddix/5201691 to your computer and use it in GitHub Desktop.
Lua Object Prototype
-- Lua Object Prototype
Robot = {name = "Eddix", id = 001}
function Robot:new()
self.__index = self
local t = setmetatable({}, self)
return t
end
function Robot:setName(name)
self.name = name
end
robot = Robot:new()
robot2 = Robot:new()
print(robot.name) --> Eddix
robot:setName("test")
robot2:setName("test2")
print(robot.name) --> test
print(robot2.name) --> test2
robot.name = "set-test"
print(robot.name) --> set-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment