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

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Apr 17, 2026, 5:45:55 PMApr 17
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/fdcfc7529fdc623521448743c84441af4612ac63

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

commit fdcfc7529fdc623521448743c84441af4612ac63
Author: Shmuel Zeigerman <solo...@gmail.com>
Date: Sat Apr 18 00:34:07 2026 +0300

LuaFAR: refactoring


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

fdcfc7529fdc623521448743c84441af4612ac63
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 ++++
plugins/luamacro/luafar/lf_service.c | 37 ++++++++++++++++--------------------
plugins/luamacro/luafar/lf_version.h | 2 +-
4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index 6cd5f66b3..58ae5c528 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 919 },
+ Version = { 3, 0, 0, 920 },
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 ca6cd426c..70ec5bb2c 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-04-18 00:28:31+03:00 - build 920
+
+1. LuaFAR: refactoring.
+
shmuel 2026-04-13 19:20:58+03:00 - build 919

1. LuaFAR: refactoring.
diff --git a/plugins/luamacro/luafar/lf_service.c b/plugins/luamacro/luafar/lf_service.c
index 44802ea33..3bfdd1a43 100644
--- a/plugins/luamacro/luafar/lf_service.c
+++ b/plugins/luamacro/luafar/lf_service.c
@@ -1841,13 +1841,13 @@ static int far_Menu(lua_State *L)
intptr_t *pBreakCode = NULL;
if (lua_type(L, POS_BKEYS) == LUA_TSTRING)
{
- const char *q, *ptr = lua_tostring(L, POS_BKEYS);
+ const char *ptr = lua_tostring(L, POS_BKEYS);
lua_newtable(L);
while (*ptr)
{
while (isspace(*ptr)) ptr++;
if (*ptr == 0) break;
- q = ptr++;
+ const char *q = ptr++;
while(*ptr && !isspace(*ptr)) ptr++;
lua_createtable(L,0,1);
lua_pushlstring(L,q,ptr-q);
@@ -1861,8 +1861,6 @@ static int far_Menu(lua_State *L)

if (NumBreakCodes)
{
- char buf[32];
- int ind;
struct FarKey* BreakKeys = (struct FarKey*)lua_newuserdata(L, (1+NumBreakCodes)*sizeof(struct FarKey));
// get virtualkeys table from the registry; push it on top
lua_pushstring(L, FAR_VIRTUALKEYS);
@@ -1870,16 +1868,9 @@ static int far_Menu(lua_State *L)
// push breakkeys table on top
lua_pushvalue(L, POS_BKEYS); // vk=-2; bk=-1;

- for(ind=0; ind < NumBreakCodes; ind++)
+ int ind_target = 0;
+ for (int ind=0; ind < NumBreakCodes; ind++)
{
- DWORD mod = 0;
- const char* s;
- char* vk; // virtual key
- WORD VirtualKeyCode;
-
- BreakKeys[ind].VirtualKeyCode = 0xFF; // preset to invalid value !=0, since 0 marks end-of-array for Far.
- BreakKeys[ind].ControlKeyState = LEFT_CTRL_PRESSED|LEFT_ALT_PRESSED|SHIFT_PRESSED;
-
// get next break key (optional modifier plus virtual key)
lua_pushinteger(L,ind+1); // vk=-3; bk=-2;
lua_gettable(L,-2); // vk=-3; bk=-2; bki=-1;
@@ -1897,8 +1888,9 @@ static int far_Menu(lua_State *L)
if (pd->FSF->FarNameToInputRecord((const wchar_t*)lua_touserdata(L,-1), &Rec)
&& Rec.EventType == KEY_EVENT)
{
- BreakKeys[ind].VirtualKeyCode = Rec.Event.KeyEvent.wVirtualKeyCode;
- BreakKeys[ind].ControlKeyState = Rec.Event.KeyEvent.dwControlKeyState;
+ BreakKeys[ind_target].VirtualKeyCode = Rec.Event.KeyEvent.wVirtualKeyCode;
+ BreakKeys[ind_target].ControlKeyState = Rec.Event.KeyEvent.dwControlKeyState;
+ ind_target++;
lua_pop(L, 2);
continue; // success
}
@@ -1908,13 +1900,15 @@ static int far_Menu(lua_State *L)
}

// separate modifier and virtual key strings
- s = lua_tostring(L,-1);
+ const char* s = lua_tostring(L,-1);

+ char buf[32];
+ DWORD mod = 0;
if (strlen(s) >= sizeof(buf)) { lua_pop(L,2); continue; }

strcpy(buf, s);
_strupr(buf);
- vk = strchr(buf, '+'); // virtual key
+ char* vk = strchr(buf, '+'); // virtual key

if (vk)
{
@@ -1935,16 +1929,17 @@ static int far_Menu(lua_State *L)

// get virtual key and break key values
lua_rawget(L,-4); // vk=-4; bk=-3;
- VirtualKeyCode = (WORD)lua_tointeger(L,-1);
+ WORD VirtualKeyCode = (WORD)lua_tointeger(L,-1);
if (VirtualKeyCode)
{
- BreakKeys[ind].VirtualKeyCode = VirtualKeyCode;
- BreakKeys[ind].ControlKeyState = mod;
+ BreakKeys[ind_target].VirtualKeyCode = VirtualKeyCode;
+ BreakKeys[ind_target].ControlKeyState = mod;
+ ind_target++;
}
lua_pop(L,2); // vk=-2; bk=-1;
}

- BreakKeys[ind].VirtualKeyCode = 0; // required by FAR API
+ BreakKeys[ind_target].VirtualKeyCode = 0; // required by FAR API
pBreakKeys = BreakKeys;
pBreakCode = &BreakCode;
}
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index b87955443..aa00436d0 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 919
+#define PLUGIN_BUILD 920


Reply all
Reply to author
Forward
0 new messages