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

How to make API?

Started by CastleMan2000, 04 September 2012 - 06:46 PM
CastleMan2000 #1
Posted 04 September 2012 - 08:46 PM
How do you make an API? I.e have a bunch of functions that you could call with api.function()?
sjele #2
Posted 04 September 2012 - 09:02 PM
lets say you made some function like this:

Save this as the file myApi

function sayHello(thing)
  print("hello"..thing..")
end

function clearScreen()
  term.clear()
  term.setCursorPos(1, 1)
end

Save that and find the file. Outsides of mc, Make sure it has no extensions it is supposed to be a file file.
then goto minecraft/mods/computercraft/lua/rom/apis
Put the file in there and reboot CC pc.
now in anyfile you can do :

myApi.sayHello(sjele)
--or
myApi.clearScreen()
CastleMan2000 #3
Posted 05 September 2012 - 12:54 AM
Cool. Can you just use os.loadAPI with the file on the computer or a floppy?
sjele #4
Posted 05 September 2012 - 06:36 AM
Yeh, i belive so. But if you have it in apis folder they auto load.