public IScriptGenerator ExecuteCompiler( IScriptCompiler compiler )
        {
            _generator = compiler.Compile( this );
            _compiled = true;

            return _generator;
        }
Пример #2
0
 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);
 }
        public IScriptGenerator ExecuteCompiler(IScriptCompiler compiler)
        {
            _generator = compiler.Compile(this);
            _compiled  = true;

            return(_generator);
        }
Пример #4
0
 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!
     }
 }
Пример #5
0
        public IEnumerable <Script> GetScripts(object key, IEnumerable scripts)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            IEnumerable <Script> result;

            if (_scriptCache.TryGetValue(key, out result) == false)
            {
                _scriptCache[key] = (result = _scriptCompiler.Compile(scripts));
            }

            return(result);
        }
Пример #6
0
        public object Build(ObjectBuilderContext context, View parent, dynamic metadata)
        {
            // Todo: Кэширование скриптов представления (ScriptCache)

            return(_scriptCompiler.Compile(metadata));
        }
        //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());
                }
            }
        }
Пример #8
0
        public BehaviourTreeDefinition BuildFromFiles <TState>(params string[] files)
        {
            var context = new BehaviourTreeDefinition();

            context.TypeDefMap = new Dictionary <string, ParserNode>();

            // Load all xml documents from files.
            var documents = LoadDocuments(files, context.Errors);

            // Extract all behaviour node tags from the xml documents.
            context.NodeTypeTags = GetAllBehaviourNodeTagNames(documents.Values);

            // Create parser nodes from xml documents.
            var parserNodesMap = CreateParserNodes(documents, context.TypeDefMap, context.Errors, context.NodeTypeTags);

            if (parserNodesMap == null)
            {
                return(context);
            }

            context.ParserNodes = parserNodesMap.Values.ToList();

            // Determine underlying types.
            if (!TryResolveTypes(context.ParserNodes, context.TypeDefMap, context.Errors))
            {
                return(context);
            }

            // Create function definitions.
            var functionDefinitions = GetFunctionDefinitions(context.ParserNodes, context.NodeTypeTags);

            if (functionDefinitions == null)
            {
                return(context);
            }

            // Compile scripted functions.
            context.Compilation = _compiler.Compile <TState>(_config.ScriptNamespaces, _config.ReferenceAssemblyPaths,
                                                             functionDefinitions);
            context.Errors.AddRange(context.Compilation.Errors);
            if (context.Errors.Any(e => e.IsCritical))
            {
                return(context);
            }

            // Set scripted functions on parser nodes.
            foreach (var parserNode in context.ParserNodes)
            {
                if (!context.Compilation.GuidFunctionMap.TryGetValue(parserNode.Guid, out var functions))
                {
                    continue;
                }

                parserNode.ScriptedFunctions = functions;
            }

            // Instantiate nodes once to test them.
            foreach (var parserNode in context.ParserNodes.Where(p => p.IsTopmost))
            {
                var node = parserNode.CreateInstance(context.TypeDefMap, context.Errors);
                if (context.Errors.Any(e => e.IsCritical))
                {
                    return(context);
                }

                if (node != null)
                {
                    context.TopmostNodeCount += 1;
                }
            }

            return(context);
        }