73560

Table with methods, how to handle/inspect them?

Question:

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.getinfo and 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.

Recommend

  • SQL Server varchar(50) and varchar(128) performance difference [duplicate]
  • how to play a mp3 file from the middle
  • Copy current CLOB column to new BLOB column in Oracle
  • Vector Drawables in Layer List on Android API 16 and higher
  • Keep playing a sound over and over again in Matlab?
  • Matlab to Python Conversion binary file read
  • Catching exceptions caused in different threads [duplicate]
  • Sql indexes vs full table scan
  • Class implementation in a header file == bad style? [duplicate]
  • get src attribute of an image based on class or id
  • Furthest-point Voronoi diagram in Java
  • How to use SBT with multiple sub project web applications?
  • Get all existing pointers to an object
  • android-support-v7-appcompat has same attrs as actionbarsherlock library
  • include dlls in visual studio c++ 2008
  • react split panel resize
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • Access user's phone number on iOS 7
  • Zurb Foundation _global.scss meta styles for js?
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Installed module is empty
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Spring security and special characters
  • JSON with duplicate key names losing information when parsed
  • How to make Safari send if-modified-since header?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • QuartzCore.framework for Mono Develop
  • How to pass list parameters for each object using Spring MVC?
  • RestKit - RKRequestDelegate does not exist
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • C# - Getting references of reference
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • JaxB to read class hierarchy
  • Is there any way to bind data to data.frame by some index?
  • How can i traverse a binary tree from right to left in java?
  • Unable to use reactive element in my shiny app