lua-users home
lua-l archive

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


Hi, list

As per the documentation(https://www.lua.org/pil/26.1.html), which says:

As a first example, let us see how to implement a simplified version
of a function that returns the sine of a given number (a more
professional implementation should check whether its argument is a
number):

    static int l_sin (lua_State *L) {
      double d = lua_tonumber(L, 1);  /* get argument */
      lua_pushnumber(L, sin(d));  /* push result */
      return 1;  /* number of results */
    }
>From the point of view of C, a C function gets as its single argument
the Lua state and returns (in C) an integer with the number of values
it is returning (in Lua). Therefore, the function does not need to
clear the stack before pushing its results. After it returns, Lua
automatically removes whatever is in the stack below the results.

***
How to comprehend that Lua automatically removes whatever is in the
stack below the results after the function returned?
How does it achieve this goal?
Any explanation or document helps.
I would be grateful if you could shed some light on this matter.

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