summaryrefslogtreecommitdiff
path: root/class.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2025-02-17 14:48:34 +0000
committerubq323 <ubq323@ubq323.website>2025-02-17 14:48:34 +0000
commitf1492b52414b6f2ad6cfff45375c08677feab18c (patch)
tree2eac341c813f513b4acef7ff591f6f68936eb334 /class.lua
initial
Diffstat (limited to 'class.lua')
-rw-r--r--class.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/class.lua b/class.lua
new file mode 100644
index 0000000..8fb84b0
--- /dev/null
+++ b/class.lua
@@ -0,0 +1,31 @@
+-- currently a class is a table T with T.__index = T
+-- then to make an instance of this class, we do
+-- setmetatable(instance,T)
+-- this should be fine for anything we wish to do.
+-- it is possible we will eventually split this into two separate
+-- tables perhaps? i don't see why we would ever do that though
+
+local function class()
+ local T = {}
+ T.__index = T
+ return T
+end
+
+local function extend(Base)
+ local T = {}
+ T.__index = T
+ for k,v in pairs(Base) do
+ if k:sub(1,2) == "__" and k~="__index" then
+ T[k]=v
+ end
+ end
+ setmetatable(T,{__index=Base})
+ return T
+end
+
+return setmetatable({
+ class=class,
+ extend=extend
+},{__call=class})
+
+