Exemplo n.º 1
0
 public LuaValue rawget(int key) {
   if (key > 0 && key <= array.length) {
     LuaValue v = m_metatable == null ? array[key - 1] : m_metatable.arrayget(array, key - 1);
     return v != null ? v : NIL;
   }
   return hashget(LuaInteger.valueOf(key));
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
  /**
   * Get the next element after a particular key in the table
   *
   * @return key,value or nil
   */
  public Varargs next(LuaValue key) {
    int i = 0;
    do {
      // find current key index
      if (!key.isnil()) {
        if (key.isinttype()) {
          i = key.toint();
          if (i > 0 && i <= array.length) {
            break;
          }
        }
        if (hash.length == 0) error("invalid key to 'next'");
        i = hashSlot(key);
        boolean found = false;
        for (Slot slot = hash[i]; slot != null; slot = slot.rest()) {
          if (found) {
            StrongSlot nextEntry = slot.first();
            if (nextEntry != null) {
              return nextEntry.toVarargs();
            }
          } else if (slot.keyeq(key)) {
            found = true;
          }
        }
        if (!found) {
          error("invalid key to 'next'");
        }
        i += 1 + array.length;
      }
    } while (false);

    // check array part
    for (; i < array.length; ++i) {
      if (array[i] != null) {
        LuaValue value = m_metatable == null ? array[i] : m_metatable.arrayget(array, i);
        if (value != null) {
          return varargsOf(LuaInteger.valueOf(i + 1), value);
        }
      }
    }

    // check hash part
    for (i -= array.length; i < hash.length; ++i) {
      Slot slot = hash[i];
      while (slot != null) {
        StrongSlot first = slot.first();
        if (first != null) return first.toVarargs();
        slot = slot.rest();
      }
    }

    // nothing found, push nil, return nil.
    return NIL;
  }
Exemplo n.º 4
0
 private boolean compare(int i, int j, LuaValue cmpfunc) {
   LuaValue a, b;
   if (m_metatable == null) {
     a = array[i];
     b = array[j];
   } else {
     a = m_metatable.arrayget(array, i);
     b = m_metatable.arrayget(array, j);
   }
   if (a == null || b == null) return false;
   if (!cmpfunc.isnil()) {
     return cmpfunc.call(a, b).toboolean();
   } else {
     return a.lt_b(b);
   }
 }
Exemplo n.º 5
0
 private void dropWeakArrayValues() {
   for (int i = 0; i < array.length; ++i) {
     m_metatable.arrayget(array, i);
   }
 }