public void trim(LuaValue count) { int min = count.toint() - 1; for (int i = list.size() - 1; i >= min; i--) { list.remove(i); } }
public void trim(LuaValue count) { int min = count.toint() - 1; for (int i = list.size() - 1; i >= min; i--) { list.remove(i); } }
public void set(LuaValue index, LuaValue value) { int i = index.toint(); ensureSize(i); list.set(i - 1, value); }
/** Return argument i as a java int value, discarding any fractional part and truncating, * or 0 if not a number. * @param i the index of the argument to convert, 1 is the first argument * @return int value with fraction discarded and truncated if necessary if argument i is number, otherwise 0 * */ public int toint(int i) { return arg(i).toint(); }
public void insert(LuaValue index, LuaValue value) { int i = index.toint(); ensureSize(i); list.add(i - 1, value); }
/** Length operator: return lua length of object {@code (#this)} including metatag processing as java int * @return length as defined by the lua # operator * or metatag processing result converted to java int using {@link #toint()} * @throws LuaError if {@code this} is not a table or string, and has no {@link LEN} metatag */ public int length() { return len().toint(); }
public LuaList take(LuaValue items) { int max = items.toint(); if (max > list.size()) { max = list.size(); } return subList(0, max); }
public LuaList take(LuaValue items) { int max = items.toint(); if (max > list.size()) { max = list.size(); } return subList(0, max); }
public void set(LuaValue index, LuaValue value) { int i = index.toint(); ensureSize(i); list.set(i - 1, value); }
public void insert(LuaValue index, LuaValue value) { int i = index.toint(); ensureSize(i); list.add(i - 1, value); }
/** Return argument i as a java int value, discarding any fractional part and truncating, * or 0 if not a number. * @param i the index of the argument to convert, 1 is the first argument * @return int value with fraction discarded and truncated if necessary if argument i is number, otherwise 0 * */ public int toint(int i) { return arg(i).toint(); }
public LuaList drop(LuaValue count) { int c = count.toint(); if (c >= list.size()) { return new LuaList(instance, new ArrayList<LuaValue>(0)); } return subList(c, list.size()); }
public LuaList drop(LuaValue count) { int c = count.toint(); if (c >= list.size()) { return new LuaList(instance, new ArrayList<LuaValue>(0)); } return subList(c, list.size()); }
public void set(LuaValue key, LuaValue value) { if ( key.isint() ) { int i = key.toint() - 1; if ( i>=0 && i<Array.getLength(m_instance) ) Array.set(m_instance,i,CoerceLuaToJava.coerce(value, m_instance.getClass().getComponentType())); else if ( m_metatable==null || ! settable(this,key,value) ) error("array index out of bounds"); } else super.set(key, value); } }
void dumpString(LuaString s) throws IOException { final int len = s.len().toint(); dumpInt( len+1 ); s.write( writer, 0, len ); writer.write( 0 ); }
/** caller must ensure key is not nil */ public void rawset( LuaValue key, LuaValue value ) { if ( !key.isinttype() || !arrayset(key.toint(), value) ) hashset( key, value ); }
public LuaValue rawget( LuaValue key ) { if ( key.isinttype() ) { int ikey = key.toint(); if ( ikey>0 && ikey<=array.length ) { LuaValue v = m_metatable == null ? array[ikey-1] : m_metatable.arrayget(array, ikey-1); return v != null ? v : NIL; } } return hashget( key ); }
/** caller must ensure key is not nil */ @Override public void rawset( LuaValue key, LuaValue value ) { if ( !key.isinttype() || !arrayset(key.toint(), value) ) hashset( key, value ); }
/** caller must ensure key is not nil */ public void rawset( LuaValue key, LuaValue value ) { if ( !key.isinttype() || !arrayset(key.toint(), value) ) hashset( key, value ); }
protected static Entry defaultEntry(LuaValue key, LuaValue value) { if ( key.isinttype() ) { return new IntKeyEntry( key.toint(), value ); } else if (value.type() == TNUMBER) { return new NumberValueEntry( key, value.todouble() ); } else { return new NormalEntry( key, value ); } }