pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:1:
/* -*- c -*- || 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" #include "interpret.h" #include "svalue.h" #include "opcodes.h" #include "pike_macros.h" #include "object.h" #include "program.h" #include "array.h"
pike.git/src/builtin.cmod:728:
REF_RETURN ID_FROM_INT(t->frame->current_object->prog, t->func)->name; } REF_RETURN ID_FROM_INT(func->u.object->prog, func->subtype)->name; } pop_n_elems(args); 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; if(func->u.object->prog == pike_trampoline_program) { struct object *o; o=((struct pike_trampoline *)func->u.object->storage)->frame->current_object; add_ref(o); pop_n_elems(args); push_object(o);
pike.git/src/builtin.cmod:777:
return; default: SIMPLE_BAD_ARG_ERROR("function_object",1,"function"); } pop_n_elems(args); 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. *! *! @seealso *! @[random_seed()] */ PIKEFUN mixed random(object o)