Home  Contents

Platform

Core4 Lua

INTRODUCTION

Lua is a scripting language developped at the University of Rio de Janeiro (PUC-Rio). From the homepage (www.lua.org):

Lua is a powerful, fast, light-weight, embeddable scripting language.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

Included here is a quick reference of the basic Lua commands from Lua 5.1.4 and also a reference of all additions made to Lua for use with Core4.

More information about Lua can be found at www.lua.org.

Also, there are two official books:

Lua 5.1 Reference Manual
by R. Ierusalimschy, L. H. de Figueiredo, W. Celes
Lua.org, August 2006
ISBN 85-903798-3-3

Programming in Lua (second edition)
by Roberto Ierusalimschy
Lua.org, March 2006
ISBN 85-903798-2-5

DEVIATIONS

A few changes have been made to adapt Lua to the specific requirements of embedded systems.

Most of these changes where taken from the lua-users wiki at http://lua-users.org/wiki/LuaPowerPatches.

  • Native number format is 32-bit signed integer.

    Originally, Lua uses 64-bit floating point numbers. Most Core4 systems do not have a FPU, so the number format was changed.

  • Numbers can be specified in hexadecimal using 0xNN or binary using 0yBB....BB.
  • Inside strings, a byte can be specified by hexadecimal code using \xNN, and a UTF-8 encoded character can be given with it's 16-bit unicode codepoint using \uNNNN.
  • Fix: Null bytes inside a string are printed properly with the print command.
  • echo command, works like print, but adds no TAB or newline characters.
  • Multiple string literals are automatically concatenated at compile time into a single string:

    a = "Hello" "World"
    is the same as
    a = "HelloWorld"
  • Bitwise operators have been added:

    Operator Event Description
    & __and Bitwise AND
    | __or Bitwise OR
    ^^ __xor Bitwise XOR
    << __shl Shift left
    >> __shr Shift right
    ~ __not Bitwise negation

    'Event' indicates the event name to be used for overloading within a metatable.

  • The function string.char() will happily accept values outside the range of 0...255. All values are implicitly truncated to eight bits.