Mercurial Hosting > luan
view 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 |
line wrap: on
line source
java() local TableLuan = require "java:luan.modules.TableLuan" local Table = {} Table.clear = TableLuan.clear Table.concat = TableLuan.concat Table.copy = TableLuan.copy Table.hash_value = TableLuan.hash_value Table.insert = TableLuan.insert Table.is_empty = TableLuan.is_empty Table.pack = TableLuan.pack Table.remove = TableLuan.remove Table.size = TableLuan.size Table.sort = TableLuan.sort Table.unpack = TableLuan.unpack local Luan = require "luan:Luan.luan" local error = Luan.error local type = Luan.type or error() local pairs = Luan.pairs or error() local LuanJava = require "java:luan.Luan" local toTable = LuanJava.toTable or error() function Table.java_to_table_shallow(obj) return toTable(obj) or error("can't convert type "..obj.getClass().getName().." to table") end local to_luan, deepen function to_luan(obj,java_to_table_shallow) return type(obj)=="java" and deepen(java_to_table_shallow(obj),java_to_table_shallow) or obj end function deepen(tbl,java_to_table_shallow) local rtn = {} for key, value in pairs(tbl) do key = to_luan(key,java_to_table_shallow) value = to_luan(value,java_to_table_shallow) rtn[key] = value end return rtn end function Table.java_to_table_deep(obj,java_to_table_shallow) java_to_table_shallow = java_to_table_shallow or Table.java_to_table_shallow return deepen(java_to_table_shallow(obj),java_to_table_shallow) end return Table