lua-users home
lua-l archive

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


Roughly....

q = x
function x()
	q()
	z()
	x = q -- auto "unhook" x
end

-----------
With some parameter/return handling....

q = x
function x(...)
	Rets = {q(unpack(arg))}
	z()
	x = q -- auto "unhook" x
	return unpack(Rets)
end

-------
Of course this doesn't catch other references to x, such as....

b = x
.....
q = x
function x()
	q()
	z()
	x = q -- auto "unhook" x
end
...
b() -- Does not call "hook"
x() -- Does call "hook"

-------
If this isn't in the class of what you wanted, then you should probably
spend some quality time with the Debug interface.

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Fabrício de
Alexandria
Sent: Wednesday, October 22, 2003 11:05 AM
To: lua@bazar2.conectiva.com.br
Subject: Intercept function call




Here is my situation. Suppose that I have three functions:

function x()
  print "x"
end

function y()
  print "y"
end

function z()
  print "z"
end

x()
y()


I want to execute x() and y() but before or after the execution of x() I
want to execute z(). Something like during the execution of the program I
want to intercept the x() function call, execute z() and then return to
the normal execution of the program. How can I do that?

I searched something like this in the archive but I didn't find anything.




Fabrício de Alexandria Fernandes
HomePage: http://www.ppgsc.ufrn.br/~fabricio
E-mail: fabricio@ppgsc.ufrn.br
UFRN - CCET - DIMAp
Natal - RN - Brasil