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

ReactorCraft compatibility

Started by joselitosn, 18 March 2015 - 12:45 AM
joselitosn #1
Posted 18 March 2015 - 01:45 AM
I'm trying to automate an Extractor from RotaryCraft by reading the inventory slots. The problem is the functions do not behave as expected. The function i call is "printInv", which following the source code of RotaryCraft seems to return an array list of strings.

Now when i print the result directly using the print function, i receive the the strings for each slot in each line. But if i assign the call directly to a variable, i receive only the first element.

I'm not sure this is the right place to ask this question, but i've been looking in both mods documentation and everything seems right to me. Might be a problem at converting the results?

In case it matters the code for the specific files invoking the function:
TileEntityBase.java and LuaPrintInv.java
Lyqyd #2
Posted 18 March 2015 - 02:56 AM
Moved to Ask a Pro.

When you're getting the results in Lua, print(myFunc()) will mean that the print function gets all of the arguments returned. It prints each argument it receives, so that would print all of them. When you're getting the results and trying to put them into a variable, you're doing this:


local var = myFunc()

When you need to be doing this:


local var = {myFunc()}

That will put the results into a table that you can then index to view the results.
joselitosn #3
Posted 18 March 2015 - 01:41 PM
Moved to Ask a Pro.

When you're getting the results in Lua, print(myFunc()) will mean that the print function gets all of the arguments returned. It prints each argument it receives, so that would print all of them. When you're getting the results and trying to put them into a variable, you're doing this:


local var = myFunc()

When you need to be doing this:


local var = {myFunc()}

That will put the results into a table that you can then index to view the results.

Interesting, i thought CC did the translation automatically from the java object[] to the table type. That was my mistake for not understanding Lua and CC well enough. Thanks for the help and sorry for any incovenience!
Lyqyd #4
Posted 18 March 2015 - 02:22 PM
Well, the Object[] that you return from your peripheral functions is the list of arguments to return. If it squished those all into a single table, there'd be no way to return multiple values from a peripheral. You may be able to use a second Object[] as one of the arguments in the array your return to cause it to return a table. I don't know for certain what all LuaJ can turn into a Lua table. I know (Hash)Maps work, and I suspect Object[]s would as well, but I haven't used them for that, personally.