diff Core.lua @ 122:6724bc8eface

Reduced usage of global functions by defining them locally.
author Zerotorescue
date Sat, 15 Jan 2011 18:52:01 +0100
parents 00cf4fc1697f
children 1729a41324d5
line wrap: on
line diff
--- a/Core.lua	Sat Jan 15 17:09:13 2011 +0100
+++ b/Core.lua	Sat Jan 15 18:52:01 2011 +0100
@@ -2,6 +2,10 @@
 local addon = select(2, ...);
 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0");
 
+local _G = _G;
+local sformat, ssplit, slower, strim, smatch = _G.string.format, _G.string.split, _G.string.lower, _G.string.trim, _G.string.match;
+local mfloor, print, pairs, tonumber = _G.math.floor, _G.print, _G.pairs, _G.tonumber;
+
 --@debug@
 local addonRevision = 1;
 --@end-debug@
@@ -9,9 +13,6 @@
 local addonRevision = @project-revision@;
 --@end-non-debug@]===]
 
-local _G = _G;
-local sformat, print, pairs, tonumber = _G.string.format, _G.print, _G.pairs, _G.tonumber;
-
 --  All modules must be able to retrieve our supported addons database, thus keep it a part of the addon object rather than local
 addon.supportedAddons = {};
 addon.supportedAddons.auctionPricing = {};
@@ -309,8 +310,8 @@
 local slashError = "Wrong argument, the following arguments are available:";
 
 function addon:CommandHandler(message)
-	local cmd, arg = string.split(" ", (message or ""), 2);
-	cmd = string.lower(cmd);
+	local cmd, arg = ssplit(" ", (message or ""), 2);
+	cmd = slower(cmd);
 	
 	if slashArgs[cmd] then
 		-- Pass a reference to the addon (to be used as "self") and the provided arg
@@ -369,19 +370,19 @@
 function addon:ReadableMoney(copper, clean)
 	local text = "";
 	
-	local gold = floor( copper / COPPER_PER_GOLD );
+	local gold = mfloor( copper / COPPER_PER_GOLD );
 	if gold > 0 then
 		text = sformat(goldText, text, gold);
 	end
 	
 	if not clean or (not gold or gold < 10) then
-		local silver = floor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
+		local silver = mfloor( ( copper % COPPER_PER_GOLD ) / COPPER_PER_SILVER );
 		if silver > 0 then
 			text = sformat(silverText, text, silver);
 		end
 		
 		if not clean or (not gold or gold < 1) then
-			local copper = floor( copper % COPPER_PER_SILVER );
+			local copper = mfloor( copper % COPPER_PER_SILVER );
 			if copper > 0 or text == "" then
 				text = sformat(copperText, text, copper);
 			end
@@ -389,16 +390,16 @@
 	end
 	
 	
-	return string.trim(text);
+	return strim(text);
 end
 
 function addon:ReadableMoneyToCopper(value)
 	-- If a player enters a value it will be filled without color codes
 	-- If it is retrieved from the database, it will be colored coded
 	-- Thus we look for both
-	local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
-	local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
-	local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
+	local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
+	local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
+	local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
 		
 	return ( (gold or 0) * COPPER_PER_GOLD ) + ( (silver or 0) * COPPER_PER_SILVER ) + (copper or 0);
 end
@@ -407,9 +408,9 @@
 	-- If a player enters a value it will be filled without color codes
 	-- If it is retrieved from the database, it will be colored coded
 	-- Thus we look for both
-	local gold = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+g|r") or string.match(value, "(%d+)g"));
-	local silver = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+s|r") or string.match(value, "(%d+)s"));
-	local copper = tonumber(string.match(value, "(%d+)|c[a-fA-F0-9]+c|r") or string.match(value, "(%d+)c"));
+	local gold = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+g|r") or smatch(value, "(%d+)g"));
+	local silver = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+s|r") or smatch(value, "(%d+)s"));
+	local copper = tonumber(smatch(value, "(%d+)|c[a-fA-F0-9]+c|r") or smatch(value, "(%d+)c"));
 	
 	if not gold and not silver and not copper then
 		return "The provided amount of money is invalid. Please provide the amount of money as #g#s#c, e.g. 591617g24s43c.";