ComputerCraft Forums

ComputerCraft => Tutorials => Topic started by: Creepdasheep on Nov 09, 2022, 03:24 PM

Title: How to make a API
Post by: Creepdasheep on Nov 09, 2022, 03:24 PM
step 1, make a script with the name of the api you want to call
step 2, go into the script and make some functions like..

function wait(int)
 local waitint = tonumber(int)
 os.sleep(waitint)
end

Now in your main script insert your api
os.loadAPI("creepdasheep_api")
with your function put the name of your api...
creepdasheep_api.wait(1)
Now you know how to make API's or you could have just gone to the wiki
Title: How to make a API
Post by: Erb3 on Nov 09, 2022, 08:50 PM
Using `os.loadAPI` is one way of doing it. Another more modern way of doing it is `require`.

File a:
local a = {}

local function a.sum(a, b)
  return a + b
end

return a

File b:
local a = require("a")
a.sum(5+5)

Tweaked.cc | Reusing code with require (https://tweaked.cc/guide/using_require.html)
Title: How to make a API
Post by: QuickMuffin8782 on Mar 29, 2023, 11:33 PM
Quote from: PC_Cat on Nov 09, 2022, 08:50 PM-snip-
Using require(), you can use other's libraries/modules, or CraftOS's built-in libraries/modules. If you look inside the code for CraftOS's rom, you'll understand how it works and what you can create, whatever if it's an API or not.