\0 in tooltip
Moderator: Moderators
\0 in tooltip
\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
\255\255\255\1 works.
\255\255\255\1 works.
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: \0 in tooltip
That is correct.Regret wrote:\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
\255\255\255\1 works.
Let me know if you need any more reassurance. I am here to help.
Re: \0 in tooltip
needs fixing anyhow imho. low priority tho.
Re: \0 in tooltip
ever heard something of null-terminated strings?
Re: \0 in tooltip
yes, both lua and c++ don't have them.
Re: \0 in tooltip
wrong, in both languages you can avoid themimbaczek wrote:yes, both lua and c++ don't have them.
-
- Spring Developer
- Posts: 1254
- Joined: 24 Jun 2007, 08:34
Re: \0 in tooltip
About null-terminating strings: the topic title breaks melbot 

Re: \0 in tooltip
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.
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.
Re: \0 in tooltip
in lua-c you have to write additional code, see:
becomes:
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)
Code: Select all
const string text = lua_tostring(L, 2);
Code: Select all
const string text(lua_tostring(L, 2),lua_strlen(L, 2));
Re: \0 in tooltip
the "additional code" is one regex search&replace. avoiding c string functions is a good idea anyway. for formatting, use boost.format or stringstreams.
Re: \0 in tooltip
what about the C AI Interface?
cant really avoid C strings there
cant really avoid C strings there
Re: \0 in tooltip
int, char* pair. see lua, etc.
Re: \0 in tooltip
Of course, doing that also means hacking up your own version of strcmp(), etc.
Re: \0 in tooltip
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
)
Boost::format or other fancy replacements only have checking at runtime, which has bitten us one time already..

Boost::format or other fancy replacements only have checking at runtime, which has bitten us one time already..
Re: \0 in tooltip
stringstream is also compile-time checked, and arguably in a stronger way.
Re: \0 in tooltip
Yeah stringstream is fine (just a bit verbose IMO, in particular if you want field width / padding / hexadecimal numbers), just arguing against boost::format. 

Re: \0 in tooltip
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?Regret wrote:\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
So in short: Not a bug. Do not attempt to fix.
Re: \0 in tooltip
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.
Re: \0 in tooltip
...the leading \255 is a marker, not part of the color.zwzsg wrote: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?Regret wrote:\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
So in short: Not a bug. Do not attempt to fix.
Re: \0 in tooltip
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.