| 200 | |
| 201 | |
| 202 | static int db_getlocal (lua_State *L) { |
| 203 | int arg; |
| 204 | lua_State *L1 = getthread(L, &arg); |
| 205 | int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */ |
| 206 | if (lua_isfunction(L, arg + 1)) { /* function argument? */ |
| 207 | lua_pushvalue(L, arg + 1); /* push function */ |
| 208 | lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */ |
| 209 | return 1; /* return only name (there is no value) */ |
| 210 | } |
| 211 | else { /* stack-level argument */ |
| 212 | lua_Debug ar; |
| 213 | const char *name; |
| 214 | int level = (int)luaL_checkinteger(L, arg + 1); |
| 215 | if (!lua_getstack(L1, level, &ar)) /* out of range? */ |
| 216 | return luaL_argerror(L, arg+1, "level out of range"); |
| 217 | checkstack(L, L1, 1); |
| 218 | name = lua_getlocal(L1, &ar, nvar); |
| 219 | if (name) { |
| 220 | lua_xmove(L1, L, 1); /* move local value */ |
| 221 | lua_pushstring(L, name); /* push name */ |
| 222 | lua_rotate(L, -2, 1); /* re-order */ |
| 223 | return 2; |
| 224 | } |
| 225 | else { |
| 226 | luaL_pushfail(L); /* no name (nor value) */ |
| 227 | return 1; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | |
| 233 | static int db_setlocal (lua_State *L) { |
nothing calls this directly
no test coverage detected