Skip to content

Commit

Permalink
Far.GetConfig() is implemented entirely in Far.exe (was: Far + LuaMacro)
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Nov 21, 2023
1 parent a413ebc commit 02fd17c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
shmuel 2023-11-21 20:32:53+02:00 - build 6214

1. Far.GetConfig() is implemented entirely in Far.exe (was: Far + LuaMacro).

--------------------------------------------------------------------------------
drkns 2023-11-19 21:55:10+00:00 - build 6213

Expand Down
47 changes: 28 additions & 19 deletions far/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3515,43 +3515,52 @@ void FarMacroApi::farcfggetFunc() const
return option? PassValue(option->toString()) : PassBoolean(false);
}

// V=Far.GetConfig(Key,Name)
// V=Far.GetConfig(Key.Name)
void FarMacroApi::fargetconfigFunc() const
{
if (mData->Count >= 2 && mData->Values[0].Type==FMVT_STRING && mData->Values[1].Type==FMVT_STRING)
const wchar_t *Keyname = (mData->Count >= 1 && mData->Values[0].Type==FMVT_STRING) ?
mData->Values[0].String : L"";

auto Dot = wcsrchr(Keyname, L'.');
if (Dot)
{
if (const auto option = Global->Opt->GetConfigValue(mData->Values[0].String, mData->Values[1].String))
string Key(Keyname, Dot - Keyname);

if (const auto option = Global->Opt->GetConfigValue(Key.c_str(), Dot+1))
{
if (const auto Opt = dynamic_cast<const BoolOption*>(option))
{
PassValue(1);
PassBoolean(Opt->Get());
return;
PassValue(L"boolean");
}

if (const auto Opt = dynamic_cast<const Bool3Option*>(option))
else if (const auto Opt = dynamic_cast<const Bool3Option*>(option))
{
PassValue(2);
PassValue(Opt->Get());
return;
}
auto Val = Opt->Get();
if (Val == 0 || Val == 1)
PassBoolean(Val == 1);
else
PassValue(L"other");

if (const auto Opt = dynamic_cast<const IntOption*>(option))
PassValue(L"3-state");
}
else if (const auto Opt = dynamic_cast<const IntOption*>(option))
{
PassValue(3);
PassValue(Opt->Get());
return;
PassValue(L"integer");
}

if (const auto Opt = dynamic_cast<const StringOption*>(option))
else if (const auto Opt = dynamic_cast<const StringOption*>(option))
{
PassValue(4);
PassValue(Opt->Get());
return;
PassValue(L"string");
}
else
PassError(L"unknown option type");
}
else
PassError(L"setting doesn't exist");
}
PassBoolean(false);
else
PassError(L"invalid argument #1");
}

// V=Dlg->GetValue([Pos[,InfoID]])
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6213
6214
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, 788 },
Version = { 3, 0, 0, 789 },
MinFarVersion = { 3, 0, 0, 5171 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
19 changes: 1 addition & 18 deletions plugins/luamacro/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local Shared = ...
local checkarg, utils, yieldcall = Shared.checkarg, Shared.utils, Shared.yieldcall

local MCODE_F_USERMENU = 0x80C66
local MCODE_F_FAR_GETCONFIG = 0x80C69
local F=far.Flags
local band,bor = bit64.band,bit64.bor
local MacroCallFar = Shared.MacroCallFar
Expand Down Expand Up @@ -292,28 +291,12 @@ SetProperties(Menu, {
Far = {
Cfg_Get = function(...) return MacroCallFar(0x80C58, ...) end,
DisableHistory = function(...) return Shared.keymacro.DisableHistory(...) end,
GetConfig = function(...) return MacroCallFar(0x80C69, ...) end,
KbdLayout = function(...) return MacroCallFar(0x80C49, ...) end,
KeyBar_Show = function(...) return MacroCallFar(0x80C4B, ...) end,
Window_Scroll = function(...) return MacroCallFar(0x80C4A, ...) end,
}

function Far.GetConfig (keyname)
checkarg(keyname, 1, "string")
local key, name = keyname:match("^(.+)%.([^.]+)$")
if not key then
error("invalid format of arg. #1", 2)
end
local tp,val = MacroCallFar(MCODE_F_FAR_GETCONFIG, key, name)
if not tp then
error("cannot get setting '"..keyname.."'", 2)
end
tp = ({"boolean","3-state","integer","string"})[tp]
if tp == "3-state" then
if val==0 or val==1 then val=(val==1) else val="other" end
end
return val,tp
end

SetProperties(Far, {
FullScreen = function() return MacroCallFar(0x80411) end,
Height = function() return MacroCallFar(0x80801) end,
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 2023-11-21 20:39:31+02:00 - build 789

1. Far.GetConfig() is implemented entirely in Far.exe (was: Far + LuaMacro).

shmuel 2023-11-16 19:03:27+02:00 - build 788

1. LuaFAR: add functions far.CheckMask, far.CmpName, far.CmpNameList, far.GenerateName.
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 788
#define PLUGIN_BUILD 789

0 comments on commit 02fd17c

Please sign in to comment.