annotate src/luan/modules/Table.luan @ 1261:198d6af7330a

rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 24 Sep 2018 13:09:16 -0600
parents 4b5b84853f6f
children 81d3a01fbd09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
321
7f7708e8fdd4 remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 320
diff changeset
1 java()
7f7708e8fdd4 remove import statement
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 320
diff changeset
2 local TableLuan = require "java:luan.modules.TableLuan"
297
899253043270 remove PackageLuan.load_lib()
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
3
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
4 local Table = {}
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 497
diff changeset
5
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
6 Table.clear = TableLuan.clear
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
7 Table.concat = TableLuan.concat
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
8 Table.copy = TableLuan.copy
1095
2443152dc2f1 add Luan.hash_code() and Table.hash_value()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1088
diff changeset
9 Table.hash_value = TableLuan.hash_value
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
10 Table.insert = TableLuan.insert
1100
ad6b3b9fef40 add Table.is_empty() and Table.size()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1095
diff changeset
11 Table.is_empty = TableLuan.is_empty
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
12 Table.pack = TableLuan.pack
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
13 Table.remove = TableLuan.remove
1100
ad6b3b9fef40 add Table.is_empty() and Table.size()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1095
diff changeset
14 Table.size = TableLuan.size
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
15 Table.sort = TableLuan.sort
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
16 Table.unpack = TableLuan.unpack
497
55f9f74f1e55 Http.request is now pure luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 407
diff changeset
17
1261
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
18
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
19 local Luan = require "luan:Luan.luan"
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
20 local error = Luan.error
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
21 local type = Luan.type or error()
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
22 local pairs = Luan.pairs or error()
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
23 local LuanJava = require "java:luan.Luan"
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
24 local toTable = LuanJava.toTable or error()
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
25
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
26 function Table.java_to_table_shallow(obj)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
27 return toTable(obj) or error("can't convert type "..obj.getClass().getName().." to table")
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
28 end
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
29
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
30 local to_luan, deepen
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
31
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
32 function to_luan(obj,java_to_table_shallow)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
33 return type(obj)=="java" and deepen(java_to_table_shallow(obj),java_to_table_shallow) or obj
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
34 end
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
35
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
36 function deepen(tbl,java_to_table_shallow)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
37 local rtn = {}
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
38 for key, value in pairs(tbl) do
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
39 key = to_luan(key,java_to_table_shallow)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
40 value = to_luan(value,java_to_table_shallow)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
41 rtn[key] = value
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
42 end
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
43 return rtn
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
44 end
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
45
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
46 function Table.java_to_table_deep(obj,java_to_table_shallow)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
47 java_to_table_shallow = java_to_table_shallow or Table.java_to_table_shallow
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
48 return deepen(java_to_table_shallow(obj),java_to_table_shallow)
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
49 end
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
50
198d6af7330a rename Luan.to_table to Table.java_to_table_shallow and Luan.to_luan to Table.java_to_table_deep
Franklin Schmidt <fschmidt@gmail.com>
parents: 1260
diff changeset
51
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 796
diff changeset
52 return Table