[FarGroup/FarManager] master: LuaFAR: refactoring (f231decec)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Apr 13, 2026, 12:30:57 PM (3 days ago) Apr 13
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/f231decec8713a5bb2ed255db3e56e9252d1bb92

>---------------------------------------------------------------

commit f231decec8713a5bb2ed255db3e56e9252d1bb92
Author: Shmuel Zeigerman <solo...@gmail.com>
Date: Mon Apr 13 19:24:39 2026 +0300

LuaFAR: refactoring


>---------------------------------------------------------------

f231decec8713a5bb2ed255db3e56e9252d1bb92
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 ++
plugins/luamacro/luafar/lf_exported.c | 123 ++++++++++++++++++----------------
plugins/luamacro/luafar/lf_version.h | 2 +-
4 files changed, 72 insertions(+), 59 deletions(-)

diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index 13e74a486..6cd5f66b3 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 918 },
+ Version = { 3, 0, 0, 919 },
MinFarVersion = { 3, 0, 0, 6632 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
diff --git a/plugins/luamacro/changelog b/plugins/luamacro/changelog
index c8c6ede5b..ca6cd426c 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-04-13 19:20:58+03:00 - build 919
+
+1. LuaFAR: refactoring.
+
shmuel 2026-04-04 22:06:50+03:00 - build 918

1. LuaFAR: support named groups in regex.gsub.
diff --git a/plugins/luamacro/luafar/lf_exported.c b/plugins/luamacro/luafar/lf_exported.c
index 3c31f2ae2..c05471b69 100644
--- a/plugins/luamacro/luafar/lf_exported.c
+++ b/plugins/luamacro/luafar/lf_exported.c
@@ -595,45 +595,9 @@ void LF_CloseAnalyse(lua_State* L, const struct CloseAnalyseInfo *Info)
}
//---------------------------------------------------------------------------

-void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)
+// the KeyBar table is on stack top
+static void OPI_FillInfoLines(lua_State *L, struct OpenPanelInfo *Info, int cpos)
{
- int cpos;
- size_t dfn;
- struct OpenPanelInfo *Info;
-
- if (!GetExportFunction(L, "GetOpenPanelInfo")) //+1
- return;
-
- PushPluginPair(L, aInfo->hPanel); //+3
-
- if (pcall_msg(L, 2, 1) != 0)
- return;
-
- if (!lua_istable(L, -1)) //+1: Info
- {
- lua_pop(L, 1);
- return;
- }
-
- PushPluginTable(L, aInfo->hPanel); //+2: Info,Tbl
- lua_newtable(L); //+3: Info,Tbl,Coll
- cpos = lua_gettop(L); // collector stack position
- lua_pushvalue(L,-1); //+4: Info,Tbl,Coll,Coll
- lua_setfield(L, -3, COLLECTOR_OPI); //+3: Info,Tbl,Coll
- lua_pushvalue(L,-3); //+4: Info,Tbl,Coll,Info
- //---------------------------------------------------------------------------
- // First element in the collector; can be retrieved on later calls;
- Info = (struct OpenPanelInfo*) AddBufToCollector(L, cpos, sizeof(struct OpenPanelInfo));
- //---------------------------------------------------------------------------
- Info->StructSize = sizeof(struct OpenPanelInfo);
- Info->hPanel = aInfo->hPanel;
- Info->FreeSize = CAST(unsigned __int64, GetOptNumFromTable(L, "FreeSize", 0));
- Info->Flags = GetFlagsFromTable(L, -1, "Flags");
- Info->HostFile = AddStringToCollectorField(L, cpos, "HostFile");
- Info->CurDir = AddStringToCollectorField(L, cpos, "CurDir");
- Info->Format = AddStringToCollectorField(L, cpos, "Format");
- Info->PanelTitle = AddStringToCollectorField(L, cpos, "PanelTitle");
- //---------------------------------------------------------------------------
lua_getfield(L, -1, "InfoLines");
lua_getfield(L, -2, "InfoLinesNumber");

@@ -644,13 +608,12 @@ void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)

if (InfoLinesNumber > 0)
{
- int i;
struct InfoPanelLine *pl = (struct InfoPanelLine*)
AddBufToCollector(L, cpos, InfoLinesNumber * sizeof(struct InfoPanelLine));
Info->InfoLines = pl;
Info->InfoLinesNumber = InfoLinesNumber;

- for(i=0; i<InfoLinesNumber; ++i,++pl,lua_pop(L,1))
+ for(int i=0; i<InfoLinesNumber; ++i,++pl,lua_pop(L,1))
{
lua_pushinteger(L, i+1);
lua_gettable(L, -2);
@@ -667,11 +630,11 @@ void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)
lua_pop(L,1);
}
else lua_pop(L, 2);
+}

- //---------------------------------------------------------------------------
- Info->DescrFiles = CreateStringsArray(L, cpos, "DescrFiles", &dfn);
- Info->DescrFilesNumber = dfn;
- //---------------------------------------------------------------------------
+// the KeyBar table is on stack top
+static void OPI_FillPanelModes(lua_State *L, struct OpenPanelInfo *Info, int cpos)
+{
lua_getfield(L, -1, "PanelModesArray");
lua_getfield(L, -2, "PanelModesNumber");

@@ -682,13 +645,12 @@ void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)

