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

api refuses to work

Started by Reinified, 12 May 2018 - 04:16 PM
Reinified #1
Posted 12 May 2018 - 06:16 PM
right so I've got an api which refuses to load.

Code: pastebin get kYQqr67d b-client

So basically, os.loadAPI("b-client") returns true but none of the functions are usable. When manually running the program, the API loads and allows usage. Why?
H4X0RZ #2
Posted 12 May 2018 - 06:32 PM
try renaming it; os.loadAPI really just loads all the global stuff the file exposes and stores it in a table inside _G. Typing `b-client.someFunction` is not valid Lua though. Another thing you could do is this:


os.loadAPI "b-client"

_G["b-client"].someFunction()
Reinified #3
Posted 12 May 2018 - 06:41 PM
Thanks, the _G system works.
Jummit #4
Posted 13 May 2018 - 06:59 AM
BTW, why don't you use require? Its a lot more controllable that os.loadAPI. You can specify the table in which the api is loaded, and you don't have to have unnecessary globals. You can also name the api files as you want without haveing to do the

local api = _G["api.lua"]
thing.
Lupus590 #5
Posted 13 May 2018 - 01:44 PM
BTW, why don't you use require?

Could be running on old CC or wanting to keep compatability. Also might not know about require or how to use it.
Reinified #6
Posted 14 May 2018 - 01:06 PM
BTW, why don't you use require?

Could be running on old CC or wanting to keep compatability. Also might not know about require or how to use it.

I'm using an older version of computercraft because I need to run it on a 1.8.9 server. Thanks for the tips though!