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