Skip to content

Commit

Permalink
Merge pull request #53 from zhangjiequan/feat/extend_all_lua_types_fo…
Browse files Browse the repository at this point in the history
…r_pr

feat: Added a toggle enableDisplayCustomTypeInfo aimed at further enhancing performance
  • Loading branch information
CppCXY committed Feb 23, 2024
2 parents 2d76b15 + e8bfb0e commit ff0edf9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ class Debugger: public std::enable_shared_from_this<Debugger>

Arena<Variable> *arenaRef;

bool displayCustomTypeInfo;
std::bitset<LUA_NUMTAGS> registeredTypes;
};
40 changes: 21 additions & 19 deletions emmy_debugger/src/debugger/emmy_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Debugger::Debugger(lua_State *L, EmmyDebuggerManager *manager)
running(false),
skipHook(false),
blocking(false),
arenaRef(nullptr) {
arenaRef(nullptr),
displayCustomTypeInfo(false) {
}

Debugger::~Debugger() {
Expand Down Expand Up @@ -371,7 +372,7 @@ void Debugger::GetVariable(lua_State *L, Idx<Variable> variable, int index, int
variable->valueType = type;

if (queryHelper) {
if (type >= 0 && type < registeredTypes.size() && registeredTypes.test(type)
if (displayCustomTypeInfo && type >= 0 && type < registeredTypes.size() && registeredTypes.test(type)
&& manager->extension.QueryVariableCustom(L, variable, typeName, index, depth)) {
return;
}
Expand Down Expand Up @@ -1430,24 +1431,25 @@ void Debugger::ExecuteOnLuaThread(const Executor &exec) {
}

int Debugger::GetTypeFromName(const char* typeName) {
if (strcmp(typeName, "nil") == 0) return LUA_TNIL;
if (strcmp(typeName, "boolean") == 0) return LUA_TBOOLEAN;
if (strcmp(typeName, "lightuserdata") == 0) return LUA_TLIGHTUSERDATA;
if (strcmp(typeName, "number") == 0) return LUA_TNUMBER;
if (strcmp(typeName, "string") == 0) return LUA_TSTRING;
if (strcmp(typeName, "table") == 0) return LUA_TTABLE;
if (strcmp(typeName, "function") == 0) return LUA_TFUNCTION;
if (strcmp(typeName, "userdata") == 0) return LUA_TUSERDATA;
if (strcmp(typeName, "thread") == 0) return LUA_TTHREAD;
return -1; // 未知类型
if (strcmp(typeName, "nil") == 0) return LUA_TNIL;
if (strcmp(typeName, "boolean") == 0) return LUA_TBOOLEAN;
if (strcmp(typeName, "lightuserdata") == 0) return LUA_TLIGHTUSERDATA;
if (strcmp(typeName, "number") == 0) return LUA_TNUMBER;
if (strcmp(typeName, "string") == 0) return LUA_TSTRING;
if (strcmp(typeName, "table") == 0) return LUA_TTABLE;
if (strcmp(typeName, "function") == 0) return LUA_TFUNCTION;
if (strcmp(typeName, "userdata") == 0) return LUA_TUSERDATA;
if (strcmp(typeName, "thread") == 0) return LUA_TTHREAD;
return -1; // 未知类型
}

bool Debugger::RegisterTypeName(const std::string& typeName, std::string& err) {
int type = GetTypeFromName(typeName.c_str());
if (type == -1) {
err = "Unknown type name: " + typeName;
return false;
}
registeredTypes.set(type);
return true;
int type = GetTypeFromName(typeName.c_str());
if (type == -1) {
err = "Unknown type name: " + typeName;
return false;
}
displayCustomTypeInfo = true;
registeredTypes.set(type);
return true;
}
6 changes: 3 additions & 3 deletions emmy_debugger/src/debugger/extension_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ bool ExtensionPoint::QueryVariableGeneric(lua_State *L, Idx<Variable> variable,
result = lua_toboolean(L, -1);
} else {
const auto err = lua_tostring(L, -1);
printf("query error in %s: %s\n", queryFunction, err);
printf("query error in %s: %s\n", queryFunction, err);
}
}
}
Expand All @@ -150,11 +150,11 @@ bool ExtensionPoint::QueryVariableGeneric(lua_State *L, Idx<Variable> variable,
}

bool ExtensionPoint::QueryVariable(lua_State *L, Idx<Variable> variable, const char *typeName, int object, int depth) {
return QueryVariableGeneric(L, variable, typeName, object, depth, "queryVariable");
return QueryVariableGeneric(L, variable, typeName, object, depth, "queryVariable");
}

bool ExtensionPoint::QueryVariableCustom(lua_State *L, Idx<Variable> variable, const char *typeName, int object, int depth) {
return QueryVariableGeneric(L, variable, typeName, object, depth, "queryVariableCustom");
return QueryVariableGeneric(L, variable, typeName, object, depth, "queryVariableCustom");
}

lua_State *ExtensionPoint::QueryParentThread(lua_State *L) {
Expand Down

0 comments on commit ff0edf9

Please sign in to comment.