Search in sources :

Example 1 with LuaFunction

use of org.luaj.vm2.LuaFunction in project aerospike-client-java by aerospike.

the class LuaMap method merge.

public LuaMap merge(LuaMap map2, LuaFunction func) {
    HashMap<LuaValue, LuaValue> target = new HashMap<LuaValue, LuaValue>(map.size() + map2.map.size());
    target.putAll(map);
    boolean hasFunc = !(func == null || func.isnil());
    for (Entry<LuaValue, LuaValue> entry : map2.map.entrySet()) {
        if (hasFunc) {
            LuaValue value = map.get(entry.getKey());
            if (value != null) {
                Varargs ret = func.invoke(value, entry.getValue());
                target.put(entry.getKey(), (LuaValue) ret);
                continue;
            }
        }
        target.put(entry.getKey(), entry.getValue());
    }
    return new LuaMap(instance, target);
}
Also used : HashMap(java.util.HashMap) Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue)

Example 2 with LuaFunction

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

the class HttpMethodMapper method post.

/**
 * pos 请求
 *
 * @param http
 * @param varargs
 * @return
 */
public LuaValue post(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.post(url, params, callback);
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaFunction(org.luaj.vm2.LuaFunction)

Example 3 with LuaFunction

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

the class BitmapMethodMapper method sprite.

// --------------------------------------- API --------------------------------------------------
/**
 * 切割bitmap
 *
 * @param bitmap
 * @param varargs
 * @return
 */
public LuaValue sprite(U bitmap, Varargs varargs) {
    final int x = DimenUtil.dpiToPx(varargs.arg(2));
    final int y = DimenUtil.dpiToPx(varargs.arg(3));
    final int width = DimenUtil.dpiToPx(varargs.arg(4));
    final int height = DimenUtil.dpiToPx(varargs.arg(5));
    final LuaFunction callback = LuaUtil.getFunction(varargs, 6);
    return bitmap.sprite(x, y, width, height, callback);
}
Also used : LuaFunction(org.luaj.vm2.LuaFunction)

Example 4 with LuaFunction

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

the class UDViewGroup method children.

/**
 * 提供View的构造环境,注意,callback里面不能有异步操作,否则操作的时序上会混乱
 *
 * @param callback
 * @return
 */
public UDViewGroup children(LuaFunction callback) {
    if (getView() instanceof ViewGroup) {
        Globals globals = getGlobals();
        if (globals != null) {
            globals.pushContainer(getView());
            LuaUtil.callFunction(callback, this);
            globals.popContainer();
        }
    }
    return this;
}
Also used : Globals(org.luaj.vm2.Globals) ViewGroup(android.view.ViewGroup) ILVViewGroup(com.taobao.luaview.view.interfaces.ILVViewGroup)

Example 5 with LuaFunction

use of org.luaj.vm2.LuaFunction 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)

Aggregations

LuaFunction (org.luaj.vm2.LuaFunction)6 LuaTable (org.luaj.vm2.LuaTable)4 LuaValue (org.luaj.vm2.LuaValue)3 Varargs (org.luaj.vm2.Varargs)2 ViewGroup (android.view.ViewGroup)1 UDBitmap (com.taobao.luaview.userdata.kit.UDBitmap)1 UDData (com.taobao.luaview.userdata.kit.UDData)1 ILVViewGroup (com.taobao.luaview.view.interfaces.ILVViewGroup)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Globals (org.luaj.vm2.Globals)1 LuaString (org.luaj.vm2.LuaString)1 LuaThread (org.luaj.vm2.LuaThread)1 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)1