// // Establish the compiler hook (if we haven't already). // private void HookScriptCompiler() { if (m_Compiler != null) { return; } if (m_CompilerField == null) { MessageBox.Show(NWN2ToolsetMainForm.App, "Failed to hook script compiler (compiler field not found). The standard compiler will be used."); return; } IScriptCompiler Compiler = (IScriptCompiler)m_CompilerField.GetValue(null); if (Compiler == null) { MessageBox.Show(NWN2ToolsetMainForm.App, "Failed to hook script compiler (compiler not initialized). The standard compiler will be used."); return; } m_Compiler = new ScriptCompilerHook(Compiler, m_ResourceAccessor, m_SettingsManager); m_CompilerField.SetValue(null, m_Compiler); }
/// <summary> /// creates a new <see cref="ScriptExecutor"/> /// </summary> /// <param name="logger">used for logging in script</param> /// <param name="compiler">compiler used to parse script</param> /// <param name="name">name of script to execute</param> /// <param name="revision">revision of script to execute</param> public ScriptExecutor(WorkableLogger logger, IScriptCompiler compiler, string name, int?revision) { this.logger = logger; this.compiler = compiler; this.name = name; this.revision = revision; }
public IScriptGenerator ExecuteCompiler(IScriptCompiler compiler) { _generator = compiler.Compile(this); _compiled = true; return(_generator); }
/// <summary> /// creates a new <see cref="WorkflowCompiler"/> /// </summary> /// <param name="logger">access to logging</param> /// <param name="cacheservice">access to object cache</param> /// <param name="workflowservice">access to workflow data</param> /// <param name="compiler">compiles scripts for conditions and internal workflow code</param> public WorkflowCompiler(ILogger <WorkflowCompiler> logger, ICacheService cacheservice, IWorkflowService workflowservice, IScriptCompiler compiler) { this.logger = logger; this.cacheservice = cacheservice; this.workflowservice = workflowservice; this.compiler = compiler; }
public IScriptGenerator ExecuteCompiler( IScriptCompiler compiler ) { _generator = compiler.Compile( this ); _compiled = true; return _generator; }
private bool registerMacro(String macro, String name, IScriptCompiler scriptCompiler, IMacroService macroService, XmlScriptExecutor executor) { ScriptedMacro scriptedMacro = new ScriptedMacro(executor); scriptedMacro.Name = name; scriptedMacro.Script = scriptCompiler.Compile(macro, name); return macroService.registerMacro(new XnaScrapId(name), scriptedMacro); }
/// <summary> /// creates a new <see cref="ScriptNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="name">name of node</param> /// <param name="parameters">parameters for script</param> /// <param name="compiler">compiler used to retrieve script instance</param> /// <param name="language">language used to translate parameters</param> public ScriptNode(Guid nodeid, string name, CallWorkableParameters parameters, IScriptCompiler compiler, ScriptLanguage?language) : base(nodeid, name) { this.compiler = compiler; Name = parameters.Name; Arguments = parameters.Arguments.BuildArguments(compiler, language); }
/// <summary> /// Adds the script compiler. /// </summary> /// <param name="type">The type.</param> /// <param name="compiler">The compiler.</param> public static void AddScriptCompiler([NotNull] IScriptCompiler compiler) { if (type2compiler.ContainsKey(compiler.ScriptCodeType)) { throw new ArgumentException("The type " + compiler.ScriptCodeType + " already registered."); } type2compiler[compiler.ScriptCodeType] = compiler; }
public ScriptCache(IScriptCompiler scriptCompiler) { if (scriptCompiler == null) { throw new ArgumentNullException("scriptCompiler"); } _scriptCompiler = scriptCompiler; }
// // Construct a new instance with the given stock compiler that is to be // attached. // public ScriptCompilerHook(IScriptCompiler StandardCompiler, ResourceAccessor ResourceAccessor, SettingsManager SettingsMgr) { m_Disposed = false; m_StandardCompiler = StandardCompiler; m_ResourceAccessor = ResourceAccessor; m_SettingsManager = SettingsMgr; m_NscCompiler = new NscCompiler(ResourceAccessor, SettingsMgr); }
public YggParser(YggParserConfig config, IScriptCompiler compiler) { _config = config ?? new YggParserConfig(); _compiler = compiler; BaseNodeMap = AppDomain.CurrentDomain.GetAssemblies() .Where(a => _config.NodeTypeAssemblies.Contains(a.GetName().Name)) .SelectMany(a => a.GetTypes()) .Where(t => typeof(Node).IsAssignableFrom(t) && !t.IsAbstract && t != typeof(Node)) .GroupBy(t => t.Name) .Select(g => g.First()) .ToDictionary(t => t.Name, t => t); }
private void registerScript(String script, String name, IScriptCompiler scriptCompiler, IResourceService resourceService) { IScript compiled = scriptCompiler.Compile(script, name); if (!resourceService.Scripts.Keys.Contains(name)) { resourceService.Scripts.Add(name, compiled); } else { resourceService.Scripts[name] = compiled; // TODO report an error back! } }
/// <summary> /// creates a new <see cref="IteratorNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="nodeName">name of node</param> /// <param name="parameters">parameters to use</param> /// <param name="compiler">compiler used to compile expressions</param> public IteratorNode(Guid nodeid, string nodeName, IteratorParameters parameters, IScriptCompiler compiler) : base(nodeid, nodeName) { this.compiler = compiler; Parameters = parameters; }
public ScriptCompilerService(IScriptCompiler scriptCompiler) { _scriptCompiler = scriptCompiler; }
protected virtual void Dispose(bool Disposing) { if (m_Disposed) return; if (m_StandardCompiler != null) { m_StandardCompiler.Dispose(); m_StandardCompiler = null; } if (m_NscCompiler != null) { m_NscCompiler.Dispose(); m_NscCompiler = null; } }
/// <summary> /// builds argument scripts for workflow nodes /// </summary> /// <param name="arguments">arguments to use as code source</param> /// <param name="compiler">compiler used to compile scripts</param> /// <returns></returns> public static IDictionary <string, IScript> BuildArguments(this IDictionary <string, object> arguments, IScriptCompiler compiler, ScriptLanguage?language) { if (arguments == null) { return(null); } Dictionary <string, IScript> result = new Dictionary <string, IScript>(); foreach ((string key, object value) in arguments) { if (value is string code) { result[key] = compiler.CompileCode(code, language ?? ScriptLanguage.NCScript) ?? new ConstantValueScript(null); } else { result[key] = new ConstantValueScript(value); } } return(result); }
/// <summary> /// creates a new <see cref="ScriptExecutionService"/> /// </summary> /// <param name="logger">access to logging</param> /// <param name="scriptinstances">access to script instances</param> /// <param name="scriptcompiler">compiles code to executable scripts</param> public ScriptExecutionService(ILogger <ScriptExecutionService> logger, ITaskService scriptinstances, IScriptCompiler scriptcompiler) { this.logger = logger; this.scriptinstances = scriptinstances; this.scriptcompiler = scriptcompiler; }
/// <summary> /// creates a new <see cref="ValueNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="name">name of node</param> /// <param name="value">value to provide to workflow</param> /// <param name="compiler">compiler used to compile generated code</param> public ValueNode(Guid nodeid, string name, object value, IScriptCompiler compiler) : base(nodeid, name, compiler) { Value = value; }
/// <summary> /// creates a new <see cref="CallNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="nodeName">name of node</param> /// <param name="parameters">parameters for method call</param> /// <param name="compiler">parser for script code</param> public CallNode(Guid nodeid, string nodeName, CallParameters parameters, IScriptCompiler compiler) : base(nodeid, nodeName, compiler) { Parameters = parameters; }
/// <summary> /// Removes the script compiler. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public static bool RemoveScriptCompiler([NotNull] IScriptCompiler compiler) { return(type2compiler.Remove(compiler.ScriptCodeType)); }
/// <summary> /// creates a new <see cref="ScriptIdMethod"/> /// </summary> /// <param name="scriptid">id of script</param> /// <param name="compiler">compiler used to retrieve script instance</param> public ScriptIdMethod(long scriptid, IScriptCompiler compiler) { this.scriptid = scriptid; this.compiler = compiler; }
//public void _StartScript(uint localID, UUID itemID, string Script, int startParam, bool postOnRez) private void _StartScript(LoadUnloadStructure ScriptObject) { m_log.DebugFormat( "[{0}]: ScriptManager StartScript: localID: {1}, itemID: {2}", Name, ScriptObject.Script.LocalID, ScriptObject.Script.ItemID); // We will initialize and start the script. // It will be up to the script itself to hook up the correct events. SceneObjectPart m_host = ScriptObject.Script.RegionInfo.Scene.GetSceneObjectPart(ScriptObject.Script.LocalID); if (null == m_host) { m_log.ErrorFormat( "[{0}]: Could not find scene object part corresponding " + "to localID {1} to start script", Name, ScriptObject.Script.LocalID); return; } //UUID assetID = UUID.Zero; TaskInventoryItem taskInventoryItem = new TaskInventoryItem(); //if (m_host.TaskInventory.TryGetValue(ScriptObject.Script.ItemID, out taskInventoryItem)) // assetID = taskInventoryItem.AssetID; ScenePresence presence = ScriptObject.Script.RegionInfo.Scene.GetScenePresence(taskInventoryItem.OwnerID); CultureInfo USCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = USCulture; try { // // Compile script to an assembly // //TODO: DEBUG BaseClassFactory.MakeBaseClass(ScriptObject.Script); m_log.DebugFormat("[{0}] Compiling script {1}", Name, ScriptObject.Script.Name); string fileName = ""; try { IScriptCompiler compiler = ScriptObject.Script.RegionInfo.FindCompiler(ScriptObject.Script.ScriptMetaData); //RegionInfoStructure currentRegionInfo = ScriptObject.Script.RegionInfo; fileName = compiler.Compile(ScriptObject.Script.ScriptMetaData, ref ScriptObject.Script.Source); ScriptObject.Script.AssemblyFileName = fileName; } catch (Exception e) { m_log.ErrorFormat("[{0}] Internal error while compiling \"{1}\": {2}", Name, ScriptObject.Script.Name, e.ToString()); } m_log.DebugFormat("[{0}] Compiled \"{1}\" to assembly: \"{2}\".", Name, ScriptObject.Script.Name, fileName); // Add it to our script memstruct MemAddScript(ScriptObject.Script); ScriptAssemblies.IScript CompiledScript; CompiledScript = CurrentRegion.ScriptLoader.LoadScript(ScriptObject.Script); ScriptObject.Script.State = "default"; ScriptObject.Script.ScriptObject = CompiledScript; ScriptObject.Script.Disabled = false; ScriptObject.Script.Running = true; //id.LineMap = LSLCompiler.LineMap(); //id.Script = CompiledScript; //id.Source = item.Script.Script; //item.StartParam = startParam; // TODO: Fire the first start-event //int eventFlags = // m_scriptEngine.m_ScriptManager.GetStateEventFlags( // localID, itemID); //m_host.SetScriptEvents(itemID, eventFlags); ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script, new EventParams(ScriptObject.Script.LocalID, ScriptObject.Script.ItemID, "state_entry", new object[] { }, new Region.ScriptEngine.Shared.DetectParams[0]) ); if (ScriptObject.PostOnRez) { ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script, new EventParams(ScriptObject.Script.LocalID, "on_rez", new object[] { new Region.ScriptEngine.Shared.LSL_Types.LSLInteger(ScriptObject.StartParam) }, new Region.ScriptEngine.Shared.DetectParams[0])); } } catch (Exception e) // LEGIT: User Scripting { if (presence != null && (!ScriptObject.PostOnRez)) { presence.ControllingClient.SendAgentAlertMessage( "Script saved with errors, check debug window!", false); } try { // DISPLAY ERROR INWORLD string text = "Error compiling script:\n" + e.Message.ToString(); if (text.Length > 1100) { text = text.Substring(0, 1099); } ScriptObject.Script.RegionInfo.Scene.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, 2147483647, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false); } catch (Exception e2) // LEGIT: User Scripting { m_log.Error("[" + Name + "]: Error displaying error in-world: " + e2.ToString()); m_log.Error("[" + Name + "]: " + "Errormessage: Error compiling script:\r\n" + e2.Message.ToString()); } } }
/// <summary> /// creates a new <see cref="StartNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="nodeName">name of node</param> /// <param name="parameters">parameters for workflow start</param> /// <param name="compiler">parser used to convert parameter data</param> public StartNode(Guid nodeid, string nodeName, StartParameters parameters, IScriptCompiler compiler) : base(nodeid, nodeName) { this.compiler = compiler; Parameters = parameters; }
/// <summary> /// creates a new <see cref="CompiledExpressionNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="nodeName">name of node</param> /// <param name="compiler">compiler used to compile scripts</param> protected CompiledExpressionNode(Guid nodeid, string nodeName, IScriptCompiler compiler) : base(nodeid, nodeName) { this.compiler = compiler; }
/// <summary> /// translates workable variables to parameter values /// </summary> /// <param name="variables">variables to translate</param> /// <param name="compiler">compiler to use to parse variable scripts</param> /// <returns>workable parameter variables</returns> public static async Task <IDictionary <string, object> > TranslateVariables(this IDictionary <string, object> variables, IScriptCompiler compiler, ScriptLanguage?language) { if (variables == null) { return(null); } Dictionary <string, object> translated = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> kvp in variables) { if (kvp.Value is string code) { translated[kvp.Key] = await(await compiler.CompileCodeAsync(code, language ?? ScriptLanguage.NCScript)).ExecuteAsync(); } else { translated[kvp.Key] = kvp.Value; } } return(translated); }
public ScriptsBuilder() { _scriptCompiler = new ScriptCompilerCSharp(); }
/// <summary> /// creates a new <see cref="WorkflowInstanceNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="name">name of node</param> /// <param name="parameters">parameters for workflow call</param> /// <param name="scriptcompiler">compiler used to build workflow arguments</param> /// <param name="language">language used to translate arguments</param> public WorkflowInstanceNode(Guid nodeid, string name, CallWorkableParameters parameters, IScriptCompiler scriptcompiler, ScriptLanguage?language) : base(nodeid, name) { this.parameters = parameters; Arguments = parameters.Arguments.BuildArguments(scriptcompiler, language ?? ScriptLanguage.NCScript); }
/// <summary> /// creates a new <see cref="AssignStateNode"/> /// </summary> /// <param name="node">node of which to assign result</param> /// <param name="variableName">name of variable to assign result to</param> /// <param name="variableoperation">operation to use when assigning variable</param> /// <param name="compiler">compiler to use to compile variable operation</param> public AssignStateNode(IInstanceNode node, string variableName, VariableOperation variableoperation, IScriptCompiler compiler) { this.node = node; VariableName = variableName; if (variableoperation != VariableOperation.Assign) { operation = compiler.CompileCode($"$lhs{variableoperation.ToOperatorString()}$rhs", ScriptLanguage.NCScript); } }
/// <summary> /// creates a new <see cref="BinaryNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="name">name of node</param> /// <param name="parameters">parameters for operation</param> /// <param name="compiler">access to code compiler</param> public BinaryNode(Guid nodeid, string name, BinaryOpParameters parameters, IScriptCompiler compiler) : base(nodeid, name, compiler) { Parameters = parameters; }
/// <summary> /// creates a new <see cref="LogNode"/> /// </summary> /// <param name="nodeid">id of workflow node</param> /// <param name="nodeName">name of node</param> /// <param name="compiler">compiler for script code</param> /// <param name="parameters">parameters for log action</param> public LogNode(Guid nodeid, string nodeName, IScriptCompiler compiler, LogParameters parameters) : base(nodeid, nodeName) { this.compiler = compiler; Parameters = parameters; }
/// <summary> /// creates a new <see cref="ScriptIdMethod"/> /// </summary> /// <param name="scriptname">name of script</param> /// <param name="compiler">compiler used to retrieve script instances</param> public ScriptNameMethod(string scriptname, IScriptCompiler compiler) { this.scriptname = scriptname; this.compiler = compiler; }