| 40 | |
| 41 | |
| 42 | static int tinsert (lua_State *L) { |
| 43 | int e = aux_getn(L, 1) + 1; /* first empty element */ |
| 44 | int pos; /* where to insert new element */ |
| 45 | switch (lua_gettop(L)) { |
| 46 | case 2: { /* called with only 2 arguments */ |
| 47 | pos = e; /* insert new element at the end */ |
| 48 | break; |
| 49 | } |
| 50 | case 3: { |
| 51 | int i; |
| 52 | pos = luaL_checkint(L, 2); /* 2nd argument is the position */ |
| 53 | luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds"); |
| 54 | for (i = e; i > pos; i--) { /* move up elements */ |
| 55 | lua_rawgeti(L, 1, i-1); |
| 56 | lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ |
| 57 | } |
| 58 | break; |
| 59 | } |
| 60 | default: { |
| 61 | return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); |
| 62 | } |
| 63 | } |
| 64 | lua_rawseti(L, 1, pos); /* t[pos] = v */ |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | static int tremove (lua_State *L) { |
nothing calls this directly
no test coverage detected