Switch to using lambdas in a few places
This commit is contained in:
parent
2c1f593a13
commit
1a6caa27b6
4 changed files with 27 additions and 38 deletions
|
@ -722,28 +722,25 @@ namespace Automation4 {
|
||||||
return lua_error(L);
|
return lua_error(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lua_threaded_call(ProgressSink *ps, lua_State *L, int nargs, int nresults, bool can_open_config, bool *failed)
|
|
||||||
{
|
|
||||||
LuaProgressSink lps(L, ps, can_open_config);
|
|
||||||
|
|
||||||
if (lua_pcall(L, nargs, nresults, 0)) {
|
|
||||||
if (!lua_isnil(L, -1)) {
|
|
||||||
// if the call failed, log the error here
|
|
||||||
ps->Log("\n\nLua reported a runtime error:\n");
|
|
||||||
ps->Log(lua_tostring(L, -1));
|
|
||||||
}
|
|
||||||
lua_pop(L, 1);
|
|
||||||
*failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LuaThreadedCall(lua_State *L, int nargs, int nresults, wxString const& title, wxWindow *parent, bool can_open_config)
|
void LuaThreadedCall(lua_State *L, int nargs, int nresults, wxString const& title, wxWindow *parent, bool can_open_config)
|
||||||
{
|
{
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
BackgroundScriptRunner bsr(parent, title);
|
BackgroundScriptRunner bsr(parent, title);
|
||||||
bsr.Run([&](ProgressSink *ps) { lua_threaded_call(ps, L, nargs, nresults, can_open_config, &failed); });
|
bsr.Run([&](ProgressSink *ps) {
|
||||||
|
LuaProgressSink lps(L, ps, can_open_config);
|
||||||
|
|
||||||
|
if (lua_pcall(L, nargs, nresults, 0)) {
|
||||||
|
if (!lua_isnil(L, -1)) {
|
||||||
|
// if the call failed, log the error here
|
||||||
|
ps->Log("\n\nLua reported a runtime error:\n");
|
||||||
|
ps->Log(lua_tostring(L, -1));
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||||
|
});
|
||||||
if (failed)
|
if (failed)
|
||||||
throw agi::UserCancelException("Script threw an error");
|
throw agi::UserCancelException("Script threw an error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,10 +51,6 @@
|
||||||
#include <libaegisub/exception.h>
|
#include <libaegisub/exception.h>
|
||||||
#include <libaegisub/spellchecker.h>
|
#include <libaegisub/spellchecker.h>
|
||||||
|
|
||||||
static void save_skip_comments(wxCommandEvent &evt) {
|
|
||||||
OPT_SET("Tool/Spell Checker/Skip Comments")->SetBool(!!evt.GetInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
DialogSpellChecker::DialogSpellChecker(agi::Context *context)
|
DialogSpellChecker::DialogSpellChecker(agi::Context *context)
|
||||||
: wxDialog(context->parent, -1, _("Spell Checker"))
|
: wxDialog(context->parent, -1, _("Spell Checker"))
|
||||||
, context(context)
|
, context(context)
|
||||||
|
@ -129,7 +125,8 @@ DialogSpellChecker::DialogSpellChecker(agi::Context *context)
|
||||||
skip_comments = new wxCheckBox(this, -1, _("&Skip Comments"));
|
skip_comments = new wxCheckBox(this, -1, _("&Skip Comments"));
|
||||||
actions_sizer->Add(skip_comments, button_flags);
|
actions_sizer->Add(skip_comments, button_flags);
|
||||||
skip_comments->SetValue(OPT_GET("Tool/Spell Checker/Skip Comments")->GetBool());
|
skip_comments->SetValue(OPT_GET("Tool/Spell Checker/Skip Comments")->GetBool());
|
||||||
skip_comments->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, save_skip_comments);
|
skip_comments->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED,
|
||||||
|
[](wxCommandEvent &evt) { OPT_SET("Tool/Spell Checker/Skip Comments")->SetBool(!!evt.GetInt()); });
|
||||||
|
|
||||||
wxButton *button;
|
wxButton *button;
|
||||||
|
|
||||||
|
|
|
@ -114,21 +114,17 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void do_wait(agi::ProgressSink *ps, FontConfigCacheThread const * const * const cache_worker) {
|
|
||||||
ps->SetIndeterminate();
|
|
||||||
while (*cache_worker && !ps->IsCancelled())
|
|
||||||
wxMilliSleep(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wait_for_cache_thread(FontConfigCacheThread const * const * const cache_worker) {
|
static void wait_for_cache_thread(FontConfigCacheThread const * const * const cache_worker) {
|
||||||
if (!*cache_worker) return;
|
if (!*cache_worker) return;
|
||||||
|
|
||||||
DialogProgress progress(wxGetApp().frame, "Updating font index", "This may take several minutes");
|
DialogProgress progress(wxGetApp().frame, "Updating font index", "This may take several minutes");
|
||||||
progress.Run(std::bind(do_wait, std::placeholders::_1, cache_worker));
|
progress.Run([=](agi::ProgressSink *ps) {
|
||||||
|
ps->SetIndeterminate();
|
||||||
|
while (*cache_worker && !ps->IsCancelled())
|
||||||
|
wxMilliSleep(100);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Constructor
|
|
||||||
///
|
|
||||||
LibassSubtitlesProvider::LibassSubtitlesProvider(std::string) {
|
LibassSubtitlesProvider::LibassSubtitlesProvider(std::string) {
|
||||||
wait_for_cache_thread(&cache_worker);
|
wait_for_cache_thread(&cache_worker);
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,12 @@ struct invisible_line : public std::unary_function<AssEntry const&, bool> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void delete_frame(AegiVideoFrame *frame) {
|
|
||||||
frame->Clear();
|
|
||||||
delete frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<AegiVideoFrame> ThreadedFrameSource::ProcFrame(int frameNum, double time, bool raw) {
|
std::shared_ptr<AegiVideoFrame> ThreadedFrameSource::ProcFrame(int frameNum, double time, bool raw) {
|
||||||
std::shared_ptr<AegiVideoFrame> frame(new AegiVideoFrame, delete_frame);
|
std::shared_ptr<AegiVideoFrame> frame(new AegiVideoFrame, [](AegiVideoFrame *frame) {
|
||||||
|
frame->Clear();
|
||||||
|
delete frame;
|
||||||
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
wxMutexLocker locker(providerMutex);
|
wxMutexLocker locker(providerMutex);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue