When --shell-escape is enabled, pdfTeX allows to run external programs and input the result expandably with \input|"...". Together with the Lua interpreter texlua, this could be used to provide a dumbed down version of \directlua. However, texlua expects a file name as its argument.
In my setup (Ubuntu 10.04, with up-to-date TeXLive 2012 install), one can run pdftex --shell-escape on
\everyeof{\noexpand}
\message{\input|"echo print\string\(3.4+5.7\string\) > tmp.lua ; texlua tmp.lua" a}
\bye
to get \message{9.1}. Note that the \everyeof{\noexpand} is in part for convenience, it would be possible to make the construction work (not entirely robustly) without this non-expandable step.
This approach is not portable because it relies on echo, which probably doesn't exist in Windows environments. One way around this would be to have a simple Lua script taking the code print\string\(3.4+5.7\string\) as its argument (see a recent question on texlua arguments), then somehow performing it. Is this possible? Otherwise, we need an os-dependent approach.
A second problem is that special characters such as parentheses need escaping. Which ones? In particular, I'm worried about quotes ", which are used to enclose the argument of \input|. Given a list of which escapings to perform, I have some code up my sleeve to do that expandably (see the l3kernel-extras package on the LaTeX3 svn repository).
Basically, my question boils down to: "How can I invoke texlua from pdfTeX with arbitrary Lua code as portably as possible?"
echocertainly exists on Windows, although the syntax is slightly different to on *nix. Take a look for example at the LaTeX3make.batfiles ;-) – Joseph Wright Aug 01 '12 at 19:13\message{\input|"echo print(3.4+5.7) > tmp.lua & texlua tmp.lua" a}(ascmd.exedoes not treat parentheses as special and you need to use&to start a second process). Would a solution usingifplatformbe acceptable? – Joseph Wright Aug 01 '12 at 19:22\input|support to XeTeX, and have an expandable quasi-\directlua, of course with no support for interacting with TeX directly. I am very much interested in knowing which characters have to be escaped depending on the platform. – Bruno Le Floch Aug 01 '12 at 19:28>,<and^which are escaped as^>,^<and^^. Unix is more tricky, but this is more about how Unix works than how TeX works. – Joseph Wright Aug 01 '12 at 19:40