The easiest sort of modification to make is to add a new built-in function, or to modify the behavior of an existing one. The implementations of built-in functions are kept in three different files:
/std/bfuns.c
/std/dgdfuns.c
dgd_*() built-in
functions whose purposes are specific to LPMOO.
/std/extrafuns.c
IMPLEMENT(function_name)
{
ARGLEN_CK(min, max);
...
RETURN(value);
}
The ARGLEN_CK() macro asserts the number of arguments the
function expects to receive. If fewer than min or more than
max arguments are passed, E_ARGS will be raised. If
the function can accept an arbitrary number of arguments, max may
be set to -1. The number of arguments actually received can be
obtained with the NUMARGS macro.
The arguments are accessible with ARG(x) where
x is a 0-based index into the argument list. However, before using
any arguments, their types should be asserted:
ARGTYPE_CK_type(x);
Substitute type with one of NUM, STR,
OBJ, ERR, or LST; if the indicated
argument is not of the specified type, E_TYPE will be raised.
If an argument can be of any type, the actual type of the argument passed can
be determined with the expression ARGTYPE(x). This
yields an integer value, which can be matched with the macros
T_NUM, T_STR, T_OBJ,
T_ERR, or T_LST.
ARGTYPE_CK_type(x) or by dynamic evaluation
with ARGTYPE(x). The value can then be accessed as
follows:
Argument Type Expression Resulting LPC Type
============== =============== ==================
number (T_NUM) ARGVALUE_NUM(x) integer (int)
string (T_STR) ARGVALUE_STR(x) string (string)
object (T_OBJ) ARGVALUE_OBJ(x) integer (int)
error (T_ERR) ARGVALUE_ERR(x) integer (int)
list (T_LST) ARGVALUE_LST(x) array (MOOVAL *)