object1 is the one which primarily fills the mapping, objects X and Y can modify the data, but they primarily use it. They won't ever use the data simultaneously, though - just that they have to reach back to the object1 instance. So, as you can see, the setup is pretty complex, but that makes an elegant solution for the user. The question is - will the assigning the svalue in objects X/Y work to make them refer back to object1?
No, but you don't have to assign the svalue in order to put things into the mapping. mappings are reference types.
it is not. It's just a pike-level variable.
Then you need to index it out, using object_index_no_free.
objectX contains callbacks which are called from C methods defined in object1; object1, in turn, collects some data that it puts in its own storage (and makes use of it at times) before calling up to the callbacks defined in the passed object.
Can't you just pass a reference to the mapping as a parameter to the callback then?
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2002-09-06 21:45: Subject: Mapping a variable in an object from C
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.
Not really, since I pass objectX to object1 as the create() parameter. That would be a chicken-and-egg problem then.
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.
object1 is the one which primarily fills the mapping, objects X and Y can modify the data, but they primarily use it. They won't ever use the data simultaneously, though - just that they have to reach back to the object1 instance. So, as you can see, the setup is pretty complex, but that makes an elegant solution for the user. The question is - will the assigning the svalue in objects X/Y work to make them refer back to object1?
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
it is not. It's just a pike-level variable.
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?
objectX contains callbacks which are called from C methods defined in object1; object1, in turn, collects some data that it puts in its own storage (and makes use of it at times) before calling up to the callbacks defined in the passed object.
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.
As I said, that would be chicken-and-egg since then both object would have to know each other. The alternative method is to collect the data in the callback object (objectX) but that would be, for some reason, less elegant...
/ Marek Habersack (Grendel)