Add sage.class.namespace function
Silversage of Eitrigg [10-03-11 - 01:01]
Add sage.class.namespace function
diff --git a/SageClass.lua b/SageClass.lua
index 4b5e4f5..9967429 100644
--- a/SageClass.lua
+++ b/SageClass.lua
@@ -1,7 +1,15 @@
-- SageClass.lua
-sage = sage or {}
-sage.class = sage.class or {}
+local function namespace(s)
+ local result = _G
+ for name in s:gmatch("%w+") do
+ result[name] = result[name] or {}
+ result = result[name]
+ end
+ return result
+end
+
+namespace("sage.class").namespace = namespace
----------------------------------------------------------------------------------------------------
local rgbHash do
@@ -72,4 +80,4 @@ do
Class = class
end
-sage.class.Class = Class
+namespace("sage.class").Class = Class
diff --git a/SageItem.lua b/SageItem.lua
index 56ae472..bbce2e5 100644
--- a/SageItem.lua
+++ b/SageItem.lua
@@ -1,9 +1,8 @@
-- SageItem.lua
----------------------------------------------------------------------------------------------------
-local Class = (sage and sage.class and sage.class.Class) or error("Need access to sage.class.Class")
-
-local Reforgings = sage.reforge and sage.reforge.Reforgings or error("Need Reforgings")
+local Class = sage.class.Class
+local Reforgings = sage.reforge.Reforgings
----------------------------------------------------------------------------------------------------
local Item do
@@ -84,5 +83,4 @@ local Item do
Item = class
end
-sage.item = sage.item or {}
-sage.item.Item = Item
+sage.class.namespace("sage.item").Item = Item