| 17. The rest |
| Namespace 0.6:: |
Pike 0.6 compatibility.
The symbols in this namespace will appear in programs that use #pike 0.6 or lower.
7.0::
inherit 7.0:: :
array(mixed) aggregate(mixed ... args)
More lax types than in later versions.
| Module Array |
inherit Array : Array
array map(array x, int|string|function fun, mixed ... args)
Much simplified type compared to later versions of map.
| Namespace 7.6:: |
Pike 7.6 compatibility.
The symbols in this namespace will appear in programs that use #pike 7.6 or lower.
inherit predef:: :
| Module Stdio |
inherit Stdio.module : module
string read_file(string filename)
string read_file(string filename, int start, int len)
Read len lines from a file filename after skipping start lines and return those lines as a string. If both start and len are omitted the whole file is read.
read_bytes() , write_file()
string read_bytes(string filename, int start, int len)
string read_bytes(string filename, int start)
string read_bytes(string filename)
Read len number of bytes from the file filename starting at byte start , and return it as a string.
If len is omitted, the rest of the file will be returned.
If start is also omitted, the entire file will be returned.
Throws an error if filename isn't a regular file.
Returns 0 (zero) on failure to open filename .
Returns a string with the requested data otherwise.
read_file , write_file() , append_file()
int write_file(string filename, string str, int|void access)
Write the string str onto the file filename . Any existing data in the file is overwritten.
For a description of access , see Stdio.File()->open() .
Throws an error if filename couldn't be opened for writing.
Returns the number of bytes written.
append_file() , read_bytes() , Stdio.File()->open()
int append_file(string filename, string str, int|void access)
Append the string str onto the file filename .
For a description of access , see Stdio.File->open() .
Throws an error if filename couldn't be opened for writing.
Returns the number of bytes written.
write_file() , read_bytes() , Stdio.File()->open()
| Module Standards |
| Module Standards.UUID |
string new()
Return a new binary UUID.
string new_string()
Return a new UUID string.
| Module Calendar |
| Module Calendar.ISO |
This is the standard western calendar, which is a derivate of the Gregorian calendar, but with weeks that starts on Monday instead of Sunday.
inherit Calendar.Gregorian : Gregorian
| Module Calendar.YMD |
base for all Roman-kind of Calendars, ie, one with years, months, weeks and days
| CLASS Calendar.YMD.YMD |
Base (virtual) time period of the Roman-kind of calendar.
string format_iso_ymd()
string format_ymd()
string format_ymd_short()
string format_ymd_xshort()
string format_iso_week()
string format_iso_week_short()
string format_week()
string format_week_short()
string format_month()
string format_month_short()
string format_iso_time()
string format_time()
string format_time_short()
string format_time_xshort()
string format_mtime()
string format_xtime()
string format_tod()
string format_todz()
string format_xtod()
string format_mod()
Format the object into nice strings;
iso_ymd "2000-06-02 (Jun) -W22-5 (Fri)" [2]
ext_ymd "Friday, 2 June 2000" [2]
ymd "2000-06-02"
ymd_short "20000602"
ymd_xshort "000602" [1]
iso_week "2000-W22"
iso_week_short "2000W22"
week "2000-w22" [2]
week_short "2000w22" [2]
month "2000-06"
month_short "200006" [1]
iso_time "2000-06-02 (Jun) -W22-5 (Fri) 00:00:00 UTC+1" [2]
ext_time "Friday, 2 June 2000, 00:00:00" [2]
ctime "Fri Jun 2 00:00:00 2000\n" [2] [3]
http "Fri, 02 Jun 2000 00:00:00 GMT" [4]
time "2000-06-02 00:00:00"
time_short "20000602 00:00:00"
time_xshort "000602 00:00:00"
iso_short "2000-06-02T00:00:00"
mtime "2000-06-02 00:00"
xtime "2000-06-02 00:00:00.000000"
tod "00:00:00"
tod_short "000000"
todz "00:00:00 CET"
todz_iso "00:00:00 UTC+1"
xtod "00:00:00.000000"
mod "00:00"
[1] note conflict (think 1 February 2003)
[2] language dependent
[3] as from the libc function ctime()
[4] as specified by the HTTP standard;
not language dependent.
float fraction_no()
int hour_no()
int julian_day()
int leap_year()
int minute_no()
int month_day()
int month_no()
int second_no()
int utc_offset()
int week_day()
int week_no()
int year_day()
int year_no()
string month_name()
string month_shortname()
string month_day_name()
string week_day_name()
string week_day_shortname()
string week_name()
string year_name()
string tzname()
string tzname_iso()
function method int unix_time()
Returns the unix time integer corresponding to the start
of the time range object. (An unix time integer is UTC.)
function method datetime()
This gives back a mapping with the relevant
time information (representing the start of the period);
([ "year": int // year number (2000 AD=2000, 1 BC==0)
"month": int(1..) // month of year
"day": int(1..) // day of month
"yearday": int(0..) // day of year
"week": int(1..) // week of year
"week_day": int(0..) // day of week
"timezone": int // offset to utc, including dst
"unix": int // unix time
"julian": int // julian day
// for compatibility:
"hour": 0 // hour of day, including dst
"minute": 0 // minute of hour
"second": 0 // second of minute
"fraction": 0.0 // fraction of second
]);
Day of week is compatible with old versions, ie, 0 is sunday, 6 is saturday, so it shouldn't be used to calculate the day of the week with the given week number. Year day is also backwards compatible, ie, one (1) less then from the year_day() function.
Second second()
Second second(int n)
Minute minute(int hour, int minute, int second)
array(Second) seconds()
array(Second) seconds(int first, int last)
int number_of_seconds()
Minute minute()
Minute minute(int n)
Minute minute(int hour, int minute)
array(Minute) minutes()
array(Minute) minutes(int first, int last)
int number_of_minutes()
Hour hour()
Hour hour(int n)
array(Hour) hours()
array(Hour) hours(int first, int last)
int number_of_hours()
| CLASS Calendar.YMD.Year |
This is the time period of a year.
void Calendar.YMD.Year("unix", int unix_time)
void Calendar.YMD.Year("julian", int|float julian_day)
void Calendar.YMD.Year(int year)
void Calendar.YMD.Year(string year)
void Calendar.YMD.Year(TimeRange range)
It's possible to create the standard year by using three different methods; either the normal way - from standard unix time or the julian day, and also, for more practical use, from the year number.
Month month()
Month month(int n)
Month month(string name)
The Year type overloads the month() method, so it is possible to get a specified month by string:
year->month("April")
The integer and no argument behavior is inherited from YMD ().
Week week()
Week week(int n)
Week week(string name)
The Year type overloads the week() method, so it is possible to get a specified week by name:
year->week("17") year->week("w17")
The integer and no argument behavior is inherited from YMD ().
This is useful, since the first week of a year not always (about half the years, in the ISO calendar) is numbered '1'.
| CLASS Calendar.YMD.Week |
The Calendar week represents a standard time period of a week. In the Gregorian calendar, the standard week starts on a sunday and ends on a saturday; in the ISO calendar, it starts on a monday and ends on a sunday.
The week are might not be aligned to the year, and thus the week may cross year borders and the year of the week might not be the same as the year of all the days in the week. The basic rule is that the week year is the year that has the most days in the week, but since week number only is specified in the ISO calendar - and derivates - the week number of most calendars is the week number of most of the days in the ISO calendar, which modifies this rule for the Gregorian calendar; the week number and year is the same as for the ISO calendar, except for the sundays.
When adding, moving and subtracting months to a week, it falls back to using days.
When adding, moving or subtracting years, if tries to place the moved week in the resulting year.
void Calendar.YMD.Week("unix", int unix_time)
void Calendar.YMD.Week("julian", int|float julian_day)
void Calendar.YMD.Week(int year, int week)
It's possible to create the standard week by using three different methods; either the normal way - from standard unix time or the julian day, and also, for more practical use, from year and week number.
void Calendar.YMD.Week("unix", int unix_time)
void Calendar.YMD.Week("julian", int|float julian_day)
void Calendar.YMD.Week(int year, int month, int day)
void Calendar.YMD.Week(int year, int year_day)
void Calendar.YMD.Week(int julian_day)
It's possible to create the day by using five different methods; either the normal way - from standard unix time or the julian day, and also, for more practical use, from year, month and day, from year and day of year, and from julian day without extra fuzz.
Day day()
Day day(int n)
Day day(string name)
The Week type overloads the day() method, so it is possible to get a specified weekday by string:
week->day("sunday")
The integer and no argument behavior is inherited from YMD ().
the weekday-from-string routine is language dependent.
| CLASS Calendar.YMD.Hour |
global convinience functions
TimeRange parse(string fmt, string arg)
parse a date, create relevant object
fmt is in the format "abc%xdef..."
where abc and def is matched, and %x is
one of those time units:
%Y absolute year
%y dwim year (70-99 is 1970-1999, 0-69 is 2000-2069)
%M month (number, name or short name) (needs %y)
%W week (needs %y)
%D date (needs %y, %m)
%d short date (20000304, 000304)
%a day (needs %y)
%e weekday (needs %y, %w)
%h hour (needs %d, %D or %W)
%m minute (needs %h)
%s second (needs %m)
%S seconds since the Epoch (only combines with %f)
%f fraction of a second (needs %s or %S)
%t short time (205314, 2053)
%z zone
%p "am" or "pm"
%n empty string (to be put at the end of formats)
0 if format doesn't match data, or the appropriate time object.
The zone will be a guess if it doesn't state an exact regional timezone (like "Europe/Stockholm") - most zone abbriviations (like "CET") are used by more then one region with it's own daylight saving rules. Also beware that for instance CST can be up to four different zones, central Australia or America being the most common.
Abbreviation Interpretation
AMT America/Manaus [UTC-4]
AST America/Curacao [UTC-4]
CDT America/Costa_Rica [UTC-6]
CST America/El Salvador [UTC-6]
EST America/Panama [UTC-5]
GST Asia/Dubai [UTC+4]
IST Asia/Jerusalem [UTC+2]
WST Australia/Perth [UTC+8]
This mapping is modifiable in the ruleset, see
Ruleset.set_abbr2zone .
function Day dwim_day(string date)
function Day dwim_day(string date,TimeRange context)
Tries a number of different formats on the given date (in order):
parse format as in
"%y-%M-%D (%M) -W%W-%e (%e)" "2000-03-20 (Mar) -W12-1 (Mon)"
"%y-%M-%D" "2000-03-20", "00-03-20"
"%M%/%D/%y" "3/20/2000"
"%D%*[ /]%M%*[ /-,]%y" "20/3/2000" "20 mar 2000" "20/3 -00"
"%e%*[ ]%D%*[ /]%M%*[ /-,]%y" "Mon 20 Mar 2000" "Mon 20/3 2000"
"-%y%*[ /]%D%*[ /]%M" "-00 20/3" "-00 20 mar"
"-%y%*[ /]%M%*[ /]%D" "-00 3/20" "-00 march 20"
"%y%*[ /]%D%*[ /]%M" "00 20 mar" "2000 20/3"
"%y%*[ /]%M%*[ /]%D" "2000 march 20"
"%D%.%M.%y" "20.3.2000"
"%D%*[ -/]%M" "20/3" "20 mar" "20-03"
"%M%*[ -/]%D" "3/20" "march 20"
"%M-%D-%y" "03-20-2000"
"%D-%M-%y" "20-03-2000"
"%e%*[- /]%D%*[- /]%M" "mon 20 march"
"%e%*[- /]%M%*[- /]%D" "mon/march/20"
"%e%*[ -/wv]%W%*[ -/]%y" "mon w12 -00" "1 w12 2000"
"%e%*[ -/wv]%W" "mon w12"
"%d" "20000320", "000320"
"today" "today"
"last %e" "last monday"
"next %e" "next monday"
Casts exception if it fails to dwim out a day. "dwim" means do-what-i-mean.
function datetime(int|void unix_time)
Replacement for localtime; gives back a mapping:
([ "year": int // year number (2000 AD=2000, 1 BC==0)
"month": int(1..) // month of year
"day": int(1..) // day of month
"yearday": int(1..) // day of year
"week": int(1..) // week of year
"week_day": int(1..) // day of week (depending on calendar)
"unix": int // unix time
"julian": float // julian day
"hour": int(0..) // hour of day, including dst
"minute": int(0..59) // minute of hour
"second": int(0..59) // second of minute
"fraction": float // fraction of second
"timezone": int // offset to utc, including dst
]);
This is the same as calling Second ()->datetime ().
function datetime_name(int|void unix_time) function datetime_short_name(int|void unix_time) Compat functions; same as format_iso and format_iso_short .
function string format_iso(void|int unix_time)
function string format_iso_short(void|int unix_time)
function string format_iso_tod(void|int unix_time)
function string format_day_iso(void|int unix_time)
function string format_day_iso_short(void|int unix_time)
Format the object into nice strings;
iso "2000-06-02 (Jun) -W22-5 (Fri) 11:57:18 CEST"
iso_short "2000-06-02 11:57:18"
iso_tod "11:57:18"
| Module Calendar.Gregorian |
This is the standard conservative christian calendar, used regularly in some countries - USA, for instance - and which derivate - the ISO calendar - is used in most of Europe.
inherit Calendar.YMD : YMD
| Module Debug |
array(array(int|string)) describe_program(program p)
Debug function for showing the symbol table of a program.
| Module Image |
| CLASS Image.Image |
inherit Image.Image : Image
array(Image.Color) select_colors(int n)
Do (array)Image.Colortable(this, n) instead.
Image.Image map_closest(array(array(int)) t)
Do Image.Colortable(t)->map(this) instead.
Image.Image map_fast(array(array(int)) t)
Do Image.Colortable(t)->map(this) instead.
Image.Image map_fs(array(array(int)) t)
Do
Image.Colortable(t)->floyd_steinberg()->map(this)
instead.
| Module Protocols |
| Module Protocols.TELNET |
Pike 7.6 compatibility.
Some symbols in Protocols.TELNET that now are protected used to be visible in Pike 7.6 and earlier.
inherit Protocols.TELNET : TELNET
inherit predef::Protocols.TELNET : TELNET
Based on the current Protocols.TELNET.
| CLASS Protocols.TELNET.protocol |
Pike 7.6 compatibility version of Protocols.TELNET.protocol.
inherit TELNET::protocol : protocol
Based on the current Protocols.TELNET.protocol.
void Protocols.TELNET.protocol(object f, function(mixed:void) r_cb, function(mixed|void:string) w_cb, function(mixed|void:void) c_cb, mapping callbacks, mixed|void new_id)
create() used to be visible.
::create()
void setup()
setup() used to be visible.
::setup()
| CLASS Protocols.TELNET.LineMode |
Pike 7.6 compatibility version of Protocols.TELNET.LineMode.
inherit TELNET::LineMode : LineMode
Based on the current Protocols.TELNET.LineMode.
void Protocols.TELNET.LineMode(object f, function(mixed:void) r_cb, function(mixed|void:string) w_cb, function(mixed|void:void) c_cb, mapping callbacks, mixed|void new_id)
create() used to be visible.
::create()
void setup()
setup() used to be visible.
::setup()
| CLASS Protocols.TELNET.Readline |
Pike 7.6 compatibility version of Protocols.TELNET.Readline.
inherit TELNET::Readline : Readline
Based on the current Protocols.TELNET.Readline.
void Protocols.TELNET.Readline(object f, function(mixed:void) r_cb, function(mixed|void:string) w_cb, function(mixed|void:void) c_cb, mapping callbacks, mixed|void new_id)
create() used to be visible.
::create()
void setup()
setup() used to be visible.
::setup()
| Namespace 7.4:: |
Pike 7.4 compatibility.
The symbols in this namespace will appear in programs that use #pike 7.4 or lower.
inherit 7.6:: :
array(int) rusage()
Return resource usage. An error is thrown if it isn't supported or if the system fails to return any information.
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:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The values will not be further explained here; read your system manual for more information.
All values may not be present on all systems.
time() , System.getrusage()
int hash(string s)
int hash(string s, int max)
Return an integer derived from the string s . The same string will always hash to the same value, also between processes.
If max is given, the result will be >= 0 and < max , otherwise the result will be >= 0 and <= 0x7fffffff.
This function is provided for backward compatibility reasons.
This function is byte-order dependant for wide strings.
hash() , 7.0::hash()
| Module Stdio |
| CLASS Stdio.File |
The life length of the Fd instance has changed. In newer versions it's always the same as for the File instance. That can theoretically cause incompatibilities in code that uses File.dup and File.assign, which are deprecated and very rarely used.
inherit Stdio.File : File
| Module Standards |
| Module Standards.ASN1 |
| Module Standards.ASN1.Encode |
This module is obsolete. All code should use ASN1.Types instead.
| Module Standards.PKCS |
| Module Standards.PKCS.Signature |
inherit Standards.PKCS.Signature : Signature
string build_digestinfo(string msg, object hash)
In Pike 7.6 the hash is required to be a Crypto.Hash object.
| Module Crypto |
string crypt_md5(string pw, void|string salt)
From Pike 7.5 pw and salt are binary strings, so
the result is different if any of these includes "\0".
The return type is also changed from string to int|string. If the second argument is a hash, pw will be hashed with the salt from the hash and compared with the hash.
constant Crypto.string_to_hex
constant Crypto.hex_to_string
string des_parity(string s)
des_parity is removed. Instead there is Crypto.DES->fix_parity , but it always outputs a key sized string.
| CLASS Crypto.md4 |
inherit Nettle.MD4_State : MD4_State
| CLASS Crypto.idea_cbc |
Use Crypto.CBC(Crypto.IDEA) instead.
inherit Nettle.CBC : CBC
| CLASS Crypto.idea |
inherit Nettle.IDEA_State : IDEA_State
| CLASS Crypto.sha |
inherit Nettle.SHA1_State : SHA1_State
| CLASS Crypto.md5 |
inherit Nettle.MD5_State : MD5_State
| CLASS Crypto.cast |
inherit Nettle.CAST128_State : CAST128_State
| CLASS Crypto.des |
inherit Nettle.DES_State : DES_State
| CLASS Crypto.crypto |
inherit Nettle.Proxy : Proxy
| CLASS Crypto.des3 |
inherit Nettle.DES3_State : DES3_State
| CLASS Crypto.cbc |
inherit Nettle.CBC : CBC
| CLASS Crypto.des_cbc |
Use Crypto.CBC(Crypto.DES) instead.
inherit Nettle.CBC : CBC
| CLASS Crypto.invert |
Inversion crypto module.
string name()
Returns the string "INVERT".
int(8..8) query_block_size()
Returns the block size for the invert crypto (currently 8).
int(0..0) query_key_length()
Returns the minimum key length for the invert crypto.
Since this crypto doesn't use a key, this will be 0.
void set_encrypt_key(string key)
Set the encryption key (currently a no op).
void set_decrypt_key(string key)
Set the decryption key (currently a no op).
string crypt_block(string data)
De/encrypt the string data with the invert crypto (ie invert the string).
| CLASS Crypto.md2 |
inherit Nettle.MD2_State : MD2_State
| CLASS Crypto.substitution |
inherit Crypto.Substitution : Substitution
| CLASS Crypto.rijndael |
inherit Nettle.AES_State : AES_State
| CLASS Crypto.dsa |
| CLASS Crypto.rsa |
inherit Crypto.RSA : RSA
| CLASS Crypto.hmac |
inherit Crypto.HMAC : HMAC
| CLASS Crypto.des3_cbc |
Use Crypto.CBC(Crypto.DES3) instead.
inherit Nettle.CBC : CBC
| CLASS Crypto.arcfour |
inherit Nettle.ARCFOUR_State : ARCFOUR_State
| CLASS Crypto.aes |
inherit Nettle.AES_State : AES_State
| Module Crypto.koremutake |
inherit Crypto.Koremutake : Koremutake
| Module Crypto.randomness |
Assorted stronger or weaker randomnumber generators. These devices try to collect entropy from the environment. They differ in behaviour when they run low on entropy, /dev/random will block if it can't provide enough random bits, while /dev/urandom will degenerate into a reasonably strong pseudo random generator
string some_entropy()
Executes several programs (last -256, arp -a, netstat -anv, netstat -mv, netstat -sv, uptime, ps -fel, ps aux, vmstat -s, vmstat -M, iostat, iostat -cdDItx) to generate some entropy from their output. On Microsoft Windows the Windows cryptographic routines are called to generate random data.
RandomSource reasonably_random()
Returns a reasonably random random-source.
RandomSource really_random(int|void may_block)
Returns a really random random-source.
| CLASS Crypto.randomness.RandomSource |
Virtual class for randomness source object.
string read(int(0..) len)
Returns a string of length len with (pseudo) random values.
| CLASS Crypto.randomness.arcfour_random |
A pseudo random generator based on the arcfour crypto.
inherit Nettle.ARCFOUR_State : ARCFOUR_State
void Crypto.randomness.arcfour_random(string secret)
Initialize and seed the arcfour random generator.
string read(int len)
Return a string of the next len random characters from the arcfour random generator.
| Module Sql |
| CLASS Sql.sql |
inherit Sql.Sql : Sql
| Module Locale |
| Module Locale.Charset |
inherit Locale.Charset : Charset
constant Locale.Charset._encoder
| CLASS Locale.Charset.ascii |
This class does not exist in the Locale module in Pike 7.6.
| Module ADT |
| CLASS ADT.Heap |
inherit ADT.Heap : Heap
mixed top()
This method has been renamed to pop in Pike 7.6.
| Module Protocols |
| Module Protocols.SMTP |
| CLASS Protocols.SMTP.protocol |
inherit Protocols.SMTP.Protocol : Protocol
| CLASS Protocols.SMTP.client |
inherit Protocols.SMTP.Client : Client
| Module SSL |
| CLASS SSL.cipher |
Encryption and MAC algorithms used in SSL.
inherit "constants"
| CLASS SSL.sslfile |
Interface similar to Stdio.File.
inherit "cipher"
inherit SSL.connection : connection
| CLASS SSL.constants |
Protocol constants
| Module Array |
inherit Array : Array
array(array(array)) diff3_old(array mid, array left, array right)
This diff3 implementation is obsoleted by Array.diff3 .
| Module Thread |
inherit Thread : Thread
constant Thread.Mutex
The Mutex destruct behaviour in Pike 7.4 and below is different from 7.6 in that destructing a mutex destroys the key that is locking it.
| Namespace 7.0:: |
Pike 7.0 compatibility.
The symbols in this namespace will appear in programs that use #pike 7.0 or lower.
7.2::
inherit 7.2:: :
array(int) file_stat(string path, void|int symlink)
Stat a file (Pike 7.0 compatibility).
Returns an array with the following content:
| ||||||||||||||||
See predef::file_stat() for a full description of the array.
predef::file_stat()
string _typeof(mixed x)
Get the runtime type of a value (Pike 7.0 compatibility).
Returns the type of x as a string.
predef::_typeof()
mapping m_delete(mapping m, mixed x)
Delete an entry x from a mapping m (Pike 7.0 compatibility).
Returns m .
predef::m_delete()
int hash(string s, int|void f)
Calculate a hash of a string (Pike 7.0 compatibility).
This function is now available as predef::hash_7_0() .
predef::hash_7_0() , predef::hash()
int hash(string s)
int hash(string s, int max)
Return an integer derived from the string s . The same string always hashes to the same value, also between processes.
If max is given, the result will be >= 0 and < max , otherwise the result will be >= 0 and <= 0x7fffffff.
This function is provided for backward compatibility reasons.
This function is not NUL-safe, and is byte-order dependant.
hash() , 7.4::hash()
| Module Calendar |
This module implements calendar calculations, and base classes for time units.
This module exists only for backward compatibility with Pike 7.0.
| CLASS Calendar._TimeUnit |
Base class for units of time.
array(string) lesser()
Gives a list of methods to get lesser (shorter) time units.
ie, for a month, this gives back ({"day"})
and the method day(mixed n) gives back that
day object. The method days() gives back a
list of possible argument values to the method day.
Concurrently, Array.map(o->days(),o->day) gives
a list of day objects in the object o.
Ie:
array(string) lesser() - gives back a list of possible xxx's.
object xxxs() - gives back a list of possible n's.
object xxx(mixed n) - gives back xxx n
object xxx(object(Xxx) o) - gives back the corresponing xxx
The list of n's (as returned from xxxs) are always in order.
There are two n's with special meaning, 0 and -1. 0 always gives the first xxx, equal to my_obj->xxx(my_obj->xxxs()[0]), and -1 gives the last, equal to my_obj->xxx(my_obj->xxxs()[-1]).
To get all xxxs in the object, do something like
Array.map(my_obj->xxxs(),my_obj->xxx).
xxx(object) may return zero, if there was no correspondning xxx.
array(string) greater()
Gives a list of methods to get greater (longer) time units
from this object. For a month, this gives back ({"year"}),
thus the method month->year() gives the year object.
object next()
object prev()
object `+(int n)
object `-(int n)
object `-(object x)
next() and prev() give the logical next and previous object.
The `+() operator gives that logical relative object,
ie my_day+14 gives 14 days ahead.
`-() works the same way, but can also take an object
of the same type and give the difference as an integer.
| Module Calendar.Gregorian |
time units: <ref>Year</ref>, <ref>Month</ref>, <ref>Week</ref>, <ref>Day</ref>
object parse(string fmt, string arg)
parse a date, create relevant object fmt is in the format "abc%xdef..." where abc and def is matched, and %x is one of those time units: %Y absolute year %y year (70-99 is 1970-1999, 0-69 is 2000-2069) %M month (number, name or short name) (needs %y) %W week (needs %y) %D date (needs %y, %m) %a day (needs %y) %e weekday (needs %y, %w) %h hour (needs %d, %D or %W) %m minute (needs %h) %s second (needs %s)
mapping(string:int) datetime(int|void unix_time, int|void skip_extra)
Replacement for localtime() .
string datetime_name(int|void unix_time)
Replacement for ctime() .
string datetime_short_name(int|void unix_time)
Replacement for ctime.
| CLASS Calendar.Gregorian.Year |
A Calendar._TimeUnit .
Lesser units: <ref>Month</ref>, <ref>Week</ref>, <ref>Day</ref> Greater units: none
inherit _TimeUnit : _TimeUnit
| Module Calendar.Stardate |
time unit: TNGDate
| CLASS Calendar.Stardate.TNGDate |
Implements ST:TNG stardates. Can be used as create argument to Day.
inherit Calendar._TimeUnit : _TimeUnit
| Namespace predef:: |
constant TOKENIZE_KEEP_ESCAPES
Don't unquote backslash-sequences in quoted strings during tokenizing. This is used for bug-compatibility with Microsoft...
tokenize() , tokenize_labled()
void (array(string) headers, object from, int offset, int len, array(string) trailers, object to, function callback, mixed ... args)
Low-level implementation of Stdio.sendfile() .
Sends headers followed by len bytes starting at offset from the file from followed by trailers to the file to . When completed callback will be called with the total number of bytes sent as the first argument, followed by args .
Any of headers , from and trailers may be left out
by setting them to 0.
Setting offset to -1 means send from the current position in
from .
Setting len to -1 means send until from 's end of file is
reached.
Don't use this class directly! Use Stdio.sendfile() instead.
In Pike 7.7 and later the callback function will be called from the backend associated with to .
Stdio.sendfile()
array(string) listxattr(string file, void|int(0..1) symlink)
Return an array of all extended attributes set on the file
string getxattr(string file, string attr, void|int(0..1) symlink)
Return the value of a specified attribute, or 0 if it does not exist.
void removexattr(string file, string attr, void|int(0..1) symlink)
Remove the specified extended attribute.
void setxattr(string file, string attr, string value, int flags, void|int(0..1) symlink)
Set the attribute attr to the value value .
The flags parameter can be used to refine the semantics of the operation.
Stdio.XATTR_CREATE specifies a pure create, which fails if the named attribute exists already.
Stdio.XATTR_REPLACE specifies a pure replace operation, which fails if the named attribute does not already exist.
By default (no flags), the extended attribute will be created if need be, or will simply replace the value if the attribute exists.
1 if successful, 0 otherwise, setting errno.
Stdio.Stat file_stat(string path, void|int(0..1) symlink)
Stat a file.
If the argument symlink is 1 symlinks will not be followed.
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.
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;
}
Stdio.Stat , Stdio.File->stat()
int file_truncate(string file, int length)
Truncates the file file to the length specified in length .
Returns 1 if ok, 0 if failed.
mapping(string:int) filesystem_stat(string path)
Returns a mapping describing the properties of the filesystem containing the path specified by path .
If a filesystem cannot be determined 0 (zero) will be returned.
Otherwise a mapping(string:int) with the following fields will be returned:
|
Please note that not all members are present on all OSs.
file_stat()
int rm(string f)
Remove a file or directory.
Returns 0 (zero) on failure, 1 otherwise.
mkdir() , Stdio.recursive_rm()
int mkdir(string dirname, void|int mode)
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 0 (zero) on failure, 1 otherwise.
rm() , cd() , Stdio.mkdirhier()
array(string) get_dir(void|string dirname)
Returns an array of all filenames in the directory dirname , or
0 (zero) if the directory does not exist. When no
dirname is given, current work directory is used.
mkdir() , cd()
int cd(string s)
Change the current directory for the whole Pike process.
Returns 1 for success, 0 (zero) otherwise.
getcwd()
string getcwd()
Returns the current working directory.
cd()
int exece(string file, array(string) args)
int exece(string file, array(string) args, mapping(string:string) env)
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.
This function only returns if something went wrong during exece(2),
and in that case it returns 0 (zero).
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.
This function is not available on all platforms.
Process.create_process() , fork() , Stdio.File->pipe()
int mv(string from, string to)
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 0 (zero) on failure, 1 otherwise. Call
errno() to get more error info on failure.
rm()
string strerror(int errno)
This function returns a description of an error code. The error code is usually obtained from eg Stdio.File->errno() .
On some platforms the string returned can be somewhat nondescriptive.
int errno()
This function returns the system error from the last file operation.
Note that you should normally use Stdio.File->errno() instead.
Stdio.File->errno() , strerror()
float sin(float f)
Returns the sine value for f . f should be specified in radians.
asin() , cos() , tan()
float asin(float f)
Return the arcus sine value for f . The result will be in radians.
sin() , acos()
float cos(float f)
Return the cosine value for f . f should be specified in radians.
acos() , sin() , tan()
float acos(float f)
Return the arcus cosine value for f . The result will be in radians.
cos() , asin()
float tan(float f)
Returns the tangent value for f . f should be specified in radians.
atan() , sin() , cos()
float atan(float f)
Returns the arcus tangent value for f . The result will be in radians.
tan() , asin() , acos() , atan2()
float atan2(float f1, float f2)
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.
tan() , asin() , acos() , atan()
float sinh(float f)
Returns the hyperbolic sine value for f .
asinh() , cosh() , tanh()
float asinh(float f)
Return the hyperbolic arcus sine value for f .
sinh() , acosh()
float cosh(float f)
Return the hyperbolic cosine value for f .
acosh() , sinh() , tanh()
float acosh(float f)
Return the hyperbolic arcus cosine value for f .
cosh() , asinh()
float tanh(float f)
Returns the hyperbolic tangent value for f .
atanh() , sinh() , cosh()
float atanh(float f)
Returns the hyperbolic arcus tangent value for f .
tanh() , asinh() , acosh()
float sqrt(float f)
int sqrt(int i)
mixed sqrt(object o)
Returns the square root of f , or in the integer case, the square root truncated to the closest lower integer. If the argument is an object, the lfun _sqrt in the object will be called.
pow() , log() , exp() , floor() , lfun::_sqrt
float log(float f)
Return the natural logarithm of f .
exp( log(x) ) == x for x > 0.
pow() , exp()
float exp(float|int f)
Return the natural exponential of f .
log( exp( x ) ) == x as long as exp(x) doesn't overflow an int.
pow() , log()
int|float pow(float|int n, float|int x)
mixed pow(object n, float|int|object x)
Return n raised to the power of x . If both n and x are integers the result will be an integer. If n is an object its pow method will be called with x as argument.
exp() , log()
float floor(float f)
Return the closest integer value less or equal to f .
floor() does not return an int, merely an integer value
stored in a float.
ceil() , round()
float ceil(float f)
Return the closest integer value greater or equal to f .
ceil() does not return an int, merely an integer value
stored in a float.
floor() , round()
float round(float f)
Return the closest integer value to f .
round() does not return an int, merely an integer value
stored in a float.
floor() , ceil()
int|float|object limit(int|float|object minval, int|float|object x, int|float|object maxval)
Limits the value x so that it's between minval and maxval . If x is an object, it must implement the lfun::`< method.
max() and min()
int|float|object min(int|float|object ... args)
string min(string ... args)
int(0..0) min()
Returns the smallest value among args . Compared objects must implement the lfun::`< method.
max() and limit()
int|float|object max(int|float|object ... args)
string max(string ... args)
int(0..0) max()
Returns the largest value among args . Compared objects must implement the lfun::`< method.
min() and limit()
float abs(float f)
int abs(int f)
object abs(object f)
Return the absolute value for f . If f is an object it must implement lfun::`< and unary lfun::`- .
int sgn(mixed value)
int sgn(mixed value, mixed zero)
Check the sign of a value.
Returns -1 if value is less than zero ,
1 if value is greater than zero and 0
(zero) otherwise.
abs()
array(array(string)|string) tokenize(string code)
Tokenize a string of C tokens.
Returns an array with C-level tokens and the remainder (a partial token), if any.
array(array(string)|string) tokenize(string code)
Tokenize a string of Pike tokens.
Returns an array with Pike-level tokens and the remainder (a partial token), if any.
string sprintf(string format, mixed ... args)
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:
|
The following operators are supported:
|
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.
Pike v7.4 release 13 running Hilfe v3.5 (Incremental Pike Frontend) > sprintf("The unicode character %c has character code %04X.", 'A', 'A'); (1) Result: "The unicode character A has character code 0041." > sprintf("#%@02X is the HTML code for purple.", Image.Color.purple->rgb()); (2) Result: "#A020F0 is the HTML code for purple." > int n=4711; > sprintf("%d = hexadecimal %x = octal %o = %b binary", n, n, n, n); (3) Result: "4711 = hexadecimal 1267 = octal 11147 = 1001001100111 binary"
sprintf style formatting is applied by many formatting functions, such write() and werror .
The 'q' operator was added in Pike 7.7.
> write(#"Formatting examples: Left adjusted [%-10d] Centered [%|10d] Right adjusted [%10d] Zero padded [%010d] ", n, n, n, n); Formatting examples: Left adjusted [4711 ] Centered [ 4711 ] Right adjusted [ 4711] Zero padded [0000004711] (5) Result: 142 int screen_width=70; > write("%-=*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. (6) Result: 355 > write("%-=*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. (7) Result: 426 > write("%-$*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. (8) Result: 312 > write("%-#*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. (9) Result: 312 > sample = ([ "align":"left", "valign":"middle" ]); (10) Result: ([ /* 2 elements */ "align":"left", "valign":"middle" ]) > write("<td%{ %s='%s'%}>\n", (array)sample); <td valign='middle' align='left'> (11) Result: 34 > write("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 (12) Result: 106 > write("%[0]d, %[0]x, %[0]X, %[0]o, %[0]c\n", 75); 75, 4b, 4B, 113, K (13) Result: 19 > write("%|*s\n",screen_width, "THE END"); THE END (14) Result: 71
lfun::_sprintf()
array(int|string|array(string)) getgrgid(int gid)
Get the group entry for the group with the id gid using the systemfunction getgrid(3).
The id of the group
An array with the information about the group
| ||||||||||
getgrent() getgrnam()
array(int|string|array(string)) getgrnam(string str)
Get the group entry for the group with the name str using the systemfunction getgrnam(3).
The name of the group
An array with the information about the group
| ||||||||||
getgrent() getgrgid()
array(int|string) getpwnam(string str)
Get the user entry for login str using the systemfunction getpwnam(3).
The login name of the user whos userrecord is requested.
An array with the information about the user
| ||||||||||||||||
getpwuid() getpwent()
array(int|string) getpwuid(int uid)
Get the user entry for UID uid using the systemfunction getpwuid(3).
The uid of the user whos userrecord is requested.
An array with the information about the user
| ||||||||||||||||
getpwnam() getpwent()
array(array(int|string)) get_all_users()
Returns an array with all users in the system.
An array with arrays of userinfo as in getpwent .
getpwent() getpwnam() getpwuid()
array(array(int|string|array(string))) get_all_groups()
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.
The groups source is system dependant. Refer to your system manuals for information about how to set the source.
| ||||
getgrent()
array(int) get_groups_for_user(int|string user)
Gets all groups which a given user is a member of.
UID or loginname of the user
| ||||
get_all_groups() getgrgid() getgrnam() getpwuid() getpwnam()
int(0..1) connect_lock(void|int enable)
Enable or disable a mutex that serializes all ODBC SQLConnect calls (i.e. when ODBC connections are created). This lock might be necessary to work around bugs in ODBC drivers.
Enables the mutex if nonzero, disables it otherwise. The state is not changed if this argument is left out.
The old state of the flag.
This is currently enabled by default due to bugs in the current FreeTDS library (version 0.63), but that might change if the demand for this kludge ceases in the future. Therefore, if this setting is important to you then always set it explicitly. Hopefully most users don't need to bother with it.
multiset aggregate_multiset(mixed ... elems)
Construct a multiset with the arguments as indices. The multiset
will not contain any values. This method is most useful when
constructing multisets with map or similar; generally, the
multiset literal syntax is handier: (<elem1, elem2, ...>)
With it, it's also possible to construct a multiset with values:
(<index1: value1, index2: value2, ...>)
sizeof() , multisetp() , mkmultiset()
int(0..1) `!=(mixed arg1, mixed arg2, mixed ... extras)
Inequality test.
Every expression with the != operator becomes a call to
this function, i.e. a!=b is the same as
predef::`!=(a,b).
This is the inverse of `==() ; see that function for further details.
Returns 1 if the test is successful, 0
otherwise.
`==()
int(0..1) `==(mixed arg1, mixed arg2, mixed ... extras)
Equality test.
Every expression with the == operator becomes a call to
this function, i.e. a==b is the same as
predef::`==(a,b).
If more than two arguments are given, each argument is compared with the following one as described below, and the test is successful iff all comparisons are successful.
If the first argument is an object with an lfun::`==() , that function is called with the second as argument, unless the second argument is the same as the first argument. The test is successful iff its result is nonzero (according to `! ).
Otherwise, if the second argument is an object with an lfun::`==() , that function is called with the first as argument, and the test is successful iff its result is nonzero (according to `! ).
Otherwise, if the arguments are of different types, the test is unsuccessful. Function pointers to programs are automatically converted to program pointers if necessary, though.
Otherwise the test depends on the type of the arguments:
|
Returns 1 if the test is successful, 0
otherwise.
Floats and integers are not automatically converted to test
against each other, so e.g. 0==0.0 is false.
Programs are not automatically converted to types to be compared type-wise.
`!() , `!=()
int(0..1) `<(mixed arg1, mixed arg2, mixed ... extras)
Less than test.
Every expression with the < operator becomes a call to
this function, i.e. a<b is the same as
predef::`<(a,b).
Returns 1 if the test is successful, 0
otherwise.
`<=() , `>() , `>=()
int(0..1) `<=(mixed arg1, mixed arg2, mixed ... extras)
Less than or equal test.
Every expression with the <= operator becomes a call to
this function, i.e. a<=b is the same as
predef::`<=(a,b).
Returns 1 if the test is successful, 0
otherwise.
For total orders, e.g. integers, this is the inverse of `>() .
`<() , `>() , `>=()
int(0..1) `>(mixed arg1, mixed arg2, mixed ... extras)
Greater than test.
Every expression with the > operator becomes a call to
this function, i.e. a>b is the same as
predef::`>(a,b).
Returns 1 if the arguments are strictly decreasing, and
0 (zero) otherwise.
`<() , `<=() , `>=()
int(0..1) `>=(mixed arg1, mixed arg2, mixed ... extras)
Greater than or equal test.
Every expression with the >= operator becomes a call to
this function, i.e. a>=b is the same as
predef::`>=(a,b).
Returns 1 if the test is successful, 0
otherwise.
For total orders, e.g. integers, this is the inverse of `<() .
`<=() , `>() , `<()
mixed `+(mixed arg)
mixed `+(object arg, mixed ... more)
int `+(int arg, int ... more)
float `+(float|int arg, float|int ... more)
string `+(string|float|int arg, string|float|int ... more)
array `+(array arg, array ... more)
mapping `+(mapping arg, mapping ... more)
multiset `+(multiset arg, multiset ... more)
Addition/concatenation.
Every expression with the + operator becomes a call to
this function, i.e. a+b is the same as
predef::`+(a,b). Longer + expressions are
normally optimized to one call, so e.g. a+b+c becomes
predef::`+(a,b,c).
If there's a single argument, that argument is returned.
If arg is an object with only one reference and an lfun::`+=() , that function is called with the rest of the arguments, and its result is returned.
Otherwise, if arg is an object with an lfun::`+() , that function is called with the rest of the arguments, and its result is returned.
Otherwise, if any of the other arguments is an object that has an lfun::``+() , the first such function is called with the arguments leading up to it, and `+() is then called recursively with the result and the rest of the arguments.
Otherwise, if arg is UNDEFINED and the other arguments are
either arrays, mappings or multisets, the first argument is
ignored and the remaining are added together as described below.
This is useful primarily when appending to mapping values since
m[x] += ({foo}) will work even if m[x] doesn't
exist yet.
Otherwise the result depends on the argument types:
|
The function is not destructive on the arguments - the result is always a new instance.
In Pike 7.0 and earlier the addition order was unspecified.
The treatment of UNDEFINED was new in Pike 7.0.
`-() , lfun::`+() , lfun::``+()
mixed `-(mixed arg1)
mixed `-(mixed arg1, mixed arg2, mixed ... extras)
mixed `-(object arg1, mixed arg2)
mixed `-(mixed arg1, object arg2)
int `-(int arg1, int arg2)
float `-(float arg1, int|float arg2)
float `-(int|float arg1, float arg2)
string `-(string arg1, string arg2)
array `-(array arg1, array arg2)
mapping `-(mapping arg1, array arg2)
mapping `-(mapping arg1, mapping arg2)
mapping `-(mapping arg1, multiset arg2)
multiset `-(multiset arg1, multiset arg2)
Negation/subtraction/set difference.
Every expression with the - operator becomes a call to
this function, i.e. -a is the same as
predef::`-(a) and a-b is the same as
predef::`-(a,b). Longer - expressions are
normally optimized to one call, so e.g. a-b-c becomes
predef::`-(a,b,c).
If there's a single argument, that argument is returned negated. If arg1 is an object with an lfun::`-() , that function is called without arguments, and its result is returned.
If there are more than two arguments the result is:
`-(`-(arg1 , arg2 ), @extras ).
Otherwise, if arg1 is an object with an lfun::`-() , that function is called with arg2 as argument, and its result is returned.
Otherwise, if arg2 is an object with an lfun::``-() , that function is called with arg1 as argument, and its result is returned.
Otherwise the result depends on the argument types:
arg1 can have any of the following types:
|
The function is not destructive on the arguments - the result is always a new instance.
In Pike 7.0 and earlier the subtraction order was unspecified.
`+()
mixed `&(mixed arg1)
mixed `&(mixed arg1, mixed arg2, mixed ... extras)
mixed `&(object arg1, mixed arg2)
mixed `&(mixed arg1, object arg2)
int `&(int arg1, int arg2)
string `&(string arg1, string arg2)
array `&(array arg1, array arg2)
mapping `&(mapping arg1, mapping arg2)
mapping `&(mapping arg1, array arg2)
mapping `&(mapping arg1, multiset arg2)
multiset `&(multiset arg1, multiset arg2)
type(mixed) `&(type(mixed)|program arg1, type(mixed)|program arg2)
Bitwise and/intersection.
Every expression with the & operator becomes a call to
this function, i.e. a&b is the same as
predef::`&(a,b).
If there's a single argument, that argument is returned.
If there are more than two arguments the result is:
`&(`&(arg1 , arg2 ), @extras ).
Otherwise, if arg1 is an object with an lfun::`&() , that function is called with arg2 as argument, and its result is returned.
Otherwise, if arg2 is an object with an lfun::``&() , that function is called with arg1 as argument, and its result is returned.
Otherwise the result depends on the argument types:
arg1 can have any of the following types:
|
The function is not destructive on the arguments - the result is always a new instance.
`|() , lfun::`&() , lfun::``&()
mixed `|(mixed arg1)
mixed `|(mixed arg1, mixed arg2, mixed ... extras)
mixed `|(object arg1, mixed arg2)
mixed `|(mixed arg1, object arg2)
int `|(int arg1, int arg2)
string `|(string arg1, string arg2)
array `|(array arg1, array arg2)
mapping `|(mapping arg1, mapping arg2)
multiset `|(multiset arg1, multiset arg2)
type(mixed) `|(program|type(mixed) arg1, program|type(mixed) arg2)
Bitwise or/union.
Every expression with the | operator becomes a call to
this function, i.e. a|b is the same as
predef::`|(a,b).
If there's a single argument, that argument is returned.
If there are more than two arguments, the result is:
`|(`|(arg1 , arg2 ), @extras ).
Otherwise, if arg1 is an object with an lfun::`|() , that function is called with arg2 as argument, and its result is returned.
Otherwise, if arg2 is an object with an lfun::``|() , that function is called with arg1 as argument, and its result is returned.
Otherwise the result depends on the argument types:
arg1 can have any of the following types:
|
The function is not destructive on the arguments - the result is always a new instance.
`&() , lfun::`|() , lfun::``|()
mixed `^(mixed arg1)
mixed `^(mixed arg1, mixed arg2, mixed ... extras)
mixed `^(object arg1, mixed arg2)
mixed `^(mixed arg1, object arg2)
int `^(int arg1, int arg2)
string `^(string arg1, string arg2)
array `^(array arg1, array arg2)
mapping `^(mapping arg1, mapping arg2)
multiset `^(multiset arg1, multiset arg2)
type(mixed) `^(program|type(mixed) arg1, program|type(mixed) arg2)
Exclusive or.
Every expression with the ^ operator becomes a call to
this function, i.e. a^b is the same as
predef::`^(a,b).
If there's a single argument, that argument is returned.
If there are more than two arguments, the result is:
`^(`^(arg1 , arg2 ), @extras ).
Otherwise, if arg1 is an object with an lfun::`^() , that function is called with arg2 as argument, and its result is returned.
Otherwise, if arg2 is an object with an lfun::``^() , that function is called with arg1 as argument, and its result is returned.
Otherwise the result depends on the argument types:
arg1 can have any of the following types:
|
The function is not destructive on the arguments - the result is always a new instance.
`&() , `|() , lfun::`^() , lfun::``^()
int `<<(int arg1, int arg2)
mixed `<<(object arg1, int|object arg2)
mixed `<<(int arg1, object arg2)
Left shift.
Every expression with the << operator becomes a call to
this function, i.e. a<<b is the same as
predef::`<<(a,b).
If arg1 is an object that implements lfun::`<<() , that function will be called with arg2 as the single argument.
If arg2 is an object that implements lfun::``<<() , that function will be called with arg1 as the single argument.
Otherwise arg1 will be shifted arg2 bits left.
`>>()
int `>>(int arg1, int arg2)
mixed `>>(object arg1, int|object arg2)
mixed `>>(int arg1, object arg2)
Right shift.
Every expression with the >> operator becomes a call to
this function, i.e. a>>b is the same as
predef::`>>(a,b).
If arg1 is an object that implements lfun::`>>() , that function will be called with arg2 as the single argument.
If arg2 is an object that implements lfun::``>>() , that function will be called with arg1 as the single argument.
Otherwise arg1 will be shifted arg2 bits right.
`<<()
mixed `*(mixed arg1)
mixed `*(object arg1, mixed arg2, mixed ... extras)
mixed `*(mixed arg1, object arg2)
array `*(array arg1, int arg2)
array `*(array arg1, float arg2)
string `*(string arg1, int arg2)
string `*(string arg1, float arg2)
string `*(array(string) arg1, string arg2)
array `*(array(array) arg1, array arg2)
float `*(float arg1, int|float arg2)
float `*(int arg1, float arg2)
int `*(int arg1, int arg2)
mixed `*(mixed arg1, mixed arg2, mixed ... extras)
Multiplication/repetition/implosion.
Every expression with the * operator becomes a call to
this function, i.e. a*b is the same as
predef::`*(a,b). Longer * expressions are
normally optimized to one call, so e.g. a*b*c becomes
predef::`*(a,b,c).
If there's a single argument, that argument will be returned.
If the first argument is an object that implements lfun::`*() , that function will be called with the rest of the arguments.
If there are more than two arguments, the result will be
`*(`*(arg1 , arg2 ), @extras ).
If arg2 is an object that implements lfun::``*() , that function will be called with arg1 as the single argument.
Otherwise the result will be as follows:
arg1 can have any of the following types:
|
In Pike 7.0 and earlier the multiplication order was unspecified.
`+() , `-() , `/() , lfun::`*() , lfun::``*()
mixed `/(object arg1, mixed arg2)
mixed `/(mixed arg1, object arg2)
array(string) `/(string arg1, int arg2)
array(string) `/(string arg1, float arg2)
array(array) `/(array arg1, int arg2)
array(array) `/(array arg1, float arg2)
array(string) `/(string arg1, string arg2)
array(array) `/(array arg1, array arg2)
float `/(float arg1, int|float arg2)
float `/(int arg1, float arg2)
int `/(int arg1, int arg2)
mixed `/(mixed arg1, mixed arg2, mixed ... extras)
Division/split.
Every expression with the / operator becomes a call to
this function, i.e. a/b is the same as
predef::`/(a,b).
If there are more than two arguments, the result will be
`/(`/(arg1 , arg2 ), @extras ).
If arg1 is an object that implements lfun::`/() , that function will be called with arg2 as the single argument.
If arg2 is an object that implements lfun::``/() , that function will be called with arg1 as the single argument.
Otherwise the result will be as follows:
arg1 can have any of the following types:
|
Unlike in some languages, the function f(x) = x/n (x and n integers) behaves in a well-defined way and is always rounded down. When you increase x, f(x) will increase with one for each n:th increment. For all x, (x + n) / n = x/n + 1; crossing zero is not special. This also means that / and % are compatible, so that a = b*(a/b) + a%b for all a and b.
`%
mixed `%(object arg1, mixed arg2)
mixed `%(mixed arg1, object arg2)
string `%(string arg1, int arg2)
array `%(array arg1, int arg2)
float `%(float arg1, float|int arg2)
float `%(int arg1, float arg2)
int `%(int arg1, int arg2)
Modulo.
Every expression with the % operator becomes a call to
this function, i.e. a%b is the same as
predef::`%(a,b).
If arg1 is an object that implements lfun::`%() then that function will be called with arg2 as the single argument.
If arg2 is an object that implements lfun::``%() then that function will be called with arg2 as the single argument.
Otherwise the result will be as follows:
arg1 can have any of the following types:
|
For numbers, this means that
a % b always has the same sign as b (typically b is positive; array size, rsa modulo, etc, and a varies a lot more than b).
The function f(x) = x % n behaves in a sane way; as x increases, f(x) cycles through the values 0,1, ..., n-1, 0, .... Nothing strange happens when you cross zero.
The % operator implements the binary "mod" operation, as defined by Donald Knuth (see the Art of Computer Programming, 1.2.4). It should be noted that Pike treats %-by-0 as an error rather than returning 0, though.
/ and % are compatible, so that a = b*(a/b) + a%b for all a and b.
`/
int(0..1) `!(object|function arg)
int(1..1) `!(int(0..0) arg)
int(0..0) `!(mixed arg)
Logical not.
Every expression with the ! operator becomes a call to
this function, i.e. !a is the same as
predef::`!(a).
It's also used when necessary to test truth on objects, i.e. in
a statement if (o) ... where o is an object, the
test becomes the equivalent of !!o so that any
lfun::`!() the object might have gets called.
If arg is an object that implements lfun::`!() , that function will be called.
If arg is 0 (zero), a destructed object, or a function in a
destructed object, 1 will be returned.
Otherwise 0 (zero) will be returned.
No float is considered false, not even 0.0.
`==() , `!=() , lfun::`!()
mixed `~(object arg)
int `~(int arg)
float `~(float arg)
type(mixed) `~(type(mixed)|program arg)
string `~(string arg)
Complement/inversion.
Every expression with the ~ operator becomes a call to
this function, i.e. ~a is the same as
predef::`~(a).
The result will be as follows:
arg can have any of the following types:
|
`!() , lfun::`~()
mixed `[..](object arg, mixed start, int start_type, mixed end, int end_type)
string `[..](string arg, int start, int start_type, int end, int end_type)
array `[..](array arg, int start, int start_type, int end, int end_type)
Extracts a subrange.
This is the function form of expressions with the [..]
operator. arg is the thing from which the subrange is to be
extracted. start is the lower bound of the subrange and
end the upper bound.
start_type and end_type specifies how the start and end indices, respectively, are to be interpreted. The types are either Pike.INDEX_FROM_BEG , Pike.INDEX_FROM_END or Pike.OPEN_BOUND . In the last case, the index value is insignificant.
The relation between [..] expressions and this function
is therefore as follows:
a[i..j] <=> `[..] (a, i, Pike.INDEX_FROM_BEG, j, Pike.INDEX_FROM_BEG)
a[i..<j] <=> `[..] (a, i, Pike.INDEX_FROM_BEG, j, Pike.INDEX_FROM_END)
a[i..] <=> `[..] (a, i, Pike.INDEX_FROM_BEG, 0, Pike.OPEN_BOUND)
a[<i..j] <=> `[..] (a, i, Pike.INDEX_FROM_END, j, Pike.INDEX_FROM_BEG)
a[<i..<j] <=> `[..] (a, i, Pike.INDEX_FROM_END, j, Pike.INDEX_FROM_END)
a[<i..] <=> `[..] (a, i, Pike.INDEX_FROM_END, 0, Pike.OPEN_BOUND)
a[..j] <=> `[..] (a, 0, Pike.OPEN_BOUND, j, Pike.INDEX_FROM_BEG)
a[..<j] <=> `[..] (a, 0, Pike.OPEN_BOUND, j, Pike.INDEX_FROM_END)
a[..] <=> `[..] (a, 0, Pike.OPEN_BOUND, 0, Pike.OPEN_BOUND)
The subrange is specified as follows by the two bounds:
If the lower bound refers to an index before the lowest allowable (typically zero) then it's taken as an open bound which starts at the first index (without any error).
Correspondingly, if the upper bound refers to an index past the last allowable then it's taken as an open bound which ends at the last index (without any error).
If the lower bound is less than or equal to the upper bound, then the subrange is the inclusive range between them, i.e. from and including the element at the lower bound and up to and including the element at the upper bound.
If the lower bound is greater than the upper bound then the result is an empty subrange (without any error).
The returned value depends on the type of arg :
arg can have any of the following types:
|
lfun::`[..] , `[]
mixed `[](object arg, mixed index)
mixed `[](object arg, string index)
function `[](int arg, string index)
int `[](string arg, int index)
mixed `[](array arg, int index)
mixed `[](array arg, mixed index)
mixed `[](mapping arg, mixed index)
int(0..1) `[](multiset arg, mixed index)
mixed `[](program arg, string index)
mixed `[](object arg, mixed start, mixed end)
string `[](string arg, int start, int end)
array `[](array arg, int start, int end)
Indexing.
This is the function form of expressions with the []
operator, i.e. a[i] is the same as
predef::`[](a,i).
If arg is an object that implements lfun::`[]() , that function is called with the index argument.
Otherwise, the action depends on the type of arg :
arg can have any of the following types:
|
As a compatibility measure, this function also performs range operations if it's called with three arguments. In that case it becomes equivalent to:
`[..] (arg, start, Pike.INDEX_FROM_BEG , end, Pike.INDEX_FROM_BEG )
See `[..] for further details.
An indexing expression in an lvalue context, i.e. where the index is being assigned a new value, uses `[]= instead of this function.
`->() , lfun::`[]() , `[]= , `[..]
mixed `->(object arg, string index)
mixed `->(int arg, string index)
mixed `->(array arg, string index)
mixed `->(mapping arg, string index)
int(0..1) `->(multiset arg, string index)
mixed `->(program arg, string index)
Arrow indexing.
Every non-lvalue expression with the -> operator becomes
a call to this function. a->b is the same as
predef::`^(a,"b") where "b" is the symbol
b in string form.
This function behaves like `[] , except that the index is passed literally as a string instead of being evaluated.
If arg is an object that implements lfun::`->() , that function will be called with index as the single argument.
Otherwise the result will be as follows:
arg can have any of the following types:
|
In an expression a->b, the symbol b can be any
token that matches the identifier syntax - keywords are
disregarded in that context.
An arrow indexing expression in an lvalue context, i.e. where the index is being assigned a new value, uses `->= instead of this function.
`[]() , lfun::`->() , ::`->() , `->=
mixed `[]=(object arg, mixed index, mixed val)
mixed `[]=(object arg, string index, mixed val)
mixed `[]=(array arg, int index, mixed val)
mixed `[]=(mapping arg, mixed index, mixed val)
int(0..1) `[]=(multiset arg, mixed index, int(0..1) val)
Index assignment.
Every lvalue expression with the [] operator becomes a
call to this function, i.e. a[b]=c is the same as
predef::`[]=(a,b,c).
If arg is an object that implements lfun::`[]=() , that function will be called with index and val as the arguments.
arg can have any of the following types:
|
val will be returned.
An indexing expression in a non-lvalue context, i.e. where the index is being queried instead of assigned, uses `[] instead of this function.
`->=() , lfun::`[]=() , `[]
mixed `->=(object arg, string index, mixed val)
mixed `->=(mapping arg, string index, mixed val)
int(0..1) `->=(multiset arg, string index, int(0..1) val)
Arrow index assignment.
Every lvalue expression with the -> operator becomes a
call to this function, i.e. a->b=c is the same as
predef::`->=(a,"b",c) where "b" is the symbol
b in string form.
This function behaves like `[]= , except that the index is passed literally as a string instead of being evaluated.
If arg is an object that implements lfun::`->=() , that function will be called with index and val as the arguments.
arg can have any of the following types:
|
val will be returned.
In an expression a->b=c, the symbol b can be any
token that matches the identifier syntax - keywords are
disregarded in that context.
An arrow indexing expression in a non-lvalue context, i.e. where the index is being queried instead of assigned, uses `-> instead of this function.
`[]=() , lfun::`->=() , `->
int sizeof(string arg)
int sizeof(array arg)
int sizeof(mapping arg)
int sizeof(multiset arg)
int sizeof(object arg)
Size query.
The result will be as follows:
arg can have any of the following types:
|
lfun::_sizeof()
string encode_value(mixed value, Codec|void codec)
Code a value into a string.
This function takes a value, and converts it to a string. This string can then be saved, sent to another Pike process, packed or used in any way you like. When you want your value back you simply send this string to decode_value() and it will return the value you encoded.
Almost any value can be coded, mappings, floats, arrays, circular structures etc.
If codec is specified, it's used as the codec for the decode. If no codec is specified, the current master object will be used.
If codec ->nameof(o) returns UNDEFINED for an
object, val = o->encode_object(o) will be called. The
returned value will be passed to o->decode_object(o, val)
when the object is decoded.
When only simple types like int, floats, strings, mappings, multisets and arrays are encoded, the produced string is very portable between pike versions. It can at least be read by any later version.
The portability when objects, programs and functions are involved depends mostly on the codec. If the byte code is encoded, i.e. when Pike programs are actually dumped in full, then the string can probably only be read by the same pike version.
decode_value() , sprintf() , encode_value_canonic()
string encode_value_canonic(mixed value, object|void codec)
Code a value into a string on canonical form.
Takes a value and converts it to a string on canonical form, much like encode_value() . The canonical form means that if an identical value is encoded, it will produce exactly the same string again, even if it's done at a later time and/or in another Pike process. The produced string is compatible with decode_value() .
Note that this function is more restrictive than encode_value() with respect to the types of values it can encode. It will throw an error if it can't encode to a canonical form.
encode_value() , decode_value()
mixed decode_value(string coded_value, void|Codec codec)
Decode a value from the string coded_value .
This function takes a string created with encode_value() or encode_value_canonic() and converts it back to the value that was coded.
If codec is specified, it's used as the codec for the decode. If no codec is specified, the current master object will be used.
encode_value() , encode_value_canonic()
constant UNDEFINED
The undefined value; ie a zero for which zero_type() returns 1.
constant this
Builtin read only variable that evaluates to the current object.
this_program , this_object()
constant this_program
Builtin constant that evaluates to the current program.
this , this_object()
constant __null_program
Program used internally by the compiler to create objects that are later modified into instances of the compiled program by the compiler.
__placeholder_object
constant __placeholder_object
Object used internally by the compiler.
__null_program
mixed call_out(function f, float|int delay, mixed ... args)
void _do_call_outs()
int find_call_out(function f)
int find_call_out(mixed id)
int remove_call_out(function f)
int remove_call_out(function id)
array(array) call_out_info()
These are aliases for the corresponding functions in Pike.DefaultBackend .
Pike.Backend()->call_out() , Pike.Backend()->_do_call_outs() , Pike.Backend()->find_call_out() , Pike.Backend()->remove_call_out() , Pike.Backend()->call_out_info()
mixed `()(function fun, mixed ... args)
mixed call_function(function fun, mixed ... args)
Call a function.
Calls the function fun with the arguments specified by args .
lfun::`()()
Iterator get_iterator(object|array|mapping|multiset|string data)
Creates and returns a canonical iterator for data .
|
This function is used by foreach to get an iterator for an object.
Iterator , lfun::_get_iterator
program load_module(string module_name)
Load a binary module.
This function loads a module written in C or some other language into Pike. The module is initialized and any programs or constants defined will immediately be available.
When a module is loaded the C function pike_module_init() will be called to initialize it. When Pike exits pike_module_exit() will be called. These two functions must be available in the module.
The current working directory is normally not searched for
dynamic modules. Please use "./name.so" instead of just
"name.so" to load modules from the current directory.
void signal(int sig, function(int|void:void) callback)
void signal(int sig)
Trap signals.
This function allows you to trap a signal and have a function called when the process receives a signal. Although it IS possible to trap SIGBUS, SIGSEGV etc. I advice you not to. Pike should not receive any such signals and if it does it is because of bugs in the Pike interpreter. And all bugs should be reported, no matter how trifle.
The callback will receive the signal number as its only argument.
See the documentation for kill() for a list of signals.
If no second argument is given, the signal handler for that signal is restored to the default handler.
If the second argument is zero, the signal will be completely ignored.
kill() , signame() , signum()
int signum(string sig)
Get a signal number given a descriptive string.
This function is the inverse of signame() .
signame() , kill() , signal()
string signame(int sig)
Returns a string describing the signal sig .
kill() , signum() , signal()
int set_priority(string level, int|void pid)
object fork()
Fork the process in two.
Fork splits the process in two, and for the parent it returns a pid object for the child. Refer to your Unix manual for further details.
This function can cause endless bugs if used without proper care.
This function is disabled when using threads.
This function is not available on all platforms.
The most common use for fork is to start sub programs, which is better done with Process.create_process() .
Process.create_process()
void kill(int pid, int signal)
Send a signal to another process. Returns nonzero if it worked, zero otherwise. errno may be used in the latter case to find out what went wrong.
Some signals and their supposed purpose:
|
Note that you have to use signame to translate the name of a signal to its number.
Note that the kill function is not available on platforms that do not support signals. Some platforms may also have signals not listed here.
signal() , signum() , signame() , fork()
int getpid()
Returns the process ID of this process.
System.getppid() , System.getpgrp()
int alarm(int seconds)
Set an alarm clock for delivery of a signal.
alarm() arranges for a SIGALRM signal to be delivered to the process in seconds seconds.
If seconds is 0 (zero), no new alarm will be scheduled.
Any previous alarms will in any case be canceled.
Returns the number of seconds remaining until any previously scheduled alarm was due to be delivered, or zero if there was no previously scheduled alarm.
This function is only available on platforms that support signals.
ualarm() , signal() , call_out()
int ualarm(int useconds)
Set an alarm clock for delivery of a signal.
alarm() arranges for a SIGALRM signal to be delivered to the process in useconds microseconds.
If useconds is 0 (zero), no new alarm will be scheduled.
Any previous alarms will in any case be canceled.
Returns the number of microseconds remaining until any previously scheduled alarm was due to be delivered, or zero if there was no previously scheduled alarm.
This function is only available on platforms that support signals.
alarm() , signal() , call_out()
void atexit(function callback)
This function puts the callback in a queue of callbacks to call when pike exits. The call order is reversed, i.e. callbacks that have been added earlier are called after callback .
Please note that atexit callbacks are not called if Pike exits abnormally.
exit() , _exit()
string cpp(string data, string|void current_file, int|string|void charset, object|void handler, void|int compat_major, void|int compat_minor, void|int picky_cpp)
Run a string through the preprocessor.
Preprocesses the string data with Pike's builtin ANSI-C look-alike
preprocessor. If the current_file argument has not been specified,
it will default to "-". charset defaults to "ISO-10646".
compile()
string version()
Report the version of Pike. Does the same as
sprintf("Pike v%d.%d release %d", __REAL_VERSION__,
__REAL_MINOR__, __REAL_BUILD__);
__VERSION__ , __MINOR__ , __BUILD__ , __REAL_VERSION__ , __REAL_MINOR__ , __REAL_BUILD__ ,
int sscanf(string data, string format, mixed ... lvalues)
The purpose of sscanf is to match a string data against a format string and place the matching results into a list of variables. The list of lvalues are destructively modified (which is only possible because sscanf really is an opcode, rather than a pike function) with the values extracted from the data according to the format specification. Only the variables up to the last matching directive of the format string are touched.
The format string can contain strings separated by special matching directives like %d, %s%c and %f. Every such directive corresponds to one of the lvalues , in order they are listed. An lvalue is the name of a variable, a name of a local variable, an index in an array, mapping or object. It is because of these lvalues that sscanf can not be implemented as a normal function.
Whenever a percent character is found in the format string, a match is performed, according to which operator and modifiers follow it:
|
Similar to sprintf , you may supply modifiers between the % character and the operator, to slightly change its behaviour from the default:
|
Sscanf does not use backtracking. Sscanf simply looks at the format string up to the next % and tries to match that with the string. It then proceeds to look at the next part. If a part does not match, sscanf immediately returns how many % were matched. If this happens, the lvalues for % that were not matched will not be changed.
// a will be assigned "oo" and 1 will be returned sscanf("foo", "f%s", a);
// a will be 4711 and b will be "bar", 2 will be returned sscanf("4711bar", "%d%s", a, b);
// a will be 4711, 2 will be returned sscanf("bar4711foo", "%*s%d", a);
// a will become "test", 2 will be returned sscanf(" \t test", "%*[ \t]%s", a);
// Remove "the " from the beginning of a string // If 'str' does not begin with "the " it will not be changed sscanf(str, "the %s", str);
// It is also possible to declare a variable directly in the sscanf call; // another reason for sscanf not to be an ordinary function:
sscanf("abc def", "%s %s", string a, string b);
The number of directives matched in the format string. Note that a string directive (%s or %[]) counts as a match even when matching just the empty string (which either may do).
sprintf , array_sscanf
array array_sscanf(string data, string format)
This function works just like sscanf() , but returns the matched results in an array instead of assigning them to lvalues. This is often useful for user-defined sscanf strings.
sscanf() , `/()
string basetype(mixed x)
Same as sprintf("%t",x);
sprintf()
array column(array data, mixed index)
Extract a column from a two-dimensional array.
This function is exactly equivalent to:
map(data , lambda(mixed x,mixed y) { return x[y]; }, index )
Except of course it is a lot shorter and faster. That is, it indices every index in the array data on the value of the argument index and returns an array with the results.
rows()
multiset mkmultiset(array a)
This function creates a multiset from an array.
aggregate_multiset()
int trace(int level, void|string facility, void|int all_threads)
This function changes the trace level for the subsystem identified by facility to level . If facility is zero or left out, it changes the global trace level which affects all subsystems.
Enabling tracing causes messages to be printed to stderr. A higher trace level includes the output from all lower levels. The lowest level is zero which disables all trace messages.
See the -t command-line option for more information.
If facility is specified then there is typically only one trace level for it, i.e. it's an on-or-off toggle. The global trace levels, when facility isn't specified, are:
|
Valid facilities are:
|
Trace levels are normally thread local, so changes affect only the current thread. To change the level in all threads, pass a nonzero value in this argument.
The old trace level in the current thread is returned.
string ctime(int timestamp)
Convert the output from a previous call to time() into a readable string containing the current year, month, day and time.
Like localtime , this function might throw an error if the ctime(2) call failed on the system. It's platform dependent what time ranges that function can handle, e.g. Windows doesn't handle a negative timestamp .
time() , localtime() , mktime() , gmtime()
mapping mkmapping(array ind, array val)
Make a mapping from two arrays.
Makes a mapping ind[x] :val[x] , 0 <= x < sizeof(ind).
ind and val must have the same size.
This is the inverse operation of indices() and values() .
indices() , values()
mixed m_delete(object|mapping map, mixed index)
If map is an object that implements lfun::_m_delete() , that function will be called with index as its single argument.
Otherwise if map is a mapping the entry with index index will be removed from map destructively.
If the mapping does not have an entry with index index , nothing is done.
The value that was removed will be returned.
Note that m_delete() changes map destructively.
mappingp()
int get_weak_flag(array|mapping|multiset m)
Returns the weak flag settings for m . It's a combination of Pike.WEAK_INDICES and Pike.WEAK_VALUES .
program __empty_program(int|void line, string|void file)
string function_name(function f)
Return the name of the function f .
If f is a global function defined in the runtime 0
(zero) will be returned.
function_object()
object function_object(function f)
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.
function_name() , function_program()
program function_program(function|program f)
Return the program the function f is in.
If f is a global function defined in the runtime 0
(zero) will be returned.
function_name() , function_object()
mixed random(object o)
If random is called with an object, lfun::random will be called in the object.
lfun::_random
int random(int max)
float random(float max)
This function returns a random number in the range 0 - max -1.
random_seed()
mixed random(array|multiset x)
Returns a random element from x .
array random(mapping m)
Returns a random index-value pair from the mapping.
array(Pike.BacktraceFrame) backtrace()
FIXME: This documentation is not up to date!
Get a description of the current call stack.
The description is returned as an array with one entry for each call frame on the stack.
Each entry has this format:
| ||||||||||
The current call frame will be last in the array.
Please note that the frame order may be reversed in a later version (than 7.1) of Pike to accommodate for deferred backtraces.
Note that the arguments reported in the backtrace are the current values of the variables, and not the ones that were at call-time. This can be used to hide sensitive information from backtraces (eg passwords).
catch() , throw()
_disable_threads _disable_threads()
This function first posts a notice to all threads that it is time to stop. It then waits until all threads actually *have* stopped, and then then returns a lock object. All other threads will be blocked from running until that object has been freed/destroyed.
It's mainly useful to do things that require a temporary uid/gid change, since on many OS the effective user and group applies to all threads.
You should make sure that the returned object is freed even if some kind of error is thrown. That means in practice that it should only have references (direct or indirect) from function local variables. Also, it shouldn't be referenced from cyclic memory structures, since those are only destructed by the periodic gc. (This advice applies to mutex locks in general, for that matter.)
mapping aggregate_mapping(mixed ... elems)
Construct a mapping.
Groups the arguments together two and two in key-index pairs and
creates a mapping of those pairs. Generally, the mapping literal
syntax is handier: ([ key1:val1, key2:val2, ... ])
sizeof() , mappingp() , mkmapping()
int equal(mixed a, mixed b)
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.
copy_value()
array aggregate(mixed ... elements)
Construct an array with the arguments as indices.
This function could be written in Pike as:
array aggregate(mixed ... elems) { return elems; }
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.
sizeof() , arrayp() , allocate()
__deprecated__ int hash_7_4(string s)
__deprecated__ int hash_7_4(string s, int max)
7.4::hash()
__deprecated__ int hash_7_0(string s)
__deprecated__ int hash_7_0(string s, int max)
7.0::hash()
int hash(string s)
int hash(string s, int max)
Return an integer derived from the string s . The same string always hashes to the same value, also between processes, architectures, and Pike versions (see compatibility notes below, though).
If max is given, the result will be >= 0 and < max , otherwise the result will be >= 0 and <= 0x7fffffff.
The hash algorithm was changed in Pike 7.5. If you want a hash that is compatible with Pike 7.4 and earlier, use 7.4::hash() . The difference only affects wide strings.
The hash algorithm was also changed in Pike 7.1. If you want a hash that is compatible with Pike 7.0 and earlier, use 7.0::hash() .
7.0::hash() , 7.4::hash() , hash_value
int hash_value(mixed value)
Return a hash value for the argument. It's an integer in the native integer range.
The hash will be the same for the same value in the running process only (the memory address is typically used as the basis for the hash value).
If the value is an object with an lfun::__hash , that function is called and its result is returned.
This is the hashing method used by mappings.
hash
mixed copy_value(mixed value)
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 `==() ).
equal()
string lower_case(string s)
int lower_case(int c)
Convert a string or character to lower case.
Returns a copy of the string s with all upper case characters converted to lower case, or the character c converted to lower case.
Assumes the string or character to be coded according to ISO-10646 (aka Unicode). If they are not, Locale.Charset.decoder can do the initial conversion for you.
Prior to Pike 7.5 this function only accepted strings.
upper_case() , Locale.Charset.decoder
string upper_case(string s)
int upper_case(int c)
Convert a string or character to upper case.
Returns a copy of the string s with all lower case characters converted to upper case, or the character c converted to upper case.
Assumes the string or character to be coded according to ISO-10646 (aka Unicode). If they are not, Locale.Charset.decoder can do the initial conversion for you.
Prior to Pike 7.5 this function only accepted strings.
lower_case() , Locale.Charset.decoder
string random_string(int len)
Returns a string of random characters 0-255 with the length len .
void random_seed(int seed)
This function sets the initial value for the random generator.
random()
int query_num_arg()
Returns the number of arguments given when the previous function was called.
This is useful for functions that take a variable number of arguments.
call_function()
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)
mixed search(object haystack, mixed needle, mixed|void start)
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.
haystack can have any of the following types:
|
If start is supplied to an iterator object without an lfun::_search() , haystack will need to implement Iterator()->set_index() .
For mappings and object UNDEFINED will be returned when not found.
In all other cases -1 will be returned when not found.
indices() , values() , zero_type()
int has_prefix(string s, string prefix)
Returns 1 if the string s starts with prefix ,
returns 0 (zero) otherwise.
int has_suffix(string s, string suffix)
Returns 1 if the string s ends with suffix ,
returns 0 (zero) otherwise.
int has_index(string haystack, int index)
int has_index(array haystack, int index)
int has_index(mapping|multiset|object|program haystack, mixed index)
Search for index in haystack .
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
A negative index in strings and arrays as recognized by the
index operators `[]() and `[]=() is not considered
a proper index by has_index()
has_value() , indices() , search() , values() , zero_type()
int has_value(string haystack, string value)
int has_value(string haystack, int value)
int has_value(array|mapping|object|program haystack, mixed value)
Search for value in haystack .
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
has_index() , indices() , search() , values() , zero_type()
void add_constant(string name, mixed value)
void add_constant(string name)
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.
all_constants()
string combine_path(string path, string ... paths)
string combine_path_unix(string path, string ... paths)
string combine_path_nt(string path, string ... paths)
string combine_path_amigaos(string path, string ... paths)
Concatenate a number of paths to a straightforward path without
any "//", "/.." or "/.". If any path
argument is absolute then the result is absolute and the
preceding arguments are ignored. If the result is relative then
it might have leading ".." components. If the last
nonempty argument ends with a directory separator then the
result ends with that too. If all components in a relative path
disappear due to subsequent ".." components then the
result is ".".
combine_path_unix() concatenates in UNIX style, which also is appropriate for e.g. URL:s ("/" separates path components and absolute paths start with "/"). combine_path_nt() concatenates according to NT filesystem conventions ("/" and "\" separates path components and there might be a drive letter in front of absolute paths). combine_path_amigaos() concatenates according to AmigaOS filesystem conventions.
combine_path() is equivalent to combine_path_unix() on UNIX-like operating systems, and equivalent to combine_path_nt() on NT-like operating systems, and equivalent to combine_path_amigaos() on AmigaOS-like operating systems.
getcwd() , Stdio.append_path()
int zero_type(mixed a)
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() .
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).
find_call_out()
string string_to_unicode(string s)
Converts a string into an UTF16 compliant byte-stream.
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.
Locale.Charset.decoder() , string_to_utf8() , unicode_to_string() , utf8_to_string()
string unicode_to_string(string s)
Converts an UTF16 byte-stream into a string.
This function did not decode surrogates in Pike 7.2 and earlier.
Locale.Charset.decoder() , string_to_unicode() , string_to_utf8() , utf8_to_string()
string string_to_utf8(string s)
string string_to_utf8(string s, int extended)
Converts a string into an UTF-8 compliant byte-stream.
Throws an error if characters not valid in an UTF-8 stream are
encountered. Valid characters are in the ranges
0x00000000-0x0000d7ff and 0x0000e000-0x0010ffff.
If extended is 1 then characters outside the valid ranges are accepted too and encoded using the same algorithm. Such encoded characters are however not UTF-8 compliant.
Locale.Charset.encoder() , string_to_unicode() , unicode_to_string() , utf8_to_string()
string utf8_to_string(string s)
string utf8_to_string(string s, int extended)
Converts an UTF-8 byte-stream into a string.
Throws an error if the stream is not a legal UTF-8 byte-stream.
Accepts and decodes the extension used by string_to_utf8() if
extended is 1.
In conformance with RFC 3629 and Unicode 3.1 and later, non-shortest forms are not decoded. An error is thrown instead.
Locale.Charset.encoder() , string_to_unicode() , string_to_utf8() , unicode_to_string()
string __parse_pike_type(string t)
type(mixed) __soft_cast(type(mixed) to, type(mixed) from)
Return the resulting type from a soft cast of from to to .
type(mixed) __low_check_call(type(mixed) fun_type, type(mixed) arg_type)
type(mixed) __low_check_call(type(mixed) fun_type, type(mixed) arg_type, int flags)
Check whether a function of type fun_type may be called with a first argument of type arg_type .
The following flags are currently defined:
|
Returns a continuation type on success.
Returns 0 (zero) on failure.
type(mixed) __get_return_type(type(mixed) fun_type)
Check what a function of the type fun_type will return if called with no arguments.
Returns the type of the returned value on success
Returns 0 (zero) on failure.
type(mixed) __get_first_arg_type(type(mixed) fun_type)
Check if a function of the type fun_type may be called with an argument, and return the type of that argument.
Returns the expected type of the first argument to the function.
Returns 0 (zero) if a function of the type fun_type may not be called with any argument, or if it is not callable.
mapping(string:mixed) all_constants()
Returns a mapping containing all global constants, indexed on the name of the constant, and with the value of the constant as value.
add_constant()
CompilationHandler get_active_compilation_handler()
Returns the currently active compilation compatibility handler, or 0 (zero) if none is active.
This function should only be used during a call of compile() .
get_active_error_handler() , compile() , master()->get_compilation_handler() , CompilationHandler
CompilationHandler get_active_error_handler()
Returns the currently active compilation error handler (second argument to compile() ), or 0 (zero) if none is active.
This function should only be used during a call of compile() .
get_active_compilation_handler() , compile() , CompilationHandler
array allocate(int size)
array allocate(int size, mixed init)
Allocate an array of size elements. If init is specified then each element is initialized by copying that value recursively.
sizeof() , aggregate() , arrayp()
object this_object(void|int level)
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 that surrounds the class that the object comes from, and so on.
As opposed to a qualified this reference such as
global::this, this function doesn't always access the
objects belonging to the lexically surrounding classes. If the
class containing the call has been inherited then the objects
surrounding the inheriting class are accessed.
mixed|void throw(mixed value)
Throw value to a waiting catch .
If no catch is waiting the global error handling will send the value to master()->handle_error() .
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.
catch
void exit(int returncode, void|string fmt, mixed ... extra)
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.
The arguments after the returncode will be used for a call to werror to output a message on stderr.
_exit()
void _exit(int returncode)
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.
exit()
int time()
int time(int(1..1) one)
float time(int(2..) t)
This function returns the number of seconds since 00:00:00 UTC, 1 Jan 1970.
The second syntax does not query the system for the current time. Instead the latest done by the pike process is returned again. That's slightly faster but can be wildly inaccurate. Pike queries the time internally when a thread has waited for something, typically in sleep or in a backend (see Pike.Backend ).
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.
ctime() , localtime() , mktime() , gmtime() , System.gettimeofday , gethrtime
string crypt(string password)
int(0..1) crypt(string typed_password, string crypted_password)
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.
Note that strings containing null characters will only be processed up until the null character.
void destruct(void|object o)
Mark an object as destructed.
Calls o->destroy(), and then clears all variables in the
object. If no argument is given, the current object is destructed.
All pointers and function pointers to this object will become zero. The destructed object will be freed from memory as soon as possible.
array indices(string|array|mapping|multiset|object x)
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 might contain any value.
For objects which define lfun::_indices() that return value is used.
For other objects an array with all non-protected symbols is returned.
values()
array values(string|array|mapping|multiset|object x)
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 is used.
For other objects an array with the values of all non-protected symbols is returned.
indices()
object next_object(object o)
object next_object()
Returns the next object from the list of all objects.
All objects are stored in a linked list.
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.
This function is not recomended to use.
destruct()
program|function object_program(mixed o)
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.
string reverse(string s, int|void start, int|void end)
array reverse(array a, int|void start, int|void end)
int reverse(int i, int|void start, int|void end)
Reverses a string, array or int.
String to reverse.
Array to reverse.
Integer to reverse.
Optional start index of the range to reverse.
Default: 0 (zero).
Optional end index of the range to reverse.
Default for strings: sizeof(s)-1.
Default for arrays: sizeof(a)-1.
Default for integers: Pike.get_runtime_info()->int_size - 1.
This function reverses a string, char by char, an array, value by value or an int, bit by bit and returns the result. It's not destructive on the input value.
Reversing strings can be particularly useful for parsing difficult syntaxes which require scanning backwards.
sscanf()
string replace(string s, string from, string to)
string replace(string s, array(string) from, array(string) to)
string replace(string s, array(string) from, 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)
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 that replace() on arrays and mappings is a destructive operation.
program compile(string source, CompilationHandler|void handler, int|void major, int|void minor, program|void target, object|void placeholder)
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 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() .
compile_string() , compile_file() , cpp() , master() , CompilationHandler , DefaultCompilerEnvironment
array|mapping|multiset set_weak_flag(array|mapping|multiset m, int state)
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:
|
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 .
m will be returned.
int objectp(mixed arg)
Returns 1 if arg is an object, 0 (zero) otherwise.
mappingp() , programp() , arrayp() , stringp() , functionp() , multisetp() , floatp() , intp()
int functionp(mixed arg)
Returns 1 if arg is a function, 0 (zero) otherwise.
mappingp() , programp() , arrayp() , stringp() , objectp() , multisetp() , floatp() , intp()
int callablep(mixed arg)
Returns 1 if arg is a callable, 0 (zero) otherwise.
mappingp() , programp() , arrayp() , stringp() , objectp() , multisetp() , floatp() , intp()
void sleep(int|float s, void|int abort_on_signal)
This function makes the program stop for s seconds.
Only signal handlers can interrupt the sleep, and only when abort_on_signal is set. If more than one thread is running the signal must be sent to the sleeping thread. Other callbacks are not called during sleep.
If s is zero then this thread will yield to other threads but not sleep otherwise. Note that Pike yields internally at regular intervals so it's normally not necessary to do this.
signal() , delay()
void delay(int|float s)
This function makes the program stop for s seconds.
Only signal handlers can interrupt the sleep. Other callbacks are not called during delay. Beware that this function uses busy-waiting to achieve the highest possible accuracy.
signal() , sleep()
int gc()
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.
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.)
The amount of garbage is returned. This is the number of arrays, mappings, multisets, objects and programs that had no nonweak external references during the garbage collection. It's normally the same as the number of freed things, but there might be some difference since destroy() functions are called during freeing, which can cause more things to be freed or allocated.
Pike.gc_parameters , Debug.gc_status
int undefinedp(mixed arg)
Returns 1 if arg is undefined, 0 (zero) otherwise.
zero_type , destructedp , intp
int destructedp(mixed arg)
Returns 1 if arg is a destructed object, 0
(zero) otherwise.
zero_type , undefinedp , intp
int programp(mixed arg)
Returns 1 if arg is a program, 0 (zero) otherwise.
mappingp() , intp() , arrayp() , stringp() , objectp() , multisetp() , floatp() , functionp()
int intp(mixed arg)
Returns 1 if arg is an int, 0 (zero) otherwise.
mappingp() , programp() , arrayp() , stringp() , objectp() , multisetp() , floatp() , functionp()
int mappingp(mixed arg)
Returns 1 if arg is a mapping, 0 (zero) otherwise.
intp() , programp() , arrayp() , stringp() , objectp() , multisetp() , floatp() , functionp()
int arrayp(mixed arg)
Returns 1 if arg is an array, 0 (zero) otherwise.
intp() , programp() , mappingp() , stringp() , objectp() , multisetp() , floatp() , functionp()
int multisetp(mixed arg)
Returns 1 if arg is a multiset, 0 (zero) otherwise.
intp() , programp() , arrayp() , stringp() , objectp() , mappingp() , floatp() , functionp()
int stringp(mixed arg)
Returns 1 if arg is a string, 0 (zero) otherwise.
intp() , programp() , arrayp() , multisetp() , objectp() , mappingp() , floatp() , functionp()
int floatp(mixed arg)
Returns 1 if arg is a float, 0 (zero) otherwise.
intp() , programp() , arrayp() , multisetp() , objectp() , mappingp() , stringp() , functionp()
array sort(array(mixed) index, array(mixed) ... data)
Sort arrays destructively.
This function sorts the array index destructively. That means that the array itself is changed and returned, no copy is created.
If extra arguments are given, they are supposed to be arrays of the same size as index . Each of these arrays will be modified in the same way as index . I.e. if index 3 is moved to position 0 in index index 3 will be moved to position 0 in all the other arrays as well.
The sort order is as follows:
Integers and floats are sorted in ascending order.
Strings are sorted primarily on the first characters that are different, and secondarily with shorter strings before longer. Different characters are sorted in ascending order on the character value. Thus the sort order is not locale dependent.
Arrays are sorted recursively on the first element. Empty arrays are sorted before nonempty ones.
Multisets are sorted recursively on the first index. Empty multisets are sorted before nonempty ones.
Objects are sorted in ascending order according to `<() , `>() and `==() .
Other types aren't reordered.
Different types are sorted in this order: Arrays, mappings, multisets, objects, functions, programs, strings, types, integers and floats. Note however that objects can control their ordering wrt other types with `< , `> and `== , so this ordering of types only applies to objects without those functions.
The first argument is returned.
The sort is stable, i.e. elements that are compare-wise equal aren't reordered.
Array.sort_array , reverse()
array rows(mixed data, array index)
Select a set of rows from an array.
This function is en optimized equivalent to:
map(index , lambda(mixed x) { return data [x]; })
That is, it indices data on every index in the array index and returns an array with the results.
column()
void _dump_program_tables(program p)
Dumps the internal tables for the program p on stderr.
mapping(string:int) gmtime(int timestamp)
Convert seconds since 00:00:00 UTC, Jan 1, 1970 into components.
This function works like localtime() but the result is not adjusted for the local time zone.
localtime() , time() , ctime() , mktime()
mapping(string:int) localtime(int timestamp)
Convert seconds since 00:00:00 UTC, 1 Jan 1970 into components.
This function returns a mapping with the following components:
|
An error is thrown if the localtime(2) call failed on the system. It's platform dependent what time ranges that function can handle, e.g. Windows doesn't handle a negative timestamp .
Prior to Pike 7.5 the field "timezone" was sometimes not
present, and was sometimes not adjusted for daylight savings time.
Calendar , gmtime() , time() , ctime() , mktime()
int mktime(mapping(string:int) tm)
int mktime(int sec, int min, int hour, int mday, int mon, int year, int|void isdst, int|void tz)
This function converts information about date and time into an integer which contains the number of seconds since 00:00:00 UTC, Jan 1, 1970.
You can either call this function with a mapping containing the following elements:
|
Or you can just send them all on one line as the second syntax suggests.
On some operating systems (notably AIX and Win32), dates before 00:00:00 UTC, Jan 1, 1970 are not supported.
On most systems, the supported range of dates are Dec 13, 1901 20:45:52 UTC through Jan 19, 2038 03:14:07 UTC (inclusive).
time() , ctime() , localtime() , gmtime()
int(0..1) glob(string glob, string str)
array(string) glob(string glob, array(string) str)
Match strings against a glob pattern.
The glob pattern. A question sign ('?') matches any character and an asterisk ('*') matches a string of arbitrary length. All other characters only match themselves.
|
sscanf() , Regexp
mixed _next(mixed x)
Find the next object/array/mapping/multiset/program or string.
All objects, arrays, mappings, multisets, programs and strings are stored in linked lists inside Pike. This function returns the next item on the corresponding list. It is mainly meant for debugging the Pike runtime, but can also be used to control memory usage.
next_object() , _prev()
mixed _prev(mixed x)
Find the previous object/array/mapping/multiset or program.
All objects, arrays, mappings, multisets and programs are stored in linked lists inside Pike. This function returns the previous item on the corresponding list. It is mainly meant for debugging the Pike runtime, but can also be used to control memory usage.
Unlike _next() this function does not work on strings.
next_object() , _next()
int _refs(string|array|mapping|multiset|function|object|program o)
Return the number of references o has.
It is mainly meant for debugging the Pike runtime, but can also be used to control memory usage.
Note that the number of references will always be at least one since the value is located on the stack when this function is executed.
_next() , _prev()
type(mixed) _typeof(mixed x)
Return the runtime type of x .
typeof()
void replace_master(object o)
Replace the master object with o .
This will let you control many aspects of how Pike works, but beware that master.pike may be required to fill certain functions, so it is usually a good idea to have your master inherit the original master and only re-define certain functions.
FIXME: Tell how to inherit the master.
master()
object master()
Return the current master object.
May return UNDEFINED if no master has been loaded yet.
replace_master()
int gethrvtime(void|int nsec)
Return the CPU time that has been consumed by this process or thread. -1 is returned if the system couldn't determine it. The time is normally returned in microseconds, but if the optional argument nsec is nonzero it's returned in nanoseconds.
The CPU time includes both user and system time, i.e. it's approximately the same thing you would get by adding together the "utime" and "stime" fields returned by System.getrusage (but perhaps with better accuracy).
It's however system dependent whether or not it's the time consumed in all threads or in the current one only; System.CPU_TIME_IS_THREAD_LOCAL tells which. If both types are available then thread local time is preferred.
The actual accuracy on many systems is significantly less than microseconds or nanoseconds. See System.CPU_TIME_RESOLUTION .
The garbage collector might run automatically at any time. The time it takes is not included in the figure returned by this function, so that normal measurements aren't randomly clobbered by it. Explicit calls to gc are still included, though.
The special function gauge is implemented with this function.
System.CPU_TIME_IS_THREAD_LOCAL , System.CPU_TIME_RESOLUTION , gauge() , System.getrusage() , gethrtime()
int gethrtime(void|int nsec)
Return the high resolution real time since some arbitrary event in the past. The time is normally returned in microseconds, but if the optional argument nsec is nonzero it's returned in nanoseconds.
It's system dependent whether or not this time is monotonic, i.e. if it's unaffected by adjustments of the calendaric clock in the system. System.REAL_TIME_IS_MONOTONIC tells what it is. Pike tries to use monotonic time for this function if it's avaiable.
The actual accuracy on many systems is significantly less than microseconds or nanoseconds. See System.REAL_TIME_RESOLUTION .
System.REAL_TIME_IS_MONOTONIC , System.REAL_TIME_RESOLUTION , time() , System.gettimeofday() , gethrvtime()
array(int|mapping(string:array(int))) get_profiling_info(program prog)
Get profiling information.
Returns an array with two elements.
| |||||||||||||||
This function is only available if the runtime was compiled with the option --with-profiling.
int(0..1) object_variablep(object o, string var)
Find out if an object identifier is a variable.
This function returns 1 if var exists as a
non-protected variable in o , and returns 0 (zero)
otherwise.
indices() , values()
mixed map(mixed arr, void|mixed fun, mixed ... extra)
Applies fun to the elements in arr and collects the results.
arr is treated as a set of elements, as follows:
fun is applied in order to each element. The results are collected, also in order, to a value of the same type as arr , which is returned.
fun is applied to the values, and each result is assigned to the same index in a new mapping, which is returned.
The program is treated as a mapping containing the identifiers that are indexable from it and their values.
If there is a lfun::cast method in the object, it's called to try to cast the object to an array, a mapping, or a multiset, in that order, which is then handled as described above.
fun is applied in different ways depending on its type:
fun is called for each element. It gets the current element as the first argument and extra as the rest. The result of the call is collected.
fun is used as a function like above, i.e. the lfun::`() method in it is called.
fun is indexed with each element. The result of that is collected.
Each element that is callable is called with extra as arguments. The result of the calls are collected. Elements that aren't callable gets zero as result.
Each element is indexed with the given string. If the result of that is zero then a zero is collected, otherwise it's called with extra as arguments and the result of that call is collected.
This is typically used when arr is a collection of objects, and fun is the name of some function in them.
The function is never destructive on arr .
filter() , enumerate() , foreach()
mixed filter(mixed arr, void|mixed fun, mixed ... extra)
Filters the elements in arr through fun .
arr is treated as a set of elements to be filtered, as follows:
Each element is filtered with fun . The return value is of the same type as arr and it contains the elements that fun accepted. fun is applied in order to each element, and that order is retained between the kept elements.
If fun is an array, it should have the same length as arr . In this case, the elements in arr are kept where the corresponding positions in fun are nonzero. Otherwise fun is used as described below.
The values are filtered with fun , and the index/value pairs it accepts are kept in the returned mapping.
The program is treated as a mapping containing the identifiers that are indexable from it and their values.
If there is a lfun::cast method in the object, it's called to try to cast the object to an array, a mapping, or a multiset, in that order, which is then filtered as described above.
Unless something else is mentioned above, fun is used as filter like this:
fun is called for each element. It gets the current element as the first argument and extra as the rest. The element is kept if it returns true, otherwise it's filtered out.
The object is used as a function like above, i.e. the lfun::`() method in it is called.
fun is indexed with each element. The element is kept if the result is nonzero, otherwise it's filtered out.
Each element that is callable is called with extra as arguments. The element is kept if the result of the call is nonzero, otherwise it's filtered out. Elements that aren't callable are also filtered out.
Each element is indexed with the given string. If the result of that is zero then the element is filtered out, otherwise the result is called with extra as arguments. The element is kept if the return value is nonzero, otherwise it's filtered out.
This is typically used when arr is a collection of objects, and fun is the name of some predicate function in them.
The function is never destructive on arr .
map() , foreach()
array(int) enumerate(int n)
array enumerate(int n, void|mixed step, void|mixed start, void|function operator)
Create an array with an enumeration, useful for initializing arrays or as first argument to map() or foreach() .
The defaults are: step = 1, start = 0, operator = `+
map() , foreach()
void error(sprintf_format f, sprintf_args ... args)
Throws an error. A more readable version of the code
throw( ({ sprintf(f, @args), backtrace() }) ).
int is_absolute_path(string p)
Check if a path p is fully qualified (ie not relative).
Returns 1 if the path is absolute, 0 otherwise.
array(string) explode_path(string p)
Split a path p into its components.
This function divides a path into its components. This might seem like it could be done by dividing the string on <tt>"/"</tt>, but that will not work on some operating systems. To turn the components back into a path again, use combine_path() .
string dirname(string x)
Returns all but the last segment of a path. Some example inputs and outputs:
|
basename() , explode_path()
string basename(string x)
Returns the last segment of a path.
dirname() , explode_path()
program compile_string(string source, void|string filename, object|void handler, void|program p, void|object o, void|int _show_if_constant_errors)
Compile the Pike code in the string source into a program.
If filename is not specified, it will default to "-".
Functionally equal to compile (cpp (source , filename )).
compile() , cpp() , compile_file()
program compile_file(string filename, object|void handler, void|program p, void|object o)
Compile the Pike code contained in the file filename into a program.
This function will compile the file filename to a Pike program that can
later be instantiated. It is the same as doing
compile_string (Stdio.read_file (filename ), filename ).
compile() , compile_string() , cpp()
string normalize_path(string path)
Replaces "\" with "/" if runing on MS Windows. It is adviced to use System.normalize_path instead.
int strlen(string|multiset|array|mapping|object thing)
Alias for sizeof .
int write(string fmt, mixed ... args)
Writes a string on stdout. Works just like Stdio.File.write on Stdio.stdout .
int werror(string fmt, mixed ... args)
Writes a string on stderr. Works just like Stdio.File.write on Stdio.stderr .
string describe_backtrace(mixed trace, void|int linewidth)
Return a readable message that describes where the backtrace trace was made (by backtrace ).
It may also be an error object or array (typically caught by a catch ), in which case the error message also is included in the description.
backtrace() , describe_error() , catch() , throw()
string describe_error(mixed err)
Return the error message from an error object or array (typically
caught by a catch ). The type of the error is checked, hence
err is declared as mixed and not object|array.
If an error message couldn't be obtained, a fallback message describing the failure is returned. No errors due to incorrectness in err are thrown.
describe_backtrace() , get_backtrace
array get_backtrace(object|array err)
Return the backtrace array from an error object or array (typically caught by a catch ), or zero if there is none. Errors are thrown on if there are problems retrieving the backtrace.
describe_backtrace() , describe_error()
| CLASS FacetGroup |
This class is used to handle facets in the system. All facets in the system have to belong to a facet group. The facet group is a pike module that inherits from this class. For example you can create a file MyFacetgroup.pmod with the following content:
inherit FacetGroup;
You can then use the facet group MyFacetGroup in a facet-class like this:
class A
{
facet NameOfMyFacet : .MyFacetGroup;
// Rest of class A
}
| CLASS MasterObject |
Master control program for Pike.
predef::master() , predef::replace_master()
object cast_to_object(string str, string|void current_file)
Called by the Pike runtime to cast strings to objects.
String to cast to object.
Filename of the file that attempts to perform the cast.
Returns the resulting object.
cast_to_program()
program cast_to_program(string str, string|void current_file)
Called by the Pike runtime to cast strings to programs.
String to cast to object.
Filename of the file that attempts to perform the cast.
Returns the resulting program.
cast_to_object()
inherit Codec : Codec
The master object is used as a fallback codec by encode_value() and decode_value() if no codec was given.
It will also be used as a codec if decode_value() encounters old-style encode_value() 'ed data.
void unregister(program p)
Unregister a program that was only partially compiled.
Called by compile() to clean up references to partially compiled programs.
Partially compiled program that should no longer be referenced.
Shouldn't this function be in the compilation handler?
void handle_error(mixed exception)
Called by the Pike runtime if an exception isn't caught.
Value that was throw() 'n.
describe_backtrace()
inherit CompilationHandler : CompilationHandler
The master object acts as fallback compilation handler for compile() and cpp() .
CompilationHandler get_compilation_handler(int major, int minor)
Get compilation handler for simulation of Pike vmajor .minor .
This function is called by cpp() when it encounters
#pike directives.
Major version.
Minor version.
Returns a compilation handler for Pike >= major .minor .