This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Jajnick's profile picture

[1.31][SSP]Java exception while replacing brackets in a string

Started by Jajnick, 14 March 2012 - 05:12 PM
Jajnick #1
Posted 14 March 2012 - 06:12 PM
Hello.
I was debugging my new program when an Java exception was thrown. I'm pretty sure it's not my fault.
Spoiler


ComputerCraft Version Information: 1.31 Client

Description of Bug: java.lang.ArrayIndexOutOfBoundsException exception while replacing square brackets.

Steps to Reproduce Bug:
1.Create new program
2.Write
string.gsub("test [[", "[[", "test")
3.Save changes
4.Run the program.
Advert #2
Posted 15 March 2012 - 05:00 AM
Not a bug, but the error could be better.

You need to escape the brackets in the matching string.


string.gsub("test [[", "%[%[", "test")


See: Programming in Lua, Chapter 20
Jajnick #3
Posted 15 March 2012 - 12:13 PM
Oh, my bad, but shouldn't I see something like:

test:1: <error description>
?
Advert #4
Posted 15 March 2012 - 04:38 PM
Oh, my bad, but shouldn't I see something like:

test:1: <error description>
?

Yes, I mentioned this.

This'd be something that has to be fixed in LuaJ, though – I'm not sure if Dan can.

A wrapper for the string.gsub function could be made, but it'd get messy.