mirror of
https://github.com/celisej567/wiki.git
synced 2026-01-03 18:11:10 +03:00
More elaboration
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<!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']
|
||||
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/Intro.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
|
||||
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Intro', 'Lua Objects', 'QScript Tutorial Chapter 1']
|
||||
|
||||
function updateSearch() {
|
||||
searchtext = document.getElementById("searchbox").value.toLowerCase();
|
||||
@@ -44,7 +44,11 @@ pre {
|
||||
<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>
|
||||
<p>Let's start with an analogy. Imagine you want to make star-shaped cookies. You could of course, manually cut the baked cookie and then be left with a mess, or you could use a cookie cutter before baking it. In this analogy, the cookie is an object, the manual cutting method is using tables, and the cookie cutter is a class.</p>
|
||||
|
||||
<p>Before explaining what an object is, let's first take a look at how you even make a class.</p>
|
||||
|
||||
<p>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>
|
||||
@@ -72,17 +76,16 @@ end
|
||||
|
||||
<pre><code>another_class = class(my_class) -- Inherits from my_class
|
||||
|
||||
another_class.MyVar = 20.0 -- Overrides the built-in variable
|
||||
function another_class.NewFunc(self,b)
|
||||
another_class.MyVar = 20.0 -- Changes the existing variable
|
||||
function another_class.NewFunc(self,b) -- Makes a new function
|
||||
return self.MyVar-b
|
||||
end
|
||||
|
||||
finish(another_class) -- Finishes it
|
||||
|
||||
another_class.MyFunc(5) -- Will return 25
|
||||
another_class.NewFunc(5) -- Will return 15
|
||||
</code></pre>
|
||||
|
||||
<p>We can now move on to objects.</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<p><a href="/wiki/QScript/Lua/Objects.html">Next -></a></p>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!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']
|
||||
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/Intro.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
|
||||
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Intro', 'Lua Objects', 'QScript Tutorial Chapter 1']
|
||||
|
||||
function updateSearch() {
|
||||
searchtext = document.getElementById("searchbox").value.toLowerCase();
|
||||
@@ -69,6 +69,8 @@ export(my_class)
|
||||
export(my_object)
|
||||
</code></pre>
|
||||
|
||||
<p>That's great but now what can you do with the exported variables? That's the thing. You don't! Other scripts use the exported variables. See how and why in the next page.</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<p><a href="/wiki/QScript/Lua/Objects.html"><- Prev</a> |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!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']
|
||||
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/Intro.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
|
||||
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Intro', 'Lua Objects', 'QScript Tutorial Chapter 1']
|
||||
|
||||
function updateSearch() {
|
||||
searchtext = document.getElementById("searchbox").value.toLowerCase();
|
||||
@@ -48,8 +48,9 @@ pre {
|
||||
|
||||
<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)
|
||||
<p><small style="position:relative; top:16px;">MyMod/MyLib.lua</small></p>
|
||||
|
||||
<pre><code>function add(a,b)
|
||||
return a + b
|
||||
end
|
||||
|
||||
@@ -65,6 +66,8 @@ MyLib.add(5,7) -- Will return 12
|
||||
|
||||
<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>
|
||||
|
||||
<p>The reason why you can't use tables, is because objects, are actually shared! One script can modify it (like set a variable), and every other script will also see the change. Tables differ between languages, meaning that having to manually sync them between eachother would be a bad idea. Here, you only get a "reference" to the object. Meaning that every script sees the <em>same</em> object, not copies of it.</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<p><a href="/wiki/QScript/Lua/Exports.html"><- Prev</a></p>
|
||||
|
||||
51
dst/QScript/Lua/Intro.html
Normal file
51
dst/QScript/Lua/Intro.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!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/Intro.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
|
||||
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Intro', '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 Intro</h1>
|
||||
|
||||
<p>The tutorial will assume that you already know the basics of Lua. If you do not know anything about it, then you can go to <a href="https://www.lua.org/pil/contents.html">the official PIL</a></p>
|
||||
|
||||
<p>First, let's learn about <a href="/wiki/QScript/Lua/Classes.html">Lua Classes</a></p>
|
||||
|
||||
</div>
|
||||
@@ -1,7 +1,7 @@
|
||||
<!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']
|
||||
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/Intro.html', '/wiki/QScript/Lua/Objects.html', '/wiki/QScript/Tutorial/Chapter1.html']
|
||||
const namelist = ['Wiki Intro', 'QScript Intro', 'Lua Classes', 'Lua Exports', 'Lua Imports', 'Lua Intro', 'Lua Objects', 'QScript Tutorial Chapter 1']
|
||||
|
||||
function updateSearch() {
|
||||
searchtext = document.getElementById("searchbox").value.toLowerCase();
|
||||
@@ -59,6 +59,8 @@ finish(my_class) -- Finish the class
|
||||
my_object = object(my_class) -- Make the object
|
||||
</code></pre>
|
||||
|
||||
<p>Why would you use an object instead of a table? Well, you'll soon see why.</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<p><a href="/wiki/QScript/Lua/Classes.html"><- Prev</a> |
|
||||
|
||||
Reference in New Issue
Block a user