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

[Lua] Call a program with parameters from terminal

Started by Meni, 17 December 2012 - 11:58 AM
Meni #1
Posted 17 December 2012 - 12:58 PM
Think that i have a program. Like: test.
test program:

function f(x)
	print(x+1)
end
I wanna call test with a value for x but from terminal, like:

>test 4
5

Hope you help me guys!
remiX #2
Posted 17 December 2012 - 01:06 PM
Simple, using arguments:


args = {...}  -- The ... are for arguments, the {} is to declare it as a table.
x = tonumber(args[1])  -- It is initially a string, this will convert the string to a number.
print(x+1)

Usage: test 4
Output: 5
Meni #3
Posted 17 December 2012 - 01:26 PM
Thank you very much men! You helped me much!