CLASSIC
What is it ?Classic is an api that offers users the possibility to use some common features of many oop languages.
That basically means you can use classes that inherit from each other and implement interfaces.
I know there are quite a few pretty similar oop libraries out there, but I haven´t found many that try to implement classes in a way that both looks pretty and is convenient to use.
Therefore I gave it try and finally after a few attempts I came up with this api.
How to use it:
The library allows the usage of two things: Classes and Interfaces.
Let´s look at how you create a simple class:
dofile("classic") class "Shape" { colour; }
That´s it ! We´ve created a simple class called "Shape" that has a property called "colour".
Anyways we can´t yet create an instance of this class as we still lack a method that serves as a constructor:
class "Shape" { colour; } function Shape:init(colour) self.colour=colour print("I am a simple shape !") end
Now that we´ve added a init function we can create an instance of our class by writing:
local testshape=Shape(colours.red)
Of course we can´t do much with such an abstract "Shape" Object so let´s create a class that is a bit more usefull !
class "Square" extends "Shape" { x; y; width; height; } function Square:init(x,y,width,height,colour) self.x=x self.y=y self.width=width self.height=height self.colour=colour end
As you can see the "Square" class inherits all properties from Shape by extending the class.
The last feature , this library has to offer are interfaces.
Interfaces are a basically classes without an init function:
interface "ITalk" { talk=function(self,text) print(self.name.." says :"..text) end; } class "Human" implements "ITalk" { ... }
Every "Person" can now use the function talk to say something !
Of course you can also inherit from a class and implement an interface at the same time :
class "Male" extends "Human" implements "ITalk" { ... }
Some further details:
ToDo:
Download:
Pastebin:
pastebin get MfsdVz6U classic
Let me know if there are any bugs or errors with this library !
Edited by Kouksi44, 12 September 2016 - 07:49 PM.