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 <> 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

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

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.