Prototype={} function Prototype:init() end -- dummy constructor -- function for injecting our functionality into an table function Prototype:__set_parent(newparent) setmetatable(self, { -- non-overwritten keys are to be fetched from parent __index=newparent, -- construct a child when called directly __call=function(parent, ...) local newchild = {} self.__set_parent(newchild, parent) newchild:init(...) return newchild end }) end -- serialize our object into a string function Prototype:__tostring() local t=type(self) if t=="table" then local r="" -- load and sort table keys local tkeys={} for k in pairs(self) do table.insert(tkeys, k) end table.sort(tkeys, function(a,b) return tostring(a)