Refactor API's related to compiling and loading scripts and character encoding handling.

This commit is contained in:
James Roseborough
2013-09-18 05:32:30 +00:00
parent a552494b72
commit 2123d3f924
35 changed files with 489 additions and 293 deletions

View File

@@ -21,14 +21,10 @@
******************************************************************************/
package org.luaj.luajc;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Print;
import org.luaj.vm2.Prototype;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.jse.JsePlatform;
/** Test the plain old bytecode interpreter */
@@ -51,11 +47,10 @@ public class TestLuaJ {
System.out.println(script);
// create an environment to run in
LuaTable _G = JsePlatform.standardGlobals();
Globals _G = JsePlatform.standardGlobals();
// compile into a chunk, or load as a class
InputStream is = new ByteArrayInputStream( script.getBytes() );
LuaValue chunk = LuaC.instance.load(is, "script", _G);
LuaValue chunk = _G.load(script, "script");
// The loaded chunk should be a closure, which contains the prototype.
print( chunk.checkclosure().p );

View File

@@ -51,14 +51,14 @@ public class TestLuaJC {
_G = JsePlatform.standardGlobals();
// print the chunk as a closure, and pretty-print the closure.
LuaValue f = _G.loadFile(filename).arg1();
LuaValue f = _G.loadfile(filename).arg1();
Prototype p = f.checkclosure().p;
Print.print(p);
// load into a luajc java-bytecode based chunk by installing the LuaJC compiler first
if ( ! (args.length>0 && args[0].equals("nocompile")) ) {
LuaJC.install();
f = _G.loadFile(filename).arg1();
LuaJC.install(_G);
f = _G.loadfile(filename).arg1();
}
// call with arguments
@@ -80,7 +80,7 @@ public class TestLuaJC {
String destdir = ".";
InputStream is = _G.FINDER.findResource(filename);
Hashtable t = LuaJC.getInstance().compileAll(is, filename, filename, true);
Hashtable t = LuaJC.instance.compileAll(is, filename, filename, _G, true);
// write out the chunk
for ( Enumeration e = t.keys(); e.hasMoreElements(); ) {