annotate src/luan/modules/Boot.luan @ 1321:307e76ccd0d6

generalize separate logging
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Feb 2019 22:36:55 -0700
parents ca742d51b31f
children f41919741100
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 java()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local System = require "java:java.lang.System"
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local URL = require "java:java.net.URL"
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local BasicLuan = require "java:luan.modules.BasicLuan"
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local new_error = BasicLuan.new_error
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local ipairs = BasicLuan.ipairs
1283
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
7 local set_metatable = BasicLuan.set_metatable
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local StringLuan = require "java:luan.modules.StringLuan"
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local match = StringLuan.match -- String.match
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local IoLuan = require "java:luan.modules.IoLuan"
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local LuanUrl = require "java:luan.modules.url.LuanUrl"
1321
307e76ccd0d6 generalize separate logging
Franklin Schmidt <fschmidt@gmail.com>
parents: 1311
diff changeset
12 IoLuan.unrestricted() -- not right
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local Boot = {}
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local function error(message)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 new_error(message).throw()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 Boot.error = error
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 local function new_LuanIn(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local this = {}
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 this.java = io
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 this.to_string = io.to_string
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 this.to_uri_string = io.to_uri_string
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 this.read_text = io.read_text
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 this.read_binary = io.read_binary
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 this.read_lines = io.read_lines
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 this.read_blocks = io.read_blocks
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 this.exists = io.exists
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 this.checksum = io.checksum
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 this.charset = io.charset
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 this.set_charset = io.set_charset
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 return this
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 Boot.new_LuanIn = new_LuanIn
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 local function new_writer(writer)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 local this = {}
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 this.java = writer
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 this.write = writer.write
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 this.close = writer.close
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 return this
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 function Boot.text_writer(out)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 return new_writer( IoLuan.luanWriter(out) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 Boot.binary_writer = new_writer
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 local function new_LuanIO(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 local this = new_LuanIn(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 this.write = io.write
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 this.write_text = io.write_text
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 function this.text_writer()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 return new_writer( io.text_writer() )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 function this.binary_writer()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 return new_writer( io.binary_writer() )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 return this
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 local schemes = {}
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 function schemes.null(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 return new_LuanIO( IoLuan.nullIO )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 function schemes.string(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 return new_LuanIO( IoLuan.LuanString.new(path) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 function schemes.classpath(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 local cp = IoLuan.classpath(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 return cp and new_LuanIn(cp)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 function schemes.luan(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 return schemes.classpath("luan/modules/"..path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 function schemes.stdin(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 local Io = require "luan:Io.luan"
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 return Io.stdin
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 local function url(path,options)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 return new_LuanIn( LuanUrl.new(URL.new(path),options) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 function schemes.http(path,options)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100 return url( "http:"..path, options )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 function schemes.https(path,options)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 return url( "https:"..path, options )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 local function new_BaseOs(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 local this = new_LuanIO(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 this.wait_for = io.wait_for
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 return this
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 function schemes.os(path,options)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 return new_BaseOs( IoLuan.LuanOs.new(path,options) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 function schemes.bash(path,options)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 return new_BaseOs( IoLuan.LuanBash.new(path,options) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 local function new_LuanFile(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 local this = new_LuanIO(io)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 this.name = io.file.getName
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 this.is_directory = io.file.isDirectory
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 this.is_file = io.file.isFile
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 this.delete = io.delete
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 this.delete_on_exit = io.file.deleteOnExit
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 this.mkdir = io.mkdir
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 this.last_modified = io.file.lastModified
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 this.set_last_modified = io.set_last_modified
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 this.length = io.file.length
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 this.rename_to = io.rename_to
1311
ca742d51b31f don't delete into symbolic links
Franklin Schmidt <fschmidt@gmail.com>
parents: 1286
diff changeset
133 this.is_symbolic_link = io.is_symbolic_link
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 function this.child(name)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 return new_LuanFile( io.child(name) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 function this.children()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 local raw = io.children()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 if raw == nil then
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 return nil
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 local rtn = {}
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 for _, child in ipairs(raw) do
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 rtn[#rtn+1] = new_LuanFile(child)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 return rtn
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 function this.parent()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 return new_LuanFile( io.parent() )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 function this.canonical()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 return new_LuanFile( io.canonical() )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 function this.create_temp_file(prefix,suffix)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 return new_LuanFile( io.create_temp_file(prefix,suffix) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 return this
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 function schemes.file(path)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 return new_LuanFile( IoLuan.LuanFile.new(path) )
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 Boot.schemes = schemes
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 local function uri(name,options)
1286
9eb3a9724853 uri bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1283
diff changeset
174 local scheme, location = match( name, "(?s)^([^:]+):(.*)$" )
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 scheme or error( "invalid Io.uri name '"..name.."', missing scheme" )
1286
9eb3a9724853 uri bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1283
diff changeset
176 local opener = schemes[scheme] or error( "invalid scheme '"..scheme.."' in '"..name.."'" )
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 return opener(location,options)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 Boot.uri = uri
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 function Boot.read(uri_str) -- for PackageLuan.java
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 local u = uri(uri_str)
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 if u==nil or not u.exists() then
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 return nil
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187 return u.read_text()
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 end
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190
1283
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
191 local error_mt = {}
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
192
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
193 function error_mt.__to_string(t)
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
194 return t.java.getLuanStackTraceString()
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
195 end
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
196
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
197 function Boot.new_error_table(ex) -- for LuanException.java
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
198 local this = {}
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
199 set_metatable(this,error_mt)
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
200 this.java = ex
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
201 this.get_message = ex.getMessage
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
202 this.throw = ex.throwThis
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
203 this.get_stack_trace_string = ex.getLuanStackTraceString
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
204 this.get_java_stack_trace_string = ex.getLuanStackTraceString
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
205 return this
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
206 end
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
207
503bde9a7c80 add luan.require() and table.call()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1280
diff changeset
208
1280
781ec0a92bb5 add Boot.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209 return Boot