| 160 | } |
| 161 | |
| 162 | void tolua_stack_dump(lua_State* L, int offset, const char* label) { |
| 163 | int top = lua_gettop(L) + offset; |
| 164 | if (top == 0) { |
| 165 | return; |
| 166 | } |
| 167 | std::list<std::string> msgs; |
| 168 | msgs.push_back(fmt::format("Total [{}] in lua stack: {}\n", top, label != 0 ? label : "")); |
| 169 | for (int i = -1; i >= -top; i--) { |
| 170 | int t = lua_type(L, i); |
| 171 | switch (t) { |
| 172 | case LUA_TSTRING: |
| 173 | msgs.push_back(fmt::format(" [{}] [string] {}\n", i, lua_tostring(L, i))); |
| 174 | break; |
| 175 | case LUA_TBOOLEAN: |
| 176 | msgs.push_back(fmt::format(" [{}] [boolean] {}\n", i, lua_toboolean(L, i) ? "true" : "false")); |
| 177 | break; |
| 178 | case LUA_TNUMBER: |
| 179 | msgs.push_back(fmt::format(" [{}] [number] {}\n", i, lua_tonumber(L, i))); |
| 180 | break; |
| 181 | default: |
| 182 | msgs.push_back(fmt::format(" [{}] {}\n", i, lua_typename(L, t))); |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | LogInfo(String::join(msgs)); |
| 187 | } |
| 188 | |
| 189 | Slice tolua_toslice(lua_State* L, int narg, const char* def) { |
| 190 | if (lua_gettop(L) < abs(narg)) { |
nothing calls this directly
no test coverage detected