Fix xpcall arg check logic.
This commit is contained in:
@@ -330,6 +330,10 @@ public class Print extends Lua {
|
||||
private static String id(Prototype f) {
|
||||
return "Proto";
|
||||
}
|
||||
private void _assert(boolean b) {
|
||||
if ( !b )
|
||||
throw new NullPointerException("_assert failed");
|
||||
}
|
||||
|
||||
public static void printState(LuaClosure cl, int pc, LuaValue[] stack, int top, Varargs varargs) {
|
||||
// print opcode into buffer
|
||||
|
||||
@@ -137,7 +137,8 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
|
||||
if ( arg == null )
|
||||
LuaValue.argerror(1, "invalid level");
|
||||
}
|
||||
return arg.getfenv();
|
||||
LuaValue e = arg.getfenv();
|
||||
return e!=null? e: NIL;
|
||||
}
|
||||
case 1: // "getmetatable", // ( object ) -> table
|
||||
LuaValue mt = arg.getmetatable();
|
||||
@@ -252,13 +253,15 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
|
||||
return varargsOf(FALSE, valueOf(m!=null? m: e.toString()));
|
||||
}
|
||||
case 6: // "xpcall", // (f, err) -> result1, ...
|
||||
{
|
||||
LuaValue errfunc = args.checkvalue(2);
|
||||
try {
|
||||
LuaThread.onCall(this);
|
||||
try {
|
||||
LuaThread thread = LuaThread.getRunning();
|
||||
LuaValue olderr = thread.err;
|
||||
try {
|
||||
thread.err = args.arg(2);
|
||||
thread.err = errfunc;
|
||||
return varargsOf(LuaValue.TRUE, args.arg1().invoke(args.subargs(2)));
|
||||
} finally {
|
||||
thread.err = olderr;
|
||||
@@ -266,11 +269,12 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
|
||||
} finally {
|
||||
LuaThread.onReturn();
|
||||
}
|
||||
} catch ( LuaError le ) {
|
||||
String m = le.getMessage();
|
||||
return varargsOf(FALSE, m!=null? valueOf(m): NIL);
|
||||
} catch ( Exception e ) {
|
||||
try {
|
||||
return args.arg(2).invoke(valueOf(e.getMessage()));
|
||||
} catch ( Exception f ) {
|
||||
return varargsOf(FALSE, valueOf(f.getMessage()));
|
||||
String m = e.getMessage();
|
||||
return varargsOf(FALSE, valueOf(m!=null? m: e.toString()));
|
||||
}
|
||||
}
|
||||
case 7: // "print", // (...) -> void
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.net.URL;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.vm2.LuaThread;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
/**
|
||||
@@ -89,6 +90,7 @@ public class Luajvm1CompatibilityTest extends TestCase {
|
||||
PrintStream printStream = new PrintStream( outputStream );
|
||||
try {
|
||||
org.luaj.vm2.LuaTable _G = org.luaj.vm2.lib.JsePlatform.standardGlobals();
|
||||
LuaThread.getRunning().setfenv(_G);
|
||||
_G.get("package").get("loaders").checktable().insert(1, new org.luaj.vm2.lib.OneArgFunction(_G) {
|
||||
public LuaValue call(LuaValue arg) {
|
||||
String name = arg.toString();
|
||||
|
||||
Reference in New Issue
Block a user