From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Fabrice Couvreur <fabrice1.couvreur@gmail.com>
Subject: Re: Lua code and table
Date: Fri, 19 Feb 2021 13:06:26 +0100 [thread overview]
Message-ID: <b5db45f3-8400-261d-e460-28121c78c2d1@xs4all.nl> (raw)
In-Reply-To: <CACyK-eoYtk_skM68YeQ5i4q7wJ0P2Rpd76+eSjc1=J6SnDSV3A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 669 bytes --]
On 2/19/2021 12:42 PM, Fabrice Couvreur wrote:
> Hi Hans,Thanks again for the ideas to improve my code. However, I am new
> to Lua and my level is far from sufficient to understand everything. Why
> in no table do the crosses appear in the cells; which was my original
> idea.Thank you.Fabrice
I get a cross (see attached).
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
[-- Attachment #2: xx.tex --]
[-- Type: text/plain, Size: 3559 bytes --]
\setupbodyfont[pagella]
\starttext
\definextable
[MyTable]
[align={middle,lohi},
width=0.8cm,
offset=0.8ex,
bodyfont=9pt,
framecolor=cyan]
\startluacode
function document.MyTable(specification)
local pattern = specification.pattern
local action = specification.action
local conversion = specification.conversion or "Characters"
local n = #pattern
-- context.startxtable { align = "middle,lohi", width = "0.8cm", offset = "0.8ex", bodyfont = "9pt", framecolor = "cyan" }
context.startxtable { "MyTable" }
context.startxrow()
context.startxcell { frame = "off" }
context()
context.stopxcell()
for i=1,n do
context.startxcell()
context.convertnumber(conversion,i)
context.stopxcell()
end
context.stopxrow()
for i=1,n do
context.startxrow()
context.startxcell()
context.convertnumber(conversion,i)
context.stopxcell()
for j=1,n do
context.startxcell { align = "middle" }
action(string.sub(pattern[i],j,j))
context.stopxcell()
end
context.stopxrow()
end
context.stopxtable()
end
\stopluacode
\startuniqueMPgraphic{cross}{width,height,depth,color,line}
draw image (
draw (\MPvar{depth},\MPvar{height}) -- (\MPvar{width},0) ;
draw (\MPvar{depth},0) -- (\MPvar{width},\MPvar{height}) ;
)
withpen pencircle scaled \MPvar{line}
withcolor \MPvar{color} ;
\stopuniqueMPgraphic
\definesymbol
[MyRedCross]
[\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=red,line=.2ex}]
\definesymbol
[MyGreenCross]
[\uniqueMPgraphic{cross}{width=1em,height=1ex,depth=.5ex,color=green,line=.2ex}]
\startluacode
document.MyTable {
action = function(value)
context(value == "X" and 1 or 0)
end,
conversion = "Characters",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX...."
}
}
\stopluacode
\startluacode
document.MyTable {
action = function(value)
context(value == "X" and 1 or 0)
end,
conversion = "Greek",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
}
}
\stopluacode
\startluacode
document.MyTable {
action = function(value)
if value == "X" then
context.symbol { "MyRedCross" }
end
end,
conversion = "Romannumerals",
pattern = {
".XXX..XX",
"X...XXX.",
"X..X.XXX",
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX...."
}
}
\stopluacode
\startluacode
document.MyTable {
action = function(value)
context.symbol { value == "X" and "MyRedCross" or "MyGreenCross" }
end,
conversion = "Romannumerals",
pattern = {
"X.X.X..X",
".X.X.XX.",
".XX.X...",
"XXX.X...",
"X.XX...."
}
}
\stopluacode
\stoptext
[-- Attachment #3: xx.pdf --]
[-- Type: application/pdf, Size: 12946 bytes --]
[-- Attachment #4: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2021-02-19 12:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-17 17:40 Fabrice Couvreur
2021-02-17 21:13 ` Tomas Hala
2021-02-17 21:26 ` Wolfgang Schuster
2021-02-17 22:52 ` Hans Hagen
2021-02-17 23:22 ` Bruce Horrocks
2021-02-18 9:06 ` Hans Hagen
2021-02-18 15:14 ` Fabrice Couvreur
2021-02-18 15:26 ` Jano Kula
2021-02-18 15:28 ` Fabrice Couvreur
2021-02-19 11:42 ` Fabrice Couvreur
2021-02-19 12:06 ` Hans Hagen [this message]
2021-02-19 13:12 ` Jano Kula
2021-02-19 13:26 ` Hans Hagen
2021-02-20 17:21 ` Fabrice Couvreur
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=b5db45f3-8400-261d-e460-28121c78c2d1@xs4all.nl \
--to=j.hagen@xs4all.nl \
--cc=fabrice1.couvreur@gmail.com \
--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).