Jump to content




shell.run()

computer help lua

8 replies to this topic

#1 Piorjade

  • Members
  • 244 posts
  • LocationComputer, Germany

Posted 19 September 2016 - 07: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 by Piorjade, 19 September 2016 - 07:37 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 September 2016 - 09: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/a...grams/shell#L76

#3 Piorjade

  • Members
  • 244 posts
  • LocationComputer, Germany

Posted 19 September 2016 - 09:52 AM

Aah nice, thank you =)

#4 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 19 September 2016 - 10: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

#5 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 19 September 2016 - 01: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 by MKlegoman357, 20 September 2016 - 04:41 AM.


#6 Lupus590

  • Members
  • 2,019 posts
  • LocationUK

Posted 19 September 2016 - 01:50 PM

View PostMKlegoman357, on 19 September 2016 - 01:21 PM, said:

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 by Lupus590, 20 September 2016 - 01:30 PM.


#7 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 20 September 2016 - 04:40 AM

View PostLupus590, on 19 September 2016 - 01:50 PM, said:

you'll have no APIs with that: http://www.computerc...-a-cc-computer/

How so? All the APIs will already be loaded when any user-made programs run.

#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 September 2016 - 11:48 AM

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.

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 20 September 2016 - 12: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users