Hi,
I'm not sure where or why your code is failing but in all the code you've posted you've done absolutely no error checking....and that's spells trouble.

Have a look at all the Lua APIs...like this example:

Code:
LUA Syntax: 
retval, rc = mc.mcCntlGetLocalVar(
		number mInst, 
		number hVars, 
		number varNumber)


Note that the function has two outputs, retval (return value) and rc (return code). You should test the return code for error for each and EVERY API call....after all thats what they are
for. If you don't test each return code how do you know that the function executed?

Craig