Mercurial Hosting > luan
comparison src/luan/lib/init.luan @ 139:3b384dc5ca91
replace WebShell.java with web_shell.luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@140 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 13 Jun 2014 12:26:44 +0000 |
parents | 98aba462c422 |
children | c2ee8a717b73 |
comparison
equal
deleted
inserted
replaced
138:06159094b802 | 139:3b384dc5ca91 |
---|---|
1 --Io.stdout.write "this is init.luan\n" | 1 --Io.stdout.write "this is init.luan\n" |
2 | 2 |
3 local function print(...) | 3 function Io.print_to(out,...) |
4 local list = {} | 4 local list = {} |
5 for _,v in Basic.values(...) do | 5 for _,v in Basic.values(...) do |
6 list[#list+1] = to_string(v) | 6 list[#list+1] = to_string(v) |
7 list[#list+1] = '\t' | 7 list[#list+1] = '\t' |
8 end | 8 end |
9 if #list == 0 then | 9 if #list == 0 then |
10 Io.stdout.write( '\n' ) | 10 out.write( '\n' ) |
11 else | 11 else |
12 list[#list] = '\n' | 12 list[#list] = '\n' |
13 Io.stdout.write( Table.unpack(list) ) | 13 out.write( Table.unpack(list) ) |
14 end | 14 end |
15 end | 15 end |
16 | 16 |
17 _G.print = print | 17 function _G.print(...) |
18 | 18 Io.print_to(Io.stdout,...) |
19 end | |
19 | 20 |
20 local Debug = {} | 21 local Debug = {} |
21 Package.loaded.Debug = Debug | 22 Package.loaded.Debug = Debug |
22 _G.Debug = Debug | 23 _G.Debug = Debug |
24 | |
25 function Debug.print_if_something(...) | |
26 if Table.pack(...).n > 0 then | |
27 _G.print(...) | |
28 end | |
29 end | |
23 | 30 |
24 function Debug.debug(prompt) | 31 function Debug.debug(prompt) |
25 prompt = prompt or "luan_debug> " | 32 prompt = prompt or "luan_debug> " |
26 local function console() | 33 local function console() |
27 return Io.read_console_line(prompt) | 34 return Io.read_console_line(prompt) |
28 end | 35 end |
29 for line in console do | 36 for line in console do |
30 try | 37 try |
31 local fn = load(line,"stdin",true,true) | 38 local fn = load(line,"stdin",true,true) |
32 local result = Table.pack( fn() ) | 39 Debug.print_if_something( fn() ) |
33 if result.n > 0 then | |
34 print( Table.unpack(result,1,result.n) ) | |
35 end | |
36 catch e do | 40 catch e do |
37 print(e) | 41 print(e) |
38 end | 42 end |
39 end | 43 end |
40 end | 44 end |