Lua rundown

This commit is contained in:
relt-1
2023-09-23 15:37:48 +02:00
parent f6b4c0b47b
commit cdf5e7a2ae
12 changed files with 434 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'QScript Tutorial Chapter 1']
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
@@ -25,6 +25,15 @@
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
var res = [];
var searchresults = document.getElementById("searchresults")
searchresults.innerHTML = ""
if(searchtext === "")
return;
for (var i = 0; i < namelist.length; i++)
{
if(!namelist[i].toLowerCase().includes(searchtext)) continue;
var searchelement = document.createElement("li");
var link = document.createElement("a");
searchelement.appendChild(link);
link.setAttribute("href", documentlist[i]);
link.innerHTML = namelist[i];
searchresults.appendChild(searchelement);
}
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>
<ul id="searchresults">
</ul>
</nav>
</div>
<div style="margin-left:200px;">
<h1>Lua Classes</h1>
<p>If you want to create a class, you first call the <code>class()</code> function like this:</p>
<pre><code>my_class = class() -- Creates a class creator
</code></pre>
<p><code>my_class</code> becomes a class creator. You can think of it like a bowl of ingredients which you can add to by simply setting the values of it.</p>
<pre><code>my_class = class() -- Creates a class creator
my_class.MyVar = 50.0 -- Creates a variable inside the class
function my_class.MyFunc(self,a) -- Creates a function inside the class
return self.MyVar+a
end
</code></pre>
<p>Once you are done with defining your class, you call the <code>finish()</code> function like this:</p>
<pre><code>finish(my_class) -- Finishes the class
</code></pre>
<p><code>my_class</code> will turn into a normal class where you cannot add any more variables or functions to it. In other words, <code>my_class</code> will get "baked" and you cannot add any more ingredients to it.</p>
<hr />
<p><a href="/wiki/QScript/Lua/Objects.html">Next -></a></p>
</div>

View File

@@ -0,0 +1,77 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
var res = [];
var searchresults = document.getElementById("searchresults")
searchresults.innerHTML = ""
if(searchtext === "")
return;
for (var i = 0; i < namelist.length; i++)
{
if(!namelist[i].toLowerCase().includes(searchtext)) continue;
var searchelement = document.createElement("li");
var link = document.createElement("a");
searchelement.appendChild(link);
link.setAttribute("href", documentlist[i]);
link.innerHTML = namelist[i];
searchresults.appendChild(searchelement);
}
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>
<ul id="searchresults">
</ul>
</nav>
</div>
<div style="margin-left:200px;">
<h1>Lua Exports</h1>
<p>Here is the real meat and potatoes of QScript. The import/export system allows you to share objects, functions and classes between scripts and other languages! The system is stupidly simple to understand.</p>
<p>Here is a simple code example:</p>
<pre><code>function Add(a,b)
return a + b
end
export(Add)
</code></pre>
<p>That is it! Just put the global variable you want to export in the global scope (not inside another function) and the thing you want to export will get added to a special list which will contain all the exported elements from your file.</p>
<p>Exporting classes and objects works the same way.</p>
<pre><code>my_class = class()
finish(my_class)
my_object = object(my_class)
export(my_class)
export(my_object)
</code></pre>
<hr />
<p><a href="/wiki/QScript/Lua/Objects.html">&lt;- Prev</a> |
<a href="/wiki/QScript/Lua/Imports.html">Next -></a></p>
</div>

View File

@@ -0,0 +1,72 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
var res = [];
var searchresults = document.getElementById("searchresults")
searchresults.innerHTML = ""
if(searchtext === "")
return;
for (var i = 0; i < namelist.length; i++)
{
if(!namelist[i].toLowerCase().includes(searchtext)) continue;
var searchelement = document.createElement("li");
var link = document.createElement("a");
searchelement.appendChild(link);
link.setAttribute("href", documentlist[i]);
link.innerHTML = namelist[i];
searchresults.appendChild(searchelement);
}
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>
<ul id="searchresults">
</ul>
</nav>
</div>
<div style="margin-left:200px;">
<h1>Lua Imports</h1>
<p>Now that you have exported some variables, something's gotta import them! As always, it is very simple to do.</p>
<p>Let's say that you have made a file called "MyLib.lua" inside a mod called "MyMod". These are the contents of it:</p>
<pre><code>-- MyMod/MyLib.lua
function add(a,b)
return a + b
end
export(add)
</code></pre>
<p>Now you want to import it inside another file. You call the <code>import()</code> function with the file name of the thing you want to import. It will return a table containing all the exported variables.</p>
<pre><code>MyLib = import("MyMod/MyLib.lua") -- Import the library
MyLib.add(5,7) -- Will return 12
</code></pre>
<p>Importing works between other languages. So you don't need to worry about a library being written in a different language than you would like. (You could even use multiple languages in one project! Think about that!)</p>
<hr />
<p><a href="/wiki/QScript/Lua/Exports.html">&lt;- Prev</a></p>
</div>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
var res = [];
var searchresults = document.getElementById("searchresults")
searchresults.innerHTML = ""
if(searchtext === "")
return;
for (var i = 0; i < namelist.length; i++)
{
if(!namelist[i].toLowerCase().includes(searchtext)) continue;
var searchelement = document.createElement("li");
var link = document.createElement("a");
searchelement.appendChild(link);
link.setAttribute("href", documentlist[i]);
link.innerHTML = namelist[i];
searchresults.appendChild(searchelement);
}
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>
<ul id="searchresults">
</ul>
</nav>
</div>
<div style="margin-left:200px;">
<h1>Lua Objects</h1>
<p>Objects store a number of variables and functions which are defined in the class the object comes from. They kind of act like tables but are not modifiable. Meaning, if you wanted to make a new variable or function inside an object, you would get an error.</p>
<p>Another thing that is different from tables is that you cannot change the type of the variables. Once they have been defined, that's it. You cannot change that variable to any other type which it originally was defined with.</p>
<p>To create a new object, simply call the <code>object()</code> function with a class, and it will return a new object based on the class you gave it.</p>
<pre><code>my_class = class() -- Start creating the class
my_class.var = 10.0 -- Make a variable
finish(my_class) -- Finish the class
my_object = object(my_class) -- Make the object
</code></pre>
<hr />
<p><a href="/wiki/QScript/Lua/Classes.html">&lt;- Prev</a> |
<a href="/wiki/QScript/Lua/Exports_Imports.html">Next -></a></p>
</div>

