mirror of https://github.com/odrling/Aegisub
Change the syntax for setting automation button IDs to be more backwards compatible
This commit is contained in:
parent
f90a5b21e9
commit
8f65d43b6c
|
@ -465,29 +465,20 @@ namespace Automation4 {
|
||||||
if (include_buttons && lua_istable(L, 2)) {
|
if (include_buttons && lua_istable(L, 2)) {
|
||||||
lua_pushvalue(L, 2);
|
lua_pushvalue(L, 2);
|
||||||
lua_for_each(L, [&]{
|
lua_for_each(L, [&]{
|
||||||
// String key: key is button ID, value is button label
|
buttons.emplace_back(-1, luaL_checkstring(L, -1));
|
||||||
// lua_isstring actually checks "is convertible to string"
|
});
|
||||||
if (lua_type(L, -2) == LUA_TSTRING)
|
}
|
||||||
buttons.emplace_back(
|
|
||||||
string_to_wx_id(lua_tostring(L, -2)),
|
|
||||||
luaL_checkstring(L, -1));
|
|
||||||
|
|
||||||
// Number key, string value: value is label
|
if (include_buttons && lua_istable(L, 3)) {
|
||||||
else if (lua_isstring(L, -1))
|
lua_pushvalue(L, 3);
|
||||||
buttons.emplace_back(-1, lua_tostring(L, -1));
|
lua_for_each(L, [&]{
|
||||||
|
int id = string_to_wx_id(luaL_checkstring(L, -2));
|
||||||
// Table value: Is a subtable that needs to be flatten.
|
std::string label = luaL_checkstring(L, -1);
|
||||||
// Used for ordered key-value pairs
|
auto btn = boost::find_if(buttons,
|
||||||
else if (lua_istable(L, -1)) {
|
[&](std::pair<int, std::string>& btn) { return btn.second == label; });
|
||||||
lua_pushvalue(L, -1);
|
if (btn == end(buttons))
|
||||||
lua_for_each(L, [&]{
|
luaL_error(L, "Invalid button for id %s", lua_tostring(L, -2));
|
||||||
buttons.emplace_back(
|
btn->first = id;
|
||||||
string_to_wx_id(luaL_checkstring(L, -2)),
|
|
||||||
luaL_checkstring(L, -1));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
luaL_error(L, "Invalid entry in buttons table");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue