From 7c92e6bbd65da85f584a4bce932160e6fb5594f9 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sun, 31 Jul 2022 21:31:34 +0200 Subject: [PATCH] Folding: Dont error on missing _foldinfo --- src/auto4_lua_assfile.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index f98e0a35d..c3e3902e6 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -102,13 +102,19 @@ namespace { } template - void get_userdata_field(lua_State *L, const char *name, const char *line_class, T *target) + bool get_userdata_field(lua_State *L, const char *name, const char *line_class, T *target, bool required) { lua_getfield(L, -1, name); - if (!lua_isuserdata(L, -1)) + if (!lua_isuserdata(L, -1)) { + if (!required) { + lua_pop(L, 1); + return false; + } throw bad_field("userdata", name, line_class); + } *target = *static_cast(lua_touserdata(L, -1)); lua_pop(L, 1); + return true; } using namespace Automation4; @@ -316,7 +322,9 @@ 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); + if (!get_userdata_field(L, "_foldinfo", "dialogue", &dia->Fold, false)) { + dia->Fold = FoldInfo(); + } std::vector new_ids;