diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-19 19:11:03 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-19 19:11:03 -0800 |
commit | b43747ecef13a7cbe5eb5842d03d803165a473b3 (patch) | |
tree | dbecfd6324961dd4c1debfc3fb1128acf5794a55 /src/lcurses/curses.lua | |
parent | 9837d327f5617852167d82ed589c9342539072ac (diff) | |
download | teliva-b43747ecef13a7cbe5eb5842d03d803165a473b3.tar.gz |
inline lcurses maximally rather than minimally
Until now we had just the bare minimum bindings needed for the demos built so far. Now we have all of lcurses building in place with minimal changes. The changes in this commit can run hanoi.lua when inlined into Lua 5.1, but don't work with Teliva.
Diffstat (limited to 'src/lcurses/curses.lua')
-rw-r--r-- | src/lcurses/curses.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lcurses/curses.lua b/src/lcurses/curses.lua new file mode 100644 index 0000000..bba9d12 --- /dev/null +++ b/src/lcurses/curses.lua @@ -0,0 +1,58 @@ +--- Lua bindings for curses +local M = curses + +-- These Lua functions detect number of args, like Unified Funcs in Perl Curses +-- see http://pjb.com.au/comp/lua/lcurses.html +-- see http://search.cpan.org/perldoc?Curses + +function M.addch (...) + if #{...} == 3 then + return curses.stdscr():mvaddch(...) + else + return curses.stdscr():addch(...) + end +end + +function M.addstr(...) -- detect number of args, like Unified Funcs in Perl Curses + if #{...} == 3 then + return curses.stdscr():mvaddstr(...) + else + return curses.stdscr():addstr(...) + end +end + +function M.attrset (a) return curses.stdscr():attrset(a) end +function M.clear () return curses.stdscr():clear() end +function M.clrtobot () return curses.stdscr():clrtobot() end +function M.clrtoeol () return curses.stdscr():clrtoeol() end + +function M.getch (...) + local c + if #{...} == 2 then + c = curses.stdscr():mvgetch(...) + else + c = curses.stdscr():getch() + end + if c < 256 then + return string.char(c) + end + -- could kludge-test for utf8, e.g. c3 a9 20 c3 aa 20 c3 ab 20 e2 82 ac 0a + return c +end + +function M.getstr (...) + if #{...} > 1 then + return curses.stdscr():mvgetstr(...) + else + return curses.stdscr():getstr(...) + end +end +M.getnstr = M.getstr + +function M.getyx () return curses.stdscr():getyx() end +function M.keypad (b) return curses.stdscr():keypad(b) end +function M.move (y,x) return curses.stdscr():move(y,x) end +function M.refresh () return curses.stdscr():refresh() end +function M.timeout (t) return curses.stdscr():timeout(t) end + +return M |