public static void LuaSearcher()
        {
            foreach (var mod in Global.Instance.modManager.mods)
            {
                if (mod.is_subscribed)   //ScriptingCore.InfoLog("modfolder contains " + mod.file_source.GetRoot()  ) ;
                {
                    modfolder.Add(mod.file_source.GetRoot().Replace('\\', '/'));
                }
            }

            string basefolder = System.IO.Path.Combine(Util.RootFolder(), "mods/");

            foreach (string file in System.IO.Directory.GetFiles(
                         basefolder, "LuaEntryPoint.dll", SearchOption.AllDirectories))
            {
                if (!luafolder.Contains(Path.GetDirectoryName(file)))
                {
                    luafolder.Add(Path.GetDirectoryName(file.Replace('\\', '/')));
                }
            }

            foreach (var file in luafolder)
            {
                ScriptingCore.InfoLog("tryload " + file);
                if (modfolder.Contains(file))
                {
                    new LuaCore.ScriptingInstance(file);
                    //ScriptingCore.InfoLog("Started new Lua Scripting Instance " + file);
                }
            }
        }
Пример #2
0
        public static void RegisterTypeAdv <T>(System.Object dynv, string typename, string Helptext = "")
        {
            ScriptingCore.InfoLog("RegisterType with Advanced Object: " + typename);
            if (dynv == null)
            {
                ScriptingCore.DebugLogError("The type " + typename + " is null! ");
                throw new ArgumentNullException("The type of " + typename + " is null! ");
            }
            DynValue dynvalue = UserData.Create(dynv);

            try
            {
                UserData.RegisterType <T>();
            }
            catch { return; }
            if (ScriptingCore.typedict.ContainsKey(typename))
            {
                ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
            }
            else
            {
                if (dynvalue == null)
                {
                    ScriptingCore.DebugLogError("The  Dynvalue of " + typename + " is null! ");
                    throw new ArgumentNullException("The  Dynvalue of " + typename + " is null! ");
                }
                else
                {
                    ScriptingCore.typedict.Add(typename, dynvalue);
                }
            }
            AddHelpInfo <T>(typename, "Class: " + Helptext, false);
        }
Пример #3
0
        public static bool ClassHelp()
        {
            string fieldlist = " Use this strings with ClassHelpString " + "\n";

            foreach (var i in ScriptingCore.classhelpdict)
            {
                fieldlist += i.Key + " : " + i.Value + "\n";
            }
            ScriptingCore.InfoLog(fieldlist);
            return(true);
        }
Пример #4
0
        public static bool Help()
        {
            string debuglogtext = " Luahelp: This lists Functions and classes, if you want to know more about a class do ClassHelp(classname) \n Functionname : Helptext\n";

            foreach (var i in ScriptingCore.helpdict)
            {
                debuglogtext += i.Key + " : " + i.Value + "\n";
            }
            ScriptingCore.InfoLog(debuglogtext);
            return(true);
        }
Пример #5
0
        public static bool ListFieldsString(string typename)
        {
            string fieldlist = " List all fields of " + typename;

            foreach (var i in LuaInterface.GetType(typename).GetFields())
            {
                fieldlist += i.Name + " : " + i.GetValue(i).ToString();
            }
            ScriptingCore.InfoLog(fieldlist);
            return(true);
        }
