[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: default LUA_TTABLE metatable, like for strings
- From: Sean Conner <sean@...>
- Date: Sun, 17 Mar 2019 18:13:31 -0400
It was thus said that the Great Dirk Laurie once stated:
>
> Here is my full and complete class system. It is written to be the
> body of a file but I often simply insert the code sans comments and
> final 'return' at the top of a program.
>
> local new = function(class,...)
> local object = setmetatable({},class)
> if object.init then object:init(...) end
> return object
> end
>
> local class = function(name,index,newindex)
> local mt = setmetatable({__name=name,__newindex=newindex},
> {__call=new,__index=index})
> mt.__index = mt
> return mt
> end
>
> local is = function(class,object)
> return getmetatable(object) == class
> end
>
> if _ENV.is==nil then _ENV.is = is end
> return class
Why not make this code its own module? It seems useful enough.
-spc