comparison core/src/luan/LuanJavaFunction.java @ 221:ec016471c6eb

make LuanTable an interface git-svn-id: https://luan-java.googlecode.com/svn/trunk@222 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 17 Jul 2014 07:49:26 +0000
parents 4a27f24ce2b5
children 0a8e6fdb62f0
comparison
equal deleted inserted replaced
220:61afe2a1ce96 221:ec016471c6eb
200 return null; 200 return null;
201 Object[] a = new Object[Array.getLength(obj)]; 201 Object[] a = new Object[Array.getLength(obj)];
202 for( int i=0; i<a.length; i++ ) { 202 for( int i=0; i<a.length; i++ ) {
203 a[i] = Array.get(obj,i); 203 a[i] = Array.get(obj,i);
204 } 204 }
205 return new LuanTable(new ArrayList<Object>(Arrays.asList(a))); 205 return new LuanTableImpl(new ArrayList<Object>(Arrays.asList(a)));
206 } 206 }
207 }; 207 };
208 208
209 private static RtnConverter getRtnConverter(JavaMethod m,boolean convertArray) { 209 private static RtnConverter getRtnConverter(JavaMethod m,boolean convertArray) {
210 Class<?> rtnType = m.getReturnType(); 210 Class<?> rtnType = m.getReturnType();
367 if( obj == null ) 367 if( obj == null )
368 return null; 368 return null;
369 if( obj instanceof List ) { 369 if( obj instanceof List ) {
370 @SuppressWarnings("unchecked") 370 @SuppressWarnings("unchecked")
371 List<Object> list = (List<Object>)obj; 371 List<Object> list = (List<Object>)obj;
372 return new LuanTable(list); 372 return new LuanTableImpl(list);
373 } 373 }
374 if( obj instanceof Map ) { 374 if( obj instanceof Map ) {
375 @SuppressWarnings("unchecked") 375 @SuppressWarnings("unchecked")
376 Map<Object,Object> map = (Map<Object,Object>)obj; 376 Map<Object,Object> map = (Map<Object,Object>)obj;
377 return new LuanTable(map); 377 return new LuanTableImpl(map);
378 } 378 }
379 if( obj instanceof Set ) { 379 if( obj instanceof Set ) {
380 @SuppressWarnings("unchecked") 380 @SuppressWarnings("unchecked")
381 Set<Object> set = (Set<Object>)obj; 381 Set<Object> set = (Set<Object>)obj;
382 return new LuanTable(set); 382 return new LuanTableImpl(set);
383 } 383 }
384 Class cls = obj.getClass(); 384 Class cls = obj.getClass();
385 if( cls.isArray() && !cls.getComponentType().isPrimitive() ) { 385 if( cls.isArray() && !cls.getComponentType().isPrimitive() ) {
386 Object[] a = (Object[])obj; 386 Object[] a = (Object[])obj;
387 return new LuanTable(Arrays.asList(a)); 387 return new LuanTableImpl(Arrays.asList(a));
388 } 388 }
389 return obj; 389 return obj;
390 } 390 }
391 }; 391 };
392 392
393 private static final ArgConverter ARG_MAP = new ArgConverter() { 393 private static final ArgConverter ARG_MAP = new ArgConverter() {
394 public Object convert(Object obj) { 394 public Object convert(Object obj) {
395 if( obj instanceof LuanTable ) { 395 if( obj instanceof LuanTableImpl ) {
396 LuanTable t = (LuanTable)obj; 396 LuanTableImpl t = (LuanTableImpl)obj;
397 return t.asMap(); 397 return t.asMap();
398 } 398 }
399 return obj; 399 return obj;
400 } 400 }
401 }; 401 };
402 402
403 private static final ArgConverter ARG_LIST = new ArgConverter() { 403 private static final ArgConverter ARG_LIST = new ArgConverter() {
404 public Object convert(Object obj) { 404 public Object convert(Object obj) {
405 if( obj instanceof LuanTable ) { 405 if( obj instanceof LuanTableImpl ) {
406 LuanTable t = (LuanTable)obj; 406 LuanTableImpl t = (LuanTableImpl)obj;
407 if( t.isList() ) 407 if( t.isList() )
408 return t.asList(); 408 return t.asList();
409 } 409 }
410 return obj; 410 return obj;
411 } 411 }
412 }; 412 };
413 413
414 private static final ArgConverter ARG_SET = new ArgConverter() { 414 private static final ArgConverter ARG_SET = new ArgConverter() {
415 public Object convert(Object obj) { 415 public Object convert(Object obj) {
416 if( obj instanceof LuanTable ) { 416 if( obj instanceof LuanTableImpl ) {
417 LuanTable t = (LuanTable)obj; 417 LuanTableImpl t = (LuanTableImpl)obj;
418 if( t.isSet() ) 418 if( t.isSet() )
419 return t.asSet(); 419 return t.asSet();
420 } 420 }
421 return obj; 421 return obj;
422 } 422 }
428 ArgArray(Class cls) { 428 ArgArray(Class cls) {
429 a = (Object[])Array.newInstance(cls.getComponentType(),0); 429 a = (Object[])Array.newInstance(cls.getComponentType(),0);
430 } 430 }
431 431
432 public Object convert(Object obj) { 432 public Object convert(Object obj) {
433 if( obj instanceof LuanTable ) { 433 if( obj instanceof LuanTableImpl ) {
434 LuanTable t = (LuanTable)obj; 434 LuanTableImpl t = (LuanTableImpl)obj;
435 if( t.isList() ) { 435 if( t.isList() ) {
436 try { 436 try {
437 return t.asList().toArray(a); 437 return t.asList().toArray(a);
438 } catch(ArrayStoreException e) {} 438 } catch(ArrayStoreException e) {}
439 } 439 }