| 77 | |
| 78 | |
| 79 | static int tinsert (lua_State *L) { |
| 80 | lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */ |
| 81 | lua_Integer pos; /* where to insert new element */ |
| 82 | switch (lua_gettop(L)) { |
| 83 | case 2: { /* called with only 2 arguments */ |
| 84 | pos = e; /* insert new element at the end */ |
| 85 | break; |
| 86 | } |
| 87 | case 3: { |
| 88 | lua_Integer i; |
| 89 | pos = luaL_checkinteger(L, 2); /* 2nd argument is the position */ |
| 90 | luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds"); |
| 91 | for (i = e; i > pos; i--) { /* move up elements */ |
| 92 | lua_geti(L, 1, i - 1); |
| 93 | lua_seti(L, 1, i); /* t[i] = t[i - 1] */ |
| 94 | } |
| 95 | break; |
| 96 | } |
| 97 | default: { |
| 98 | return luaL_error(L, "wrong number of arguments to 'insert'"); |
| 99 | } |
| 100 | } |
| 101 | lua_seti(L, 1, pos); /* t[pos] = v */ |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | static int tremove (lua_State *L) { |
nothing calls this directly
no test coverage detected