Repository :
https://github.com/FarGroup/FarManager
On branch : master
Link :
https://github.com/FarGroup/FarManager/commit/8a387ed5e5c37060bf4b46bbfc7d8f09f1e2b1b2
>---------------------------------------------------------------
commit 8a387ed5e5c37060bf4b46bbfc7d8f09f1e2b1b2
Author: Shmuel Zeigerman <
solo...@gmail.com>
Date: Thu May 7 14:51:26 2026 +0300
LuaFAR: refactoring
>---------------------------------------------------------------
8a387ed5e5c37060bf4b46bbfc7d8f09f1e2b1b2
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 +++
plugins/luamacro/luafar/lf_exported.c | 43 ++++++++++++++++---------------
plugins/luamacro/luafar/lf_service.c | 48 +++++++++++++++++------------------
plugins/luamacro/luafar/lf_string.c | 14 +++++-----
plugins/luamacro/luafar/lf_string.h | 1 -
plugins/luamacro/luafar/lf_util.c | 10 ++++----
plugins/luamacro/luafar/lf_version.h | 2 +-
8 files changed, 65 insertions(+), 59 deletions(-)
diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index 6e19f19db..744842e35 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 924 },
+ Version = { 3, 0, 0, 925 },
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 9f6ea63da..62fd23bcd 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-05-07 14:49:36+03:00 - build 925
+
+1. LuaFAR: refactoring.
+
shmuel 2026-04-28 12:37:25+03:00 - build 924
1. LuaFAR: refactoring.
diff --git a/plugins/luamacro/luafar/lf_exported.c b/plugins/luamacro/luafar/lf_exported.c
index 5bf1dfdc5..eb6a18194 100644
--- a/plugins/luamacro/luafar/lf_exported.c
+++ b/plugins/luamacro/luafar/lf_exported.c
@@ -573,7 +573,7 @@ HANDLE LF_Analyse(lua_State* L, const struct AnalyseInfo *Info)
luaL_unref(L, LUA_REGISTRYINDEX, 0);
}
- result = CAST(HANDLE, ref);
+ result = (HANDLE)ref;
}
else
lua_pop(L, 1); //+0
@@ -693,7 +693,7 @@ static void OPI_FillKeyBarTitles(lua_State *L, struct OpenPanelInfo *Info, int c
kbt->Labels[i].Key.VirtualKeyCode = GetOptIntFromTable(L, "VirtualKeyCode", 0);
lua_getfield(L, -1, "ControlKeyState");
- kbt->Labels[i].Key.ControlKeyState = CAST(DWORD, GetFlagCombination(L, -1, NULL));
+ kbt->Labels[i].Key.ControlKeyState = (DWORD) GetFlagCombination(L, -1, NULL);
lua_pop(L, 1);
kbt->Labels[i].Text = AddStringToCollectorField(L, cpos, "Text");
kbt->Labels[i].LongText = AddStringToCollectorField(L, cpos, "LongText");
@@ -735,7 +735,7 @@ void LF_GetOpenPanelInfo(lua_State* L, struct OpenPanelInfo *aInfo)
//---------------------------------------------------------------------------
Info->StructSize = sizeof(struct OpenPanelInfo);
Info->hPanel = aInfo->hPanel;
- Info->FreeSize = CAST(unsigned __int64, GetOptNumFromTable(L, "FreeSize", 0));
+ Info->FreeSize = (unsigned __int64) GetOptNumFromTable(L, "FreeSize", 0);
Info->Flags = GetFlagsFromTable(L, -1, "Flags");
Info->HostFile = AddStringToCollectorField(L, cpos, "HostFile");
Info->CurDir = AddStringToCollectorField(L, cpos, "CurDir");
@@ -936,31 +936,35 @@ HANDLE LF_Open(lua_State* L, const struct OpenInfo *Info)
}
else if (Info->OpenFrom == OPEN_SHORTCUT)
{
- struct OpenShortcutInfo *osi = CAST(struct OpenShortcutInfo*, Info->Data);
+ struct OpenShortcutInfo *osi = (struct OpenShortcutInfo*)Info->Data;
lua_createtable(L, 0, 3);
PutWStrToTable(L, "HostFile", osi->HostFile, -1);
PutWStrToTable(L, "ShortcutData", osi->ShortcutData, -1);
PutFlagsToTable(L, "Flags", osi->Flags);
}
else if (Info->OpenFrom == OPEN_COMMANDLINE)
- push_utf8_string(L, CAST(struct OpenCommandLineInfo*, Info->Data)->CommandLine, -1);
+ {
+ push_utf8_string(L, ((struct OpenCommandLineInfo*)Info->Data)->CommandLine, -1);
+ }
else if (Info->OpenFrom == OPEN_DIALOG)
{
- struct OpenDlgPluginData *data = CAST(struct OpenDlgPluginData*, Info->Data);
+ struct OpenDlgPluginData *data = (struct OpenDlgPluginData*)Info->Data;
lua_createtable(L, 0, 1);
NewDialogData(L, NULL, data->hDlg, FALSE);
lua_setfield(L, -2, "hDlg");
}
else if (Info->OpenFrom == OPEN_ANALYSE)
{
- struct OpenAnalyseInfo* oai = CAST(struct OpenAnalyseInfo*, Info->Data);
+ struct OpenAnalyseInfo* oai = (struct OpenAnalyseInfo*)Info->Data;
PushAnalyseInfo(L, oai->Info);
lua_rawgeti(L, LUA_REGISTRYINDEX, (int)(intptr_t)oai->Handle);
lua_setfield(L, -2, "Handle");
luaL_unref(L, LUA_REGISTRYINDEX, (int)(intptr_t)oai->Handle);
}
else
+ {
lua_pushinteger(L, Info->Data);
+ }
// Call export.Open()
@@ -969,31 +973,30 @@ HANDLE LF_Open(lua_State* L, const struct OpenInfo *Info)
int top = lua_gettop(L);
if (pcall_msg(L, 3, LUA_MULTRET) == 0)
{
- HANDLE ret;
- int narg = lua_gettop(L) - top + 4; // narg
- if (narg > 0 && lua_istable(L, -narg))
+ int nret = lua_gettop(L) - top + 4; // nret
+ if (nret > 0 && lua_istable(L, -nret))
{
- lua_getfield(L, -narg, "type"); // narg+1
+ lua_getfield(L, -nret, "type"); // nret+1
if (lua_type(L,-1)==LUA_TSTRING && lua_objlen(L,-1)==5 && !strcmp("panel",lua_tostring(L,-1)))
{
- lua_pop(L,1); // narg
- lua_rawgeti(L,-narg,1); // narg+1
+ lua_pop(L,1); // nret
+ lua_rawgeti(L,-nret,1); // nret+1
if (lua_toboolean(L, -1))
{
struct FarMacroCall* fmc = CreateFarMacroCall(1);
fmc->Values[0].Type = FMVT_PANEL;
- fmc->Values[0].Value.Pointer = RegisterObject(L); // narg
- lua_pop(L,narg); // +0
+ fmc->Values[0].Value.Pointer = RegisterObject(L); // nret
+ lua_pop(L,nret); // +0
return fmc;
}
- lua_pop(L,narg+1); // +0
+ lua_pop(L,nret+1); // +0
return NULL;
}
- lua_pop(L,1); // narg
+ lua_pop(L,1); // nret
}
- ret = FillFarMacroCall(L,narg);
- lua_pop(L,narg);
- return ret;
+ HANDLE hndl = FillFarMacroCall(L,nret);
+ lua_pop(L,nret);
+ return hndl;
}
}
else
diff --git a/plugins/luamacro/luafar/lf_service.c b/plugins/luamacro/luafar/lf_service.c
index f582b0ef8..34ecb60e2 100644
--- a/plugins/luamacro/luafar/lf_service.c
+++ b/plugins/luamacro/luafar/lf_service.c
@@ -1024,7 +1024,7 @@ static void FillKeyBarTitles(lua_State *L, int src_pos, struct KeyBarTitles *kbt
}
kbt->Labels[i].Key.VirtualKeyCode = GetOptIntFromTable(L, "VirtualKeyCode", 0);
- kbt->Labels[i].Key.ControlKeyState = CAST(DWORD,CheckFlagsFromTable(L, -1, "ControlKeyState"));
+ kbt->Labels[i].Key.ControlKeyState = (DWORD) CheckFlagsFromTable(L, -1, "ControlKeyState");
//-----------------------------------------------------------------------
lua_getfield(L, -1, "Text");
kbt->Labels[i].Text = StoreTempString(L, store_pos);
@@ -1283,7 +1283,7 @@ static int FillEditorSelect(lua_State *L, int pos_table, struct EditorSelect *es
{
int success;
lua_getfield(L, pos_table, "BlockType");
- es->BlockType = CAST(int, get_env_flag(L, -1, &success));
+ es->BlockType = (int) get_env_flag(L, -1, &success);
if (!success)
{
@@ -1311,7 +1311,7 @@ static int editor_Select(lua_State *L)
success = FillEditorSelect(L, 2, &es);
else
{
- es.BlockType = CAST(int, check_env_flag(L, 2));
+ es.BlockType = (int) check_env_flag(L, 2);
es.BlockStartLine = luaL_optinteger(L, 3, 0) - 1;
es.BlockStartPos = luaL_optinteger(L, 4, 0) - 1;
es.BlockWidth = luaL_optinteger(L, 5, -1);
@@ -1427,9 +1427,9 @@ int GetFarColor(lua_State *L, int pos, struct FarColor* Color)
{
lua_pushvalue(L, pos);
Color->Flags = CheckFlagsFromTable(L, -1, "Flags");
- Color->Foreground.ForegroundColor = CAST(COLORREF, GetOptNumFromTable(L, "ForegroundColor", 0));
- Color->Background.BackgroundColor = CAST(COLORREF, GetOptNumFromTable(L, "BackgroundColor", 0));
- Color->Underline.UnderlineColor = CAST(COLORREF, GetOptNumFromTable(L, "UnderlineColor", 0));
+ Color->Foreground.ForegroundColor = (COLORREF) GetOptNumFromTable(L, "ForegroundColor", 0);
+ Color->Background.BackgroundColor = (COLORREF) GetOptNumFromTable(L, "BackgroundColor", 0);
+ Color->Underline.UnderlineColor = (COLORREF) GetOptNumFromTable(L, "UnderlineColor", 0);
Color->Reserved = 0;
lua_pop(L, 1);
return 1;
@@ -1459,7 +1459,7 @@ void PushFarColor(lua_State *L, const struct FarColor* Color)
static void GetOptGuid(lua_State *L, int pos, GUID* target, const GUID* source)
{
if (lua_type(L, pos) == LUA_TSTRING && lua_objlen(L, pos) >= sizeof(GUID))
- *target = *CAST(const GUID*, lua_tostring(L, pos));
+ *target = *(const GUID*) lua_tostring(L, pos);
else if (lua_isnoneornil(L, pos))
*target = *source;
else
@@ -1478,7 +1478,7 @@ static int editor_AddColor(lua_State *L)
ec.EndPos = luaL_checkinteger(L, 4) - 1;
ec.Flags = OptFlags(L, 5, 0);
luaL_argcheck(L, GetFarColor(L, 6, &ec.Color), 6, "table or number expected");
- ec.Priority = CAST(unsigned, luaL_optnumber(L, 7, EDITOR_COLOR_NORMAL_PRIORITY));
+ ec.Priority = (unsigned) luaL_optnumber(L, 7, EDITOR_COLOR_NORMAL_PRIORITY);
GetOptGuid(L, 8, &ec.Owner, pd->PluginId);
lua_pushboolean(L, pd->Info->EditorControl(EditorId, ECTL_ADDCOLOR, 0, &ec) != 0);
return 1;
@@ -1595,7 +1595,7 @@ void FillInputRecord(lua_State *L, int pos, INPUT_RECORD *ir)
memset(ir, 0, sizeof(INPUT_RECORD));
// determine event type
lua_getfield(L, pos, "EventType");
- ir->EventType = CAST(WORD, get_env_flag(L, -1, &success));
+ ir->EventType = (WORD) get_env_flag(L, -1, &success);
if (success)
{
if (ir->EventType == 0)
@@ -2345,7 +2345,7 @@ static int SetPanelIntegerProperty(lua_State *L, int command)
{
PSInfo *Info = GetPluginData(L)->Info;
HANDLE handle = OptHandle2(L);
- int param1 = CAST(int, check_env_flag(L,3));
+ int param1 = (int) check_env_flag(L,3);
lua_pushboolean(L, Info->PanelControl(handle, command, param1, 0) != 0);
return 1;
}
@@ -3115,7 +3115,7 @@ static int DoSendDlgMessage (lua_State *L, intptr_t Msg, int delta)
lua_settop(L, pos4); //many cases below rely on top==pos4
HANDLE hDlg = CheckDialogHandle(L, 1);
if (delta == 0)
- Msg = CAST(int, check_env_flag(L, 2));
+ Msg = (int) check_env_flag(L, 2);
// Param1
switch(Msg)
@@ -4782,7 +4782,7 @@ static int DoAdvControl (lua_State *L, int Command, int Delta)
lua_settop(L,pos3); /* for proper calling GetOptIntFromTable and the like */
if (Delta == 0)
- Command = CAST(int, check_env_flag(L, 1));
+ Command = (int) check_env_flag(L, 1);
switch(Command)
{
@@ -4800,7 +4800,7 @@ static int DoAdvControl (lua_State *L, int Command, int Delta)
break;
case ACTL_GETFARHWND:
- lua_pushlightuserdata(L, CAST(void*, Info->AdvControl(PluginId, Command, 0, NULL)));
+ lua_pushlightuserdata(L, (void*) Info->AdvControl(PluginId, Command, 0, NULL));
return 1;
case ACTL_SETCURRENTWINDOW:
@@ -4924,12 +4924,12 @@ static int DoAdvControl (lua_State *L, int Command, int Delta)
case WTYPE_DIALOG:
case WTYPE_VMENU:
case WTYPE_COMBOBOX:
- NewDialogData(L, Info, CAST(HANDLE, wi.Id), FALSE);
+ NewDialogData(L, Info, (HANDLE)wi.Id, FALSE);
lua_setfield(L, -2, "Id");
break;
default:
- PutIntToTable(L, "Id", CAST(int, wi.Id));
+ PutIntToTable(L, "Id", (int)wi.Id);
break;
}
@@ -5383,7 +5383,7 @@ static int far_CreateFileFilter(lua_State *L)
{
PSInfo *Info = GetPluginData(L)->Info;
HANDLE hHandle = (luaL_checkinteger(L,1) % 2) ? PANEL_ACTIVE:PANEL_PASSIVE;
- int filterType = CAST(int, check_env_flag(L,2));
+ int filterType = (int) check_env_flag(L,2);
HANDLE* pOutHandle = (HANDLE*)lua_newuserdata(L, sizeof(HANDLE));
if (Info->FileFilterControl(hHandle, FFCTL_CREATEFILEFILTER, filterType, pOutHandle))
@@ -5462,11 +5462,11 @@ static int filefilter_IsFileInFilter(lua_State *L)
static int plugin_load(lua_State *L, enum FAR_PLUGINS_CONTROL_COMMANDS command)
{
PSInfo *Info = GetPluginData(L)->Info;
- int param1 = CAST(int, check_env_flag(L, 1));
+ int param1 = (int) check_env_flag(L, 1);
void *param2 = check_utf8_string(L, 2, NULL);
intptr_t result = Info->PluginsControl(INVALID_HANDLE_VALUE, command, param1, param2);
- if (result) PushPluginHandle(L, CAST(HANDLE, result));
+ if (result) PushPluginHandle(L, (HANDLE)result);
else lua_pushnil(L);
return 1;
@@ -5486,7 +5486,7 @@ static int far_UnloadPlugin(lua_State *L)
static int far_FindPlugin(lua_State *L)
{
PSInfo *Info = GetPluginData(L)->Info;
- int param1 = CAST(int, check_env_flag(L, 1));
+ int param1 = (int) check_env_flag(L, 1);
void *param2 = NULL;
if (param1 == PFM_MODULENAME)
@@ -5494,7 +5494,7 @@ static int far_FindPlugin(lua_State *L)
else if (param1 == PFM_GUID)
{
size_t len;
- param2 = CAST(void*, luaL_checklstring(L, 2, &len));
+ param2 = (void*) luaL_checklstring(L, 2, &len);
if (len < sizeof(GUID)) param2 = NULL;
}
@@ -5505,7 +5505,7 @@ static int far_FindPlugin(lua_State *L)
if (handle)
{
- PushPluginHandle(L, CAST(HANDLE, handle));
+ PushPluginHandle(L, (HANDLE)handle);
return 1;
}
}
@@ -5524,7 +5524,7 @@ static void PutPluginMenuItemToTable(lua_State *L, const char* field, const stru
for (int i=0; i < (int) mi->Count; i++)
{
- lua_pushlstring(L, CAST(const char*, mi->Guids + i), sizeof(GUID));
+ lua_pushlstring(L, (const char*)(mi->Guids + i), sizeof(GUID));
lua_rawseti(L, -3, i+1);
push_utf8_string(L, mi->Strings[i], -1);
lua_rawseti(L, -2, i+1);
@@ -5881,10 +5881,10 @@ static int far_CreateSettings(lua_State *L)
return 1;
}
- ParamId = IsFarSettings? &FarGuid : CAST(const GUID*, strId);
+ ParamId = IsFarSettings? &FarGuid : (const GUID*)strId;
}
- int location = CAST(int, OptFlags(L, 2, PSL_ROAMING));
+ int location = (int) OptFlags(L, 2, PSL_ROAMING);
struct FarSettingsCreate fsc = { sizeof(fsc) };
fsc.Guid = *ParamId;
diff --git a/plugins/luamacro/luafar/lf_string.c b/plugins/luamacro/luafar/lf_string.c
index f97af2d64..7ad40a312 100644
--- a/plugins/luamacro/luafar/lf_string.c
+++ b/plugins/luamacro/luafar/lf_string.c
@@ -671,13 +671,13 @@ int ustring_GlobalMemoryStatus(lua_State *L)
lua_createtable(L, 0, 8);
PutNumToTable(L, "MemoryLoad", ms.dwMemoryLoad);
- PutNumToTable(L, "TotalPhys", CAST(double, ms.ullTotalPhys));
- PutNumToTable(L, "AvailPhys", CAST(double, ms.ullAvailPhys));
- PutNumToTable(L, "TotalPageFile", CAST(double, ms.ullTotalPageFile));
- PutNumToTable(L, "AvailPageFile", CAST(double, ms.ullAvailPageFile));
- PutNumToTable(L, "TotalVirtual", CAST(double, ms.ullTotalVirtual));
- PutNumToTable(L, "AvailVirtual", CAST(double, ms.ullAvailVirtual));
- PutNumToTable(L, "AvailExtendedVirtual", CAST(double, ms.ullAvailExtendedVirtual));
+ PutNumToTable(L, "TotalPhys", (double) ms.ullTotalPhys);
+ PutNumToTable(L, "AvailPhys", (double) ms.ullAvailPhys);
+ PutNumToTable(L, "TotalPageFile", (double) ms.ullTotalPageFile);
+ PutNumToTable(L, "AvailPageFile", (double) ms.ullAvailPageFile);
+ PutNumToTable(L, "TotalVirtual", (double) ms.ullTotalVirtual);
+ PutNumToTable(L, "AvailVirtual", (double) ms.ullAvailVirtual);
+ PutNumToTable(L, "AvailExtendedVirtual", (double) ms.ullAvailExtendedVirtual);
return 1;
}
diff --git a/plugins/luamacro/luafar/lf_string.h b/plugins/luamacro/luafar/lf_string.h
index 5417ca258..7bc8bb97b 100644
--- a/plugins/luamacro/luafar/lf_string.h
+++ b/plugins/luamacro/luafar/lf_string.h
@@ -9,7 +9,6 @@
#endif
#define ARRSIZE(buff) (sizeof(buff)/sizeof(buff[0]))
-#define CAST(tp,expr) ((tp)(expr))
#ifdef __cplusplus
extern "C" {
diff --git a/plugins/luamacro/luafar/lf_util.c b/plugins/luamacro/luafar/lf_util.c
index 8a5d13fb2..5a1f65db9 100644
--- a/plugins/luamacro/luafar/lf_util.c
+++ b/plugins/luamacro/luafar/lf_util.c
@@ -52,7 +52,7 @@ unsigned __int64 GetFileSizeFromTable(lua_State *L, const char *key)
FILETIME GetFileTimeFromTable(lua_State *L, const char *key)
{
FILETIME ft;
- INT64 tm = {0};
+ INT64 tm = 0;
int OK = 0;
lua_getfield(L, -1, key);
@@ -67,12 +67,12 @@ FILETIME GetFileTimeFromTable(lua_State *L, const char *key)
}
else
{
- OK = bit64_getvalue(L, -1, &tm);
+ OK = bit64_getvalue(L, -1, &tm);
}
if (OK)
{
- ft.dwHighDateTime = CAST(DWORD, (UINT64)tm >> 32);
- ft.dwLowDateTime = CAST(DWORD, tm & 0xFFFFFFFF);
+ ft.dwHighDateTime = (DWORD) ((UINT64)tm >> 32);
+ ft.dwLowDateTime = (DWORD) (tm & 0xFFFFFFFF);
}
else
ft.dwLowDateTime = ft.dwHighDateTime = 0;
@@ -88,7 +88,7 @@ void PutFileTimeToTable(lua_State *L, const char* key, FILETIME ft)
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
- PutNumToTable(L, key, CAST(double, li.QuadPart/10000)); // convert 100ns units to 1ms ones
+ PutNumToTable(L, key, (double) li.QuadPart/10000); // convert 100ns units to 1ms ones
}
else
{
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index 51d038e67..b4ac2cc6b 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 924
+#define PLUGIN_BUILD 925