Hi, I'm wondering if I can register a Lua function as callback on the expansion of a specific macro? I'm expecting something like this: \def\hello#1{#1} callback.register("macro.hello",lua_func_hello) when using \hello{abc}, the lua_func_hello will get called and have access to the arguments of \hello (abc). In this way, we can implement loop structure in lua (which I think is a cleaner way than tail recursion in TeX). - jjgod.
Jjgod Jiang wrote:
Hi,
I'm wondering if I can register a Lua function as callback on the expansion of a specific macro? I'm expecting something like this:
\def\hello#1{#1}
callback.register("macro.hello",lua_func_hello)
when using \hello{abc}, the lua_func_hello will get called and have access to the arguments of \hello (abc).
\def\hello#1{\directlua 0 {YourFunction("#1")}} Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi,
2007/2/20, Hans Hagen
\def\hello#1{\directlua 0 {YourFunction("#1")}}
Yep. That works (but not for lua state 0, I use state 1 instead.) But I'll need the slunicode library to process string like this, is it available now? I have not found it on luatexref-t.pdf. Thanks. - jjgod.
Hi,
2007/2/20, Hans Hagen
: \def\hello#1{\directlua 0 {YourFunction("#1")}}
Yep. That works (but not for lua state 0, I use state 1 instead.) But I'll need the slunicode library to process string like this, is it available now? I have not found it on luatexref-t.pdf.
Jjgod Jiang wrote: this is state independent, so state 1 should work; indeed the slunicode lib is there as is lfs Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi,
2007/2/20, Hans Hagen
this is state independent, so state 1 should work; indeed the slunicode lib is there as is lfs
I've tried with \directlua 0 { function hello(str) tex.print(str) end } \def\hello#1{\directlua 0 {hello("#1")}} \hello{hi} \bye But only got: ! LuaTeX error [string "luas[0]"]:1: attempt to index global 'tex' (a nil value ). \hello #1->\directlua 0 {hello("#1")} l.9 \hello{hi} - jjgod.
Jjgod Jiang wrote:
Hi,
2007/2/20, Hans Hagen
: this is state independent, so state 1 should work; indeed the slunicode lib is there as is lfs
I've tried with
\directlua 0 { function hello(str) tex.print(str) end }
\def\hello#1{\directlua 0 {hello("#1")}}
\hello{hi} \bye
But only got:
! LuaTeX error [string "luas[0]"]:1: attempt to index global 'tex' (a nil value ). \hello #1->\directlua 0 {hello("#1")}
l.9 \hello{hi} \starttext
\directlua 0 { function hello(str) tex.print(str) end } \directlua 5 { function hello(str) tex.print(str) end } \directlua 0 { tex.print("HELLO") } \directlua 5 { tex.print("HELLO") } \directlua 0 { hello("HELLO") } \directlua 5 { hello("HELLO") } \def\hello#1{\directlua 5 {hello("#1")}} \hello{HELLO} \stoptext works ok here (1 too) so there is another problem; it could be that luatex is not in luatex mode or that somehow the tex table gets messed up Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi Jjgod, Jjgod Jiang wrote:
Hi,
I'm wondering if I can register a Lua function as callback on the expansion of a specific macro? I'm expecting something like this:
\def\hello#1{#1}
callback.register("macro.hello",lua_func_hello)
when using \hello{abc}, the lua_func_hello will get called and have access to the arguments of \hello (abc).
In this way, we can implement loop structure in lua (which I think is a cleaner way than tail recursion in TeX).
Not right now, but soon. (perhaps using a slighly different interface, because your example makes the macro definition body pointless, and that can be confusing). Cheers, Taco
participants (3)
-
Hans Hagen
-
Jjgod Jiang
-
Taco Hoekwater