20. Introspection

20.1. Value inspection


Methodarrayp

intarrayp(mixedarg)

Description

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

See also

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


Methodcallablep

intcallablep(mixedarg)

Description

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

See also

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


Methoddestructedp

intdestructedp(mixedarg)

Description

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

See also

zero_type, undefinedp, intp


Methodfloatp

intfloatp(mixedarg)

Description

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

See also

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


Methodfunctionp

intfunctionp(mixedarg)

Description

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

See also

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


Methodintp

intintp(mixedarg)

Description

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

See also

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


Methodmappingp

intmappingp(mixedarg)

Description

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

See also

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


Methodmultisetp

intmultisetp(mixedarg)

Description

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

See also

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


Methodprogramp

intprogramp(mixedarg)

Description

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

See also

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


Methodundefinedp

intundefinedp(mixedarg)

Description

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

See also

zero_type, destructedp, intp


Method_typeof

type_typeof(mixedx)

Description

Return the runtime type of x.

See also

typeof()

20.2. Content inspection


Methodindices

arrayindices(string|array|mapping|multiset|objectx)

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()


Methodvalues

arrayvalues(string|array|mapping|multiset|objectx)

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()


Methodtypes

array(type) types(string|array|mapping|multiset|object|programx)

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()


Methodannotations

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

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()


Methodget_weak_flag

intget_weak_flag(array|mapping|multisetm)

Description

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

20.3. Integer inspection


Methodzero_type

intzero_type(mixeda)

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()

20.4. Function inspection


Methodfunction_name

stringfunction_name(function(:void)|programf)

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()


Methodfunction_object

objectfunction_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()


Methodfunction_program

programfunction_program(function(:void)|programf)

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()

20.5. Object inspection


Methodobject_program

program|function(:void) object_program(mixedo)

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.

20.6. Program inspection


Methodget_profiling_info

array(int|mapping(string:array(int))) get_profiling_info(programprog)

Description

Get profiling information.

Returns

Returns an array with two elements.

Array
intnum_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
intnum_calls

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

inttotal_time

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

intself_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.


Methodtypeof_identifier

typetypeof_identifier(programp, stringidentifier)

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.

20.7. Type inspection


Methoddeprecated_typep

int(..1)deprecated_typep(typet)

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.