Skip to content

Commit

Permalink
LuaFAR: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Jun 17, 2024
1 parent b5abe8f commit c68ffd1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 50 deletions.
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 3, 0, 0, 842 },
Version = { 3, 0, 0, 843 },
MinFarVersion = { 3, 0, 0, 6327 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
4 changes: 4 additions & 0 deletions plugins/luamacro/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
shmuel 2024-06-17 09:32:42+03:00 - build 843

1. LuaFAR: refactoring

shmuel 2024-06-12 01:00:14+03:00 - build 842

1. LuaFAR: refactoring
Expand Down
80 changes: 36 additions & 44 deletions plugins/luamacro/luafar/exported.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,10 @@ void UpdateFileSelection(lua_State* L, struct PluginPanelItem *PanelItem,

intptr_t LF_GetFiles(lua_State* L, struct GetFilesInfo *Info)
{
intptr_t ret = 0;

if (GetExportFunction(L, "GetFiles")) //+1: Func
{
intptr_t ret;
Info->StructSize = sizeof(*Info);
PushPanelItems(L, Info->PanelItem, Info->ItemsNumber, 0); //+2: Func,Item
lua_insert(L,-2); //+2: Item,Func
Expand All @@ -417,9 +418,8 @@ intptr_t LF_GetFiles(lua_State* L, struct GetFilesInfo *Info)
lua_pushboolean(L, Info->Move);
push_utf8_string(L, Info->DestPath, -1);
bit64_push(L, Info->OpMode); //+8: Item,Func,Pair,Item,Move,Dest,OpMode
ret = pcall_msg(L, 6, 2); //+3: Item,Res,Dest

if (ret == 0)
if (!pcall_msg(L, 6, 2)) //+3: Item,Res,Dest
{
if (lua_isstring(L,-1))
{
Expand All @@ -432,13 +432,10 @@ intptr_t LF_GetFiles(lua_State* L, struct GetFilesInfo *Info)
ret = lua_tointeger(L,-1);
lua_pop(L,1); //+1: Item
UpdateFileSelection(L, Info->PanelItem, Info->ItemsNumber);
return lua_pop(L,1), ret;
}

return lua_pop(L,1), 0;
lua_pop(L,1); //+0
}

return 0;
return ret;
}
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -1140,80 +1137,76 @@ intptr_t LF_ProcessPanelEvent(lua_State* L, const struct ProcessPanelEventInfo *

intptr_t LF_ProcessHostFile(lua_State* L, const struct ProcessHostFileInfo *Info)
{
intptr_t ret = 0;

if (GetExportFunction(L, "ProcessHostFile")) //+1: Func
{
intptr_t ret;
PushPanelItems(L, Info->PanelItem, Info->ItemsNumber, 0); //+2: Func,Item
lua_insert(L,-2); //+2: Item,Func
PushPluginPair(L, Info->hPanel); //+4: Item,Func,Pair
lua_pushvalue(L,-4); //+5: Item,Func,Pair,Item
bit64_push(L, Info->OpMode); //+6: Item,Func,Pair,Item,OpMode
ret = pcall_msg(L, 4, 1); //+2: Item,Res

if (ret == 0)
if (!pcall_msg(L, 4, 1)) //+2: Item,Res
{
ret = lua_toboolean(L,-1);
lua_pop(L,1); //+1: Item
UpdateFileSelection(L, Info->PanelItem, Info->ItemsNumber);
return lua_pop(L,1), ret;
}

lua_pop(L,1);
lua_pop(L,1); //+0
}

return FALSE;
return ret;
}

intptr_t LF_ProcessPanelInput(lua_State* L, const struct ProcessPanelInputInfo *Info)
{
intptr_t ret = 0;

if (GetExportFunction(L, "ProcessPanelInput")) //+1: Func
{
PushPluginPair(L, Info->hPanel); //+3: Func,Pair
PushInputRecord(L, &Info->Rec); //+4

if (pcall_msg(L, 3, 1) == 0) //+1: Res
if (!pcall_msg(L, 3, 1)) //+1: Res
{
intptr_t ret = lua_toboolean(L,-1);
return lua_pop(L,1), ret;
ret = lua_toboolean(L,-1);
lua_pop(L,1);
}
}

return FALSE;
return ret;
}

intptr_t LF_PutFiles(lua_State* L, const struct PutFilesInfo *Info)
{
intptr_t ret = 0;

if (GetExportFunction(L, "PutFiles")) //+1: Func
{
intptr_t ret;
PushPanelItems(L, Info->PanelItem, Info->ItemsNumber, 0); //+2: Func,Items
lua_insert(L,-2); //+2: Items,Func
PushPluginPair(L, Info->hPanel); //+4: Items,Func,Pair
lua_pushvalue(L,-4); //+5: Items,Func,Pair,Items
lua_pushboolean(L, Info->Move); //+6: Items,Func,Pair,Items,Move
push_utf8_string(L, Info->SrcPath, -1); //+7: Items,Func,Pair,Items,Move,SrcPath
bit64_push(L, Info->OpMode); //+8: Items,Func,Pair,Items,Move,SrcPath,OpMode
ret = pcall_msg(L, 6, 1); //+2: Items,Res

if (ret == 0)
if (!pcall_msg(L, 6, 1)) //+2: Items,Res
{
ret = lua_tointeger(L,-1);
lua_pop(L,1); //+1: Items
UpdateFileSelection(L, Info->PanelItem, Info->ItemsNumber);
return lua_pop(L,1), ret;
}

lua_pop(L,1);
lua_pop(L,1); //+0
}

return 0;
return ret;
}

intptr_t LF_SetDirectory(lua_State* L, const struct SetDirectoryInfo *Info)
{
intptr_t ret = 0;

if (GetExportFunction(L, "SetDirectory")) //+1: Func
{
intptr_t ret;
PushPluginPair(L, Info->hPanel); //+3: Func,Pair
push_utf8_string(L, Info->Dir, -1); //+4: Func,Pair,Dir
bit64_push(L, Info->OpMode); //+5: Func,Pair,Dir,OpMode
Expand All @@ -1226,35 +1219,33 @@ intptr_t LF_SetDirectory(lua_State* L, const struct SetDirectoryInfo *Info)
{
lua_pushnil(L);
}
ret = pcall_msg(L, 5, 1); //+1: Res

if (ret == 0)
if (!pcall_msg(L, 5, 1)) //+1: Res
{
ret = lua_toboolean(L,-1);
return lua_pop(L,1), ret;
lua_pop(L,1);
}
}

return FALSE;
return ret;
}

intptr_t LF_SetFindList(lua_State* L, const struct SetFindListInfo *Info)
{
intptr_t ret = 0;

if (GetExportFunction(L, "SetFindList")) //+1: Func
{
intptr_t ret;
PushPluginPair(L, Info->hPanel); //+3: Func,Pair
PushPanelItems(L, Info->PanelItem, Info->ItemsNumber, 0); //+4: Func,Pair,Items
ret = pcall_msg(L, 3, 1); //+1: Res

if (ret == 0)
if (!pcall_msg(L, 3, 1)) //+1: Res
{
ret = lua_toboolean(L,-1);
return lua_pop(L,1), ret;
lua_pop(L,1);
}
}

return FALSE;
return ret;
}

void LF_ExitFAR(lua_State* L, const struct ExitInfo *Info)
Expand Down Expand Up @@ -1326,18 +1317,19 @@ void LF_GetPluginInfo(lua_State* L, struct PluginInfo *PI)

intptr_t LF_ProcessEditorInput(lua_State* L, const struct ProcessEditorInputInfo *Info)
{
intptr_t ret = 0;

if (!GetExportFunction(L, "ProcessEditorInput")) //+1: Func
return 0;

PushInputRecord(L, &Info->Rec);

if (pcall_msg(L, 1, 1) == 0) //+1: Res
{
intptr_t ret = lua_toboolean(L,-1);
return lua_pop(L,1), ret;
ret = lua_toboolean(L,-1);
lua_pop(L,1);
}

return 0;
return ret;
}

intptr_t LF_ProcessEditorEvent(lua_State* L, const struct ProcessEditorEventInfo *Info)
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luafar/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 842
#define PLUGIN_BUILD 843
6 changes: 2 additions & 4 deletions plugins/luamacro/luafar/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,13 +939,11 @@ static int win_SetFileTimes(lua_State *L)
p_access = &t_access;
if (ExtractFileTime(L, "LastWriteTime", &t_write, hFile))
p_write = &t_write;
lua_pushboolean(L, (p_create||p_access||p_write) && SetFileTime(hFile,p_create,p_access,p_write));
res = (p_create||p_access||p_write) && SetFileTime(hFile,p_create,p_access,p_write);
CloseHandle(hFile);
res = 1;
}
}
if (res == 0)
lua_pushboolean(L, 0);
lua_pushboolean(L, res);
return 1;
}

Expand Down

0 comments on commit c68ffd1

Please sign in to comment.