[NTG-context] Checking existence of a macro (control sequence) by Lua
context at vivaldi.net
context at vivaldi.net
Thu May 28 23:24:42 CEST 2020
Hello,
one more question - why macros \Undefined and \DoNothing show "defined"
although I (tried to) undefine them?
----
\starttext
\def\MyMacro{Ahoj}
\def\MyMac#1#2{Something}
\def\Undefined{}
\let\Undefined\undefined
\def\DoNothing{}
\let\DoNothing\donothing
\startluacode
local str = { [true] = "defined", [false] = "undefined" }
local function whatever(s)
context.type("\\" .. s)
context(" is " .. (tokens.defined(s) and "defined" or
"undefined")) --% Hans' way
context(" and is " .. str[token.is_defined(s)] .. ".") --% Henri's
way
context.par()
end
whatever("MyMacro")
whatever("MyMacroD")
whatever(" ")
whatever("-")
whatever("Undefined")
whatever("DoNothing")
\stopluacode
%\Undefined % Causes "! Undefined control sequence"
\stoptext
----
Gives:
"
\MyMacro is defined and is defined.
\MyMacroD is undefined and is undefined.
\ is defined and is defined.
\- is defined and is defined.
\Undefined is defined and is defined.
\DoNothing is defined and is defined.
"
Lukas
More information about the ntg-context
mailing list