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

unknown return

Started by manuwar, 16 June 2014 - 11:02 AM
manuwar #1
Posted 16 June 2014 - 01:02 PM
Hi everyone, i'm new on the forum and on computercraft and there are some things that's drive me crazy XD
One of this is when i execute a method and the return is like "table: 18dh9jd9" what does this mean?
The only thing i've thinked is that the result of the method were stored in a table with that name but i can't understand…
Thanks and sorry for my english ;)/>
Bomb Bloke #2
Posted 16 June 2014 - 03:38 PM
Indeed, it means the function is returning a table. Store the table in a variable perhaps, then take a look at what's inside.

Eg, let's say you have a monitor attached to the right of your computer. You might do this:

myMonitor = peripheral.wrap("right")  -- This returns a table containing functions that influence the monitor.

print("\"myMonitor\" is a "..type(myMonitor)..", and it contains:")

for key, value in pairs(myMonitor) print(key..", which is a "..type(value)) end
manuwar #3
Posted 16 June 2014 - 06:17 PM
thanks!
so if i run that code the result is a list of the possible methods for that peripheral, that's a beginning :)/>
but then i've tried to print even the value of the table and the system told me that i was trying to print a function.. mmh so lua can store functions in tables??
Bomb Bloke #4
Posted 17 June 2014 - 01:42 AM
In Lua, a variable can have numbers, strings, booleans, table pointers, function pointers, and maybe a few other types stored against it.

Tables can likewise store any of the above. You can even put a pointer leading to a given table in that table.

In fact, an API is just a table filled with function pointers.
manuwar #5
Posted 17 June 2014 - 10:26 AM
ok now everything is a bit more clear :)/> thanks