Skip to topic | Skip to bottom
Home
DGD

Welcome Register

TWiki Web TWiki Web Home Changes Topics Index Search


TWiki Webs DGD Main Sandbox TWiki Welcome Register


TWiki Web TWiki Web Home Changes Topics Index Search


TWiki Webs DGD Main Sandbox TWiki Create personal sidebar porn free porn

DGD.Kfunr1.2 - 20 Jan 2005 - 22:20 - ErwinHartetopic end

Start of topic | Skip to actions

Kfuns

These are functions provided by DGD to all objects. Some of these are masked by the KernelLib's auto object. Of course, if you are using another mudlib or are making your own then many of these may be masked.

Math

acos()

Definition
float acos(float x)

Requires
-1 <= x <= 1

Returns
The arc cosine of x.

asin()

Definition
float asin(float x)

Requires
-1 <= x <= 1

Returns
The arc sine of x.

atan()

Definition
float atan(float x)

Returns
The arc tangent of x.

atan2()

Definition
float atan2(float y, float x)

Returns
The arc tangent of y/x, determining the quadrant of the result from the signs of x and y.

ceil()

Definition
float ceil(float x)

Returns
x rounded to the next highest integer (that is 0.4 -> 1.0, while -0.4 -> 0.0).

cos()

Definition
float cos(float x)

Requires
That x not be too large (due to the way floats work, when x is greater than about 1e9, the accuracy of cos will be too low for it to be used reliably).

Returns
The cosine of the argument.

cohs()

Definition
float cosh(float x)

Errors
If the calculated result is too large, an error will result.

Returns
The hyperbolic cosine of the argument.

exp()

Definition
float exp(float x)

Returns
The exponential value of the given argument.

Error
If the result is larger than a float can hold, it will generate and error.

fabs()

Definition
float fabs(float x)

Returns
The absolute value of x.

floor()

Definition
float floor(float x)

Returns
x rounded to the next lowest integer (that is 0.4 -> 0.0, while -0.4 -> -1.0).

fmod()

Definition
float fmod(float x, float y)

Requires
y = 0.0

Returns
The value f, for which there exists an integer k such that k * y + f == x, f has the same sign of x, and the absolute value of f is less than the absolute value of y.

frexp()

Definition
mixed *frexp(float x)

Returns
({y, n}), such that y*2^n = x and y = 0.0 or 0.5 <= |y| < 1.0. If x = 0.0, the result will be (0.0, 0.0).

Array

allocate()

Definition
mixed *allocate(int size)

Requires
0 <= size <= status()[ST_ARRAYSIZE]

Returns
An array of the given size, with all elements initialised to nil.

allocate_float()

Definition
float *allocate_float(int size)

Requires
0 <= size <= status()[ST_ARRAYSIZE]

Returns
An array of floats of the given size, with all elements initialised to 0.0.

allocate_int()

Definition
float *allocate_int(int size)

Requires
0 <= size <= status()[ST_ARRAYSIZE]

Returns
An array of ints of the given size, with all elements initialised to 0.

Connection

block_input()

Definition
void block_input(int flag)

Effect
Will block or unblock all input from the user associated with the current object, on a non-zero or zero flag respectively.

LPC object

call_other()

Definition
mixed call_other(mixed obj, string function, mixed args...)

Requires
obj must be either a string giving the path of a compiled object or an object.

Effect
Will call the given function in obj, passing the given arguments. The function will not be called if it is private, or if it is static and obj = this_object().

Returns
The result of the called function or nil if the function doesn't exist or cannot be called with call_other().

Note
The -> operator is shorthand for this function. obj->function(arg1, arg2) is equivalent to call_other(obj, "function", arg1, arg2).

call_out()

Definition
int call_out(string function, mixed delay, mixed args...)

Requires
Delay must either be an integer >= 0, or a float >= 0.0 and <= 60.0. Also, the number of existing callouts is less than the value of ST_COTABSIZE in the array returned by status().

Effect
Will call the function on this object after the delay has passed, with the arguments.

Returns
The call_out handle (reference).

Note
If the maximum number of callouts is set to zero, call_out() will be ignored with no error.

clone_object()

Definition
object clone_object(object master)

Requires
That the master object must not itself be a clone.

Effects
Creates a clone of the master object with a unique name ("my_object#1234" for instance). The create(int clone) function will be called on the new object immediately, where "clone" is the number of the clone (1234 in this case).

Returns
The new object.

compile_object()

Definition
object compile_object(string file)

Requires
That if the object already exists, that it not be inherited by anything. file must give the full path of the file, including the extension (".c").

Effects
Creates an object whose name will be the file argument. ("my_object#1234" for instance). The create(int clone) function will be called on the new object immediately, where "clone" is the number of the clone (1234 in this case). If the file already exists, then at the end of the thread all clones will be updated. Any existing variables will be kept if the new master object also has those variables and they are the same type - otherwise they will be lost.

