From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Problem with luacode
Date: Thu, 22 Jan 2015 19:51:37 +0100 [thread overview]
Message-ID: <54C146B9.4070408@wxs.nl> (raw)
In-Reply-To: <A6098789-7340-4195-B96E-C6C899150425@gmail.com>
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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
prev parent reply other threads:[~2015-01-22 18:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 19:03 Eric Gerard
2015-01-22 18:51 ` Hans Hagen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54C146B9.4070408@wxs.nl \
--to=pragma@wxs.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).