Lua 5.2 compatibility updates to VM and base and package libraries.

This commit is contained in:
James Roseborough
2012-09-06 04:01:28 +00:00
parent 41d9dd6176
commit a5fddce465
18 changed files with 244 additions and 328 deletions

View File

@@ -30,10 +30,13 @@ import java.util.Vector;
import org.luaj.vm2.LoadState;
import org.luaj.vm2.Lua;
import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Print;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.DebugLib;
import org.luaj.vm2.lib.jse.JsePlatform;
import org.luaj.vm2.lua2java.Lua2Java;
import org.luaj.vm2.luajc.LuaJC;
@@ -55,6 +58,7 @@ public class lua {
" -j use lua2java source-to-source compiler\n" +
" -b use luajc bytecode-to-bytecode compiler (requires bcel on class path)\n" +
" -n nodebug - do not load debug library by default\n" +
" -p pretty-print the prototype\n" +
" -- stop handling options\n" +
" - execute stdin and stop handling options";
@@ -72,6 +76,7 @@ public class lua {
boolean versioninfo = false;
boolean processing = true;
boolean nodebug = false;
boolean print = false;
boolean luajc = false;
boolean lua2java = false;
Vector libs = null;
@@ -112,6 +117,9 @@ public class lua {
case 'n':
nodebug = true;
break;
case 'p':
print = true;
break;
case '-':
if ( args[i].length() > 2 )
usageExit();
@@ -190,7 +198,14 @@ public class lua {
try {
LuaFunction c;
try {
c = LoadState.load(script, chunkname, _G);
c = LoadState.load(script, chunkname, "bt", _G);
if (c instanceof LuaClosure) {
LuaClosure closure = (LuaClosure) c;
Print.print(closure.p);
// DebugLib.DEBUG_ENABLED = true;
} else {
System.out.println( "Not a LuaClosure: "+c);
}
} finally {
script.close();
}

View File

@@ -64,7 +64,7 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
LuaValue t = super.call(arg);
bind( t, JseMathLib1.class, new String[] {
"acos", "asin", "atan", "cosh",
"exp", "log", "log10", "sinh",
"exp", "log", "sinh",
"tanh" } );
bind( t, JseMathLib2.class, new String[] {
"atan2", "pow", } );
@@ -80,9 +80,8 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
case 3: return valueOf(Math.cosh(arg.checkdouble()));
case 4: return valueOf(Math.exp(arg.checkdouble()));
case 5: return valueOf(Math.log(arg.checkdouble()));
case 6: return valueOf(Math.log10(arg.checkdouble()));
case 7: return valueOf(Math.sinh(arg.checkdouble()));
case 8: return valueOf(Math.tanh(arg.checkdouble()));
case 6: return valueOf(Math.sinh(arg.checkdouble()));
case 7: return valueOf(Math.tanh(arg.checkdouble()));
}
return NIL;
}

View File

@@ -162,7 +162,7 @@ public class LuaScriptEngine implements ScriptEngine, Compilable {
try {
InputStream ris = new Utf8Encoder(reader);
try {
final LuaFunction f = LoadState.load(ris, "script", null);
final LuaFunction f = LoadState.load(ris, "script", "bt", null);
if ( f.isclosure() ) {
// most compiled functions are closures with prototypes
final Prototype p = f.checkclosure().p;