Название: Optimalization command to command inside Отправлено: truefriend-cz от 07 августа 2017, 10:50:28 Hi. I optimalizing code and have question. I can join this two line to one? How?
i = 'image_for_show' Код: i = i:gsub('^%l', string.upper) -- first letter upper Название: Re: Optimalization command to command inside Отправлено: zed от 07 августа 2017, 14:01:25 I think that it's impossible to join this two operations to one and that you should ask such questions on https://stackoverflow.com/
Название: Re: Optimalization command to command inside Отправлено: Михаил от 07 августа 2017, 15:38:09 Код: i = i:gsub('^%l', string.upper):gsub('_', ' ') Название: Re: Optimalization command to command inside Отправлено: zed от 07 августа 2017, 15:54:24 Михаил
This is not an optimization. Here is still 2 calls of "gsub". Название: Re: Optimalization command to command inside Отправлено: Михаил от 07 августа 2017, 16:07:47 1. The question was: "I can join this two line to one? How?". This is optimization by code lines number that user asks.
2. And at the same time this is optimization by code execution: it removes medium temporary saves/loads from string variable "i". Название: Re: Optimalization command to command inside Отправлено: truefriend-cz от 07 августа 2017, 17:38:10 Михаил yes, it is great optimalization. Thank you.
And,.. I can have a condition that would also create a variable? Equivalent for: Код: var = re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]], 1) Example idea: url http://www.domain.tld/index.php Код: if re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]], 1) then --- --- --- Example idea/solution from my coding, but not accepted in LUA: Код: if var=re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]], 1) then Код: if var:re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]], 1) then Код: if re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]], 1)>>var then Код: for var in re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]]) do Название: Re: Optimalization command to command inside Отправлено: Михаил от 07 августа 2017, 18:49:19 Lua havn't such syntax. You should write:
Код: local var = re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]], 1) Код: if re.find(hc.url, [[\.(htm|html|php|php3|php5|asp|aspx)(\?|$)]]) then Note that you should use local variables almost everywhere. "local var" is much preferred then "var" Название: Re: Optimalization command to command inside Отправлено: truefriend-cz от 07 августа 2017, 18:56:34 Михаил thank you very much.
Powered by SMF 1.1.3 SMF © 2006, Simple Machines LLC
Joomla Bridge by JoomlaHacks.com |