Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
admicos

aclass -- A lightweight and easy class system for Lua.

Recommended Posts

aclass is a lightweight and easy class system. Yes this is the third time i wrote that line. Anyways:

 

How to make a class:

Since i'm not that great at documentation, you might want to check the example afterwards.

Also, this relies on some Lua formatting tricks to stay readable-ish, so expect some weird syntax

To make a class, you use the class function as demonstrated here:

class "classname" { "optional parent class";
    variable = "hello";

    constructor = function(self, hello) --# Constructor is optional
        self:parentConstructor() --# Runs the parent classes constructor.

        self.hello = hello or "world" --# Example variable change.
    end;
  
    func = function(self)
        print(self.variable)
    end;
}

 

To use the class in your program, you use the new function as demonstrated here:

local myClass = new "classname"("constructor", "ar", "gs", 1234) --# While the constructor args are optional, the paranthesis are required
print(myClass.variable)
myClass:func()

 

Examples:

One example can be found here

 

Downloads:

Available though oppm as aclass

Direct Link: https://raw.githubusercontent.com/OpenPrograms/admicos-Programs/master/aclass/aclass.lua

Link to post
Share on other sites

aclass has updated.

 

To load aclass, you now do 

local new, class = require("aclass")()

and it will return the new and class functions as locals instead of globals.

 

And printing the class variable will return "class: ClassName" instead of "table: 0xhexcode"

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.