pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:8639:    *! @item mapping    *! @[fun] is applied to the values, and each result is assigned    *! to the same index in a new mapping, which is returned.    *!    *! @item program    *! The program is treated as a mapping containing the    *! identifiers that are indexable from it and their values.    *!    *! @item object    *! If there is a @[lfun::cast] method in the object, it's -  *! called -  *! to try to cast the object to an array, a mapping, or a -  *! multiset, in that order, which is then handled as described -  *! above. +  *! called to try to cast the object to an array, a mapping, or +  *! a multiset, in that order, which is then handled as +  *! described above.    *! @enddl    *!    *! @[fun] is applied in different ways depending on its type:    *!    *! @dl    *! @item function    *! @[fun] is called for each element. It gets the current    *! element as the first argument and @[extra] as the rest. The    *! result of the call is collected.    *!
pike.git/src/builtin_functions.c:8766:    return;       case T_OBJECT:    /* if arr->cast :    try map((array)arr,fun,@extra);    try map((mapping)arr,fun,@extra);    try map((multiset)arr,fun,@extra); */       mysp=Pike_sp+3-args;    -  push_svalue(mysp-3); -  push_constant_text("cast"); -  f_arrow(2); -  if (!UNSAFE_IS_ZERO(Pike_sp-1)) +     { -  pop_stack(); +  struct object *o = mysp[-3].u.object; +  int f = FIND_LFUN(o->prog->inherits[SUBTYPEOF(mysp[-3])].prog, +  LFUN_CAST);    -  +  if( f!=-1 ) +  { +     ref_push_string(literal_array_string); -  /* FIXME: Object subtype! */ -  safe_apply(mysp[-3].u.object,"cast",1); +  apply_low(o, f, 1); +     if (TYPEOF(Pike_sp[-1]) == T_ARRAY)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_map(args);    return;    }    pop_stack();       ref_push_string(literal_mapping_string); -  /* FIXME: Object subtype! */ -  safe_apply(mysp[-3].u.object,"cast",1); +  apply_low(o, f, 1);    if (TYPEOF(Pike_sp[-1]) == T_MAPPING)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_map(args);    return;    }    pop_stack();       ref_push_string(literal_multiset_string); -  /* FIXME: Object subtype! */ -  safe_apply(mysp[-3].u.object,"cast",1); +  apply_low(o, f, 1);    if (TYPEOF(Pike_sp[-1]) == T_MULTISET)    {    free_svalue(mysp-3);    mysp[-3]=*(--Pike_sp);    dmalloc_touch_svalue(Pike_sp);    f_map(args);    return;    }    pop_stack();    } -  pop_stack(); +  }       /* if arr->_sizeof && arr->`[]    array ret; ret[i]=arr[i];    ret=map(ret,fun,@extra); */       /* class myarray { int a0=1,a1=2; int `[](int what) { return ::`[]("a"+what); } int _sizeof() { return 2; } }    map(myarray(),lambda(int in){ werror("in=%d\n",in); }); */       push_svalue(mysp-3);    push_constant_text("`[]");