-
Notifications
You must be signed in to change notification settings - Fork 0
SuperClass
Jab edited this page Jul 16, 2025
·
3 revisions
-- Create the super-class.
local SuperClass = class 'SuperClass' {
constructor {
function()
print('Hello from SuperClass!');
end
}
};
-- Create the class.
local SubClass = class 'SubClass' {
-- Extend the super-class using this API.
extends(SuperClass),
constructor {
function()
print('Hello from SubClass!');
end
}
};
-- Print out the class structs, showing that the sub-class extends the super-class.
print(SuperClass);
print(SubClass);
-- Create an instance of the class.
SubClass.new();local SuperClass = cool.newClass {
name = 'SuperClass'
};
SuperClass:addConstructor {
body = function()
print('Hello from SuperClass!');
end
};
local SubClass = cool.newClass {
name = 'SubClass',
extends = SuperClass,
};
SubClass:addConstructor {
body = function()
print('Hello from SubClass!');
end
};
-- Print out the class structs, showing that the sub-class extends the super-class.
print(SuperClass);
print(SubClass);
-- Create an instance of the class.
SubClass.new();class examples.SuperClass
class examples.SubClass extends examples.SuperClass
Hello from SuperClass!
Hello from SubClass!