From: John L. <jla...@gm...> - 2006-02-14 04:46:47
|
On 2/13/06, k. holwerda <kla...@nl...> wrote: > It would be great, if you could manage the problem with namespaces in > wxluacan. > Or if not so possible, before the release change the namespace to wx > instead of wxluacan. > I am confused what is in CVS by now. Me too, I didn't understand what you meant when you said "run scripts" when you asked about this before (maybe it wasn't in CVS then?) and forgot to get back about it. I see that you can do that now. > But this does not work, when run from the run script menu, it still > calls function that are wrong. I've changed wxluacan to use the "wxluacan" namespace and everything seems to work properly. Please let me know if there are other problems. I also changed the interface file and removed %delete for the classes. It's meant only for classes that lua itself will delete, like wxColour for example. A wxColour (wxRect etc) exists only in lua and refed copies of it are passed to c++. You cannot use %delete for a wxWindow on the other hand since wxWidgets deletes the windows itself so when lua tries to delete it when being closed you get a segfault. If I understand correctly the c++ AddObject function takes ownership of the pointer and deletes it in the destructor. Regards, John Labenski |
From: klaas.holwerda <kho...@xs...> - 2006-02-14 18:14:34
|
John Labenski wrote: >>But this does not work, when run from the run script menu, it still >>calls function that are wrong. >> >> > >I've changed wxluacan to use the "wxluacan" namespace and everything >seems to work properly. Please let me know if there are other >problems. > > I did update from cvs, and in the wxluacan sample in the menu -> ModifyObjects->Run Script. And you run the script in wxCanlua.acripts/incircles.lua. I get still the same error: attempt to call field `getCan` ( a nil value ). Do you not get this? Now if you change all the name spaces in lua to use wx instead of wxcanlua, it all works well. ( so in the rules file and in the script ). >I also changed the interface file and removed %delete for the classes. >It's meant only for classes that lua itself will delete, like wxColour >for example. > But what if both can happen? Can an object not be created in lua and/or C++? Like here i can imagine one wants to create a wxlCan in lua script, and add objects to it in lua. But in the sample it is all added to C++ instead. >If I >understand correctly the c++ AddObject function takes ownership of the >pointer and deletes it in the destructor. > > Yes, as i say, i can imagine that for a class both can happen. I would say this is a perfect use of smart pointers. In that case Lua and C++ can hold a smrtPtr to the object, who releases it last will delete the object. So making the wxLuaState::m_pTrackedList a smart pointer list, will already solve it. Since then i would use for say the object in a canvas smart pointers too, and all will be fine, no matter if Lua or C++ releases its smrtPtr to the object first. I think it would make thinks easier. Klaas |
From: John L. <jla...@gm...> - 2006-02-14 18:24:08
|
On 2/14/06, klaas.holwerda <kho...@xs...> wrote: > >>But this does not work, when run from the run script menu, it still > >>calls function that are wrong. > > > >I've changed wxluacan to use the "wxluacan" namespace and everything > >seems to work properly. Please let me know if there are other > >problems. > > > I did update from cvs, and in the wxluacan sample in the menu -> > ModifyObjects->Run Script. > And you run the script in wxCanlua.acripts/incircles.lua. > > I get still the same error: > attempt to call field `getCan` ( a nil value ). > Do you not get this? No, it works on two different machines in MSW and Linux. It adds some rects and an ellipse. Try doing another checkout maybe? > >I also changed the interface file and removed %delete for the classes. > >It's meant only for classes that lua itself will delete, like wxColour > >for example. > > > But what if both can happen? Can an object not be created in lua and/or C= ++? > Like here i can imagine one wants to create a wxlCan in lua script, and > add objects to it in lua. > But in the sample it is all added to C++ instead. Well, you can always remove the pointers from the wxLuaState, but that's not so elegant. > >If I > >understand correctly the c++ AddObject function takes ownership of the > >pointer and deletes it in the destructor. > > > Yes, as i say, i can imagine that for a class both can happen. > I would say this is a perfect use of smart pointers. In that case Lua > and C++ can hold a smrtPtr to the object, who releases it last will > delete the object. > So making the wxLuaState::m_pTrackedList a smart pointer list, will > already solve it. > Since then i would use for say the object in a canvas smart pointers > too, and all will be fine, no matter if Lua or C++ releases its smrtPtr > to the object first. > I think it would make thinks easier. I'm still a little sketchy about smart pointers. Does the template code work in MSVC 6? The last I tried templates VC6 couldn't handle them and I gave up. Your smart pointer class is just a single header file right? Regards, John Labenski |
From: k. h. <kla...@nl...> - 2006-02-15 16:26:15
|
Hi John, John Labenski wrote: >>Do you not get this? >> >> > >No, it works on two different machines in MSW and Linux. It adds some >rects and an ellipse. Try doing another checkout maybe? > > That is right, i will try again. Yesterday imy windows PC gave up, needs a reinstall. So i tried on Linux, did a make clean, and cvs upadte, and compiled all. The result was that nor wxlua or wxluacan did even startup. And you guys seem to have it all functional. So i will start from scatch again, to see if that solves it all. If i only new what is going wrong :-( >>I think it would make thinks easier. >> >> > >I'm still a little sketchy about smart pointers. Does the template >code work in MSVC 6? > Sure, it is simple template code. >The last I tried templates VC6 couldn't handle >them and I gave up. > > Difficult template stuff is hard, but this is all oke. >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. Klaas -- Unclassified |
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 |