Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function new(prototype)
- return setmetatable({}, {__index = prototype})
- end
- local function uplift(object) -- TODO: performance test vs unuplifted object
- local prototype = getmetatable(object).__index
- local uplifitedObject = {}
- for k, v in pairs(prototype) do
- if type(v) == "function" then
- uplifitedObject[k] = function(...)
- return v(uplifitedObject, ...) -- TODO: catch errors which are blamed on this function's caller and blame our caller
- end
- else
- uplifitedObject[k] = v
- end
- end
- for k, v in pairs(object) do
- if type(v) == "function" then
- uplifitedObject[k] = function(...)
- return v(uplifitedObject, ...) -- TODO: catch errors which are blamed on this function's caller and blame our caller
- end
- else
- uplifitedObject[k] = v
- end
- end
- return uplifitedObject
- end
- local function upliftNew(prototype)
- return uplift(new(prototype))
- end
- local p = {
- f = function() end
- }
- local o = new(p)
- local max = 10000000
- local stopTime, startTime, deltaTime
- startTime = os.clock("utc")
- for i = 1, max do
- o:f()
- end
- stopTime = os.clock("utc")
- deltaTime = stopTime - startTime
- print(deltaTime)
- o = uplift(o)
- startTime = os.clock("utc")
- for i = 1, max do
- o.f()
- end
- stopTime = os.clock("utc")
- deltaTime = stopTime - startTime
- print(deltaTime)
Advertisement
Add Comment
Please, Sign In to add comment