Mercurial Hosting > luan
comparison src/luan/modules/Luan.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 | 781ec0a92bb5 |
comparison
equal
deleted
inserted
replaced
1260:4b5b84853f6f | 1261:198d6af7330a |
---|---|
1 java() | 1 java() |
2 local BasicLuan = require "java:luan.modules.BasicLuan" | 2 local BasicLuan = require "java:luan.modules.BasicLuan" |
3 local LuanJava = require "java:luan.Luan" | |
4 | 3 |
5 local Luan = {} | 4 local Luan = {} |
6 | 5 |
7 Luan.get_metatable = BasicLuan.get_metatable | 6 Luan.get_metatable = BasicLuan.get_metatable |
8 Luan.hash_code = BasicLuan.hash_code | 7 Luan.hash_code = BasicLuan.hash_code |
36 | 35 |
37 function Luan.eval(s,source_name) | 36 function Luan.eval(s,source_name) |
38 return Luan.load( "return "..s, source_name or "eval" )() | 37 return Luan.load( "return "..s, source_name or "eval" )() |
39 end | 38 end |
40 | 39 |
41 | |
42 local error = Luan.error | |
43 local type = Luan.type or error() | |
44 local pairs = Luan.pairs or error() | |
45 | |
46 Luan.to_table = LuanJava.toTable | |
47 | |
48 local function to_luan(obj,to_table) | |
49 if type(obj) ~= "java" then | |
50 return obj | |
51 end | |
52 obj = to_table(obj) or error("can't convert type "..obj.getClass().getName().." to luan") | |
53 local tbl = {} | |
54 for key, value in pairs(obj) do | |
55 key = to_luan(key,to_table) | |
56 value = to_luan(value,to_table) | |
57 tbl[key] = value | |
58 end | |
59 return tbl | |
60 end | |
61 | |
62 function Luan.to_luan(obj,to_table) | |
63 to_table = to_table or Luan.to_table | |
64 return to_luan(obj,to_table) | |
65 end | |
66 | |
67 return Luan | 40 return Luan |