Jump to content




String.gsub error


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

#1 faubiguy

  • Members
  • 213 posts

Posted 09 October 2012 - 09:34 PM

when I attempt to call string.gsub like so:
string.gsub(a_string, "(%a+)%s*(%b())", "any string, table, or function")

It causes the error: vm error: java.lang.ArrayIndexOutOfBoundsException: N, on the line number of the string.gsub call (N is the number of characters in a_string), when a_string both starts and ends with a letter.

This happens whether the '(' and ')' in %b() are escaped or not.

I think it might be a bug, but I'm posting it here in case I'm just doing something wrong.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 October 2012 - 12:24 AM

Interesting. I can reproduce this. I suppose a possible workaround would be to make your own substitution function using string.gmatch or similar, to avoid this issue.

Further investigation suggests that the %bxy pattern is the problematic portion. May I ask what sort of string transformations you're using this for?

#3 faubiguy

  • Members
  • 213 posts

Posted 10 October 2012 - 12:35 AM

I'm matching parentheses to detect functions in my calculator program and catch nonexistent functions, as well as remove any arguments past the number the function takes.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 October 2012 - 12:40 AM

Ah. Well, you may have better luck going through the string a bit more slowly. It might be worth posting a bug report down in the Bugs section, though I think that if this is a bug, it's most likely a bug in LuaJ, so there wouldn't be much that dan200 or Cloudy could do about it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users