Модуль:JsonPaths: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показана 1 промежуточная версия этого же участника) | |||
| Строка 39: | Строка 39: | ||
end | end | ||
function p.project( | local function isFrameLike(value) | ||
return | return type(value) == "table" and type(value.getParent) == "function" | ||
end | |||
local function getPathFromCall(call) | |||
if type(call) == "string" then | |||
return resolvePath(call) | |||
end | |||
if isFrameLike(call) then | |||
local args = getArgs(call) | |||
return resolvePath(args.path or args[1]) | |||
end | |||
if type(call) == "table" then | |||
return resolvePath(call.path or call[1]) | |||
end | |||
return resolvePath("") | |||
end | |||
function p.project(call) | |||
return getPathFromCall(call) | |||
end | |||
function p.prefix(call) | |||
local path = getPathFromCall(call) | |||
if path ~= "" then | |||
return path .. ":" | |||
end | |||
return "" | |||
end | end | ||
| Строка 89: | Строка 120: | ||
function p.has(id, path) | function p.has(id, path) | ||
if isFrameLike(id) then | |||
local args = getArgs(id) | |||
id = args[1] or args.id | |||
path = args.path or args[2] | |||
end | |||
id = trim(id) | id = trim(id) | ||
if id == "" then | if id == "" then | ||
| Строка 108: | Строка 145: | ||
function p.get(rel, path) | function p.get(rel, path) | ||
if isFrameLike(rel) then | |||
local args = getArgs(rel) | |||
rel = args[1] or args.rel | |||
path = args.path or args[2] | |||
end | |||
rel = trim(rel) | rel = trim(rel) | ||
if rel == "" then | if rel == "" then | ||
| Строка 123: | Строка 166: | ||
end | end | ||
function p.git( | function p.git(call) | ||
local path = getPathFromCall(call) | |||
local path = | |||
if path == "Goob" then | if path == "Goob" then | ||