Jump to content




Return tables


  • You cannot reply to this topic
3 replies to this topic

#1 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 14 March 2012 - 09:13 PM

Hi,

I noticed that you cannot return tables or functions from a peripheral method implemented in java. I don't need functions, but the lack of tables is really bad. luaj contains a huge conversion algorithm java <=> lua, but for some reason, ComputerCraft uses an own one which can only handle strings, integers, doubles, and null.

So, I would suggest using the luaj java <=> lua conversion for the peripherals.

#2 Casper7526

    OG of CC

  • Members
  • 362 posts

Posted 14 March 2012 - 11:02 PM

You could always serialize them and unserialize them.

#3 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 15 March 2012 - 01:27 AM

@Xfel:
function pack( ... )
  return arg
end
pack() takes an arbitrary amount of parameters, which is then accessible via the table 'arg' (which is then simply returned).
It's basically the opposite of what Lua's unpack() does.

Here's how you'd use the above function:
local periph = peripheral.wrap("right")
local tValues = pack( periph.getMultipleReturnValues() )
After the last line, 'tValues' will be a table with all the values that periph.getMultipleReturnValues() returned.

Cheers :D/>

#4 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 15 March 2012 - 03:43 PM

@Espen:
Yes, but that doesn't work if you want nested tables, dictionaries, or metatables

@Casper7526:
I'm currently using this solution, but it is more complicated than needed.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users