rename lua_State

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

rename lua_State

Thijs Schreijer
As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?

I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.

Thijs

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Coroutines
On Sun, Aug 24, 2014 at 1:02 PM, Thijs Schreijer
<[hidden email]> wrote:
> As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?
>
> I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.

>From my shallow knowledge of that struct, "lua_Stack" would seem more
appropriate.

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Patrick Donnelly
In reply to this post by Thijs Schreijer
On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
<[hidden email]> wrote:
> As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?
>
> I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.

+1 for lua_Thread.

--
Patrick Donnelly

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Dirk Laurie-2
In reply to this post by Thijs Schreijer
2014-08-24 22:02 GMT+02:00 Thijs Schreijer <[hidden email]>:
> As "lua_State" not actually refers to a state, but to a thread
> or an execution stack, could it be renamed? To something that
> properly reflects what it is?

-1.

I'm not going to argue, though one could, about "state" in terms
of Turing machines. The issue is more practical.

When I was a junior programmer, I often asked a certain senior
colleague for help. Invariably, when the question involved some
user-supplied name, such as a filename, he would put "PIET"
in his example. (That is one of the most common nicknames
for a male in my country.)

I asked him why he does not put FILENAME etc. He said:
"It's just a name. Use anything you can remember."

Now, I have almost four year's worth of C code full of
parameter lists starting

   Lua_State *L,...

and I no longer even think of what I type before that *L.
It's just a name. I would be equally happy with PIET.
And I would hate, really hate, to change all that code.

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Thomas Jericke
In reply to this post by Patrick Donnelly
On 08/25/2014 02:56 AM, Patrick Donnelly wrote:
> On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
> <[hidden email]> wrote:
>> As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?
>>
>> I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.
> +1 for lua_Thread.
>

I don't really get the use of the word 'thread' in the C API, they are
called "coroutines" in the Lua library.
--
Thomas

Reply | Threaded
Open this post in threaded view
|

RE: rename lua_State

Thijs Schreijer
In reply to this post by Coroutines

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Coroutines
> Sent: maandag 25 augustus 2014 0:50
> To: Lua mailing list
> Subject: Re: rename lua_State
>
> On Sun, Aug 24, 2014 at 1:02 PM, Thijs Schreijer
> <[hidden email]> wrote:
> > As "lua_State" not actually refers to a state, but to a thread or an
> execution stack, could it be renamed? To something that properly reflects
> what it is?
> >
> > I suspect that the name was introduced before coroutines were added, which
> meant that a state and a thread were pretty much the same thing then.
>
> >From my shallow knowledge of that struct, "lua_Stack" would seem more
> appropriate.

I think lua_Stack is more appropriate than lua_Thread;

Consider code
- In C having L1 as reference
- it calls Lua code
- The Lua code calls another C function, having L2 as reference

If you name it lua_Thread, you would assume L1 and L2 would be the same, as they run on the same coroutine/thread. But they are not the same, they both have their own stack to interact with Lua.

Hence lua_Stack would be more appropriate I think.

Thijs
Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Alex Queiroz
In reply to this post by Thijs Schreijer
Hallo,

On Sun, Aug 24, 2014 at 10:02 PM, Thijs Schreijer
<[hidden email]> wrote:
> As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?
>

Hmm, no.

"An opaque structure that points to a thread and indirectly (through
the thread) to the whole state of a Lua interpreter. The Lua library
is fully reentrant: it has no global variables. All information about
a state is accessible through this structure. "

Cheers,
--
-alex
http://unendli.ch/

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Roberto Ierusalimschy
In reply to this post by Thijs Schreijer
> Consider code
> - In C having L1 as reference
> - it calls Lua code
> - The Lua code calls another C function, having L2 as reference
>
> If you name it lua_Thread, you would assume L1 and L2 would be the same, as they run on the same coroutine/thread. But they are not the same, they both have their own stack to interact with Lua.

But L1 and L2 will be the same (that is, L1 == L2)! Each routine has its
own stack, but they use the same PIET to refer to their stacks (unless
they are in different threads).

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Tim Hill
In reply to this post by Dirk Laurie-2

On Aug 24, 2014, at 11:51 PM, Dirk Laurie <[hidden email]> wrote:

> 2014-08-24 22:02 GMT+02:00 Thijs Schreijer <[hidden email]>:
>> As "lua_State" not actually refers to a state, but to a thread
>> or an execution stack, could it be renamed? To something that
>> properly reflects what it is?
>
> -1.
>
> I'm not going to argue, though one could, about "state" in terms
> of Turing machines. The issue is more practical.
>
> When I was a junior programmer, I often asked a certain senior
> colleague for help. Invariably, when the question involved some
> user-supplied name, such as a filename, he would put "PIET"
> in his example. (That is one of the most common nicknames
> for a male in my country.)

So it’s going to be lua_PIET now? :)

-1 for me too, I see no problem with the existing name, particularly as most C code doesn’t really care which lua_State it is given; it just uses it as “the current state”.

However, I think a paragraph or two in the reference manual clarifying the relationship between Lua states, stack and the “shared” state (registry etc) would be useful for those starting out with the C API.

—Tim



Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Dirk Laurie-2
2014-08-25 20:10 GMT+02:00 Tim Hill <[hidden email]>:

> However, I think a paragraph or two in the reference manual
> clarifying the relationship between Lua states, stack and the
> “shared” state (registry etc) would be useful for those starting
> out with the C API.

Well, now. We don't want PiL to become dispensable, do we?

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Tim Hill

On Aug 25, 2014, at 11:31 AM, Dirk Laurie <[hidden email]> wrote:

> 2014-08-25 20:10 GMT+02:00 Tim Hill <[hidden email]>:
>
>> However, I think a paragraph or two in the reference manual
>> clarifying the relationship between Lua states, stack and the
>> “shared” state (registry etc) would be useful for those starting
>> out with the C API.
>
> Well, now. We don't want PiL to become dispensable, do we?
>

Well in PiL then, as that doesn’t cover much about this topic either (from memory, it’s been a few years since I looked at the chapters on the Lua API).

—Tim


Reply | Threaded
Open this post in threaded view
|

RE: rename lua_State

Thijs Schreijer
In reply to this post by Roberto Ierusalimschy

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Roberto Ierusalimschy
> Sent: maandag 25 augustus 2014 20:05
> To: Lua mailing list
> Subject: Re: rename lua_State
>
> > Consider code
> > - In C having L1 as reference
> > - it calls Lua code
> > - The Lua code calls another C function, having L2 as reference
> >
> > If you name it lua_Thread, you would assume L1 and L2 would be the same,
> as they run on the same coroutine/thread. But they are not the same, they
> both have their own stack to interact with Lua.
>
> But L1 and L2 will be the same (that is, L1 == L2)! Each routine has its
> own stack, but they use the same PIET to refer to their stacks (unless
> they are in different threads).
>
> -- Roberto

The behaviour is different due to the different stacks they use. Hence I thought lua_Stack would be more appropriate. Anyway, lua_State is worse than both others imo.

I just think it's easier to explain that 2 lua_Stack structures act on their own stacks, but are the same structure (L1 == L2). Than explaining that lua_State is not actually a state at all, but a thread, and then further down the line, depending on where you happen to use it, it acts on different stacks. I've seen many questions here on the list relating to this.

Anything that better represents its use than lua_State would be fine by me.

Thijs

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Ahmed Charles
For the record, I like lua_State.

> On Aug 26, 2014, at 12:39 AM, "Thijs Schreijer" <[hidden email]> wrote:
>
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On
>> Behalf Of Roberto Ierusalimschy
>> Sent: maandag 25 augustus 2014 20:05
>> To: Lua mailing list
>> Subject: Re: rename lua_State
>>
>>> Consider code
>>> - In C having L1 as reference
>>> - it calls Lua code
>>> - The Lua code calls another C function, having L2 as reference
>>>
>>> If you name it lua_Thread, you would assume L1 and L2 would be the same,
>> as they run on the same coroutine/thread. But they are not the same, they
>> both have their own stack to interact with Lua.
>>
>> But L1 and L2 will be the same (that is, L1 == L2)! Each routine has its
>> own stack, but they use the same PIET to refer to their stacks (unless
>> they are in different threads).
>>
>> -- Roberto
>
> The behaviour is different due to the different stacks they use. Hence I thought lua_Stack would be more appropriate. Anyway, lua_State is worse than both others imo.
>
> I just think it's easier to explain that 2 lua_Stack structures act on their own stacks, but are the same structure (L1 == L2). Than explaining that lua_State is not actually a state at all, but a thread, and then further down the line, depending on where you happen to use it, it acts on different stacks. I've seen many questions here on the list relating to this.
>
> Anything that better represents its use than lua_State would be fine by me.
>
> Thijs
>

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Duncan Cross
In reply to this post by Thomas Jericke



On Mon, Aug 25, 2014 at 8:01 AM, Thomas Jericke <[hidden email]> wrote:
On 08/25/2014 02:56 AM, Patrick Donnelly wrote:
On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
<[hidden email]> wrote:
As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?

I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.
+1 for lua_Thread.


I don't really get the use of the word 'thread' in the C API, they are called "coroutines" in the Lua library.
--
Thomas


It's because not all threads are coroutines. Every Lua state automatically has a "main" thread, and this thread is not a coroutine. It cannot be suspended.

For example, compare the C API function lua_pushthread(L), which will always push a thread object even if it is the main thread, with the Lua library function coroutine.running(), which will return nil if the current thread is the main thread.

-Duncan

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Duncan Cross



On Tue, Aug 26, 2014 at 10:15 AM, Duncan Cross <[hidden email]> wrote:
On Mon, Aug 25, 2014 at 8:01 AM, Thomas Jericke <[hidden email]> wrote:
On 08/25/2014 02:56 AM, Patrick Donnelly wrote:
On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
<[hidden email]> wrote:
As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?

I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.
+1 for lua_Thread.


I don't really get the use of the word 'thread' in the C API, they are called "coroutines" in the Lua library.
--
Thomas


It's because not all threads are coroutines. Every Lua state automatically has a "main" thread, and this thread is not a coroutine. It cannot be suspended.

For example, compare the C API function lua_pushthread(L), which will always push a thread object even if it is the main thread, with the Lua library function coroutine.running(), which will return nil if the current thread is the main thread.

-Duncan
 
Unless things have changed in the most recent version(s), in which case: for historical reasons. :)

-Duncan

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Thomas Jericke
In reply to this post by Duncan Cross
On 08/26/2014 11:15 AM, Duncan Cross wrote:



On Mon, Aug 25, 2014 at 8:01 AM, Thomas Jericke <[hidden email]> wrote:
On 08/25/2014 02:56 AM, Patrick Donnelly wrote:
On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
<[hidden email]> wrote:
As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?

I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.
+1 for lua_Thread.


I don't really get the use of the word 'thread' in the C API, they are called "coroutines" in the Lua library.
--
Thomas


It's because not all threads are coroutines. Every Lua state automatically has a "main" thread, and this thread is not a coroutine. It cannot be suspended.

For example, compare the C API function lua_pushthread(L), which will always push a thread object even if it is the main thread, with the Lua library function coroutine.running(), which will return nil if the current thread is the main thread.

-Duncan

That doesn't explain lua_newthread which (AFAIK) always returns a coroutine, and the only thread that isn't a coroutine is made with lua_newstate ;-)
It doesn't really brother me as long as it is in the C API.

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

Re: rename lua_State

Jerome Vuarand
In reply to this post by Duncan Cross
2014-08-26 10:15 GMT+01:00 Duncan Cross <[hidden email]>:
> It's because not all threads are coroutines. Every Lua state automatically
> has a "main" thread, and this thread is not a coroutine. It cannot be
> suspended.

Also Lua threads don't necessarily have the "routine" part of
coroutines. coroutine.create takes a function to be run, but from C
you can create a thread and use it without ever calling a function in
it. It's sometimes useful for example to store temporary data when
binding C APIs involving callbacks (you create a clean thread, pass
it's lua_State* as the API void*, have the callback push values, and
xmove them afterwards).

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Dirk Laurie-2
In reply to this post by Thijs Schreijer
2014-08-24 22:02 GMT+02:00 Thijs Schreijer <[hidden email]>:

> As "lua_State" not actually refers to a state, but to a thread or an
> execution, could it be renamed? To something that properly reflects
> what it is?
>
> I suspect that the name was introduced before coroutines were added,
> which meant that a state and a thread were pretty much the same thing
> then.

Your suspicion is correct. lua_State was introduced in Lua 3.1, the
API routines took *L as a parameter as from Lua 4.0, coroutines were
introduced in Lua 5.0.

But the world is full of things with names that reflect history rather
than modern insight. The "English horn" is not a horn. "Bombay duck"
is not a duck, etc.

And one is also used to various kinds of states: the state of the
nation, the nation state, a state of anxiety.

Frankly, if the most important thing that might be changed in Lua
is the word used for the structure created by lua_newstate (yes,
the repercussions of changing lua_State are considerable), there
is nothing rotten in the state of Lua.

Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Soni "They/Them" L.
In reply to this post by Duncan Cross

On 26/08/14 06:18 AM, Duncan Cross wrote:



On Tue, Aug 26, 2014 at 10:15 AM, Duncan Cross <[hidden email]> wrote:
On Mon, Aug 25, 2014 at 8:01 AM, Thomas Jericke <[hidden email]> wrote:
On 08/25/2014 02:56 AM, Patrick Donnelly wrote:
On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
<[hidden email]> wrote:
As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?

I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.
+1 for lua_Thread.


I don't really get the use of the word 'thread' in the C API, they are called "coroutines" in the Lua library.
--
Thomas


It's because not all threads are coroutines. Every Lua state automatically has a "main" thread, and this thread is not a coroutine. It cannot be suspended.

For example, compare the C API function lua_pushthread(L), which will always push a thread object even if it is the main thread, with the Lua library function coroutine.running(), which will return nil if the current thread is the main thread.

-Duncan
 
Unless things have changed in the most recent version(s), in which case: for historical reasons. :)

-Duncan

coroutine.running() returns the main thread in lua 5.2+

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> =coroutine.running()
thread: 0xc8b010    true
>
Reply | Threaded
Open this post in threaded view
|

Re: rename lua_State

Axel Kittenberger
Can you save a state and revert a machine to a previous state (like in VMs)? Or is the whole thing part of a state machine?

If not, "state" doesnt quite cut it. "lua_Instance" would IMHO be a better name.

I disagree with the "PIET" argument. If you are not doing that one-time-throw-away-script, coding is at least as much communicating with other humans as it is communicating with the computer. So anyhting *I* remember will is not a good point.

Is it worth changing it? I don't know, I like renaming things when I figured out a better caption for something thats more precise or to now fit better in an overall naming scheme.

Albeit I can fully undestand if someone says, a rename is definitely not worth the breakage when the library binding would be called lua_newinstance instead of newstate.


On Tue, Aug 26, 2014 at 1:57 PM, Thiago L. <[hidden email]> wrote:

On 26/08/14 06:18 AM, Duncan Cross wrote:



On Tue, Aug 26, 2014 at 10:15 AM, Duncan Cross <[hidden email]> wrote:
On Mon, Aug 25, 2014 at 8:01 AM, Thomas Jericke <[hidden email]> wrote:
On 08/25/2014 02:56 AM, Patrick Donnelly wrote:
On Sun, Aug 24, 2014 at 4:02 PM, Thijs Schreijer
<[hidden email]> wrote:
As "lua_State" not actually refers to a state, but to a thread or an execution stack, could it be renamed? To something that properly reflects what it is?

I suspect that the name was introduced before coroutines were added, which meant that a state and a thread were pretty much the same thing then.
+1 for lua_Thread.


I don't really get the use of the word 'thread' in the C API, they are called "coroutines" in the Lua library.
--
Thomas


It's because not all threads are coroutines. Every Lua state automatically has a "main" thread, and this thread is not a coroutine. It cannot be suspended.

For example, compare the C API function lua_pushthread(L), which will always push a thread object even if it is the main thread, with the Lua library function coroutine.running(), which will return nil if the current thread is the main thread.

-Duncan
 
Unless things have changed in the most recent version(s), in which case: for historical reasons. :)

-Duncan

coroutine.running() returns the main thread in lua 5.2+

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> =coroutine.running()
thread: 0xc8b010    true
>

12