Example #1
0
        public void CallNCScript()
        {
            ScriptParser parser = new ScriptParser();

            parser.Types.AddType <Script>();
            IScript ncscript = parser.Parse("parameter($data, script) return($data.name)");

            Mock <IScriptCompiler> scriptcompiler = new Mock <IScriptCompiler>();

            scriptcompiler.Setup(s => s.CompileScriptAsync(It.IsAny <string>(), It.IsAny <int?>())).ReturnsAsync(new CompiledScript {
                Instance = ncscript
            });

            LuaImportService importservice = new LuaImportService();

            importservice.AddScript("Test", new ScriptExecutor(new WorkableLogger(new NullLogger <JavascriptTests>(), null), scriptcompiler.Object, "Test", 1));

            Mock <IServiceProvider> serviceprovider = new Mock <IServiceProvider>();

            serviceprovider.Setup(s => s.GetService(typeof(IScriptCompiler))).Returns(scriptcompiler.Object);

            //PythonService pythonservice = new PythonService(importservice.Object, null);
            LuaScript script = new LuaScript("script=load:Script(\"Test\", nil)\nreturn script:Execute({data={Name=\"Test\"}})", new LuaService(serviceprovider.Object, null));

            Assert.AreEqual("Test", script.Execute(new Dictionary <string, object> {
                ["log"] = null
            }));
        }
Example #2
0
        public override void Interact()
        {
            if (destroyed)
            {
                return;
            }

            SceneSaver.Instance.AddUsed(this.name);

            Logger.Log($"interacting with {EntityName}");

            if (runScriptOnInteraction)
            {
                LuaScript.Execute(script);
            }

            if (runYarnProgramOnInteraction)
            {
                FindObjectOfType <DialogueRunner>().StartDialogue(yarnNodeToStart);
            }

            if (destroyOnInteraction)
            {
                SceneSaver.Instance.AddDestroyed(this.name);
                destroyed = true;
                Destroy(this.gameObject);
            }
        }
Example #3
0
        public void IntCall()
        {
//            PythonService pythonservice=new PythonService(new Mock<IScriptImportService>().Object, null);
            LuaScript script = new LuaScript("return test:TestNumber(7)", new LuaService(null, null));

            Assert.AreEqual(7, script.Execute(new Dictionary <string, object> {
                ["test"] = this
            }));
        }
Example #4
0
        public void AwaitTask()
        {
            //PythonService pythonservice=new PythonService(new Mock<IScriptImportService>().Object, null);
            LuaScript script = new LuaScript("return await(test.TestTask())", new LuaService(null, null));

            Assert.AreEqual("test", script.Execute(new Dictionary <string, object> {
                ["test"] = this
            }));
        }
Example #5
0
        public override void StartTalking()
        {
            state = NPCState.Talking;

            Logger.Log("[NPC] StartTalking()");

            if (shouldExecScript)
            {
                LuaScript.Execute(dialogueScript);
            }
        }
Example #6
0
        public LuaExecutorServiceResponse Execute(string code)
        {
            var            response = new LuaExecutorServiceResponse();
            IScriptSession session  = new LuaScript();

            session.Set("userConnection", UserConnection);
            try {
                var returnedValue = session.Execute <object>(code);
                response.Value = returnedValue;
            } catch (Exception e) {
                response.Exception = e;
            }
            return(response);
        }
Example #7
0
        public void TypeConversion()
        {
            Mock <IConfigurationSection> typeconfig = new Mock <IConfigurationSection>();

            typeconfig.SetupGet(s => s.Key).Returns("NamedCode");
            typeconfig.SetupGet(s => s.Value).Returns("ScriptService.Dto.NamedCode,ScriptService");

            Mock <IConfigurationSection> typesconfig = new Mock <IConfigurationSection>();

            typesconfig.Setup(s => s.GetChildren()).Returns(new[] { typeconfig.Object });

            Mock <IConfiguration> config = new Mock <IConfiguration>();

            config.Setup(s => s.GetSection("Types")).Returns(typesconfig.Object);

            TypeCreator creator = new TypeCreator(new NullLogger <TypeCreator>(), config.Object);

            LuaScript script = new LuaScript("return test:TestMethod(new(\"NamedCode\", {Name=\"Test\"}))", new LuaService(null, creator));

            Assert.AreEqual("Test", script.Execute(new Dictionary <string, object> {
                ["log"]  = new WorkableLogger(new NullLogger <JavascriptTests>(), null),
                ["test"] = this
            }));
        }
Example #8
0
 void Execute(string cmd)
 {
     LuaScript.Execute(cmd);
     inputField.text = "";
 }