# Print Latex Code with LuaLatex in function

I want to print Latex Code with a Lua Function. But there is a problem with my function if there are parenthesis in the string: in the example the second code will not be printed), who can help me?

\RequirePackage{luatex85}
\documentclass[a4paper,parskip=half-]{scrartcl}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new, babelshorthands=true]{german}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{luacode}

\begin{luacode*}
function myprint(string)
tex.sprint(string)
end
\end{luacode*}

\newcommand*{\myprint}[1]{\directlua{myprint([[#1]])} }

\begin{document}
\myprint{works fine $\pi\cdot x^2$}
\myprint{doesn't work $\sqrt{2}$}
\end{document}


Ok, i have found a working solution with xparse package:

\usepackage{xparse}


and then using

\NewDocumentCommand{\myprint}{v}
{
\directlua{myprint([[#1]])}
}


The v means verbatim, that makes it work!