[FarGroup/FarManager] master: LuaFAR: refactoring (55d855b7f)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Apr 27, 2026, 12:00:56 PM (9 days ago) Apr 27
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/55d855b7f479be41f9f154c3a9c2df465b05d5a8

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

commit 55d855b7f479be41f9f154c3a9c2df465b05d5a8
Author: Shmuel Zeigerman <solo...@gmail.com>
Date: Mon Apr 27 18:49:15 2026 +0300

LuaFAR: refactoring


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

55d855b7f479be41f9f154c3a9c2df465b05d5a8
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 +++
plugins/luamacro/luafar/lf_bit64.c | 2 +-
plugins/luamacro/luafar/lf_exported.c | 52 +++++++++++++++++------------------
plugins/luamacro/luafar/lf_version.h | 2 +-
plugins/luamacro/luafar/luaplug.mak | 2 +-
6 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index 52d463a69..14dcbcb41 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 922 },
+ Version = { 3, 0, 0, 923 },
MinFarVersion = { 3, 0, 0, 6678 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
diff --git a/plugins/luamacro/changelog b/plugins/luamacro/changelog
index 3f7242a64..4245c0d0b 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-04-27 18:48:05+03:00 - build 923
+
+1. LuaFAR: refactoring.
+
shmuel 2026-04-19 22:39:51+03:00 - build 922

1. LuaFAR: refactoring.
diff --git a/plugins/luamacro/luafar/lf_bit64.c b/plugins/luamacro/luafar/lf_bit64.c
index a68f29512..8a6c62518 100644
--- a/plugins/luamacro/luafar/lf_bit64.c
+++ b/plugins/luamacro/luafar/lf_bit64.c
@@ -9,7 +9,7 @@
#include "lf_bit64.h"

#define MAX52 (1LL << 52)
-#define FIT52(v) ((v >= 0 && v < MAX52) || (v < 0 && v >= -MAX52))
+#define FIT52(v) (((v) >= 0 && (v) < MAX52) || ((v) < 0 && (v) >= -MAX52))

static int f_new(lua_State *L); /* forward declaration */

diff --git a/plugins/luamacro/luafar/lf_exported.c b/plugins/luamacro/luafar/lf_exported.c
index c05471b69..5bf1dfdc5 100644
--- a/plugins/luamacro/luafar/lf_exported.c
+++ b/plugins/luamacro/luafar/lf_exported.c
@@ -201,8 +201,7 @@ void* AddBufToCollector(lua_State *L, int pos, size_t size)
// -- a table is on stack top
// -- its field 'field' is an array of strings
// -- 'cpos' - collector stack position
-const wchar_t** CreateStringsArray(lua_State* L, int cpos, const char* field,
- size_t *numstrings)
+const wchar_t** CreateStringsArray(lua_State* L, int cpos, const char* field, size_t *numstrings)
{
const wchar_t **buf = NULL;
if (numstrings) *numstrings = 0;
@@ -217,10 +216,9 @@ const wchar_t** CreateStringsArray(lua_State* L, int cpos, const char* field,

if (n > 0)
{
- size_t i;
buf = (const wchar_t**)AddBufToCollector(L, cpos, (n+1) * sizeof(wchar_t*));

- for(i=0; i < n; i++)
+ for(size_t i=0; i < n; i++)
buf[i] = AddStringToCollectorSlot(L, cpos, (int)i+1);

buf[n] = NULL;
@@ -381,12 +379,9 @@ void LF_FreeFindData(lua_State* L, const struct FreeFindDataInfo *Info)
//---------------------------------------------------------------------------

// PanelItem table should be on Lua stack top
-void UpdateFileSelection(lua_State* L, struct PluginPanelItem *PanelItem,
- size_t ItemsNumber)
+void UpdateFileSelection(lua_State* L, struct PluginPanelItem *PanelItem, size_t ItemsNumber)
{
- int i;
-
- for(i=0; i<(int)ItemsNumber; i++)
+ for (int i=0; i < (int)ItemsNumber; i++)
{
lua_rawgeti(L, -1, i+1); //+1

@@ -448,12 +443,9 @@ intptr_t LF_GetFiles(lua_State* L, struct GetFilesInfo *Info)
BOOL RunDefaultScript(lua_State* L, int ForFirstTime)
{
int pos = lua_gettop(L);
- int status = 1, i;
- wchar_t *defscript;
- FILE *fp = NULL;
+ int status = 1;
const char *name = "<boot";
const wchar_t *ModuleName = GetPluginData(L)->Info->ModuleName;
- const wchar_t delims[] = L".-";

// First: try to load the default script embedded into the plugin.
lua_getglobal(L, "package");
@@ -474,10 +466,12 @@ BOOL RunDefaultScript(lua_State* L, int ForFirstTime)

lua_pop(L, 3);
// Second: try to load the default script from a disk file
- defscript = (wchar_t*)lua_newuserdata(L, sizeof(wchar_t)*(wcslen(ModuleName)+5));
+ wchar_t *defscript = (wchar_t*)lua_newuserdata(L, sizeof(wchar_t)*(wcslen(ModuleName)+5));
wcscpy(defscript, ModuleName);

- for(i=0; delims[i]; i++)
+ FILE *fp = NULL;
+ const wchar_t delims[] = L".-";
+ for (int i=0; delims[i]; i++)
{
wchar_t *end = wcsrchr(defscript, delims[i]);

@@ -609,7 +603,7 @@ static void OPI_FillInfoLines(lua_State *L, struct OpenPanelInfo *Info, int cpos
if (InfoLinesNumber > 0)
{
struct InfoPanelLine *pl = (struct InfoPanelLine*)
- AddBufToCollector(L, cpos, InfoLinesNumber * sizeof(struct InfoPanelLine));
+ AddBufToCollector(L, cpos, InfoLinesNumber * sizeof(struct InfoPanelLine));
Info->InfoLines = pl;
Info->InfoLinesNumber = InfoLinesNumber;

@@ -646,7 +640,7 @@ static void OPI_FillPanelModes(lua_State *L, struct OpenPanelInfo *Info, int cpo
if (PanelModesNumber > 0)
{
struct PanelMode *pm = (struct PanelMode*)
- AddBufToCollector(L, cpos, PanelModesNumber * sizeof(struct PanelMode));
+ AddBufToCollector(L, cpos, PanelModesNumber * sizeof(struct PanelMode));
Info->PanelModesArray = pm;
Info->PanelModesNumber = PanelModesNumber;

@@ -657,10 +651,10 @@ static void OPI_FillPanelModes(lua_State *L, struct OpenPanelInfo *Info, int cpo

if (lua_istable(L, -1)) //+6: Info,Tbl,Coll,Info,Modes,Mode
{
- pm->ColumnTypes = (wchar_t*)AddStringToCollectorField(L, cpos, "ColumnTypes");
- pm->ColumnWidths = (wchar_t*)AddStringToCollectorField(L, cpos, "ColumnWidths");
- pm->StatusColumnTypes = (wchar_t*)AddStringToCollectorField(L, cpos, "StatusColumnTypes");
- pm->StatusColumnWidths = (wchar_t*)AddStringToCollectorField(L, cpos, "StatusColumnWidths");
+ pm->ColumnTypes = AddStringToCollectorField(L, cpos, "ColumnTypes");
+ pm->ColumnWidths = AddStringToCollectorField(L, cpos, "ColumnWidths");
+ pm->StatusColumnTypes = AddStringToCollectorField(L, cpos, "StatusColumnTypes");
+ pm->StatusColumnWidths = AddStringToCollectorField(L, cpos, "StatusColumnWidths");
pm->ColumnTitles = (const wchar_t* const*)CreateStringsArray(L, cpos, "ColumnTitles", NULL);
pm->Flags = GetFlagsFromTable(L, -1, "Flags");
}
@@ -679,7 +673,8 @@ static void OPI_FillKeyBarTitles(lua_State *L, struct OpenPanelInfo *Info, int c

if (lua_istable(L, -1))
{
- struct KeyBarTitles *kbt = (struct KeyBarTitles*)AddBufToCollector(L, cpos, sizeof(struct KeyBarTitles));
+ struct KeyBarTitles *kbt = (struct KeyBarTitles*)
+ AddBufToCollector(L, cpos, sizeof(struct KeyBarTitles));
Info->KeyBar = kbt;
kbt->CountLabels = lua_objlen(L, -1);
size_t size = kbt->CountLabels * sizeof(struct KeyBarLabel);
@@ -914,6 +909,11 @@ static HANDLE FillFarMacroCall (lua_State* L, int narg)
return (HANDLE)fmc;
}

+static void push_guid(lua_State *L, const void *pGuid)
+{
+ lua_pushlstring(L, (const char*)pGuid, sizeof(GUID));
+}
+
HANDLE LF_Open(lua_State* L, const struct OpenInfo *Info)
{
FP_PROTECT();
@@ -925,7 +925,7 @@ HANDLE LF_Open(lua_State* L, const struct OpenInfo *Info)
return Open_Luamacro(L, Info);

lua_pushinteger(L, Info->OpenFrom); // 1-st argument
- lua_pushlstring(L, (const char*)Info->Guid, sizeof(GUID)); // 2-nd argument
+ push_guid(L, Info->Guid); // 2-nd argument

// 3-rd argument

@@ -1054,7 +1054,7 @@ intptr_t LF_Configure(lua_State* L, const struct ConfigureInfo *Info)

if (GetExportFunction(L, "Configure")) //+1: Func
{
- lua_pushlstring(L, (const char*)Info->Guid, sizeof(GUID));
+ push_guid(L, Info->Guid);

if (0 == pcall_msg(L, 1, 1)) //+1
{
@@ -1298,8 +1298,6 @@ void getPluginMenuItems(lua_State* L, struct PluginMenuItem *pmi, const char* na

void LF_GetPluginInfo(lua_State* L, struct PluginInfo *PI)
{
- int cpos;
-
if (!GetExportFunction(L, "GetPluginInfo")) //+1
return;

@@ -1313,7 +1311,7 @@ void LF_GetPluginInfo(lua_State* L, struct PluginInfo *PI)
}

ReplacePluginInfoCollector(L, COLLECTOR_PI); //+2: Info,Coll
- cpos = lua_gettop(L); // collector position
+ int cpos = lua_gettop(L); // collector position
lua_pushvalue(L, -2); //+3: Info,Coll,Info
//--------------------------------------------------------------------------
PI->StructSize = sizeof(*PI);
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index 590f7d8c6..ae1e897d6 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 922
+#define PLUGIN_BUILD 923
diff --git a/plugins/luamacro/luafar/luaplug.mak b/plugins/luamacro/luafar/luaplug.mak
index 15096e10e..ce50ebd8e 100644
--- a/plugins/luamacro/luafar/luaplug.mak
+++ b/plugins/luamacro/luafar/luaplug.mak
@@ -47,5 +47,5 @@ vpath %.h $(PATH_LUAFAR)
$(TARGET): $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS) -l$(LUADLLNAME) -l$(LUAFARDLLNAME)

-luaplug.o: luaplug.c luafar.h
+luaplug.o: luaplug.c lf_luafar.h
# (end of Makefile)


Reply all
Reply to author
Forward
0 new messages