diff options
author | Norbert Preining <norbert@preining.info> | 2023-10-27 03:03:08 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-10-27 03:03:08 +0000 |
commit | e7c703c953f148411c70d5ca86dc1c1023d73806 (patch) | |
tree | 103695d0d26aa0b1d5b1942fd433cf5f9a90d47f /macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua | |
parent | 721b0492f150d59f61b504ab803c7ef1a9a67a0b (diff) |
CTAN sync 202310270303
Diffstat (limited to 'macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua')
-rw-r--r-- | macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua new file mode 100644 index 0000000000..8a2564bd36 --- /dev/null +++ b/macros/latex/contrib/tkz/tkz-elements/latex/tkz_elements_class.lua @@ -0,0 +1,48 @@ +-- tkz_elements_class.lua +-- from class.lua (Simple Lua Classes from Lua-users wiki) +-- Compatible with Lua 5.1 (not 5.0). +-- http://lua-users.org/wiki/SimpleLuaClasses DavidManura + +function class(base, init) + local c = {} -- a new class instance + if not init and type(base) == 'function' then + init = base + base = nil + elseif type(base) == 'table' then + -- our new class is a shallow copy of the base class! + for i,v in pairs(base) do + c[i] = v + end + c._base = base + end + -- the class will be the metatable for all its objects, + -- and they will look up their methods in it. + c.__index = c + + -- expose a constructor which can be called by <classname>(<args>) + local mt = {} + mt.__call = function(class_tbl, ...) + local obj = {} + setmetatable(obj,c) + if init then + init(obj,...) + else + -- make sure that any stuff from the base class is initialized! + if base and base.init then + base.init(obj, ...) + end + end + return obj + end + c.init = init + c.is_a = function(self, klass) + local m = getmetatable(self) + while m do + if m == klass then return true end + m = m._base + end + return false + end + setmetatable(c, mt) + return c +end
\ No newline at end of file |