From 45a226cb7b0f312a81e5fb2f3c9e8f88279851bc Mon Sep 17 00:00:00 2001 From: lordlogo2002 Date: Thu, 1 Jan 2026 17:20:14 +0100 Subject: [PATCH] Enhance class definition: add inherit method to support base class inheritance --- oop/oop.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/oop/oop.lua b/oop/oop.lua index 93fc3c2..2d2c823 100644 --- a/oop/oop.lua +++ b/oop/oop.lua @@ -70,6 +70,16 @@ function oop.class(def, base) function cls.setattr(target, key, value) return oop.setattr(target, key, value) end + function cls.inherit(parent) + cls.__base = parent + cls.super = parent + local mt = getmetatable(cls) or {} + mt.__index = parent + mt.__call = mt.__call or function(c, ...) + return oop.new(c, ...) + end + setmetatable(cls, mt) + end setmetatable(cls, { __index = base, @@ -85,6 +95,9 @@ function oop.class(def, base) elseif def ~= nil then error("class definition must be a function or name string") end + if base then + cls.inherit(base) + end return cls end