Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports customizing the display of all data types in Lua on the project side(支持在项目侧自定义Lua中所有类型数据的展示方式) #51

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion emmy_debugger/src/debugger/emmy_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ void Debugger::GetVariable(lua_State *L, Idx<Variable> variable, int index, int
variable->valueType = type;


if (queryHelper && (type == LUA_TTABLE || type == LUA_TUSERDATA || type == LUA_TFUNCTION)) {
if (queryHelper && (type == LUA_TTABLE || type == LUA_TUSERDATA || type == LUA_TFUNCTION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该改为类似 && registerType[type] (registerType应该是个数组) 的方式判断类型是否需要导出判断,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的意思是改为使用类似表驱动(或控制表, Control_table)的方式来实现?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你加的这个功能对大部分人是不需要,所以影响尽可能的要小,判断类型是否在某个数组(不是set)上性能足够的高, 另外你需要提供函数: 注册需要导入到lua中的类型. 比如对外的接口类似dbg.registerType("string")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你加的这个功能对大部分人是不需要,所以影响尽可能的要小,判断类型是否在某个数组(不是set)上性能足够的高, 另外你需要提供函数: 注册需要导入到lua中的类型. 比如对外的接口类似dbg.registerType("string")

话说,为什么使用数组而不是set?

有以下事实:

  1. std::unordered_set,基于哈希表,它的查找复杂度是O(1)
  2. std::vector,基于动态数组,它的查找复杂度是O(n)

为了高性能,是不是应该使用vector呢?
亦或,你的意思是,这里的元素量很小(n很小),哈希算法反而更耗?

Copy link
Member

@CppCXY CppCXY Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::array预先申请足够的内存(大概就8)然后把type的整型值作为索引去索引目标位置是否为true, 实际上更应该使用的是std::bitset, 或者直接使用整数的位运算

|| type == LUA_TSTRING || type == LUA_TNUMBER || type == LUA_TLIGHTUSERDATA || type == LUA_TTHREAD
|| type == LUA_TNONE || type == LUA_TNIL || type == LUA_TBOOLEAN)) {
if (manager->extension.QueryVariable(L, variable, typeName, index, depth)) {
return;
}
Expand Down