[DGD]Inherit and include

Tim Vernum tpv at acay.com.au
Sat May 26 02:41:24 CEST 2001


>I have a little question regarding inherits and includes.... It's probably
>going to seem really dumb but here goes:

No, it sounds perfectly sensible.
(ie, the questions you're asking are good questions to ask)

>The way I understand it (and I may embarrass myself by being totally wrong)

>when you include a file into a file you are effectively copying the code in

>the include file into your other file.

Pretty much.
There some tiny differences (like the error messages will point you to the correct
line in the ".h" file), but the don't really effect the outcome of your question.


>When you inherit a file does it do the same thing?

No.
You don't technically inherit a file.
You inherit a program.
The program is defined by a file containing LPC code, but
   inherit "/usr/darkcide/frobnaz" ;
doesn't actually mean to inherit the file, it means to inherit the program that
is produced by compiling that file.

> For example if I inherit
>file Y in file Z is it the same as writing all the code in the
> Y file into my Z file. 

No.

>Or does it make a reference to the functions in Y.

Yes (more or less)

>Each command file inherits tools.c
>
>So ... Is each command file copying the tools.c file into itself thus
>creating essentially loads of copies of the tools.c code?

Not quite.
If tools.c contains lost of variables, then they are copied, because each object
needs its own copy of the variable, but the code is not copied.
It's much like using clone_object(), each time you clone it, you recreate the
variables, but there's only 1 copy of the code.


>Would it be better to have all the commands in one .c file that inherits
>tools.c?

Possibly, but that's a design question that relates to the way your mudlib will
operate.
You probably don't need to worry from an efficiency point of view.

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list