Skip to content

Instantly share code, notes, and snippets.

@porglezomp porglezomp/meta.lua
Created Feb 2, 2019

What would you like to do?
Metatable on Metatables
local x = { value = 42 }
local index = {
__index = function(t, k)
if k == "__add" then
return function(l, r)
return { value = l.value + r.value }
setmetatable(index, index)
setmetatable(x, index)
index.__add -- works fine, gives the right add
x.__add -- works fine, gives the right add
x + x -- fails, presumably the metatable lookup uses primitive indexing and skips meta indexing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.