I already tried pcall, but when a program fails, it only returns false and true, which is not what I expect
Thanks
that value always give me true, no matter whatpcall should be returning a second argument in those cases, which would contain the error message. Perhaps you need assert instead, I can't really recall. Either way, look at the second return value.
loadfile = function( _sFile )
local file = fs.open( _sFile, "r" )
if file then
local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
file.close()
return func, err
end
return nil, "File not found"
end
dofile = function( _sFile )
local fnFile, e = loadfile( _sFile )
if fnFile then
setfenv( fnFile, getfenv(2) )
return fnFile()
else
error( e, 2 )
end
end
-- Install the rest of the OS api
function os.run( _tEnv, _sPath, ... )
local tArgs = { ... }
local fnFile, err = loadfile( _sPath )
if fnFile then
local tEnv = _tEnv
--setmetatable( tEnv, { __index = function(t,k) return _G[k] end } )
setmetatable( tEnv, { __index = _G } )
setfenv( fnFile, tEnv )
local ok, err = pcall( function()
fnFile( unpack( tArgs ) )
end )
if not ok then
if err and err ~= "" then
printError( err )
end
return false
end
return true
end
if err and err ~= "" then
printError( err )
end
return false
end
rone,rtwo = pcall(func)
local ok, err = pcall(function() fnFile(unpack(tArgs)) end )
part of the bios, but is a little less complicated and probably better suited to your needs.I am using that, like this:You need to use multiple assignment to catch the second return. Like:rone,rtwo = pcall(func)
That corresponds to thepart of the bios, but is a little less complicated and probably better suited to your needs.local ok, err = pcall(function() fnFile(unpack(tArgs)) end )
ok, err = pcall(os.ru({}, program)
but the second variable always return trueLike:…you need to not use os.run(), that prevents error propagation but it doesn't return an error message. Just use "ok,err = pcall(program)"
ok, err = pcall(myProgram, my argument, soOn)
If yes, thank you! If not, please explain me how
atempt to call string
even that I am using
pcall("pahtoprogram/program", args)