lua-users home
lua-l archive

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


zeusedit wrote:

> What I did was try to use the "__call" index to trap the macro
> function calls using the following code snipet:
[.. snip snip ..]
> but even though the macro contains several function calls my
> call hook does not get triggered.

The __call metamethod is used if you call a table _itself_, not one of its
members.  Your macro does not call the globals table, it only accesses it.
(It is in fact not easy to call the globals, it can be done by getfenv(0)()
or something similar.)

I'm not sure what you're trying to do exactly, but it seems that your
__index metamethod should check if the global is a function and if so then
call your zeus_hook with it?

So in Lua your metatable could be defined something like this (assuming
zeus_hook is your hook):

{
  __index = function(tab, index)
    local v = rawget(tab, index)
    if type(v) == "function" then
      -- do your thing (whatever that is)...
      zeus_hook(index, v)
    end
    return v
  end,
}

Transcribing this in C is straightforward.

Bye,
Wim