# Being a number

Hi!
Is it any code that says “if x== a number then text(x/2)” and “if x~= a number then text(x)”? I’m looking for a code that’s check if it is a number or just a word

`if type(x)=="number"`

Thanks @yojimbo2000

`type` will return “string”, “table”, “function”, but if it’s one of the Codea API elements like a vec or a matrix it will just say “userdata”

@yojimbo2000 - here is some code somebody worked out a while back to give more info on “userdata” types

``````function typeOf(x)
if x==nil then return "nil" end
if type(x) == "table" and x.is_a then return("class") end
local txt
if typeTable==nil then
typeTable = {
[getmetatable(vec2()).__index  ] = "vec2",
[getmetatable(vec3()).__index  ] = "vec3",
[getmetatable(color()).__index ] = "color",
[getmetatable(image(1,1)).__index ] = "image",
[getmetatable(matrix()).__index] = "matrix",
[getmetatable(mesh()).__index  ] = "mesh" ,
}
end
local i = getmetatable(x)
if i then txt = typeTable[i.__index] end
if txt then return txt end
txt = type(x)
return txt
end
``````

whats the difference between table and class?

This is something you can learn on your own, it’s too big a subject to teach you here

I’ve also written ebooks which explain the differences, see the wiki link above

i mean whats x.is_a

that’s a property of every class (but not a table), which is why it’s used to tell the difference

From wiki pedia for lua:

``````if tonumber(a) ~= nil then
--it's a number
end;
``````

That should work if it’s hex like 0xFF or scientific notation 1.1e-40 as well