Exemple #1
0
        private void RegisterAssemblyTypes(Assembly assembly)
        {
            var types = assembly.GetTypes().Where(x => x.GetCustomAttribute <LunarBindHideAttribute>() == null && x.GetCustomAttribute <LunarBindIgnoreAssemblyAddAttribute>() == null);

            foreach (var type in types)
            {
                if (type.IsEnum)
                {
                    var enumAttr = (LunarBindEnumAttribute)type.GetCustomAttribute(typeof(LunarBindEnumAttribute));
                    if (enumAttr != null)
                    {
                        BindingHelpers.CreateBindEnum(bindItems, enumAttr.Name ?? type.Name, type);
                    }
                }
                else
                {
                    var instantiable = (LunarBindInstanceAttribute)type.GetCustomAttribute(typeof(LunarBindInstanceAttribute));
                    if (instantiable != null)
                    {
                        var constructor = type.GetConstructor(new Type[] { });
                        if (constructor != null)
                        {
                            object instance = constructor.Invoke(new object[] { });
                            RegisterUserDataType(type);
                            var bindObj = BindingHelpers.CreateBindUserObject(bindItems, instantiable.Path, instance);
                            var doc     = type.GetCustomAttribute <LunarBindDocumentationAttribute>()?.Data ?? "";
                            var ex      = type.GetCustomAttribute <LunarBindExampleAttribute>()?.Data ?? "";
                            bindObj.Documentation = doc;
                            bindObj.Example       = ex;


                            //AddGlobalObject(instantiable.Path, instance);
                        }
                        else
                        {
                            //TODO: custom exception
                            throw new Exception($"LunarBind: No public empty constructor found on Type [{type.Name}] with LunarBindInstantiableAttribute");
                        }
                    }

                    var staticAttribute = (LunarBindStaticAttribute)type.GetCustomAttribute(typeof(LunarBindStaticAttribute));
                    if (staticAttribute != null)
                    {
                        RegisterUserDataType(type);
                        BindingHelpers.CreateBindType(bindItems, staticAttribute.Path ?? type.Name, type);
                    }

                    RegisterTypeFuncs(type);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Allows you to access static functions and members on the type by using the Lua global with the name<para/>
 /// <para/>
 /// Equivalent to script.Globals[name] = t
 /// </summary>
 /// <param name="name"></param>
 /// <param name="t"></param>
 public void AddGlobalType(string name, Type t)
 {
     RegisterUserDataType(t);
     BindingHelpers.CreateBindType(bindItems, name, t);
 }
 /// <summary>
 /// Allows you to access static functions and members on the type by using the Lua global with the name<para/>
 /// <para/>
 /// Equivalent to script.Globals[name] = t
 /// </summary>
 /// <param name="path"></param>
 /// <param name="t"></param>
 public static void AddGlobalType(string path, Type t)
 {
     RegisterUserDataType(t);
     BindingHelpers.CreateBindType(bindItems, path, t);
 }
 /// <summary>
 /// Allows you to access static functions and members on the type by using the Lua global with the name<para/>
 /// Equivalent to script.Globals[t.Name] = t
 /// </summary>
 /// <param name="t"></param>
 public static void AddGlobalType(Type t)
 {
     RegisterUserDataType(t);
     BindingHelpers.CreateBindType(bindItems, t.Name, t);
 }