On Mon, Oct 14, 2019 at 09:26:58PM +0200, Taco Hoekwater wrote:
> Hi,
> > On 14 Oct 2019, at 21:08, Rudolf Bahr <qu...@quasi.de> wrote:
> > 
> > 
> > 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!
> If you do not want the error message, don’t use assert(). You can just do 
> f = io.open(...)
> If f then ... else ... end
> Best wishes,
> Taco

Hi Taco!

Thank you again for your message!

My wish isn't to avoid error messages, if they are justified! In the case of my 
I want to have a decision in my \startluacode ... \stopluacode environment, 
a certain file exists or not. With this decision I want to branch in my program 
with an error message I cannot do it.

Lua is a wonderfull programming language and I'm appreciative to get a way to 
ConTeXt, run Lua code and enter the ConTeXt program at the same location again! 
the other side, in the last days I spent some time to eliminate errors in my
\startluacode ...\stopluacode program to change code which causes no error 
in pure Lua.

Now to your suggestion not to use "assert ()". Indeed it's a solution! My 
works! I append again its output (again just for fun!). Did you really try it or
has it been just an idea? The MWE is now as follows:


userdata = userdata or {}

function userdata.file_exists (name)

   local name = name
   local f    = io.open ( name, "r" )

   if f then
      f:close ()
      context ( name )
      context ( "  exists!" )
      context ( name )
      context ( "  doesn't exist!" )




\lookupfile{/home/sam/context-tests/AAA.lua}    % "AAA.lua" intentionally does 


\lookupfile{/home/sam/context-tests/BBB.lua}    % "BBB.lua" intentionally 
doesn't exist


R. Ierusalimschy encourages the use of "assert()". But it is apparantly better 
not to
use it under certain circumstances as in \startluacode ... \stopluacode as I've 
Can I avoid therefore Hans' prefix resolvers code?

Best wishes,

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

If your question is of interest to others as well, please add an entry to the 

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