So without the context, I have a method that returns a table. Trying to print it out, it seems that the table mainly contains methods to be called. However not being very knowledgeable in LUA, i have no idea how to properly get some information about these methods i should call.
I tried to get documentation from the creator of the thing, but there is none as far as i know. And since this is inside computercraft (minecraft mod) i don't have a lot of features to rely on either.
So knowing only that it is a table with methods that i can call, how do i properly figure out how to call them, and with what parameters etc. ?Answer1:
Generally speaking, modules/ libraries always come with docs, or a method to print the docs.
But if this is not the case, here's what you can do:<ul><li><em>You can print everything in the table</em>! This is a must, the names of the methods can be <strong>very</strong> useful</li> <li><em>You can seek out help</em>! Find people who have used the same module, and ask them how it works. Why solve something others have <strong>already figured out</strong>?</li> <li><em>Use
debug.getinfoand other hacky functions for the debug library</em>! They can provide <strong>more info</strong> than anything else in the Lua standard libraries!</li> <li><em>C-Side coding can reveal what Lua cannot</em>! If you have access to the C-Side you can see <strong>exactly</strong> what the code is doing (or at least I think so)</li> <li><em>Check out the source code</em>! This shows you what the code does and <strong>how it does it</strong></li> <li><em>And above all else, experiment</em>! Try the methods on different parameters, different values, and <strong>identify</strong> what it does through continuous testing!</li> </ul>Answer2:
Just knowing the names of the methods is not enough to figure how to call them.
Their names may be a clue, but there is no guarantee.
If the methods are written in Lua, you could use the debug API to discover the names of parameters, which again may just be an indication of how to call the methods.
Bottom line: you need documentation or example code.Answer3:
I knew this existed, didn't know how it worked. So for future reference: You can dump your peripherals and methods by doing /op_dump in the minecraft chat.
This generates an XML which writes out all methods it has found in peripherals OR objects/tables.
This means that you have to call every interesting method once, which generates the table as return. And then calling /op_dump will include that newly encountered object with all information about there methods/parameters etc.