re: Write a function that shows off something unique or interesting about the language you're using VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

Another contender, though for a different language:

mt.__index = function(self,key)
    local k = self.data[key]
    local metatable = getmetatable(k)
    if key == 'data' or not k then
        return rawget(self, key)
    elseif type(k) ~= 'function' and (metatable == nil or metatable.__call == nil) then
        return k
    else
        return function(...)
            if self == ... then
                return k(self.data, select(2,...))
            else
                return k(...)
            end
        end
    end
end

One does not underestimate the power of metatables in Lua, particularly when having to differentiate between userdata fields and Lua table fields.

code of conduct - report abuse