Search in sources :

Example 16 with LuaValue

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

the class LuanThread method InitLib.

public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    LuaValue _G = vm.get_G();
    _G.set(sMetaName_LuanThread, LuanObjThreadObj.CreateMetaTable(this));
    // / thread = love.thread.newThread( name, filename )
    // / thread = love.thread.newThread( name, file )  -- File file : The file to use as source.
    // / thread = love.thread.newThread( name, data )  -- Data data : The data to use as source.
    // / Creates a new Thread from a File or Data Object.
    t.set("newThread", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            String name = args.checkjstring(1);
            // TODO: param2 ? can be different things
            try {
                return LuaValue.userdataOf(new LuanObjThreadObj(LuanThread.this, name), vm.get_G().get(sMetaName_LuanThread));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    // / thread = love.thread.getThread( name )
    // / Look for a thread and get its object.
    // / TODO: not yet implemented
    t.set("getThread", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.thread.getThread");
            return LuaValue.NONE;
        }
    });
    // / threads = love.thread.getThreads( )
    // / Get all threads.
    // / TODO: not yet implemented
    t.set("getThreads", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.thread.getThreads");
            return LuaValue.NONE;
        }
    });
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Example 17 with LuaValue

use of org.luaj.vm2.LuaValue 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 18 with LuaValue

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

the class UDSpannableString method initSpannableStringBuilder.

private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
    SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
    if (text != null && text.isstring()) {
        spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
    }
    if (spannableStringBuilder.length() > 0) {
        if (config != null && config.istable()) {
            final int end = spannableStringBuilder.length();
            final int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
            final Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
            final String fontName = config.get("fontName").optjstring(null);
            final LuaValue weightValue = config.get("fontWeight");
            final int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));
            final LuaValue styleValue = config.get("fontStyle");
            final int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));
            final Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
            final boolean strikethrough = config.get("strikethrough").optboolean(false);
            final boolean underline = config.get("underline").optboolean(false);
            if (fontSize != -1) {
                // 字体大小
                spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontColor != null) {
                // 字体颜色
                spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontName != null && getLuaResourceFinder() != null) {
                // 字体
                spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {
                // 文字Weight
                spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {
                // 文字样式
                spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (backgroundColor != null) {
                // 背景色
                spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (strikethrough) {
                // 删除线
                spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (underline) {
                // 下划线
                spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) CustomTypefaceSpan(com.taobao.luaview.extend.CustomTypefaceSpan) WeightStyleSpan(com.taobao.luaview.extend.WeightStyleSpan) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) StyleSpan(android.text.style.StyleSpan) WeightStyleSpan(com.taobao.luaview.extend.WeightStyleSpan) LuaValue(org.luaj.vm2.LuaValue) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 19 with LuaValue

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

the class UDHttp method initVarargs.

/**
 * 初始化数据
 */
private void initVarargs() {
    final LuaValue param1 = getInitParam1();
    final LuaFunction callback = LuaUtil.getFunction(initParams, 2);
    final String method = LuaUtil.getString(param1, "method");
    final LuaTable params = LuaUtil.getTable(param1, "params");
    setMethod(method);
    setParams(params);
    setCallback(callback);
    disableConnectionReuseIfNecessary();
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaValue(org.luaj.vm2.LuaValue) LuaFunction(org.luaj.vm2.LuaFunction)

Example 20 with LuaValue

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

the class UDBitmap method init.

/**
 * 初始化
 */
private void init() {
    if (initParams != null) {
        LuaValue data = null;
        if (initParams.isuserdata(1)) {
            data = LuaUtil.getUserdata(initParams, 1);
        } else {
            mUrl = LuaUtil.getString(initParams, 1);
        }
        mCallback = LuaUtil.getFunction(initParams, 2);
        if (data != null) {
            fetchBitmapFromData(data);
        } else {
            fetchBitmapFromUrl(mUrl);
        }
    }
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

Aggregations

LuaValue (org.luaj.vm2.LuaValue)55 LuaTable (org.luaj.vm2.LuaTable)37 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)6 LuaError (org.luaj.vm2.LuaError)6 LuaFunction (org.luaj.vm2.LuaFunction)6 View (android.view.View)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 LuaViewApi (com.taobao.luaview.fun.mapper.LuaViewApi)2 UDLuaTable (com.taobao.luaview.userdata.base.UDLuaTable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2