1From 5d8ca4500e360108a8ce7fae0a5e5c03844c854d Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Sun, 2 Feb 2025 03:03:11 -0800
4Subject: [PATCH] Build in luaposix modules
5
6---
7 lua.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 1 file changed, 88 insertions(+)
9
10diff --git a/src/lua.c b/src/lua.c
11index 5054583d..4e12fe5e 100644
12--- a/src/lua.c
13+++ b/src/lua.c
14@@ -697,6 +697,35 @@ static void doREPL (lua_State *L) {
15 #endif
16
17
18+int luaopen_posix_ctype(lua_State *L);
19+int luaopen_posix_dirent(lua_State *L);
20+int luaopen_posix_errno(lua_State *L);
21+int luaopen_posix_fcntl(lua_State *L);
22+int luaopen_posix_fnmatch(lua_State *L);
23+int luaopen_posix_glob(lua_State *L);
24+int luaopen_posix_grp(lua_State *L);
25+int luaopen_posix_libgen(lua_State *L);
26+int luaopen_posix_poll(lua_State *L);
27+int luaopen_posix_pwd(lua_State *L);
28+int luaopen_posix_sched(lua_State *L);
29+int luaopen_posix_signal(lua_State *L);
30+int luaopen_posix_stdio(lua_State *L);
31+int luaopen_posix_stdlib(lua_State *L);
32+int luaopen_posix_sys_msg(lua_State *L);
33+int luaopen_posix_sys_resource(lua_State *L);
34+int luaopen_posix_sys_socket(lua_State *L);
35+int luaopen_posix_sys_stat(lua_State *L);
36+int luaopen_posix_sys_statvfs(lua_State *L);
37+int luaopen_posix_sys_time(lua_State *L);
38+int luaopen_posix_sys_times(lua_State *L);
39+int luaopen_posix_sys_utsname(lua_State *L);
40+int luaopen_posix_sys_wait(lua_State *L);
41+int luaopen_posix_syslog(lua_State *L);
42+int luaopen_posix_termio(lua_State *L);
43+int luaopen_posix_time(lua_State *L);
44+int luaopen_posix_unistd(lua_State *L);
45+int luaopen_posix_utime(lua_State *L);
46+
47 /*
48 ** Main body of stand-alone interpreter (to be called in protected mode).
49 ** Reads the options and handles them all.
50@@ -719,6 +748,65 @@ static int pmain (lua_State *L) {
51 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
52 }
53 luai_openlibs(L); /* open standard libraries */
54+ luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
55+ /* luaposix */
56+ lua_pushcfunction(L, luaopen_posix_ctype);
57+ lua_setfield(L, -2, "posix.ctype");
58+ lua_pushcfunction(L, luaopen_posix_dirent);
59+ lua_setfield(L, -2, "posix.dirent");
60+ lua_pushcfunction(L, luaopen_posix_errno);
61+ lua_setfield(L, -2, "posix.errno");
62+ lua_pushcfunction(L, luaopen_posix_fcntl);
63+ lua_setfield(L, -2, "posix.fcntl");
64+ lua_pushcfunction(L, luaopen_posix_fnmatch);
65+ lua_setfield(L, -2, "posix.fnmatch");
66+ lua_pushcfunction(L, luaopen_posix_glob);
67+ lua_setfield(L, -2, "posix.glob");
68+ lua_pushcfunction(L, luaopen_posix_grp);
69+ lua_setfield(L, -2, "posix.grp");
70+ lua_pushcfunction(L, luaopen_posix_libgen);
71+ lua_setfield(L, -2, "posix.libgen");
72+ lua_pushcfunction(L, luaopen_posix_poll);
73+ lua_setfield(L, -2, "posix.poll");
74+ lua_pushcfunction(L, luaopen_posix_pwd);
75+ lua_setfield(L, -2, "posix.pwd");
76+ lua_pushcfunction(L, luaopen_posix_sched);
77+ lua_setfield(L, -2, "posix.sched");
78+ lua_pushcfunction(L, luaopen_posix_signal);
79+ lua_setfield(L, -2, "posix.signal");
80+ lua_pushcfunction(L, luaopen_posix_stdio);
81+ lua_setfield(L, -2, "posix.stdio");
82+ lua_pushcfunction(L, luaopen_posix_stdlib);
83+ lua_setfield(L, -2, "posix.stdlib");
84+ lua_pushcfunction(L, luaopen_posix_sys_msg);
85+ lua_setfield(L, -2, "posix.sys.msg");
86+ lua_pushcfunction(L, luaopen_posix_sys_resource);
87+ lua_setfield(L, -2, "posix.sys.resource");
88+ lua_pushcfunction(L, luaopen_posix_sys_socket);
89+ lua_setfield(L, -2, "posix.sys.socket");
90+ lua_pushcfunction(L, luaopen_posix_sys_stat);
91+ lua_setfield(L, -2, "posix.sys.stat");
92+ lua_pushcfunction(L, luaopen_posix_sys_statvfs);
93+ lua_setfield(L, -2, "posix.sys.statvfs");
94+ lua_pushcfunction(L, luaopen_posix_sys_time);
95+ lua_setfield(L, -2, "posix.sys.time");
96+ lua_pushcfunction(L, luaopen_posix_sys_times);
97+ lua_setfield(L, -2, "posix.sys.times");
98+ lua_pushcfunction(L, luaopen_posix_sys_utsname);
99+ lua_setfield(L, -2, "posix.sys.utsname");
100+ lua_pushcfunction(L, luaopen_posix_sys_wait);
101+ lua_setfield(L, -2, "posix.sys.wait");
102+ lua_pushcfunction(L, luaopen_posix_syslog);
103+ lua_setfield(L, -2, "posix.syslog");
104+ lua_pushcfunction(L, luaopen_posix_termio);
105+ lua_setfield(L, -2, "posix.termio");
106+ lua_pushcfunction(L, luaopen_posix_time);
107+ lua_setfield(L, -2, "posix.time");
108+ lua_pushcfunction(L, luaopen_posix_unistd);
109+ lua_setfield(L, -2, "posix.unistd");
110+ lua_pushcfunction(L, luaopen_posix_utime);
111+ lua_setfield(L, -2, "posix.utime");
112+ lua_pop(L, 1);
113 createargtable(L, argv, argc, script); /* create table 'arg' */
114 lua_gc(L, LUA_GCRESTART); /* start GC... */
115 lua_gc(L, LUA_GCGEN); /* ...in generational mode */
116--
1172.49.0
118