This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- depends on tostringall() https://gist.github.com/nefftd/11382819 | |
| -- see: line 15 | |
| do | |
| local err_fmt = "bad argument #%d to '%s' (%s expected, got %s)" | |
| local function checktypelist(t,a1,...) | |
| if a1 then | |
| return t == a1 or checktypelist(t,...) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do | |
| local function _tsa(n,a,...) | |
| if n > 0 then | |
| return tostring(a),_tsa(n-1,...) | |
| end | |
| end | |
| function tostringall(...) | |
| local n = select('#',...) | |
| if n > 0 then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function math.isinf(x) | |
| argcheck(x,1,'number') | |
| return ( | |
| x == math.huge and 1 or | |
| x == -math.huge and -1 | |
| ) | |
| end | |
| function math.isnan(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do | |
| local function shallowcopy(tbl) | |
| local new = {} | |
| for k,v in next,tbl do | |
| new[k] = v | |
| end | |
| return new | |
| end | |
| local function deepcopy(tbl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do | |
| checktypelist = (t,a1,...) -> | |
| t == a1 or checktypelist t,... if a1 ~= nil | |
| export argcheck = (val,argn,...) -> | |
| return if checktypelist type(val),... | |
| types = '/'\join tostringall ... | |
| fname = debug.getinfo(2,'n').name or 'unknown' | |
| error "bad argument ##{tonumber(argn) or '?'} to '#{fname}' (#{types} expected, got #{type val})",3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do | |
| tsa = (n,a,...) -> | |
| tostring(a),tsa(n-1,...) if n > 0 | |
| export tostringall = (...) -> | |
| n = select '#',... | |
| tsa n,... if n > 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- lol | |
| setmetatable(myarray,{ | |
| __len = function(self) | |
| local n = 0 | |
| while self[n+1] do | |
| n = n + 1 | |
| end | |
| return n | |
| end | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Here's a super-simple implementation of something like bucket events. The | |
| -- idea is, you want to call some code, but the event you're listening to is | |
| -- very spammy (many times per second!), and it's just not necessary to update | |
| -- that often. So when the event first occurs, we start a timer to call the | |
| -- actual routines. Subsequent occurances of the event simply fail silently | |
| -- until the timer is finished. So your code only runs at most every N seconds | |
| -- see: BUCKET_DELAY. Caveat: even if the event only runs once, there will be a | |
| -- delay of N seconds before your routines get called. Tweak BUCKET_DELAY to | |
| -- your needs. Caveat 2: you can't collect arguments (can be implemented, but | |
| -- not trivially). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local name,realm = UnitName(unit) | |
| if not realm or realm == '' then realm = GetRealmName() end | |
| name = name..'-'..realm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local _,dtype | |
| for i = 1,40 do | |
| _,_,_,_,dtype = UnitAura(unit,i,'HARMFUL') | |
| if dtype == 'Magic' then | |
| return '[M]' -- DOES have magic debuff; change as you see fit | |
| end | |
| end | |
| return '' -- DOESN'T have magic debuff; change as you see fit |
OlderNewer