lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Fri, Aug 14, 2009 at 11:12 AM, Shmuel Zeigerman <shmuz@013net.net> wrote:
Recently I was manipulating wide character strings in a Lua library. Windows API assumes these strings to end with L'\0' which is represented as 2 successive zero bytes. The problem is, lua_tolstring guarantees only 1 zero byte at the end (according to the manual):

lua_tolstring returns a fully aligned pointer to a string inside the Lua state. This string always has a zero ('\0') after its last character (as in C), but can contain other zeros in its body.

If I solve this by appending L'\0' to strings (which is expensive operation), then I have problems to lua_concat such strings.

So I've a wish for Lua 5.2:
   "Make lua_tolstring guarantee 2 zero bytes at the string end".
It seems that no noticeable overhead would be incurred, and no compatibility issues would arise.

Please correct me if I'm wrong, or if better options exist.
Thanks.

--
Shmuel

When processing "strings" that may contain non-ASCII data it is imperative you always only ever use the C API functions where you pass in the length of the buffer holding your "string"! Never rely on the C style terminating zero.

Robby