I'd like to get the meaning of a LaTeX command in fully expanded form in a lua variable. What is the easiest way of getting there? In other words, what should I be replacing the function getmeaning with?
% !TeX program = lualatex
\documentclass{article}
\usepackage{luacode,luatexbase}
\begin{luacode}
function whatis(s)
s="\\" .. s
x=getmeaning(s)
end
\end{luacode}
\newcommand{\whatis}[1]{\luadirect{whatis(\luastring{#1})}}
\begin{document}
I want the contents of \textbackslash{}foo fully expanded to appear in the Lua variable x.
\whatis{foo}
\end{document}

\def\foo{\def\a{1}\def\b{\a}\def\c{\b}\the\numexpr\a+\b+\c\relax}(to stay simple). What happens if\expandafter\expandafter\expandafter\x\expandafter\string\bis added to contents of\foo? – Oct 01 '17 at 16:58\meaninginto a Lua string simply by\def\whatis#1{\directlua{s="\expandafter\luaescape\expandafter{\meaning#1}"}}...\whatis\foo– David Carlisle Oct 01 '17 at 17:36\edefyou get an error message and no usable document. try\edef\zz{\section{}}given that that gives a fatal error what yould you want\whatis{\section}to do? – David Carlisle Oct 01 '17 at 20:15token.get_macroortoken.get_meaning– ShreevatsaR Feb 23 '18 at 02:35