Make soem methods final, let loadsting use "string" for chunk name
This commit is contained in:
@@ -26,7 +26,7 @@ package org.luaj.vm2;
|
||||
* String buffer for use in string library methods, optimized for production
|
||||
* of StrValue instances.
|
||||
*/
|
||||
public class Buffer {
|
||||
public final class Buffer {
|
||||
private static final int DEFAULT_CAPACITY = 64;
|
||||
|
||||
private byte[] bytes;
|
||||
@@ -36,32 +36,32 @@ public class Buffer {
|
||||
this(DEFAULT_CAPACITY);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new LuaString(bytes, 0, length).toString();
|
||||
}
|
||||
|
||||
public Buffer( int initialCapacity ) {
|
||||
bytes = new byte[ initialCapacity ];
|
||||
length = 0;
|
||||
}
|
||||
|
||||
public void append( byte b ) {
|
||||
public final String toString() {
|
||||
return new LuaString(bytes, 0, length).toString();
|
||||
}
|
||||
|
||||
public final void append( byte b ) {
|
||||
ensureCapacity( length + 1 );
|
||||
bytes[ length++ ] = b;
|
||||
}
|
||||
|
||||
public void append( LuaValue val ) {
|
||||
public final void append( LuaValue val ) {
|
||||
append( val.strvalue() );
|
||||
}
|
||||
|
||||
public void append( LuaString str ) {
|
||||
public final void append( LuaString str ) {
|
||||
final int alen = str.length();
|
||||
ensureCapacity( length + alen );
|
||||
str.copyInto( 0, bytes, length, alen );
|
||||
length += alen;
|
||||
}
|
||||
|
||||
public void append( String str ) {
|
||||
public final void append( String str ) {
|
||||
char[] chars = str.toCharArray();
|
||||
final int alen = LuaString.lengthAsUtf8( chars );
|
||||
ensureCapacity( length + alen );
|
||||
@@ -69,25 +69,25 @@ public class Buffer {
|
||||
length += alen;
|
||||
}
|
||||
|
||||
public void setLength( int length ) {
|
||||
public final void setLength( int length ) {
|
||||
ensureCapacity( length );
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public LuaString tostrvalue() {
|
||||
public final LuaString tostrvalue() {
|
||||
return new LuaString( realloc( bytes, length ) );
|
||||
}
|
||||
|
||||
public void ensureCapacity( int minSize ) {
|
||||
public final void ensureCapacity( int minSize ) {
|
||||
if ( minSize > bytes.length )
|
||||
realloc( minSize );
|
||||
}
|
||||
|
||||
private void realloc( int minSize ) {
|
||||
private final void realloc( int minSize ) {
|
||||
bytes = realloc( bytes, Math.max( bytes.length * 2, minSize ) );
|
||||
}
|
||||
|
||||
private static byte[] realloc( byte[] b, int newSize ) {
|
||||
private final static byte[] realloc( byte[] b, int newSize ) {
|
||||
byte[] newBytes = new byte[ newSize ];
|
||||
System.arraycopy( b, 0, newBytes, 0, Math.min( b.length, newSize ) );
|
||||
return newBytes;
|
||||
|
||||
@@ -177,6 +177,7 @@ public class LuaValue extends Varargs {
|
||||
public void rawset( String key, double value ) { rawset(valueOf(key),valueOf(value)); }
|
||||
public void rawset( String key, int value ) { rawset(valueOf(key),valueOf(value)); }
|
||||
public void rawset( String key, String value ) { rawset(valueOf(key),valueOf(value)); }
|
||||
public void rawsetlist( int key0, Varargs values ) { for ( int i=0, n=values.narg(); i<n; i++ ) rawset(key0+i,values.arg(i+1)); }
|
||||
public void presize( int i) { unimplemented("presize"); }
|
||||
public Varargs next(LuaValue index) { unimplemented("next"); return null; }
|
||||
public Varargs inext(LuaValue index) { unimplemented("inext"); return null; }
|
||||
@@ -286,10 +287,10 @@ public class LuaValue extends Varargs {
|
||||
// for loop helpers
|
||||
/** test numeric for loop */
|
||||
public boolean testfor_b(LuaValue limit, boolean stepgtzero) { return stepgtzero? lteq_b(limit): gteq_b(limit); }
|
||||
/** used in for loop only */
|
||||
public boolean testfor_b(LuaValue limit, LuaValue step) { return step.gt_b(0)? lteq_b(limit): gteq_b(limit); }
|
||||
/** @deprecated - used in samples only */
|
||||
public boolean testfor_b(LuaValue limit) { return lteq(limit).toboolean(); }
|
||||
/** @deprecated - used in samples only */
|
||||
public boolean testfor_b(LuaValue limit, LuaValue step) { return step.gt_b(0)? lteq_b(limit): gteq_b(limit); }
|
||||
/** @deprecated - used in samples only, use add(1) instead */
|
||||
public LuaValue incr() { return add(ONE); }
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ package org.luaj.vm2;
|
||||
|
||||
|
||||
/** Upvalue used with Closure formulation */
|
||||
public class UpValue {
|
||||
public final class UpValue {
|
||||
|
||||
LuaValue[] array; // initially the stack, becomes a holder
|
||||
int index;
|
||||
@@ -40,15 +40,15 @@ public class UpValue {
|
||||
return (closed? "-": "+") + array[index];
|
||||
}
|
||||
|
||||
public LuaValue getValue() {
|
||||
public final LuaValue getValue() {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
public void setValue( LuaValue value ) {
|
||||
public final void setValue( LuaValue value ) {
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
public boolean close( int limit ) {
|
||||
public final boolean close( int limit ) {
|
||||
if ( (!closed) && (index>=limit) ) {
|
||||
array = new LuaValue[] { array[index] };
|
||||
index = 0;
|
||||
@@ -58,7 +58,7 @@ public class UpValue {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
public final boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,8 +238,8 @@ public class BaseLib extends LuaTable implements ResourceFinder {
|
||||
case 4: // "loadstring", // ( string [,chunkname] ) -> chunk | nil, msg
|
||||
try {
|
||||
LuaString script = args.checkstring(1);
|
||||
LuaString chunkname = args.optstring(2, script);
|
||||
return LoadState.load(script.toInputStream(), chunkname.toString(),LuaThread.getRunningEnv(env));
|
||||
String chunkname = args.optString(2, "string");
|
||||
return LoadState.load(script.toInputStream(),chunkname,LuaThread.getRunningEnv(env));
|
||||
} catch ( Exception e ) {
|
||||
return varargsOf(NIL, valueOf(e.getMessage()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user