Exemple #1
0
        public MainPage()
        {
            this.InitializeComponent();

            var setup = new ScriptRuntimeSetup();

            setup.HostType = typeof(DlrHost);
            setup.AddRubySetup();

            var runtime = Ruby.CreateRuntime(setup);

            this.engine = Ruby.GetEngine(runtime);
            this.scope  = engine.CreateScope();
            this.scope.SetVariable("Main", this);

            runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);

            string outputText = @"
box = main.find_name('OutputBox')
p box.text_alignment
box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
p box.text_alignment
";

            InputBox.IsSpellCheckEnabled  = false;
            OutputBox.IsSpellCheckEnabled = false;
            InputBox.Document.SetText(TextSetOptions.None, outputText);
        }
Exemple #2
0
        public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase)
        {
            _driver   = driver;
            _testName = testCase.Name;

            if (testCase.Options.NoRuntime)
            {
                return;
            }

            if (_driver.SaveToAssemblies)
            {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup  = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.DebugMode      = _driver.IsDebug;
            runtimeSetup.PrivateBinding = testCase.Options.PrivateBinding;
            runtimeSetup.HostType       = typeof(TestHost);
            runtimeSetup.HostArguments  = new object[] { testCase.Options };
            languageSetup.Options["NoAdaptiveCompilation"] = _driver.NoAdaptiveCompilation;
            languageSetup.Options["CompilationThreshold"]  = _driver.CompilationThreshold;
            languageSetup.Options["Verbosity"]             = 2;

            _runtime = Ruby.CreateRuntime(runtimeSetup);
            _engine  = Ruby.GetEngine(_runtime);
            _context = (RubyContext)HostingHelpers.GetLanguageContext(_engine);
        }
Exemple #3
0
        public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase)
        {
            _driver   = driver;
            _testName = testCase.Name;

            if (_driver.IsDebug)
            {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var           runtimeSetup  = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup langaugeSetup = null;

            foreach (var language in runtimeSetup.LanguageSetups)
            {
                if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName)
                {
                    langaugeSetup = language;
                    break;
                }
            }

            // TODO: dynamic modules with symbols are not available in partial trust
            runtimeSetup.DebugMode = !driver.PartialTrust;
            langaugeSetup.Options["InterpretedMode"] = _driver.Interpret;
            langaugeSetup.Options["Verbosity"]       = 2;
            langaugeSetup.Options["Compatibility"]   = testCase.Compatibility;

            _env     = Ruby.CreateRuntime(runtimeSetup);
            _engine  = Ruby.GetEngine(_env);
            _context = Ruby.GetExecutionContext(_engine);
        }
Exemple #4
0
        public string CompileSass(string input, SassMode mode)
        {
            var srs = new ScriptRuntimeSetup()
            {
                HostType = typeof(ResourceAwareScriptHost)
            };

            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);

            var engine = runtime.GetRubyEngine();

            engine.SetSearchPaths(new List <string> {
                @"R:\lib\ironruby", @"R:\lib\ruby\1.9.1"
            });

            var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SquishIt.Sass.lib.sass_in_one.rb"), SourceCodeKind.File);
            var scope  = engine.CreateScope();

            source.Execute(scope);

            dynamic sassMode = mode == SassMode.Sass
                                   ? engine.Execute("{:syntax => :sass}")
                                   : engine.Execute("{:syntax => :scss}");

            var sassEngine = scope.Engine.Runtime.Globals.GetVariable("Sass");

            return((string)sassEngine.compile(input, sassMode));
        }
