@@ -291,6 +291,94 @@ std::string ToPointer(lua_State* L, int index)
291291 return ss.str ();
292292}
293293
294+
295+ void DisplayFunction54 (std::shared_ptr<Variable> variable, lua_State* L, int index, lua_Debug_54& ar)
296+ {
297+ if (ar.what == nullptr )
298+ {
299+ return ;
300+ }
301+ std::string what = ar.what ;
302+ if (what == " Lua" )
303+ {
304+ auto paramNum = ar.nparams > 10 ? 10 : ar.nparams ;
305+ std::string showValue = " function(" ;
306+ lua_pushvalue (L, index);
307+ for (auto i = 0 ; i != paramNum; i++)
308+ {
309+ auto paramIndex = i + 1 ;
310+ auto paramName = lua_getlocal (L, nullptr , paramIndex);
311+ if (paramName)
312+ {
313+ showValue.append (paramName);
314+ if (paramIndex != paramNum)
315+ {
316+ showValue.append (" , " );
317+ }
318+ }
319+ }
320+ showValue.push_back (' )' );
321+ variable->value = showValue;
322+ variable->valueType = 9 ;
323+ variable->valueTypeName = " function" ;
324+ // ptr
325+ auto ptr = variable->CreateChildNode ();
326+ ptr->nameType = LUA_TSTRING;
327+ ptr->valueType = LUA_TFUNCTION;
328+ ptr->name = " pointer" ;
329+ ptr->value = ToPointer (L, index);
330+
331+ // source
332+ if (ar.source )
333+ {
334+ std::string sourceText = ar.source ;
335+ if (!sourceText.empty () && sourceText.front () == ' @' )
336+ {
337+ sourceText = sourceText.substr (1 );
338+ }
339+ auto source = variable->CreateChildNode ();
340+ source->nameType = LUA_TSTRING;
341+ source->valueType = LUA_TSTRING;
342+ source->name = " source" ;
343+ source->value = sourceText.append (" :" ).append (std::to_string (ar.linedefined ));
344+ }
345+ }
346+ else if (what == " C" )
347+ {
348+ variable->value = " C " + ToPointer (L, index);
349+ }
350+ else
351+ {
352+ variable->value = ToPointer (L, index);
353+ return ;
354+ }
355+ }
356+
357+ void DisplayFunction (std::shared_ptr<Variable> variable, lua_State* L, int index)
358+ {
359+ lua_Debug ar{};
360+ lua_pushvalue (L, index);
361+ if (lua_getinfo (L, " >Snu" , &ar) == 0 )
362+ {
363+ variable->value = ToPointer (L, index);
364+ return ;
365+ }
366+ switch (luaVersion)
367+ {
368+ case LuaVersion::LUA_54:
369+ {
370+ DisplayFunction54 (variable, L, index, ar.u .ar54 );
371+ break ;
372+ }
373+ default :
374+ {
375+ variable->value = ToPointer (L, index);
376+ break ;
377+ }
378+ }
379+ lua_settop (L, index);
380+ }
381+
294382// algorithm optimization
295383void Debugger::GetVariable (std::shared_ptr<Variable> variable, int index, int depth, bool queryHelper)
296384{
@@ -316,7 +404,7 @@ void Debugger::GetVariable(std::shared_ptr<Variable> variable, int index, int de
316404 variable->valueType = type;
317405
318406
319- if (queryHelper && (type == LUA_TTABLE || type == LUA_TUSERDATA))
407+ if (queryHelper && (type == LUA_TTABLE || type == LUA_TUSERDATA || type == LUA_TFUNCTION ))
320408 {
321409 if (query_variable (L, variable, typeName, index, depth))
322410 {
@@ -377,6 +465,10 @@ void Debugger::GetVariable(std::shared_ptr<Variable> variable, int index, int de
377465 break ;
378466 }
379467 case LUA_TFUNCTION:
468+ {
469+ DisplayFunction (variable, L, index);
470+ break ;
471+ }
380472 case LUA_TLIGHTUSERDATA:
381473 case LUA_TTHREAD:
382474 {
@@ -426,7 +518,8 @@ void Debugger::GetVariable(std::shared_ptr<Variable> variable, int index, int de
426518 variable->children .push_back (metatable);
427519
428520 // __index
429- if (lua_istable (L, -1 )){
521+ if (lua_istable (L, -1 ))
522+ {
430523 // fix BUG 导致涉及到FGUI的框架崩溃
431524 lua_pushstring (L, " __index" );
432525 lua_rawget (L, -2 );
0 commit comments