[Next] [Up] [Previous] [Contents] [Index]
Next: 9. The Keywords of Up: NannyMUD LPC Previous: 7. Inheritance and Overloading


8. Miscelleanous Features

8.1 Shadows

Shadows are used to reroute the calls to lfuns through another object. In a sense, the functions in the shadowed object are overloaded by those in the shadowing object - for external function call (i.e. call_other, ->). The shadowee still has access to the original functions by internal calls.

This can be used to modify the returned value and the sideeffects of a function without having to re-define it, especially for objects that are not under your own control (i.e. you didn't write their definition files).

This means also that when designing an object, the coder has to consider how shadows can be used on and affect the behaviour of the object. It might be a good idea to block the possibility to shadow certain functions, or perhaps make the object impossible to shadow at all.

This involves a judgement call, as denying shadows increases security but decreases flexibility. For most objects, flexibility is more important than tight security.

8.2 Virtual Compiling

Virtual compiling allows for objects with distinctive filenames, without any corresponding file defining them. This might sound a little odd, but it has its uses.

When the driver is instructed to load a file, it first checks if it is already loaded. If not it looks in the specified directory. If there is no file there that can be used, it looks for a file named vcompile.c in the directory (and in the parent directories!). If found, that object is loaded and the function compile_virtual in it is called with the filename of the wanted object as argument. This function should clone an object and return it.

If anything else than an object is returned, the common error handling mechanism for a non-existing definition file is used. But if an object is returned, the driver now changes file name on the clone to the filename given as argument to compile_virtual, and the reset function in the object is called with the argument -1.

This can then be used to create large areas based on a database or some fancy algorithms instead of writing a large number of files defining every single location.

[Next] [Up] [Previous] [Contents] [Index]
Next: 9. The Keywords of Up: NannyMUD LPC Previous: 7. Inheritance and Overloading
Mats Henrik Carlberg