manual.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>LuaFileSystem</title>
  6. <link rel="stylesheet" href="doc.css" type="text/css"/>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo">
  13. <a href="http://keplerproject.github.io/luafilesystem">
  14. <img alt="LuaFileSystem" src="luafilesystem.png"/>
  15. </a>
  16. </div>
  17. <div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
  18. <div id="product_description">File System Library for the Lua Programming Language</div>
  19. </div> <!-- id="product" -->
  20. <div id="main">
  21. <div id="navigation">
  22. <h1>LuaFileSystem</h1>
  23. <ul>
  24. <li><a href="index.html">Home</a>
  25. <ul>
  26. <li><a href="index.html#overview">Overview</a></li>
  27. <li><a href="index.html#status">Status</a></li>
  28. <li><a href="index.html#download">Download</a></li>
  29. <li><a href="index.html#history">History</a></li>
  30. <li><a href="index.html#credits">Credits</a></li>
  31. </ul>
  32. </li>
  33. <li><strong>Manual</strong>
  34. <ul>
  35. <li><a href="manual.html#introduction">Introduction</a></li>
  36. <li><a href="manual.html#building">Building</a></li>
  37. <li><a href="manual.html#installation">Installation</a></li>
  38. <li><a href="manual.html#reference">Reference</a></li>
  39. </ul>
  40. </li>
  41. <li><a href="examples.html">Examples</a></li>
  42. <li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
  43. <ul>
  44. <li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
  45. <li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
  46. </ul>
  47. </li>
  48. <li><a href="license.html">License</a></li>
  49. </ul>
  50. </div> <!-- id="navigation" -->
  51. <div id="content">
  52. <h2><a name="introduction"></a>Introduction</h2>
  53. <p>LuaFileSystem is a <a href="http://www.lua.org">Lua</a> library
  54. developed to complement the set of functions related to file
  55. systems offered by the standard Lua distribution.</p>
  56. <p>LuaFileSystem offers a portable way to access
  57. the underlying directory structure and file attributes.</p>
  58. <h2><a name="building"></a>Building</h2>
  59. <p>
  60. LuaFileSystem should be built with Lua 5.1 so the language library
  61. and header files for the target version must be installed properly.
  62. </p>
  63. <p>
  64. LuaFileSystem offers a Makefile and a separate configuration file,
  65. <code>config</code>,
  66. which should be edited to suit your installation before running
  67. <code>make</code>.
  68. The file has some definitions like paths to the external libraries,
  69. compiler options and the like.
  70. </p>
  71. <p>On Windows, the C runtime used to compile LuaFileSystem must be the same
  72. runtime that Lua uses, or some LuaFileSystem functions will not work.</p>
  73. <h2><a name="installation"></a>Installation</h2>
  74. <p>The easiest way to install LuaFileSystem is to use LuaRocks:</p>
  75. <pre class="example">
  76. luarocks install luafilesystem
  77. </pre>
  78. <p>If you prefer to install LuaFileSystem manually, the compiled binary should be copied to a directory in your
  79. <a href="http://www.lua.org/manual/5.1/manual.html#pdf-package.cpath">C path</a>.</p>
  80. <h2><a name="reference"></a>Reference</h2>
  81. <p>
  82. LuaFileSystem offers the following functions:
  83. </p>
  84. <dl class="reference">
  85. <dt><a name="attributes"></a><strong><code>lfs.attributes (filepath [, request_name | result_table])</code></strong></dt>
  86. <dd>Returns a table with the file attributes corresponding to
  87. <code>filepath</code> (or <code>nil</code> followed by an error message and a system-dependent error code
  88. in case of error).
  89. If the second optional argument is given and is a string, then only the value of the
  90. named attribute is returned (this use is equivalent to
  91. <code>lfs.attributes(filepath)[request_name]</code>, but the table is not created
  92. and only one attribute is retrieved from the O.S.).
  93. if a table is passed as the second argument, it (<code>result_table</code>) is filled with attributes and returned instead of a new table.
  94. The attributes are described as follows;
  95. attribute <code>mode</code> is a string, all the others are numbers,
  96. and the time related attributes use the same time reference of
  97. <a href="http://www.lua.org/manual/5.1/manual.html#pdf-os.time"><code>os.time</code></a>:
  98. <dl>
  99. <dt><strong><code>dev</code></strong></dt>
  100. <dd>on Unix systems, this represents the device that the inode resides on. On Windows systems,
  101. represents the drive number of the disk containing the file</dd>
  102. <dt><strong><code>ino</code></strong></dt>
  103. <dd>on Unix systems, this represents the inode number. On Windows systems this has no meaning</dd>
  104. <dt><strong><code>mode</code></strong></dt>
  105. <dd>string representing the associated protection mode (the values could be
  106. <code>file</code>, <code>directory</code>, <code>link</code>, <code>socket</code>,
  107. <code>named pipe</code>, <code>char device</code>, <code>block device</code> or
  108. <code>other</code>)</dd>
  109. <dt><strong><code>nlink</code></strong></dt>
  110. <dd>number of hard links to the file</dd>
  111. <dt><strong><code>uid</code></strong></dt>
  112. <dd>user-id of owner (Unix only, always 0 on Windows)</dd>
  113. <dt><strong><code>gid</code></strong></dt>
  114. <dd>group-id of owner (Unix only, always 0 on Windows)</dd>
  115. <dt><strong><code>rdev</code></strong></dt>
  116. <dd>on Unix systems, represents the device type, for special file inodes.
  117. On Windows systems represents the same as <code>dev</code></dd>
  118. <dt><strong><code>access</code></strong></dt>
  119. <dd>time of last access</dd>
  120. <dt><strong><code>modification</code></strong></dt>
  121. <dd>time of last data modification</dd>
  122. <dt><strong><code>change</code></strong></dt>
  123. <dd>time of last file status change</dd>
  124. <dt><strong><code>size</code></strong></dt>
  125. <dd>file size, in bytes</dd>
  126. <dt><strong><code>permissions</code></strong></dt>
  127. <dd>file permissions string</dd>
  128. <dt><strong><code>blocks</code></strong></dt>
  129. <dd>block allocated for file; (Unix only)</dd>
  130. <dt><strong><code>blksize</code></strong></dt>
  131. <dd>optimal file system I/O blocksize; (Unix only)</dd>
  132. </dl>
  133. This function uses <code>stat</code> internally thus if the given
  134. <code>filepath</code> is a symbolic link, it is followed (if it points to
  135. another link the chain is followed recursively) and the information
  136. is about the file it refers to.
  137. To obtain information about the link itself, see function
  138. <a href="#symlinkattributes">lfs.symlinkattributes</a>.
  139. </dd>
  140. <dt><a name="chdir"></a><strong><code>lfs.chdir (path)</code></strong></dt>
  141. <dd>Changes the current working directory to the given
  142. <code>path</code>.<br />
  143. Returns <code>true</code> in case of success or <code>nil</code> plus an
  144. error string.</dd>
  145. <dt><a name="lock_dir"></a><strong><code>lfs.lock_dir(path, [seconds_stale])</code></strong></dt>
  146. <dd>Creates a lockfile (called lockfile.lfs) in <code>path</code> if it does not
  147. exist and returns the lock. If the lock already exists checks if
  148. it's stale, using the second parameter (default for the second
  149. parameter is <code>INT_MAX</code>, which in practice means the lock will never
  150. be stale. To free the the lock call <code>lock:free()</code>. <br/>
  151. In case of any errors it returns nil and the error message. In
  152. particular, if the lock exists and is not stale it returns the
  153. "File exists" message.</dd>
  154. <dt><a name="currentdir"></a><strong><code>lfs.currentdir ()</code></strong></dt>
  155. <dd>Returns a string with the current working directory or <code>nil</code>
  156. plus an error string.</dd>
  157. <dt><a name="dir"></a><strong><code>iter, dir_obj = lfs.dir (path)</code></strong></dt>
  158. <dd>
  159. Lua iterator over the entries of a given directory.
  160. Each time the iterator is called with <code>dir_obj</code> it returns a directory entry's name as a string, or
  161. <code>nil</code> if there are no more entries. You can also iterate by calling <code>dir_obj:next()</code>, and
  162. explicitly close the directory before the iteration finished with <code>dir_obj:close()</code>.
  163. Raises an error if <code>path</code> is not a directory.
  164. </dd>
  165. <dt><a name="lock"></a><strong><code>lfs.lock (filehandle, mode[, start[, length]])</code></strong></dt>
  166. <dd>Locks a file or a part of it. This function works on <em>open files</em>; the
  167. file handle should be specified as the first argument.
  168. The string <code>mode</code> could be either
  169. <code>r</code> (for a read/shared lock) or <code>w</code> (for a
  170. write/exclusive lock). The optional arguments <code>start</code>
  171. and <code>length</code> can be used to specify a starting point and
  172. its length; both should be numbers.<br />
  173. Returns <code>true</code> if the operation was successful; in
  174. case of error, it returns <code>nil</code> plus an error string.
  175. </dd>
  176. <dt><a name="link"></a><strong><code>lfs.link (old, new[, symlink])</code></strong></dt>
  177. <dd>Creates a link. The first argument is the object to link to
  178. and the second is the name of the link. If the optional third
  179. argument is true, the link will by a symbolic link (by default, a
  180. hard link is created).
  181. </dd>
  182. <dt><a name="mkdir"></a><strong><code>lfs.mkdir (dirname)</code></strong></dt>
  183. <dd>Creates a new directory. The argument is the name of the new
  184. directory.<br />
  185. Returns <code>true</code> in case of success or <code>nil</code>, an error message and
  186. a system-dependent error code in case of error.
  187. </dd>
  188. <dt><a name="rmdir"></a><strong><code>lfs.rmdir (dirname)</code></strong></dt>
  189. <dd>Removes an existing directory. The argument is the name of the directory.<br />
  190. Returns <code>true</code> in case of success or <code>nil</code>, an error message and
  191. a system-dependent error code in case of error.
  192. <dt><a name="setmode"></a><strong><code>lfs.setmode (file, mode)</code></strong></dt>
  193. <dd>Sets the writing mode for a file. The mode string can be either <code>"binary"</code> or <code>"text"</code>.
  194. Returns <code>true</code> followed the previous mode string for the file, or
  195. <code>nil</code> followed by an error string in case of errors.
  196. On non-Windows platforms, where the two modes are identical,
  197. setting the mode has no effect, and the mode is always returned as <code>binary</code>.
  198. </dd>
  199. <dt><a name="symlinkattributes"></a><strong><code>lfs.symlinkattributes (filepath [, request_name])</code></strong></dt>
  200. <dd>Identical to <a href="#attributes">lfs.attributes</a> except that
  201. it obtains information about the link itself (not the file it refers to).
  202. It also adds a <strong><code>target</code></strong> field, containing
  203. the file name that the symlink points to.
  204. On Windows this function does not yet support links, and is identical to
  205. <code>lfs.attributes</code>.
  206. </dd>
  207. <dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt>
  208. <dd>Set access and modification times of a file. This function is
  209. a bind to <code>utime</code> function. The first argument is the
  210. filename, the second argument (<code>atime</code>) is the access time,
  211. and the third argument (<code>mtime</code>) is the modification time.
  212. Both times are provided in seconds (which should be generated with
  213. Lua standard function <code>os.time</code>).
  214. If the modification time is omitted, the access time provided is used;
  215. if both times are omitted, the current time is used.<br />
  216. Returns <code>true</code> in case of success or <code>nil</code>, an error message and
  217. a system-dependent error code in case of error.
  218. </dd>
  219. <dt><a name="unlock"></a><strong><code>lfs.unlock (filehandle[, start[, length]])</code></strong></dt>
  220. <dd>Unlocks a file or a part of it. This function works on
  221. <em>open files</em>; the file handle should be specified as the first
  222. argument. The optional arguments <code>start</code> and
  223. <code>length</code> can be used to specify a starting point and its
  224. length; both should be numbers.<br />
  225. Returns <code>true</code> if the operation was successful;
  226. in case of error, it returns <code>nil</code> plus an error string.
  227. </dd>
  228. </dl>
  229. </div> <!-- id="content" -->
  230. </div> <!-- id="main" -->
  231. <div id="about">
  232. <p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
  233. </div> <!-- id="about" -->
  234. </div> <!-- id="container" -->
  235. </body>
  236. </html>