This should work to set globals in the Lua virtual machine:
Function SetScriptObject(name:String,o:Object)
Local size:Int=GetStackSize()
lua_pushbmaxobject(luastate.L,o)
lua_setglobal(luastate.L,name)
SetStackSize(size)
EndFunction
Function GetStackSize:Int()
Return lua_gettop(luastate.L)
EndFunction
Function SetStackSize(size:Int)
Local currentsize:Int=GetStackSize()
If size<currentsize
lua_pop(luastate.L,currentsize-size)
EndIf
EndFunction