1 Commits

Author SHA1 Message Date
Benjamin P. Jung
70cb74b4d6 Migrate CVS project to Git 2015-08-27 15:50:46 +02:00
26 changed files with 265 additions and 387 deletions

View File

@@ -1,22 +1,22 @@
# This is a fork!
<div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;">
This repository has been forked from the original CVS sources of Luaj.
The commit history has been converted to make sure that the original work of
James Roseborough and Ian Farmer is not lost.
Unfortunately, I was not able to contact either James or Ian to hand over
ownership of the Github organization/repo as I have originally intended to.
The community however seems interested enough to continue work on the original
sources and therefore I have decided to make sure that any useful pull requests
that may add some value to the original code base shall be merged in from now
on.<br>
-- Benjamin P. Jung, Jan. 26th 2018
</div>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<h1>Getting Started with LuaJ</h1>
<head>
<title>Getting Started with LuaJ</title>
<link rel="stylesheet" type="text/css" href="http://www.lua.org/lua.css">
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Getting Started with LuaJ</h1>
James Roseborough, Ian Farmer, Version 3.0.2
<hr>
<h1>
<a href="README.html"><img src="http://sourceforge.net/dbimage.php?id=196139" alt="" border="0"></a>
Getting Started with LuaJ
</h1>
James Roseborough, Ian Farmer, Version 3.0.1
<p>
<small>
Copyright &copy; 2009-2014 Luaj.org.
@@ -120,7 +120,7 @@ in comparison with the standard C distribution.
<td>16.794</td>
<td>11.274</td>
<td>Java</td>
<td>java -cp luaj-jse-3.0.2.jar;bcel-5.2.jar lua <b>-b</b> fannkuch.lua 10</td></tr>
<td>java -cp luaj-jse-3.0.1.jar;bcel-5.2.jar lua <b>-b</b> fannkuch.lua 10</td></tr>
<tr valign="top">
<td></td>
<td></td>
@@ -130,7 +130,7 @@ in comparison with the standard C distribution.
<td>36.894</td>
<td>15.163</td>
<td></td>
<td>java -cp luaj-jse-3.0.2.jar lua -n fannkuch.lua 10</td></tr>
<td>java -cp luaj-jse-3.0.1.jar lua -n fannkuch.lua 10</td></tr>
<tr valign="top">
<td>lua</td>
<td>5.1.4</td>
@@ -186,7 +186,7 @@ It is also faster than Java-lua implementations Jill, Kahlua, and Mochalua for a
From the main distribution directory line type:
<pre>
java -cp lib/luaj-jse-3.0.2.jar lua examples/lua/hello.lua
java -cp lib/luaj-jse-3.0.1.jar lua examples/lua/hello.lua
</pre>
<p>
@@ -198,7 +198,7 @@ You should see the following output:
To see how luaj can be used to acccess most Java API's including swing, try:
<pre>
java -cp lib/luaj-jse-3.0.2.jar lua examples/lua/swingapp.lua
java -cp lib/luaj-jse-3.0.1.jar lua examples/lua/swingapp.lua
</pre>
<p>
@@ -213,8 +213,8 @@ Links to sources:<pre>
From the main distribution directory line type:
<pre>
java -cp lib/luaj-jse-3.0.2.jar luac examples/lua/hello.lua
java -cp lib/luaj-jse-3.0.2.jar lua luac.out
java -cp lib/luaj-jse-3.0.1.jar luac examples/lua/hello.lua
java -cp lib/luaj-jse-3.0.1.jar lua luac.out
</pre>
<p>
@@ -228,8 +228,8 @@ Luaj can compile lua sources or binaries directly to java bytecode if the bcel l
<pre>
ant bcel-lib
java -cp &quot;lib/luaj-jse-3.0.2.jar;lib/bcel-5.2.jar&quot; luajc -s examples/lua -d . hello.lua
java -cp &quot;lib/luaj-jse-3.0.2.jar;.&quot; lua -l hello
java -cp &quot;lib/luaj-jse-3.0.1.jar;lib/bcel-5.2.jar&quot; luajc -s examples/lua -d . hello.lua
java -cp &quot;lib/luaj-jse-3.0.1.jar;.&quot; lua -l hello
</pre>
<p>
@@ -240,7 +240,7 @@ but the compiled classes must be in the class path at runtime, unless runtime ji
<p>
Lua scripts can also be run directly in this mode without precompiling using the <em>lua</em> command with the <b><em>-b</em></b> option and providing the <em>bcel</em> library in the class path:
<pre>
java -cp &quot;lib/luaj-jse-3.0.2.jar;lib/bcel-5.2.jar&quot; lua -b examples/lua/hello.lua
java -cp &quot;lib/luaj-jse-3.0.1.jar;lib/bcel-5.2.jar&quot; lua -b examples/lua/hello.lua
</pre>
@@ -284,7 +284,7 @@ A simple example may be found in
</pre>
<p>
You must include the library <b>lib/luaj-jse-3.0.2.jar</b> in your class path.
You must include the library <b>lib/luaj-jse-3.0.1.jar</b> in your class path.
<h2>Run a script in a MIDlet</h2>
@@ -311,7 +311,7 @@ A simple example may be found in
</pre>
<p>
You must include the library <b>lib/luaj-jme-3.0.2.jar</b> in your midlet jar.
You must include the library <b>lib/luaj-jme-3.0.1.jar</b> in your midlet jar.
<p>
An ant script to build and run the midlet is in
@@ -341,7 +341,7 @@ You can also look up the engine by language "lua" or mimetypes "text/lua" or "ap
All standard aspects of script engines including compiled statements are supported.
<p>
You must include the library <b>lib/luaj-jse-3.0.2.jar</b> in your class path.
You must include the library <b>lib/luaj-jse-3.0.1.jar</b> in your class path.
<p>
A working example may be found in
@@ -352,8 +352,8 @@ A working example may be found in
To compile and run it using Java 1.6 or higher:
<pre>
javac -cp lib/luaj-jse-3.0.2.jar examples/jse/ScriptEngineSample.java
java -cp &quot;lib/luaj-jse-3.0.2.jar;examples/jse&quot; ScriptEngineSample
javac -cp lib/luaj-jse-3.0.1.jar examples/jse/ScriptEngineSample.java
java -cp &quot;lib/luaj-jse-3.0.1.jar;examples/jse&quot; ScriptEngineSample
</pre>
<h2>Excluding the lua bytecode compiler</h2>
@@ -593,7 +593,7 @@ The following lua script will open a swing frame on Java SE:
See a longer sample in <em>examples/lua/swingapp.lua</em> for details, including a simple animation loop, rendering graphics, mouse and key handling, and image loading.
Or try running it using:
<pre>
java -cp lib/luaj-jse-3.0.2.jar lua examples/lua/swingapp.lua
java -cp lib/luaj-jse-3.0.1.jar lua examples/lua/swingapp.lua
</pre>
<p>
@@ -842,7 +842,7 @@ For JSE projects, add this dependency for the luaj-jse jar:
&lt;dependency&gt;
&lt;groupId&gt;org.luaj&lt;/groupId&gt;
&lt;artifactId&gt;luaj-jse&lt;/artifactId&gt;
&lt;version&gt;3.0.2&lt;/version&gt;
&lt;version&gt;3.0.1&lt;/version&gt;
&lt;/dependency&gt;
</pre>
while for JME projects, use the luaj-jme jar:
@@ -850,7 +850,7 @@ while for JME projects, use the luaj-jme jar:
&lt;dependency&gt;
&lt;groupId&gt;org.luaj&lt;/groupId&gt;
&lt;artifactId&gt;luaj-jme&lt;/artifactId&gt;
&lt;version&gt;3.0.2&lt;/version&gt;
&lt;version&gt;3.0.1&lt;/version&gt;
&lt;/dependency&gt;
</pre>
@@ -880,7 +880,7 @@ Unit test scripts can be found in these locations
test/lua/*.lua
test/lua/errors/*.lua
test/lua/perf/*.lua
test/lua/luaj3.0.2-tests.zip
test/lua/luaj3.0.1-tests.zip
</pre>
<h2>Code coverage</h2>
@@ -1017,11 +1017,6 @@ and at <a href="http://luaj.sourceforge.net/api/2.0/index.html">http://luaj.sour
<li>Move online docs to <a href="http://luaj.org/luaj/3.0/api/index.html">http://luaj.org/luaj/3.0/api/</a></li>
<li>Fix os.time() conversions for pm times.</li>
<tr valign="top"><td>&nbsp;&nbsp;<b>3.0.2</b></td><td><ul>
<li>Fix JsePlatform.luaMain() to provide an "arg" table in the chunk's environment.</li>
<li>Let JsePlatform.luaMain() return values returned by the main chunk.</li>
<li>Add synchronization to CoerceJavaToLua.COERCIONS map.</li>
</ul></td></tr>
</table></td></tr></table>

View File

@@ -97,19 +97,14 @@ public class LuaClosure extends LuaFunction {
*/
public LuaClosure(Prototype p, LuaValue env) {
this.p = p;
this.initupvalue1(env);
globals = env instanceof Globals? (Globals) env: null;
}
public void initupvalue1(LuaValue env) {
if (p.upvalues == null || p.upvalues.length == 0)
this.upValues = NOUPVALUES;
else {
this.upValues = new UpValue[p.upvalues.length];
this.upValues[0] = new UpValue(new LuaValue[] {env}, 0);
}
globals = env instanceof Globals? (Globals) env: null;
}
public boolean isclosure() {
return true;
@@ -123,24 +118,26 @@ public class LuaClosure extends LuaFunction {
return this;
}
public LuaValue getmetatable() {
return s_metatable;
}
public String tojstring() {
return "function: " + p.toString();
}
private LuaValue[] getNewStack() {
int max = p.maxstacksize;
LuaValue[] stack = new LuaValue[max];
System.arraycopy(NILS, 0, stack, 0, max);
return stack;
}
public final LuaValue call() {
LuaValue[] stack = getNewStack();
LuaValue[] stack = new LuaValue[p.maxstacksize];
for (int i = 0; i < p.numparams; ++i )
stack[i] = NIL;
return execute(stack,NONE).arg1();
}
public final LuaValue call(LuaValue arg) {
LuaValue[] stack = getNewStack();
LuaValue[] stack = new LuaValue[p.maxstacksize];
System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
for (int i = 1; i < p.numparams; ++i )
stack[i] = NIL;
switch ( p.numparams ) {
default: stack[0]=arg; return execute(stack,NONE).arg1();
case 0: return execute(stack,arg).arg1();
@@ -148,7 +145,9 @@ public class LuaClosure extends LuaFunction {
}
public final LuaValue call(LuaValue arg1, LuaValue arg2) {
LuaValue[] stack = getNewStack();
LuaValue[] stack = new LuaValue[p.maxstacksize];
for (int i = 2; i < p.numparams; ++i )
stack[i] = NIL;
switch ( p.numparams ) {
default: stack[0]=arg1; stack[1]=arg2; return execute(stack,NONE).arg1();
case 1: stack[0]=arg1; return execute(stack,arg2).arg1();
@@ -157,7 +156,9 @@ public class LuaClosure extends LuaFunction {
}
public final LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
LuaValue[] stack = getNewStack();
LuaValue[] stack = new LuaValue[p.maxstacksize];
for (int i = 3; i < p.numparams; ++i )
stack[i] = NIL;
switch ( p.numparams ) {
default: stack[0]=arg1; stack[1]=arg2; stack[2]=arg3; return execute(stack,NONE).arg1();
case 2: stack[0]=arg1; stack[1]=arg2; return execute(stack,arg3).arg1();
@@ -171,9 +172,9 @@ public class LuaClosure extends LuaFunction {
}
public final Varargs onInvoke(Varargs varargs) {
LuaValue[] stack = getNewStack();
LuaValue[] stack = new LuaValue[p.maxstacksize];
for ( int i=0; i<p.numparams; i++ )
stack[i] = varargs.arg(i+1);
stack[i] = varargs.arg(i+1);
return execute(stack,p.is_vararg!=0? varargs.subargs(p.numparams+1): NONE);
}
@@ -301,7 +302,7 @@ public class LuaClosure extends LuaFunction {
if ( c > b+1 ) {
Buffer sb = stack[c].buffer();
while ( --c>=b )
sb.concatTo(stack[c]);
sb = stack[c].concat(sb);
stack[a] = sb.value();
} else {
stack[a] = stack[c-1].concat(stack[c]);

View File

@@ -144,7 +144,7 @@ public class LuaString extends LuaValue {
/** Construct a new LuaString using a copy of the bytes array supplied */
private static LuaString valueFromCopy(byte[] bytes, int off, int len) {
final byte[] copy = new byte[len];
System.arraycopy(bytes, off, copy, 0, len);
for (int i=0; i<len; ++i) copy[i] = bytes[off+i];
return new LuaString(copy, 0, len);
}

View File

@@ -266,8 +266,8 @@ public class LuaTable extends LuaValue implements Metatable {
/** caller must ensure key is not nil */
public void set( LuaValue key, LuaValue value ) {
if (key == null || !key.isvalidkey() && !metatag(NEWINDEX).isfunction())
throw new LuaError("value ('" + key + "') can not be used as a table index");
if (!key.isvalidkey() && !metatag(NEWINDEX).isfunction())
typerror("table index");
if ( m_metatable==null || ! rawget(key).isnil() || ! settable(this,key,value) )
rawset(key, value);
}
@@ -347,12 +347,7 @@ public class LuaTable extends LuaValue implements Metatable {
}
public int length() {
if (m_metatable != null) {
LuaValue len = len();
if (!len.isint()) throw new LuaError("table length is not an integer: " + len);
return len.toint();
}
return rawlen();
return m_metatable != null? len().toint(): rawlen();
}
public LuaValue len() {
@@ -395,7 +390,7 @@ public class LuaTable extends LuaValue implements Metatable {
}
}
if ( hash.length == 0 )
error( "invalid key to 'next' 1: " + key );
error( "invalid key to 'next'" );
i = hashSlot( key );
boolean found = false;
for ( Slot slot = hash[i]; slot != null; slot = slot.rest() ) {
@@ -409,7 +404,7 @@ public class LuaTable extends LuaValue implements Metatable {
}
}
if ( !found ) {
error( "invalid key to 'next' 2: " + key );
error( "invalid key to 'next'" );
}
i += 1+array.length;
}
@@ -785,7 +780,6 @@ public class LuaTable extends LuaValue implements Metatable {
* @param comparator {@link LuaValue} to be called to compare elements.
*/
public void sort(LuaValue comparator) {
if (len().tolong() >= (long)Integer.MAX_VALUE) throw new LuaError("array too big: " + len().tolong());
if (m_metatable != null && m_metatable.useWeakValues()) {
dropWeakArrayValues();
}
@@ -898,11 +892,6 @@ public class LuaTable extends LuaValue implements Metatable {
/** Unpack the elements from i to j inclusive */
public Varargs unpack(int i, int j) {
if (j < i) return NONE;
int count = j - i;
if (count < 0) throw new LuaError("too many results to unpack: greater " + Integer.MAX_VALUE); // integer overflow
int max = 0x00ffffff;
if (count >= max) throw new LuaError("too many results to unpack: " + count + " (max is " + max + ')');
int n = j + 1 - i;
switch (n) {
case 0: return NONE;
@@ -911,14 +900,10 @@ public class LuaTable extends LuaValue implements Metatable {
default:
if (n < 0)
return NONE;
try {
LuaValue[] v = new LuaValue[n];
while (--n >= 0)
v[n] = get(i+n);
return varargsOf(v);
} catch (OutOfMemoryError e) {
throw new LuaError("too many results to unpack [out of memory]: " + n);
}
LuaValue[] v = new LuaValue[n];
while (--n >= 0)
v[n] = get(i+n);
return varargsOf(v);
}
}
@@ -1246,14 +1231,13 @@ public class LuaTable extends LuaValue implements Metatable {
}
public Entry set(LuaValue value) {
if (value.type() == TNUMBER) {
LuaValue n = value.tonumber();
if (!n.isnil()) {
this.value = n.todouble();
return this;
}
LuaValue n = value.tonumber();
if ( !n.isnil() ) {
this.value = n.todouble();
return this;
} else {
return new NormalEntry( this.key, value );
}
return new NormalEntry( this.key, value );
}
public int keyindex( int mask ) {

View File

@@ -2045,7 +2045,7 @@ public class LuaValue extends Varargs {
* @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
* @see #EQ
*/
public LuaValue eq( LuaValue val ) { return eq_b(val)? TRUE: FALSE; }
public LuaValue eq( LuaValue val ) { return this == val? TRUE: FALSE; }
/** Equals: Perform equality comparison with another value
* including metatag processing using {@link #EQ},
@@ -3143,7 +3143,7 @@ public class LuaValue extends Varargs {
* @return {@link LuaString} corresponding to the value if a string or number
* @throws LuaError if not a string or number
*/
public LuaString strvalue() { typerror("string or number"); return null; }
public LuaString strvalue() { typerror("strValue"); return null; }
/** Return this value as a strong reference, or null if it was weak and is no longer referenced.
* @return {@link LuaValue} referred to, or null if it was weak and is no longer referenced.
@@ -3298,7 +3298,7 @@ public class LuaValue extends Varargs {
if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil())
return res;
} else if ((tm = t.metatag(INDEX)).isnil())
t.indexerror(key.tojstring());
t.indexerror();
if (tm.isfunction())
return tm.call(t, key);
t = tm;
@@ -3326,7 +3326,7 @@ public class LuaValue extends Varargs {
return true;
}
} else if ((tm = t.metatag(NEWINDEX)).isnil())
throw new LuaError("table expected for set index ('" + key + "') value, got " + t.typename());
t.typerror("index");
if (tm.isfunction()) {
tm.call(t, key, value);
return true;
@@ -3389,8 +3389,8 @@ public class LuaValue extends Varargs {
/** Throw {@link LuaError} indicating index was attempted on illegal type
* @throws LuaError when called.
*/
private void indexerror(String key) {
error( "attempt to index ? (a "+typename()+" value) with key '" + key + "'" );
private void indexerror() {
error( "attempt to index ? (a "+typename()+" value)" );
}
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.

View File

@@ -128,10 +128,6 @@ public class Print extends Lua {
}
static void printValue( PrintStream ps, LuaValue v ) {
if (v == null) {
ps.print("null");
return;
}
switch ( v.type() ) {
case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
default: ps.print( v.tojstring() );
@@ -140,7 +136,7 @@ public class Print extends Lua {
}
static void printConstant(PrintStream ps, Prototype f, int i) {
printValue( ps, i < f.k.length ? f.k[i] : LuaValue.valueOf("UNKNOWN_CONST_" + i) );
printValue( ps, f.k[i] );
}
static void printUpvalue(PrintStream ps, Upvaldesc u) {
@@ -156,7 +152,7 @@ public class Print extends Lua {
int[] code = f.code;
int pc, n = code.length;
for (pc = 0; pc < n; pc++) {
pc = printOpCode(f, pc);
printOpCode(f, pc);
ps.println();
}
}
@@ -165,10 +161,9 @@ public class Print extends Lua {
* Print an opcode in a prototype
* @param f the {@link Prototype}
* @param pc the program counter to look up and print
* @return pc same as above or changed
*/
public static int printOpCode(Prototype f, int pc) {
return printOpCode(ps,f,pc);
public static void printOpCode(Prototype f, int pc) {
printOpCode(ps,f,pc);
}
/**
@@ -176,9 +171,8 @@ public class Print extends Lua {
* @param ps the {@link PrintStream} to print to
* @param f the {@link Prototype}
* @param pc the program counter to look up and print
* @return pc same as above or changed
*/
public static int printOpCode(PrintStream ps, Prototype f, int pc) {
public static void printOpCode(PrintStream ps, Prototype f, int pc) {
int[] code = f.code;
int i = code[pc];
int o = GET_OPCODE(i);
@@ -193,67 +187,80 @@ public class Print extends Lua {
ps.print("[" + line + "] ");
else
ps.print("[-] ");
if (o >= OPNAMES.length - 1) {
ps.print("UNKNOWN_OP_" + o + " ");
} else {
ps.print(OPNAMES[o] + " ");
switch (getOpMode(o)) {
case iABC:
ps.print( a );
if (getBMode(o) != OpArgN)
ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
if (getCMode(o) != OpArgN)
ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
break;
case iABx:
if (getBMode(o) == OpArgK) {
ps.print(a + " " + (-1 - bx));
} else {
ps.print(a + " " + (bx));
}
break;
case iAsBx:
if (o == OP_JMP)
ps.print( sbx );
else
ps.print(a + " " + sbx);
break;
ps.print(OPNAMES[o] + " ");
switch (getOpMode(o)) {
case iABC:
ps.print( a );
if (getBMode(o) != OpArgN)
ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
if (getCMode(o) != OpArgN)
ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
break;
case iABx:
if (getBMode(o) == OpArgK) {
ps.print(a + " " + (-1 - bx));
} else {
ps.print(a + " " + (bx));
}
switch (o) {
case OP_LOADK:
break;
case iAsBx:
if (o == OP_JMP)
ps.print( sbx );
else
ps.print(a + " " + sbx);
break;
}
switch (o) {
case OP_LOADK:
ps.print(" ; ");
printConstant(ps, f, bx);
break;
case OP_GETUPVAL:
case OP_SETUPVAL:
ps.print(" ; ");
printUpvalue(ps, f.upvalues[b]);
break;
case OP_GETTABUP:
ps.print(" ; ");
printUpvalue(ps, f.upvalues[b]);
ps.print(" ");
if (ISK(c))
printConstant(ps, f, INDEXK(c));
else
ps.print("-");
break;
case OP_SETTABUP:
ps.print(" ; ");
printUpvalue(ps, f.upvalues[a]);
ps.print(" ");
if (ISK(b))
printConstant(ps, f, INDEXK(b));
else
ps.print("-");
ps.print(" ");
if (ISK(c))
printConstant(ps, f, INDEXK(c));
else
ps.print("-");
break;
case OP_GETTABLE:
case OP_SELF:
if (ISK(c)) {
ps.print(" ; ");
printConstant(ps, f, bx);
break;
case OP_GETUPVAL:
case OP_SETUPVAL:
printConstant(ps, f, INDEXK(c));
}
break;
case OP_SETTABLE:
case OP_ADD:
case OP_SUB:
case OP_MUL:
case OP_DIV:
case OP_POW:
case OP_EQ:
case OP_LT:
case OP_LE:
if (ISK(b) || ISK(c)) {
ps.print(" ; ");
if (b < f.upvalues.length) {
printUpvalue(ps, f.upvalues[b]);
} else {
ps.print("UNKNOWN_UPVALUE_" + b);
}
break;
case OP_GETTABUP:
ps.print(" ; ");
if (b < f.upvalues.length) {
printUpvalue(ps, f.upvalues[b]);
} else {
ps.print("UNKNOWN_UPVALUE_" + b);
}
ps.print(" ");
if (ISK(c))
printConstant(ps, f, INDEXK(c));
else
ps.print("-");
break;
case OP_SETTABUP:
ps.print(" ; ");
if (a < f.upvalues.length) {
printUpvalue(ps, f.upvalues[a]);
} else {
ps.print("UNKNOWN_UPVALUE_" + a);
}
ps.print(" ");
if (ISK(b))
printConstant(ps, f, INDEXK(b));
else
@@ -263,62 +270,28 @@ public class Print extends Lua {
printConstant(ps, f, INDEXK(c));
else
ps.print("-");
break;
case OP_GETTABLE:
case OP_SELF:
if (ISK(c)) {
ps.print(" ; ");
printConstant(ps, f, INDEXK(c));
}
break;
case OP_SETTABLE:
case OP_ADD:
case OP_SUB:
case OP_MUL:
case OP_DIV:
case OP_POW:
case OP_EQ:
case OP_LT:
case OP_LE:
if (ISK(b) || ISK(c)) {
ps.print(" ; ");
if (ISK(b))
printConstant(ps, f, INDEXK(b));
else
ps.print("-");
ps.print(" ");
if (ISK(c))
printConstant(ps, f, INDEXK(c));
else
ps.print("-");
}
break;
case OP_JMP:
case OP_FORLOOP:
case OP_FORPREP:
ps.print(" ; to " + (sbx + pc + 2));
break;
case OP_CLOSURE:
if (bx < f.p.length) {
ps.print(" ; " + f.p[bx].getClass().getName());
} else {
ps.print(" ; UNKNOWN_PROTYPE_" + bx);
}
break;
case OP_SETLIST:
if (c == 0)
ps.print(" ; " + ((int) code[++pc]) + " (stored in the next OP)");
else
ps.print(" ; " + ((int) c));
break;
case OP_VARARG:
ps.print( " ; is_vararg="+ f.is_vararg );
break;
default:
break;
}
break;
case OP_JMP:
case OP_FORLOOP:
case OP_FORPREP:
ps.print(" ; to " + (sbx + pc + 2));
break;
case OP_CLOSURE:
ps.print(" ; " + f.p[bx].getClass().getName());
break;
case OP_SETLIST:
if (c == 0)
ps.print(" ; " + ((int) code[++pc]));
else
ps.print(" ; " + ((int) c));
break;
case OP_VARARG:
ps.print( " ; is_vararg="+ f.is_vararg );
break;
default:
break;
}
return pc;
}
private static int getline(Prototype f, int pc) {

View File

@@ -117,7 +117,7 @@ public class LuaC extends Constants implements Globals.Compiler, Globals.Loader
protected CompileState() {}
/** Parse the input */
Prototype luaY_parser(InputStream z, String name) throws IOException{
private Prototype luaY_parser(InputStream z, String name) throws IOException{
LexState lexstate = new LexState(this, z);
FuncState funcstate = new FuncState();
// lexstate.buff = buff;

View File

@@ -245,7 +245,7 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
public Varargs invoke(Varargs args) {
LuaValue tostring = globals.get("tostring");
for ( int i=1, n=args.narg(); i<=n; i++ ) {
if ( i>1 ) globals.STDOUT.print( " \t" );
if ( i>1 ) globals.STDOUT.print( '\t' );
LuaString s = tostring.call( args.arg(i) ).strvalue();
globals.STDOUT.print(s.tojstring());
}

View File

@@ -92,7 +92,7 @@ public class CoroutineLib extends TwoArgFunction {
}
}
static final class resume extends VarArgFunction {
final class resume extends VarArgFunction {
public Varargs invoke(Varargs args) {
final LuaThread t = args.checkthread(1);
return t.resume( args.subargs(2) );
@@ -127,7 +127,7 @@ public class CoroutineLib extends TwoArgFunction {
}
}
static final class wrapper extends VarArgFunction {
final class wrapper extends VarArgFunction {
final LuaThread luathread;
wrapper(LuaThread luathread) {
this.luathread = luathread;

View File

@@ -84,27 +84,27 @@ public class DebugLib extends TwoArgFunction {
try { TRACE = (null != System.getProperty("TRACE")); } catch (Exception e) {}
}
static final LuaString LUA = valueOf("Lua");
private static final LuaString LUA = valueOf("Lua");
private static final LuaString QMARK = valueOf("?");
private static final LuaString CALL = valueOf("call");
private static final LuaString LINE = valueOf("line");
private static final LuaString COUNT = valueOf("count");
private static final LuaString RETURN = valueOf("return");
static final LuaString FUNC = valueOf("func");
static final LuaString ISTAILCALL = valueOf("istailcall");
static final LuaString ISVARARG = valueOf("isvararg");
static final LuaString NUPS = valueOf("nups");
static final LuaString NPARAMS = valueOf("nparams");
static final LuaString NAME = valueOf("name");
static final LuaString NAMEWHAT = valueOf("namewhat");
static final LuaString WHAT = valueOf("what");
static final LuaString SOURCE = valueOf("source");
static final LuaString SHORT_SRC = valueOf("short_src");
static final LuaString LINEDEFINED = valueOf("linedefined");
static final LuaString LASTLINEDEFINED = valueOf("lastlinedefined");
static final LuaString CURRENTLINE = valueOf("currentline");
static final LuaString ACTIVELINES = valueOf("activelines");
private static final LuaString FUNC = valueOf("func");
private static final LuaString ISTAILCALL = valueOf("istailcall");
private static final LuaString ISVARARG = valueOf("isvararg");
private static final LuaString NUPS = valueOf("nups");
private static final LuaString NPARAMS = valueOf("nparams");
private static final LuaString NAME = valueOf("name");
private static final LuaString NAMEWHAT = valueOf("namewhat");
private static final LuaString WHAT = valueOf("what");
private static final LuaString SOURCE = valueOf("source");
private static final LuaString SHORT_SRC = valueOf("short_src");
private static final LuaString LINEDEFINED = valueOf("linedefined");
private static final LuaString LASTLINEDEFINED = valueOf("lastlinedefined");
private static final LuaString CURRENTLINE = valueOf("currentline");
private static final LuaString ACTIVELINES = valueOf("activelines");
Globals globals;
@@ -234,7 +234,7 @@ public class DebugLib extends TwoArgFunction {
}
// debug.getmetatable (value)
static final class getmetatable extends LibFunction {
final class getmetatable extends LibFunction {
public LuaValue call(LuaValue v) {
LuaValue mt = v.getmetatable();
return mt != null? mt: NIL;
@@ -311,7 +311,7 @@ public class DebugLib extends TwoArgFunction {
}
// debug.setmetatable (value, table)
static final class setmetatable extends TwoArgFunction {
final class setmetatable extends TwoArgFunction {
public LuaValue call(LuaValue value, LuaValue table) {
LuaValue mt = table.opttable(null);
switch ( value.type() ) {
@@ -328,7 +328,7 @@ public class DebugLib extends TwoArgFunction {
}
// debug.setupvalue (f, up, value)
static final class setupvalue extends VarArgFunction {
final class setupvalue extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaValue func = args.checkfunction(1);
int up = args.checkint(2);
@@ -346,7 +346,7 @@ public class DebugLib extends TwoArgFunction {
}
// debug.setuservalue (udata, value)
static final class setuservalue extends VarArgFunction {
final class setuservalue extends VarArgFunction {
public Varargs invoke(Varargs args) {
Object o = args.checkuserdata(1);
LuaValue v = args.checkvalue(2);
@@ -370,7 +370,7 @@ public class DebugLib extends TwoArgFunction {
}
// debug.upvalueid (f, n)
static final class upvalueid extends VarArgFunction {
final class upvalueid extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaValue func = args.checkfunction(1);
int up = args.checkint(2);
@@ -385,7 +385,7 @@ public class DebugLib extends TwoArgFunction {
}
// debug.upvaluejoin (f1, n1, f2, n2)
static final class upvaluejoin extends VarArgFunction {
final class upvaluejoin extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaClosure f1 = args.checkclosure(1);
int n1 = args.checkint(2);
@@ -565,11 +565,7 @@ public class DebugLib extends TwoArgFunction {
sb.append( ar.name );
sb.append( '\'' );
} else {
sb.append( "function <" );
sb.append( c.shortsource() );
sb.append( ':' );
sb.append( c.linedefined() );
sb.append( '>' );
sb.append( "function <"+c.shortsource()+":"+c.linedefined()+">" );
}
}
sb.append("\n\t[Java]: in ?");
@@ -677,16 +673,16 @@ public class DebugLib extends TwoArgFunction {
}
Varargs getLocal(int i) {
LuaString name = getlocalname(i);
if ( i >= 1 && i <= stack.length && stack[i-1] != null )
return varargsOf( name == null ? NIL : name, stack[i-1] );
if ( name != null )
return varargsOf( name, stack[i-1] );
else
return NIL;
}
Varargs setLocal(int i, LuaValue value) {
LuaString name = getlocalname(i);
if ( i >= 1 && i <= stack.length && stack[i-1] != null ) {
if ( name != null ) {
stack[i-1] = value;
return name == null ? NIL : name;
return name;
} else {
return NIL;
}
@@ -700,7 +696,7 @@ public class DebugLib extends TwoArgFunction {
if ( !f.isclosure() ) return f.tojstring();
return f.checkclosure().p.shortsource() + ":" + currentline();
}
int linedefined() {
private int linedefined() {
return f.isclosure()? f.checkclosure().p.linedefined: -1;
}
LuaString getlocalname(int index) {
@@ -871,10 +867,6 @@ public class DebugLib extends TwoArgFunction {
if (reg == a) setreg = pc; /* jumped code can change 'a' */
break;
}
case Lua.OP_SETLIST: { // Lua.testAMode(Lua.OP_SETLIST) == false
if ( ((i>>14)&0x1ff) == 0 ) pc++; // if c == 0 then c stored in next op -> skip
break;
}
default:
if (Lua.testAMode(op) && reg == a) /* any instruction that set A */
setreg = pc;

View File

@@ -467,7 +467,7 @@ public class IoLib extends TwoArgFunction {
return LuaValue.TRUE;
}
static Varargs errorresult(Exception ioe) {
private static Varargs errorresult(Exception ioe) {
String s = ioe.getMessage();
return errorresult("io error: "+(s!=null? s: ioe.toString()));
}
@@ -544,7 +544,7 @@ public class IoLib extends TwoArgFunction {
}
boolean isreadmode = mode.startsWith("r");
boolean isappend = mode.startsWith("a");
boolean isupdate = mode.indexOf('+') > 0;
boolean isupdate = mode.indexOf("+") > 0;
boolean isbinary = mode.endsWith("b");
return openFile( filename, isreadmode, isappend, isupdate, isbinary );
}

View File

@@ -139,7 +139,7 @@ abstract public class LibFunction extends LuaFunction {
}
public String tojstring() {
return name != null ? "function: " + name : super.tojstring();
return name != null? name: super.tojstring();
}
/**

View File

@@ -80,8 +80,8 @@ import org.luaj.vm2.Varargs;
* @see <a href="http://www.lua.org/manual/5.1/manual.html#5.8">http://www.lua.org/manual/5.1/manual.html#5.8</a>
*/
public class OsLib extends TwoArgFunction {
public static final String TMP_PREFIX = ".luaj";
public static final String TMP_SUFFIX = "tmp";
public static String TMP_PREFIX = ".luaj";
public static String TMP_SUFFIX = "tmp";
private static final int CLOCK = 0;
private static final int DATE = 1;

View File

@@ -81,26 +81,23 @@ public class PackageLib extends TwoArgFunction {
/** The default value to use for package.path. This can be set with the system property
* <code>"luaj.package.path"</code>, and is <code>"?.lua"</code> by default. */
public static final String DEFAULT_LUA_PATH;
public static String DEFAULT_LUA_PATH;
static {
String path = null;
try {
path = System.getProperty("luaj.package.path");
DEFAULT_LUA_PATH = System.getProperty("luaj.package.path");
} catch (Exception e) {
System.out.println(e.toString());
}
if (path == null) {
path = "?.lua";
}
DEFAULT_LUA_PATH = path;
if (DEFAULT_LUA_PATH == null)
DEFAULT_LUA_PATH = "?.lua";
}
static final LuaString _LOADED = valueOf("loaded");
private static final LuaString _LOADED = valueOf("loaded");
private static final LuaString _LOADLIB = valueOf("loadlib");
static final LuaString _PRELOAD = valueOf("preload");
static final LuaString _PATH = valueOf("path");
static final LuaString _SEARCHPATH = valueOf("searchpath");
static final LuaString _SEARCHERS = valueOf("searchers");
private static final LuaString _PRELOAD = valueOf("preload");
private static final LuaString _PATH = valueOf("path");
private static final LuaString _SEARCHPATH = valueOf("searchpath");
private static final LuaString _SEARCHERS = valueOf("searchers");
/** The globals that were used to load this library. */
Globals globals;
@@ -255,6 +252,7 @@ public class PackageLib extends TwoArgFunction {
public class lua_searcher extends VarArgFunction {
public Varargs invoke(Varargs args) {
LuaString name = args.checkstring(1);
InputStream is = null;
// get package path
LuaValue path = package_.get(_PATH);

View File

@@ -97,12 +97,12 @@ public class StringLib extends TwoArgFunction {
string.set("reverse", new reverse());
string.set("sub", new sub());
string.set("upper", new upper());
LuaTable mt = LuaValue.tableOf(
new LuaValue[] { INDEX, string });
env.set("string", string);
env.get("package").get("loaded").set("string", string);
if (LuaString.s_metatable == null) {
LuaString.s_metatable = LuaValue.tableOf(new LuaValue[] { INDEX, string });
}
if (LuaString.s_metatable == null)
LuaString.s_metatable = mt;
return string;
}
@@ -154,7 +154,7 @@ public class StringLib extends TwoArgFunction {
byte[] bytes = new byte[n];
for ( int i=0, a=1; i<n; i++, a++ ) {
int c = args.checkint(a);
if (c<0 || c>=256) argerror(a, "invalid value for string.char [0; 255]: " + c);
if (c<0 || c>=256) argerror(a, "invalid value");
bytes[i] = (byte) c;
}
return LuaString.valueUsing( bytes );
@@ -162,22 +162,20 @@ public class StringLib extends TwoArgFunction {
}
/**
* string.dump (function[, stripDebug])
* string.dump (function)
*
* Returns a string containing a binary representation of the given function,
* so that a later loadstring on this string returns a copy of the function.
* function must be a Lua function without upvalues.
* Boolean param stripDebug - true to strip debugging info, false otherwise.
* The default value for stripDebug is true.
*
* TODO: port dumping code as optional add-on
*/
static final class dump extends VarArgFunction {
public LuaValue invoke(Varargs args) {
LuaValue f = args.checkfunction(1);
static final class dump extends OneArgFunction {
public LuaValue call(LuaValue arg) {
LuaValue f = arg.checkfunction();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
DumpState.dump( ((LuaClosure)f).p, baos, args.optboolean(2, true) );
DumpState.dump( ((LuaClosure)f).p, baos, true );
return LuaString.valueUsing(baos.toByteArray());
} catch (IOException e) {
return error( e.getMessage() );
@@ -300,7 +298,7 @@ public class StringLib extends TwoArgFunction {
}
}
static void addquoted(Buffer buf, LuaString s) {
private static void addquoted(Buffer buf, LuaString s) {
int c;
buf.append( (byte) '"' );
for ( int i = 0, n = s.length(); i < n; i++ ) {
@@ -340,13 +338,11 @@ public class StringLib extends TwoArgFunction {
private static final int MAX_FLAGS = 5;
private int width;
int precision;
private int precision;
public final int conversion;
public final int length;
public final String src;
public FormatDesc(Varargs args, LuaString strfrmt, final int start) {
int p = start, n = strfrmt.length();
int c = 0;
@@ -394,7 +390,6 @@ public class StringLib extends TwoArgFunction {
zeroPad &= !leftAdjust; // '-' overrides '0'
conversion = c;
length = p - start;
src = strfrmt.substring(start - 1, p).tojstring();
}
public void format(Buffer buf, byte c) {
@@ -470,13 +465,8 @@ public class StringLib extends TwoArgFunction {
}
public void format(Buffer buf, double x) {
String out;
try {
out = String.format(src, x);
} catch (Throwable e) {
out = String.valueOf( x );
}
buf.append( out );
// TODO
buf.append( String.valueOf( x ) );
}
public void format(Buffer buf, LuaString s) {
@@ -535,13 +525,12 @@ public class StringLib extends TwoArgFunction {
this.soffset = 0;
}
public Varargs invoke(Varargs args) {
for ( ; soffset<=srclen; soffset++ ) {
for ( ; soffset<srclen; soffset++ ) {
ms.reset();
int res = ms.match(soffset, 0);
if ( res >=0 ) {
int soff = soffset;
soffset = res;
if (soff == res) soffset++; /* empty match? go at least one position */
return ms.push_captures( true, soff, res );
}
}
@@ -775,7 +764,7 @@ public class StringLib extends TwoArgFunction {
boolean anchor = false;
int poff = 0;
if ( pat.length() > 0 && pat.luaByte( 0 ) == '^' ) {
if ( pat.luaByte( 0 ) == '^' ) {
anchor = true;
poff = 1;
}
@@ -796,7 +785,7 @@ public class StringLib extends TwoArgFunction {
return NIL;
}
static int posrelat( int pos, int len ) {
private static int posrelat( int pos, int len ) {
return ( pos >= 0 ) ? pos : len + pos + 1;
}
@@ -818,7 +807,7 @@ public class StringLib extends TwoArgFunction {
private static final byte MASK_CONTROL = 0x40;
private static final byte MASK_HEXDIGIT = (byte)0x80;
static final byte[] CHAR_TABLE;
private static final byte[] CHAR_TABLE;
static {
CHAR_TABLE = new byte[256];
@@ -972,19 +961,19 @@ public class StringLib extends TwoArgFunction {
switch ( p.luaByte( poffset++ ) ) {
case L_ESC:
if ( poffset == p.length() ) {
error( "malformed pattern (ends with '%')" );
error( "malformed pattern (ends with %)" );
}
return poffset + 1;
case '[':
if ( poffset != p.length() && p.luaByte( poffset ) == '^' ) poffset++;
if ( p.luaByte( poffset ) == '^' ) poffset++;
do {
if ( poffset == p.length() ) {
error( "malformed pattern (missing ']')" );
error( "malformed pattern (missing ])" );
}
if ( p.luaByte( poffset++ ) == L_ESC && poffset < p.length() )
poffset++; /* skip escapes (e.g. '%]') */
} while ( poffset == p.length() || p.luaByte( poffset ) != ']' );
if ( p.luaByte( poffset++ ) == L_ESC && poffset != p.length() )
poffset++;
} while ( p.luaByte( poffset ) != ']' );
return poffset + 1;
default:
return poffset;
@@ -1073,14 +1062,13 @@ public class StringLib extends TwoArgFunction {
continue;
case 'f': {
poffset += 2;
if ( poffset == p.length() || p.luaByte( poffset ) != '[' ) {
error("Missing '[' after '%f' in pattern");
if ( p.luaByte( poffset ) != '[' ) {
error("Missing [ after %f in pattern");
}
int ep = classend( poffset );
int previous = ( soffset == 0 ) ? '\0' : s.luaByte( soffset - 1 );
int next = ( soffset == s.length() ) ? '\0' : s.luaByte( soffset );
int previous = ( soffset == 0 ) ? -1 : s.luaByte( soffset - 1 );
if ( matchbracketclass( previous, poffset, ep - 1 ) ||
!matchbracketclass( next, poffset, ep - 1 ) )
matchbracketclass( s.luaByte( soffset ), poffset, ep - 1 ) )
return -1;
poffset = ep;
continue;

View File

@@ -189,10 +189,8 @@ public class luajc {
public Class findClass(String classname) throws ClassNotFoundException {
byte[] bytes = (byte[]) t.get(classname);
if ( bytes != null ) {
classname = classname.replace('/', '.');
if ( bytes != null )
return defineClass(classname, bytes, 0, bytes.length);
}
return super.findClass(classname);
}
}

View File

@@ -101,7 +101,7 @@ abstract public class Visitor {
visitExps(args.exps);
}
public void visit(TableField field) {
if ( field.name != null )
if ( field.name != null );
visit( field.name );
if ( field.index != null )
field.index.accept(this);

View File

@@ -21,7 +21,6 @@
******************************************************************************/
package org.luaj.vm2.lib.jse;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -134,7 +133,7 @@ public class CoerceJavaToLua {
}
static final Map COERCIONS = Collections.synchronizedMap(new HashMap());
static final Map COERCIONS = new HashMap();
static {
Coercion boolCoercion = new BoolCoercion() ;

View File

@@ -21,7 +21,6 @@
******************************************************************************/
package org.luaj.vm2.lib.jse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -107,10 +106,9 @@ public class JseBaseLib extends org.luaj.vm2.lib.BaseLib {
if ( ! f.exists() )
return super.findResource(filename);
try {
return new BufferedInputStream(new FileInputStream(f));
return new FileInputStream(f);
} catch ( IOException ioe ) {
return null;
}
}
}

View File

@@ -24,7 +24,6 @@ package org.luaj.vm2.lib.jse;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.LibFunction;
import org.luaj.vm2.lib.TwoArgFunction;
/**
* Subclass of {@link LibFunction} which implements the lua standard {@code math}
@@ -77,9 +76,8 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
LuaValue math = env.get("math");
math.set("acos", new acos());
math.set("asin", new asin());
LuaValue atan = new atan2();
math.set("atan", atan);
math.set("atan2", atan);
math.set("atan", new atan());
math.set("atan2", new atan2());
math.set("cosh", new cosh());
math.set("exp", new exp());
math.set("log", new log());
@@ -91,11 +89,8 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
static final class acos extends UnaryOp { protected double call(double d) { return Math.acos(d); } }
static final class asin extends UnaryOp { protected double call(double d) { return Math.asin(d); } }
static final class atan2 extends TwoArgFunction {
public LuaValue call(LuaValue x, LuaValue y) {
return valueOf(Math.atan2(x.checkdouble(), y.optdouble(1)));
}
}
static final class atan extends UnaryOp { protected double call(double d) { return Math.atan(d); } }
static final class atan2 extends BinaryOp { protected double call(double y, double x) { return Math.atan2(y, x); } }
static final class cosh extends UnaryOp { protected double call(double d) { return Math.cosh(d); } }
static final class exp extends UnaryOp { protected double call(double d) { return Math.exp(d); } }
static final class log extends UnaryOp { protected double call(double d) { return Math.log(d); } }
@@ -110,4 +105,3 @@ public class JseMathLib extends org.luaj.vm2.lib.MathLib {
}

View File

@@ -74,13 +74,13 @@ import org.luaj.vm2.lib.OsLib;
public class JseOsLib extends org.luaj.vm2.lib.OsLib {
/** return code indicating the execute() threw an I/O exception */
public static final int EXEC_IOEXCEPTION = 1;
public static int EXEC_IOEXCEPTION = 1;
/** return code indicating the execute() was interrupted */
public static final int EXEC_INTERRUPTED = -2;
public static int EXEC_INTERRUPTED = -2;
/** return code indicating the execute() threw an unknown exception */
public static final int EXEC_ERROR = -3;
public static int EXEC_ERROR = -3;
/** public constructor */
public JseOsLib() {
@@ -120,7 +120,7 @@ public class JseOsLib extends org.luaj.vm2.lib.OsLib {
if ( ! f.exists() )
throw new IOException("No such file or directory");
if ( ! f.renameTo(new File(newname)) )
throw new IOException("Failed to rename");
throw new IOException("Failed to delete");
}
protected String tmpname() {

View File

@@ -25,7 +25,6 @@ import org.luaj.vm2.Globals;
import org.luaj.vm2.LoadState;
import org.luaj.vm2.LuaThread;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.Bit32Lib;
import org.luaj.vm2.lib.CoroutineLib;
@@ -125,11 +124,10 @@ public class JsePlatform {
/** Simple wrapper for invoking a lua function with command line arguments.
* The supplied function is first given a new Globals object as its environment
* then the program is run with arguments.
* @return {@link Varargs} containing any values returned by mainChunk.
* The supplied function is first given a new Globals object,
* then the program is run with arguments.
*/
public static Varargs luaMain(LuaValue mainChunk, String[] args) {
public static void luaMain(LuaValue mainChunk, String[] args) {
Globals g = standardGlobals();
int n = args.length;
LuaValue[] vargs = new LuaValue[args.length];
@@ -139,6 +137,6 @@ public class JsePlatform {
arg.set("n", n);
g.set("arg", arg);
mainChunk.initupvalue1(g);
return mainChunk.invoke(LuaValue.varargsOf(vargs));
mainChunk.invoke(LuaValue.varargsOf(vargs));
}
}

View File

@@ -114,24 +114,7 @@ public class LuaJC implements Globals.Loader {
StringBuffer classname = new StringBuffer();
for (int i = 0, n = stub.length(); i < n; ++i) {
final char c = stub.charAt(i);
switch(i) {
case 0:
if(Character.isJavaIdentifierStart(c)) {
classname.append(c);
} else {
classname.append('_');
}
break;
default:
if(c == '/') {
classname.append(c);
} else if(Character.isJavaIdentifierPart(c)) {
classname.append(c);
} else {
classname.append('_');
}
break;
}
classname.append((((i == 0) && Character.isJavaIdentifierStart(c)) || ((i > 0) && Character.isJavaIdentifierPart(c)))? c: '_');
}
return classname.toString();
}

View File

@@ -32,7 +32,6 @@ import org.luaj.vm2.compiler.DumpLoadEndianIntTest;
import org.luaj.vm2.compiler.LuaParserTests;
import org.luaj.vm2.compiler.RegressionTests;
import org.luaj.vm2.compiler.SimpleTests;
import org.luaj.vm2.lib.jse.JsePlatformTest;
import org.luaj.vm2.lib.jse.LuaJavaCoercionTest;
import org.luaj.vm2.lib.jse.LuajavaAccessibleMembersTest;
import org.luaj.vm2.lib.jse.LuajavaClassMembersTest;
@@ -86,7 +85,6 @@ public class AllTests {
// library tests
TestSuite lib = new TestSuite("Library Tests");
lib.addTestSuite(JsePlatformTest.class);
lib.addTestSuite(LuajavaAccessibleMembersTest.class);
lib.addTestSuite(LuajavaClassMembersTest.class);
lib.addTestSuite(LuaJavaCoercionTest.class);

View File

@@ -1,21 +0,0 @@
package org.luaj.vm2.lib.jse;
import junit.framework.TestCase;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
public class JsePlatformTest extends TestCase {
public void testLuaMainPassesArguments() {
Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globals.load("return #arg, arg.n, arg[2], arg[1]");
Varargs results = JsePlatform.luaMain(chunk, new String[] { "aaa", "bbb" });
assertEquals(results.narg(), 4);
assertEquals(results.arg(1), LuaValue.valueOf(2));
assertEquals(results.arg(2), LuaValue.valueOf(2));
assertEquals(results.arg(3), LuaValue.valueOf("bbb"));
assertEquals(results.arg(4), LuaValue.valueOf("aaa"));
}
}

View File

@@ -1 +1 @@
version: 3.0.2
version: 3.0.1