WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Simple lua code help (https://www.wowinterface.com/forums/showthread.php?t=45580)

akgis 01-06-13 06:54 AM

Simple lua code help
 
Want to do the following

lets say we have a function called X in the middle of the code, I want to add code to that function X but adding it at the end of the Lua file or even better in another Lua file

In the practice what I want is to add all that code again to that function but instead of looking all over the addon and messing the code I just want to add my custom code:eek: and then just call a line or 2 in that function, that way I know my custom code its at the end of the file(or another file would be even better)

humfras 01-06-13 08:36 AM

http://www.wowpedia.org/Hooking_functions is what you're looking for.

akgis 01-06-13 08:44 AM

thanks, but thats is abit out of my league...

Would you be so kind to exemplify in this how I can do it?

Code:

  function Whatever()
    (...)
|-->
|  (...)
| end
|
|- - <my code>

what I have to do so <my code> gets in the middle of the function Whatever like the "arrows" indicate

Tim 01-06-13 09:16 AM

Code:

local function yourfunction()
-- code
end

local function otherfunction()
yourfunction()
end


humfras 01-06-13 01:32 PM

Quote:

Originally Posted by akgis (Post 271417)
thanks, but thats is abit out of my league...

Would you be so kind to exemplify in this how I can do it?

Code:

  function Whatever()
    (...)
|-->
|  (...)
| end
|
|- - <my code>

what I have to do so <my code> gets in the middle of the function Whatever like the "arrows" indicate

You can only pre- or post-hook a function. You can not split the function!


What you can do is:
Lua Code:
  1. function mainfunc(...)
  2.   --this is the function you want to alter/enhance
  3. end
Lua Code:
  1. --store the old (default) function before
  2. local old_mainfunc = mainfunc
  3. function mainfunc(...)
  4.    old_mainfunc(...) --if you want to run the old code first (this is better done via 'hooksecurefunc')
  5.    -- your code
  6.    old_mainfunc(...) --if you want to run the old code after your code is executed
  7. end


Please post the function you want to alter and the code you want to use. Then we can get more into detail.

Vlad 01-06-13 04:02 PM

Oh boy spread the taint, break everything! I hope protected/secure API get involved. :P


All times are GMT -6. The time now is 07:55 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI