[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Not one stack but several? I'm mixed up
- From: Dong Feng <middle.fengdong@...>
- Date: Mon, 7 Jan 2013 00:20:06 +0800
Hi Patrick,
I once had a similar confusion, though only for a very short while.
The problem is, when we hear the term "stack," most of us would think
of "call-stack." In most languages, call-stack is used for both
continuation and parameter passing. And call-stack is by its nature
per-thread. As Lua VM is single-threaded, it is natural to think there
is a "global stack."
But Lua C API stack is not a call-stack stack. It is used for purely
parameter passing. A C API stack is shared between a calling Lua
function, and a called C function, and (if there is any) the Lua
functions immediately called by the C function. There is up to
three-level sharing the stack, but never two levels of C function
share a C API stack.
And, to my understanding, Lua does have a complex call-stack, which
consists of one or more fragments of Lua call-stack intermediated by
one or more C runtime stack. Lua call-stacks are maintained by Lua VM.
Neither Lua code nor Lua VM is able to access the content of C
runtime stack (unless through black-art hacking). Lua VM maintains a
structure about the relative level position among Lua call-stack and C
runtime stacks. (Maybe this is not accurate.)
Dong
2013/1/6 Patrick <patrick@spellingbeewinnars.org>:
> [snip]
>
>
> I hope this clarifies things for you
>
> Hi Jerome
>
> It does thanks!
>
> Did anyone else get confused with this earlier on? Should I post something
> on the wiki in a few weeks or months when I have finished studying, so
> others won't get mixed up?
>