nml/readme/Lua Basics.html

1 line
4.4 KiB
HTML
Raw Normal View History

2024-11-03 14:12:43 +01:00
<!DOCTYPE HTML><html><head><meta charset="UTF-8"><title>NML | Lua Basics</title><link rel="stylesheet" href="../style.css"></head><body><div class="layout"><input id="navbar-checkbox" class="toggle" type="checkbox" style="display:none" checked><div id="navbar"><ul><li class="navbar-entry"><a href="Getting Started.html">Getting Started</a></li><li class="navbar-entry"><a href="Sections.html">Sections</a></li><li class="navbar-entry"><a href="Variables.html">Variables</a></li><li class="navbar-entry"><a href="References.html">References</a></li><li class="navbar-entry"><a href="Imports.html">Imports</a></li><li class="navbar-entry"><a href="Raw.html">Raw</a></li><li class="navbar-entry"><a href="Comments.html">Comments</a></li><li><details><summary class="navbar-category">External Tools</summary><ul><li class="navbar-entry"><a href="Graphviz.html">Graphviz</a></li><li class="navbar-entry"><a href="LaTeX.html">LaTeX</a></li></ul></details></li><li><details><summary class="navbar-category">Blocks</summary><ul><li class="navbar-entry"><a href="Blockquotes.html">Blockquotes</a></li><li class="navbar-entry"><a href="Code.html">Code</a></li><li class="navbar-entry"><a href="Lists.html">Lists</a></li></ul></details></li><li><details open><summary class="navbar-category">Lua</summary><ul><li class="navbar-entry-current"><a href="Lua Basics.html">Lua</a></li></ul></details></li><li><details><summary class="navbar-category">Styles</summary><ul><li class="navbar-entry"><a href="Basic Styles.html">Basic</a></li><li class="navbar-entry"><a href="Basic Layouts.html">Layouts</a></li><li class="navbar-entry"><a href="User-Defined Styles.html">User-Defined</a></li></ul></details></li></ul></div><label for="navbar-checkbox" class="navbar-checkbox-label">&#9776;</label><div class="content"><div class="toc"><span>Table of Content</span><ol><li value="1"><a href="#Running_lua_code">Running lua code</a></li><ol><li value="1"><a href="#Lua_to_text">Lua to text</a></li><li value="2"><a href="#Parse_lua_string">Parse lua string</a></li></div><h1 id="Running_lua_code">1. Running lua code <a class="section-link" href="#Running_lua_code">🔗 </a> </h1><p>Running lua code is done using the following syntax: <a class="inline-code"><code><span style="color:#c0c5ce;">%&lt;</span><span style="color:#96b5b4;">print</span><span style="color:#c0c5ce;">(&quot;</span><span style="color:#a3be8c;">Hello World!</span><span style="color:#c0c5ce;">&quot;)&gt;%</span></code></a></p><h2 id="Lua_to_text">1.1. Lua to text <a class="section-link" href="#Lua_to_text">🔗 </a> </h2><p>To convert the return value of your lua code, append <a class="inline-code"><code><span style="color:#c0c5ce;">&quot;</span></code></a> at the start of your lua expression:</p><ul><li><a class="inline-code"><code><span style="color:#c0c5ce;">%&lt;&quot;</span><span style="color:#a3be8c;">return </span><span style="color:#c0c5ce;">&quot;Hello World&quot;</span><span style="color:#a3be8c;">&gt;%</span></code></a> → Hello World</li><li><a class="inline-code"><code><span style="color:#c0c5ce;">%&lt;&quot; &quot;Hello, &quot;</span><span style="color:#a3be8c;"> .. </span><span style="color:#c0c5ce;">&quot;World&quot;</span><span style="color:#a3be8c;">&gt;%</span></code></a> → Hello, World</li></ul><h2 id="Parse_lua_string">1.2. Parse lua string <a class="section-link" href="#Parse_lua_string">🔗 </a> </h2><p>Additionnaly, you can output lua to be parsed by the document's parser. To do so, append <a class="inline-code"><code><span style="color:#c0c5ce;">!</span></code></a> at the start of your lua expression:</p><ul><li><a class="inline-code"><code><span style="color:#c0c5ce;">%&lt;!&quot;</span><span style="color:#a3be8c;">**</span><span style="color:#c0c5ce;">&quot; .. &quot;</span><span style="color:#a3be8c;">Bold from lua?</span><span style="color:#c0c5ce;">&quot; .. &quot;</span><span style="color:#a3be8c;">**</span><span style="color:#c0c5ce;">&quot;&gt;%</span></code></a><b>Bold from lua?</b></li><li><a class="inline-code"><code><span style="color:#c0c5ce;">%&