3 posts
Posted 17 June 2012 - 05:52 AM
If I have a program called "return", with code like:
return 100
How can I get 100 from this program in a different program?
I tried:
shell.run("return")
print(shell.run("return"))
a, b, c = shell.run("return"))
print(a, b, c)
And I couldn't get 100 from any of them. I have absolutely no clue how to do it, as it doesn't work like any other programming language I've ever dealt with.
351 posts
Posted 18 June 2012 - 03:43 PM
The command you are looking for is loadfile(). Check it out in the lua documentation
here and
here. Something like this should work:
a = assert(loadfile("return"))()
3 posts
Posted 19 June 2012 - 01:50 AM
Hmm… try this code:
Return Program:
return_code = 100
Actual Program:
shell.run("return")
if return_code == nil then
print("This test has failed.")
else
print("Success!")
print(return_code)
end
Perfect. Thanks!
2 posts
Posted 02 February 2013 - 08:09 AM
Is there no other way to get return values from a program called form another program?
Cause i dont want to use global variables.
I want to call a program with args and get a return value back.
Someone got an idea?
1688 posts
Location
'MURICA
Posted 02 February 2013 - 08:12 AM
Is there no other way to get return values from a program called form another program?
Cause i dont want to use global variables.
I want to call a program with args and get a return value back.
Someone got an idea?
As stated by kazagistar, you can use loadfile().
There's also dofile(). The difference between the two is that loadfile() returns a function with the program's code, while dofile() immediately runs it.
2 posts
Posted 03 February 2013 - 03:29 AM
Yes. It works with:
returnvalue = assert(loadfile("programname"))("argument")
thx very much