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.
Luan is implemented in Java and is tightly integrated with Java. This makes it an excellent scripting language for Java.
Luan does not have the Lua thread type. Luan adds a binary type that Lua doesn't have. This is because Lua strings can represent binary while Luan strings cannot.
The Luan Nil type is implemented as the Java null. The Luan Boolean type is implemented as the Java Boolean type. The Luan Number type is implemented as the Java Number type. The Luan String type is implemented as the Java String type. Actual numbers may be any subclass of the Java Number class.
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.
The Luan java type is a replacement for Lua's userdata. A Luan java value is nothing more than a Java object that doesn't fall into one of the other recognized types.
The Luan binary type is the Java byte[ ] type which is an array of bytes.
The Luan table type is just like its Lua equivalent, but implemented in Java.
Luan has no global environment at all, no
_G. By default, Luan doesn't define
_ENV either, but if you define it as a local table in a chunk, then it acts like it does in Lua. When
_ENV isn't defined, there are no global variables and an unrecognized variable name produces a compile error.
Every module is initialized with one local function:
require. The module then uses this function to get access to whatever else it needs.
Luan has the function
error but does not have
xpcall. Luan adds the try statement instead. Luan errors are implemented as an error table, not as a message object.
Luan only has metatable for tables, not for other types.
Luan does not support the call metamethod. There is nothing that one can do with the call metamethod that can't be done more cleanly with closures, so this was left out.
Luan uses Java garbage collection. Luan has no special garbage collection methods.
Luan does not yet have weak tables but this will be added.
Luan does not have coroutines. Coroutines is a complex concept that isn't needed in a simple language, so it was left out.
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.
Luan has a similar set of keywords to Lua and has the same other lexical conventions.
By default, there are no global variables and an undefined variable produces a compile error. To enable global variables, one must define
_ENV. Avoiding global variables makes it much easier to catch errors at compile time.
Luan adds the block terminators end_do, end_for, end_function, end_if, end_try, and end_while. These can be used to end the appropriate block type, but end can also be used to end any block.
Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.
The Luan if, while, and repeat 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.
Luan adds the continue statement which is used inside loops.
Luan does not have a goto statement.
Luan has no numeric for statement. Luan only has generic for statement. Instead of the numeric for statement, Luan uses the
range function in a generic for statement like this:
for i in range(from,to,step) do block end
The Luan generic for statement is simpler than the Lua version because Luan only uses an expression, not an explist. So a for statement like:
for var_1, ···, var_n in exp do block end
is equivalent to the code:
do local f = exp while true do local var_1, ···, var_n = f() if var_1 == nil then break end block end end
Unlike Lua, Luan has a try statement. See Try Statement in the Luan Reference Manual. This also eliminates the need for Lua's pcall function which Luan doesn't have.
Unlike Lua, Luan allows or and and expressions to be stand-alone statements. This is useful in cases like this:
x==5 or error "x should be 5"
Template statements are a Luan addition that don't exist in Lua. See Template Statements in the Luan Reference Manual.
Unlike Lua, Luan does not do automatic conversions of strings to numbers.
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.
The only change in Luan is that not must take a boolean argument. This helps catch errors and makes code more readable.
Unlike Lua, Luan converts all concatenation operands to strings.
Unlike Lua, Luan considers an end_of_line to be a field separator in a table constructor.
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.
Luan does not support Lua's
v:name(args) style object-oriented function call. Object oriented programming is done in Luan using closures, so this feature is not needed.
Luan doesn't support proper tail calls. Because Java doesn't support this cleanly, this was left out.
Backtick expressions are a Luan addition that don't exist in Lua. See Backticks in the Luan Reference Manual.