Re: [Gambas-user] Error in Left$ and Mid$ functions to the gb.ncurses component
On Sun, 20 May 2012, tobi wrote: > On Sun, 20 May 2012, Benoît Minisini wrote: > > Le 20/05/2012 16:26, William Cabrera a écrit : > > > Hi, I have been testing the component ncurses and so far everything well, > > > but the functions mentioned in the title simply do not work. Below is a > > > sample code: > > > > > > #!/usr/bin/env gbs3 > > > > > > USE "gb.ncurses" > > > > > > dim hwin As Window > > > dim cadena, cad as string > > > cadena = "Hola Mundo" > > > cad = left(cadena) > > > hwin = New Window(0, 0, 20, 30) > > > hwin.Background = Color.Blue > > > hwin.show() > > > hwin.Full() > > > hwin.print(right$(cadena), 0, 0) > > > hwin.print(right$(cadena, 3), 0, 1) > > > hwin.print(right$(cadena, -3), 0, 2) > > > hwin.print(left$(cadena), 0, 3) > > > hwin.print(left$(cadena, 3), 0, 4) > > > hwin.print(left$(cadena, -3), 0, 5) > > > hwin.print(mid$(cadena, 2, 2), 0, 6) > > > hwin.WaitKey() > > > > > > And this is the output > > > > > > o > > > ndo > > > a Mundo > > > Hola Mundo > > > Hola Mundo > > > Hola Mundo > > > ola Mundo > > > > > > [System] > > > OperatingSystem=Linux > > > Kernel=3.2.0-1-686-pae > > > Architecture=i686 > > > Memory=2065228 kB > > > DistributionVendor=Asturix > > > DistributionRelease="Asturix 4" > > > Desktop=Gnome > > > > > > [Gambas 3] > > > Version=3.1.90 > > > Path=/usr/local/bin/gbx3 > > > > > > [Libraries] > > > Qt4=libQtCore.so.4.8.1 > > > GTK+=libgtk-x11-2.0.so.0.2400.10 > > > > > > P.D. Sorry for my english, this is not my native language > > > > > > -- > > > William Cabrera > > > http://willicab.gnu.org.ve > > > > This is a bug in the gb.ncurses component whose methods do not read > > their string arguments correctly. Tobi are you here? > > > > -- > > Benoît Minisini > > > > -- > > Live Security Virtual Conference > > Exclusive live event will cover all the ways today's security and > > threat landscape has changed and how IT managers can respond. Discussions > > will include endpoint security, mobile security and the latest in malware > > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > ___ > > Gambas-user mailing list > > Gambas-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/gambas-user > > I'm here and working! Sorry, haven't read the subject entirely when I first > saw the incoming mail... > > So you expect this output in the window, right?: > > o > ndo > a Mundo > H > Hol > Hola Mu > ol > > So my question bounces to Benoît: It's said in the docs that the three string > functions used above > are optimised so that they don't duplicate strings. Does that mean or is it a > general fact that I > cannot rely on the STRING() macro to extract a NUL-terminated string from a > given GB_STRING > argument? At least there doesn't seem to be a NUL byte which causes the > component to print > everything that follows until the end of the original string... > Brief explanation and after lunch, it's done. > > Regards, > Tobi There was an accumulation of changes due to an unfinished feature but I finally commited the fix for that issue - component is still broken. Printing should work as expected now. But don't try to use events in the meantime until. However, thank you for pointing that out. Regards, Tobi -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Error in Left$ and Mid$ functions to the gb.ncurses component
Le 20/05/2012 18:43, tobi a écrit : > > So my question bounces to Benoît: It's said in the docs that the three string > functions used above > are optimised so that they don't duplicate strings. Does that mean or is it a > general fact that I > cannot rely on the STRING() macro to extract a NUL-terminated string from a > given GB_STRING > argument? At least there doesn't seem to be a NUL byte which causes the > component to print > everything that follows until the end of the original string... > Brief explanation and after lunch, it's done. > > Regards, > Tobi > No problem, I never told you how it works, so you couldn't guess! Gambas strings are not C strings (i.e. null byte terminated), but a combination of a string pointer (char *) and a length. To get the string pointer from a string argument, you must use the STRING() macro, but you already knew. To get the length of a string argument, you must use the LENGTH() macro. Now, the problem is that sometimes you cannot deal with such strings, and need a C-string. Hopefully, the interpreter provides the GB.ToZeroString() API that takes the string argument (through the ARG() macro) and returns a temporary C-string that will be automatically freed later. So, either you have: BEGIN_METHOD(MyMethod, GB_STRING arg) my_function(STRING(arg), LENGTH(arg)); END_METHOD or (if you really need a C-string): BEGIN_METHOD(MyMethod, GB_STRING arg) my_function(GB.ToZeroString(ARG(arg))); END_METHOD Regards, -- Benoît Minisini -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Error in Left$ and Mid$ functions to the gb.ncurses component
On Sun, 20 May 2012, Benoît Minisini wrote: > Le 20/05/2012 16:26, William Cabrera a écrit : > > Hi, I have been testing the component ncurses and so far everything well, > > but the functions mentioned in the title simply do not work. Below is a > > sample code: > > > > #!/usr/bin/env gbs3 > > > > USE "gb.ncurses" > > > > dim hwin As Window > > dim cadena, cad as string > > cadena = "Hola Mundo" > > cad = left(cadena) > > hwin = New Window(0, 0, 20, 30) > > hwin.Background = Color.Blue > > hwin.show() > > hwin.Full() > > hwin.print(right$(cadena), 0, 0) > > hwin.print(right$(cadena, 3), 0, 1) > > hwin.print(right$(cadena, -3), 0, 2) > > hwin.print(left$(cadena), 0, 3) > > hwin.print(left$(cadena, 3), 0, 4) > > hwin.print(left$(cadena, -3), 0, 5) > > hwin.print(mid$(cadena, 2, 2), 0, 6) > > hwin.WaitKey() > > > > And this is the output > > > > o > > ndo > > a Mundo > > Hola Mundo > > Hola Mundo > > Hola Mundo > > ola Mundo > > > > [System] > > OperatingSystem=Linux > > Kernel=3.2.0-1-686-pae > > Architecture=i686 > > Memory=2065228 kB > > DistributionVendor=Asturix > > DistributionRelease="Asturix 4" > > Desktop=Gnome > > > > [Gambas 3] > > Version=3.1.90 > > Path=/usr/local/bin/gbx3 > > > > [Libraries] > > Qt4=libQtCore.so.4.8.1 > > GTK+=libgtk-x11-2.0.so.0.2400.10 > > > > P.D. Sorry for my english, this is not my native language > > > > -- > > William Cabrera > > http://willicab.gnu.org.ve > > This is a bug in the gb.ncurses component whose methods do not read > their string arguments correctly. Tobi are you here? > > -- > Benoît Minisini > > -- > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > ___ > Gambas-user mailing list > Gambas-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gambas-user I'm here and working! Sorry, haven't read the subject entirely when I first saw the incoming mail... So you expect this output in the window, right?: o ndo a Mundo H Hol Hola Mu ol So my question bounces to Benoît: It's said in the docs that the three string functions used above are optimised so that they don't duplicate strings. Does that mean or is it a general fact that I cannot rely on the STRING() macro to extract a NUL-terminated string from a given GB_STRING argument? At least there doesn't seem to be a NUL byte which causes the component to print everything that follows until the end of the original string... Brief explanation and after lunch, it's done. Regards, Tobi -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Error in Left$ and Mid$ functions to the gb.ncurses component
Le 20/05/2012 16:26, William Cabrera a écrit : > Hi, I have been testing the component ncurses and so far everything well, > but the functions mentioned in the title simply do not work. Below is a > sample code: > > #!/usr/bin/env gbs3 > > USE "gb.ncurses" > > dim hwin As Window > dim cadena, cad as string > cadena = "Hola Mundo" > cad = left(cadena) > hwin = New Window(0, 0, 20, 30) > hwin.Background = Color.Blue > hwin.show() > hwin.Full() > hwin.print(right$(cadena), 0, 0) > hwin.print(right$(cadena, 3), 0, 1) > hwin.print(right$(cadena, -3), 0, 2) > hwin.print(left$(cadena), 0, 3) > hwin.print(left$(cadena, 3), 0, 4) > hwin.print(left$(cadena, -3), 0, 5) > hwin.print(mid$(cadena, 2, 2), 0, 6) > hwin.WaitKey() > > And this is the output > > o > ndo > a Mundo > Hola Mundo > Hola Mundo > Hola Mundo > ola Mundo > > [System] > OperatingSystem=Linux > Kernel=3.2.0-1-686-pae > Architecture=i686 > Memory=2065228 kB > DistributionVendor=Asturix > DistributionRelease="Asturix 4" > Desktop=Gnome > > [Gambas 3] > Version=3.1.90 > Path=/usr/local/bin/gbx3 > > [Libraries] > Qt4=libQtCore.so.4.8.1 > GTK+=libgtk-x11-2.0.so.0.2400.10 > > P.D. Sorry for my english, this is not my native language > > -- > William Cabrera > http://willicab.gnu.org.ve This is a bug in the gb.ncurses component whose methods do not read their string arguments correctly. Tobi are you here? -- Benoît Minisini -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user