MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / tinsert

Function tinsert

Source/Misc/lua/src/lua.c:14636–14661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

lua_gettopFunction · 0.85
lua_rawgetiFunction · 0.85
lua_rawsetiFunction · 0.85
luaL_errorFunction · 0.85
luaL_setnFunction · 0.85

Tested by

no test coverage detected