Update javadoc comments related to library initialization and loading lua code.
This commit is contained in:
@@ -64,17 +64,17 @@ public class FragmentsTest extends TestSuite {
|
||||
public void runFragment( Varargs expected, String script ) {
|
||||
try {
|
||||
String name = getName();
|
||||
Globals _G = JsePlatform.debugGlobals();
|
||||
Globals globals = JsePlatform.debugGlobals();
|
||||
Reader reader = new StringReader(script);
|
||||
LuaValue chunk ;
|
||||
switch ( TEST_TYPE ) {
|
||||
case TEST_TYPE_LUAJC:
|
||||
LuaJC.install(_G);
|
||||
chunk = _G.load(reader, name);
|
||||
LuaJC.install(globals);
|
||||
chunk = globals.load(reader, name);
|
||||
break;
|
||||
default:
|
||||
Prototype p = _G.compilePrototype(reader, name);
|
||||
chunk = new LuaClosure(p, _G);
|
||||
Prototype p = globals.compilePrototype(reader, name);
|
||||
chunk = new LuaClosure(p, globals);
|
||||
Print.print(p);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ public class LuaOperationsTest extends TestCase {
|
||||
|
||||
public Prototype createPrototype( String script, String name ) {
|
||||
try {
|
||||
Globals _G = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
|
||||
Globals globals = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
|
||||
Reader reader = new StringReader(script);
|
||||
return _G.compilePrototype(reader, name);
|
||||
return globals.compilePrototype(reader, name);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@@ -146,25 +146,25 @@ public class LuaOperationsTest extends TestCase {
|
||||
// set up suitable environments for execution
|
||||
LuaValue aaa = LuaValue.valueOf("aaa");
|
||||
LuaValue eee = LuaValue.valueOf("eee");
|
||||
final Globals _G = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
|
||||
final Globals globals = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals();
|
||||
LuaTable newenv = LuaValue.tableOf( new LuaValue[] {
|
||||
LuaValue.valueOf("a"), LuaValue.valueOf("aaa"),
|
||||
LuaValue.valueOf("b"), LuaValue.valueOf("bbb"), } );
|
||||
LuaTable mt = LuaValue.tableOf( new LuaValue[] { LuaValue.INDEX, _G } );
|
||||
LuaTable mt = LuaValue.tableOf( new LuaValue[] { LuaValue.INDEX, globals } );
|
||||
newenv.setmetatable(mt);
|
||||
_G.set("a", aaa);
|
||||
globals.set("a", aaa);
|
||||
newenv.set("a", eee);
|
||||
|
||||
// function tests
|
||||
{
|
||||
LuaFunction f = new ZeroArgFunction() { public LuaValue call() { return _G.get("a");}};
|
||||
LuaFunction f = new ZeroArgFunction() { public LuaValue call() { return globals.get("a");}};
|
||||
assertEquals( aaa, f.call() );
|
||||
}
|
||||
|
||||
// closure tests
|
||||
{
|
||||
Prototype p = createPrototype( "return a\n", "closuretester" );
|
||||
LuaClosure c = new LuaClosure(p, _G);
|
||||
LuaClosure c = new LuaClosure(p, globals);
|
||||
|
||||
// Test that a clusure with a custom enviroment uses that environment.
|
||||
assertEquals( aaa, c.call() );
|
||||
|
||||
@@ -177,7 +177,7 @@ public class ScriptDrivenTest extends TestCase implements ResourceFinder {
|
||||
}
|
||||
}
|
||||
|
||||
protected LuaValue loadScript(String name, Globals _G) throws IOException {
|
||||
protected LuaValue loadScript(String name, Globals globals) throws IOException {
|
||||
InputStream script = this.findResource(name+".lua");
|
||||
if ( script == null )
|
||||
fail("Could not load script for test case: " + name);
|
||||
@@ -188,11 +188,11 @@ public class ScriptDrivenTest extends TestCase implements ResourceFinder {
|
||||
LuaValue c = (LuaValue) Class.forName(name).newInstance();
|
||||
return c;
|
||||
} else {
|
||||
LuaJC.install(_G);
|
||||
return _G.load(script, name, "bt", _G);
|
||||
LuaJC.install(globals);
|
||||
return globals.load(script, name, "bt", globals);
|
||||
}
|
||||
default:
|
||||
return _G.load(script, "@"+name+".lua", "bt", _G);
|
||||
return globals.load(script, "@"+name+".lua", "bt", globals);
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -21,7 +21,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
|
||||
private final String dir;
|
||||
private final String jar;
|
||||
private Globals _G;
|
||||
private Globals globals;
|
||||
|
||||
public AbstractUnitTests(String zipdir, String zipfile, String dir) {
|
||||
URL zip = null;
|
||||
@@ -43,7 +43,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
_G = JsePlatform.standardGlobals();
|
||||
globals = JsePlatform.standardGlobals();
|
||||
}
|
||||
|
||||
protected String pathOfFile(String file) {
|
||||
@@ -67,7 +67,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
|
||||
// compile in memory
|
||||
InputStream is = new ByteArrayInputStream(lua);
|
||||
Prototype p = _G.loadPrototype(is, "@" + file, "bt");
|
||||
Prototype p = globals.loadPrototype(is, "@" + file, "bt");
|
||||
String actual = protoToString(p);
|
||||
|
||||
// load expected value from jar
|
||||
@@ -109,7 +109,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
protected Prototype loadFromBytes(byte[] bytes, String script)
|
||||
throws IOException {
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
return _G.loadPrototype(is, script, "b");
|
||||
return globals.loadPrototype(is, script, "b");
|
||||
}
|
||||
|
||||
protected String protoToString(Prototype p) {
|
||||
|
||||
@@ -30,11 +30,11 @@ public class DumpLoadEndianIntTest extends TestCase {
|
||||
private static final String withdoubles = "1234-#!-23.75";
|
||||
private static final String withints = "1234-#!-23";
|
||||
|
||||
private Globals _G;
|
||||
private Globals globals;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
_G = JsePlatform.standardGlobals();
|
||||
globals = JsePlatform.standardGlobals();
|
||||
DumpState.ALLOW_INTEGER_CASTING = false;
|
||||
}
|
||||
|
||||
@@ -86,10 +86,10 @@ public class DumpLoadEndianIntTest extends TestCase {
|
||||
|
||||
// compile into prototype
|
||||
Reader reader = new StringReader(script);
|
||||
Prototype p = _G.compilePrototype(reader, "script");
|
||||
Prototype p = globals.compilePrototype(reader, "script");
|
||||
|
||||
// double check script result before dumping
|
||||
LuaFunction f = new LuaClosure(p, _G);
|
||||
LuaFunction f = new LuaClosure(p, globals);
|
||||
LuaValue r = f.call();
|
||||
String actual = r.tojstring();
|
||||
assertEquals( expectedPriorDump, actual );
|
||||
@@ -110,7 +110,7 @@ public class DumpLoadEndianIntTest extends TestCase {
|
||||
|
||||
// load again using compiler
|
||||
InputStream is = new ByteArrayInputStream(dumped);
|
||||
f = _G.load(is, "dumped", "b", _G).checkfunction();
|
||||
f = globals.load(is, "dumped", "b", globals).checkfunction();
|
||||
r = f.call();
|
||||
actual = r.tojstring();
|
||||
assertEquals( expectedPostDump, actual );
|
||||
|
||||
@@ -10,16 +10,16 @@ import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
public class SimpleTests extends TestCase {
|
||||
|
||||
private Globals _G;
|
||||
private Globals globals;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
_G = JsePlatform.standardGlobals();
|
||||
globals = JsePlatform.standardGlobals();
|
||||
}
|
||||
|
||||
private void doTest( String script ) {
|
||||
try {
|
||||
LuaValue c = _G.load(script, "script");
|
||||
LuaValue c = globals.load(script, "script");
|
||||
c.call();
|
||||
} catch ( Exception e ) {
|
||||
fail("i/o exception: "+e );
|
||||
|
||||
@@ -6,13 +6,12 @@ import org.luaj.vm2.LuaError;
|
||||
import org.luaj.vm2.LuaInteger;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaUserdata;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
|
||||
public class LuaJavaCoercionTest extends TestCase {
|
||||
|
||||
private static LuaValue _G;
|
||||
private static LuaValue globals;
|
||||
private static LuaValue ZERO = LuaValue.ZERO;
|
||||
private static LuaValue ONE = LuaValue.ONE;
|
||||
private static LuaValue TWO = LuaValue.valueOf(2);
|
||||
@@ -21,7 +20,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
_G = JsePlatform.standardGlobals();
|
||||
globals = JsePlatform.standardGlobals();
|
||||
}
|
||||
|
||||
public void testJavaIntToLuaInt() {
|
||||
@@ -220,7 +219,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
||||
public void testExceptionMessage() {
|
||||
String script = "local c = luajava.bindClass( \""+SomeClass.class.getName()+"\" )\n" +
|
||||
"return pcall( c.someMethod, c )";
|
||||
Varargs vresult = _G.get("load").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
|
||||
Varargs vresult = globals.get("load").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
|
||||
LuaValue status = vresult.arg1();
|
||||
LuaValue message = vresult.arg(2);
|
||||
assertEquals( LuaValue.FALSE, status );
|
||||
@@ -230,7 +229,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
||||
|
||||
public void testLuaErrorCause() {
|
||||
String script = "luajava.bindClass( \""+SomeClass.class.getName()+"\"):someMethod()";
|
||||
LuaValue chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||
LuaValue chunk = globals.get("load").call(LuaValue.valueOf(script));
|
||||
try {
|
||||
chunk.invoke(LuaValue.NONE);
|
||||
fail( "call should not have succeeded" );
|
||||
@@ -259,7 +258,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
||||
" ) or '-nil')\n" +
|
||||
" end,\n" +
|
||||
"} )\n";
|
||||
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||
Varargs chunk = globals.get("load").call(LuaValue.valueOf(script));
|
||||
if ( ! chunk.arg1().toboolean() )
|
||||
fail( chunk.arg(2).toString() );
|
||||
LuaValue result = chunk.arg1().call();
|
||||
@@ -284,7 +283,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
||||
//"print(bigNumB:toString())\n" +
|
||||
//"print(bigNumC:toString())\n" +
|
||||
"return bigNumA:toString(), bigNumB:toString(), bigNumC:toString()";
|
||||
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||
Varargs chunk = globals.get("load").call(LuaValue.valueOf(script));
|
||||
if ( ! chunk.arg1().toboolean() )
|
||||
fail( chunk.arg(2).toString() );
|
||||
Varargs results = chunk.arg1().invoke();
|
||||
@@ -369,7 +368,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
||||
"local b = a:set(a:get"+typename+"())\n" +
|
||||
"local c = a:setr(a:get"+typename+"())\n" +
|
||||
"return b,c";
|
||||
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||
Varargs chunk = globals.get("load").call(LuaValue.valueOf(script));
|
||||
if ( ! chunk.arg1().toboolean() )
|
||||
fail( chunk.arg(2).toString() );
|
||||
Varargs results = chunk.arg1().invoke();
|
||||
|
||||
@@ -7,16 +7,16 @@ import org.luaj.vm2.LuaValue;
|
||||
|
||||
public class LuajavaAccessibleMembersTest extends TestCase {
|
||||
|
||||
private Globals _G;
|
||||
private Globals globals;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
_G = JsePlatform.standardGlobals();
|
||||
globals = JsePlatform.standardGlobals();
|
||||
}
|
||||
|
||||
private String invokeScript(String script) {
|
||||
try {
|
||||
LuaValue c = _G.load(script, "script");
|
||||
LuaValue c = globals.load(script, "script");
|
||||
return c.call().tojstring();
|
||||
} catch ( Exception e ) {
|
||||
fail("exception: "+e );
|
||||
|
||||
Reference in New Issue
Block a user