1818#include " emmy_facade.h"
1919#include " hook_state.h"
2020#include < algorithm>
21+ #include < sstream>
2122
2223bool query_variable (Variable* variable, lua_State* L, const char * typeName, int object, int depth);
2324
@@ -231,6 +232,13 @@ bool CallMetaFunction(lua_State* L, int valueIndex, const char* method, int numR
231232 return false ;
232233}
233234
235+ std::string ToPointer (lua_State* L, int index) {
236+ const void * pointer = lua_topointer (L, index);
237+ std::stringstream ss;
238+ ss << lua_typename (L, lua_type (L, index)) << " (0x" << std::hex << pointer << " )" ;
239+ return ss.str ();
240+ }
241+
234242void Debugger::GetVariable (Variable* variable, lua_State* L, int index, int depth, bool queryHelper) {
235243 const int t1 = lua_gettop (L);
236244 index = lua_absindex (L, index);
@@ -262,15 +270,8 @@ void Debugger::GetVariable(Variable* variable, lua_State* L, int index, int dept
262270 variable->value = lua_tostring (L, index);
263271 break ;
264272 }
265- case LUA_TFUNCTION: {
266- const void * fAddr = lua_topointer (L, index);
267- char buff[100 ];
268- snprintf (buff, sizeof (buff), " %p" , fAddr );
269- variable->value = buff;
270- break ;
271- }
272273 case LUA_TUSERDATA: {
273- auto string = lua_tostring (L, index);
274+ auto * string = lua_tostring (L, index);
274275 if (string == nullptr ) {
275276 int result;
276277 if (CallMetaFunction (L, t1, " __tostring" , 1 , result) && result == 0 ) {
@@ -282,10 +283,7 @@ void Debugger::GetVariable(Variable* variable, lua_State* L, int index, int dept
282283 variable->value = string;
283284 }
284285 else {
285- const void * fAddr = lua_topointer (L, index);
286- char buff[100 ];
287- snprintf (buff, sizeof (buff), " %p" , fAddr );
288- variable->value = buff;
286+ variable->value = ToPointer (L, index);
289287 }
290288 if (depth > 1 ) {
291289 if (lua_getmetatable (L, index)) {
@@ -295,18 +293,10 @@ void Debugger::GetVariable(Variable* variable, lua_State* L, int index, int dept
295293 }
296294 break ;
297295 }
298- case LUA_TLIGHTUSERDATA: {
299- const void * fAddr = lua_topointer (L, index);
300- char buff[100 ];
301- snprintf (buff, sizeof (buff), " %p" , fAddr );
302- variable->value = buff;
303- break ;
304- }
296+ case LUA_TFUNCTION:
297+ case LUA_TLIGHTUSERDATA:
305298 case LUA_TTHREAD: {
306- const void * fAddr = lua_topointer (L, index);
307- char buff[100 ];
308- snprintf (buff, sizeof (buff), " %p" , fAddr );
309- variable->value = buff;
299+ variable->value = ToPointer (L, index);
310300 break ;
311301 }
312302 case LUA_TTABLE: {
@@ -317,7 +307,7 @@ void Debugger::GetVariable(Variable* variable, lua_State* L, int index, int dept
317307 // k: -2, v: -1
318308 if (depth > 1 ) {
319309 // todo: use allocator
320- const auto v = new Variable ();
310+ auto * const v = new Variable ();
321311 const auto t = lua_type (L, -2 );
322312 v->nameType = t;
323313 if (t == LUA_TSTRING) {
@@ -338,7 +328,7 @@ void Debugger::GetVariable(Variable* variable, lua_State* L, int index, int dept
338328 tableSize++;
339329 }
340330 char buff[100 ];
341- snprintf (buff, sizeof (buff), " table(%p)" , tableAddr);
331+ snprintf (buff, sizeof (buff), " table(0x %p)" , tableAddr);
342332 variable->value = buff;
343333 break ;
344334 }
0 commit comments