Mercurial Hosting > luan
comparison src/luan/cmd_line.luan @ 1520:d9a5405a3102
try statement
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 21 Jun 2020 18:14:13 -0600 |
parents | 219f2b937f2b |
children | 46cf5137cb6b |
comparison
equal
deleted
inserted
replaced
1519:3ebf9781707c | 1520:d9a5405a3102 |
---|---|
1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | 2 local error = Luan.error |
3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
4 local load_file = Luan.load_file or error() | 4 local load_file = Luan.load_file or error() |
5 local try = Luan.try or error() | |
6 local Table = require "luan:Table.luan" | 5 local Table = require "luan:Table.luan" |
7 local pack = Table.pack or error() | 6 local pack = Table.pack or error() |
8 local unpack = Table.unpack or error() | 7 local unpack = Table.unpack or error() |
9 local Io = require "luan:Io.luan" | 8 local Io = require "luan:Io.luan" |
10 local print = Io.print or error() | 9 local print = Io.print or error() |
18 local file = args[1] | 17 local file = args[1] |
19 Luan.arg = {} | 18 Luan.arg = {} |
20 for j,v in ipairs(args) do | 19 for j,v in ipairs(args) do |
21 Luan.arg[j-1] = v | 20 Luan.arg[j-1] = v |
22 end | 21 end |
23 try { | 22 try |
24 function() | 23 local main_file = load_file(file) or error("file '"..file.."' not found") |
25 local main_file = load_file(file) or error("file '"..file.."' not found") | 24 local rtn = pack( main_file( unpack(Luan.arg) ) ) |
26 local rtn = pack( main_file( unpack(Luan.arg) ) ) | 25 if rtn.n > 0 then |
27 if rtn.n > 0 then | 26 print( unpack(rtn) ) |
28 print( unpack(rtn) ) | |
29 end | |
30 end | 27 end |
31 catch = function(e) | 28 catch e |
32 -- require "java"; e.java.printStackTrace(); | 29 -- require "java"; e.java.printStackTrace(); |
33 Io.print_to(Io.stderr, e ) | 30 Io.print_to(Io.stderr, e ) |
34 end | 31 end |
35 } | |
36 end | 32 end |