MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / operator()

Method operator()

src/auto4_lua.cpp:796–897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

794 }
795
796 void LuaCommand::operator()(agi::Context *c)
797 {
798 LuaStackcheck stackcheck(L);
799 set_context(L, c);
800 stackcheck.check_stack(0);
801
802 GetFeatureFunction("run");
803 auto subsobj = new LuaAssFile(L, c->ass.get(), true, true);
804
805 int original_offset = c->ass->Info.size() + c->ass->Styles.size() + 1;
806 auto original_sel = selected_rows(c);
807 int original_active = 0;
808 if (auto active_line = c->selectionController->GetActiveLine())
809 original_active = active_line->Row + original_offset;
810
811 push_value(L, original_sel);
812 push_value(L, original_active);
813
814 try {
815 LuaThreadedCall(L, 3, 2, from_wx(StrDisplay(c)), c->parent, true);
816 }
817 catch (agi::UserCancelException const&) {
818 subsobj->Cancel();
819 stackcheck.check_stack(0);
820 return;
821 }
822
823 auto lines = subsobj->ProcessingComplete(StrDisplay(c));
824
825 AssDialogue *active_line = nullptr;
826 int active_idx = original_active;
827
828 // Check for a new active row
829 if (lua_isnumber(L, -1)) {
830 active_idx = lua_tointeger(L, -1);
831 if (active_idx < 1 || active_idx > (int)lines.size()) {
832 wxLogError("Active row %d is out of bounds (must be 1-%u)", active_idx, lines.size());
833 active_idx = original_active;
834 }
835 }
836
837 stackcheck.check_stack(2);
838 lua_pop(L, 1);
839
840 // top of stack will be selected lines array, if any was returned
841 if (lua_istable(L, -1)) {
842 std::set<AssDialogue*> sel;
843 lua_for_each(L, [&] {
844 if (!lua_isnumber(L, -1))
845 return;
846 int cur = lua_tointeger(L, -1);
847 if (cur < 1 || cur > (int)lines.size()) {
848 wxLogError("Selected row %d is out of bounds (must be 1-%u)", cur, lines.size());
849 throw LuaForEachBreak();
850 }
851
852 if (typeid(*lines[cur - 1]) != typeid(AssDialogue)) {
853 wxLogError("Selected row %d is not a dialogue line", cur);

Callers

nothing calls this directly

Calls 15

set_contextFunction · 0.85
selected_rowsFunction · 0.85
push_valueFunction · 0.85
LuaThreadedCallFunction · 0.85
from_wxFunction · 0.85
lua_for_eachFunction · 0.85
LuaForEachBreakClass · 0.85
GetActiveLineMethod · 0.80
ProcessingCompleteMethod · 0.80
SetSelectionAndActiveMethod · 0.80
check_stackMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected