|
I wrote your algorithm into a usable Lua function to try it out. I had to add a check for nonexistent metatables, but it does work.
From the manual:"The code shown here in Lua is only illustrative; the real behavior is hard coded in the interpreter and it is much more efficient than this simulation. All functions used in these descriptions (rawget, tonumber, etc.) are described in §5.1. In particular, to retrieve the metamethod of a given object, we use the expression
metatable(obj)[event] This should be read as rawget(getmetatable(obj) or {}, event)"