lua-users home
lua-l archive

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


Ivan-Assen Ivanov wrote:
> When a "line executed" event arrives via the debug hook function (
> lua_sethook etc.), one of the fields in the lua_Debug structure is
> "source", containing filename or entire string.
>
> Are there any lifetime guarantees for this string? Is it safe to keep
> only the const char *, not to strcpy the string itself, for each and
> every line executed?

It's lifetime is the same as the lifetime of the function closure (it's
a normal Lua string, subject to garbage collection).

Rather than strcpy, I'd suggest keeping it as a Lua string. Alternatively,
you could keep a reference to the function closure itself, since it's
quite easy to get the string back out of the function closure.