What does "slot" mean for Lua?

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

What does "slot" mean for Lua?

孙世龙 sunshilong
Hi, list

As per the documentation(https://www.lua.org/pil/24.2.1.html),
which says that [emphasise mine]:
When Lua starts and any time that Lua calls C, the stack has at least 20
**free slots** (this constant is defined as LUA_MINSTACK in lua.h). This is
          ^^^^
more than enough for most common uses, so usually we do not even think
about that. However, some tasks may need more stack space (e.g., for
calling a function with a variable number of arguments).

What does "slot" mean for Lua?
I guess it is Tagged Values(i.e struct TValue) since there is a hint on
http://lua-users.org/wiki/FastStringPatc, which says that:
Lua stores all objects in tagged value slots on the Lua stack or in
Lua tables. These slots are usually 12 or 16 bytes long (depending
on the architecture and the type of lua_Number). The size is
dominated by the requirement to store properly aligned pointers and
lua_Number's. The tag itself is a small integer and easily fits into
a single byte. That leaves us either 11 or 15 bytes of free space
that can be put to good use.

Please let me know if I miss something.

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

Re: What does "slot" mean for Lua?

Egor Skriptunoff-2
On Thu, Sep 24, 2020 at 11:49 AM 孙世龙 sunshilong wrote:
What does "slot" mean for Lua?

A stack (abstract data type) consists of elements (they may also be referred to as cells, slots,...).
A slot in Lua docs is an element of Lua C API stack.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

孙世龙 sunshilong
>> What does "slot" mean for Lua?
>A stack (abstract data type) consists of elements (they may also be referred to as cells, slots,...).
>A slot in Lua docs is an element of Lua C API stack.
Could you please explain that in more details or suggest some articles
for me to go through?
How does this kind of element is reprensented?

Thank you for your attention to my question.

Best regards
Sunshilong

On Thu, Sep 24, 2020 at 5:11 PM Egor Skriptunoff
<[hidden email]> wrote:
>
> On Thu, Sep 24, 2020 at 11:49 AM 孙世龙 sunshilong wrote:
>>
>> What does "slot" mean for Lua?
>
>
> A stack (abstract data type) consists of elements (they may also be referred to as cells, slots,...).
> A slot in Lua docs is an element of Lua C API stack.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

Viacheslav Usov
In reply to this post by 孙世龙 sunshilong
On Thu, Sep 24, 2020 at 10:48 AM 孙世龙 sunshilong <[hidden email]> wrote:

> As per the documentation(https://www.lua.org/pil/24.2.1.html),

This is not the documentation. It is a book that complements the
documentation, and it describes a version of Lua that was current 15
years ago.

The current documentation is at https://www.lua.org/manual/5.4/

The latest edition of the book Programming in Lua targets Lua 5.3 and
it is not available at lua.org free of charge.

The other page that you found is also not documentation, and it was
written more than 10 years ago.

Even if some of what they might be true today, you should be very
careful about statements made so long ago, and you should try to
confirm them with the current documentation.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

孙世龙 sunshilong
Hi, Viacheslav Usov

>Even if some of what they might be true today, you should be very
>careful about statements made so long ago, and you should try to
>confirm them with the current documentation.
Thanks a lot.

As per the manual that is contained in the repo of Lua(
https://github.com/lua/lua/blob/master/manual/manual.of),
which says that [emphasis mine]:
Whenever Lua calls C, it ensures that the stack has space for
at least LUA_MINSTACK extra **slots**.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
LUA_MINSTACK is defined as 20, so that usually you do not
have to worry about stack space unless your code has loops
pushing elements onto the stack.

The same question arises, what does the "slots" mean for Lua?

Thank you for your attention to this matter.
Best Regards
Sunshilong

On Thu, Sep 24, 2020 at 7:59 PM Viacheslav Usov <[hidden email]> wrote:

>
> On Thu, Sep 24, 2020 at 10:48 AM 孙世龙 sunshilong <[hidden email]> wrote:
>
> > As per the documentation(https://www.lua.org/pil/24.2.1.html),
>
> This is not the documentation. It is a book that complements the
> documentation, and it describes a version of Lua that was current 15
> years ago.
>
> The current documentation is at https://www.lua.org/manual/5.4/
>
> The latest edition of the book Programming in Lua targets Lua 5.3 and
> it is not available at lua.org free of charge.
>
> The other page that you found is also not documentation, and it was
> written more than 10 years ago.
>
> Even if some of what they might be true today, you should be very
> careful about statements made so long ago, and you should try to
> confirm them with the current documentation.
>
> Cheers,
> V.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

Viacheslav Usov
On Thu, Sep 24, 2020 at 2:09 PM 孙世龙 sunshilong <[hidden email]> wrote:

> https://github.com/lua/lua/blob/master/manual/manual.of

This is work in progress that does not necessarily correspond to any
released version of Lua. This is the other dangerous end, and you
should be equally careful about it.

> The same question arises, what does the "slots" mean for Lua?

There are only 7 mentions of the word "slot" in the manual, and I
think the second of them defines exactly what it means.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

孙世龙 sunshilong
>> https://github.com/lua/lua/blob/master/manual/manual.of
>This is work in progress that does not necessarily correspond to any
>released version of Lua. This is the other dangerous end, and you
>should be equally careful about it.
I see. Thank you.
I can find the same statement in the official version of Lua.
As for as I know, there is no official git or repo, so I have no choice other
than posting the aforementioned repo to show the statement (which I saw in
the officially released version).

>>The same question arises, what does the "slots" mean for Lua?
>There are only 7 mentions of the word "slot" in the manual, and I
>think the second of them defines exactly what it means.
Hmmmm, you mean this one:
Ensures that the stack has space for at least @id{n} extra slots,
that is, that you can safely push up to @id{n} values into it.

If I understand it correctly, the stack contains several slots which can
be used to store numbers and etc. Am I right?
How "slots" are implemented?
How this goal (i.e slots can store several kinds\types of data) is achieved?

Best regards
Sunshilong

On Thu, Sep 24, 2020 at 8:21 PM Viacheslav Usov <[hidden email]> wrote:

>
> On Thu, Sep 24, 2020 at 2:09 PM 孙世龙 sunshilong <[hidden email]> wrote:
>
> > https://github.com/lua/lua/blob/master/manual/manual.of
>
> This is work in progress that does not necessarily correspond to any
> released version of Lua. This is the other dangerous end, and you
> should be equally careful about it.
>
> > The same question arises, what does the "slots" mean for Lua?
>
> There are only 7 mentions of the word "slot" in the manual, and I
> think the second of them defines exactly what it means.
>
> Cheers,
> V.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

Viacheslav Usov
On Thu, Sep 24, 2020 at 2:52 PM 孙世龙 sunshilong <[hidden email]> wrote:

> As for as I know, there is no official git or repo, so I have no choice other
> than posting the aforementioned repo to show the statement (which I saw in
> the officially released version).

The official source of information on Lua is lua.org. It has
documentation and source code. Anything else is not official.

As I already said, the official current documentation is at
https://www.lua.org/manual/5.4/. There are also manuals for older
versions. But then you need to say what version you are using.

> How "slots" are implemented?

Any such question can be answered by looking at Lua's source code. For
Lua 5.4: https://www.lua.org/ftp/lua-5.4.0.tar.gz.

None of this needs to be known to use Lua.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

Dibyendu Majumdar
In reply to this post by 孙世龙 sunshilong
On Thu, 24 Sep 2020 at 13:52, 孙世龙 sunshilong <[hidden email]> wrote:
> If I understand it correctly, the stack contains several slots which can
> be used to store numbers and etc. Am I right?
> How "slots" are implemented?
> How this goal (i.e slots can store several kinds\types of data) is achieved?
>

At some point you will need to start reading the code to figure things
out especially if you intend to customise Lua.
Reply | Threaded
Open this post in threaded view
|

Re: What does "slot" mean for Lua?

Luiz Henrique de Figueiredo
In reply to this post by Viacheslav Usov
> Any such question can be answered by looking at Lua's source code.

See also http://www.lua.org/source/5.4/