3 ms·
It would be better if this article had been using real Lua code, and not starting with a "class" function. Lua does !NOT! have classes. Lua is a prototyping lan
by kephra 13y ago
It would be better if this article had been using real Lua code, and not starting with a "class" function. Lua does !NOT! have classes. Lua is a prototyping language, and anybody can handwave an own class system, or go without classes at all. The idea of mixins makes only sense in languages that have classes. Lua does not. References have a metatable, and this metatable contains functions. The functions are independent of the reference, and there are no classes. So basically all functions in a metatable are mixins by default.
- bartbes 13y agoYet the very first sentence of the article mentions the class library he's using for the rest of the it.
- octopus 13y agoBest Lua "class" example I've seen is in the PIL 3rd edition it is about 10 lines of code and lets you use inheritance and some other nice OOP concepts.
- kzrdude 13y agoThis is a boring view! All the same concepts of classes, interfaces, objects still exist when using Lua, you just don't have a canonical implementation. This is also interesting in itself -- the best class system may spread and be improved.
- otikik 13y agoHi, I am the author of the library mentioned in the article (not the article author, that's someone else). You seem to have missed the link to the OOP library used, so here it is: https://github.com/kikito/middleclass https://github.com/kikito/middleclass Also, notice that in other comments on this thread I mention that I don't think OOP in Lua it's a one-size-fits-all thing. I think middleclass has its uses, but most of the time plain Lua with some metatables does the trick just fine.