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

Adding InputText and InputTextWithHint to Lua. #1453

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Changes from all commits
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
74 changes: 74 additions & 0 deletions src/gui/luaimguiextra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "gui/luaimguiextra.h"

#include "imgui/imgui.h"
#include "imgui_stdlib.h"
#include "lua/luawrapper.h"

namespace {
Expand Down Expand Up @@ -69,4 +70,77 @@
#include "gui/imguiextraffi.lua"
);
L.load(imguiextra, "internal:gui/imguiextraffi.lua");

L.getfieldtable("imgui", LUA_GLOBALSINDEX);
L.getfieldtable("extra");
L.declareFunc(

Check warning on line 76 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L74-L76

Added lines #L74 - L76 were not covered by tests
"InputText",
[](lua_State* L_) -> int {
Lua L(L_);
int n = L.gettop();
if (n < 2) {
return L.error("InputText: not enough arguments");

Check warning on line 82 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L78-L82

Added lines #L78 - L82 were not covered by tests
}
if (n > 3) {
return L.error("InputText: too many arguments");

Check warning on line 85 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L84-L85

Added lines #L84 - L85 were not covered by tests
}
if (!L.isstring(1)) {
return L.error("InputText: argument 1 must be a string");

Check warning on line 88 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L87-L88

Added lines #L87 - L88 were not covered by tests
}
if (!L.isstring(2)) {
return L.error("InputText: argument 2 must be a string");

Check warning on line 91 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L90-L91

Added lines #L90 - L91 were not covered by tests
}
std::string label = L.tostring(1);
std::string str = L.tostring(2);
ImGuiInputTextFlags flags = 0;
if (n == 3) {
if (!L.isnumber(3)) {
return L.error("InputText: argument 3 must be a number");

Check warning on line 98 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L93-L98

Added lines #L93 - L98 were not covered by tests
}
flags = L.tonumber(3);

Check warning on line 100 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L100

Added line #L100 was not covered by tests
}
bool ret = ImGui::InputText(label.c_str(), &str, flags);
L.push(ret);
L.push(str);
return 2;
},

Check warning on line 106 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L102-L106

Added lines #L102 - L106 were not covered by tests
-1);
L.declareFunc(

Check warning on line 108 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L108

Added line #L108 was not covered by tests
"InputTextWithHint",
[](lua_State* L_) -> int {
Lua L(L_);
int n = L.gettop();
if (n < 3) {
return L.error("InputTextWithHint: not enough arguments");

Check warning on line 114 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L110-L114

Added lines #L110 - L114 were not covered by tests
}
if (n > 4) {
return L.error("InputTextWithHint: too many arguments");

Check warning on line 117 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L116-L117

Added lines #L116 - L117 were not covered by tests
}
if (!L.isstring(1)) {
return L.error("InputTextWithHint: argument 1 must be a string");

Check warning on line 120 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L119-L120

Added lines #L119 - L120 were not covered by tests
}
if (!L.isstring(2)) {
return L.error("InputTextWithHint: argument 2 must be a string");

Check warning on line 123 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L122-L123

Added lines #L122 - L123 were not covered by tests
}
if (!L.isstring(3)) {
return L.error("InputTextWithHint: argument 3 must be a string");

Check warning on line 126 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L125-L126

Added lines #L125 - L126 were not covered by tests
}
std::string label = L.tostring(1);
std::string hint = L.tostring(2);
std::string str = L.tostring(3);
ImGuiInputTextFlags flags = 0;
if (n == 4) {
if (!L.isnumber(4)) {
return L.error("InputTextWithHint: argument 4 must be a number");

Check warning on line 134 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L128-L134

Added lines #L128 - L134 were not covered by tests
}
flags = L.tonumber(4);

Check warning on line 136 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L136

Added line #L136 was not covered by tests
}
bool ret = ImGui::InputTextWithHint(label.c_str(), hint.c_str(), &str, flags);
L.push(ret);
L.push(str);
return 2;
},

Check warning on line 142 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L138-L142

Added lines #L138 - L142 were not covered by tests
-1);
L.pop(2);
assert(L.gettop() == 0);

Check warning on line 145 in src/gui/luaimguiextra.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

PCSX::LuaFFI::open_imguiextra has a cyclomatic complexity of 14, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 145 in src/gui/luaimguiextra.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

PCSX::LuaFFI::open_imguiextra has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 145 in src/gui/luaimguiextra.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/luaimguiextra.cc#L144-L145

Added lines #L144 - L145 were not covered by tests
}
Loading