use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class NewIndexFunction method invoke.
@Override
public Varargs invoke(Varargs args) {
LuaValue key = args.arg(2);
Varargs newargs = varargsOf(args.arg(1), args.arg(3));
LuaValue func = metatable.get(key);
if (func.isfunction()) {
//函数调用
func.invoke(newargs);
} else {
LogUtil.d("[LuaView error]", "property not fount :", key.toString());
}
return NONE;
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class UIImageViewMethodMapper method setImage.
public LuaValue setImage(U view, Varargs varargs) {
if (varargs.isstring(2)) {
final String url = varargs.optjstring(2, null);
final LuaFunction callback = varargs.optfunction(3, null);
return view.setImageUrl(url, callback);
} else if (varargs.arg(2) instanceof UDData) {
//data
final UDData data = (UDData) varargs.arg(2);
return view.setImageBitmap(data != null ? data.bytes() : null);
}
return view;
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class LVCustomPanel method callLuaCallback.
/**
* 子类实现该方法,用于Lua回调该方法
*/
public void callLuaCallback(Object... objs) {
UDView userdata = getUserdata();
if (userdata != null) {
final LuaValue callback = userdata.getCallback();
LuaUtil.callFunction(callback, objs);
}
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class UDBaseRecyclerView method getId.
/**
* 由于该函数的特殊性,有则获取无则生成。
* 对于生成,有Pinned.YES标记的Id,会先加后缀(".PINNED"+position),再存放到mIdCache中;
* 对于获取,用mPinnedPositionCellId缓存的Lua定义的真实的Id。
*
* @param position
* @param section
* @param row
* @return
*/
@Override
protected String getId(int position, int section, int row) {
final String cacheId = mIdCache != null ? mIdCache.get(position) : null;
if (cacheId != null) {
if (this.mIsPinnedSparseArray.get(position)) {
// 获取CellId的时候,要用lua定义的真正的Id
return mPinnedPositionCellId.get(position);
}
return cacheId;
} else {
String id = null;
Varargs args = LuaUtil.invokeFunction(mCellDelegate.get("Id"), LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
if (args != null) {
if (args.narg() > 1) {
if (args.arg(2).toint() == UDPinned.PINNED_YES) {
mHasPinnedCell = true;
mIsPinnedSparseArray.put(position, true);
id = args.arg(1).optjstring("");
/**
* 构造唯一的id,使得在lua用同一种Cell作为多个position的PinnedCell时,也会有不同的viewType.
* 见 {@link UDBaseRecyclerView#getItemViewType(int)}
*/
mPinnedPositionCellId.put(position, id);
id = new StringBuffer(id).append(".PINNED").append(position).toString();
} else {
id = args.arg(1).optjstring("");
}
} else {
// 兼容旧版本的写法,只有一个String参数的情况
id = ((LuaValue) args).optjstring("");
}
}
if (mIdCache != null) {
mIdCache.put(position, id);
}
return id;
}
}
use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.
the class JsonUtil method toJSONObject.
public static JSONObject toJSONObject(LuaTable table) {
JSONObject obj = new JSONObject();
if (table != null) {
LuaValue[] keys = table.keys();
if (keys != null && keys.length > 0) {
try {
for (int i = 0; i < keys.length; i++) {
String key = keys[i].optjstring("");
LuaValue value = table.get(keys[i]);
if (value instanceof LuaTable) {
obj.put(key, toJSONObject((LuaTable) value));
} else {
obj.put(key, value);
}
}
} catch (JSONException e) {
LogUtil.e("[LuaView Error-toJSONObject]-Json Parse Failed, Reason: Invalid Format!", e);
}
}
}
return obj;
}
Aggregations