Tutorial Examples

lua-users home
wiki

Lua command line

If we run the Lua executable without parameters we get the following message and a > command prompt.

Lua 5.0  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
>

All of the examples in the tutorial are typed at the command prompt > and the output copied and pasted into the wiki.

> print("hello Lua user")
hello Lua user
> print(10*10)
100

If a line begins with an = Lua evaluates the line as an expression. Its shorthand for having to use the print() function.

> = "hello Lua user"
hello Lua user
> = 10*10
100

Multiline entry

We can enter commands over multiple lines if necessary. Lua will try and evaluate what you typed on a given line and assess whether the command is complete. If it is not considered complete a double command prompt appears >> so you can continue typing. E.g.,

> print(
>>  "Hello lua user"
>> )
Hello lua user
In the above example the print( statement is incomplete as the matching closing bracket is missing. The Lua command line assumes that you have more to type so the >> prompt is displayed. This continues until the statement is deemed complete. If you made a mistake you will get an error. This also works for the evaluation shorthand:
> = 10 *
>> 10 +
>> 5
105

Comments

Where you see "--", followed by text, this is a comment. Everything after the -- is ignored by the Lua compiler on that line.

> = 1+1  -- this is ignored
2
> = 1+1     no comment
stdin:1: <eof> expected near `no'

Note: You do not have to type the comments in! They are just comments about what is happening for clarity.


FindPage · RecentChanges · preferences
edit · history
Last edited October 2, 2007 4:35 pm GMT (diff)