[DGD] Dynamic inheritance

Wes Connell wes at brutality.org
Sat Dec 22 11:48:55 CET 2001


.oOo. Shevek (shevek at btinternet.com) wrote:

> object A requires inheritance alteration.
> Make a call to daemon with new inheritance flags.
> Daemon read a template file, inserts requested inherit lines, saves and 
> compiles the new file to new object B.
> Get a list of all things object A and clones are associated with.
> Destruct A and clones and reassociate everything with object B and clones 
> of object B.

You probably wouldn't need a daemon for this. You could hack up a wrapper
for compile_object() that draws influence from cmd_code() in the default
wiztool.

#define INHERIT_ONLY   1
#define INHERIT_CREATE 2

/* I removed the security checks btw... you should add them back. */
static object compile_object(string path, varargs mapping flags) {
  string filename, filedata, *list;
  object obj;
  int i;

  if (!flags) {
    return ::compile_object(path);
  }

  filename = "/obj/dynamic-object";
  remove_file(filename + ".c");
  obj = find_object(filename);
  if (obj) {
    destruct_object(obj);
  }

  /* Rebuild this statement with your own include file list. */ 
  filedata = "# include <foo.h>\n# include <bar.h>\n\n";

  list = map_indices(flags);
  for (i = 0; i < sizeof(list); i++) {
    if (flags[list[i]] == INHERIT_ONLY)
      filedata += "inherit /your-obj-lib/" + list[i] + "\n";
    else
      filedata += "inherit " + list[i] + " /your-obj-lib/" + list[i] + "\n";
  } 

  filedata += "\n\n";
  filedata += "void create() {\n";

  for (i = 0; i < sizeof(list); i++) {
    if (flags[list[i]] == INHERIT_CREATE) 
      filedata += list[i] + "::create();\n";
  }

  filedata += "}\n";

  /* You could load up the rest of your object from a file. */
  filedata += read_file("your template file");

  if (write_file(filename)) {
    err = catch(obj = ::compile_object(filename));
               
    if (err) {
      remove_file(str + ".c");
      message("Error: " + err + ".\n");
    }
  }
 
  return obj;
} 

-----

At least I think it would work. I know you would run into 'update' problems
since you don't really have a master object of sense. 

I hope I dont spark up a nasty debate here... but why not use single
inheritance? I know you said its a horrible waste of resources, but is it 
really? Can you not get enough memory/disk space to make up for it?

Good luck with it... keep the list informed of your progress. I'm interested
to know what you find.

-- 
Wes!
wes at brutality.org
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list