Exemple #5
0
        /// ------------------------------------------------------------------------------------
        public static Dictionary <double, double> SegmentAudioFile(string audioFile,
                                                                   int silenceThreshold, float clusterDuration, int clusterThreshold,
                                                                   float[] onsetDetectionValues)
        {
            var rubyScript =
                FileLocator.GetFileDistributedWithApplication("AutoSegmenter", "rubyscripts", "segmenter.rb");

            var libAubioFolder = Path.GetDirectoryName(
                FileLocator.GetFileDistributedWithApplication("AutoSegmenter", "libaudio", "aubioonset.exe"));

            if (!libAubioFolder.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture)))
            {
                libAubioFolder += Path.DirectorySeparatorChar;
            }

            var runtime = Ruby.CreateRuntime();
            var engine  = runtime.GetEngine("rb");
            var paths   = engine.GetSearchPaths().ToList();

            paths.Add(Path.GetDirectoryName(rubyScript));
            engine.SetSearchPaths(paths);

            engine.Runtime.ExecuteFile(rubyScript);
            var segmenterObj  = engine.Runtime.Globals.GetVariable("Segmenter");
            var segmenterInst = engine.Operations.CreateInstance(segmenterObj);

            engine.Operations.InvokeMember(segmenterInst, "initFromCSharp",
                                           silenceThreshold, clusterDuration, clusterThreshold, onsetDetectionValues);

            IronRuby.Builtins.Hash returnValues = engine.Operations.InvokeMember(segmenterInst,
                                                                                 "processFromCSharp", libAubioFolder, audioFile);

            return(returnValues.ToDictionary(kvp => (double)kvp.Key, kvp => (double)kvp.Value));
        }
Exemple #6
0
 public ScriptHandler()
 {
     _runtime = Ruby.CreateRuntime();
     _runtime.LoadAssembly(GetType().Assembly);
     _engine = Ruby.GetEngine(_runtime);
     _scope  = _engine.CreateScope();
 }
Exemple #7
0
        protected virtual ScriptRuntime /*!*/ CreateRuntime()
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();

            setup.AddRubySetup();
            setup.DebugMode = true;
            return(Ruby.CreateRuntime(setup));
        }
Exemple #8
0
        private static ScriptRuntime InitializeIronRuby()
        {
            var rubySetup = Ruby.CreateRubySetup();

            var runtimeSetup = new ScriptRuntimeSetup();

            runtimeSetup.LanguageSetups.Add(rubySetup);
            runtimeSetup.DebugMode = true;

            return(Ruby.CreateRuntime(runtimeSetup));
        }
Exemple #9
0
        public static void Initialize()
        {
            self_path = System.IO.Directory.GetCurrentDirectory();
            ScriptRuntime _runTime = Ruby.CreateRuntime();

            _engine = Ruby.GetEngine(_runTime);
            _scope  = _engine.CreateScope();
            _engine.Execute(@"load_assembly 'IronRuby.Libraries'; load_assembly 'DataStructure'", _scope);
            _engine.ExecuteFile(@"rb\mapx.rb");
            _scope.SetVariable("a", "");
            _engine.Execute(@"$path = a", _scope);
        }
Exemple #10
0
        private static RubyEngine InitializeIronRuby(IPathProvider vpp)
        {
            var rubySetup    = Ruby.CreateRubySetup();
            var runtimeSetup = new ScriptRuntimeSetup();

            runtimeSetup.LanguageSetups.Add(rubySetup);
            runtimeSetup.DebugMode = true;
//            runtimeSetup.HostType = typeof (MvcScriptHost);

            var runtime = Ruby.CreateRuntime(runtimeSetup);

            return(new RubyEngine(runtime, vpp));
        }
Exemple #11
0
        public ScriptRuntime CreateRuntime()
        {
            var rubySetup = Ruby.CreateRubySetup();

            rubySetup.Options["InterpretedMode"] = true;

            var runtimeSetup = new ScriptRuntimeSetup();

            runtimeSetup.LanguageSetups.Add(rubySetup);
            runtimeSetup.DebugMode = true;

            return(Ruby.CreateRuntime(runtimeSetup));
        }
