Mercurial Hosting > luan
comparison src/luan/lib/StringLib.java @ 79:805929c3c6e1
add string.format
git-svn-id: https://luan-java.googlecode.com/svn/trunk@80 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 15 Feb 2013 23:12:15 +0000 |
parents | 4bf3d0c0b6b9 |
children | 6db8f286fa6c |
comparison
equal
deleted
inserted
replaced
78:7c08b611125d | 79:805929c3c6e1 |
---|---|
21 LuanTable global = luan.global(); | 21 LuanTable global = luan.global(); |
22 try { | 22 try { |
23 module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) ); | 23 module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) ); |
24 module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) ); | 24 module.put( "char", new LuanJavaFunction(StringLib.class.getMethod("char_",new byte[0].getClass()),null) ); |
25 add( module, "find", String.class, String.class, Integer.class, Boolean.class ); | 25 add( module, "find", String.class, String.class, Integer.class, Boolean.class ); |
26 add( module, "format", String.class, new Object[0].getClass() ); | |
26 add( module, "gmatch", String.class, String.class ); | 27 add( module, "gmatch", String.class, String.class ); |
27 add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class ); | 28 add( module, "gsub", LuanState.class, String.class, String.class, Object.class, Integer.class ); |
28 add( module, "len", String.class ); | 29 add( module, "len", String.class ); |
29 add( module, "lower", String.class ); | 30 add( module, "lower", String.class ); |
30 add( module, "match", String.class, String.class, Integer.class ); | 31 add( module, "match", String.class, String.class, Integer.class ); |
66 } | 67 } |
67 | 68 |
68 public static String char_(byte... bytes) { | 69 public static String char_(byte... bytes) { |
69 return new String(bytes); | 70 return new String(bytes); |
70 } | 71 } |
71 | |
72 // format is hard because String.format() is too stupid to convert ints to floats. | |
73 | 72 |
74 public static int len(String s) { | 73 public static int len(String s) { |
75 return s.length(); | 74 return s.length(); |
76 } | 75 } |
77 | 76 |
208 return new Object[]{ sb.toString(), i }; | 207 return new Object[]{ sb.toString(), i }; |
209 } | 208 } |
210 throw new LuanException( luan, LuanElement.JAVA, "bad argument #3 to 'gsub' (string/function/table expected)" ); | 209 throw new LuanException( luan, LuanElement.JAVA, "bad argument #3 to 'gsub' (string/function/table expected)" ); |
211 } | 210 } |
212 | 211 |
212 // note - String.format() is too stupid to convert between ints and floats. | |
213 public static String format(String format,Object... args) { | |
214 return String.format(format,args); | |
215 } | |
216 | |
213 } | 217 } |