Re: no custom metamethods for cdata

  • From: Philipp Kutin <philipp.kutin@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 28 Feb 2014 16:46:42 +0100

On Fri, Feb 28, 2014 at 3:49 PM, Mike Pall <mike-1402@xxxxxxxxxx> wrote:
> This is just an indication that the base metatable for cdata types
> is 'off-limits' and must not be modified or inspected in any way.
> It's quite common for Lua libraries to set __metatable to the
> library name when they want to seal their metatables.

Would it be easy to allow setting custom placeholder values of this
kind returned by getmetatable(cdata), i.e. implement __metatable for
custom cdata types? One use case is to encode some meta-information
about that type in a string. For example, it could tell whether the
type is serializable, in which case it must by convention provide a
_serialize() method. Otherwise, one has to keep that information
somewhere separate (such as a table indexed by tonumber(cdata)), which
is fine by itself, but requires a bit of management when many types
are defined from different modules.

--Philipp

Other related posts: