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

Grabbing Arguments

Started by Csstform, 23 April 2014 - 02:18 PM
Csstform #1
Posted 23 April 2014 - 04:18 PM
Alright. I know how to grab arguments when the program is run, tArgs and all that, but is there any way to grab text with io.read() or something, then look for arguments in that? Thanks.
OReezy #2
Posted 23 April 2014 - 05:25 PM
Check out the string library.
http://lua-users.org/wiki/StringLibraryTutorial

Once you have your string you can use functions like string.match() to search for words or patterns.
Lyqyd #3
Posted 23 April 2014 - 05:46 PM
Check out how the shell splits them out of the command string if you're looking for similar functionality.
TheOddByte #4
Posted 23 April 2014 - 08:01 PM
Here's a little function that I threw together

function getArguments( mask )
    local args = {}
    local input = read( mask )
    for word in input:gmatch("%S+") do
        table.insert( args, word )
    end
    return args
end
But you should check out this code and the lua wiki aswell to get a better understanding of it.
Csstform #5
Posted 23 April 2014 - 10:10 PM
Thanks, guys!