The syntax is quite different from "lclass", which I found out about just recently after writing this library. Whether this is as good as "lclass" or not, I'm not sure. I'd consider myself a novice programmer, but I prefer the workflow of my library.
It's on gitHub, along with some quick documentation I threw together in the Readme. I'll also paste an example Class here.
Code: Select all
local Kid = {}
Kid.name = "Kid" -- Name of the class (should be same as table name above)
Kid.parent = "Dad" -- Name of parent's class
function Kid.new(args)
local self = {} -- Instance variables are stored in this table
self.name = args.name or "Riley"
self.age = args.age or 3 -- Get age from creation arguments, or default to 3
self.favoriteColor = "green"
self.gender = args.gender or "male"
-- Public Functions
-----------------------------------
function self:create() -- The 'create' function is automatically called on instance creation.
_zokClass.addList(self, "alive") -- Adds instance to the list "alive"
print("Hello World!")
end
function self:speak()
print("My name is "..self.name)
end
return (self)
end
return (Kid)
Code: Select all
zClass = require "zokClass" -- Import library
zClass.import(classes) -- Import a table of class files
-- Creates instance of class 'Kid'
-- Any variables given in the argument table will override the class defaults
lesley = zClass.instCreate( zclass.classList.Kid,
{ name="Lesley",
gender="female",
favoriteColor="orange" })
-- Access instance variables
print(lesley.name)
print(lesley.gender)
print(lesley.age) -- Note that since we didn't specify an age, it will print 3, because of the default in the class file
-- Overwrite instance variables
lesley.name = "Linda"
lesley.gender = "male"