From: John L. <jla...@gm...> - 2006-02-20 19:22:52
|
On 2/15/06, k. holwerda <kla...@nl...> wrote: > >I'm still a little sketchy about smart pointers. Does the template > >code work in MSVC 6? > > > Sure, it is simple template code. > >Your smart pointer class is just a single header file right? > > > Not exactly. The class itself yes, but a list of smrt pointers now uses > a simple a2dlist as base, is derived from STL as container. > Before we used wxList as container, but i am glad i moved to STL. > Anyway for wxLua wxList is maybe the best choice for the moment, so i > can easily make that again. > Just a few lines of code. > > I think i best prepare a header and source file, containing all that is > needed here. > This will make it simple for you to use it. I've looked it over and I'm a little confused. We'd use a a2dSmrtPtrList of template classes a2dSmrtPtr right? Would we have to have templated versions of the a2dSmrtPtr for every class type in order for it to know how to delete it? For example, you've got a class MyDataClass that you can create in C++ and push into lua or create in lua and pass to a C function that may or may not delete it. Does this mean that your class has to be derived from the template version of a2dSmrtPtr? What if someone has an existing class from some other library, like wxWidgets, that they cannot make it derived from a2dSmrtPtr? How would this work? How would deleting the object be able to tell the smart pointer that it's gone? If these issues can't be resolved I think it would be best to have your C code pull the data from lua and take ownership of it. If you wanted to get it back in lua you'd have a function to get it back by using an id of some sort. int DoStuffWithMyData(MyDataClass* data) pull *data from lua and take ownership return an int id to access the data again MyDataClass* GetMyDataClass(int id) return pointer to data based on id or null for none Does this second way work for you? This way we don't have to force every class to be derived from a2dSmrtPtr. Regards, John Labenski |