Files
wiki/dst/QScript/Lua/Imports.html
2023-09-23 15:37:48 +02:00

72 lines
2.7 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/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>