MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tinsert

Function tinsert

freebsd/contrib/openzfs/module/lua/ltablib.c:40–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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