Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a metamethod (or way) to catch :func() being called on a table?

Asked by
LuaQuest 450 Moderation Voter
8 years ago

So I'm trying to make an event happen when a function is being called from a table, using colons (:). Here's what i have to far:

local this = {}

setmetatable(this, {
    __index = function(t,k)
        print'Metamethod was invoked'
        return getfenv()[k] -- return normal
    end
})

function this:test()
    return 'test'
end

print(this:test())   -- > prints 1, but doesn't invoke the __index metamethod?

Anyway i can catch a function being called from a table like this?

Answer this question