Path: blob/main/editors/fxite/files/patch-src_macro.cpp
16461 views
--- src/macro.cpp.orig 2013-10-03 09:22:51 UTC1+++ src/macro.cpp2@@ -47,7 +47,7 @@ MacroRunner::~MacroRunner()3/* Catch and report script errors */4static FXint traceback(lua_State *L)5{6- lua_getfield(L, LUA_GLOBALSINDEX, "debug");7+ lua_getglobal(L, "debug");8if (!lua_istable(L, -1)) {9lua_pop(L, 1);10return 1;11@@ -324,7 +324,7 @@ static void debug_hook(lua_State *L, lua_Debug *ar)12/* Override a builtin Lua function, or add a new one if it doesn't exist */13static void override(lua_State *L, const char*module, const char* funcname, lua_CFunction newfunc)14{15- lua_getfield(L,LUA_GLOBALSINDEX,module);16+ lua_getglobal(L,module);17if (lua_istable(L,-1)) {18lua_pushstring(L,funcname);19if (newfunc) {20@@ -342,7 +342,7 @@ static void override(lua_State *L, const char*module,21/* Don't let scripts try to read from stdin, as this would block indefinitely */22static void close_stdin(lua_State *L)23{24- lua_getfield(L, LUA_GLOBALSINDEX, "io");25+ lua_getglobal(L, "io");26if (!lua_istable(L, -1)) {27lua_pop(L, 1);28return;29@@ -384,7 +384,7 @@ typedef struct {3031void MacroRunner::ClearKeepers()32{33- for (FXint i=keepers.first(); i<=keepers.last(); i=keepers.next(i)) {34+ if (UsedSlotsInDict(&keepers)>0) for (FXint i=0; i<TotalSlotsInDict(&keepers); ++i) {35PersistRecord*pr=(PersistRecord*)keepers.data(i);36if (pr) {37if (pr->t==LUA_TSTRING) {38@@ -406,11 +406,12 @@ void MacroRunner::PushKeepers(lua_State *L)39lua_pushstring(L,PERSIST_TABLE_NAME);40lua_newtable(L);41lua_settable(L, -3);42- for (FXint i=keepers.first(); i<=keepers.last(); i=keepers.next(i)) {43+ if (UsedSlotsInDict(&keepers)>0) for (FXint i=0; i<TotalSlotsInDict(&keepers); ++i) {44PersistRecord*pr=(PersistRecord*)keepers.data(i);45+ if (!pr) { continue; }46lua_getglobal(L, LUA_MODULE_NAME);47lua_getfield(L,-1,PERSIST_TABLE_NAME);48- lua_pushstring(L,keepers.key(i));49+ lua_pushstring(L,DictKeyName(keepers,i));50switch (pr->t) {51case LUA_TNUMBER: { lua_pushnumber(L, pr->n); break;}52case LUA_TBOOLEAN:{ lua_pushboolean(L, pr->b); break;}53@@ -455,7 +456,7 @@ void MacroRunner::PopKeepers(lua_State *L)54}55}56if (pr) {57- keepers.replace(lua_tostring(L,-2), pr);58+ ReplaceInDict(&keepers,lua_tostring(L,-2),pr);59}60}61lua_pop(L, 1);62@@ -479,6 +480,9 @@ bool MacroRunner::RunMacro(const FXString &source, boo63lua_State *L=luaL_newstate();64luaL_openlibs(L);65luaopen_dialog(L);66+#if LUA_VERSION_NUM>=50267+ lua_setglobal(L, "dialog");68+#endif69override(L,"os","exit", osexit);70override(L,"io","stdin", NULL);71override(L,"_G","print", print);72@@ -487,11 +491,27 @@ bool MacroRunner::RunMacro(const FXString &source, boo73si->script=isfilename?source.text():NULL;74states.append(si);75lua_sethook(L,debug_hook,LUA_MASKLINE,1);76- luaL_register(L, LUA_MODULE_NAME, LuaFuncs());77- luaL_register(L, LUA_MODULE_NAME, LuaFxUtils(TopWinPub::instance(), EXE_NAME));78+#if LUA_VERSION_NUM<50279+ luaL_Register(L, LUA_MODULE_NAME, LuaFuncs());80+ luaL_Register(L, LUA_MODULE_NAME, LuaFxUtils(TopWinPub::instance(), EXE_NAME));81+ luaL_Register(L, LUA_MODULE_NAME, LuaCommands(TopWinPub::instance()));82+#else83+ int n=0;84+ const luaL_Reg*p;85+ const luaL_Reg*funcs = LuaFuncs();86+ const luaL_Reg*utils = LuaFxUtils(TopWinPub::instance(), EXE_NAME);87+ const luaL_Reg*cmds = LuaCommands(TopWinPub::instance());88+ for (p=funcs; p->name; p++) { n++; }89+ for (p=utils; p->name; p++) { n++; }90+ for (p=cmds; p->name; p++) { n++; }91+ lua_createtable(L, 0, n);92+ luaL_setfuncs(L, funcs, 0);93+ luaL_setfuncs(L, utils, 0);94+ luaL_setfuncs(L, cmds, 0);95+ lua_setglobal(L, LUA_MODULE_NAME);96+#endif97override(L,LUA_MODULE_NAME,"script", scriptname);98override(L,LUA_MODULE_NAME,"optimize", optimize);99- luaL_openlib(L, LUA_MODULE_NAME, LuaCommands(TopWinPub::instance()), 0);100set_string_token(L, "_VERSION", VERSION);101PushKeepers(L);102if (isfilename) {103104105