Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
254 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
|
|
||
| if not commands then | ||
| error( "Cannot load command API on normal computer", 2 ) | ||
| end | ||
| native = commands.native or commands | ||
|
|
||
| local function collapseArgs( errorDepth, arg1, ... ) | ||
| if arg1 ~= nil then | ||
| if type(arg1) == "boolean" or type(arg1) == "number" or type(arg1) == "string" then | ||
| return tostring(arg1) .. " " .. collapseArgs( errorDepth + 1, ... ) | ||
| elseif type(arg1) == "table" then | ||
| return textutils.serialiseJSON(arg1) .. " " .. collapseArgs( errorDepth + 1, ... ) | ||
| else | ||
| error( "Expected string, number, boolean or table", errorDepth ) | ||
| end | ||
| end | ||
| return "" | ||
| end | ||
|
|
||
| -- Put native functions into the environment | ||
| local env = getfenv() | ||
| for k,v in pairs( native ) do | ||
| env[k] = v | ||
| end | ||
|
|
||
| -- Create wrapper functions for all the commands | ||
| local tCommands = native.list() | ||
| local tAsync = {} | ||
| for n,sCommandName in ipairs(tCommands) do | ||
| if env[ sCommandName ] == nil then | ||
| env[ sCommandName ] = function( ... ) | ||
| local sCommand = sCommandName .. " " .. collapseArgs( 3, ... ) | ||
| return native.exec( sCommand ) | ||
| end | ||
| tAsync[ sCommandName ] = function( ... ) | ||
| local sCommand = sCommandName .. " " .. collapseArgs( 3, ... ) | ||
| return native.execAsync( sCommand ) | ||
| end | ||
| end | ||
| end | ||
| env.async = tAsync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| On a Command Computer, "commands" will list all the commands available for use. Use "exec" to execute them. | ||
| Type "help commandsapi" for help using commands in lua programs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Functions in the commands API: | ||
| commands.exec( command ) | ||
| commands.execAsync( command ) | ||
| commands.list() | ||
| commands.getBlockPosition() | ||
| commands.getBlockInfo( x, y, z ) | ||
|
|
||
| The commands API can also be used to invoke commands directly, like so: | ||
| commands.say( "Hello World" ) | ||
| commands.give( "dan200", "minecraft:diamond", 64 ) | ||
| This works with any command. Use "commands.async" instead of "commands" to execute asynchronously. | ||
|
|
||
| The commands API is only available on Command Computers. | ||
| Visit http://minecraft.gamepedia.com/Commands for documentation on all commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| On a Command Computer, "exec" will execute a command as if entered on a command block. Use "commands" to list all the available commands. | ||
|
|
||
| ex: | ||
| "exec say Hello World" | ||
| "exec setblock ~0 ~1 ~0 minecraft:dirt" | ||
|
|
||
| Type "help commandsapi" for help using commands in lua programs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| New Features in ComputerCraft 1.65: | ||
| New Features in ComputerCraft 1.66: | ||
|
|
||
| * Fixed a multiplayer-only crash with turtle.place() | ||
| * Fixed some problems with http.post() | ||
| * Fixed fs.getDrive() returning incorrect results on remote peripherals | ||
| * Added Command Computers | ||
| * Added new API: commands | ||
| * Added new programs: commands, exec | ||
| * Added textutils.serializeJSON() | ||
| * Added ILuaContext.executeMainThreadTask() for peripheral developers | ||
| * Disk Drives and Printers can be renamed with Anvils | ||
| * Fixed some bugs and crashes | ||
|
|
||
| Type "help changelog" to see the full version history. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
|
|
||
| if not commands then | ||
| printError( "Requires a Command Computer." ) | ||
| return | ||
| end | ||
|
|
||
| local tCommands = commands.list() | ||
| table.sort( tCommands ) | ||
| textutils.pagedTabulate( tCommands ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
|
|
||
| local tArgs = { ... } | ||
| if #tArgs == 0 then | ||
| printError( "Usage: exec <command>" ) | ||
| return | ||
| end | ||
| if not commands then | ||
| printError( "Requires a Command Computer." ) | ||
| return | ||
| end | ||
|
|
||
| local sCommand = tArgs[1] | ||
| local fnCommand = commands[sCommand] | ||
| if fnCommand then | ||
| local bResult = fnCommand( select( 2, ... ) ) | ||
| if bResult then | ||
| print( "Success" ) | ||
| else | ||
| print( "Failed" ) | ||
| end | ||
| else | ||
| printError( "No such command" ) | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters