ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Checking existence of a macro (control sequence) by Lua - problem after updating MkIV
@ 2020-06-18  8:27 Lukas/ConTeXt
  2020-06-18 10:21 ` Hans van der Meer
  2020-06-18 20:52 ` Hans Hagen
  0 siblings, 2 replies; 5+ messages in thread
From: Lukas/ConTeXt @ 2020-06-18  8:27 UTC (permalink / raw)
  To: ntg-context

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

Hello,
I'm using Hans' macro suggested some time 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\donothing

  \startluacode
    if CONTEXTLMTXMODE == 0 then
        local d = tokens.defined
        local c = tokens.create

        function tokens.defined(s,b)
            if b then
                return d(s)
            else
                return c(s).cmd_name == "undefined_cmd"
            end
        end
    end

    --

    local defined = tokens.defined

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

  Aaa
\stoptext
----

gives:
"
MyMacro         false   false   false
MyMacWithPars   false   false   false
Undefined       false   false   false
DoNothing       false   false   false
NonExisting     false   false   false
"

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

[-- Attachment #2: IsMacDef3.log --]
[-- Type: text/plain, Size: 7235 bytes --]

open source     > level 1, order 1, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv'
system          > 
system          > ConTeXt  ver: 2020.06.17 18:56 MKIV beta  fmt: 2020.6.18  int: english/english
system          > 
system          > 'cont-new.mkiv' loaded
open source     > level 2, order 2, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-new.mkiv'
system          > beware: some patches loaded from cont-new.mkiv
close source    > level 2, order 2, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-new.mkiv'

system          > jobfiles > using path: d:/Lukas/ConTeXt/Styles
system          > files > jobname 'IsMacDef3', input 'D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv', result 'IsMacDef3'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 2, order 3, name 'D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv'
fonts           > preloading latin modern fonts (second stage)
fonts           > 'fallback modern-designsize rm 12pt' is loaded
backend         > xmp > using file 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/lpdf-pdx.xml'
pages           > flushing realpage 1, userpage 1, subpage 1
close source    > level 2, order 3, name 'D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv'
close source    > level 1, order 3, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv'

system          > start used files

system          > text: IsMacDef3

system          > stop used files


system          > start used files

system          >    1: filename=char-prv.lua filetype=tex format=tex foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/char-prv.lua fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/char-prv.lua usedmethod=database
system          >    2: filename=cont-yes.mkiv filetype=tex foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv usedmethod=database
system          >    3: filename=publ-imp-default.lua filetype=lua foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/publ-imp-default.lua fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/publ-imp-default.lua usedmethod=otherwise
system          >    4: filename=cont-new.mkiv filetype=tex foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-new.mkiv fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-new.mkiv usedmethod=database
system          >    5: filename=lang-exc.lua filetype=lua foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/lang-exc.lua fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/lang-exc.lua usedmethod=otherwise
system          >    6: filename=lang-us.lua filetype=lua foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/patterns/mkiv/lang-us.lua fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/patterns/mkiv/lang-us.lua usedmethod=otherwise
system          >    7: filename=D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv foundname=D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv fullname=D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv usedmethod=direct
system          >    8: filename=lm.lfg filetype=tex foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/fonts/mkiv/lm.lfg fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/fonts/mkiv/lm.lfg usedmethod=database
system          >    9: filename=lmroman12-regular filetype=otf format=otf foundname=d:/Ctx-Beta/tex/texmf/fonts/opentype/public/lm/lmroman12-regular.otf fullname=d:/Ctx-Beta/tex/texmf/fonts/opentype/public/lm/lmroman12-regular.otf usedmethod=database
system          >   10: filename=latinmodern-math.otf filetype=opentypefonts foundname=d:/Ctx-Beta/tex/texmf/fonts/opentype/public/lm-math/latinmodern-math.otf fullname=d:/Ctx-Beta/tex/texmf/fonts/opentype/public/lm-math/latinmodern-math.otf usedmethod=database
system          >   11: filename=pdftex.map filetype=map format=map foundname=d:/Ctx-Beta/tex/texmf/fonts/map/pdftex/plain/pdftex.map fullname=d:/Ctx-Beta/tex/texmf/fonts/map/pdftex/plain/pdftex.map usedmethod=database
system          >   12: filename=lpdf-pdx.xml filetype=tex foundname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/lpdf-pdx.xml fullname=d:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/lpdf-pdx.xml usedmethod=database

system          > stop used files


system          > start commandline options

system          > currentrun="1"
system          > fulljobname="D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv"
system          > input="D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv"
system          > kindofrun="1"
system          > maxnofruns="9"
system          > nonstopmode="true"
system          > path="d:/Lukas/ConTeXt/Styles"
system          > texmfbinpath="d:/Ctx-Beta/tex/texmf-mswin/bin"

system          > stop commandline options


system          > start commandline files

system          >    1: D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv

system          > stop commandline files


modules         > start used modules


modules         > stop used modules


mkiv lua stats  > used config file: selfautoparent:/texmf/web2c/texmfcnf.lua
mkiv lua stats  > used cache path: d:/Ctx-Beta/tex/texmf-cache/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e
mkiv lua stats  > resource resolver: loadtime 0.008 seconds, 0 scans with scantime 0.000 seconds, 0 shared scans, 12 found files, scanned paths: <none>
mkiv lua stats  > stored bytecode data: 452 modules (0.231 sec), 93 tables (0.013 sec), 545 chunks (0.244 sec)
mkiv lua stats  > traced context: maxstack: 1409, freed: 0, unreachable: 1409
mkiv lua stats  > cleaned up reserved nodes: 57 nodes, 9 lists of 442
mkiv lua stats  > node memory usage: 11 attribute, 4 attribute_list, 1 glue, 51 glue_spec, 3 kern, 2 penalty, 2 temp, 2 user_defined
mkiv lua stats  > node list callback tasks: 8 unique task lists, 7 instances (re)created, 38 calls
mkiv lua stats  > used backend: pdf (backend for directly generating pdf output)
mkiv lua stats  > jobdata time: 0.001 seconds saving, 0.001 seconds loading
mkiv lua stats  > callbacks: internal: 138, file: 179, direct: 3, late: 0, function 502, total: 822
mkiv lua stats  > randomizer: resumed with value 0.54769897460938
mkiv lua stats  > result saved in file: IsMacDef3.pdf, compresslevel 3, objectcompresslevel 1
mkiv lua stats  > loaded patterns: en::1, load time: 0.000
mkiv lua stats  > loaded fonts: 2 files: latinmodern-math.otf, lmroman12-regular.otf
mkiv lua stats  > font engine: otf 3.111, afm 1.513, tfm 1.000, 7 instances, 3 shared in backend, 3 common vectors, 0 common hashes, load time 0.191 seconds 
mkiv lua stats  > used platform: mswin, type: windows, binary subtree: texmf-mswin
mkiv lua stats  > used engine: luatex version: 1.13, functionality level: 7353, banner: this is luatex, version 1.13.0 (tex live 2020/w32tex)
mkiv lua stats  > used hash slots: 45878 of 65536 + 100000
mkiv lua stats  > lua properties: engine: lua 5.3, used memory: 71 MB, ctx: 70 MB, max: unknown MB, hash chars: min(32,40), symbol mask: utf (τεχ)
mkiv lua stats  > runtime: 0.494 seconds, 1 processed pages, 1 shipped pages, 2.024 pages/second


[-- Attachment #3: IsMacDef3.mkiv --]
[-- Type: text/plain, Size: 798 bytes --]

\starttext
  \def\MyMacro{Ahoj}

  \def\MyMacWithPars#1#2{Something}

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

  \def\DoNothing{}
  \let\DoNothing\donothing

  \startluacode
    if CONTEXTLMTXMODE == 0 then

        local d = tokens.defined
        local c = tokens.create

        function tokens.defined(s,b)
            if b then
                return d(s)
            else
                return c(s).cmd_name == "undefined_cmd"
            end
        end

    end

    --

    local defined = tokens.defined

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

  Aaa
\stoptext

[-- Attachment #4: IsMacDef3.log_ --]
[-- Type: text/plain, Size: 3980 bytes --]

resolvers       | formats | executing runner 'run luatex format': d:/Ctx-Beta/tex/texmf-mswin/bin/luatex --interaction="nonstopmode" --jobnam
xmf-mswin/bin"
This is LuaTeX, Version 1.13.0 (TeX Live 2020/W32TeX)
 system commands enabled.
open source     > level 1, order 1, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv'
system          >
system          > ConTeXt  ver: 2020.06.17 18:56 MKIV beta  fmt: 2020.6.18  int: english/english
system          >
system          > 'cont-new.mkiv' loaded
open source     > level 2, order 2, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-new.mkiv'
system          > beware: some patches loaded from cont-new.mkiv
close source    > level 2, order 2, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-new.mkiv'

system          > jobfiles > using path: d:/Lukas/ConTeXt/Styles
system          > files > jobname 'IsMacDef3', input 'D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv', result 'IsMacDef3'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 2, order 3, name 'D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv'
fonts           > preloading latin modern fonts (second stage)
fonts           > 'fallback modern-designsize rm 12pt' is loaded
MyMacro         false   false   false
MyMacWithPars   false   false   false
Undefined       false   false   false
DoNothing       false   false   false
NonExisting     false   false   false
backend         > xmp > using file 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/lpdf-pdx.xml'
pages           > flushing realpage 1, userpage 1, subpage 1
close source    > level 2, order 3, name 'D:/Lukas/ConTeXt/Test/IsMacDef3.mkiv'
close source    > level 1, order 3, name 'd:/Ctx-Beta/tex/texmf-context/tex/context/base/mkiv/cont-yes.mkiv'

mkiv lua stats  > used config file: selfautoparent:/texmf/web2c/texmfcnf.lua
mkiv lua stats  > used cache path: d:/Ctx-Beta/tex/texmf-cache/luatex-cache/context/5fe67e0bfe781ce0dde776fb1556f32e
mkiv lua stats  > resource resolver: loadtime 0.008 seconds, 0 scans with scantime 0.000 seconds, 0 shared scans, 12 found files, scanned pat
mkiv lua stats  > stored bytecode data: 452 modules (0.231 sec), 93 tables (0.013 sec), 545 chunks (0.244 sec)
mkiv lua stats  > traced context: maxstack: 1409, freed: 0, unreachable: 1409
mkiv lua stats  > cleaned up reserved nodes: 57 nodes, 9 lists of 442
mkiv lua stats  > node memory usage: 11 attribute, 4 attribute_list, 1 glue, 51 glue_spec, 3 kern, 2 penalty, 2 temp, 2 user_defined
mkiv lua stats  > node list callback tasks: 8 unique task lists, 7 instances (re)created, 38 calls
mkiv lua stats  > used backend: pdf (backend for directly generating pdf output)
mkiv lua stats  > jobdata time: 0.001 seconds saving, 0.001 seconds loading
mkiv lua stats  > callbacks: internal: 138, file: 179, direct: 3, late: 0, function 502, total: 822
mkiv lua stats  > randomizer: resumed with value 0.54769897460938
mkiv lua stats  > result saved in file: IsMacDef3.pdf, compresslevel 3, objectcompresslevel 1
mkiv lua stats  > loaded patterns: en::1, load time: 0.000
mkiv lua stats  > loaded fonts: 2 files: latinmodern-math.otf, lmroman12-regular.otf
mkiv lua stats  > font engine: otf 3.111, afm 1.513, tfm 1.000, 7 instances, 3 shared in backend, 3 common vectors, 0 common hashes, load tim
mkiv lua stats  > used platform: mswin, type: windows, binary subtree: texmf-mswin
mkiv lua stats  > used engine: luatex version: 1.13, functionality level: 7353, banner: this is luatex, version 1.13.0 (tex live 2020/w32tex)
mkiv lua stats  > used hash slots: 45878 of 65536 + 100000
mkiv lua stats  > lua properties: engine: lua 5.3, used memory: 71 MB, ctx: 70 MB, max: unknown MB, hash chars: min(32,40), symbol mask: utf
mkiv lua stats  > runtime: 0.494 seconds, 1 processed pages, 1 shipped pages, 2.024 pages/second
system          | total runtime: 0.798 seconds

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Checking existence of a macro (control sequence) by Lua - problem after updating MkIV
  2020-06-18  8:27 Checking existence of a macro (control sequence) by Lua - problem after updating MkIV Lukas/ConTeXt
@ 2020-06-18 10:21 ` Hans van der Meer
  2020-06-18 10:29   ` Lukas/ConTeXt
  2020-06-18 20:52 ` Hans Hagen
  1 sibling, 1 reply; 5+ messages in thread
From: Hans van der Meer @ 2020-06-18 10:21 UTC (permalink / raw)
  To: NTG ConTeXt


[-- Attachment #1.1: Type: text/plain, Size: 2259 bytes --]

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 <lpr.context@email.cz> wrote:
> 
> Hello,
> I'm using Hans' macro suggested some time 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\donothing
> 
>  \startluacode
>    if CONTEXTLMTXMODE == 0 then
>        local d = tokens.defined
>        local c = tokens.create
> 
>        function tokens.defined(s,b)
>            if b then
>                return d(s)
>            else
>                return c(s).cmd_name == "undefined_cmd"
>            end
>        end
>    end
> 
>    --
> 
>    local defined = tokens.defined
> 
>    for _, v in ipairs{ "MyMacro", "MyMacWithPars", "Undefined", "DoNothing", "NonExisting" } do
>      print(string.format("\letterpercent-12s", v), defined(v), defined(v, true), defined(v, false))
>    end
>  \stopluacode
> 
>  Aaa
> \stoptext
> ----
> 
> gives:
> "
> MyMacro         false   false   false
> MyMacWithPars   false   false   false
> Undefined       false   false   false
> DoNothing       false   false   false
> NonExisting     false   false   false
> "
> 
> 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<IsMacDef3.log><IsMacDef3.mkiv><IsMacDef3.log_>___________________________________________________________________________________
> 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
> ___________________________________________________________________________________


[-- Attachment #1.2: Type: text/html, Size: 6058 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re:  Checking existence of a macro (control sequence) by Lua - problem after updating MkIV
  2020-06-18 10:21 ` Hans van der Meer
@ 2020-06-18 10:29   ` Lukas/ConTeXt
  0 siblings, 0 replies; 5+ messages in thread
From: Lukas/ConTeXt @ 2020-06-18 10:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 3647 bytes --]


Hello,




I need to check within Lua.

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




Best,




Lukas



---------- Původní e-mail ----------
Od: Hans van der Meer <havdmeer@ziggo.nl>
Komu: NTG ConTeXt <ntg-context@ntg.nl>
Datum: 18. 6. 2020 12:25:42
Předmět: Re: [NTG-context] Checking existence of a macro (control 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 <lpr.context@email.cz
(mailto:lpr.context@email.cz)> wrote:



Hello,
I'm using Hans' macro suggested some time 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\donothing

  \startluacode
    if CONTEXTLMTXMODE == 0 then
       local d = tokens.defined
       local c = tokens.create

       function tokens.defined(s,b)
           if b then
               return d(s)
           else
                return c(s).cmd_name == "undefined_cmd"
           end
        end
    end

    --

    local defined = tokens.defined

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

  Aaa
\stoptext
----

gives:
"
MyMacro         false   false   false
MyMacWithPars   false   false   false
Undefined       false   false   false
DoNothing       false   false   false
NonExisting     false   false   false
"

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<IsMacDef3.log><IsMacDef3.mkiv><IsMacDef3.log_>________________________
___________________________________________________________
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  : http://www.pragma-ade.nl(http://www.pragma-ade.nl) / http://
context.aanhet.net(http://context.aanhet.net)
archive  : https://bitbucket.org/phg/context-mirror/commits/
(https://bitbucket.org/phg/context-mirror/commits/)
wiki     : http://contextgarden.net(http://contextgarden.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
____________________________________________________________________________
_______
"

[-- Attachment #1.2: Type: text/html, Size: 6614 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Checking existence of a macro (control sequence) by Lua - problem after updating MkIV
  2020-06-18  8:27 Checking existence of a macro (control sequence) by Lua - problem after updating MkIV Lukas/ConTeXt
  2020-06-18 10:21 ` Hans van der Meer
@ 2020-06-18 20:52 ` Hans Hagen
  2020-06-19  6:36   ` Lukas/ConTeXt
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2020-06-18 20:52 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Lukas/ConTeXt

On 6/18/2020 10:27 AM, Lukas/ConTeXt wrote:
> Hello,
> I'm using Hans' macro suggested some time 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\donothing
> 
>    \startluacode
>      if CONTEXTLMTXMODE == 0 then
>          local d = tokens.defined
>          local c = tokens.create
> 
>          function tokens.defined(s,b)
>              if b then
>                  return d(s)
>              else
>                  return c(s).cmd_name == "undefined_cmd"
>              end
>          end
>      end
> 
>      --
> 
>      local defined = tokens.defined
> 
>      for _, v in ipairs{ "MyMacro", "MyMacWithPars", "Undefined", "DoNothing", "NonExisting" } do
>        print(string.format("\letterpercent-12s", v), defined(v), defined(v, true), defined(v, false))
>      end
>    \stopluacode
> 
>    Aaa
> \stoptext
as you updated, it's just:

   \startluacode
     local defined = tokens.defined

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


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re:  Checking existence of a macro (control sequence) by Lua - problem after updating MkIV
  2020-06-18 20:52 ` Hans Hagen
@ 2020-06-19  6:36   ` Lukas/ConTeXt
  0 siblings, 0 replies; 5+ messages in thread
From: Lukas/ConTeXt @ 2020-06-19  6:36 UTC (permalink / raw)
  To: ntg-context

Hello Hans,

---------- Původní e-mail ---------- {
Od: Hans Hagen <j.hagen@xs4all.nl>

as you updated, it's just:

   \startluacode
     local defined = tokens.defined
     for _, v in ipairs{ "MyMacro", "MyMacWithPars", "Undefined", "DoNothing", "NonExisting" } do
       print(string.format("\letterpercent-12s", v), defined(v), defined(v, true), defined(v, false))
     end
   \stopluacode
---------- Původní e-mail ---------- }

your solution gives me:

"
MyMacro         false   true    false
MyMacWithPars   false   true    false
Undefined       false   true    false
DoNothing       false   true    false
NonExisting     false   false   false
"
which desn't recognize \Undefined - it should give 'false' in the 2nd column of results, like \NonExisting does.

But I have another solution (asked in Czech TUG) - use of 'token.get_meaning(cs)': 
----
  \startluacode
    for _, v in ipairs{ "MyMacro", "MyMacWithPars", "Undefined", "DoNothing", "NonExisting" } do
      print(string.format("\letterpercent-12s", v), "get_meaning", token.get_meaning(v) or "(non-existing/undefined)")
    end
  \stopluacode
----

- Produces:

"
MyMacro         get_meaning     ->Ahoj
MyMacWithPars   get_meaning     #1#2->Something
Undefined       get_meaning     (non-existing/undefined)
DoNothing       get_meaning     ->
NonExisting     get_meaning     (non-existing/undefined)
"
which is perfectly what I need.

But thank you anyway for your effort.

Best regards,

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-19  6:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18  8:27 Checking existence of a macro (control sequence) by Lua - problem after updating MkIV Lukas/ConTeXt
2020-06-18 10:21 ` Hans van der Meer
2020-06-18 10:29   ` Lukas/ConTeXt
2020-06-18 20:52 ` Hans Hagen
2020-06-19  6:36   ` Lukas/ConTeXt

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).