| 14634 | |
| 14635 | |
| 14636 | static int tinsert (lua_State *L) { |
| 14637 | int e = aux_getn(L, 1) + 1; /* first empty element */ |
| 14638 | int pos; /* where to insert new element */ |
| 14639 | switch (lua_gettop(L)) { |
| 14640 | case 2: { /* called with only 2 arguments */ |
| 14641 | pos = e; /* insert new element at the end */ |
| 14642 | break; |
| 14643 | } |
| 14644 | case 3: { |
| 14645 | int i; |
| 14646 | pos = luaL_checkint(L, 2); /* 2nd argument is the position */ |
| 14647 | if (pos > e) e = pos; /* `grow' array if necessary */ |
| 14648 | for (i = e; i > pos; i--) { /* move up elements */ |
| 14649 | lua_rawgeti(L, 1, i-1); |
| 14650 | lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ |
| 14651 | } |
| 14652 | break; |
| 14653 | } |
| 14654 | default: { |
| 14655 | return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); |
| 14656 | } |
| 14657 | } |
| 14658 | luaL_setn(L, 1, e); /* new size */ |
| 14659 | lua_rawseti(L, 1, pos); /* t[pos] = v */ |
| 14660 | return 0; |
| 14661 | } |
| 14662 | |
| 14663 | |
| 14664 | static int tremove (lua_State *L) { |
nothing calls this directly
no test coverage detected