diff --git a/automation/Makefile b/automation/Makefile index 5abfccf59..955e2b1dd 100644 --- a/automation/Makefile +++ b/automation/Makefile @@ -10,9 +10,10 @@ CXXFLAGS += -I../libaegisub/include -I../src -I ../vendor/lua/src $(CXXFLAGS_WX) CPPFLAGS += $(CPPFLAGS_BOOST) LIBS := -L../libaegisub -laegisub -L../vendor/lua -llua-aegisub $(LIBS) +LIBS += ../vendor/luabins/libluabins.a LIBS += $(LIBS_WX) $(LIBS_BOOST) $(LIBS_ICU) -SRC += tests/aegisub.cpp ../src/auto4_regex.cpp +SRC += tests/aegisub.cpp test: $(LIB_SHARED) moon tests/runner.moon diff --git a/automation/include/aegisub/re.moon b/automation/include/aegisub/re.moon index 1a877f067..b571b74bd 100644 --- a/automation/include/aegisub/re.moon +++ b/automation/include/aegisub/re.moon @@ -18,7 +18,7 @@ select = select type = type -- Get the boost::regex binding -regex = aegisub.__init_regex() +regex = require 'aegisub.__re_impl' -- Return the first n elements from ... select_first = (n, a, ...) -> diff --git a/automation/tests/aegisub.cpp b/automation/tests/aegisub.cpp index 48467e95d..e733978b7 100644 --- a/automation/tests/aegisub.cpp +++ b/automation/tests/aegisub.cpp @@ -14,15 +14,9 @@ // // Aegisub Project http://www.aegisub.org/ - -#include "auto4_lua_utils.h" - -namespace Automation4 { int regex_init(lua_State *L); } +#include extern "C" int luaopen_aegisub(lua_State *L) { - lua_pushstring(L, "aegisub"); - lua_newtable(L); - set_field(L, "__init_regex", Automation4::regex_init); - lua_settable(L, LUA_GLOBALSINDEX); + agi::lua::preload_modules(L); return 1; } diff --git a/build/Aegisub/Aegisub.vcxproj b/build/Aegisub/Aegisub.vcxproj index 56aa2e069..443e861e9 100644 --- a/build/Aegisub/Aegisub.vcxproj +++ b/build/Aegisub/Aegisub.vcxproj @@ -121,8 +121,6 @@ - - @@ -187,7 +185,6 @@ - @@ -308,8 +305,6 @@ - - @@ -382,7 +377,6 @@ - diff --git a/build/Aegisub/Aegisub.vcxproj.filters b/build/Aegisub/Aegisub.vcxproj.filters index 2441580aa..9fc3e3d32 100644 --- a/build/Aegisub/Aegisub.vcxproj.filters +++ b/build/Aegisub/Aegisub.vcxproj.filters @@ -261,9 +261,6 @@ Features\Export - - Automation\Lua - Automation\Lua @@ -615,12 +612,6 @@ ASS - - Automation\Lua - - - Automation\Lua - Features\Resolution resampler @@ -896,9 +887,6 @@ Automation\Lua - - Automation\Lua - Automation\UI @@ -1163,12 +1151,6 @@ ASS - - Automation\Lua - - - Automation\Lua - Features\Resolution resampler diff --git a/build/libaegisub/libaegisub.vcxproj b/build/libaegisub/libaegisub.vcxproj index b34e4bb01..98226baee 100644 --- a/build/libaegisub/libaegisub.vcxproj +++ b/build/libaegisub/libaegisub.vcxproj @@ -65,6 +65,9 @@ + + + @@ -82,6 +85,7 @@ + @@ -116,6 +120,10 @@ + + + + diff --git a/build/libaegisub/libaegisub.vcxproj.filters b/build/libaegisub/libaegisub.vcxproj.filters index de010829d..8bda75bd2 100644 --- a/build/libaegisub/libaegisub.vcxproj.filters +++ b/build/libaegisub/libaegisub.vcxproj.filters @@ -21,6 +21,12 @@ {c97bd8a3-ebb7-4c43-9ca0-4ab8479d9388} + + {ce495b25-1630-42e1-8ab0-053c313448f0} + + + {2cf3ad94-e8a9-4a89-b47e-29523d90fd08} + @@ -173,6 +179,18 @@ Header Files + + Lua + + + Lua + + + Lua\Modules + + + Lua + @@ -283,6 +301,18 @@ Source Files\Common + + Lua + + + Lua\Modules + + + Lua\Modules + + + Lua + diff --git a/libaegisub/Makefile b/libaegisub/Makefile index f47c78dcc..e3c9a5619 100644 --- a/libaegisub/Makefile +++ b/libaegisub/Makefile @@ -41,6 +41,10 @@ SRC += \ common/thesaurus.cpp \ common/util.cpp \ common/vfr.cpp \ + lua/modules.cpp \ + lua/modules/lpeg.cpp \ + lua/modules/re.cpp \ + lua/script_reader.cpp \ unix/access.cpp \ unix/fs.cpp \ unix/log.cpp \ diff --git a/libaegisub/include/libaegisub/lua/modules.h b/libaegisub/include/libaegisub/lua/modules.h new file mode 100644 index 000000000..9783b9723 --- /dev/null +++ b/libaegisub/include/libaegisub/lua/modules.h @@ -0,0 +1,21 @@ +// Copyright (c) 2014, Thomas Goyne +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// Aegisub Project http://www.aegisub.org/ + +struct lua_State; + +namespace agi { namespace lua { + void preload_modules(lua_State *L); +} } diff --git a/src/auto4_lua_scriptreader.h b/libaegisub/include/libaegisub/lua/script_reader.h similarity index 81% rename from src/auto4_lua_scriptreader.h rename to libaegisub/include/libaegisub/lua/script_reader.h index f833c876d..9f8dc59b5 100644 --- a/src/auto4_lua_scriptreader.h +++ b/libaegisub/include/libaegisub/lua/script_reader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013, Thomas Goyne +// Copyright (c) 2014, Thomas Goyne // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -11,16 +11,13 @@ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -/// @file auto4_lua_scriptreader.h -/// @see auto4_lua_scriptreader.cpp -/// @ingroup scripting -/// +// +// Aegisub Project http://www.aegisub.org/ #include struct lua_State; -namespace Automation4 { +namespace agi { namespace lua { bool LoadFile(lua_State *L, agi::fs::path const& filename); -} +} } diff --git a/src/auto4_lua_utils.h b/libaegisub/include/libaegisub/lua/utils.h similarity index 77% rename from src/auto4_lua_utils.h rename to libaegisub/include/libaegisub/lua/utils.h index 594eec419..00e2fd7c6 100644 --- a/src/auto4_lua_utils.h +++ b/libaegisub/include/libaegisub/lua/utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012, Thomas Goyne +// Copyright (c) 2014, Thomas Goyne // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -14,16 +14,15 @@ // // Aegisub Project http://www.aegisub.org/ +#include #include -#include - #include -#include #include #include #include -#include + +namespace agi { namespace lua { inline void push_value(lua_State *L, bool value) { lua_pushboolean(L, value); } inline void push_value(lua_State *L, const char *value) { lua_pushstring(L, value); } @@ -33,15 +32,12 @@ inline void push_value(lua_State *L, void *p) { lua_pushlightuserdata(L, p); } template typename std::enable_if::value>::type -push_value(lua_State *L, Integer value) { lua_pushinteger(L, value); } - -inline void push_value(lua_State *L, wxString const& value) { - lua_pushstring(L, value.utf8_str()); +push_value(lua_State *L, Integer value) { + lua_pushinteger(L, static_cast(value)); } -inline void push_value(lua_State *L, agi::fs::path const& value) { - std::string strval = value.string(); - lua_pushlstring(L, strval.c_str(), strval.size()); +inline void push_value(lua_State *L, fs::path const& value) { + lua_pushstring(L, value.string().c_str()); } inline void push_value(lua_State *L, std::string const& value) { @@ -63,22 +59,26 @@ inline void set_field(lua_State *L, const char *name, T value) { lua_setfield(L, -2, name); } -inline wxString get_wxstring(lua_State *L, int idx) { - return wxString::FromUTF8(lua_tostring(L, idx)); -} - -inline wxString check_wxstring(lua_State *L, int idx) { - return wxString::FromUTF8(luaL_checkstring(L, idx)); -} - inline std::string get_string_or_default(lua_State *L, int idx) { size_t len = 0; const char *str = lua_tolstring(L, idx, &len); if (!str) - str = ""; + return ""; return std::string(str, len); } +inline std::string get_string(lua_State *L, int idx) { + size_t len = 0; + const char *str = lua_tolstring(L, idx, &len); + return std::string(str ? str : "", len); +} + +inline std::string check_string(lua_State *L, int idx) { + size_t len = 0; + const char *str = luaL_checklstring(L, idx, &len); + return std::string(str ? str : "", len); +} + inline std::string get_global_string(lua_State *L, const char *name) { lua_getglobal(L, name); std::string ret; @@ -88,6 +88,20 @@ inline std::string get_global_string(lua_State *L, const char *name) { return ret; } +template +T *make(lua_State *L, const char *mt, Args&&... args) { + auto obj = static_cast(lua_newuserdata(L, sizeof(T))); + new(obj) T(std::forward(args)...); + luaL_getmetatable(L, mt); + lua_setmetatable(L, -2); + return obj; +} + +template +T& get(lua_State *L, int idx, const char *mt) { + return *static_cast(luaL_checkudata(L, idx, mt)); +} + struct LuaForEachBreak {}; template @@ -144,3 +158,5 @@ struct LuaStackcheck { LuaStackcheck(lua_State*) { } }; #endif + +} } diff --git a/libaegisub/lua/modules.cpp b/libaegisub/lua/modules.cpp new file mode 100644 index 000000000..5e388000a --- /dev/null +++ b/libaegisub/lua/modules.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2014, Thomas Goyne +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// Aegisub Project http://www.aegisub.org/ + +#include "libaegisub/lua/modules.h" + +#include "libaegisub/lua/utils.h" + +int luaopen_lpeg(lua_State *L); +extern "C" int luaopen_luabins(lua_State *L); +extern "C" int luaopen_re_impl(lua_State *L); + +namespace agi { namespace lua { +int regex_init(lua_State *L); + +void preload_modules(lua_State *L) { + lua_getglobal(L, "package"); + lua_getfield(L, -1, "preload"); + + set_field(L, "lpeg", luaopen_lpeg); + set_field(L, "luabins", luaopen_luabins); + set_field(L, "aegisub.__re_impl", luaopen_re_impl); + + lua_pop(L, 2); +} +} } diff --git a/src/lpeg.cpp b/libaegisub/lua/modules/lpeg.cpp similarity index 100% rename from src/lpeg.cpp rename to libaegisub/lua/modules/lpeg.cpp diff --git a/src/lpeg.h b/libaegisub/lua/modules/lpeg.h similarity index 100% rename from src/lpeg.h rename to libaegisub/lua/modules/lpeg.h diff --git a/src/auto4_regex.cpp b/libaegisub/lua/modules/re.cpp similarity index 83% rename from src/auto4_regex.cpp rename to libaegisub/lua/modules/re.cpp index e2cd19c93..61b407a72 100644 --- a/src/auto4_regex.cpp +++ b/libaegisub/lua/modules/re.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013, Thomas Goyne +// Copyright (c) 2014, Thomas Goyne // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -14,34 +14,33 @@ // // Aegisub Project http://www.aegisub.org/ -#include "auto4_lua_utils.h" +#include "libaegisub/lua/utils.h" #include +#include namespace { +using namespace agi::lua; + boost::u32regex& get_regex(lua_State *L) { - return *static_cast(luaL_checkudata(L, 1, "aegisub.regex")); + return get(L, 1, "aegisub.regex"); } boost::smatch& get_smatch(lua_State *L) { - return *static_cast(luaL_checkudata(L, 1, "aegisub.smatch")); + return get(L, 1, "aegisub.smatch"); } int regex_matches(lua_State *L) { - lua_pushboolean(L, u32regex_match(luaL_checkstring(L, 2), get_regex(L))); + lua_pushboolean(L, u32regex_match(check_string(L, 2), get_regex(L))); return 1; } int regex_match(lua_State *L) { auto re = get_regex(L); - std::string str = luaL_checkstring(L, 2); + std::string str = check_string(L, 2); int start = lua_tointeger(L, 3); - auto result = static_cast(lua_newuserdata(L, sizeof(boost::smatch))); - new(result) boost::smatch; - luaL_getmetatable(L, "aegisub.smatch"); - lua_setmetatable(L, -2); - + auto result = make(L, "aegisub.smatch"); if (!u32regex_search(str.cbegin() + start, str.cend(), *result, re, start > 0 ? boost::match_prev_avail | boost::match_not_bob : boost::match_default)) { @@ -67,7 +66,7 @@ int regex_get_match(lua_State *L) { int regex_search(lua_State *L) { auto re = get_regex(L); - std::string str = luaL_checkstring(L, 2); + std::string str = check_string(L, 2); int start = luaL_checkinteger(L, 3) - 1; boost::smatch result; if (!u32regex_search(str.cbegin() + start, str.cend(), result, re, @@ -84,8 +83,8 @@ int regex_search(lua_State *L) { int regex_replace(lua_State *L) { auto re = get_regex(L); - const auto replacement = luaL_checkstring(L, 2); - const std::string str = luaL_checkstring(L, 3); + const auto replacement = check_string(L, 2); + const std::string str = check_string(L, 3); int max_count = luaL_checkinteger(L, 4); // Can't just use regex_replace here since it can only do one or infinite replacements @@ -111,12 +110,11 @@ int regex_replace(lua_State *L) { } int regex_compile(lua_State *L) { - std::string pattern(luaL_checkstring(L, 1)); + std::string pattern(check_string(L, 1)); int flags = luaL_checkinteger(L, 2); - boost::u32regex *re = static_cast(lua_newuserdata(L, sizeof(boost::u32regex))); + auto re = make(L, "aegisub.regex"); try { - new(re) boost::u32regex; *re = boost::make_u32regex(pattern, boost::u32regex::perl | flags); } catch (std::exception const& e) { @@ -127,9 +125,6 @@ int regex_compile(lua_State *L) { // can report the original call site } - luaL_getmetatable(L, "aegisub.regex"); - lua_setmetatable(L, -2); - return 1; } @@ -178,8 +173,7 @@ int regex_init_flags(lua_State *L) { } -namespace Automation4 { -int regex_init(lua_State *L) { +extern "C" int luaopen_re_impl(lua_State *L) { if (luaL_newmetatable(L, "aegisub.regex")) { set_field(L, "__gc", regex_gc); lua_pop(L, 1); @@ -201,4 +195,3 @@ int regex_init(lua_State *L) { set_field(L, "init_flags", regex_init_flags); return 1; } -} diff --git a/src/auto4_lua_scriptreader.cpp b/libaegisub/lua/script_reader.cpp similarity index 85% rename from src/auto4_lua_scriptreader.cpp rename to libaegisub/lua/script_reader.cpp index d04106729..85f8a1975 100644 --- a/src/auto4_lua_scriptreader.cpp +++ b/libaegisub/lua/script_reader.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013, Thomas Goyne +// Copyright (c) 2014, Thomas Goyne // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -11,21 +11,17 @@ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// Aegisub Project http://www.aegisub.org/ -/// @file auto4_lua_scriptreader.cpp -/// @brief Script-file reader for Lua 5.1-based scripting engine -/// @ingroup scripting -/// +#include "libaegisub/lua/script_reader.h" -#include "auto4_lua_scriptreader.h" +#include "libaegisub/file_mapping.h" +#include "libaegisub/lua/utils.h" -#include "auto4_lua_utils.h" +#include -#include - -#include - -namespace Automation4 { +namespace agi { namespace lua { bool LoadFile(lua_State *L, agi::fs::path const& raw_filename) { auto filename = raw_filename; try { @@ -37,7 +33,7 @@ namespace Automation4 { agi::read_file_mapping file(filename); auto buff = file.read(); - size_t size = file.size(); + size_t size = static_cast(file.size()); // Discard the BOM if present if (size >= 3 && buff[0] == -17 && buff[1] == -69 && buff[2] == -65) { @@ -72,4 +68,4 @@ namespace Automation4 { lua_pop(L, 1); // Remove the extra nil for the stackchecker return true; } -} +} } diff --git a/src/Makefile b/src/Makefile index 77f91e1b6..767dff4c6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -106,7 +106,7 @@ charset_detect.o: CXXFLAGS += -D_X86_ font_file_lister_fontconfig.o: CXXFLAGS += $(CFLAGS_FONTCONFIG) text_file_reader.o: CXXFLAGS += -D_X86_ video_provider_manager.o: CXXFLAGS += $(CFLAGS_FFMS2) -auto4_lua.o auto4_lua_assfile.o auto4_lua_dialog.o auto4_lua_progresssink.o auto4_lua_regex.o auto4_lua_scriptreader.o auto4_regex.o lpeg.o: CXXFLAGS += $(CFLAGS_LUA) +auto4_lua.o auto4_lua_assfile.o auto4_lua_dialog.o auto4_lua_progresssink.o: CXXFLAGS += $(CFLAGS_LUA) SRC += \ MatroskaParser.c \ @@ -147,8 +147,6 @@ SRC += \ auto4_lua_assfile.cpp \ auto4_lua_dialog.cpp \ auto4_lua_progresssink.cpp \ - auto4_lua_scriptreader.cpp \ - auto4_regex.cpp \ avisynth_wrap.cpp \ base_grid.cpp \ charset_detect.cpp \ @@ -200,7 +198,6 @@ SRC += \ hotkey.cpp \ hotkey_data_view_model.cpp \ initial_line_state.cpp \ - lpeg.cpp \ main.cpp \ menu.cpp \ mkv_wrap.cpp \ diff --git a/src/auto4_lua.cpp b/src/auto4_lua.cpp index 468bddf0b..1803364f8 100644 --- a/src/auto4_lua.cpp +++ b/src/auto4_lua.cpp @@ -34,14 +34,13 @@ #include "auto4_lua.h" -#include "auto4_lua_utils.h" #include "ass_attachment.h" #include "ass_dialogue.h" #include "ass_info.h" #include "ass_file.h" #include "ass_style.h" #include "auto4_lua_factory.h" -#include "auto4_lua_scriptreader.h" +#include "command/command.h" #include "compat.h" #include "include/aegisub/context.h" #include "main.h" @@ -52,6 +51,9 @@ #include "utils.h" #include +#include +#include +#include #include #include @@ -67,8 +69,9 @@ #include #include #include +#include +#include #include - #include #include #include @@ -76,13 +79,21 @@ #include #include -// Forward declarations of stuff with no public headers -int luaopen_lpeg (lua_State *L); -extern "C" int luaopen_luabins(lua_State * L); -namespace Automation4 { int regex_init(lua_State *L); } +using namespace agi::lua; +using namespace Automation4; namespace { - using namespace Automation4; + + wxString get_wxstring(lua_State *L, int idx) + { + return wxString::FromUTF8(lua_tostring(L, idx)); + } + + wxString check_wxstring(lua_State *L, int idx) + { + return wxString::FromUTF8(luaL_checkstring(L, idx)); + } + void set_context(lua_State *L, const agi::Context *c) { // Explicit cast is needed to discard the const @@ -115,7 +126,7 @@ namespace { int get_translation(lua_State *L) { wxString str(check_wxstring(L, 1)); - push_value(L, _(str)); + push_value(L, _(str).utf8_str()); return 1; } @@ -426,19 +437,18 @@ namespace { try { // create lua environment L = lua_open(); - LuaStackcheck _stackcheck(L); + LuaStackcheck stackcheck(L); // register standard libs push_value(L, luaopen_base); lua_call(L, 0, 0); push_value(L, luaopen_io); lua_call(L, 0, 0); - push_value(L, luaopen_lpeg); lua_call(L, 0, 0); push_value(L, luaopen_math); lua_call(L, 0, 0); push_value(L, luaopen_os); lua_call(L, 0, 0); push_value(L, luaopen_package); lua_call(L, 0, 0); push_value(L, luaopen_string); lua_call(L, 0, 0); push_value(L, luaopen_table); lua_call(L, 0, 0); - push_value(L, luaopen_luabins); lua_call(L, 0, 0); - _stackcheck.check_stack(0); + agi::lua::preload_modules(L); + stackcheck.check_stack(0); // dofile and loadfile are replaced with include lua_pushnil(L); @@ -476,19 +486,19 @@ namespace { push_value(L, LuaModuleLoader); lua_rawseti(L, -2, 2); lua_pop(L, 2); - _stackcheck.check_stack(0); + stackcheck.check_stack(0); // prepare stuff in the registry // store the script's filename push_value(L, GetFilename().stem()); lua_setfield(L, LUA_REGISTRYINDEX, "filename"); - _stackcheck.check_stack(0); + stackcheck.check_stack(0); // reference to the script object push_value(L, this); lua_setfield(L, LUA_REGISTRYINDEX, "aegisub"); - _stackcheck.check_stack(0); + stackcheck.check_stack(0); // make "aegisub" table lua_pushstring(L, "aegisub"); @@ -504,14 +514,17 @@ namespace { set_field(L, "decode_path", decode_path); set_field(L, "cancel", cancel_script); set_field(L, "lua_automation_version", 4); - set_field(L, "__init_regex", regex_init); set_field(L, "__init_clipboard", clipboard_init); set_field(L, "file_name", get_file_name); set_field(L, "gettext", get_translation); // store aegisub table to globals lua_settable(L, LUA_GLOBALSINDEX); - _stackcheck.check_stack(0); + stackcheck.check_stack(0); + + // Preload packaged binary modules + preload_modules(L); + stackcheck.check_stack(0); // load user script if (!LoadFile(L, GetFilename())) { @@ -519,7 +532,7 @@ namespace { lua_pop(L, 1); throw ScriptLoadError(err); } - _stackcheck.check_stack(1); + stackcheck.check_stack(1); // and execute it // this is where features are registered @@ -530,7 +543,7 @@ namespace { lua_pop(L, 1); throw ScriptLoadError(err); } - _stackcheck.check_stack(0); + stackcheck.check_stack(0); lua_getglobal(L, "version"); if (lua_isnumber(L, -1) && lua_tointeger(L, -1) == 3) { @@ -548,7 +561,7 @@ namespace { lua_pop(L, 1); // if we got this far, the script should be ready - _stackcheck.check_stack(0); + stackcheck.check_stack(0); } catch (agi::Exception const& e) { diff --git a/src/auto4_lua.h b/src/auto4_lua.h index c629bd3a2..26d909954 100644 --- a/src/auto4_lua.h +++ b/src/auto4_lua.h @@ -34,8 +34,6 @@ #include "auto4_base.h" -#include "command/command.h" - #include #include diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index 74024071d..39a71f40b 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -34,7 +34,6 @@ #include "auto4_lua.h" -#include "auto4_lua_utils.h" #include "ass_dialogue.h" #include "ass_info.h" #include "ass_file.h" @@ -44,6 +43,7 @@ #include #include +#include #include #include @@ -51,6 +51,8 @@ #include namespace { + using namespace agi::lua; + DEFINE_SIMPLE_EXCEPTION_NOINNER(BadField, Automation4::MacroRunError, "automation/macro/bad_field") BadField bad_field(const char *expected_type, const char *name, const char *line_clasee) { diff --git a/src/auto4_lua_dialog.cpp b/src/auto4_lua_dialog.cpp index b63ddafe4..c53e6c793 100644 --- a/src/auto4_lua_dialog.cpp +++ b/src/auto4_lua_dialog.cpp @@ -34,7 +34,6 @@ #include "auto4_lua.h" -#include "auto4_lua_utils.h" #include "ass_style.h" #include "colour_button.h" #include "compat.h" @@ -43,6 +42,7 @@ #include "validators.h" #include +#include #include #include @@ -64,6 +64,7 @@ #include #include +using namespace agi::lua; namespace { inline void get_if_right_type(lua_State *L, std::string &def) { if (lua_isstring(L, -1)) diff --git a/src/auto4_lua_progresssink.cpp b/src/auto4_lua_progresssink.cpp index f966dff9d..8a2ae096f 100644 --- a/src/auto4_lua_progresssink.cpp +++ b/src/auto4_lua_progresssink.cpp @@ -34,7 +34,7 @@ #include "auto4_lua.h" -#include "auto4_lua_utils.h" +#include #include @@ -51,6 +51,11 @@ namespace { lua_pushnil(L); lua_setfield(L, idx, name); } + + wxString check_wxstring(lua_State *L, int idx) + { + return wxString::FromUTF8(luaL_checkstring(L, idx)); + } } namespace Automation4 {