Re: [NTG-context] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Jaroslav Hajtmar

Thanx Wolfgang.
It is a good example, which I will definitely come in handy sometimes, 
but unfortunately I can not help my problem to solve.


Once again, many thanks

Jaroslav


Dne 17.7.2011 15:40, Wolfgang Schuster napsal(a):

You can’t expand macro from Lua but the following is possible:

\startluacode

values = {
I  = "1",
II = "2",
}

function test(arg)
if string.find(arg,"\\macro") then
arg = string.gsub(arg,"\\macro","")
if values[arg] then
context(values[arg])
else
context("Invalid index.")
end
else
context("Invalid command.")
end
end

\stopluacode

\starttext

\starttabulate
\NC \type{\macroI}   \EQ \ctxlua{test("\\macroI")}   \NC\NR
\NC \type{\macroII}  \EQ \ctxlua{test("\\macroII")}  \NC\NR
\NC \type{\macroIII} \EQ \ctxlua{test("\\macroIII")} \NC\NR
\NC \type{\foo}  \EQ \ctxlua{test("\\foo")}  \NC\NR
\stoptabulate

\stoptext

Wolfgang

   


___
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] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Wolfgang Schuster

Am 17.07.2011 um 15:10 schrieb Jaroslav Hajtmar:

> then it's not for me very good news, because I thus probably not my module to 
> process only at the Lua language ...


You can’t expand macro from Lua but the following is possible:

\startluacode

values = {
I  = "1",
II = "2",
}

function test(arg)
if string.find(arg,"\\macro") then
arg = string.gsub(arg,"\\macro","")
if values[arg] then
context(values[arg])
else
context("Invalid index.")
end
else
context("Invalid command.")
end
end

\stopluacode

\starttext

\starttabulate
\NC \type{\macroI}   \EQ \ctxlua{test("\\macroI")}   \NC\NR
\NC \type{\macroII}  \EQ \ctxlua{test("\\macroII")}  \NC\NR
\NC \type{\macroIII} \EQ \ctxlua{test("\\macroIII")} \NC\NR
\NC \type{\foo}  \EQ \ctxlua{test("\\foo")}  \NC\NR
\stoptabulate

\stoptext

Wolfgang

___
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] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Jaroslav Hajtmar

Wolfgang,
Me too. This is because the parameter '\macroI' is evaluated as a 
number, but the parameter '\\macroI' is in fact really a string - the 
name of a context macro. context (...) command properly put correctly 
content of the  '\macroI' macro into the ConTeXt, but without knowledge 
of his contents ...


If you write that:


 Not possible.



then it's not for me very good news, because I thus probably not my 
module to process only at the Lua language ...



Thanx Jaroslav...




Dne 17.7.2011 14:53, Wolfgang Schuster napsal(a):

Am 17.07.2011 um 14:42 schrieb Jaroslav Hajtmar:

   

Thanx Wolfgang.
But I guess I was wrong to express..

I need to pass parameter  '\\macroI' to the function  and turn it up a inside 
luafunction  expand to its value.
 

Not possible.

   

Ie when \def\macroI{6}

Then I need when I make in your example \ctxlua{test("\\macroI")} get the 
result :
"The argument “6” is a positive number" and not result "The argument “6” is a 
string."
 

That’s odd because for me

   \ctxlua{test("\macroI")}

results in

   The argument “6” is a positive number.

and

   \ctxlua{test("\\macroI")}

in

   The argument “6” is a string.

Wolfgang


   


___
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] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Wolfgang Schuster

Am 17.07.2011 um 14:42 schrieb Jaroslav Hajtmar:

> Thanx Wolfgang.
> But I guess I was wrong to express..
> 
> I need to pass parameter  '\\macroI' to the function  and turn it up a inside 
> luafunction  expand to its value.

Not possible.

> Ie when \def\macroI{6}
> 
> Then I need when I make in your example \ctxlua{test("\\macroI")} get the 
> result :
> "The argument “6” is a positive number" and not result "The argument “6” is a 
> string."

That’s odd because for me

  \ctxlua{test("\macroI")}

results in

  The argument “6” is a positive number.

and

  \ctxlua{test("\\macroI")}

in

  The argument “6” is a string.

Wolfgang

___
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] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Jaroslav Hajtmar

Thanx Wolfgang.
But I guess I was wrong to express..

I need to pass parameter  '\\macroI' to the function  and turn it up a 
inside luafunction  expand to its value.


Ie when \def\macroI{6}

Then I need when I make in your example \ctxlua{test("\\macroI")} get 
the result :
"The argument “6” is a positive number" and not result "The argument “6” 
is a string."


see: I modify your example :

