Quantcast

Create a template class creator

Brandon Talbot [06-29-16 - 07:16]
Create a template class creator
Filename
src/lua/base/djclass.lua
src/lua/core.lua
src/manifest.xml
diff --git a/src/lua/base/djclass.lua b/src/lua/base/djclass.lua
new file mode 100644
index 0000000..157a374
--- /dev/null
+++ b/src/lua/base/djclass.lua
@@ -0,0 +1,69 @@
+-- local NAME, ADDON = ...
+
+function class(...)
+    local arg1 = ...
+    local base
+    if type(arg1) == 'table' and arg1.__djclass then
+        base = arg1
+    end
+
+    local c = {}
+    c.__index = c
+    c.__djclass = true
+    c.type = select(base and 2 or 1, ...) or base and base.type
+    c.inherits = select(base and 3 or 2, ...) or base and base.inherits
+
+    if base then
+        for k, v in pairs(base) do
+            c[k] = v
+        end
+    end
+
+    setmetatable(c, {
+        __call = function(table, ...)
+            local name
+            if table.type then
+                name = ...
+                assert(name and type(name) == 'string', 'DJClass needs a name (first argument) when creating an object for WoWs frame content')
+            end
+            local obj
+            if name then
+                obj = {} -- CreateFrame(name, table.type, UIParent, table.inherits)
+            else
+                obj = {}
+            end
+
+            for k, v in pairs(table) do
+                obj[k] = v
+            end
+
+            if obj.init and type(obj.init) == 'function' then
+                obj:init(select(name and 2 or 1, ...))
+            end
+
+            return obj
+        end
+    })
+
+    return c
+end
+
+local A = class('FRAME')
+function A:init(string)
+    self.name = string
+end
+
+local B = class(A)
+function B:init(name, text)
+    A.init(self, name)
+    self.text = text
+end
+
+function B:print()
+    print(self.name, self.text)
+end
+
+print("\nstart\n\n")
+
+local b = B('Namerize', 'Text', 'Face')
+b:print()
\ No newline at end of file
diff --git a/src/lua/core.lua b/src/lua/core.lua
new file mode 100644
index 0000000..4f05f6d
--- /dev/null
+++ b/src/lua/core.lua
@@ -0,0 +1 @@
+local NAME, ADDON = ...
\ No newline at end of file
diff --git a/src/manifest.xml b/src/manifest.xml
new file mode 100644
index 0000000..5e4e862
--- /dev/null
+++ b/src/manifest.xml
@@ -0,0 +1,33 @@
+<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/  http://wowprogramming.com/FrameXML/UI.xsd">
+    <!-- Utils -->
+    <!--<Script file="src/lua/util/uuid.lua"/>-->
+    <!--<Script file="src/lua/util/util.lua"/>-->
+
+    <!-- Cache -->
+    <!--<Script file="src/lua/cache/cache.lua"/>-->
+
+    <!-- Settings -->
+    <!--<Script file="src/lua/settings/defaults/item.lua"/>-->
+    <!--<Script file="src/lua/settings/defaults/container.lua"/>-->
+    <!--<Script file="src/lua/settings/defaults/itemContainer.lua"/>-->
+    <!--<Script file="src/lua/settings/defaults/category.lua"/>-->
+    <!--<Script file="src/lua/settings/defaults/categoryContainer.lua"/>-->
+    <!--<Script file="src/lua/settings/defaults/moneyBar.lua"/>-->
+    <!--<Script file="src/lua/settings/settings.lua"/>-->
+
+    <!-- Tools -->
+    <!--<Script file="src/lua/event/eventManager.lua"/>-->
+
+    <!-- elements -->
+    <!--<Script file="src/lua/element/item.lua"/>-->
+    <!--<Script file="src/lua/element/container.lua"/>-->
+    <!--<Script file="src/lua/element/itemContainer.lua"/>-->
+    <!--<Script file="src/lua/element/categoryContainer.lua"/>-->
+    <!--<Script file="src/lua/element/moneyBar.lua"/>-->
+
+    <!-- Controller -->
+    <!--<Script file="src/lua/controller/bag.lua"/>-->
+
+    <!-- Core (Load last) -->
+    <Script file="src/lua/core.lua"/>
+</Ui>
\ No newline at end of file