Repository :
https://github.com/FarGroup/FarManager
On branch : master
Link :
https://github.com/FarGroup/FarManager/commit/9cf2e6c49fba957af2294ebe359c6c13fd953b9c
>---------------------------------------------------------------
commit 9cf2e6c49fba957af2294ebe359c6c13fd953b9c
Author: Shmuel Zeigerman <
solo...@gmail.com>
Date: Tue Apr 28 12:38:15 2026 +0300
LuaFAR: refactoring
>---------------------------------------------------------------
9cf2e6c49fba957af2294ebe359c6c13fd953b9c
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 +
plugins/luamacro/luafar/lf_luamacro.c | 164 +++++++++++++++++-----------------
plugins/luamacro/luafar/lf_version.h | 2 +-
4 files changed, 86 insertions(+), 86 deletions(-)
diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index 14dcbcb41..6e19f19db 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 923 },
+ Version = { 3, 0, 0, 924 },
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 4245c0d0b..9f6ea63da 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-04-28 12:37:25+03:00 - build 924
+
+1. LuaFAR: refactoring.
+
shmuel 2026-04-27 18:48:05+03:00 - build 923
1. LuaFAR: refactoring.
diff --git a/plugins/luamacro/luafar/lf_luamacro.c b/plugins/luamacro/luafar/lf_luamacro.c
index 81870c958..97277596e 100644
--- a/plugins/luamacro/luafar/lf_luamacro.c
+++ b/plugins/luamacro/luafar/lf_luamacro.c
@@ -32,26 +32,95 @@ static void InitMPR (lua_State* L, struct MacroPluginReturn *mpr, size_t nargs,
if (nargs)
{
mpr->Values = (struct FarMacroValue*)lua_newuserdata(L, nargs*sizeof(struct FarMacroValue));
- lua_setfield(L, -2, "MacroPluginReturn");
+ lua_setfield(L, -2, "MacroPluginReturn"); // protect from garbage collection
}
mpr->Count = nargs;
mpr->ReturnType = ReturnType;
}
-HANDLE Open_Luamacro(lua_State* L, const struct OpenInfo *Info)
+static void FillMPR (lua_State* L, struct MacroPluginReturn* Ret, intptr_t ReturnType)
{
- struct OpenMacroPluginInfo* om_info = (struct OpenMacroPluginInfo*)Info->Data;
- int calltype = om_info->CallType;
- size_t argc = om_info->Data ? om_info->Data->Count : 0; // store Data->Count: 'Data' will be invalid after FL_PushParams()
+ lua_getfield(L,-1,"n");
+ int nargs = lua_type(L,-1)==LUA_TNUMBER ? (int)lua_tointeger(L,-1) : (int)lua_objlen(L,-2);
+ lua_pop(L,1);
+ if (nargs < 0) nargs = 0;
+
+ InitMPR(L, Ret, (size_t)nargs, ReturnType);
+
+ for(int idx=0; idx<nargs; idx++)
+ {
+ INT64 val64;
+ Ret->Values[idx].Type = FMVT_NIL;
+ lua_rawgeti(L,-1,idx+1);
+
+ switch (lua_type(L, -1))
+ {
+ case LUA_TNUMBER:
+ Ret->Values[idx].Type = FMVT_DOUBLE;
+ Ret->Values[idx].Value.Double = lua_tonumber(L, -1);
+ lua_pop(L,1);
+ break;
+
+ case LUA_TSTRING:
+ Ret->Values[idx].Type = FMVT_STRING;
+ Ret->Values[idx].Value.String = check_utf8_string(L, -1, NULL);
+ lua_rawseti(L,-2,idx+1);
+ break;
+
+ case LUA_TBOOLEAN:
+ Ret->Values[idx].Type = FMVT_BOOLEAN;
+ Ret->Values[idx].Value.Boolean = lua_toboolean(L, -1);
+ lua_pop(L,1);
+ break;
+
+ case LUA_TLIGHTUSERDATA:
+ Ret->Values[idx].Type = FMVT_POINTER;
+ Ret->Values[idx].Value.Pointer = lua_touserdata(L, -1);
+ lua_rawseti(L,-2,idx+1);
+ break;
+
+ case LUA_TTABLE:
+ lua_getfield(L, -1, TKEY_BINARY);
+ if (lua_type(L, -1) == LUA_TSTRING)
+ {
+ Ret->Values[idx].Type = FMVT_BINARY;
+ Ret->Values[idx].Value.Binary.Data = (char*)lua_tostring(L,-1);
+ Ret->Values[idx].Value.Binary.Size = lua_objlen(L,-1);
+ lua_rawseti(L,-3,idx+1);
+ }
+ lua_pop(L,1);
+ break;
+ default:
+ if (bit64_getvalue(L, -1, &val64))
+ {
+ Ret->Values[idx].Type = FMVT_INTEGER;
+ Ret->Values[idx].Value.Integer = val64;
+ lua_pop(L,1);
+ }
+ else
+ {
+ Ret->Values[idx].Type = FMVT_NIL;
+ lua_pop(L,1);
+ }
+ break;
+ }
+ }
+}
+
+HANDLE Open_Luamacro(lua_State* L, const struct OpenInfo *Info)
+{
if (!IsEqualGUID(GetPluginData(L)->PluginId, LuamacroGuid))
{
lua_pop(L, 1);
return NULL;
}
+ struct OpenMacroPluginInfo* om_info = (struct OpenMacroPluginInfo*)Info->Data;
+ size_t argc = om_info->Data ? om_info->Data->Count : 0; // store Data->Count: 'Data' will be invalid after FL_PushParams()
+
lua_pushinteger(L, Info->OpenFrom); //+2
- lua_pushinteger(L, calltype); //+3
+ lua_pushinteger(L, om_info->CallType); //+3
if (om_info->Data && !FL_PushParams(L, om_info->Data))
{
lua_pop(L, 3);
@@ -74,87 +143,14 @@ HANDLE Open_Luamacro(lua_State* L, const struct OpenInfo *Info)
lua_pop(L,1);
lua_pushvalue(L,-1);
}
+
if (!lua_istable(L,-1))
- {
InitMPR(L, &om_info->Ret, 0, ReturnType);
- lua_pop(L,2);
- return (HANDLE)1;
- }
else
- {
- struct MacroPluginReturn* Ret = &om_info->Ret;
-
- lua_getfield(L,-1,"n");
- int nargs = lua_type(L,-1)==LUA_TNUMBER ? (int)lua_tointeger(L,-1) : (int)lua_objlen(L,-2);
- lua_pop(L,1);
- if (nargs < 0)
- nargs = 0;
-
- InitMPR(L, Ret, (size_t)nargs, ReturnType);
-
- for(int idx=0; idx<nargs; idx++)
- {
- Ret->Values[idx].Type = FMVT_NIL;
- lua_rawgeti(L,-1,idx+1);
-
- switch (lua_type(L, -1))
- {
- case LUA_TNUMBER:
- Ret->Values[idx].Type = FMVT_DOUBLE;
- Ret->Values[idx].Value.Double = lua_tonumber(L, -1);
- lua_pop(L,1);
- break;
-
- case LUA_TSTRING:
- Ret->Values[idx].Type = FMVT_STRING;
- Ret->Values[idx].Value.String = check_utf8_string(L, -1, NULL);
- lua_rawseti(L,-2,idx+1);
- break;
-
- case LUA_TBOOLEAN:
- Ret->Values[idx].Type = FMVT_BOOLEAN;
- Ret->Values[idx].Value.Boolean = lua_toboolean(L, -1);
- lua_pop(L,1);
- break;
-
- case LUA_TLIGHTUSERDATA:
- Ret->Values[idx].Type = FMVT_POINTER;
- Ret->Values[idx].Value.Pointer = lua_touserdata(L, -1);
- lua_rawseti(L,-2,idx+1);
- break;
-
- case LUA_TTABLE:
- lua_getfield(L, -1, TKEY_BINARY);
- if (lua_type(L, -1) == LUA_TSTRING)
- {
- Ret->Values[idx].Type = FMVT_BINARY;
- Ret->Values[idx].Value.Binary.Data = (char*)lua_tostring(L,-1);
- Ret->Values[idx].Value.Binary.Size = lua_objlen(L,-1);
- lua_rawseti(L,-3,idx+1);
- }
- lua_pop(L,1);
- break;
-
- default:
- INT64 val64;
- if (bit64_getvalue(L, -1, &val64))
- {
- Ret->Values[idx].Type = FMVT_INTEGER;
- Ret->Values[idx].Value.Integer = val64;
- lua_pop(L,1);
- }
- else
- {
- Ret->Values[idx].Type = FMVT_NIL;
- lua_pop(L,1);
- }
- break;
- }
- }
+ FillMPR(L, &om_info->Ret, ReturnType);
- lua_pop(L,2);
- return (HANDLE)1;
- }
+ lua_pop(L,2);
+ return (HANDLE)1;
}
return NULL;
@@ -263,7 +259,7 @@ int far_MacroCallFar(lua_State *L)
fmc.Callback = MacroCallFarCallback;
fmc.CallbackData = &cbdata;
- for(int idx=0; idx<(int)fmc.Count; idx++)
+ for(size_t idx=0; idx < fmc.Count; idx++)
{
ConvertLuaValue(L, idx+2, fmc.Values+idx);
if (fmc.Values[idx].Type == FMVT_UNKNOWN)
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index ae1e897d6..51d038e67 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 923
+#define PLUGIN_BUILD 924