Search in sources :

Example 11 with LuaTable

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

Example 12 with LuaTable

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

Example 13 with LuaTable

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);
                }
            }
        }
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable) UDView(com.taobao.luaview.userdata.ui.UDView) ViewGroup(android.view.ViewGroup) BaseUserdata(com.taobao.luaview.userdata.base.BaseUserdata) LuaValue(org.luaj.vm2.LuaValue) UDView(com.taobao.luaview.userdata.ui.UDView) View(android.view.View) ILVView(com.taobao.luaview.view.interfaces.ILVView)

Example 14 with LuaTable

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

Example 15 with LuaTable

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;
}
Also used : Globals(org.luaj.vm2.Globals) UDLuaTable(com.taobao.luaview.userdata.base.UDLuaTable) UDViewGroup(com.taobao.luaview.userdata.ui.UDViewGroup) LVViewGroup(com.taobao.luaview.view.LVViewGroup) ILVView(com.taobao.luaview.view.interfaces.ILVView) HorizontalScrollView(android.widget.HorizontalScrollView) UDView(com.taobao.luaview.userdata.ui.UDView) View(android.view.View)

Aggregations

LuaTable (org.luaj.vm2.LuaTable)54 LuaValue (org.luaj.vm2.LuaValue)19 Varargs (org.luaj.vm2.Varargs)16 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)15 LuaError (org.luaj.vm2.LuaError)5 LuaFunction (org.luaj.vm2.LuaFunction)4 View (android.view.View)3 JSONObject (org.json.JSONObject)3 LibFunction (org.luaj.vm2.lib.LibFunction)3 BaseLuaTable (com.taobao.luaview.userdata.base.BaseLuaTable)2 UDView (com.taobao.luaview.userdata.ui.UDView)2 ILVView (com.taobao.luaview.view.interfaces.ILVView)2 List (java.util.List)2 LuanObjImage (net.schattenkind.androidLove.luan.obj.LuanObjImage)2 LuaString (org.luaj.vm2.LuaString)2 Paint (android.graphics.Paint)1 Sensor (android.hardware.Sensor)1 SoundPool (android.media.SoundPool)1 MotionEvent (android.view.MotionEvent)1 ViewGroup (android.view.ViewGroup)1