On Mon, Oct 14, 2019 at 07:19:53PM +0200, Hans Hagen wrote:
> On 10/14/2019 6:50 PM, Rudolf Bahr wrote:
 
> > THis MWE must be faulty, but where is the error?
> > 
> > ====================================================
> > 
> > \startluacode
> > 
> > userdata = userdata or {}
> > 
> > function userdata.file_exists (name)
> > 
> >     local name = name
> >     local f    = assert ( io.open ( name, "r" ))
> > 
> >     if f then
> >        f:close ()
> >        context ( name )
> >        context ( "  exists!" )
> >     else
> >        context ( name )
> >        context ( "  doesn't exist!" )
> >     end
> > end
> > 
> > \stopluacode
> > 
> > 
> > \starttext
> > 
> > \def\lookupfile#1%
> >     {\ctxlua{userdata.file_exists([==[#1]==])}}
> > 
> > \lookupfile{"$HOME/context-tests/AAA.lua"}  % "AAA.lua" intentionally does  
> >   exist
> > \lookupfile{"$HOME/context-tests/BBB.lua"}  % "BBB.lua" intentionally 
> > doesn't exist
> > 
> > \stoptext
> > 
> > ====================================================
> > 
> > It makes no difference in commenting out the first or the second 
> > "\lookupfile" command.
> > The error message eventually is always nearly the same:
> > 
> > token call, execute: [ctxlua]:8: "$HOME/context-tests/AAA.lua": No such 
> > file or directory
> > token call, execute: [ctxlua]:8: "$HOME/context-tests/BBB.lua": No such 
> > file or directory


Joseph, Taco and Hans, I thank you very much for your quick answers!
I shall try Hans' interesting suggestion on prefix resolvers after I've studied 
it,
for which I certainly need some time!

But before doing so I've a comment:
Your answers, Joseph, Taco and Hans, could  lead to the impression, that giving 
up
"double quotes as part of file names" and/or "$HOME" in the MWE would be the 
solution.
And indeed, not using "double quotes" and "expanding $HOME" by hand partly 
brings success:

1. In the case of an existing file (AAA.lua) the MWE works without error 
message!
   I will append the output-pdf-file here (just for fun!).

2. But in the case of an not existing file (BBB.lua) the known error message 
comes up
   again:
   "token call, execute: [ctxlua]:8: /home/sam/context-tests/BBB.lua: No such 
file or 
    directory".
    This, of course, is true, but shouldn't be mentioned in an error message!

Within \startluacode ... \stopluacode it seems one has to abandon the normal 
lua world,
at least partly. Are there other "special features"?

Rudolf

Attachment: is-file.pdf
Description: Adobe PDF document

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

Reply via email to