Search in sources :

Example 51 with LuaValue

use of org.luaj.vm2.LuaValue in project love-android by hagish.

the class LuaUtils method getFromTableByPath.

public static LuaValue getFromTableByPath(LuaTable t, String path) {
    String[] pathParts = path.split("\\.");
    LuaValue cur = t;
    for (String part : pathParts) {
        LuaValue next = cur.get(part);
        if (next.equals(LuaValue.NIL)) {
            cur = next;
            break;
        } else {
            cur = next;
        }
    }
    return cur;
}
Also used : LuaString(org.luaj.vm2.LuaString) LuaValue(org.luaj.vm2.LuaValue)

Example 52 with LuaValue

use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.

the class UDBaseListOrRecyclerView method callCellSize.

/**
     * return width, height
     *
     * @param cell
     * @param position
     * @return
     */
public int[] callCellSize(LuaValue cell, int position, int... defaultSize) {
    final Varargs size = invokeCellSize(cell, position);
    int defaultWidth = (defaultSize != null && defaultSize.length > 1) ? defaultSize[0] : AndroidUtil.getScreenWidth(getContext());
    int width = 0, height = 0;
    if (size != null) {
        if (size.narg() > 1) {
            //width & height
            width = DimenUtil.dpiToPx(size.arg(1), defaultWidth);
            height = DimenUtil.dpiToPx(size.arg(2));
        } else {
            width = defaultWidth;
            height = DimenUtil.dpiToPx(size.arg(1));
        }
    }
    return new int[] { width, height };
}
Also used : Varargs(org.luaj.vm2.Varargs) Point(android.graphics.Point)

Example 53 with LuaValue

use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.

the class UDBaseListOrRecyclerView method onCellLongClicked.

/**
     * 调用 Callback 方法
     *
     * @param cell
     * @param position
     * @return
     */
public boolean onCellLongClicked(LuaValue cell, int position) {
    final int section = getSectionByPosition(position);
    final int row = getRowInSectionByPosition(position);
    final String id = getId(position, section, row);
    final LuaValue cellData = getCell(id);
    if (cellData != null) {
        final LuaValue callback = cellData.get("Callback");
        if (callback != null && callback.istable()) {
            return LuaUtil.callFunction(LuaUtil.getFunction(callback, "LongClick", "longClick"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row)).optboolean(false);
        }
    }
    return false;
}
Also used : LuaValue(org.luaj.vm2.LuaValue) Point(android.graphics.Point)

Example 54 with LuaValue

use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.

the class UDBaseListOrRecyclerView method onCellClicked.

/**
     * 调用 Callback 方法
     *
     * @param cell
     * @param position
     * @return
     */
public LuaValue onCellClicked(LuaValue cell, int position) {
    final int section = getSectionByPosition(position);
    final int row = getRowInSectionByPosition(position);
    final String id = getId(position, section, row);
    final LuaValue cellData = getCell(id);
    if (cellData != null) {
        final LuaValue callback = cellData.get("Callback");
        if (callback.isfunction()) {
            return LuaUtil.callFunction(callback, cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
        } else if (callback.istable()) {
            return LuaUtil.callFunction(LuaUtil.getFunction(callback, "Click", "click"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
        }
    }
    return NIL;
}
Also used : LuaValue(org.luaj.vm2.LuaValue) Point(android.graphics.Point)

Example 55 with LuaValue

use of org.luaj.vm2.LuaValue in project LuaViewSDK by alibaba.

the class HttpMethodMapper method get.

/**
     * get请求
     *
     * @param http
     * @param varargs
     * @return
     */
public LuaValue get(U http, Varargs varargs) {
    final String url = LuaUtil.getString(varargs, 2);
    final LuaTable params = LuaUtil.getTable(varargs, 3, 2);
    final LuaFunction callback = LuaUtil.getFunction(varargs, 4, 3, 2);
    return http.get(url, params, callback);
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaFunction(org.luaj.vm2.LuaFunction)

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