4 ms·
That's literally true in Lua, where there is no such thing as object-orientation but there's lots of ways to do object-oriented programming. The simplest, most
by jschwartzi 6y ago
That's literally true in Lua, where there is no such thing as object-orientation but there's lots of ways to do object-oriented programming. The simplest, most performant way I've found is to return a hash map containing lexical closures and data from a "constructor" function. Any enclosed functions which refer to values declared in the constructor use those values in a closure, so it's easy to do instance or static member fields by putting the field declaration inside or outside of the constructor function.
You can do it with metatable manipulation as well(changing the functions which map to specific table operators which lets you change how unmapped keys are handled) but I found the lexical closures to make a lot more sense.