Exemple #12
0
        public ScriptEngine CreateRubyEngine()
        {
            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.PrivateBinding = true;
            runtimeSetup.HostType = typeof(TmpHost);
            runtimeSetup.HostArguments = new object[] { new OptionsAttribute() };

            languageSetup.Options["Verbosity"] = 2;

            var runtime = Ruby.CreateRuntime(runtimeSetup);
            return Ruby.GetEngine(runtime);
        }
        public Action Cleanup;  // A function delegate that will be called when the script is completed to allow any cleanup actions to take place.

        public DialPlanExecutingScript(SIPMonitorLogDelegate logDelegate)
        {
            ScriptNumber = ++ScriptCounter % Int32.MaxValue;
            Id           = Guid.NewGuid();

            var setup         = ScriptRuntimeSetup.ReadConfiguration();
            var scriptRuntime = Ruby.CreateRuntime(setup);

            DialPlanScriptEngine = Ruby.GetEngine(scriptRuntime);

            //DialPlanScriptEngine = Ruby.CreateEngine();

            DialPlanScriptScope = DialPlanScriptEngine.CreateScope();

            LogDelegate = logDelegate;
        }
Exemple #14
0
        protected override void EstablishContext()
        {
            if (_scriptRuntime == null)
            {
                var rubySetup = Ruby.CreateRubySetup();
                rubySetup.Options["InterpretedMode"] = true;

                var runtimeSetup = new ScriptRuntimeSetup();
                runtimeSetup.LanguageSetups.Add(rubySetup);
                runtimeSetup.DebugMode = true;

                _scriptRuntime = Ruby.CreateRuntime(runtimeSetup);
            }
            _engine  = _scriptRuntime.GetRubyEngine();
            _context = Ruby.GetExecutionContext(_engine);
        }
Exemple #15
0
        public MainPage()
        {
            this.InitializeComponent();

            var setup = new ScriptRuntimeSetup();

            setup.HostType = typeof(DlrHost);
            setup.AddRubySetup();

            var runtime = Ruby.CreateRuntime(setup);

            this.engine = Ruby.GetEngine(runtime);
            this.scope  = engine.CreateScope();
            this.scope.SetVariable("Main", this);

            runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);

            string outputText = @"
box = main.find_name('OutputBox')
p box.text_alignment
box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
p box.text_alignment
";

            InputBox.IsSpellCheckEnabled  = false;
            OutputBox.IsSpellCheckEnabled = false;
            InputBox.Document.SetText(TextSetOptions.None, outputText);

            // http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx

            IInspectable insp = (IInspectable)InputBox.Document;
            string       winTypeName;

            insp.GetRuntimeClassName(out winTypeName);
            Guid[] iids;
            int    iidCount;

            insp.GetIids(out iidCount, out iids);

            // winTypeName = "Windows.Foundation.Collections.IIterator`1<Windows.Foundation.Collections.IMapView`2<Windows.Foundation.Collections.IVector`1<String>, String>>";

            var  parts = ParseWindowsTypeName(winTypeName);
            Type type  = MakeWindowsType(parts);
            var  guid  = type.GetTypeInfo().GUID;
        }
Exemple #16
0
        public ScriptEngine CreateRubyEngine(bool privateBinding = false, OptionsAttribute options = null)
        {
            var runtimeSetup  = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = runtimeSetup.AddRubySetup();

            runtimeSetup.DebugMode      = IsDebug;
            runtimeSetup.PrivateBinding = privateBinding;
            runtimeSetup.HostType       = typeof(TestHost);
            runtimeSetup.HostArguments  = new object[] { options ?? new OptionsAttribute() };

            languageSetup.Options["ApplicationBase"]       = BaseDirectory;
            languageSetup.Options["NoAdaptiveCompilation"] = NoAdaptiveCompilation;
            languageSetup.Options["CompilationThreshold"]  = CompilationThreshold;
            languageSetup.Options["Verbosity"]             = 2;

            var runtime = Ruby.CreateRuntime(runtimeSetup);

            return(Ruby.GetEngine(runtime));
        }
Exemple #17
0
        void Initialize()
        {
            if (initialized)
            {
                return;
            }

            pal = new CassettePlatformAdaptationLayer(new ResourceRedirectionPlatformAdaptationLayer(), RootDirectory);
            var srs = new ScriptRuntimeSetup
            {
                HostType      = typeof(SassCompilerScriptHost),
                HostArguments = new List <object> {
                    pal
                },
            };

            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);

            engine = runtime.GetRubyEngine();

            // NB: 'R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}' is a garbage path that the PAL override will
            // detect and attempt to find via an embedded Resource file
            engine.SetSearchPaths(new List <string>
            {
                @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ironruby",
                @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ruby\1.9.1"
            });

            var source = engine.CreateScriptSourceFromString(
                Utility.ResourceAsString("lib.sass_in_one.rb", typeof(SassAndCoffee.Ruby.Sass.SassCompiler)),
                SourceCodeKind.File);

            scope = engine.CreateScope();
            source.Execute(scope);

            sassCompiler = scope.Engine.Runtime.Globals.GetVariable("Sass");
            sassOption   = engine.Execute("{:cache => false, :syntax => :sass}");
            scssOption   = engine.Execute("{:cache => false, :syntax => :scss}");

            initialized = true;
        }
Exemple #18
0
        static string ErbToRb(string str)
        {
            if (_erbCompiler == null)
            {
                var engine = Ruby.CreateRuntime().GetEngine("rb");
                engine.Execute(@"
require 'erb'

class ErbCompiler
  def compile(str)
    ERB.new(str.to_s).src + ""\n\nputs _erbout""
  end
end
                ");

                dynamic ruby = engine.Runtime.Globals;
                _erbCompiler = ruby.ErbCompiler.@new();
            }

            return(_erbCompiler.compile(str).ToString());
        }
Exemple #19
0
        static void Main(string[] args)
        {
            var runtime = Ruby.CreateRuntime();
            var engine  = runtime.GetRubyEngine();

            engine.Execute("def hello; puts 'hello world'; end");

            string s = engine.Execute("hello") as string;

            Console.WriteLine(s);
            // outputs "hello world"

            engine.Execute("class Foo; def bar; puts 'hello from bar'; end; end");
            object o          = engine.Execute("Foo.new");
            var    operations = engine.CreateOperations();
            string s2         = operations.InvokeMember(o, "bar") as string;

            Console.WriteLine(s2);
            // outputs "hello from bar"

            Console.ReadKey();
        }
        protected void CreateScriptRuntime(ContainerBuilder builder)
        {
            var runtime = Ruby.CreateRuntime();

            AppDomain.CurrentDomain.GetAssemblies().ForEach(runtime.LoadAssembly);
            var engine = runtime.GetEngine("rb");

            var searchPaths = new List <string>(engine.GetSearchPaths())
            {
                @".\Scripts\Lib",
                @".\Scripts\Lib\IronRuby",
                @".\Scripts\Lib\Ruby\1.9.1"
            };

            engine.SetSearchPaths(searchPaths);

            builder.RegisterInstance(runtime);
            builder.RegisterInstance(engine);

            Directory.CreateDirectory(@"Scripts");
            Directory.CreateDirectory(@"Scripts\Modules");
            Directory.CreateDirectory(@"Scripts\Events");
        }
Exemple #21
0
        /// <summary>
        /// Initializes the Ruby engine.
        /// </summary>
        private void Initialize()
        {
            if (initialized)
            {
                return;
            }

            ResourceAwarePlatformAdaptationLayer resourceAwarePlatform = new ResourceAwarePlatformAdaptationLayer();

            ScriptRuntimeSetup srs = new ScriptRuntimeSetup
            {
                HostType      = typeof(ResourceAwareScriptHost),
                HostArguments = new List <object> {
                    resourceAwarePlatform
                }
            };

            srs.AddRubySetup();
            ScriptRuntime runtime = Ruby.CreateRuntime(srs);

            engine = runtime.GetRubyEngine();

            engine.SetSearchPaths(new List <string> {
                @"R:\Resources\ironruby", @"R:\Resources\ruby\1.9.1"
            });

            string       resouce = Utils.ResourceAsString("Cruncher.Preprocessors.Sass.Resources.sass_in_one.rb");
            ScriptSource source  = engine.CreateScriptSourceFromString(resouce, SourceCodeKind.File);

            scope = engine.CreateScope();

            source.Execute(scope);

            sassEngine = scope.Engine.Runtime.Globals.GetVariable("Sass");

            initialized = true;
        }
Exemple #22
0
 public Parser(string Source, ErrorSink errorSink)
 {
     source         = Ruby.CreateRuntime().GetEngine("rb").CreateScriptSourceFromString(Source);
     this.errorSink = errorSink;
 }
Exemple #23
0
        public static int Run(List <string> /*!*/ args)
        {
            if (!ParseArguments(args))
            {
                return(-3);
            }

            int status = 0;

            if (_runTokenizerDriver)
            {
                TokenizerTestDriver driver = new TokenizerTestDriver(Ruby.GetExecutionContext(Ruby.CreateRuntime()));
                if (!driver.ParseArgs(args))
                {
                    return(-3);
                }

                status = driver.RunTests();
            }
            else
            {
                InitializeDomain();
                Driver driver = new Driver();

                if (Manual.TestCode.Trim().Length == 0)
                {
                    status = driver.RunUnitTests(args);
                }
                else
                {
                    driver.RunManualTest();

                    // for case the test is forgotten, this would fail the test suite:
                    status = -2;
                }
            }

            // return failure on bad filter (any real failures throw)
            return(status);
        }
    public string runRuby(GameObject logWindow, string script, string method_name, string augments_name, string limit, object[] argments)
    {
        // Rubyスクリプトを実行
        var runtime = Ruby.CreateRuntime();
        var engine  = runtime.GetEngine("Ruby");

        var outputStream = new MemoryStream();
        var errorStream  = new MemoryStream();

        engine.Runtime.IO.SetOutput(outputStream, Encoding.UTF8);
        engine.Runtime.IO.SetErrorOutput(errorStream, Encoding.UTF8);

        ScriptScope scope  = engine.CreateScope();
        var         source = engine.CreateScriptSourceFromString(script);

        source.Execute(scope);

        // 無限ループ対策
        TextAsset textasset = new TextAsset(); //テキストファイルのデータを取得するインスタンスを作成

        textasset = Resources.Load("timeout", typeof(TextAsset)) as TextAsset;
        source    = engine.CreateScriptSourceFromString(textasset.text);
        source.Execute(scope);

        source = engine.CreateScriptSourceFromString(setTimeout(method_name, augments_name, limit));
        source.Execute(scope);

        string error_log = "";

        try
        {
            engine.Operations.InvokeMember(scope, "rwrapper", argments);
        }
        catch (Exception e)
        {
            error_log = e.Message;
        }

        outputStream.Flush();
        errorStream.Flush();

        var logs = new Queue <String>();

        string output_log = Encoding.UTF8.GetString(outputStream.ToArray());

        error_log += Encoding.UTF8.GetString(errorStream.ToArray());

        StringReader strReader = new StringReader(output_log);

        string line;

        while ((line = strReader.ReadLine()) != null)
        {
            textPrefab = (GameObject)Resources.Load("Prefabs/Log");
            GameObject _text_obj = Instantiate(textPrefab, logWindow.transform);
            Text       _text     = _text_obj.GetComponent <Text>();
            _text.text  = line;
            _text.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        }

        strReader = new StringReader(error_log);

        //Debug.Log(error_log);

        while ((line = strReader.ReadLine()) != null)
        {
            textPrefab = (GameObject)Resources.Load("Prefabs/Log");
            GameObject _text_obj = Instantiate(textPrefab, logWindow.transform);
            Text       _text     = _text_obj.GetComponent <Text>();
            _text.text  = line;
            _text.color = new Color(1.0f, 0.0f, 0.0f, 1.0f);
        }

        return(output_log);
    }
Exemple #25
0
 static RubyHasher()
 {
     runtime = Ruby.CreateRuntime();
     engine  = Ruby.GetEngine(runtime);
 }