2019-12-25 16:29:58 +11:00
|
|
|
local vcomponent = require "vcomponent"
|
2023-09-18 08:25:14 +10:00
|
|
|
local r2r = require "r2r"
|
2019-12-25 16:29:58 +11:00
|
|
|
local tA = {...}
|
|
|
|
local host, ctype, addr = tA[1], tA[2], tA[3]
|
|
|
|
|
|
|
|
if #tA < 3 then
|
|
|
|
print("Usage: importcomponent <host> <component type> <component address>")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local saddr = addr:gsub("%-","%%-")
|
|
|
|
|
|
|
|
if addr:len() < 36 then
|
2023-09-18 08:25:14 +10:00
|
|
|
local flist = r2r.call(host,"list")
|
2019-12-25 16:29:58 +11:00
|
|
|
for k,v in pairs(flist) do
|
|
|
|
faddr = v:match(ctype.."_("..saddr..".*)_") or faddr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print(faddr)
|
|
|
|
saddr = (faddr or addr):gsub("%-","%%-")
|
2023-09-18 08:25:14 +10:00
|
|
|
local px = r2r.proxy(host,ctype.."_"..saddr..".*_")
|
2019-12-25 16:29:58 +11:00
|
|
|
local mc = 0
|
|
|
|
for k,v in pairs(px) do
|
|
|
|
mc = mc + 1
|
|
|
|
end
|
|
|
|
if mc < 1 then
|
|
|
|
error("no such remote component: "..addr)
|
|
|
|
end
|
|
|
|
vcomponent.register(faddr or addr, ctype, px)
|