\0 in tooltip

\0 in tooltip

Discuss your problems with the latest release of the engine here. Problems with games, maps or other utilities belong in their respective forums.

Moderator: Moderators

Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

\0 in tooltip

Post by Regret »

\255\255\255\0text set as tooltip doesn't make anything display due to the \0.

\255\255\255\1 works.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: \0 in tooltip

Post by CarRepairer »

Regret wrote:\255\255\255\0text set as tooltip doesn't make anything display due to the \0.

\255\255\255\1 works.
That is correct.

Let me know if you need any more reassurance. I am here to help.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

needs fixing anyhow imho. low priority tho.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: \0 in tooltip

Post by jK »

ever heard something of null-terminated strings?
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

yes, both lua and c++ don't have them.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: \0 in tooltip

Post by jK »

imbaczek wrote:yes, both lua and c++ don't have them.
wrong, in both languages you can avoid them
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: \0 in tooltip

Post by Auswaschbar »

About null-terminating strings: the topic title breaks melbot :lol:
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

jk: i don't understand.

in c++, std::string handles \0s just fine. in lua, you don't have to do anything. when passing data between the two, you only need to take care to not use c_str() (use .data() instead) and use proper constructors. null-terminated strings are a C-ism that should die.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: \0 in tooltip

Post by jK »

in lua-c you have to write additional code, see:

Code: Select all

const string text = lua_tostring(L, 2);
becomes:

Code: Select all

const string text(lua_tostring(L, 2),lua_strlen(L, 2));
and in c++ itself you have to avoid all c functions (especiallly the format() ones). (tip: just grep for .c_str() in spring's source code)
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

the "additional code" is one regex search&replace. avoiding c string functions is a good idea anyway. for formatting, use boost.format or stringstreams.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: \0 in tooltip

Post by hoijui »

what about the C AI Interface?
cant really avoid C strings there
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

int, char* pair. see lua, etc.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: \0 in tooltip

Post by Kloot »

Of course, doing that also means hacking up your own version of strcmp(), etc.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: \0 in tooltip

Post by Tobi »

The C format functions (sprintf etc.) have the advantage however that they are checked at compile time. (Although this has it's quirks too; like the compiler intentionally emitting incorrect code and giving a warning instead of giving an error in some cases :roll: )

Boost::format or other fancy replacements only have checking at runtime, which has bitten us one time already..
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

stringstream is also compile-time checked, and arguably in a stronger way.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: \0 in tooltip

Post by Tobi »

Yeah stringstream is fine (just a bit verbose IMO, in particular if you want field width / padding / hexadecimal numbers), just arguing against boost::format. ;-)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: \0 in tooltip

Post by zwzsg »

Regret wrote:\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
I don't really see that as a problem. I mean, \0 is not the only character that you aren't allowed to use as a color. For instance, how you'd fix \78\85\66\33 telling you what you are instead of turning the color to poo?

So in short: Not a bug. Do not attempt to fix.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: \0 in tooltip

Post by imbaczek »

i believe it is a bug because it goes against the principle of least surprise. passing \0 in strings around lua is perfectly fine, but the engine treats this data differently. imho behaviour of lua strings should be consistent regardless of their usage.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: \0 in tooltip

Post by lurker »

zwzsg wrote:
Regret wrote:\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
I don't really see that as a problem. I mean, \0 is not the only character that you aren't allowed to use as a color. For instance, how you'd fix \78\85\66\33 telling you what you are instead of turning the color to poo?

So in short: Not a bug. Do not attempt to fix.
...the leading \255 is a marker, not part of the color.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: \0 in tooltip

Post by zwzsg »

Oh, I always though it was supposed to be transparency, even though I could never get semi-transparent text with it. Thanks for clearing that up.
Post Reply

Return to “Help & Bugs”