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); }
/// <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 } } }