16. The rest


Method sin

float sin(float f)

Description

Returns the sine value for f. f should be specified in radians.

See also

asin, cos, tan


Method asin

float asin(float f)

Description

Return the arcus sine value for f. The result will be in radians.

See also

sin, acos


Method cos

float cos(float f)

Description

Return the cosine value for f. f should be specified in radians.

See also

acos, sin, tan


Method acos

float acos(float f)

Description

Return the arcus cosine value for f. The result will be in radians.

See also

cos, asin


Method tan

float tan(float f)

Description

Returns the tangent value for f. f should be specified in radians.

See also

atan, sin, cos


Method atan

float atan(float f)

Description

Returns the arcus tangent value for f. The result will be in radians.

See also

tan, asin, acos, atan2


Method atan2

float atan2(float f1, float f2)

Description

Returns the arcus tangent value for f1/f2, and uses the signs of f1 and f2 to determine the quadrant. The result will be in radians.

See also

tan, asin, acos, atan


Method sqrt

float sqrt(float f)
int sqrt(int i)

Description

Returns the square root of f, or in the integer case, the square root truncated to the closest lower integer.

See also

pow, log, exp, floor


Method log

float log(float f)

Description

Return the natural logarithm of f.

exp( log(x) ) == x
for x > 0.

See also

pow, exp


Method exp

float exp(float f)

Description

Return the natural exponential of f.

log( exp( x ) ) == x
as long as exp(x) doesn't overflow an int.

See also

pow, log


Method pow

float pow(float|int n, float|int x)

Description

Return n raised to the power of x.

See also

exp, log


Method floor

float floor(float f)

Description

Return the closest integer value less or equal to f.

Note

floor does not return an int, merely an integer value stored in a float.

See also

ceil, round


Method ceil

float ceil(float f)

Description

Return the closest integer value greater or equal to f.

Note

ceil does not return an int, merely an integer value stored in a float.

See also

floor, round


Method round

float round(float f)

Description

Return the closest integer value to f.

Note

round does not return an int, merely an integer value stored in a float.

See also

floor, ceil


Method min

mixed min(mixed ... args)

Description

Returns the smallest value among args.

See also

max


Method max

mixed max(mixed ... args)

Description

Returns the largest value among args.

See also

min


Method abs

float abs(float f)
int abs(int f)
object abs(object f)

Description

Return the absolute value for f.


Method sgn

int sgn(mixed value)
int sgn(mixed value, mixed zero)

Description

Check the sign of a value.

Returns

Returns -1 if value is less than zero, 1 if value is greater than zero and 0 (zero) otherwise.

See also

abs


Method file_stat

Stdio.Stat file_stat(string path, void|int(0..1) symlink)

Description

Stat a file.

If the argument symlink is 1 symlinks will not be followed.

Returns

If the path specified by path doesn't exist 0 (zero) will be returned.

Otherwise an object describing the properties of path will be returned.

Note

In Pike 7.0 and earlier this function returned an array with 7 elements. The old behaviour can be simulated with the following function:

array(int) file_stat(string path, void|int(0..1) symlink)
         {
           File.Stat st = predef::file_stat(path, symlink);
           if (!st) return 0;
           return (array(int))st;
         }

See also

Stdio.Stat, Stdio.File.stat


Method file_truncate

int file_truncate(string file, int length)

Description

Truncates the file file to the length specified in length.

Returns

Returns 1 if ok, 0 if failed.


Method filesystem_stat

mapping(string:int) filesystem_stat(string path)

Description

Returns a mapping describing the properties of the filesystem containing the path specified by path.

Returns

If a filesystem cannot be determined 0 (zero) will be returned.

Otherwise a mapping(string:int) with the following fields will be returned:

"blocksize" : int

Size in bytes of the filesystem blocks.

"blocks" : int

Size of the entire filesystem in blocks.

"bfree" : int

Number of free blocks in the filesystem.

"bavail" : int

Number of available blocks in the filesystem. This is usually somewhat less than the "bfree" value, and can usually be adjusted with eg tunefs(1M).

"files" : int

Total number of files (aka inodes) allowed by this filesystem.

"ffree" : int

Number of free files in the filesystem.

