Skip to content

Commit fdcfc75

Browse files
committed
LuaFAR: refactoring
1 parent 1ff4b95 commit fdcfc75

4 files changed

Lines changed: 22 additions & 23 deletions

File tree

plugins/luamacro/_globalinfo.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function export.GetGlobalInfo()
22
return {
3-
Version = { 3, 0, 0, 919 },
3+
Version = { 3, 0, 0, 920 },
44
MinFarVersion = { 3, 0, 0, 6632 },
55
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
66
Title = "LuaMacro",

plugins/luamacro/changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
shmuel 2026-04-18 00:28:31+03:00 - build 920
2+
3+
1. LuaFAR: refactoring.
4+
15
shmuel 2026-04-13 19:20:58+03:00 - build 919
26

37
1. LuaFAR: refactoring.

plugins/luamacro/luafar/lf_service.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,13 +1841,13 @@ static int far_Menu(lua_State *L)
18411841
intptr_t *pBreakCode = NULL;
18421842
if (lua_type(L, POS_BKEYS) == LUA_TSTRING)
18431843
{
1844-
const char *q, *ptr = lua_tostring(L, POS_BKEYS);
1844+
const char *ptr = lua_tostring(L, POS_BKEYS);
18451845
lua_newtable(L);
18461846
while (*ptr)
18471847
{
18481848
while (isspace(*ptr)) ptr++;
18491849
if (*ptr == 0) break;
1850-
q = ptr++;
1850+
const char *q = ptr++;
18511851
while(*ptr && !isspace(*ptr)) ptr++;
18521852
lua_createtable(L,0,1);
18531853
lua_pushlstring(L,q,ptr-q);
@@ -1861,25 +1861,16 @@ static int far_Menu(lua_State *L)
18611861

18621862
if (NumBreakCodes)
18631863
{
1864-
char buf[32];
1865-
int ind;
18661864
struct FarKey* BreakKeys = (struct FarKey*)lua_newuserdata(L, (1+NumBreakCodes)*sizeof(struct FarKey));
18671865
// get virtualkeys table from the registry; push it on top
18681866
lua_pushstring(L, FAR_VIRTUALKEYS);
18691867
lua_rawget(L, LUA_REGISTRYINDEX);
18701868
// push breakkeys table on top
18711869
lua_pushvalue(L, POS_BKEYS); // vk=-2; bk=-1;
18721870

1873-
for(ind=0; ind < NumBreakCodes; ind++)
1871+
int ind_target = 0;
1872+
for (int ind=0; ind < NumBreakCodes; ind++)
18741873
{
1875-
DWORD mod = 0;
1876-
const char* s;
1877-
char* vk; // virtual key
1878-
WORD VirtualKeyCode;
1879-
1880-
BreakKeys[ind].VirtualKeyCode = 0xFF; // preset to invalid value !=0, since 0 marks end-of-array for Far.
1881-
BreakKeys[ind].ControlKeyState = LEFT_CTRL_PRESSED|LEFT_ALT_PRESSED|SHIFT_PRESSED;
1882-
18831874
// get next break key (optional modifier plus virtual key)
18841875
lua_pushinteger(L,ind+1); // vk=-3; bk=-2;
18851876
lua_gettable(L,-2); // vk=-3; bk=-2; bki=-1;
@@ -1897,8 +1888,9 @@ static int far_Menu(lua_State *L)
18971888
if (pd->FSF->FarNameToInputRecord((const wchar_t*)lua_touserdata(L,-1), &Rec)
18981889
&& Rec.EventType == KEY_EVENT)
18991890
{
1900-
BreakKeys[ind].VirtualKeyCode = Rec.Event.KeyEvent.wVirtualKeyCode;
1901-
BreakKeys[ind].ControlKeyState = Rec.Event.KeyEvent.dwControlKeyState;
1891+
BreakKeys[ind_target].VirtualKeyCode = Rec.Event.KeyEvent.wVirtualKeyCode;
1892+
BreakKeys[ind_target].ControlKeyState = Rec.Event.KeyEvent.dwControlKeyState;
1893+
ind_target++;
19021894
lua_pop(L, 2);
19031895
continue; // success
19041896
}
@@ -1908,13 +1900,15 @@ static int far_Menu(lua_State *L)
19081900
}
19091901

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

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

19151909
strcpy(buf, s);
19161910
_strupr(buf);
1917-
vk = strchr(buf, '+'); // virtual key
1911+
char* vk = strchr(buf, '+'); // virtual key
19181912

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

19361930
// get virtual key and break key values
19371931
lua_rawget(L,-4); // vk=-4; bk=-3;
1938-
VirtualKeyCode = (WORD)lua_tointeger(L,-1);
1932+
WORD VirtualKeyCode = (WORD)lua_tointeger(L,-1);
19391933
if (VirtualKeyCode)
19401934
{
1941-
BreakKeys[ind].VirtualKeyCode = VirtualKeyCode;
1942-
BreakKeys[ind].ControlKeyState = mod;
1935+
BreakKeys[ind_target].VirtualKeyCode = VirtualKeyCode;
1936+
BreakKeys[ind_target].ControlKeyState = mod;
1937+
ind_target++;
19431938
}
19441939
lua_pop(L,2); // vk=-2; bk=-1;
19451940
}
19461941

1947-
BreakKeys[ind].VirtualKeyCode = 0; // required by FAR API
1942+
BreakKeys[ind_target].VirtualKeyCode = 0; // required by FAR API
19481943
pBreakKeys = BreakKeys;
19491944
pBreakCode = &BreakCode;
19501945
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#include <farversion.hpp>
22

3-
#define PLUGIN_BUILD 919
3+
#define PLUGIN_BUILD 920

0 commit comments

Comments
 (0)