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

Function tinsert

third-party/lua-5.2.4/src/ltablib.c:42–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42static int tinsert (lua_State *L) {
43 int e = aux_getn(L, 1) + 1; /* first empty element */
44 int pos; /* where to insert new element */
45 switch (lua_gettop(L)) {
46 case 2: { /* called with only 2 arguments */
47 pos = e; /* insert new element at the end */
48 break;
49 }
50 case 3: {
51 int i;
52 pos = luaL_checkint(L, 2); /* 2nd argument is the position */
53 luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
54 for (i = e; i > pos; i--) { /* move up elements */
55 lua_rawgeti(L, 1, i-1);
56 lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
57 }
58 break;
59 }
60 default: {
61 return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
62 }
63 }
64 lua_rawseti(L, 1, pos); /* t[pos] = v */
65 return 0;
66}
67
68
69static int tremove (lua_State *L) {

Callers

nothing calls this directly

Calls 4

lua_gettopFunction · 0.70
lua_rawgetiFunction · 0.70
lua_rawsetiFunction · 0.70
luaL_errorFunction · 0.70

Tested by

no test coverage detected