예제 #1
0
        public CompiledScript GetOrCompileScript(string script, out string error)
        {
            if (string.IsNullOrEmpty(script))
            {
                Log.Fatal("ScriptCache: Get: \"script\" is empty.");
            }

            error = "";

            lock ( lockObjectGetOrCompileScript )
            {
                var compiledScript = GetCompiledScript(script);
                if (compiledScript != null)
                {
                    return(compiledScript);
                }

                if (!ScriptingCSharpEngine.CanCompileScripts)
                {
                    error = "Unable to get compiled script. The script is not precompiled in the cache. Script compilation is not supported on the current platform, run scenes on dev machine to make the cache.";
                    return(null);
                }

                try
                {
                    ScriptingCSharpEngine.CheckForSyntaxErrors(script);

                    var assembly = ScriptingCSharpEngine.CompileScriptsToAssembly(new List <string> {
                        script
                    }, null);
                    compiledScript = CompiledScript.CreateFrom(assembly);

                    AddCompiledScript(script, compiledScript);

                    return(compiledScript);
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                    return(null);
                }
            }
        }
예제 #2
0
        CompiledScript GetCompiledScript(string script)
        {
            CompiledScript compiledScript;

            compiledScripts.TryGetValue(script, out compiledScript);
            if (compiledScript != null)
            {
                return(compiledScript);
            }

            var scriptType = FindScriptTypeInLoadedAssemblyDll(script);

            if (scriptType != null)
            {
                compiledScript = CompiledScript.CreateFrom(scriptType);
                compiledScripts.Add(script, compiledScript);
                return(compiledScript);
            }

            return(null);
        }