Ejemplo n.º 1
0
int
strm_ptr_eq(struct strm_object *a, struct strm_object *b)
{
  if (a == b) return TRUE;
  if (a == NULL) return FALSE;
  if (a->type != b->type) return FALSE;
  switch (a->type) {
  case STRM_OBJ_ARRAY:
    return strm_ary_eq((struct strm_array*)a, (struct strm_array*)b);
  case STRM_OBJ_STRING:
    return strm_str_eq((struct strm_string*)a, (struct strm_string*)b);
  default:
    return FALSE;
  }
}
Ejemplo n.º 2
0
int
strm_value_eq(strm_value a, strm_value b)
{
  if (a == b) return TRUE;
  if (strm_value_tag(a) != strm_value_tag(b)) return FALSE;
  switch (strm_value_tag(a)) {
  case STRM_TAG_ARRAY:
  case STRM_TAG_STRUCT:
    return strm_ary_eq(a, b);
  case STRM_TAG_STRING_I:
  case STRM_TAG_STRING_6:
  case STRM_TAG_STRING_O:
  case STRM_TAG_STRING_F:
    return strm_str_eq(a, b);
  case STRM_TAG_CFUNC:
    return (strm_cfunc)strm_value_vptr(a) == (strm_cfunc)strm_value_vptr(b);
  case STRM_TAG_PTR:
    return strm_value_vptr(a) == strm_value_vptr(b);
  default:
    return FALSE;
  }
}
Ejemplo n.º 3
0
int
strm_value_eq(strm_value a, strm_value b)
{
  if (a == b) return TRUE;
  if (strm_value_tag(a) != strm_value_tag(b)) goto typediff;
  switch (strm_value_tag(a)) {
  case STRM_TAG_STRUCT:
    return strm_ary_eq(a, b);
  case STRM_TAG_STRING_O:
  case STRM_TAG_STRING_F:
    return strm_str_eq(a, b);
  case STRM_TAG_CFUNC:
    return (strm_cfunc)(intptr_t)strm_value_val(a) == (strm_cfunc)(intptr_t)strm_value_val(b);
  case STRM_TAG_PTR:
    return strm_value_vptr(a) == strm_value_vptr(b);
  typediff:
  default:
    if (strm_number_p(a) && strm_number_p(b)) {
      return strm_value_flt(a) == strm_value_flt(b);
    }
    return FALSE;
  }
}
Ejemplo n.º 4
0
static int
ary_get(strm_stream* strm, strm_value ary, int argc, strm_value* argv, strm_value* ret)
{
  struct strm_array* a;
  strm_value idx;

  if (argc != 1) {
    strm_raise(strm, "wrong number of arguments");
    return STRM_NG;
  }

  a = strm_ary_struct(ary);
  idx = argv[0];
  if (strm_num_p(idx)) {
    strm_int i = strm_value_int(idx);

    if (i>=a->len)
      return STRM_NG;
    *ret = a->ptr[i];
    return STRM_OK;
  }
  if (strm_string_p(idx)) {
    if (a->headers) {
      strm_int i, len = a->len;

      for (i=0; i<len; i++) {
        if (strm_str_eq(strm_value_str(idx),
                        strm_value_str(strm_ary_ptr(a->headers)[i]))) {
          *ret = a->ptr[i];
          return STRM_OK;
        }
      }
    }
  }
  return STRM_NG;
}