The self
keyword in Lua is not valid in global scope or in a function that isn’t part of a table. It’s simply syntactic sugar for a reference to the current table or object. In Defold scripts, we can use self
in every function, for instance init()
and update()
.
Are these standard engine functions internally stored in a Lua table like the following example?
local tbl =
{
init,
update,
...
}
If this is the case, then it makes sense why using self
works in these functions. For example, something like self.velocity
would be stored like so:
local tbl =
{
init,
update,
...
velocity
}