use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LuaUtil method toTable.
/**
* convert params to LuaTable
*
* @param params
* @return
*/
public static LuaValue toTable(List<?> params) {
if (params != null) {
final LuaTable result = new LuaTable();
if (params.size() > 0) {
Object value = null;
for (int i = 0; i < params.size(); i++) {
value = params.get(i);
result.set(i + 1, toLuaValue(value));
}
}
return result;
}
return LuaValue.NIL;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LuaUtil method toTable.
/**
* convert map to LuaTable
*
* @param params
* @return
*/
public static LuaValue toTable(Map<?, ?> params) {
if (params != null) {
final LuaTable result = new LuaTable();
if (params.size() > 0) {
Object valueObj = null;
LuaValue key = null;
for (final Object keyObj : params.keySet()) {
valueObj = params.get(keyObj);
key = toLuaValue(keyObj);
if (key != LuaValue.NIL) {
result.set(key, toLuaValue(valueObj));
}
}
}
return result;
}
return LuaValue.NIL;
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class DestroyUtil method onDestroyTable.
public static void onDestroyTable(LuaTable table) {
if (table != null) {
LuaValue isDestroy = table.get(KEY_DESTROY);
if (isDestroy == null || !LuaBoolean.TRUE.eq_b(isDestroy)) {
//标志位
table.set(KEY_DESTROY, LuaBoolean.TRUE);
LuaValue value = null;
View view = null;
for (LuaValue key : table.keys()) {
value = table.get(key);
if (value instanceof UDView) {
view = ((UDView) value).getView();
if (view instanceof ViewGroup) {
clearViews((ViewGroup) view);
} else {
((UDView) value).onDestroy();
}
} else if (value instanceof BaseUserdata) {
((BaseUserdata) value).onDestroy();
} else if (value instanceof LuaTable) {
onDestroyTable((LuaTable) value);
}
}
}
}
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class DestroyUtil method onDestroyClosure.
public static void onDestroyClosure(LuaClosure closure) {
if (closure != null) {
if (closure.upValues != null) {
UpValue upValue = null;
for (int i = 0; i < closure.upValues.length; i++) {
upValue = closure.upValues[i];
// if (upValue != null && upValue.array != null) {
// for (LuaValue value : upValue.array) {//destroy upvalues
// if (value instanceof BaseUserdata) {//userdata destory
// ((BaseUserdata) value).onDestroy();
// } else if (value instanceof LuaTable) {//destroy table
// onDestroyTable((LuaTable) value);
// }
// }
// }
closure.upValues[i] = null;
}
closure.upValues = null;
}
}
}
use of org.luaj.vm2.LuaTable in project LuaViewSDK by alibaba.
the class LVCustomViewPagerIndicator method createView.
/**
* create view
*
* @param pos
* @return
*/
private LuaValue createView(int pos, int currentItem) {
Globals globals = this.mLuaUserdata.getGlobals();
//View封装
final LVViewGroup container = createCellLayout();
final UDViewGroup cell = new UDViewGroup(container, globals, null);
//对外数据封装,必须使用LuaTable
final UDLuaTable cellData = new UDLuaTable(cell);
//call init
globals.saveContainer(container);
//初始化
this.mLuaUserdata.callCellInit(cellData, pos, currentItem);
globals.restoreContainer();
//set tag
View view = cellData.getView();
if (view != null) {
view.setTag(Constants.RES_LV_TAG, cellData);
}
return cellData;
}
Aggregations