mirror of
https://github.com/ldmud/ldmud
synced 2026-08-12 14:26:05 -04:00
When creating, copying or restoring lightweight objects always call __INIT. This is needed, because restore will not touch nosave variables, and __INIT might have side-effects that are needed. Also when copying and restoring free any previous contents of variables (might come from __INIT or the UID hook). And when pragma share_variables is in effect, abort __INIT also in lightweight objects.
76 lines
2.6 KiB
Text
76 lines
2.6 KiB
Text
CONCEPT
|
|
lwobjects
|
|
|
|
INTRODUCTION
|
|
Lightweight objects are a cross between regular objects and structs.
|
|
Like regular objects they are build from programs (.c files) and
|
|
encapsulate data and functions. Like structs they are automatically
|
|
destructed, they can be copied and saved.
|
|
|
|
As with regular objects its variables are hidden from outside
|
|
objects, its functions can be called with call_other() and related
|
|
efuns.
|
|
|
|
Lightweight objects are passed by reference.
|
|
|
|
|
|
DEFINITION
|
|
Lightweight objects are created from a program, i.e. an LPC file.
|
|
This file needs to have the pragma
|
|
|
|
#pragma lightweight
|
|
|
|
to allow being used as a lightweight object. This pragma implies
|
|
the no_clone pragma (which can be overridden with the clone pragma).
|
|
|
|
There are no restriction on the program itself. It can inherit
|
|
other programs. Those programs don't need to have that pragma,
|
|
but the compiler might warn about unsuitable programs.
|
|
|
|
|
|
USAGE
|
|
A lightweight objects is created by calling the efun new_lwobject():
|
|
|
|
lwobject lwo = new_lwobject("/obj/foo");
|
|
|
|
The efun new_lwobject() will load the file to create a blueprint
|
|
from it (which is a regular object) and then creates a lightweight
|
|
object therefrom.
|
|
|
|
The efun can be given optional arguments that are passed to the
|
|
H_CREATE_LWOBJECT driver hook.
|
|
|
|
Functions of the lightweight object can be called with the efuns
|
|
call_other() and its companions and operators:
|
|
|
|
lwo->fun();
|
|
lwo.fun();
|
|
|
|
|
|
MISCELLANEOUS
|
|
Only declarative casts to lwobject are possible, there is no
|
|
conversion of any other type to lwobjects available (therefore
|
|
there is no to_lwobject() efun).
|
|
|
|
Support for lightweight objects is signaled by the macro
|
|
__LPC_LWOBJECTS__.
|
|
|
|
Lightweight objects have a UID and EUID and therefore can also
|
|
do file operations or create new objects themselves.
|
|
|
|
Lightweight objects can be serialized with save_value(), so
|
|
any outside program can inspect its variables. To really hide
|
|
variable contents they must be nosave.
|
|
|
|
Prior to restoring or copying a lightweight object all variables
|
|
of the new lightweight object will be initialized regularly first
|
|
when pragma init_variables is in effect.
|
|
|
|
|
|
HISTORY
|
|
Lightweight objects were introduced in LDMud 3.6.5.
|
|
|
|
|
|
SEE ALSO
|
|
structs(LPC), new_lwobject(E), call_other(E), configure_lwobject(E),
|
|
lwobject_info(E)
|