diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 3aef3b769..f98e0a35d 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -40,6 +40,7 @@ #include "ass_karaoke.h" #include "ass_style.h" #include "compat.h" +#include "fold_controller.h" #include #include @@ -100,6 +101,16 @@ namespace { return ret; } + template + void get_userdata_field(lua_State *L, const char *name, const char *line_class, T *target) + { + lua_getfield(L, -1, name); + if (!lua_isuserdata(L, -1)) + throw bad_field("userdata", name, line_class); + *target = *static_cast(lua_touserdata(L, -1)); + lua_pop(L, 1); + } + using namespace Automation4; template int closure_wrapper(lua_State *L) @@ -181,6 +192,10 @@ namespace Automation4 { set_field(L, "text", dia->Text); + // preserve the folds + *static_cast(lua_newuserdata(L, sizeof(FoldInfo))) = dia->Fold; + lua_setfield(L, -2, "_foldinfo"); + // create extradata table lua_newtable(L); for (auto const& ed : ass->GetExtradata(dia->ExtradataIds)) { @@ -301,6 +316,7 @@ namespace Automation4 { dia->Margin[2] = get_int_field(L, "margin_t", "dialogue"); dia->Effect = get_string_field(L, "effect", "dialogue"); dia->Text = get_string_field(L, "text", "dialogue"); + get_userdata_field(L, "_foldinfo", "dialogue", &dia->Fold); std::vector new_ids;