Fixed issue: #94
This commit is contained in:
@@ -591,19 +591,19 @@ 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, int level) {
|
LuaValue errorHook(LuaValue msgobj, String msg, int level) {
|
||||||
if (globals == null ) return msg;
|
if (globals == null ) return LuaValue.valueOf(msg);
|
||||||
final LuaThread r = globals.running;
|
final LuaThread r = globals.running;
|
||||||
if (r.errorfunc == null)
|
if (r.errorfunc == null)
|
||||||
return globals.debuglib != null?
|
return LuaValue.valueOf(globals.debuglib != null?
|
||||||
msg + "\n" + globals.debuglib.traceback(level):
|
msg + "\n" + globals.debuglib.traceback(level):
|
||||||
msg;
|
msg);
|
||||||
final LuaValue e = r.errorfunc;
|
final LuaValue e = r.errorfunc;
|
||||||
r.errorfunc = null;
|
r.errorfunc = null;
|
||||||
try {
|
try {
|
||||||
return e.call( LuaValue.valueOf(msg) ).tojstring();
|
return e.call(msgobj != null ? msgobj : LuaValue.NIL);
|
||||||
} catch ( Throwable t ) {
|
} catch ( Throwable t ) {
|
||||||
return "error in error handling";
|
return LuaValue.valueOf("error in error handling");
|
||||||
} finally {
|
} finally {
|
||||||
r.errorfunc = e;
|
r.errorfunc = e;
|
||||||
}
|
}
|
||||||
@@ -628,7 +628,9 @@ public class LuaClosure extends LuaFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
le.fileline = file + ":" + line;
|
le.fileline = file + ":" + line;
|
||||||
le.traceback = errorHook(le.getMessage(), le.level);
|
LuaValue error = errorHook(le.getMessageObject(), le.getMessage(), le.level);
|
||||||
|
le.setMessageObject(error);
|
||||||
|
le.traceback = error != null ? error.tojstring() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
||||||
@@ -656,4 +658,4 @@ public class LuaClosure extends LuaFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ public class LuaError extends RuntimeException {
|
|||||||
String m = getMessage();
|
String m = getMessage();
|
||||||
return m != null ? LuaValue.valueOf(m): null;
|
return m != null ? LuaValue.valueOf(m): null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMessageObject(LuaValue messageObject) {
|
||||||
|
this.object = messageObject;
|
||||||
|
}
|
||||||
|
|
||||||
/** Construct LuaError when a program exception occurs.
|
/** Construct LuaError when a program exception occurs.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -591,6 +591,17 @@ public class FragmentsTest extends TestSuite {
|
|||||||
runFragment(LuaValue.varargsOf(LuaValue.valueOf("boolean"), LuaValue.TRUE),
|
runFragment(LuaValue.varargsOf(LuaValue.valueOf("boolean"), LuaValue.TRUE),
|
||||||
"a,b = pcall(error, true); return type(b), b\n");
|
"a,b = pcall(error, true); return type(b), b\n");
|
||||||
}
|
}
|
||||||
|
public void testXpcallHandlerResultReplacesStringError() {
|
||||||
|
runFragment(LuaValue.varargsOf(LuaValue.valueOf("table"), LuaValue.valueOf(1)),
|
||||||
|
"local ok, err = xpcall(function() error('oh no') end, function(e) return { marker = 1, original = e } end)\n" +
|
||||||
|
"return type(err), err.marker\n");
|
||||||
|
}
|
||||||
|
public void testXpcallHandlerGetsOriginalErrorObject() {
|
||||||
|
runFragment(LuaValue.varargsOf(LuaValue.valueOf("table"), LuaValue.valueOf(1)),
|
||||||
|
"local source = { marker = 1 }\n" +
|
||||||
|
"local ok, err = xpcall(function() error(source) end, function(e) return e end)\n" +
|
||||||
|
"return type(err), err.marker\n");
|
||||||
|
}
|
||||||
public void testBalancedMatchOnEmptyString() {
|
public void testBalancedMatchOnEmptyString() {
|
||||||
runFragment(LuaValue.NIL, "return (\"\"):match(\"%b''\")\n");
|
runFragment(LuaValue.NIL, "return (\"\"):match(\"%b''\")\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user