Planet, Lua OOP made easy

Planet

Object-orientated scripting for Lua made easier.

Description

Lua doesn’t have built in OOP, which makes developers have to make their own manually. Planet is aimed to make using OOP within Lua a lot easier, and faster. This was made by @Sublivion and I, but we are looking for contributors.

Usage

To create a class you use the Class, this is put into the current environment by default.

Class( ClassTable )
-- Returns the class. To create a new class you run the `new` function,
-- this is part of the table that is returned.
local vehicle = Class({
    topSpeed = 60;
    name = "";
    manufacturer = "";
    value = 100;
    constructor = function(self, name, manufacturer, topSpeed)
        self.name = name
        self.topSpeed = topSpeed
        self.manufacturer = manufacturer
    end
})

If you can’t access Class its most likely not been put into your environment, if thats the case you can just do planet.Class( ... ) instead.

Inheritance can be done by adding the class you are inheriting from. e.g. Class({}, InheritedClass)
An example would be;

local car = Class({
    value = 200;
    horn = function(self)
        print("beep")
    end;
}, vehicle)

Now when you call car.new("DeLorean","DMC",85) that will now have all of the functions and variables from the vehicle class, unless you override them.

If you are interested, you can view the github; here

What do you want?

Since we got the classes down, we haven’t got much of an idea what to add next.
So, what would you like to see added to Planet?

15 Likes

For Roblox use, you will have to use planet.Class() unless you set it yourself as a global variable as getfenv() returns a copy of the env - not one that we can write to.

3 Likes