[NTG-context] Checking existence of a macro (control sequence) by Lua - problem after updating MkIV

Lukas/ConTeXt lpr.context at email.cz
Fri Jun 19 08:36:26 CEST 2020


Hello Hans,

---------- Původní e-mail ---------- {
Od: Hans Hagen <j.hagen at 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


More information about the ntg-context mailing list