Help with making a class library
Posted: Wed Nov 27, 2019 7:16 am
I just started getting back into Lua and I decided to try and write my own class library based on ones made by other people (rxi and recursor specifically). So far I have this:
But from looking at the implementations of the people mentioned above, they have something like this in Class:new() as well as an initialization function at the top of the file with nothing in it.
So what's the difference between the two? And why would you need an empty initialization function?
Code: Select all
local Class = {}
Class.__index = Class
function Class:new()
local obj = setmetatable({}, self)
obj['__call'] = self.__call
obj.__index = obj
return obj
end
function Class:__call(...)
local obj = setmetatable({}, self)
obj:load(...)
return obj
end
return Class
Code: Select all
function Class:new()
local obj = {}
obj['__call'] = self.__call
obj.__index = obj
setmetatable(obj, self)
return obj
end