Skip to content

Commit

Permalink
show_flexbuffer()
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Oct 4, 2023
1 parent 16a3bea commit cd6bf08
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions dev/src/imbind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,41 @@ void EngineStatsGUI() {
ImGui::PlotLines("gl.deltatime", ft.data(), (int)ft.size());
}

void FlexBufferGUI(flexbuffers::Reference r, const char *label) {
switch (r.GetType()) {
case flexbuffers::FBT_MAP: {
if (ImGui::TreeNodeEx(label, 0)) {
auto m = r.AsMap();
auto keys = m.Keys();
auto vals = m.Values();
for (size_t i = 0; i < keys.size(); i++) {
string key;
keys[i].ToString(true, false, key);
FlexBufferGUI(vals[i], key.c_str());
}
ImGui::TreePop();
}
break;
}
case flexbuffers::FBT_VECTOR: {
if (ImGui::TreeNodeEx(label, 0)) {
auto vals = r.AsVector();
for (size_t i = 0; i < vals.size(); i++) {
auto labeli = cat(i);
FlexBufferGUI(vals[i], labeli.c_str());
}
ImGui::TreePop();
}
break;
}
default: {
auto s = r.ToString();
ImGui::LabelText(label, "%s", s.c_str());
break;
}
}
}

// See also VM::DumpStackTrace and VM::DumpStackTraceMemory()
void DumpStackTrace(VM &vm) {
if (vm.fun_id_stack.empty()) return;
Expand Down Expand Up @@ -1467,6 +1502,16 @@ nfr("graph", "label,values,ishistogram", "SF]I", "",
return NilVal();
});

nfr("show_flexbuffer", "value", "S", "",
"",
[](StackPtr &, VM &vm, Value &v) {
IsInit(vm);
auto sv = v.sval()->strv();
auto root = flexbuffers::GetRoot((const uint8_t *)sv.data(), sv.size());
FlexBufferGUI(root, "Stack trace");
return NilVal();
});

nfr("show_vars", "", "", "",
"shows an automatic editing UI for each global variable in your program",
[](StackPtr &, VM &vm) {
Expand Down
2 changes: 1 addition & 1 deletion dev/src/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void VM::DumpStackTraceMemory(const string &err) {
// cycles etc, so it will output max 1 copy of each data structure.
ToFlexBufferContext fbc(*this);
fbc.cycle_detect = true;
fbc.max_depth = 16;
fbc.max_depth = 64;
fbc.ignore_unsupported_types = true;

#ifdef USE_EXCEPTION_HANDLING
Expand Down

0 comments on commit cd6bf08

Please sign in to comment.