\starttext
\startluacode
userdata = userdata or {}
function userdata.simple(c)
context("\\%s{%s}{%s}",c,1,4)
context.par()
context[c](1,4)
end
\stopluacode
\define[1]\tolua{\ctxlua{userdata.simple("#1")}}
\define[2]\simple{-#1#2-}
\simple{22}{55}
% This is what I have to do, because the below causes an error:
\tolua{simple}
% This is what I'd prefer, because the above feels like a confusing mix of Lua and TeX:
\tolua{\simple}
\stoptext
Here we're passing a TeX macro (\simple
) into Lua, then calling it from Lua. It works but the goal is to write \tolua{\simple}
instead of \tolua{simple}
. I think the error I'm getting has to do with the TeX macro being expanded.
\luaescapestring
discards the catcode information however. See e.g. Can the Lua part of LuaTeX know about tokens? - TeX - LaTeX Stack Exchange