Search in sources :

Example 81 with LuaValue

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

the class LuaInstance method getLuaValue.

public LuaValue getLuaValue(int type, byte[] buf, int offset, int len) throws AerospikeException {
    if (len <= 0) {
        return LuaValue.NIL;
    }
    switch(type) {
        case ParticleType.STRING:
            byte[] copy = new byte[len];
            System.arraycopy(buf, offset, copy, 0, len);
            return LuaString.valueOf(copy, 0, len);
        case ParticleType.INTEGER:
            if (len <= 4) {
                return LuaInteger.valueOf(Buffer.bytesToInt(buf, offset));
            }
            if (len <= 8) {
                return LuaInteger.valueOf(Buffer.bytesToLong(buf, offset));
            }
            throw new AerospikeException("Lua BigInteger not implemented.");
        case ParticleType.DOUBLE:
            return LuaDouble.valueOf(Buffer.bytesToDouble(buf, offset));
        case ParticleType.BLOB:
            byte[] blob = new byte[len];
            System.arraycopy(buf, offset, blob, 0, len);
            return new LuaBytes(this, blob);
        case ParticleType.JBLOB:
            Object object = Buffer.bytesToObject(buf, offset, len);
            return new LuaJavaBlob(object);
        case ParticleType.LIST:
            {
                LuaUnpacker unpacker = new LuaUnpacker(this, buf, offset, len);
                return unpacker.unpackList();
            }
        case ParticleType.MAP:
            {
                LuaUnpacker unpacker = new LuaUnpacker(this, buf, offset, len);
                return unpacker.unpackMap();
            }
        case ParticleType.GEOJSON:
            // skip the flags
            int ncells = Buffer.bytesToShort(buf, offset + 1);
            int hdrsz = 1 + 2 + (ncells * 8);
            return new LuaGeoJSON(new String(buf, offset + hdrsz, len - hdrsz));
        default:
            return LuaValue.NIL;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) LuaString(org.luaj.vm2.LuaString)

Example 82 with LuaValue

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

the class LuaInstance method getLuaMap.

public LuaMap getLuaMap(Map<?, ?> map) {
    Map<LuaValue, LuaValue> luaMap = new HashMap<LuaValue, LuaValue>(map.size());
    for (Map.Entry<?, ?> entry : map.entrySet()) {
        LuaValue key = getLuaValue(entry.getKey());
        LuaValue value = getLuaValue(entry.getValue());
        luaMap.put(key, value);
    }
    return new LuaMap(this, luaMap);
}
Also used : HashMap(java.util.HashMap) LuaValue(org.luaj.vm2.LuaValue) HashMap(java.util.HashMap) Map(java.util.Map)

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