From 182f91b7a03b144e967b0aa0f76d698ad89d2459 Mon Sep 17 00:00:00 2001 From: Shmuel Zeigerman Date: Sun, 19 May 2024 17:35:16 +0300 Subject: [PATCH] LuaFAR: refactoring --- plugins/luamacro/_globalinfo.lua | 2 +- plugins/luamacro/changelog | 4 ++++ plugins/luamacro/luafar/service.c | 24 ++++++++++++------------ plugins/luamacro/luafar/version.h | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua index b9662c3b4d..99ea74c302 100644 --- a/plugins/luamacro/_globalinfo.lua +++ b/plugins/luamacro/_globalinfo.lua @@ -1,6 +1,6 @@ function export.GetGlobalInfo() return { - Version = { 3, 0, 0, 833 }, + Version = { 3, 0, 0, 834 }, MinFarVersion = { 3, 0, 0, 6327 }, Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"), Title = "LuaMacro", diff --git a/plugins/luamacro/changelog b/plugins/luamacro/changelog index 6338e1f58c..b7efa951ae 100644 --- a/plugins/luamacro/changelog +++ b/plugins/luamacro/changelog @@ -1,3 +1,7 @@ +shmuel 2024-05-19 17:31:46+03:00 - build 834 + +1. LuaFAR: refactoring. + shmuel 2024-05-19 11:12:10+03:00 - build 833 1. LuaFAR: refactoring. diff --git a/plugins/luamacro/luafar/service.c b/plugins/luamacro/luafar/service.c index 58843b76a7..bc183998ed 100644 --- a/plugins/luamacro/luafar/service.c +++ b/plugins/luamacro/luafar/service.c @@ -1702,7 +1702,7 @@ static int far_Menu(lua_State *L) const GUID* MenuGuid = NULL; struct FarMenuItem *Items, *pItem; struct FarKey *pBreakKeys; - lua_settop(L, POS_BKEYS); // cut unneeded parameters; make stack predictable + luaL_checktype(L, POS_PROPS, LUA_TTABLE); luaL_checktype(L, POS_ITEMS, LUA_TTABLE); ItemsNumber = lua_objlen(L, POS_ITEMS); @@ -1710,37 +1710,37 @@ static int far_Menu(lua_State *L) if (!lua_isnil(L,POS_BKEYS) && !lua_istable(L,POS_BKEYS) && lua_type(L,POS_BKEYS)!=LUA_TSTRING) return luaL_argerror(L, POS_BKEYS, "must be table, string or nil"); + lua_settop(L, POS_BKEYS); // cut unneeded parameters; make stack predictable lua_newtable(L); // temporary store; at stack position 4 + // Properties - lua_pushvalue(L, POS_PROPS); //+1 + lua_pushvalue(L, POS_PROPS); X = GetOptIntFromTable(L, "X", -1); Y = GetOptIntFromTable(L, "Y", -1); MaxHeight = GetOptIntFromTable(L, "MaxHeight", 0); - lua_getfield(L, POS_PROPS, "Flags"); //+2 + lua_getfield(L, POS_PROPS, "Flags"); if (!lua_isnil(L, -1)) Flags = CheckFlags(L, -1); - lua_getfield(L, POS_PROPS, "Title"); //+3 - + lua_getfield(L, POS_PROPS, "Title"); if (lua_isstring(L,-1)) Title = StoreTempString(L, POS_STORE); - lua_getfield(L, POS_PROPS, "Bottom"); //+3 - + lua_getfield(L, POS_PROPS, "Bottom"); if (lua_isstring(L,-1)) Bottom = StoreTempString(L, POS_STORE); - lua_getfield(L, POS_PROPS, "HelpTopic"); //+3 - + lua_getfield(L, POS_PROPS, "HelpTopic"); if (lua_isstring(L,-1)) HelpTopic = StoreTempString(L, POS_STORE); - lua_getfield(L, POS_PROPS, "SelectIndex"); //+3 + lua_getfield(L, POS_PROPS, "SelectIndex"); if ((SelectIndex = lua_tointeger(L,-1)) > ItemsNumber) SelectIndex = 0; - lua_getfield(L, POS_PROPS, "Id"); //+4 + lua_getfield(L, POS_PROPS, "Id"); if (lua_type(L,-1)==LUA_TSTRING && lua_objlen(L,-1)==sizeof(GUID)) MenuGuid = (const GUID*)lua_tostring(L, -1); - lua_pop(L, 4); + lua_settop (L, POS_STORE); + // Items Items = (struct FarMenuItem*)lua_newuserdata(L, ItemsNumber*sizeof(struct FarMenuItem)); memset(Items, 0, ItemsNumber*sizeof(struct FarMenuItem)); diff --git a/plugins/luamacro/luafar/version.h b/plugins/luamacro/luafar/version.h index bb458d6136..1213721ad7 100644 --- a/plugins/luamacro/luafar/version.h +++ b/plugins/luamacro/luafar/version.h @@ -1,3 +1,3 @@ #include -#define PLUGIN_BUILD 833 +#define PLUGIN_BUILD 834