MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | OBSOLETE |
| 2 | CONCEPT |
| 3 | initialisation |
| 4 | |
| 5 | DESCRIPTION |
| 6 | There are two different flavours of initialisations, |
| 7 | selectable in config.h at driver compile time: |
| 8 | |
| 9 | i) #undef INITIALIZATION_BY___INIT |
| 10 | ------------------------------------ |
| 11 | |
| 12 | Initialisation is done at compile time. This is fast and costs |
| 13 | no extra code in the program. Allowed expressions currently |
| 14 | include integer literals, string literals, integer operators, |
| 15 | string addition, bracketing, array constructors, the empty |
| 16 | mapping and order_alist() . |
| 17 | When an object with initialised variables is cloned or |
| 18 | inherited, all initialised variables are copied from the |
| 19 | blueprint. A special application of this feature is to have |
| 20 | an initialised non-empty array or a mapping; it will be shared |
| 21 | by all clones or inheriting objects unless an assignment to |
| 22 | the variable - as opposed to an assignment to an element of |
| 23 | the array/mapping - is done in all clones etc. To prevent |
| 24 | unauthorised chenges in initialised arrays/mappings, you can |
| 25 | declare the variables as ``private static'' or use a nomask |
| 26 | reset/create that checks for undesired inheritance. |
| 27 | |
| 28 | ii) #define INITIALIZATION_BY___INIT |
| 29 | ------------------------------------- |
| 30 | |
| 31 | Creates a function named __INIT() for all variable |
| 32 | initialisations and for calls to __INIT() in all inherited |
| 33 | objects, and runs this function at object creation time. |
| 34 | Any efun can be used in the expressions for variable |
| 35 | initialisations, even ones with severe side effects, like |
| 36 | destruct() or shutdown() . The code created for __INIT() is a |
| 37 | little worse than a medium-skilled lpc-programmer would |
| 38 | generate, because it is scattered all over the program. |
| 39 | It is possible (though discouraged) to overload __INIT() with |
| 40 | selfwritten functions. |
| 41 | |
| 42 | HISTORY |
| 43 | Since LDMud 3.3, order_alist() is no longer accepted without |
| 44 | INITIALIZATION_BY___INIT. |
| 45 | LDMud 3.3.378 replaced this static choice of initialisation |
| 46 | methods by compile-time pragmas. |
| 47 | |
| 48 | 29.10.2006 Zesstra |