Skip to content

Commit

Permalink
simplify package
Browse files Browse the repository at this point in the history
  • Loading branch information
taoguan committed Jan 7, 2025
1 parent fa87630 commit 98f89a1
Show file tree
Hide file tree
Showing 50 changed files with 1,040 additions and 1,039 deletions.
50 changes: 25 additions & 25 deletions src/main/java/io/github/taoguan/luaj/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class Buffer {
private int offset;

/** Value of this buffer, when not represented in bytes */
private io.github.taoguan.luaj.LuaValue value;
private LuaValue value;

/**
* Create buffer with default capacity
Expand All @@ -57,38 +57,38 @@ public Buffer(int initialCapacity ) {
* Create buffer with specified initial value
* @param value the initial value
*/
public Buffer(io.github.taoguan.luaj.LuaValue value) {
public Buffer(LuaValue value) {
bytes = NOBYTES;
length = offset = 0;
this.value = value;
}

/**
* Get buffer contents as a {@link io.github.taoguan.luaj.LuaValue}
* @return value as a {@link io.github.taoguan.luaj.LuaValue}, converting as necessary
* Get buffer contents as a {@link LuaValue}
* @return value as a {@link LuaValue}, converting as necessary
*/
public io.github.taoguan.luaj.LuaValue value() {
public LuaValue value() {
return value != null? value: this.tostring();
}

/**
* Set buffer contents as a {@link io.github.taoguan.luaj.LuaValue}
* Set buffer contents as a {@link LuaValue}
* @param value value to set
*/
public Buffer setvalue(io.github.taoguan.luaj.LuaValue value) {
public Buffer setvalue(LuaValue value) {
bytes = NOBYTES;
offset = length = 0;
this.value = value;
return this;
}

/**
* Convert the buffer to a {@link io.github.taoguan.luaj.LuaString}
* @return the value as a {@link io.github.taoguan.luaj.LuaString}
* Convert the buffer to a {@link LuaString}
* @return the value as a {@link LuaString}
*/
public final io.github.taoguan.luaj.LuaString tostring() {
public final LuaString tostring() {
realloc( length, 0 );
return io.github.taoguan.luaj.LuaString.valueOf( bytes, offset, length );
return LuaString.valueOf( bytes, offset, length );
}

/**
Expand Down Expand Up @@ -118,19 +118,19 @@ public final Buffer append( byte b ) {
}

/**
* Append a {@link io.github.taoguan.luaj.LuaValue} to the buffer.
* Append a {@link LuaValue} to the buffer.
* @return {@code this} to allow call chaining
*/
public final Buffer append( io.github.taoguan.luaj.LuaValue val ) {
public final Buffer append( LuaValue val ) {
append( val.strvalue() );
return this;
}

/**
* Append a {@link io.github.taoguan.luaj.LuaString} to the buffer.
* Append a {@link LuaString} to the buffer.
* @return {@code this} to allow call chaining
*/
public final Buffer append( io.github.taoguan.luaj.LuaString str ) {
public final Buffer append( LuaString str ) {
final int n = str.m_length;
makeroom( 0, n );
str.copyInto( 0, bytes, offset + length, n );
Expand All @@ -142,30 +142,30 @@ public final Buffer append( io.github.taoguan.luaj.LuaString str ) {
* Append a Java String to the buffer.
* The Java string will be converted to bytes using the UTF8 encoding.
* @return {@code this} to allow call chaining
* @see io.github.taoguan.luaj.LuaString#encodeToUtf8(char[], int, byte[], int)
* @see LuaString#encodeToUtf8(char[], int, byte[], int)
*/
public final Buffer append( String str ) {
char[] c = str.toCharArray();
final int n = io.github.taoguan.luaj.LuaString.lengthAsUtf8( c );
final int n = LuaString.lengthAsUtf8( c );
makeroom( 0, n );
io.github.taoguan.luaj.LuaString.encodeToUtf8( c, c.length, bytes, offset + length );
LuaString.encodeToUtf8( c, c.length, bytes, offset + length );
length += n;
return this;
}

/** Concatenate this buffer onto a {@link io.github.taoguan.luaj.LuaValue}
/** Concatenate this buffer onto a {@link LuaValue}
* @param lhs the left-hand-side value onto which we are concatenating {@code this}
* @return {@link Buffer} for use in call chaining.
*/
public Buffer concatTo(io.github.taoguan.luaj.LuaValue lhs) {
public Buffer concatTo(LuaValue lhs) {
return setvalue(lhs.concat(value()));
}

/** Concatenate this buffer onto a {@link io.github.taoguan.luaj.LuaString}
/** Concatenate this buffer onto a {@link LuaString}
* @param lhs the left-hand-side value onto which we are concatenating {@code this}
* @return {@link Buffer} for use in call chaining.
*/
public Buffer concatTo(io.github.taoguan.luaj.LuaString lhs) {
public Buffer concatTo(LuaString lhs) {
return value!=null&&!value.isstring()? setvalue(lhs.concat(value)): prepend(lhs);
}

Expand All @@ -179,11 +179,11 @@ public Buffer concatTo(LuaNumber lhs) {
return value!=null&&!value.isstring()? setvalue(lhs.concat(value)): prepend(lhs.strvalue());
}

/** Concatenate bytes from a {@link io.github.taoguan.luaj.LuaString} onto the front of this buffer
/** Concatenate bytes from a {@link LuaString} onto the front of this buffer
* @param s the left-hand-side value which we will concatenate onto the front of {@code this}
* @return {@link Buffer} for use in call chaining.
*/
public Buffer prepend(io.github.taoguan.luaj.LuaString s) {
public Buffer prepend(LuaString s) {
int n = s.m_length;
makeroom( n, 0 );
System.arraycopy( s.m_bytes, s.m_offset, bytes, offset-n, n );
Expand All @@ -199,7 +199,7 @@ public Buffer prepend(io.github.taoguan.luaj.LuaString s) {
*/
public final void makeroom( int nbefore, int nafter ) {
if ( value != null ) {
io.github.taoguan.luaj.LuaString s = value.strvalue();
LuaString s = value.strvalue();
value = null;
length = s.m_length;
offset = nbefore;
Expand Down
66 changes: 33 additions & 33 deletions src/main/java/io/github/taoguan/luaj/LoadState.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
public class LoadState {

/** Shared instance of Globals.Undumper to use loading prototypes from binary lua files */
public static final io.github.taoguan.luaj.Globals.Undumper instance = new GlobalsUndumper();
public static final Globals.Undumper instance = new GlobalsUndumper();

/** format corresponding to non-number-patched lua, all numbers are floats or doubles */
public static final int NUMBER_FORMAT_FLOATS_OR_DOUBLES = 0;
Expand Down Expand Up @@ -129,18 +129,18 @@ public class LoadState {
/** Name of what is being loaded? */
String name;

private static final io.github.taoguan.luaj.LuaValue[] NOVALUES = {};
private static final io.github.taoguan.luaj.Prototype[] NOPROTOS = {};
private static final io.github.taoguan.luaj.LocVars[] NOLOCVARS = {};
private static final io.github.taoguan.luaj.LuaString[] NOSTRVALUES = {};
private static final LuaValue[] NOVALUES = {};
private static final Prototype[] NOPROTOS = {};
private static final LocVars[] NOLOCVARS = {};
private static final LuaString[] NOSTRVALUES = {};
private static final Upvaldesc[] NOUPVALDESCS = {};
private static final int[] NOINTS = {};

/** Read buffer */
private byte[] buf = new byte[512];

/** Install this class as the standard Globals.Undumper for the supplied Globals */
public static void install(io.github.taoguan.luaj.Globals globals) {
public static void install(Globals globals) {
globals.undumper = instance;
}

Expand Down Expand Up @@ -192,25 +192,25 @@ long loadInt64() throws IOException {
}

/** Load a lua strin gvalue from the input stream
* @return the {@link io.github.taoguan.luaj.LuaString} value laoded.
* @return the {@link LuaString} value laoded.
**/
io.github.taoguan.luaj.LuaString loadString() throws IOException {
LuaString loadString() throws IOException {
int size = this.luacSizeofSizeT == 8? (int) loadInt64(): loadInt();
if ( size == 0 )
return null;
byte[] bytes = new byte[size];
is.readFully( bytes, 0, size );
return io.github.taoguan.luaj.LuaString.valueUsing( bytes, 0, bytes.length - 1 );
return LuaString.valueUsing( bytes, 0, bytes.length - 1 );
}

/**
* Convert bits in a long value to a {@link io.github.taoguan.luaj.LuaValue}.
* Convert bits in a long value to a {@link LuaValue}.
* @param bits long value containing the bits
* @return {@link LuaInteger} or {@link LuaDouble} whose value corresponds to the bits provided.
*/
public static io.github.taoguan.luaj.LuaValue longBitsToLuaNumber(long bits ) {
public static LuaValue longBitsToLuaNumber(long bits ) {
if ( ( bits & ( ( 1L << 63 ) - 1 ) ) == 0L ) {
return io.github.taoguan.luaj.LuaValue.ZERO;
return LuaValue.ZERO;
}

int e = (int)((bits >> 52) & 0x7ffL) - 1023;
Expand All @@ -225,15 +225,15 @@ public static io.github.taoguan.luaj.LuaValue longBitsToLuaNumber(long bits ) {
}
}

return io.github.taoguan.luaj.LuaValue.valueOf( Double.longBitsToDouble(bits) );
return LuaValue.valueOf( Double.longBitsToDouble(bits) );
}

/**
* Load a number from a binary chunk
* @return the {@link io.github.taoguan.luaj.LuaValue} loaded
* @return the {@link LuaValue} loaded
* @throws IOException if an i/o exception occurs
*/
io.github.taoguan.luaj.LuaValue loadNumber() throws IOException {
LuaValue loadNumber() throws IOException {
if ( luacNumberFormat == NUMBER_FORMAT_INTS_ONLY ) {
return LuaInteger.valueOf( loadInt() );
} else {
Expand All @@ -246,16 +246,16 @@ io.github.taoguan.luaj.LuaValue loadNumber() throws IOException {
* @param f the function prototype
* @throws IOException if an i/o exception occurs
*/
void loadConstants(io.github.taoguan.luaj.Prototype f) throws IOException {
void loadConstants(Prototype f) throws IOException {
int n = loadInt();
io.github.taoguan.luaj.LuaValue[] values = n>0? new io.github.taoguan.luaj.LuaValue[n]: NOVALUES;
LuaValue[] values = n>0? new LuaValue[n]: NOVALUES;
for ( int i=0; i<n; i++ ) {
switch ( is.readByte() ) {
case LUA_TNIL:
values[i] = io.github.taoguan.luaj.LuaValue.NIL;
values[i] = LuaValue.NIL;
break;
case LUA_TBOOLEAN:
values[i] = (0 != is.readUnsignedByte()? io.github.taoguan.luaj.LuaValue.TRUE: io.github.taoguan.luaj.LuaValue.FALSE);
values[i] = (0 != is.readUnsignedByte()? LuaValue.TRUE: LuaValue.FALSE);
break;
case LUA_TINT:
values[i] = LuaInteger.valueOf( loadInt() );
Expand All @@ -273,14 +273,14 @@ void loadConstants(io.github.taoguan.luaj.Prototype f) throws IOException {
f.k = values;

n = loadInt();
io.github.taoguan.luaj.Prototype[] protos = n>0? new io.github.taoguan.luaj.Prototype[n]: NOPROTOS;
Prototype[] protos = n>0? new Prototype[n]: NOPROTOS;
for ( int i=0; i<n; i++ )
protos[i] = loadFunction(f.source);
f.p = protos;
}


void loadUpvalues(io.github.taoguan.luaj.Prototype f) throws IOException {
void loadUpvalues(Prototype f) throws IOException {
int n = loadInt();
f.upvalues = n>0? new Upvaldesc[n]: NOUPVALDESCS;
for (int i=0; i<n; i++) {
Expand All @@ -295,16 +295,16 @@ void loadUpvalues(io.github.taoguan.luaj.Prototype f) throws IOException {
* @param f the function Prototype
* @throws IOException if there is an i/o exception
*/
void loadDebug( io.github.taoguan.luaj.Prototype f ) throws IOException {
void loadDebug( Prototype f ) throws IOException {
f.source = loadString();
f.lineinfo = loadIntArray();
int n = loadInt();
f.locvars = n>0? new io.github.taoguan.luaj.LocVars[n]: NOLOCVARS;
f.locvars = n>0? new LocVars[n]: NOLOCVARS;
for ( int i=0; i<n; i++ ) {
io.github.taoguan.luaj.LuaString varname = loadString();
LuaString varname = loadString();
int startpc = loadInt();
int endpc = loadInt();
f.locvars[i] = new io.github.taoguan.luaj.LocVars(varname, startpc, endpc);
f.locvars[i] = new LocVars(varname, startpc, endpc);
}

n = loadInt();
Expand All @@ -315,11 +315,11 @@ void loadDebug( io.github.taoguan.luaj.Prototype f ) throws IOException {
/**
* Load a function prototype from the input stream
* @param p name of the source
* @return {@link io.github.taoguan.luaj.Prototype} instance that was loaded
* @return {@link Prototype} instance that was loaded
* @throws IOException
*/
public io.github.taoguan.luaj.Prototype loadFunction(io.github.taoguan.luaj.LuaString p) throws IOException {
io.github.taoguan.luaj.Prototype f = new io.github.taoguan.luaj.Prototype();
public Prototype loadFunction(LuaString p) throws IOException {
Prototype f = new Prototype();
//// this.L.push(f);
// f.source = loadString();
// if ( f.source == null )
Expand Down Expand Up @@ -364,10 +364,10 @@ public void loadHeader() throws IOException {
* Load input stream as a lua binary chunk if the first 4 bytes are the lua binary signature.
* @param stream InputStream to read, after having read the first byte already
* @param chunkname Name to apply to the loaded chunk
* @return {@link io.github.taoguan.luaj.Prototype} that was loaded, or null if the first 4 bytes were not the lua signature.
* @return {@link Prototype} that was loaded, or null if the first 4 bytes were not the lua signature.
* @throws IOException if an IOException occurs
*/
public static io.github.taoguan.luaj.Prototype undump(InputStream stream, String chunkname) throws IOException {
public static Prototype undump(InputStream stream, String chunkname) throws IOException {
// check rest of signature
if ( stream.read() != LUA_SIGNATURE[0]
|| stream.read() != LUA_SIGNATURE[1]
Expand All @@ -389,7 +389,7 @@ public static io.github.taoguan.luaj.Prototype undump(InputStream stream, String
default:
throw new LuaError("unsupported int size");
}
return s.loadFunction( io.github.taoguan.luaj.LuaString.valueOf(sname) );
return s.loadFunction( LuaString.valueOf(sname) );
}

/**
Expand All @@ -412,8 +412,8 @@ private LoadState(InputStream stream, String name ) {
this.is = new DataInputStream( stream );
}

private static final class GlobalsUndumper implements io.github.taoguan.luaj.Globals.Undumper {
public io.github.taoguan.luaj.Prototype undump(InputStream stream, String chunkname)
private static final class GlobalsUndumper implements Globals.Undumper {
public Prototype undump(InputStream stream, String chunkname)
throws IOException {
return LoadState.undump(stream, chunkname);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/taoguan/luaj/LocVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public class LocVars {
/** The local variable name */
public io.github.taoguan.luaj.LuaString varname;
public LuaString varname;

/** The instruction offset when the variable comes into scope */
public int startpc;
Expand All @@ -19,7 +19,7 @@ public class LocVars {
* @param startpc The instruction offset when the variable comes into scope
* @param endpc The instruction offset when the variable goes out of scope
*/
public LocVars(io.github.taoguan.luaj.LuaString varname, int startpc, int endpc) {
public LocVars(LuaString varname, int startpc, int endpc) {
this.varname = varname;
this.startpc = startpc;
this.endpc = endpc;
Expand Down
Loading

0 comments on commit 98f89a1

Please sign in to comment.