Search in sources :

Example 56 with LuaValue

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;
}
Also used : Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue)

Example 57 with LuaValue

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;
}
Also used : UDData(com.taobao.luaview.userdata.kit.UDData) LuaFunction(org.luaj.vm2.LuaFunction)

Example 58 with LuaValue

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);
    }
}
Also used : UDView(com.taobao.luaview.userdata.ui.UDView) LuaValue(org.luaj.vm2.LuaValue)

Example 59 with LuaValue

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;
    }
}
Also used : Varargs(org.luaj.vm2.Varargs)

Example 60 with LuaValue

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;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) LuaValue(org.luaj.vm2.LuaValue)

Aggregations

LuaValue (org.luaj.vm2.LuaValue)51 LuaTable (org.luaj.vm2.LuaTable)35 Varargs (org.luaj.vm2.Varargs)12 LuaString (org.luaj.vm2.LuaString)9 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)7 UDView (com.taobao.luaview.userdata.ui.UDView)5 LuaFunction (org.luaj.vm2.LuaFunction)5 View (android.view.View)4 LuaError (org.luaj.vm2.LuaError)4 Point (android.graphics.Point)3 ILVView (com.taobao.luaview.view.interfaces.ILVView)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 HorizontalScrollView (android.widget.HorizontalScrollView)2 AerospikeException (com.aerospike.client.AerospikeException)2 UDLuaTable (com.taobao.luaview.userdata.base.UDLuaTable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Field (java.lang.reflect.Field)2