diff --git a/oop/oop.lua b/oop/oop.lua index f28a6a3..ef024f6 100644 --- a/oop/oop.lua +++ b/oop/oop.lua @@ -34,6 +34,38 @@ end local function_def_cache = setmetatable({}, { __mode = "k" }) oop._call_stack = {} +local default_dunders = { + "__add", + "__sub", + "__mul", + "__div", + "__idiv", + "__mod", + "__pow", + "__unm", + "__band", + "__bor", + "__bxor", + "__bnot", + "__shl", + "__shr", + "__concat", + "__len", + "__eq", + "__lt", + "__le", + "__pairs", + "__ipairs", + "__call", + "__tostring" +} + +local function deny_op(name) + return function() + error("operation not allowed: " .. name, 2) + end +end + local function normalize_visibility(visibility) if visibility == nil then return oop.Visibility.PUBLIC @@ -263,6 +295,12 @@ function oop.class(def, base) end }) + for _, name in ipairs(default_dunders) do + if rawget(cls, name) == nil then + cls[name] = deny_op(name) + end + end + if type(def) == "string" then cls.__name = def elseif type(def) == "function" then