The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
liolib.cpp
Go to the documentation of this file.
1 /*
2 ** Standard I/O (and system) library
3 ** See Copyright Notice in lua.h
4 */
5 
6 
7 /*
8 ** This definition must come before the inclusion of 'stdio.h'; it
9 ** should not affect non-POSIX systems
10 */
11 #if !defined(_FILE_OFFSET_BITS)
12 #define _LARGEFILE_SOURCE 1
13 #define _FILE_OFFSET_BITS 64
14 #endif
15 
16 
17 #include <errno.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #define liolib_c
23 #define LUA_LIB
24 
25 #include "lua.h"
26 
27 #include "lauxlib.h"
28 #include "lualib.h"
29 
30 
31 #if !defined(lua_checkmode)
32 
33 /*
34 ** Check whether 'mode' matches '[rwa]%+?b?'.
35 ** Change this macro to accept other modes for 'fopen' besides
36 ** the standard ones.
37 */
38 #define lua_checkmode(mode) \
39  (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
40  (*mode != '+' || ++mode) && /* skip if char is '+' */ \
41  (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
42  (*mode == '\0'))
43 
44 #endif
45 
46 /*
47 ** {======================================================
48 ** lua_popen spawns a new process connected to the current
49 ** one through the file streams.
50 ** =======================================================
51 */
52 
53 #if !defined(lua_popen) /* { */
54 
55 #if defined(LUA_USE_POPEN) /* { */
56 
57 #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
58 #define lua_pclose(L,file) ((void)L, pclose(file))
59 
60 #elif defined(LUA_WIN) /* }{ */
61 
62 #define lua_popen(L,c,m) ((void)L, _popen(c,m))
63 #define lua_pclose(L,file) ((void)L, _pclose(file))
64 
65 
66 #else /* }{ */
67 
68 #define lua_popen(L,c,m) ((void)((void)c, m), \
69  luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
70 #define lua_pclose(L,file) ((void)((void)L, file), -1)
71 
72 
73 #endif /* } */
74 
75 #endif /* } */
76 
77 /* }====================================================== */
78 
79 
80 /*
81 ** {======================================================
82 ** lua_fseek: configuration for longer offsets
83 ** =======================================================
84 */
85 
86 #if !defined(lua_fseek) && !defined(LUA_ANSI) /* { */
87 
88 #if defined(LUA_USE_POSIX) /* { */
89 
90 #define l_fseek(f,o,w) fseeko(f,o,w)
91 #define l_ftell(f) ftello(f)
92 #define l_seeknum off_t
93 
94 #elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
95  && defined(_MSC_VER) && (_MSC_VER >= 1400) /* }{ */
96 /* Windows (but not DDK) and Visual C++ 2005 or higher */
97 
98 #define l_fseek(f,o,w) _fseeki64(f,o,w)
99 #define l_ftell(f) _ftelli64(f)
100 #define l_seeknum __int64
101 
102 #endif /* } */
103 
104 #endif /* } */
105 
106 
107 #if !defined(l_fseek) /* default definitions */
108 #define l_fseek(f,o,w) fseek(f,o,w)
109 #define l_ftell(f) ftell(f)
110 #define l_seeknum long
111 #endif
112 
113 /* }====================================================== */
114 
115 
116 #define IO_PREFIX "_IO_"
117 #define IO_INPUT (IO_PREFIX "input")
118 #define IO_OUTPUT (IO_PREFIX "output")
119 
120 
122 
123 
124 #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
125 
126 #define isclosed(p) ((p)->closef == NULL)
127 
128 
129 static int io_type (lua_State *L) {
130  LStream *p;
131  luaL_checkany(L, 1);
132  p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
133  if (p == NULL)
134  lua_pushnil(L); /* not a file */
135  else if (isclosed(p))
136  lua_pushliteral(L, "closed file");
137  else
138  lua_pushliteral(L, "file");
139  return 1;
140 }
141 
142 
143 static int f_tostring (lua_State *L) {
144  LStream *p = tolstream(L);
145  if (isclosed(p))
146  lua_pushliteral(L, "file (closed)");
147  else
148  lua_pushfstring(L, "file (%p)", p->f);
149  return 1;
150 }
151 
152 
153 static FILE *tofile (lua_State *L) {
154  LStream *p = tolstream(L);
155  if (isclosed(p))
156  luaL_error(L, "attempt to use a closed file");
157  lua_assert(p->f);
158  return p->f;
159 }
160 
161 
162 /*
163 ** When creating file handles, always creates a `closed' file handle
164 ** before opening the actual file; so, if there is a memory error, the
165 ** file is not left opened.
166 */
168  LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
169  p->closef = NULL; /* mark file handle as 'closed' */
171  return p;
172 }
173 
174 
175 static int aux_close (lua_State *L) {
176  LStream *p = tolstream(L);
177  lua_CFunction cf = p->closef;
178  p->closef = NULL; /* mark stream as closed */
179  return (*cf)(L); /* close it */
180 }
181 
182 
183 static int io_close (lua_State *L) {
184  if (lua_isnone(L, 1)) /* no argument? */
185  lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
186  tofile(L); /* make sure argument is an open stream */
187  return aux_close(L);
188 }
189 
190 
191 static int f_gc (lua_State *L) {
192  LStream *p = tolstream(L);
193  if (!isclosed(p) && p->f != NULL)
194  aux_close(L); /* ignore closed and incompletely open files */
195  return 0;
196 }
197 
198 
199 /*
200 ** function to close regular files
201 */
202 static int io_fclose (lua_State *L) {
203  LStream *p = tolstream(L);
204  int res = fclose(p->f);
205  return luaL_fileresult(L, (res == 0), NULL);
206 }
207 
208 
209 static LStream *newfile (lua_State *L) {
210  LStream *p = newprefile(L);
211  p->f = NULL;
212  p->closef = &io_fclose;
213  return p;
214 }
215 
216 
217 static void opencheck (lua_State *L, const char *fname, const char *mode) {
218  LStream *p = newfile(L);
219  p->f = fopen(fname, mode);
220  if (p->f == NULL)
221  luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
222 }
223 
224 
225 static int io_open (lua_State *L) {
226  const char *filename = luaL_checkstring(L, 1);
227  const char *mode = luaL_optstring(L, 2, "r");
228  LStream *p = newfile(L);
229  const char *md = mode; /* to traverse/check mode */
230  luaL_argcheck(L, lua_checkmode(md), 2, "invalid mode");
231  p->f = fopen(filename, mode);
232  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
233 }
234 
235 
236 /*
237 ** function to close 'popen' files
238 */
239 static int io_pclose (lua_State *L) {
240  LStream *p = tolstream(L);
241  return luaL_execresult(L, lua_pclose(L, p->f));
242 }
243 
244 
245 static int io_popen (lua_State *L) {
246  const char *filename = luaL_checkstring(L, 1);
247  const char *mode = luaL_optstring(L, 2, "r");
248  LStream *p = newprefile(L);
249  p->f = lua_popen(L, filename, mode);
250  p->closef = &io_pclose;
251  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
252 }
253 
254 
255 static int io_tmpfile (lua_State *L) {
256  LStream *p = newfile(L);
257  p->f = tmpfile();
258  return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
259 }
260 
261 
262 static FILE *getiofile (lua_State *L, const char *findex) {
263  LStream *p;
264  lua_getfield(L, LUA_REGISTRYINDEX, findex);
265  p = (LStream *)lua_touserdata(L, -1);
266  if (isclosed(p))
267  luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
268  return p->f;
269 }
270 
271 
272 static int g_iofile (lua_State *L, const char *f, const char *mode) {
273  if (!lua_isnoneornil(L, 1)) {
274  const char *filename = lua_tostring(L, 1);
275  if (filename)
276  opencheck(L, filename, mode);
277  else {
278  tofile(L); /* check that it's a valid file handle */
279  lua_pushvalue(L, 1);
280  }
282  }
283  /* return current value */
285  return 1;
286 }
287 
288 
289 static int io_input (lua_State *L) {
290  return g_iofile(L, IO_INPUT, "r");
291 }
292 
293 
294 static int io_output (lua_State *L) {
295  return g_iofile(L, IO_OUTPUT, "w");
296 }
297 
298 
299 static int io_readline (lua_State *L);
300 
301 
302 static void aux_lines (lua_State *L, int toclose) {
303  int i;
304  int n = lua_gettop(L) - 1; /* number of arguments to read */
305  /* ensure that arguments will fit here and into 'io_readline' stack */
306  luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
307  lua_pushvalue(L, 1); /* file handle */
308  lua_pushinteger(L, n); /* number of arguments to read */
309  lua_pushboolean(L, toclose); /* close/not close file when finished */
310  for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1); /* copy arguments */
311  lua_pushcclosure(L, io_readline, 3 + n);
312 }
313 
314 
315 static int f_lines (lua_State *L) {
316  tofile(L); /* check that it's a valid file handle */
317  aux_lines(L, 0);
318  return 1;
319 }
320 
321 
322 static int io_lines (lua_State *L) {
323  int toclose;
324  if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
325  if (lua_isnil(L, 1)) { /* no file name? */
326  lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
327  lua_replace(L, 1); /* put it at index 1 */
328  tofile(L); /* check that it's a valid file handle */
329  toclose = 0; /* do not close it after iteration */
330  }
331  else { /* open a new file */
332  const char *filename = luaL_checkstring(L, 1);
333  opencheck(L, filename, "r");
334  lua_replace(L, 1); /* put file at index 1 */
335  toclose = 1; /* close it after iteration */
336  }
337  aux_lines(L, toclose);
338  return 1;
339 }
340 
341 
342 /*
343 ** {======================================================
344 ** READ
345 ** =======================================================
346 */
347 
348 
349 static int read_number (lua_State *L, FILE *f) {
350  lua_Number d;
351  if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
352  lua_pushnumber(L, d);
353  return 1;
354  }
355  else {
356  lua_pushnil(L); /* "result" to be removed */
357  return 0; /* read fails */
358  }
359 }
360 
361 
362 static int test_eof (lua_State *L, FILE *f) {
363  int c = getc(f);
364  ungetc(c, f);
365  lua_pushlstring(L, NULL, 0);
366  return (c != EOF);
367 }
368 
369 
370 static int read_line (lua_State *L, FILE *f, int chop) {
371  luaL_Buffer b;
372  luaL_buffinit(L, &b);
373  for (;;) {
374  size_t l;
375  char *p = luaL_prepbuffer(&b);
376  if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
377  luaL_pushresult(&b); /* close buffer */
378  return (lua_rawlen(L, -1) > 0); /* check whether read something */
379  }
380  l = strlen(p);
381  if (l == 0 || p[l-1] != '\n')
382  luaL_addsize(&b, l);
383  else {
384  luaL_addsize(&b, l - chop); /* chop 'eol' if needed */
385  luaL_pushresult(&b); /* close buffer */
386  return 1; /* read at least an `eol' */
387  }
388  }
389 }
390 
391 
392 #define MAX_SIZE_T (~(size_t)0)
393 
394 static void read_all (lua_State *L, FILE *f) {
395  size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
396  luaL_Buffer b;
397  luaL_buffinit(L, &b);
398  for (;;) {
399  char *p = luaL_prepbuffsize(&b, rlen);
400  size_t nr = fread(p, sizeof(char), rlen, f);
401  luaL_addsize(&b, nr);
402  if (nr < rlen) break; /* eof? */
403  else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
404  rlen *= 2; /* double buffer size at each iteration */
405  }
406  luaL_pushresult(&b); /* close buffer */
407 }
408 
409 
410 static int read_chars (lua_State *L, FILE *f, size_t n) {
411  size_t nr; /* number of chars actually read */
412  char *p;
413  luaL_Buffer b;
414  luaL_buffinit(L, &b);
415  p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
416  nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
417  luaL_addsize(&b, nr);
418  luaL_pushresult(&b); /* close buffer */
419  return (nr > 0); /* true iff read something */
420 }
421 
422 
423 static int g_read (lua_State *L, FILE *f, int first) {
424  int nargs = lua_gettop(L) - 1;
425  int success;
426  int n;
427  clearerr(f);
428  if (nargs == 0) { /* no arguments? */
429  success = read_line(L, f, 1);
430  n = first+1; /* to return 1 result */
431  }
432  else { /* ensure stack space for all results and for auxlib's buffer */
433  luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
434  success = 1;
435  for (n = first; nargs-- && success; n++) {
436  if (lua_type(L, n) == LUA_TNUMBER) {
437  size_t l = (size_t)lua_tointeger(L, n);
438  success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
439  }
440  else {
441  const char *p = lua_tostring(L, n);
442  luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
443  switch (p[1]) {
444  case 'n': /* number */
445  success = read_number(L, f);
446  break;
447  case 'l': /* line */
448  success = read_line(L, f, 1);
449  break;
450  case 'L': /* line with end-of-line */
451  success = read_line(L, f, 0);
452  break;
453  case 'a': /* file */
454  read_all(L, f); /* read entire file */
455  success = 1; /* always success */
456  break;
457  default:
458  return luaL_argerror(L, n, "invalid format");
459  }
460  }
461  }
462  }
463  if (ferror(f))
464  return luaL_fileresult(L, 0, NULL);
465  if (!success) {
466  lua_pop(L, 1); /* remove last result */
467  lua_pushnil(L); /* push nil instead */
468  }
469  return n - first;
470 }
471 
472 
473 static int io_read (lua_State *L) {
474  return g_read(L, getiofile(L, IO_INPUT), 1);
475 }
476 
477 
478 static int f_read (lua_State *L) {
479  return g_read(L, tofile(L), 2);
480 }
481 
482 
483 static int io_readline (lua_State *L) {
485  int i;
486  int n = (int)lua_tointeger(L, lua_upvalueindex(2));
487  if (isclosed(p)) /* file is already closed? */
488  return luaL_error(L, "file is already closed");
489  lua_settop(L , 1);
490  for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
491  lua_pushvalue(L, lua_upvalueindex(3 + i));
492  n = g_read(L, p->f, 2); /* 'n' is number of results */
493  lua_assert(n > 0); /* should return at least a nil */
494  if (!lua_isnil(L, -n)) /* read at least one value? */
495  return n; /* return them */
496  else { /* first result is nil: EOF or error */
497  if (n > 1) { /* is there error information? */
498  /* 2nd result is error message */
499  return luaL_error(L, "%s", lua_tostring(L, -n + 1));
500  }
501  if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
502  lua_settop(L, 0);
504  aux_close(L); /* close it */
505  }
506  return 0;
507  }
508 }
509 
510 /* }====================================================== */
511 
512 
513 static int g_write (lua_State *L, FILE *f, int arg) {
514  int nargs = lua_gettop(L) - arg;
515  int status = 1;
516  for (; nargs--; arg++) {
517  if (lua_type(L, arg) == LUA_TNUMBER) {
518  /* optimization: could be done exactly as for strings */
519  status = status &&
520  fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
521  }
522  else {
523  size_t l;
524  const char *s = luaL_checklstring(L, arg, &l);
525  status = status && (fwrite(s, sizeof(char), l, f) == l);
526  }
527  }
528  if (status) return 1; /* file handle already on stack top */
529  else return luaL_fileresult(L, status, NULL);
530 }
531 
532 
533 static int io_write (lua_State *L) {
534  return g_write(L, getiofile(L, IO_OUTPUT), 1);
535 }
536 
537 
538 static int f_write (lua_State *L) {
539  FILE *f = tofile(L);
540  lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
541  return g_write(L, f, 2);
542 }
543 
544 
545 static int f_seek (lua_State *L) {
546  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
547  static const char *const modenames[] = {"set", "cur", "end", NULL};
548  FILE *f = tofile(L);
549  int op = luaL_checkoption(L, 2, "cur", modenames);
550  lua_Number p3 = luaL_optnumber(L, 3, 0);
551  l_seeknum offset = (l_seeknum)p3;
552  luaL_argcheck(L, (lua_Number)offset == p3, 3,
553  "not an integer in proper range");
554  op = l_fseek(f, offset, mode[op]);
555  if (op)
556  return luaL_fileresult(L, 0, NULL); /* error */
557  else {
559  return 1;
560  }
561 }
562 
563 
564 static int f_setvbuf (lua_State *L) {
565  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
566  static const char *const modenames[] = {"no", "full", "line", NULL};
567  FILE *f = tofile(L);
568  int op = luaL_checkoption(L, 2, NULL, modenames);
570  int res = setvbuf(f, NULL, mode[op], sz);
571  return luaL_fileresult(L, res == 0, NULL);
572 }
573 
574 
575 
576 static int io_flush (lua_State *L) {
577  return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
578 }
579 
580 
581 static int f_flush (lua_State *L) {
582  return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
583 }
584 
585 
586 /*
587 ** functions for 'io' library
588 */
589 static const luaL_Reg iolib[] = {
590  {"close", io_close},
591  {"flush", io_flush},
592  {"input", io_input},
593  {"lines", io_lines},
594  {"open", io_open},
595  {"output", io_output},
596  {"popen", io_popen},
597  {"read", io_read},
598  {"tmpfile", io_tmpfile},
599  {"type", io_type},
600  {"write", io_write},
601  {NULL, NULL}
602 };
603 
604 
605 /*
606 ** methods for file handles
607 */
608 static const luaL_Reg flib[] = {
609  {"close", io_close},
610  {"flush", f_flush},
611  {"lines", f_lines},
612  {"read", f_read},
613  {"seek", f_seek},
614  {"setvbuf", f_setvbuf},
615  {"write", f_write},
616  {"__gc", f_gc},
617  {"__tostring", f_tostring},
618  {NULL, NULL}
619 };
620 
621 
622 static void createmeta (lua_State *L) {
623  luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
624  lua_pushvalue(L, -1); /* push metatable */
625  lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
626  luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
627  lua_pop(L, 1); /* pop new metatable */
628 }
629 
630 
631 /*
632 ** function to (not) close the standard files stdin, stdout, and stderr
633 */
634 static int io_noclose (lua_State *L) {
635  LStream *p = tolstream(L);
636  p->closef = &io_noclose; /* keep file opened */
637  lua_pushnil(L);
638  lua_pushliteral(L, "cannot close standard file");
639  return 2;
640 }
641 
642 
643 static void createstdfile (lua_State *L, FILE *f, const char *k,
644  const char *fname) {
645  LStream *p = newprefile(L);
646  p->f = f;
647  p->closef = &io_noclose;
648  if (k != NULL) {
649  lua_pushvalue(L, -1);
650  lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
651  }
652  lua_setfield(L, -2, fname); /* add file to module */
653 }
654 
655 
657  luaL_newlib(L, iolib); /* new module */
658  createmeta(L);
659  /* create (and set) default files */
660  createstdfile(L, stdin, IO_INPUT, "stdin");
661  createstdfile(L, stdout, IO_OUTPUT, "stdout");
662  createstdfile(L, stderr, NULL, "stderr");
663  return 1;
664 }
665 
#define luaL_addsize(B, s)
Definition: lauxlib.h:156
static int io_input(lua_State *L)
Definition: liolib.cpp:289
#define lua_isnoneornil(L, n)
Definition: lua.h:337
FILE * f
Definition: lauxlib.h:189
#define isclosed(p)
Definition: liolib.cpp:126
static int f_seek(lua_State *L)
Definition: liolib.cpp:545
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:622
LUA_API void lua_replace(lua_State *L, int idx)
Definition: lapi.cpp:211
static int io_close(lua_State *L)
Definition: liolib.cpp:183
LUA_API void lua_settop(lua_State *L, int idx)
Definition: lapi.cpp:159
#define lua_isnone(L, n)
Definition: lua.h:336
LUA_API int lua_type(lua_State *L, int idx)
Definition: lapi.cpp:243
static void createmeta(lua_State *L)
Definition: liolib.cpp:622
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
Definition: lauxlib.cpp:439
#define LUA_NUMBER_SCAN
Definition: luaconf.h:412
static int read_line(lua_State *L, FILE *f, int chop)
Definition: liolib.cpp:370
const GLfloat * c
Definition: glew.h:12741
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.cpp:571
static void read_all(lua_State *L, FILE *f)
Definition: liolib.cpp:394
static int io_fclose(lua_State *L)
Definition: liolib.cpp:202
static FILE * tofile(lua_State *L)
Definition: liolib.cpp:153
luaL_Stream LStream
Definition: liolib.cpp:121
static void createstdfile(lua_State *L, FILE *f, const char *k, const char *fname)
Definition: liolib.cpp:643
static int test_eof(lua_State *L, FILE *f)
Definition: liolib.cpp:362
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
Definition: lauxlib.cpp:473
static int io_popen(lua_State *L)
Definition: liolib.cpp:245
LUA_API int lua_gettop(lua_State *L)
Definition: lapi.cpp:154
static int f_setvbuf(lua_State *L)
Definition: liolib.cpp:564
static int g_write(lua_State *L, FILE *f, int arg)
Definition: liolib.cpp:513
#define lua_tointeger(L, i)
Definition: lua.h:319
static int g_read(lua_State *L, FILE *f, int first)
Definition: liolib.cpp:423
#define LUA_FILEHANDLE
Definition: lauxlib.h:185
#define lua_tonumber(L, i)
Definition: lua.h:318
static int f_flush(lua_State *L)
Definition: liolib.cpp:581
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
Definition: lauxlib.cpp:335
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
Definition: lapi.cpp:549
#define d
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:286
GLenum mode
Definition: glew.h:2390
#define luaL_argcheck(L, cond, numarg, extramsg)
Definition: lauxlib.h:113
static FILE * getiofile(lua_State *L, const char *findex)
Definition: liolib.cpp:262
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
Definition: lauxlib.cpp:409
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
Definition: lapi.cpp:1169
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:55
#define lua_pop(L, n)
Definition: lua.h:322
GLdouble l
Definition: glew.h:6966
#define lua_pclose(L, file)
Definition: liolib.cpp:70
static int aux_close(lua_State *L)
Definition: liolib.cpp:175
static int f_read(lua_State *L)
Definition: liolib.cpp:478
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
#define IO_OUTPUT
Definition: liolib.cpp:118
GLintptr offset
Definition: glew.h:1650
#define lua_upvalueindex(i)
Definition: lua.h:40
LUA_INTEGER lua_Integer
Definition: lua.h:106
#define LUAL_BUFFERSIZE
Definition: luaconf.h:382
LUAMOD_API int luaopen_io(lua_State *L)
Definition: liolib.cpp:656
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
Definition: lauxlib.cpp:209
static int read_number(lua_State *L, FILE *f)
Definition: liolib.cpp:349
LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, const char *const lst[])
Definition: lauxlib.cpp:322
static int io_noclose(lua_State *L)
Definition: liolib.cpp:634
static int io_pclose(lua_State *L)
Definition: liolib.cpp:239
static int io_readline(lua_State *L)
Definition: liolib.cpp:483
LUA_API int lua_toboolean(lua_State *L, int idx)
Definition: lapi.cpp:377
static int read_chars(lua_State *L, FILE *f, size_t n)
Definition: liolib.cpp:410
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
Definition: lauxlib.cpp:498
static int io_output(lua_State *L)
Definition: liolib.cpp:294
#define lua_checkmode(mode)
Definition: liolib.cpp:38
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
Definition: lapi.cpp:495
#define LUA_TNUMBER
Definition: lua.h:80
static int f_write(lua_State *L)
Definition: liolib.cpp:538
static LStream * newprefile(lua_State *L)
Definition: liolib.cpp:167
static const luaL_Reg iolib[]
Definition: liolib.cpp:589
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.cpp:292
#define l_fseek(f, o, w)
Definition: liolib.cpp:108
GLfloat GLfloat p
Definition: glew.h:12766
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
#define tolstream(L)
Definition: liolib.cpp:124
LUA_API void lua_pushnil(lua_State *L)
Definition: lapi.cpp:459
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
Definition: lapi.cpp:467
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
Definition: lauxlib.cpp:359
#define lua_pushliteral(L, s)
Definition: lua.h:339
#define LUA_NUMBER_FMT
Definition: luaconf.h:413
LUALIB_API lua_Number luaL_optnumber(lua_State *L, int narg, lua_Number def)
Definition: lauxlib.cpp:386
#define luaL_prepbuffer(B)
Definition: lauxlib.h:167
#define IO_PREFIX
Definition: liolib.cpp:116
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:274
GLuint res
Definition: glew.h:9258
LUA_API void * lua_touserdata(lua_State *L, int idx)
Definition: lapi.cpp:421
#define lua_isnil(L, n)
Definition: lua.h:333
static int f_tostring(lua_State *L)
Definition: liolib.cpp:143
lua_CFunction closef
Definition: lauxlib.h:190
#define lua_assert(c)
Definition: llimits.h:65
#define LUA_QS
Definition: luaconf.h:199
#define l_ftell(f)
Definition: liolib.cpp:109
static void aux_lines(lua_State *L, int toclose)
Definition: liolib.cpp:302
#define LUAMOD_API
Definition: luaconf.h:163
#define l_seeknum
Definition: liolib.cpp:110
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
Definition: lauxlib.cpp:152
size_t i
Definition: function.cpp:1057
#define lua_tostring(L, i)
Definition: lua.h:345
#define IO_INPUT
Definition: liolib.cpp:117
static int f_gc(lua_State *L)
Definition: liolib.cpp:191
#define LUA_MINSTACK
Definition: lua.h:92
LUA_API void lua_pushvalue(lua_State *L, int idx)
Definition: lapi.cpp:229
static int io_type(lua_State *L)
Definition: liolib.cpp:129
static int io_open(lua_State *L)
Definition: liolib.cpp:225
#define luaL_newlib(L, l)
Definition: lauxlib.h:111
static int io_tmpfile(lua_State *L)
Definition: liolib.cpp:255
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.cpp:198
static int io_lines(lua_State *L)
Definition: liolib.cpp:322
LUA_API size_t lua_rawlen(lua_State *L, int idx)
Definition: lapi.cpp:401
static int io_flush(lua_State *L)
Definition: liolib.cpp:576
#define LUA_REGISTRYINDEX
Definition: lua.h:39
#define lua_popen(L, c, m)
Definition: liolib.cpp:68
static int io_read(lua_State *L)
Definition: liolib.cpp:473
GLclampd n
Definition: glew.h:5903
static LStream * newfile(lua_State *L)
Definition: liolib.cpp:209
static int f_lines(lua_State *L)
Definition: liolib.cpp:315
LUALIB_API void luaL_checkany(lua_State *L, int narg)
Definition: lauxlib.cpp:353
LUALIB_API int luaL_execresult(lua_State *L, int stat)
Definition: lauxlib.cpp:249
GLint * first
Definition: glew.h:1496
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
Definition: lapi.cpp:536
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
Definition: lauxlib.cpp:850
#define MAX_SIZE_T
Definition: liolib.cpp:392
GLdouble s
Definition: glew.h:1358
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.cpp:477
#define luaL_optstring(L, n, d)
Definition: lauxlib.h:116
LUA_NUMBER lua_Number
Definition: lua.h:102
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:752
static int g_iofile(lua_State *L, const char *f, const char *mode)
Definition: liolib.cpp:272
static const luaL_Reg flib[]
Definition: liolib.cpp:608
static void opencheck(lua_State *L, const char *fname, const char *mode)
Definition: liolib.cpp:217
static int io_write(lua_State *L)
Definition: liolib.cpp:533
GLclampf f
Definition: glew.h:3024
#define luaL_checkstring(L, n)
Definition: lauxlib.h:115