lua-users home
lua-l archive

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


I was puzzled by a few things in Lua 5.1.4 header files. Apologies if
these have been asked about before; I'm at a loss how to search the
mailing list for them.

1. In lobject.h, both the CommonHeader fragment and the lua_TValue
struct have a "tt" field. I take it this means "type tag". However, why
is it a lu_byte-sized field in CommonHeader and a int-sized field in
lua_TValue?
    I realize that that the type tag enumerations will always be less than lu_byte-sized.
    And I don't think these two types are ever applied to a single block of data; if I understand right, CommonHeader is always part of a heap-allocated structure, and TValues are small objects (booleans, numbers, pointers). But why do the declarations vary? Is that deliberate? Is there a reason for it?

2. A TValue is a type-tagged Lua object. Some fields point to Lua
objects, themselves, directly, rather than to TValues. For instance, in
lstate.h, struct global_State.mt is a array of pointers to to Tables,
rather than an array of pointers to
Tables-wrapped-as-TValues-with-a-LUA_TTABLE-tag. OK.
    Now I'm a bit puzzled by why struct lua_State.l_gt and .env are
TValues rather than simply Table*s. There isn't much space difference,
but I was puzzled whether there was a reason, given that in some other
cases simple Table*s were used. Perhaps the reason is that those two
fields are exposed in the Lua environment? But there's also a third
case: struct global_State.l_registry is also a TValue not a Table*.
That's not normally exposed in Lua. Granted,  one can make it exposed.
But then, the elements of struct global_State.mt can also be exposed
through debug calls, and they're Tables not TValues. So I was wondering
whether there was any principle governing when TValues were used and
when the type-untagged Lua objects themselves (or pointers to them) were
used.

Obviously, none of this is very important.

-- 
Jim Pryor
profjim@jimpryor.net