When creating XOTcl objects from C, it would be nice to be able to initialize the new object's clientData prior to any methods being invoked on the object.
Right now, the only way I can think of to do this is to 1. create the object (which invokes "init", which can't rely on the ClientData) 2. XOTclSetObjectClientData( XOTclGetObject(), data); // Or the Class equivalent 3. Invoke some secondary, private "init"-like method that does true initialization
It would be nice to have two new exported functions:
int XOTclCreateObjectCl (Tcl_Interp* in, Tcl_Obj* name, ClientData data, struct XOTcl_Class* cl); int XOTclCreateClassCl (Tcl_Interp* in, Tcl_Obj* name, ClientData data, struct XOTcl_Class* cl);
That initialize the XOTcl ClientData field prior to invoking "init" so that "init" could rely on the XOTcl ClientData being valid. This would make it much easier to construct XOTcl wrappers around C/C++ objects.
Is this reasonable? Is there a better way to accomplish this?
Scott
Notice The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying or distribution of the message, or any action taken by you in reliance on it, is prohibited and may be unlawful. If you have received this message in error, please delete it and contact the sender immediately. Thank you.
Scott,
good points. One can create an uninitialized object in XOTcl using the "alloc" method. So, the best approach for the current versions is
1) alloc object 2) set the defaults 3) call configure 4) call init
in the prerelase of xotcl 1.5.3, (2) can be achieved by the new "initslots" method, in earlier versions this is more tricky than needed. Since you are creating the object from C, you don't need (3), maybe you don't even need (2). If this is the case, you just need
callmethod yourclass alloc name obj = getobject(name) setobjclientdata obj cd callmethod obj init
That should be actually slightly faster than the current createobject interface. If you don't need the default values, this works with already with 1.5.2, otherwise you need the prerelease.
You find the prerelease under http://media.wu-wien.ac.at/download/xotcl-1.5.3-alpha2.tar.gz I made this version available for the heated discussion about tip257 vs. tip279 http://www.tcl.tk/cgi-bin/tct/tip/279.html
i am leaving tomorrow morning for one week to the US, so i might not be able to answer mails for one week.
-gustaf
PS: simplifying this on the c-interface is still a good idea.
Scott Gargash schrieb:
When creating XOTcl objects from C, it would be nice to be able to initialize the new object's clientData prior to any methods being invoked on the object.
Right now, the only way I can think of to do this is to
- create the object (which invokes "init", which can't rely on the
ClientData) 2. XOTclSetObjectClientData( XOTclGetObject(), data); // Or the Class equivalent 3. Invoke some secondary, private "init"-like method that does true initialization
It would be nice to have two new exported functions:
int XOTclCreateObjectCl (Tcl_Interp* in, Tcl_Obj* name, ClientData data, struct XOTcl_Class* cl); int XOTclCreateClassCl (Tcl_Interp* in, Tcl_Obj* name, ClientData data, struct XOTcl_Class* cl);
That initialize the XOTcl ClientData field prior to invoking "init" so that "init" could rely on the XOTcl ClientData being valid. This would make it much easier to construct XOTcl wrappers around C/C++ objects.
Is this reasonable? Is there a better way to accomplish this?
Scott
*Notice* The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying or distribution of the message, or any action taken by you in reliance on it, is prohibited and may be unlawful. If you have received this message in error, please delete it and contact the sender immediately. Thank you.
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl