Add loadstring and other standard library commands (untested)

This commit is contained in:
James Roseborough
2007-09-15 00:51:30 +00:00
parent 6d0e9bb566
commit 5efda81b17
3 changed files with 177 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ import java.io.OutputStream;
import java.io.PrintStream;
import lua.value.LFunction;
import lua.value.LNil;
import lua.value.LTable;
import lua.value.LValue;
@@ -17,13 +18,19 @@ final class Builtin extends LFunction {
table.put( NAMES[i], new Builtin(i) );
}
private static final String[] NAMES = {
"print",
"pairs",
"getmetatable",
"setmetatable",
"type",
"pcall" };
private static final int PRINT = 0;
private static final int PAIRS = 1;
private static final int GETMETATABLE = 2;
private static final int SETMETATABLE = 3;
private static final int TYPE = 4;
private static final String[] NAMES = { "print", "pairs", "getmetatable", "setmetatable", "type" };
private static final int PCALL = 5;
private static PrintStream stdout = System.out;
@@ -63,6 +70,10 @@ final class Builtin extends LFunction {
case TYPE:
vm.setResult( vm.getArg(0).luaGetType() );
break;
case PCALL:
// TODO: implement pcall
vm.setResult( LNil.NIL );
break;
default:
luaUnsupportedOperation();
}

View File

@@ -140,4 +140,10 @@ public interface VM {
*/
public void setResult(LValue val);
/**
* Generates a Lua error. The error message(which can actually be a Lua value of any type)
* must be on the top of the stack.
*/
public void lua_error();
}