Mercurial Hosting > luan
comparison core/src/luan/modules/Io.luan @ 554:18504c41b0be
move debug() to Io and remove Debug module;
Io.print() now doesn't print newline if there is nothing to be printed;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 18 Jun 2015 03:30:18 -0600 |
parents | 473e456444ff |
children | 97c8ae330efe |
comparison
equal
deleted
inserted
replaced
553:b1256e2d19a3 | 554:18504c41b0be |
---|---|
12 M.stdout = IoLuan.textWriter(System.out) | 12 M.stdout = IoLuan.textWriter(System.out) |
13 M.stderr = IoLuan.textWriter(System.err) | 13 M.stderr = IoLuan.textWriter(System.err) |
14 | 14 |
15 | 15 |
16 local Luan = require "luan:Luan" | 16 local Luan = require "luan:Luan" |
17 local to_string = Luan.to_string | 17 local error = Luan.error |
18 local type = Luan.type | 18 local to_string = Luan.to_string or error() |
19 local try = Luan.try | 19 local type = Luan.type or error() |
20 local ipairs = Luan.ipairs | 20 local try = Luan.try or error() |
21 local pairs = Luan.pairs | 21 local ipairs = Luan.ipairs or error() |
22 local values = Luan.values | 22 local pairs = Luan.pairs or error() |
23 local values = Luan.values or error() | |
24 local load = Luan.load or error() | |
23 local Table = require "luan:Table" | 25 local Table = require "luan:Table" |
24 local unpack = Table.unpack | 26 local unpack = Table.unpack or error() |
25 local String = require "luan:String" | 27 local String = require "luan:String" |
26 local encode = String.encode | 28 local encode = String.encode or error() |
27 local matches = String.matches | 29 local matches = String.matches or error() |
28 | 30 |
29 | 31 |
30 function M.print_to(out,...) | 32 function M.print_to(out,...) |
31 local list = {} | 33 local list = {} |
32 for v in values(...) do | 34 for v in values(...) do |
33 list[#list+1] = to_string(v) | 35 list[#list+1] = to_string(v) |
34 list[#list+1] = '\t' | 36 list[#list+1] = '\t' |
35 end | 37 end |
36 if #list == 0 then | 38 if #list > 0 then |
37 out.write( '\n' ) | |
38 else | |
39 list[#list] = '\n' | 39 list[#list] = '\n' |
40 out.write( unpack(list) ) | 40 out.write( unpack(list) ) |
41 end | 41 end |
42 end | 42 end |
43 | 43 |
120 end | 120 end |
121 write_fn(...) | 121 write_fn(...) |
122 end | 122 end |
123 end | 123 end |
124 | 124 |
125 | |
126 -- debug | |
127 | |
128 function M.debug(prompt) | |
129 prompt = prompt or "luan_debug> " | |
130 local function console() | |
131 return M.read_console_line(prompt) | |
132 end | |
133 local env = {} | |
134 for line in console do | |
135 try { | |
136 function() | |
137 local fn = load(line,"stdin",env,true) | |
138 M.print( fn() ) | |
139 end; | |
140 catch = function(e) | |
141 M.print(e) | |
142 end; | |
143 } | |
144 end | |
145 end | |
146 | |
147 | |
125 return M | 148 return M |