예제 #1
0
        /// <summary>
        /// Registers methods with [LuaBind] attributes in Lua.
        /// </summary>
        private void RegisterLuaMethods(object obj)
        {
            const BindingFlags flags = BindingFlags.Static | BindingFlags.Instance
                                       | BindingFlags.Public | BindingFlags.NonPublic;

            foreach (var method in obj.GetType().GetMethods(flags))
            {
                var attr = method.GetCustomAttributes(typeof(BindLuaAttribute),
                                                      inherit: false).FirstOrDefault() as BindLuaAttribute;
                if (attr == null)
                {
                    continue;
                }

                var wrapper = new LuaRuntime.MethodWrapper(this, method);
                var fn      = luaRuntime.CreateFunctionFromMethodWrapper(wrapper);

                var name = string.IsNullOrEmpty(attr.Name) ? method.Name : attr.Name;
                luaRuntime.Globals[name] = fn;
            }
        }
예제 #2
0
        /// <summary>
        /// Registers methods with [LuaBind] attributes in Lua.
        /// </summary>
        private void RegisterLuaMethods(object obj)
        {
            const BindingFlags flags = BindingFlags.Static | BindingFlags.Instance
                                       | BindingFlags.Public | BindingFlags.NonPublic;
            foreach (var method in obj.GetType().GetMethods(flags))
            {
                var attr = method.GetCustomAttributes(typeof(BindLuaAttribute),
                    inherit: false).FirstOrDefault() as BindLuaAttribute;
                if (attr == null) continue;

                var wrapper = new LuaRuntime.MethodWrapper(this, method);
                var fn = luaRuntime.CreateFunctionFromMethodWrapper(wrapper);

                var name = string.IsNullOrEmpty(attr.Name) ? method.Name : attr.Name;
                luaRuntime.Globals[name] = fn;
            }
        }