Exemplo n.º 1
0
static int lupb_array_index(lua_State *L) {
  lupb_array *larray = lupb_array_check(L, 1);
  upb_array *array = larray->arr;
  uint32_t n = lupb_array_checkindex(L, 2, upb_array_size(array));
  upb_fieldtype_t type = upb_array_type(array);

  if (lupb_istypewrapped(type)) {
    lupb_uservalgeti(L, 1, n);
  } else {
    lupb_pushmsgval(L, upb_array_type(array), upb_array_get(array, n));
  }

  return 1;
}
Exemplo n.º 2
0
static upb_flow_t upb_msg_dispatch(upb_msg *msg, upb_msgdef *md,
                                   upb_dispatcher *d) {
  upb_msg_iter i;
  for(i = upb_msg_begin(md); !upb_msg_done(i); i = upb_msg_next(md, i)) {
    upb_fielddef *f = upb_msg_iter_field(i);
    if (!upb_msg_has(msg, f)) continue;
    upb_fhandlers *hf = upb_dispatcher_lookup(d, f->number);
    if (!hf) continue;
    upb_value val = upb_msg_get(msg, f);
    if (upb_isarray(f)) {
      upb_array *arr = upb_value_getarr(val);
      for (uint32_t j = 0; j < upb_array_len(arr); ++j) {
        upb_msg_pushval(upb_array_get(arr, f, j), f, d, hf);
      }
    } else {
      upb_msg_pushval(val, f, d, hf);
    }
  }
  return UPB_CONTINUE;
}