MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / tinsert

Function tinsert

other_src/lua/src/ltablib.cpp:97–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95
96
97static int tinsert (lua_State *L) {
98 int e = aux_getn(L, 1) + 1; /* first empty element */
99 int pos; /* where to insert new element */
100 switch (lua_gettop(L)) {
101 case 2: { /* called with only 2 arguments */
102 pos = e; /* insert new element at the end */
103 break;
104 }
105 case 3: {
106 int i;
107 pos = luaL_checkint(L, 2); /* 2nd argument is the position */
108 if (pos > e) e = pos; /* `grow' array if necessary */
109 for (i = e; i > pos; i--) { /* move up elements */
110 lua_rawgeti(L, 1, i-1);
111 lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
112 }
113 break;
114 }
115 default: {
116 return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
117 }
118 }
119 luaL_setn(L, 1, e); /* new size */
120 lua_rawseti(L, 1, pos); /* t[pos] = v */
121 return 0;
122}
123
124
125static int tremove (lua_State *L) {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected