Re: [NTG-context] Testing TeX macros through Lua

2010-04-23 Thread Hans Hagen

On 22-4-2010 9:15, Taco Hoekwater wrote:

Jaroslav Hajtmar wrote:

Hello everybody.

Is there any possibility discover through Lua in ConTeXt whether it
has been defined in ConTeXt source any regular TeX macros?


\starttext
\directlua{print(token.command_name(token.create('starttext')))}
\directlua{print(token.command_name(token.create('starttextx')))}
\stoptext

In short: if the result of command_name is "undefined_cs", the
corresponding identifier is undefined (at this moment at this level).

What command_name returns is a string representation of the internal
command, of which there are some 140. normal macros are "call",
conditionals are "if_test", box commands are "box_set", etc. There is
no list of returned names in the manual, but you can generate one by
something like this:

\directlua{
i=0
while i<200 do
v = token.command_name({i,0,0})
if not v then break end
print(i, v)
i=i+1
end}


Alternatively, you can do this:

\directlua{print(token.csname_name(token.create('starttext')))}

if the returned string is empty, the command was undefined, otherwise
you get the string back that you gave yourself (but with this option
you don't know what kind of command it was).


\starttext

\startluacode

function interfaces.valid_command(str)
return (str and str ~= "" and 
token.csname_name(token.create(str)) ~= "") or false

end

print(interfaces.is_command())
print(interfaces.is_command(""))
print(interfaces.is_command("interesting"))
print(interfaces.is_command("starttext"))

\stopluacode

\stoptext



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Testing TeX macros through Lua

2010-04-22 Thread Taco Hoekwater

Jaroslav Hajtmar wrote:

Hello everybody.

Is there any possibility discover through Lua in ConTeXt whether it has 
been defined in ConTeXt source any regular TeX macros?


\starttext
\directlua{print(token.command_name(token.create('starttext')))}
\directlua{print(token.command_name(token.create('starttextx')))}
\stoptext

In short: if the result of command_name is "undefined_cs", the
corresponding identifier is undefined (at this moment at this level).

What command_name returns is a string representation of the internal
command, of which there are some 140. normal macros are "call",
conditionals are "if_test", box commands are "box_set", etc. There is
no list of returned names in the manual, but you can generate one by
something like this:

\directlua{
  i=0
  while i<200 do
v = token.command_name({i,0,0})
if not v then break end
print(i, v)
i=i+1
  end}


Alternatively, you can do this:

  \directlua{print(token.csname_name(token.create('starttext')))}

if the returned string is empty, the command was undefined, otherwise
you get the string back that you gave yourself (but with this option
you don't know what kind of command it was).

Best wishes,
Taco
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] Testing TeX macros through Lua

2010-04-22 Thread Jaroslav Hajtmar

Hello everybody.

Is there any possibility discover through Lua in ConTeXt whether it has 
been defined in ConTeXt source any regular TeX macros?

Be enough for me any simple example or relevant link.

Thanx
J.Hajtmar


___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___