Jump to content




shell.run -> bad argument: string expected


  • You cannot reply to this topic
3 replies to this topic

#1 StefannafetS

  • Members
  • 3 posts

Posted 05 June 2013 - 05: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.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 June 2013 - 06: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.

#3 Bomb Bloke

    Hobbyist Coder

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

Posted 05 June 2013 - 07: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.

#4 StefannafetS

  • Members
  • 3 posts

Posted 06 June 2013 - 01:54 AM

View PostBomb Bloke, on 05 June 2013 - 07:01 PM, said:

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 :)

View PostLyqyd, on 05 June 2013 - 06:52 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users