Mercurial Hosting > luan
comparison src/luan/lib/init.luan @ 128:f0a4abe58593
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@129 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 08 Jun 2014 03:38:25 +0000 |
parents | cba7ed3f06cc |
children | 98aba462c422 |
comparison
equal
deleted
inserted
replaced
127:bcb3a09d0caf | 128:f0a4abe58593 |
---|---|
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 local function print(...) |
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 Io.stdout.write( '\n' ) |
25 prompt = prompt or "luan_debug> " | 25 prompt = prompt or "luan_debug> " |
26 local function console() | 26 local function console() |
27 return Io.read_console_line(prompt) | 27 return Io.read_console_line(prompt) |
28 end | 28 end |
29 for line in console do | 29 for line in console do |
30 local fn = load(line,"stdin",true) | 30 try |
31 local result = Table.pack( fn() ) | 31 local fn = load(line,"stdin",true,true) |
32 if result.n > 0 then | 32 local result = Table.pack( fn() ) |
33 print( Table.unpack(result,1,result.n) ) | 33 if result.n > 0 then |
34 print( Table.unpack(result,1,result.n) ) | |
35 end | |
36 catch e do | |
37 print(e) | |
34 end | 38 end |
35 end | 39 end |
36 end | 40 end |
37 | 41 |
38 | 42 |
73 if i == #args then | 77 if i == #args then |
74 standalone_error "'-e' needs argument" | 78 standalone_error "'-e' needs argument" |
75 return | 79 return |
76 end | 80 end |
77 local cmd = args[i] | 81 local cmd = args[i] |
78 local fn = load(cmd,"(command line)",true) | 82 local fn = load(cmd,"(command line)",true,true) |
79 local result = Table.pack( fn() ) | 83 local result = Table.pack( fn() ) |
80 if result.n > 0 then | 84 if result.n > 0 then |
81 print( Table.unpack(result,1,result.n) ) | 85 print( Table.unpack(result,1,result.n) ) |
82 end | 86 end |
83 elseif arg == "-" then | 87 elseif arg == "-" then |
84 local src = Io.stdin.read_text() | 88 local src = Io.stdin.read_text() |
85 local fn = load(src,"stdin",false) | 89 local fn = load(src,"stdin") |
86 fn() | 90 fn() |
87 return | 91 return |
88 else | 92 else |
89 standalone_error( "unrecognized option '"..arg.."'" ) | 93 standalone_error( "unrecognized option '"..arg.."'" ) |
90 return | 94 return |