object-oriented programming in lua

taledentaleden Join Date: 2003-04-06 Member: 15252Members, Constellation
I know Lua doesn't provide objects/classes/inheritance by default, but its (awesome, brilliant, genius) metatable mechanism makes it possible to implement an OOP framework.

Does the engine test's Lua code already use such a scheme and/or provide a way to do it? If not, would other developers here be interested in a simple OOP library? I originally wrote it for use in a WoW addon, but it's generic Lua 5.1 code, so it should be easy enough to drop into NS2.

It just provides the basics: a simple way to define classes and extend them, separate inheritance for classes and their objects, subclassof/instanceof tests, and super-calls for method overrides.

Comments

  • DixieWolfDixieWolf Join Date: 2010-02-10 Member: 70508Members
    the engine test already features classes; for example
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->class 'Player' (Actor)<!--c2--></div><!--ec2-->
    where Actor is the class extended by Player.
    and class functions...
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Player:OnInit()
    -- some code
    end<!--c2--></div><!--ec2-->

    buuut, i would be interested in looking at your library for my own tinkering..
  • Dalin SeivewrightDalin Seivewright 0x0000221E Join Date: 2007-10-20 Member: 62685Members, Constellation
    As mentioned in another thread, Lua already has features that can be used for OOP but syntax for creating classes in the Engine Test are definitely not already in Lua. It is likely syntactic sugar for more complicated uses of the metatables. As such, I don't think it really needs an OOP library at all because all of the needed functionality such as subclassing, super calls, method overrides, already exists - if not in the Engine Test, then surely when the engine is actually complete and NS2 is released.
Sign In or Register to comment.