starting on curses library
First piece of working new vocabulary: print(curses:cols()) Just pulling in code from lcurses for the most part. But I'm trying to understand its internals as I gradually add them in, after my more blunt first approach of packaging up lcurses/ext failed. Overall plan for Teliva's API: - start out with a 'curses' library that does what people who are used to ncurses/lcurses expect. - over time create a more opinionated library called 'screen' or 'window' or something.
This commit is contained in:
parent
37b05c2957
commit
8552ad4ced
|
@ -26,8 +26,8 @@ LUA_A= liblua.a
|
|||
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
|
||||
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
|
||||
lundump.o lvm.o lzio.o
|
||||
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
|
||||
lstrlib.o loadlib.o linit.o
|
||||
LIB_O= lauxlib.o lbaselib.o lcurseslib.o ldblib.o liolib.o lmathlib.o \
|
||||
loslib.o ltablib.o lstrlib.o loadlib.o linit.o
|
||||
|
||||
LUA_T= lua
|
||||
LUA_O= lua.o
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#include <ncurses.h>
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
static int Pcols(lua_State *L) {
|
||||
lua_pushinteger(L, COLS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const struct luaL_Reg curseslib [] = {
|
||||
{"cols", Pcols},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
static void curses_newwin (lua_State *L, WINDOW *nw) {
|
||||
if (nw) {
|
||||
WINDOW **w = lua_newuserdata(L, sizeof(WINDOW*));
|
||||
luaL_getmetatable(L, "meta.window");
|
||||
lua_setmetatable(L, -2);
|
||||
*w = nw;
|
||||
}
|
||||
else {
|
||||
lua_pushliteral(L, "failed to create window");
|
||||
lua_error(L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API int luaopen_curses (lua_State *L) {
|
||||
luaL_register(L, "curses", curseslib);
|
||||
curses_newwin(L, stdscr);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ static const luaL_Reg lualibs[] = {
|
|||
{LUA_OSLIBNAME, luaopen_os},
|
||||
{LUA_STRLIBNAME, luaopen_string},
|
||||
{LUA_MATHLIBNAME, luaopen_math},
|
||||
{LUA_CURSESLIBNAME, luaopen_curses},
|
||||
{LUA_DBLIBNAME, luaopen_debug},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
@ -466,7 +466,6 @@ int main (int argc, char **argv) {
|
|||
/* stack: metatable */
|
||||
luaL_register(L, NULL, array_methods); /* register array_methods in metatable */
|
||||
luaL_register(L, "array", arraylib_functions);
|
||||
//? luaL_register(L, "curses.window", curses_window_fns);
|
||||
initscr();
|
||||
echo();
|
||||
s.argc = argc;
|
||||
|
|
|
@ -33,6 +33,9 @@ LUALIB_API int (luaopen_string) (lua_State *L);
|
|||
#define LUA_MATHLIBNAME "math"
|
||||
LUALIB_API int (luaopen_math) (lua_State *L);
|
||||
|
||||
#define LUA_CURSESLIBNAME "curses"
|
||||
LUALIB_API int (luaopen_curses) (lua_State *L);
|
||||
|
||||
#define LUA_DBLIBNAME "debug"
|
||||
LUALIB_API int (luaopen_debug) (lua_State *L);
|
||||
|
||||
|
|
Loading…
Reference in New Issue