[FarGroup/FarManager] master: LuaFAR: add win.GetEnvironmentStrings function (22468c661)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Mar 8, 2026, 1:30:58 PMMar 8
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/22468c66160137300341841dddeb9ba93a27acc4

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

commit 22468c66160137300341841dddeb9ba93a27acc4
Author: Shmuel Zeigerman <solo...@gmail.com>
Date: Sun Mar 8 19:14:58 2026 +0200

LuaFAR: add win.GetEnvironmentStrings function


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

22468c66160137300341841dddeb9ba93a27acc4
enc/enc_lua/luafar_manual.tsi | 26 ++++++++++++++++++++++++++
plugins/luamacro/_globalinfo.lua | 2 +-
plugins/luamacro/changelog | 4 ++++
plugins/luamacro/luafar/lf_version.h | 2 +-
plugins/luamacro/luafar/lf_win.c | 28 +++++++++++++++++++++++++---
5 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/enc/enc_lua/luafar_manual.tsi b/enc/enc_lua/luafar_manual.tsi
index f1d7b0890..94aa511a2 100644
--- a/enc/enc_lua/luafar_manual.tsi
+++ b/enc/enc_lua/luafar_manual.tsi
@@ -11138,6 +11138,32 @@ nm=win.GetEnv
</article>
</node>
<node>
+id=599
+lv=3
+dt=Text
+nm=win.GetEnvironmentStrings
+ctime=3982158263
+mtime=3982158716
+<article>
+#_result = win.GetEnvironmentStrings()
+#_
+#_**Parameters:**
+#_ none
+#_
+#_**Returns:**
+#_ result: table
+#_
+#_**Description:**
+#_ Returns a table.
+#_ All keys and values in the table are strings.
+#_ E.g.: for the "SystemDrive" key, the value is "C:".
+#_
+#_**Windows API used:**
+#_ GetEnvironmentStringsW
+#_
+</article>
+</node>
+<node>
id=522
lv=3
dt=Text
diff --git a/plugins/luamacro/_globalinfo.lua b/plugins/luamacro/_globalinfo.lua
index e2edea063..fb19a251d 100644
--- a/plugins/luamacro/_globalinfo.lua
+++ b/plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
- Version = { 3, 0, 0, 915 },
+ Version = { 3, 0, 0, 916 },
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 8167e02f1..0eaca545b 100644
--- a/plugins/luamacro/changelog
+++ b/plugins/luamacro/changelog
@@ -1,3 +1,7 @@
+shmuel 2026-03-08 19:13:10+02:00 - build 916
+
+1. LuaFAR: add win.GetEnvironmentStrings function.
+
shmuel 2026-02-06 18:39:22+02:00 - build 915

1. LuaMacro: fix ShiftF9 handling in Plugins/Disks menus.
diff --git a/plugins/luamacro/luafar/lf_version.h b/plugins/luamacro/luafar/lf_version.h
index b6c7bfd1c..6f556ea55 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 915
+#define PLUGIN_BUILD 916
diff --git a/plugins/luamacro/luafar/lf_win.c b/plugins/luamacro/luafar/lf_win.c
index 4bb4d6865..5a045b29a 100644
--- a/plugins/luamacro/luafar/lf_win.c
+++ b/plugins/luamacro/luafar/lf_win.c
@@ -153,7 +153,7 @@ static int win_GetRegKey(lua_State *L)
{
HKEY hKey;
DWORD datatype, datasize;
- char *data;
+ void *data;
LONG ret;
HKEY hRoot = CheckHKey(L, 1);
wchar_t* Key = (wchar_t*)check_utf8_string(L, 2, NULL);
@@ -169,7 +169,7 @@ static int win_GetRegKey(lua_State *L)
}

RegQueryValueExW(hKey, ValueName, NULL, &datatype, NULL, &datasize);
- data = (char*) malloc(datasize);
+ data = malloc(datasize);
ret = RegQueryValueExW(hKey, ValueName, NULL, &datatype, (BYTE*)data, &datasize);
RegCloseKey(hKey);

@@ -183,7 +183,7 @@ static int win_GetRegKey(lua_State *L)
switch(datatype)
{
case REG_BINARY:
- lua_pushlstring(L, data, datasize);
+ lua_pushlstring(L, (char*)data, datasize);
lua_pushstring(L, "binary");
break;
case REG_DWORD:
@@ -1014,6 +1014,27 @@ static int win_JoinPath(lua_State *L)
return 1;
}

+static int win_GetEnvironmentStrings(lua_State *L)
+{
+ wchar_t *buf = GetEnvironmentStringsW();
+ lua_newtable(L);
+ for (wchar_t *ptr=buf; ;) {
+ size_t len = wcslen(ptr);
+ if (len) {
+ wchar_t *eq = wcschr(ptr, L'=');
+ if (eq && eq != ptr) {
+ push_utf8_string(L, ptr, eq - ptr);
+ push_utf8_string(L, eq + 1, -1);
+ lua_rawset(L, -3);
+ }
+ ptr += len + 1;
+ }
+ else break;
+ }
+ FreeEnvironmentStringsW(buf);
+ return 1;
+}
+
#define PAIR(prefix,txt) {#txt, prefix ## _ ## txt}

const luaL_Reg win_funcs[] =
@@ -1032,6 +1053,7 @@ const luaL_Reg win_funcs[] =
PAIR( win, FileTimeToSystemTime),
PAIR( win, GetConsoleScreenBufferInfo),
PAIR( win, GetEnv),
+ PAIR( win, GetEnvironmentStrings),
PAIR( win, GetFileInfo),
PAIR( win, GetFileTimes),
PAIR( win, GetLocalTime),


Reply all
Reply to author
Forward
0 new messages