annotate src/luan/cmd_line.luan @ 1260:4b5b84853f6f

replace Table.as_table with Luan.to_table
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Sep 2018 22:32:34 -0600
parents d6d0bd05ad8c
children 5ba660381bd5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
1 local Luan = require "luan:Luan.luan"
554
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
2 local error = Luan.error
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
3 local ipairs = Luan.ipairs or error()
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
4 local load_file = Luan.load_file or error()
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
5 local try = Luan.try or error()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
6 local Table = require "luan:Table.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
7 local Io = require "luan:Io.luan"
554
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
8 local print = Io.print or error()
320
fed1893821bf remove global namespace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 313
diff changeset
9
133
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
10
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
11 local args = {...}
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
12 if #args == 0 then
774
3e30cf310e56 change download to use bitbucket
Franklin Schmidt <fschmidt@gmail.com>
parents: 693
diff changeset
13 print("Luan "..Luan.VERSION)
554
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
14 Io.debug("> ")
133
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
15 else
462
2e79b47d02a2 remove all command line options;
Franklin Schmidt <fschmidt@gmail.com>
parents: 421
diff changeset
16 local file = args[1]
323
cd2924a1052c improve testing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 322
diff changeset
17 Luan.arg = {}
133
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
18 for j,v in ipairs(args) do
462
2e79b47d02a2 remove all command line options;
Franklin Schmidt <fschmidt@gmail.com>
parents: 421
diff changeset
19 Luan.arg[j-1] = v
133
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
20 end
326
db37d6aee4db remove try-catch statement;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 323
diff changeset
21 try {
db37d6aee4db remove try-catch statement;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 323
diff changeset
22 function()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 555
diff changeset
23 local main_file = load_file(file)
554
18504c41b0be move debug() to Io and remove Debug module;
Franklin Schmidt <fschmidt@gmail.com>
parents: 517
diff changeset
24 print( main_file( Table.unpack(Luan.arg) ) )
1175
d6d0bd05ad8c exit on bind conflict, serve "127.0.0.1" for serve_for_nginx
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
25 end
326
db37d6aee4db remove try-catch statement;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 323
diff changeset
26 catch = function(e)
555
e25ba7a2e816 some String documentation and fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 554
diff changeset
27 -- java(); e.java.printStackTrace();
326
db37d6aee4db remove try-catch statement;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 323
diff changeset
28 Io.print_to(Io.stderr, e )
1175
d6d0bd05ad8c exit on bind conflict, serve "127.0.0.1" for serve_for_nginx
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
29 end
326
db37d6aee4db remove try-catch statement;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 323
diff changeset
30 }
133
98aba462c422 add tools/cmd_line.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
31 end