comparison website/src/tutorial.html.luan @ 1827:50e570b598b2

security
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 15 Sep 2024 10:36:46 -0600
parents f44dcb3fedf7
children
comparison
equal deleted inserted replaced
1826:3cd1d267508c 1827:50e570b598b2
31 &lt;% 31 &lt;%
32 </code> 32 </code>
33 33
34 <p>To run this, type <b>luan hello.luan</b> on the command line. This should print <b>Hello World</b>.</p> 34 <p>To run this, type <b>luan hello.luan</b> on the command line. This should print <b>Hello World</b>.</p>
35 35
36 <p>The syntax here is based on <a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a>. Let's change it a little:</p> 36 <p>The syntax here is based on <a href="https://en.wikipedia.org/wiki/Jakarta_Server_Pages">JSP</a>. Let's change it a little:</p>
37 37
38 <code block> 38 <code block>
39 local name = "Bob" 39 local name = "Bob"
40 %&gt; 40 %&gt;
41 Hello &lt;%= name %&gt; 41 Hello &lt;%= name %&gt;
51 print("Hello World") 51 print("Hello World")
52 </code> 52 </code>
53 53
54 <p>In Luan, a function call with one string argument doesn't require parenthesis, so <b>print("Hello World")</b> is the same as <b>print "Hello World"</b> and <b>require "luan:Io.luan"</b> is the same as <b>require("luan:Io.luan")</b>. Both <b>require</b> and <b>print</b> are functions.</p> 54 <p>In Luan, a function call with one string argument doesn't require parenthesis, so <b>print("Hello World")</b> is the same as <b>print "Hello World"</b> and <b>require "luan:Io.luan"</b> is the same as <b>require("luan:Io.luan")</b>. Both <b>require</b> and <b>print</b> are functions.</p>
55 55
56 <p>The <b>require</b> function takes a <a href="http://en.wikipedia.org/wiki/Uniform_resource_identifier">URI</a> as an argument. Examples of URIs are "<b>luan:Io.luan</b>" and "<b>file:hello.luan</b>". <b>require</b> is used to import a module, which is returned from the <b>require</b> function call. In the case above, we assign the module to the local variable <b>Io</b>. The function <b>print</b> is a member of this module. We could have done <b>Io.print("Hello World")</b> but instead we chose to assign <b>print</b> to a local variable and use that to call the function.</p> 56 <p>The <b>require</b> function takes a <a href="https://en.wikipedia.org/wiki/Uniform_Resource_Identifier">URI</a> as an argument. Examples of URIs are "<b>luan:Io.luan</b>" and "<b>file:hello.luan</b>". <b>require</b> is used to import a module, which is returned from the <b>require</b> function call. In the case above, we assign the module to the local variable <b>Io</b>. The function <b>print</b> is a member of this module. We could have done <b>Io.print("Hello World")</b> but instead we chose to assign <b>print</b> to a local variable and use that to call the function.</p>
57 57
58 <p>Luan starts with only one defined function: <b>require</b>. You will use <b>require</b> to import whatever you need. This is a little more work, but makes it clear in each file where each function comes from.</p> 58 <p>Luan starts with only one defined function: <b>require</b>. You will use <b>require</b> to import whatever you need. This is a little more work, but makes it clear in each file where each function comes from.</p>
59 59
60 <p>Let's a make fancier version:</p> 60 <p>Let's a make fancier version:</p>
61 61