From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107780 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Lukas/ConTeXt" Newsgroups: gmane.comp.tex.context Subject: Re: =?utf-8?q?Checking_existence_of_a_macro_=28control?= =?utf-8?q?_sequence=29_by_Lua_-_problem_after_updating_MkIV?= Date: Thu, 18 Jun 2020 12:29:41 +0200 (CEST) Message-ID: References: <4A610884-7395-45B9-9D92-DF0409B440F2@ziggo.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (szn-mime-2.0.57) Content-Type: multipart/mixed; boundary="===============1181840520723102029==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="81861"; mail-complaints-to="usenet@ciao.gmane.io" To: "mailing list for ConTeXt users" Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 18 12:30:11 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlroB-000LC3-O2 for gctc-ntg-context-518@m.gmane-mx.org; Thu, 18 Jun 2020 12:30:11 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 71782163B05; Thu, 18 Jun 2020 12:29:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XP5kW2kTaflu; Thu, 18 Jun 2020 12:29:49 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 5A7601639CB; Thu, 18 Jun 2020 12:29:49 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 085AB1639CB for ; Thu, 18 Jun 2020 12:29:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SNGwB6aiMiLH for ; Thu, 18 Jun 2020 12:29:48 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=77.75.78.89; helo=mxb1.seznam.cz; envelope-from=lpr.context@email.cz; receiver= Original-Received: from mxb1.seznam.cz (mxb1.seznam.cz [77.75.78.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id F0ACF162F45 for ; Thu, 18 Jun 2020 12:29:47 +0200 (CEST) Original-Received: from email.seznam.cz by email-smtpc23a.ko.seznam.cz (email-smtpc23a.ko.seznam.cz [10.53.18.30]) id 3499215a0d9fbc7832b21235; Thu, 18 Jun 2020 12:29:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1592476187; bh=XinKUb0B+6aOqx9XzAgh/WtKRV7noXlUqynDWfweWuw=; h=Received:From:To:Subject:Date:Message-Id:References:Mime-Version: X-Mailer:Content-Type; b=XuKy4sfGzdXq0ZVAj7vcAjEWY7OHGTjOBArJiJCrQAOi2Zg09t6RGRuj5qLsskP1Q K5ld7i8Qe2K8igblJowYVRMUWFAapVefn5rf4815xP5dWKp0sosnciKS+6MLzdCgg7 vrd8qXojC10iqNYxRWqxDxBH6D9GICloEOMlk+ko= Original-Received: from unknown ([::ffff:185.228.166.98]) by email.seznam.cz (szn-ebox-5.0.29) with HTTP; Thu, 18 Jun 2020 12:29:41 +0200 (CEST) X-Mailer: szn-ebox-5.0.29 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107780 Archived-At: --===============1181840520723102029== Content-Type: multipart/alternative; boundary="=_6ed5ee2578d5a7df6b8ff84b=6e1ed393-bec0-5916-bffe-7feea402d49e_=" --=_6ed5ee2578d5a7df6b8ff84b=6e1ed393-bec0-5916-bffe-7feea402d49e_= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, I need to check within Lua. My sample cases are very minimalistic - I'm working on more complicated ta= sk actually, where check-for-control-sequence-existence need to be performed = run-time within Lua scope. Best, Lukas ---------- P=C5=AFvodn=C3=AD e-mail ---------- Od: Hans van der Meer Komu: NTG ConTeXt Datum: 18. 6. 2020 12:25:42 P=C5=99edm=C4=9Bt: Re: [NTG-context] Checking existence of a macro (contro= l sequence) by Lua - problem after updating MkIV " Why can you not simply use one of the doifundefined macro's? Something for= example: \doifundefined{ExitStatus}{\gdef\ExitStatus{0}} % default to ok as in UNIX= dr. Hans van der Meer " On 18 Jun 2020, at 10:27, Lukas/ConTeXt wrote: Hello, I'm using Hans' macro suggested some time before. I've just updated Ctx MkIV and my sample code: ---- \starttext =C2=A0\def\MyMacro{Ahoj} =C2=A0\def\MyMacWithPars#1#2{Something} =C2=A0\def\Undefined{} =C2=A0\let\Undefined\undefined =C2=A0\def\DoNothing{} =C2=A0\let\DoNothing\donothing =C2=A0\startluacode =C2=A0=C2=A0=C2=A0if CONTEXTLMTXMODE =3D=3D 0 then =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0local d =3D tokens.defined =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0local c =3D tokens.create =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0function tokens.defined(s,b) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if b the= n =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0return d(s) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0else =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0return c(s).cmd_name =3D=3D "undefined_cmd" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0end =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0end =C2=A0=C2=A0=C2=A0end =C2=A0=C2=A0=C2=A0-- =C2=A0=C2=A0=C2=A0local defined =3D tokens.defined =C2=A0=C2=A0=C2=A0for _, v in ipairs{ "MyMacro", "MyMacWithPars", "Undefin= ed", "DoNothing", "NonExisting" } do =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0print(string.format("\letterpercent-12s", v)= , defined(v), defined(v, true), defined(v, false)) =C2=A0=C2=A0=C2=A0end =C2=A0\stopluacode =C2=A0Aaa \stoptext ---- gives: " MyMacro =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0false =C2=A0=C2=A0= false =C2=A0=C2=A0false MyMacWithPars =C2=A0=C2=A0false =C2=A0=C2=A0false =C2=A0=C2=A0false Undefined =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0false =C2=A0=C2=A0false = =C2=A0=C2=A0false DoNothing =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0false =C2=A0=C2=A0false = =C2=A0=C2=A0false NonExisting =C2=A0=C2=A0=C2=A0=C2=A0false =C2=A0=C2=A0false =C2=A0=C2=A0fa= lse " IOW, I'm not able to determine whether a control sequence has not been defined (or has \undefined value) or not. Am I doing a trivial mistake or has anything changed? Thank you for patience... Lukas______________________= __ ___________________________________________________________ If your question is of interest to others as well, please add an entry to = the Wiki! maillist : ntg-context@ntg.nl(mailto:ntg-context@ntg.nl) / http://www.ntg.= nl/mailman/listinfo/ntg-context (http://www.ntg.nl/mailman/listinfo/ntg-context) webpage =C2=A0: http://www.pragma-ade.nl(http://www.pragma-ade.nl) / http:= // context.aanhet.net(http://context.aanhet.net) archive =C2=A0: https://bitbucket.org/phg/context-mirror/commits/ (https://bitbucket.org/phg/context-mirror/commits/) wiki =C2=A0=C2=A0=C2=A0=C2=A0: http://contextgarden.net(http://contextgard= en.net) __________________________________________________________________________= __ _______ " __________________________________________________________________________= __ _______ 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 __________________________________________________________________________= __ _______ " --=_6ed5ee2578d5a7df6b8ff84b=6e1ed393-bec0-5916-bffe-7feea402d49e_= Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hello,

I need to check within Lu= a.
My sample cases are very minimalistic - I'm working on more c= omplicated task actually, where check-for-control-sequence-existence need = to be performed run-time within Lua scope.

Best,<= /div>

Lukas


Why can you not= simply use one of the doifundefined macro's? Something for example:
\doifundefined{ExitStatus= }{\gdef\ExitStatus{0}} % default to ok as in UNIX

dr. Hans van der Meer

=0A=
=0A=

On 18 Jun 2020, at 10:27, Luka= s/ConTeXt <lpr.context@em= ail.cz> wrote:

Hello,
I'm using Hans' macro suggested some ti= me before.
I've just updated Ctx MkIV and my sample code:

----
\starttext
 \def\MyMacro{Ahoj}
 \def\MyMacWithPars#1#2{Something}

 \def\Undefined{}
 \let\Undefined\undefined

 \def\DoNothing{}
 \let\DoNothing\donoth= ing

 \startluacode
   if= CONTEXTLMTXMODE =3D=3D 0 then
     &nb= sp; local d =3D tokens.defined
    &nbs= p;  local c =3D tokens.create

  &n= bsp;    function tokens.defined(s,b)
 &= nbsp;         if b then
           &nb= sp;   return d(s)
     &= nbsp;     else
    =            return c= (s).cmd_name =3D=3D "undefined_cmd"
    &nbs= p;      end
   &nbs= p;   end
   end

   --

   local defined= =3D tokens.defined

   for _, v in ipai= rs{ "MyMacro", "MyMacWithPars", "Undefined", "DoNothing", "NonExisting" } = do
     print(string.format("\letterper= cent-12s", v), defined(v), defined(v, true), defined(v, false))
=    end
 \stopluacode

&nb= sp;Aaa
\stoptext
----

gives:
"
MyMacro         false =   false   false
MyMacWithPars   fal= se   false   false
Undefined   &nbs= p;   false   false   false
DoN= othing       false   false  &= nbsp;false
NonExisting     false   = false   false
"

IOW, I'm not able to= determine whether a control sequence has not been defined (or has \undefi= ned value) or not.

Am I doing a trivial mistake or has = anything changed?

Thank you for patience...
Lukas<IsMacDef3.log><IsMacDef3.mkiv><IsMacDef3.log_>________________________________________________________________________= ___________
If your question is of interest to others as well, pl= ease add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/l= istinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : = https:= //bitbucket.org/phg/context-mirror/commits/
wiki   =   : http://contextgar= den.net
_____________________________________________________= ______________________________
___________________________________________________________________= ________________
If your question is of interest to others as well, ple= ase 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
_______= __________________________________________________________________________= __
--=_6ed5ee2578d5a7df6b8ff84b=6e1ed393-bec0-5916-bffe-7feea402d49e_=-- --===============1181840520723102029== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============1181840520723102029==--