Example #1
0
        public static void PrintAllGlobalMethods()
        {
            var hEnviroment = XLLuaRuntime.XLLRT_GetEnv(new IntPtr(0));
            var hEnum       = XLLRT_BeginEnumGlobalAPI(hEnviroment);
            var luaAPI      = new XLLRTGlobalAPI();
            var luaAPIPtr   = Marshal.AllocHGlobal(GLOBAL_API_SIZE);

            while (XLLRT_GetNextGlobalAPI(hEnum, luaAPIPtr))
            {
                luaAPI = (XLLRTGlobalAPI)Marshal.PtrToStructure(luaAPIPtr, typeof(XLLRTGlobalAPI));
                Console.WriteLine("name={0}", luaAPI.funName);
            }
            XLLRT_EndEnum(hEnum);
        }
Example #2
0
 public static void RegisterGlobalAPI(IntPtr hEnviroment, XLRTMethodsInfo info)
 {
     foreach (var methodInfo in info.Methods)
     {
         var pClassMemberGlobalAPI = new XLLRTGlobalAPI {
             permission = 0,
             funName    = methodInfo.Key,
             func       = methodInfo.Value
         };
         XLLRT_RegisterGlobalAPI(hEnviroment, pClassMemberGlobalAPI);
         Console.WriteLine("Return {0}", XLLRT_IsGlobalAPIRegistered(hEnviroment, methodInfo.Key));
         if (XLLRT_IsGlobalAPIRegistered(hEnviroment, methodInfo.Key) == IntPtr.Zero)
         {
             Console.WriteLine("Func {0} has been registed!", methodInfo.Key);
         }
     }
 }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
 public static extern IntPtr XLLRT_RegisterGlobalAPI(IntPtr env, XLLRTGlobalAPI theAPI);