As noted before, I'm relatively new to lua, but again, I learn quick. The last time I got help here, it helped me immensely, and I was able to write a better script. Now I've come to another question that I think will make my life a bit easier. I have no clue what I'm doing with functions, but I'm hoping there is a way to do what I want to do here. Below, you'll see an example of code I have to do to strip down some unneeded elements. Yeah, I realize it's not efficient in the least, so if anyone else has a better idea of how to make it much more efficient, I'm all ears. What I would like to do is create a function with it so that I can strip down whatever variable with a simple call of it (like stripdown(winds)). I appreciate any help that is offered, and any lessons given. Thanks!
winds = string.gsub(winds,"%b<>","")
winds = string.gsub(winds,"%c"," ")
winds = string.gsub(winds," "," ")
winds = string.gsub(winds," "," ")
winds = string.gsub(winds,"^%s*(.-)%s*$", "%1)")
winds = string.gsub(winds," ","")
winds = string.gsub(winds,"/ ", "(")
Josh
This should be slightly better:
function stripdown(str)
return (str:gsub("%b<>","")
:gsub("[%c ]+"," ")
:gsub("^%s*(.-)%s*$", "%1)")
:gsub(" ","")
:gsub("/ ", "("))
end
Reduced 3 of the patterns down to one; The brackets around the return expression reduce the output to only the first return value from gsub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With