Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Replace 'Class' (with capital C) with actual name of 'Class'
- local class_mt = {}
- local object_mt = {}
- local object_idx = {}
- local Class = setmetatable({}, class_mt)
- -- tells lua where to look for functions called by objects/instances of 'Class'
- object_mt.__index = object_idx
- -- metamethods (aka operator overloading)
- function class_mt.__call(class, ...)
- return class.new(...)
- end
- function object_mt.__eq(left, right)
- return false
- end
- -- example class function
- function object_idx:getId()
- return self._id
- end
- -- constructor
- function Class.new()
- local self = setmetatable({}, object_mt)
- return self
- end
- -- returns a handle to the class definition so other files can use this class
- return Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement