diff options
author | Mark Johnston <markj@FreeBSD.org> | 2025-07-07 15:43:27 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2025-07-07 15:43:27 +0000 |
commit | eda96744b434325c475dce449744f2268f1033e8 (patch) | |
tree | a11f5f08db8f900f783fa5c6a74c039702650da7 | |
parent | 9940c974029ba53fc00696b3fa1784725c48a9e9 (diff) |
-rw-r--r-- | libexec/flua/linit_flua.c | 10 | ||||
-rw-r--r-- | libexec/flua/modules/lposix.c | 51 | ||||
-rw-r--r-- | libexec/flua/modules/lposix.h | 8 |
3 files changed, 42 insertions, 27 deletions
diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c index 8eaa4af1ffca..b466b7872158 100644 --- a/libexec/flua/linit_flua.c +++ b/libexec/flua/linit_flua.c @@ -57,18 +57,11 @@ static const luaL_Reg loadedlibs[] = { #endif /* FreeBSD Extensions */ {"lfs", luaopen_lfs}, - {"posix.fnmatch", luaopen_posix_fnmatch}, - {"posix.libgen", luaopen_posix_libgen}, - {"posix.stdlib", luaopen_posix_stdlib}, - {"posix.sys.stat", luaopen_posix_sys_stat}, - {"posix.sys.utsname", luaopen_posix_sys_utsname}, - {"posix.sys.wait", luaopen_posix_sys_wait}, - {"posix.unistd", luaopen_posix_unistd}, + {"posix", luaopen_posix}, {"fbsd", luaopen_fbsd}, {NULL, NULL} }; - LUALIB_API void luaL_openlibs (lua_State *L) { const luaL_Reg *lib; /* "require" functions from 'loadedlibs' and set results to global table */ @@ -77,4 +70,3 @@ LUALIB_API void luaL_openlibs (lua_State *L) { lua_pop(L, 1); /* remove lib */ } } - diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c index 9edc7e687786..75cdd345aeaa 100644 --- a/libexec/flua/modules/lposix.c +++ b/libexec/flua/modules/lposix.c @@ -590,21 +590,21 @@ static const struct luaL_Reg unistdlib[] = { #undef REG_SIMPLE #undef REG_DEF -int +static int luaopen_posix_libgen(lua_State *L) { luaL_newlib(L, libgenlib); return (1); } -int +static int luaopen_posix_stdlib(lua_State *L) { luaL_newlib(L, stdliblib); return (1); } -int +static int luaopen_posix_fnmatch(lua_State *L) { luaL_newlib(L, fnmatchlib); @@ -622,14 +622,21 @@ luaopen_posix_fnmatch(lua_State *L) return 1; } -int +static int luaopen_posix_sys_stat(lua_State *L) { luaL_newlib(L, sys_statlib); return (1); } -int +static int +luaopen_posix_sys_utsname(lua_State *L) +{ + luaL_newlib(L, sys_utsnamelib); + return 1; +} + +static int luaopen_posix_sys_wait(lua_State *L) { luaL_newlib(L, sys_waitlib); @@ -655,16 +662,38 @@ luaopen_posix_sys_wait(lua_State *L) return (1); } -int -luaopen_posix_sys_utsname(lua_State *L) +static int +luaopen_posix_unistd(lua_State *L) { - luaL_newlib(L, sys_utsnamelib); - return 1; + luaL_newlib(L, unistdlib); + return (1); } int -luaopen_posix_unistd(lua_State *L) +luaopen_posix(lua_State *L) { - luaL_newlib(L, unistdlib); + lua_newtable(L); /* posix */ + + luaL_requiref(L, "posix.fnmatch", luaopen_posix_fnmatch, 0); + lua_setfield(L, -2, "fnmatch"); + + luaL_requiref(L, "posix.libgen", luaopen_posix_libgen, 0); + lua_setfield(L, -2, "libgen"); + + luaL_requiref(L, "posix.stdlib", luaopen_posix_stdlib, 0); + lua_setfield(L, -2, "stdlib"); + + lua_newtable(L); /* posix.sys */ + luaL_requiref(L, "posix.sys.stat", luaopen_posix_sys_stat, 0); + lua_setfield(L, -2, "stat"); + luaL_requiref(L, "posix.sys.utsname", luaopen_posix_sys_utsname, 0); + lua_setfield(L, -2, "utsname"); + luaL_requiref(L, "posix.sys.wait", luaopen_posix_sys_wait, 0); + lua_setfield(L, -2, "wait"); + lua_setfield(L, -2, "sys"); + + luaL_requiref(L, "posix.unistd", luaopen_posix_unistd, 0); + lua_setfield(L, -2, "unistd"); + return (1); } diff --git a/libexec/flua/modules/lposix.h b/libexec/flua/modules/lposix.h index da7079056826..1aa33f042571 100644 --- a/libexec/flua/modules/lposix.h +++ b/libexec/flua/modules/lposix.h @@ -7,10 +7,4 @@ #include <lua.h> -int luaopen_posix_fnmatch(lua_State *L); -int luaopen_posix_libgen(lua_State *L); -int luaopen_posix_stdlib(lua_State *L); -int luaopen_posix_sys_stat(lua_State *L); -int luaopen_posix_sys_utsname(lua_State *L); -int luaopen_posix_sys_wait(lua_State *L); -int luaopen_posix_unistd(lua_State *L); +int luaopen_posix(lua_State *L); |