4 ms·
Comment on the code: As a Lua aficionado I hate to see stuff like this: Ball = {} Ball.__index = Ball function Ball.new (x, y) local table = {}
by copx 10y ago
Comment on the code:
As a Lua aficionado I hate to see stuff like this:
Ball = {}
Ball.__index = Ball
function Ball.new (x, y)
local table = {}
setmetatable(table, Ball)
table.x = x
table.y = y
return table
end
Explicit setmetatable() call and manual __index setting? You can automate this and hide all the metatable magic = less code to write, less potential for bugs.
E.g. in my own Lua object system the above would be:
Ball = Class()
function Ball:Properties(x, y)
return { x = x, y = y }
end