Re: [gdome]user_data and language bindings



Hi Claudio,

thanks for the elaboration. Until here is was very understandable:

>     d) Finally, obj' is raised to the OO level by constructing a new
>        class of type node whose "this" becomes obj': new node obj'

And then, obj' and newChild are just two names for the same object,
because of some feature in ocaml?

This is what using the user_data pointer on an extension is all about. We
could easily drop using it and have possibly multiple wrapper objects per
gdome node (but it would not hurt, except for the fact that Node identity
does not imply wrapper object identity).

>     To sum up, we have two "functions" (the constructor and as_node)
>     to map "this" of the pre-method level to objects at the OO-level.
>     A method M at the OO level is the composition of a constructor
>     with the pre-method M' with the as_node method.

Ok, how is this mapping performed in the constructor? Using a per-document
this-to-OO hash table or something?

>  As you can see we don't need to store any information in the user_data field.
>  Moreover, we can always add more information at the OO-level. How? We
>  simply add new fileds to the OO-level classes. An hash-table can finally
>  be used to map this to OO objects, so that when we rebuild (using new)
>  an OO object corresponding to a this we can also retrieve from the
>  hash-table the additional information that was associated to the class.

First I wanted to write that I don't understand this paragraph, but having
read it for the third time or so it becomes somewhat clear. You are in
fact using a global or per-document hash to map the C pointers to gdome
objects in OCaml. Well then prepare for the great programming language
shootout :-)

>  Of course, this approach is probably not feasible for other languages.

Ha! Ruby has hash tables, and so has Perl, and even C++! We could do the
very same thing in these other languages :-) 

It's just much more efficient to simply use the user_data pointer. Admit: 
I have not thought that people would want to use the same gdome tree from
two different languages, and then still want to use the user_data
themselves. Not really polite by these people. 

Tobias





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]