ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* explain please
@ 2020-06-24 19:00 Hans van der Meer
  2020-06-24 19:10 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Hans van der Meer @ 2020-06-24 19:00 UTC (permalink / raw)
  To: NTG ConTeXt


[-- Attachment #1.1: Type: text/plain, Size: 204 bytes --]

How can the crash in the minimal example here be explained? And is there a solution to avoid this and make the crash going away "without having to jump through special hoops"?

dr. Hans van der Meer


[-- Attachment #1.2.1: Type: text/html, Size: 1309 bytes --]

[-- Attachment #1.2.2: currentdate.pdf --]
[-- Type: application/pdf, Size: 18767 bytes --]

[-- Attachment #1.2.3: Type: text/html, Size: 208 bytes --]

[-- Attachment #1.2.4: currentdate.tex --]
[-- Type: application/octet-stream, Size: 1703 bytes --]

% Interface to Lua call:
\startluacode
-- Define namespace as test
test = test or {}
test.luafunc = function (argument)
	return "RETURN: " .. argument
end
test.Upper = function(s)
	return s and string.upper(s) or ""
end
\stopluacode
\def\LuaFunc#1{\directlua{tex.print(test.luafunc("#1"))}}
\def\ChangeUpper#1{\directlua{tex.print(test.Upper("#1"))}}
\starttext
{\bf Lua and interface code:}
\starttyping
\startluacode
-- Define namespace as test
test = test or {}
test.luafunc = function (argument)
	return "RETURN: " .. argument
end
test.Upper = function(s)
	return s and string.upper(s) or ""
end
\stopluacode
\def\LuaFunc#1{\directlua{tex.print(test.luafunc("#1"))}}
\def\ChangeUpper#1{\directlua{tex.print(test.Upper("#1"))}}
\def\textex{textex}
\stoptyping
Test of various macros as input argument to Lua functions.\blank
contextversion = \contextversion\blank
\def\textex{textex}

This call didnt crash:
\type{\LuaFunc{\textex}} = \LuaFunc{\textex}\blank

This call didnt crash:
\type{\ChangeUpper{\textex}} = \ChangeUpper{\textex}\blank

This call didnt crash:
\type{\LuaFunc{\ChangeUpper{\textex}}} = \LuaFunc{\ChangeUpper{\textex}}\blank

\type{\currentdate} = \currentdate\crlf
This call didnt crash:
\type{\WORD{\currentdate}} = \WORD{\currentdate}\blank

This call crashed: \type{\LuaFunc{\currentdate}} =\crlf
%\LuaFunc{\currentdate}

This call too: \type{\expanded{\LuaFunc{\currentdate}}} =
%\expanded{\LuaFunc{\currentdate}}
\starttyping
lua error       > lua error on line 54 in file ./currentdate.tex:
token call, syntax: [ctxlua]:1: invalid escape sequence near '"\c'
\stoptyping

Why is "\currentdate" not transferred to the Lua end, even if \type{\expanded} is applied?
\stoptext


[-- Attachment #1.2.5: Type: text/html, Size: 226 bytes --]

[-- Attachment #2: 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: explain please
  2020-06-24 19:00 explain please Hans van der Meer
@ 2020-06-24 19:10 ` Hans Hagen
  2020-06-24 19:31   ` Hans van der Meer
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2020-06-24 19:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Hans van der Meer

On 6/24/2020 9:00 PM, Hans van der Meer wrote:
> How can the crash in the minimal example here be explained? And is there 
> a solution to avoid this and make the crash going away "without having 
> to jump through special hoops"?
because \currentdate is a macro thatv does some magic ... it's nor fully 
expandable

so, lua sees \currentdate == \c as first escaped character coming in and 
that's invalid (\\currentdate would work)

just try

print("\come on") in pure lua

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 / 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: explain please
  2020-06-24 19:10 ` Hans Hagen
@ 2020-06-24 19:31   ` Hans van der Meer
  0 siblings, 0 replies; 3+ messages in thread
From: Hans van der Meer @ 2020-06-24 19:31 UTC (permalink / raw)
  To: NTG ConTeXt


[-- Attachment #1.1: Type: text/plain, Size: 1059 bytes --]

\\currentdate 
Neat solution, worked without a hitch. Now I have to remember this for future use ...

dr. Hans van der Meer


> On 24 Jun 2020, at 21:10, Hans Hagen <j.hagen@xs4all.nl> wrote:
> 
> On 6/24/2020 9:00 PM, Hans van der Meer wrote:
>> How can the crash in the minimal example here be explained? And is there a solution to avoid this and make the crash going away "without having to jump through special hoops"?
> because \currentdate is a macro thatv does some magic ... it's nor fully expandable
> 
> so, lua sees \currentdate == \c as first escaped character coming in and that's invalid (\\currentdate would work)
> 
> just try
> 
> print("\come on") in pure lua
> 
> 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 #1.2: Type: text/html, Size: 3054 bytes --]

[-- Attachment #2: 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-24 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 19:00 explain please Hans van der Meer
2020-06-24 19:10 ` Hans Hagen
2020-06-24 19:31   ` Hans van der Meer

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).