Exemplo n.º 1
0
        public static void RegisterClass(IntPtr hEnviroment, XLRTClassInfo info)
        {
            int i            = 0;
            var pClassMember = Marshal.AllocHGlobal(GLOBAL_API_SIZE * (info.Methods.Count + 2));

            foreach (var methodInfo in info.Methods)
            {
                var pClassMemberGlobalAPI = new XLLRTGlobalAPI
                {
                    permission = 0,
                    funName    = methodInfo.Key,
                    func       = methodInfo.Value
                };
                var pClassMemberPos = new IntPtr(pClassMember.ToInt32() + i * GLOBAL_API_SIZE);
                Marshal.StructureToPtr(pClassMemberGlobalAPI, pClassMemberPos, false);
                i++;
            }
            var pDeleteMemberGlobalAPI = new XLLRTGlobalAPI
            {
                permission = 0,
                funName    = "__gc",
                func       = info.DeleteFunction
            };
            var pDeleteMemberPos = new IntPtr(pClassMember.ToInt32() + info.Methods.Count * GLOBAL_API_SIZE);

            Marshal.StructureToPtr(pDeleteMemberGlobalAPI, pDeleteMemberPos, false);

            var pNullMemberGlobalAPI = new XLLRTGlobalAPI
            {
                permission = 0,
                funName    = null,
                func       = null
            };
            var pNullMemberPos = new IntPtr(pClassMember.ToInt32() + (info.Methods.Count + 1) * GLOBAL_API_SIZE);

            Marshal.StructureToPtr(pNullMemberGlobalAPI, pNullMemberPos, false);

            XLLuaRuntime.XLLRT_RegisterClass(hEnviroment, info.ClassName, pClassMember, info.FatherClassName, 0);
            Marshal.FreeHGlobal(pClassMember);
        }
Exemplo n.º 2
0
        public static void RegisterClass(IntPtr hEnviroment, XLRTClassInfo info)
        {
            int i = 0;
            var pClassMember = Marshal.AllocHGlobal(GLOBAL_API_SIZE * (info.Methods.Count + 2));
            foreach (var methodInfo in info.Methods)
            {
                var pClassMemberGlobalAPI = new XLLRTGlobalAPI
                {
                    permission = 0,
                    funName = methodInfo.Key,
                    func = methodInfo.Value
                };
                var pClassMemberPos = new IntPtr(pClassMember.ToInt32() + i * GLOBAL_API_SIZE);
                Marshal.StructureToPtr(pClassMemberGlobalAPI, pClassMemberPos, false);
                i++;
            }
            var pDeleteMemberGlobalAPI = new XLLRTGlobalAPI
            {
                permission = 0,
                funName = "__gc",
                func = info.DeleteFunction
            };
            var pDeleteMemberPos = new IntPtr(pClassMember.ToInt32() + info.Methods.Count * GLOBAL_API_SIZE);
            Marshal.StructureToPtr(pDeleteMemberGlobalAPI, pDeleteMemberPos, false);

            var pNullMemberGlobalAPI = new XLLRTGlobalAPI
            {
                permission = 0,
                funName = null,
                func = null
            };
            var pNullMemberPos = new IntPtr(pClassMember.ToInt32() + (info.Methods.Count + 1) * GLOBAL_API_SIZE);
            Marshal.StructureToPtr(pNullMemberGlobalAPI, pNullMemberPos, false);

            XLLuaRuntime.XLLRT_RegisterClass(hEnviroment, info.ClassName, pClassMember, info.FatherClassName, 0);
            Marshal.FreeHGlobal(pClassMember);
        }