42 posts
Location
Germany
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?
454 posts
Location
London
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()
42 posts
Location
Germany
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.
454 posts
Location
London
Posted 19 February 2012 - 03:15 PM
Try rebooting the computer; this should clear all the global variables on it.
42 posts
Location
Germany
Posted 19 February 2012 - 04:44 PM
doesn't work :/
454 posts
Location
London
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.
42 posts
Location
Germany
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^^
454 posts
Location
London
Posted 19 February 2012 - 06:16 PM
42 posts
Location
Germany
Posted 19 February 2012 - 07:05 PM
ah thanks, it worked now.
I'm not quite sure why but at least it works.