| 88 | |
| 89 | |
| 90 | static int tinsert (lua_State *L) { |
| 91 | int e = aux_getn(L, 1) + 1; /* first empty element */ |
| 92 | int pos; /* where to insert new element */ |
| 93 | switch (lua_gettop(L)) { |
| 94 | case 2: { /* called with only 2 arguments */ |
| 95 | pos = e; /* insert new element at the end */ |
| 96 | break; |
| 97 | } |
| 98 | case 3: { |
| 99 | int i; |
| 100 | pos = luaL_checkint(L, 2); /* 2nd argument is the position */ |
| 101 | if (pos > e) e = pos; /* `grow' array if necessary */ |
| 102 | for (i = e; i > pos; i--) { /* move up elements */ |
| 103 | lua_rawgeti(L, 1, i-1); |
| 104 | lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ |
| 105 | } |
| 106 | break; |
| 107 | } |
| 108 | default: { |
| 109 | return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); |
| 110 | } |
| 111 | } |
| 112 | luaL_setn(L, 1, e); /* new size */ |
| 113 | lua_rawseti(L, 1, pos); /* t[pos] = v */ |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | static int tremove (lua_State *L) { |
nothing calls this directly
no test coverage detected