lua-users home
lua-l archive

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


Roberto:

On Tue, Aug 25, 2020 at 5:02 PM Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
.......
> > It seems likely, and it is true on userdata, but the wording on
> > lua_tostring make me fear the string can me moved around by the
> > collector if it is not pinned especifically by a stack entry.

> I think the docs are quite clear; your fear is intentional.

Rest assured the doc is clear, and I coded according to it,
getuservalue plus optional index adjustments in some paths. But I have
been proven to miss some parts of the manual, so I thought better to
ask it, in case there were some relevant paragraphs extending that
which I had skipped.

By "intentional" do you mean "justified" ? I'm not quite sure I
understand that part.

> Currently the collector does not move strings around, but this
> is an implementation detail that can change in the future and
> then create really hard-to-find bugs in your code.

That is what I thought, but no problem. I will keep reloading from the
registry/uservalue and cache it in std::strings or via plain strdups
if I need to get at them without touching lua. I really wanted to
avoid some convoluted paths to get at a lua stack in some situations,
but it is not a problem.

> - Concrete example: recently it was discussed in this list the
> idea of using an unboxed representation for small strings. If we
> decide to adopt that proposal, we will ensure that elements active
> in the stack do not move (because the manual assures that), but
> elements in a table (e.g., the registry) are free to be moved if
> the table resizes.

Understood. I remember seeing something like that. I will continue
pinning them with the stack.

Francisco Olarte.