Drobe :: The archives
About Drobe | Contact | RSS | Twitter | Webspace | 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



Mail Merging
SHIFT-CTRL-dragging a script will alter the contents of all the StrongED windows, so this offers the ability to do alterations in bulk. Let us consider the matter of after-Christmas thank-you letters.

screen6.pngWe make the script define a template while several StrongED windows hold the separate blocks of information to be filled into the letter template. The template is a string in which certain words, prefixed by a dollar sign, denote where phrases are to be inserted. Note the double-square-bracket notation for strings, which allows newline characters inside them.

The function io.write outputs its string argument without appending newlines, as print does. The function string.gsub performs global substitutions to a string, which is used to copy the blocks of information into the template. This function returns more than one value. The extra parentheses round the argument of io.write ensures that all but the first value, which is the resultant processed string, are thrown away. The pattern "%$(%w+)" matches the words prefixed by a dollar sign and captures all but the initial dollar sign. These captures are used to index the table returned by the function dofile. This function interprets the contents of its argument as the body of a Lua function and evaluates it. So when the script is applied to the following text file...

=> {
donor = [[Aunt Agatha]];
gift = [[Yellow striped boxer shorts]];
appreciate = [[will look lovely on the clothesline]];
stroke = [[Keep on trucking.]];
}


...we get the output:

Dear Aunt Agatha
Thank you for the Yellow striped boxer shorts,
which will look lovely on the clothesline.
Keep on trucking.
Yours faithfully
Squiffy


The initial block of information is copied into the template appropriately, and a completed version is given as a result.

Back to the main article

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

+++ Message board +++

Read messages or start a new thread

Search the archives

Today's featured article

  • RiscPC breaks 1.5GHz barrier
    Calm down dear, this is a case mod
     23 comments, latest by flypig on 13/5/04 1:56PM. Published: 12 May 2004

  • Random article

  • A guide to overclocking Kinetic and StrongARM CPU cards
    Charlie Lane has compiled a package of notes and photos on overclocking various StrongARM processer cards, including Castle Kinetics, for RiscPCs. Overclocking is the process of ramping up the digital timing signals of the computer to force the processor to work faster. Charlie told us: "I thought it would be fun to investigate the possibilities of speeding up my Kinetic RiscPC - only to find suitable information on Kinetic cards was rather hard to come by so I set about working it out for myself." Note: Follow the instructions entirely at your own risk.
     9 comments, latest by rjek on 20/1/09 4:23PM. Published: 6 Jan 2009

  • Login

    Username

    Password

    Create a new account
    Forgot your password?

    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
    "..your knowledge seems to be below par"
    Page generated in 0.0229 seconds.