\startluacode
function test(arg) -- use thirddata namespace for real functions
if type(tonumber(arg)) == "number" then
if tonumber(arg) > 0 then
context("The argument \\quotation{%s} is a positive 
number",arg)

else
context("The argument \\quotation{%s} is a negative 
number",arg)

end
else
context("The argument \\quotation{%s} is a string.",arg)
end
end
\stopluacode






\starttext

\ctxlua{test("7")}

\ctxlua{test("-4")}

\ctxlua{test("text")}

\def\macroI{6}

\ctxlua{test("\macroI")}

\ctxlua{test("\\macroI")}


\stoptext


Dne 17.7.2011 14:19, Wolfgang Schuster napsal(a):

Am 17.07.2011 um 14:01 schrieb Jaroslav Hajtmar:

   

>  Hello all,
>  
>  For several hours trying to find solutions of problem.
>  
>  My minimal example (I mention it at the end of email)  for clear reasons show, that :
>  
>  7 is not number.

>  7 is number.
>  7is not number.
>  7is not number.
>  
>  In the first is argument '\value' negotiable to the value, in second it is not possible (but for clear reasons too).
>  
>  I would need to find from  argument ie macro '\\value'  in the LUA function its numerical value.

>  Is there any function that would do that?
>  
>  I need something as a function of context (...), which would, however, its output is not located into ConTeXt, but its result get to back to a Lua function or into variable.

>  It is something like the expansion of an existing ConTeXt macro to its value.
 

\startluacode
function test(arg) -- use thirddata namespace for real functions
if type(tonumber(arg)) == "number" then
if tonumber(arg)>  0 then
context("The argument \\quotation{%s} is a positive 
number",arg)
else
context("The argument \\quotation{%s} is a negative 
number",arg)
end
else
context("The argument \\quotation{%s} is a string.",arg)
end
end
\stopluacode

\starttext

\ctxlua{test("7")}

\ctxlua{test("-4")}

\ctxlua{test("text")}

\stoptext

Wolfgang


   


___
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] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Wolfgang Schuster

Am 17.07.2011 um 14:01 schrieb Jaroslav Hajtmar:

> Hello all,
> 
> For several hours trying to find solutions of problem.
> 
> My minimal example (I mention it at the end of email)  for clear reasons 
> show, that :
> 
> 7 is not number.
> 7 is number.
> 7is not number.
> 7is not number.
> 
> In the first is argument '\value' negotiable to the value, in second it is 
> not possible (but for clear reasons too).
> 
> I would need to find from  argument ie macro '\\value'  in the LUA function 
> its numerical value.
> Is there any function that would do that?
> 
> I need something as a function of context (...), which would, however, its 
> output is not located into ConTeXt, but its result get to back to a Lua 
> function or into variable.
> It is something like the expansion of an existing ConTeXt macro to its value.

\startluacode
function test(arg) -- use thirddata namespace for real functions
if type(tonumber(arg)) == "number" then
if tonumber(arg) > 0 then
context("The argument \\quotation{%s} is a positive 
number",arg)
else
context("The argument \\quotation{%s} is a negative 
number",arg)
end
else
context("The argument \\quotation{%s} is a string.",arg)
end
end
\stopluacode

\starttext

\ctxlua{test("7")}

\ctxlua{test("-4")}

\ctxlua{test("text")}

\stoptext

Wolfgang

___
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] Finding values ​​of the context macros inside Lua functions (=expansion inside Lua functions?)

2011-07-17 Thread Jaroslav Hajtmar

Hello all,

For several hours trying to find solutions of problem.

My minimal example (I mention it at the end of email)  for clear reasons 
show, that :


7 is not number.
7 is number.
7is not number.
7is not number.


In the first is argument '\value' negotiable to the value, in second it 
is not possible (but for clear reasons too).


I would need to find from  argument ie macro '\\value'  in the LUA 
function its numerical value.

Is there any function that would do that?

I need something as a function of context (...), which would, however, 
its output is not located into ConTeXt, but its result get to back to a 
Lua function or into variable.
It is something like the expansion of an existing ConTeXt macro to its 
value.


Thanx Jaroslav


Here is my minimal example:

\startluacode
function test(arg)

  if type(arg)=='number' then
context(arg.." is number.\\par ")
  else
context(arg.." is not number.\\par")
  end

  if type(tonumber(arg))=='number' then
context(arg.." is number.\\par ")
  else
context(arg.." is not number.\\par")
  end
end

\stopluacode


\starttext
  \def\value{7}

  \ctxlua{test('\value');}

  \blank[big]

  \ctxlua{test('\\value');}

\stoptext




___
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
___