Branch: Tag:

2003-01-08

2003-01-08 14:00:53 by Henrik Grubbström (Grubba) <grubba@grubba.org>

function_object() now behaves as in Pike 7.2. The other cases have been moved to function_program().

Rev: src/builtin.cmod:1.103

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin.cmod,v 1.102 2003/01/05 00:54:02 nilsson Exp $ + || $Id: builtin.cmod,v 1.103 2003/01/08 14:00:53 grubba Exp $   */      #include "global.h"
735:    push_int(0);   }    - /*! @decl object function_object(function|program f) + /*! @decl object function_object(function f)    *! -  *! Return the object the function @[f] is in. +  *! Return the object the function @[f] is in.    *! -  *! If @[f] is a global function defined in the runtime @tt{0@} (zero) -  *! will be returned. +  *! If @[f] is a global function defined in the runtime @tt{0@} (zero) +  *! will be returned.    *! -  +  *! Zero will also be returned if @[f] is a constant in the +  *! parent class. In that case @[function_program()] can be +  *! used to get the parent program. +  *!    *! @seealso -  *! @[function_name()] +  *! @[function_name()], @[function_program()]    */ - PIKEFUN object|program function_object(object|program|function func) + PIKEFUN object|program function_object(function|program func)    efun;    optflags OPT_TRY_OPTIMIZE; -  type function(function|object:object)|function(program:program); +  type function(function:object);   {    switch(func->type)    {    case PIKE_T_PROGRAM: -  { -  struct program *p; -  if(!(p=func->u.program->parent)) break; -  add_ref(p); -  free_program(func->u.program); -  func->u.program=p; -  return; -  } +  break;       case PIKE_T_FUNCTION:    if(func->subtype == FUNCTION_BUILTIN) break;
784:    push_int(0);   }    + /*! @decl program function_program(function|program f) +  *! +  *! Return the program the function @[f] is in. +  *! +  *! If @[f] is a global function defined in the runtime @tt{0@} (zero) +  *! will be returned. +  *! +  *! @seealso +  *! @[function_name()], @[function_object()] +  */ + PIKEFUN program function_program(program|function func) +  efun; +  optflags OPT_TRY_OPTIMIZE; + { +  switch(func->type) +  { +  case PIKE_T_PROGRAM: +  { +  struct program *p; +  if(!(p=func->u.program->parent)) break; +  add_ref(p); +  free_program(func->u.program); +  func->u.program=p; +  return; +  }    -  +  case PIKE_T_FUNCTION: +  { +  struct program *p; +  if(func->subtype == FUNCTION_BUILTIN) break; +  p = func->u.object->prog; +  if(p == pike_trampoline_program) +  { +  p = ((struct pike_trampoline *)func->u.object->storage)-> +  frame->current_object->prog; +  } +  if (p) { +  ref_push_program(p); +  stack_pop_n_elems_keep_top(args); +  return; +  } +  } +  break;    -  +  default: +  SIMPLE_BAD_ARG_ERROR("function_program", 1, "function"); +  } +  pop_n_elems(args); +  push_int(0); + } +  +  +    /*! @decl int random(int max)    *!    *! This function returns a random number in the range 0 - @[max]-1.