From 689c16deb34ed346c553d49b371ecf40eaa736b3 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 27 Apr 2014 06:41:28 -0700 Subject: [PATCH] Use lua_createtable where applicable --- libaegisub/lua/modules/re.cpp | 4 ++-- src/auto4_lua.cpp | 14 +++++++------- src/auto4_lua_assfile.cpp | 6 +++--- src/auto4_lua_dialog.cpp | 2 +- src/auto4_lua_progresssink.cpp | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libaegisub/lua/modules/re.cpp b/libaegisub/lua/modules/re.cpp index 61b407a72..d5bdb4a55 100644 --- a/libaegisub/lua/modules/re.cpp +++ b/libaegisub/lua/modules/re.cpp @@ -156,7 +156,7 @@ int regex_process_flags(lua_State *L) { } int regex_init_flags(lua_State *L) { - lua_newtable(L); + lua_createtable(L, 0, 9); set_field(L, "ICASE", (void*)boost::u32regex::icase); set_field(L, "NOSUB", (void*)boost::u32regex::nosubs); @@ -184,7 +184,7 @@ extern "C" int luaopen_re_impl(lua_State *L) { lua_pop(L, 1); } - lua_newtable(L); + lua_createtable(L, 0, 8); set_field(L, "matches", regex_matches); set_field(L, "search", regex_search); set_field(L, "match", regex_match); diff --git a/src/auto4_lua.cpp b/src/auto4_lua.cpp index 3c6ffed46..25527b6fb 100644 --- a/src/auto4_lua.cpp +++ b/src/auto4_lua.cpp @@ -157,7 +157,7 @@ namespace { int clipboard_init(lua_State *L) { - lua_newtable(L); + lua_createtable(L, 0, 2); set_field(L, "get", clipboard_get); set_field(L, "set", clipboard_set); return 1; @@ -256,7 +256,7 @@ namespace { std::vector const& kf = c->videoController->GetKeyFrames(); - lua_newtable(L); + lua_createtable(L, kf.size(), 0); for (size_t i = 0; i < kf.size(); ++i) { push_value(L, kf[i]); lua_rawseti(L, -2, i); @@ -466,7 +466,7 @@ namespace { // make "aegisub" table lua_pushstring(L, "aegisub"); - lua_newtable(L); + lua_createtable(L, 0, 12); set_field(L, "register_macro", LuaCommand::LuaRegister); set_field(L, "register_filter", LuaExportFilter::LuaRegister); @@ -698,7 +698,7 @@ namespace { cmd_type |= cmd::COMMAND_TOGGLE; // new table for containing the functions for this feature - lua_newtable(L); + lua_createtable(L, 0, 3); // store processing function push_value(L, "run"); @@ -739,9 +739,9 @@ namespace { return rows; } - static void transform_selection(lua_State *L, std::vector rows) + static void transform_selection(lua_State *L, std::vector const& rows) { - lua_newtable(L); + lua_createtable(L, rows.size(), 0); for (size_t i = 0; i < rows.size(); ++i) { push_value(L, rows[i]); lua_rawseti(L, -2, i + 1); @@ -924,7 +924,7 @@ namespace { luaL_error(L, "The filter processing function must be a function"); // new table for containing the functions for this feature - lua_newtable(L); + lua_createtable(L, 0, 2); // store processing function push_value(L, "run"); diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 5b54afa5d..a52aacbc9 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -628,7 +628,7 @@ namespace Automation4 { // 2.1.x stored everything before the first syllable at index zero // There's no longer any such thing with the new parser, but scripts // may rely on kara[0] existing so add an empty syllable - lua_newtable(L); + lua_createtable(L, 0, 6); set_field(L, "duration", 0); set_field(L, "start_time", 0); set_field(L, "end_time", 0); @@ -639,7 +639,7 @@ namespace Automation4 { AssKaraoke kara(dia, false, false); for (auto const& syl : kara) { - lua_newtable(L); + lua_createtable(L, 0, 6); set_field(L, "duration", syl.duration); set_field(L, "start_time", syl.start_time - dia->Start); set_field(L, "end_time", syl.start_time + syl.duration - dia->Start); @@ -740,7 +740,7 @@ namespace Automation4 { *static_cast(lua_newuserdata(L, sizeof(LuaAssFile*))) = this; // make the metatable - lua_newtable(L); + lua_createtable(L, 0, 5); set_field(L, "__index", closure_wrapper<&LuaAssFile::ObjectIndexRead>); set_field(L, "__newindex", closure_wrapper_v<&LuaAssFile::ObjectIndexWrite, false>); set_field(L, "__len", closure_wrapper<&LuaAssFile::ObjectGetLen>); diff --git a/src/auto4_lua_dialog.cpp b/src/auto4_lua_dialog.cpp index 73fc520fe..21d5086f6 100644 --- a/src/auto4_lua_dialog.cpp +++ b/src/auto4_lua_dialog.cpp @@ -543,7 +543,7 @@ namespace Automation4 { } // Then read controls back - lua_newtable(L); + lua_createtable(L, 0, controls.size()); for (auto& control : controls) { control->LuaReadBack(L); lua_setfield(L, -2, control->name.c_str()); diff --git a/src/auto4_lua_progresssink.cpp b/src/auto4_lua_progresssink.cpp index 8a2ae096f..76fc8a1fa 100644 --- a/src/auto4_lua_progresssink.cpp +++ b/src/auto4_lua_progresssink.cpp @@ -69,7 +69,7 @@ namespace Automation4 { lua_getglobal(L, "aegisub"); // Create aegisub.progress table - lua_newtable(L); + lua_createtable(L, 0, 5); set_field_to_closure(L, "set", LuaSetProgress); set_field_to_closure(L, "task", LuaSetTask); set_field_to_closure(L, "title", LuaSetTitle); @@ -77,7 +77,7 @@ namespace Automation4 { lua_setfield(L, -2, "progress"); // Create aegisub.debug table - lua_newtable(L); + lua_createtable(L, 0, 4); set_field_to_closure(L, "out", LuaDebugOut); lua_setfield(L, -2, "debug"); @@ -85,7 +85,7 @@ namespace Automation4 { set_field_to_closure(L, "log", LuaDebugOut, -2); if (allow_config_dialog) { - lua_newtable(L); + lua_createtable(L, 0, 3); set_field_to_closure(L, "display", LuaDisplayDialog); set_field_to_closure(L, "open", LuaDisplayOpenDialog); set_field_to_closure(L, "save", LuaDisplaySaveDialog); @@ -216,7 +216,7 @@ namespace Automation4 { wxArrayString files; diag.GetPaths(files); - lua_newtable(L); + lua_createtable(L, files.size(), 0); for (size_t i = 0; i < files.size(); ++i) { lua_pushstring(L, files[i].utf8_str()); lua_rawseti(L, -2, i + 1);