ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Rudolf Bahr <quasi@quasi.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: \ctxlua and \startluacode ... \stopluacode
Date: Tue, 15 Oct 2019 00:50:31 +0200	[thread overview]
Message-ID: <20191014225031.GA2472@nan> (raw)
In-Reply-To: <017004DC-6E05-4B4D-A8D7-75A97041FF44@elvenkind.com>

[-- Attachment #1: Type: text/plain, Size: 2503 bytes --]

On Mon, Oct 14, 2019 at 09:26:58PM +0200, Taco Hoekwater wrote:
> Hi,
> 
> > On 14 Oct 2019, at 21:08, Rudolf Bahr <quasi@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 MWE
I want to have a decision in my \startluacode ... \stopluacode environment, whether
a certain file exists or not. With this decision I want to branch in my program and
with an error message I cannot do it.

Lua is a wonderfull programming language and I'm appreciative to get a way to exit
ConTeXt, run Lua code and enter the ConTeXt program at the same location again! On
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 messages
in pure Lua.

Now to your suggestion not to use "assert ()". Indeed it's a solution! My program
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:

=======================================================================================
\startluacode

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!" )
   else
      context ( name )
      context ( "  doesn't exist!" )
   end
end

\stopluacode


\starttext

\def\lookupfile#1%
	{\ctxlua{userdata.file_exists([==[#1]==])}}

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

\par

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

\stoptext
=======================================================================================

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 learnt
now.
Can I avoid therefore Hans' prefix resolvers code?

Best wishes,
Rudolf

[-- Attachment #2: is-file.pdf --]
[-- Type: application/pdf, Size: 5954 bytes --]

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

  reply	other threads:[~2019-10-14 22:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 16:50 Rudolf Bahr
2019-10-14 16:55 ` RE : " Joseph
2019-10-14 17:08 ` Taco Hoekwater
2019-10-14 17:19 ` Hans Hagen
2019-10-14 19:07   ` Rudolf Bahr
2019-10-14 19:26     ` Taco Hoekwater
2019-10-14 22:50       ` Rudolf Bahr [this message]
2019-10-15  8:04         ` Taco Hoekwater
2019-10-15  8:15           ` Hans Hagen
2019-10-16  7:03             ` Rudolf Bahr

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=20191014225031.GA2472@nan \
    --to=quasi@quasi.de \
    --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).