[NTG-context] Problem with luacode

Eric Gerard eric.b.gerard at gmail.com
Tue Jan 20 20:03:33 CET 2015


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.

Can you explain if you have a bit of time the remark you made about the overload of table ?

Eric Gerard




More information about the ntg-context mailing list