From: klaas.holwerda <kho...@xs...> - 2005-12-30 18:53:11
|
John Labenski wrote: > >Ok, we can try to turn on debug info. I'll have to see if I can do it >in the bakefiles? Do you know how? > > I am affraid not, but i think Franscesco knows it right away :-) > >Ok, so there really is a problem. > > Right, we need to find a solution for the static initalization classes. And i think wxModule is oke to use, since i think the first wxLuaState will be defined by other classes which are initiated after wxApp startup etc. Am i Right?? If this is the case, we only need to make sure all wxModule (one per binding module ) is called before initating the first wxLuaState. And as far as i can see, no static initialisation class is needed. I use wxModule like classes for stock object s, which is close to what we need. Maybe we can simple generate the wxModule_bindX automatically? >So, I got your email from Michael, I don't understand the first part. >I guess I'm missing some of the lingo. > > I will read it once more, and already asked Michael to explain the first better. > > >>1. Rely on 0-initialization for 'first objects' and don't touch them >>in their constructors (maybe use a special constructor for this). The >>0 intialization of all objects is guaranteed to be finished before any >>constructors are called. But of course the real constructor can be >>called later at any time, so it must not touch e.g. the list head, >>that might already have been valid data. >> >> > >Can you give me an example? > > Asked that too. >The second example of guaranteeing static var initialization works >like this, right? We have no problem doing this and Michael says the >only downside is code bloat, but we're not going to have very many of >these, so that's not an issue. This can be easily automated in >genwxluabind.lua. > >static wxLuaBinding* wxLua_GetMyBinding() >{ static wxLuaMyBinding m_binding; return &m_binding; } > > I tried it now, and just defining such a function is not enough. ( i tried in header and source ). The only thing which works is the next: In header file: extern wxart2d_Binding* wxLua_GetArt2DBinding(); In the binding .cpp file wxart2d_Binding* wxLua_GetArt2DBinding() { static wxart2d_Binding binding; binding.GetBindingList()->Append(&binding); return &binding; } In wxMyApp::OnInit() { wxLua_GetArt2DBinding(); } And this is essential how wxModule can work, and that has the advantage that the user is not responsible for calling the initilization himself, it is done automatically. So finally i tried the next : In the binding header: class wxArt2DBindingModule : public wxModule { public: wxArt2DBindingModule() { m_intialized = false; } virtual bool OnInit(); virtual void OnExit(); bool IsInitialized() { return m_intialized; } private: DECLARE_DYNAMIC_CLASS(wxArt2DBindingModule) bool m_intialized; }; In the binding source: // ---------------------------------------------------------------------------- // wxArt2DBindingModule // ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxArt2DBindingModule, wxModule) bool wxArt2DBindingModule::OnInit() { if ( !m_intialized ) { /* if we want failsave: // Initialize lower level modules first wxModuleList::compatibility_iterator node; for ( node = m_modules.GetFirst(); node; node = node->GetNext() ) { wxLuaModule* wxluabase = wxDynamicCast( node->GetData(), wxLuaModule ); if ( wxluabase && !wxluabase->IsInitialized() ) { node->GetData()->Init(); } } */ static wxart2d_Binding binding; binding.GetBindingList()->Append(&binding); m_intialized = true; } return true; } void wxArt2DBindingModule::OnExit() { } And guess what it only works ( means it is only linked in ) when i add my dummy wxart2d_binding m_dummy somewhere in my main program code. Or adding a "wxArt2DBindingModule dummy" works as well, anything that makes this library linked in , will do. So maybe we best do wxArt2DBindingModule, and a simple macro like: wxUSES_LUA_BINDING( wxArt2DBinding ) The first to make initialization work any way we want too. The second macro to be used by the user program to force linkage of that binding. Klaas |