Browse Source

Object:type;

bjorn 1 year ago
parent
commit
8ada5976dc
2 changed files with 38 additions and 0 deletions
  1. 18 0
      api/init.lua
  2. 20 0
      api/lovr/Object/type.lua

+ 18 - 0
api/init.lua

@@ -963,6 +963,24 @@ return {
                   returns = {}
                 }
               }
+            },
+            {
+              name = "type",
+              summary = "Get the type name of the object.",
+              description = "Returns the name of the object's type as a string.",
+              key = "Object:type",
+              module = "lovr",
+              examples = {
+                {
+                  code = "function isTexture(obj)\n  return type(obj) == 'userdata' and obj:type() == 'Texture'\nend"
+                }
+              },
+              variants = {
+                arguments = {},
+                returns = {
+                  "type"
+                }
+              }
             }
           },
           notes = "Note that the functions here don't apply to any vector objects, see `Vectors`."

+ 20 - 0
api/lovr/Object/type.lua

@@ -0,0 +1,20 @@
+return {
+  summary = 'Get the type name of the object.',
+  description = 'Returns the name of the object\'s type as a string.',
+  arguments = {},
+  returns = {
+    type = {
+      type = 'string',
+      description = 'The type of the object.'
+    }
+  },
+  variants = {
+    arguments = {},
+    returns = { 'type' }
+  },
+  example = [[
+    function isTexture(obj)
+      return type(obj) == 'userdata' and obj:type() == 'Texture'
+    end
+  ]]
+}