示例#1
0
文件: _helpers.c 项目: zevv/luaposix
static int
pushresult(lua_State *L, int i, const char *info)
{
	if (i==-1)
		return pusherror(L, info);
	return pushintresult(i);
}
示例#2
0
static int
Palarm(lua_State *L)
{
	int seconds = checkint(L, 1);
	checknargs(L, 1);
	return pushintresult(alarm(seconds));
}
示例#3
0
文件: unistd.c 项目: batrick/luaposix
/***
Sleep for a number of seconds.
@function sleep
@int seconds minimum numebr of seconds to sleep
@treturn[1] int `0` if the requested time has elapsed
@treturn[2] int unslept seconds remaining, if interrupted
@see sleep(3)
@see posix.time.nanosleep
*/
static int
Psleep(lua_State *L)
{
	unsigned int seconds = checkint(L, 1);
	checknargs(L, 1);
	return pushintresult(sleep(seconds));
}
示例#4
0
文件: unistd.c 项目: batrick/luaposix
/***
Get a value for a configuration option for a filename.
@function pathconf
@string path optional
@int key one of `_PC_LINK_MAX`, `_PC_MAX_CANON`, `_PC_NAME_MAX`,
  `_PC_PIPE_BUF`, `_PC_CHOWN_RESTRICTED`, `_PC_NO_TRUNC` or
  `_PC_VDISABLE`
@treturn int associated path configuration value
@see pathconf(3)
@usage for a, b in pairs (P.pathconf "/dev/tty") do print(a, b) end
*/
static int
Ppathconf(lua_State *L)
{
	const char *path = luaL_checkstring(L, 1);
	checknargs(L, 2);
	return pushintresult(pathconf(path, checkint(L, 2)));
}
示例#5
0
/***
Raise a signal on this process.
@function raise
@int sig signal to send
@treturn[1] int `0`, if successful
@return[2] nil
@treturn[2] string error message
@treturn[2] int errnum
@see raise(3)
*/
static int
Praise(lua_State *L)
{
	int sig = checkint(L, 1);
	checknargs(L, 1);
	lua_pop(L, 1);
	return pushintresult(raise(sig));
}
示例#6
0
static int
bind_ctype(lua_State *L, int (*cb)(int))
{
	const char *s = luaL_checkstring(L, 1);
	char c = *s;
	checknargs(L, 1);
	lua_pop(L, 1);
	return pushintresult(cb((int)c));
}
示例#7
0
/***
Match a filename against a shell pattern.
@function fnmatch
@string pat shell pattern
@string name filename
@int[opt=0] flags optional
@treturn[1] int `0`, if successful
@treturn[2] int `FNM_NOMATCH`
@treturn[3] int some other non-zero integer if fnmatch itself failed
@see fnmatch(3)
*/
static int
Pfnmatch(lua_State *L)
{
	const char *pattern = luaL_checkstring(L, 1);
	const char *string = luaL_checkstring(L, 2);
	int flags = optint(L, 3, 0);
	int res;
	checknargs(L, 3);
	return pushintresult(fnmatch(pattern, string, flags));
}
示例#8
0
文件: curses.c 项目: lcurses/lcurses
/***
Change the visibility of the cursor.
@function curs_set
@int vis one of `0` (invisible), `1` (visible) or `2` (very visible)
@treturn[1] int previous cursor state
@return[2] nil if *vis* is not supported
@see curs_set(3x)
*/
static int
Pcurs_set(lua_State *L)
{
	int vis = checkint(L, 1);
	int state = curs_set(vis);
	if (state == ERR)
		return 0;

	return pushintresult(state);
}
示例#9
0
文件: curses.c 项目: lcurses/lcurses
/***
Bitwise OR of all (or selected) video attributes supported by the terminal.
@function termattrs
@int[opt] a terminal attribute bits
@treturn[1] bool `true`, if the terminal supports attribute *a*
@treturn[2] int bitarray of supported terminal attributes
@see termattrs(3x)
*/
static int
Ptermattrs(lua_State *L)
{
	if (lua_gettop(L) > 0)
	{
		int a = checkint(L, 1);
		return pushboolresult(termattrs() & a);
	}
	return pushintresult(termattrs());
}
示例#10
0
文件: time.c 项目: tongson/omnia
/***
Convert a broken-down localtime table into an epoch time.
@function mktime
@tparam PosixTm broken-down localtime
@treturn int seconds since epoch
@see mktime(3)
@see localtime
*/
static int
Pmktime(lua_State *L)
{
	struct tm t;
	time_t epoch;
	checknargs(L, 1);
	totm(L, 1, &t);
	if ((epoch = mktime(&t)) < 0)
		return 0;
	return pushintresult(epoch);
}
示例#11
0
文件: unistd.c 项目: batrick/luaposix
/***
Get host id.
@function gethostid
@see gethostid(3)
@treturn[1] int host id
@return[2] nil
@treturn[2] string error message
*/
static int
Pgethostid(lua_State *L)
{
	checknargs(L, 0);
#if HAVE_GETHOSTID
	return pushintresult(gethostid());
#else
	lua_pushnil(L);
	lua_pushliteral(L, "unsupported by this host");
	return 2;
#endif
}
示例#12
0
文件: curses.c 项目: lcurses/lcurses
/***
Number of lines in the main screen window.
@function lines
@treturn int number of lines in the main screen
@see cols
@see stdscr
@see LINES(3x)
*/
static int
Plines(lua_State *L)
{
	return pushintresult(LINES);
}
示例#13
0
文件: unistd.c 项目: batrick/luaposix
/***
Return user id of calling process.
@function getuid
@treturn int user id of calling process
@see geteuid
*/
static int
Pgetuid(lua_State *L)
{
	checknargs(L, 0);
	return pushintresult(getuid ());
}
示例#14
0
文件: curses.c 项目: lcurses/lcurses
/***
Return the attributes for the given color pair id.
@function color_pair
@int pair color pair id to act on
@treturn int attributes for color pair *pair*
@see can_change_color(3x)
*/
static int
Pcolor_pair(lua_State *L)
{
	int n = checkint(L, 1);
	return pushintresult(COLOR_PAIR(n));
}
示例#15
0
文件: stat.c 项目: istr/luaposix
/***
Test for a character special file.
@function S_ISCHR
@int mode the st_mode field of a @{PosixStat}
@treturn int non-zero if *mode* represents a character special file
*/
static int
PS_ISCHR(lua_State *L)
{
	checknargs(L, 1);
	return pushintresult(S_ISCHR((mode_t) checkint(L, 1)));
}
示例#16
0
文件: stat.c 项目: istr/luaposix
/***
Set file mode creation mask.
@function umask
@int[opt] mode new file creation mask
@treturn int previous umask
@see umask(2)
@see posix.umask
*/
static int
Pumask(lua_State *L)
{
	checknargs(L, 1);
	return pushintresult(umask((mode_t) checkint(L, 1)));
}
示例#17
0
文件: curses.c 项目: lcurses/lcurses
/***
How may distinct color pairs are supported by this terminal?
@function color_pairs
@treturn int total number of available color pairs
@see can_change_color(3x)
@see colors
*/
static int
Pcolor_pairs(lua_State *L)
{
	return pushintresult(COLOR_PAIRS);
}
示例#18
0
文件: curses.c 项目: lcurses/lcurses
/***
Fetch the output speed of the terminal.
@function baudrate
@treturn int output speed of the terminal in bits-per-second
@see baudrate(3x)
*/
static int
Pbaudrate(lua_State *L)
{
	return pushintresult(baudrate());
}
示例#19
0
文件: curses.c 项目: lcurses/lcurses
/***
Fetch the terminal's current erase character.
@function erasechar
@treturn int current erase character
@see erasechar(3x)
*/
static int
Perasechar(lua_State *L)
{
	return pushintresult(erasechar());
}
示例#20
0
文件: curses.c 项目: lcurses/lcurses
/***
Fetch the terminal's current kill character.
@function killchar
@treturn int current line kill character
@see killchar(3x)
*/
static int
Pkillchar(lua_State *L)
{
	return pushintresult(killchar());
}
示例#21
0
文件: unistd.c 项目: batrick/luaposix
/***
Get configuration information at runtime.
@function sysconf
@int key one of `_SC_ARG_MAX`, `_SC_CHILD_MAX`, `_SC_CLK_TCK`, `_SC_JOB_CONTROL`,
  `_SC_OPEN_MAX`, `_SC_NGROUPS_MAX`, `_SC_SAVED_IDS`, `_SC_STREAM_MAX`,
  `_SC_TZNAME_MAX` or `_SC_VERSION`,
@treturn int associated system configuration value
@see sysconf(3)
*/
static int
Psysconf(lua_State *L)
{
	checknargs(L, 1);
	return pushintresult(sysconf(checkint(L, 1)));
}
示例#22
0
文件: curses.c 项目: lcurses/lcurses
/***
How many colors are available for this terminal?
@function colors
@treturn int total number of available colors
@see can_change_color(3x)
@see color_pairs
*/
static int
Pcolors(lua_State *L)
{
	return pushintresult(COLORS);
}
示例#23
0
/***
Mask bit for given log priority.
@function LOG_MASK
@int priority one of `LOG_EMERG`, `LOG_ALERT`, `LOG_CRIT`, `LOG_WARNING`,
  `LOG_NOTICE`, `LOG_INFO` or `LOG_DEBUG`
@treturn int mask bit corresponding to *priority*
@see setlogmask(3)
*/
static int
PLOG_MASK(lua_State *L)
{
    checknargs(L, 1);
    return pushintresult(LOG_MASK(checkint(L, 1)));
}
示例#24
0
文件: curses.c 项目: lcurses/lcurses
/***
Number of columns in the main screen window.
@function cols
@treturn int number of columns in the main screen
@see lines
@see stdscr
@see COLS(3x)
*/
static int
Pcols(lua_State *L)
{
	return pushintresult(COLS);
}