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

Getting a API to run on loading?

Started by makeme, 28 February 2014 - 12:06 PM
makeme #1
Posted 28 February 2014 - 01:06 PM
I'm making an API and I want it to print a Version Line on being loaded. is there any way to do this without it being called in the program?
CometWolf #2
Posted 28 February 2014 - 01:08 PM
Anything in the API is ran when it's loaded, just in it's own environment table, so just put a print at the top of it.
makeme #3
Posted 28 February 2014 - 01:15 PM
I don't quite get what you mean. Where do I need to put the print?
MKlegoman357 #4
Posted 28 February 2014 - 03:14 PM
You can put it anywhere outside of any functions.

The way API loading in ComputerCraft works is os.loadAPI runs an API just like a normal program, then takes all global variables left after run and puts it into a global table.

Something like this would work:


--// Test API

local version = "1.0.2"

function test ()
  ...
end

print(version)


--// Test program

os.loadAPI("test") -->> prints '1.0.2'
makeme #5
Posted 28 February 2014 - 03:33 PM
Oh right thanks