View File

@@ -1,7 +1,7 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'QScript Tutorial Chapter 1']
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
@@ -25,6 +25,15 @@
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>

View File

@@ -1,7 +1,7 @@
<!DOCTYPE html>
<script>
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'QScript Tutorial Chapter 1']
const documentlist = ['/wiki/index.html', '/wiki/QScript/Introduction.html', '/wiki/QScript/Lua/Classes.html', '/wiki/QScript/Lua/Exports.html', '/wiki/QScript/Lua/Imports.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Objects', 'QScript Tutorial Chapter 1']
function updateSearch() {
searchtext = document.getElementById("searchbox").value.toLowerCase();
@@ -25,6 +25,15 @@
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>

View File

@@ -0,0 +1,30 @@
# Lua Classes
If you want to create a class, you first call the `class()` function like this:
my_class = class() -- Creates a class creator
`my_class` becomes a class creator. You can think of it like a bowl of ingredients which you can add to by simply setting the values of it.
my_class = class() -- Creates a class creator
my_class.MyVar = 50.0 -- Creates a variable inside the class
function my_class.MyFunc(self,a) -- Creates a function inside the class
return self.MyVar+a
end
Once you are done with defining your class, you call the `finish()` function like this:
finish(my_class) -- Finishes the class
`my_class` will turn into a normal class where you cannot add any more variables or functions to it. In other words, `my_class` will get "baked" and you cannot add any more ingredients to it.
---
[Next ->][QScript/Lua/Objects]

View File

@@ -0,0 +1,29 @@
# Lua Exports
Here is the real meat and potatoes of QScript. The import/export system allows you to share objects, functions and classes between scripts and other languages! The system is stupidly simple to understand.
Here is a simple code example:
function Add(a,b)
return a + b
end
export(Add)
That is it! Just put the global variable you want to export in the global scope (not inside another function) and the thing you want to export will get added to a special list which will contain all the exported elements from your file.
Exporting classes and objects works the same way.
my_class = class()
finish(my_class)
my_object = object(my_class)
export(my_class)
export(my_object)
---
[<- Prev][QScript/Lua/Objects] |
[Next ->][QScript/Lua/Imports]

View File

@@ -0,0 +1,24 @@
# Lua Imports
Now that you have exported some variables, something's gotta import them! As always, it is very simple to do.
Let's say that you have made a file called "MyLib.lua" inside a mod called "MyMod". These are the contents of it:
-- MyMod/MyLib.lua
function add(a,b)
return a + b
end
export(add)
Now you want to import it inside another file. You call the `import()` function with the file name of the thing you want to import. It will return a table containing all the exported variables.
MyLib = import("MyMod/MyLib.lua") -- Import the library
MyLib.add(5,7) -- Will return 12
Importing works between other languages. So you don't need to worry about a library being written in a different language than you would like. (You could even use multiple languages in one project! Think about that!)
---
[<- Prev][QScript/Lua/Exports]

View File

@@ -0,0 +1,20 @@
# Lua Objects
Objects store a number of variables and functions which are defined in the class the object comes from. They kind of act like tables but are not modifiable. Meaning, if you wanted to make a new variable or function inside an object, you would get an error.
Another thing that is different from tables is that you cannot change the type of the variables. Once they have been defined, that's it. You cannot change that variable to any other type which it originally was defined with.
To create a new object, simply call the `object()` function with a class, and it will return a new object based on the class you gave it.
my_class = class() -- Start creating the class
my_class.var = 10.0 -- Make a variable
finish(my_class) -- Finish the class
my_object = object(my_class) -- Make the object
---
[<- Prev][QScript/Lua/Classes] |
[Next ->][QScript/Lua/Exports_Imports]

View File

@@ -25,6 +25,15 @@
}
</script>
<style>
pre {
margin-left:16px;
background-color: #EEE;
border-color: #CCC;
border-style:solid;
border-width:1px;
}
</style>
<div style="position:fixed; display:block; top: 0px; left: 0px; height:100%; width:200px;border-color: black; border-width: 1px; border-style:solid;">
<input type="text" placeholder="search..." autocomplete="off" id="searchbox" oninput="updateSearch();" style="width:192px;">
<nav>