PRELIMINARY
CONCEPT
python
DESCRIPTION
Python can be used to extend the LDMud driver. At the startup
of LDMud a python script will be called that can register
additional efuns. The python script can either be given
on the command line using the --python-script option,
or at compile time with the --with-python-script configuration
option.
The python script can import the builtin ldmud module.
This module provides the following functions:
- register_efun(name, function) -> None
Registers a new efun name. This is not allowed during
compilation of an LPC object.
If the Python function has type annotations for its
arguments and return value, the type is checked
at compile and runtime. Union types can be specified
as tuples of types.
- unregister_efun(name) -> None
Removes a python efun from registration. This is not
allowed during compilation of an LPC object. The
removal will only affect newly compiled code,
already compiled code will produce errors when
calling this efun.
- register_socket(fd, function [,eventmask]) -> None
Registers a socket to watch for events (like
poll/select). The socket must be either given as
an integer or an object with a fileno() method
returning an integer. The function must be a callable
accepting one argument, the actual event mask.
may be an combination of select.POLLIN,
select.POLLOUT and select.POLLPRI or a callable
returning such a combination.
- unregister_socket(fd) -> None
Removes a previously registered socket from the
watch list.
- register_hook(hook, function) -> None
Register a hook. The python function will be called
whenever happens. can be one of the
following:
ON_HEARTBEAT
Called without arguments for every backend loop
ON_OBJECT_CREATED
Called whenever an object was created, with the
object as its first and only argument. This call
happens before any LPC code of the object ran.
ON_OBJECT_DESTRUCTED
Called just before an object will be destructed,
with the object as its first and only argument.
ON_CHILD_PROCESS_TERMINATED
Called without any arguments whenever a SIGCHLD signal
was received. This could also happen for processes
spawned by the driver itself (eg. erq).
- unregister_hook(hook, function) -> None
Removes a hook function.
- get_master() - > Object
Returns the current master object.
Returns None, if there is no master object (yet).
- get_simul_efun() - > Object
Returns the current simul-efun object
(or None if there is none).
This module provides the following types:
- Object(filename)
Corresponds to the LPC object type.
On instantiation a filename for an object
to search or load is required.
Has the following members:
name
The object name
functions
Contains all the visible functions (private functions
are excluded) as attributes. They support the call
operator and contain the following attributes:
name
The name of the function
file_name
The file that contains the function's definition
line_number
The starting line number of the function's definition
arguments
A list of all arguments with their type, flags
(combination of LA_* constants) and position.
return_type
The return type as Python object (maybe missing if
unknown or mixed).
flags
A combination of the following flags:
LF_STATIC, LF_NOMASK, LF_VARARGS, LF_VIRTUAL and
LF_DEPRECATED
visibility:
One of the following:
VIS_PRIVATE, VIS_PROTECTED, VIS_VISIBLE, VIS_PUBLIC
variables
Contains all variables as attributes. They contain the
following attributes:
name
The name of the variable
value
The value of the variable. This attribute is writable
to assign a new value.
type
The type as a Python object (maybe missing if
unknown or mixed).
flags
A combination of the following flags:
VF_NOSAVE, VF_NOMASK, VF_VIRTUAL and VF_DEPRECATED
visibility:
One of the following:
VIS_PRIVATE, VIS_PROTECTED, VIS_VISIBLE, VIS_PUBLIC
- LWObject(filename)
Corresponds to the LPC lwobject type.
On instantiation a filename of a blueprint to create
a lightweight object from is required.
Has the following members:
program_name
The program name (file name it was created from)
functions
Contains all the visible functions (private functions
are excluded) as attributes. They are similar to the
same member of the Object type.
variables
Contains all variables as attributes. They are similar
to the same member of the Object type.
- Array([values | size])
Corresponds to an LPC array.
Can either be initialized with a list of values
or to a given size.
Supports element access with [], len() and __contains__.
- Mapping([values | width])
Corresponds to an LPC mapping.
Can either be initialized with a dict, a list of tuples
or as an empty mapping with a given width.
Supports element access with [], len(), __contains__
and has a width member.
- Struct(object, name [, values])
Corresponds to an LPC struct.
On initialization the name of the struct definition and
the correspopnding object is required. It can be initialized
with a list of values or dict.
Has the following members:
name
The name of the struct
program_name
The name of the program that defined the struct.
members
Contains all members as attributes. They contain the
following attributes:
name
The name of the member
value
The value of the member. This attribute is writable
to assign a new value.
type
The type as a Python object (maybe missing if
unknown or mixed).
- Closure(object [,name [, lfun_object]])
Corresponds to an LPC closure.
On initialization a closure bound to