How Luan differs from Lua

This document explains how Luan differs from Lua as described in the Lua 5.3 Reference Manual.

Contents

Introduction
Basic Concepts
The Language

Introduction

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.

Basic Concepts

Values and Types

Luan does not have the Lua thread type. Luan add 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.

Luan userdata 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.

Environments

Luan has an _ENV which is like its Lua equivalent. However Luan has no global environment at all, no _G.

Every module is initialized with two local functions: require and java. The module then uses these functions to get access to whatever else it needs.

Error Handling

Luan has the functions error and pcall but does not have xpcall. Luan adds the function try which looks and acts like try-catch blocks in other languages.

Metatables and Metamethods

to document later...

Garbage Collection

Luan uses Java garbage collection. Luan has no special garbage collection methods.

Luan does not yet have weak tables but this will be added.

Coroutines

Luan does not have coroutines. Coroutines is a complex concept that isn't needed in a simple language, so it was left out.

The Language

Lexical Conventions

Unlike Lua, Luan generally considers the end of a line to be the end of a statement. This catches errors and encourages readability. The exception to this is in paranthesis ( (...), [...], and {...} ) where the end of line is treated as white space.

Luan has exactly the same set of keywords as Lua and has the same other lexical conventions.

Statements

Most statements in Luan are the same as Lua. Only those statements that differ will be listed here.

Control Structures

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 does not have a goto statement.

For 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 and 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
			

Logical Statements

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"