Search in sources :

Example 66 with LuaValue

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

the class JavaClass method getMethod.

LuaValue getMethod(LuaValue key) {
    if (methods == null) {
        Map namedlists = new HashMap();
        Method[] m = ((Class) m_instance).getMethods();
        for (int i = 0; i < m.length; i++) {
            Method mi = m[i];
            if (Modifier.isPublic(mi.getModifiers())) {
                String name = mi.getName();
                List list = (List) namedlists.get(name);
                if (list == null) {
                    namedlists.put(name, list = new ArrayList());
                }
                JavaMethod method = JavaMethod.forMethod(mi);
                if (method != null) {
                    //FIXME by song, 做保护
                    list.add(method);
                }
            }
        }
        Map map = new HashMap();
        Constructor[] c = ((Class) m_instance).getConstructors();
        List list = new ArrayList();
        for (int i = 0; i < c.length; i++) if (Modifier.isPublic(c[i].getModifiers()))
            list.add(JavaConstructor.forConstructor(c[i]));
        switch(list.size()) {
            case 0:
                break;
            case 1:
                map.put(NEW, list.get(0));
                break;
            default:
                map.put(NEW, JavaConstructor.forConstructors((JavaConstructor[]) list.toArray(new JavaConstructor[list.size()])));
                break;
        }
        for (Iterator it = namedlists.entrySet().iterator(); it.hasNext(); ) {
            Entry e = (Entry) it.next();
            String name = (String) e.getKey();
            List methods = (List) e.getValue();
            map.put(LuaValue.valueOf(name), methods.size() == 1 ? methods.get(0) : JavaMethod.forMethods((JavaMethod[]) methods.toArray(new JavaMethod[methods.size()])));
        }
        methods = map;
    }
    return (LuaValue) methods.get(key);
}
Also used : HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LuaValue(org.luaj.vm2.LuaValue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 67 with LuaValue

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

the class JavaInstance method set.

public void set(LuaValue key, LuaValue value) {
    if (jclass == null)
        jclass = JavaClass.forClass(m_instance.getClass());
    Field f = jclass.getField(key);
    if (f != null)
        try {
            f.set(m_instance, CoerceLuaToJava.coerce(value, f.getType()));
            return;
        } catch (Exception e) {
            throw new LuaError(e);
        }
    super.set(key, value);
}
Also used : Field(java.lang.reflect.Field) LuaError(org.luaj.vm2.LuaError)

Example 68 with LuaValue

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

the class JavaInstance method get.

public LuaValue get(LuaValue key) {
    if (jclass == null)
        jclass = JavaClass.forClass(m_instance.getClass());
    Field f = jclass.getField(key);
    if (f != null)
        try {
            return CoerceJavaToLua.coerce(f.get(m_instance));
        } catch (Exception e) {
            throw new LuaError(e);
        }
    LuaValue m = jclass.getMethod(key);
    if (m != null)
        return m;
    return super.get(key);
}
Also used : Field(java.lang.reflect.Field) LuaError(org.luaj.vm2.LuaError) LuaValue(org.luaj.vm2.LuaValue)

Example 69 with LuaValue

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

the class JseMathLib method call.

public LuaValue call(LuaValue modname, LuaValue env) {
    super.call(modname, env);
    LuaValue math = env.get("math");
    math.set("acos", new acos());
    math.set("asin", new asin());
    math.set("atan", new atan());
    math.set("atan2", new atan2());
    math.set("cosh", new cosh());
    math.set("exp", new exp());
    math.set("log", new log());
    math.set("pow", new pow());
    math.set("sinh", new sinh());
    math.set("tanh", new tanh());
    return math;
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

Example 70 with LuaValue

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

the class LVCustomViewPagerIndicator method createAndRenderView.

/**
     * 创建一个item
     *
     * @param pos
     * @return
     */
private View createAndRenderView(int pos) {
    final int currentItem = mViewPager.getCurrentItem();
    final LuaValue cellData = createView(pos, currentItem);
    if (cellData instanceof UDLuaTable) {
        //绘制
        mLuaUserdata.callCellLayout(cellData, pos, currentItem);
        return ((UDLuaTable) cellData).getView();
    }
    return null;
}
Also used : UDLuaTable(com.taobao.luaview.userdata.base.UDLuaTable) 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