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

shell.run -> bad argument: string expected

Started by StefannafetS, 05 June 2013 - 04:49 PM
StefannafetS #1
Posted 05 June 2013 - 06:49 PM
Title: [LUA] shell.run -> bad argument: string expected
Hi,
I have made a program called: "paste". I want to run it with shell.run(). The problem I have with shell.run() is that it gives me an error when I give it an argument, it has to be a string but I want it to use the output of a function. the variable command is "pastebin btUYgsHK"

function get_command(command)
  local a = string.find(command," ")
  if a == nil then
	return false
  else
	return string.sub(command,0,a)
  end
end

function get_argument(t)
  local a = string.find(t," ")
  if a == nil then
	return false
  else
	return string.sub(command,a)
  end
end
first I did:

if get_command(command) == "pastebin" then
	  shell.run("paste",get_argument(command))
	  m.write("Pastebin accepted")
end
it gave me the error: "bad argument: string expected, got function". So i tried using a variable instead.

if get_command(command) == "pastebin" then
	  local argument = get_argument(command)
	  shell.run("paste",argument)
	  m.write("Pastebin accepted")
end
I still get the same error as before. Is it possible what I want to do or not? and if so what am I doing wrong?

I think people are going to ask: "Why do you want to do it this way?"
Let me explain: I'm using miscperipherals and I want to create a fully chat controlled computer using the ChatBox. The only thing that doesn't work is this error.
Lyqyd #2
Posted 05 June 2013 - 07:52 PM
Split into new topic.

shell.run can take the whole command in a single string as the first argument now. Try manipulating it all into a single string to run.
Bomb Bloke #3
Posted 05 June 2013 - 08:01 PM
My bet is you've defined "command" as a function at some point, and because you're declaring your functions as global (by omitting the "local" tag in front of them), that'd mean it'd stay loaded as a function until the whole CC computer reboots.

Any function that receives an arguement and titles it "command" would override this, but the "get_argument()" function stores its arguement as "t", and tries to return a substring of "command" anyway. My bet is that that's the actual line returning the error.

You could confirm if this is the case by sticking a "print(command)" statement near the top of the "get_argument()" function.
StefannafetS #4
Posted 06 June 2013 - 02:54 AM
My bet is you've defined "command" as a function at some point, and because you're declaring your functions as global (by omitting the "local" tag in front of them), that'd mean it'd stay loaded as a function until the whole CC computer reboots. Any function that receives an arguement and titles it "command" would override this, but the "get_argument()" function stores its arguement as "t", and tries to return a substring of "command" anyway. My bet is that that's the actual line returning the error. You could confirm if this is the case by sticking a "print(command)" statement near the top of the "get_argument()" function.
I tried this and it worked, thanks :)/>

Split into new topic. shell.run can take the whole command in a single string as the first argument now. Try manipulating it all into a single string to run.
If this would work it would be nice, I can say one thing: "It worked" :)/> no need of extracting complete strings for all their arguments, thanks