Major refactoring of package names, class names
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src/main/java"/>
|
<classpathentry kind="src" path="src/core"/>
|
||||||
<classpathentry kind="src" path="src/addon/java"/>
|
<classpathentry kind="src" path="src/j2se"/>
|
||||||
|
<classpathentry kind="src" path="src/debug"/>
|
||||||
|
<classpathentry kind="src" path="src/sample"/>
|
||||||
<classpathentry kind="src" path="src/test/java"/>
|
<classpathentry kind="src" path="src/test/java"/>
|
||||||
<classpathentry kind="src" path="src/test/res"/>
|
<classpathentry kind="src" path="src/test/res"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
|||||||
27
build.xml
27
build.xml
@@ -15,9 +15,8 @@
|
|||||||
<target name="compile">
|
<target name="compile">
|
||||||
<mkdir dir="build/all/classes"/>
|
<mkdir dir="build/all/classes"/>
|
||||||
<javac destdir="build/all/classes" encoding="utf-8" source="1.3" target="1.1">
|
<javac destdir="build/all/classes" encoding="utf-8" source="1.3" target="1.1">
|
||||||
<src path="src/main/java" />
|
<src path="src/core" />
|
||||||
<src path="src/addon/java" />
|
<src path="src/j2se" />
|
||||||
<exclude name="lua/debug/j2me/**"/>
|
|
||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
@@ -53,11 +52,10 @@
|
|||||||
<mkdir dir="build/core/classes"/>
|
<mkdir dir="build/core/classes"/>
|
||||||
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.1"
|
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.1"
|
||||||
bootclasspathref="wtk-libs">
|
bootclasspathref="wtk-libs">
|
||||||
<src path="src/main/java"/>
|
<src path="src/core" />
|
||||||
<src path="src/addon/java"/>
|
<src path="src/debug" />
|
||||||
<exclude name="lua/debug/j2se/**"/>
|
<exclude name="org/luaj/debug/j2se/**"/>
|
||||||
<exclude name="lua/debug/j2me/**"/>
|
<exclude name="org/luaj/debug/j2me/**"/>
|
||||||
<exclude name="lua/addon/luajava/**"/>
|
|
||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
@@ -65,10 +63,10 @@
|
|||||||
<mkdir dir="build/extras-j2se/classes"/>
|
<mkdir dir="build/extras-j2se/classes"/>
|
||||||
<javac destdir="build/extras-j2se/classes" encoding="utf-8" source="1.3" target="1.1"
|
<javac destdir="build/extras-j2se/classes" encoding="utf-8" source="1.3" target="1.1"
|
||||||
classpath="build/core/classes">
|
classpath="build/core/classes">
|
||||||
<src path="src/main/java"/>
|
<src path="src/debug" />
|
||||||
<src path="src/addon/java"/>
|
<src path="src/j2se" />
|
||||||
<include name="lua/debug/j2se/**"/>
|
<include name="org/luaj/debug/j2se/**"/>
|
||||||
<include name="lua/addon/luajava/**"/>
|
<include name="org/luaj/lib/j2se/**"/>
|
||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
@@ -76,9 +74,8 @@
|
|||||||
<mkdir dir="build/extras-j2me/classes"/>
|
<mkdir dir="build/extras-j2me/classes"/>
|
||||||
<javac destdir="build/extras-j2me/classes" encoding="utf-8" source="1.3" target="1.1"
|
<javac destdir="build/extras-j2me/classes" encoding="utf-8" source="1.3" target="1.1"
|
||||||
bootclasspathref="wtk-libs" classpath="build/core/classes">
|
bootclasspathref="wtk-libs" classpath="build/core/classes">
|
||||||
<src path="src/main/java"/>
|
<src path="src/debug" />
|
||||||
<src path="src/addon/java"/>
|
<exclude name="org/luaj/debug/j2se/**"/>
|
||||||
<include name="lua/debug/j2me/**"/>
|
|
||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package lua.addon.compile;
|
|
||||||
|
|
||||||
import lua.io.Proto;
|
|
||||||
|
|
||||||
public class CheckCode {
|
|
||||||
|
|
||||||
public static boolean checkcode(Proto f) {
|
|
||||||
// TODO: port logic from ldebug.c
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import lua.addon.luacompat.Platform;
|
import org.luaj.vm.LString;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LPrototype;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
|
||||||
public class Compiler {
|
public class Compiler {
|
||||||
|
|
||||||
@@ -23,12 +24,12 @@ public class Compiler {
|
|||||||
* @param stream InputStream to read from.
|
* @param stream InputStream to read from.
|
||||||
* @param name Name of the chunk
|
* @param name Name of the chunk
|
||||||
* @return null if the first byte indicates it is a binary chunk,
|
* @return null if the first byte indicates it is a binary chunk,
|
||||||
* a Proto instance if it can be compiled,
|
* a LPrototype instance if it can be compiled,
|
||||||
* or an exception is thrown if there is an error.
|
* or an exception is thrown if there is an error.
|
||||||
* @throws IOException if an I/O exception occurs
|
* @throws IOException if an I/O exception occurs
|
||||||
* @throws RuntimeException if there is a syntax error.
|
* @throws RuntimeException if there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public static Proto compile(InputStream stream, String name) throws IOException {
|
public static LPrototype compile(InputStream stream, String name) throws IOException {
|
||||||
|
|
||||||
int c = stream.read();
|
int c = stream.read();
|
||||||
if ( c == LUAC_BINARY_SIG )
|
if ( c == LUAC_BINARY_SIG )
|
||||||
@@ -40,7 +41,7 @@ public class Compiler {
|
|||||||
|
|
||||||
public int nCcalls;
|
public int nCcalls;
|
||||||
|
|
||||||
Proto luaY_parser(int firstByte, Reader z, String name) {
|
LPrototype luaY_parser(int firstByte, Reader z, String name) {
|
||||||
LexState lexstate = new LexState(this, z);
|
LexState lexstate = new LexState(this, z);
|
||||||
FuncState funcstate = new FuncState();
|
FuncState funcstate = new FuncState();
|
||||||
// lexstate.buff = buff;
|
// lexstate.buff = buff;
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import lua.Lua;
|
import org.luaj.vm.LBoolean;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LNil;
|
||||||
import lua.value.LBoolean;
|
import org.luaj.vm.LNumber;
|
||||||
import lua.value.LNil;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LNumber;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.Lua;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LPrototype;
|
||||||
|
|
||||||
|
|
||||||
public class DumpState {
|
public class DumpState {
|
||||||
|
|
||||||
@@ -85,14 +86,14 @@ public class DumpState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpCode( final Proto f ) throws IOException {
|
void dumpCode( final LPrototype f ) throws IOException {
|
||||||
int n = f.code.length;
|
int n = f.code.length;
|
||||||
dumpInt( n );
|
dumpInt( n );
|
||||||
for ( int i=0; i<n; i++ )
|
for ( int i=0; i<n; i++ )
|
||||||
dumpInt( f.code[i] );
|
dumpInt( f.code[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpConstants(final Proto f) throws IOException {
|
void dumpConstants(final LPrototype f) throws IOException {
|
||||||
int i, n = f.k.length;
|
int i, n = f.k.length;
|
||||||
dumpInt(n);
|
dumpInt(n);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
@@ -119,7 +120,7 @@ public class DumpState {
|
|||||||
dumpFunction(f.p[i], f.source);
|
dumpFunction(f.p[i], f.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpDebug(final Proto f) throws IOException {
|
void dumpDebug(final LPrototype f) throws IOException {
|
||||||
int i, n;
|
int i, n;
|
||||||
n = (strip) ? 0 : f.lineinfo.length;
|
n = (strip) ? 0 : f.lineinfo.length;
|
||||||
dumpInt(n);
|
dumpInt(n);
|
||||||
@@ -138,7 +139,7 @@ public class DumpState {
|
|||||||
dumpString(f.upvalues[i]);
|
dumpString(f.upvalues[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpFunction(final Proto f, final LString string) throws IOException {
|
void dumpFunction(final LPrototype f, final LString string) throws IOException {
|
||||||
if ( f.source == null || f.source.equals(string) || strip )
|
if ( f.source == null || f.source.equals(string) || strip )
|
||||||
dumpInt(0);
|
dumpInt(0);
|
||||||
else
|
else
|
||||||
@@ -169,14 +170,14 @@ public class DumpState {
|
|||||||
/*
|
/*
|
||||||
** dump Lua function as precompiled chunk
|
** dump Lua function as precompiled chunk
|
||||||
*/
|
*/
|
||||||
public static int dump( Proto f, OutputStream w, boolean strip ) throws IOException {
|
public static int dump( LPrototype f, OutputStream w, boolean strip ) throws IOException {
|
||||||
DumpState D = new DumpState(w,strip);
|
DumpState D = new DumpState(w,strip);
|
||||||
D.dumpHeader();
|
D.dumpHeader();
|
||||||
D.dumpFunction(f,null);
|
D.dumpFunction(f,null);
|
||||||
return D.status;
|
return D.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int dump(Proto f, OutputStream w, boolean strip, boolean intonly, boolean littleendian) throws IOException {
|
public static int dump(LPrototype f, OutputStream w, boolean strip, boolean intonly, boolean littleendian) throws IOException {
|
||||||
DumpState D = new DumpState(w,strip);
|
DumpState D = new DumpState(w,strip);
|
||||||
D.IS_LITTLE_ENDIAN = littleendian;
|
D.IS_LITTLE_ENDIAN = littleendian;
|
||||||
D.IS_NUMBER_INTEGRAL = intonly;
|
D.IS_NUMBER_INTEGRAL = intonly;
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import lua.Lua;
|
import org.luaj.compiler.LexState.ConsControl;
|
||||||
import lua.addon.compile.LexState.ConsControl;
|
import org.luaj.compiler.LexState.expdesc;
|
||||||
import lua.addon.compile.LexState.expdesc;
|
import org.luaj.vm.LBoolean;
|
||||||
import lua.io.LocVars;
|
import org.luaj.vm.LDouble;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LInteger;
|
||||||
import lua.value.LBoolean;
|
import org.luaj.vm.LNil;
|
||||||
import lua.value.LDouble;
|
import org.luaj.vm.LNumber;
|
||||||
import lua.value.LInteger;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LNil;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LNumber;
|
import org.luaj.vm.LocVars;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.Lua;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LPrototype;
|
||||||
|
|
||||||
|
|
||||||
public class FuncState extends LuaC {
|
public class FuncState extends LuaC {
|
||||||
class upvaldesc {
|
class upvaldesc {
|
||||||
@@ -29,7 +30,7 @@ public class FuncState extends LuaC {
|
|||||||
boolean isbreakable; /* true if `block' is a loop */
|
boolean isbreakable; /* true if `block' is a loop */
|
||||||
};
|
};
|
||||||
|
|
||||||
Proto f; /* current function header */
|
LPrototype f; /* current function header */
|
||||||
// LTable h; /* table to find (and reuse) elements in `k' */
|
// LTable h; /* table to find (and reuse) elements in `k' */
|
||||||
Hashtable htable; /* table to find (and reuse) elements in `k' */
|
Hashtable htable; /* table to find (and reuse) elements in `k' */
|
||||||
FuncState prev; /* enclosing function */
|
FuncState prev; /* enclosing function */
|
||||||
@@ -418,7 +419,7 @@ public class FuncState extends LuaC {
|
|||||||
} else {
|
} else {
|
||||||
idx = this.nk;
|
idx = this.nk;
|
||||||
this.htable.put(v, new Integer(idx));
|
this.htable.put(v, new Integer(idx));
|
||||||
final Proto f = this.f;
|
final LPrototype f = this.f;
|
||||||
if (f.k == null || nk + 1 >= f.k.length)
|
if (f.k == null || nk + 1 >= f.k.length)
|
||||||
f.k = realloc( f.k, nk*2 + 1 );
|
f.k = realloc( f.k, nk*2 + 1 );
|
||||||
f.k[this.nk++] = v;
|
f.k[this.nk++] = v;
|
||||||
@@ -1010,7 +1011,7 @@ public class FuncState extends LuaC {
|
|||||||
|
|
||||||
|
|
||||||
int code(int instruction, int line) {
|
int code(int instruction, int line) {
|
||||||
Proto f = this.f;
|
LPrototype f = this.f;
|
||||||
this.dischargejpc(); /* `pc' will change */
|
this.dischargejpc(); /* `pc' will change */
|
||||||
/* put new instruction in code array */
|
/* put new instruction in code array */
|
||||||
if (f.code == null || this.pc + 1 > f.code.length)
|
if (f.code == null || this.pc + 1 > f.code.length)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
class InstructionPtr {
|
class InstructionPtr {
|
||||||
final int[] code;
|
final int[] code;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
public class IntPtr {
|
public class IntPtr {
|
||||||
int i;
|
int i;
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import lua.Lua;
|
import org.luaj.compiler.FuncState.BlockCnt;
|
||||||
import lua.addon.compile.FuncState.BlockCnt;
|
import org.luaj.vm.LDouble;
|
||||||
import lua.io.LocVars;
|
import org.luaj.vm.LInteger;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LNumber;
|
||||||
import lua.value.LDouble;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LInteger;
|
import org.luaj.vm.LocVars;
|
||||||
import lua.value.LNumber;
|
import org.luaj.vm.Lua;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LPrototype;
|
||||||
|
|
||||||
|
|
||||||
public class LexState extends LuaC {
|
public class LexState extends LuaC {
|
||||||
|
|
||||||
@@ -781,7 +782,7 @@ public class LexState extends LuaC {
|
|||||||
|
|
||||||
int registerlocalvar(LString varname) {
|
int registerlocalvar(LString varname) {
|
||||||
FuncState fs = this.fs;
|
FuncState fs = this.fs;
|
||||||
Proto f = fs.f;
|
LPrototype f = fs.f;
|
||||||
if (f.locvars == null || fs.nlocvars + 1 > f.locvars.length)
|
if (f.locvars == null || fs.nlocvars + 1 > f.locvars.length)
|
||||||
f.locvars = realloc( f.locvars, fs.nlocvars*2+1 );
|
f.locvars = realloc( f.locvars, fs.nlocvars*2+1 );
|
||||||
f.locvars[fs.nlocvars] = new LocVars(varname,0,0);
|
f.locvars[fs.nlocvars] = new LocVars(varname,0,0);
|
||||||
@@ -860,7 +861,7 @@ public class LexState extends LuaC {
|
|||||||
|
|
||||||
void pushclosure(FuncState func, expdesc v) {
|
void pushclosure(FuncState func, expdesc v) {
|
||||||
FuncState fs = this.fs;
|
FuncState fs = this.fs;
|
||||||
Proto f = fs.f;
|
LPrototype f = fs.f;
|
||||||
if (f.p == null || fs.np + 1 > f.p.length)
|
if (f.p == null || fs.np + 1 > f.p.length)
|
||||||
f.p = realloc( f.p, fs.np*2 + 1 );
|
f.p = realloc( f.p, fs.np*2 + 1 );
|
||||||
f.p[fs.np++] = func.f;
|
f.p[fs.np++] = func.f;
|
||||||
@@ -874,7 +875,7 @@ public class LexState extends LuaC {
|
|||||||
|
|
||||||
void open_func (FuncState fs) {
|
void open_func (FuncState fs) {
|
||||||
Compiler L = this.L;
|
Compiler L = this.L;
|
||||||
Proto f = new Proto();
|
LPrototype f = new LPrototype();
|
||||||
if ( this.fs!=null )
|
if ( this.fs!=null )
|
||||||
f.source = this.fs.f.source;
|
f.source = this.fs.f.source;
|
||||||
fs.f = f;
|
fs.f = f;
|
||||||
@@ -898,9 +899,9 @@ public class LexState extends LuaC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void close_func() {
|
void close_func() {
|
||||||
Compiler L = this.L;
|
// Compiler L = this.L;
|
||||||
FuncState fs = this.fs;
|
FuncState fs = this.fs;
|
||||||
Proto f = fs.f;
|
LPrototype f = fs.f;
|
||||||
this.removevars(0);
|
this.removevars(0);
|
||||||
fs.ret(0, 0); /* final return */
|
fs.ret(0, 0); /* final return */
|
||||||
f.code = realloc(f.code, fs.pc);
|
f.code = realloc(f.code, fs.pc);
|
||||||
@@ -911,7 +912,7 @@ public class LexState extends LuaC {
|
|||||||
f.locvars = realloc(f.locvars, fs.nlocvars);
|
f.locvars = realloc(f.locvars, fs.nlocvars);
|
||||||
// f.sizelocvars = fs.nlocvars;
|
// f.sizelocvars = fs.nlocvars;
|
||||||
f.upvalues = realloc(f.upvalues, f.nups);
|
f.upvalues = realloc(f.upvalues, f.nups);
|
||||||
_assert (CheckCode.checkcode(f));
|
// _assert (CheckCode.checkcode(f));
|
||||||
_assert (fs.bl == null);
|
_assert (fs.bl == null);
|
||||||
this.fs = fs.prev;
|
this.fs = fs.prev;
|
||||||
// L.top -= 2; /* remove table and prototype from the stack */
|
// L.top -= 2; /* remove table and prototype from the stack */
|
||||||
@@ -1052,7 +1053,7 @@ public class LexState extends LuaC {
|
|||||||
void parlist () {
|
void parlist () {
|
||||||
/* parlist -> [ param { `,' param } ] */
|
/* parlist -> [ param { `,' param } ] */
|
||||||
FuncState fs = this.fs;
|
FuncState fs = this.fs;
|
||||||
Proto f = fs.f;
|
LPrototype f = fs.f;
|
||||||
int nparams = 0;
|
int nparams = 0;
|
||||||
f.is_vararg = false;
|
f.is_vararg = false;
|
||||||
if (this.t.token != ')') { /* is `parlist' not empty? */
|
if (this.t.token != ')') { /* is `parlist' not empty? */
|
||||||
@@ -1,21 +1,24 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
|
import org.luaj.vm.LString;
|
||||||
|
import org.luaj.vm.LValue;
|
||||||
|
import org.luaj.vm.LocVars;
|
||||||
|
import org.luaj.vm.Lua;
|
||||||
|
import org.luaj.vm.LPrototype;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
import lua.io.LocVars;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.value.LString;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional constants and utilities required for the compiler,
|
* Additional constants and utilities required for the compiler,
|
||||||
* but not required for the interpreter.
|
* but not required for the interpreter.
|
||||||
*
|
*
|
||||||
|
* * @deprecated - this class will go away. Constants will probably move to LexState
|
||||||
*/
|
*/
|
||||||
public class LuaC extends Lua {
|
public class LuaC extends Lua {
|
||||||
protected static void _assert(boolean b) {
|
protected static void _assert(boolean b) {
|
||||||
if (!b) throw new RuntimeException("assert failed");
|
if (!b) throw new RuntimeException("assert failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final int MAXSTACK = 250;
|
||||||
static final int LUAI_MAXUPVALUES = 60;
|
static final int LUAI_MAXUPVALUES = 60;
|
||||||
static final int LUAI_MAXVARS = 200;
|
static final int LUAI_MAXVARS = 200;
|
||||||
static final int LFIELDS_PER_FLUSH = 50;
|
static final int LFIELDS_PER_FLUSH = 50;
|
||||||
@@ -87,8 +90,8 @@ public class LuaC extends Lua {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Proto[] realloc(Proto[] v, int n) {
|
static LPrototype[] realloc(LPrototype[] v, int n) {
|
||||||
Proto[] a = new Proto[n];
|
LPrototype[] a = new LPrototype[n];
|
||||||
if ( v != null )
|
if ( v != null )
|
||||||
System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
|
System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
|
||||||
return a;
|
return a;
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package lua.addon.luacompat;
|
package org.luaj.lib;
|
||||||
|
|
||||||
import lua.GlobalState;
|
import org.luaj.vm.LClosure;
|
||||||
import lua.VM;
|
import org.luaj.vm.LFunction;
|
||||||
import lua.io.Closure;
|
import org.luaj.vm.LTable;
|
||||||
import lua.value.LFunction;
|
import org.luaj.vm.LThread;
|
||||||
import lua.value.LTable;
|
import org.luaj.vm.LuaState;
|
||||||
import lua.value.LThread;
|
|
||||||
|
|
||||||
|
public class CoroutineLib extends LFunction {
|
||||||
public class CoroutinesLib extends LFunction {
|
|
||||||
|
|
||||||
private static final String[] NAMES = {
|
private static final String[] NAMES = {
|
||||||
"loadlib",
|
"loadlib",
|
||||||
@@ -21,22 +19,22 @@ public class CoroutinesLib extends LFunction {
|
|||||||
"wrapped"
|
"wrapped"
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void install() {
|
public static void install( LTable globals ) {
|
||||||
LTable lib = new LTable(0,6);
|
LTable lib = new LTable(0,6);
|
||||||
for ( int i=1; i<=6; i++ )
|
for ( int i=1; i<=6; i++ )
|
||||||
lib.put(NAMES[i], new CoroutinesLib(i));
|
lib.put(NAMES[i], new CoroutineLib(i));
|
||||||
GlobalState.getGlobalsTable().put("coroutine",lib);
|
globals.put("coroutine",lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private final LThread thread;
|
private final LThread thread;
|
||||||
|
|
||||||
public CoroutinesLib() {
|
public CoroutineLib() {
|
||||||
this.id = 0;
|
this.id = 0;
|
||||||
this.thread = null;
|
this.thread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoroutinesLib( int id ) {
|
private CoroutineLib( int id ) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.thread = null;
|
this.thread = null;
|
||||||
}
|
}
|
||||||
@@ -45,20 +43,20 @@ public class CoroutinesLib extends LFunction {
|
|||||||
return "coroutine."+NAMES[id];
|
return "coroutine."+NAMES[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
private CoroutinesLib( int id, LThread thread ) {
|
private CoroutineLib( int id, LThread thread ) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean luaStackCall( VM vm ) {
|
public boolean luaStackCall( LuaState vm ) {
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case 0: { // load lib
|
case 0: { // load lib
|
||||||
install();
|
install(vm._G);
|
||||||
vm.pushnil();
|
vm.pushnil();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: { // create
|
case 1: { // create
|
||||||
Closure c = (Closure) vm.topointer(2);
|
LClosure c = (LClosure) vm.topointer(2);
|
||||||
vm.pushlvalue( new LThread(c) );
|
vm.pushlvalue( new LThread(c) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -81,8 +79,8 @@ public class CoroutinesLib extends LFunction {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: { // wrap
|
case 5: { // wrap
|
||||||
Closure c = (Closure) vm.topointer(2);
|
LClosure c = (LClosure) vm.topointer(2);
|
||||||
vm.pushlvalue( new CoroutinesLib(7,new LThread(c)) );
|
vm.pushlvalue( new CoroutineLib(7,new LThread(c)) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 6: { // yield
|
case 6: { // yield
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package lua.addon.luacompat;
|
package org.luaj.lib;
|
||||||
|
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LString;
|
||||||
|
|
||||||
public class LBuffer {
|
public class LBuffer {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.luacompat;
|
package org.luaj.lib;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -7,30 +7,29 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import lua.CallInfo;
|
import org.luaj.vm.CallInfo;
|
||||||
import lua.GlobalState;
|
import org.luaj.vm.LBoolean;
|
||||||
import lua.Lua;
|
import org.luaj.vm.LClosure;
|
||||||
import lua.StackState;
|
import org.luaj.vm.LDouble;
|
||||||
import lua.VM;
|
import org.luaj.vm.LFunction;
|
||||||
import lua.io.Closure;
|
import org.luaj.vm.LInteger;
|
||||||
import lua.value.LBoolean;
|
import org.luaj.vm.LNil;
|
||||||
import lua.value.LDouble;
|
import org.luaj.vm.LNumber;
|
||||||
import lua.value.LFunction;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LInteger;
|
import org.luaj.vm.LTable;
|
||||||
import lua.value.LNil;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LNumber;
|
import org.luaj.vm.Lua;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LuaState;
|
||||||
import lua.value.LTable;
|
import org.luaj.vm.Platform;
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
public class LuaCompat extends LFunction {
|
|
||||||
|
public class MathLib extends LFunction {
|
||||||
|
|
||||||
public static InputStream STDIN = null;
|
public static InputStream STDIN = null;
|
||||||
public static PrintStream STDOUT = System.out;
|
public static PrintStream STDOUT = System.out;
|
||||||
public static LTable LOADED = new LTable();
|
public static LTable LOADED = new LTable();
|
||||||
|
|
||||||
public static void install() {
|
public static void install( LTable globals ) {
|
||||||
LTable globals = GlobalState.getGlobalsTable();
|
|
||||||
installNames( globals, GLOBAL_NAMES, GLOBALS_BASE );
|
installNames( globals, GLOBAL_NAMES, GLOBALS_BASE );
|
||||||
|
|
||||||
// math lib
|
// math lib
|
||||||
@@ -53,16 +52,16 @@ public class LuaCompat extends LFunction {
|
|||||||
|
|
||||||
// table lib
|
// table lib
|
||||||
LTable table = new LTable();
|
LTable table = new LTable();
|
||||||
installNames( pckg, TABLE_NAMES, TABLES_BASE );
|
installNames( table, TABLE_NAMES, TABLES_BASE );
|
||||||
globals.put( "table", pckg );
|
globals.put( "table", table );
|
||||||
|
|
||||||
// coroutines
|
// coroutines
|
||||||
CoroutinesLib.install();
|
CoroutineLib.install(globals);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void installNames( LTable table, String[] names, int indexBase ) {
|
private static void installNames( LTable table, String[] names, int indexBase ) {
|
||||||
for ( int i=0; i<names.length; i++ )
|
for ( int i=0; i<names.length; i++ )
|
||||||
table.put( names[i], new LuaCompat(indexBase+i) );
|
table.put( names[i], new MathLib(indexBase+i) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String[] GLOBAL_NAMES = {
|
public static final String[] GLOBAL_NAMES = {
|
||||||
@@ -183,22 +182,22 @@ public class LuaCompat extends LFunction {
|
|||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
private LuaCompat( int id ) {
|
private MathLib( int id ) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setResult( VM vm, LValue value ) {
|
private static void setResult( LuaState vm, LValue value ) {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushlvalue( value );
|
vm.pushlvalue( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setErrorResult( VM vm, String message ) {
|
private static void setErrorResult( LuaState vm, String message ) {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushnil();
|
vm.pushnil();
|
||||||
vm.pushstring( message );
|
vm.pushstring( message );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean luaStackCall( VM vm ) {
|
public boolean luaStackCall( LuaState vm ) {
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case LOADFILE:
|
case LOADFILE:
|
||||||
loadfile(vm, vm.tostring(2));
|
loadfile(vm, vm.tostring(2));
|
||||||
@@ -226,7 +225,7 @@ public class LuaCompat extends LFunction {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case SETFENV:
|
case SETFENV:
|
||||||
setfenv( (StackState) vm );
|
setfenv( (LuaState) vm );
|
||||||
break;
|
break;
|
||||||
case SELECT:
|
case SELECT:
|
||||||
select( vm );
|
select( vm );
|
||||||
@@ -291,46 +290,46 @@ public class LuaCompat extends LFunction {
|
|||||||
|
|
||||||
// String functions
|
// String functions
|
||||||
case BYTE:
|
case BYTE:
|
||||||
StrLib.byte_( vm );
|
StringLib.byte_( vm );
|
||||||
break;
|
break;
|
||||||
case CHAR:
|
case CHAR:
|
||||||
StrLib.char_( vm );
|
StringLib.char_( vm );
|
||||||
break;
|
break;
|
||||||
case DUMP:
|
case DUMP:
|
||||||
StrLib.dump( vm );
|
StringLib.dump( vm );
|
||||||
break;
|
break;
|
||||||
case FIND:
|
case FIND:
|
||||||
StrLib.find( vm );
|
StringLib.find( vm );
|
||||||
break;
|
break;
|
||||||
case FORMAT:
|
case FORMAT:
|
||||||
StrLib.format( vm );
|
StringLib.format( vm );
|
||||||
break;
|
break;
|
||||||
case GMATCH:
|
case GMATCH:
|
||||||
StrLib.gmatch( vm );
|
StringLib.gmatch( vm );
|
||||||
break;
|
break;
|
||||||
case GSUB:
|
case GSUB:
|
||||||
StrLib.gsub( vm );
|
StringLib.gsub( vm );
|
||||||
break;
|
break;
|
||||||
case LEN:
|
case LEN:
|
||||||
StrLib.len( vm );
|
StringLib.len( vm );
|
||||||
break;
|
break;
|
||||||
case LOWER:
|
case LOWER:
|
||||||
StrLib.lower( vm );
|
StringLib.lower( vm );
|
||||||
break;
|
break;
|
||||||
case MATCH:
|
case MATCH:
|
||||||
StrLib.match( vm );
|
StringLib.match( vm );
|
||||||
break;
|
break;
|
||||||
case REP:
|
case REP:
|
||||||
StrLib.rep( vm );
|
StringLib.rep( vm );
|
||||||
break;
|
break;
|
||||||
case REVERSE:
|
case REVERSE:
|
||||||
StrLib.reverse( vm );
|
StringLib.reverse( vm );
|
||||||
break;
|
break;
|
||||||
case SUB:
|
case SUB:
|
||||||
StrLib.sub( vm );
|
StringLib.sub( vm );
|
||||||
break;
|
break;
|
||||||
case UPPER:
|
case UPPER:
|
||||||
StrLib.upper( vm );
|
StringLib.upper( vm );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// package functions
|
// package functions
|
||||||
@@ -364,7 +363,7 @@ public class LuaCompat extends LFunction {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select( VM vm ) {
|
private void select( LuaState vm ) {
|
||||||
LValue arg = vm.topointer(2);
|
LValue arg = vm.topointer(2);
|
||||||
if ( arg instanceof LNumber ) {
|
if ( arg instanceof LNumber ) {
|
||||||
final int start = Math.min(arg.toJavaInt(),vm.gettop());
|
final int start = Math.min(arg.toJavaInt(),vm.gettop());
|
||||||
@@ -389,7 +388,7 @@ public class LuaCompat extends LFunction {
|
|||||||
return rhs.luaBinCmpUnknown( Lua.OP_LT, lhs ) ? lhs: rhs;
|
return rhs.luaBinCmpUnknown( Lua.OP_LT, lhs ) ? lhs: rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modf( VM vm ) {
|
private void modf( LuaState vm ) {
|
||||||
LValue arg = vm.topointer(2);
|
LValue arg = vm.topointer(2);
|
||||||
double v = arg.toJavaDouble();
|
double v = arg.toJavaDouble();
|
||||||
double intPart = ( v > 0 ) ? Math.floor( v ) : Math.ceil( v );
|
double intPart = ( v > 0 ) ? Math.floor( v ) : Math.ceil( v );
|
||||||
@@ -399,7 +398,7 @@ public class LuaCompat extends LFunction {
|
|||||||
vm.pushnumber( fracPart );
|
vm.pushnumber( fracPart );
|
||||||
}
|
}
|
||||||
|
|
||||||
private LValue toNumber( VM vm ) {
|
private LValue toNumber( LuaState vm ) {
|
||||||
LValue input = vm.topointer(2);
|
LValue input = vm.topointer(2);
|
||||||
if ( input instanceof LNumber ) {
|
if ( input instanceof LNumber ) {
|
||||||
return input;
|
return input;
|
||||||
@@ -413,17 +412,17 @@ public class LuaCompat extends LFunction {
|
|||||||
return LNil.NIL;
|
return LNil.NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setfenv( StackState state ) {
|
private void setfenv( LuaState state ) {
|
||||||
LValue f = state.topointer(2);
|
LValue f = state.topointer(2);
|
||||||
LValue newenv = state.topointer(3);
|
LValue newenv = state.topointer(3);
|
||||||
|
|
||||||
Closure c = null;
|
LClosure c = null;
|
||||||
|
|
||||||
// Lua reference manual says that first argument, f, can be a "Lua
|
// Lua reference manual says that first argument, f, can be a "Lua
|
||||||
// function" or an integer. Lots of things extend LFunction, but only
|
// function" or an integer. Lots of things extend LFunction, but only
|
||||||
// instances of Closure are "Lua functions".
|
// instances of Closure are "Lua functions".
|
||||||
if ( f instanceof Closure ) {
|
if ( f instanceof LClosure ) {
|
||||||
c = (Closure) f;
|
c = (LClosure) f;
|
||||||
} else {
|
} else {
|
||||||
int callStackDepth = f.toJavaInt();
|
int callStackDepth = f.toJavaInt();
|
||||||
if ( callStackDepth > 0 ) {
|
if ( callStackDepth > 0 ) {
|
||||||
@@ -472,7 +471,7 @@ public class LuaCompat extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return true if laoded, false if error put onto the stack
|
// return true if laoded, false if error put onto the stack
|
||||||
private static boolean loadis(VM vm, InputStream is, String chunkname ) {
|
private static boolean loadis(LuaState vm, InputStream is, String chunkname ) {
|
||||||
try {
|
try {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
if ( 0 != vm.load(is, chunkname) ) {
|
if ( 0 != vm.load(is, chunkname) ) {
|
||||||
@@ -488,7 +487,7 @@ public class LuaCompat extends LFunction {
|
|||||||
|
|
||||||
|
|
||||||
// return true if loaded, false if error put onto stack
|
// return true if loaded, false if error put onto stack
|
||||||
public static boolean loadfile( VM vm, String fileName ) {
|
public static boolean loadfile( LuaState vm, String fileName ) {
|
||||||
InputStream is;
|
InputStream is;
|
||||||
|
|
||||||
String script;
|
String script;
|
||||||
@@ -509,7 +508,7 @@ public class LuaCompat extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if load succeeds, return 0 for success, 1 for error (as per lua spec)
|
// if load succeeds, return 0 for success, 1 for error (as per lua spec)
|
||||||
private void dofile( VM vm ) {
|
private void dofile( LuaState vm ) {
|
||||||
String filename = vm.tostring(2);
|
String filename = vm.tostring(2);
|
||||||
if ( loadfile( vm, filename ) ) {
|
if ( loadfile( vm, filename ) ) {
|
||||||
int s = vm.pcall(1, 0, 0);
|
int s = vm.pcall(1, 0, 0);
|
||||||
@@ -520,20 +519,20 @@ public class LuaCompat extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return true if loaded, false if error put onto stack
|
// return true if loaded, false if error put onto stack
|
||||||
private boolean loadstring(VM vm, LValue string, String chunkname) {
|
private boolean loadstring(LuaState vm, LValue string, String chunkname) {
|
||||||
return loadis( vm,
|
return loadis( vm,
|
||||||
string.luaAsString().toInputStream(),
|
string.luaAsString().toInputStream(),
|
||||||
("".equals(chunkname)? "(string)": chunkname) );
|
("".equals(chunkname)? "(string)": chunkname) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// return true if loaded, false if error put onto stack
|
// return true if loaded, false if error put onto stack
|
||||||
private boolean load(VM vm, LValue chunkPartLoader, String chunkname) {
|
private boolean load(LuaState vm, LValue chunkPartLoader, String chunkname) {
|
||||||
if ( ! (chunkPartLoader instanceof Closure) ) {
|
if ( ! (chunkPartLoader instanceof LClosure) ) {
|
||||||
vm.error("not a closure: "+chunkPartLoader);
|
vm.error("not a closure: "+chunkPartLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load all the parts
|
// load all the parts
|
||||||
Closure c = (Closure) chunkPartLoader;
|
LClosure c = (LClosure) chunkPartLoader;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
@@ -562,7 +561,7 @@ public class LuaCompat extends LFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LValue tostring(VM vm, LValue arg) {
|
private LValue tostring(LuaState vm, LValue arg) {
|
||||||
return arg.luaAsString();
|
return arg.luaAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +573,7 @@ public class LuaCompat extends LFunction {
|
|||||||
* except that the above code can be written only for a fixed number of elements.
|
* except that the above code can be written only for a fixed number of elements.
|
||||||
* By default, i is 1 and j is the length of the list, as defined by the length operator (see §2.5.5).
|
* By default, i is 1 and j is the length of the list, as defined by the length operator (see §2.5.5).
|
||||||
*/
|
*/
|
||||||
private void unpack(VM vm) {
|
private void unpack(LuaState vm) {
|
||||||
LValue v = vm.topointer(2);
|
LValue v = vm.topointer(2);
|
||||||
int i = vm.tointeger(3);
|
int i = vm.tointeger(3);
|
||||||
int j = vm.tointeger(4);
|
int j = vm.tointeger(4);
|
||||||
@@ -588,14 +587,14 @@ public class LuaCompat extends LFunction {
|
|||||||
vm.pushlvalue( list.get(k) );
|
vm.pushlvalue( list.get(k) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private LValue next(VM vm, LValue table, int index) {
|
private LValue next(LuaState vm, LValue table, int index) {
|
||||||
throw new java.lang.RuntimeException("next() not supported yet");
|
throw new java.lang.RuntimeException("next() not supported yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ======================== Module, Package loading =============================
|
// ======================== Module, Package loading =============================
|
||||||
|
|
||||||
public static void module( VM vm ) {
|
public static void module( LuaState vm ) {
|
||||||
vm.error( "module not implemented" );
|
vm.error( "module not implemented" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,7 +624,7 @@ public class LuaCompat extends LFunction {
|
|||||||
* If there is any error loading or running the module, or if it cannot find any loader for
|
* If there is any error loading or running the module, or if it cannot find any loader for
|
||||||
* the module, then require signals an error.
|
* the module, then require signals an error.
|
||||||
*/
|
*/
|
||||||
public static void require( VM vm ) {
|
public static void require( LuaState vm ) {
|
||||||
LString modname = vm.tolstring(2);
|
LString modname = vm.tolstring(2);
|
||||||
if ( LOADED.containsKey(modname) )
|
if ( LOADED.containsKey(modname) )
|
||||||
setResult( vm, LOADED.get(modname) );
|
setResult( vm, LOADED.get(modname) );
|
||||||
@@ -644,11 +643,11 @@ public class LuaCompat extends LFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadlib( VM vm ) {
|
public static void loadlib( LuaState vm ) {
|
||||||
vm.error( "loadlib not implemented" );
|
vm.error( "loadlib not implemented" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void seeall( VM vm ) {
|
public static void seeall( LuaState vm ) {
|
||||||
vm.error( "seeall not implemented" );
|
vm.error( "seeall not implemented" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,7 +659,7 @@ public class LuaCompat extends LFunction {
|
|||||||
* The default value for sep is the empty string, the default for i is 1, and the default for j is the length of the table.
|
* The default value for sep is the empty string, the default for i is 1, and the default for j is the length of the table.
|
||||||
* If i is greater than j, returns the empty string.
|
* If i is greater than j, returns the empty string.
|
||||||
*/
|
*/
|
||||||
private void concat(VM vm) {
|
private void concat(LuaState vm) {
|
||||||
int n = vm.gettop();
|
int n = vm.gettop();
|
||||||
LTable table = vm.totable(2);
|
LTable table = vm.totable(2);
|
||||||
LString sep = (n>=3? vm.tolstring(3): null);
|
LString sep = (n>=3? vm.tolstring(3): null);
|
||||||
@@ -692,7 +691,7 @@ public class LuaCompat extends LFunction {
|
|||||||
* The default value for pos is n+1, where n is the length of the table (see §2.5.5), so that a call
|
* The default value for pos is n+1, where n is the length of the table (see §2.5.5), so that a call
|
||||||
* table.insert(t,x) inserts x at the end of table t.
|
* table.insert(t,x) inserts x at the end of table t.
|
||||||
*/
|
*/
|
||||||
private void insert(VM vm) {
|
private void insert(LuaState vm) {
|
||||||
int n = vm.gettop();
|
int n = vm.gettop();
|
||||||
LTable table = vm.totable(2);
|
LTable table = vm.totable(2);
|
||||||
int pos = (n>=4? vm.tointeger(3): 0);
|
int pos = (n>=4? vm.tointeger(3): 0);
|
||||||
@@ -706,7 +705,7 @@ public class LuaCompat extends LFunction {
|
|||||||
* Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical
|
* Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical
|
||||||
* indices. (To do its job this function does a linear traversal of the whole table.)
|
* indices. (To do its job this function does a linear traversal of the whole table.)
|
||||||
*/
|
*/
|
||||||
private void maxn(VM vm) {
|
private void maxn(LuaState vm) {
|
||||||
LTable table = vm.totable(2);
|
LTable table = vm.totable(2);
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushinteger( table.luaMaxN() );
|
vm.pushinteger( table.luaMaxN() );
|
||||||
@@ -719,7 +718,7 @@ public class LuaCompat extends LFunction {
|
|||||||
* Returns the value of the removed element. The default value for pos is n, where n is the length of the table,
|
* Returns the value of the removed element. The default value for pos is n, where n is the length of the table,
|
||||||
* so that a call table.remove(t) removes the last element of table t.
|
* so that a call table.remove(t) removes the last element of table t.
|
||||||
*/
|
*/
|
||||||
private void remove(VM vm) {
|
private void remove(LuaState vm) {
|
||||||
int n = vm.gettop();
|
int n = vm.gettop();
|
||||||
LTable table = vm.totable(2);
|
LTable table = vm.totable(2);
|
||||||
int pos = (n>=3? vm.tointeger(3): 0);
|
int pos = (n>=3? vm.tointeger(3): 0);
|
||||||
@@ -736,7 +735,7 @@ public class LuaCompat extends LFunction {
|
|||||||
*
|
*
|
||||||
* The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort.
|
* The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort.
|
||||||
*/
|
*/
|
||||||
private void sort(VM vm) {
|
private void sort(LuaState vm) {
|
||||||
LTable table = vm.totable(2);
|
LTable table = vm.totable(2);
|
||||||
LValue compare = vm.topointer(3);
|
LValue compare = vm.topointer(3);
|
||||||
table.luaSort( vm, compare );
|
table.luaSort( vm, compare );
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package lua.addon.luacompat;
|
package org.luaj.lib;
|
||||||
|
|
||||||
import lua.VM;
|
import org.luaj.vm.LFunction;
|
||||||
import lua.value.LFunction;
|
import org.luaj.vm.LNumber;
|
||||||
import lua.value.LNumber;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LTable;
|
||||||
import lua.value.LTable;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
public class StrLib {
|
|
||||||
|
public class StringLib {
|
||||||
/**
|
/**
|
||||||
* string.byte (s [, i [, j]])
|
* string.byte (s [, i [, j]])
|
||||||
*
|
*
|
||||||
@@ -19,7 +20,7 @@ public class StrLib {
|
|||||||
*
|
*
|
||||||
* @param vm the calling vm
|
* @param vm the calling vm
|
||||||
*/
|
*/
|
||||||
static void byte_( VM vm ) {
|
static void byte_( LuaState vm ) {
|
||||||
LString ls = vm.tolstring(2);
|
LString ls = vm.tolstring(2);
|
||||||
int l = ls.length();
|
int l = ls.length();
|
||||||
final int top = vm.gettop();
|
final int top = vm.gettop();
|
||||||
@@ -48,7 +49,7 @@ public class StrLib {
|
|||||||
*
|
*
|
||||||
* @param vm the calling VM
|
* @param vm the calling VM
|
||||||
*/
|
*/
|
||||||
public static void char_( VM vm) {
|
public static void char_( LuaState vm) {
|
||||||
int nargs = vm.gettop()-1;
|
int nargs = vm.gettop()-1;
|
||||||
byte[] bytes = new byte[nargs];
|
byte[] bytes = new byte[nargs];
|
||||||
for ( int i=0; i<nargs; i++ )
|
for ( int i=0; i<nargs; i++ )
|
||||||
@@ -66,7 +67,7 @@ public class StrLib {
|
|||||||
*
|
*
|
||||||
* TODO: port dumping code as optional add-on
|
* TODO: port dumping code as optional add-on
|
||||||
*/
|
*/
|
||||||
static void dump( VM vm ) {
|
static void dump( LuaState vm ) {
|
||||||
vm.error("dump() not supported");
|
vm.error("dump() not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ public class StrLib {
|
|||||||
* If the pattern has captures, then in a successful match the captured values
|
* If the pattern has captures, then in a successful match the captured values
|
||||||
* are also returned, after the two indices.
|
* are also returned, after the two indices.
|
||||||
*/
|
*/
|
||||||
static void find( VM vm ) {
|
static void find( LuaState vm ) {
|
||||||
str_find_aux( vm, true );
|
str_find_aux( vm, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ public class StrLib {
|
|||||||
* This function does not accept string values containing embedded zeros,
|
* This function does not accept string values containing embedded zeros,
|
||||||
* except as arguments to the q option.
|
* except as arguments to the q option.
|
||||||
*/
|
*/
|
||||||
static void format( VM vm ) {
|
static void format( LuaState vm ) {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushstring( "" );
|
vm.pushstring( "" );
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ public class StrLib {
|
|||||||
* For this function, a '^' at the start of a pattern does not work as an anchor,
|
* For this function, a '^' at the start of a pattern does not work as an anchor,
|
||||||
* as this would prevent the iteration.
|
* as this would prevent the iteration.
|
||||||
*/
|
*/
|
||||||
static void gmatch( VM vm ) {
|
static void gmatch( LuaState vm ) {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushlvalue( new GMatchAux(vm) );
|
vm.pushlvalue( new GMatchAux(vm) );
|
||||||
}
|
}
|
||||||
@@ -152,14 +153,14 @@ public class StrLib {
|
|||||||
private final int srclen;
|
private final int srclen;
|
||||||
private final MatchState ms;
|
private final MatchState ms;
|
||||||
private int soffset;
|
private int soffset;
|
||||||
public GMatchAux(VM vm) {
|
public GMatchAux(LuaState vm) {
|
||||||
this.src = vm.tolstring(2);
|
this.src = vm.tolstring(2);
|
||||||
this.pat = vm.tolstring(3);
|
this.pat = vm.tolstring(3);
|
||||||
this.srclen = src.length();
|
this.srclen = src.length();
|
||||||
this.ms = new MatchState(vm, src, pat);
|
this.ms = new MatchState(vm, src, pat);
|
||||||
this.soffset = 0;
|
this.soffset = 0;
|
||||||
}
|
}
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
for ( ; soffset<srclen; soffset++ ) {
|
for ( ; soffset<srclen; soffset++ ) {
|
||||||
int res = ms.match(soffset, 0);
|
int res = ms.match(soffset, 0);
|
||||||
@@ -221,7 +222,7 @@ public class StrLib {
|
|||||||
* x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
|
* x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
|
||||||
* --> x="lua-5.1.tar.gz"
|
* --> x="lua-5.1.tar.gz"
|
||||||
*/
|
*/
|
||||||
static void gsub( VM vm ) {
|
static void gsub( LuaState vm ) {
|
||||||
LString src = vm.tolstring(2);
|
LString src = vm.tolstring(2);
|
||||||
final int srclen = src.length();
|
final int srclen = src.length();
|
||||||
LString p = vm.tolstring(3);
|
LString p = vm.tolstring(3);
|
||||||
@@ -262,7 +263,7 @@ public class StrLib {
|
|||||||
* Receives a string and returns its length. The empty string "" has length 0.
|
* Receives a string and returns its length. The empty string "" has length 0.
|
||||||
* Embedded zeros are counted, so "a\000bc\000" has length 5.
|
* Embedded zeros are counted, so "a\000bc\000" has length 5.
|
||||||
*/
|
*/
|
||||||
static void len( VM vm ) {
|
static void len( LuaState vm ) {
|
||||||
int l = vm.tostring(2).length();
|
int l = vm.tostring(2).length();
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushinteger( l );
|
vm.pushinteger( l );
|
||||||
@@ -275,7 +276,7 @@ public class StrLib {
|
|||||||
* changed to lowercase. All other characters are left unchanged.
|
* changed to lowercase. All other characters are left unchanged.
|
||||||
* The definition of what an uppercase letter is depends on the current locale.
|
* The definition of what an uppercase letter is depends on the current locale.
|
||||||
*/
|
*/
|
||||||
static void lower( VM vm ) {
|
static void lower( LuaState vm ) {
|
||||||
String s = vm.tostring(2).toLowerCase();
|
String s = vm.tostring(2).toLowerCase();
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushstring( s );
|
vm.pushstring( s );
|
||||||
@@ -290,7 +291,7 @@ public class StrLib {
|
|||||||
* A third, optional numerical argument init specifies where to start the
|
* A third, optional numerical argument init specifies where to start the
|
||||||
* search; its default value is 1 and may be negative.
|
* search; its default value is 1 and may be negative.
|
||||||
*/
|
*/
|
||||||
static void match( VM vm ) {
|
static void match( LuaState vm ) {
|
||||||
str_find_aux( vm, false );
|
str_find_aux( vm, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +300,7 @@ public class StrLib {
|
|||||||
*
|
*
|
||||||
* Returns a string that is the concatenation of n copies of the string s.
|
* Returns a string that is the concatenation of n copies of the string s.
|
||||||
*/
|
*/
|
||||||
static void rep( VM vm ) {
|
static void rep( LuaState vm ) {
|
||||||
LString s = vm.tolstring(2);
|
LString s = vm.tolstring(2);
|
||||||
int n = vm.tointeger( 3 );
|
int n = vm.tointeger( 3 );
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
@@ -318,7 +319,7 @@ public class StrLib {
|
|||||||
*
|
*
|
||||||
* Returns a string that is the string s reversed.
|
* Returns a string that is the string s reversed.
|
||||||
*/
|
*/
|
||||||
static void reverse( VM vm ) {
|
static void reverse( LuaState vm ) {
|
||||||
LString s = vm.tolstring(2);
|
LString s = vm.tolstring(2);
|
||||||
int n = s.length();
|
int n = s.length();
|
||||||
byte[] b = new byte[n];
|
byte[] b = new byte[n];
|
||||||
@@ -339,7 +340,7 @@ public class StrLib {
|
|||||||
* string.sub(s, -i)
|
* string.sub(s, -i)
|
||||||
* returns a suffix of s with length i.
|
* returns a suffix of s with length i.
|
||||||
*/
|
*/
|
||||||
static void sub( VM vm ) {
|
static void sub( LuaState vm ) {
|
||||||
final int top = vm.gettop();
|
final int top = vm.gettop();
|
||||||
final LString s = vm.tolstring(2);
|
final LString s = vm.tolstring(2);
|
||||||
final int len = s.length();
|
final int len = s.length();
|
||||||
@@ -368,7 +369,7 @@ public class StrLib {
|
|||||||
* changed to uppercase. All other characters are left unchanged.
|
* changed to uppercase. All other characters are left unchanged.
|
||||||
* The definition of what a lowercase letter is depends on the current locale.
|
* The definition of what a lowercase letter is depends on the current locale.
|
||||||
*/
|
*/
|
||||||
static void upper( VM vm ) {
|
static void upper( LuaState vm ) {
|
||||||
String s = vm.tostring(2).toUpperCase();
|
String s = vm.tostring(2).toUpperCase();
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
vm.pushstring(s);
|
vm.pushstring(s);
|
||||||
@@ -377,7 +378,7 @@ public class StrLib {
|
|||||||
/**
|
/**
|
||||||
* This utility method implements both string.find and string.match.
|
* This utility method implements both string.find and string.match.
|
||||||
*/
|
*/
|
||||||
static void str_find_aux( VM vm, boolean find ) {
|
static void str_find_aux( LuaState vm, boolean find ) {
|
||||||
LString s = vm.tolstring(2);
|
LString s = vm.tolstring(2);
|
||||||
LString pat = vm.tolstring(3);
|
LString pat = vm.tolstring(3);
|
||||||
int init = vm.gettop() >= 4 ? vm.tointeger( 4 ) : 1;
|
int init = vm.gettop() >= 4 ? vm.tointeger( 4 ) : 1;
|
||||||
@@ -482,12 +483,12 @@ public class StrLib {
|
|||||||
private static class MatchState {
|
private static class MatchState {
|
||||||
final LString s;
|
final LString s;
|
||||||
final LString p;
|
final LString p;
|
||||||
final VM vm;
|
final LuaState vm;
|
||||||
int level;
|
int level;
|
||||||
int[] cinit;
|
int[] cinit;
|
||||||
int[] clen;
|
int[] clen;
|
||||||
|
|
||||||
MatchState( VM vm, LString s, LString pattern ) {
|
MatchState( LuaState vm, LString s, LString pattern ) {
|
||||||
this.s = s;
|
this.s = s;
|
||||||
this.p = pattern;
|
this.p = pattern;
|
||||||
this.vm = vm;
|
this.vm = vm;
|
||||||
@@ -1,19 +1,18 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package lua;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import lua.value.LTable;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
final class Builtin extends JavaFunction {
|
|
||||||
|
|
||||||
static void addBuiltins(LTable table) {
|
public class BaseLib extends LFunction {
|
||||||
|
|
||||||
|
static void install(LTable globals) {
|
||||||
for ( int i=0; i<NAMES.length; i++ )
|
for ( int i=0; i<NAMES.length; i++ )
|
||||||
table.put( NAMES[i], new Builtin(i) );
|
globals.put( NAMES[i], new BaseLib(i) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] NAMES = {
|
private static final String[] NAMES = {
|
||||||
@@ -40,7 +39,7 @@ final class Builtin extends JavaFunction {
|
|||||||
private static PrintStream stdout = System.out;
|
private static PrintStream stdout = System.out;
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private Builtin( int id ) {
|
private BaseLib( int id ) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ final class Builtin extends JavaFunction {
|
|||||||
/**
|
/**
|
||||||
* Invoke a builtin
|
* Invoke a builtin
|
||||||
*/
|
*/
|
||||||
public int invoke(VM vm) {
|
public int invoke(LuaState vm) {
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case PRINT: {
|
case PRINT: {
|
||||||
int n = vm.gettop();
|
int n = vm.gettop();
|
||||||
@@ -110,11 +109,11 @@ final class Builtin extends JavaFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void redirectOutput( OutputStream newStdOut ) {
|
public static void redirectOutput( OutputStream newStdOut ) {
|
||||||
stdout = new PrintStream( newStdOut );
|
stdout = new PrintStream( newStdOut );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restoreStandardOutput() {
|
public static void restoreStandardOutput() {
|
||||||
stdout = System.out;
|
stdout = System.out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
package lua;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.io.Closure;
|
|
||||||
|
|
||||||
public class CallInfo {
|
public class CallInfo {
|
||||||
|
|
||||||
public Closure closure;
|
public LClosure closure;
|
||||||
public int base;
|
public int base;
|
||||||
public int top;
|
public int top;
|
||||||
public int pc;
|
public int pc;
|
||||||
public int resultbase;
|
public int resultbase;
|
||||||
public int nresults;
|
public int nresults;
|
||||||
|
|
||||||
public CallInfo(Closure c, int base, int top, int resultoff, int nresults) {
|
public CallInfo(LClosure c, int base, int top, int resultoff, int nresults) {
|
||||||
this.closure = c;
|
this.closure = c;
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.top = top;
|
this.top = top;
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
public final class LBoolean extends LValue {
|
public final class LBoolean extends LValue {
|
||||||
|
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
package lua.io;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.StackState;
|
|
||||||
import lua.VM;
|
|
||||||
import lua.value.LFunction;
|
|
||||||
import lua.value.LTable;
|
|
||||||
|
|
||||||
public class Closure extends LFunction {
|
|
||||||
|
public class LClosure extends LFunction {
|
||||||
public LTable env;
|
public LTable env;
|
||||||
public Proto p;
|
public LPrototype p;
|
||||||
public UpVal[] upVals;
|
public UpVal[] upVals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +12,7 @@ public class Closure extends LFunction {
|
|||||||
* @param state
|
* @param state
|
||||||
* @param p
|
* @param p
|
||||||
*/
|
*/
|
||||||
public Closure(StackState state, Proto p) {
|
public LClosure(LuaState state, LPrototype p) {
|
||||||
this.env = state._G;
|
this.env = state._G;
|
||||||
this.p = p;
|
this.p = p;
|
||||||
upVals = new UpVal[p.nups];
|
upVals = new UpVal[p.nups];
|
||||||
@@ -26,7 +23,7 @@ public class Closure extends LFunction {
|
|||||||
* @param p
|
* @param p
|
||||||
* @param env
|
* @param env
|
||||||
*/
|
*/
|
||||||
public Closure(Proto p, LTable env) {
|
public LClosure(LPrototype p, LTable env) {
|
||||||
this.p = p;
|
this.p = p;
|
||||||
this.env = env;
|
this.env = env;
|
||||||
upVals = new UpVal[p.nups];
|
upVals = new UpVal[p.nups];
|
||||||
@@ -35,7 +32,7 @@ public class Closure extends LFunction {
|
|||||||
// called by vm when there is an OP_CALL
|
// called by vm when there is an OP_CALL
|
||||||
// in this case, we are on the stack,
|
// in this case, we are on the stack,
|
||||||
// and simply need to cue the VM to treat it as a stack call
|
// and simply need to cue the VM to treat it as a stack call
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
vm.prepStackCall();
|
vm.prepStackCall();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
public class LDouble extends LNumber {
|
public class LDouble extends LNumber {
|
||||||
|
|
||||||
59
src/core/org/luaj/vm/LFunction.java
Normal file
59
src/core/org/luaj/vm/LFunction.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package org.luaj.vm;
|
||||||
|
|
||||||
|
|
||||||
|
abstract
|
||||||
|
public class LFunction extends LValue {
|
||||||
|
|
||||||
|
public String toJavaString() {
|
||||||
|
return "function: "+hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void luaSetTable(LuaState vm, LValue table, LValue key, LValue val) {
|
||||||
|
vm.pushlvalue( this );
|
||||||
|
vm.pushlvalue( table );
|
||||||
|
vm.pushlvalue( key );
|
||||||
|
vm.pushlvalue( val );
|
||||||
|
vm.call( 3, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void luaGetTable(LuaState vm, LValue table, LValue key) {
|
||||||
|
vm.pushlvalue( this );
|
||||||
|
vm.pushlvalue( table );
|
||||||
|
vm.pushlvalue( key );
|
||||||
|
vm.call( 2, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public int luaGetType() {
|
||||||
|
return Lua.LUA_TFUNCTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up a Java invocation, and leave the results on the stack
|
||||||
|
* starting at base. The default implementation for LFunction
|
||||||
|
* delegates to the VM which provides convenience.
|
||||||
|
*/
|
||||||
|
public boolean luaStackCall(LuaState vm) {
|
||||||
|
vm.invokeJavaFunction( this );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to invoke a JavaFunction.
|
||||||
|
*
|
||||||
|
* The implementation should manipulate the stack
|
||||||
|
* via the VM Java API in the same way that lua_CFunctions
|
||||||
|
* do so in standard lua.
|
||||||
|
*
|
||||||
|
* Arguments to the function will be in position 1-n.
|
||||||
|
* Return values can be pushed onto the stack, and will be
|
||||||
|
* copied down to the appropriate location by the calling LuaState.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param lua the LuaState calling this function.
|
||||||
|
* @return number of results pushed onto the stack.
|
||||||
|
*/
|
||||||
|
public int invoke( LuaState lua ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
public class LInteger extends LNumber {
|
public class LInteger extends LNumber {
|
||||||
private final int m_value;
|
private final int m_value;
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
public final class LNil extends LValue {
|
public final class LNil extends LValue {
|
||||||
public static final LNil NIL = new LNil();
|
public static final LNil NIL = new LNil();
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
abstract
|
abstract
|
||||||
public class LNumber extends LValue {
|
public class LNumber extends LValue {
|
||||||
@@ -1,21 +1,19 @@
|
|||||||
package lua.io;
|
package org.luaj.vm;
|
||||||
|
|
||||||
|
|
||||||
import lua.StackState;
|
|
||||||
import lua.value.LValue;
|
|
||||||
import lua.value.LString;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function Prototypes
|
** Function Prototypes
|
||||||
*/
|
*/
|
||||||
public class Proto {
|
public class LPrototype {
|
||||||
public Proto() {
|
public LPrototype() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* constants used by the function */
|
/* constants used by the function */
|
||||||
public LValue[] k;
|
public LValue[] k;
|
||||||
public int[] code;
|
public int[] code;
|
||||||
/* functions defined inside the function */
|
/* functions defined inside the function */
|
||||||
public Proto[] p;
|
public LPrototype[] p;
|
||||||
/* map from opcodes to source lines */
|
/* map from opcodes to source lines */
|
||||||
public int[] lineinfo;
|
public int[] lineinfo;
|
||||||
/* information about local variables */
|
/* information about local variables */
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A String implementation for Lua using bytes instead of chars.
|
* A String implementation for Lua using bytes instead of chars.
|
||||||
@@ -386,54 +384,6 @@ public class LString extends LValue {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] stringToUtf8Bytes( final String string ) {
|
|
||||||
final int strlen = string.length();
|
|
||||||
byte[] bytes = new byte[ strlen ];
|
|
||||||
byte b1 = 0, b2 = 0, b3 = 0;
|
|
||||||
|
|
||||||
int j = 0;
|
|
||||||
for ( int i = 0; i < strlen; ++i ) {
|
|
||||||
int c = string.charAt( i );
|
|
||||||
// TODO: combine 2-character combinations
|
|
||||||
int count;
|
|
||||||
if ( c > 0x07FF ) {
|
|
||||||
count = 3;
|
|
||||||
b3 = (byte)( 0xE0 | ( c >> 12 ) );
|
|
||||||
b2 = (byte)( 0x80 | ( ( c >> 6 ) & 0x03F ) );
|
|
||||||
b1 = (byte)( 0x80 | ( ( c ) & 0x03F ) );
|
|
||||||
} else if ( c > 0x07F ) {
|
|
||||||
count = 2;
|
|
||||||
b2 = (byte)( 0xC0 | ( c >> 6 ) );
|
|
||||||
b1 = (byte)( 0x80 | ( c & 0x03F ) );
|
|
||||||
} else {
|
|
||||||
count = 1;
|
|
||||||
b1 = (byte) c;
|
|
||||||
}
|
|
||||||
if ( j + count > bytes.length ) {
|
|
||||||
bytes = realloc( bytes, ( j + count ) * 2 );
|
|
||||||
}
|
|
||||||
switch ( count ) {
|
|
||||||
case 3:
|
|
||||||
bytes[j++] = b3;
|
|
||||||
case 2:
|
|
||||||
bytes[j++] = b2;
|
|
||||||
case 1:
|
|
||||||
bytes[j++] = b1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( j != bytes.length ) {
|
|
||||||
bytes = realloc( bytes, j );
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static byte[] realloc( byte[] a, int newSize ) {
|
|
||||||
final byte[] newbytes = new byte[ newSize ];
|
|
||||||
System.arraycopy( a, 0, newbytes, 0, Math.min( newSize, a.length ) );
|
|
||||||
return newbytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int luaByte(int index) {
|
public int luaByte(int index) {
|
||||||
return m_bytes[m_offset + index] & 0x0FF;
|
return m_bytes[m_offset + index] & 0x0FF;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
import lua.VM;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation of table structure for Lua VM. Maintains both an array
|
* Simple implementation of table structure for Lua VM. Maintains both an array
|
||||||
@@ -213,7 +211,7 @@ public class LTable extends LValue {
|
|||||||
return m_hashKeys[ slot ] != null;
|
return m_hashKeys[ slot ] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void luaGetTable(VM vm, LValue table, LValue key) {
|
public void luaGetTable(LuaState vm, LValue table, LValue key) {
|
||||||
LValue v = get(key);
|
LValue v = get(key);
|
||||||
if ( v == LNil.NIL && m_metatable != null ) {
|
if ( v == LNil.NIL && m_metatable != null ) {
|
||||||
super.luaGetTable( vm, table, key );
|
super.luaGetTable( vm, table, key );
|
||||||
@@ -222,7 +220,7 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
|
public void luaSetTable(LuaState vm, LValue table, LValue key, LValue val) {
|
||||||
if ( (!containsKey( key )) && m_metatable != null && m_metatable.containsKey(TM_NEWINDEX) )
|
if ( (!containsKey( key )) && m_metatable != null && m_metatable.containsKey(TM_NEWINDEX) )
|
||||||
m_metatable.get(TM_NEWINDEX).luaSetTable( vm, table, key, val );
|
m_metatable.get(TM_NEWINDEX).luaSetTable( vm, table, key, val );
|
||||||
else
|
else
|
||||||
@@ -281,7 +279,7 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
vm.settop(0);
|
vm.settop(0);
|
||||||
int i;
|
int i;
|
||||||
while ( ( i = arrayIndex++ ) < m_vector.length ) {
|
while ( ( i = arrayIndex++ ) < m_vector.length ) {
|
||||||
@@ -563,11 +561,11 @@ public class LTable extends LValue {
|
|||||||
//
|
//
|
||||||
// implemented heap sort from wikipedia
|
// implemented heap sort from wikipedia
|
||||||
//
|
//
|
||||||
public void luaSort(VM vm, LValue compare) {
|
public void luaSort(LuaState vm, LValue compare) {
|
||||||
heapSort(m_arrayEntries, vm, compare);
|
heapSort(m_arrayEntries, vm, compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void heapSort(int count, VM vm, LValue cmpfunc) {
|
private void heapSort(int count, LuaState vm, LValue cmpfunc) {
|
||||||
heapify(count, vm, cmpfunc);
|
heapify(count, vm, cmpfunc);
|
||||||
for ( int end=count-1; end>0; ) {
|
for ( int end=count-1; end>0; ) {
|
||||||
swap(end, 0);
|
swap(end, 0);
|
||||||
@@ -575,12 +573,12 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void heapify(int count, VM vm, LValue cmpfunc) {
|
private void heapify(int count, LuaState vm, LValue cmpfunc) {
|
||||||
for ( int start=count/2-1; start>=0; --start )
|
for ( int start=count/2-1; start>=0; --start )
|
||||||
siftDown(start, count - 1, vm, cmpfunc);
|
siftDown(start, count - 1, vm, cmpfunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void siftDown(int start, int end, VM vm, LValue cmpfunc) {
|
private void siftDown(int start, int end, LuaState vm, LValue cmpfunc) {
|
||||||
for ( int root=start; root*2+1 <= end; ) {
|
for ( int root=start; root*2+1 <= end; ) {
|
||||||
int child = root*2+1;
|
int child = root*2+1;
|
||||||
if (child < end && compare(child, child + 1, vm, cmpfunc))
|
if (child < end && compare(child, child + 1, vm, cmpfunc))
|
||||||
@@ -593,7 +591,7 @@ public class LTable extends LValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean compare(int i, int j, VM vm, LValue cmpfunc) {
|
private boolean compare(int i, int j, LuaState vm, LValue cmpfunc) {
|
||||||
if ( cmpfunc != LNil.NIL ) {
|
if ( cmpfunc != LNil.NIL ) {
|
||||||
vm.pushlvalue(cmpfunc);
|
vm.pushlvalue(cmpfunc);
|
||||||
vm.pushlvalue(m_vector[i]);
|
vm.pushlvalue(m_vector[i]);
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
import lua.StackState;
|
|
||||||
import lua.VM;
|
|
||||||
import lua.io.Closure;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of lua coroutines using Java Threads
|
* Implementation of lua coroutines using Java Threads
|
||||||
@@ -22,16 +19,15 @@ public class LThread extends LValue implements Runnable {
|
|||||||
|
|
||||||
private int status = STATUS_SUSPENDED;
|
private int status = STATUS_SUSPENDED;
|
||||||
|
|
||||||
private StackState threadVm;
|
private LuaState threadVm;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
private static LThread running;
|
private static LThread running;
|
||||||
|
|
||||||
|
|
||||||
public LThread(Closure c) {
|
public LThread(LClosure c) {
|
||||||
// TODO: inherit globals!
|
threadVm = new LuaState(c.env);
|
||||||
threadVm = new StackState();
|
threadVm.pushlvalue(new LClosure(c.p, threadVm._G));
|
||||||
threadVm.pushlvalue(new Closure(c.p, threadVm._G));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int luaGetType() {
|
public int luaGetType() {
|
||||||
@@ -83,7 +79,7 @@ public class LThread extends LValue implements Runnable {
|
|||||||
* @param vm
|
* @param vm
|
||||||
* @param nargs
|
* @param nargs
|
||||||
*/
|
*/
|
||||||
public void resumeFrom(VM vm, int nargs) {
|
public void resumeFrom(LuaState vm, int nargs) {
|
||||||
|
|
||||||
synchronized ( this ) {
|
synchronized ( this ) {
|
||||||
if ( status == STATUS_DEAD ) {
|
if ( status == STATUS_DEAD ) {
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
public class LUserData extends LValue {
|
public class LUserData extends LValue {
|
||||||
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
import lua.VM;
|
|
||||||
|
|
||||||
abstract
|
abstract
|
||||||
public class LValue {
|
public class LValue {
|
||||||
@@ -32,7 +30,7 @@ public class LValue {
|
|||||||
|
|
||||||
// perform a lua call, return true if the call is to a lua function, false
|
// perform a lua call, return true if the call is to a lua function, false
|
||||||
// if it ran to completion.
|
// if it ran to completion.
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
vm.error("attempt to call "+this);
|
vm.error("attempt to call "+this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -91,7 +89,7 @@ public class LValue {
|
|||||||
* @param the key to set
|
* @param the key to set
|
||||||
* @param the value to set
|
* @param the value to set
|
||||||
*/
|
*/
|
||||||
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
|
public void luaSetTable(LuaState vm, LValue table, LValue key, LValue val) {
|
||||||
LTable mt = luaGetMetatable();
|
LTable mt = luaGetMetatable();
|
||||||
if ( mt != null ) {
|
if ( mt != null ) {
|
||||||
LValue event = mt.get( TM_NEWINDEX );
|
LValue event = mt.get( TM_NEWINDEX );
|
||||||
@@ -108,7 +106,7 @@ public class LValue {
|
|||||||
* @param table the table from which to get the value
|
* @param table the table from which to get the value
|
||||||
* @param key the key to look up
|
* @param key the key to look up
|
||||||
*/
|
*/
|
||||||
public void luaGetTable(VM vm, LValue table, LValue key) {
|
public void luaGetTable(LuaState vm, LValue table, LValue key) {
|
||||||
LTable mt = luaGetMetatable();
|
LTable mt = luaGetMetatable();
|
||||||
if ( mt != null ) {
|
if ( mt != null ) {
|
||||||
LValue event = mt.get( TM_INDEX );
|
LValue event = mt.get( TM_INDEX );
|
||||||
@@ -1,18 +1,11 @@
|
|||||||
package lua.io;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
import lua.VM;
|
|
||||||
import lua.value.LBoolean;
|
|
||||||
import lua.value.LDouble;
|
|
||||||
import lua.value.LInteger;
|
|
||||||
import lua.value.LNil;
|
|
||||||
import lua.value.LNumber;
|
|
||||||
import lua.value.LString;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Function Prototypes
|
** Function Prototypes
|
||||||
@@ -55,7 +48,7 @@ public class LoadState {
|
|||||||
String name;
|
String name;
|
||||||
|
|
||||||
/** The VM doing the loading */
|
/** The VM doing the loading */
|
||||||
VM L;
|
LuaState L;
|
||||||
|
|
||||||
int loadByte() throws IOException {
|
int loadByte() throws IOException {
|
||||||
return is.readUnsignedByte();
|
return is.readUnsignedByte();
|
||||||
@@ -94,7 +87,7 @@ public class LoadState {
|
|||||||
return new LString( bytes, 0, bytes.length - 1 );
|
return new LString( bytes, 0, bytes.length - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static LNumber longBitsToLuaNumber( long bits ) {
|
public static LNumber longBitsToLuaNumber( long bits ) {
|
||||||
if ( ( bits & ( ( 1L << 63 ) - 1 ) ) == 0L ) {
|
if ( ( bits & ( ( 1L << 63 ) - 1 ) ) == 0L ) {
|
||||||
return LInteger.valueOf( 0 );
|
return LInteger.valueOf( 0 );
|
||||||
}
|
}
|
||||||
@@ -124,7 +117,7 @@ public class LoadState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCode( Proto f ) throws IOException {
|
public void loadCode( LPrototype f ) throws IOException {
|
||||||
int n = loadInt();
|
int n = loadInt();
|
||||||
int[] code = new int[n];
|
int[] code = new int[n];
|
||||||
for ( int i=0; i<n; i++ )
|
for ( int i=0; i<n; i++ )
|
||||||
@@ -132,7 +125,7 @@ public class LoadState {
|
|||||||
f.code = code;
|
f.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadConstants(Proto f) throws IOException {
|
void loadConstants(LPrototype f) throws IOException {
|
||||||
int n = loadInt();
|
int n = loadInt();
|
||||||
LValue[] values = new LValue[n];
|
LValue[] values = new LValue[n];
|
||||||
for ( int i=0; i<n; i++ ) {
|
for ( int i=0; i<n; i++ ) {
|
||||||
@@ -156,13 +149,13 @@ public class LoadState {
|
|||||||
f.k = values;
|
f.k = values;
|
||||||
|
|
||||||
n = loadInt();
|
n = loadInt();
|
||||||
Proto[] protos = new Proto[n];
|
LPrototype[] protos = new LPrototype[n];
|
||||||
for ( int i=0; i<n; i++ )
|
for ( int i=0; i<n; i++ )
|
||||||
protos[i] = loadFunction(f.source);
|
protos[i] = loadFunction(f.source);
|
||||||
f.p = protos;
|
f.p = protos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadDebug( Proto f ) throws IOException {
|
void loadDebug( LPrototype f ) throws IOException {
|
||||||
int n = loadInt();
|
int n = loadInt();
|
||||||
f.lineinfo = new int[n];
|
f.lineinfo = new int[n];
|
||||||
for ( int i=0; i<n; i++ )
|
for ( int i=0; i<n; i++ )
|
||||||
@@ -184,8 +177,8 @@ public class LoadState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Proto loadFunction(LString p) throws IOException {
|
public LPrototype loadFunction(LString p) throws IOException {
|
||||||
Proto f = new Proto();
|
LPrototype f = new LPrototype();
|
||||||
// this.L.push(f);
|
// this.L.push(f);
|
||||||
f.source = loadString();
|
f.source = loadString();
|
||||||
if ( f.source == null )
|
if ( f.source == null )
|
||||||
@@ -227,10 +220,10 @@ public class LoadState {
|
|||||||
luacIsNumberIntegral = (0 != is.readByte());
|
luacIsNumberIntegral = (0 != is.readByte());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Proto undump( VM L, InputStream stream, String name ) throws IOException {
|
public static LPrototype undump( LuaState L, InputStream stream, String name ) throws IOException {
|
||||||
|
|
||||||
// is this a source file?
|
// is this a source file?
|
||||||
Proto p = lua.addon.compile.Compiler.compile(stream, name);
|
LPrototype p = org.luaj.compiler.Compiler.compile(stream, name);
|
||||||
if ( p != null )
|
if ( p != null )
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
@@ -259,7 +252,7 @@ public class LoadState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Private constructor for create a load state */
|
/** Private constructor for create a load state */
|
||||||
private LoadState( VM L, InputStream stream, String name ) {
|
private LoadState( LuaState L, InputStream stream, String name ) {
|
||||||
this.L = L;
|
this.L = L;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.is = new DataInputStream( stream );
|
this.is = new DataInputStream( stream );
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package lua.io;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.value.LString;
|
|
||||||
|
|
||||||
public class LocVars {
|
public class LocVars {
|
||||||
public LString varname;
|
public LString varname;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua;
|
package org.luaj.vm;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6,20 +6,11 @@ package lua;
|
|||||||
*
|
*
|
||||||
* @author jim_roseborough
|
* @author jim_roseborough
|
||||||
*
|
*
|
||||||
|
* @deprecated - this class will go away. Constants will probably move to LuaState
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class Lua {
|
public class Lua {
|
||||||
|
|
||||||
// from llimits.h
|
|
||||||
|
|
||||||
/** maximum stack for a Lua function */
|
|
||||||
public static final int MAXSTACK = 250;
|
|
||||||
|
|
||||||
/** minimum size for the string table (must be power of 2) */
|
|
||||||
public static final int MINSTRTABSIZE = 32;
|
|
||||||
|
|
||||||
/** minimum size for string buffer */
|
|
||||||
public static final int LUA_MINBUFFER = 32;
|
|
||||||
|
|
||||||
/** use return values from previous op */
|
/** use return values from previous op */
|
||||||
public static final int LUA_MULTRET = -1;
|
public static final int LUA_MULTRET = -1;
|
||||||
|
|
||||||
@@ -312,50 +303,6 @@ public class Lua {
|
|||||||
return 0 != (luaP_opmodes[m] & (1 << 7));
|
return 0 != (luaP_opmodes[m] & (1 << 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** opcode names */
|
|
||||||
public static final String[] luaP_opnames = {
|
|
||||||
"MOVE",
|
|
||||||
"LOADK",
|
|
||||||
"LOADBOOL",
|
|
||||||
"LOADNIL",
|
|
||||||
"GETUPVAL",
|
|
||||||
"GETGLOBAL",
|
|
||||||
"GETTABLE",
|
|
||||||
"SETGLOBAL",
|
|
||||||
"SETUPVAL",
|
|
||||||
"SETTABLE",
|
|
||||||
"NEWTABLE",
|
|
||||||
"SELF",
|
|
||||||
"ADD",
|
|
||||||
"SUB",
|
|
||||||
"MUL",
|
|
||||||
"DIV",
|
|
||||||
"MOD",
|
|
||||||
"POW",
|
|
||||||
"UNM",
|
|
||||||
"NOT",
|
|
||||||
"LEN",
|
|
||||||
"CONCAT",
|
|
||||||
"JMP",
|
|
||||||
"EQ",
|
|
||||||
"LT",
|
|
||||||
"LE",
|
|
||||||
"TEST",
|
|
||||||
"TESTSET",
|
|
||||||
"CALL",
|
|
||||||
"TAILCALL",
|
|
||||||
"RETURN",
|
|
||||||
"FORLOOP",
|
|
||||||
"FORPREP",
|
|
||||||
"TFORLOOP",
|
|
||||||
"SETLIST",
|
|
||||||
"CLOSE",
|
|
||||||
"CLOSURE",
|
|
||||||
"VARARG",
|
|
||||||
null,
|
|
||||||
};
|
|
||||||
|
|
||||||
// type constants
|
// type constants
|
||||||
|
|
||||||
public static final int LUA_TNONE = (-1);
|
public static final int LUA_TNONE = (-1);
|
||||||
@@ -1,26 +1,14 @@
|
|||||||
package lua;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import lua.io.Closure;
|
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.io.LocVars;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.io.UpVal;
|
|
||||||
import lua.value.LBoolean;
|
|
||||||
import lua.value.LDouble;
|
|
||||||
import lua.value.LInteger;
|
|
||||||
import lua.value.LNil;
|
|
||||||
import lua.value.LString;
|
|
||||||
import lua.value.LTable;
|
|
||||||
import lua.value.LUserData;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
|
|
||||||
public class StackState extends Lua implements VM {
|
|
||||||
private static final boolean TRACE = (null != System.getProperty("TRACE"));
|
|
||||||
|
public class LuaState extends Lua {
|
||||||
|
|
||||||
/* thread status; 0 is OK */
|
/* thread status; 0 is OK */
|
||||||
private static final int LUA_YIELD = 1;
|
private static final int LUA_YIELD = 1;
|
||||||
@@ -35,13 +23,13 @@ public class StackState extends Lua implements VM {
|
|||||||
public int base = 0;
|
public int base = 0;
|
||||||
protected int top = 0;
|
protected int top = 0;
|
||||||
protected int nresults = -1;
|
protected int nresults = -1;
|
||||||
protected LValue[] stack = new LValue[LUA_MINSTACK];
|
public LValue[] stack = new LValue[LUA_MINSTACK];
|
||||||
public int cc = -1;
|
public int cc = -1;
|
||||||
protected CallInfo[] calls = new CallInfo[LUA_MINCALLS];
|
public CallInfo[] calls = new CallInfo[LUA_MINCALLS];
|
||||||
protected Stack upvals = new Stack();
|
protected Stack upvals = new Stack();
|
||||||
protected JavaFunction panic;
|
protected LFunction panic;
|
||||||
|
|
||||||
public LTable _G = GlobalState.getGlobalsTable();
|
public LTable _G;
|
||||||
|
|
||||||
// main debug hook, overridden by DebugStackState
|
// main debug hook, overridden by DebugStackState
|
||||||
protected void debugHooks(int pc) {
|
protected void debugHooks(int pc) {
|
||||||
@@ -64,13 +52,20 @@ public class StackState extends Lua implements VM {
|
|||||||
* second argument, <code>ud</code>, is an opaque pointer that Lua simply
|
* second argument, <code>ud</code>, is an opaque pointer that Lua simply
|
||||||
* passes to the allocator in every call.
|
* passes to the allocator in every call.
|
||||||
*/
|
*/
|
||||||
public StackState() {
|
public LuaState() {
|
||||||
|
_G = new LTable();
|
||||||
|
_G.put("_G", _G);
|
||||||
|
BaseLib.install( _G );
|
||||||
|
}
|
||||||
|
|
||||||
|
public LuaState(LTable globals) {
|
||||||
|
_G = globals;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ interfaces for performing calls
|
// ================ interfaces for performing calls
|
||||||
|
|
||||||
public void prepStackCall() {
|
public void prepStackCall() {
|
||||||
Closure c = (Closure) stack[base];
|
LClosure c = (LClosure) stack[base];
|
||||||
int resultbase = base;
|
int resultbase = base;
|
||||||
// Expand the stack if necessary
|
// Expand the stack if necessary
|
||||||
checkstack( c.p.maxstacksize );
|
checkstack( c.p.maxstacksize );
|
||||||
@@ -106,7 +101,7 @@ public class StackState extends Lua implements VM {
|
|||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doCall( Closure c, LValue[] args ) {
|
public void doCall( LClosure c, LValue[] args ) {
|
||||||
settop(0);
|
settop(0);
|
||||||
pushlvalue( c );
|
pushlvalue( c );
|
||||||
for ( int i=0, n=(args!=null? args.length: 0); i<n; i++ )
|
for ( int i=0, n=(args!=null? args.length: 0); i<n; i++ )
|
||||||
@@ -116,15 +111,14 @@ public class StackState extends Lua implements VM {
|
|||||||
base = (cc>=0? calls[cc].base: 0);
|
base = (cc>=0? calls[cc].base: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invokeJavaFunction(JavaFunction javaFunction) {
|
public void invokeJavaFunction(LFunction javaFunction) {
|
||||||
int resultbase = base;
|
int resultbase = base;
|
||||||
int resultsneeded = nresults;
|
int resultsneeded = nresults;
|
||||||
++base;
|
++base;
|
||||||
int nactual = javaFunction.invoke(this);
|
int nactual = javaFunction.invoke(this);
|
||||||
debugAssert(nactual>=0);
|
debugAssert(nactual>=0);
|
||||||
debugAssert(top-nactual>=base);
|
debugAssert(top-nactual>=base);
|
||||||
base = resultbase;
|
System.arraycopy(stack, top-nactual, stack, base=resultbase, nactual);
|
||||||
System.arraycopy(stack, top-nactual, stack, base, nactual);
|
|
||||||
settop( nactual );
|
settop( nactual );
|
||||||
if ( resultsneeded >= 0 )
|
if ( resultsneeded >= 0 )
|
||||||
settop( resultsneeded );
|
settop( resultsneeded );
|
||||||
@@ -201,8 +195,8 @@ public class StackState extends Lua implements VM {
|
|||||||
// loader
|
// loader
|
||||||
public int load( InputStream is, String chunkname ) {
|
public int load( InputStream is, String chunkname ) {
|
||||||
try {
|
try {
|
||||||
Proto p = LoadState.undump(this, is, chunkname );
|
LPrototype p = LoadState.undump(this, is, chunkname );
|
||||||
pushlvalue( new Closure( p, _G ) );
|
pushlvalue( new LClosure( p, _G ) );
|
||||||
return 0;
|
return 0;
|
||||||
} catch ( Throwable t ) {
|
} catch ( Throwable t ) {
|
||||||
pushstring( t.getMessage() );
|
pushstring( t.getMessage() );
|
||||||
@@ -212,8 +206,8 @@ public class StackState extends Lua implements VM {
|
|||||||
|
|
||||||
// ================ execute instructions
|
// ================ execute instructions
|
||||||
private LValue RKBC(LValue[] k, int bc) {
|
private LValue RKBC(LValue[] k, int bc) {
|
||||||
return StackState.ISK(bc) ?
|
return LuaState.ISK(bc) ?
|
||||||
k[StackState.INDEXK(bc)]:
|
k[LuaState.INDEXK(bc)]:
|
||||||
stack[base + bc];
|
stack[base + bc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,14 +234,14 @@ public class StackState extends Lua implements VM {
|
|||||||
LValue rkb, rkc, nvarargs, key, val;
|
LValue rkb, rkc, nvarargs, key, val;
|
||||||
LValue i0, step, idx, limit, init, table;
|
LValue i0, step, idx, limit, init, table;
|
||||||
boolean back, body;
|
boolean back, body;
|
||||||
Proto proto;
|
LPrototype proto;
|
||||||
Closure newClosure;
|
LClosure newClosure;
|
||||||
|
|
||||||
// reload values from the current call frame
|
// reload values from the current call frame
|
||||||
// into local variables
|
// into local variables
|
||||||
CallInfo ci = calls[cc];
|
CallInfo ci = calls[cc];
|
||||||
Closure cl = ci.closure;
|
LClosure cl = ci.closure;
|
||||||
Proto p = cl.p;
|
LPrototype p = cl.p;
|
||||||
int[] code = p.code;
|
int[] code = p.code;
|
||||||
LValue[] k = p.k;
|
LValue[] k = p.k;
|
||||||
|
|
||||||
@@ -261,9 +255,6 @@ public class StackState extends Lua implements VM {
|
|||||||
// sync up top
|
// sync up top
|
||||||
ci.top = top;
|
ci.top = top;
|
||||||
|
|
||||||
if (TRACE)
|
|
||||||
Print.printState(this, base, top, base+p.maxstacksize, cl, ci.pc);
|
|
||||||
|
|
||||||
// allow debug hooks a chance to operate
|
// allow debug hooks a chance to operate
|
||||||
debugHooks( ci.pc );
|
debugHooks( ci.pc );
|
||||||
|
|
||||||
@@ -271,81 +262,81 @@ public class StackState extends Lua implements VM {
|
|||||||
i = code[ci.pc++];
|
i = code[ci.pc++];
|
||||||
|
|
||||||
// get first opcode arg
|
// get first opcode arg
|
||||||
a = StackState.GETARG_A(i);
|
a = LuaState.GETARG_A(i);
|
||||||
switch (StackState.GET_OPCODE(i)) {
|
switch (LuaState.GET_OPCODE(i)) {
|
||||||
case StackState.OP_MOVE: {
|
case LuaState.OP_MOVE: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
this.stack[base + a] = this.stack[base + b];
|
this.stack[base + a] = this.stack[base + b];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_LOADK: {
|
case LuaState.OP_LOADK: {
|
||||||
b = StackState.GETARG_Bx(i);
|
b = LuaState.GETARG_Bx(i);
|
||||||
this.stack[base + a] = k[b];
|
this.stack[base + a] = k[b];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_LOADBOOL: {
|
case LuaState.OP_LOADBOOL: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
this.stack[base + a] = (b != 0 ? LBoolean.TRUE : LBoolean.FALSE);
|
this.stack[base + a] = (b != 0 ? LBoolean.TRUE : LBoolean.FALSE);
|
||||||
if (c != 0)
|
if (c != 0)
|
||||||
ci.pc++; /* skip next instruction (if C) */
|
ci.pc++; /* skip next instruction (if C) */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_LOADNIL: {
|
case LuaState.OP_LOADNIL: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
do {
|
do {
|
||||||
this.stack[base + b] = LNil.NIL;
|
this.stack[base + b] = LNil.NIL;
|
||||||
} while ((--b) >= a);
|
} while ((--b) >= a);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_GETUPVAL: {
|
case LuaState.OP_GETUPVAL: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
this.stack[base + a] = cl.upVals[b].getValue();
|
this.stack[base + a] = cl.upVals[b].getValue();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_GETGLOBAL: {
|
case LuaState.OP_GETGLOBAL: {
|
||||||
b = StackState.GETARG_Bx(i);
|
b = LuaState.GETARG_Bx(i);
|
||||||
key = k[b];
|
key = k[b];
|
||||||
table = cl.env;
|
table = cl.env;
|
||||||
top = base + a;
|
top = base + a;
|
||||||
table.luaGetTable(this, table, key);
|
table.luaGetTable(this, table, key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_GETTABLE: {
|
case LuaState.OP_GETTABLE: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
key = GETARG_RKC(k, i);
|
key = GETARG_RKC(k, i);
|
||||||
table = this.stack[base + b];
|
table = this.stack[base + b];
|
||||||
top = base + a;
|
top = base + a;
|
||||||
table.luaGetTable(this, table, key);
|
table.luaGetTable(this, table, key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_SETGLOBAL: {
|
case LuaState.OP_SETGLOBAL: {
|
||||||
b = StackState.GETARG_Bx(i);
|
b = LuaState.GETARG_Bx(i);
|
||||||
key = k[b];
|
key = k[b];
|
||||||
val = this.stack[base + a];
|
val = this.stack[base + a];
|
||||||
table = cl.env;
|
table = cl.env;
|
||||||
table.luaSetTable(this, table, key, val);
|
table.luaSetTable(this, table, key, val);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_SETUPVAL: {
|
case LuaState.OP_SETUPVAL: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
cl.upVals[b].setValue( this.stack[base + a] );
|
cl.upVals[b].setValue( this.stack[base + a] );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_SETTABLE: {
|
case LuaState.OP_SETTABLE: {
|
||||||
key = GETARG_RKB(k, i);
|
key = GETARG_RKB(k, i);
|
||||||
val = GETARG_RKC(k, i);
|
val = GETARG_RKC(k, i);
|
||||||
table = this.stack[base + a];
|
table = this.stack[base + a];
|
||||||
table.luaSetTable(this, table, key, val);
|
table.luaSetTable(this, table, key, val);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_NEWTABLE: {
|
case LuaState.OP_NEWTABLE: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
this.stack[base + a] = new LTable(b, c);
|
this.stack[base + a] = new LTable(b, c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_SELF: {
|
case LuaState.OP_SELF: {
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
rkc = GETARG_RKC(k, i);
|
rkc = GETARG_RKC(k, i);
|
||||||
top = base + a;
|
top = base + a;
|
||||||
@@ -356,37 +347,37 @@ public class StackState extends Lua implements VM {
|
|||||||
// Protect(luaV_gettable(L, rb, RKC(i), ra));
|
// Protect(luaV_gettable(L, rb, RKC(i), ra));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_ADD:
|
case LuaState.OP_ADD:
|
||||||
case StackState.OP_SUB:
|
case LuaState.OP_SUB:
|
||||||
case StackState.OP_MUL:
|
case LuaState.OP_MUL:
|
||||||
case StackState.OP_DIV:
|
case LuaState.OP_DIV:
|
||||||
case StackState.OP_MOD:
|
case LuaState.OP_MOD:
|
||||||
case StackState.OP_POW: {
|
case LuaState.OP_POW: {
|
||||||
o = StackState.GET_OPCODE(i);
|
o = LuaState.GET_OPCODE(i);
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
rkc = GETARG_RKC(k, i);
|
rkc = GETARG_RKC(k, i);
|
||||||
this.stack[base + a] = rkc.luaBinOpUnknown(o, rkb);
|
this.stack[base + a] = rkc.luaBinOpUnknown(o, rkb);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_UNM: {
|
case LuaState.OP_UNM: {
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
this.stack[base + a] = rkb.luaUnaryMinus();
|
this.stack[base + a] = rkb.luaUnaryMinus();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_NOT: {
|
case LuaState.OP_NOT: {
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
this.stack[base + a] = (!rkb.toJavaBoolean() ? LBoolean.TRUE
|
this.stack[base + a] = (!rkb.toJavaBoolean() ? LBoolean.TRUE
|
||||||
: LBoolean.FALSE);
|
: LBoolean.FALSE);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_LEN: {
|
case LuaState.OP_LEN: {
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
this.stack[base + a] = LInteger.valueOf( rkb.luaLength() );
|
this.stack[base + a] = LInteger.valueOf( rkb.luaLength() );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_CONCAT: {
|
case LuaState.OP_CONCAT: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
int numValues = c - b + 1;
|
int numValues = c - b + 1;
|
||||||
LString[] strings = new LString[numValues];
|
LString[] strings = new LString[numValues];
|
||||||
|
|
||||||
@@ -397,14 +388,14 @@ public class StackState extends Lua implements VM {
|
|||||||
this.stack[base + a] = LString.concat( strings );
|
this.stack[base + a] = LString.concat( strings );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_JMP: {
|
case LuaState.OP_JMP: {
|
||||||
ci.pc += StackState.GETARG_sBx(i);
|
ci.pc += LuaState.GETARG_sBx(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_EQ:
|
case LuaState.OP_EQ:
|
||||||
case StackState.OP_LT:
|
case LuaState.OP_LT:
|
||||||
case StackState.OP_LE: {
|
case LuaState.OP_LE: {
|
||||||
o = StackState.GET_OPCODE(i);
|
o = LuaState.GET_OPCODE(i);
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
rkc = GETARG_RKC(k, i);
|
rkc = GETARG_RKC(k, i);
|
||||||
boolean test = rkc.luaBinCmpUnknown(o, rkb);
|
boolean test = rkc.luaBinCmpUnknown(o, rkb);
|
||||||
@@ -412,33 +403,33 @@ public class StackState extends Lua implements VM {
|
|||||||
ci.pc++;
|
ci.pc++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_TEST: {
|
case LuaState.OP_TEST: {
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
if (this.stack[base + a].toJavaBoolean() != (c != 0))
|
if (this.stack[base + a].toJavaBoolean() != (c != 0))
|
||||||
ci.pc++;
|
ci.pc++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_TESTSET: {
|
case LuaState.OP_TESTSET: {
|
||||||
rkb = GETARG_RKB(k, i);
|
rkb = GETARG_RKB(k, i);
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
if (rkb.toJavaBoolean() != (c != 0))
|
if (rkb.toJavaBoolean() != (c != 0))
|
||||||
ci.pc++;
|
ci.pc++;
|
||||||
else
|
else
|
||||||
this.stack[base + a] = rkb;
|
this.stack[base + a] = rkb;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_CALL: {
|
case LuaState.OP_CALL: {
|
||||||
|
|
||||||
// ra is base of new call frame
|
// ra is base of new call frame
|
||||||
this.base += a;
|
this.base += a;
|
||||||
|
|
||||||
// number of args
|
// number of args
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
if (b != 0) // else use previous instruction set top
|
if (b != 0) // else use previous instruction set top
|
||||||
top = base + b;
|
top = base + b;
|
||||||
|
|
||||||
// number of return values we need
|
// number of return values we need
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
|
|
||||||
// make or set up the call
|
// make or set up the call
|
||||||
this.nresults = c - 1;
|
this.nresults = c - 1;
|
||||||
@@ -457,13 +448,13 @@ public class StackState extends Lua implements VM {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
case StackState.OP_TAILCALL: {
|
case LuaState.OP_TAILCALL: {
|
||||||
close(base);
|
close(base);
|
||||||
|
|
||||||
// copy down the frame before calling!
|
// copy down the frame before calling!
|
||||||
|
|
||||||
// number of args (including the function)
|
// number of args (including the function)
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
if (b == 0)
|
if (b == 0)
|
||||||
b = top - (base + a);
|
b = top - (base + a);
|
||||||
|
|
||||||
@@ -497,9 +488,9 @@ public class StackState extends Lua implements VM {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case StackState.OP_RETURN: {
|
case LuaState.OP_RETURN: {
|
||||||
// number of return vals to return
|
// number of return vals to return
|
||||||
b = StackState.GETARG_B(i) - 1;
|
b = LuaState.GETARG_B(i) - 1;
|
||||||
if (b == -1)
|
if (b == -1)
|
||||||
b = top - (base + a);
|
b = top - (base + a);
|
||||||
|
|
||||||
@@ -520,7 +511,7 @@ public class StackState extends Lua implements VM {
|
|||||||
// force a reload of the calling context
|
// force a reload of the calling context
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case StackState.OP_FORLOOP: {
|
case LuaState.OP_FORLOOP: {
|
||||||
i0 = this.stack[base + a];
|
i0 = this.stack[base + a];
|
||||||
step = this.stack[base + a + 2];
|
step = this.stack[base + a + 2];
|
||||||
idx = step.luaBinOpUnknown(Lua.OP_ADD, i0);
|
idx = step.luaBinOpUnknown(Lua.OP_ADD, i0);
|
||||||
@@ -532,20 +523,20 @@ public class StackState extends Lua implements VM {
|
|||||||
this.stack[base + a] = idx;
|
this.stack[base + a] = idx;
|
||||||
this.stack[base + a + 3] = idx;
|
this.stack[base + a + 3] = idx;
|
||||||
top = base + a + 3 + 1;
|
top = base + a + 3 + 1;
|
||||||
ci.pc += StackState.GETARG_sBx(i);
|
ci.pc += LuaState.GETARG_sBx(i);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_FORPREP: {
|
case LuaState.OP_FORPREP: {
|
||||||
init = this.stack[base + a];
|
init = this.stack[base + a];
|
||||||
step = this.stack[base + a + 2];
|
step = this.stack[base + a + 2];
|
||||||
this.stack[base + a] = step.luaBinOpUnknown(Lua.OP_SUB,
|
this.stack[base + a] = step.luaBinOpUnknown(Lua.OP_SUB,
|
||||||
init);
|
init);
|
||||||
b = StackState.GETARG_sBx(i);
|
b = LuaState.GETARG_sBx(i);
|
||||||
ci.pc += b;
|
ci.pc += b;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_TFORLOOP: {
|
case LuaState.OP_TFORLOOP: {
|
||||||
cb = a + 3; /* call base */
|
cb = a + 3; /* call base */
|
||||||
System.arraycopy(this.stack, base + a, this.stack,
|
System.arraycopy(this.stack, base + a, this.stack,
|
||||||
base + cb, 3);
|
base + cb, 3);
|
||||||
@@ -554,7 +545,7 @@ public class StackState extends Lua implements VM {
|
|||||||
top = base + 3; /* func. + 2 args (state and index) */
|
top = base + 3; /* func. + 2 args (state and index) */
|
||||||
|
|
||||||
// call the iterator
|
// call the iterator
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
if (this.stack[base].luaStackCall(this))
|
if (this.stack[base].luaStackCall(this))
|
||||||
execute();
|
execute();
|
||||||
adjustTop( base + c - 1 );
|
adjustTop( base + c - 1 );
|
||||||
@@ -570,9 +561,9 @@ public class StackState extends Lua implements VM {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_SETLIST: {
|
case LuaState.OP_SETLIST: {
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
c = StackState.GETARG_C(i);
|
c = LuaState.GETARG_C(i);
|
||||||
int listBase = base + a;
|
int listBase = base + a;
|
||||||
if (b == 0) {
|
if (b == 0) {
|
||||||
b = top - listBase - 1;
|
b = top - listBase - 1;
|
||||||
@@ -589,21 +580,21 @@ public class StackState extends Lua implements VM {
|
|||||||
top = base + a - 1;
|
top = base + a - 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_CLOSE: {
|
case LuaState.OP_CLOSE: {
|
||||||
close( a ); // close upvals higher in the stack than position a
|
close( a ); // close upvals higher in the stack than position a
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_CLOSURE: {
|
case LuaState.OP_CLOSURE: {
|
||||||
b = StackState.GETARG_Bx(i);
|
b = LuaState.GETARG_Bx(i);
|
||||||
proto = cl.p.p[b];
|
proto = cl.p.p[b];
|
||||||
newClosure = new Closure(proto, _G);
|
newClosure = new LClosure(proto, _G);
|
||||||
for (int j = 0; j < newClosure.upVals.length; j++, ci.pc++) {
|
for (int j = 0; j < newClosure.upVals.length; j++, ci.pc++) {
|
||||||
i = code[ci.pc];
|
i = code[ci.pc];
|
||||||
o = StackState.GET_OPCODE(i);
|
o = LuaState.GET_OPCODE(i);
|
||||||
b = StackState.GETARG_B(i);
|
b = LuaState.GETARG_B(i);
|
||||||
if (o == StackState.OP_GETUPVAL) {
|
if (o == LuaState.OP_GETUPVAL) {
|
||||||
newClosure.upVals[j] = cl.upVals[b];
|
newClosure.upVals[j] = cl.upVals[b];
|
||||||
} else if (o == StackState.OP_MOVE) {
|
} else if (o == LuaState.OP_MOVE) {
|
||||||
newClosure.upVals[j] = findUpVal( proto.upvalues[j], base + b );
|
newClosure.upVals[j] = findUpVal( proto.upvalues[j], base + b );
|
||||||
} else {
|
} else {
|
||||||
throw new java.lang.IllegalArgumentException(
|
throw new java.lang.IllegalArgumentException(
|
||||||
@@ -613,12 +604,12 @@ public class StackState extends Lua implements VM {
|
|||||||
this.stack[base + a] = newClosure;
|
this.stack[base + a] = newClosure;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case StackState.OP_VARARG: {
|
case LuaState.OP_VARARG: {
|
||||||
// figure out how many args to copy
|
// figure out how many args to copy
|
||||||
b = StackState.GETARG_B(i) - 1;
|
b = LuaState.GETARG_B(i) - 1;
|
||||||
nvarargs = this.stack[base - 1];
|
nvarargs = this.stack[base - 1];
|
||||||
n = nvarargs.toJavaInt();
|
n = nvarargs.toJavaInt();
|
||||||
if (b == StackState.LUA_MULTRET) {
|
if (b == LuaState.LUA_MULTRET) {
|
||||||
b = n; // use entire varargs supplied
|
b = n; // use entire varargs supplied
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,8 +662,8 @@ public class StackState extends Lua implements VM {
|
|||||||
throw new java.lang.RuntimeException("AbstractStack: not yet implemented");
|
throw new java.lang.RuntimeException("AbstractStack: not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaFunction atpanic(JavaFunction panicf) {
|
public LFunction atpanic(LFunction panicf) {
|
||||||
JavaFunction f = panic;
|
LFunction f = panic;
|
||||||
panic = panicf;
|
panic = panicf;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
@@ -695,11 +686,11 @@ public class StackState extends Lua implements VM {
|
|||||||
notImplemented();
|
notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushclosure(JavaFunction fn, int n) {
|
public void pushclosure(LFunction fn, int n) {
|
||||||
notImplemented();
|
notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int javapcall(JavaFunction func, Object ud) {
|
public int javapcall(LFunction func, Object ud) {
|
||||||
this.pushjavafunction(func);
|
this.pushjavafunction(func);
|
||||||
this.pushlightuserdata(ud);
|
this.pushlightuserdata(ud);
|
||||||
return this.pcall(1, 0, 0);
|
return this.pcall(1, 0, 0);
|
||||||
@@ -811,7 +802,7 @@ public class StackState extends Lua implements VM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isjavafunction(int index) {
|
public boolean isjavafunction(int index) {
|
||||||
return topointer(index) instanceof JavaFunction;
|
return topointer(index) instanceof LFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean islightuserdata(int index) {
|
public boolean islightuserdata(int index) {
|
||||||
@@ -903,7 +894,7 @@ public class StackState extends Lua implements VM {
|
|||||||
pushlvalue( LInteger.valueOf(n) );
|
pushlvalue( LInteger.valueOf(n) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushjavafunction(JavaFunction f) {
|
public void pushjavafunction(LFunction f) {
|
||||||
pushlvalue( f );
|
pushlvalue( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -968,7 +959,7 @@ public class StackState extends Lua implements VM {
|
|||||||
t.put(n,v);
|
t.put(n,v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(String name, JavaFunction f) {
|
public void register(String name, LFunction f) {
|
||||||
pushjavafunction(f);
|
pushjavafunction(f);
|
||||||
setglobal(name);
|
setglobal(name);
|
||||||
}
|
}
|
||||||
@@ -1017,7 +1008,7 @@ public class StackState extends Lua implements VM {
|
|||||||
notImplemented();
|
notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StackState tothread(int index) {
|
public LuaState tothread(int index) {
|
||||||
notImplemented();
|
notImplemented();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1030,8 +1021,8 @@ public class StackState extends Lua implements VM {
|
|||||||
return topointer(index).toJavaInt();
|
return topointer(index).toJavaInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaFunction tojavafunction(int index) {
|
public LFunction tojavafunction(int index) {
|
||||||
return (JavaFunction) topointer(index);
|
return (LFunction) topointer(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LString tolstring(int index) {
|
public LString tolstring(int index) {
|
||||||
@@ -1094,10 +1085,10 @@ public class StackState extends Lua implements VM {
|
|||||||
return topointer(index).luaGetTypeName().toJavaString();
|
return topointer(index).luaGetTypeName().toJavaString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void xmove(VM to, int n) {
|
public void xmove(LuaState to, int n) {
|
||||||
if ( n > 0 ) {
|
if ( n > 0 ) {
|
||||||
to.checkstack(n);
|
to.checkstack(n);
|
||||||
StackState ss = (StackState)to;
|
LuaState ss = (LuaState)to;
|
||||||
System.arraycopy(stack, top-n, ss.stack, ss.top, n);
|
System.arraycopy(stack, top-n, ss.stack, ss.top, n);
|
||||||
ss.top += n;
|
ss.top += n;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.luacompat;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -7,6 +7,7 @@ import java.io.Reader;
|
|||||||
/**
|
/**
|
||||||
* Singleton to manage platform-specific behaviors.
|
* Singleton to manage platform-specific behaviors.
|
||||||
*
|
*
|
||||||
|
* @deprecated - will probably be replaced with Config, LuaConfig or something similar.
|
||||||
*/
|
*/
|
||||||
abstract public class Platform {
|
abstract public class Platform {
|
||||||
private static Platform instance;
|
private static Platform instance;
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package lua.io;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import lua.value.LString;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
public class UpVal {
|
public class UpVal {
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
public class AbortException extends RuntimeException {
|
public class AbortException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 8043724992294286647L;
|
private static final long serialVersionUID = 8043724992294286647L;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
@@ -27,29 +27,32 @@ import java.util.Timer;
|
|||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import lua.CallInfo;
|
import org.luaj.compiler.LexState;
|
||||||
import lua.Lua;
|
import org.luaj.debug.event.DebugEvent;
|
||||||
import lua.StackState;
|
import org.luaj.debug.event.DebugEventBreakpoint;
|
||||||
import lua.addon.compile.LexState;
|
import org.luaj.debug.event.DebugEventError;
|
||||||
import lua.debug.event.DebugEvent;
|
import org.luaj.debug.event.DebugEventType;
|
||||||
import lua.debug.event.DebugEventBreakpoint;
|
import org.luaj.debug.request.DebugRequest;
|
||||||
import lua.debug.event.DebugEventError;
|
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
||||||
import lua.debug.event.DebugEventType;
|
import org.luaj.debug.request.DebugRequestListener;
|
||||||
import lua.debug.request.DebugRequest;
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
import lua.debug.request.DebugRequestLineBreakpointToggle;
|
import org.luaj.debug.request.DebugRequestType;
|
||||||
import lua.debug.request.DebugRequestListener;
|
import org.luaj.debug.response.DebugResponse;
|
||||||
import lua.debug.request.DebugRequestStack;
|
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||||
import lua.debug.request.DebugRequestType;
|
import org.luaj.debug.response.DebugResponseSimple;
|
||||||
import lua.debug.response.DebugResponse;
|
import org.luaj.debug.response.DebugResponseStack;
|
||||||
import lua.debug.response.DebugResponseCallgraph;
|
import org.luaj.vm.CallInfo;
|
||||||
import lua.debug.response.DebugResponseSimple;
|
import org.luaj.vm.LClosure;
|
||||||
import lua.debug.response.DebugResponseVariables;
|
import org.luaj.vm.LTable;
|
||||||
import lua.io.LocVars;
|
import org.luaj.vm.LValue;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LocVars;
|
||||||
import lua.value.LTable;
|
import org.luaj.vm.Lua;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LPrototype;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
public class DebugStackState extends StackState implements DebugRequestListener {
|
|
||||||
|
public class DebugStackState extends LuaState implements DebugRequestListener {
|
||||||
|
private static final boolean TRACE = (null != System.getProperty("TRACE"));
|
||||||
|
|
||||||
// stepping constants and stepping state
|
// stepping constants and stepping state
|
||||||
protected static final int STEP_NONE = 0;
|
protected static final int STEP_NONE = 0;
|
||||||
@@ -97,7 +100,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
String source = "?";
|
String source = "?";
|
||||||
if (cindex >= 0) {
|
if (cindex >= 0) {
|
||||||
CallInfo call = this.calls[cindex];
|
CallInfo call = this.calls[cindex];
|
||||||
Proto p = call.closure.p;
|
LPrototype p = call.closure.p;
|
||||||
if (p != null && p.source != null)
|
if (p != null && p.source != null)
|
||||||
source = p.source.toJavaString();
|
source = p.source.toJavaString();
|
||||||
int pc = getCurrentPc(call);
|
int pc = getCurrentPc(call);
|
||||||
@@ -149,6 +152,13 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
|
|
||||||
// debug hooks
|
// debug hooks
|
||||||
public void debugHooks(int pc) {
|
public void debugHooks(int pc) {
|
||||||
|
if (TRACE) {
|
||||||
|
CallInfo ci = calls[cc];
|
||||||
|
LClosure cl = ci.closure;
|
||||||
|
LPrototype p = cl.p;
|
||||||
|
Print.printState(this, base, top, base+p.maxstacksize, cl, pc);
|
||||||
|
}
|
||||||
|
|
||||||
if (exiting) {
|
if (exiting) {
|
||||||
throw new AbortException("aborted by debug client");
|
throw new AbortException("aborted by debug client");
|
||||||
}
|
}
|
||||||
@@ -171,7 +181,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
CallInfo currentCallInfo = calls[cc];
|
CallInfo currentCallInfo = calls[cc];
|
||||||
Proto currentProto = currentCallInfo.closure.p;
|
LPrototype currentProto = currentCallInfo.closure.p;
|
||||||
|
|
||||||
// if we are not stepping, we would keep going if the line doesn't
|
// if we are not stepping, we would keep going if the line doesn't
|
||||||
// change
|
// change
|
||||||
@@ -185,8 +195,8 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
DebugUtils.println("debugHook - executing line: " + line);
|
DebugUtils.println("debugHook - executing line: " + line);
|
||||||
|
|
||||||
int i = currentProto.code[pc];
|
int i = currentProto.code[pc];
|
||||||
int opCode = StackState.GET_OPCODE(i);
|
int opCode = LuaState.GET_OPCODE(i);
|
||||||
if (isStepping() && opCode == StackState.OP_RETURN && cc == 0) {
|
if (isStepping() && opCode == LuaState.OP_RETURN && cc == 0) {
|
||||||
cancelStepping();
|
cancelStepping();
|
||||||
} else if (shouldPauseForStepping) {
|
} else if (shouldPauseForStepping) {
|
||||||
shouldPauseForStepping = false;
|
shouldPauseForStepping = false;
|
||||||
@@ -194,7 +204,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
} else if (stepping == STEP_INTO) {
|
} else if (stepping == STEP_INTO) {
|
||||||
if (lastline != line) {
|
if (lastline != line) {
|
||||||
suspendOnStepping();
|
suspendOnStepping();
|
||||||
} else if (opCode == StackState.OP_CALL) {
|
} else if (opCode == LuaState.OP_CALL) {
|
||||||
shouldPauseForStepping = true;
|
shouldPauseForStepping = true;
|
||||||
}
|
}
|
||||||
} else if (stepping == STEP_OVER) {
|
} else if (stepping == STEP_OVER) {
|
||||||
@@ -203,8 +213,8 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
suspendOnStepping();
|
suspendOnStepping();
|
||||||
}
|
}
|
||||||
} else if (stepping == STEP_RETURN) {
|
} else if (stepping == STEP_RETURN) {
|
||||||
if ((opCode == StackState.OP_RETURN && cc == this.steppingFrame) ||
|
if ((opCode == LuaState.OP_RETURN && cc == this.steppingFrame) ||
|
||||||
(opCode == StackState.OP_TAILCALL && cc == this.steppingFrame)) {
|
(opCode == LuaState.OP_TAILCALL && cc == this.steppingFrame)) {
|
||||||
shouldPauseForStepping = true;
|
shouldPauseForStepping = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,9 +338,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
} else if (DebugRequestType.stack == requestType) {
|
} else if (DebugRequestType.stack == requestType) {
|
||||||
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
||||||
int index = stackRequest.getIndex();
|
int index = stackRequest.getIndex();
|
||||||
return new DebugResponseVariables(getStack(index));
|
return new DebugResponseStack(getStack(index));
|
||||||
} else if (DebugRequestType.global == requestType) {
|
|
||||||
return new DebugResponseVariables(getGlobals());
|
|
||||||
} else if (DebugRequestType.stepInto == requestType) {
|
} else if (DebugRequestType.stepInto == requestType) {
|
||||||
DebugEvent event = new DebugEvent(
|
DebugEvent event = new DebugEvent(
|
||||||
DebugEventType.resumedOnSteppingInto);
|
DebugEventType.resumedOnSteppingInto);
|
||||||
@@ -477,44 +485,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
|
|
||||||
Vector variables = new Vector();
|
Vector variables = new Vector();
|
||||||
Hashtable variablesSeen = new Hashtable();
|
Hashtable variablesSeen = new Hashtable();
|
||||||
Proto p = calls[index].closure.p;
|
addVariables(variables, variablesSeen, index);
|
||||||
for (int i = index; i >= 0; i--) {
|
|
||||||
if (i == index || isInScope(p, calls[i])) {
|
|
||||||
addVariables(variables, variablesSeen, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Variable[] result = new Variable[variables.size()];
|
|
||||||
for (int i = 0; i < variables.size(); i++) {
|
|
||||||
result[i] = (Variable) variables.elementAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isInScope(Proto p, CallInfo ci) {
|
|
||||||
Proto[] enclosingProtos = ci.closure.p.p;
|
|
||||||
boolean bFound = false;
|
|
||||||
for (int i = 0; enclosingProtos!= null && i < enclosingProtos.length; i++) {
|
|
||||||
if (enclosingProtos[i] == p) {
|
|
||||||
bFound = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the visible globals to the current VM.
|
|
||||||
* @return the visible globals.
|
|
||||||
*/
|
|
||||||
public Variable[] getGlobals() {
|
|
||||||
Vector variables = new Vector();
|
|
||||||
variables.addElement(
|
|
||||||
new TableVariable(0,
|
|
||||||
"*Globals*",
|
|
||||||
Lua.LUA_TTABLE,
|
|
||||||
(LTable) _G));
|
|
||||||
|
|
||||||
Variable[] result = new Variable[variables.size()];
|
Variable[] result = new Variable[variables.size()];
|
||||||
for (int i = 0; i < variables.size(); i++) {
|
for (int i = 0; i < variables.size(); i++) {
|
||||||
@@ -561,7 +532,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
|
|
||||||
private void addVariables(Vector variables, Hashtable variablesSeen, int index) {
|
private void addVariables(Vector variables, Hashtable variablesSeen, int index) {
|
||||||
CallInfo callInfo = calls[index];
|
CallInfo callInfo = calls[index];
|
||||||
Proto prototype = callInfo.closure.p;
|
LPrototype prototype = callInfo.closure.p;
|
||||||
int base = callInfo.base;
|
int base = callInfo.base;
|
||||||
int top = callInfo.top < callInfo.base ? callInfo.base+1 : callInfo.top;
|
int top = callInfo.top < callInfo.base ? callInfo.base+1 : callInfo.top;
|
||||||
|
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.event.DebugEvent;
|
import org.luaj.debug.event.DebugEvent;
|
||||||
import lua.debug.event.DebugEventListener;
|
import org.luaj.debug.event.DebugEventListener;
|
||||||
import lua.debug.request.DebugRequest;
|
import org.luaj.debug.request.DebugRequest;
|
||||||
import lua.debug.request.DebugRequestListener;
|
import org.luaj.debug.request.DebugRequestListener;
|
||||||
import lua.debug.response.DebugResponse;
|
import org.luaj.debug.response.DebugResponse;
|
||||||
|
|
||||||
|
|
||||||
public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||||
protected static final int UNKNOWN = 0;
|
protected static final int UNKNOWN = 0;
|
||||||
@@ -19,10 +19,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
|
import org.luaj.vm.LString;
|
||||||
|
import org.luaj.vm.LoadState;
|
||||||
|
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.value.LString;
|
|
||||||
|
|
||||||
public class DebugUtils {
|
public class DebugUtils {
|
||||||
public static final boolean IS_DEBUG = false;
|
public static final boolean IS_DEBUG = false;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -1,21 +1,70 @@
|
|||||||
package lua;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import lua.io.Closure;
|
import org.luaj.vm.LClosure;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LDouble;
|
||||||
import lua.value.LDouble;
|
import org.luaj.vm.LFunction;
|
||||||
import lua.value.LFunction;
|
import org.luaj.vm.LInteger;
|
||||||
import lua.value.LInteger;
|
import org.luaj.vm.LPrototype;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LValue;
|
||||||
|
import org.luaj.vm.Lua;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Print extends Lua {
|
public class Print extends Lua {
|
||||||
|
|
||||||
|
/** opcode names */
|
||||||
private static final String STRING_FOR_NULL = "null";
|
private static final String STRING_FOR_NULL = "null";
|
||||||
public static PrintStream ps = System.out;
|
public static PrintStream ps = System.out;
|
||||||
|
|
||||||
|
private static final String[] luaP_opnames = {
|
||||||
|
"MOVE",
|
||||||
|
"LOADK",
|
||||||
|
"LOADBOOL",
|
||||||
|
"LOADNIL",
|
||||||
|
"GETUPVAL",
|
||||||
|
"GETGLOBAL",
|
||||||
|
"GETTABLE",
|
||||||
|
"SETGLOBAL",
|
||||||
|
"SETUPVAL",
|
||||||
|
"SETTABLE",
|
||||||
|
"NEWTABLE",
|
||||||
|
"SELF",
|
||||||
|
"ADD",
|
||||||
|
"SUB",
|
||||||
|
"MUL",
|
||||||
|
"DIV",
|
||||||
|
"MOD",
|
||||||
|
"POW",
|
||||||
|
"UNM",
|
||||||
|
"NOT",
|
||||||
|
"LEN",
|
||||||
|
"CONCAT",
|
||||||
|
"JMP",
|
||||||
|
"EQ",
|
||||||
|
"LT",
|
||||||
|
"LE",
|
||||||
|
"TEST",
|
||||||
|
"TESTSET",
|
||||||
|
"CALL",
|
||||||
|
"TAILCALL",
|
||||||
|
"RETURN",
|
||||||
|
"FORLOOP",
|
||||||
|
"FORPREP",
|
||||||
|
"TFORLOOP",
|
||||||
|
"SETLIST",
|
||||||
|
"CLOSE",
|
||||||
|
"CLOSURE",
|
||||||
|
"VARARG",
|
||||||
|
null,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void printString(String s) {
|
static void printString(String s) {
|
||||||
char[] chars = s.toCharArray();
|
char[] chars = s.toCharArray();
|
||||||
ps.print('"');
|
ps.print('"');
|
||||||
@@ -78,11 +127,11 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printConstant(Proto f, int i) {
|
static void printConstant(LPrototype f, int i) {
|
||||||
printValue( f.k[i] );
|
printValue( f.k[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printCode(Proto f) {
|
public static void printCode(LPrototype f) {
|
||||||
int[] code = f.code;
|
int[] code = f.code;
|
||||||
int pc, n = code.length;
|
int pc, n = code.length;
|
||||||
for (pc = 0; pc < n; pc++) {
|
for (pc = 0; pc < n; pc++) {
|
||||||
@@ -91,7 +140,7 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printOpCode(Proto f, int pc) {
|
static void printOpCode(LPrototype f, int pc) {
|
||||||
int[] code = f.code;
|
int[] code = f.code;
|
||||||
int i = code[pc];
|
int i = code[pc];
|
||||||
int o = GET_OPCODE(i);
|
int o = GET_OPCODE(i);
|
||||||
@@ -195,11 +244,11 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getline(Proto f, int pc) {
|
private static int getline(LPrototype f, int pc) {
|
||||||
return f.lineinfo[pc];
|
return f.lineinfo[pc];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printHeader(Proto f) {
|
static void printHeader(LPrototype f) {
|
||||||
String s = String.valueOf(f.source);
|
String s = String.valueOf(f.source);
|
||||||
if (s.startsWith("@") || s.startsWith("="))
|
if (s.startsWith("@") || s.startsWith("="))
|
||||||
s = s.substring(1);
|
s = s.substring(1);
|
||||||
@@ -217,7 +266,7 @@ public class Print extends Lua {
|
|||||||
+ " constant, " + f.p.length + " function\n");
|
+ " constant, " + f.p.length + " function\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printConstants(Proto f) {
|
static void printConstants(LPrototype f) {
|
||||||
int i, n = f.k.length;
|
int i, n = f.k.length;
|
||||||
ps.print("constants (" + n + ") for " + id(f) + ":\n");
|
ps.print("constants (" + n + ") for " + id(f) + ":\n");
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
@@ -227,7 +276,7 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printLocals(Proto f) {
|
static void printLocals(LPrototype f) {
|
||||||
int i, n = f.locvars.length;
|
int i, n = f.locvars.length;
|
||||||
ps.print("locals (" + n + ") for " + id(f) + ":\n");
|
ps.print("locals (" + n + ") for " + id(f) + ":\n");
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
@@ -235,7 +284,7 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printUpValues(Proto f) {
|
static void printUpValues(LPrototype f) {
|
||||||
int i, n = f.upvalues.length;
|
int i, n = f.upvalues.length;
|
||||||
ps.print("upvalues (" + n + ") for " + id(f) + ":\n");
|
ps.print("upvalues (" + n + ") for " + id(f) + ":\n");
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
@@ -243,7 +292,7 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printFunction(Proto f, boolean full) {
|
public void printFunction(LPrototype f, boolean full) {
|
||||||
int i, n = f.p.length;
|
int i, n = f.p.length;
|
||||||
printHeader(f);
|
printHeader(f);
|
||||||
printCode(f);
|
printCode(f);
|
||||||
@@ -267,8 +316,8 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printState(StackState state, int base, int top, int max,
|
public static void printState(LuaState state, int base, int top, int max,
|
||||||
Closure cl, int pc) {
|
LClosure cl, int pc) {
|
||||||
|
|
||||||
// print opcode into buffer
|
// print opcode into buffer
|
||||||
PrintStream previous = ps;
|
PrintStream previous = ps;
|
||||||
@@ -301,7 +350,7 @@ public class Print extends Lua {
|
|||||||
ps.println();
|
ps.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String id(Proto f) {
|
private static String id(LPrototype f) {
|
||||||
return "Proto";
|
return "Proto";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
176
src/debug/org/luaj/debug/SerializationHelper.java
Normal file
176
src/debug/org/luaj/debug/SerializationHelper.java
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
package org.luaj.debug;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
import org.luaj.debug.event.DebugEventBreakpoint;
|
||||||
|
import org.luaj.debug.event.DebugEventError;
|
||||||
|
import org.luaj.debug.event.DebugEventType;
|
||||||
|
import org.luaj.debug.request.DebugRequest;
|
||||||
|
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
||||||
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
|
import org.luaj.debug.request.DebugRequestType;
|
||||||
|
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||||
|
import org.luaj.debug.response.DebugResponseSimple;
|
||||||
|
import org.luaj.debug.response.DebugResponseStack;
|
||||||
|
|
||||||
|
|
||||||
|
public class SerializationHelper {
|
||||||
|
|
||||||
|
public static byte[] serialize(Serializable object) throws IOException {
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dout = new DataOutputStream(bout);
|
||||||
|
|
||||||
|
serialize(object, dout);
|
||||||
|
|
||||||
|
byte[] data = bout.toByteArray();
|
||||||
|
|
||||||
|
bout.close();
|
||||||
|
dout.close();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Serializable deserialize(byte[] data) throws IOException {
|
||||||
|
ByteArrayInputStream bin = new ByteArrayInputStream(data);
|
||||||
|
DataInputStream din = new DataInputStream(bin);
|
||||||
|
|
||||||
|
Serializable object = deserialize(din);
|
||||||
|
|
||||||
|
bin.close();
|
||||||
|
din.close();
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static final int SERIAL_TYPE_NullableString = 0;
|
||||||
|
static final int SERIAL_TYPE_TableVariable = 1;
|
||||||
|
static final int SERIAL_TYPE_Variable = 2;
|
||||||
|
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
||||||
|
static final int SERIAL_TYPE_DebugResponseStack = 4;
|
||||||
|
static final int SERIAL_TYPE_DebugResponseSimple = 5;
|
||||||
|
static final int SERIAL_TYPE_StackFrame = 6;
|
||||||
|
static final int SERIAL_TYPE_DebugRequestType = 7;
|
||||||
|
static final int SERIAL_TYPE_DebugRequest = 8;
|
||||||
|
static final int SERIAL_TYPE_DebugRequestStack = 9;
|
||||||
|
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 10;
|
||||||
|
static final int SERIAL_TYPE_DebugEventType = 11;
|
||||||
|
static final int SERIAL_TYPE_DebugEvent = 12;
|
||||||
|
static final int SERIAL_TYPE_DebugEventBreakpoint = 13;
|
||||||
|
static final int SERIAL_TYPE_DebugEventError = 14;
|
||||||
|
|
||||||
|
public static void serialize(Serializable object, DataOutputStream dout)
|
||||||
|
throws IOException {
|
||||||
|
if (object instanceof NullableString) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_NullableString);
|
||||||
|
NullableString.serialize(dout, (NullableString)object);
|
||||||
|
} else if (object instanceof TableVariable) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_TableVariable);
|
||||||
|
TableVariable.serialize(dout, (TableVariable)object);
|
||||||
|
} else if (object instanceof Variable) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_Variable);
|
||||||
|
Variable.serialize(dout, (Variable)object);
|
||||||
|
} else if (object instanceof StackFrame) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_StackFrame);
|
||||||
|
StackFrame.serialize(dout, (StackFrame)object);
|
||||||
|
} else if (object instanceof DebugResponseSimple) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugResponseSimple);
|
||||||
|
DebugResponseSimple.serialize(dout, (DebugResponseSimple)object);
|
||||||
|
} else if (object instanceof DebugResponseStack) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugResponseStack);
|
||||||
|
DebugResponseStack.serialize(dout, (DebugResponseStack)object);
|
||||||
|
} else if (object instanceof DebugResponseCallgraph) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph);
|
||||||
|
DebugResponseCallgraph.serialize(dout, (DebugResponseCallgraph)object);
|
||||||
|
} else if (object instanceof DebugRequestType) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugRequestType);
|
||||||
|
DebugRequestType.serialize(dout, (DebugRequestType)object);
|
||||||
|
} else if (object instanceof DebugRequestStack) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugRequestStack);
|
||||||
|
DebugRequestStack.serialize(dout, (DebugRequestStack)object);
|
||||||
|
} else if (object instanceof DebugRequestLineBreakpointToggle) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle);
|
||||||
|
DebugRequestLineBreakpointToggle.serialize(dout, (DebugRequestLineBreakpointToggle)object);
|
||||||
|
} else if (object instanceof DebugRequest) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugRequest);
|
||||||
|
DebugRequest.serialize(dout, (DebugRequest)object);
|
||||||
|
} else if (object instanceof DebugEventType) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugEventType);
|
||||||
|
DebugEventType.serialize(dout, (DebugEventType)object);
|
||||||
|
} else if (object instanceof DebugEventBreakpoint) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint);
|
||||||
|
DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint)object);
|
||||||
|
} else if (object instanceof DebugEventError) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugEventError);
|
||||||
|
DebugEventError.serialize(dout, (DebugEventError)object);
|
||||||
|
} else if (object instanceof DebugEvent) {
|
||||||
|
dout.writeInt(SERIAL_TYPE_DebugEvent);
|
||||||
|
DebugEvent.serialize(dout, (DebugEvent)object);
|
||||||
|
} else {
|
||||||
|
// catch the errors: forgot to implement serialization/deserialization
|
||||||
|
throw new RuntimeException("serialization operation is not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Serializable deserialize(DataInputStream din)
|
||||||
|
throws IOException {
|
||||||
|
Serializable object = null;
|
||||||
|
int type = din.readInt();
|
||||||
|
switch (type) {
|
||||||
|
case SERIAL_TYPE_NullableString:
|
||||||
|
object = NullableString.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_TableVariable:
|
||||||
|
object = TableVariable.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_Variable:
|
||||||
|
object = Variable.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_StackFrame:
|
||||||
|
object = StackFrame.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugResponseSimple:
|
||||||
|
object = DebugResponseSimple.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugResponseCallgraph:
|
||||||
|
object = DebugResponseCallgraph.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugResponseStack:
|
||||||
|
object = DebugResponseStack.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugRequestType:
|
||||||
|
object = DebugRequestType.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugRequestStack:
|
||||||
|
object = DebugRequestStack.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugRequestLineBreakpointToggle:
|
||||||
|
object = DebugRequestLineBreakpointToggle.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugRequest:
|
||||||
|
object = DebugRequest.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugEventType:
|
||||||
|
object = DebugEventType.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugEventBreakpoint:
|
||||||
|
object = DebugEventBreakpoint.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugEventError:
|
||||||
|
object = DebugEventError.deserialize(din);
|
||||||
|
break;
|
||||||
|
case SERIAL_TYPE_DebugEvent:
|
||||||
|
object = DebugEvent.deserialize(din);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("deserialization operation is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,13 +40,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.CallInfo;
|
import org.luaj.vm.CallInfo;
|
||||||
|
|
||||||
|
|
||||||
public class StackFrame implements Serializable {
|
public class StackFrame implements Serializable {
|
||||||
protected int lineNumber;
|
protected int lineNumber;
|
||||||
@@ -19,16 +19,17 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import lua.Lua;
|
import org.luaj.vm.LTable;
|
||||||
import lua.value.LTable;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
|
|
||||||
public class TableVariable extends Variable {
|
public class TableVariable extends Variable {
|
||||||
protected String[] keys;
|
protected String[] keys;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
public class VMException extends RuntimeException {
|
public class VMException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 7876955153693775429L;
|
private static final long serialVersionUID = 7876955153693775429L;
|
||||||
@@ -19,13 +19,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.Lua;
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
|
|
||||||
public class Variable implements Serializable {
|
public class Variable implements Serializable {
|
||||||
protected int index;
|
protected int index;
|
||||||
@@ -19,14 +19,15 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.Serializable;
|
import org.luaj.debug.Serializable;
|
||||||
import lua.debug.SerializationHelper;
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
|
||||||
|
|
||||||
public class DebugEvent implements Serializable {
|
public class DebugEvent implements Serializable {
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
public interface DebugEventListener {
|
public interface DebugEventListener {
|
||||||
public void notifyDebugEvent(DebugEvent event);
|
public void notifyDebugEvent(DebugEvent event);
|
||||||
@@ -19,12 +19,13 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.EnumType;
|
import org.luaj.debug.EnumType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DebugEventType extends EnumType {
|
public class DebugEventType extends EnumType {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.debug.j2me;
|
package org.luaj.debug.j2me;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -6,8 +6,9 @@ import javax.microedition.io.Connector;
|
|||||||
import javax.microedition.io.ServerSocketConnection;
|
import javax.microedition.io.ServerSocketConnection;
|
||||||
import javax.microedition.io.SocketConnection;
|
import javax.microedition.io.SocketConnection;
|
||||||
|
|
||||||
import lua.debug.DebugSupport;
|
import org.luaj.debug.DebugSupport;
|
||||||
import lua.debug.event.DebugEvent;
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
|
||||||
|
|
||||||
public class DebugSupportImpl extends DebugSupport {
|
public class DebugSupportImpl extends DebugSupport {
|
||||||
protected ServerSocketConnection requestServerConnection;
|
protected ServerSocketConnection requestServerConnection;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.j2se;
|
package org.luaj.debug.j2se;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -27,8 +27,9 @@ import java.io.IOException;
|
|||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import lua.debug.DebugSupport;
|
import org.luaj.debug.DebugSupport;
|
||||||
import lua.debug.event.DebugEvent;
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
|
||||||
|
|
||||||
public class DebugSupportImpl extends DebugSupport {
|
public class DebugSupportImpl extends DebugSupport {
|
||||||
protected ServerSocket requestSocket;
|
protected ServerSocket requestSocket;
|
||||||
@@ -19,26 +19,27 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.j2se;
|
package org.luaj.debug.j2se;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import lua.GlobalState;
|
import org.luaj.debug.DebugStackState;
|
||||||
import lua.StackState;
|
import org.luaj.debug.DebugSupport;
|
||||||
import lua.addon.luacompat.LuaCompat;
|
import org.luaj.debug.DebugUtils;
|
||||||
import lua.addon.luajava.LuaJava;
|
import org.luaj.debug.VMException;
|
||||||
import lua.debug.DebugStackState;
|
import org.luaj.lib.MathLib;
|
||||||
import lua.debug.DebugSupport;
|
import org.luaj.lib.j2se.LuajavaLib;
|
||||||
import lua.debug.DebugUtils;
|
import org.luaj.vm.LClosure;
|
||||||
import lua.debug.VMException;
|
import org.luaj.vm.LPrototype;
|
||||||
import lua.io.Closure;
|
import org.luaj.vm.LString;
|
||||||
import lua.io.LoadState;
|
import org.luaj.vm.LTable;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LoadState;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StandardLuaJVM executes a lua program in normal run mode or debug mode.
|
* StandardLuaJVM executes a lua program in normal run mode or debug mode.
|
||||||
@@ -52,7 +53,7 @@ public class StandardLuaJVM {
|
|||||||
protected int eventPort;
|
protected int eventPort;
|
||||||
protected String script;
|
protected String script;
|
||||||
protected String[] scriptArgs;
|
protected String[] scriptArgs;
|
||||||
protected StackState state;
|
protected LuaState state;
|
||||||
protected boolean isReady = false;
|
protected boolean isReady = false;
|
||||||
protected boolean isTerminated = false;
|
protected boolean isTerminated = false;
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ public class StandardLuaJVM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void parseScriptArgs(String[] args)
|
private void parseScriptArgs(String[] args)
|
||||||
throws lua.debug.j2se.StandardLuaJVM.ParseException {
|
throws org.luaj.debug.j2se.StandardLuaJVM.ParseException {
|
||||||
if (args == null || args.length < 1) {
|
if (args == null || args.length < 1) {
|
||||||
throw new ParseException("script is missing.");
|
throw new ParseException("script is missing.");
|
||||||
}
|
}
|
||||||
@@ -159,22 +160,20 @@ public class StandardLuaJVM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init(LTable globals) {
|
||||||
//Reset the _G table
|
|
||||||
GlobalState.resetGlobals();
|
|
||||||
|
|
||||||
// add LuaJava bindings
|
// add LuaJava bindings
|
||||||
LuaJava.install();
|
LuajavaLib.install(globals);
|
||||||
|
|
||||||
// add LuaCompat bindings
|
// add LuaCompat bindings
|
||||||
LuaCompat.install();
|
MathLib.install(globals);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doRun() throws IOException {
|
protected void doRun() throws IOException {
|
||||||
init();
|
|
||||||
|
|
||||||
// new lua state
|
// new lua state
|
||||||
state = new StackState();
|
state = new LuaState();
|
||||||
|
init(state._G);
|
||||||
|
|
||||||
// convert args to lua
|
// convert args to lua
|
||||||
String[] scriptArgs = getScriptArgs();
|
String[] scriptArgs = getScriptArgs();
|
||||||
@@ -187,24 +186,24 @@ public class StandardLuaJVM {
|
|||||||
// load the Lua file
|
// load the Lua file
|
||||||
DebugUtils.println("loading Lua script '" + getScript() + "'");
|
DebugUtils.println("loading Lua script '" + getScript() + "'");
|
||||||
InputStream is = new FileInputStream(new File(getScript()));
|
InputStream is = new FileInputStream(new File(getScript()));
|
||||||
Proto p = LoadState.undump(state, is, getScript());
|
LPrototype p = LoadState.undump(state, is, getScript());
|
||||||
|
|
||||||
// create closure and execute
|
// create closure and execute
|
||||||
Closure c = new Closure(state, p);
|
LClosure c = new LClosure(state, p);
|
||||||
state.doCall(c, vargs);
|
state.doCall(c, vargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doDebug() throws IOException {
|
protected void doDebug() throws IOException {
|
||||||
DebugUtils.println("setting up LuaJava and debug stack state...");
|
DebugUtils.println("setting up LuaJava and debug stack state...");
|
||||||
init();
|
|
||||||
|
|
||||||
// new lua debug state
|
// new lua debug state
|
||||||
state = new DebugStackState();
|
state = new DebugStackState();
|
||||||
|
init(state._G);
|
||||||
|
|
||||||
// load the Lua file
|
// load the Lua file
|
||||||
DebugUtils.println("loading Lua script '" + getScript() + "'");
|
DebugUtils.println("loading Lua script '" + getScript() + "'");
|
||||||
InputStream is = new FileInputStream(new File(getScript()));
|
InputStream is = new FileInputStream(new File(getScript()));
|
||||||
Proto p = LoadState.undump(state, is, getScript());
|
LPrototype p = LoadState.undump(state, is, getScript());
|
||||||
|
|
||||||
// set up debug support if the file is successfully loaded
|
// set up debug support if the file is successfully loaded
|
||||||
DebugUtils.println("start debugging...");
|
DebugUtils.println("start debugging...");
|
||||||
@@ -214,7 +213,7 @@ public class StandardLuaJVM {
|
|||||||
getDebugState().setSuspendAtStart(true);
|
getDebugState().setSuspendAtStart(true);
|
||||||
|
|
||||||
// create closure and execute
|
// create closure and execute
|
||||||
final Closure c = new Closure(state, p);
|
final LClosure c = new LClosure(p, state._G);
|
||||||
String[] args = getScriptArgs();
|
String[] args = getScriptArgs();
|
||||||
int numOfScriptArgs = (args != null ? args.length : 0);
|
int numOfScriptArgs = (args != null ? args.length : 0);
|
||||||
LValue[] vargs = new LValue[numOfScriptArgs];
|
LValue[] vargs = new LValue[numOfScriptArgs];
|
||||||
@@ -19,14 +19,15 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.Serializable;
|
import org.luaj.debug.Serializable;
|
||||||
import lua.debug.SerializationHelper;
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
|
||||||
|
|
||||||
public class DebugRequest implements Serializable {
|
public class DebugRequest implements Serializable {
|
||||||
protected DebugRequestType type;
|
protected DebugRequestType type;
|
||||||
@@ -46,16 +47,14 @@ public class DebugRequest implements Serializable {
|
|||||||
return type.toString();
|
return type.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serialize(DataOutputStream out, DebugRequest request)
|
public static void serialize(DataOutputStream out, DebugRequest request)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
DebugRequestType type = request.getType();
|
DebugRequestType type = request.getType();
|
||||||
SerializationHelper.serialize(type, out);
|
SerializationHelper.serialize(type, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugRequest deserialize(DataInputStream in)
|
public static DebugRequest deserialize(DataInputStream in) throws IOException {
|
||||||
throws IOException {
|
DebugRequestType type = (DebugRequestType) SerializationHelper.deserialize(in);
|
||||||
DebugRequestType type = (DebugRequestType) SerializationHelper
|
return new DebugRequest(type);
|
||||||
.deserialize(in);
|
}
|
||||||
return new DebugRequest(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -19,13 +19,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.SerializationHelper;
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
|
||||||
|
|
||||||
public class DebugRequestLineBreakpointToggle extends DebugRequest {
|
public class DebugRequestLineBreakpointToggle extends DebugRequest {
|
||||||
protected String source;
|
protected String source;
|
||||||
@@ -19,9 +19,9 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import lua.debug.response.DebugResponse;
|
import org.luaj.debug.response.DebugResponse;
|
||||||
|
|
||||||
public interface DebugRequestListener {
|
public interface DebugRequestListener {
|
||||||
|
|
||||||
@@ -19,13 +19,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.Serializable;
|
import org.luaj.debug.Serializable;
|
||||||
|
|
||||||
|
|
||||||
public class DebugRequestStack extends DebugRequest implements Serializable {
|
public class DebugRequestStack extends DebugRequest implements Serializable {
|
||||||
protected int index;
|
protected int index;
|
||||||
@@ -19,18 +19,19 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.EnumType;
|
import org.luaj.debug.EnumType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DebugRequestType extends EnumType {
|
public class DebugRequestType extends EnumType {
|
||||||
public static final DebugRequestType start = new DebugRequestType("start", 0);
|
public static final DebugRequestType start = new DebugRequestType("start", 0);
|
||||||
public static final DebugRequestType resume = new DebugRequestType("resume", 1);
|
public static final DebugRequestType resume = new DebugRequestType("resume", 1);
|
||||||
public static final DebugRequestType suspend = new DebugRequestType("suspend", 2);
|
public static final DebugRequestType suspend = new DebugRequestType("suspend", 2);
|
||||||
public static final DebugRequestType exit = new DebugRequestType("exit", 3);
|
public static final DebugRequestType exit = new DebugRequestType("exit", 3);
|
||||||
public static final DebugRequestType lineBreakpointSet = new DebugRequestType("lineBreakpointSet", 4);
|
public static final DebugRequestType lineBreakpointSet = new DebugRequestType("lineBreakpointSet", 4);
|
||||||
public static final DebugRequestType lineBreakpointClear = new DebugRequestType("lineBreakpointClear", 5);
|
public static final DebugRequestType lineBreakpointClear = new DebugRequestType("lineBreakpointClear", 5);
|
||||||
@@ -41,7 +42,6 @@ public class DebugRequestType extends EnumType {
|
|||||||
public static final DebugRequestType stepInto = new DebugRequestType("stepInto", 10);
|
public static final DebugRequestType stepInto = new DebugRequestType("stepInto", 10);
|
||||||
public static final DebugRequestType stepOver = new DebugRequestType("stepOver", 11);
|
public static final DebugRequestType stepOver = new DebugRequestType("stepOver", 11);
|
||||||
public static final DebugRequestType stepReturn = new DebugRequestType("stepReturn", 12);
|
public static final DebugRequestType stepReturn = new DebugRequestType("stepReturn", 12);
|
||||||
public static final DebugRequestType global = new DebugRequestType("global", 13);
|
|
||||||
|
|
||||||
protected static final DebugRequestType[] ENUMS = new DebugRequestType[] {
|
protected static final DebugRequestType[] ENUMS = new DebugRequestType[] {
|
||||||
start,
|
start,
|
||||||
@@ -56,8 +56,7 @@ public class DebugRequestType extends EnumType {
|
|||||||
stack,
|
stack,
|
||||||
stepInto,
|
stepInto,
|
||||||
stepOver,
|
stepOver,
|
||||||
stepReturn,
|
stepReturn
|
||||||
global
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public DebugRequestType(String name, int ordinal) {
|
public DebugRequestType(String name, int ordinal) {
|
||||||
@@ -19,9 +19,9 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import lua.debug.EnumType;
|
import org.luaj.debug.EnumType;
|
||||||
|
|
||||||
public class DebugRequestWatchpointToggle extends DebugRequest {
|
public class DebugRequestWatchpointToggle extends DebugRequest {
|
||||||
public static class AccessType extends EnumType {
|
public static class AccessType extends EnumType {
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.response;
|
package org.luaj.debug.response;
|
||||||
|
|
||||||
import lua.debug.Serializable;
|
import org.luaj.debug.Serializable;
|
||||||
|
|
||||||
public interface DebugResponse extends Serializable {}
|
public interface DebugResponse extends Serializable {}
|
||||||
@@ -19,13 +19,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.response;
|
package org.luaj.debug.response;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.StackFrame;
|
import org.luaj.debug.StackFrame;
|
||||||
|
|
||||||
|
|
||||||
public class DebugResponseCallgraph implements DebugResponse {
|
public class DebugResponseCallgraph implements DebugResponse {
|
||||||
protected StackFrame[] stackFrames;
|
protected StackFrame[] stackFrames;
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.response;
|
package org.luaj.debug.response;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@@ -19,21 +19,22 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.response;
|
package org.luaj.debug.response;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import lua.debug.SerializationHelper;
|
import org.luaj.debug.SerializationHelper;
|
||||||
import lua.debug.Variable;
|
import org.luaj.debug.Variable;
|
||||||
|
|
||||||
public class DebugResponseVariables implements DebugResponse {
|
|
||||||
|
public class DebugResponseStack implements DebugResponse {
|
||||||
protected Variable[] variables;
|
protected Variable[] variables;
|
||||||
|
|
||||||
public DebugResponseVariables(Variable[] variables) {
|
public DebugResponseStack(Variable[] variables) {
|
||||||
if (variables == null) {
|
if (variables == null) {
|
||||||
this.variables = new Variable[0];
|
this.variables = new Variable[0];
|
||||||
} else {
|
} else {
|
||||||
this.variables = variables;
|
this.variables = variables;
|
||||||
}
|
}
|
||||||
@@ -54,23 +55,21 @@ public class DebugResponseVariables implements DebugResponse {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serialize(DataOutputStream out,
|
public static void serialize(DataOutputStream out, DebugResponseStack response)
|
||||||
DebugResponseVariables response)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Variable[] variables = response.getVariables();
|
Variable[] variables = response.getVariables();
|
||||||
out.writeInt(variables == null ? 0 : variables.length);
|
out.writeInt(variables == null ? 0 : variables.length);
|
||||||
for (int i = 0; i < variables.length; i++) {
|
for (int i = 0; i < variables.length; i++) {
|
||||||
SerializationHelper.serialize(variables[i], out);
|
SerializationHelper.serialize(variables[i], out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugResponseVariables deserialize(DataInputStream in)
|
public static DebugResponseStack deserialize(DataInputStream in) throws IOException {
|
||||||
throws IOException {
|
int count = in.readInt();
|
||||||
int count = in.readInt();
|
Variable[] variables = new Variable[count];
|
||||||
Variable[] variables = new Variable[count];
|
for (int i = 0; i < count; i++) {
|
||||||
for (int i = 0; i < count; i++) {
|
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
||||||
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
}
|
||||||
}
|
return new DebugResponseStack(variables);
|
||||||
return new DebugResponseVariables(variables);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
package lua.addon.luajava;
|
package org.luaj.lib.j2se;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import lua.addon.luajava.LuaJava.LInstance;
|
import org.luaj.lib.j2se.LuajavaLib.LInstance;
|
||||||
import lua.value.LBoolean;
|
import org.luaj.vm.LBoolean;
|
||||||
import lua.value.LDouble;
|
import org.luaj.vm.LDouble;
|
||||||
import lua.value.LInteger;
|
import org.luaj.vm.LInteger;
|
||||||
import lua.value.LNil;
|
import org.luaj.vm.LNil;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LValue;
|
||||||
|
|
||||||
|
|
||||||
public class CoerceJavaToLua {
|
public class CoerceJavaToLua {
|
||||||
|
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
package lua.addon.luajava;
|
package org.luaj.lib.j2se;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import lua.value.LBoolean;
|
import org.luaj.vm.LBoolean;
|
||||||
import lua.value.LDouble;
|
import org.luaj.vm.LDouble;
|
||||||
import lua.value.LInteger;
|
import org.luaj.vm.LInteger;
|
||||||
import lua.value.LNil;
|
import org.luaj.vm.LNil;
|
||||||
import lua.value.LNumber;
|
import org.luaj.vm.LNumber;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LString;
|
||||||
import lua.value.LUserData;
|
import org.luaj.vm.LUserData;
|
||||||
import lua.value.LValue;
|
import org.luaj.vm.LValue;
|
||||||
|
|
||||||
|
|
||||||
public class CoerceLuaToJava {
|
public class CoerceLuaToJava {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.luajava;
|
package org.luaj.lib.j2se;
|
||||||
|
|
||||||
|
|
||||||
/** LuaJava-like bindings to Java scripting.
|
/** LuaJava-like bindings to Java scripting.
|
||||||
@@ -14,21 +14,20 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import lua.GlobalState;
|
import org.luaj.vm.LFunction;
|
||||||
import lua.VM;
|
import org.luaj.vm.LTable;
|
||||||
import lua.value.LFunction;
|
import org.luaj.vm.LUserData;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LValue;
|
||||||
import lua.value.LTable;
|
import org.luaj.vm.LuaState;
|
||||||
import lua.value.LUserData;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
public final class LuaJava extends LFunction {
|
|
||||||
|
|
||||||
public static void install() {
|
public final class LuajavaLib extends LFunction {
|
||||||
|
|
||||||
|
public static void install(LTable globals) {
|
||||||
LTable luajava = new LTable();
|
LTable luajava = new LTable();
|
||||||
for ( int i=0; i<NAMES.length; i++ )
|
for ( int i=0; i<NAMES.length; i++ )
|
||||||
luajava.put( NAMES[i], new LuaJava(i) );
|
luajava.put( NAMES[i], new LuajavaLib(i) );
|
||||||
GlobalState.getGlobalsTable().put( "luajava", luajava );
|
globals.put( "luajava", luajava );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int NEWINSTANCE = 0;
|
private static final int NEWINSTANCE = 0;
|
||||||
@@ -45,7 +44,7 @@ public final class LuaJava extends LFunction {
|
|||||||
"loadLib" };
|
"loadLib" };
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private LuaJava( int id ) {
|
private LuajavaLib( int id ) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +53,7 @@ public final class LuaJava extends LFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform a lua call
|
// perform a lua call
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
String className;
|
String className;
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
case BINDCLASS:
|
case BINDCLASS:
|
||||||
@@ -97,7 +96,7 @@ public final class LuaJava extends LFunction {
|
|||||||
public final LValue[] values;
|
public final LValue[] values;
|
||||||
public final Class[] classes;
|
public final Class[] classes;
|
||||||
public int hash;
|
public int hash;
|
||||||
ParamsList( VM vm ) {
|
ParamsList( LuaState vm ) {
|
||||||
int n = vm.gettop()-2;
|
int n = vm.gettop()-2;
|
||||||
values = new LValue[n];
|
values = new LValue[n];
|
||||||
classes = new Class[n];
|
classes = new Class[n];
|
||||||
@@ -123,7 +122,7 @@ public final class LuaJava extends LFunction {
|
|||||||
super(o);
|
super(o);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
}
|
}
|
||||||
public void luaGetTable(VM vm, LValue table, LValue key) {
|
public void luaGetTable(LuaState vm, LValue table, LValue key) {
|
||||||
final String s = key.toJavaString();
|
final String s = key.toJavaString();
|
||||||
try {
|
try {
|
||||||
Field f = clazz.getField(s);
|
Field f = clazz.getField(s);
|
||||||
@@ -136,7 +135,7 @@ public final class LuaJava extends LFunction {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
|
public void luaSetTable(LuaState vm, LValue table, LValue key, LValue val) {
|
||||||
Class c = m_instance.getClass();
|
Class c = m_instance.getClass();
|
||||||
String s = key.toJavaString();
|
String s = key.toJavaString();
|
||||||
try {
|
try {
|
||||||
@@ -149,7 +148,7 @@ public final class LuaJava extends LFunction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return super.luaStackCall(vm);
|
return super.luaStackCall(vm);
|
||||||
}
|
}
|
||||||
@@ -168,7 +167,7 @@ public final class LuaJava extends LFunction {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return clazz.getName()+"."+s+"()";
|
return clazz.getName()+"."+s+"()";
|
||||||
}
|
}
|
||||||
public boolean luaStackCall(VM vm) {
|
public boolean luaStackCall(LuaState vm) {
|
||||||
try {
|
try {
|
||||||
// find the method
|
// find the method
|
||||||
ParamsList params = new ParamsList( vm );
|
ParamsList params = new ParamsList( vm );
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package lua;
|
|
||||||
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
import lua.value.LTable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
** `global state', shared by all threads of this state
|
|
||||||
*/
|
|
||||||
public class GlobalState {
|
|
||||||
|
|
||||||
// typedef struct global_State {
|
|
||||||
Hashtable strt; /* hash table for strings */
|
|
||||||
StringBuffer buff; /* temporary buffer for string concatentation */
|
|
||||||
// lu_mem totalbytes; /* number of bytes currently allocated */
|
|
||||||
// lu_mem estimate; /* an estimate of number of bytes actually in use */
|
|
||||||
// lua_CFunction panic; /* to be called in unprotected errors */
|
|
||||||
// TValue l_registry;
|
|
||||||
// struct lua_State *mainthread;
|
|
||||||
StackState mainthread;
|
|
||||||
// UpVal uvhead; /* head of double-linked list of all open upvalues */
|
|
||||||
// struct Table *mt[NUM_TAGS]; /* metatables for basic types */
|
|
||||||
// TString *tmname[TM_N]; /* array with tag-method names */
|
|
||||||
// } global_State;
|
|
||||||
//
|
|
||||||
private static LTable _G;
|
|
||||||
|
|
||||||
static {
|
|
||||||
resetGlobals();
|
|
||||||
}
|
|
||||||
|
|
||||||
static public void resetGlobals() {
|
|
||||||
_G = new LTable();
|
|
||||||
_G .put( "_G", _G );
|
|
||||||
Builtin.addBuiltins( _G );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LTable getGlobalsTable() {
|
|
||||||
return _G;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
package lua;
|
|
||||||
|
|
||||||
import lua.value.LFunction;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Type for Java functions.
|
|
||||||
|
|
||||||
|
|
||||||
<p>
|
|
||||||
In order to communicate properly with Lua,
|
|
||||||
a Java function must use the following protocol,
|
|
||||||
which defines the way parameters and results are passed:
|
|
||||||
a Java function receives its arguments from Lua in its stack
|
|
||||||
in direct order (the first argument is pushed first).
|
|
||||||
So, when the function starts,
|
|
||||||
<code>lua_gettop(L)</code> returns the number of arguments received by the function.
|
|
||||||
The first argument (if any) is at index 1
|
|
||||||
and its last argument is at index <code>lua_gettop(L)</code>.
|
|
||||||
To return values to Lua, a Java function just pushes them onto the stack,
|
|
||||||
in direct order (the first result is pushed first),
|
|
||||||
and returns the number of results.
|
|
||||||
Any other value in the stack below the results will be properly
|
|
||||||
discarded by Lua.
|
|
||||||
Like a Lua function, a Java function called by Lua can also return
|
|
||||||
many results.
|
|
||||||
|
|
||||||
|
|
||||||
<p>
|
|
||||||
As an example, the following function receives a variable number
|
|
||||||
of numerical arguments and returns their average and sum:
|
|
||||||
|
|
||||||
<pre><code>
|
|
||||||
int foo (VM lua) {
|
|
||||||
int n = lua.gettop(); // number of arguments
|
|
||||||
double sum = 0;
|
|
||||||
int i;
|
|
||||||
for (i = 1; i <= n; i++) {
|
|
||||||
if (!lua.isnumber(L, i)) {
|
|
||||||
lua.pushstring(L, "incorrect argument");
|
|
||||||
lua.error(L);
|
|
||||||
}
|
|
||||||
sum += lua.tonumber(L, i);
|
|
||||||
}
|
|
||||||
lua.pushnumber(L, sum/n); // first result
|
|
||||||
lua.pushnumber(L, sum); // second result
|
|
||||||
return 2; // number of results
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
*/
|
|
||||||
|
|
||||||
abstract public class JavaFunction extends LFunction {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called to invoke a JavaFunction.
|
|
||||||
*
|
|
||||||
* The implementation should manipulate the stack
|
|
||||||
* via the VM Java API in the same way that lua_CFunctions
|
|
||||||
* do so in standard lua.
|
|
||||||
*
|
|
||||||
* @param lua the LuaState calling this function.
|
|
||||||
* @return number of results pushed onto the stack.
|
|
||||||
*/
|
|
||||||
abstract public int invoke( VM lua );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up a Java invocation, and fix up the results
|
|
||||||
* when it returns.
|
|
||||||
*/
|
|
||||||
public boolean luaStackCall(VM vm) {
|
|
||||||
vm.invokeJavaFunction( this );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,179 +0,0 @@
|
|||||||
package lua.debug;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import lua.debug.event.DebugEvent;
|
|
||||||
import lua.debug.event.DebugEventBreakpoint;
|
|
||||||
import lua.debug.event.DebugEventError;
|
|
||||||
import lua.debug.event.DebugEventType;
|
|
||||||
import lua.debug.request.DebugRequest;
|
|
||||||
import lua.debug.request.DebugRequestLineBreakpointToggle;
|
|
||||||
import lua.debug.request.DebugRequestStack;
|
|
||||||
import lua.debug.request.DebugRequestType;
|
|
||||||
import lua.debug.response.DebugResponseCallgraph;
|
|
||||||
import lua.debug.response.DebugResponseSimple;
|
|
||||||
import lua.debug.response.DebugResponseVariables;
|
|
||||||
|
|
||||||
public class SerializationHelper {
|
|
||||||
|
|
||||||
public static byte[] serialize(Serializable object) throws IOException {
|
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
||||||
DataOutputStream dout = new DataOutputStream(bout);
|
|
||||||
|
|
||||||
serialize(object, dout);
|
|
||||||
|
|
||||||
byte[] data = bout.toByteArray();
|
|
||||||
|
|
||||||
bout.close();
|
|
||||||
dout.close();
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Serializable deserialize(byte[] data) throws IOException {
|
|
||||||
ByteArrayInputStream bin = new ByteArrayInputStream(data);
|
|
||||||
DataInputStream din = new DataInputStream(bin);
|
|
||||||
|
|
||||||
Serializable object = deserialize(din);
|
|
||||||
|
|
||||||
bin.close();
|
|
||||||
din.close();
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final int SERIAL_TYPE_NullableString = 0;
|
|
||||||
static final int SERIAL_TYPE_TableVariable = 1;
|
|
||||||
static final int SERIAL_TYPE_Variable = 2;
|
|
||||||
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
|
||||||
static final int SERIAL_TYPE_DebugResponseVariables = 4;
|
|
||||||
static final int SERIAL_TYPE_DebugResponseSimple = 5;
|
|
||||||
static final int SERIAL_TYPE_StackFrame = 6;
|
|
||||||
static final int SERIAL_TYPE_DebugRequestType = 7;
|
|
||||||
static final int SERIAL_TYPE_DebugRequest = 8;
|
|
||||||
static final int SERIAL_TYPE_DebugRequestStack = 9;
|
|
||||||
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 10;
|
|
||||||
static final int SERIAL_TYPE_DebugEventType = 11;
|
|
||||||
static final int SERIAL_TYPE_DebugEvent = 12;
|
|
||||||
static final int SERIAL_TYPE_DebugEventBreakpoint = 13;
|
|
||||||
static final int SERIAL_TYPE_DebugEventError = 14;
|
|
||||||
|
|
||||||
public static void serialize(Serializable object, DataOutputStream dout)
|
|
||||||
throws IOException {
|
|
||||||
if (object instanceof NullableString) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_NullableString);
|
|
||||||
NullableString.serialize(dout, (NullableString) object);
|
|
||||||
} else if (object instanceof TableVariable) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_TableVariable);
|
|
||||||
TableVariable.serialize(dout, (TableVariable) object);
|
|
||||||
} else if (object instanceof Variable) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_Variable);
|
|
||||||
Variable.serialize(dout, (Variable) object);
|
|
||||||
} else if (object instanceof StackFrame) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_StackFrame);
|
|
||||||
StackFrame.serialize(dout, (StackFrame) object);
|
|
||||||
} else if (object instanceof DebugResponseSimple) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseSimple);
|
|
||||||
DebugResponseSimple.serialize(dout, (DebugResponseSimple) object);
|
|
||||||
} else if (object instanceof DebugResponseVariables) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseVariables);
|
|
||||||
DebugResponseVariables.serialize(dout, (DebugResponseVariables) object);
|
|
||||||
} else if (object instanceof DebugResponseCallgraph) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph);
|
|
||||||
DebugResponseCallgraph.serialize(dout,
|
|
||||||
(DebugResponseCallgraph) object);
|
|
||||||
} else if (object instanceof DebugRequestType) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequestType);
|
|
||||||
DebugRequestType.serialize(dout, (DebugRequestType) object);
|
|
||||||
} else if (object instanceof DebugRequestStack) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequestStack);
|
|
||||||
DebugRequestStack.serialize(dout, (DebugRequestStack) object);
|
|
||||||
} else if (object instanceof DebugRequestLineBreakpointToggle) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle);
|
|
||||||
DebugRequestLineBreakpointToggle.serialize(dout,
|
|
||||||
(DebugRequestLineBreakpointToggle) object);
|
|
||||||
} else if (object instanceof DebugRequest) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequest);
|
|
||||||
DebugRequest.serialize(dout, (DebugRequest) object);
|
|
||||||
} else if (object instanceof DebugEventType) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugEventType);
|
|
||||||
DebugEventType.serialize(dout, (DebugEventType) object);
|
|
||||||
} else if (object instanceof DebugEventBreakpoint) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint);
|
|
||||||
DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint) object);
|
|
||||||
} else if (object instanceof DebugEventError) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugEventError);
|
|
||||||
DebugEventError.serialize(dout, (DebugEventError) object);
|
|
||||||
} else if (object instanceof DebugEvent) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugEvent);
|
|
||||||
DebugEvent.serialize(dout, (DebugEvent) object);
|
|
||||||
} else {
|
|
||||||
// catch the errors: forgot to implement
|
|
||||||
// serialization/deserialization
|
|
||||||
throw new RuntimeException(
|
|
||||||
"serialization operation is not supported");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Serializable deserialize(DataInputStream din)
|
|
||||||
throws IOException {
|
|
||||||
Serializable object = null;
|
|
||||||
int type = din.readInt();
|
|
||||||
switch (type) {
|
|
||||||
case SERIAL_TYPE_NullableString:
|
|
||||||
object = NullableString.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_TableVariable:
|
|
||||||
object = TableVariable.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_Variable:
|
|
||||||
object = Variable.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_StackFrame:
|
|
||||||
object = StackFrame.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugResponseSimple:
|
|
||||||
object = DebugResponseSimple.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugResponseCallgraph:
|
|
||||||
object = DebugResponseCallgraph.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugResponseVariables:
|
|
||||||
object = DebugResponseVariables.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugRequestType:
|
|
||||||
object = DebugRequestType.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugRequestStack:
|
|
||||||
object = DebugRequestStack.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugRequestLineBreakpointToggle:
|
|
||||||
object = DebugRequestLineBreakpointToggle.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugRequest:
|
|
||||||
object = DebugRequest.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugEventType:
|
|
||||||
object = DebugEventType.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugEventBreakpoint:
|
|
||||||
object = DebugEventBreakpoint.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugEventError:
|
|
||||||
object = DebugEventError.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugEvent:
|
|
||||||
object = DebugEvent.deserialize(din);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new RuntimeException(
|
|
||||||
"deserialization operation is not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package lua.value;
|
|
||||||
|
|
||||||
import lua.Lua;
|
|
||||||
import lua.VM;
|
|
||||||
|
|
||||||
|
|
||||||
public class LFunction extends LValue {
|
|
||||||
|
|
||||||
public String toJavaString() {
|
|
||||||
return "function: "+hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void luaSetTable(VM vm, LValue table, LValue key, LValue val) {
|
|
||||||
vm.pushlvalue( this );
|
|
||||||
vm.pushlvalue( table );
|
|
||||||
vm.pushlvalue( key );
|
|
||||||
vm.pushlvalue( val );
|
|
||||||
vm.call( 3, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void luaGetTable(VM vm, LValue table, LValue key) {
|
|
||||||
vm.pushlvalue( this );
|
|
||||||
vm.pushlvalue( table );
|
|
||||||
vm.pushlvalue( key );
|
|
||||||
vm.call( 2, 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int luaGetType() {
|
|
||||||
return Lua.LUA_TFUNCTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
45
src/sample/org/luaj/sample/LuaRunner.java
Normal file
45
src/sample/org/luaj/sample/LuaRunner.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package org.luaj.sample;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.luaj.lib.MathLib;
|
||||||
|
import org.luaj.lib.j2se.LuajavaLib;
|
||||||
|
import org.luaj.vm.LClosure;
|
||||||
|
import org.luaj.vm.LPrototype;
|
||||||
|
import org.luaj.vm.LValue;
|
||||||
|
import org.luaj.vm.LoadState;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Program to run a lua chunk
|
||||||
|
*
|
||||||
|
* @author jim_roseborough
|
||||||
|
*/
|
||||||
|
public class LuaRunner {
|
||||||
|
|
||||||
|
public static void main( String[] args ) throws IOException {
|
||||||
|
|
||||||
|
// new lua state
|
||||||
|
LuaState state = new LuaState();
|
||||||
|
|
||||||
|
// get script name
|
||||||
|
String script = (args.length>0? args[0]: "/test2.luac");
|
||||||
|
System.out.println("loading '"+script+"'");
|
||||||
|
|
||||||
|
// add LuaCompat bindings
|
||||||
|
MathLib.install(state._G);
|
||||||
|
LuajavaLib.install(state._G);
|
||||||
|
|
||||||
|
// load the file
|
||||||
|
InputStream is = LuaRunner.class.getResourceAsStream( script );
|
||||||
|
LPrototype p = LoadState.undump(state, is, script);
|
||||||
|
|
||||||
|
// create closure and execute
|
||||||
|
LClosure c = new LClosure( p, state._G );
|
||||||
|
|
||||||
|
// do the call
|
||||||
|
state.doCall( c, new LValue[0] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
|
package org.luaj.sample;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import lua.StackState;
|
import org.luaj.lib.MathLib;
|
||||||
import lua.addon.luacompat.LuaCompat;
|
import org.luaj.lib.j2se.LuajavaLib;
|
||||||
import lua.addon.luajava.LuaJava;
|
import org.luaj.vm.LClosure;
|
||||||
import lua.io.Closure;
|
import org.luaj.vm.LPrototype;
|
||||||
import lua.io.LoadState;
|
import org.luaj.vm.LValue;
|
||||||
import lua.io.Proto;
|
import org.luaj.vm.LoadState;
|
||||||
import lua.value.LString;
|
import org.luaj.vm.LuaState;
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program to run a compiled lua chunk for test purposes,
|
* Program to run a compiled lua chunk for test purposes,
|
||||||
@@ -17,29 +18,29 @@ import lua.value.LValue;
|
|||||||
*
|
*
|
||||||
* @author jim_roseborough
|
* @author jim_roseborough
|
||||||
*/
|
*/
|
||||||
public class LuaJavaAppRunner {
|
public class LuajavaRunner {
|
||||||
|
|
||||||
public static void main( String[] args ) throws IOException {
|
public static void main( String[] args ) throws IOException {
|
||||||
|
|
||||||
|
// new lua state
|
||||||
|
LuaState state = new LuaState();
|
||||||
|
|
||||||
// add LuaCompat bindings
|
// add LuaCompat bindings
|
||||||
LuaCompat.install();
|
MathLib.install(state._G);
|
||||||
|
|
||||||
// add LuaJava bindings
|
// add LuaJava bindings
|
||||||
LuaJava.install();
|
LuajavaLib.install(state._G);
|
||||||
|
|
||||||
// get script name
|
// get script name
|
||||||
String script = (args.length>0? args[0]: "/swingapp.luac");
|
String script = (args.length>0? args[0]: "/swingapp.luac");
|
||||||
System.out.println("loading '"+script+"'");
|
System.out.println("loading '"+script+"'");
|
||||||
|
|
||||||
// new lua state
|
|
||||||
StackState state = new StackState();
|
|
||||||
|
|
||||||
// load the file
|
// load the file
|
||||||
InputStream is = LuaJavaAppRunner.class.getResourceAsStream( script );
|
InputStream is = LuajavaRunner.class.getResourceAsStream( script );
|
||||||
Proto p = LoadState.undump(state, is, script);
|
LPrototype p = LoadState.undump(state, is, script);
|
||||||
|
|
||||||
// create closure and execute
|
// create closure and execute
|
||||||
Closure c = new Closure( state, p );
|
LClosure c = new LClosure( p, state._G );
|
||||||
state.doCall(c, new LValue[0]);
|
state.doCall(c, new LValue[0]);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.luaj.sample;
|
||||||
|
|
||||||
public class SampleClass {
|
public class SampleClass {
|
||||||
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import lua.StackState;
|
|
||||||
import lua.VM;
|
|
||||||
import lua.addon.luacompat.LuaCompat;
|
|
||||||
import lua.addon.luajava.LuaJava;
|
|
||||||
import lua.debug.DebugStackState;
|
|
||||||
import lua.io.Closure;
|
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Program to run a compiled lua chunk for test purposes
|
|
||||||
*
|
|
||||||
* @author jim_roseborough
|
|
||||||
*/
|
|
||||||
public class LuacRunner {
|
|
||||||
|
|
||||||
public static void main( String[] args ) throws IOException {
|
|
||||||
|
|
||||||
// get script name
|
|
||||||
String script = (args.length>0? args[0]: "/test2.luac");
|
|
||||||
System.out.println("loading '"+script+"'");
|
|
||||||
|
|
||||||
// add LuaCompat bindings
|
|
||||||
LuaCompat.install();
|
|
||||||
LuaJava.install();
|
|
||||||
|
|
||||||
// new lua state
|
|
||||||
StackState state = new StackState();
|
|
||||||
VM vm = state;
|
|
||||||
|
|
||||||
// load the file
|
|
||||||
InputStream is = LuacRunner.class.getResourceAsStream( script );
|
|
||||||
Proto p = LoadState.undump(state, is, script);
|
|
||||||
|
|
||||||
// create closure and execute
|
|
||||||
Closure c = new Closure( state, p );
|
|
||||||
|
|
||||||
// do the call
|
|
||||||
vm.doCall( c, new LValue[0] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
42
src/test/java/org/luaj/AllTests.java
Normal file
42
src/test/java/org/luaj/AllTests.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package org.luaj;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
public class AllTests {
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
TestSuite suite = new TestSuite("Test for org.luaj");
|
||||||
|
|
||||||
|
// compiler tests
|
||||||
|
TestSuite compiler = new TestSuite("Compiler");
|
||||||
|
compiler.addTestSuite(org.luaj.compiler.SimpleTests.class);
|
||||||
|
compiler.addTestSuite(org.luaj.compiler.RegressionTests.class);
|
||||||
|
compiler.addTestSuite(org.luaj.compiler.CompilerUnitTests.class);
|
||||||
|
suite.addTest(compiler);
|
||||||
|
|
||||||
|
// debug tests
|
||||||
|
TestSuite debug = new TestSuite("Debug");
|
||||||
|
debug.addTestSuite(org.luaj.debug.DebugEventTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.DebugRequestTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.DebugResponseTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.DebugStackStateTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.EnumTypeTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.StackFrameTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.TableVariableTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.VariableTest.class);
|
||||||
|
debug.addTestSuite(org.luaj.debug.j2se.LuaJVMTest.class);
|
||||||
|
suite.addTest(debug);
|
||||||
|
|
||||||
|
// debug tests
|
||||||
|
TestSuite vm = new TestSuite("VM");
|
||||||
|
vm.addTestSuite(org.luaj.vm.LoadStateTest.class);
|
||||||
|
vm.addTestSuite(org.luaj.vm.LStringTest.class);
|
||||||
|
vm.addTestSuite(org.luaj.vm.LTableTest.class);
|
||||||
|
vm.addTestSuite(org.luaj.vm.LuaJTest.class);
|
||||||
|
suite.addTest(vm);
|
||||||
|
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -9,14 +9,15 @@ import java.io.PrintStream;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.luaj.compiler.Compiler;
|
||||||
|
import org.luaj.compiler.DumpState;
|
||||||
|
import org.luaj.debug.Print;
|
||||||
|
import org.luaj.vm.LoadState;
|
||||||
|
import org.luaj.vm.LPrototype;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import lua.Print;
|
|
||||||
import lua.StackState;
|
|
||||||
import lua.addon.compile.Compiler;
|
|
||||||
import lua.addon.compile.DumpState;
|
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.io.Proto;
|
|
||||||
|
|
||||||
abstract
|
abstract
|
||||||
public class AbstractUnitTests extends TestCase {
|
public class AbstractUnitTests extends TestCase {
|
||||||
@@ -37,12 +38,12 @@ public class AbstractUnitTests extends TestCase {
|
|||||||
|
|
||||||
// compile in memory
|
// compile in memory
|
||||||
InputStream is = new ByteArrayInputStream( lua );
|
InputStream is = new ByteArrayInputStream( lua );
|
||||||
Proto p = Compiler.compile(is, dir+"/"+file);
|
LPrototype p = Compiler.compile(is, dir+"/"+file);
|
||||||
String actual = protoToString( p );
|
String actual = protoToString( p );
|
||||||
|
|
||||||
// load expected value from jar
|
// load expected value from jar
|
||||||
byte[] luac = bytesFromJar( path + "c" );
|
byte[] luac = bytesFromJar( path + "c" );
|
||||||
Proto e = loadFromBytes( luac, file );
|
LPrototype e = loadFromBytes( luac, file );
|
||||||
String expected = protoToString( e );
|
String expected = protoToString( e );
|
||||||
|
|
||||||
// compare results
|
// compare results
|
||||||
@@ -54,7 +55,7 @@ public class AbstractUnitTests extends TestCase {
|
|||||||
byte[] dumped = baos.toByteArray();
|
byte[] dumped = baos.toByteArray();
|
||||||
|
|
||||||
// re-undump
|
// re-undump
|
||||||
Proto p2 = loadFromBytes( dumped, file );
|
LPrototype p2 = loadFromBytes( dumped, file );
|
||||||
String actual2 = protoToString( p2 );
|
String actual2 = protoToString( p2 );
|
||||||
|
|
||||||
// compare again
|
// compare again
|
||||||
@@ -77,13 +78,13 @@ public class AbstractUnitTests extends TestCase {
|
|||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Proto loadFromBytes(byte[] bytes, String script) throws IOException {
|
protected LPrototype loadFromBytes(byte[] bytes, String script) throws IOException {
|
||||||
StackState state = new StackState();
|
LuaState state = new LuaState();
|
||||||
InputStream is = new ByteArrayInputStream( bytes );
|
InputStream is = new ByteArrayInputStream( bytes );
|
||||||
return LoadState.undump(state, is, script);
|
return LoadState.undump(state, is, script);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String protoToString(Proto p) {
|
protected String protoToString(LPrototype p) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintStream ps = new PrintStream( baos );
|
PrintStream ps = new PrintStream( baos );
|
||||||
Print.ps = ps;
|
Print.ps = ps;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
|
|
||||||
public class CompilerUnitTests extends AbstractUnitTests {
|
public class CompilerUnitTests extends AbstractUnitTests {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Framework to add regression tests as problem areas are found.
|
* Framework to add regression tests as problem areas are found.
|
||||||
@@ -1,28 +1,30 @@
|
|||||||
package lua.addon.compile;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.luaj.compiler.Compiler;
|
||||||
|
import org.luaj.debug.Print;
|
||||||
|
import org.luaj.vm.LClosure;
|
||||||
|
import org.luaj.vm.LValue;
|
||||||
|
import org.luaj.vm.LPrototype;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.Print;
|
|
||||||
import lua.StackState;
|
|
||||||
import lua.io.Closure;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
public class SimpleTests extends TestCase {
|
public class SimpleTests extends TestCase {
|
||||||
|
|
||||||
private void doTest( String script ) {
|
private void doTest( String script ) {
|
||||||
try {
|
try {
|
||||||
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
|
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
|
||||||
Proto p = Compiler.compile( is, "script" );
|
LPrototype p = Compiler.compile( is, "script" );
|
||||||
assertNotNull( p );
|
assertNotNull( p );
|
||||||
Print.printCode( p );
|
Print.printCode( p );
|
||||||
|
|
||||||
// try running the code!
|
// try running the code!
|
||||||
StackState state = new StackState();
|
LuaState state = new LuaState();
|
||||||
Closure c = new Closure( state, p );
|
LClosure c = new LClosure( state, p );
|
||||||
state.doCall( c, new LValue[0] );
|
state.doCall( c, new LValue[0] );
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
fail("i/o exception: "+e );
|
fail("i/o exception: "+e );
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
import org.luaj.debug.event.DebugEventBreakpoint;
|
||||||
|
import org.luaj.debug.event.DebugEventType;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.debug.event.DebugEvent;
|
|
||||||
import lua.debug.event.DebugEventBreakpoint;
|
|
||||||
import lua.debug.event.DebugEventType;
|
|
||||||
|
|
||||||
public class DebugEventTest extends TestCase {
|
public class DebugEventTest extends TestCase {
|
||||||
public void testDebugEventSerialization() {
|
public void testDebugEventSerialization() {
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.request.DebugRequest;
|
||||||
|
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
||||||
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
|
import org.luaj.debug.request.DebugRequestType;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.debug.request.DebugRequest;
|
|
||||||
import lua.debug.request.DebugRequestLineBreakpointToggle;
|
|
||||||
import lua.debug.request.DebugRequestStack;
|
|
||||||
import lua.debug.request.DebugRequestType;
|
|
||||||
|
|
||||||
public class DebugRequestTest extends TestCase {
|
public class DebugRequestTest extends TestCase {
|
||||||
public void testDebugRequestSerialization() {
|
public void testDebugRequestSerialization() {
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.StackFrame;
|
||||||
|
import org.luaj.debug.TableVariable;
|
||||||
|
import org.luaj.debug.Variable;
|
||||||
|
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||||
|
import org.luaj.debug.response.DebugResponseSimple;
|
||||||
|
import org.luaj.debug.response.DebugResponseStack;
|
||||||
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.Lua;
|
|
||||||
import lua.debug.response.DebugResponseCallgraph;
|
|
||||||
import lua.debug.response.DebugResponseSimple;
|
|
||||||
import lua.debug.response.DebugResponseVariables;
|
|
||||||
|
|
||||||
public class DebugResponseTest extends TestCase {
|
public class DebugResponseTest extends TestCase {
|
||||||
public void testDebugResponseSimpleSerialization() {
|
public void testDebugResponseSimpleSerialization() {
|
||||||
@@ -46,10 +51,10 @@ public class DebugResponseTest extends TestCase {
|
|||||||
|
|
||||||
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
|
DebugResponseStack stackIn = new DebugResponseStack(variables);
|
||||||
byte[] data = SerializationHelper.serialize(stackIn);
|
byte[] data = SerializationHelper.serialize(stackIn);
|
||||||
DebugResponseVariables stackOut
|
DebugResponseStack stackOut
|
||||||
= (DebugResponseVariables) SerializationHelper.deserialize(data);
|
= (DebugResponseStack) SerializationHelper.deserialize(data);
|
||||||
Variable[] variablesIn = stackIn.getVariables();
|
Variable[] variablesIn = stackIn.getVariables();
|
||||||
Variable[] variablesOut = stackOut.getVariables();
|
Variable[] variablesOut = stackOut.getVariables();
|
||||||
assertNotNull(variablesIn);
|
assertNotNull(variablesIn);
|
||||||
@@ -19,16 +19,18 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.luaj.debug.DebugStackState;
|
||||||
|
import org.luaj.vm.LClosure;
|
||||||
|
import org.luaj.vm.LValue;
|
||||||
|
import org.luaj.vm.LoadState;
|
||||||
|
import org.luaj.vm.LPrototype;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.io.Closure;
|
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
public class DebugStackStateTest extends TestCase {
|
public class DebugStackStateTest extends TestCase {
|
||||||
|
|
||||||
@@ -38,10 +40,10 @@ public class DebugStackStateTest extends TestCase {
|
|||||||
// set up the vm
|
// set up the vm
|
||||||
final DebugStackState state = new DebugStackState();
|
final DebugStackState state = new DebugStackState();
|
||||||
InputStream is = getClass().getResourceAsStream( script );
|
InputStream is = getClass().getResourceAsStream( script );
|
||||||
Proto p = LoadState.undump(state, is, script);
|
LPrototype p = LoadState.undump(state, is, script);
|
||||||
|
|
||||||
// create closure and execute
|
// create closure and execute
|
||||||
final Closure c = new Closure( state, p );
|
final LClosure c = new LClosure( state, p );
|
||||||
|
|
||||||
// suspend the vm right away
|
// suspend the vm right away
|
||||||
state.suspend();
|
state.suspend();
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.event.DebugEventType;
|
||||||
|
import org.luaj.debug.request.DebugRequestType;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.debug.event.DebugEventType;
|
|
||||||
import lua.debug.request.DebugRequestType;
|
|
||||||
|
|
||||||
public class EnumTypeTest extends TestCase {
|
public class EnumTypeTest extends TestCase {
|
||||||
public void testDebugRequestTypeSerialization() {
|
public void testDebugRequestTypeSerialization() {
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.StackFrame;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class StackFrameTest extends TestCase {
|
public class StackFrameTest extends TestCase {
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.TableVariable;
|
||||||
|
import org.luaj.vm.LBoolean;
|
||||||
|
import org.luaj.vm.LDouble;
|
||||||
|
import org.luaj.vm.LInteger;
|
||||||
|
import org.luaj.vm.LNil;
|
||||||
|
import org.luaj.vm.LString;
|
||||||
|
import org.luaj.vm.LTable;
|
||||||
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.Lua;
|
|
||||||
import lua.value.LBoolean;
|
|
||||||
import lua.value.LDouble;
|
|
||||||
import lua.value.LInteger;
|
|
||||||
import lua.value.LNil;
|
|
||||||
import lua.value.LString;
|
|
||||||
import lua.value.LTable;
|
|
||||||
|
|
||||||
public class TableVariableTest extends TestCase {
|
public class TableVariableTest extends TestCase {
|
||||||
public void testCreate() {
|
public void testCreate() {
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package lua.debug;
|
package org.luaj.debug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.luaj.debug.SerializationHelper;
|
||||||
|
import org.luaj.debug.Variable;
|
||||||
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.Lua;
|
|
||||||
|
|
||||||
public class VariableTest extends TestCase {
|
public class VariableTest extends TestCase {
|
||||||
public void testSerialization() {
|
public void testSerialization() {
|
||||||
@@ -19,14 +19,15 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug.j2se;
|
package org.luaj.debug.j2se;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.luaj.debug.j2se.StandardLuaJVM;
|
||||||
|
import org.luaj.debug.j2se.StandardLuaJVM.ParseException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.debug.j2se.StandardLuaJVM;
|
|
||||||
import lua.debug.j2se.StandardLuaJVM.ParseException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanity test for StandardLuaJVM.
|
* Sanity test for StandardLuaJVM.
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.luaj.vm.LString;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class LStringTest extends TestCase {
|
public class LStringTest extends TestCase {
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
package lua.value;
|
package org.luaj.vm;
|
||||||
|
|
||||||
|
import org.luaj.vm.LDouble;
|
||||||
|
import org.luaj.vm.LInteger;
|
||||||
|
import org.luaj.vm.LNil;
|
||||||
|
import org.luaj.vm.LString;
|
||||||
|
import org.luaj.vm.LTable;
|
||||||
|
import org.luaj.vm.LValue;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package lua.io;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.luaj.vm.LDouble;
|
||||||
|
import org.luaj.vm.LInteger;
|
||||||
|
import org.luaj.vm.LNumber;
|
||||||
|
import org.luaj.vm.LoadState;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.value.LDouble;
|
|
||||||
import lua.value.LInteger;
|
|
||||||
import lua.value.LNumber;
|
|
||||||
|
|
||||||
public class LoadStateTest extends TestCase {
|
public class LoadStateTest extends TestCase {
|
||||||
double[] DOUBLE_VALUES = {
|
double[] DOUBLE_VALUES = {
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
package lua;
|
package org.luaj.vm;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import lua.addon.luacompat.LuaCompat;
|
|
||||||
import lua.addon.luajava.LuaJava;
|
import org.luaj.debug.DebugStackState;
|
||||||
import lua.debug.DebugStackState;
|
import org.luaj.lib.MathLib;
|
||||||
import lua.io.Closure;
|
import org.luaj.lib.j2se.LuajavaLib;
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
|
|
||||||
public class LuaJTest extends TestCase {
|
public class LuaJTest extends TestCase {
|
||||||
@@ -114,27 +111,24 @@ public class LuaJTest extends TestCase {
|
|||||||
|
|
||||||
private void runTest( String testName ) throws IOException, InterruptedException {
|
private void runTest( String testName ) throws IOException, InterruptedException {
|
||||||
|
|
||||||
// Reset the _G table just in case some test mucks with it
|
// new lua state
|
||||||
GlobalState.resetGlobals();
|
LuaState state = new DebugStackState();
|
||||||
|
|
||||||
// add LuaJava bindings
|
// add LuaJava bindings
|
||||||
LuaJava.install();
|
LuajavaLib.install(state._G);
|
||||||
|
|
||||||
// add LuaCompat bindings
|
// add LuaCompat bindings
|
||||||
LuaCompat.install();
|
MathLib.install(state._G);
|
||||||
|
|
||||||
// new lua state
|
|
||||||
StackState state = new StackState();
|
|
||||||
|
|
||||||
// load the file
|
// load the file
|
||||||
Proto p = loadScriptResource( state, testName );
|
LPrototype p = loadScriptResource( state, testName );
|
||||||
|
|
||||||
// Replace System.out with a ByteArrayOutputStream
|
// Replace System.out with a ByteArrayOutputStream
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
Builtin.redirectOutput( outputStream );
|
BaseLib.redirectOutput( outputStream );
|
||||||
try {
|
try {
|
||||||
// create closure and execute
|
// create closure and execute
|
||||||
Closure c = new Closure( state, p );
|
LClosure c = new LClosure( p, state._G );
|
||||||
state.doCall(c, new LValue[0]);
|
state.doCall(c, new LValue[0]);
|
||||||
|
|
||||||
final String actualOutput = new String( outputStream.toByteArray() );
|
final String actualOutput = new String( outputStream.toByteArray() );
|
||||||
@@ -142,12 +136,12 @@ public class LuaJTest extends TestCase {
|
|||||||
|
|
||||||
assertEquals( expectedOutput, actualOutput );
|
assertEquals( expectedOutput, actualOutput );
|
||||||
} finally {
|
} finally {
|
||||||
Builtin.restoreStandardOutput();
|
BaseLib.restoreStandardOutput();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Proto loadScriptResource( StackState state, String name ) throws IOException {
|
private LPrototype loadScriptResource( LuaState state, String name ) throws IOException {
|
||||||
InputStream script = getClass().getResourceAsStream( "/"+name+".luac" );
|
InputStream script = getClass().getResourceAsStream( "/"+name+".luac" );
|
||||||
if ( script == null ) {
|
if ( script == null ) {
|
||||||
script = getClass().getResourceAsStream( "/"+name+".lua" );
|
script = getClass().getResourceAsStream( "/"+name+".lua" );
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package lua;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -12,16 +12,9 @@ import java.util.zip.ZipInputStream;
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import lua.Builtin;
|
|
||||||
import lua.StackState;
|
import org.luaj.debug.DebugStackState;
|
||||||
import lua.addon.luacompat.LuaCompat;
|
import org.luaj.lib.MathLib;
|
||||||
import lua.debug.DebugStackState;
|
|
||||||
import lua.io.Closure;
|
|
||||||
import lua.io.LoadState;
|
|
||||||
import lua.io.Proto;
|
|
||||||
import lua.value.LNil;
|
|
||||||
import lua.value.LString;
|
|
||||||
import lua.value.LValue;
|
|
||||||
|
|
||||||
public class StandardTest extends TestCase {
|
public class StandardTest extends TestCase {
|
||||||
|
|
||||||
@@ -37,7 +30,7 @@ public class StandardTest extends TestCase {
|
|||||||
while ( ( file = testSuiteArchive.getNextEntry() ) != null ) {
|
while ( ( file = testSuiteArchive.getNextEntry() ) != null ) {
|
||||||
final String entryName = file.getName();
|
final String entryName = file.getName();
|
||||||
if ( entryName.endsWith( ".luac" ) ) {
|
if ( entryName.endsWith( ".luac" ) ) {
|
||||||
Proto p = LoadState.undump( new StackState(), testSuiteArchive, entryName );
|
LPrototype p = LoadState.undump( new LuaState(), testSuiteArchive, entryName );
|
||||||
tests.put( entryName.substring( 0, entryName.length() - 5 ), p );
|
tests.put( entryName.substring( 0, entryName.length() - 5 ), p );
|
||||||
} else if ( entryName.endsWith( ".out" ) ) {
|
} else if ( entryName.endsWith( ".out" ) ) {
|
||||||
results.put( entryName.substring( 0, entryName.length() - 4 ), readString( testSuiteArchive ) );
|
results.put( entryName.substring( 0, entryName.length() - 4 ), readString( testSuiteArchive ) );
|
||||||
@@ -51,7 +44,7 @@ public class StandardTest extends TestCase {
|
|||||||
|
|
||||||
for ( Iterator keys = tests.keySet().iterator(); keys.hasNext(); ) {
|
for ( Iterator keys = tests.keySet().iterator(); keys.hasNext(); ) {
|
||||||
String test = (String)keys.next();
|
String test = (String)keys.next();
|
||||||
final Proto code = (Proto)tests.get( test );
|
final LPrototype code = (LPrototype)tests.get( test );
|
||||||
final String expectedResult = (String)results.get( test );
|
final String expectedResult = (String)results.get( test );
|
||||||
|
|
||||||
if ( code != null && expectedResult != null ) {
|
if ( code != null && expectedResult != null ) {
|
||||||
@@ -62,29 +55,28 @@ public class StandardTest extends TestCase {
|
|||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Proto code;
|
private final LPrototype code;
|
||||||
private final String expectedResult;
|
private final String expectedResult;
|
||||||
|
|
||||||
public StandardTest( String name, Proto code, String expectedResult ) {
|
public StandardTest( String name, LPrototype code, String expectedResult ) {
|
||||||
super( name );
|
super( name );
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.expectedResult = expectedResult;
|
this.expectedResult = expectedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
GlobalState.resetGlobals();
|
LuaState state = new DebugStackState();
|
||||||
LuaCompat.install();
|
MathLib.install(state._G);
|
||||||
// hack: it's unpleasant when the test cases fail to terminate;
|
// hack: it's unpleasant when the test cases fail to terminate;
|
||||||
// unfortunately, there is a test in the standard suite that
|
// unfortunately, there is a test in the standard suite that
|
||||||
// relies on weak tables having their elements removed by
|
// relies on weak tables having their elements removed by
|
||||||
// the garbage collector. Until we implement that, remove the
|
// the garbage collector. Until we implement that, remove the
|
||||||
// built-in collectgarbage function.
|
// built-in collectgarbage function.
|
||||||
GlobalState.getGlobalsTable().put( "collectgarbage", LNil.NIL );
|
state._G.put( "collectgarbage", LNil.NIL );
|
||||||
StackState state = new DebugStackState();
|
LClosure c = new LClosure( code, state._G );
|
||||||
Closure c = new Closure( state, code );
|
|
||||||
|
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
Builtin.redirectOutput( output );
|
BaseLib.redirectOutput( output );
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
state.doCall( c, new LValue[0] );
|
state.doCall( c, new LValue[0] );
|
||||||
@@ -94,7 +86,7 @@ public class StandardTest extends TestCase {
|
|||||||
|
|
||||||
for ( int i = 0; i < ncalls; ++i ) {
|
for ( int i = 0; i < ncalls; ++i ) {
|
||||||
CallInfo call = state.calls[i];
|
CallInfo call = state.calls[i];
|
||||||
Proto p = call.closure.p;
|
LPrototype p = call.closure.p;
|
||||||
int line = p.lineinfo[call.pc-1];
|
int line = p.lineinfo[call.pc-1];
|
||||||
String func = call.closure.luaAsString().toJavaString();
|
String func = call.closure.luaAsString().toJavaString();
|
||||||
stackTrace[ncalls - i - 1] = new StackTraceElement(getName(), func, getName()+".lua", line );
|
stackTrace[ncalls - i - 1] = new StackTraceElement(getName(), func, getName()+".lua", line );
|
||||||
@@ -110,7 +102,7 @@ public class StandardTest extends TestCase {
|
|||||||
|
|
||||||
assertEquals( expectedResult, actualResult );
|
assertEquals( expectedResult, actualResult );
|
||||||
} finally {
|
} finally {
|
||||||
Builtin.restoreStandardOutput();
|
BaseLib.restoreStandardOutput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
obj = luajava.newInstance("java.lang.Object")
|
obj = luajava.newInstance("java.lang.Object")
|
||||||
print( obj )
|
print( obj )
|
||||||
|
|
||||||
obj = luajava.newInstance("SampleClass")
|
obj = luajava.newInstance("org.luaj.sample.SampleClass")
|
||||||
print( obj )
|
print( obj )
|
||||||
obj.s = "Hello"
|
obj.s = "Hello"
|
||||||
print( obj.s )
|
print( obj.s )
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user