Convert to new JavaFunction api
This commit is contained in:
@@ -6,13 +6,10 @@ package lua;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import lua.value.LBoolean;
|
|
||||||
import lua.value.LFunction;
|
|
||||||
import lua.value.LNil;
|
|
||||||
import lua.value.LTable;
|
import lua.value.LTable;
|
||||||
import lua.value.LValue;
|
import lua.value.LValue;
|
||||||
|
|
||||||
final class Builtin extends LFunction {
|
final class Builtin extends JavaFunction {
|
||||||
|
|
||||||
static void addBuiltins(LTable table) {
|
static void addBuiltins(LTable table) {
|
||||||
for ( int i=0; i<NAMES.length; i++ )
|
for ( int i=0; i<NAMES.length; i++ )
|
||||||
@@ -48,50 +45,55 @@ final class Builtin extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public boolean luaStackCall(VM vm) {
|
/**
|
||||||
|
* Invoke a builtin
|
||||||
|
*/
|
||||||
|
public int invoke(VM vm) {
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case PRINT: {
|
case PRINT: {
|
||||||
int n = vm.getArgCount();
|
int n = vm.gettop();
|
||||||
for ( int i=0; i<n; i++ ) {
|
for ( int i=1; i<=n; i++ ) {
|
||||||
if ( i > 0 )
|
if ( i > 1 )
|
||||||
stdout.print( "\t" );
|
stdout.print( "\t" );
|
||||||
stdout.print( vm.getArg(i).luaAsString() );
|
stdout.print( vm.topointer(i).luaAsString() );
|
||||||
}
|
|
||||||
stdout.println();
|
|
||||||
vm.setResult();
|
|
||||||
}
|
}
|
||||||
break;
|
stdout.println();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
case PAIRS:
|
case PAIRS:
|
||||||
case IPAIRS:
|
case IPAIRS: {
|
||||||
vm.setResult( vm.getArg(0).luaPairs(id==PAIRS) );
|
LValue v = vm.topointer(1);
|
||||||
break;
|
LValue r = v.luaPairs(id==PAIRS);
|
||||||
|
vm.pushlvalue( r );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
case GETMETATABLE:
|
case GETMETATABLE:
|
||||||
vm.setResult( vm.getArg(0).luaGetMetatable() );
|
return vm.getmetatable(1);
|
||||||
break;
|
|
||||||
case SETMETATABLE:
|
case SETMETATABLE:
|
||||||
LValue t = vm.getArg(0);
|
vm.setmetatable(1);
|
||||||
t.luaSetMetatable(vm.getArg(1));
|
return 1;
|
||||||
vm.setResult( t );
|
case TYPE: {
|
||||||
break;
|
LValue v = vm.topointer(1);
|
||||||
case TYPE:
|
vm.pushlstring( v.luaGetTypeName() );
|
||||||
vm.setResult( vm.getArg(0).luaGetTypeName() );
|
return 1;
|
||||||
break;
|
}
|
||||||
case PCALL: {
|
case PCALL: {
|
||||||
int n = vm.getArgCount();
|
int n = vm.gettop();
|
||||||
int s = vm.pcall( n-1, Lua.LUA_MULTRET, 0 );
|
int s = vm.pcall( n-1, Lua.LUA_MULTRET, 0 );
|
||||||
if ( s != 0 ) {
|
if ( s == 0 ) { // success
|
||||||
LValue v = vm.topointer(-1);
|
vm.pushboolean( true );
|
||||||
vm.setResult( LBoolean.FALSE );
|
vm.insert( 1 );
|
||||||
vm.push( v );
|
return vm.gettop();
|
||||||
} else {
|
} else { // error, error message is on the stack
|
||||||
vm.setResult( LBoolean.TRUE );
|
vm.pushboolean( false );
|
||||||
}
|
vm.insert( -2 );
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
default:
|
||||||
luaUnsupportedOperation();
|
luaUnsupportedOperation();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void redirectOutput( OutputStream newStdOut ) {
|
static void redirectOutput( OutputStream newStdOut ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user