lua-users home
lua-l archive

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


English is not my native language,so it is maybe a little difficult to understand me.Sorry.
>Could you please explain that(i.e the >emphasised part) in more detail? 
Negative indexes access the stack from the top.So if there are n things on the stack,the negative index -i is equal to n-i+1
A C function that was called by Lua can only access the arguments pushed by Lua,just like the at first the stack was empty and then Lua pushed the arguments.
When we call a C function,Lua will push the arguments from left to right one by one.So the first argument passed to the C function is at index 1.

>I'd appreciate it if you could give me a simple >example which could 
>make it clearer.c 

e.g.
// C function
int foo(lua_State *state)
{
    lua_pushvalue(state,-3);
    lua_pushvalue(state,1);
    return 2;
}
It will return two same values("foo1") when we call it like
foo("foo1",13,{}); -- return "foo1"  "foo1"