private static bool ConfigureServices() { try { PyEngine.Initialize(); } catch { Log.Error("Unable to connect to python driver."); Log.Error("Please uninstall all python builds (2.7, 3.5, etc) and reinstall python 3.7"); return(false); } var basePath = Directory.GetCurrentDirectory(); const string configFileName = "config.json"; try { var config = new ConfigurationBuilder() .SetBasePath(basePath) .AddJsonFile(configFileName, false) .Build(); var mainThread = new ServerAppThread(Constants.ServerThreadFPS); //TODO: From config var builder = new ContainerBuilder(); builder.RegisterInstance(config).As <IConfiguration>(); builder.RegisterInstance(mainThread); builder.RegisterType <WvsCenter>().AsSelf().SingleInstance(); builder.RegisterType <CenterStorage>().AsSelf().SingleInstance(); builder.RegisterType <CommandHandle>().AsSelf().SingleInstance(); builder.RegisterType <ScriptManager>().AsSelf().SingleInstance(); Container = builder.Build(); return(true); } catch { Log.Error("Unable to build config.json file."); Log.Error($"File name: {configFileName}"); Log.Error($"File directory: {basePath}"); Log.Error($"Full file path: {basePath}\\{configFileName}"); return(false); } }
static void Main(string[] args) { PyEngine pyEngine = new PyEngine(); if (pyEngine.PyInitialize()) // 初始化PyEngine { pyEngine.PySetModulePath(null); // null 默认当前路径否则填绝对路径 if (pyEngine.PyImportModule("t123")) // 导入模块 { object[] argss = new object[] { 1.2, 2 }; // 添加参数 object obj = pyEngine.PyCallFuncFromModule("t123", "F", argss, "D"); // 执行函数 Console.WriteLine(obj); } } Console.ReadLine(); }
protected ScriptBase(string sScriptName, string sScriptContents, WvsGameClient client) { Parent = client; Engine = new PyEngine(sScriptContents); ScriptName = sScriptName; }