if (PanelModesNumber > 0)
{
- int i;
struct PanelMode *pm = (struct PanelMode*)
AddBufToCollector(L, cpos, PanelModesNumber * sizeof(struct PanelMode));
Info->PanelModesArray = pm;
Info->PanelModesNumber = PanelModesNumber;

- for(i=0; i<PanelModesNumber; ++i,++pm,lua_pop(L,1))
+ for(int i=0; i<PanelModesNumber; ++i,++pm,lua_pop(L,1))
{
lua_pushinteger(L, i+1);
lua_gettable(L, -2);
@@ -708,26 +670,22 @@ void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)
lua_pop(L,1);
}
else lua_pop(L, 2);
+}

- //---------------------------------------------------------------------------
- Info->StartPanelMode = GetOptIntFromTable(L, "StartPanelMode", 0);
- Info->StartSortMode = GetFlagsFromTable(L, -1, "StartSortMode");
- Info->StartSortOrder = GetOptIntFromTable(L, "StartSortOrder", 0);
- //---------------------------------------------------------------------------
+// the KeyBar table is on stack top
+static void OPI_FillKeyBarTitles(lua_State *L, struct OpenPanelInfo *Info, int cpos)
+{
lua_getfield(L, -1, "KeyBar");

if (lua_istable(L, -1))
{
- size_t size;
- int i;
struct KeyBarTitles *kbt = (struct KeyBarTitles*)AddBufToCollector(L, cpos, sizeof(struct KeyBarTitles));
Info->KeyBar = kbt;
kbt->CountLabels = lua_objlen(L, -1);
- size = kbt->CountLabels * sizeof(struct KeyBarLabel);
+ size_t size = kbt->CountLabels * sizeof(struct KeyBarLabel);
kbt->Labels = (struct KeyBarLabel*)AddBufToCollector(L, cpos, size);
- memset(kbt->Labels, 0, size);

- for(i=0; i < (int)kbt->CountLabels; i++)
+ for(size_t i=0; i < kbt->CountLabels; i++)
{
lua_rawgeti(L, -1, i+1);

@@ -749,13 +707,64 @@ void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)
}

lua_pop(L, 1);
+}
+
+void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)
+{
+ int stack_top = lua_gettop(L);
+
+ if (!GetExportFunction(L, "GetOpenPanelInfo")) //+1
+ return;
+
+ PushPluginPair(L, aInfo->hPanel); //+3
+
+ if (pcall_msg(L, 2, 1) != 0)
+ return;
+
+ if (!lua_istable(L, -1)) //+1: Info
+ {
+ lua_pop(L, 1);
+ return;
+ }
+
+ PushPluginTable(L, aInfo->hPanel); //+2: Info,Tbl
+ lua_newtable(L); //+3: Info,Tbl,Coll
+ int cpos = lua_gettop(L); // collector stack position
+ lua_pushvalue(L,-1); //+4: Info,Tbl,Coll,Coll
+ lua_setfield(L, -3, COLLECTOR_OPI); //+3: Info,Tbl,Coll
+ lua_pushvalue(L,-3); //+4: Info,Tbl,Coll,Info
+ //---------------------------------------------------------------------------
+ // First element in the collector; can be retrieved on later calls;
+ struct OpenPanelInfo *Info =
+ (struct OpenPanelInfo*) AddBufToCollector(L, cpos, sizeof(struct OpenPanelInfo));
+ //---------------------------------------------------------------------------
+ Info->StructSize = sizeof(struct OpenPanelInfo);
+ Info->hPanel = aInfo->hPanel;
+ Info->FreeSize = CAST(unsigned __int64, GetOptNumFromTable(L, "FreeSize", 0));
+ Info->Flags = GetFlagsFromTable(L, -1, "Flags");
+ Info->HostFile = AddStringToCollectorField(L, cpos, "HostFile");
+ Info->CurDir = AddStringToCollectorField(L, cpos, "CurDir");
+ Info->Format = AddStringToCollectorField(L, cpos, "Format");
+ Info->PanelTitle = AddStringToCollectorField(L, cpos, "PanelTitle");
+ //---------------------------------------------------------------------------
+ OPI_FillInfoLines(L, Info, cpos);
+ OPI_FillPanelModes(L, Info, cpos);
+ OPI_FillKeyBarTitles(L, Info, cpos);
+ //---------------------------------------------------------------------------
+ size_t dfn;
+ Info->DescrFiles = CreateStringsArray(L, cpos, "DescrFiles", &dfn);
+ Info->DescrFilesNumber = dfn;
+ //---------------------------------------------------------------------------
+ Info->StartPanelMode = GetOptIntFromTable(L, "StartPanelMode", 0);
+ Info->StartSortMode = GetFlagsFromTable(L, -1, "StartSortMode");
+ Info->StartSortOrder = GetOptIntFromTable(L, "StartSortOrder", 0);
//---------------------------------------------------------------------------
// _ModuleShortcutData is a non-standard field used with LuaMacro panel modules
Info->ShortcutData = AddStringToCollectorField(L, cpos, "_ModuleShortcutData");
if (Info->ShortcutData == NULL)
Info->ShortcutData = AddStringToCollectorField(L, cpos, "ShortcutData");
//---------------------------------------------------------------------------
- lua_pop(L,4);
+ lua_settop(L, stack_top);
*aInfo = *Info;
}
//---------------------------------------------------------------------------
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index cfc03ca69..b87955443 100644
--- a/plugins/luamacro/luafar/lf_version.h
+++ b/plugins/luamacro/luafar/lf_version.h
@@ -1,3 +1,3 @@
#include <farversion.hpp>

-#define PLUGIN_BUILD 918
+#define PLUGIN_BUILD 919


Reply all
Reply to author
Forward
0 new messages