|
| 03 Mar 2015 05:12 PM |
What I'm looking at doing is finding a way to determine the class of a variable and return whether it's a string, vector3, cframe, udim2, etc.
Is there any easy way to do this? |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:34 PM |
Yep. print(type(variable)) |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:36 PM |
| However, many of those are considered userdata values. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Mar 2015 05:36 PM |
Nope, type only gets the datatype, the class itself is not so easy.
local isVector3 = function(userdata) assert(type(userdata) == "userdata", "userdata expected, got " .. type(userdata)); return pcall(function() return userdata.isClose; end); end; |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:36 PM |
| However, many of those are considered userdata values |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:37 PM |
| agh floodcheck-double-post-glitch |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2015 05:42 PM |
If you were using MoonScript, it looks WAY cleaner and prettier than Lua. This is a function I wrote (Modified by eLunate) that I converted to MoonScript.
GetType = (Value) -> Type = type Value return Type if Type != "userdata" return "Instance" if pcall -> return Value.IsA return "CFrame" if pcall -> return Value.p return "Vector3" if pcall -> return Value.Z return "UDim2" if pcall -> return Value.X.Offset return "Vector2" if pcall -> return Value.X return "BrickColor" if pcall -> return Value.Color return "Color3" if pcall -> return Value.r return "Ray" if pcall -> return Value.ClosestPoint return "Region3int16" if pcall -> return Value.Min return "Region3" if pcall -> return Value.CFrame return "UDim" if pcall -> return Value.Scale return "Event" if pcall -> return Value.connect return "Connection" if pcall -> return Value.disconnect return "Unknown"
Unfortunately, I can't see any way it will ever look pretty in Lua. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
| |
|
|
| 03 Mar 2015 05:45 PM |
@hex Hmm? I'm not sure we've met, but it's been a while since I've been here.
And thanks @cnt. I suppose something like that will be my best bet, ahah. |
|
|
| Report Abuse |
|
|