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

[HOW TO] How to call a peripheral method with a list

Started by xuma202, 09 February 2013 - 12:48 PM
xuma202 #1
Posted 09 February 2013 - 01:48 PM
Hello,

here I want to tell you about a concept I came up with about how to send a list from lua to Java.
As you know you can't call a peripherals function with a list as a parameter.

But for my peripheral http://www.computerc...-nbt-editor-10/ I wanted to do this.
I've tried many ways but none did really work well.
The concept I ended up which was working and an ok solution was this:

I used a JSON library for lua http://regex.info/blog/lua/json and an api function turned my table into a JSON string.
Because sending this String to Java didn't work for some reason. I had to make my api saving it into a file. Next I called the peripherals function with the filename. In java I opened the file and parsed it using this JSON parser http://wiki.fasterxm...JacksonDownload into a HashMap. Back in lua I deleted the temporary file.
That's it.

So hope this helps you if you have to pass a multidimensional array to a peripheral.
Xfel #2
Posted 10 February 2013 - 09:11 PM
Just a hint: there is a JSON parser included with minecraftforge. I'd recommend using that one instead of another api. Additionally, I'm quite shure that you should be able to pass the string to java without using a temp file.

But apart from that, this is a good solution for an old and known problem the cc developers could easily fix if they wanted to do so…
xuma202 #3
Posted 12 February 2013 - 09:54 AM
Oh I didn't know about the JSON parser in minecraftforge. And about passing the string to java without a temp file: I've tried that. I've also made a method that gave me the encoded hashmap and i passed this directly into the decoder. It worked but when I just passed the string to lua and back it didn't. So I don't know it should be working sure but it didn't so I went with the temp file for now.