mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-07 18:52:30 +00:00
20887b1ccb
Trying `rc.print()` causes redirection to native global Lua `print()`, which prints to stdout. I don't see any proc of shor-circuiting `autocall_config` with global environment `_G`.
44 lines
1.3 KiB
Lua
44 lines
1.3 KiB
Lua
-- The "rtorrent" table is passed in by the C++ code, modify and
|
|
-- return it for loading.
|
|
local args = {...}
|
|
local rtorrent = args[1]
|
|
|
|
-- Autocall
|
|
-- Allows syntax like `rtorrent.autocall.system.hostname()`
|
|
local mt = {}
|
|
function mt.__call (t, ...)
|
|
name = table.concat(rawget(t, "__namestack"), ".")
|
|
success, ret = pcall(rtorrent.call, name, ...)
|
|
if not success then error(name..": "..ret, 2) end
|
|
return ret
|
|
end
|
|
function mt.__index (t, key)
|
|
ns = rawget(t, "__namestack") or {}
|
|
table.insert(ns, key)
|
|
return setmetatable({__namestack=ns}, mt)
|
|
end
|
|
rtorrent["autocall"] = setmetatable({}, mt)
|
|
|
|
-- Autocall-config
|
|
-- 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 = {}
|
|
function mt.__call (t, ...)
|
|
name = table.concat(rawget(t, "__namestack"), ".")
|
|
success, ret = pcall(rtorrent.call, name, "", ...)
|
|
if not success then error(name..": "..ret, 2) end
|
|
return ret
|
|
end
|
|
function mt.__index (t, key)
|
|
ns = rawget(t, "__namestack") or {}
|
|
table.insert(ns, key)
|
|
return setmetatable({__namestack=ns}, mt)
|
|
end
|
|
function mt.__newindex (t, key, value)
|
|
t[key].set(value)
|
|
end
|
|
rtorrent["autocall_config"] = setmetatable({}, mt)
|
|
|
|
return rtorrent
|