This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
diegodan1893's profile picture

[1.45][Lua]Shell.run() doesnt work in apis

Started by diegodan1893, 23 October 2012 - 05:25 PM
diegodan1893 #1
Posted 23 October 2012 - 07:25 PM
I don't know if this is a bug but I think it is.

ComputerCraft Version Information: I get this bug in 1.45 and 1.43 but I don't know if it is in preview versions.

Description of Bug: Shell.run() doesn't work if it is in a API.

Steps to Reproduce Bug: First make a file called "test" (the name doesn't matter) and write in it:

function bug()
shell.run("hello") --replace hello for a existing program in your computer
end

Then in shell run the program LUA and write this:

lua> os.loadAPI("test") --or the name of your test program
lua> test.bug()
it will return:
test:2: attempt to index ? (a nil value)

EDIT: This isn't a bug, faubiguy answered me in this topic: http://www.computercraft.info/forums2/index.php?/topic/5311-luaerror-shellrun-doesnt-work/page__pid__43561__st__20
Cloudy #2
Posted 23 October 2012 - 08:39 PM
Not a bug. Shell doesn't yet exist in the environment that the API's are being loaded in. If you want to use the shell API you will need to pass the shell object to the API function. To revise your code:

function bug(shellObj)
shellObj.run("hello") --replace hello for a existing program in your computer
end

Then in any Lua shell do this:

lua> os.loadAPI("test") --or the name of your test program
lua> test.bug(shell)

And it would work fine.