Exemplo n.º 1
0
        public static int luaD_pcall(lua_State L, Pfunc func, object u,
                                     ptrdiff_t old_top, ptrdiff_t ef)
        {
            int       status;
            CallInfo  old_ci         = L.ci;
            lu_byte   old_allowhooks = L.allowhook;
            ushort    old_nny        = L.nny;
            ptrdiff_t old_errfunc    = L.errfunc;

            L.errfunc = ef;
            status    = luaD_rawrunprotected(L, func, u);
            if (status != LUA_OK)          /* an error occurred? */
            {
                StkId oldtop = restorestack(L, old_top);
                luaF_close(L, oldtop);          /* close possible pending closures */
                luaD_seterrorobj(L, status, oldtop);
                L.ci        = old_ci;
                L.allowhook = old_allowhooks;
                L.nny       = old_nny;
                restore_stack_limit(L);
            }
            L.errfunc = old_errfunc;
            return(status);
        }
Exemplo n.º 2
0
        public static int luaD_pcall(lua_State L, Pfunc func, object u,
                                     ptrdiff_t old_top, ptrdiff_t ef)
        {
            int       status;
            ptrdiff_t old_ci         = saveci(L, L.ci);
            lu_byte   old_allowhooks = L.allowhook;
            ptrdiff_t old_errfunc    = L.errfunc;

            L.errfunc = ef;
            status    = luaD_rawrunprotected(L, func, u);
            if (status != LUA_OK)          /* an error occurred? */
            {
                StkId oldtop = restorestack(L, old_top);
                luaF_close(L, oldtop);          /* close possible pending closures */
                luaD_seterrorobj(L, status, oldtop);
                L.ci    = restoreci(L, old_ci);
                L.base_ = L.ci.base_;
                InstructionPtr.Assign(L.ci.savedpc, ref L.savedpc);
                L.allowhook = old_allowhooks;
                restore_stack_limit(L);
            }
            L.errfunc = old_errfunc;
            return(status);
        }
Exemplo n.º 3
0
 public static int LuaDRawRunProtected(LuaState L, Pfunc f, object ud)
 {
     LuaLongJmp lj = new LuaLongJmp();
     lj.status = 0;
     lj.previous = L.errorJmp;  /* chain new error handler */
     L.errorJmp = lj;
     /*
       LUAI_TRY(L, lj,
     f(L, ud)
       );
      * */
     try
     {
         f(L, ud);
     }
     catch
     {
         if (lj.status == 0)
             lj.status = -1;
     }
     L.errorJmp = lj.previous;  /* restore old error handler */
     return lj.status;
 }
Exemplo n.º 4
0
 public static int LuaDPCall(LuaState L, Pfunc func, object u,
                 ptrdiff_t old_top, ptrdiff_t ef)
 {
     int status;
     ushort oldnCcalls = L.nCcalls;
     ptrdiff_t old_ci = SaveCI(L, L.ci);
     LuaByteType old_allowhooks = L.allowhook;
     ptrdiff_t old_errfunc = L.errfunc;
     L.errfunc = ef;
     status = LuaDRawRunProtected(L, func, u);
     if (status != 0)
     {  /* an error occurred? */
         StkId oldtop = RestoreStack(L, old_top);
         LuaFClose(L, oldtop);  /* close eventual pending closures */
         LuaDSetErrorObj(L, status, oldtop);
         L.nCcalls = oldnCcalls;
         L.ci = RestoreCI(L, old_ci);
         L.base_ = L.ci.base_;
         L.savedpc = InstructionPtr.Assign(L.ci.savedpc);
         L.allowhook = old_allowhooks;
         RestoreStackLimit(L);
     }
     L.errfunc = old_errfunc;
     return status;
 }
Exemplo n.º 5
0
 public static int luaD_pcall (lua_State L, Pfunc func, object u,
                               ptrdiff_t old_top, ptrdiff_t ef) {
     int status;
     ushort oldnCcalls = L.nCcalls;
     ptrdiff_t old_ci = saveci(L, L.ci);
     lu_byte old_allowhooks = L.allowhook;
     ptrdiff_t old_errfunc = L.errfunc;
     L.errfunc = ef;
     status = luaD_rawrunprotected(L, func, u);
     if (status != 0) {  /* an error occurred? */
         StkId oldtop = restorestack(L, old_top);
         luaF_close(L, oldtop);  /* close eventual pending closures */
         luaD_seterrorobj(L, status, oldtop);
         L.nCcalls = oldnCcalls;
         L.ci = restoreci(L, old_ci);
         L.base_ = L.ci.base_;
         L.savedpc = InstructionPtr.Assign(L.ci.savedpc);
         L.allowhook = old_allowhooks;
         restore_stack_limit(L);
     }
     L.errfunc = old_errfunc;
     return status;
 }
Exemplo n.º 6
0
        public static int luaD_rawrunprotected (lua_State L, Pfunc f, object ud) {
            lua_longjmp lj = new lua_longjmp();
            lj.status = 0;
            lj.previous = L.errorJmp;  /* chain new error handler */
            L.errorJmp = lj;
            /*
		  LUAI_TRY(L, lj,
			f(L, ud)
		  );
             * */
            #if CATCH_EXCEPTIONS
            try
                #endif
            {
                f(L, ud);
            }
            #if CATCH_EXCEPTIONS
            catch
            {
                if (lj.status == 0)
                    lj.status = -1;
            }
            #endif
            L.errorJmp = lj.previous;  /* restore old error handler */
            return lj.status;
        }
Exemplo n.º 7
0
        public static int luaD_rawrunprotected(LuaState L, Pfunc f, object ud)
        {
            lua_longjmp lj = new lua_longjmp();
            lj.status = 0;
            lj.previous = L.errorJmp;  /* chain new error handler */
            L.errorJmp = lj;
            /*
		  LUAI_TRY(L, lj,
			f(L, ud)
		  );
             * */
#if CATCH_EXCEPTIONS
            try
#endif
            {
                f(L, ud);
            }
#if CATCH_EXCEPTIONS
            catch (LuaException ex)
            {
                Debug.WriteLine("Caught exception: " + ex.ToString());
                Debug.WriteLine("Status: " + ex.c.status);
                
                if (lj.status == 0)
                    lj.status = -1;
            }
            /*catch (Exception ex)
            {
                Debug.WriteLine("Caught exception: " + ex.ToString());

                throw ex;
                //if (lj.status == 0)
                //    lj.status = -1;
            }*/
#endif
            L.errorJmp = lj.previous;  /* restore old error handler */
            return lj.status;
        }
 public static int luaD_rawrunprotected(lua_State L, Pfunc f, object ud)
 {
     lua_longjmp lj = new lua_longjmp();
       lj.status = 0;
       lj.previous = L.errorJmp;  /* chain new error handler */
       L.errorJmp = lj;
     /*
       LUAI_TRY(L, lj,
     f(L, ud)
       );
      * */
     #if CATCH_EXCEPTIONS
       try
     #endif
       {
       f(L, ud);
       }
     #if CATCH_EXCEPTIONS
       catch(LuaException e)
       {
       if (lj.status == 0)
           lj.status = -1;
       }
       catch(Exception e) {
         Console.WriteLine("uncaught {0}",e);
         Console.WriteLine("at {0} {1}",c_lexstate.source,c_lexstate.linenumber);
     }
     #endif
       L.errorJmp = lj.previous;  /* restore old error handler */
       return lj.status;
 }