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

[1.3]os.loadAPI() loading API if you change the file

Started by rockymc, 02 March 2012 - 11:59 PM
rockymc #1
Posted 03 March 2012 - 12:59 AM
Well, if you load the API file in lua, then make some changes to the file, and use the same command it will only appear 'true' and load the same API. I don't know if this is a bug or no.
Espen #2
Posted 03 March 2012 - 01:24 AM
I think it is intended behavior that os.loadAPI() doesn't load an API again if it is already loaded.
You'd have to unload it first and then load it again.

But since the os.unloadAPI() function is bugged at the moment, you might have to reboot as an alternative (or remove it manually).
Or you can apply the proposed fix described here: http://www.computercraft.info/forums2/index.php?/topic/357-13sspsmp-unloadapi-not-working/

EDIT: I wasn't sure before, assumed it works like 'require' somehow.
I just looked at the code now and it looks like it should load the API regardless, as MysticT said in the next post.
Edited on 03 March 2012 - 01:12 AM
MysticT #3
Posted 03 March 2012 - 01:37 AM
For what I saw in the code, it should load it with the changes. It doesn't check if the API is already loaded, it just loads it, and if it exists it overwrites it.

_G[sName] = tAPI
sName is the name of the API file (without the path), so if you load the same file it should overwrite it.
What changes did you do that doesn't load? (added functions, fixed errors, etc)
rockymc #4
Posted 04 March 2012 - 09:33 PM
What I meant is, if you load the API the first time, then make some changes to the API, then use os.loadAPI, the same API loads again.
MysticT #5
Posted 04 March 2012 - 11:27 PM
If it loads it again the changes should be there. If the changes you made are not applied, it's not loading the API.
Espen #6
Posted 05 March 2012 - 08:45 PM
Ok, I just tried it myself.
  • loaded up some API
  • executed a function
  • changed something in the API code
  • loaded the API again
  • executed the function anew.
  • => got a different result, as expected
So far it's all behaving as intended for me.
Can you provide us with a bit more details or a sample code with which we can reproduce the problem?