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: Wed, 16 Oct 2019 09:03:13 +0200	[thread overview]
Message-ID: <20191016070312.GA15308@nan> (raw)
In-Reply-To: <d9510b3e-153c-f1b4-2639-a1bad8a6b895@xs4all.nl>

On Tue, Oct 15, 2019 at 10:15:34AM +0200, Hans Hagen wrote:
> On 10/15/2019 10:04 AM, Taco Hoekwater wrote:
> > Hi Rudolf,
> > 
> > > On 15 Oct 2019, at 00:50, Rudolf Bahr <quasi@quasi.de> wrote:
> > > 
> > > 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?
> > 
> > First, let me say that embedded lua versions are typically a little bit different
> > from standalone. Just how much different depends on the embedding program. Luatex
> > is actually pretty close to standalone lua. Luatex adds a bunch of extension libraries,
> > but it changes very little of the core language. And all those changes are documented
> > in the luatex manual. None of those changes affect your minimal example, except
> > that lua errors are handled a little differently.
> > 
> > Note that standalone lua *also* produces an error, as that is what assert() is
> > supposed to do. And when lua runs into an error, it ignores the rest of the current
> > chunk:
> > 
> >    “... whenever an error occurs, Lua ends the current chunk and returns
> >    to the application.” (from lua.org)
> > 
> > Standalone lua typically sees only one chunk (the file you pass on the command
> > line) but embedded lua implementation often see (sometimes many) more chunks.
> > In luatex’s case, each \directlua is a separate chunk (in ConTeXt, that means every
> > \startluacode block and every \ctxlua call is a separate chunk).
> > 
> > The only unusual thing here is that standalone lua silently quits and returns a
> > non-zero exit code to the shell, whereas luatex gives you the typical TeX-style
> > error prompt. The rationale for that is: lua errors can happen in many places in
> > your input file, and if they were silently ignored, your typeset pages could be
> > wrong without you realising it.
> > 
> > 
> > And to answer your question above: I did not have to try or guess. I know about
> > how assert() works because it is documented in the lua manual (and as it closely
> > mimics the assert() C function, that is easy for me to remember).
> as you say, it's all normal lua behaviour:
> 
> if you do:
> 
>   print(io.open("crap.crap"))
> 
> one gets
> 
>   nil	crap.crap: No such file or directory	2
> 
> and i think that assert then returns the second returned argument
> 
> but if one does
> 
>   context(io.open("crap.crap") and "yes" or "no")
> 
> then the first argument is checked against
> 
> Hans


Hi Hans, hi Taco!

For your answers and patient explanations I want to thank you, not to forget
[1], [2], [3] for instance! Now it gets clearer to me what the distinctive
features could be which one can encounter when using a combination of even so
wunderful programming languages as ConTeXt and Lua are!

Best wishes,

Rudolf

[1] https://wiki.contextgarden.net/Programming_in_LuaTeX
[2] http://www.luatex.org/svn/trunk/manual/luatex.pdf
[3] http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf

___________________________________________________________________________________
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-16  7:03 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
2019-10-15  8:04         ` Taco Hoekwater
2019-10-15  8:15           ` Hans Hagen
2019-10-16  7:03             ` Rudolf Bahr [this message]

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=20191016070312.GA15308@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).