Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
m (Minor code and grammar corrections.)
 
 
Line 1: Line 1:
  +
{{Stub/NPC}}
{{merge|Function arguments}}
 
  +
{{npcbox
{{tocright}}
 
  +
| name = Gurubashi Berserker
With patch 2.0 and the upgrade to lua 5.1, the '...' arg is much more powerful and less memory intensive than it was previously. Here's some handy tips on how to use this new functionality
 
  +
| image = Gurubashi Berseker Cata.jpg
  +
| level = 85
  +
| type = Elite
  +
| money = {{cost||82|87}}
  +
| faction = Combat
  +
| aggro = {{aggro|-1|-1}}
  +
| race =Dire troll
  +
| creature = Humanoid
  +
| location = [[Zul'Gurub]]
  +
}}
   
== Hooking ==
+
==Abilities==
  +
*Hypothermia-Reduces the target's movement speed by 50%. Cannot be frozen again.
Previously, the ... arg would create a table 'args' if called. This allocated a table into memory, and thus became a source of garbage churn. A very common pitfall of this came from hooking:
 
  +
*Knock Away-Inflicts normal damage to an enemy and knocks it back.
local f = somefunc
 
  +
*Pursuit-This creature blindly chases the target and is immune to taunts.
somefunc = function(...)
 
  +
**Pursuit-The zombie fixates on a random target.
-- do some crap
 
  +
*[[Thunderclap]]-Damages all nearby enemies for 31500 to 38500 Nature damage and slows attack speed by 20%.
return f(unpack(args))
 
end
 
Now if this function is called often, or there are many hooks like this, there will be a significant hit on performance. With lua 5.1 we can do this hook with no memory wasted
 
local f = somefunc
 
somefunc = function(...)
 
-- do some crap
 
return f(...)
 
end
 
   
=== Post-hooks ===
+
==Patch changes==
  +
*{{Patch 4.1.0|note=Re-Added. Level increased from 60 to 85; abilities changed.}}
The new functionality also allows for a nice clean post hook to be made. In this example we need the first arg passed to the function, and we wish to maintain a full proper hook. That means every arg is passed to the hooked function, and every return from that is returned back from our function.
 
  +
*{{Patch 4.0.3a|note=Removed.}}
local f = somefunc
 
  +
*{{Patch 1.7.0|note=Added.}}
local ph = function(a1, ...)
 
-- do something with a1
 
return ...
 
end
 
somefunc = function(a1, ...)
 
return ph(a1, f(a1, ...))
 
end
 
   
== Iterations ==
+
==External links==
  +
<!-- Read http://www.wowpedia.org/Wowpedia:External_links before posting your links here.
As with hooking, iteration over arbitrary number of args would create a table and thus waste memory. With lua 5.1 we can do this cleanly in a for loop
 
  +
Links that do not conform to the rules will be DELETED.
function f(...)
 
  +
Repeat violations may result in a BAN.
for i=1,select("#", ...) do
 
  +
Have a nice day. :) -->
local x = select(i, ...)
 
  +
{{elinks-NPC|11352}}
-- do something with x
 
end
 
end
 
   
  +
[[Category:Zul'Gurub (original) mobs]]
== Recursion ==
 
Clean recursive functions are simple with ...
 
function r(x, ...)
 
local y = x*x
 
if select("#", ...) > 0 then
 
return y, r(...)
 
else
 
return y
 
end
 
end
 
 
[[Category:HOWTOs|U]]
 

Revision as of 01:29, 17 January 2012

MobGurubashi Berserker
No image available
Race Dire troll (Humanoid)
Level 85 Elite
Reaction Alliance Horde
Location Zul'Gurub

Abilities

  • Hypothermia-Reduces the target's movement speed by 50%. Cannot be frozen again.
  • Knock Away-Inflicts normal damage to an enemy and knocks it back.
  • Pursuit-This creature blindly chases the target and is immune to taunts.
    • Pursuit-The zombie fixates on a random target.
  • Thunderclap-Damages all nearby enemies for 31500 to 38500 Nature damage and slows attack speed by 20%.

Patch changes

External links