diff options
Diffstat (limited to 'server/src/core/find_lib.lua')
-rw-r--r-- | server/src/core/find_lib.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/server/src/core/find_lib.lua b/server/src/core/find_lib.lua new file mode 100644 index 00000000..c4d5bff3 --- /dev/null +++ b/server/src/core/find_lib.lua @@ -0,0 +1,47 @@ +local function findLib(var) + if var.type ~= 'local' and var.type ~= 'field' then + return nil + end + local value = var.value + local lib = value.lib + if not lib then + return nil + end + if lib.parent then + local res + for _, parent in ipairs(lib.parent) do + if parent.type == value.parentType then + res = parent + end + end + if not res then + res = lib.parent[1] + end + if res.type == 'object' then + local fullKey = ('*%s:%s'):format(res.nick or res.name, lib.name) + return lib, fullKey, true + else + local fullKey = ('%s.%s'):format(res.nick or res.name, lib.name) + return lib, fullKey, false + end + else + local res + if not lib.source then + return lib, lib.nick or lib.name, false + end + for _, source in ipairs(lib.source) do + if source.type == value.parentType then + res = source + end + end + if not res then + return lib, lib.nick or lib.name, false + end + return lib, res.nick or res.name or lib.nick or lib.name, false + end +end + +return function (var) + local lib, fullKey, oo = findLib(var) + return lib, fullKey, oo +end |