Add tests for pcall, add error() builtin, fix assert(), error levels.

This commit is contained in:
James Roseborough
2007-10-23 00:34:04 +00:00
parent 8248cca2bf
commit 932960c846
12 changed files with 92 additions and 49 deletions

View File

@@ -24,6 +24,8 @@ final class Builtin extends JavaFunction {
"type",
"pcall",
"ipairs",
"error",
"assert",
};
private static final int PRINT = 0;
private static final int PAIRS = 1;
@@ -32,6 +34,8 @@ final class Builtin extends JavaFunction {
private static final int TYPE = 4;
private static final int PCALL = 5;
private static final int IPAIRS = 6;
private static final int ERROR = 7;
private static final int ASSERT = 8;
private static PrintStream stdout = System.out;
@@ -90,6 +94,16 @@ final class Builtin extends JavaFunction {
return 2;
}
}
case ERROR: {
vm.error(vm.tostring(1), vm.gettop()>1? vm.tointeger(2): 1);
}
case ASSERT: {
if ( ! vm.toboolean(1) ) {
vm.error( vm.gettop()>1? vm.tostring(2): "assertion failed!", 0 );
} else {
return vm.gettop();
}
}
default:
luaUnsupportedOperation();
return 0;