Improve compatibility with luaj 1.0

This commit is contained in:
James Roseborough
2010-04-18 21:14:02 +00:00
parent 5a416f177c
commit 494e4206c4
3 changed files with 9 additions and 6 deletions

View File

@@ -204,7 +204,7 @@ public class LuaC extends Lua implements LuaCompiler {
lexstate.open_func(funcstate);
/* main func. is always vararg */
funcstate.f.is_vararg = LuaC.VARARG_ISVARARG;
funcstate.f.source = (LuaString) LuaValue.valueOf("@"+name);
funcstate.f.source = (LuaString) LuaValue.valueOf(name);
lexstate.next(); /* read first token */
lexstate.chunk();
lexstate.check(LexState.TK_EOS);

View File

@@ -204,7 +204,7 @@ public class PackageLib extends OneArgFunction {
if ( e < 0 )
e = fname.m_length;
LuaString key = fname.substring(b, e);
LuaValue val = table.get(key);
LuaValue val = table.rawget(key);
if ( val.isnil() ) { /* no such field? */
LuaTable field = new LuaTable(); /* new table for field */
table.set(key, field);

View File

@@ -22,6 +22,8 @@
package org.luaj.vm2.vm1;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
@@ -55,9 +57,10 @@ public class Luajvm1CompatibilityTest extends TestCase {
private static InputStream open(String file) {
try {
String path = jarpath+file;
URL url = new URL(path);
return url.openStream();
File f = new File(file);
return f.exists()?
new FileInputStream(f):
new URL(jarpath+file).openStream();
} catch ( Exception e ) {
return null;
}
@@ -99,7 +102,7 @@ public class Luajvm1CompatibilityTest extends TestCase {
if ( is == null )
return LuaValue.valueOf("not found: "+file);
try {
return org.luaj.vm2.LoadState.load(is, name, env);
return org.luaj.vm2.LoadState.load(is, file, env);
} catch (IOException e) {
return LuaValue.valueOf(e.toString());
} finally {