8

When there is \directlua{x = 25} one can say \edef\rgf{\directlua{tex.sprint(x)}}, but when x was never created by \directlua{x = 25}, \directlua{tex.sprint(x)} will fail. Thus something like \@ifundefined{x}{x undefined}{x defined} would be nice. How does one "say this in Lua", please?

  • 3
    May be you 'd try reading some general lua programming documentation first. – Khaled Hosny Nov 3 '11 at 14:28
  • @KhaledHosny: I tried but did not find it there. Any suggestion for better lua-documentation? – Stephen Nov 3 '11 at 17:56
12

You can do this:

\directlua{tex.sprint( x or 42 ) }

or perhaps

\directlua{
  if x then
    tex.sprint(x)
  % else
    % do something else
  end
}
  • 1
    But see also the question about using luacode and \directlua{} – topskip Nov 3 '11 at 12:31
  • Thanks, it works! (Upvoted & accepted.) Also your answer to the other question is enlightening, but unfortunately with that question title one does not find it without being told that it is there. – Stephen Nov 3 '11 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.