111 posts
Location
here
Posted 20 July 2016 - 07:38 PM
I think the title says it all. Are all APIs, like http, textutils, fs or shell loaded into _G, and you can modify them all using _G[''][''] = …?
Are there other things in that global variable? os.loadAPI uses it to load custom APIs? They are some questions I've come through while trying to modify some functions, and I'm still trying to guess it.
Thanks,
~ thecrimulo
8543 posts
Posted 20 July 2016 - 07:42 PM
Everything loaded with os.loadAPI ends up as a table in _G, and these can be modified. Other things, like shell and multishell are provided directly in the environment of programs run inside the shell. These are not in _G (and should never be put in _G), and can also be modified.
111 posts
Location
here
Posted 20 July 2016 - 07:45 PM
And when they are not in _G, can I modify them directly with api.function = function()…?
8543 posts
Posted 20 July 2016 - 07:49 PM
Yep.
463 posts
Location
Star Wars
Posted 20 July 2016 - 09:03 PM
Everything loaded with os.loadAPI ends up as a table in _G, and these can be modified. Other things, like shell and multishell are provided directly in the environment of programs run inside the shell. These are not in _G (and should never be put in _G), and can also be modified.
Why shell and multishell should never be put in _G?
3057 posts
Location
United States of America
Posted 20 July 2016 - 09:04 PM
Why shell and multishell should never be put in _G?
A new shell and multishell instance is required for every program, so that things like shell.getRunningProgram return correct information.
463 posts
Location
Star Wars
Posted 20 July 2016 - 09:41 PM
Why shell and multishell should never be put in _G?
A new shell and multishell instance is required for every program, so that things like shell.getRunningProgram return correct information.
Thanks!
8543 posts
Posted 21 July 2016 - 12:01 AM
KoGY's explanation is correct, but more accurately phrased: the shell and multishell APIs must be provided by the appropriate shell (if any) that a given piece of code is run from. A program run by another program will end up with the same shell instance as its parent, and can manipulate it (which makes it possible to create a program to assign a shell alias, for instance).