CLNinja, on 26 February 2017 - 08:53 PM, said:
fishermedders, on 26 February 2017 - 07:16 PM, said:
CLNinja, on 26 February 2017 - 05:00 PM, said:
Also what do you mean about the general-use api?
Just like if you're gonna have a bunch of functions to use in a program, why not create an API that you can use over and over again (or just for this 1 program), that has all of the functions that you need in it, and download it once rather than spamming pastebin for it. Just my opinion.
I have no idea what you're talking about.
Basically, if you wanted to have all of your functions in a file, you'd do something like this:
myapi:
function centerPrint( sText, nY ) -- The text to center, the Y Line.
tSize = { term.getSize() }
term.setCursorPos( math.floor( tSize[1]/2 )-math.floor( #sText/2 ), nY )
term.write( sText )
end
function sayHello()
print( "Hello, world!" )
end
function foo()
return "bar"
end
Then in another file, you would be able to do things like:
programusingapi:
bDidLoad= os.loadAPI("myapi")
if bDidLoad then
myapicenterPrint( "Hello World!", 1 )
myapi.sayHello()
print( myapi.foo() )
end
I usually make
APIs like this for functions that I use most often.
[Edit Reason: Wacky code formatting]
Edited by fishermedders, 27 February 2017 - 02:25 AM.