Add back stack traces when debug is installed and new error message handler is defined.
This commit is contained in:
@@ -19,7 +19,7 @@ Getting Started with LuaJ
|
|||||||
James Roseborough, Ian Farmer, Version 3.0-beta2
|
James Roseborough, Ian Farmer, Version 3.0-beta2
|
||||||
<p>
|
<p>
|
||||||
<small>
|
<small>
|
||||||
Copyright © 2009-2013 Luaj.org.
|
Copyright © 2009-2014 Luaj.org.
|
||||||
Freely available under the terms of the
|
Freely available under the terms of the
|
||||||
<a href="http://sourceforge.net/dbimage.php?id=196142">Luaj license</a>.
|
<a href="http://sourceforge.net/dbimage.php?id=196142">Luaj license</a>.
|
||||||
</small>
|
</small>
|
||||||
|
|||||||
@@ -518,26 +518,28 @@ public class LuaClosure extends LuaFunction {
|
|||||||
* Run the error hook if there is one
|
* Run the error hook if there is one
|
||||||
* @param msg the message to use in error hook processing.
|
* @param msg the message to use in error hook processing.
|
||||||
* */
|
* */
|
||||||
String errorHook(String msg) {
|
String errorHook(String msg, int level) {
|
||||||
if (globals == null ) return msg;
|
if (globals == null ) return msg;
|
||||||
final LuaThread running = globals.running;
|
final LuaThread r = globals.running;
|
||||||
if (running == null) return msg;
|
if (r.errorfunc == null)
|
||||||
final LuaValue errfunc = running.errorfunc;
|
return globals.debuglib != null?
|
||||||
if (errfunc == null) return msg;
|
msg + "\n" + globals.debuglib.traceback(level):
|
||||||
running.errorfunc = null;
|
msg;
|
||||||
|
final LuaValue e = r.errorfunc;
|
||||||
|
r.errorfunc = null;
|
||||||
try {
|
try {
|
||||||
return errfunc.call( LuaValue.valueOf(msg) ).tojstring();
|
return e.call( LuaValue.valueOf(msg) ).tojstring();
|
||||||
} catch ( Throwable t ) {
|
} catch ( Throwable t ) {
|
||||||
return "error in error handling";
|
return "error in error handling";
|
||||||
} finally {
|
} finally {
|
||||||
running.errorfunc = errfunc;
|
r.errorfunc = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processErrorHooks(LuaError le, Prototype p, int pc) {
|
private void processErrorHooks(LuaError le, Prototype p, int pc) {
|
||||||
le.fileline = (p.source != null? p.source.tojstring(): "?") + ":"
|
le.fileline = (p.source != null? p.source.tojstring(): "?") + ":"
|
||||||
+ (p.lineinfo != null && pc >= 0 && pc < p.lineinfo.length? String.valueOf(p.lineinfo[pc]): "?");
|
+ (p.lineinfo != null && pc >= 0 && pc < p.lineinfo.length? String.valueOf(p.lineinfo[pc]): "?");
|
||||||
le.traceback = errorHook(le.getMessage());
|
le.traceback = errorHook(le.getMessage(), le.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
||||||
|
|||||||
Reference in New Issue
Block a user