lua-users home
lua-l archive

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


API users are free to assume that strings will always have a
terminating null: "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 may contain other zeros in its
body".

Some parts of the standard string library (specifically parts of the
pattern matching code) will also break without a terminating null.

On Mon, Feb 16, 2009 at 12:04 PM, Juris Kalnins <juris@mt.lv> wrote:
> All Lua strings are created using newlstr(), which always adds '\0' at the
> end of allocated string.
> Would Lua work without this terminating null?
> How much change is needed to make it work?
>
> Why:
> I have modified Lua to keep data separately from the TString header, so that
> it can reside in memory that is not managed by Lua. However, there might be
> some cases when target data may have no terminating null. I want to know if
> Lua can operate correctly with string data even if no terminating null is
> present, or does such data always require copying.
> --j<
>