Exemplo n.º 1
0
upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) {
  upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof());

  if (!ret) {
    return NULL;
  }

  upb_mapiter_begin(ret, t);
  return ret;
}
Exemplo n.º 2
0
static int lupb_map_pairs(lua_State *L) {
  lupb_map *lmap = lupb_map_check(L, 1);

  if (lupb_istypewrapped(upb_map_keytype(lmap->map)) ||
      lupb_istypewrapped(upb_map_valuetype(lmap->map))) {
    /* Complex key or value type.
     * Sync upb_map to userval if necessary, then iterate over userval. */

    /* TODO: Lua tables don't know how many entries they have, gah!. */
    return 1;
  } else {
    /* Simple key and value type, iterate over the upb_map directly. */
    upb_mapiter *i = lua_newuserdata(L, upb_mapiter_sizeof());

    upb_mapiter_begin(i, lmap->map);
    lua_pushvalue(L, 1);

    /* Upvalues are [upb_mapiter, lupb_map]. */
    lua_pushcclosure(L, &lupb_mapiter_next, 2);

    return 1;
  }
}