* [NTG-context] \luaescapestring in proper Lua
@ 2024-04-10 17:49 Pablo Rodriguez via ntg-context
2024-04-10 19:48 ` [NTG-context] " Hans Hagen via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-04-10 17:49 UTC (permalink / raw)
To: ConTeXt users; +Cc: Pablo Rodriguez
Dear list,
I have the following sample:
\starttext
\startluacode
function document.print_the_thing(str)
context(str)
end
\stopluacode
\unexpanded\def\PrintTheThing#1{%
\ctxlua{document.print_the_thing([[\luaescapestring{#1}]])}}
\PrintTheThing{a \em b {c}}
\stoptext
I wonder whether there is a proper way in the Lua code to avoid
[[\luaescapestring{}]] in \ctxlua.
BTW, [[\luaescapestring{}]] in \ctxlua works better for me, since in my
real world document, I’m using str:match() to check whether the string
ends with interrogation or exclamation marks ("%?!$").
Many thanks for your help,
Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: \luaescapestring in proper Lua
2024-04-10 17:49 [NTG-context] \luaescapestring in proper Lua Pablo Rodriguez via ntg-context
@ 2024-04-10 19:48 ` Hans Hagen via ntg-context
2024-04-11 15:07 ` Pablo Rodriguez via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen via ntg-context @ 2024-04-10 19:48 UTC (permalink / raw)
To: ntg-context; +Cc: Hans Hagen
On 4/10/2024 7:49 PM, Pablo Rodriguez via ntg-context wrote:
> Dear list,
>
> I have the following sample:
>
> \starttext
> \startluacode
> function document.print_the_thing(str)
> context(str)
> end
> \stopluacode
>
> \unexpanded\def\PrintTheThing#1{%
> \ctxlua{document.print_the_thing([[\luaescapestring{#1}]])}}
>
> \PrintTheThing{a \em b {c}}
> \stoptext
>
> I wonder whether there is a proper way in the Lua code to avoid
> [[\luaescapestring{}]] in \ctxlua.
>
> BTW, [[\luaescapestring{}]] in \ctxlua works better for me, since in my
> real world document, I’m using str:match() to check whether the string
> ends with interrogation or exclamation marks ("%?!$").
\starttext
\startluacode
function document.print_the_thing()
context(tokens.scanners.string())
end
\stopluacode
\protected\def\PrintTheThing{\ctxlua{document.print_the_thing()}}
\PrintTheThing{a \em b {\bf c} d}
\stoptext
bonus:
test!\removepunctuation ?
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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: \luaescapestring in proper Lua
2024-04-10 19:48 ` [NTG-context] " Hans Hagen via ntg-context
@ 2024-04-11 15:07 ` Pablo Rodriguez via ntg-context
2024-04-11 16:56 ` Hans Hagen via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-04-11 15:07 UTC (permalink / raw)
To: Hans Hagen via ntg-context; +Cc: Pablo Rodriguez
On 4/10/24 21:48, Hans Hagen via ntg-context wrote:
> On 4/10/2024 7:49 PM, Pablo Rodriguez via ntg-context wrote:
>> [...]
>> I wonder whether there is a proper way in the Lua code to avoid
>> [[\luaescapestring{}]] in \ctxlua.
>> [...]
> context(tokens.scanners.string())
Many thanks for your reply, Hans.
> \protected\def\PrintTheThing{\ctxlua{document.print_the_thing()}}
Sorry, but why \protected is required or recommended here?
Many thanks for your help,
Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: \luaescapestring in proper Lua
2024-04-11 15:07 ` Pablo Rodriguez via ntg-context
@ 2024-04-11 16:56 ` Hans Hagen via ntg-context
2024-04-11 17:32 ` Pablo Rodriguez via ntg-context
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen via ntg-context @ 2024-04-11 16:56 UTC (permalink / raw)
To: Pablo Rodriguez via ntg-context; +Cc: Hans Hagen
On 4/11/2024 5:07 PM, Pablo Rodriguez via ntg-context wrote:
> On 4/10/24 21:48, Hans Hagen via ntg-context wrote:
>> On 4/10/2024 7:49 PM, Pablo Rodriguez via ntg-context wrote:
>>> [...]
>>> I wonder whether there is a proper way in the Lua code to avoid
>>> [[\luaescapestring{}]] in \ctxlua.
>>> [...]
>> context(tokens.scanners.string())
>
> Many thanks for your reply, Hans.
>
>> \protected\def\PrintTheThing{\ctxlua{document.print_the_thing()}}
>
> Sorry, but why \protected is required or recommended here?
depends if you want it to be expandable
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | 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 / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* [NTG-context] Re: \luaescapestring in proper Lua
2024-04-11 16:56 ` Hans Hagen via ntg-context
@ 2024-04-11 17:32 ` Pablo Rodriguez via ntg-context
0 siblings, 0 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-04-11 17:32 UTC (permalink / raw)
To: Hans Hagen via ntg-context; +Cc: Pablo Rodriguez
On 4/11/24 18:56, Hans Hagen via ntg-context wrote:
> [...]
>>> \protected\def\PrintTheThing{\ctxlua{document.print_the_thing()}}
>>
>> Sorry, but why \protected is required or recommended here?
>
> depends if you want it to be expandable
I see now that "still.pdf" has a full chapter (#3, titled “Scanning
Input”) and page 79 explains exactly this.
Many thanks for your help,
Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-11 17:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-10 17:49 [NTG-context] \luaescapestring in proper Lua Pablo Rodriguez via ntg-context
2024-04-10 19:48 ` [NTG-context] " Hans Hagen via ntg-context
2024-04-11 15:07 ` Pablo Rodriguez via ntg-context
2024-04-11 16:56 ` Hans Hagen via ntg-context
2024-04-11 17:32 ` Pablo Rodriguez via ntg-context
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).