User:ArceusInator/Sandbox: Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>ArceusInator will finish |
>ArceusInator working |
||
Line 1: | Line 1: | ||
Some useful functions... | Some useful functions... | ||
<pre> | <pre> | ||
--- shared:RealType( v ) | |||
function shared:RealType(v) | function shared:RealType(v) | ||
local libraries = {Axes, BrickColor, CFrame, Color3, Faces} | local libraries = {Axes, BrickColor, CFrame, Color3, Faces, Ray, Region3, UDim, UDim2, Vector2, Vector3, Instance, math, table, string, coroutine} | ||
if type(v) == "userdata" then | if type(v) == "userdata" then | ||
Line 26: | Line 29: | ||
elseif Vector2.new(v.X, v.Y) == v then | elseif Vector2.new(v.X, v.Y) == v then | ||
return "vector2" | return "vector2" | ||
elseif pcall(function() xo = | elseif pcall(function() xo = v.X.Offset end) then | ||
return "universaldimension2" | |||
end | end | ||
elseif pcall(function() r = v.r end) then | elseif pcall(function() r = v.r end) then | ||
Line 46: | Line 50: | ||
elseif pcall(function() cf = v.CFrame end) then | elseif pcall(function() cf = v.CFrame end) then | ||
return "region3" | return "region3" | ||
elseif pcall(function() o = v.Offset end) then | |||
return "universaldimension" | |||
end | |||
end | |||
return type(v) | |||
end | |||
--- shared:ToupleToTable( ... ) | |||
function shared:ToupleToTable(...) | |||
assert(loadstring("return {" .. ... .. "}"))() | |||
end | |||
function r(v) -- for me | |||
return shared:RealType(v) | |||
end | |||
--- math.curt(v) | |||
function math.curt(v) | |||
if not r(v) == "number" then | |||
error("Number expected",1) |
Revision as of 20:22, 30 March 2011
Some useful functions...
--- shared:RealType( v ) function shared:RealType(v) local libraries = {Axes, BrickColor, CFrame, Color3, Faces, Ray, Region3, UDim, UDim2, Vector2, Vector3, Instance, math, table, string, coroutine} if type(v) == "userdata" then for _,i in pairs(libraries) do if v == i then return string.lower(tostring(i)) end end if pcall(function() i = v:IsA("Instance") end) then return "object" elseif pcall(function() x = v.X end) then if pcall(function() z = v.Z end) then if Axes.new(v.X, v.Y, v.Z) == v then return "axes" elseif pcall(function() comp = v:components() end) then return "coordinateframe" else return "vector3" end elseif Vector2.new(v.X, v.Y) == v then return "vector2" elseif pcall(function() xo = v.X.Offset end) then return "universaldimension2" end elseif pcall(function() r = v.r end) then if BrickColor.new(v.r, v.g, v.b) == v then return "brickcolor" elseif Color3.new(v.r, v.g, v.b) == v then return "color3" end elseif pcall(function() top = v.Top) then if Faces.new(v.Back, v.Bottom, v.Front, v.Left, v.Right, v.Top) == v then return "faces" end elseif pcall(function() connect = v.connected end) then return "rbxscriptconnection" elseif pcall(function() conn = v:connect(function()end)end) then return "rbxscriptsignal" elseif pcall(function() origin = v.Origin end) then return "ray" elseif pcall(function() cf = v.CFrame end) then return "region3" elseif pcall(function() o = v.Offset end) then return "universaldimension" end end return type(v) end --- shared:ToupleToTable( ... ) function shared:ToupleToTable(...) assert(loadstring("return {" .. ... .. "}"))() end function r(v) -- for me return shared:RealType(v) end --- math.curt(v) function math.curt(v) if not r(v) == "number" then error("Number expected",1)