[NTG-context] Problem with luacode
Hans Hagen
pragma at wxs.nl
Thu Jan 22 19:51:37 CET 2015
On 1/20/2015 8:03 PM, Eric Gerard wrote:
> Hello Hans,
>
> sorry for that, here is the code I used to check some LUACODE.
>
> \definepapersize[normal][width=14.85cm, height=21cm]
>
> \setupbodyfont[10pt]
> \enableregime[il1]
> \setupcolor[xwi]
>
> \setuplayout[backspace=16mm, leftmargin=15mm,leftmargindistance=1mm,topspace=10mm,header=0mm,footer=0mm,height=200mm,rightmargin=0mm,width=131mm,location=middle,marking=on]
>
> \setuppapersize[normal][A4]
> \definelayer[OngletGauche][x=0mm, y=0mm, width=\paperwidth, height=\paperheight]
> \setupTABLE[r][1][color=dodgerblue,align={middle,lohi},height=1cm,style={\sansserif \bfx},framecolor=black]
>
> % variables
> \newdimen\hauteuronglet %height of tab
> \hauteuronglet=1cm
>
> %variables onglet bas
> \newdimen\largeurzoneongletsbas % total width available for tabs
> \newdimen\ordonneeongletsbas % vertical position of tab
> \newdimen\abscisseongletsbas % horizontal position of tab
> \newdimen\largeurongletbas % tab width
>
> \startluacode
> function test(opt_1, arg_1)
> local table = lpeg.split(",",interfaces.tolist(opt_1))
> local labels = lpeg.split(",",arg_1)
>
> local NumLigne = table[1]
> local NbTotalOnglets = table[2]
> local PremierOnglet = table[3]
>
> local decalage = tex.sp("6.5pt")
>
> print(NumLigne)
> print(NbTotalOnglets)
> print(PremierOnglet)
>
> tex.dimen.ordonneeongletsbas = tex.dimen.paperheight - tex.dimen.hauteuronglet * NumLigne
> tex.dimen.largeurzoneongletsbas = tex.dimen.paperwidth - tex.dimen.backspace
> tex.dimen.largeurongletbas = tex.dimen.largeurzoneongletsbas / NbTotalOnglets
> tex.dimen.abscisseongletsbas = tex.dimen.backspace + tex.dimen.largeurongletbas * (PremierOnglet - 1)
>
> local x_ongletsbas = tex.dimen.abscisseongletsbas - decalage
> local y_ongletsbas = tex.dimen.ordonneeongletsbas
> local largeurongletbas = tex.dimen.largeurongletbas
>
> context.setupbackgrounds({"page"},{background = "OngletBas,OngletGauche,ACouper"})
>
> context.setlayer({"OngletBas"},{hoffset = x_ongletsbas, voffset = y_ongletsbas},
> context.setupTABLE({c},{1,2,3,4,5,6},{width = largeurongletbas})
> context.bTABLE()
> context.bTR()
> context.bTD()
> context(labels[1])
> context.eTD()
> context.eTR()
> context.eTABLE()
> )
> end
> interfaces.definecommand {
> name = "test",
> arguments = {
> { "option", "hash" },
> { "content", "string" },
> },
> macro = test,
> }
> \stopluacode
>
> \starttext
> \ss
> \showframe
> \input{tufte}
> \test[1,6,1]{GROUND EGRESS}
>
> \stoptext
>
> This code is not working, I get an error while calling the function, and I don’t understand why.
\definepapersize
[normal]
[width=14.85cm,
height=21cm]
\setupbodyfont
[10pt,ss]
\setupcolor
[xwi]
\setuppapersize
[normal][A4]
\setuplayout
[backspace=16mm,
leftmargin=15mm,
leftmargindistance=1mm,
topspace=10mm,
header=0mm,
footer=0mm,
height=200mm,
rightmargin=0mm,
width=131mm,
location=middle,
marking=on]
\definelayer
[OngletGauche]
[x=0mm,
y=0mm,
width=\paperwidth,
height=\paperheight]
\definelayer
[OngletBas]
[x=0mm,
y=0mm,
width=\paperwidth,
height=\paperheight]
\setupTABLE
[r][1]
[color=dodgerblue,
align={middle,lohi},
height=1cm,
style=\bfx,
framecolor=black]
% variables
\startluacode
local decalage = string.todimen("6.5pt")
local hauteuronglet = string.todimen("1cm")
function test(opt_1,arg_1)
local options = utilities.parsers.settings_to_array(opt_1)
local labels = utilities.parsers.settings_to_array(arg_1)
local NumLigne = options[1]
local NbTotalOnglets = options[2]
local PremierOnglet = options[3]
local ordonneeongletsbas = tex.dimen.paperheight - hauteuronglet *
NumLigne
local largeurzoneongletsbas = tex.dimen.paperwidth - tex.dimen.backspace
local largeurongletbas = largeurzoneongletsbas / NbTotalOnglets
local abscisseongletsbas = tex.dimen.backspace + largeurongletbas
* (PremierOnglet - 1)
local x_ongletsbas = abscisseongletsbas - decalage
local y_ongletsbas = ordonneeongletsbas
context.setupbackgrounds({"page"},{background =
"OngletBas,OngletGauche,ACouper"})
context.setlayer(
{ "OngletBas" },
{
hoffset = number.todimen(x_ongletsbas),
voffset = number.todimen(y_ongletsbas),
},
function()
context.setupTABLE(
{ c },
{ 1, 2, 3, 4, 5, 6 },
{ width = number.todimen(largeurongletbas) }
)
context.bTABLE()
context.bTR()
context.bTD()
context(labels[1])
context.eTD()
context.eTR()
context.eTABLE()
end
)
end
interfaces.definecommand {
name = "test",
macro = test,
arguments = {
{ "option", "hash" },
{ "content", "string" },
},
}
\stopluacode
\starttext
\showframe
\input{tufte}
\test[1,6,1]{GROUND EGRESS}
\stoptext
> Can you explain if you have a bit of time the remark you made about the overload of table ?
just don't use string, table, number and other library names as variable
name
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
More information about the ntg-context
mailing list