/Code/Angel/Libraries/lua-libs/luafilesystem-1.5.0/doc/us/manual.html

http://angel-engine.googlecode.com/ · HTML · 271 lines · 223 code · 48 blank · 0 comment · 0 complexity · 4ce5fbcb073538cb5509c20e7fa4b13b MD5 · raw file

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