Improve compatibility with vm1 and C-based lua.
This commit is contained in:
@@ -107,7 +107,7 @@ public class LuaValue extends Varargs {
|
||||
public Object touserdata() { return null; }
|
||||
public Object touserdata(Class c) { return null; }
|
||||
|
||||
// object tojstring() maps to tojstring()
|
||||
// Object.toString() maps to tojstring()
|
||||
public String toString() { return tojstring(); }
|
||||
|
||||
// type coercion to lua values
|
||||
@@ -519,9 +519,6 @@ public class LuaValue extends Varargs {
|
||||
public LuaValue arg1() {
|
||||
return v1;
|
||||
}
|
||||
public String tojstring() {
|
||||
return "{"+v1+","+v2+"}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -143,6 +143,9 @@ public abstract class Varargs {
|
||||
sb.append( ")" );
|
||||
return sb.tojstring();
|
||||
}
|
||||
|
||||
// Object.toString() maps to tojstring()
|
||||
public String toString() { return tojstring(); }
|
||||
|
||||
public Varargs subargs(final int start) {
|
||||
int end = narg();
|
||||
|
||||
@@ -22,9 +22,12 @@
|
||||
package org.luaj.vm2.lib;
|
||||
|
||||
import org.luaj.vm2.Lua;
|
||||
import org.luaj.vm2.LuaBoolean;
|
||||
import org.luaj.vm2.LuaClosure;
|
||||
import org.luaj.vm2.LuaError;
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaNil;
|
||||
import org.luaj.vm2.LuaNumber;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaThread;
|
||||
@@ -534,10 +537,15 @@ public class DebugLib extends OneArgFunction {
|
||||
private static Varargs _setmetatable(Varargs args) {
|
||||
LuaValue object = args.arg(1);
|
||||
try {
|
||||
if ( ! args.isnoneornil(2) )
|
||||
object.setmetatable(args.checktable(2));
|
||||
else
|
||||
object.setmetatable(null);
|
||||
LuaValue mt = args.opttable(2, null);
|
||||
switch ( object.type() ) {
|
||||
case TNIL: LuaNil.s_metatable = mt; break;
|
||||
case TNUMBER: LuaNumber.s_metatable = mt; break;
|
||||
case TBOOLEAN: LuaBoolean.s_metatable = mt; break;
|
||||
case TSTRING: LuaString.s_metatable = mt; break;
|
||||
case TFUNCTION: LuaFunction.s_metatable = mt; break;
|
||||
default: object.setmetatable( mt );
|
||||
}
|
||||
return LuaValue.TRUE;
|
||||
} catch ( LuaError e ) {
|
||||
return varargsOf(FALSE, valueOf(e.toString()));
|
||||
|
||||
@@ -126,7 +126,7 @@ public class lua {
|
||||
break;
|
||||
} else if ( "-".equals( args[i] ) ) {
|
||||
setGlobalArg( _G, args, i );
|
||||
processScript( System.in, "stdin" );
|
||||
processScript( System.in, "=stdin" );
|
||||
break;
|
||||
} else {
|
||||
switch ( args[i].charAt(1) ) {
|
||||
@@ -202,7 +202,7 @@ public class lua {
|
||||
String line = reader.readLine();
|
||||
if ( line == null )
|
||||
return;
|
||||
processScript( new ByteArrayInputStream(line.getBytes()), "stdin" );
|
||||
processScript( new ByteArrayInputStream(line.getBytes()), "=stdin" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class luac {
|
||||
String chunkname = args[i].substring(0,args[i].length()-4);
|
||||
processScript( new FileInputStream(args[i]), chunkname, fos );
|
||||
} else if ( args[i].length() <= 1 ) {
|
||||
processScript( System.in, "stdin", fos );
|
||||
processScript( System.in, "=stdin", fos );
|
||||
} else {
|
||||
switch ( args[i].charAt(1) ) {
|
||||
case 'o':
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ScriptDrivenTest extends TestCase {
|
||||
default:
|
||||
case JSE:
|
||||
case LUAJIT:
|
||||
_G = org.luaj.vm2.lib.JsePlatform.standardGlobals();
|
||||
_G = org.luaj.vm2.lib.JsePlatform.debugGlobals();
|
||||
break;
|
||||
case JME:
|
||||
_G = org.luaj.vm2.lib.JmePlatform.debugGlobals();
|
||||
@@ -115,7 +115,7 @@ public class ScriptDrivenTest extends TestCase {
|
||||
}
|
||||
default:
|
||||
script = new FileInputStream(file);
|
||||
return LoadState.load(script, "stdin", _G);
|
||||
return LoadState.load(script, "=stdin", _G);
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Luajvm1CompatibilityTest extends TestCase {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream( outputStream );
|
||||
try {
|
||||
org.luaj.vm2.LuaTable _G = org.luaj.vm2.lib.JsePlatform.standardGlobals();
|
||||
org.luaj.vm2.LuaTable _G = org.luaj.vm2.lib.JsePlatform.debugGlobals();
|
||||
LuaThread.getRunning().setfenv(_G);
|
||||
_G.get("package").get("loaders").checktable().insert(1, new org.luaj.vm2.lib.OneArgFunction(_G) {
|
||||
public LuaValue call(LuaValue arg) {
|
||||
|
||||
Binary file not shown.
@@ -114,8 +114,8 @@ print( 'get='..tostring(s4)..','..tostring(x4==nil)..','..tostring(y4) )
|
||||
print( 'set='..tostring(s5)..','..tostring(x5==a)..','..tostring(y5) )
|
||||
print( 'get='..tostring(s6)..','..tostring(x6==nil)..','..tostring(y6) )
|
||||
print( pcall( debug.getmetatable, 1 ) )
|
||||
-- print( pcall( debug.setmetatable, 1, {} ) )
|
||||
-- print( pcall( debug.setmetatable, 1, nil ) )
|
||||
print( pcall( debug.setmetatable, 1, {} ) )
|
||||
print( pcall( debug.setmetatable, 1, nil ) )
|
||||
|
||||
print( '----- debug.getinfo' )
|
||||
local printfield = function(tbl, field)
|
||||
@@ -126,10 +126,6 @@ local printfield = function(tbl, field)
|
||||
x = '{'..table.concat(x,',')..'}'
|
||||
elseif typ=='function' then
|
||||
x = typ
|
||||
elseif typ=='string' then
|
||||
if field == 'source' then
|
||||
x = x:sub(2)
|
||||
end
|
||||
end
|
||||
print( ' '..field..': '..tostring(x) )
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user