This is a library with functions I tend to need in all my addons. Instead of copy/pasting the lua file everywhere I'm making a mixin library out of it that can be added as an external through the power of the packager.
It contains following handy functions:
*TABLES*
- Copy a table (recursively if specified) into a new duplicate.
- Copy the contents of one table into another existing one (also recursively if specified).
- Clear a table of all it's member (again, recursively if specified).
- Recycle tables (with the popular :new() and :del() functions). The other functions use these as well. Reduces garbage generated by addons.
- Gives back a count of ALL members a table has. table.getn and #table only return the number of integer-keyed members.
- Get the key of a member with a certain value.
- Get the key of a member that has a member with a certain value (this is kinda like searching a table in a real, non-Lua, DB)
- Replace all found values in a table where the (old) value matches another (old) value. Has a count-parameter to limit to number of replaces.
- Combination of the replace and the "get key of member with certain member as value" function. Fills member1 with val1 of member2 = val2. Also has a count-parameter to limit to number of replaces.
*GENERAL*
- Pass a potentially-nil variable and, if nil, replace it with a non-nil default.
*UNITS*
- Determine if a unit is in your raid/group, is a pet, is a raidpet.
- Determine if a unitid is a raidid, partyid, petid, ...
- Determine the owner-unitid from a raidpetid.