Phantasmal MUD Lib for DGD

Phantasmal Site > DGD > Writing a Library > Conditional Inheritance

How Can I Conditionally Inherit a File?

When a program includes a file, the path_include function is called in the driver object. By returning a different file name, you can change what file is included. You can then choose between including an empty file and one that inherits the program you'd like inherited.

The file must be valid either way, which is why you can't just have path_include return (nil) and include nothing at all.

Note that the standard include file (usually ⁄include⁄std.h) does not have path_include() called for it, so you can't redirect that one. However, you can #include a file from the standard include file, and redirect that one.

The Kernel Library does this in a slightly different way, but underneath it's doing the same thing. It uses AUTO as the name of the file included by the standard include file, which is why you need an empty file called AUTO to use this method.

Note that Kernel Library or not, you can use this for conditional inclusion, not just inheritance. So if you'd like to change what gets put into the standard header, just have it include another file (again, the Kernel uses AUTO as that name) and you can put different #includes and #defines in the different AUTO objects that you return under different circumstances. This is a great way to do scripting, because you can change the script's parent objects, predefined constants and standard library and AUTO-object functions, all without making the script itself have to include or inherit anything.

Phantasmal's test game, Seas of Night, is a good example of the scripting usage above. Have a look at its custom rooms in version 0.003 or later.