839 posts
Location
England
Posted 25 November 2012 - 06:35 AM
For some reason, whenever I use string.find on a string without a "." to find a ".", it returns 11 instead of nil.
I'm running MC version 1.4.2 and CC version 1.46.
example code:
print(string.find("hello world","."))--prints 11, should print nil
2447 posts
Posted 25 November 2012 - 06:45 AM
string.find is broken in this implementation of Lua. You are best replacing it with your own function - or appending a blank string to the variable you are using.
2217 posts
Location
3232235883
Posted 25 November 2012 - 07:25 AM
common mistake
its because "." represents all characters
read this:
http://www.lua.org/manual/5.1/manual.html#5.4.1in order to do that you will need to escape it:
print(string.find("hello world","%."))
2447 posts
Posted 25 November 2012 - 11:19 AM
Ah. My point still stands though :D/>/>
389 posts
Location
Norway
Posted 25 November 2012 - 01:30 PM
Yeah, to use string.find() you simply do… string.find(str.."", pattern) :D/>/> it be borked
997 posts
Location
Wellington, New Zealand
Posted 01 December 2012 - 08:36 PM
CC could fix it in bios.lua, by including a wrapper that just appends "" - but it would need to be fixed in the metatable too so str:find("stuff") works.
2217 posts
Location
3232235883
Posted 02 December 2012 - 09:01 AM
CC could fix it in bios.lua, by including a wrapper that just appends "" - but it would need to be fixed in the metatable too so str:find("stuff") works.
metatables of strings are blocked in the bios.lua so you wouldnt need to use anything other than lua
839 posts
Location
England
Posted 02 December 2012 - 09:41 AM
I should have got this closed ages ago, I found out that someone thought it was a good idea to use . as a pattern shortly after starting this post.
common mistake
its because "." represents all characters
read this:
http://www.lua.org/m...nual.html#5.4.1in order to do that you will need to escape it:
print(string.find("hello world","%."))
I really hate that page, the layout is awkward.
2447 posts
Posted 02 December 2012 - 10:22 AM
Your wish is my command.