| 118 | */ |
| 119 | |
| 120 | static int pack (lua_State *L) { |
| 121 | int n = lua_gettop(L); /* number of elements to pack */ |
| 122 | lua_createtable(L, n, 1); /* create result table */ |
| 123 | lua_pushinteger(L, n); |
| 124 | lua_setfield(L, -2, "n"); /* t.n = number of elements */ |
| 125 | if (n > 0) { /* at least one element? */ |
| 126 | int i; |
| 127 | lua_pushvalue(L, 1); |
| 128 | lua_rawseti(L, -2, 1); /* insert first element */ |
| 129 | lua_replace(L, 1); /* move table into index 1 */ |
| 130 | for (i = n; i >= 2; i--) /* assign other elements */ |
| 131 | lua_rawseti(L, 1, i); |
| 132 | } |
| 133 | return 1; /* return table */ |
| 134 | } |
| 135 | |
| 136 | |
| 137 | static int unpack (lua_State *L) { |
nothing calls this directly
no test coverage detected