summaryrefslogtreecommitdiff
path: root/script-beta/core/hover/class.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/core/hover/class.lua')
-rw-r--r--script-beta/core/hover/class.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/script-beta/core/hover/class.lua b/script-beta/core/hover/class.lua
new file mode 100644
index 00000000..6d28ee8a
--- /dev/null
+++ b/script-beta/core/hover/class.lua
@@ -0,0 +1,27 @@
+local vm = require 'vm'
+
+local function getClass(source, deep)
+ if deep > 3 then
+ return nil
+ end
+ local class = vm.eachField(source, function (info)
+ if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
+ if info.value and info.value.type == 'string' then
+ return info.value[1]
+ end
+ end
+ end)
+ if class then
+ return class
+ end
+ return vm.eachMeta(source, function (meta)
+ local cl = getClass(meta, deep + 1)
+ if cl then
+ return cl
+ end
+ end)
+end
+
+return function (source)
+ return getClass(source, 1)
+end