1214 posts
Location
The Sammich Kingdom
Posted 19 August 2012 - 10:02 AM
How would I split up a string? For instance I want to have a program that checks which words are types for instance: lights on.
Or something pretty basic like that, I know the obvious answer is to make a lights program then use args to turn on/off but I basically want to have a program to control the whole system (add users, del users, perms) and stuff like that.
992 posts
Posted 19 August 2012 - 10:14 AM
no read() cant split up a string
string.match() can
string.gmath() can
string.sub() can
But it depends on what you are trying to do
http://www.lua.org/manual/5.1/manual.html#pdf-string.sub
839 posts
Location
England
Posted 19 August 2012 - 12:09 PM
How would I split up a string? For instance I want to have a program that checks which words are types for instance: lights on.
Or something pretty basic like that, I know the obvious answer is to make a lights program then use args to turn on/off but I basically want to have a program to control the whole system (add users, del users, perms) and stuff like that.
I'd recommend doing something like:
local input = read()
if string.sub(input,1,3) = "Del" then
if string.sub(input,5,9) = "User" then
local user = string.sub(input,10)
DeleteUser(user)
end
end
end
And basically follow that pattern for all commands, not forgetting to account for the spaces between words.
You could also do it by breaking up the words with commas when writing and then in the code creating separate strings for the words between the commas.
8543 posts
Posted 19 August 2012 - 04:20 PM
Take a look at how the shell splits up command arguments to send to the programs it's running. That's how you'll want to do this.