[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redefining a function
- From: "Carl Dougan" <carl.dougan@...>
- Date: Mon, 21 Jan 2008 03:14:32 -0800
On Jan 20, 2008 8:17 PM, Zhuang Zhao <zhuazhao@yahoo.com> wrote:
> Hi everyone,
>
> I'm currently coding a modification for a game using lua, and I want to
> redefine a function. The function is called OnTick, and is called every
> second. Here's the original ,
>
> function PowerStruggle:OnTick()
> System.LogAlways("++++++++++++OnTick++++++++++");
> if (self:GetState()~="PostGame") then
> self:UpdateReviveQueue();
> end
>
> TeamInstantAction.OnTick(self);
> end
>
> And here's my hook creation function,
>
> function hookFunction()
> local oldTick = PowerStruggle.OnTick;
> LogAlways("oldfunc:"..tostring(PowerStruggle.OnTick));
> PowerStruggle.OnTick = function()
> LogAlways("*****************************OnTick
> Hooked!!!****************************");
> - oldTick(obj);
> return;
nothing is returned
> end
> LogAlways("newfunc"..tostring(PowerStruggle.OnTick));
so tostring(PowerStruggle.OnTick()) would be tostring(nil)
and tostring(PowerStruggle.OnTick) would show the new function addr
- end