blob: f9559c8e432862a11ae0ab500de074fb6867bcbb [file] [log] [blame]
Zesstra5481d492021-04-08 20:07:06 +02001CONCEPT
2 lwobjects
3
4INTRODUCTION
5 Lightweight objects are a cross between regular objects and structs.
6 Like regular objects they are build from programs (.c files) and
7 encapsulate data und functions. Like structs they are automatically
8 destructed, they can be copied and saved.
9
10 As with regular objects its variables are hidden from outside
11 objects, its functions can be called with call_other() and related
12 efuns.
13
14 Lightweight objects are passed by reference.
15
16
17DEFINITION
18 Lightweight objects are created from a program, i.e. an LPC file.
19 This file needs to have the pragma
20
21 #pragma lightweight
22
23 to allow being used as a lightweight object. This pragma implies
24 the no_clone pragma (which can be overridden with the clone pragma).
25
26 There are no restriction on the program itself. It can inherit
27 other programs. Those programs don't need to have that pragma,
28 but the compiler might warn about unsuitable programs.
29
30
31USAGE
32 A lightweight objects is created by calling the efun new_lwobject():
33
34 lwobject lwo = new_lwobject("/obj/foo");
35
36 The efun new_lwobject() will load the file to create a blueprint
37 from it (which is a regular object) and then creates a lightweight
38 object therefrom.
39
40 The efun can be given optional arguments that are passed to the
41 H_CREATE_LWOBJECT driver hook.
42
43 Functions of the lightweight object can be called with the efuns
44 call_other() and its companions and operators:
45
46 lwo->fun();
47 lwo.fun();
48
49
50MISCELLANEOUS
51 Only declarative casts to lwobject are possible, there is no
52 conversion of any other type to lwobjects available (therefore
53 there is no to_lwobject() efun).
54
55 Support for lightweight objects is signaled by the macro
56 __LPC_LWOBJECTS__.
57
58 Lightweight objects have a UID and EUID and therefore can also
59 do file operations or create new objects themselves.
60
61 Lightweight objects can be serialized with save_value(), so
62 any outside program can inspect its variables. To really hide
63 variable contents they must be nosave.
64
65
66HISTORY
67 Lightweight objects were introduced in LDMud 3.6.5.
68
69
70SEE ALSO
71 structs(LPC), new_lwobject(E), call_other(E), configure_lwobject(E),
72 lwobject_info(E)