23. Introspection

23.1. Value inspection


Method arrayp

int arrayp(mixed arg)

Description

Returns 1 if arg is an array, 0 (zero) otherwise.

See also

intp(), programp(), mappingp(), stringp(), objectp(), multisetp(), floatp(), functionp()


Method callablep

int callablep(mixed arg)

Description

Returns 1 if arg is a callable, 0 (zero) otherwise.

See also

mappingp(), programp(), arrayp(), stringp(), objectp(), multisetp(), floatp(), intp()


Method destructedp

int destructedp(mixed arg)

Description

Returns 1 if arg is a destructed object, 0 (zero) otherwise.

See also

zero_type, undefinedp, intp


Method floatp

int floatp(mixed arg)

Description

Returns 1 if arg is a float, 0 (zero) otherwise.

See also

intp(), programp(), arrayp(), multisetp(), objectp(), mappingp(), stringp(), functionp()


Method functionp

int functionp(mixed arg)

Description

Returns 1 if arg is a function, 0 (zero) otherwise.

See also

mappingp(), programp(), arrayp(), stringp(), objectp(), multisetp(), floatp(), intp()


Method intp

int intp(mixed arg)

Description

Returns 1 if arg is an int, 0 (zero) otherwise.

See also

mappingp(), programp(), arrayp(), stringp(), objectp(), multisetp(), floatp(), functionp()


Method mappingp

int mappingp(mixed arg)

Description

Returns 1 if arg is a mapping, 0 (zero) otherwise.

See also

intp(), programp(), arrayp(), stringp(), objectp(), multisetp(), floatp(), functionp()


Method multisetp

int multisetp(mixed arg)

Description

Returns 1 if arg is a multiset, 0 (zero) otherwise.

See also

intp(), programp(), arrayp(), stringp(), objectp(), mappingp(), floatp(), functionp()


Method programp

int programp(mixed arg)

Description

Returns 1 if arg is a program, 0 (zero) otherwise.

See also

mappingp(), intp(), arrayp(), stringp(), objectp(), multisetp(), floatp(), functionp()


Method undefinedp

int undefinedp(mixed arg)

Description

Returns 1 if arg is undefined, 0 (zero) otherwise.

See also

zero_type, destructedp, intp


Method _typeof

type _typeof(mixed x)

Description

Return the runtime type of x.

See also

typeof()

23.2. Content inspection


Method indices

array indices(string|array|mapping|multiset|object x)

Description

Return an array of all valid indices for the value x.

Parameter x
string

For strings and arrays this is simply an array of ascending numbers.

mapping

For mappings and multisets, the array might contain any value.

object

For objects which define lfun::_indices() that return value is used.

For other objects an array with the names of all non-protected symbols is returned.

See also

values(), types(), lfun::_indices()


Method values

array values(string|array|mapping|multiset|object x)

Description

Return an array of all possible values from indexing the value x.

Parameter x
string

For strings an array of int with the ISO10646 codes of the characters in the string is returned.

multiset

For a multiset an array filled with ones (1) is returned.

array

For arrays a single-level copy of x is returned.

mapping

For mappings the array may contain any value.

object

For objects which define lfun::_values() that return value is used.

For other objects an array with the values of all non-protected symbols is returned.

See also

indices(), types(), lfun::_values()


Method types

array(type) types(string|array|mapping|multiset|object|program x)

Description

Return an array with the types of all valid indices for the value x.

Parameter x
string

For strings this is simply an array with int

array

For arrays, mappings and multisets this is simply an array with mixed.

object

For objects which define lfun::_types() that return value is used.

For other objects an array with type types for all non-protected symbols is returned.

Note

This function was added in Pike 7.9.

See also

indices(), values(), lfun::_types()


Method annotations

array(multiset(Pike.Annotation)) annotations(object|program|function(:void) x, bool|void recurse)

Description

Return an array with the annotations for all symbols in x.

Parameter x
object

For objects which define lfun::_annotations() that return value is used.

For other objects an array with annotations for all non-protected symbols is returned.

program

Returns an array with annotations for all non-protected constant symbols.

Parameter recurse

Include annotations recursively added via inherits.

Returns

The order of the resulting array is the same as that of indices() for the same x.

Note

This function was added in Pike 8.1.

See also

indices(), values(), types(), lfun::_annotations(), ::_annotations(), Program.annotations


Method get_weak_flag

int get_weak_flag(array|mapping|multiset m)

Description

Returns the weak flag settings for m. It's a combination of Pike.WEAK_INDICES and Pike.WEAK_VALUES.

23.3. Integer inspection


Method zero_type

int zero_type(mixed a)

Description

Return the type of zero.

There are many types of zeros out there, or at least there are two. One is returned by normal functions, and one returned by mapping lookups and find_call_out() when what you looked for wasn't there. The only way to separate these two kinds of zeros is zero_type().

Returns

When doing a find_call_out() or mapping lookup, zero_type() on this value will return 1 if there was no such thing present in the mapping, or if no such call_out could be found.

If the argument to zero_type() is a destructed object or a function in a destructed object, 2 will be returned.

In all other cases zero_type() will return 0 (zero).

See also

find_call_out()

23.4. Function inspection


Method function_name

string function_name(function(:void)|program f)

Description

Return the name of the function or program f.

If f is a global function defined in the runtime 0 (zero) will be returned.

See also

function_object()


Method function_object

object function_object(function(:void) f)

Description

Return the object the function f is in.

If f is a global function defined in the runtime 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.

See also

function_name(), function_program()


Method function_program

program function_program(function(:void)|program f)

Description

Return the program the function f is in.

If f is a global function defined in the runtime 0 (zero) will be returned.

See also

function_name(), function_object()

23.5. Object inspection


Method object_program

program|function(:void) object_program(mixed o)

Description

Return the program from which o was instantiated. If the object was instantiated from a class using parent references the generating function will be returned.

If o is not an object or has been destructed 0 (zero) will be returned.

23.6. Program inspection


Method get_profiling_info

array(int|mapping(string:array(int))) get_profiling_info(program prog)

Description

Get profiling information.

Returns

Returns an array with two elements.

Array
int num_clones

The first element is the number of times the program prog has been instantiated.

mapping(string:array(int)) fun_prof_info

The second element is mapping from function name to an array with three elements.

Array
int num_calls

The first element is the number of times the function has been called.

int total_time

The second element is the total time (in milliseconds) spent executing this function, and any functions called from it.

int self_time

The third element is the time (in milliseconds) actually spent in this function so far.

Note

This function is only available if the runtime was compiled with the option --with-profiling.


Method typeof_identifier

type|zero typeof_identifier(program p, string identifier)

Description

Allows access to the static type of an identifier ("member") in a program.

Returns

The static type of p->identifier, or UNDEFINED if it can not be determined, be it because identifier does not exist in p or for other reasons.

23.7. Type inspection


Method deprecated_typep

bool deprecated_typep(type t)

Description

Checks if the supplied type has the "deprecated" attribute. This would generally only be true in static types of identifiers that have been marked as __deprecated__.

Returns

1 if the type has the "deprecated" attribute, 0 otherwise.