What Infuse Does
Syntax
Desktop Usage
It is time to make a whispered confession: the syntax of content-files is actually that of the programming language Lua. The only non-Lua aspect of them is the convention that only words sandwiched in $ symbols get to have their values appear in the merged output files. So if you know some Lua there are all sorts of cunning things that become possible. For the benefit of those who do not, we indicate one or two. Built-in values In your content-file you can use the following values:
| HERE | The directorypath of the output file |
| EXT | The extension to be carried by output files |
| THIS | The index of the current content-file |
| LIST | The list of filenames of the content-files |
("%s%s/%s"):format(HERE,LIST[THIS],EXT)
and the total number of files being processed will be given by
#LIST
Conditional definitions
You can make values conditional on the existence or nonexistence
of previously defined variables like this
$pudding$ = $Lucy$ and [[ice cream]] or [[marmalade pud]]This ensures that if $Lucy$ has been defined then $pudding$ will have the value [[ice cream]] and otherwise $pudding$ will have the value [[marmalade pud]]. Alternatively you can write
if $Lucy$ then $pudding$ = [[ice cream]] else $pudding$ = [[marmalade pud]] end -- ifThe else clause is optional. This construction lets you switch blocks of definitions on or off according to whether a variable (such as debug) has been defined previously. Comments You can put comments in a content-file, which will not affect Infuse's action. Comments begin with --[[ and end with --]]. They may contain newlines.
$greataunt$ = [[Clarissa O'Driscoll]] --[[ from County Clare of course --]]Included content You may include in a content-file the definitions of another using the function dofile. For example
local mylib = [[<MyWorkpath$>.Mylib]] dofile(mylib)or simply
dofile [[<MyWorkpath>.Mylib]]will have the effect of defining at that point all the variables defined in the file Mylib, so that they can be used subsequently in the content-file. Such inclusions can be nested, but must not be recursive. System variables You can use the values of system variables. For example, to get the time, date and year you can include:
local getenv in os $time$ = getenv [[Sys$Time]] $date$ = getenv [[Sys$Date]] $year$ = getenv [[Sys$Year]]Then, using these variables in the container, you get an automatic time stamp of when the output was created. We meet one syntactic novelty here, which is not actually part of standard Lua. The phrase
local getenv in os
is equivalent to
local getenv = os.getenv
The function getenv is a member of the library
os, built in to standard Lua. It evaluates system variables
(other people call them environment variables).
Using tables
The use of tables is potentially a very powerful feature.
This manual is not a textbook on Lua, so we can only hint at some
possibilities here.
Can you guess what the following does?
if THIS == 1 then oo = {} end -- if
local link = [[<a href="%s.%s">%s</a><br>]]
local name = LIST[THIS]
if not (name:sub(1,1) == "/") then
oo[1+#oo] = link:format(name,EXT,name)
end -- if
$navlinks$ = THIS == #LIST and table.concat(oo) or [[]]