/** * */ package lua; import java.io.OutputStream; import java.io.PrintStream; import lua.value.LTable; import lua.value.LValue; final class Builtin extends JavaFunction { static void addBuiltins(LTable table) { for ( int i=0; i 1 ) stdout.print( "\t" ); stdout.print( vm.topointer(i).toJavaString() ); } stdout.println(); return 0; } case PAIRS: case IPAIRS: { LValue v = vm.topointer(1); LValue r = v.luaPairs(id==PAIRS); vm.pushlvalue( r ); return 1; } case GETMETATABLE: return vm.getmetatable(1); case SETMETATABLE: vm.setmetatable(1); return 1; case TYPE: { LValue v = vm.topointer(1); vm.pushlstring( v.luaGetTypeName() ); return 1; } case PCALL: { int n = vm.gettop(); int s = vm.pcall( n-1, Lua.LUA_MULTRET, 0 ); if ( s == 0 ) { // success vm.pushboolean( true ); vm.insert( 1 ); return vm.gettop(); } else { // error, error message is on the stack vm.pushboolean( false ); vm.insert( -2 ); 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; } } static void redirectOutput( OutputStream newStdOut ) { stdout = new PrintStream( newStdOut ); } static void restoreStandardOutput() { stdout = System.out; } }