|
Using StrongED with Lua By Gavin Wraith. Published: 29th Apr 2006, 23:13:56 | Permalink | PrintableWork that text editor hard Following 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:
#! lua
and the expression arg[1] 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.
Links
Download the scripts used in this article
Lua homepage
Programming in Lua - a good online book, 1st ed only
Lua wiki
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
Discussion Viewing threaded comments | View comments unthreaded, listed by date | Skip to the endPlease 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
Click right on with RISC OS Martin Hansen runs through a few useful desktop tricks you may not be aware of
16 comments, latest by Anon on 26/3/09 1:01PM. Published: 22 Mar 2008
Random article
Another round of Software updates We do another weekly rundown of the latest software updates
Discuss this. Published: 19 Jan 2003
Useful links
News and media:
Iconbar •
MyRISCOS •
ArcSite •
RISCOScode •
ANS •
C.S.A.Announce •
Archive •
Qercus •
RiscWorld •
Drag'n'Drop •
GAG-News
Top developers:
RISCOS Ltd •
RISC OS Open •
MW Software •
R-Comp •
Advantage Six •
VirtualAcorn
Dealers:
CJE Micros •
APDL •
Castle •
a4 •
X-Ample •
Liquid Silicon •
Webmonster
Usergroups:
WROCC •
RONE •
NKACC •
IRUG •
SASAUG •
ROUGOL •
RONWUG •
MUG •
WAUG •
GAG •
RISCOS.be
Useful:
RISCOS.org.uk •
RISCOS.org •
RISCOS.info •
Filebase •
Chris Why's Acorn/RISC OS collection •
NetSurf
Non-RISC OS:
The Register •
The Inquirer •
Apple Insider •
BBC News •
Sky News •
Google News •
xkcd •
diodesign
|