Blob Blame History Raw
<!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>luaposix 33.3.0 Reference</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>luaposix 33.3.0</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
  <li><strong>curses.lua</strong></li>
  <li><a href="../examples/dir.lua.html">dir.lua</a></li>
  <li><a href="../examples/fork.lua.html">fork.lua</a></li>
  <li><a href="../examples/fork2.lua.html">fork2.lua</a></li>
  <li><a href="../examples/getopt.lua.html">getopt.lua</a></li>
  <li><a href="../examples/glob.lua.html">glob.lua</a></li>
  <li><a href="../examples/limit.lua.html">limit.lua</a></li>
  <li><a href="../examples/lock.lua.html">lock.lua</a></li>
  <li><a href="../examples/netlink-uevent.lua.html">netlink-uevent.lua</a></li>
  <li><a href="../examples/ping.lua.html">ping.lua</a></li>
  <li><a href="../examples/poll.lua.html">poll.lua</a></li>
  <li><a href="../examples/rt_sched.lua.html">rt_sched.lua</a></li>
  <li><a href="../examples/signal.lua.html">signal.lua</a></li>
  <li><a href="../examples/socket.lua.html">socket.lua</a></li>
  <li><a href="../examples/termios.lua.html">termios.lua</a></li>
  <li><a href="../examples/tree.lua.html">tree.lua</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
  <li><a href="../modules/posix.html">posix</a></li>
  <li><a href="../modules/posix.ctype.html">posix.ctype</a></li>
  <li><a href="../modules/posix.curses.html">posix.curses</a></li>
  <li><a href="../modules/posix.dirent.html">posix.dirent</a></li>
  <li><a href="../modules/posix.errno.html">posix.errno</a></li>
  <li><a href="../modules/posix.fcntl.html">posix.fcntl</a></li>
  <li><a href="../modules/posix.fnmatch.html">posix.fnmatch</a></li>
  <li><a href="../modules/posix.getopt.html">posix.getopt</a></li>
  <li><a href="../modules/posix.glob.html">posix.glob</a></li>
  <li><a href="../modules/posix.grp.html">posix.grp</a></li>
  <li><a href="../modules/posix.libgen.html">posix.libgen</a></li>
  <li><a href="../modules/posix.poll.html">posix.poll</a></li>
  <li><a href="../modules/posix.pwd.html">posix.pwd</a></li>
  <li><a href="../modules/posix.sched.html">posix.sched</a></li>
  <li><a href="../modules/posix.signal.html">posix.signal</a></li>
  <li><a href="../modules/posix.stdio.html">posix.stdio</a></li>
  <li><a href="../modules/posix.stdlib.html">posix.stdlib</a></li>
  <li><a href="../modules/posix.sys.msg.html">posix.sys.msg</a></li>
  <li><a href="../modules/posix.sys.resource.html">posix.sys.resource</a></li>
  <li><a href="../modules/posix.sys.socket.html">posix.sys.socket</a></li>
  <li><a href="../modules/posix.sys.stat.html">posix.sys.stat</a></li>
  <li><a href="../modules/posix.sys.statvfs.html">posix.sys.statvfs</a></li>
  <li><a href="../modules/posix.sys.time.html">posix.sys.time</a></li>
  <li><a href="../modules/posix.sys.times.html">posix.sys.times</a></li>
  <li><a href="../modules/posix.sys.utsname.html">posix.sys.utsname</a></li>
  <li><a href="../modules/posix.sys.wait.html">posix.sys.wait</a></li>
  <li><a href="../modules/posix.syslog.html">posix.syslog</a></li>
  <li><a href="../modules/posix.termio.html">posix.termio</a></li>
  <li><a href="../modules/posix.time.html">posix.time</a></li>
  <li><a href="../modules/posix.unistd.html">posix.unistd</a></li>
  <li><a href="../modules/posix.utime.html">posix.utime</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
  <li><a href="../classes/posix.curses.chstr.html">posix.curses.chstr</a></li>
  <li><a href="../classes/posix.curses.window.html">posix.curses.window</a></li>
</ul>

</div>

<div id="content">

    <h2>curses.lua</h2>
<pre>
<span class="keyword">local</span> curses = <span class="global">require</span> <span class="string">"curses"</span>


<span class="keyword">local</span> <span class="keyword">function</span> printf (fmt, ...)
  <span class="keyword">return</span> <span class="global">print</span> (<span class="global">string</span>.format (fmt, ...))
<span class="keyword">end</span>


<span class="keyword">local</span> <span class="keyword">function</span> main ()
  <span class="keyword">local</span> stdscr = curses.initscr ()

  curses.cbreak ()
  curses.echo (<span class="number">0</span>)	<span class="comment">-- not noecho !
</span>  curses.nl( <span class="number">0</span>)		<span class="comment">-- not nonl !
</span>
  stdscr:clear()

  <span class="keyword">local</span> a = {}
  <span class="keyword">for</span> k, v <span class="keyword">in</span> <span class="global">pairs</span> (curses) <span class="keyword">do</span>
    <span class="keyword">if</span> <span class="global">type</span> (v) == <span class="string">"number"</span> <span class="keyword">then</span> a[#a+<span class="number">1</span>] = k <span class="keyword">end</span>
  <span class="keyword">end</span>

  stdscr:mvaddstr (<span class="number">15</span>, <span class="number">20</span>, <span class="string">"print out curses constants (y/n) ? "</span>)
  stdscr:refresh()

  <span class="keyword">local</span> c = stdscr:getch ()
  <span class="keyword">if</span> c &lt; <span class="number">256</span> <span class="keyword">then</span> c = <span class="global">string</span>.char (c) <span class="keyword">end</span>

  curses.endwin ()

  <span class="keyword">if</span> c == <span class="string">"y"</span> <span class="keyword">then</span>
    <span class="global">table</span>.sort (a, cmp)
    <span class="keyword">for</span> i, k <span class="keyword">in</span> <span class="global">ipairs</span> (a) <span class="keyword">do</span>
      printf (<span class="string">" %03d. %20s = 0x%08x (%d)"</span>,
        i, <span class="string">"curses."</span> .. k, curses[k], curses[k])
    <span class="keyword">end</span>
  <span class="keyword">end</span>
<span class="keyword">end</span>


<span class="comment">-- To display Lua errors, we must close curses to return to
</span><span class="comment">-- normal terminal mode, and then write the error to stdout.
</span><span class="keyword">local</span> <span class="keyword">function</span> err (err)
  curses.endwin ()
  <span class="global">print</span> <span class="string">"Caught an error:"</span>
  <span class="global">print</span> (<span class="global">debug</span>.traceback (err, <span class="number">2</span>))
  <span class="global">os</span>.exit (<span class="number">2</span>)
<span class="keyword">end</span>

<span class="global">xpcall</span> (main, err)</pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-03-01 09:06:02 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>