feat(lua): Add autocall_config assignment semantic

This commit is contained in:
PRESFIL
2025-06-11 18:34:26 +00:00
committed by Jari Sundell
parent f8ec1ca95e
commit 3bd111e498
+8 -3
View File
@@ -1,4 +1,4 @@
-- the "rtorrent" table is passed in by the C++ code, modify and -- The "rtorrent" table is passed in by the C++ code, modify and
-- return it for loading. -- return it for loading.
local args = {...} local args = {...}
local rtorrent = args[1] local rtorrent = args[1]
@@ -19,8 +19,10 @@ function mt.__index (t, key)
end end
rtorrent["autocall"] = setmetatable({}, mt) rtorrent["autocall"] = setmetatable({}, mt)
-- Autocall-config Same as autocall, but passes an empty first target -- Autocall-config
-- implicitly, for syntax like `rtorrent.autocall_config.session.directory.set("/tmp/")` -- Same as autocall, but passes an empty first target implicitly, for syntax
-- like `rtorrent.autocall_config.session.directory.set("/tmp/")` or
-- like `rtorrent.autocall_config.session.directory = "/tmp/"`
local mt = {} local mt = {}
function mt.__call (t, ...) function mt.__call (t, ...)
name = table.concat(rawget(t, "__namestack"), ".") name = table.concat(rawget(t, "__namestack"), ".")
@@ -37,6 +39,9 @@ function mt.__index (t, key)
table.insert(ns, key) table.insert(ns, key)
return setmetatable({__namestack=ns}, mt) return setmetatable({__namestack=ns}, mt)
end end
function mt.__newindex (t, key, value)
t[key].set(value)
end
rtorrent["autocall_config"] = setmetatable({}, mt) rtorrent["autocall_config"] = setmetatable({}, mt)
return rtorrent return rtorrent