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

Multiple Os.loadapi

Started by IHHI, 24 August 2013 - 01:54 AM
IHHI #1
Posted 24 August 2013 - 03:54 AM
I want to access the function myFunc and the local myVar from api2. The main program load the api1 and the api1 load the api2.


myProgram
----
os.loadAPI("api1")

-- I want to use the function myFunc from api2
--[[???]]

-- I want to print the local myVar from api2
print(--[[???]])


api1
-----
os.loadAPI("api2")


api2
-----
local myVar = "This is myVar"

function myFunc()
  print("This is myFunc")
end

Thanks to anyone who help me.
Lyqyd #2
Posted 24 August 2013 - 12:08 PM
Uh, api2.myFunc(), of course. You can't access local variables in APIs.
IHHI #3
Posted 24 August 2013 - 12:38 PM
Thanks for api2.myFunc() . For the local var, I know I can't access it directly but I'm searching something that will create a kind of enum like colors.white and colors.orange that I will be able to load from the api2, I thought to create multiple functions but I want to know if there is a better way to do that.

Example with the
Phonetic Alphabet:
api2.a = Alpha
abi2.b = Bravo
abi2.c = Charlie

Lyqyd #4
Posted 24 August 2013 - 12:42 PM
Don't make it local. If you read the colors API, it's got a section that's a bit like this:


white = 1
orange = 2
magenta = 4
lightBlue = 8

etc.
IHHI #5
Posted 24 August 2013 - 12:45 PM
Thanks. :)/>

Just want to clarify this by doing comparison with c#/c++ local == private and nothing == public, is there something else like protected or what ever?
Lyqyd #6
Posted 24 August 2013 - 12:52 PM
local isn't the same as private, and there's no equivalent to protected.
IHHI #7
Posted 24 August 2013 - 12:54 PM
That's nice and you are pretty fast to answer, thanks again.