1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Luxio Light UNIX I/O</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Luxio Light UNIX I/O</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Tables">Tables</a></li>
<li><a href="#Class_file">Class file </a></li>
<li><a href="#Helper_functions">Helper functions </a></li>
<li><a href="#Opening_files">Opening files </a></li>
</ul>
<h2>Modules</h2>
<ul>
<li><a href="../modules/luxio.html">luxio</a></li>
<li><strong>luxio.simple</strong></li>
</ul>
</div>
<div id="content">
<h1>Module <code>luxio.simple</code></h1>
<p>High-level bindings to POSIX functionality.</p>
<p></p>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#stat">stat</a></td>
<td class="summary">stat result table.</td>
</tr>
</table>
<h2><a href="#Class_file">Class file </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#file.fd">file.fd</a></td>
<td class="summary">The file descriptor as a number.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file.name">file.name</a></td>
<td class="summary">Helpful text representation of file handle.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:close">file:close()</a></td>
<td class="summary">Close an open file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:nogc">file:nogc()</a></td>
<td class="summary">Disable garbage collection of a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:nonblocking">file:nonblocking(blocking)</a></td>
<td class="summary">Set the non-blocking flag on a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:write">file:write(data[, offset=1])</a></td>
<td class="summary">Write data to a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:writev">file:writev(...)</a></td>
<td class="summary">Write a list of strings to a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:read">file:read(...)</a></td>
<td class="summary">Read data from a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:fstat">file:fstat()</a></td>
<td class="summary">Get information on an option file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:seek">file:seek(whence, offset)</a></td>
<td class="summary">Change the position within a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:lock">file:lock(rw, whence, offset, len, wait, test)</a></td>
<td class="summary">Apply or remove an advisory lock on an open file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#file:unlock">file:unlock(whence, offset, len)</a></td>
<td class="summary">Unlock a region of an open file.</td>
</tr>
</table>
<h2><a href="#Helper_functions">Helper functions </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#flags">flags(...)</a></td>
<td class="summary">Convert a string of comma-seperated flag names to a number.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#tomode">tomode(f)</a></td>
<td class="summary">Convert a string representing a permissions mode to a number.</td>
</tr>
</table>
<h2><a href="#Opening_files">Opening files </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#open">open(filename[, flags="r"[, number]])</a></td>
<td class="summary">Open a file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#pipe">pipe()</a></td>
<td class="summary">Create an anonymous pipe.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#pipe">pipe()</a></td>
<td class="summary">Create an anonymous UNIX domain socket pair.</td>
</tr>
</table>
<br/>
<br/>
<h2><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "stat"></a>
<strong>stat</strong>
</dt>
<dd>
stat result table.
The table that all the stat family returns.
<h3>Fields:</h3>
<ul>
<li><span class="parameter">dev</span>
ID of device containing file
</li>
<li><span class="parameter">ino</span>
inode number
</li>
<li><span class="parameter">mode</span>
protection mode
</li>
<li><span class="parameter">nlink</span>
number of hard links
</li>
<li><span class="parameter">uid</span>
user ID of owner
</li>
<li><span class="parameter">gid</span>
group ID of owner
</li>
<li><span class="parameter">rdev</span>
device ID (if special file)
</li>
<li><span class="parameter">size</span>
total size, in bytes
</li>
<li><span class="parameter">blksize</span>
blocksize for file system I/O
</li>
<li><span class="parameter">blocks</span>
number of 512 byte blocks allocated
</li>
<li><span class="parameter">atime</span>
time of last access
</li>
<li><span class="parameter">mtime</span>
time of last modification
</li>
<li><span class="parameter">ctime</span>
time of last status change
</li>
</ul>
</dd>
</dl>
<h2><a name="Class_file"></a>Class file </h2>
The basic type used to expose file handles.
<dl class="function">
<dt>
<a name = "file.fd"></a>
<strong>file.fd</strong>
</dt>
<dd>
The file descriptor as a number.
</dd>
<dt>
<a name = "file.name"></a>
<strong>file.name</strong>
</dt>
<dd>
Helpful text representation of file handle.
</dd>
<dt>
<a name = "file:close"></a>
<strong>file:close()</strong>
</dt>
<dd>
Close an open file.
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">bool</span> or <span class="type">nil</span></span>
true on success, nil on failure</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno on error</li>
</ol>
</dd>
<dt>
<a name = "file:nogc"></a>
<strong>file:nogc()</strong>
</dt>
<dd>
Disable garbage collection of a file.
</dd>
<dt>
<a name = "file:nonblocking"></a>
<strong>file:nonblocking(blocking)</strong>
</dt>
<dd>
Set the non-blocking flag on a file.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">blocking</span>
<span class="types"><span class="type">bool</span></span>
true for non-blocking, false or nil for blocking.
</li>
</ul>
</dd>
<dt>
<a name = "file:write"></a>
<strong>file:write(data[, offset=1])</strong>
</dt>
<dd>
Write data to a file.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">data</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">offset</span>
<span class="types"><span class="type">number</span></span>
into string to start write from
(<em>default</em> 1)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
bytes written, or nil on error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
<dt>
<a name = "file:writev"></a>
<strong>file:writev(...)</strong>
</dt>
<dd>
Write a list of strings to a file.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
List of strings to write
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
Bytes written, or nil in case of error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
<dt>
<a name = "file:read"></a>
<strong>file:read(...)</strong>
</dt>
<dd>
<p>Read data from a file.
This function takes a list of patterns to read, based loosely
on Lua’s own read function. They are:</p>
<ul>
<li>“*a” - read all data until end of file.</li>
<li>“*l” - read a single line of data, or until end of file.</li>
<li>Or, a number describing the number of bytes to read.</li>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
List of read patterns.
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">...</span> or <span class="type">nil</span></span>
List of return strings, or nil if error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
String describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
<dt>
<a name = "file:fstat"></a>
<strong>file:fstat()</strong>
</dt>
<dd>
Get information on an option file.
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="../modules/luxio.simple.html#stat">stat</a> or <span class="type">nil</span></span>
stat table or nil if error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
<dt>
<a name = "file:seek"></a>
<strong>file:seek(whence, offset)</strong>
</dt>
<dd>
Change the position within a file.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">whence</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
one of “cur”, “set”, and “end”.
</li>
<li><span class="parameter">offset</span>
<span class="types"><span class="type">number</span></span>
signed number describing requested change.
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">number</span> or <span class="type">nil</span></span>
resulting offset, as measured from beginning of file
in bytes, or nil if error.</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
<dt>
<a name = "file:lock"></a>
<strong>file:lock(rw, whence, offset, len, wait, test)</strong>
</dt>
<dd>
Apply or remove an advisory lock on an open file.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rw</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Lock type “r” for read, “w” for write, “” for unlock.
</li>
<li><span class="parameter">whence</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
one of “cur”, “set”, and “end”
</li>
<li><span class="parameter">offset</span>
<span class="types"><span class="type">number</span></span>
offset of start of lock/unlock location
</li>
<li><span class="parameter">len</span>
<span class="types"><span class="type">number</span></span>
length in bytes of lock/unlock locations
</li>
<li><span class="parameter">wait</span>
<span class="types"><span class="type">bool</span></span>
true if the call should block until region is unlocked
</li>
<li><span class="parameter">test</span>
<span class="types"><span class="type">bool</span></span>
true if you simply want to check if locked
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">true</span> or <span class="type">nil</span></span>
nil if error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
<dt>
<a name = "file:unlock"></a>
<strong>file:unlock(whence, offset, len)</strong>
</dt>
<dd>
Unlock a region of an open file.
Convienence function. Simply calls <a href="../modules/luxio.simple.html#file:lock">file:lock</a> with an empty rw.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">whence</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">offset</span>
<span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">len</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">true</span> or <span class="type">nil</span></span>
nil if error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
string describing error if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
errno if error</li>
</ol>
</dd>
</dl>
<h2><a name="Helper_functions"></a>Helper functions </h2>
<dl class="function">
<dt>
<a name = "flags"></a>
<strong>flags(...)</strong>
</dt>
<dd>
<p>Convert a string of comma-seperated flag names to a number.
This function takes a list of strings, each with comma-seperated flag names
and returns a number which is all of those flags ORed together.
Flags can optionally be lower-case, and also if they begin with one of
the common prefixes, such as O<em>, S</em>, F<em>, AF</em>, AI<em>, SO</em>, TCP_ and many others
can be omitted.
For example:</p>
<pre><code> myflags = sio.flags "rdwr,creat,excl"
</code></pre>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">number</span></span>
</ol>
</dd>
<dt>
<a name = "tomode"></a>
<strong>tomode(f)</strong>
</dt>
<dd>
<p>Convert a string representing a permissions mode to a number.
This function converts a string into a mode flag. It supports
many different forms. For example:</p>
<pre><code>sio.tomode(0666) -- already a mode, it'll just return it
sio.tomode "666" -- converted directly to number, assumed octal
sio.tomode "-rw-r--r--" -- as emitted by ls
sio.tomode "o+rw,g+r" -- as used by chmod
</code></pre>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">f</span>
<span class="types"><span class="type">number</span> or <a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
mode description to convert
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">number</span></span>
</ol>
</dd>
</dl>
<h2><a name="Opening_files"></a>Opening files </h2>
<dl class="function">
<dt>
<a name = "open"></a>
<strong>open(filename[, flags="r"[, number]])</strong>
</dt>
<dd>
<p>Open a file.
The open type may contain the following characters;</p>
<ul>
<li> r - open file for reading</li>
<li> w - open file for writing</li>
<li> + - append</li>
<li> e - open and create exclusively (O_EXCL and O_CREAT)</li>
<li> c - create file if it doesn’t exist. (O_CREAT)</li>
<li> n - do not modify access time (O_NOATIME)</li>
<li> d - open in non-blocking mode (O_NDELAY)</li>
<li> t - truncate file</li>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">filename</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">flags</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
open type
(<em>default</em> "r")
</li>
<li><span class="parameter">number</span>
<span class="types"><span class="type">mode</span></span>
permissions mode if creating.
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="../modules/luxio.simple.html#Class_file">file</a> or <span class="type">nil</span></span>
File handle, or nil if error</li>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a> or <span class="type">nil</span></span>
Error string if error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
Error number if error</li>
</ol>
</dd>
<dt>
<a name = "pipe"></a>
<strong>pipe()</strong>
</dt>
<dd>
Create an anonymous pipe.
Returns two files, the first one can be used to read data written
to the second.
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="../modules/luxio.simple.html#Class_file">file</a> or <span class="type">nil</span></span>
Reading half of pipe, or nil on error</li>
<li>
<span class="types"><a class="type" href="../modules/luxio.simple.html#Class_file">file</a> or <a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Writing half of pipe, or string describing error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
Error number if error</li>
</ol>
</dd>
<dt>
<a name = "pipe"></a>
<strong>pipe()</strong>
</dt>
<dd>
Create an anonymous UNIX domain socket pair.
Returns two files, which can be considered as each end of a bi-directional
pipe.
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="../modules/luxio.simple.html#Class_file">file</a> or <span class="type">nil</span></span>
First socket of the pair, or nil on error</li>
<li>
<span class="types"><a class="type" href="../modules/luxio.simple.html#Class_file">file</a> or <a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
Second socket of the pair, or string describing error</li>
<li>
<span class="types"><span class="type">errno</span> or <span class="type">nil</span></span>
Error number if error</li>
</ol>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.0</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
|