mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
Change to macro 'LUAI_TRY'
The call to 'f' is done by the macro, to give it more flexibility.
This commit is contained in:
parent
50c7c915ee
commit
682efe2678
14
ldo.c
14
ldo.c
@ -69,22 +69,22 @@
|
|||||||
|
|
||||||
/* C++ exceptions */
|
/* C++ exceptions */
|
||||||
#define LUAI_THROW(L,c) throw(c)
|
#define LUAI_THROW(L,c) throw(c)
|
||||||
#define LUAI_TRY(L,c,a) \
|
#define LUAI_TRY(L,c,f,ud) \
|
||||||
try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
|
try { (f)(L, ud); } catch(...) { if ((c)->status == 0) (c)->status = -1; }
|
||||||
#define luai_jmpbuf int /* dummy variable */
|
#define luai_jmpbuf int /* dummy field */
|
||||||
|
|
||||||
#elif defined(LUA_USE_POSIX) /* }{ */
|
#elif defined(LUA_USE_POSIX) /* }{ */
|
||||||
|
|
||||||
/* in POSIX, try _longjmp/_setjmp (more efficient) */
|
/* in POSIX, try _longjmp/_setjmp (more efficient) */
|
||||||
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
|
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
|
||||||
#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
|
#define LUAI_TRY(L,c,f,ud) if (_setjmp((c)->b) == 0) ((f)(L, ud))
|
||||||
#define luai_jmpbuf jmp_buf
|
#define luai_jmpbuf jmp_buf
|
||||||
|
|
||||||
#else /* }{ */
|
#else /* }{ */
|
||||||
|
|
||||||
/* ISO C handling with long jumps */
|
/* ISO C handling with long jumps */
|
||||||
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
|
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
|
||||||
#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
|
#define LUAI_TRY(L,c,f,ud) if (setjmp((c)->b) == 0) ((f)(L, ud))
|
||||||
#define luai_jmpbuf jmp_buf
|
#define luai_jmpbuf jmp_buf
|
||||||
|
|
||||||
#endif /* } */
|
#endif /* } */
|
||||||
@ -154,9 +154,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
|
|||||||
lj.status = LUA_OK;
|
lj.status = LUA_OK;
|
||||||
lj.previous = L->errorJmp; /* chain new error handler */
|
lj.previous = L->errorJmp; /* chain new error handler */
|
||||||
L->errorJmp = &lj;
|
L->errorJmp = &lj;
|
||||||
LUAI_TRY(L, &lj,
|
LUAI_TRY(L, &lj, f, ud); /* call 'f' catching errors */
|
||||||
(*f)(L, ud);
|
|
||||||
);
|
|
||||||
L->errorJmp = lj.previous; /* restore old error handler */
|
L->errorJmp = lj.previous; /* restore old error handler */
|
||||||
L->nCcalls = oldnCcalls;
|
L->nCcalls = oldnCcalls;
|
||||||
return lj.status;
|
return lj.status;
|
||||||
|
@ -766,6 +766,7 @@ if not _port then
|
|||||||
assert((v[3] == nil and z > 0) or v[3] == z)
|
assert((v[3] == nil and z > 0) or v[3] == z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
print("(done)")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user