-
Notifications
You must be signed in to change notification settings - Fork 1
/
lua54.txt
310 lines (292 loc) · 10.2 KB
/
lua54.txt
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
diff -u work/lua-5.4.0/src/lauxlib.c work-orig/lua-5.4.0-work1/src/lauxlib.c
--- work/lua-5.4.0/src/lauxlib.c 2018-05-06 13:07:28.334256500 -0700
+++ work-orig/lua-5.4.0-work1/src/lauxlib.c 2018-02-27 10:47:32.000000000 -0800
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp $
+** $Id: lauxlib.c,v 1.294 2018/02/27 18:47:32 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -76,7 +76,7 @@
lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
if (findfield(L, top + 1, 2)) {
const char *name = lua_tostring(L, -1);
- if (strncmp(name, "_G.", 3) == 0) { /* name start with '_G.'? */
+ if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */
lua_pushstring(L, name + 3); /* push name without prefix */
lua_remove(L, -2); /* remove original name */
}
@@ -273,11 +273,7 @@
LUALIB_API int luaL_execresult (lua_State *L, int stat) {
const char *what = "exit"; /* type of termination */
- if (stat == -1
-#if defined(LUA_USE_WINDOWS)
- && errno != 0
-#endif
- ) /* error? */
+ if (stat == -1) /* error? */
return luaL_fileresult(L, 0, NULL);
else {
l_inspectstat(stat, what); /* interpret result */
@@ -484,10 +480,10 @@
static void *newbox (lua_State *L, size_t newsize) {
- UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));
+ UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0);
box->box = NULL;
box->bsize = 0;
- if (luaL_newmetatable(L, "LUABOX")) { /* creating metatable? */
+ if (luaL_newmetatable(L, "_UBOX*")) { /* creating metatable? */
lua_pushcfunction(L, boxgc);
lua_setfield(L, -2, "__gc"); /* metatable.__gc = boxgc */
}
@@ -850,87 +846,6 @@
/*
-** {======================================================
-** Compatibility with 5.1 module functions
-** =======================================================
-*/
-#if defined(LUA_COMPAT_MODULE)
-
-static const char *luaL_findtable (lua_State *L, int idx,
- const char *fname, int szhint) {
- const char *e;
- if (idx) lua_pushvalue(L, idx);
- do {
- e = strchr(fname, '.');
- if (e == NULL) e = fname + strlen(fname);
- lua_pushlstring(L, fname, e - fname);
- if (lua_rawget(L, -2) == LUA_TNIL) { /* no such field? */
- lua_pop(L, 1); /* remove this nil */
- lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
- lua_pushlstring(L, fname, e - fname);
- lua_pushvalue(L, -2);
- lua_settable(L, -4); /* set new table into field */
- }
- else if (!lua_istable(L, -1)) { /* field has a non-table value? */
- lua_pop(L, 2); /* remove table and value */
- return fname; /* return problematic part of the name */
- }
- lua_remove(L, -2); /* remove previous table */
- fname = e + 1;
- } while (*e == '.');
- return NULL;
-}
-
-
-/*
-** Count number of elements in a luaL_Reg list.
-*/
-static int libsize (const luaL_Reg *l) {
- int size = 0;
- for (; l && l->name; l++) size++;
- return size;
-}
-
-
-/*
-** Find or create a module table with a given name. The function
-** first looks at the LOADED table and, if that fails, try a
-** global variable with that name. In any case, leaves on the stack
-** the module table.
-*/
-LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
- int sizehint) {
- luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);
- if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no LOADED[modname]? */
- lua_pop(L, 1); /* remove previous result */
- /* try global variable (and create one if it does not exist) */
- lua_pushglobaltable(L);
- if (luaL_findtable(L, 0, modname, sizehint) != NULL)
- luaL_error(L, "name conflict for module '%s'", modname);
- lua_pushvalue(L, -1);
- lua_setfield(L, -3, modname); /* LOADED[modname] = new table */
- }
- lua_remove(L, -2); /* remove LOADED table */
-}
-
-
-LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
- const luaL_Reg *l, int nup) {
- luaL_checkversion(L);
- if (libname) {
- luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
- lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
- }
- if (l)
- luaL_setfuncs(L, l, nup);
- else
- lua_pop(L, nup); /* remove upvalues */
-}
-
-#endif
-/* }====================================================== */
-
-/*
** set functions from list 'l' into table at top - 'nup'; each
** function gets the 'nup' elements at the top as upvalues.
** Returns with only the table at the stack.
diff -u work/lua-5.4.0/src/liolib.c work-orig/lua-5.4.0-work1/src/liolib.c
--- work/lua-5.4.0/src/liolib.c 2018-05-06 11:43:59.946085200 -0700
+++ work-orig/lua-5.4.0-work1/src/liolib.c 2018-03-02 10:25:00.000000000 -0800
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 roberto Exp $
+** $Id: liolib.c,v 2.156 2018/03/02 18:25:00 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -186,7 +186,7 @@
** handle is in a consistent state.
*/
static LStream *newprefile (lua_State *L) {
- LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
+ LStream *p = (LStream *)lua_newuserdatauv(L, sizeof(LStream), 0);
p->closef = NULL; /* mark file handle as 'closed' */
luaL_setmetatable(L, LUA_FILEHANDLE);
return p;
@@ -206,11 +206,16 @@
}
+static int f_close (lua_State *L) {
+ tofile(L); /* make sure argument is an open stream */
+ return aux_close(L);
+}
+
+
static int io_close (lua_State *L) {
if (lua_isnone(L, 1)) /* no argument? */
lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
- tofile(L); /* make sure argument is an open stream */
- return aux_close(L);
+ return f_close(L);
}
@@ -264,9 +269,6 @@
*/
static int io_pclose (lua_State *L) {
LStream *p = tolstream(L);
-#if defined(LUA_USE_WINDOWS)
- errno = 0;
-#endif
return luaL_execresult(L, l_pclose(L, p->f));
}
@@ -445,7 +447,7 @@
decp[1] = '.'; /* always accept a dot */
l_lockfile(rn.f);
do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */
- test2(&rn, "-+"); /* optional signal */
+ test2(&rn, "-+"); /* optional sign */
if (test2(&rn, "00")) {
if (test2(&rn, "xX")) hex = 1; /* numeral is hexadecimal */
else count = 1; /* count initial '0' as a valid digit */
@@ -454,7 +456,7 @@
if (test2(&rn, decp)) /* decimal point? */
count += readdigits(&rn, hex); /* fractional part */
if (count > 0 && test2(&rn, (hex ? "pP" : "eE"))) { /* exponent mark? */
- test2(&rn, "-+"); /* exponent signal */
+ test2(&rn, "-+"); /* exponent sign */
readdigits(&rn, 0); /* exponent digits */
}
ungetc(rn.c, rn.f); /* unread look-ahead char */
@@ -526,14 +528,14 @@
static int g_read (lua_State *L, FILE *f, int first) {
int nargs = lua_gettop(L) - 1;
- int success;
- int n;
+ int n, success;
clearerr(f);
if (nargs == 0) { /* no arguments? */
success = read_line(L, f, 1);
- n = first+1; /* to return 1 result */
+ n = first + 1; /* to return 1 result */
}
- else { /* ensure stack space for all results and for auxlib's buffer */
+ else {
+ /* ensure stack space for all results and for auxlib's buffer */
luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
success = 1;
for (n = first; nargs-- && success; n++) {
@@ -715,7 +717,7 @@
** methods for file handles
*/
static const luaL_Reg flib[] = {
- {"close", io_close},
+ {"close", f_close},
{"flush", f_flush},
{"lines", f_lines},
{"read", f_read},
diff -u work/lua-5.4.0/src/loslib.c work-orig/lua-5.4.0-work1/src/loslib.c
--- work/lua-5.4.0/src/loslib.c 2018-05-06 11:43:59.980603000 -0700
+++ work-orig/lua-5.4.0-work1/src/loslib.c 2017-03-14 05:40:44.000000000 -0700
@@ -1,5 +1,5 @@
/*
-** $Id: loslib.c,v 1.65 2016/07/18 17:58:58 roberto Exp $
+** $Id: loslib.c,v 1.66 2017/03/14 12:40:44 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@@ -140,11 +140,7 @@
static int os_execute (lua_State *L) {
const char *cmd = luaL_optstring(L, 1, NULL);
- int stat;
-#if defined(LUA_USE_WINDOWS)
- errno = 0;
-#endif
- stat = system(cmd);
+ int stat = system(cmd);
if (cmd != NULL)
return luaL_execresult(L, stat);
else {
@@ -297,7 +293,8 @@
else
stm = l_localtime(&t, &tmr);
if (stm == NULL) /* invalid date? */
- luaL_error(L, "time result cannot be represented in this installation");
+ return luaL_error(L,
+ "time result cannot be represented in this installation");
if (strcmp(s, "*t") == 0) {
lua_createtable(L, 0, 9); /* 9 = number of fields */
setallfields(L, stm);
@@ -344,7 +341,8 @@
setallfields(L, &ts); /* update fields with normalized values */
}
if (t != (time_t)(l_timet)t || t == (time_t)(-1))
- luaL_error(L, "time result cannot be represented in this installation");
+ return luaL_error(L,
+ "time result cannot be represented in this installation");
l_pushtime(L, t);
return 1;
}
diff -u work/lua-5.4.0/src/lua.c work-orig/lua-5.4.0-work1/src/lua.c
--- work/lua-5.4.0/src/lua.c 2018-05-14 22:02:29.124723400 -0700
+++ work-orig/lua-5.4.0-work1/src/lua.c 2018-03-06 12:30:17.000000000 -0800
@@ -5,7 +5,7 @@
*/
#define lua_c
-#define LUA_LIB
+
#include "lprefix.h"
@@ -599,8 +599,8 @@
return 1;
}
-/*2018-05-10 - WinLua modification*/
-LUA_API int mainL (int argc, char **argv) {
+
+int main (int argc, char **argv) {
int status, result;
lua_State *L = luaL_newstate(); /* create state */
if (L == NULL) {
@@ -616,3 +616,4 @@
lua_close(L);
return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}
+
diff -u work/lua-5.4.0/src/lua.h work-orig/lua-5.4.0-work1/src/lua.h
--- work/lua-5.4.0/src/lua.h 2018-05-14 22:02:35.596632800 -0700
+++ work-orig/lua-5.4.0-work1/src/lua.h 2018-03-13 05:05:24.000000000 -0700
@@ -217,8 +217,6 @@
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
-/*2018-05-10 - WinLua modification*/
-LUA_API int (mainL) (int argc, char **argv);
/*
** push functions (C -> stack)