Thread Tools Display Modes
01-06-13, 06:54 AM   #1
akgis
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 29
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 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)
__________________
  Reply With Quote
01-06-13, 08:36 AM   #2
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
http://www.wowpedia.org/Hooking_functions is what you're looking for.
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker
  Reply With Quote
01-06-13, 08:44 AM   #3
akgis
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 29
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
__________________
  Reply With Quote
01-06-13, 09:16 AM   #4
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Code:
local function yourfunction()
-- code
end

local function otherfunction()
yourfunction()
end
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
01-06-13, 01:32 PM   #5
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
Originally Posted by akgis View Post
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.
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker

Last edited by humfras : 01-06-13 at 01:51 PM.
  Reply With Quote
01-06-13, 04:02 PM   #6
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Oh boy spread the taint, break everything! I hope protected/secure API get involved. :P
__________________
Profile: Curse | Wowhead
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simple lua code help

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off