lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

于 2011-8-28 9:11, HyperHacker 写道:
On Sat, Aug 27, 2011 at 17:03, Joshua Jensen<>  wrote:

* A hook to catch errors, allowing the debugger to break at the point of
error in the code and allow the user to investigate further.
* The ability to expand varargs.

The patch is below.  Does Lua 5.2 expose facilities for this now?

  static void funcinfo (lua_Debug *ar, Closure *cl) {
   if (cl->c.isC) {
@@ -608,6 +626,8 @@
     luaD_call(L, L->top - 2, 1);  /* call it */
+  if (L->hookmask&  LUA_MASKERROR)
+    luaD_callhook(L, LUA_HOOKERROR, -1);
   luaD_throw(L, LUA_ERRRUN);

These seem like quite useful extensions, although I'm not sure what
the difference is between the error hook and the handler set by

according to the patch, the hook is called before the error is thrown out, while the handler of xpcall is called after the error thrown.
or in another word, this hook is called at the error point, while the handler of xpcall is called at the recover point.

although it seems trivial, I think it does make diffrences to a debugger, e.g., to examine the detailed status and environment of the error.

so I think this hook is useful, especially for a debugger.

Joshua might also use this feature for other uses in his debugger.