Just define the functions you would like to expose in your API, save it as a file, then os.loadAPI it.
PROTIP:
Reboot your Computer (CTRL-R/CTRL-S/reboot/shutdown) if your API errors, as the computer will think it's still being loaded if it errors.
For example: Save this as SPD (semi-persistent data)
-- Example semi-persistent data (does not save to files; you could add that, of course) API
local data = {}
-- Return this API's version! This can be very useful for developers, especially for complex APIs
function getVersion()
return 0.2
end
-- A function to get data from the API
function getData(key)
return data[key]
end
-- A function to set data in the API
function setData(key, value)
local oldData = data[key]
data[key] = value
return oldData -- It's always useful to return the old data when doing this.
end
This API would expose the following functions: SPD.getVersion(), SPD.getData(key), SPD.setData(key, value), and allow you to get/set data between programs, as long as the computer has not rebooted.
I think this is about it; If you still aren't sure, you can always take a look at rom/apis/*, or make a post!