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