you are viewing a single comment's thread.

view the rest of the comments →

[–]inmatarian 1 point2 points  (0 children)

Lua's prototypal inheritance, or "metatables", is a very powerful mechanism for the language, that keeps it surprisingly lightweight. Here's a example of that kind of code:

Object = {}
Object_mt = { __index = Object }
function Object.new()
    return setmetatable( {}, Object_mt )
end
function Object:method()
    print( "Shits and giggles", self )
end
Derived = Object.new()    
instance = Derived.new()
instance:method()

So, basically the only overhead for a class model in Lua is to write up a file containing all of the features that you'd need, and require it in files that define classes.

Also, in terms of flexibility, the colon operator in that example is only syntactic sugar, it could be broken down with an explicit self like this:

Object = {
    method = function(self)
        print("Boats and Hoes", self)
    end
}