mirror of
https://github.com/celisej567/wiki.git
synced 2026-01-03 18:11:10 +03:00
75 lines
3.2 KiB
HTML
75 lines
3.2 KiB
HTML
<!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 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>
|
|
|
|
<p><small style="position:relative; top:16px;">MyMod/MyLib.lua</small></p>
|
|
|
|
<pre><code>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>
|
|
|
|
<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>
|
|
|
|
</div> |