diff --git a/oop/oop.lua b/oop/oop.lua index 0a723bc..f28a6a3 100644 --- a/oop/oop.lua +++ b/oop/oop.lua @@ -307,6 +307,25 @@ function oop.install(env) target.isinstance = oop.isinstance target.issubclass = oop.issubclass target.Visibility = oop.Visibility + + local mt = getmetatable(target) + if not mt then + mt = {} + setmetatable(target, mt) + end + local prev_newindex = mt.__newindex + mt.__newindex = function(t, k, v) + local val = v + if type(k) == "string" and type(v) == "function" and k:match("^[A-Z]") then + val = oop.class(v) + val.__name = k + function_def_cache[v] = val + end + if prev_newindex then + return prev_newindex(t, k, val) + end + rawset(t, k, val) + end end oop.install()