Lua export filters didn't work when there was no configuration dialog function. Really stupid fix. Also, Lua include files are now more usable and karaskel pre-calculation actually works.

Originally committed to SVN as r940.
This commit is contained in:
Niels Martin Hansen 2007-02-20 02:50:40 +00:00
parent 9dcae98180
commit 3a1d4ee18e
6 changed files with 67 additions and 27 deletions

View File

@ -55,7 +55,8 @@ namespace Automation4 {
// LuaStackcheck
#ifdef _DEBUG
//#ifdef _DEBUG
#if 0
struct LuaStackcheck {
lua_State *L;
int startstack;
@ -241,7 +242,7 @@ namespace Automation4 {
// load user script
LuaScriptReader script_reader(GetFilename());
if (lua_load(L, script_reader.reader_func, &script_reader, GetFilename().mb_str(wxConvUTF8))) {
if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().mb_str(wxConvUTF8))) {
wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8);
err->Prepend(_T("Error loading Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err->c_str();
@ -412,7 +413,7 @@ namespace Automation4 {
}
LuaScriptReader script_reader(fname.GetFullPath());
if (lua_load(L, script_reader.reader_func, &script_reader, s->GetFilename().mb_str(wxConvUTF8))) {
if (lua_load(L, script_reader.reader_func, &script_reader, fname.GetFullName().mb_str(wxConvUTF8))) {
lua_pushfstring(L, "Error loading Lua include \"%s\":\n\n%s", fname.GetFullPath().mb_str(wxConvUTF8).data(), lua_tostring(L, -1));
lua_error(L);
return 0;
@ -475,6 +476,15 @@ namespace Automation4 {
lua_getfield(L, LUA_REGISTRYINDEX, "progress_sink");
if (lua_isuserdata(L, -1)) {
LuaProgressSink *ps = LuaProgressSink::GetObjPointer(L, -1);
if (result) {
// if the call failed, log the error here
wxString errmsg(lua_tostring(L, -2), wxConvUTF8);
ps->AddDebugOutput(_T("\n\nLua reported a runtime error:\n"));
ps->AddDebugOutput(errmsg);
lua_pop(L, 1);
}
// don't bother protecting this with a mutex, it should be safe enough like this
ps->script_finished = true;
// tell wx to run its idle-events now, just to make the progress window notice earlier that we're done
@ -628,7 +638,7 @@ namespace Automation4 {
ps->ShowModal();
wxThread::ExitCode code = call.Wait();
if (code) ThrowError();
//if (code) ThrowError();
delete ps;
}
@ -676,6 +686,7 @@ namespace Automation4 {
void LuaFeatureFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog)
{
GetFeatureFunction(1); // 1 = processing function
assert(lua_isfunction(L, -1));
// prepare function call
// subtitles (undo doesn't make sense in exported subs, in fact it'll totally break the undo system)
@ -685,6 +696,9 @@ namespace Automation4 {
if (has_config && config_dialog) {
assert(config_dialog->LuaReadBack(L) == 1);
// TODO, write back stored options here
} else {
// no config so put an empty table instead
lua_newtable(L);
}
LuaProgressSink *ps = new LuaProgressSink(L, export_dialog, false);
@ -695,7 +709,7 @@ namespace Automation4 {
ps->ShowModal();
wxThread::ExitCode code = call.Wait();
if (code) ThrowError();
//if (code) ThrowError();
delete ps;
}
@ -722,12 +736,16 @@ namespace Automation4 {
ps->ShowModal();
wxThread::ExitCode code = call.Wait();
if (code) ThrowError();
//if (code) ThrowError();
delete ps;
// The config dialog table should now be on stack
return config_dialog = new LuaConfigDialog(L, false);
if (!code) {
return config_dialog = new LuaConfigDialog(L, false);
} else {
return config_dialog = 0;
}
}

View File

@ -865,7 +865,9 @@ void BaseGrid::SetColumnWidths() {
// Gets dialogue from map
AssDialogue *BaseGrid::GetDialogue(int n) {
try {
return AssEntry::GetAsDialogue(*(diagMap.at(n)));
AssEntry *e = *diagMap.at(n);
if (e->GetType() != ENTRY_DIALOGUE) return NULL;
return AssEntry::GetAsDialogue(e);
}
catch (...) {
return NULL;

View File

@ -998,11 +998,13 @@ void FrameMain::OnOpenAutomation (wxCommandEvent &event) {
///////////////////////////////////////////////////////////
// General handler for all Automation-generated menu items
void FrameMain::OnAutomationMacro (wxCommandEvent &event) {
// Clear all maps from the subs grid before running the macro
// The stuff done by the macro might invalidate some of the iterators held by the grid, which will cause great crashing
SubsBox->Clear();
// Run the macro...
activeMacroItems[event.GetId()-Menu_Automation_Macro]->Process(SubsBox->ass, SubsBox->GetAbsoluteSelection(), SubsBox->GetFirstSelRow(), this);
// check if modifications were made and put on undo stack
AssFile::Popping = true; // HACK to avoid getting an additional undo point on stack
SubsBox->LoadFromAss(AssFile::top, true, true);
AssFile::Popping = false;
// Have the grid update its maps, this properly refreshes it to reflect the changed subs
SubsBox->UpdateMaps();
}

View File

@ -52,7 +52,7 @@ function karaskel.collect_head(subs)
local l = subs[i]
if l.class == "style" then
styles.n = styles.n + 1
styles[n] = l
styles[styles.n] = l
styles[l.name] = l
elseif l.class == "info" then
local k = l.key:lower()
@ -91,23 +91,23 @@ end
-- Modifies the line parameter
function karaskel.preproc_line(subs, meta, styles, line)
-- Assume line is class=dialogue
local kara = aegisub.parse_karaoke_data(line.text)
local kara = aegisub.parse_karaoke_data(line)
line.kara = { n = 0 }
line.furi = { n = 0 }
if styles[line.style] then
line.style = styles[line.style]
line.styleref = styles[line.style]
else
aegisub.debug.out("WARNING: Style not found: " .. line.style .. "\n")
line.style = styles[1]
aegisub.debug.out(2, "WARNING: Style not found: " .. line.style .. "\n")
line.styleref = styles[1]
end
line.text_stripped = ""
local curx = 0
local worksyl = { }
for i = 0, #line.kara do
local syl = line.kara[i]
for i = 0, #kara do
local syl = kara[i]
-- Spaces at the start and end of the syllable are best ignored
local prespace, syltext, postspace = syl.text_stripped:match("^([ \t]*)(.-)([ \t]*)$")
@ -155,7 +155,7 @@ function karaskel.preproc_line(subs, meta, styles, line)
-- If this is the start of a highlight group, do regular processing
if prefix ~= "#" and prefix ~= "" then
-- Update stripped line-text
line.text_stripped = line.text_stripped + syl.text_stripped
line.text_stripped = line.text_stripped .. syl.text_stripped
-- Copy data from syl to worksyl
worksyl.text = syl.text
@ -165,16 +165,16 @@ function karaskel.preproc_line(subs, meta, styles, line)
worksyl.end_time = syl.end_time
worksyl.tag = syl.tag
worksyl.line = line
worksyl.style = line.style
worksyl.style = line.styleref
-- And add new data to worksyl
worksyl.text_stripped = syltext
worksyl.width = aegisub.text_extents(line.style, syltext)
curx = curx + aegisub.text_extents(line.style, prespace)
worksyl.width = aegisub.text_extents(line.styleref, syltext)
curx = curx + aegisub.text_extents(line.styleref, prespace)
worksyl.left = curx
worksyl.center = curx + worksyl.width/2
worksyl.right = curx + worksyl.width
curx = curx + worksyl.width + aegisub.text_extents(line.style, postspace)
curx = curx + worksyl.width + aegisub.text_extents(line.styleref, postspace)
-- TODO: inlinefx here
end
@ -192,10 +192,12 @@ function karaskel.preproc_line(subs, meta, styles, line)
line.kara[line.kara.n] = worksyl
-- Full line sizes
line.width, line.height, line.descent, line.extlead = aegisub.text_extents(line.style, line.text_stripped)
line.width, line.height, line.descent, line.extlead = aegisub.text_extents(line.styleref, line.text_stripped)
-- And positioning (FIXME: assume centering for now)
line.left = (meta.res_x - line.styleref.margin_l - line.styleref.margin_r - line.width) / 2 + line.styleref.margin_l
-- Generate furigana style
local furistyle = table.copy(line.style)
local furistyle = table.copy(line.styleref)
furistyle.fontsize = furistyle.fontsize / 2
furistyle.outline = furistyle.outline / 2

View File

@ -35,7 +35,12 @@ module("unicode")
-- Return the number of bytes occupied by the character starting at the i'th byte in s
function charwidth(s, i)
local b = s:byte(i)
if b < 128 then
if not b then
--aegisub.debug.out(3, "unicode.charwidth of '%s' @ %d, nil byte\n", s, i)
-- FIXME, something in karaskel results in this case, shouldn't happen
-- What would "proper" behaviour be? Zero? Or just explode?
return 1
elseif b < 128 then
return 1
elseif b < 224 then
return 2

View File

@ -143,3 +143,14 @@ function string.headtail(s)
return s, ""
end
end
-- Clamp a number value to a range
function clamp(val, min, max)
if val < min then
return min
elseif val > max then
return max
else
return val
end
end