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

Function tinsert

src/Chain/libraries/glua/ltablib.cpp:78–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

lua_gettopFunction · 0.85
lua_getiFunction · 0.85
lua_setiFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected