Jump to content




Unable to string.find for "[[" - CC version 1.63



  • You cannot reply to this topic
4 replies to this topic

#1 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 15 February 2015 - 08:27 PM

Bug:
When trying to string,find for [[ , it will give you:
Lua:1: vm error: java.lang.arrayIndexOutOfBoundsException: 2
What I did:
f=string.find("[[]]","[[")
It happens any time you search for [[ , though. Screenies aren't really necessary here.
edit: also, it happens if you search for "=[[". It gives the same error, but a 3 rather than 2
doubleedit: no, it errors any time you find "[" using string.find in a string.

Edited by Geforce Fan, 15 February 2015 - 08:35 PM.


#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 15 February 2015 - 08:39 PM

Looking at string patterns, you can see that [ and ] serve a similar purpose to that in regexes.

You can pass an optional 4th argument to string.find which is plain. So you would want to have:

-- Find [[ in [[]] from position 1, without using Lua patterns
string.find("[[]]", "[[", 1, true)

This isn't a bug and is the correct behaviour for Lua.

#3 Lignum

  • Members
  • 558 posts

Posted 15 February 2015 - 09:12 PM

You can also prefix the symbol with a percent sign if you prefer.
string.find("[[]]", "%[%[")


#4 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 15 February 2015 - 10:18 PM

Oh. Thank you.

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 February 2015 - 03:24 PM

Moved to Ask a Pro.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users