Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | lwobject new_lwobject(string name, ...) |
| 3 | |
| 4 | DESCRIPTION |
| 5 | Creates a new lightweight object from the program <name> and |
| 6 | returns it. The program will be loaded as a regular object, |
| 7 | called a blueprint, first, and then a lightweight object will |
| 8 | be created therefrom. |
| 9 | |
| 10 | Note that the pathname must be complete, which means there are no |
| 11 | relative paths allowed. Any further arguments will be passed to |
| 12 | the H_CREATE_LWOBJECT hook to initialize the lightweight object. |
| 13 | |
| 14 | If strict euids are enforced, the calling object must have a |
| 15 | non-zero euid. |
| 16 | |
| 17 | Variable initialization is done similar to cloned objects with a call |
| 18 | to the internal lfun __INIT(). However, if #pragma share_variables is |
| 19 | in effect, the values for a lightweight object's variables are taken |
| 20 | from the current variables of the blueprint. |
| 21 | |
| 22 | In the absence of share_variables, variables without explicit |
| 23 | initializers are initialized to 0. |
| 24 | |
| 25 | |
| 26 | EXAMPLES |
| 27 | --- /lwo/stack.c --- |
| 28 | mixed* stack = ({}); |
| 29 | |
| 30 | int empty() |
| 31 | { |
| 32 | return sizeof(stack) == 0; |
| 33 | } |
| 34 | |
| 35 | void push(mixed val) |
| 36 | { |
| 37 | stack += ({ val }); |
| 38 | } |
| 39 | |
| 40 | mixed pop() |
| 41 | { |
| 42 | mixed result; |
| 43 | |
| 44 | if (empty()) |
| 45 | raise_error("stack is empty.\n"); |
| 46 | |
| 47 | result = stack[<1]; |
| 48 | stack = stack[..<2]; |
| 49 | return result; |
| 50 | } |
| 51 | |
| 52 | --- usage: --- |
| 53 | lwobject stack = new_lwobject("/lwo/stack"); |
| 54 | |
| 55 | stack.push("A"); |
| 56 | return stack.pop(); |
| 57 | |
| 58 | |
| 59 | HISTORY |
| 60 | LDMud 3.6.5 introduced lightweight objects. |
| 61 | |
| 62 | SEE ALSO |
| 63 | blueprint(E), lwobjectp(E), load_name(E), uids(C), pragma(LPC) |