Making Modifications to LPMOO

Because the simulation is written entirely in LPC, it is relatively easy to make modifications (sometimes known as making server hacks.) This document describes how to make such modifications.

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
This contains the implementation of all the standard MOO built-in functions.

/std/dgdfuns.c
This contains the implementation for all dgd_*() built-in functions whose purposes are specific to LPMOO.

/std/extrafuns.c
This is where all miscellaneous functions are implemented, including any functions you may wish to add yourself.

Implementation Structure

Built-in functions are implemented with the following structure:

    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.

Accessing Function Arguments

Before accessing the value of an argument, the argument type must already have been determined, either by asserting the type with 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 *)

rob@ccs.neu.edu