From 740e87e97b0fcabbcee4b0ede73972e474b19ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 5 Mar 2014 12:23:08 -0800 Subject: [PATCH] added missing methods --- API-Component.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/API-Component.md b/API-Component.md index 3065d7d..6a3cfd2 100644 --- a/API-Component.md +++ b/API-Component.md @@ -1,6 +1,19 @@ The component API is used to access and interact with components available to a computer. Also see [[the page on component interaction|ComponentAccess]]. -- `component.get(address: string, componentType: string): string | (nil, string)` +- `component.doc(address:string, method:string): string` + Returns the documentation string for the method with the specified name of the component with the specified address, if any. Note that you can also get this string by using `tostring` on a method in a proxy, for example `tostring(component.screen.isOn)`. +- `component.invoke(address:string, method:string[, ...]): ...` + Calls the method with the specified name on the component with the specified address, passing the remaining arguments as arguments to that method. Returns the result of the method call, i.e. the values returned by the method. Depending on the called method's implementation this may throw. +- `component.list([filter:string]):function` + Returns an iterator over all components currently attached to the computer, providing tuples of address and component type. Use it like so: `for address, componentType in component.list() do ... end` + If `filter` is set this will only return components that contain the filter string (this is *not* a pattern/regular expression). For example, `component.list("red")` will return `redstone` components. +- `component.proxy(address:string):table` + Gets a 'proxy' object for a component that provides all methods the component provides as fields, so they can be called more directly (instead of via `invoke`). This is what's used to generate 'primaries' of the individual component types, i.e. what you get via `component.blah`. + For example, you can use it like so: `component.proxy(component.list("redstone")()).getInput(sides.north)`, which gets you a proxy for the first `redstone` component returned by the `component.list` iterator, and then calls `getInput` on it. + Note that proxies will always have at least two fields, `type` with the component's type name, and `address` with the component's address. +- `component.type(address:string):string` + Get the component type of the component with the specified address. +- `component.get(address: string[, componentType: string]): string | (nil, string)` Tries to resolve an abbreviated address to a full address. Returns the full address on success, or `nil` and an error message otherwise. Optionally filters by component type. - `component.isAvailable(componentType: string): boolean` Checks if there is a primary component of the specified component type.