"favail" : int

Number of available files in the filesystem. This is usually the same as the "ffree" value, and can usually be adjusted with eg tunefs(1M).

"fsname" : int

Name assigned to the filesystem.

"fstype" : int

Type of filesystem (eg "nfs").


Note

Please note that not all members are present on all OSs.

See also

file_stat


Method werror

void werror(string msg, mixed ... args)

Description

Write to standard error.


Method rm

int rm(string f)

Description

Remove a file or directory.

Returns

Returns 0 (zero) on failure, 1 otherwise.

See also

mkdir, Stdio.recursive_rm


Method mkdir

int mkdir(string dirname, void|int mode)

Description

Create a directory.

If mode is specified, it's will be used for the new directory after being &'ed with the current umask (on OS'es that support this).

Returns

Returns 0 (zero) on failure, 1 otherwise.

See also

rm, cd, Stdio.mkdirhier


Method get_dir

array(string) get_dir(string dirname)

Description

Returns an array of all filenames in the directory dirname, or 0 (zero) if the directory does not exist.

See also

mkdir, cd


Method cd

int cd(string s)

Description

Change the current directory for the whole Pike process.

Returns

Returns 1 for success, 0 (zero) otherwise.

See also

getcwd


Method getcwd

string getcwd()

Description

Returns the current working directory.

See also

cd


Method exece

int exece(string file, array(string) args)
int exece(string file, array(string) args, mapping(string:string) env)

Description

This function transforms the Pike process into a process running the program specified in the argument file with the arguments args.

If the mapping env is present, it will completely replace all environment variables before the new program is executed.

Returns

This function only returns if something went wrong during exece(2), and in that case it returns 0 (zero).

Note

The Pike driver _dies_ when this function is called. You must either use fork or Process.create_process if you wish to execute a program and still run the Pike runtime.

See also

Process.create_process, fork, Stdio.File.pipe


Method mv

int mv(string from, string to)

Description

Rename or move a file or directory.

If the destination already exists, it will be replaced. Replacement often only works if to is of the same type as from, i.e. a file can only be replaced by another file and so on. Also, a directory will commonly be replaced only if it's empty.

On some OSs this function can't move directories, only rename them.

Returns

Returns 0 (zero) on failure, 1 otherwise. Call errno to get more error info on failure.

See also

rm


Method strerror

string strerror(int errno)

Description

This function returns a description of an error code. The error code is usually obtained from eg Stdio.File.errno.

Note

On some platforms the string returned can be somewhat nondescriptive.


Method errno

int errno()

Description

This function returns the system error from the last file operation.

Note

Note that you should normally use Stdio.File.errno instead.

See also

Stdio.File.errno, strerror


Method sprintf

string sprintf(string format, mixed ... args)

Description

Print formated output to string.

The format string is a string containing a description of how to output the data in args. This string should generally speaking have one %<modifiers><operator> format specifier (examples: %s, %0d, %-=20s) for each of the arguments.

The following modifiers are supported:

'0'

Zero pad numbers (implies right justification).

'!'

Toggle truncation.

' '

Pad positive integers with a space.

'+'

Pad positive integers with a plus sign.

'-'

Left adjust within field size (default is right).

'|'

Centered within field size.

'='

Column mode if strings are greater than field size.

'/'

Rough line break (break at exactly field size instead of between words).

'#'

Table mode, print a list of '\n' separated word (top-to-bottom order).

'$'

Inverse table mode (left-to-right order).

'n'

(Where n is a number or *) field size specifier.

'.n'

Precision specifier.

':n'

Field size precision specifier.

';n'

Column width specifier.

'*'

If n is a * then next argument is used for precision/field size.

"'"

Set a pad string. ' cannot be a part of the pad string (yet).

'~'

Get pad string from argument list.

'<'

Use same argument again.

'^'

Repeat this on every line produced.

'@@'

Repeat this format for each element in the argument array.

'>'

Put the string at the bottom end of column instead of top.

'_'

Set width to the length of data.

'[n]'

Select argument number n. Use * to use the next argument as selector.


The following operators are supported:

'%'

Percent.

'b'

Signed binary integer.

'd'

Signed decimal integer.

'u'

Unsigned decimal integer.

'o'

Signed octal integer.

'x'

Lowercase signed hexadecimal integer.

'X'

Uppercase signed hexadecimal integer.

'c'

Character. If a fieldsize has been specified this will output the low-order bytes of the integer in network byte order.

'f'

Float.

'g'

Heuristically chosen representation of float.

'G'

Like %g, but uses uppercase E for exponent.

'e'

Exponential notation float.

'E'

Like %e, but uses uppercase E for exponent.

'F'

Binary IEEE representation of float (%4F gives single precision, %8F gives double precision.)

's'

String.

'O'

Any value (debug style).

'n'

No operation (ignore the argument).

't'

Type of the argument.

'{'

Perform the enclosed format for every element of the argument array.

'}'

Most modifiers and operators are combinable in any fashion, but some combinations may render strange results.

If an argument is an object that implements lfun::_sprintf, that callback will be called with the operator as the first argument, and the current modifiers as the second. The callback is expected to return a string.

Example

Pike v7.3 release 11 running Hilfe v2.0 (Incremental Pike Frontend) > int screen_width=70; Result: 70 > mixed sample; > write(sprintf("fish: %c\n", 65)); fish: A Result: 8 > write(sprintf("Hello green friends\n")); Hello green friends Result: 20 > write(sprintf("num: %d\n", 10)); num: 10 Result: 8 > write(sprintf("num: %+10d\n", 10)); num: +10 Result: 16 > write(sprintf("num: %010d\n", 5*2)); num: 0000000010 Result: 16 > write(sprintf("num: %|10d\n", 20/2)); num: 10 Result: 16 > write(sprintf("%|*s\n",screen_width,"THE NOT END")); THE NOT END Result: 71 > write(sprintf("%|=*s\n",screen_width, "fun with penguins\n")); fun with penguins Result: 71 > write(sprintf("%-=*O\n",screen_width,({ "fish", 9, "gumbies", 2 }))); ({ /* 4 elements */ "fish", 9, "gumbies", 2 }) Result: 426 > write(sprintf("%-=*s\n", screen_width, >> "This will wordwrap the specified string within the "+ >> "specified field size, this is useful say, if you let "+ >> "users specify their screen size, then the room "+ >> "descriptions will automagically word-wrap as appropriate.\n"+ >> "slosh-n's will of course force a new-line when needed.\n")); This will wordwrap the specified string within the specified field size, this is useful say, if you let users specify their screen size, then the room descriptions will automagically word-wrap as appropriate. slosh-n's will of course force a new-line when needed. Result: 355 > write(sprintf("%-=*s %-=*s\n", screen_width/2, >> "Two columns next to each other (any number of columns will "+ >> "of course work) independantly word-wrapped, can be useful.", >> screen_width/2-1, >> "The - is to specify justification, this is in addherence "+ >> "to std sprintf which defaults to right-justification, "+ >> "this version also supports centre and right justification.")); Two columns next to each other (any The - is to specify justification, number of columns will of course this is in addherence to std work) independantly word-wrapped, sprintf which defaults to can be useful. right-justification, this version also supports centre and right justification. Result: 426 > write(sprintf("%-$*s\n", screen_width, >> "Given a\nlist of\nslosh-n\nseparated\n'words',\nthis option\n"+ >> "creates a\ntable out\nof them\nthe number of\ncolumns\n"+ >> "be forced\nby specifying a\npresision.\nThe most obvious\n"+ >> "use is for\nformatted\nls output.")); Given a list of slosh-n separated 'words', this option creates a table out of them the number of columns be forced by specifying a presision. The most obvious use is for formatted ls output. Result: 312 > write(sprintf("%-#*s\n", screen_width, >> "Given a\nlist of\nslosh-n\nseparated\n'words',\nthis option\n"+ >> "creates a\ntable out\nof them\nthe number of\ncolumns\n"+ >> "be forced\nby specifying a\npresision.\nThe most obvious\n"+ >> "use is for\nformatted\nls output.")); Given a creates a by specifying a list of table out presision. slosh-n of them The most obvious separated the number of use is for 'words', columns formatted this option be forced ls output. Result: 312 > sample = ([ "align":"left", "valign":"middle" ]); Result: ([ /* 2 elements */ "align":"left", "valign":"middle" ]) > write(sprintf("<td%{ %s='%s'%}>\n", (array)sample)); <td valign='middle' align='left'> Result: 34 > write(sprintf("Of course all the simple printf options "+ >> "are supported:\n %s: %d %x %o %c\n", >> "65 as decimal, hex, octal and a char", >> 65, 65, 65, 65)); Of course all the simple printf options are supported: 65 as decimal, hex, octal and a char: 65 41 101 A Result: 106 > write(sprintf("%[0]d, %[0]x, %[0]X, %[0]o, %[0]c\n", 75)); 75, 4b, 4B, 113, K Result: 19 > write(sprintf("%|*s\n",screen_width, "THE END")); THE END Result: 71

See also

lfun::_sprintf


Method getgrgid

array(int|string|array(string)) getgrgid(int gid)

Description

Get the group entry for the group with the id gid using the systemfunction getgrid(3).

Parameter gid

The id of the group

Returns

An array with the information about the group

Array
string 0

Group name

string 1

Group password (encrypted)

int 2

ID of the group

array 3..

Array with UIDs of group members


See also

getgrent getgrnam


Method getgrnam

array(int|string|array(string)) getgrnam(string str)

Description

Get the group entry for the group with the name str using the systemfunction getgrnam(3).

Parameter str

The name of the group

Returns

An array with the information about the group

Array
string 0

Group name

string 1

Group password (encrypted)

int 2

ID of the group

array 3..

Array with UIDs of group members


See also

getgrent getgrgid


Method getpwnam

array(int|string) getpwnam(string str)

Description

Get the user entry for login str using the systemfunction getpwnam(3).

Parameter str

The login name of the user whos userrecord is requested.

Returns

An array with the information about the user

Array
string 0

Users username (loginname)

string 1

User password (encrypted)

int 2

Users ID

int 3

Users primary group ID

string 4

Users real name an possibly some other info

string 5

Users home directory

string 6

Users shell


See also

getpwuid getpwent


Method getpwuid

array(int|string) getpwuid(int uid)

Description

Get the user entry for UID uid using the systemfunction getpwuid(3).

Parameter uid

The uid of the user whos userrecord is requested.

Returns

An array with the information about the user

Array
string 0

Users username (loginname)

string 1

User password (encrypted)

int 2

Users ID

int 3

Users primary group ID

string 4

Users real name an possibly some other info

string 5

Users home directory

string 6

Users shell


See also

getpwnam getpwent


Method setpwent

int setpwent()

Description

Resets the getpwent function to the first entry in the passwd source using the systemfunction setpwent(3).

Returns

Always 0 (zero)

See also

getpwent endpwent


Method endpwent

int endpwent()

Description

Closes the passwd source opened by getpwent function using the systemfunction endpwent(3).

Returns

Always 0 (zero)

See also

getpwent setpwent


Method getpwent

array(int|string) getpwent()

Description

When first called, the getpwent function opens the passwd source and returns the first record using the systemfunction getpwent(3). For each following call, it returns the next record until EOF.

Call endpwent when done using getpwent.

Returns

An array with the information about the user

Array
string 0

Users username (loginname)

string 1

User password (encrypted)

int 2

Users ID

int 3

Users primary group ID

string 4

Users real name an possibly some other info

string 5

Users home directory

string 6

Users shell


0 if EOF.

See also

getpwnam getpwent setpwent endpwent


Method get_all_users

array(array(int|string)) get_all_users()

Description

Returns an array with all users in the system.

Returns

An array with arrays of userinfo as in getpwent.

See also

getpwent getpwnam getpwuid


Method setgrent

int setgrent()

Description

Rewinds the getgrent pointer to the first entry

See also

getgrent endgrent


Method endgrent

int endgrent()

Description

Closes the /etc/groups file after using the getgrent function.

See also

getgrent setgrent


Method getgrent

array(int|string|array(string)) getgrent()

Description

Get a group entry from /etc/groups file. getgrent interates thru the groups source and returns one entry per call using the systemfunction getgrent(3).

Always call endgrent when done using getgrent!

Returns

An array with the information about the group

Array
string 0

Group name

string 1

Group password (encrypted)

int 2

ID of the group

array 3..

Array with UIDs of group members


See also

getgrnam getgrgid


Method get_all_groups

array(array(int|string|array(string))) get_all_groups()

Description

Returns an array of arrays with all groups in the system groups source. Each element in the returned array has the same structure as in getgrent function.

Note

The groups source is system dependant. Refer to your system manuals for information about how to set the source.

Returns
Array
array(int|string|array(string)) 0..

Array with info about the group


See also

getgrent


Method get_groups_for_user

array(int) get_groups_for_user(int|string user)

Description

Gets all groups which a given user is a member of.

Parameter user

UID or loginname of the user

Returns
Array
array 0..

Information about all the users groups


See also

get_all_groups getgrgid getgrnam getpwuid getpwnam


Method equal

int equal(mixed a, mixed b)

Description

This function checks if the values a and b are equal.

For all types but arrays, multisets and mappings, this operation is the same as doing

a == b
. For arrays, mappings and multisets however, their contents are checked recursively, and if all their contents are the same and in the same place, they are considered equal.

See also

copy_value


Method aggregate

array aggregate(mixed ... elements)

Description

Construct an array with the arguments as indices.

This function could be written in Pike as:

array aggregate(mixed ... elems) { return elems; }

Note

Arrays are dynamically allocated there is no need to declare them like

int a[10]=allocate(10);
(and it isn't possible either) like in C, just
array(int) a=allocate(10);
will do.

See also

sizeof, arrayp, allocate


Method hash_7_0

int hash_7_0(string s)
int hash_7_0(string s, int max)

Description

This function will return an int derived from the string s. The same string will always hash to the same value. If max is given, the result will be >= 0 and < max, otherwise the result will be >= 0 and <= 0x7fffffff.

Note

This function is provided for backward compatibility reasons.

See also

hash


Method hash

int hash(string s)
int hash(string s, int max)

Description

This function will return an int derived from the string s. The same string will always hash to the same value. If max is given, the result will be >= 0 and < max, otherwise the result will be >= 0 and <= 0x7fffffff.

Note

The hash algorithm was changed in Pike 7.1. If you want a hash that is compatible with Pike 7.0 and earlier, use hash_7_0.

See also

hash_7_0


Method copy_value

mixed copy_value(mixed value)

Description

Copy a value recursively.

If the result value is changed destructively (only possible for multisets, arrays and mappings) the copied value will not be changed.

The resulting value will always be equal to the copied (as tested with the function equal), but they may not the the same value (as tested with `==).

See also

equal


Method lower_case

string lower_case(string s)

Description

Convert a string to lower case.

Returns

Returns a copy of the string s with all upper case characters converted to lower case.

See also

upper_case


Method upper_case

string upper_case(string s)

Description

Convert a string to upper case.

Returns

Returns a copy of the string s with all lower case characters converted to upper case.

See also

lower_case


Method random_string

string random_string(int len)

Description

Returns a string of random characters 0-255 with the length len.


Method random_seed

void random_seed(int seed)

Description

This function sets the initial value for the random generator.

See also

random


Method query_num_arg

int query_num_arg()

Description

Returns the number of arguments given when the previous function was called.

This is useful for functions that take a variable number of arguments.

See also

call_function


Method search

int search(string haystack, string|int needle, int|void start)
int search(array haystack, mixed needle, int|void start)
mixed search(mapping haystack, mixed needle, mixed|void start)

Description

Search for needle in haystack. Return the position of needle in haystack or -1 if not found.

If the optional argument start is present search is started at this position.

When haystack is a string needle must be a string or an int, and the first occurrence of the string or int is returned.

When haystack is an array, needle is compared only to one value at a time in haystack.

When haystack is a mapping, search tries to find the index connected to the data needle. That is, it tries to lookup the mapping backwards. If needle isn't present in the mapping, zero is returned, and zero_type() will return 1 for this zero.

See also

indices, values, zero_type


Method has_prefix

int has_prefix(string s, string prefix)

Description

Returns 1 if the string s starts with prefix, returns 0 (zero) otherwise.


Method has_suffix

int has_suffix(string s, string suffix)

Description

Returns 1 if the string s ends with suffix, returns 0 (zero) otherwise.


Method has_index

int has_index(string haystack, int index)
int has_index(array haystack, int index)
int has_index(mapping haystack, mixed index)

Description

Search for index in haystack.

Returns

Returns 1 if index is in the index domain of haystack, or 0 (zero) if not found.

This function is equivalent to (but sometimes faster than):

search(indices(haystack), index) != -1

Note

A negative index in strings and arrays as recognized by the index operators `[]() and `[]=() is not considered a proper index by has_index

See also

has_value, indices, search, values, zero_type


Method has_value

int has_value(string haystack, string value)
int has_value(string haystack, int value)
int has_value(array haystack, int value)
int has_value(mapping haystack, mixed value)

Description

Search for value in haystack.

Returns

Returns 1 if value is in the value domain of haystack, or 0 (zero) if not found.

This function is in all cases except when both arguments are strings equivalent to (but sometimes faster than):

search(values(haystack), value) != -1

If both arguments are strings, has_value is equivalent to:

search(haystack, value) != -1

See also

has_index, indices, search, values, zero_type


Method add_constant

void add_constant(string name, mixed value)
void add_constant(string name)

Description

Add a new predefined constant.

This function is often used to add builtin functions. All programs compiled after the add_constant function has been called can access value by the name name.

If there is a constant called name already, it will be replaced by by the new definition. This will not affect already compiled programs.

Calling add_constant without a value will remove that name from the list of constants. As with replacing, this will not affect already compiled programs.

See also

all_constants


Method combine_path
Method combine_path_unix
Method combine_path_nt

string combine_path(string absolute, string ... relative)
string combine_path_unix(string absolute, string ... relative)
string combine_path_nt(string absolute, string ... relative)

Description

Concatenate a relative path to an absolute path and remove any "//", "/.." or "/." to produce a straightforward absolute path as result.

combine_path_nt concatenates according to NT-filesystem conventions, while combine_path_unix concatenates according to UNIX-style.

combine_path is equvivalent to combine_path_unix on UNIX-like operating systems, and equvivalent to combine_path_nt on NT-like operating systems.

See also

getcwd, Stdio.append_path


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


Method string_to_unicode

string string_to_unicode(string s)

Description

Converts a string into an UTF16 compliant byte-stream.

Note

Throws an error if characters not legal in an UTF16 stream are encountered. Valid characters are in the range 0x00000 - 0x10ffff, except for characters 0xfffe and 0xffff.

Characters in range 0x010000 - 0x10ffff are encoded using surrogates.

See also

Locale.Charset.decoder, string_to_utf8, unicode_to_string, utf8_to_string


Method unicode_to_string

string unicode_to_string(string s)

Description

Converts an UTF16 byte-stream into a string.

Note

This function did not decode surrogates in Pike 7.2 and earlier.

See also

Locale.Charset.decoder, string_to_unicode, string_to_utf8, utf8_to_string


Method string_to_utf8

string string_to_utf8(string s)
string string_to_utf8(string s, int extended)

Description

Converts a string into an UTF8 compliant byte-stream.

Note

Throws an error if characters not valid in an UTF8 stream are encountered. Valid characters are in the range 0x00000000 - 0x7fffffff.

If extended is 1, characters in the range 0x80000000-0xfffffffff will also be accepted, and encoded using a non-standard UTF8 extension.

See also

Locale.Charset.encoder, string_to_unicode, unicode_to_string, utf8_to_string


Method utf8_to_string

string utf8_to_string(string s)
string utf8_to_string(string s, int extended)

Description

Converts an UTF8 byte-stream into a string.

Note

Throws an error if the stream is not a legal UFT8 byte-stream.

Accepts and decodes the extension used by string_to_utf8, if extended is 1.

See also

Locale.Charset.encoder, string_to_unicode, string_to_utf8, unicode_to_string


Method __parse_pike_type

string __parse_pike_type(string t)


Method all_constants

mapping(string:mixed) all_constants()

Description

Returns a mapping containing all global constants, indexed on the name of the constant, and with the value of the constant as value.

See also

add_constant


Method allocate

array allocate(int size)
array allocate(int size, mixed zero)

Description

Allocate an array of size elements and initialize them to zero.

See also

sizeof, aggregate, arrayp


Method rusage

array(int) rusage()

Description

Return resource usage.

Returns

Returns an array of ints describing how much resources the interpreter process has used so far. This array will have at least 29 elements, of which those values not available on this system will be zero.

The elements are as follows:

Array
int user_time

Time in milliseconds spent in user code.

int system_time

Time in milliseconds spent in system calls.

int maxrss

Maximum used resident size in kilobytes.

int ixrss

Quote from GNU libc: An integral value expressed in kilobytes times ticks of execution, which indicates the amount of memory used by text that was shared with other processes.

int idrss

Quote from GNU libc: An integral value expressed the same way, which is the amount of unshared memory used for data.

int isrss

Quote from GNU libc: An integral value expressed the same way, which is the amount of unshared memory used for stack space.

int minor_page_faults

Minor page faults, i.e. TLB misses which required no disk I/O.

int major_page_faults

Major page faults, i.e. paging with disk I/O required.

int swaps

Number of times the process was swapped out entirely.

int block_input_op

Number of block input operations.

int block_output_op

Number of block output operations.

int messages_sent

Number of IPC messsages sent.

int messages_received

Number of IPC messsages received.

int signals_received

Number of signals received.

int voluntary_context_switches

Number of voluntary context switches (usually to wait for some service).

int involuntary_context_switches

Number of preemptions, i.e. context switches due to expired time slices, or when processes with higher priority were scheduled.

int sysc

Number of system calls.

int ioch

?

int rtime

?

int ttime

?

int tftime

?

int dftime

?

int kftime

?

int ltime

?

int slptime

?

int wtime

?

int stoptime

?

int brksize

Heap size.

int stksize

Stack size.


The values will not be further explained here; read your system manual for more information.

Note

All values may not be present on all systems.

See also

time


Method this_object

object this_object(void|int level)

Description

Returns the object we are currently evaluating in.

level might be used to access the object of a surrounding class: The object at level 0 is the current object, the object at level 1 is the one belonging to the class surrounding the current class, and so on.


Method throw

void throw(mixed value)

Description

Throw value to a waiting catch.

If no catch is waiting the global error handling will send the value to master.

If you throw an array with where the first index contains an error message and the second index is a backtrace, (the output from backtrace) then it will be treated exactly like a real error by overlying functions.

See also

catch


Method exit

void exit(int returncode)

Description

Exit the whole Pike program with the given returncode.

Using exit with any other value than 0 (zero) indicates that something went wrong during execution. See your system manuals for more information about return codes.

See also

_exit


Method _exit

void _exit(int returncode)

Description

This function does the same as exit, but doesn't bother to clean up the Pike interpreter before exiting. This means that no destructors will be called, caches will not be flushed, file locks might not be released, and databases might not be closed properly.

Use with extreme caution.

See also

exit


Method time

int time()
int time(int(1..1) one)
float time(int(2..) t)

Description

This function returns the number of seconds since 1 Jan 1970.

The second syntax does not call the system call time() as often, but is only updated in the backed (when Pike code isn't running).

The third syntax can be used to measure time more preciely than one second. It return how many seconds has passed since t. The precision of this function varies from system to system.

See also

ctime, localtime, mktime, gmtime


Method crypt

string crypt(string password)
int(0..1) crypt(string typed_password, string crypted_password)

Description

This function crypts and verifies a short string (only the first 8 characters are significant).

The first syntax crypts the string password into something that is hopefully hard to decrypt.

The second syntax is used to verify typed_password against crypted_password, and returns 1 if they match, and 0 (zero) otherwise.


Method destruct

void destruct(object o)

Description

Mark an object as destructed.

Calls o->destroy(), and then clears all variables in the object.

All pointers and function pointers to this object will become zero. The destructed object will be freed from memory as soon as possible.


Method indices

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

Description

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

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

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

For objects which define lfun::_indices that return value will be used.

For other objects an array with all non-static symbols will be returned.

See also

values


Method values

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

Description

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

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

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

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

For mappings the array may contain any value.

For objects which define lfun::_values that return value will be used.

For other objects an array with the values of all non-static symbols will be returned.

See also

indices


Method next_object

object next_object(object o)
object next_object()

Description

Returns the next object from the list of all objects.

All objects are stored in a linked list.

Returns

If no arguments have been given next_object will return the first object from the list.

If o has been specified the object after o on the list will be returned.

Note

This function is not recomended to use.

See also

destruct


Method object_program

program object_program(mixed o)

Description

Return the program from which o was instantiated.

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


Method reverse

string reverse(string s)
array reverse(array a)
int reverse(int i)

Description

Reverses a string, array or int.

This function reverses a string, char by char, an array, value by value or an int, bit by bit and returns the result.

Reversing strings can be particularly useful for parsing difficult syntaxes which require scanning backwards.

See also

sscanf


Method replace

string replace(string s, string from, string to)
string replace(string s, array(string) from, array(string) to)
string replace(string s, mapping(string:string) replacements)
array replace(array a, mixed from, mixed to)
mapping replace(mapping a, mixed from, mixed to)

Description

Generic replace function.

This function can do several kinds replacement operations, the different syntaxes do different things as follows:

If all the arguments are strings, a copy of s with every occurrence of from replaced with to will be returned. Special case: to will be inserted between every character in s if from is the empty string.

If the first argument is a string, and the others array(string), a string with every occurrance of from[i] in s replaced with to[i] will be returned. Instead of the arrays from and to a mapping equvivalent to

mkmapping(from, to)
can be used.

If the first argument is an array or mapping, the values of a which are `== with from will be replaced with to destructively. a will then be returned.

Note

Note that replace on arrays and mappings is a destructive operation.


Method compile

program compile(string source, object|void handler, int|void major, int|void minor, program|void target, object|void placeholder)

Description

Compile a string to a program.

This function takes a piece of Pike code as a string and compiles it into a clonable program.

The optional argument handler is used to specify an alternative error handler. If it is not specified the current master object will be used.

The optional arguments major and minor are used to tell the compiler to attempt to be compatible with Pike major.minor.

Note

Note that source must contain the complete source for a program. It is not possible to compile a single expression or statement.

Also note that compile does not preprocess the program. To preprocess the program you can use compile_string or call the preprocessor manually by calling cpp.

See also

compile_string, compile_file, cpp, master


Method set_weak_flag

array|mapping|multiset set_weak_flag(array|mapping|multiset m, int state)

Description

Set the value m to use weak or normal references in its indices and/or values (whatever is applicable). state is a bitfield built by using | between the following flags:

Pike.WEAK_INDICES

Use weak references for indices. Only applicable for multisets and mappings.

Pike.WEAK_VALUES

Use weak references for values. Only applicable for arrays and mappings.

Pike.WEAK

Shorthand for Pike.WEAK_INDICES|Pike.WEAK_VALUES.


If a flag is absent, the corresponding field will use normal references. state can also be 1 as a compatibility measure; it's treated like Pike.WEAK.

Returns

m will be returned.


Method objectp

int objectp(mixed arg)

Description

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

See also

mappingp, programp, arrayp, stringp, functionp, multisetp, floatp, intp


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 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 sleep

void sleep(int|float s)

Description

This function makes the program stop for s seconds.

Only signal handlers can interrupt the sleep. Other callbacks are not called during sleep.

See also

signal


Method delay

void delay(int|float s)

Description

This function makes the program stop for s seconds.

Only signal handlers can interrupt the sleep. Other callbacks are not called during sleep. Beware that this function uses busy-waiting to achieve the highest possible accuracy.

See also

signal, sleep


Method gc

int gc()

Description

Force garbage collection.

This function checks all the memory for cyclic structures such as arrays containing themselves and frees them if appropriate. It also frees up destructed objects and things with only weak references. It then returns how many arrays/objects/programs/etc. it managed to free by doing this.

Normally there is no need to call this function since Pike will call it by itself every now and then. (Pike will try to predict when 20% of all arrays/object/programs in memory is 'garbage' and call this routine then.)


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