Mercurial Hosting > luan
view website/src/diff.html.luan @ 1826:3cd1d267508c default tip
mikraite links
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 24 Aug 2024 21:36:47 -0600 |
parents | 0ead5c6b07b0 |
children |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local Shared = require "site:/lib/Shared.luan" local head = Shared.head or error() local docs_header = Shared.docs_header or error() local show_toc = Shared.show_toc or error() local show_content = Shared.show_content or error() local content = { intro = { title = "Introduction" content = function() %> <p>Lua is one of the simplest languages available, but Luan is even simpler. This means Luan removes more than it adds. Most of what is added is added in the library, not in the language itself.</p> <p>Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.</p> <% end } basic = { title = "Basic Concepts" subs = { types = { title = "Values and Types" content = function() %> <p>Luan adds a <em>binary</em> type that Lua doesn't have. This is because Lua strings can represent binary while Luan strings cannot.</p> <p>The Luan <em>Nil</em> type is implemented as the Java <em>null</em>. The Luan <em>Boolean</em> type is implemented as the Java <em>Boolean</em> type. The Luan <em>Number</em> type is implemented as the Java <em>Number</em> type. The Luan <em>String</em> type is implemented as the Java <em>String</em> type. Actual numbers may be any subclass of the Java <em>Number</em> class.</p> <p>Luan functions may be written in Luan or may be wrappers around native Java methods. Any Java method may be called as a Luan function.</p> <p>The Luan <em>java</em> type is a replacement for Lua's <em>userdata</em>. A Luan <em>java</em> value is nothing more than a Java object that doesn't fall into one of the other recognized types.</p> <p>The Luan <em>binary</em> type is the Java <em>byte[ ]</em> type which is an array of bytes.</p> <p>The Luan <em>table</em> type is just like its Lua equivalent, but implemented in Java.</p> <p>Luan does not have the Lua <em>thread</em> type which aren't actually threads but in fact are coroutines. Luan has real threads. This is particularly valuable for web serving where each request is handled by a thread. But thread synchronization is too complicated for application programmers. So Luan makes mutable objects immutable when they become accessible by multiple threads. This eliminates the need for thread synchronization. If there is a need to share mutable state across threads, there are special functions for this.</p> <% end } env = { title = "Environments" content = function() %> <p>Luan has no global environment at all, no <code>_G</code>. By default, Luan doesn't define <code>_ENV</code> either, but if you define it as a local table in a chunk, then it acts like it does in Lua. When <code>_ENV</code> isn't defined, there are no global variables and an unrecognized variable name produces a compile error.</p> <p>Every module is initialized with one local function: <code>require</code>. The module then uses this function to get access to whatever else it needs.</p> <% end } error = { title = "Error Handling" content = function() %> <p>Luan has the function <code>error</code> but does not have <code>pcall</code> or <code>xpcall</code>. Luan adds the <a href="#try">try statement</a> instead. Luan errors are implemented as an error table, not as a message object.</p> <% end } meta = { title = "Metatables and Metamethods" content = function() %> <p>Luan only has metatable for tables, not for other types.</p> <p>Luan does not support the <b>call</b> metamethod. There is nothing that one can do with the <b>call</b> metamethod that can't be done more cleanly with closures, so this was left out.</p> <% end } gc = { title = "Garbage Collection" content = function() %> <p>Luan uses Java garbage collection. Luan has no special garbage collection methods.</p> <p>Luan does not yet have weak tables but this will be added.</p> <% end } coroutines = { title = "Coroutines" content = function() %> <p>Luan does not have coroutines. Coroutines is a complex concept that isn't needed in a simple language, so it was left out.</p> <% end } } } lang = { title = "The Language" subs = { lex = { title = "Lexical Conventions" content = function() %> <p>Unlike Lua, Luan considers the end of a line to be the end of a statement. This catches errors and encourages readability. If you want to continue a statement on another line, you can use a backslash followed by a newline which will be treated as white space.</p> <p>Luan has a similar set of keywords to Lua and has the same other lexical conventions.</p> <% end } vars = { title = "Variables" content = function() %> <p>By default, there are no global variables and an undefined variable produces a compile error. To enable global variables, one must define <code>_ENV</code>. Avoiding global variables makes it much easier to catch errors at compile time.</p> <% end } stmt = { title = "Statements" content = function() %> <p>Luan adds the block terminators <b>end_do</b>, <b>end_for</b>, <b>end_function</b>, <b>end_if</b>, <b>end_try</b>, and <b>end_while</b>. These can be used to end the appropriate block type, but <b>end</b> can also be used to end any block.</p> <p>Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.</p> <% end subs = { control = { title = "Control Structures" content = function() %> <p>The Luan <b>if</b>, <b>while</b>, and <b>repeat</b> statement are the same as in Lua except that the condition expression must return a boolean value. Any other value type will produce an error. This helps catch errors and makes code more readable.</p> <p>Luan adds the <b>continue</b> statement which is used inside loops.</p> <p>Luan does not have a <b>goto</b> statement.</p> <% end } ["for"] = { title = "For Statement" content = function() %> <p>Luan has no numeric <b>for</b> statement. Luan only has generic <b>for</b> statement. Instead of the numeric <b>for</b> statement, Luan uses the <code>range</code> function in a generic <b>for</b> statement like this:</p> <code block> for i in range(from,to,step) do <em>block</em> end </code> <p>The Luan generic <b>for</b> statement is simpler than the Lua version because Luan only uses an expression, not an explist. So a <b>for</b> statement like:</p> <code block> for var_1, ···, var_n in exp do block end </code> <p>is equivalent to the code:</p> <code block> do local f = exp while true do local var_1, ···, var_n = f() if var_1 == nil then break end block end end </code> <% end } ["try"] = { title = "Try Statement" content = function() %> <p>Unlike Lua, Luan has a <b>try</b> statement. See <a href="manual.html#try">Try Statement</a> in the Luan Reference Manual. This also eliminates the need for Lua's <b>pcall</b> function which Luan doesn't have.</p> <% end } logical = { title = "Logical Statements" content = function() %> <p>Unlike Lua, Luan allows <b>or</b> and <b>and</b> expressions to be stand-alone statements. This is useful in cases like this:</p> <code block> x==5 or error "x should be 5" </code> <% end } template_stmt = { title = "Template Statements" content = function() %> <p>Template statements are a Luan addition that don't exist in Lua. See <a href="manual.html#template_stmt">Template Statements</a> in the Luan Reference Manual.</p> <% end } } } expr = { title = "Expressions" subs = { conversions = { title = "Coercions and Conversions" content = function() %> <p>Unlike Lua, Luan does not do automatic conversions of strings to numbers.</p> <% end } bit = { title = "Bitwise Operators" content = function() %> <p>Bitwise operators appear to be a new addition to Lua 5.3 and didn't exist in Lua 5.2. Luan does not support bitwise operators, but these can be added if there is a need.</p> <% end } logical_ops = { title = "Logical Operators" content = function() %> <p>The only change in Luan is that <b>not</b> must take a boolean argument. This helps catch errors and makes code more readable.</p> <% end } concatenation = { title = "Concatenation" content = function() %> <p>Unlike Lua, Luan converts all concatenation operands to strings.</p> <% end } constructors = { title = "Table Constructors" content = function() %> <p>Unlike Lua, Luan considers an <b>end_of_line</b> to be a field separator in a table constructor.</p> <% end } fn_calls = { title = "Function Calls" content = function() %> <p>Unlike Lua, Luan does not allow extra non-nil arguments to be passed to a function. In Luan, this causes an error. This change helps find coding mistakes that would be very hard to detect otherwise.</p> <p>Luan does not support Lua's <code>v:name(args)</code> style object-oriented function call. Object oriented programming is done in Luan using closures, so this feature is not needed.</p> <p>Luan doesn't support <em>proper tail calls</em>. Because Java doesn't support this cleanly, this was left out.</p> <% end } backticks = { title = "Backticks" content = function() %> <p>Backtick expressions are a Luan addition that don't exist in Lua. See <a href="manual.html#backticks">Backticks</a> in the Luan Reference Manual.</p> <% end } } } } } } return function() Io.stdout = Http.response.text_writer() %> <!doctype html> <html> <head> <% head() %> <title>How Luan differs from Lua</title> </head> <body> <% docs_header() %> <div content> <h1><a href="diff.html">How Luan differs from Lua</a></h1> <p>This document explains how Luan differs from <a href="http://www.lua.org">Lua</a> as described in the <a href="http://www.lua.org/manual/5.3/">Lua 5.3 Reference Manual</a>.</p> <hr> <h2>Contents</h2> <div toc> <% show_toc(content) %> </div> <hr> <% show_content(content,2) %> </div> </body> </html> <% end