The thing is that objects X and Y need to use and/or modify the mapping stored in object1 but they have no idea that the object exists.
So why not just store a reference to object1 in objectX (and objectY)? Then they know that the object exists. Problem solved.
Or alternatively, you could just store a reference to the mapping, but then they would no longer share it with object1 if you overwrite the field "mymapping" in object1 with a completely new mapping. Depends on what you want to do.
The C code in object1's create() first checks whether the passed object is of a correct type and then it should retrieve the index of the 'myothermapping' variable and set the svalue so that it references the mymapping mapping. i.e. do the C equivalent of the initialization
above.
If you know where "myothermapping" is located in the storage, all you need to do is use get_storage, like I said. That will check that the class of the object is correct as well, so you can even remove that test.
Anyway, this whole thing seems a little backwards. Why do you send an objectX to the create method of object1 that is has to modify? Wouldn't it be more natural to pass an object1 to the create method of objectX, so that it can store a reference to it (or its mapping)? That would be more like your pike code.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2002-09-06 20:53: Subject: Mapping a variable in an object from C
nope, I want something like this:
object1: mapping mymapping = ([]);
objectX: mapping myothermapping = object1->mymapping;
objectY: mapping myothermapping = object1->mymapping;
(objects X and Y are of the same class)
But the mappings in objects X and Y are supposed to be initialized to point (reference) to the object1->mymapping in the C code which lives in the create() function of object1 which, in turn, gets an object passed as one of the parameters. The thing is that objects X and Y need to use and/or modify the mapping stored in object1 but they have no idea that the object exists. The C code in object1's create() first checks whether the passed object is of a correct type and then it should retrieve the index of the 'myothermapping' variable and set the svalue so that it references the mymapping mapping. i.e. do the C equivalent of the initialization above.
/ Marek Habersack (Grendel)