Mercurial Hosting > luan
annotate src/luan/modules/Io.luan @ 1134:e54ae41e9501
cleaner security
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 17 Jan 2018 21:44:46 -0700 |
parents | bae2d0c2576c |
children | 73d754b1889f |
rev | line source |
---|---|
321
7f7708e8fdd4
remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
320
diff
changeset
|
1 java() |
7f7708e8fdd4
remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
320
diff
changeset
|
2 local IoLuan = require "java:luan.modules.IoLuan" |
7f7708e8fdd4
remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
320
diff
changeset
|
3 local System = require "java:java.lang.System" |
297
899253043270
remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
5 local Io = {} |
503 | 6 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
7 Io.ip = IoLuan.ip |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
8 Io.my_ips = IoLuan.my_ips |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
9 Io.read_console_line = IoLuan.read_console_line |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
10 Io.schemes = IoLuan.newSchemes() |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
11 Io.uri = IoLuan.uri |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
12 Io.stdin = IoLuan.defaultStdin.table() |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
13 Io.socket_server = IoLuan.socket_server |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
14 Io.stdout = IoLuan.textWriter(System.out) |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
15 Io.stderr = IoLuan.textWriter(System.err) |
1134 | 16 Io.unrestricted = IoLuan.unrestricted |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
17 |
753
5e3970ccd86a
improve password handling
Franklin Schmidt <fschmidt@gmail.com>
parents:
746
diff
changeset
|
18 -- used by http and rpc |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
19 Io.password = "password" |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
20 |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
680
diff
changeset
|
21 local Luan = require "luan:Luan.luan" |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
22 local error = Luan.error |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
23 local to_string = Luan.to_string or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
24 local type = Luan.type or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
25 local try = Luan.try or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
26 local ipairs = Luan.ipairs or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
27 local pairs = Luan.pairs or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
28 local values = Luan.values or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
29 local load = Luan.load or error() |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
680
diff
changeset
|
30 local Table = require "luan:Table.luan" |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
31 local unpack = Table.unpack or error() |
693
ca169567ce07
module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
680
diff
changeset
|
32 local String = require "luan:String.luan" |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
33 local encode = String.encode or error() |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
34 local matches = String.matches or error() |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
35 |
320
fed1893821bf
remove global namespace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
319
diff
changeset
|
36 |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
37 -- do not change |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
38 function Io.template_write(...) |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
39 return Io.stdout.write(...) |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
40 end |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
41 |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
42 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
43 function Io.print_to(out,...) |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
44 local list = {} |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
45 for v in values(...) do |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
46 list[#list+1] = to_string(v) |
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
47 list[#list+1] = '\t' |
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
48 end |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
49 if #list > 0 then |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
50 list[#list] = '\n' |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
51 out.write( unpack(list) ) |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
52 end |
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
53 end |
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
54 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
55 function Io.print(...) |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
56 Io.print_to(Io.stdout,...) |
298
2ce23c7e2342
remove init.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
297
diff
changeset
|
57 end |
392
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
58 |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
59 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
60 function Io.output_to(out,fn,...) |
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
61 local old_out = Io.stdout |
589
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
62 return try( { |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
63 function(...) |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
64 Io.stdout = out |
589
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
65 fn(...) |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
66 end; |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
67 finally = function() |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
68 Io.stdout = old_out |
589
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
69 end; |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
70 }, ... ) |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
71 end |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
72 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
73 local uri = Io.uri -- make local |
589
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
74 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
75 function Io.output_of(fn,...) |
589
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
76 local string_uri = uri "string:" |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
77 local out = string_uri.text_writer() |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
78 Io.output_to(out,fn,...) |
589
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
79 out.close() |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
80 return string_uri.read_text() |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
81 end |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
82 |
97c8ae330efe
add varargs to Luan.try;
Franklin Schmidt <fschmidt@gmail.com>
parents:
554
diff
changeset
|
83 |
422 | 84 -- repr |
85 | |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
86 local function do_repr(out,obj,strict,done) |
422 | 87 local tp = type(obj) |
88 if tp == "table" then | |
89 if done[obj] == true then | |
591
790d5de23042
add "strict" param to Io.repr();
Franklin Schmidt <fschmidt@gmail.com>
parents:
589
diff
changeset
|
90 strict and error "circular reference" |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
91 out.write "<circular reference>" |
422 | 92 return |
93 end | |
94 done[obj] = true | |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
95 out.write( "{" ) |
422 | 96 local is_first = true |
97 local in_list = {} | |
98 for key, value in ipairs(obj) do | |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
99 if is_first then is_first = false else out.write ", " end |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
100 do_repr(out,value,strict,done) |
422 | 101 in_list[key] = true |
102 end | |
103 for key, value in pairs(obj) do | |
104 if in_list[key] ~= true then | |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
105 if is_first then is_first = false else out.write ", " end |
629
35dde32c02ab
change String.matches()
Franklin Schmidt <fschmidt@gmail.com>
parents:
591
diff
changeset
|
106 if type(key) == "string" and matches(key,"^[a-zA-Z_][a-zA-Z_0-9]*$") ~= nil then |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
107 out.write( key ) |
424 | 108 elseif type(key) == "table" then |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
109 out.write( "[<", key, ">]" ) |
422 | 110 else |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
111 out.write "[" |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
112 do_repr(out,key,strict,done) |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
113 out.write "]" |
422 | 114 end |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
115 out.write "=" |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
116 do_repr(out,value,strict,done) |
422 | 117 end |
118 end | |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
119 out.write "}" |
422 | 120 elseif tp == "string" then |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
121 out.write( '"', encode(obj), '"' ) |
422 | 122 elseif tp == "nil" or tp == "boolean" or tp == "number" then |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
123 out.write( obj ) |
422 | 124 else |
591
790d5de23042
add "strict" param to Io.repr();
Franklin Schmidt <fschmidt@gmail.com>
parents:
589
diff
changeset
|
125 strict and error("can't repr type '"..tp.."' of "..obj) |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
126 out.write( "<", obj, ">" ) |
422 | 127 end |
128 end | |
129 | |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
130 function Io.repr(obj,strict) |
680
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
131 local string_uri = uri "string:" |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
132 local out = string_uri.text_writer() |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
133 do_repr(out,obj,strict or false,{}) |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
134 out.close() |
ecd436959855
improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents:
629
diff
changeset
|
135 return string_uri.read_text() |
422 | 136 end |
137 | |
138 | |
392
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
139 -- useful for SimplyHTML responsiveness |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
140 |
503 | 141 local NO = {} |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
142 Io.NO = NO |
392
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
143 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
144 function Io.dont_write_when_no(write_fn) |
392
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
145 return function(...) |
539
473e456444ff
Remove object-oriented primitive methods for string and binary
Franklin Schmidt <fschmidt@gmail.com>
parents:
503
diff
changeset
|
146 for v in values(...) do |
392
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
147 if v == NO then |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
148 return |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
149 end |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
150 end |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
151 write_fn(...) |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
152 end |
8668f3799ad9
add Io.dont_write_when_no
Franklin Schmidt <fschmidt@gmail.com>
parents:
321
diff
changeset
|
153 end |
503 | 154 |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
155 |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
156 -- debug |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
157 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
158 function Io.debug(prompt) |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
159 prompt = prompt or "luan_debug> " |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
160 local function console() |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
161 return Io.read_console_line(prompt) |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
162 end |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
163 local env = {} |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
164 for line in console do |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
165 try { |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
166 function() |
694
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
167 local fn |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
168 try { |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
169 function() |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
170 fn = load("return "..line,"stdin",env) |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
171 end |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
172 catch = function(e) |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
173 fn = load(line,"stdin",env) |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
174 end |
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
175 } |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
176 Io.print( fn() ) |
694
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
177 end |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
178 catch = function(e) |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
179 Io.print(e) |
694
b620b8e1010f
remove Luan.load() allow_expression param and add Luan.eval()
Franklin Schmidt <fschmidt@gmail.com>
parents:
693
diff
changeset
|
180 end |
554
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
181 } |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
182 end |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
183 end |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
184 |
18504c41b0be
move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents:
539
diff
changeset
|
185 |
1088
bae2d0c2576c
change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
186 return Io |