From: klaas.holwerda <kho...@xs...> - 2005-12-29 16:25:17
|
Hi John, I got something working now, but still do not understand why i can not debug into lua code itself. The problem with my script was, that wx.a2dLuaWP:Message("blah blah") should be wxart2d.a2dLuaWP:Message("blah blah") Which has to do with the namespace. What is lua doing with the namespace in front? Is it a function too? But now the question is, how does lua feedback to me what is wrong with my script? Can you tell me what i should do to get some kind of feedback when my script is not right? I did define LuaHandler derived from wxLuaHandler, but nothing in there is called, i expected DisplayError() would do the trick, but it seems more is needed. On the static bindings i found the next. If i define in MyApp as i explained the binding: class MyApp { static wxart2d_binding m_wxart2dluab; } And initialize the static instance like this: wxart2d_binding MyApp::m_wxart2dluab; BUT NOT call m_binding.GetBindingList()->Append(&m_binding); Suddenly the next two become active, i can but a break point on the last, and it stops. class wxart2d_BindingInit { public: wxart2d_BindingInit() { m_binding.GetBindingList()->Append(&m_binding); } wxart2d_Binding m_binding; }; wxart2d_BindingInit s_wxart2d_BindingInit; i conclude from this, that linking somehow only includes the classes/libraries which are really used in the code/main program/exe. If not used from there, it is not linked in and the static wxart2d_BindingInit is also not called. And since my bindings for wxArt2D are in a seperate library called luawraps, my main program did not contain anything from that. I think this in fact makes sence, why would one link anything from a library which is not used. (well it only looks like it is not used, since it is only used from scripts ) So why is the initialization order not a problem in this case? Just Luck, they are initialized in the right order. But as soon if i take class wxart2d_BindingInit from my luawraps library and but it into my program , it is wrong again. All static stuff in the program is done first and next what is in the libraries, and it should be the other way around. I do not see the solution yet, but at least the problem is more clear :-) Regards, Klaas |
From: John L. <jla...@gm...> - 2005-12-29 17:07:58
|
On 12/29/05, klaas.holwerda <kho...@xs...> wrote: > Hi John, > > I got something working now, but still do not understand why i can not > debug into lua code itself. This is a problem, we need to somehow unwind the stack better. The facilities exist, but sometimes it just errors out some trivial thing with absolutely no reference to the line number. It'll take some digging into the lua_Debug code. > The problem with my script was, that > wx.a2dLuaWP:Message("blah blah") should be > wxart2d.a2dLuaWP:Message("blah blah") > Which has to do with the namespace. What is lua doing with the namespace > in front? Is it a function too? The "namespace" is a table where the contents of it are set by bindings. I think (untested though) that you can jam other bindings into the wx. namespace by just setting the namespace in the binding "rules" file, but it may take some fiddling. I think that currently there are some class name clashes that will occur, but nothing that cannot be fixed. > But now the question is, how does lua feedback to me what is wrong with > my script? > Can you tell me what i should do to get some kind of feedback when my > script is not right? You should use wxEVT_LUA_ERROR. Set an event handler for the wxLuaState to get these messages. See the other events in what's left of wxlinterp.h, soon to be removed. If you have the need for not having an event handler, but would rather override a virtual function, we could add virtual handlers in the wxLuaStateRefData (cannot be done in the wxLuaState since it's recreated as necessary, eg. it's the only ref data that actually exists throughout the life of the lua_State) that would use the events by default. > I did define LuaHandler derived from wxLuaHandler, but nothing in there > is called, i expected DisplayError() would do the trick, but it seems > more is needed. See the events in the wxlua app or better yet, for the wxluaeditor app. The wxLuaHandler is really for the socket mechanism, I'm not convinced it's necessary. It was added to remove the previous wxApp dependence on the socket code and is a middle man of sorts. > On the static bindings i found the next. > If i define in MyApp as i explained the binding: > > class MyApp > { > static wxart2d_binding m_wxart2dluab; > } > > And initialize the static instance like this: > > wxart2d_binding MyApp::m_wxart2dluab; > > BUT NOT call m_binding.GetBindingList()->Append(&m_binding); > Suddenly the next two become active, i can but a break point on the > last, and it stops. I don't understand when you say the "next two become active"? Next two of w= hat? > class wxart2d_BindingInit > { > public: > wxart2d_BindingInit() > { > m_binding.GetBindingList()->Append(&m_binding); > } > wxart2d_Binding m_binding; > }; > > wxart2d_BindingInit s_wxart2d_BindingInit; > > i conclude from this, that linking somehow only includes the > classes/libraries which are really used in the code/main program/exe. If > not used from there, it is not linked in and the static > wxart2d_BindingInit is also not called. And since my bindings for > wxArt2D are in a seperate library called luawraps, my main program did > not contain anything from that. > I think this in fact makes sence, why would one link anything from a > library which is not used. > (well it only looks like it is not used, since it is only used from > scripts ) What about, wxModule? I'll look into that this afternoon. If I remember correctly it does something very similar to gather up all the derived wxModule classes. I don't have any problems using this mechanism in gcc in Linux, but I have yet to try to add my own bindings with msvc. > So why is the initialization order not a problem in this case? Just > Luck, they are initialized in the right order. > But as soon if i take class wxart2d_BindingInit from my luawraps library > and but it into my program , it is wrong again. All static stuff in the > program is done first and next what is in the libraries, and it should > be the other way around. Can you reverse the order of linking the .o object files for your program and the libraries? Regards, John Labenski |
From: klaas.holwerda <kho...@xs...> - 2005-12-29 17:36:36
|
John Labenski wrote: >On 12/29/05, klaas.holwerda <kho...@xs...> wrote: > > >This is a problem, we need to somehow unwind the stack better. The >facilities exist, but sometimes it just errors out some trivial thing >with absolutely no reference to the line number. It'll take some >digging into the lua_Debug code. > > Ha, you are talking about a lua script i think. My problem is the lua C code. I can not debug into that code. Is it generated without debug info?? >The "namespace" is a table where the contents of it are set by >bindings. > > Found it. What should happen if one calls a non existing function on a name space? > >You should use wxEVT_LUA_ERROR. Set an event handler for the >wxLuaState to get these messages. > > Oke, will dig into this soon. >I don't understand when you say the "next two become active"? Next two of what? > > By the next two i mean that wxart2d_BindingInit s_wxart2d_BindingInit; is seen suddenly and therefore the call to this from its construtor. m_binding.GetBindingList()->Append(&m_binding); And thus the bindings are initialized properly. Without any reference to the binding library in my exe/program code, the whole binding library is skipped. > >What about, wxModule? I'll look into that this afternoon. If I >remember correctly it does something very similar to gather up all the >derived wxModule classes. > I am not so sure about this, at least i had to do trick to make sure one module was intialized before the other. Still it works oke. wxModule is realy meant to intialize things before the wxApp is starting. I think it could help us. > I don't have any problems using this >mechanism in gcc in Linux, but I have yet to try to add my own >bindings with msvc. > > wxModule is not so much for static things, but it may solve adding bindings before wxLuaState is used. >Can you reverse the order of linking the .o object files for your >program and the libraries? > > No CMake solves/writes all the makefiles for me. Thanks! Klaas |
From: John L. <jla...@gm...> - 2005-12-30 04:09:48
|
On 12/29/05, klaas.holwerda <kho...@xs...> wrote: > Ha, you are talking about a lua script i think. My problem is the lua C > code. I can not debug into that code. > Is it generated without debug info?? Yes, it's not compiled with debug info. Why do you want to debug into lua? > >The "namespace" is a table where the contents of it are set by > >bindings. > > > Found it. What should happen if one calls a non existing function on a > name space? It's not found and the script errors out, calling the function terror(). > >I don't understand when you say the "next two become active"? Next two o= f what? > > > By the next two i mean that > > wxart2d_BindingInit s_wxart2d_BindingInit; > is seen suddenly and therefore the call to this from its construtor. > m_binding.GetBindingList()->Append(&m_binding); > > And thus the bindings are initialized properly. > Without any reference to the binding library in my exe/program code, the > whole binding library is skipped. Humm, the MSVC linker is too clever for its own good. But, the default wxWidgets binding works in VC 2003, are you sure this is really the case? > >What about, wxModule? I'll look into that this afternoon. If I > >remember correctly it does something very similar to gather up all the > >derived wxModule classes. > > > I am not so sure about this, at least i had to do trick to make sure one > module was intialized before the other. Still it works oke. wxModule is > realy meant to intialize things before the wxApp is starting. > I think it could help us. >> > > I don't have any problems using this > >mechanism in gcc in Linux, but I have yet to try to add my own > >bindings with msvc. > > > > > wxModule is not so much for static things, but it may solve adding > bindings before wxLuaState is used. > > >Can you reverse the order of linking the .o object files for your > >program and the libraries? > > > > > No CMake solves/writes all the makefiles for me. So... it works now? No need for a wxModule? Regards, John Labenski |
From: klaas.holwerda <kho...@xs...> - 2005-12-30 11:40:22
|
John Labenski wrote: >Yes, it's not compiled with debug info. Why do you want to debug into lua? > > So i can see on the stack where things are called from. It helps me to understand why things are organized the way they are. The only really existing documentation is on Lua itself. >>>I don't understand when you say the "next two become active"? Next two of what? >>> >>> >>> >Humm, the MSVC linker is too clever for its own good. But, the default >wxWidgets binding works in VC 2003, are you sure this is really the >case? > > Yes i am sure, i did test it again just now. If i outcomment them, my bindings are not initialized, and or not found. The debugger does not even stop there, and say at start that the breakpoints are invalid. Put them in again and everything works fine, and the debugger nicely stops too. >So... it works now? No need for a wxModule? > I don't think it works without problem, it only works under certain conditions. As soon one has his bindings inside a library, the main program must contain something from that library, else the library will not be linked. The order of initilization is something different from that. That it currently works for me, is because my intialization order seems to be oke, and i forces the initialization of the static binding by adding a dummy static wxart2d_Binding in my main program. In fact i did a test right now, just a dummy wxart2_binding already makes it link the library, it does not have to be static. Regards, Klaas |
From: John L. <jla...@gm...> - 2005-12-30 16:09:06
|
> >Yes, it's not compiled with debug info. Why do you want to debug into lu= a? > > > So i can see on the stack where things are called from. It helps me to > understand why things are organized the way they are. The only really > existing documentation is on Lua itself. 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? > >Humm, the MSVC linker is too clever for its own good. But, the default > >wxWidgets binding works in VC 2003, are you sure this is really the > >case? > > > Yes i am sure, i did test it again just now. If i outcomment them, my > bindings are not initialized, and or not found. The debugger does not > even stop there, and say at start that the breakpoints are invalid. > Put them in again and everything works fine, and the debugger nicely > stops too. Ok, so there really is a problem. > >So... it works now? No need for a wxModule? > > > I don't think it works without problem, it only works under certain > conditions. As soon one has his bindings inside a library, the main > program must contain something from that library, else the library will > not be linked. The order of initilization is something different from tha= t. > > That it currently works for me, is because my intialization order seems > to be oke, and i forces the initialization of the static binding by > adding a dummy static wxart2d_Binding in my main program. > In fact i did a test right now, just a dummy wxart2_binding already > makes it link the library, it does not have to be static. So, I got your email from Michael, I don't understand the first part. I guess I'm missing some of the lingo. >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? 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; } Thanks, John Labenski |
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 |