Mercurial Hosting > luan
comparison core/src/luan/modules/IoLuan.java @ 572:f1601a4ce1aa
fix stack when calling meta-methods
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 Jul 2015 21:34:23 -0600 |
parents | 2e79b47d02a2 |
children | 6cc2f047019b |
comparison
equal
deleted
inserted
replaced
571:cd944b010f25 | 572:f1601a4ce1aa |
---|---|
56 public static LuanTable textWriter(final PrintStream out) { | 56 public static LuanTable textWriter(final PrintStream out) { |
57 LuanWriter luanWriter = new LuanWriter() { | 57 LuanWriter luanWriter = new LuanWriter() { |
58 | 58 |
59 public void write(LuanState luan,Object... args) throws LuanException { | 59 public void write(LuanState luan,Object... args) throws LuanException { |
60 for( Object obj : args ) { | 60 for( Object obj : args ) { |
61 out.print( luan.toString(obj) ); | 61 out.print( luan.JAVA.toString(obj) ); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 public void close() { | 65 public void close() { |
66 out.close(); | 66 out.close(); |
72 public static LuanTable textWriter(final Writer out) { | 72 public static LuanTable textWriter(final Writer out) { |
73 LuanWriter luanWriter = new LuanWriter() { | 73 LuanWriter luanWriter = new LuanWriter() { |
74 | 74 |
75 public void write(LuanState luan,Object... args) throws LuanException, IOException { | 75 public void write(LuanState luan,Object... args) throws LuanException, IOException { |
76 for( Object obj : args ) { | 76 for( Object obj : args ) { |
77 out.write( luan.toString(obj) ); | 77 out.write( luan.JAVA.toString(obj) ); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 public void close() throws IOException { | 81 public void close() throws IOException { |
82 out.close(); | 82 out.close(); |
337 LuanWriter luanWriter = new LuanWriter() { | 337 LuanWriter luanWriter = new LuanWriter() { |
338 private final Writer out = new StringWriter(); | 338 private final Writer out = new StringWriter(); |
339 | 339 |
340 public void write(LuanState luan,Object... args) throws LuanException, IOException { | 340 public void write(LuanState luan,Object... args) throws LuanException, IOException { |
341 for( Object obj : args ) { | 341 for( Object obj : args ) { |
342 out.write( luan.toString(obj) ); | 342 out.write( luan.JAVA.toString(obj) ); |
343 } | 343 } |
344 } | 344 } |
345 | 345 |
346 public void close() throws IOException { | 346 public void close() throws IOException { |
347 s = out.toString(); | 347 s = out.toString(); |
550 return classpath( luan, "luan/modules/" + path, addExtension ); | 550 return classpath( luan, "luan/modules/" + path, addExtension ); |
551 } | 551 } |
552 | 552 |
553 public static LuanTable stdin(LuanState luan) throws LuanException { | 553 public static LuanTable stdin(LuanState luan) throws LuanException { |
554 LuanTable io = (LuanTable)PackageLuan.require(luan,"luan:Io"); | 554 LuanTable io = (LuanTable)PackageLuan.require(luan,"luan:Io"); |
555 return (LuanTable)io.get(luan,"stdin"); | 555 return (LuanTable)io.get(luan.JAVA,"stdin"); |
556 } | 556 } |
557 | 557 |
558 public static LuanTable newSchemes() { | 558 public static LuanTable newSchemes() { |
559 LuanTable schemes = new LuanTable(); | 559 LuanTable schemes = new LuanTable(); |
560 try { | 560 try { |
574 | 574 |
575 private static LuanTable schemes(LuanState luan) throws LuanException { | 575 private static LuanTable schemes(LuanState luan) throws LuanException { |
576 LuanTable t = (LuanTable)PackageLuan.loaded(luan).rawGet("luan:Io"); | 576 LuanTable t = (LuanTable)PackageLuan.loaded(luan).rawGet("luan:Io"); |
577 if( t == null ) | 577 if( t == null ) |
578 return newSchemes(); | 578 return newSchemes(); |
579 t = (LuanTable)t.get(luan,"schemes"); | 579 t = (LuanTable)t.get(luan.JAVA,"schemes"); |
580 if( t == null ) | 580 if( t == null ) |
581 return newSchemes(); | 581 return newSchemes(); |
582 return t; | 582 return t; |
583 } | 583 } |
584 | 584 |
587 if( i == -1 ) | 587 if( i == -1 ) |
588 throw luan.exception( "invalid Io.uri name '"+name+"', missing scheme" ); | 588 throw luan.exception( "invalid Io.uri name '"+name+"', missing scheme" ); |
589 String scheme = name.substring(0,i); | 589 String scheme = name.substring(0,i); |
590 String location = name.substring(i+1); | 590 String location = name.substring(i+1); |
591 LuanTable schemes = schemes(luan); | 591 LuanTable schemes = schemes(luan); |
592 LuanFunction opener = (LuanFunction)schemes.get(luan,scheme); | 592 LuanFunction opener = (LuanFunction)schemes.get(luan.JAVA,scheme); |
593 if( opener == null ) | 593 if( opener == null ) |
594 throw luan.exception( "invalid scheme '"+scheme+"' in '"+name+"'" ); | 594 throw luan.exception( "invalid scheme '"+scheme+"' in '"+name+"'" ); |
595 return (LuanTable)Luan.first(luan.call(opener,"<open \""+name+"\">",new Object[]{location,addExtension})); | 595 return (LuanTable)Luan.first(luan.call(opener,"<open \""+name+"\">",new Object[]{location,addExtension})); |
596 } | 596 } |
597 | 597 |