4 ms·
The main advantage in bringing OO concepts in the Lua world is actually to improve code modularization. There is no such thing as classes or modules in Lua - al
by jpatte 17y ago
The main advantage in bringing OO concepts in the Lua world is actually to improve code modularization. There is no such thing as classes or modules in Lua - although there is a notion of 'environments' defining the scope of global variables.
Grouping related functions/variables into classes is just a way to improve the maintability of large Lua chunks, it's not about transforming the language into something less simple.
I wrote my own library to implement OO concepts in pure Lua 5.1 several years ago; the code and details are still available at http://lua-users.org/wiki/YetAnotherClassImplementation http://lua-users.org/wiki/YetAnotherClassImplementation.
- joeyo 17y agoI suspect you know this, but as of Lua 5.1 there are modules: http://www.lua.org/manual/5.1/manual.html#5.3 http://www.lua.org/manual/5.1/manual.html#5.3
- silentbicycle 17y ago> There is no such thing as classes or modules in Lua Actually, there is a module system (http://www.lua.org/manual/5.1/manual.html#5.3 http://www.lua.org/manual/5.1/manual.html#5.3), built on the environment manipulation methods. It was added to the language with 5.1, and seems a bit less mature than the rest of the language, but it's there. It's similar to Erlang's module system, except instead of listing exports at the top, anything not flagged as local is exported.
- jpatte 17y agoWhoops, my bad. You're right, I forgot about the module system of Lua 5.1. Guess I will have to refresh some clusters of memory around here :o)
- silentbicycle 17y agoWell, the nice part with Lua is there's only so much you can forget. :)