Object-orientated scripting for Lua made easier.
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.
Firstly, require the module. In Roblox, you can use the ID 3044032874:
planet = require(3044032874)
You can use the plugin to automatically add this to the start of your scripts,
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.
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.