I have an idea for an API and I have a good Idea of the functions, but I don't know how to define that it's a new API. Is there some sort of function I use or do I just create a table?
How do I create an API?
Started by trajing, Jan 28 2014 12:15 PM
4 replies to this topic
#1
Posted 28 January 2014 - 12:15 PM
#2
Posted 28 January 2014 - 12:21 PM
My understanding of that is(i've never made one) that you write the code and then use the os.loadAPI("path/to/file") to load your code as an api... if your asking how to make one then... sorry i can't help you there.
#3
Posted 28 January 2014 - 12:37 PM
Here are some resources for you:
- API Basics tutorial which I consulted on my first API.
- Making an API in the wiki (which I also used)
- Here is a link to the API I built: Vertical Scrolling Utlity
Edited by surferpup, 28 January 2014 - 12:38 PM.
#4
Posted 28 January 2014 - 12:43 PM
trajing, on 28 January 2014 - 12:15 PM, said:
I have an idea for an API and I have a good Idea of the functions, but I don't know how to define that it's a new API. Is there some sort of function I use or do I just create a table?
if you already have the functions (say, in a test program) then you just need to move those functions into a new file, and load that file with the os.loadAPI call mentioned above
if you call your "file-o-functions" something like "fred" then
os.loadAPI("fred")
will then allow
fred.someFunctionInYourFredFile( params ) to be used
that's the basics which will allow what you have to be used... remember that in the api file, you can have local functions and non-local functions, if you define one as local then it will be internal to the api only (for example, a helper function that only the api needs)
remember to keep any variables in your api file local where possible...
more details in the above replies of course, but related to your question, and assuming you have some functions already, those two steps should bootstrap you quickly
#5
Posted 28 January 2014 - 12:51 PM
I also learned the hard way that you need to take care of the order of any local functions you create. A local function in an API is accessible by the code in the API, but it is not callable by the user (kind of handy, really). However, if one of your local functions relies on another local function in the API, the local function it needs MUST be defined before you call it.
Here is the question I had asked on this and the excellent answers I received: Question Regarding Local Functions in APIs
Here is the question I had asked on this and the excellent answers I received: Question Regarding Local Functions in APIs
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