Пример #6
0
 public static void AddFunction(string Functionnameinlua, Delegate Function, string Helptext = "")
 {
     ScriptingCore.InfoLog("RegisterFunction: " + Functionnameinlua);
     if (ScriptingCore.functiondict.ContainsKey(Functionnameinlua))
     {
         ScriptingCore.InfoLog("The type " + Functionnameinlua + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.functiondict.Add(Functionnameinlua, Function);
         AddHelpInfo(Functionnameinlua, Helptext);
     }
 }
        public static bool ListResearchsWithTypes()
        {
            string debuglogstring = " ListResearchsWithTypes ";

            foreach (Tech techtoadd in Db.Get().Techs.resources)
            {
                debuglogstring += techtoadd.Id + "\n";
                var res = Research.Instance.Get(techtoadd);
                foreach (var i in res.tech.costsByResearchTypeID.Keys.ToList())
                {
                    debuglogstring += i + res.tech.costsByResearchTypeID[i] + "\n";
                }
            }
            ScriptingCore.InfoLog(debuglogstring);
            return(true);
        }
Пример #8
0
 public static bool AddHelpInfo(string Functionnameinlua, string Helptext = "", bool log = true)
 {
     if (log)
     {
         ScriptingCore.LuaDebugLog("AddHelpInfo: " + Functionnameinlua);
     }
     if (ScriptingCore.helpdict.ContainsKey(Functionnameinlua))
     {
         ScriptingCore.InfoLog("The info " + Functionnameinlua + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.helpdict.Add(Functionnameinlua, Helptext);
     }
     return(true);
 }
Пример #9
0
        public static Type RegisterType(string typenamei)
        {
            ScriptingCore.InfoLog("RegisterType: " + typenamei);
            string typename;

            if (LuaSystemFunctions.typelist.ContainsKey(typenamei))
            {
                typename = LuaSystemFunctions.typelist[typenamei];
            }
            else
            {
                typename = typenamei;
            }
            Type t = GetType(typename);

            if (t == null)
            {
                ScriptingCore.InfoLog(" ClassHelperString " + typename + " Was not found. "); return(null);
            }
            if (ScriptingCore.typedirectdict.ContainsKey(typename))
            {
                return(t);
            }
            ScriptingCore.typedirectdict.Add(typename, t);
            if (ScriptingCore.classhelpdict.ContainsKey(typename))
            {
                ScriptingCore.InfoLog("The info " + typename + " is already registered skipping it! ");
            }
            else
            {
                ScriptingCore.classhelpdict.Add(typename, t.AssemblyQualifiedName);
            }
            // foreach (var i in Db.Get().Urges) { Debug.Log( i.Name );}

            /*
             * var d = new luahelper();
             * try
             * {
             *  var result = typeof(luahelper).GetMethod("RegisterType").MakeGenericMethod(t);
             *  RegisterTypeAdv<result>(typename);
             * }
             * catch(Exception e) { ScriptingCore.DebugLogError("RegisterType "+ typename+ " failed with error: " + e.Message ); }
             */
            return(t);
            //somehow convert the typename to the type
        }
Пример #10
0
        public static Type ClassHelpType(Type t)
        {
            var d = new LuaInterface.luahelper();

            //FieldInfo[] result = (FieldInfo[]) typeof(LuaInterface.luahelper).GetMethod("GetFields").MakeGenericMethod(t).Invoke(d, null);
            FieldInfo[] result = t.GetFields();
            // var fieldNames = result.Select(field => field.Name)                                        .ToList();

            string debuglogtext = " Luahelp: This lists Field names of the given class.\n";

            foreach (var i in result)
            {
                debuglogtext += i.Name + "\n";
            }
            ScriptingCore.InfoLog(debuglogtext);
            return(t);
        }
Пример #11
0
 public static void RegisterTypeAdv <T>(string typename, string Helptext = "")
 {
     ScriptingCore.InfoLog("RegisterType: " + typename);
     try
     {
         UserData.RegisterType <T>();
     }
     catch { ScriptingCore.InfoLog("RegisterType: " + typename + " failed! "); return; }
     if (ScriptingCore.typedirectdict.ContainsKey(typename))
     {
         ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.typedirectdict.Add(typename, typeof(T));
     }
     AddHelpInfo <T>(typename, "Class: " + Helptext, false);
 }
Пример #12
0
        public static Type ClassHelpString(string classname)
        {
            Type t = LuaInterface.GetType(classname);

            if (t == null)
            {
                try
                {
                    t = LuaInterface.GetType(ScriptingCore.classhelpdict[classname]);
                }
                catch { }
            }
            if (t == null)
            {
                ScriptingCore.InfoLog(" ClassHelperString " + classname + " Was not found. "); return(null);
            }
            ClassHelpType(t); return(t);
        }
Пример #13
0
 public static void RegisterType <T>(string typename, string Helptext = "") where T : new()
 {
     ScriptingCore.InfoLog("RegisterType: " + typename); DynValue dynv;
     try
     {
         UserData.RegisterType <T>();
         dynv = UserData.Create(new T());
     }
     catch { return; }
     if (ScriptingCore.typedict.ContainsKey(typename))
     {
         ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.typedict.Add(typename, dynv);
     }
     AddHelpInfo <T>(typename, "Class: " + Helptext, false);
 }
Пример #14
0
        static public bool RegisterAllTypes(string fileName)
        {
            if (fileName == null)
            {
                ScriptingCore.InfoLog(" ClassHelperString " + fileName + " Filename is null. "); return(false);
            }
            Assembly assembly;

            try
            {
                assembly = Assembly.Load(fileName);
            }
            catch (Exception e) { ScriptingCore.InfoLog(" RegisterAllTypes " + e.Message); return(false); }

            foreach (Type type in assembly.GetTypes())
            {
                LuaInterface.RegisterType(type.AssemblyQualifiedName);
            }
            return(true);
        }