lua-users home
lua-l archive

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


>> >Assuming table is at index 1
>> Index 1?
>> In general, the index of the stack is a negative number, e.g -1, -2, and so on.

>Not in the common case of referring to arguments passed to your C function from Lua, which are usually referred to with positive numbers
> (since the first >argument is always at index 1, the second argument at index 2, etc.)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Could you please explain that(i.e the emphasised part) in more detail?
I'd appreciate it if you could give me a simple example which could
make it clearer.c

ADDED:
I passed a negtive number to lua_rawget function and it worked indeed.

Here is the pseudocode:

myRegFunc()                                //omit types
{
       assertIfNotLuaString(-1);         //the index -1 is LUA_TSTRING indeed.
       pushLuaString("keyName");    //internally invoking lua_pushstring
      assert(lua_rawget(-2)==LUA_TNIL);  // no assertion, the key is
found indeed.
}

On Fri, Jan 15, 2021 at 9:34 AM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>
> >> >Assuming table is at index 1
> >> Index 1?
> >> In general, the index of the stack is a negative number, e.g -1, -2, and so on.
>
> >Not in the common case of referring to arguments passed to your C function from Lua, which are usually referred to with positive numbers
> > (since the first >argument is always at index 1, the second argument at index 2, etc.)
>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Could you please explain that(i.e the emphasised part) in more detail?
>
>
> On Fri, Jan 15, 2021 at 9:15 AM Jonathan Goble <jcgoble3@gmail.com> wrote:
> >
> > On Thu, Jan 14, 2021 at 8:10 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> >>
> >> >Assuming table is at index 1
> >> Index 1?
> >> In general, the index of the stack is a negative number, e.g -1, -2, and so on.
> >
> >
> > Not in the common case of referring to arguments passed to your C function from Lua, which are usually referred to with positive numbers (since the first argument is always at index 1, the second argument at index 2, etc.)