An instantiatable class to inherit for defining new instantiatble classes classes
+the "base" class. To make a new class call new_class:inherit(your_new_class).
+also note that these classes will not have the type "table" but "class".
creates an instance of the base class. Calls all constructors in the chain with def.instance=true
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/img/i-bitbucket.svg b/docs/img/i-bitbucket.svg
new file mode 100644
index 0000000..90ca0fe
--- /dev/null
+++ b/docs/img/i-bitbucket.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/img/i-download.svg b/docs/img/i-download.svg
new file mode 100644
index 0000000..67c9440
--- /dev/null
+++ b/docs/img/i-download.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/img/i-github.svg b/docs/img/i-github.svg
new file mode 100644
index 0000000..25d9004
--- /dev/null
+++ b/docs/img/i-github.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/img/i-gitlab.svg b/docs/img/i-gitlab.svg
new file mode 100644
index 0000000..6da80a3
--- /dev/null
+++ b/docs/img/i-gitlab.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/img/i-left.svg b/docs/img/i-left.svg
new file mode 100644
index 0000000..72f5e6d
--- /dev/null
+++ b/docs/img/i-left.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/img/i-right.svg b/docs/img/i-right.svg
new file mode 100644
index 0000000..22dc526
--- /dev/null
+++ b/docs/img/i-right.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
new file mode 100644
index 0000000..aa7ad47
--- /dev/null
+++ b/docs/index.html
@@ -0,0 +1,37 @@
+
+
+
+
+
+ Search - MTUL-class
+
+
+
+
+
+
+
+
MTUL-class | implementation of classes and immutable tables in lua (for minetest)
+
+
+
\ No newline at end of file
diff --git a/docs/search.js b/docs/search.js
new file mode 100644
index 0000000..cb2a7b0
--- /dev/null
+++ b/docs/search.js
@@ -0,0 +1,48 @@
+document.addEventListener("DOMContentLoaded", function() {
+ var template = document.getElementById('template');
+ var body = document.getElementById('results');
+ var params = new URLSearchParams(window.location.search);
+ var q = params.get('q');
+ if (!q) {
+ return;
+ }
+ var jss = new JsSearch.Search('title');
+ jss.tokenizer = new JsSearch.StopWordsTokenizer(new JsSearch.SimpleTokenizer());
+ jss.addIndex('title');
+ jss.addIndex('text');
+ jss.addDocuments(docs);
+ var results = jss.search(q);
+ var summary = document.getElementsByClassName('summary')[0];
+ summary.innerHTML = results.length + ' results found for "' + q + '"';
+ var words = q.split(' ');
+ for (var i = 0; i < results.length; i++) {
+ var result = results[i];
+ var clone = template.cloneNode(true);
+ clone.removeAttribute('id');
+ clone.classList.add("result-" + result.type);
+ var title = clone.childNodes[0];
+ var icon = title.childNodes[0];
+ var link = title.childNodes[1];
+ var text = result.text;
+ var title = result.title;
+ if (text.length > 200) {
+ text = text.slice(0, 210);
+ var n = text.lastIndexOf(' ');
+ if (n >= 0) {
+ text = text.slice(0, n);
+ }
+ text = text + ' ...';
+ }
+ // Bold search terms from text
+ for (var j = 0; j < words.length; j++) {
+ text = text.replace(new RegExp('(' + words[j] + ')', 'i'), '$1');
+ title = title.replace(new RegExp('(' + words[j] + ')', 'i'), '$1');
+ }
+ icon.setAttribute('title', result.type);
+ link.setAttribute('href', result.path);
+ link.innerHTML = title + (result.type == 'function' ? "()" : "");
+ var desc = clone.childNodes[1];
+ desc.innerHTML = text;
+ body.appendChild(clone);
+ }
+ });
\ No newline at end of file
diff --git a/generate_docs/luadox/luadox b/generate_docs/luadox/luadox
new file mode 100644
index 0000000..2a5ae53
Binary files /dev/null and b/generate_docs/luadox/luadox differ
diff --git a/generate_docs/luadox/luadox.conf b/generate_docs/luadox/luadox.conf
new file mode 100644
index 0000000..74b6073
--- /dev/null
+++ b/generate_docs/luadox/luadox.conf
@@ -0,0 +1,27 @@
+[project]
+# Project name that is displayed on the top bar of each page
+name = MTUL-class | implementation of classes and immutable tables in lua (for minetest)
+# HTML title that is appended to every page. If not defined, name is used.
+title = MTUL-class
+# A list of files or directories for LuaDox to parse. Globs are supported.
+# This can be spread across multiple lines if you want, as long as the
+# other lines are indented.
+files = ../../*.lua
+# The directory containing the rendered output files, which will be created
+# if necessary.
+outdir = ../../docs
+# Path to a custom css file that will be included on every page. This will
+# be copied into the outdir.
+# css = custom.css
+# Path to a custom favicon. This will be copied into the outdir.
+# favicon = img/favicon.png
+# If require()d files discovered in source should also be parsed.
+follow = true
+
+[manual]
+# Custom manual pages in the form: id = filename.
+#
+# The ids must not conflict with any class or module name otherwise references
+# will not properly resolve.
+# index = intro.md
+# tutorial = tut.md
\ No newline at end of file
diff --git a/generate_docs/luadox/run.bat b/generate_docs/luadox/run.bat
new file mode 100644
index 0000000..82ef7b7
--- /dev/null
+++ b/generate_docs/luadox/run.bat
@@ -0,0 +1,4 @@
+::literally just so I dont have to open powershell every time.
+::python 3.8+ required.
+@echo off
+python ./luadox -c ./luadox.conf
\ No newline at end of file
diff --git a/new_class.lua b/new_class.lua
index 7e8aaf1..ca2e81b 100644
--- a/new_class.lua
+++ b/new_class.lua
@@ -1,8 +1,12 @@
--- An instantiatable class to inherit for defining new instantiatble classes classes
--- the "base" class. To make a new class call `new_class:inherit(your_new_class)`
+-- the "base" class. To make a new class call `new_class:inherit(your_new_class)`.
+-- also note that these classes will not have the type "table" but "class".
--
-- @classmod new_class
-
+local objects = {}
+setmetatable(objects, {
+ __mode = 'kv' --allow garbage collection.
+})
mtul.class.new_class = {
instance = false,
--__no_copy = true
@@ -18,6 +22,7 @@ mtul.class.new_class = {
-- @return def a new base class
-- @function Guns4d.Instantiatable_class:inherit()
function mtul.class.new_class:inherit(def)
+ objects[def] = true
--construction chain for inheritance
--if not def then def = {} else def = table.shallow_copy(def) end
def.parent_class = self
@@ -59,4 +64,9 @@ function mtul.class.new_class:new(def)
--call the construct chain for inherited objects, also important this is called after meta changes
self.construct(def)
return def
+end
+local old_type = type
+function type(a, ...)
+ if objects[a] then return "class" end
+ return old_type(a, ...)
end
\ No newline at end of file
diff --git a/proxy_table.lua b/proxy_table.lua
index d8bb381..d88096e 100644
--- a/proxy_table.lua
+++ b/proxy_table.lua
@@ -1,15 +1,44 @@
--
-local Proxy_table = mtul.class.proxy_table
-Proxy_table = {
+local Proxy_table = {
registered_proxies = {},
+ tables_by_proxies = {},
proxy_children = {}
}
+--setmetatable(Proxy_table.registered_proxies, {__mode="k"})
+--setmetatable(Proxy_table.tables_by_proxies, {__mode="v"})
+--setmetatable(Proxy_table.proxy_children, {__mode="k"})
+
+mtul.class.proxy_table = Proxy_table
--this creates proxy tables in a structure of tables
--this is great if you want to prevent the change of a table
--but still want it to be viewable, such as with constants
+--og_table is the table which you want to be immutable. Parent is the parent proxy which it is apart of (this is optional and used for recursive parenting)
+local tables_by_proxies = Proxy_table.tables_by_proxies
+local metatable = {
+ __index = function(t, key)
+ local og_table = tables_by_proxies[t]
+ if type(og_table[key]) == "table" then
+ return Proxy_table:get_or_create(og_table[key], og_table.__proxy_table_parent)
+ else
+ return og_table[key]
+ end
+ end,
+ __newindex = function(table, key)
+ assert(false, "attempt to edit immutable table, cannot edit a proxy table (MTUL-class)")
+ end,
+ __len = function(t)
+ print("test")
+ return #tables_by_proxies[t]
+ end,
+ __testvar=true
+}
+
function Proxy_table:new(og_table, parent)
- local new = {}
+ local new = {
+ __proxy_table_parent = parent
+ }
self.registered_proxies[og_table] = new
+ self.tables_by_proxies[new] = og_table
if parent then
self.proxy_children[parent][og_table] = true
else
@@ -17,18 +46,7 @@ function Proxy_table:new(og_table, parent)
parent = og_table
end
--set the proxy's metatable
- setmetatable(new, {
- __index = function(t, key)
- if type(og_table[key]) == "table" then
- return Proxy_table:get_or_create(og_table[key], parent)
- else
- return og_table[key]
- end
- end,
- __newindex = function(table, key)
- assert(false, "attempt to edit immutable table, cannot edit a proxy table (MTUL-class)")
- end,
- })
+ setmetatable(new, metatable)
--[[overwrite og_table meta to destroy the proxy aswell (but I realized it wont be GCed unless it's removed altogether, so this is pointless)
local mtable = getmetatable(og_table)
local old_gc = mtable.__gc
@@ -57,4 +75,17 @@ function Proxy_table:destroy_proxy(parent)
end
end
self.proxy_children[parent] = nil
+end
+local proxies = Proxy_table.tables_by_proxies
+local old_next = next
+function next(t, i)
+ return old_next(proxies[t] or t, i)
+end
+local old_pairs = pairs
+function pairs(t, ...)
+ return old_pairs(proxies[t] or t, ...)
+end
+local old_ipairs = ipairs
+function ipairs(t, ...)
+ return old_ipairs(proxies[t] or t, ...)
end
\ No newline at end of file