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

I Need Help With Custom Apis

Started by luza, 19 February 2012 - 01:38 PM
luza #1
Posted 19 February 2012 - 02:38 PM
hey,
I'm currently writing a Database-api wich will hopefully be released this evening and I encountert one problem.

What's the different between shell.run() and os.loadAPI()?

I placed my API in my root folder and I'm currently using shell.run() to load it.
But how do I use os.loadAPI() and what's the advantage of that?
Advert #2
Posted 19 February 2012 - 02:45 PM
os.loadAPI will make your API avaliable to any program; shell.run may not.


To use os.loadAPI, simply declare functions like so:

local value
function getValue()
 return value
end
function setValue(v)
 value = v
end
The filename you load it as will be it's table, e.g if you save it as "values", and os.loadAPI("values"), you would then be able to call values.getValue() and values.setValue()
luza #3
Posted 19 February 2012 - 03:09 PM
aaaah tanks. :)/>/>
But for some reason I'm also able to call the function without the API name infront of it.
that may not be good.
Advert #4
Posted 19 February 2012 - 03:15 PM
Try rebooting the computer; this should clear all the global variables on it.
luza #5
Posted 19 February 2012 - 04:44 PM
doesn't work :/
Advert #6
Posted 19 February 2012 - 05:12 PM
Are you using os.loadAPI or another method?

Also, @ your sig: Tables are not called arrays, because they are not simply arrays; they are also hastables, sets, and objects.
luza #7
Posted 19 February 2012 - 05:20 PM
hm… now it's working but I'm getting the error: "table index expected, got nil"


PS: Hm… seems like I don't know enough about programming to understand that^^
Advert #8
Posted 19 February 2012 - 06:16 PM
See this thread: http://www.computercraft.info/forums2/index.php?/topic/118-codex-of-error-slaying-3/
luza #9
Posted 19 February 2012 - 07:05 PM
ah thanks, it worked now.
I'm not quite sure why but at least it works.