** Search for a name for a function in all loaded modules */
| 71 | ** Search for a name for a function in all loaded modules |
| 72 | */ |
| 73 | static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { |
| 74 | int top = lua_gettop(L); |
| 75 | lua_getinfo(L, "f", ar); /* push function */ |
| 76 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); |
| 77 | if (findfield(L, top + 1, 2)) { |
| 78 | const char *name = lua_tostring(L, -1); |
| 79 | if (strncmp(name, "_G.", 3) == 0) { /* name start with '_G.'? */ |
| 80 | lua_pushstring(L, name + 3); /* push name without prefix */ |
| 81 | lua_remove(L, -2); /* remove original name */ |
| 82 | } |
| 83 | lua_copy(L, -1, top + 1); /* move name to proper place */ |
| 84 | lua_pop(L, 2); /* remove pushed values */ |
| 85 | return 1; |
| 86 | } |
| 87 | else { |
| 88 | lua_settop(L, top); /* remove function and global table */ |
| 89 | return 0; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | static void pushfuncname (lua_State *L, lua_Debug *ar) { |
no test coverage detected