diff --git a/docs/class/new_class.html b/docs/class/new_class.html new file mode 100644 index 0000000..3e30e4b --- /dev/null +++ b/docs/class/new_class.html @@ -0,0 +1,133 @@ + + + + + + new_class - MTUL-class + + + + + +
+
+
MTUL-class | implementation of classes and immutable tables in lua (for minetest)
+
+
+
+
+
+
+ +
+
+

Class new_class + +

+
+

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".

+ +
+

Synopsis

+
Fields
+ + + + + + + + + + + + + +
instance

defines wether the object is an instance, use this in construction to determine what changes to make

+
base_class

only present for instances: the class from which this instance originates

+
parent_class

the class from which this class was inherited from

+
+
Methods
+ + + + + + + + + +
mtul.class.new_class:inherit()

creates a new base class

+
mtul.class.new_class:new()

creates an instance of the base class

+
+
+

Fields

+
+
+new_class.instance + +
+
+

defines wether the object is an instance, use this in construction to determine what changes to make

+ +
+
+new_class.base_class + +
+
+

only present for instances: the class from which this instance originates

+ +
+
+new_class.parent_class + +
+
+

the class from which this class was inherited from

+ +
+
+

Methods

+
+
+mtul.class.new_class:inherit(def) + +
+
+

creates a new base class. Calls all constructors in the chain with def.instance=true

+ +
+
+mtul.class.new_class:new(def) + +
+
+

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/index.js b/docs/index.js new file mode 100644 index 0000000..2dc7c4c --- /dev/null +++ b/docs/index.js @@ -0,0 +1,8 @@ +var docs = [ +{path:"class/new_class.html", type:"class", title:"new_class.new_class", text:"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\"."}, +{path:"class/new_class.html#new_class.instance", type:"field", title:"new_class.instance", text:"defines wether the object is an instance, use this in construction to determine what changes to make"}, +{path:"class/new_class.html#new_class.base_class", type:"field", title:"new_class.base_class", text:"only present for instances: the class from which this instance originates"}, +{path:"class/new_class.html#new_class.parent_class", type:"field", title:"new_class.parent_class", text:"the class from which this class was inherited from"}, +{path:"class/new_class.html#mtul.class.new_class.inherit", type:"function", title:"mtul.class.new_class:inherit", text:"creates a new base class. Calls all constructors in the chain with def.instance=true"}, +{path:"class/new_class.html#mtul.class.new_class.new", type:"function", title:"mtul.class.new_class:new", text:"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/js-search.min.js b/docs/js-search.min.js new file mode 100644 index 0000000..4adc065 --- /dev/null +++ b/docs/js-search.min.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).JsSearch={})}(this,(function(e){"use strict";var t=function(){function e(){}return e.prototype.expandToken=function(e){for(var t,n=[],i=0,r=e.length;i=0&&(f=this._wrapText(f),e=e.substring(0,l)+f+e.substring(r+1),r+=n,p+=n)}return e},t._wrapText=function(e){var t=this._wrapperTagName;return"<"+t+">"+e+""},e}();e.AllSubstringsIndexStrategy=t,e.CaseSensitiveSanitizer=r,e.ExactWordIndexStrategy=n,e.LowerCaseSanitizer=o,e.PrefixIndexStrategy=i,e.Search=_,e.SimpleTokenizer=h,e.StemmingTokenizer=f,e.StopWordsMap=d,e.StopWordsTokenizer=l,e.TfIdfSearchIndex=s,e.TokenHighlighter=m,e.UnorderedSearchIndex=u,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/docs/luadox.css b/docs/luadox.css new file mode 100644 index 0000000..56bedd4 --- /dev/null +++ b/docs/luadox.css @@ -0,0 +1,629 @@ +:target { + background-color: #ffe080 !important; + color: black !important; + border-bottom: 1px solid #cca940 !important; + border-top: 1px solid #cca940 !important; +} + +body { + font-family: sans-serif; + color: black; + padding: 0px; + margin: 0; +} + + +div.topbar { + box-sizing: border-box; + background-color: #465158; + position: fixed; + display: flex; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 40px; + padding: 0 1em 0 0.4em; + z-index: 10; + font-size: 90%; + color: white; + box-shadow: 0 0px 15px 5px rgba(0, 0, 0, 0.4); +} + +div.topbar div.group { + display: flex; + flex: 1; +} + +div.topbar div.group.one { + justify-content: flex-start; +} + +div.topbar div.group.two { + justify-content: center; +} +div.topbar div.group.three { + justify-content: flex-end; +} + +div.topbar a { + color: white; + border: none; + padding: 0.5em 1em; +} + +div.topbar div.description a { + font-size: 100% !important; + font-weight: normal !important; + margin-left: 0 !important; +} + +div.topbar div.button a { + margin: 0.375em 0; + font-size: 80%; + font-weight: bold; + white-space: nowrap; + display: flex; + align-items: center; +} + +div.topbar div.button.solid a { + margin-left: 1em; +} + +div.topbar div.button.solid a, +div.topbar div.button a:hover { + background-color: #697983; + text-shadow: 0 1px rgba(0, 0, 0, 0.5); + border-radius: 3px; + border: none; +} +div.topbar div.button.solid a:hover { + background-color: #8aa0ad; +} + +div.topbar div.button a img { + width: 1.5em; +} + +div.topbar div.button a img[src*='.svg'] { + filter: invert(1); +} + +div.topbar div.button.iconleft a { + padding-left: 0.6em; + padding-right: 1em; +} + +div.topbar div.button.iconright a { + padding-left: 1em; + padding-right: 0.6em; +} + +div.topbar div.button.iconleft a img { + padding-right: 0.5em; +} +div.topbar div.button.iconright a img { + padding-left: 0.5em; +} + +div.sidebar { + clear: both; + box-sizing: border-box; + background-color: #e8ecef; + width: 15em; + height: calc(100% - 40px); + padding: 1em 0.5em; + border-right: 1px solid #ccc; + position: fixed; + overflow-y: auto; +} + + +div.body { + margin-left: 15em; + margin-top: 2.5em; +} + +div.sidebar div.heading { + font-weight: bold; +} + +div.sidebar ul { + list-style-type: none; + padding-left: 1em; + margin-top: 0.5em; +} +div.sidebar li { + padding: 2px 0; +} + +div.sidebar li.selected { + font-weight: bold; +} + +div.sidebar div.sections li { + padding-left: 1em; + text-indent: -1em; +} + +div.sidebar p, +h2 p { + margin: 0; + padding: 0; + display: inline; +} + +a { + color: #444; + text-decoration: none; + border-bottom: 1px solid #ccc; +} + +a:hover { + color: #000; + border-bottom: 1px solid #666; +} + +div.section, div.body div.manual { + padding: 0em 1em 1em 1em; +} + +div.body pre { + margin: 0 2em; +} + +div.manual h1 { + margin: 0 -16px 0 -20px; + padding: 10px 10px 10px 20px; + font-size: 120%; +} + +div.section h2 { + margin: 0 -16px 0 -20px; + padding: 10px 10px 10px 20px; + background-color: #eeeeee; + border-top: 1px solid #ccc; + border-bottom: 1px solid #ccc; + font-size: 120%; +} + +div.manual h2, +div.manual h3 { + margin: 1em -16px 0 -20px; + padding: 10px 10px 10px 20px; +} + +div.manual h2 { + background-color: #eeeeee; + border-top: 1px solid #ccc; + border-bottom: 1px solid #ccc; + font-size: 120%; + padding: 10px 10px 10px 20px; +} + +div.manual h3 { + font-size: 110%; + padding: 5px 5px 5px 20px; + /* Ensures when :target applies (which adds borders) we don't affect layout */ + border-top: 1px solid transparent; + border-bottom: 1px solid transparent; +} + +div.hierarchy { + margin-top: 2em; + margin-bottom: 2em; +} + +div.hierarchy div.heading { + font-weight: bold; + margin-bottom: 0.5em; +} +div.hierarchy ul { + margin-top: 0.5em; + padding-left: 1em; +} + +div.hierarchy li { + list-style-type: none; + margin: 0.4em 0; +} +div.hierarchy li span { + padding: 0.2em; + font-family: "Consolas", "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", monospace; + font-size: 0.95em; + letter-spacing: 0.01em; +} +div.hierarchy li span em { + font-style: normal; +} + +div.hierarchy li.self span { + background-color: #fbedc3; +} + +h1, +div.section h2.class, +div.section h2.module { + color: white; + background-color: #555; + border-top: 1px solid #222; + border-bottom: 1px solid #222; + font-size: 140%; +} + + +code { + font-family: 'Courier New', monospace; + font-size: 0.95em; +} + +var, a code { + letter-spacing: 0.01em; + font-weight: bold; + font-style: normal; + color: #444; +} + +div.see::before { + content: "👉 "; +} + +h3.fields, h3.functions { + padding-top: 1em; + padding-bottom: 0.5em !important; +} +dl p:first-child { + margin-top: 0.5em; +} +dl dd:not(:last-child), +dl dd:not(:last-child) { + padding-bottom: 1.5em; + /*border-bottom: 1px solid #ddd;*/ +} + + +dt { + padding: 0.5em; + margin-left: -1em; + margin-right: -1em; + /* Ensures when :target applies (which adds borders) we don't affect layout */ + border-top: 1px solid transparent; + border-bottom: 1px solid transparent; +} +dt var { + font-size: 1.15em; +} +dd { + margin-left: 2.5em; +} + +dl.functions div.heading { + margin-top: 1em; + margin-left: 0em; + margin-bottom: 0.5em; + font-style: italic; +} + + +table.parameters, +table.returns { + max-width: 90%; + border-top: 1px solid #ccc; + border-bottom: 1px solid #ccc; + border-left: transparent; + border-right: transparent; + margin-left: 1em; + border-collapse: collapse; +} +table.parameters td, +table.returns td { + padding: 0.4em 0; + vertical-align: top; +} + +table.parameters tr:not(:last-child) td, +table.returns tr:not(:last-child) td { + border-bottom: 1px solid #ccc; +} + +table.parameters tr, +table.returns tr { + background: #f7f7f7; +} + + +table.parameters tr td:first-child, +table.returns tr td:first-child { + text-align: right; + padding-left: 1em; +} + +table.parameters tr td:last-child, +table.returns tr td:last-child { + padding-right: 1em; +} + +table.parameters td.name, +table.parameters td.types, +table.returns td.name, +table.returns td.types { + white-space: nowrap; + padding-right: 1em !important; +} + + +* { + scroll-padding-top: 40px; +} + +div.section div.inner { + min-width: 20em; + max-width: 80em; +} + +div.synopsis h3 { + display: none; +} + +div.synopsis div.heading { + font-weight: bold; + margin-top: 1em; + margin-bottom: 0em; + margin-left: 0.5em; +} + +div.synopsis table { + border-top: 1px solid #d2b089; + border-bottom: 1px solid #d2b089; + background-color: #f8f0e6; + width: 95%; + margin: 1em auto; + border-collapse: collapse; +} +div.synopsis td { + padding: 0.3em 0.5em 0.3em 0.5em; + vertical-align: top; +} +div.synopsis tr:not(:last-child) td { + border-bottom: 1px solid #e2d0ba; +} + +div.synopsis td:first-child { + /* min-width: 15em; + max-width: 20em; */ + white-space: nowrap; + padding-right: 1em; +} + +div.synopsis td.meta, +div.synopsis td.meta a { + white-space: nowrap; + color: #777777; +} + +div.synopsis td > p, +table.parameters td > p, +table.returns td > p { + margin: 0; +} + +div.synopsis td > p:not(:first-child) { + margin-top: 0.5em; +} + +div.synopsis td a.permalink { + color: #aaa; +} + + +div.admonition { + border: 1px solid #609060; + background-color: #e9ffe9; + width: 90%; + margin: 1.5em auto; +} + +div.admonition div.title { + margin: 0; + margin-top: 0px; + padding: 0.3em 0 0.3em 0.5em; + color: white; + font-weight: bold; + font-size: 1.0em; + text-shadow: 0 1px rgba(0, 0, 0, 0.5); +} + +div.admonition div.body { + margin: 0.5em 1em 0.5em 1em; + padding: 0; +} + + +div.warning { + border: 1px solid #900000; + background-color: #ffe9e9; +} + +div.warning div.title { + background-color: #b04040; + border-bottom: 1px solid #900000; +} + +div.note div.title { + background-color: #70A070; + border-bottom: 1px solid #609060; +} + +dl.fields dt span.icon::after { + content: "🏷️ "; + vertical-align: middle; + font-size: 110%; +} + +dl.fields dt span.tag, +dl.functions dt span.tag { + border-radius: 20px; + border: 1px solid #ccc; + background-color: #eee; + display: inline; + opacity: 0.6; + padding: 5px 10px; + font-size: 80%; + margin: 0 0.5em; +} + +dl.fields dt span.tag:first-of-type, +dl.functions dt span.tag:first-of-type { + margin-left: 2em; +} + +dl.fields dt span.meta::before, +dl.functions dt span.meta::before { + filter: saturate(0); + opacity: 0.9; + content: "👁️"; + padding-right: 0.5em; +} + +dl.fields dt span.type::before { + filter: saturate(0); + opacity: 0.9; + content: "✏️"; + padding-right: 0.5em; +} + +dl.functions dt span.icon::after { + content: "🏃‍♂️ "; + vertical-align: middle; + font-size: 140%; +} + +a.permalink:hover { + color: #c60f0f !important; + border: none; +} + +a.permalink { + color: #ccc; + font-size: 1em; + margin-left: 6px; + padding: 0 4px 0 4px; + text-decoration: none; + border: none; + visibility: hidden; +} + +h1:hover > a.permalink, +h2:hover > a.permalink, +h3:hover > a.permalink, +h4:hover > a.permalink, +td:hover > a.permalink, +td:hover > div > a.permalink, +dt:hover > a.permalink { + visibility: visible; +} + +pre.language-lua { + border-radius: 6px; +} + +dd table { +} + +input.search { + width: calc(100% - 2.5em); + opacity: 0.7; + margin: 0 1em 1em 1em; +} + +input.search:focus { + opacity: 1.0; +} + +div#template { + display: none; +} + +div#results { + padding: 1em; + max-width: 650px; +} + +div.result { + margin-bottom: 35px; + font-family: arial, sans-serif; +} + +div.result div.title { + font-size: 20px; + line-height: 1.3; +} + +div.result div.text { + line-height: 1.58; + margin-left: 2em; +} + +div.summary { + color: #666666; + font-size: 90%; + margin-bottom: 1em; +} + +div.result span { + font-size: 90%; +} + +div.result.result-class span::after { + content: "🧱 "; +} +div.result.result-module span::after { + content: "📦 "; +} +div.result.result-field span::after { + content: "🏷️ "; +} +div.result.result-function span::after { + content: "🏃‍♂️ "; +} +div.result.result-section span::after { + content: "📓 "; +} +div.result b { + background-color: #faffb8; +} + +table.user { + border-collapse: collapse; + margin: 1em; + font-family: sans-serif; + min-width: 400px; + box-shadow: 0 0 20px rgba(0, 0, 0, 0.15); + border-radius: 10px; + border-collapse: collapse; + overflow: hidden; +} + +table.user thead tr { + background-color: #3a5e75; + color: #ffffff; + text-align: left; +} + +table.user th, +table.user td { + padding: 12px 15px; +} + +table.user tbody tr { + border-bottom: 1px solid #dddddd; +} + +table.user tbody tr:nth-of-type(even) { + background-color: #f3f3f3; +} + +table.user tbody tr:last-of-type { + border-bottom: 3px solid #3a5e75; +} diff --git a/docs/prism.css b/docs/prism.css new file mode 100644 index 0000000..2c48749 --- /dev/null +++ b/docs/prism.css @@ -0,0 +1,125 @@ +/* PrismJS 1.24.1 +https://prismjs.com/download.html#themes=prism-tomorrow&languages=lua */ +/** + * prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML + * Based on https://github.com/chriskempson/tomorrow-theme + * @author Rose Pritchard + */ + +code[class*="language-"], +pre[class*="language-"] { + color: #ccc; + background: none; + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + font-size: 1em; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: 1.5; + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; + +} + +/* Code blocks */ +pre[class*="language-"] { + padding: 1em; + margin: .5em 0; + overflow: auto; +} + +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background: #2d2d2d; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + padding: .1em; + border-radius: .3em; + white-space: normal; +} + +.token.comment, +.token.block-comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: #999; +} + +.token.punctuation { + color: #ccc; +} + +.token.tag, +.token.attr-name, +.token.namespace, +.token.deleted { + color: #e2777a; +} + +.token.function-name { + color: #6196cc; +} + +.token.boolean, +.token.number, +.token.function { + color: #f08d49; +} + +.token.property, +.token.class-name, +.token.constant, +.token.symbol { + color: #f8c555; +} + +.token.selector, +.token.important, +.token.atrule, +.token.keyword, +.token.builtin { + color: #cc99cd; +} + +.token.string, +.token.char, +.token.attr-value, +.token.regex, +.token.variable { + color: #7ec699; +} + +.token.operator, +.token.entity, +.token.url { + color: #67cdcc; +} + +.token.important, +.token.bold { + font-weight: bold; +} +.token.italic { + font-style: italic; +} + +.token.entity { + cursor: help; +} + +.token.inserted { + color: green; +} + diff --git a/docs/prism.js b/docs/prism.js new file mode 100644 index 0000000..c2132f4 --- /dev/null +++ b/docs/prism.js @@ -0,0 +1,4 @@ +/* PrismJS 1.24.1 +https://prismjs.com/download.html#themes=prism-dark&languages=lua */ +var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(u){var c=/\blang(?:uage)?-([\w-]+)\b/i,n=0,e={},M={manual:u.Prism&&u.Prism.manual,disableWorkerMessageHandler:u.Prism&&u.Prism.disableWorkerMessageHandler,util:{encode:function e(n){return n instanceof W?new W(n.type,e(n.content),n.alias):Array.isArray(n)?n.map(e):n.replace(/&/g,"&").replace(/=l.reach);y+=m.value.length,m=m.next){var b=m.value;if(t.length>n.length)return;if(!(b instanceof W)){var k,x=1;if(h){if(!(k=z(v,y,n,f)))break;var w=k.index,A=k.index+k[0].length,P=y;for(P+=m.value.length;P<=w;)m=m.next,P+=m.value.length;if(P-=m.value.length,y=P,m.value instanceof W)continue;for(var E=m;E!==t.tail&&(Pl.reach&&(l.reach=N);var j=m.prev;O&&(j=I(t,j,O),y+=O.length),q(t,j,x);var C=new W(o,g?M.tokenize(S,g):S,d,S);if(m=I(t,j,C),L&&I(t,m,L),1l.reach&&(l.reach=_.reach)}}}}}}(e,a,n,a.head,0),function(e){var n=[],t=e.head.next;for(;t!==e.tail;)n.push(t.value),t=t.next;return n}(a)},hooks:{all:{},add:function(e,n){var t=M.hooks.all;t[e]=t[e]||[],t[e].push(n)},run:function(e,n){var t=M.hooks.all[e];if(t&&t.length)for(var r,a=0;r=t[a++];)r(n)}},Token:W};function W(e,n,t,r){this.type=e,this.content=n,this.alias=t,this.length=0|(r||"").length}function z(e,n,t,r){e.lastIndex=n;var a=e.exec(t);if(a&&r&&a[1]){var i=a[1].length;a.index+=i,a[0]=a[0].slice(i)}return a}function i(){var e={value:null,prev:null,next:null},n={value:null,prev:e,next:null};e.next=n,this.head=e,this.tail=n,this.length=0}function I(e,n,t){var r=n.next,a={value:t,prev:n,next:r};return n.next=a,r.prev=a,e.length++,a}function q(e,n,t){for(var r=n.next,a=0;a"+a.content+""},!u.document)return u.addEventListener&&(M.disableWorkerMessageHandler||u.addEventListener("message",function(e){var n=JSON.parse(e.data),t=n.language,r=n.code,a=n.immediateClose;u.postMessage(M.highlight(r,M.languages[t],t)),a&&u.close()},!1)),M;var t=M.util.currentScript();function r(){M.manual||M.highlightAll()}if(t&&(M.filename=t.src,t.hasAttribute("data-manual")&&(M.manual=!0)),!M.manual){var a=document.readyState;"loading"===a||"interactive"===a&&t&&t.defer?document.addEventListener("DOMContentLoaded",r):window.requestAnimationFrame?window.requestAnimationFrame(r):window.setTimeout(r,16)}return M}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); +Prism.languages.lua={comment:/^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,string:{pattern:/(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,greedy:!0},number:/\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,keyword:/\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,function:/(?!\d)\w+(?=\s*(?:[({]))/,operator:[/[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,{pattern:/(^|[^.])\.\.(?!\.)/,lookbehind:!0}],punctuation:/[\[\](){},;]|\.+|:+/}; diff --git a/docs/search.html b/docs/search.html new file mode 100644 index 0000000..da0890b --- /dev/null +++ b/docs/search.html @@ -0,0 +1,43 @@ + + + + + + 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