Mercurial Hosting > luan
view src/luan/modules/Luan.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 | e8020216dee7 |
children | 198d6af7330a |
line wrap: on
line source
java() local BasicLuan = require "java:luan.modules.BasicLuan" local LuanJava = require "java:luan.Luan" local Luan = {} Luan.get_metatable = BasicLuan.get_metatable Luan.hash_code = BasicLuan.hash_code Luan.ipairs = BasicLuan.ipairs Luan.load = BasicLuan.load Luan.load_file = BasicLuan.load_file Luan.new_error = BasicLuan.new_error Luan.pairs = BasicLuan.pairs Luan.pcall = BasicLuan.pcall Luan.range = BasicLuan.range Luan.raw_equal = BasicLuan.raw_equal Luan.raw_get = BasicLuan.raw_get Luan.raw_len = BasicLuan.raw_len Luan.raw_set = BasicLuan.raw_set Luan.set_metatable = BasicLuan.set_metatable Luan.stringify = BasicLuan.stringify Luan.to_string = BasicLuan.to_string Luan.try = BasicLuan.try_ Luan.type = BasicLuan.type Luan.values = BasicLuan.values function Luan.do_file(uri) return Luan.load_file(uri)() end Luan.VERSION = Luan.do_file "classpath:luan/version.luan" function Luan.error(message) Luan.new_error(message).throw() end function Luan.eval(s,source_name) return Luan.load( "return "..s, source_name or "eval" )() end local error = Luan.error local type = Luan.type or error() local pairs = Luan.pairs or error() Luan.to_table = LuanJava.toTable local function to_luan(obj,to_table) if type(obj) ~= "java" then return obj end obj = to_table(obj) or error("can't convert type "..obj.getClass().getName().." to luan") local tbl = {} for key, value in pairs(obj) do key = to_luan(key,to_table) value = to_luan(value,to_table) tbl[key] = value end return tbl end function Luan.to_luan(obj,to_table) to_table = to_table or Luan.to_table return to_luan(obj,to_table) end return Luan