\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{luafunction2.lua}
function joinstring (s, t)
tex.sprint(tostring(s) .. tostring(t))
end
\end{filecontents*}
\directlua{require "luafunction2.lua"}
\begin{document}
\newcommand\joinstring[2]
{%
\directlua{joinstring(
\luaescapestring{\unexpanded{#1}},
\luaescapestring{\unexpanded{#2}})
}%
}
\joinstring{foo"}{bar}
\end{document}