From: John L. <jla...@gm...> - 2006-01-11 22:08:33
|
> I hardly understand the problem. I do understand that there are two > lua_State at the same time. > While there is only one wxLuaState. > What would be the problem if there would be two wxLuaStates too? Because the rest of the variables in the wxLuaStateRefData must be shared between the two lua_States. You only know which lua_State you want to use from lua calling the C function. > And what would be the solution if the new lua_State became part of every > new wxLuaState, and that > was passed around using a Smart Pointer to it, instead of the current > ref counting mechanism. > If several lua_State need to share data, that can be done using a second > Smart Pointer inside wxLuaState. You still need a way to associate many lua_States with a single group of data structures. I'm not sure how a smart pointer would help here. > It will be cleared properly if all wxLuaStates's are released ( no more > smart pointers to it ). > I used hierarchies of smart pointers for storing drawing objects, and it > works great. Deletion is not so much a problem, I will look back at your smart pointers. Another reason to have the wxObject ref mechanism is that you can have a delayed construction, eg. make a wxLuaState a member of a class and then Create it as necessary or not at all. > What is exactly the reason you choose the current form of ref counting? So that when you pass a wxLuaState to a wxLuaCallback (a handler for a wxEvent) and then close the lua_State you want the wxLuaCallback to know that the lua_State has been closed. It's a simple way to let anyone who's given a wxLuaState that the lua_State is good or not. If you just use pointers to the lua_State you have to track them all and NULL them to avoid someone trying to use them. This can happen with delayed window deletion in wxWidgets. > I do not know how and why wxLua is organized as is yet, so don't get mad > if i am talking nonsense ;-) It's not too difficult, but there are some subtle intricacies. Regards, John Labenski |