/*** Create a unique temporary directory. @function mkdtemp @string templ pattern that ends in six 'X' characters @treturn[1] string path to directory, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see mkdtemp(3) */ static int Pmkdtemp(lua_State *L) { #if defined LPOSIX_2008_COMPLIANT const char *path = luaL_checkstring(L, 1); size_t path_len = strlen(path) + 1; void *ud; lua_Alloc lalloc; char *tmppath; char *r; checknargs(L, 1); lalloc = lua_getallocf(L, &ud); if ((tmppath = lalloc(ud, NULL, 0, path_len)) == NULL) return pusherror(L, "lalloc"); strcpy(tmppath, path); if ((r = mkdtemp(tmppath))) lua_pushstring(L, tmppath); lalloc(ud, tmppath, path_len, 0); return (r == NULL) ? pusherror(L, path) : 1; #else return binding_notimplemented(L, "mkdtemp", "C"); #endif }
/*** Mark the soft label key area for refresh. @function slk_touch @treturn bool `true`, if successful @see slk_touch(3x) */ static int Pslk_touch(lua_State *L) { #if LCURSES_POSIX_COMPLIANT return pushokresult(slk_touch()); #else return binding_notimplemented(L, "slk_touch", "curses"); #endif }
/*** Disable an attribute for soft labels. @function slk_attroff @int attrs @treturn bool `true`, if successful @see slk_attroff(3x) */ static int Pslk_attroff(lua_State *L) { chtype attrs = checkch(L, 1); #if LCURSES_POSIX_COMPLIANT return pushokresult(slk_attroff(attrs)); #else return binding_notimplemented(L, "slk_attroff", "curses"); #endif }
/*** Fetch the label for a soft label key. @function slk_label @int labnum @treturn string current label for *labnum* @see slk_label(3x) */ static int Pslk_label(lua_State *L) { int labnum = checkint(L, 1); #if LCURSES_POSIX_COMPLIANT return pushstringresult(slk_label(labnum)); #else return binding_notimplemented(L, "slk_label", "curses"); #endif }
/*** Initialise the soft label keys area. This must be called before @{initscr}. @function slk_init @int fmt @treturn bool `true`, if successful @see slk_init(3x) */ static int Pslk_init(lua_State *L) { int fmt = checkint(L, 1); #if LCURSES_POSIX_COMPLIANT return pushokresult(slk_init(fmt)); #else return binding_notimplemented(L, "slk_init", "curses"); #endif }
/*** Change the terminal size. @function resizeterm @int nlines number of lines @int ncols number of columns @treturn bool `true`, if successful @raise unimplemented @fixme ncurses only? */ static int Presizeterm(lua_State *L) { int nlines = checkint(L, 1); int ncols = checkint(L, 2); #if HAVE_RESIZETERM return pushokresult(resizeterm (nlines, ncols)); #else return binding_notimplemented(L, "resizeterm", "curses"); #endif }
/*** Set the label for a soft label key. @function slk_set @int labnum @string label @int fmt @treturn bool `true`, if successful @see slk_set(3x) */ static int Pslk_set(lua_State *L) { int labnum = checkint(L, 1); const char* label = luaL_checkstring(L, 2); int fmt = checkint(L, 3); #if LCURSES_POSIX_COMPLIANT return pushokresult(slk_set(labnum, label, fmt)); #else return binding_notimplemented(L, "slk_set", "curses"); #endif }
/*** Reduce the available size of the main screen. @function ripoffline @bool top_line @func callback @treturn bool `true`, if successful @see ripoffline(3x) */ static int Pripoffline(lua_State *L) { static int rip = 0; int top_line = lua_toboolean(L, 1); #if LCURSES_POSIX_COMPLIANT if (!lua_isfunction(L, 2)) { lua_pushliteral(L, "invalid callback passed as second parameter"); lua_error(L); } /* need to save the lua state somewhere... */ rip_L = L; /* get the table where we are going to save the callbacks */ lua_pushstring(L, RIPOFF_TABLE); lua_gettable(L, LUA_REGISTRYINDEX); if (lua_isnil(L, -1)) { lua_pop(L, 1); lua_newtable(L); lua_pushstring(L, RIPOFF_TABLE); lua_pushvalue(L, -2); lua_settable(L, LUA_REGISTRYINDEX); } /* save function callback in registry table */ lua_pushvalue(L, 2); lua_rawseti(L, -2, ++rip); /* and tell curses we are going to take the line */ return pushokresult(ripoffline(top_line ? 1 : -1, ripoffline_cb)); #else return binding_notimplemented(L, "ripoffline", "curses"); #endif }