Valkyrie
Valkyrie

Reputation: 1

Lua function: 'type', recreated in Luau

I need help with CheckType. How can I make it check: Enum. (Enum is a userdata, but it doesn't work; Enum is in Luau.) (This is me asking for help in the Language: Luau (Roblox))

When I test Enum, it gives me a string because it turns into the string: "Enums"

Doing type(Enum) -- Output: userdata.

I want my own code to be as accurate as possible to the original type function.

I also need help with a better newproxy, it just doesn't feel the same way as the original Lua 5.1 one.

local proxy = {}

newproxy = newproxy or function(bool)
   if bool then
      setmetatable(proxy, {
                      __index = {}
      })
   end
   return proxy
end

function CheckType(a)
   local s, e = pcall(function()
         return a.Archivable and (string.match(tostring(a), "^(.-):") == nil)
   end)

   local _nil = ((a == nil) and "nil")
   local Instance = ((s and e ~= nil) and "Instance")
   local userdata = ((a == newproxy(true)) and "userdata")  
   local coffee = (string.match(tostring(a), "^(.-):"))
   local boolean = (((a == true) and "boolean" or (a == false) and "boolean"))  
   local number = (((tonumber(a) ~= nil and tostring(a) ~= nil) and "number"))
   local string = ((((not tostring(a) == _nil) and (not tonumber(a)))) and "string")
   local unknown = "Unknown"

   return Instance or userdata or coffee or boolean or number or string or unknown
end

print(CheckType(Enum)) -- Output: userdata (But it Outputs: string)

Upvotes: 0

Views: 138

Answers (0)

Related Questions