Errors
Compilation errors are reported to the driver, and a runtime error will occur as will if compilation fails.

Returns
The new object.

destruct_object()

Definition
void destruct_object(object obj)

Effects
Destroys obj. If the caller is obj itself, it will be destroyed as soon as execution leaves it. If the last reference to a master object is removed, remove_program(objname) will be called on the driver.

Errors
If an object destructs itself, avoid doing anything after the call to destruct - in particular, call_other will provoke an error. Basically, try to fast-track your way out of the object as quickly as possible.

find_object()

Definition
object find_object(string obj)

Returns
The object whose path is obj, if there is one. Otherwise, nil.

function_object()

Definition
string function_object(string function, object obj)

Returns
The name of the class which obj inherits the function from (could be the name of obj), or nil if the function doesn't exist or is not callable with call_other().

Runtime

call_trace()

Definition
mixed **call_trace()

Returns
An array representing the stack of the current thread. That is to say, every element of the array represents the position of the thread within a function. Each element of the array is in the following format: ({ objname, progname, function, line, extern, arg1, ..., argn }), where:
  • objname is the name of the object it is in. (i.e. /usr/System/sys/mydaemon).
  • progname is the name of the file the current code is running in. This differs from the objname when the code being run has been inherited - it will be the inherited class.
  • function is the name of the function being called.
  • line is the line of the function being processed, or 0 if the function is in a compiled object.
  • extern is TRUE is the function was "call_other"ed, FALSE otherwise.
  • arg1...argn are the arguments of the function.
The offsets of the array elements are definied in /include/type.h. The last element of the call_trace is the current function.

Notes
There are many uses for call_trace. It is used for thread local storage and debug messages in the KernelLib, for instance.

error()

Description
void error(string errormessage)

Effect
Causes an error, which will stop execution unless caught.

Encryption/Decryption and Error Detection

crypt()

Definition
string crypt(string passwd, varargs string salt)

Returns
An encrypted version of the string. Without the salt, it will be basically random. They way to use this as follows - first you take the raw form of the password, and run it though crypt to get an encrypted version. Afterwards, when you want to check a string to see if it is the password, run it though crypt using the encrypted version of the password as the salt. If the result is equal to the encrypted password, then they are the same.

Note
Only the first 8 characters of the passwd and the first 2 characters of the salt are significant.

hash_crc16()

Definition
int hash_crc16(string str, string extra...)

Returns
Something. Um, perhaps someone can explain what this is, and a typical use for it?

hash_md5()

Definition
string hash_md5(string str, string extra...)

Returns
Something. Used for error detection?

Time

ctime()

Definition
string ctime(int time)

Returns
The string representation of time (as returned by time()), in the format: "Tue Aug 3 14:40:18 1993".

time()

Definition
int time()

Returns
The current time as an int.

Note
It returns the number of seconds since the unix epoch point (which is January 1, 1970, midnight, GMT/UTC). This means that time() - old_time is the number of seconds passed since old_time.

DGD System

dump_state()

Definition
void dump_state()

Effect
Causes the system to create a state dump at the end of the current thread, to the file specified in the dgd config file. The old state dump will be copied to the same file name appended with ".old".

File

editor()

Definition
string editor(varargs string command)

Effect
Executes an editor command for the current object. This includes creating a new editor instance and associating it with the current object if necessary. This editor instance will remain active until issues a specific command to destroy it, or the associated object is destructed.

Returns
Editor output as a string.

Errors
If the number of editors is equal to the status()[ST_ETABSIZE] and a new instance needs to be created for this object, it will fail. You also cannot use the editor kfun in a user object.

get_dir()

Definition
mixed **get_dir(string file)

Returns
Information on the given file or directory. This is returned in an array with the following format: ({ ({file names}), ({file sizes}), ({file mod times}) }). If the file in the array is a directory, it will have a file size of -2. file can be a regular expression, in which case all files matching it will be returned. If no files match, then ({ ({}),({}),({})}) will be returned. Files will be sorted by name.

Errors
Only up to status()[ST_ARRAYSIZE] files will be returned. If there are more files, then they will not be included.

String

explode()

Definition
string *explode(string str, string separator)

Returns
An array of strings, which are the parts of str seperated by the separator.

Note
If a seperator is at the beginning or end of the string, there will not be a string segment exploded before it, meaning it will be lost in a implode(explode()) operation.

Errors
If the size of the resulting array is greater than status()[ST_ARRAYSIZE], an error will occur.

implode()

Definition
string implode(string *arr, string separator)

Returns
The strings in arr appended together in order, seperated by the separator string.

Errors
If the resulting string would be too long, an error will result. The argument array may contain only string values.

-- ErwinHarte - 20 Jan 2005
to top


You are here: DGD > Kfun

to top

Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback