Using StrongED with LuaBy Gavin Wraith. Published: 29th Apr 2006, 23:13:56 | Permalink | Printable
Work that text editor hardFollowing the addition of Lua scripting support to top text and source code editor StrongED, Gavin Wraith outlines a gentle introduction to Lua scripting. The programs described below show what is possible with the language and how it can be used to manipulate your documents and search for text. Gavin maintains the RISC OS port of the Lua interpreter.
Lua is an easy to grasp programming language that is interpreted, like BASIC, and is similar to Python. It's used in various projects and applications, including video games and specialist jobs. You will need at least StrongED 4.67b3 and RiscLua 3.41 for the simple exercises in this article. Below are some notes on how to get started with StrongED and Lua scripts, and links to the tutorials. Click on a thumbnail image to see the full illustration.
This 'smarticon' on the StrongED toolbar I call the apply icon. It can be used for applying the outcome of a script to the contents of the StrongED window containing the icon.
SHIFT-dragging a script onto it will alter the window's contents.CTRL-dragging a script onto it will create a new window containing the altered text.SHIFT-CTRL-dragging will apply the script to all the StrongED windows.Clicking on it will open the directory designated by the system variable StrongED$ScriptsDir or give an error if this system variable has not been set. The idea is that you can use this to have a special directory for
keeping your scripts in. I set it by adding a suitable line to the Obey file !StrED_cfg.UserPrefs.init.
I have three subdirectories for three of the languages, Awk, Basic and Lua, for which StrongED caters by default. Python, Forth, Perl and Sed are others; you can, of course, add your own if you know your way around StrongED. My desktop furniture and StrongED toolbar icons may be different, or differently placed, from yours. Bear in mind that script is just a fancy word for program.
In this article I will only use Lua, as that is the language with which I have had most practice. The only special requirement for using Lua with StrongED is that the script must begin with the line:
and the expression arg denotes a temporary file containing the text of the StrongED window for the script to process. The replacement text is given by the standard output of the script, as produced, for example, by the function print - StrongED catches this output and applies it to the documents affected by the script. Here are some examples:
• The second edition of Programming in Lua is out, and RISC OS gets a specific mention in the portability section of the introduction.
Download the scripts used in this article
Programming in Lua - a good online book, 1st ed only
Post any feedback below for Gavin to address, or suggest future related article ideas
Previous: Dispute over 'intrusive' VRPC copy protection
Next: R-Comp responds to Grapevine feedback
DiscussionViewing threaded comments | View comments unthreaded, listed by date | Skip to the end
Please login before posting a comment. Use the form on the right to do so or create a free account.
Search the archives
Today's featured article
RISCDomain magazine reviewed
A media watch special
9 comments, latest by druck on 30/10/07 8:55AM. Published: 20 Oct 2007
BETT you've been wanting to hear this
Lucky old iconbar.com gets a BETT article so we'll say a few words about RISC OS
Discuss this. Published: 24 Jan 2002
News and media:
RISCOS Ltd •
RISC OS Open •
MW Software •
Advantage Six •
CJE Micros •
Liquid Silicon •
Chris Why's Acorn/RISC OS collection •
The Register •
The Inquirer •
Apple Insider •
BBC News •
Sky News •
Google News •