diff options
Diffstat (limited to 'docs/modules')
-rw-r--r-- | docs/modules/system.html | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/docs/modules/system.html b/docs/modules/system.html index fa41458..28ccf5a 100644 --- a/docs/modules/system.html +++ b/docs/modules/system.html | |||
@@ -124,6 +124,10 @@ | |||
124 | <td class="summary">Backs up terminal settings and restores them on application exit.</td> | 124 | <td class="summary">Backs up terminal settings and restores them on application exit.</td> |
125 | </tr> | 125 | </tr> |
126 | <tr> | 126 | <tr> |
127 | <td class="name" nowrap><a href="#detachfds">detachfds ()</a></td> | ||
128 | <td class="summary">Creates new file descriptions for <code>stdout</code> and <code>stderr</code>.</td> | ||
129 | </tr> | ||
130 | <tr> | ||
127 | <td class="name" nowrap><a href="#getconsolecp">getconsolecp ()</a></td> | 131 | <td class="name" nowrap><a href="#getconsolecp">getconsolecp ()</a></td> |
128 | <td class="summary">Gets the current console code page (Windows).</td> | 132 | <td class="summary">Gets the current console code page (Windows).</td> |
129 | </tr> | 133 | </tr> |
@@ -498,6 +502,40 @@ sequences will be buffered internally and returned one byte at a time. | |||
498 | 502 | ||
499 | </dd> | 503 | </dd> |
500 | <dt> | 504 | <dt> |
505 | <a name = "detachfds"></a> | ||
506 | <strong>detachfds ()</strong> | ||
507 | </dt> | ||
508 | <dd> | ||
509 | Creates new file descriptions for <code>stdout</code> and <code>stderr</code>. | ||
510 | Even if the file descriptors are unique, they still might point to the same | ||
511 | file description, and hence share settings like <code>O_NONBLOCK</code>. This means that | ||
512 | if one of them is set to non-blocking, the other will be as well. This can | ||
513 | lead to unexpected behavior.</p> | ||
514 | |||
515 | <p>This function is used to detach <code>stdout</code> and <code>stderr</code> from the original | ||
516 | file descriptions, and create new file descriptions for them. This allows | ||
517 | independent control of flags (e.g., <code>O_NONBLOCK</code>) on <code>stdout</code> and <code>stderr</code>, | ||
518 | avoiding shared side effects.</p> | ||
519 | |||
520 | <p>Does not modify <code>stdin</code> (fd 0), and does nothing on Windows. | ||
521 | |||
522 | |||
523 | |||
524 | <h3>Returns:</h3> | ||
525 | <ol> | ||
526 | |||
527 | boolean <code>true</code> on success, or throws an error on failure. | ||
528 | </ol> | ||
529 | |||
530 | |||
531 | <h3>See also:</h3> | ||
532 | <ul> | ||
533 | <a href="../modules/system.html#setnonblock">setnonblock</a> | ||
534 | </ul> | ||
535 | |||
536 | |||
537 | </dd> | ||
538 | <dt> | ||
501 | <a name = "getconsolecp"></a> | 539 | <a name = "getconsolecp"></a> |
502 | <strong>getconsolecp ()</strong> | 540 | <strong>getconsolecp ()</strong> |
503 | </dt> | 541 | </dt> |
@@ -632,6 +670,10 @@ for more information on the flags. | |||
632 | </ol> | 670 | </ol> |
633 | 671 | ||
634 | 672 | ||
673 | <h3>See also:</h3> | ||
674 | <ul> | ||
675 | <a href="../modules/system.html#setnonblock">setnonblock</a> | ||
676 | </ul> | ||
635 | 677 | ||
636 | 678 | ||
637 | </dd> | 679 | </dd> |
@@ -801,7 +843,7 @@ system.<span class="function-name">listconsoleflags</span>(<span class="global"> | |||
801 | </li> | 843 | </li> |
802 | <li><span class="parameter">fsleep</span> | 844 | <li><span class="parameter">fsleep</span> |
803 | <span class="types"><span class="type">function</span></span> | 845 | <span class="types"><span class="type">function</span></span> |
804 | the function to call for sleeping. | 846 | the function to call for sleeping; <code>ok, err = fsleep(secs)</code> |
805 | (<em>default</em> system.sleep) | 847 | (<em>default</em> system.sleep) |
806 | </li> | 848 | </li> |
807 | </ul> | 849 | </ul> |
@@ -819,7 +861,7 @@ system.<span class="function-name">listconsoleflags</span>(<span class="global"> | |||
819 | if no key was read</li> | 861 | if no key was read</li> |
820 | <li> | 862 | <li> |
821 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span> | 863 | <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span> |
822 | error message; <code>"timeout"</code> if the timeout was reached.</li> | 864 | error message when the timeout was reached (<code>"timeout"</code>), or if <a href="../modules/system.html#sleep">sleep</a> failed.</li> |
823 | </ol> | 865 | </ol> |
824 | 866 | ||
825 | 867 | ||
@@ -947,6 +989,7 @@ system.<span class="function-name">listconsoleflags</span>(<span class="global"> | |||
947 | </dt> | 989 | </dt> |
948 | <dd> | 990 | <dd> |
949 | Enables or disables non-blocking mode for a file (Posix). | 991 | Enables or disables non-blocking mode for a file (Posix). |
992 | Check <a href="../modules/system.html#detachfds">detachfds</a> in case there are shared file descriptions. | ||
950 | 993 | ||
951 | 994 | ||
952 | <h3>Parameters:</h3> | 995 | <h3>Parameters:</h3> |
@@ -985,13 +1028,15 @@ system.<span class="function-name">listconsoleflags</span>(<span class="global"> | |||
985 | 1028 | ||
986 | <h3>See also:</h3> | 1029 | <h3>See also:</h3> |
987 | <ul> | 1030 | <ul> |
988 | <a href="../modules/system.html#getnonblock">getnonblock</a> | 1031 | <li><a href="../modules/system.html#getnonblock">getnonblock</a></li> |
1032 | <li><a href="../modules/system.html#detachfds">detachfds</a></li> | ||
989 | </ul> | 1033 | </ul> |
990 | 1034 | ||
991 | <h3>Usage:</h3> | 1035 | <h3>Usage:</h3> |
992 | <ul> | 1036 | <ul> |
993 | <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span>(<span class="string">'system'</span>) | 1037 | <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span>(<span class="string">'system'</span>) |
994 | 1038 | sys.<span class="function-name">detachfds</span>() <span class="comment">-- detach stdout and stderr, so only stdin becomes non-blocking | |
1039 | </span> | ||
995 | <span class="comment">-- set io.stdin to non-blocking mode | 1040 | <span class="comment">-- set io.stdin to non-blocking mode |
996 | </span><span class="keyword">local</span> old_setting = sys.<span class="function-name">getnonblock</span>(<span class="global">io</span>.stdin) | 1041 | </span><span class="keyword">local</span> old_setting = sys.<span class="function-name">getnonblock</span>(<span class="global">io</span>.stdin) |
997 | sys.<span class="function-name">setnonblock</span>(<span class="global">io</span>.stdin, <span class="keyword">true</span>) | 1042 | sys.<span class="function-name">setnonblock</span>(<span class="global">io</span>.stdin, <span class="keyword">true</span>) |
@@ -1422,7 +1467,7 @@ This function will sleep, without doing a busy-loop and wasting CPU cycles. | |||
1422 | </div> <!-- id="main" --> | 1467 | </div> <!-- id="main" --> |
1423 | <div id="about"> | 1468 | <div id="about"> |
1424 | <i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> | 1469 | <i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> |
1425 | <i style="float:right;">Last updated 2025-03-12 15:17:50 </i> | 1470 | <i style="float:right;">Last updated 2025-04-10 10:12:11 </i> |
1426 | </div> <!-- id="about" --> | 1471 | </div> <!-- id="about" --> |
1427 | </div> <!-- id="container" --> | 1472 | </div> <!-- id="container" --> |
1428 | </body> | 1473 | </body> |