lua-users home
lua-l archive

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


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