Closed GoogleCodeExporter closed 9 years ago
and the patch is even better now that i discovered BaseLib.rawTostring ;e)
Original comment by matej...@gmail.com
on 30 Jun 2009 at 1:37
Attachments:
Confirmed.
I am not quite ready to commit my changes, but here is my proposed fix:
--- a/src/se/krka/kahlua/stdlib/StringLib.java
+++ b/src/se/krka/kahlua/stdlib/StringLib.java
@@ -809,6 +809,9 @@ public final class StringLib implements JavaFunction {
}
public Object[] getCaptures() {
+ if (level <= 0) {
+ return null;
+ }
Object[] caps = new String[level];
for (int i = 0; i < level; i++) {
if (capture[i].len == CAP_POSITION) {
@@ -1432,12 +1435,22 @@ public final class StringLib implements JavaFunction {
String type = BaseLib.type(repl);
if (type == BaseLib.TYPE_NUMBER || type == BaseLib.TYPE_STRING) {
b.append(addString (ms, repl, src, e));
- } else if (type == BaseLib.TYPE_FUNCTION) {
- Object res =
ms.callFrame.thread.state.call(repl,ms.getCaptures());
- b.append(res);
- } else if (type == BaseLib.TYPE_TABLE) {
- Object cap = ms.getCaptures()[0];
- b.append(((LuaTable)repl).rawget(cap));
+ } else {
+ String match = src.getString().substring(0,
e.getIndex() -
src.getIndex());
+ Object[] captures = ms.getCaptures();
+ if (captures != null) {
+ match = BaseLib.rawTostring(captures[0]);
+ }
+ Object res = null;
+ if (type == BaseLib.TYPE_FUNCTION) {
+ res = ms.callFrame.thread.state.call(repl,
match,
null, null);
+ } else if (type == BaseLib.TYPE_TABLE) {
+ res = ((LuaTable)repl).rawget(match);
+ }
+ if (res == null) {
+ res = match;
+ }
+ b.append(BaseLib.rawTostring(res));
}
}
Original comment by kristofer.karlsson@gmail.com
on 2 Jul 2009 at 10:38
Fixed in subversion.
Original comment by kristofer.karlsson@gmail.com
on 6 Jul 2009 at 11:01
Original issue reported on code.google.com by
matej...@gmail.com
on 29 Jun 2009 at 1:04Attachments: