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

Api list?

Started by KingofGamesYami, 16 March 2014 - 10:57 PM
KingofGamesYami #1
Posted 16 March 2014 - 11:57 PM
I have been looking around, and nobody has listed all the api's & commands for CC in any (single) place. This is what I know so far:
m = peripheral.wrap("side") –set monitor
p = peripheral.wrap("side") –set printer
redstone.getInput("side") –checks for redstone signal
redstone.setOutput("side") –outputs redstone signal
m.setTextScale(#) –sets text size on a monitor
m.setTextColor(colors.name) –sets text color on a monitor
m.setBackgroundColor(colors.name) –sets the background color on a monitor
m.write("text") –writes text on a monitor
os.redirect(m) –anything written to the computer is redirected to the monitor
os.write("text") –writes text on the computer
shell.clear() –clears shell or something
shell.run –runs without termination (I think)
os.read("*") –reads the written text and displays "*" instead of actual characters, useful in password systems
if variable == true then –if/then scenario
else –does opposite of if… if you know what I mean
elseif variable == variable then –does same thing as else, but includes an if
sleep(#) –pauses computer for # seconds
os.loadApi("api") –loads an api from file, such as Direwolf20's button Api
os.shutdown() –shuts off
os.restart –restarts
••••••••••••••••••••••••••••••
commands:
pastebin get <code> <name> –downloads program from pastebin as name
pastebin run <code> –runs a program from pastebin
programs –lists programs
dir –lists directories
<name> –runs program name
I have seen the page about this on the computercraft wiki, but what I want is basically a reference for when I want to put together a new program.
SuicidalSTDz #2
Posted 17 March 2014 - 12:01 AM
They are all technically stored in the global table, you just have to parse through it. Like so:


local handle = fs.open( ".dump", "w" )
local function iterateTable( tbl, id )
  print( "Iterating table " .. tostring( tbl ) )
  for k, v in pairs( tbl ) do
	if type( v ) == "table" and tostring( k ) ~= "_G" then
	  iterateTable( v, k )
	elseif type( v ) == "function" then
	  local value = "function: value: " .. ( id ~= "_G" and id .. "." or "" ) .. tostring( k ) .. "()\n"
	  write( value )
	  handle.write( value )
	elseif tostring( k ) ~= "_G" then
	  local value = "variable: value: " .. ( id ~= "_G" and id.."." or "" ) .. tostring( k ) .. "\n"
	  write( value )
	  handle.write( value )
	end
	sleep( 0 )
  end
  return
end
iterateTable( _G, "_G" )
handle.close()

Edit: Code courtesy of GravityScore or TheOriginalBIT (now I can't be wrong :P/>)

Edit: Such derp :P/>
Edited on 17 March 2014 - 03:45 AM
theoriginalbit #3
Posted 17 March 2014 - 02:07 AM
use the above code for it :)/> there is only one bug in the code, and its with the native APIs so anything starting with `native.` just ignore, you should be avoiding using them anyway.

Edit: Code courtesy of GravityScore
Pretty sure that was my code wasn't it? That's the one from the SublimeText2 Plugin thread :P/>
KingofGamesYami #4
Posted 17 March 2014 - 02:51 AM
That may be helpful, but when I run that as a program I get this:

listapi:4: bad argument: table expected, got nil
I checked line 4 against your code example, and it matched exactly. (I'm too much of a noob at this to debug myself)
Edited on 17 March 2014 - 01:52 AM
theoriginalbit #5
Posted 17 March 2014 - 02:55 AM
That may be helpful, but when I run that as a program I get this:

listapi:4: bad argument: table expected, got nil
the second line from the bottom reads iterateTable( _G, "_G" )?
SuicidalSTDz #6
Posted 17 March 2014 - 04:42 AM
use the above code for it :)/> there is only one bug in the code, and its with the native APIs so anything starting with `native.` just ignore, you should be avoiding using them anyway.

Edit: Code courtesy of GravityScore
Pretty sure that was my code wasn't it? That's the one from the SublimeText2 Plugin thread :P/>
Lol, was it? I kept it from way back, so I can't remember.

Edit: You and Grav's avatars look so much alike to me sometimes..
Edited on 17 March 2014 - 03:43 AM
MKlegoman357 #7
Posted 17 March 2014 - 07:25 AM
Lol, those answers :D/>. I think he just needs a list of CC apis. Why didn't you check the wiki?
theoriginalbit #8
Posted 17 March 2014 - 07:27 AM
I think he just needs a list of CC apis. Why didn't you check the wiki?
I have seen the page about this on the computercraft wiki, but what I want is basically a reference for when I want to put together a new program.
MKlegoman357 #9
Posted 17 March 2014 - 07:33 AM
I think he just needs a list of CC apis. Why didn't you check the wiki?
I have seen the page about this on the computercraft wiki, but what I want is basically a reference for when I want to put together a new program.
I have been looking around, and nobody has listed all the api's and commands for CC in any (single) place.
SuicidalSTDz #10
Posted 17 March 2014 - 10:57 AM
All of them are listed in one place.. The global table, which was suggested.

Edit: They are actually in three places :P/> The global table (_G), the global table in the global table (_G._G), and after running the above script they can also be found in the file '.dump'.
Edited on 17 March 2014 - 10:31 AM
theoriginalbit #11
Posted 17 March 2014 - 01:10 PM
the global table in the global table (_G._G)
well that is a recursive entry, so technically it can be found in infinite locations since you could do _G._G._G._G._G._G._G._G._G._G but that's just starting to get ridiculous.
SuicidalSTDz #12
Posted 17 March 2014 - 01:14 PM
Lol, I knew you would say something like that :P/>
Edited on 18 March 2014 - 12:12 AM
SuicidalSTDz #13
Posted 18 March 2014 - 01:15 AM
I got bored and wasn't sure if you got the above script to work, so here:

Spoiler
redstone.setBundledOutput()
redstone.getBundledInput()
redstone.testBundledInput()
redstone.getInput()
redstone.getBundledOutput()
redstone.getSides()
redstone.setOutput()
redstone.getOutput()
gps.locate()
keys.getName()
printError()
peripheral.call()
peripheral.getMethods()
peripheral.getType()
peripheral.isPresent()
peripheral.wrap()
bit.bxor()
bit.bor()
bit.blshift()
bit.blogic_rshift()
bit.brshift()
bit.band()
bit.bnot()
coroutine.status()
coroutine.resume()
coroutine.create()
coroutine.yield()
coroutine.wrap()
coroutine.running()
disk.setLabel()
disk.getLabel()
disk.hasAudio()
disk.eject()
disk.hasData()
disk.playAudio()
disk.getAudioTitle()
disk.isPresent()
disk.getID()
disk.stopAudio()
disk.getMountPath()
colours.combine()
colours.test()
fs.combine()
fs.isReadOnly()
fs.getSize()
fs.move()
fs.exists()
fs.copy()
fs.getFreeSpace()
fs.makeDir()
fs.delete()
fs.open()
fs.list()
fs.getDrive()
fs.getName()
fs.isDir()
rednet.open()
rednet.isOpen()
rednet.receive()
rednet.close()
rendet.send()
rednet.broadcast()
rednet.run()
os.day()
os.pullEventRaw()
os.queueEvent()
os.run()
os.getComputerID()
os.getComputerLabel()
os.loadAPI()
os.shutdown()
os.sleep()
os.unloadAPI()
os.setAlarm()
os.pullEvent()
os.computerLabel()
os.clock()
os.reboot()
os.time()
os.setComputerLabel()
os.startTimer()
os.version()
os.computerID()
help.setPath()
help.topics()
help.lookup()
help.path()
rs.setBundledOutput()
rs.getBundledInput()
rs.testBundledInput()
rs.getInput()
rs.getBundledOutput()
rs.getSides()
rs.setOutput()
rs.getOutput()
http.request()
http.post()
http.get()
write()
print()
textutils.pagedPrint()
textutils.unserialize()
textutils.formatTime()
textutils.pagedTabulate()
textutils.serialize()
textutils.slowWrite()
textutils.urlEncode()
textutils.tabulate()
textutils.slowPrint()
term.scroll()
term.redirect()
term.setCursorPos()
term.write()
term.clear()
term.setTextColor()
term.isColor()
term.setBackgroundColour()
term.setTextColour()
term.isColour()
term.clearLine()
term.getSize()
term.getCursorPos()
term.restore()
term.setBackgroundColor()
term.setCursorBlink()
colors.combine()
colors.subtract()
colors.test()
vector.new()
paintutils.drawPixel()
paintutils.drawLine()
paintutils.drawImage()
paintutils.loadImage()

These are all ( I think ) of the functions revealed by ComputerCraft that are worth documenting. Cheers! :P/>
CometWolf #14
Posted 18 March 2014 - 05:22 AM
You're missing shell and all Lua apis, i assume the latter was intentional?
Edited on 18 March 2014 - 04:24 AM
SuicidalSTDz #15
Posted 18 March 2014 - 11:22 AM
Lua was intentional, shell was not. I'll fix it when I get a chance :P/>
apemanzilla #16
Posted 18 March 2014 - 12:46 PM
And colors API, though it's mostly just constants.
Edit: woo! Post #200! A fifth of the way to a custom title :D/>
Edited on 18 March 2014 - 11:46 AM