I'm trying to build some sort of an interface to a lua matrix module. I've navigated a few issues and arrived at something that I felt like I could probably modify to work. Anticipating the need for expl3 functions as some point I wrapped the macro in \ExplSyntaxOn and \ExplSyntaxOff expecting a total catcode disaster. Rather I got an error relating to 'global' and 'nil value'. I am very much fumbling my way through this so, I don't have the tools to understand why what I did was bad. In the code below, the wrapper function spits out a matrix, however, when uncommenting an \ExplSyntaxOn/Off pair the error mentioned above occurs. If needed, the matrix.lua file can be found here:
https://raw.github.com/davidm/lua-matrix/master/lua/matrix.lua
\documentclass{article}
\usepackage{xparse}
\usepackage{luacode}
\usepackage{fontspec}
%\ExplSyntaxOn
\directlua{dofile("matrix.lua")}
%\ExplSyntaxOn
\NewDocumentCommand{\matrixop}{}
{
\luaexec{
local matrix = require 'matrix'
m1 = matrix{{8,4,1},{6,8,3}}
m2 = matrix{{-8,1,3},{5,2,1}}
m3 = matrix.add(m1,m2)
a=matrix.latex(m3,c)
tex.print(a)
}
}
%\ExplSyntaxOff
\begin{document}
\matrixop{}
\end{document}