lua-users home
lua-l archive

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


On Tue, Oct 20, 2020 at 10:53 AM v <v19930312@gmail.com> wrote:

> It allows you to pass data to your custom allocator.

That is not its entire use.

> Bottom line is that this option is only usable by custom allocators,
> default one ignores it completely.

This can be used outside of the allocation context. This pointer can
be retrieved from any Lua state at any time (by C code). so this could
be used, for example, to associate a Lua state with some other
structure or value that fits in a pointer value. Specifically an
application that hosts multiple Lua states will probably want to have
some other data dedicated to a given state, so it might have something
like:

struct instance
{
    lua_State *L;
    /* other data */
};

It might be useful to instantiate L with the ud that is the address of
struct instance that contains L, so that there is a one-to-one
relationship between struct instance (and the other data) and
lua_State.

A very similar means is given by the extra space (or is it bytes?) in
a Lua state, so the implementor has some design choices.

Cheers,
V.