Ejemplo n.º 1
0
        public static void RegisterGlobalObject(IntPtr hEnviroment, XLRTObjectInfo info)
        {
            int i = 0;

            var pClassMember = Marshal.AllocHGlobal(GLOBAL_API_SIZE * (info.Methods.Count + 1));

            foreach (var methodInfo in info.Methods)
            {
                var pClassMemberGlobalAPI = new XLLRTGlobalAPI
                {
                    permission = 0,
                    funName    = methodInfo.Key,
                    func       = methodInfo.Value
                };
                var pos             = pClassMember.ToInt32() + i * GLOBAL_API_SIZE;
                var pClassMemberPos = new IntPtr(pos);
                Marshal.StructureToPtr(pClassMemberGlobalAPI, pClassMemberPos, false);
                i++;
            }
            var pNullMemberGlobalAPI = new XLLRTGlobalAPI
            {
                permission = 0,
                funName    = null,
                func       = null
            };
            var pNullMemberPos = new IntPtr(pClassMember.ToInt32() + info.Methods.Count * GLOBAL_API_SIZE);

            Marshal.StructureToPtr(pNullMemberGlobalAPI, pNullMemberPos, false);

            var factoryObject = new XLLRTObject
            {
                className       = info.ClassName,
                objName         = info.ObjectName,
                userData        = info.UserData,
                pfnGetObject    = info.GetFunction,
                memberFunctions = pClassMember
            };

            XLLuaRuntime.XLLRT_RegisterGlobalObj(hEnviroment, factoryObject);
            Marshal.FreeHGlobal(pClassMember);
        }
Ejemplo n.º 2
0
        public static void RegisterGlobalObject(IntPtr hEnviroment, XLRTObjectInfo info)
        {
            int i = 0;
            var pClassMember = Marshal.AllocHGlobal(GLOBAL_API_SIZE * (info.Methods.Count + 1));
            foreach (var methodInfo in info.Methods)
            {
                var pClassMemberGlobalAPI = new XLLRTGlobalAPI
                {
                    permission = 0,
                    funName = methodInfo.Key,
                    func = methodInfo.Value
                };
                var pos = pClassMember.ToInt32() + i * GLOBAL_API_SIZE;
                var pClassMemberPos = new IntPtr(pos);
                Marshal.StructureToPtr(pClassMemberGlobalAPI, pClassMemberPos, false);
                i++;
            }
            var pNullMemberGlobalAPI = new XLLRTGlobalAPI
            {
                permission = 0,
                funName = null,
                func = null
            };
            var pNullMemberPos = new IntPtr(pClassMember.ToInt32() + info.Methods.Count * GLOBAL_API_SIZE);
            Marshal.StructureToPtr(pNullMemberGlobalAPI, pNullMemberPos, false);

            var factoryObject = new XLLRTObject
            {
                className = info.ClassName,
                objName = info.ObjectName,
                userData = info.UserData,
                pfnGetObject = info.GetFunction,
                memberFunctions = pClassMember
            };
            XLLuaRuntime.XLLRT_RegisterGlobalObj(hEnviroment, factoryObject);
            Marshal.FreeHGlobal(pClassMember);
        }