Reply
Thread Tools Display Modes
Unread 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)
__________________
akgis is offline   Reply With Quote
Unread 01-06-13, 08:36 AM   #2
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 103
http://www.wowpedia.org/Hooking_functions is what you're looking for.
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker
humfras is online now   Reply With Quote
Unread 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
__________________
akgis is offline   Reply With Quote
Unread 01-06-13, 09:16 AM   #4
Tim
A Warpwood Thunder Caller
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 95
Code:
local function yourfunction()
-- code
end

local function otherfunction()
yourfunction()
end
__________________
++ Cirax's Repository
++ Author of oUF_DHUD and cTools
Tim is online now   Reply With Quote
Unread 01-06-13, 01:32 PM   #5
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 103
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.
humfras is online now   Reply With Quote
Unread 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: 766
Oh boy spread the taint, break everything! I hope protected/secure API get involved. :P
__________________
Profile: Curse | Wowhead
Vlad is offline   Reply With Quote
Reply

Go BackWoWInterface » 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