This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Termanater13's profile picture

How do I find if a variable is a table

Started by Termanater13, 30 December 2012 - 06:27 PM
Termanater13 #1
Posted 30 December 2012 - 07:27 PM
Im trying to see if a variable is a table,. So I can write a function that asks for 4 inputs but if variable one is a table to ignore the other inputs and use the table given.
for example:
function test(a, b, c, d)
if istable(a) then
   some code
else
   some code
end
end
I hope the above gives an Idea of what Im trying to do.
Kingdaro #2
Posted 30 December 2012 - 07:32 PM
if type(a) == 'table' then

type() will also give "number" on a number, "string" on a string, "function" on a function, and so on. Pretty self-explanatory.

Off topic, but I find it a little coincidental that I'm literally doing this exact same thing in a program of mine right now, haha.
Termanater13 #3
Posted 31 December 2012 - 05:54 AM
if type(a) == 'table' then

type() will also give "number" on a number, "string" on a string, "function" on a function, and so on. Pretty self-explanatory.

Off topic, but I find it a little coincidental that I'm literally doing this exact same thing in a program of mine right now, haha.
that is exactly what I was looking for, and it also may help me when it comes to other Ideas, like input type check to see if a user input the right kind of data,