use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class JsonUtil method toLuaTable.
/**
* 将JSONObject转成LuaTable
*
* @param obj
* @return
*/
public static LuaValue toLuaTable(JSONArray obj) {
LuaValue result = LuaValue.NIL;
if (obj != null) {
//只要不空,就创建一个table
result = new LuaTable();
if (obj.length() > 0) {
for (int i = 0; i < obj.length(); i++) {
final int key = i + 1;
final Object value = obj.opt(i);
result.set(key, toLuaValue(value));
}
}
}
return result;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class JsonUtil method toLuaTable.
/**
* 将JSONObject转成LuaTable
*
* @param obj
* @return
*/
public static LuaValue toLuaTable(JSONObject obj) {
LuaValue result = LuaValue.NIL;
if (obj != null) {
result = new LuaTable();
if (obj.length() > 0) {
//只要不空,就创建一个table
Iterator<String> iter = obj.keys();
while (iter.hasNext()) {
final String key = iter.next();
final Object value = obj.opt(key);
result.set(key, toLuaValue(value));
}
}
}
return result;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LuaUtil method toMap.
/**
* convert a table to map
*
* @param table
* @return
*/
public static Map<String, String> toMap(LuaTable table) {
if (table != null) {
final Map<String, String> result = new HashMap<String, String>();
final LuaValue[] keys = table.keys();
LuaValue value = null;
for (LuaValue key : keys) {
value = table.get(key);
result.put(key.optjstring(null), value.optjstring(null));
}
}
return null;
}
Aggregations