GOOP - OOP Library
Posted: Wed Aug 16, 2023 12:52 am
This is my first time ever sharing some source and making a library, so if anyone has any feedback it would be very appreciated. Just please be nice :')
GOOP
Gage's Object Oriented Programming
An OOP library for lua that enables all of the oop features you'd want - Along with optional type checked arguments for instantiation.
I'm working on a somewhat large game right now that utilizes a decent amount of OOP practices, and I got tired of all of the boilerplate required for me to create a new class.
Also, as the codebase gets larger and larger, I've ran into instances where I may pass incorrect arguments when instantiating classes, or will miss arguments that the class absolutely needs to function.
To solve this I made GOOP.
Quick Start
Goop's only function is to define a class.
For this example lets make a Person class.
In order to inherit from this class, all we have to do is define the extends value.
Type-Checking
Type checking arguments can be done easily, and at an individual level. All you have to do is define the argument as a table containing two strings - One for the string key, and one for the expected type.
GITHUB for more info:
https://github.com/quangogage/GOOP
GOOP
Gage's Object Oriented Programming
An OOP library for lua that enables all of the oop features you'd want - Along with optional type checked arguments for instantiation.
I'm working on a somewhat large game right now that utilizes a decent amount of OOP practices, and I got tired of all of the boilerplate required for me to create a new class.
Also, as the codebase gets larger and larger, I've ran into instances where I may pass incorrect arguments when instantiating classes, or will miss arguments that the class absolutely needs to function.
To solve this I made GOOP.
Quick Start
Goop's only function is to define a class.
For this example lets make a Person class.
Code: Select all
local Person = Goop.Class({
static = {
species = "Homo sapiens"
},
dynamic = {
name = "",
age = 0
},
arguments = { "name", "age" }
})
local bob = Person("Bob") -- Missing arguments!
local bob = Person("Bob", 26) -- All good.
Code: Select all
local Bob = Goop.Class({
extends = Person,
dynamic = {
occupation = "construction",
name = "Bob",
age = 26
}
})
Type checking arguments can be done easily, and at an individual level. All you have to do is define the argument as a table containing two strings - One for the string key, and one for the expected type.
Code: Select all
local Bob = Goop.Class({
extends = Person,
dynamic = {
occupation = "construction",
name = "Bob",
age = 26
},
arguments = {
{"age", "number"}, -- MUST be a number
{"height", "number"}, -- MUST be a number
"weight" -- Will not be type checked.
}
})
local bobOne = Bob(26, "170cm", "60kg") -- Invalid type arg #2 - Expected number. Received string.
local bobTwo = Bob(26, 170, "60kg") -- All good
local bobTwo = Bob(26, 170, 60) -- Also good.
https://github.com/quangogage/GOOP