/// <summary> /// Remove the LuatScript from the database /// </summary> /// <param name="script"></param> private void Drop(LuatScript script) { // Invalidate all nodes foreach (LuatAstNodeBase node in Helpers.Traversal <IAstNode>(script.CU, n => n.ChildNodes)) { node.Invalidate(script); } script.UnresolvedExpressions.Clear(); script.UnresolvedStatements.Clear(); }
/// <summary> /// Adds a statement to the unresolved list /// </summary> /// <param name="script"></param> /// <param name="statement"></param> /// <returns></returns> public bool AddUnresolvedStatement(LuatScript script, Statement statement) { LinkedListNode <Statement> node = statement.ListNode[script]; if (node.List == script.UnresolvedStatements) { return(false); } if (null != node.List) { if (node.List != script.ResolvedStatements) { throw new Exception("Statement is part of an unknown list"); } node.List.Remove(node); } script.UnresolvedStatements.AddFirst(node); return(true); }
/// <summary> /// Adds an expression to the unresolved list /// </summary> /// <param name="script"></param> /// <param name="expression"></param> /// <returns></returns> public bool AddUnresolvedExpression(LuatScript script, Expression expression) { LinkedListNode <Expression> node = expression.ListNode[script]; if (node.List == script.UnresolvedExpressions) { return(false); } if (null != node.List) { if (node.List != script.ResolvedExpressions) { throw new Exception("Expression is part of an unknown list"); } node.List.Remove(node); } script.UnresolvedExpressions.AddFirst(node); return(true); }
private void RegisterScript(ILuaIntellisenseDocument script, LuatTable parentPublicTable) { var table = new LuatTable(null); var publicTable = new LuatTable(table); // Chain the public tables using metatable indices so that a child script can // access the content of the parent's public table at global scope. publicTable.SetMetadataIndexTable(parentPublicTable); // Expose the content of the public table at global scope table.SetMetadataIndexTable(publicTable); // Register the script var luatScript = LuatScript.Create(); luatScript.Name = script.Name; luatScript.Table = table; luatScript.Path = script.Uri.LocalPath; luatScript.Reference = script; m_scripts.Add(luatScript); table.Description = Helpers.Decorate(script.Name, DecorationType.Code); }
public UnresolvedExpression(LuatScript script, Expression expression) { Script = script; Expression = expression; }
/// <summary> /// Scans the standard library folder for *.lua files, loading each into the m_stdLibs table /// </summary> private void DoLoadStandardLibrary() { var exePath = Assembly.GetEntryAssembly().Location; var exeFolder = Path.GetDirectoryName(exePath); if (string.IsNullOrEmpty(exeFolder)) { return; } var stdFolder = Path.Combine(exeFolder, "StandardLibrary"); if (!Directory.Exists(stdFolder) && !m_attemptedStandardLibraryInstall) { m_attemptedStandardLibraryInstall = true; try { Directory.CreateDirectory(stdFolder); var assembly = Assembly.GetAssembly(typeof(Database)); var resources = assembly.GetManifestResourceNames() .Where(name => name.StartsWith(StandardLibraryAssemblyPathPrefix)); foreach (var resource in resources) { using (var stream = assembly.GetManifestResourceStream(resource)) { if ((stream == null) || (stream == Stream.Null)) { continue; } var name = resource.Substring(StandardLibraryAssemblyPathPrefix.Length); using (var reader = new StreamReader(stream)) { try { var diskPath = Path.Combine(stdFolder, name); File.WriteAllText(diskPath, reader.ReadToEnd(), reader.CurrentEncoding); } catch (Exception ex) { ex.ToString(); } } } } } catch (Exception ex) { ex.ToString(); } } var stdFiles = Directory.GetFiles(stdFolder, "*.lua"); foreach (var stdFile in stdFiles) { using (var code = new StreamReader(stdFile)) { var luatScript = LuatScript.Create(); luatScript.Name = Path.GetFileNameWithoutExtension(stdFile); luatScript.Table = m_stdLibs; luatScript.Path = stdFile; lock (this) { m_scripts.Add(luatScript); } var document = new Document(); document.Text = code.ReadToEnd(); document.Filename = stdFile; document.Language = m_language; // triggers a reparse } } }
public LuatWarning(LuatScript script, WarningType type, TextRange textRange, string message) : base(textRange, message) { Script = script; Type = type; }