Search in sources :

Example 51 with LuaTable

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

the class JsonUtil method toJSONObject.

public static JSONObject toJSONObject(LuaTable table) {
    JSONObject obj = new JSONObject();
    if (table != null) {
        LuaValue[] keys = table.keys();
        if (keys != null && keys.length > 0) {
            try {
                for (int i = 0; i < keys.length; i++) {
                    String key = keys[i].optjstring("");
                    LuaValue value = table.get(keys[i]);
                    if (value instanceof LuaTable) {
                        obj.put(key, toJSONObject((LuaTable) value));
                    } else {
                        obj.put(key, value);
                    }
                }
            } catch (JSONException e) {
                LogUtil.e("[LuaView Error-toJSONObject]-Json Parse Failed, Reason: Invalid Format!", e);
            }
        }
    }
    return obj;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) LuaValue(org.luaj.vm2.LuaValue)

Example 52 with LuaTable

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

the class JsonUtil method toLuaTable.

/**
     * 将JSONObject转成LuaTable
     *
     * @param obj
     * @return
     */
public static LuaValue toLuaTable(JSONArray obj) {
    LuaValue result = LuaValue.NIL;
    if (obj != null) {
        //只要不空,就创建一个table
        result = new LuaTable();
        if (obj.length() > 0) {
            for (int i = 0; i < obj.length(); i++) {
                final int key = i + 1;
                final Object value = obj.opt(i);
                result.set(key, toLuaValue(value));
            }
        }
    }
    return result;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) JSONObject(org.json.JSONObject) LuaValue(org.luaj.vm2.LuaValue)

Example 53 with LuaTable

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

the class JsonUtil method toLuaTable.

/**
     * 将JSONObject转成LuaTable
     *
     * @param obj
     * @return
     */
public static LuaValue toLuaTable(JSONObject obj) {
    LuaValue result = LuaValue.NIL;
    if (obj != null) {
        result = new LuaTable();
        if (obj.length() > 0) {
            //只要不空,就创建一个table
            Iterator<String> iter = obj.keys();
            while (iter.hasNext()) {
                final String key = iter.next();
                final Object value = obj.opt(key);
                result.set(key, toLuaValue(value));
            }
        }
    }
    return result;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) JSONObject(org.json.JSONObject) LuaValue(org.luaj.vm2.LuaValue)

Example 54 with LuaTable

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

the class LuaUtil method toMap.

/**
     * convert a table to map
     *
     * @param table
     * @return
     */
public static Map<String, String> toMap(LuaTable table) {
    if (table != null) {
        final Map<String, String> result = new HashMap<String, String>();
        final LuaValue[] keys = table.keys();
        LuaValue value = null;
        for (LuaValue key : keys) {
            value = table.get(key);
            result.put(key.optjstring(null), value.optjstring(null));
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) UDSpannableString(com.taobao.luaview.userdata.ui.UDSpannableString) LuaValue(org.luaj.vm2.LuaValue)

Example 55 with LuaTable

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

the class CoroutineLib method call.

public LuaValue call(LuaValue modname, LuaValue env) {
    globals = env.checkglobals();
    LuaTable coroutine = new LuaTable();
    coroutine.set("create", new create());
    coroutine.set("resume", new resume());
    coroutine.set("running", new running());
    coroutine.set("status", new status());
    coroutine.set("yield", new yield());
    coroutine.set("wrap", new wrap());
    env.set("coroutine", coroutine);
    env.get("package").get("loaded").set("coroutine", coroutine);
    return coroutine;
}
Also used : LuaTable(org.luaj.vm2.LuaTable)

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