AgentE382, on 29 April 2014 - 10:14 PM, said:
Have you tried this?
function foobartoo(str)
return string.find(str, '.', -4, true)
end
~6.0E-7 S
Still slower than str:byte()
theoriginalbit, on 30 April 2014 - 02:34 AM, said:
Link149, on 30 April 2014 - 12:54 AM, said:
function foo(str)
return str:match("%....$") and true or false
end
Still, instead of returning a period '.' when successful and nil when unsuccessful, it shall return true or false.

function foo(str)
return str:match("(%.)...$") ~= nil
end
Also ~6.0E-7 S; meaning link's (which is heavier, since there's more math) is slower too.
I'm not particularly worried about how the output is; as long as I can say something like 'if foo(str) then', the function will work for me.
Lyqyd, on 30 April 2014 - 03:38 AM, said:
Link149, on 30 April 2014 - 12:54 AM, said:
function foo(str)
return str:match("%....$") and true or false
end
I thought I would shorten Lyqyd's code snippet by using "{3}" as a quantifier instead of writing three periods in a row, but it seems Lua does not support them.
Still, instead of returning a period '.' when successful and nil when unsuccessful, it shall return true or false.

How is ".{3}" shorter than "..." anyway?
Link - What syntax is that? It's regex, right? Cause match isn't regex. It's not even particularly close.
Lyqyd - I think Link wanted to know which was faster. (shorten == less time) It would make sense if it were, since '....' is four operations, and '.{3}' should be two (if this were regex).
Edited by skwerlman, 30 April 2014 - 10:13 AM.