MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / tinsert

Function tinsert

third-party/lua-5.5.0/src/ltablib.c:72–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70
71
72static int tinsert (lua_State *L) {
73 lua_Integer pos; /* where to insert new element */
74 lua_Integer e = aux_getn(L, 1, TAB_RW);
75 e = luaL_intop(+, e, 1); /* first empty element */
76 switch (lua_gettop(L)) {
77 case 2: { /* called with only 2 arguments */
78 pos = e; /* insert new element at the end */
79 break;
80 }
81 case 3: {
82 lua_Integer i;
83 pos = luaL_checkinteger(L, 2); /* 2nd argument is the position */
84 /* check whether 'pos' is in [1, e] */
85 luaL_argcheck(L, (lua_Unsigned)pos - 1u < (lua_Unsigned)e, 2,
86 "position out of bounds");
87 for (i = e; i > pos; i--) { /* move up elements */
88 lua_geti(L, 1, i - 1);
89 lua_seti(L, 1, i); /* t[i] = t[i - 1] */
90 }
91 break;
92 }
93 default: {
94 return luaL_error(L, "wrong number of arguments to 'insert'");
95 }
96 }
97 lua_seti(L, 1, pos); /* t[pos] = v */
98 return 0;
99}
100
101
102static int tremove (lua_State *L) {

Callers

nothing calls this directly

Calls 5

lua_gettopFunction · 0.70
luaL_checkintegerFunction · 0.70
lua_getiFunction · 0.70
lua_setiFunction · 0.70
luaL_errorFunction · 0.70

Tested by

no test coverage detected