Mercurial Hosting > luan
comparison core/src/luan/modules/IoLuan.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 | 61afe2a1ce96 |
children | 97d175772fed |
comparison
equal
deleted
inserted
replaced
220:61afe2a1ce96 | 221:ec016471c6eb |
---|---|
22 import java.net.Socket; | 22 import java.net.Socket; |
23 import java.net.ServerSocket; | 23 import java.net.ServerSocket; |
24 import java.net.MalformedURLException; | 24 import java.net.MalformedURLException; |
25 import java.util.List; | 25 import java.util.List; |
26 import java.util.ArrayList; | 26 import java.util.ArrayList; |
27 import luan.Luan; | |
27 import luan.LuanState; | 28 import luan.LuanState; |
28 import luan.LuanTable; | 29 import luan.LuanTable; |
29 import luan.LuanFunction; | 30 import luan.LuanFunction; |
30 import luan.LuanJavaFunction; | 31 import luan.LuanJavaFunction; |
31 import luan.LuanException; | 32 import luan.LuanException; |
33 | 34 |
34 public final class IoLuan { | 35 public final class IoLuan { |
35 | 36 |
36 public static final LuanFunction LOADER = new LuanFunction() { | 37 public static final LuanFunction LOADER = new LuanFunction() { |
37 @Override public Object call(LuanState luan,Object[] args) { | 38 @Override public Object call(LuanState luan,Object[] args) { |
38 LuanTable module = new LuanTable(); | 39 LuanTable module = Luan.newTable(); |
39 try { | 40 try { |
40 add( module, "File", LuanState.class, String.class ); | 41 add( module, "File", LuanState.class, String.class ); |
41 add( module, "read_console_line", String.class ); | 42 add( module, "read_console_line", String.class ); |
42 | 43 |
43 LuanTable stdin = new LuanTable(); | 44 LuanTable stdin = Luan.newTable(); |
44 stdin.put( "read_text", new LuanJavaFunction( | 45 stdin.put( "read_text", new LuanJavaFunction( |
45 IoLuan.class.getMethod( "stdin_read_text" ), null | 46 IoLuan.class.getMethod( "stdin_read_text" ), null |
46 ) ); | 47 ) ); |
47 stdin.put( "read_binary", new LuanJavaFunction( | 48 stdin.put( "read_binary", new LuanJavaFunction( |
48 IoLuan.class.getMethod( "stdin_read_binary" ), null | 49 IoLuan.class.getMethod( "stdin_read_binary" ), null |
131 }; | 132 }; |
132 return writer(luanWriter); | 133 return writer(luanWriter); |
133 } | 134 } |
134 | 135 |
135 private static LuanTable writer(LuanWriter luanWriter) { | 136 private static LuanTable writer(LuanWriter luanWriter) { |
136 LuanTable writer = new LuanTable(); | 137 LuanTable writer = Luan.newTable(); |
137 try { | 138 try { |
138 writer.put( "write", new LuanJavaFunction( | 139 writer.put( "write", new LuanJavaFunction( |
139 LuanWriter.class.getMethod( "write", LuanState.class, new Object[0].getClass() ), luanWriter | 140 LuanWriter.class.getMethod( "write", LuanState.class, new Object[0].getClass() ), luanWriter |
140 ) ); | 141 ) ); |
141 writer.put( "close", new LuanJavaFunction( | 142 writer.put( "close", new LuanJavaFunction( |
147 return writer; | 148 return writer; |
148 } | 149 } |
149 | 150 |
150 | 151 |
151 public static LuanTable binaryWriter(final OutputStream out) { | 152 public static LuanTable binaryWriter(final OutputStream out) { |
152 LuanTable writer = new LuanTable(); | 153 LuanTable writer = Luan.newTable(); |
153 try { | 154 try { |
154 writer.put( "write", new LuanJavaFunction( | 155 writer.put( "write", new LuanJavaFunction( |
155 OutputStream.class.getMethod( "write", new byte[0].getClass() ), out | 156 OutputStream.class.getMethod( "write", new byte[0].getClass() ), out |
156 ) ); | 157 ) ); |
157 writer.put( "close", new LuanJavaFunction( | 158 writer.put( "close", new LuanJavaFunction( |
236 int n = blockSize!=null ? blockSize : Utils.bufSize; | 237 int n = blockSize!=null ? blockSize : Utils.bufSize; |
237 return blocks(inputStream(),n); | 238 return blocks(inputStream(),n); |
238 } | 239 } |
239 | 240 |
240 LuanTable table() { | 241 LuanTable table() { |
241 LuanTable tbl = new LuanTable(); | 242 LuanTable tbl = Luan.newTable(); |
242 try { | 243 try { |
243 tbl.put( "to_string", new LuanJavaFunction( | 244 tbl.put( "to_string", new LuanJavaFunction( |
244 LuanIn.class.getMethod( "to_string" ), this | 245 LuanIn.class.getMethod( "to_string" ), this |
245 ) ); | 246 ) ); |
246 tbl.put( "read_text", new LuanJavaFunction( | 247 tbl.put( "read_text", new LuanJavaFunction( |
356 | 357 |
357 public LuanTable children(LuanState luan) throws LuanException { | 358 public LuanTable children(LuanState luan) throws LuanException { |
358 File[] files = file.listFiles(); | 359 File[] files = file.listFiles(); |
359 if( files==null ) | 360 if( files==null ) |
360 return null; | 361 return null; |
361 LuanTable list = new LuanTable(); | 362 LuanTable list = Luan.newTable(); |
362 for( File f : files ) { | 363 for( File f : files ) { |
363 list.add(new LuanFile(luan,f).table()); | 364 list.add(new LuanFile(luan,f).table()); |
364 } | 365 } |
365 return list; | 366 return list; |
366 } | 367 } |