|
Using StrongED with Lua By Gavin Wraith. Published: 29th Apr 2006, 23:13:56 | Permalink | PrintableWork 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.
We 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 endPlease 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
Create a new account
Forgot your password?
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
|