コード例 #1
0
        private static IntPtr _instanceMethodHandler(int contextId, int classId, Int64 instancePtr, string methodName, IntPtr argumentsBuffer, int bufferSize)
        {
            if (instancePtr != 0 &&
                _exportsInstanceMethods.ContainsKey(classId) &&
                _exportsInstanceMethods[classId].ContainsKey(methodName))
            {
                LuaContext         context  = LuaContext.getContext(contextId);
                LuaObjectReference objRef   = LuaObjectReference.findObject(instancePtr);
                object             instance = objRef.target;
                MethodInfo         m        = _exportsInstanceMethods[classId][methodName];
                if (instance != null && m != null)
                {
                    ArrayList argsArr = parseMethodParameters(context, m, argumentsBuffer, bufferSize);
                    object    ret     = m.Invoke(instance, argsArr != null ? argsArr.ToArray() : null);

                    LuaValue retValue = new LuaValue(ret);

                    LuaObjectEncoder encoder = new LuaObjectEncoder(context);
                    encoder.writeObject(retValue);

                    byte[] bytes = encoder.bytes;
                    IntPtr retPtr;
                    retPtr = Marshal.AllocHGlobal(bytes.Length);
                    Marshal.Copy(bytes, 0, retPtr, bytes.Length);

                    return(retPtr);
                }
            }
            return(IntPtr.Zero);
        }
コード例 #2
0
        private static void _fieldSetter(int contextId, int classId, Int64 instancePtr, string fieldName, IntPtr valueBuffer, int bufferSize)
        {
            if (instancePtr != 0)
            {
                LuaContext         context  = LuaContext.getContext(contextId);
                LuaObjectReference objRef   = LuaObjectReference.findObject(instancePtr);
                object             instance = objRef.target;
                LuaObjectDecoder   decoder  = new LuaObjectDecoder(valueBuffer, bufferSize, context);
                LuaValue           value    = decoder.readObject() as LuaValue;


                if (_exportsProperties.ContainsKey(classId) &&
                    _exportsProperties [classId].ContainsKey(fieldName))
                {
                    PropertyInfo propertyInfo = _exportsProperties [classId] [fieldName];
                    if (instance != null && propertyInfo != null && propertyInfo.CanWrite)
                    {
                        propertyInfo.SetValue(instance, getNativeValueForLuaValue(propertyInfo.PropertyType, value), null);
                    }
                }
                else if (_exportsFields.ContainsKey(classId) &&
                         _exportsFields [classId].ContainsKey(fieldName))
                {
                    FieldInfo fieldInfo = _exportsFields [classId] [fieldName];
                    if (instance != null && fieldInfo != null)
                    {
                        fieldInfo.SetValue(instance, getNativeValueForLuaValue(fieldInfo.FieldType, value));
                    }
                }
            }
        }
コード例 #3
0
        private static IntPtr _fieldGetter(int contextId, int classId, Int64 instancePtr, string fieldName)
        {
            IntPtr retValuePtr = IntPtr.Zero;

            if (instancePtr != 0 &&
                _exportsFields.ContainsKey(classId) &&
                _exportsFields[classId].ContainsKey(fieldName))
            {
                LuaContext         context      = LuaContext.getContext(contextId);
                LuaObjectReference objRef       = LuaObjectReference.findObject(instancePtr);
                object             instance     = objRef.target;
                PropertyInfo       propertyInfo = _exportsFields[classId][fieldName];
                if (instance != null && propertyInfo != null && propertyInfo.CanRead)
                {
                    object   retValue = propertyInfo.GetValue(instance, null);
                    LuaValue value    = new LuaValue(retValue);

                    LuaObjectEncoder encoder = new LuaObjectEncoder(context);
                    encoder.writeObject(value);
                    byte[] bytes = encoder.bytes;
                    retValuePtr = Marshal.AllocHGlobal(bytes.Length);
                    Marshal.Copy(bytes, 0, retValuePtr, bytes.Length);
                }
            }

            return(retValuePtr);
        }
コード例 #4
0
        /// <summary>
        /// 读取一个对象类型
        /// </summary>
        /// <returns>对象</returns>
        public object readObject()
        {
            if (_buffer [_offset] == 'L')
            {
                _offset++;
                string className = readString();
                if (readByte() == ';')
                {
                    //反射对象
                    Type t = Type.GetType(className);
                    if (t != null)
                    {
                        object[] parameters = new object[1];
                        parameters [0] = this;

                        ConstructorInfo ci = t.GetConstructor(new Type[] { typeof(LuaObjectDecoder) });
                        return(ci.Invoke(parameters));
                    }
                }
            }
            else
            {
                Int64 refId = readInt64();
                return(LuaObjectReference.findObject(refId));
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="decoder">对象解码器</param>
        public LuaPointer(LuaObjectDecoder decoder)
            : base(decoder)
        {
            Int64 objRefId = decoder.readInt64();

            _objReference = LuaObjectReference.findObject(objRefId);
        }
コード例 #6
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="decoder">对象解码器</param>
        public LuaObjectDescriptor(LuaObjectDecoder decoder)
            : base(decoder)
        {
            Int64 objRefId = decoder.readInt64();

            _objRef = LuaObjectReference.findObject(objRefId);

            luaObjectId = decoder.readString();
        }
コード例 #7
0
 private static void _destroyInstance(Int64 instancePtr)
 {
     if (instancePtr != 0)
     {
         LuaObjectReference instanceRef = LuaObjectReference.findObject(instancePtr);
         if (instanceRef != null)
         {
             _instances.Remove(instanceRef);
         }
     }
 }
コード例 #8
0
        private static string _instanceDescription(Int64 instancePtr)
        {
            if (instancePtr != 0)
            {
                LuaObjectReference objRef = LuaObjectReference.findObject(instancePtr);
                if (objRef != null)
                {
                    return(objRef.target.ToString());
                }
            }

            return("");
        }
コード例 #9
0
ファイル: UNIEnv.cs プロジェクト: zhongbq88/LuaScriptCore
 private static void setNativeObjectId(Int64 instance, int nativeObjectId, string luaObjectId)
 {
     if (instance != 0)
     {
         LuaObjectReference objRef = LuaObjectReference.findObject(instance);
         LuaBaseObject      luaObj = objRef.target as LuaBaseObject;
         if (luaObj != null)
         {
             luaObj.objectId    = nativeObjectId;
             luaObj.luaObjectId = luaObjectId;
         }
     }
 }
コード例 #10
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="decoder">对象解码器</param>
        public LuaObjectDescriptor(LuaObjectDecoder decoder)
            : base(decoder)
        {
            Int64 objRefId = decoder.readInt64();

            _objRef = LuaObjectReference.findObject(objRefId);

            luaObjectId = decoder.readString();

            //原生类型标识读取
            decoder.readInt32();

            //读取自定义数据
            int userdataSize = decoder.readInt32();

            for (int i = 0; i < userdataSize; i++)
            {
                decoder.readString();
                decoder.readString();
            }
        }