Hello, trying out the LuaTeX snapshot 20070820, I have a couple of questions: - Is it safe to add to the LuaTeX library tables (tex, callback), i.e. a callback.push function? Or should these support functions have their own table? ("callback_utils") - How do I generate an error when inside Lua code? I could use tex.write("\\errmessage{...}"), but then the error would only be generated after the Lua code has finished executing, and after any TeX code created previously using tex.write et.al. has been executed. - How do I access control sequences from Lua code? If I have a macro \test, how would I get the tokens of this macro when inside Lua? (without passing them from TeX) Is there a table tex.macro, just like the tex.count, tex.toks etc. tables? Thanks in advance, Jonathan
Jonathan Sauer wrote:
Hello,
trying out the LuaTeX snapshot 20070820, I have a couple of questions:
- Is it safe to add to the LuaTeX library tables (tex, callback), i.e. a callback.push function? Or should these support functions have their own table? ("callback_utils")
you can indeed use those tables as any table, i.e. function tex.mystuff() ... end is legal however, there is no guarantee that future versions of luatex will not use the same names as you do; even if (widespread) macropackages will have their tex.myfunction spread all over the world, future luatex's may define its own myfunction in the tex namespace; of course one can save its meaning before redefining it; so ... it is possible but may have future side effects
- How do I generate an error when inside Lua code? I could use tex.write("\\errmessage{...}"), but then the error would only be generated after the Lua code has finished executing, and after any TeX code created previously using tex.write et.al. has been executed.
- assert - just print messages using texio.write_nl - os.exit() also works
- How do I access control sequences from Lua code? If I have a macro \test, how would I get the tokens of this macro when inside Lua? (without passing them from TeX) Is there a table tex.macro, just like the tex.count, tex.toks etc. tables?
no, you print them to tex using tex.print and tex.sprint; you're either is lua or in tex; something in between would become extremely messy 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 -----------------------------------------------------------------
Hello, thanks for your quick reply!
[...]
- How do I generate an error when inside Lua code? I could use tex.write("\\errmessage{...}"), but then the error would only be generated after the Lua code has finished executing, and after any TeX code created previously using tex.write et.al. has been executed.
- assert - just print messages using texio.write_nl - os.exit() also works
The last one is a bit radical ;-) I was hoping to be able to say i.e. "error(message,help)" and get TeX's error prompt where the user can decide how to proceed.
- How do I access control sequences from Lua code? If I have a macro \test, how would I get the tokens of this macro when inside Lua? (without passing them from TeX) Is there a table tex.macro, just like the tex.count, tex.toks etc. tables?
no, you print them to tex using tex.print and tex.sprint; you're either is lua or in tex; something in between would become extremely messy
But what about the other way round? What if I do not want to define control sequences, but access their meaning from Lua code, just as it is possible with registers? Is there a way? Jonathan
Jonathan Sauer wrote: > Hello, > > thanks for your quick reply! > >> [...] >>> - How do I generate an error when inside Lua code? I could use >>> tex.write("\\errmessage{...}"), but then the error would only be >>> generated after the Lua code has finished executing, and after >>> any TeX code created previously using tex.write et.al. has >>> been executed. >> - assert >> - just print messages using texio.write_nl >> - os.exit() also works > > The last one is a bit radical ;-) > > I was hoping to be able to say i.e. "error(message,help)" and get TeX's > error prompt where the user can decide how to proceed. revamping the eror handling mechanism is on the agenda for next year > But what about the other way round? What if I do not want to define > control sequences, but access their meaning from Lua code, just as > it is possible with registers? Is there a way? currently not, also a bit tricky because how to deal with expansion and such, i can imagine tex.meaning to work another solution is a tex.macro that gives back a table with tokens (like tex.toks) but whatver solution is chose, you then have to parse yourself. 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 -----------------------------------------------------------------
Jonathan Sauer wrote: > Hello, > > thanks for your quick reply! > >> [...] >>> - How do I generate an error when inside Lua code? I could use >>> tex.write("\\errmessage{...}"), but then the error would only be >>> generated after the Lua code has finished executing, and after >>> any TeX code created previously using tex.write et.al. has >>> been executed. >> - assert >> - just print messages using texio.write_nl >> - os.exit() also works > > The last one is a bit radical ;-) > > I was hoping to be able to say i.e. "error(message,help)" and get TeX's > error prompt where the user can decide how to proceed. That is not possible right now, but adding a simple interface would be pretty straightforward. However ... influencing the lua interpreter is not doable, so error recovery is impossible (deleting and inserting tokens will be disabled), and the error context will likely be useless. Therefore, it will not be real user interaction, more a "press return to acknowledge that you saw the error". > But what about the other way round? What if I do not want to define > control sequences, but access their meaning from Lua code, just as > it is possible with registers? Is there a way? Not now, but it is planned for the future. Best wishes, Taco
participants (3)
-
Hans Hagen
-
Jonathan Sauer
-
Taco Hoekwater