I want to implement a function with the C language, this function needs to be called with the table argument, and it should return a table type value.
Usually we implement a function with C for lua, for example, using code. But the library does not provide luaL_checktable and lua_pushtable, what can we do?
static int average(lua_State *L) { int n = lua_gettop(L); double sum = 0; int i; for (i = 1; i <= n; i++) { sum += lua_tonumber(L, i); } lua_pushnumber(L, sum / n); lua_pushnumber(L, sum); return 2; }
source share