We present four ways of running Lua programs.
Just like Basic, Lua can be used in immediate mode for simple
calculations. Open a taskwindow by pressing CTRL-F12. The command
lua at the * prompt will give
*lua
Lua 5.1.3 Copyright (C) 1994-2006 Lua.org, PUC-Rio
>
The
> prompt shows that Lua is expecting input.
> print (0x50)
80
We have entered a statement to output the value of the expression 0x50.
The prefix 0x is used to indicate hexadecimal notation for numbers.
The equivalent Basic is
*Basic
ARM BBC BASIC V version 1.37 (C) Acorn 1989
Starting with 651516 bytes free
>PRINT &50
80
Whereas Basic uses upper case letters for built-in words, Lua
tends to use lowercase, or uppercase words preceded by an underscore.
Note that, in Lua, number arguments to
print must be in parentheses. In Basic's immediate mode you must enter a complete
statement on a single line. In Lua's immediate mode if you enter
an incomplete statement the prompt will change to
>> , to remind you that more is needed.
> print (
>> 0x50)
80
You can alter Lua's prompt to suit your own tastes:
> _PROMPT = "ok then:"
ok then:
The default value of the variable _PROMPT is ">". You can alter the second prompt too:
ok then: _PROMPT2 = "finished?"
ok then: print (
finished? 0x50)
80
We have not made very explicit what we mean by an incomplete statement.
Indeed, we have not defined what a statement is yet.
To run a Lua (or Basic) program, write it in an editor, save it with
filetype Lua (Basic), and doubleclick on its icon.

To run a Lua (Basic) file in a taskwindow, which is often more
convenient, you can use
!TaskW. First run the !TaskW application, so that its running man icon
appears on the iconbar, and then drag the Lua (Basic) program's icon
onto the running man. Output from the program will now appear in a
taskwindow, from where you can save it if necessary.
If you have version 4.67 of StrongED or higher there is a way of
running certain kinds of Lua programs that you may find particularly
convenient. You may need first to check your version of StrongED.
If your version is 4.68xx look at the file
!StrongED.Defaults.Tools.!ScriptSED.Tools.Despatch
by SHIFT-doubleclicking its icon. About 16 lines down there
should be a section commented as
| Set script language if it's a known filetype
The section should contain the line
If "<StrongED$Script_Filetype>" = "18C" Then
Set StrongED$Script_Language "lua"
If it does not, add this line, with no line breaks, into
the section and resave the file.
In the directory
!StrongED.Defaults.Tools.!ScriptSED.Languages
there should be an Obey file called
lua . If not, create one, containing the single line
do lua <StrongED$Script_Script>
<StrongED$Script_Infile> >
<StrongED$Script_Outfile>
If your version of StrongED is 4.67xx look at the Obey file
!StrongED.Defaults.Tools.DoScript . This also should contain
the line
If "<StrongED$Script_Filetype>" = "18C" Then
Set StrongED$Script_Language "lua"
in the section
| Set script language if it's a known filetype
Again if it does not, add it in, with no line breaks in it.
Further down, in the section
| Now run the script using the correct syntax
for the language specified
there should be a line, with no line breaks,
If "<StrongED$Script_Language>" = "lua" Then
lua <StrongED$Script_Script>
<StrongED$Script_Infile> >
<StrongED$Script_Outfile>
Again, add it in with no line breaks, if it is not there.
Note the apply icon among the smarticons along the top of a
StrongED window.

Once !lua has been booted you can make a Lua program
manipulate text in a StrongED window. You can do this either by
shift-dragging or by control-dragging the icon of the file containing
the program onto the apply icon. Shift dragging replaces the contents
of the window with the output of the Lua program (so that the original
content is lost - it can be recovered using the Undo button).
Control-dragging opens a new StrongED window into which the output
goes. Shift-control-dragging will cause the Lua program to operate on
all the currently open StrongED windows, replacing each by its output -
useful for mailmerging. For these things to work the Lua program must
either be in a file of type Lua or have
#! lua
as its first line. The program must be written to take its input from
the file named in the expression
arg[1] and must write to the
standard output (as the
print command does).
Here, for example, is a program to strip out all lines containing
the word
sport :
#! lua
for line in io.lines(arg[1]) do
if not line:match "sport" then
print(line)
end -- if
end -- for
Look up
io.lines and
string.match in the reference manual.
Obey files are RISC OS's way of running any sort of program that takes
command line arguments (TaskObey files if you want it to run in a
taskwindow). Applications use their specially named !Run files for this
purpose. Once !lua has been filerbooted the command needed to run a
Lua program to act on, say a text file, is
*lua <progpathname> <textfilepathname>
Some of the example programs we will be looking at will be in the form
needed for using with StrongED 4.67. If you do not have StrongED then
you will need to make a TaskObey file instead, with the appropriate
command. Running the program then amounts to doubleclicking the
TaskObey file. The output will appear in a taskwindow instead of in a
StrongED window. So long as the output does not involve control
characters, the results should look the same.