245 posts
Location
Computer, Germany
Posted 19 September 2016 - 08:36 AM
As stated in my cLinux topic, I want to make ShellAPI dummies, to support programs which use stuff like shell.run()
My question is, how different is shell.run() from os.run() exactly?
Like, couldn't I just do something like this?:
shell.run = function(path, args)
return os.run({}, path, args)
end
Or can I even do something with that (or even coroutines?):
shell.run = function(path, args)
local a = loadfile(path)
return pcall(a, args)
end
Edited on 19 September 2016 - 06:37 AM
7083 posts
Location
Tasmania (AU)
Posted 19 September 2016 - 10:27 AM
shell.run() results in a call of os.run(), but first it performs various helpful tasks such as resolving the path.
https://github.com/alekso56/ComputercraftLua/blob/master/rom/programs/shell#L76
245 posts
Location
Computer, Germany
Posted 19 September 2016 - 10:52 AM
Aah nice, thank you =)
463 posts
Location
Star Wars
Posted 19 September 2016 - 11:34 AM
shell.run offers also the shell API
os.run({
shell = shell,
multishell = multishell
}, path, …)
It have to be loaded into the environment, by starting the program, cause of handling multi threaded programs, to return the exact value (shell.getRunningProgram() for example returns the path of a stack [errors if shell is global])
I hope you understand =)
Sewbacca
1140 posts
Location
Kaunas, Lithuania
Posted 19 September 2016 - 02:21 PM
It's best to simply run 'os.run({}, "shell " .. path .. arguments)' which will run the program with the shell API and the correct shell environment.
Edited on 20 September 2016 - 03:41 AM
2427 posts
Location
UK
Posted 19 September 2016 - 02:50 PM
It's best to simply run 'os.run({}, "shell " .. path .. arguments)' which will run the program with the shell API and the correcy shell environment.
you'll have no APIs with that: http://www.computerc...-a-cc-computer/see below
Edited on 20 September 2016 - 12:30 PM
1140 posts
Location
Kaunas, Lithuania
Posted 20 September 2016 - 05:40 AM
How so? All the APIs will already be loaded when any user-made programs run.
3057 posts
Location
United States of America
Posted 20 September 2016 - 12:48 PM
The shell's environment is blank, thus it will pass a copy of a blank environment to any program it runs. Which, in turn, will not have access to any APIs.
7083 posts
Location
Tasmania (AU)
Posted 20 September 2016 - 01:18 PM
Well, it'll be able to access _G still, and since that's where most of the APIs end up it's not such a problem. Values loaded into the prior global environment
won't be (bearing in mind that's not the same thing as _G), but typically all that'd make you miss is the shell API (and multishell I suppose), which'll be reloaded as the os.run() call is executing a new shell instance.
In much the same manner as bios.lua does.