Skip to content

Commit

Permalink
simplify some lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Sep 7, 2024
1 parent c930a36 commit dfb1cb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions gui/qt/emuthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void EmuThread::debugOpen(int reason, uint32_t data) {
std::unique_lock<std::mutex> lock(m_mutexDebug);
m_debug = true;
emit debugCommand(reason, data);
m_cvDebug.wait(lock, [this](){ return !m_debug; });
m_cvDebug.wait(lock, [this] { return !m_debug; });
}

void EmuThread::resume() {
Expand Down Expand Up @@ -400,12 +400,12 @@ void EmuThread::load(emu_data_t fileType, const QString &filePath) {
void EmuThread::stop() {
// Need to run events to allow queued slots to be processed during exit
QEventLoop eventLoop;
connect(this, &QThread::finished, &eventLoop, [&]() { eventLoop.exit(0); });
connect(this, &QThread::finished, &eventLoop, [&] { eventLoop.exit(0); });
if (!isRunning()) {
return;
}
emu_exit();
QTimer::singleShot(500, &eventLoop, [&]() { eventLoop.exit(1); });
QTimer::singleShot(500, &eventLoop, [&] { eventLoop.exit(1); });
if (eventLoop.exec()) {
terminate();
wait(500);
Expand Down
24 changes: 12 additions & 12 deletions gui/qt/luascripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void MainWindow::initLuaThings(sol::state& lua, bool isREPL) {
}
return !(ui->lcd->getImage().save(path, "PNG", 0));
}),
"refresh", sol::as_function([](){ QApplication::processEvents(); }),
"refresh", sol::as_function([] { QApplication::processEvents(); }),
"messageBox", sol::as_function([&](const std::string& t, const std::string& msg) {
QMessageBox::information(this, QString::fromStdString("[Lua] " + t), QString::fromStdString(msg));
}),
Expand All @@ -159,8 +159,8 @@ void MainWindow::initLuaThings(sol::state& lua, bool isREPL) {
);

lua.create_named_table("emu",
"reset", sol::as_function([&](){ resetEmu(); }),
"reloadROM", sol::as_function([&](){ emuLoad(EMU_DATA_ROM); }),
"reset", sol::as_function([&] { resetEmu(); }),
"reloadROM", sol::as_function([&] { emuLoad(EMU_DATA_ROM); }),
"throttle", sol::as_function([&](bool t){ setThrottle(t ? Qt::Checked : Qt::Unchecked); }),
"setSpeed", sol::as_function([&](int s){ s /= 10; setEmuSpeed(s<0 ? 0 : (s>50 ? 50 : s)); }), // todo: maybe fix this
"sendFile", sol::as_function([&](const std::string& path) {
Expand All @@ -171,12 +171,12 @@ void MainWindow::initLuaThings(sol::state& lua, bool isREPL) {
);

lua.create_named_table("debug",
"stop", sol::as_function([&](){ if (!guiDebug) { debugToggle(); } }),
"resume", sol::as_function([&](){ if (guiDebug) { debugToggle(); } }),
"stepIn", sol::as_function([&](){ stepIn(); }),
"stepOver", sol::as_function([&](){ stepOver(); }),
"stepNext", sol::as_function([&](){ stepNext(); }),
"stepOut", sol::as_function([&](){ stepOut(); }),
"stop", sol::as_function([&] { if (!guiDebug) { debugToggle(); } }),
"resume", sol::as_function([&] { if (guiDebug) { debugToggle(); } }),
"stepIn", sol::as_function([&] { stepIn(); }),
"stepOver", sol::as_function([&] { stepOver(); }),
"stepNext", sol::as_function([&] { stepNext(); }),
"stepOut", sol::as_function([&] { stepOut(); }),
"disasm", sol::as_function([&](uint32_t addr) -> auto {
/* todo with zdis compat */
(void)addr;
Expand All @@ -188,8 +188,8 @@ void MainWindow::initLuaThings(sol::state& lua, bool isREPL) {

lua.create_named_table("autotester",
"loadJSON", sol::as_function([&](const std::string& path) -> int { return autotesterOpen(QString::fromStdString(path)); }),
"reloadJSON", sol::as_function([&](){ autotesterReload(); }),
"launchTest", sol::as_function([&](){ autotesterLaunch(); })
"reloadJSON", sol::as_function([&] { autotesterReload(); }),
"launchTest", sol::as_function([&] { autotesterLaunch(); })

// todo: actually test this
);
Expand Down Expand Up @@ -246,7 +246,7 @@ void MainWindow::runLuaScript() {
this->initLuaThings(ed_lua, false);
// TODO: maybe have a separate thread for Lua (because of infinite loops...)
const std::string& code = ui->luaScriptEditor->toPlainText().toStdString();
const sol::protected_function_result& stringresult = ed_lua.do_string(code.c_str());
const sol::protected_function_result& stringresult = ed_lua.do_string(code);
if (!stringresult.valid())
{
const sol::error& err = stringresult;
Expand Down
8 changes: 4 additions & 4 deletions gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U
connect(ui->buttonRunLuaScript, &QPushButton::clicked, this, &MainWindow::runLuaScript);
connect(ui->buttonLoadLuaScript, &QPushButton::clicked, this, &MainWindow::loadLuaScript);
connect(ui->buttonSaveLuaScript, &QPushButton::clicked, this, &MainWindow::saveLuaScript);
connect(ui->resetREPLLuaState, &QPushButton::clicked, this, [&](){ this->initLuaThings(repl_lua, true); });
connect(ui->resetREPLLuaState, &QPushButton::clicked, this, [&] { this->initLuaThings(repl_lua, true); });
connect(ui->clearREPLConsole, &QPushButton::clicked, ui->REPLConsole, &QPlainTextEdit::clear);
connect(ui->REPLInput, &QLineEdit::returnPressed, this, &MainWindow::LuaREPLeval);

Expand Down Expand Up @@ -1065,7 +1065,7 @@ void MainWindow::setup() {
const QByteArray geometry = m_config->value(SETTING_WINDOW_GEOMETRY, QByteArray()).toByteArray();
if (restoreState(m_config->value(SETTING_WINDOW_STATE).toByteArray()) && restoreGeometry(geometry) && restoreGeometry(geometry)) {
const QPoint position = m_config->value(SETTING_WINDOW_POSITION).toPoint();
QTimer::singleShot(0, [this, position]() { move(position); });
QTimer::singleShot(0, [this, position] { move(position); });
} else {
foreach (DockWidget *dw, m_dockPtrs) {
dw->setVisible(true);
Expand Down Expand Up @@ -1838,12 +1838,12 @@ void MainWindow::showAbout() {
aboutBox->setWindowTitle(tr("About CEmu"));

QAbstractButton *buttonUpdateCheck = aboutBox->addButton(tr("Check for updates"), QMessageBox::ActionRole);
connect(buttonUpdateCheck, &QAbstractButton::clicked, this, [this](){ this->checkUpdate(true); });
connect(buttonUpdateCheck, &QAbstractButton::clicked, this, [this] { this->checkUpdate(true); });

QAbstractButton *buttonCopyVersion = aboutBox->addButton(tr("Copy version"), QMessageBox::ActionRole);
// Needed to prevent the button from closing the dialog
buttonCopyVersion->disconnect();
connect(buttonCopyVersion, &QAbstractButton::clicked, this, [this, buttonCopyVersion](){ QApplication::clipboard()->setText("CEmu " CEMU_VERSION " (git: " CEMU_GIT_SHA ")", QClipboard::Clipboard); buttonCopyVersion->setEnabled(false); buttonCopyVersion->setText(tr("Version copied!")); });
connect(buttonCopyVersion, &QAbstractButton::clicked, this, [this, buttonCopyVersion] { QApplication::clipboard()->setText("CEmu " CEMU_VERSION " (git: " CEMU_GIT_SHA ")", QClipboard::Clipboard); buttonCopyVersion->setEnabled(false); buttonCopyVersion->setText(tr("Version copied!")); });

Check warning on line 1846 in gui/qt/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / Build: macos-12 Qt5_intel

lambda capture 'this' is not used [-Wunused-lambda-capture]

QAbstractButton *okButton = aboutBox->addButton(QMessageBox::Ok);
okButton->setFocus();
Expand Down

0 comments on commit dfb1cb1

Please sign in to comment.