lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




Roberto Ierusalimschy <roberto@inf.puc-rio.br>于2020年8月19日 周三21:29写道:

I think the main issue here is what to compare the metatable with,
that is, how to specify which metatable we want. Your suggestion of

I have an idea .

Maybe we can use an indirect structure to reference the metatable rather than a direct pointer to it.

For example,

struct metatable_cache {
  struct Table *metatable;
  GCObject *metamethod[TM_N];
  struct metatable_cache *next;
};

When we set metatable, we can copy all the metamethods into this cache structure.

If we need access the metamethods , we can check the flags of metatable first to decide whether need to sync the metamethods again.

All the table used as a metatable should have a unique cache object. We can implement this like short string table.

And then , we can put the name or anything else to this structure to check it.


--
http://blog.codingnow.com