Index: head/libexec/flua/linit_flua.c =================================================================== --- head/libexec/flua/linit_flua.c +++ head/libexec/flua/linit_flua.c @@ -57,6 +57,7 @@ #endif /* FreeBSD Extensions */ {"lfs", luaopen_lfs}, + {"posix.sys.stat", luaopen_posix_sys_stat}, {"posix.unistd", luaopen_posix_unistd}, {NULL, NULL} }; Index: head/libexec/flua/modules/lposix.h =================================================================== --- head/libexec/flua/modules/lposix.h +++ head/libexec/flua/modules/lposix.h @@ -8,4 +8,5 @@ #include +int luaopen_posix_sys_stat(lua_State *L); int luaopen_posix_unistd(lua_State *L); Index: head/libexec/flua/modules/lposix.c =================================================================== --- head/libexec/flua/modules/lposix.c +++ head/libexec/flua/modules/lposix.c @@ -27,6 +27,10 @@ #include __FBSDID("$FreeBSD$"); +#include + +#include +#include #include #include @@ -38,6 +42,28 @@ */ static int +lua_chmod(lua_State *L) +{ + int n; + const char *path; + mode_t mode; + + n = lua_gettop(L); + luaL_argcheck(L, n == 2, n > 2 ? 3 : n, + "chmod takes exactly two arguments"); + path = luaL_checkstring(L, 1); + mode = (mode_t)luaL_checkinteger(L, 2); + if (chmod(path, mode) == -1) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + lua_pushinteger(L, errno); + return 3; + } + lua_pushinteger(L, 0); + return 1; +} + +static int lua_getpid(lua_State *L) { int n; @@ -49,11 +75,23 @@ } #define REG_SIMPLE(n) { #n, lua_ ## n } +static const struct luaL_Reg sys_statlib[] = { + REG_SIMPLE(chmod), + { NULL, NULL }, +}; + static const struct luaL_Reg unistdlib[] = { REG_SIMPLE(getpid), { NULL, NULL }, }; #undef REG_SIMPLE + +int +luaopen_posix_sys_stat(lua_State *L) +{ + luaL_newlib(L, sys_statlib); + return 1; +} int luaopen_posix_unistd(lua_State *L)