This question has reference to the question Error with Lua, Luamplib and Mpgraph I am trying to use lua functions inside mplib. The detailed code is here.
\documentclass{article}
\usepackage{luacode}
\usepackage{luamplib}
\begin{document}
\begin{luacode}
require("math")
local sin=math.sin;
\end{luacode}
\def\plot{%
\directlua{
luamplib.process_mplibcode([[
input graph ;
beginfig(0)
draw begingraph(5cm,3cm)
gdraw (0,sin(0)) for x = 1 upto 3: .. (x, sin(x)) endfor ;
endgraph ;
endfig ;
]])}%
}
\plot
\end{document}
There seems some problem with intermingling of lua and mplib. Where would be the problem and how can this be corrected?
luacode
will magically become available insideprocess_mplibcode
?