Page 1 of 2
\0 in tooltip
Posted: 17 Aug 2009, 14:53
by Regret
\255\255\255\0text set as tooltip doesn't make anything display due to the \0.
\255\255\255\1 works.
Re: \0 in tooltip
Posted: 17 Aug 2009, 18:33
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.
Re: \0 in tooltip
Posted: 17 Aug 2009, 23:07
by imbaczek
needs fixing anyhow imho. low priority tho.
Re: \0 in tooltip
Posted: 18 Aug 2009, 00:35
by jK
ever heard something of null-terminated strings?
Re: \0 in tooltip
Posted: 18 Aug 2009, 11:02
by imbaczek
yes, both lua and c++ don't have them.
Re: \0 in tooltip
Posted: 18 Aug 2009, 11:03
by jK
imbaczek wrote:yes, both lua and c++ don't have them.
wrong, in both languages you can
avoid them
Re: \0 in tooltip
Posted: 18 Aug 2009, 11:07
by Auswaschbar
About null-terminating strings: the topic title breaks melbot

Re: \0 in tooltip
Posted: 18 Aug 2009, 11:11
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.
Re: \0 in tooltip
Posted: 18 Aug 2009, 11:15
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)
Re: \0 in tooltip
Posted: 18 Aug 2009, 11:20
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.
Re: \0 in tooltip
Posted: 18 Aug 2009, 11:55
by hoijui
what about the C AI Interface?
cant really avoid C strings there
Re: \0 in tooltip
Posted: 18 Aug 2009, 13:56
by imbaczek
int, char* pair. see lua, etc.
Re: \0 in tooltip
Posted: 18 Aug 2009, 14:02
by Kloot
Of course, doing that also means hacking up your own version of strcmp(), etc.
Re: \0 in tooltip
Posted: 18 Aug 2009, 16:48
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

)
Boost::format or other fancy replacements only have checking at runtime, which has bitten us one time already..
Re: \0 in tooltip
Posted: 18 Aug 2009, 17:00
by imbaczek
stringstream is also compile-time checked, and arguably in a stronger way.
Re: \0 in tooltip
Posted: 18 Aug 2009, 17:01
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.

Re: \0 in tooltip
Posted: 18 Aug 2009, 20:06
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.
Re: \0 in tooltip
Posted: 18 Aug 2009, 21:25
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.
Re: \0 in tooltip
Posted: 18 Aug 2009, 23:45
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.
Re: \0 in tooltip
Posted: 18 Aug 2009, 23:53
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.