Folding: Pass fold data through Lua
This way, automation scripts won't nuke the fold data on any lines they modify. This is done as userdata for now, so scripts that don't know what they're doing don't break the folds even further. If scripts get more access to folds, it should be with a safer and simpler API.
This commit is contained in:
parent
56cc1a6873
commit
2176954aee
|
@ -40,6 +40,7 @@
|
||||||
#include "ass_karaoke.h"
|
#include "ass_karaoke.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "fold_controller.h"
|
||||||
|
|
||||||
#include <libaegisub/exception.h>
|
#include <libaegisub/exception.h>
|
||||||
#include <libaegisub/log.h>
|
#include <libaegisub/log.h>
|
||||||
|
@ -100,6 +101,16 @@ namespace {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
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<T *>(lua_touserdata(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
using namespace Automation4;
|
using namespace Automation4;
|
||||||
template<int (LuaAssFile::*closure)(lua_State *)>
|
template<int (LuaAssFile::*closure)(lua_State *)>
|
||||||
int closure_wrapper(lua_State *L)
|
int closure_wrapper(lua_State *L)
|
||||||
|
@ -181,6 +192,10 @@ namespace Automation4 {
|
||||||
|
|
||||||
set_field(L, "text", dia->Text);
|
set_field(L, "text", dia->Text);
|
||||||
|
|
||||||
|
// preserve the folds
|
||||||
|
*static_cast<FoldInfo*>(lua_newuserdata(L, sizeof(FoldInfo))) = dia->Fold;
|
||||||
|
lua_setfield(L, -2, "_foldinfo");
|
||||||
|
|
||||||
// create extradata table
|
// create extradata table
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
for (auto const& ed : ass->GetExtradata(dia->ExtradataIds)) {
|
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->Margin[2] = get_int_field(L, "margin_t", "dialogue");
|
||||||
dia->Effect = get_string_field(L, "effect", "dialogue");
|
dia->Effect = get_string_field(L, "effect", "dialogue");
|
||||||
dia->Text = get_string_field(L, "text", "dialogue");
|
dia->Text = get_string_field(L, "text", "dialogue");
|
||||||
|
get_userdata_field(L, "_foldinfo", "dialogue", &dia->Fold);
|
||||||
|
|
||||||
std::vector<uint32_t> new_ids;
|
std::vector<uint32_t> new_ids;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue