Posted 09 February 2012 - 05:29 AM
Herro, I've been using computercraft on a good friend's server for a while, messing around with it a bit.
We're considering using it to control a IC2 reactor, amongst other things.
I've noticed a problem, however: There doesn't seem to be an "easy" way of finding out what your base directory is if your code runs from a disk, example:
disk/startup:
disk/helloworld:
I'm currently using disk labels as a way to identify, but this is error prone if the disk label is changed. I could put a marker at the top of the file, and save it as a string, then search for it; but I'm too lazy.
We're considering using it to control a IC2 reactor, amongst other things.
I've noticed a problem, however: There doesn't seem to be an "easy" way of finding out what your base directory is if your code runs from a disk, example:
disk/startup:
print("Startup loaded - Attempting to open ./helloworld")
local res, err = pcall(function() dofile("./helloworld") end)
print(string.format("Result: %s; Error?: %s", res or "", err or ""))
-- Try with disk/ since that's most likely
print("Attempting to open disk/helloworld")
local res, err = pcall(function() dofile("disk/helloworld") end)
print(string.format("Result: %s; Error?: %s", res or "", err or ""))
disk/helloworld:
print("Hello, world!")
I'm currently using disk labels as a way to identify, but this is error prone if the disk label is changed. I could put a marker at the top of the file, and save it as a string, then search for it; but I'm too lazy.
local cLabel = "asdf"
local sides = {"back", "left", "right", "bottom", "top", "front"}
local sDiskSide = ""
local sDiskDir = ""
for _, s in pairs(sides) do
if disk.getLabel(s) == cLabel then
sDiskSide = s
sDiskDir = disk.getMountPath(s)
break
end
end
assert(sDiskSide ~= "", "Error locating disk.")