What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

孙世龙 sunshilong
As per the comments in the lstate.h, which says that:
/*
** macro to convert a Lua object into a GCObject
** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
*/
#define obj2gco(v)  check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc)).

If I understand the comments correctly, I can draw the conclusion that
LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua
objects.

So, what's a Lua object?
Why LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Best regards
Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

yang chao
there are lua objects,just not gc object.

> 在 2020年10月20日,下午5:10,孙世龙 sunshilong <[hidden email]> 写道:
>
> As per the comments in the lstate.h, which says that:
> /*
> ** macro to convert a Lua object into a GCObject
> ** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
> */
> #define obj2gco(v)  check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc)).
>
> If I understand the comments correctly, I can draw the conclusion that
> LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua
> objects.
>
> So, what's a Lua object?
> Why LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

孙世龙 sunshilong
>there are lua objects,just not gc object.
LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not gc objects?

On Tue, Oct 20, 2020 at 6:44 PM yang chao <[hidden email]> wrote:

>
> there are lua objects,just not gc object.
>
> > 在 2020年10月20日,下午5:10,孙世龙 sunshilong <[hidden email]> 写道:
> >
> > As per the comments in the lstate.h, which says that:
> > /*
> > ** macro to convert a Lua object into a GCObject
> > ** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
> > */
> > #define obj2gco(v)  check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc)).
> >
> > If I understand the comments correctly, I can draw the conclusion that
> > LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua
> > objects.
> >
> > So, what's a Lua object?
> > Why LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?
> >
> > Best regards
> > Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Francisco Olarte
Sunshilong:

On Tue, Oct 20, 2020 at 1:04 PM 孙世龙 sunshilong <[hidden email]> wrote:
> >there are lua objects,just not gc object.
> LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not gc objects?

What the OP probably was going to tell  you is they do not need to be
treated the same way by the GC. A lua value is normally stored using
nan tagging or similar techniques in a , say, 64 bit location. Those
three just use the location, be it a table position, a uservalue, a
local, a stack position, you do not need more than clearing it when
done. OTOH strings, userdata and tables have other memory associated
with them, so they need extra treatment when becoming garbage.

If you have not easily identified that, may be you are reading in a
too advanced area of the Lua sources. I have not read it too much and
your original question seemed obvious.

FOS.
Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Gé Weijers
In reply to this post by 孙世龙 sunshilong
On Tue, Oct 20, 2020 at 4:04 AM 孙世龙 sunshilong <[hidden email]> wrote:
>
> >there are lua objects,just not gc object.
> LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not gc objects?

No, they're not objects, they're just values. When you assign them you
make a copy.

When you assign an object, say in a statement like "b = a", both 'a'
and 'b' refer to the same object. This is not different from most
programming languages (Java for instance).
When you compare objects "a == b" only returns true if 'a' and 'b'
refer to the same object.

Strings are a bit different, because they're immutable, once created
they can't change, they act like values although they're garbage
collected, "a == b" returns string equality, even if these two strings
are not the same object in the interpreter (this will only happen for
long strings, over 32 bytes I think).



Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Roberto Ierusalimschy
> Strings are a bit different, because they're immutable, once created
> they can't change, they act like values although they're garbage
> collected, "a == b" returns string equality, even if these two strings
> are not the same object in the interpreter (this will only happen for
> long strings, over 32 bytes I think).

40 bytes (LUAI_MAXSHORTLEN).

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Gé Weijers
On Tue, Oct 20, 2020 at 7:46 AM Roberto Ierusalimschy
<[hidden email]> wrote:
>
> > Strings are a bit different, because they're immutable, once created
> > they can't change, they act like values although they're garbage
> > collected, "a == b" returns string equality, even if these two strings
> > are not the same object in the interpreter (this will only happen for
> > long strings, over 32 bytes I think).
>
> 40 bytes (LUAI_MAXSHORTLEN).

I misremembered, 32 was related to the byte skipping used to speed up
the string hash (a 5 bit right shift is equivalent to a division by
32). The 'step' is calculated as (len >> LUAI_HASHLIMIT)+1.

--

Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

孙世龙 sunshilong
>>>there are lua objects,just not gc object.
>> LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not gc objects?
>No, they're not objects, they're just values. When you assign them you make a copy.
You mean that they(i.e.
LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER
 ) are neither "objects" and "gc objects"?

Then what's an object in Lua? Is there a clear definition?
The tables, long strings belong to Lua objects?

Am I right?


On Wed, Oct 21, 2020 at 2:23 AM Gé Weijers <[hidden email]> wrote:

>
> On Tue, Oct 20, 2020 at 7:46 AM Roberto Ierusalimschy
> <[hidden email]> wrote:
> >
> > > Strings are a bit different, because they're immutable, once created
> > > they can't change, they act like values although they're garbage
> > > collected, "a == b" returns string equality, even if these two strings
> > > are not the same object in the interpreter (this will only happen for
> > > long strings, over 32 bytes I think).
> >
> > 40 bytes (LUAI_MAXSHORTLEN).
>
> I misremembered, 32 was related to the byte skipping used to speed up
> the string hash (a 5 bit right shift is equivalent to a division by
> 32). The 'step' is calculated as (len >> LUAI_HASHLIMIT)+1.
>
> --
> Gé
Reply | Threaded
Open this post in threaded view
|

Re: What's a Lua object? Why LUA_TBOOLEAN and LUA_TLIGHTUSERDATA and LUA_TNUMBER are not Lua objects?

Gé Weijers
To quote straight from the Lua 5.4 reference manual, section 2.1:

"Tables, functions, threads, and (full) userdata values are objects: variables do not actually contain these values, only references to them. Assignment, parameter passing, and function returns always manipulate references to such values; these operations do not imply any kind of copy."





On Tue, Oct 20, 2020, 18:37 孙世龙 sunshilong <[hidden email]> wrote:
>>>there are lua objects,just not gc object.
>> LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER are not gc objects?
>No, they're not objects, they're just values. When you assign them you make a copy.
You mean that they(i.e.
LUA_TBOOLEAN、LUA_TLIGHTUSERDATA and LUA_TNUMBER
 ) are neither "objects" and "gc objects"?

Then what's an object in Lua? Is there a clear definition?
The tables, long strings belong to Lua objects?

Am I right?


On Wed, Oct 21, 2020 at 2:23 AM Gé Weijers <[hidden email]> wrote:
>
> On Tue, Oct 20, 2020 at 7:46 AM Roberto Ierusalimschy
> <[hidden email]> wrote:
> >
> > > Strings are a bit different, because they're immutable, once created
> > > they can't change, they act like values although they're garbage
> > > collected, "a == b" returns string equality, even if these two strings
> > > are not the same object in the interpreter (this will only happen for
> > > long strings, over 32 bytes I think).
> >
> > 40 bytes (LUAI_MAXSHORTLEN).
>
> I misremembered, 32 was related to the byte skipping used to speed up
> the string hash (a 5 bit right shift is equivalent to a division by
> 32). The 'step' is calculated as (len >> LUAI_HASHLIMIT)+1.
>
> --
> Gé