Search in sources :

Example 1 with LuaTable

use of org.luaj.vm2.LuaTable in project LogisticsPipes by RS485.

the class LPASMHookCC method onCCWrappedILuaObject.

public static LuaTable onCCWrappedILuaObject(final LuaTable table, final ILuaObject object) {
    if (object instanceof CCCommandWrapper) {
        LuaTable lpTable = new LPLuaTable((CCCommandWrapper) object);
        LuaValue k = LuaValue.NIL;
        while (true) {
            Varargs n = table.next(k);
            if ((k = n.arg1()).isnil()) {
                break;
            }
            LuaValue v = n.arg(2);
            lpTable.set(k, v);
        }
        ((CCCommandWrapper) object).table = lpTable;
        return lpTable;
    }
    return table;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) CCCommandWrapper(logisticspipes.proxy.cc.wrapper.CCCommandWrapper) Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue)

Example 2 with LuaTable

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

the class LuaViewManager method bindMethods.

/**
     * bind lua functions using method
     *
     * @param factory
     * @param methods
     * @return
     */
public static LuaTable bindMethods(Class<? extends LibFunction> factory, List<Method> methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.size(); i++) {
                LibFunction f = factory.newInstance();
                f.opcode = -1;
                f.method = methods.get(i);
                f.name = methods.get(i).getName();
                env.set(f.name, f);
            }
        }
    } catch (Exception e) {
        throw new LuaError("[Bind Failed] " + e);
    } finally {
        return env;
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaError(org.luaj.vm2.LuaError) LibFunction(org.luaj.vm2.lib.LibFunction)

Example 3 with LuaTable

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

the class LuaViewManager method bind.

/**
     * bind lua functions using opcode
     *
     * @param factory
     * @param methods
     * @return
     */
public static LuaTable bind(Class<? extends LibFunction> factory, String[] methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.length; i++) {
                LibFunction f = factory.newInstance();
                f.opcode = i;
                f.method = null;
                f.name = methods[i];
                env.set(f.name, f);
            }
        }
    } catch (Exception e) {
        throw new LuaError("[Bind Failed] " + e);
    } finally {
        return env;
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaError(org.luaj.vm2.LuaError) LibFunction(org.luaj.vm2.lib.LibFunction)

Example 4 with LuaTable

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

the class LuaViewManager method createMetatable.

//-----------------------------------------metatable--------------------------------------------
/**
     * create metatable for libs
     *
     * @return
     */
public static LuaTable createMetatable(Class<? extends LibFunction> libClass) {
    //get from cache
    LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);
    if (result == null) {
        LuaTable libTable = null;
        if (LuaViewConfig.isUseNoReflection()) {
            final List<String> methodNames = getMapperMethodNames(libClass);
            libTable = LuaViewManager.bind(libClass, methodNames);
        } else {
            final List<Method> methods = getMapperMethods(libClass);
            libTable = LuaViewManager.bindMethods(libClass, methods);
        }
        result = LuaValue.tableOf(new LuaValue[] { LuaValue.INDEX, libTable, LuaValue.NEWINDEX, new NewIndexFunction(libTable) });
        //update cache
        AppCache.getCache(CACHE_METATABLES).put(libClass, result);
    }
    return result;
}
Also used : NewIndexFunction(com.taobao.luaview.fun.mapper.ui.NewIndexFunction) LuaTable(org.luaj.vm2.LuaTable) Method(java.lang.reflect.Method) LuaValue(org.luaj.vm2.LuaValue)

Example 5 with LuaTable

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

the class UDCanvas method getDefaultPaint.

private Paint getDefaultPaint(LuaValue config) {
    if (mPaint == null) {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }
    //config
    if (config instanceof LuaTable) {
        mPaint.reset();
        final LuaValue[] keys = ((LuaTable) config).keys();
        if (keys != null && keys.length > 0) {
            String key;
            LuaValue value;
            for (int i = 0; i < keys.length; i++) {
                if (LuaUtil.isString(keys[i])) {
                    key = keys[i].optjstring(null);
                    if (!TextUtils.isEmpty(key)) {
                        key = key.toLowerCase();
                        value = config.get(keys[i]);
                        if (LuaUtil.isValid(value)) {
                            Integer pos = sPaintAttrIndex.get(key);
                            if (pos == null) {
                                continue;
                            }
                            switch(pos) {
                                case PAINT_COLOR:
                                    mPaint.setColor(ColorUtil.parse(value));
                                    break;
                                case PAINT_ALPHA:
                                    mPaint.setAlpha(LuaUtil.toAlphaInt(value));
                                    break;
                                case PAINT_STROKE_WIDTH:
                                    mPaint.setStrokeWidth(DimenUtil.dpiToPxF((float) value.optdouble(0)));
                                    break;
                                case PAINT_TEXT_SIZE:
                                    mPaint.setTextSize(DimenUtil.spToPx((float) value.optdouble(12.0f)));
                                    break;
                                case PAINT_UNDERLINE:
                                    mPaint.setUnderlineText(value.optboolean(false));
                                    break;
                                case PAINT_STRIKE_THROUGH:
                                    mPaint.setStrikeThruText(value.optboolean(false));
                                    break;
                                case PAINT_BOLD:
                                    mPaint.setFakeBoldText(value.optboolean(false));
                                    break;
                                case PAINT_LETTER_SPACING:
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        mPaint.setLetterSpacing(DimenUtil.dpiToPxF((float) value.optdouble(0)));
                                    }
                                    break;
                                case PAINT_TYPEFACE:
                                    {
                                        String typeface = value.optjstring(null);
                                        if (!TextUtils.isEmpty(typeface)) {
                                            mPaint.setTypeface(getLuaResourceFinder().findTypeface(typeface));
                                        }
                                        break;
                                    }
                                case PAINT_TEXT_SCALE_X:
                                    mPaint.setTextScaleX((float) value.optdouble(1));
                                    break;
                                case PAINT_TEXT_SKEW_X:
                                    mPaint.setTextSkewX((float) value.optdouble(0));
                                    break;
                                case PAINT_LINEAR_TEXT:
                                    mPaint.setLinearText(value.optboolean(false));
                                    break;
                                case PAINT_TEXT_ALIGN:
                                    {
                                        setPaintTextAlign(value);
                                        break;
                                    }
                                case PAINT_STYLE:
                                    {
                                        setPaintStyle(value);
                                        break;
                                    }
                                case PAINT_FILTER_BITMAP:
                                    mPaint.setFilterBitmap(value.optboolean(false));
                                    break;
                            }
                        }
                    }
                }
            }
        }
        //anti alias
        mPaint.setAntiAlias(true);
    }
    return mPaint;
}
Also used : BaseLuaTable(com.taobao.luaview.userdata.base.BaseLuaTable) LuaTable(org.luaj.vm2.LuaTable) Paint(android.graphics.Paint) LuaValue(org.luaj.vm2.LuaValue) Paint(android.graphics.Paint)

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