306 posts
Location
Mars
Posted 24 May 2016 - 07:55 PM
This is one hell of a strange error I've been dealing with lately, I think it might be because shell.run() only can return true or false, though.
Any help would be appreciated! Thanks :)/>
Spoiler
if button == 2 and event == "mouse_click" then
for i=1, #f_file do
if x > 7 and x <= 20 and y == 6+i then
--print(tostring(fs.isDir(files..f_file[i]))..":"..files..f_file[i])
--print(files)
--print(f_file[i])
if fs.isDir(files..f_file[i]) then
else
if files..f_file[i] == "startup" then
error("An instance of Axiom is already running")
else
if not fs.exists(files..f_file[i]) then
error("File not found")
else
local ok, val = pcall(shell.run(files..f_file[i])) --# error: sys-latest.axs:1435: attempt to call boolean
if val then
errorMessager(val)
end
end
filebrowser()
end
end
end
end
end
Edited on 24 May 2016 - 06:02 PM
1080 posts
Location
In the Matrix
Posted 24 May 2016 - 08:05 PM
You're using pcall wrong, you need to pass it a function pointer.
pcall(shell.run,files..f_fille[i])
First argument is function that is going to be run, others are arguments to pass to the function.
What you were doing was running shell.run FIRST, and then when that ended it tried to run pcall on the boolean returned by shell.run, which of course doesn't work.
Edited on 24 May 2016 - 06:05 PM
306 posts
Location
Mars
Posted 24 May 2016 - 08:11 PM
You're using pcall wrong, you need to pass it a function pointer.
pcall(shell.run,files..f_fille[i])
First argument is function that is going to be run, others are arguments to pass to the function.
What you were doing was running shell.run FIRST, and then when that ended it tried to run pcall on the boolean returned by shell.run, which of course doesn't work.
That explains a lot, thank you!
One issue though, now I won't get the error that is
deliberately thrown in the file I'm trying to run.
Should I use xpcall instead?
1080 posts
Location
In the Matrix
Posted 24 May 2016 - 08:32 PM
What file are you trying to run?
306 posts
Location
Mars
Posted 24 May 2016 - 08:36 PM
a file that just simply throws an error, then it's done. it's located in os/user_files_/User-programs/crash.
It's a single line of code.
error("test")
1080 posts
Location
In the Matrix
Posted 24 May 2016 - 08:42 PM
The problem is that shell.run calls os.run that then uses pcall. You'd have to then create your own run function, in which the program being run has the proper environment. I don't know exactly what environment table you'd need to give, so someone else will have to help with that.
306 posts
Location
Mars
Posted 24 May 2016 - 08:48 PM
Right, okay.
I'll see what I can do.