[FarGroup/FarManager] master: LuaFAR: refactoring (462d05d20)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Jun 9, 2026, 10:30:54 AM (8 days ago) Jun 9
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/462d05d204c4315bc030977f8543ef1fd1bbe0ce

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

commit 462d05d204c4315bc030977f8543ef1fd1bbe0ce
Author: Shmuel Zeigerman <solo...@gmail.com>
Date: Tue Jun 9 17:22:46 2026 +0300

LuaFAR: refactoring


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

462d05d204c4315bc030977f8543ef1fd1bbe0ce
enc/enc_lua/luafar_manual.tsi | 4 +--
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 +++
plugins/luamacro/luafar/lf_exported.c | 11 +++---
plugins/luamacro/luafar/lf_loadlib51.c | 10 ++----
plugins/luamacro/luafar/lf_regex.c | 13 ++++---
plugins/luamacro/luafar/lf_service.c | 66 +++++++++++++++++-----------------
plugins/luamacro/luafar/lf_version.h | 2 +-
8 files changed, 55 insertions(+), 57 deletions(-)

diff --git a/enc/enc_lua/luafar_manual.tsi b/enc/enc_lua/luafar_manual.tsi
index 95e594b6d..4084ce511 100644
--- a/enc/enc_lua/luafar_manual.tsi
+++ b/enc/enc_lua/luafar_manual.tsi
@@ -9484,11 +9484,11 @@ article id=580 dt=Text ctime=3936005270 mtime=3936018950 nm=ACTL_WAITKEY
#_{actl_waitkey}: $(ENC_URL)/service_functions/advcontrol.html#ACTL_WAITKEY
#_

-article id=581 dt=Text ctime=3936005286 mtime=3936009976 nm=ACTL_GETCOLOR
+article id=581 dt=Text ctime=3936005286 mtime=3990186848 nm=ACTL_GETCOLOR
#_Result = far.AdvControl (ACTL_GETCOLOR, Param1)
#_
#_**Parameters:**
-#_ Param1: integer
+#_ Param1: flag
#_ Param2: N/A
#_
#_**Returns:**
diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index a03ec304d..67f81eb8b 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 928 },
+ Version = { 3, 0, 0, 929 },
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 cb3558a41..6b9e80926 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-06-09 17:21:13+03:00 - build 929
+
+1. LuaFAR: refactoring.
+
shmuel 2026-06-08 16:54:06+03:00 - build 928

