Drobe :: The archives
About Drobe | Contact | RSS | Twitter | Tech docs | Downloads | BBC Micro

Using StrongED with Lua

By Gavin Wraith. Published: 29th Apr 2006, 23:13:56 | Permalink | Printable

Work that text editor hard

Lua logoFollowing 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.

Apply iconThis '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.


sdir.gif 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 unthreaded comments | View comments threaded by reply | Skip to the end

Nice, informative article.

Incidentally, Cretin also supports lua scripts (implemented by the brothers Sidwell back before I got hold of it), so this article may also be useful to those who wish to tinker there, too.

 is a RISC OS Userjymbob on 30/4/06 9:40AM
[ Reply | Permalink | Report ]

Indeed an intersting article!

What kind of irritates me is the list of "Related articles:" since the only real relation between the ones listed and this one is that they appeared on Drobe.

 is a RISC OS Userhzn on 30/4/06 10:07AM
[ Reply | Permalink | Report ]

Maybe the programmers do link "Related articles" to this one, considering that they use a Mouse and maybe Central Heating during the winter months of the long hours of their work? ;-)

(Just kidding here).

Steve.

 is a RISC OS UserSawadee on 30/4/06 11:25AM
[ Reply | Permalink | Report ]

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

  • Jan Vibe: The interview
    The man, the myth, the BASIC graphics master
     9 comments, latest by harmsy on 17/8/07 3:50PM. Published: 11 Aug 2007

  • Random article

  • BARUG meeting postponed to October

     Discuss this. Published: 22 Sep 2000

  • Useful links

    News and media:
    IconbarMyRISCOSArcSiteRISCOScodeANSC.S.A.AnnounceArchiveQercusRiscWorldDrag'n'DropGAG-News

    Top developers:
    RISCOS LtdRISC OS OpenMW SoftwareR-CompAdvantage SixVirtualAcorn

    Dealers:
    CJE MicrosAPDLCastlea4X-AmpleLiquid SiliconWebmonster

    Usergroups:
    WROCCRONENKACCIRUGSASAUGROUGOLRONWUGMUGWAUGGAGRISCOS.be

    Useful:
    RISCOS.org.ukRISCOS.orgRISCOS.infoFilebaseChris Why's Acorn/RISC OS collectionNetSurf

    Non-RISC OS:
    The RegisterThe InquirerApple InsiderBBC NewsSky NewsGoogle Newsxkcddiodesign


    © 1999-2009 The Drobe Team. Some rights reserved, click here for more information
    Powered by MiniDrobeCMS, based on J4U | Statistics
    "D underheads R adicals O r B loody E xcentrics"
    Page generated in 0.3824 seconds.