I've spent the better part of the afternoon trying to really understand os.loadAPI() vs. dofile() vs. loadfile()
If you want the back story:
Spoiler
I wanted to learn how to make a decent UI so I started looking on the forums at some prior art the other day.I found Bedrock and Cobalt-UI on the forums. Cobalt had some recent posts so I decided to check it out but could not even get
it to do "cobalt version" after install. I narrowed it down to the use of dofile() to load the API which was throwing an attempt
to call nil error. Chatted with the author on Discord briefly and concluded it was my version / config so I decided to hunt for the root cause.
I'm working in MC1.7.10/CC1.7.4 mainly but setup a MC1.8.9/CC1.7.9 client/server to test some of these scenarios.
I worked through the API tutorial again to ensure I understood os.loadAPI and that I could make it work.
I went back to the PIL docs and reviewed chunks and the dofile() and loadfile().
I dug through the forums for dofile() issues and found a couple posts describing the differences and a known issue in CC 1.7.8
http://www.computerc...__fromsearch__1
http://www.computerc...__fromsearch__1
Tested each example on 1.7.9 and they all seemed to work.
I tried to test the examples in LDT but could not figure out environment / setup. Kept getting file not found errors in the console.
I tried various tests with 1.7.4 and could not get get dofile to work directly but could override it with a definition I found on the PIL
function dofile (filename)
local f = assert(loadfile(filename))
return f()
end
The issue reported in CC1.7.9 on github says dofile should be "fnFile, e = loadfile( _sFile, _G )"
So my questions to the Pro's are:
1) I came across a statement from exxero who authored sheets who says:
There are two ways you can load Sheets into your environment, either as an API (via os.loadAPI) or as a local library (using dofile). We recommend the latter, as using dofile means that you can use any file name for the library itself, you don't pollute the global environment and accessing the local table is slightly more efficient.
Is there any truth to the environment and speed comments? It looks to me like the PIL version and CC version all end up in _G
2) Can someone confirm what version of CC dofile() was introduced in and/or fixed in? I did not see it anywhere in the release notes.
3) Any downside to defining dofile() as stated above to allow the API's that prefer that method to run without modification?
Bonus questions:
4) Can someone point me to a LDT environment setup tutorial / primer? I tried the dofile() examples on files in the same project but got
"com.naef.jnlua.LuaRuntimeException: cannot open func.lua: No such file or directory" where func.lua was the api file in the same project.
5) Being relatively new to CC, Lua and coding, is this par for the course in terms of running down issues and work arounds in various versions?