1. LuaFAR: add far.Flavor (a string "far3"),
diff --git a/plugins/luamacro/luafar/lf_exported.c b/plugins/luamacro/luafar/lf_exported.c
index 5aa7f7832..d095084a8 100644
--- a/plugins/luamacro/luafar/lf_exported.c
+++ b/plugins/luamacro/luafar/lf_exported.c
@@ -1563,9 +1563,8 @@ intptr_t LF_GetContentFields(lua_State* L, const struct GetContentFieldsInfo *In
{
if (GetExportFunction(L, "GetContentFields")) //+1: Func
{
- int i;
lua_createtable(L, (int)Info->Count, 0); //+2
- for (i=0; i<(int)Info->Count; i++)
+ for (int i=0; i<(int)Info->Count; i++)
PutWStrToArray(L, i+1, Info->Names[i], -1);

if (pcall_msg(L, 1, 1) == 0) //+1
@@ -1582,17 +1581,16 @@ intptr_t LF_GetContentData(lua_State* L, struct GetContentDataInfo *Info)
{
if (GetExportFunction(L, "GetContentData")) //+1: Func
{
- int i;
push_utf8_string(L, Info->FilePath, -1); //+2
lua_createtable(L, (int)Info->Count, 0); //+3
- for (i=0; i<(int)Info->Count; i++)
+ for (int i=0; i<(int)Info->Count; i++)
PutWStrToArray(L, i+1, Info->Names[i], -1);

if (pcall_msg(L, 2, 1) == 0) //+1
{
if (lua_istable(L, -1))
{
- for (i=0; i<(int)Info->Count; i++)
+ for (int i=0; i<(int)Info->Count; i++)
{
lua_rawgeti(L, -1, i+1);
if (lua_type(L, -1) == LUA_TSTRING)
@@ -1615,9 +1613,8 @@ intptr_t LF_GetContentData(lua_State* L, struct GetContentDataInfo *Info)

void LF_FreeContentData(lua_State* L, const struct GetContentDataInfo *Info)
{
- size_t i;
(void) L;
- for (i=0; i<Info->Count; i++)
+ for (size_t i=0; i<Info->Count; i++)
{
if (Info->Values[i]) free((void*)Info->Values[i]);
}
diff --git a/plugins/luamacro/luafar/lf_loadlib51.c b/plugins/luamacro/luafar/lf_loadlib51.c
index 5aa0cc494..9fa74718d 100644
--- a/plugins/luamacro/luafar/lf_loadlib51.c
+++ b/plugins/luamacro/luafar/lf_loadlib51.c
@@ -598,7 +598,6 @@ static const int sentinel_ = 0;
static int ll_require(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
- int i;
lua_settop(L, 1); /* _LOADED table will be at index 2 */
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(L, 2, name);
@@ -619,7 +618,7 @@ static int ll_require(lua_State *L)

lua_pushliteral(L, ""); /* error message accumulator */

- for(i=1; ; i++)
+ for(int i=1; ; i++)
{
lua_rawgeti(L, -2, i); /* get a loader */

@@ -686,9 +685,7 @@ static void setfenv(lua_State *L)

static void dooptions(lua_State *L, int n)
{
- int i;
-
- for(i = 2; i <= n; i++)
+ for(int i = 2; i <= n; i++)
{
lua_pushvalue(L, i); /* get option (a function) */
lua_pushvalue(L, -2); /* module */
@@ -820,7 +817,6 @@ static const lua_CFunction loaders[] =

LUALIB_API int luaopen_upackage(lua_State *L)
{
- int i;
/* create new type _LOADLIB */
luaL_newmetatable(L, "_LOADLIB");
lua_pushcfunction(L, gctm);
@@ -837,7 +833,7 @@ LUALIB_API int luaopen_upackage(lua_State *L)
lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);

/* fill it with pre-defined loaders */
- for(i=0; loaders[i] != NULL; i++)
+ for(int i=0; loaders[i] != NULL; i++)
{
lua_pushcfunction(L, loaders[i]);
lua_rawseti(L, -2, i+1);
diff --git a/plugins/luamacro/luafar/lf_regex.c b/plugins/luamacro/luafar/lf_regex.c
index 453baeef2..9b054c03a 100644
--- a/plugins/luamacro/luafar/lf_regex.c
+++ b/plugins/luamacro/luafar/lf_regex.c
@@ -92,9 +92,9 @@ int _regex_gmatch_closure(lua_State *L, int is_wide)

if ((pData->Position <= pData->Length) && RegExpControl(fr->hnd, RECTL_SEARCHEX, 0, pData))
{
- int i, skip = pData->Count>1 ? 1 : 0;
+ int skip = pData->Count>1 ? 1 : 0;

- for(i=skip; i<pData->Count; i++)
+ for(int i=skip; i<pData->Count; i++)
{
if (pData->Match[i].start >= 0 && pData->Match[i].end >= pData->Match[i].start)
{
@@ -230,7 +230,6 @@ int rx_find_match(lua_State *L, int Op, int is_function, int is_wide)

if (RegExpControl(fr->hnd, RECTL_SEARCHEX, 0, &data))
{
- int i;
int skip = (Op != OP_MATCH || data.Count>1) ? 1 : 0;

if (Op != OP_MATCH)
@@ -241,7 +240,7 @@ int rx_find_match(lua_State *L, int Op, int is_function, int is_wide)
if (Op == OP_EXEC)
{
lua_createtable(L, 2*(int)data.Count, 0);
- for(i=1; i<data.Count; i++)
+ for(int i=1; i<data.Count; i++)
{
int k = (i-1)*2 + 1;
if (data.Match[i].start >= 0 && data.Match[i].end >= data.Match[i].start)
@@ -263,7 +262,7 @@ int rx_find_match(lua_State *L, int Op, int is_function, int is_wide)
}
else
{
- i = (int)data.Count - skip + 1;
+ int i = (int)data.Count - skip + 1;
if (Op == OP_TFIND)
lua_newtable(L);
else if (!lua_checkstack(L, i))
@@ -538,11 +537,11 @@ int rx_gsub(lua_State *L, int is_function, int is_wide)
}
else // if (reptype == LUA_TFUNCTION)
{
- intptr_t i, skip = data.Count==1 ? 0:1;
+ intptr_t skip = data.Count==1 ? 0:1;
lua_checkstack(L, (int)(data.Count+1-skip));
lua_pushvalue(L, 3);

- for(i=skip; i<data.Count; i++)
+ for(intptr_t i=skip; i<data.Count; i++)
{
if (data.Match[i].start >= 0 && data.Match[i].end >= data.Match[i].start)
{
diff --git a/plugins/luamacro/luafar/lf_service.c b/plugins/luamacro/luafar/lf_service.c
index 3bb884e16..594d5e667 100644
--- a/plugins/luamacro/luafar/lf_service.c
+++ b/plugins/luamacro/luafar/lf_service.c
@@ -228,6 +228,7 @@ static UINT64 get_env_flag(lua_State *L, int pos, int *success)
int dummy;
const char *str;
INT64 ret = 0;
+ int top = lua_gettop(L);

if (success)
*success = TRUE;
@@ -248,11 +249,22 @@ static UINT64 get_env_flag(lua_State *L, int pos, int *success)
str = lua_tostring(L, pos);
lua_getfield(L, LUA_REGISTRYINDEX, FAR_FLAGSTABLE);
lua_getfield(L, -1, str);
+
+ if (lua_isnil(L, -1)) // not found in far.Flags, look into far.Colors
+ {
+ if ((lua_getglobal(L, "far"), !lua_istable(L,-1))
+ || (lua_getfield(L,-1,"Colors"), !lua_istable(L,-1)))
+ {
+ *success = FALSE;
+ break;
+ }
+ lua_getfield(L, -1, str);
+ }
+
if (lua_type(L, -1) == LUA_TNUMBER)
ret = (__int64)lua_tonumber(L, -1); // IMPORTANT: cast to signed integer.
else if (!bit64_getvalue(L, -1, &ret))
*success = FALSE;
- lua_pop(L, 2);
break;

default:
@@ -261,6 +273,7 @@ static UINT64 get_env_flag(lua_State *L, int pos, int *success)
break;
}

+ lua_settop(L, top);
return ret;
}

@@ -609,10 +622,9 @@ void PushPanelItem(lua_State *L, const struct PluginPanelItem *PanelItem, int No
/* not clear why custom columns are defined on per-file basis */
if (PanelItem->CustomColumnNumber > 0)
{
- int j;
lua_createtable(L, (int)PanelItem->CustomColumnNumber, 0);

- for(j=0; j < (int)PanelItem->CustomColumnNumber; j++)
+ for(int j=0; j < (int)PanelItem->CustomColumnNumber; j++)
PutWStrToArray(L, j+1, PanelItem->CustomColumnData[j], -1);

lua_setfield(L, -2, "CustomColumnData");
@@ -658,10 +670,9 @@ static void PutRECTToTable(lua_State *L, const char* key, RECT rect)

void PushPanelItems(lua_State *L, const struct PluginPanelItem *PanelItems, size_t ItemsNumber, int NoUserData)
{
- int i;
lua_createtable(L, (int)ItemsNumber, 0); // "PanelItems"

- for(i=0; i < (int)ItemsNumber; i++)
+ for(int i=0; i < (int)ItemsNumber; i++)
{
PushPanelItem(L, PanelItems + i, NoUserData);
lua_rawseti(L, -2, i+1);
@@ -671,15 +682,15 @@ void PushPanelItems(lua_State *L, const struct PluginPanelItem *PanelItems, size

static int far_PluginStartupInfo(lua_State *L)
{
- const wchar_t *p;
intptr_t len=0;
TPluginData *pd = GetPluginData(L);
lua_createtable(L, 0, 4);
PutWStrToTable(L, "ModuleName", pd->Info->ModuleName, -1);

- for(p=pd->Info->ModuleName; *p; p++)
+ for(const wchar_t *p = pd->Info->ModuleName; *p; p++)
{
- if (*p==L'\\') len = p - pd->Info->ModuleName;
+ if (*p == L'\\')
+ len = p - pd->Info->ModuleName;
}

PutWStrToTable(L, "ModuleDir", pd->Info->ModuleName, len+1);
@@ -1001,18 +1012,16 @@ static int editor_UndoRedo(lua_State *L)

static void FillKeyBarTitles(lua_State *L, int src_pos, struct KeyBarTitles *kbt)
{
- int store_pos, i;
- size_t size;
lua_newtable(L);
- store_pos = lua_gettop(L);
+ int store_pos = lua_gettop(L);
//-------------------------------------------------------------------------
memset(kbt, 0, sizeof(*kbt));
kbt->CountLabels = lua_objlen(L, src_pos);
- size = kbt->CountLabels * sizeof(struct KeyBarLabel);
+ size_t size = kbt->CountLabels * sizeof(struct KeyBarLabel);
kbt->Labels = (struct KeyBarLabel*)lua_newuserdata(L, size);
memset(kbt->Labels, 0, size);

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

@@ -1175,9 +1184,8 @@ static int PushBookmarks(lua_State *L, int command)
ebm->Size = size;
if (GetPluginData(L)->Info->EditorControl(EditorId, command, 0, ebm))
{
- int i;
lua_createtable(L, (int)ebm->Count, 0);
- for(i=0; i < (int)ebm->Count; i++)
+ for(int i=0; i < (int)ebm->Count; i++)
{
lua_pushinteger(L, i+1);
lua_createtable(L, 0, 4);
@@ -2552,9 +2560,9 @@ static int ChangePanelSelection(lua_State *L, intptr_t command)
Info->PanelControl(handle, command, itemindex, (void*)state);
else
{
- intptr_t i, len = lua_objlen(L,3);
+ intptr_t len = lua_objlen(L,3);

- for(i=1; i<=len; i++)
+ for(intptr_t i=1; i<=len; i++)
{
lua_pushinteger(L, i);
lua_gettable(L,3);
@@ -2647,10 +2655,9 @@ static int far_GetDirList(lua_State *L)

if (Info->GetDirList(Dir, &PanelItems, &ItemsNumber))
{
- int i;
lua_createtable(L, (int)ItemsNumber, 0); // "PanelItems"

- for(i=0; i < (int)ItemsNumber; i++)
+ for(int i=0; i < (int)ItemsNumber; i++)
{
PushPanelItem(L, PanelItems + i, 0);
lua_rawseti(L, -2, i+1);
@@ -3381,7 +3388,7 @@ static int DoSendDlgMessage (lua_State *L, intptr_t Msg, int delta)
while(*p && !iswspace(*p)) p++;
}
arr = (INPUT_RECORD*)lua_newuserdata(L, count * sizeof(INPUT_RECORD));
- for(i=0,p=str; i<count; i++)
+ for(i=0, p=str; i<count; i++)
{
while(iswspace(*p)) p++;
q = p;
@@ -3792,11 +3799,10 @@ int PushDNParams (lua_State *L, intptr_t Msg, intptr_t Param1, void *Param2)
case DN_CTLCOLORDLGITEM:
case DN_CTLCOLORDLGLIST:
{
- int i;
struct FarDialogItemColors* fdic = (struct FarDialogItemColors*) Param2;
lua_createtable(L, (int)fdic->ColorsCount, 1);
PutFlagsToTable(L, "Flags", fdic->Flags);
- for(i=0; i < (int)fdic->ColorsCount; i++)
+ for(int i=0; i < (int)fdic->ColorsCount; i++)
{
PushFarColor(L, &fdic->Colors[i]);
lua_rawseti(L, -2, i+1);
@@ -3856,12 +3862,11 @@ intptr_t ProcessDNResult(lua_State *L, intptr_t Msg, void *Param2)
if ((ret = lua_istable(L,-1)) != 0)
{
struct FarDialogItemColors* fdic = (struct FarDialogItemColors*) Param2;
- int i;
size_t len = lua_objlen(L, -1);

if (len > fdic->ColorsCount) len = fdic->ColorsCount;

- for(i = 0; i < (int)len; i++)
+ for(int i = 0; i < (int)len; i++)
{
lua_rawgeti(L, -1, i+1);
GetFarColor(L, -1, &fdic->Colors[i]);
@@ -4822,7 +4827,7 @@ static int DoAdvControl (lua_State *L, int Command, int Delta)
case ACTL_GETCOLOR:
{
struct FarColor fc;
- Param1 = luaL_checkinteger(L, pos2);
+ Param1 = check_env_flag(L, pos2);

if (Info->AdvControl(PluginId, Command, Param1, &fc))
PushFarColor(L, &fc);
@@ -4869,12 +4874,12 @@ static int DoAdvControl (lua_State *L, int Command, int Delta)

case ACTL_GETARRAYCOLOR:
{
- intptr_t len = Info->AdvControl(PluginId, Command, 0, NULL), i;
+ intptr_t len = Info->AdvControl(PluginId, Command, 0, NULL);
struct FarColor *arr = (struct FarColor*) lua_newuserdata(L, len*sizeof(struct FarColor));
Info->AdvControl(PluginId, Command, len, arr);
lua_createtable(L, (int)len, 0);

- for(i=0; i < len; i++)
+ for(intptr_t i=0; i < len; i++)
{
PushFarColor(L, &arr[i]);
lua_rawseti(L, -2, (int)i+1);
@@ -5602,11 +5607,10 @@ static int far_GetPlugins(lua_State *L)

if (count > 0)
{
- int i;
HANDLE *handles = lua_newuserdata(L, count*sizeof(HANDLE));
count = (int)Info->PluginsControl(INVALID_HANDLE_VALUE, PCTL_GETPLUGINS, count, handles);

- for(i=0; i<count; i++)
+ for(int i=0; i<count; i++)
{
PushPluginHandle(L, handles[i]);
lua_rawseti(L, -3, i+1);
@@ -6851,9 +6855,7 @@ int LF_DoFile(lua_State *L, const wchar_t *fname, int argc, wchar_t* argv[])

if ((status = LF_LoadFile(L, fname)) == 0)
{
- int i;
-
- for(i=0; i < argc; i++)
+ for(int i=0; i < argc; i++)
push_utf8_string(L, argv[i], -1);

status = lua_pcall(L, argc, 0, 0);
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index cd4212bc3..106ac7d68 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 928
+#define PLUGIN_BUILD 929


Reply all
Reply to author
Forward
0 new messages