liolib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. ** $Id: liolib.c,v 2.96 2011/01/26 16:30:02 roberto Exp roberto $
  3. ** Standard I/O (and system) library
  4. ** See Copyright Notice in lua.h
  5. */
  6. #include <errno.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #define liolib_c
  11. #define LUA_LIB
  12. #include "lua.h"
  13. #include "lauxlib.h"
  14. #include "lualib.h"
  15. #define MAX_SIZE_T (~(size_t)0)
  16. /*
  17. ** lua_popen spawns a new process connected to the current one through
  18. ** the file streams.
  19. */
  20. #if !defined(lua_popen) /* { */
  21. #if defined(LUA_USE_POPEN) /* { */
  22. #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
  23. #if defined(LUA_USE_POSIX) /* { */
  24. #include <sys/wait.h>
  25. #define lua_pclose(L,file,stat,tp) \
  26. {(void)L; \
  27. stat = pclose(file); \
  28. if (stat == -1) { /* keep this value */ } \
  29. else if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); tp = "exit"; } \
  30. else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); tp = "signal"; } \
  31. else if (WIFSTOPPED(stat)) { stat = WSTOPSIG(stat); tp = "stop"; } }
  32. #else /* }{ */
  33. #define lua_pclose(L,file,stat,tp) {(void)L; stat = pclose(file);}
  34. #endif /* } */
  35. #elif defined(LUA_WIN) /* }{ */
  36. #define lua_popen(L,c,m) ((void)L, _popen(c,m))
  37. #define lua_pclose(L,file,stat,tp) {(void)L; stat = _pclose(file);}
  38. #else /* }{ */
  39. #define lua_popen(L,c,m) ((void)((void)c, m), \
  40. luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
  41. #define lua_pclose(L,file,stat,tp) {(void)L; (void)file; stat = -1;}
  42. #endif /* } */
  43. #endif /* } */
  44. #define IO_INPUT 1
  45. #define IO_OUTPUT 2
  46. static const char *const fnames[] = {"input", "output"};
  47. static int pushresult (lua_State *L, int i, const char *filename) {
  48. int en = errno; /* calls to Lua API may change this value */
  49. if (i) {
  50. lua_pushboolean(L, 1);
  51. return 1;
  52. }
  53. else {
  54. lua_pushnil(L);
  55. if (filename)
  56. lua_pushfstring(L, "%s: %s", filename, strerror(en));
  57. else
  58. lua_pushfstring(L, "%s", strerror(en));
  59. lua_pushinteger(L, en);
  60. return 3;
  61. }
  62. }
  63. static void fileerror (lua_State *L, int arg, const char *filename) {
  64. lua_pushfstring(L, "%s: %s", filename, strerror(errno));
  65. luaL_argerror(L, arg, lua_tostring(L, -1));
  66. }
  67. #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))
  68. static int io_type (lua_State *L) {
  69. void *ud;
  70. luaL_checkany(L, 1);
  71. ud = luaL_testudata(L, 1, LUA_FILEHANDLE);
  72. if (ud == NULL)
  73. lua_pushnil(L); /* not a file */
  74. else if (*((FILE **)ud) == NULL)
  75. lua_pushliteral(L, "closed file");
  76. else
  77. lua_pushliteral(L, "file");
  78. return 1;
  79. }
  80. static FILE *tofile (lua_State *L) {
  81. FILE **f = tofilep(L);
  82. if (*f == NULL)
  83. luaL_error(L, "attempt to use a closed file");
  84. return *f;
  85. }
  86. /*
  87. ** When creating file handles, always creates a `closed' file handle
  88. ** before opening the actual file; so, if there is a memory error, the
  89. ** file is not left opened.
  90. */
  91. static FILE **newprefile (lua_State *L) {
  92. FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
  93. *pf = NULL; /* file handle is currently `closed' */
  94. luaL_setmetatable(L, LUA_FILEHANDLE);
  95. return pf;
  96. }
  97. static FILE **newfile (lua_State *L) {
  98. FILE **pf = newprefile(L);
  99. lua_pushvalue(L, lua_upvalueindex(1)); /* set upvalue... */
  100. lua_setuservalue(L, -2); /* ... as environment for new file */
  101. return pf;
  102. }
  103. /*
  104. ** function to (not) close the standard files stdin, stdout, and stderr
  105. */
  106. static int io_noclose (lua_State *L) {
  107. lua_pushnil(L);
  108. lua_pushliteral(L, "cannot close standard file");
  109. return 2;
  110. }
  111. /*
  112. ** function to close 'popen' files
  113. */
  114. static int io_pclose (lua_State *L) {
  115. FILE **p = tofilep(L);
  116. int stat;
  117. const char *tp = NULL; /* type of termination (when available) */
  118. lua_pclose(L, *p, stat, tp);
  119. *p = NULL;
  120. if (stat == -1) /* error? */
  121. return pushresult(L, 0, NULL);
  122. else {
  123. lua_pushinteger(L, stat);
  124. lua_pushstring(L, tp);
  125. return 2; /* return status and type */
  126. }
  127. }
  128. /*
  129. ** function to close regular files
  130. */
  131. static int io_fclose (lua_State *L) {
  132. FILE **p = tofilep(L);
  133. int ok = (fclose(*p) == 0);
  134. *p = NULL;
  135. return pushresult(L, ok, NULL);
  136. }
  137. static int aux_close (lua_State *L) {
  138. lua_getuservalue(L, 1);
  139. lua_getfield(L, -1, "__close");
  140. return (lua_tocfunction(L, -1))(L);
  141. }
  142. static int io_close (lua_State *L) {
  143. if (lua_isnone(L, 1))
  144. lua_rawgeti(L, lua_upvalueindex(1), IO_OUTPUT);
  145. tofile(L); /* make sure argument is a file */
  146. return aux_close(L);
  147. }
  148. static int io_gc (lua_State *L) {
  149. FILE *f = *tofilep(L);
  150. /* ignore closed files */
  151. if (f != NULL)
  152. aux_close(L);
  153. return 0;
  154. }
  155. static int io_tostring (lua_State *L) {
  156. FILE *f = *tofilep(L);
  157. if (f == NULL)
  158. lua_pushliteral(L, "file (closed)");
  159. else
  160. lua_pushfstring(L, "file (%p)", f);
  161. return 1;
  162. }
  163. static int io_open (lua_State *L) {
  164. const char *filename = luaL_checkstring(L, 1);
  165. const char *mode = luaL_optstring(L, 2, "r");
  166. FILE **pf;
  167. int i = 0;
  168. /* check whether 'mode' matches '[rwa]%+?b?' */
  169. if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
  170. (mode[i] != '+' || ++i) && /* skip if char is '+' */
  171. (mode[i] != 'b' || ++i) && /* skip if char is 'b' */
  172. (mode[i] == '\0')))
  173. luaL_error(L, "invalid mode " LUA_QL("%s")
  174. " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
  175. pf = newfile(L);
  176. *pf = fopen(filename, mode);
  177. return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
  178. }
  179. /*
  180. ** this function has a separated environment, which defines the
  181. ** correct __close for 'popen' files
  182. */
  183. static int io_popen (lua_State *L) {
  184. const char *filename = luaL_checkstring(L, 1);
  185. const char *mode = luaL_optstring(L, 2, "r");
  186. FILE **pf = newfile(L);
  187. *pf = lua_popen(L, filename, mode);
  188. return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
  189. }
  190. static int io_tmpfile (lua_State *L) {
  191. FILE **pf = newfile(L);
  192. *pf = tmpfile();
  193. return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
  194. }
  195. static FILE *getiofile (lua_State *L, int findex) {
  196. FILE *f;
  197. lua_rawgeti(L, lua_upvalueindex(1), findex);
  198. f = *(FILE **)lua_touserdata(L, -1);
  199. if (f == NULL)
  200. luaL_error(L, "standard %s file is closed", fnames[findex - 1]);
  201. return f;
  202. }
  203. static int g_iofile (lua_State *L, int f, const char *mode) {
  204. if (!lua_isnoneornil(L, 1)) {
  205. const char *filename = lua_tostring(L, 1);
  206. if (filename) {
  207. FILE **pf = newfile(L);
  208. *pf = fopen(filename, mode);
  209. if (*pf == NULL)
  210. fileerror(L, 1, filename);
  211. }
  212. else {
  213. tofile(L); /* check that it's a valid file handle */
  214. lua_pushvalue(L, 1);
  215. }
  216. lua_rawseti(L, lua_upvalueindex(1), f);
  217. }
  218. /* return current value */
  219. lua_rawgeti(L, lua_upvalueindex(1), f);
  220. return 1;
  221. }
  222. static int io_input (lua_State *L) {
  223. return g_iofile(L, IO_INPUT, "r");
  224. }
  225. static int io_output (lua_State *L) {
  226. return g_iofile(L, IO_OUTPUT, "w");
  227. }
  228. static int io_readline (lua_State *L);
  229. static void aux_lines (lua_State *L, int toclose) {
  230. int i;
  231. int n = lua_gettop(L) - 1; /* number of arguments to read */
  232. /* ensure that arguments will fit here and into 'io_readline' stack */
  233. luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
  234. lua_pushvalue(L, 1); /* file handle */
  235. lua_pushinteger(L, n); /* number of arguments to read */
  236. lua_pushboolean(L, toclose); /* close/not close file when finished */
  237. for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1); /* copy arguments */
  238. lua_pushcclosure(L, io_readline, 3 + n);
  239. }
  240. static int f_lines (lua_State *L) {
  241. tofile(L); /* check that it's a valid file handle */
  242. aux_lines(L, 0);
  243. return 1;
  244. }
  245. static int io_lines (lua_State *L) {
  246. int toclose;
  247. if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
  248. if (lua_isnil(L, 1)) { /* no file name? */
  249. lua_rawgeti(L, lua_upvalueindex(1), IO_INPUT); /* get default input */
  250. lua_replace(L, 1); /* put it at index 1 */
  251. tofile(L); /* check that it's a valid file handle */
  252. toclose = 0; /* do not close it after iteration */
  253. }
  254. else { /* open a new file */
  255. const char *filename = luaL_checkstring(L, 1);
  256. FILE **pf = newfile(L);
  257. *pf = fopen(filename, "r");
  258. if (*pf == NULL)
  259. fileerror(L, 1, filename);
  260. lua_replace(L, 1); /* put file at index 1 */
  261. toclose = 1; /* close it after iteration */
  262. }
  263. aux_lines(L, toclose);
  264. return 1;
  265. }
  266. /*
  267. ** {======================================================
  268. ** READ
  269. ** =======================================================
  270. */
  271. static int read_number (lua_State *L, FILE *f) {
  272. lua_Number d;
  273. if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
  274. lua_pushnumber(L, d);
  275. return 1;
  276. }
  277. else {
  278. lua_pushnil(L); /* "result" to be removed */
  279. return 0; /* read fails */
  280. }
  281. }
  282. static int test_eof (lua_State *L, FILE *f) {
  283. int c = getc(f);
  284. ungetc(c, f);
  285. lua_pushlstring(L, NULL, 0);
  286. return (c != EOF);
  287. }
  288. static int read_line (lua_State *L, FILE *f, int chop) {
  289. luaL_Buffer b;
  290. luaL_buffinit(L, &b);
  291. for (;;) {
  292. size_t l;
  293. char *p = luaL_prepbuffer(&b);
  294. if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
  295. luaL_pushresult(&b); /* close buffer */
  296. return (lua_rawlen(L, -1) > 0); /* check whether read something */
  297. }
  298. l = strlen(p);
  299. if (l == 0 || p[l-1] != '\n')
  300. luaL_addsize(&b, l);
  301. else {
  302. luaL_addsize(&b, l - chop); /* chop 'eol' if needed */
  303. luaL_pushresult(&b); /* close buffer */
  304. return 1; /* read at least an `eol' */
  305. }
  306. }
  307. }
  308. static void read_all (lua_State *L, FILE *f) {
  309. size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
  310. luaL_Buffer b;
  311. luaL_buffinit(L, &b);
  312. for (;;) {
  313. char *p = luaL_prepbuffsize(&b, rlen);
  314. size_t nr = fread(p, sizeof(char), rlen, f);
  315. luaL_addsize(&b, nr);
  316. if (nr < rlen) break; /* eof? */
  317. else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
  318. rlen *= 2; /* double buffer size at each iteration */
  319. }
  320. luaL_pushresult(&b); /* close buffer */
  321. }
  322. static int read_chars (lua_State *L, FILE *f, size_t n) {
  323. size_t nr; /* number of chars actually read */
  324. char *p;
  325. luaL_Buffer b;
  326. luaL_buffinit(L, &b);
  327. p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
  328. nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
  329. luaL_addsize(&b, nr);
  330. luaL_pushresult(&b); /* close buffer */
  331. return (nr > 0); /* true iff read something */
  332. }
  333. static int g_read (lua_State *L, FILE *f, int first) {
  334. int nargs = lua_gettop(L) - 1;
  335. int success;
  336. int n;
  337. clearerr(f);
  338. if (nargs == 0) { /* no arguments? */
  339. success = read_line(L, f, 1);
  340. n = first+1; /* to return 1 result */
  341. }
  342. else { /* ensure stack space for all results and for auxlib's buffer */
  343. luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
  344. success = 1;
  345. for (n = first; nargs-- && success; n++) {
  346. if (lua_type(L, n) == LUA_TNUMBER) {
  347. size_t l = (size_t)lua_tointeger(L, n);
  348. success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
  349. }
  350. else {
  351. const char *p = lua_tostring(L, n);
  352. luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
  353. switch (p[1]) {
  354. case 'n': /* number */
  355. success = read_number(L, f);
  356. break;
  357. case 'l': /* line */
  358. success = read_line(L, f, 1);
  359. break;
  360. case 'L': /* line with end-of-line */
  361. success = read_line(L, f, 0);
  362. break;
  363. case 'a': /* file */
  364. read_all(L, f); /* read entire file */
  365. success = 1; /* always success */
  366. break;
  367. default:
  368. return luaL_argerror(L, n, "invalid format");
  369. }
  370. }
  371. }
  372. }
  373. if (ferror(f))
  374. return pushresult(L, 0, NULL);
  375. if (!success) {
  376. lua_pop(L, 1); /* remove last result */
  377. lua_pushnil(L); /* push nil instead */
  378. }
  379. return n - first;
  380. }
  381. static int io_read (lua_State *L) {
  382. return g_read(L, getiofile(L, IO_INPUT), 1);
  383. }
  384. static int f_read (lua_State *L) {
  385. return g_read(L, tofile(L), 2);
  386. }
  387. static int io_readline (lua_State *L) {
  388. FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
  389. int i;
  390. int n = (int)lua_tointeger(L, lua_upvalueindex(2));
  391. if (f == NULL) /* file is already closed? */
  392. luaL_error(L, "file is already closed");
  393. lua_settop(L , 1);
  394. for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
  395. lua_pushvalue(L, lua_upvalueindex(3 + i));
  396. n = g_read(L, f, 2); /* 'n' is number of results */
  397. lua_assert(n > 0); /* should return at least a nil */
  398. if (!lua_isnil(L, -n)) /* read at least one value? */
  399. return n; /* return them */
  400. else { /* first result is nil: EOF or error */
  401. if (!lua_isnil(L, -1)) /* is there error information? */
  402. return luaL_error(L, "%s", lua_tostring(L, -1)); /* error */
  403. /* else EOF */
  404. if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
  405. lua_settop(L, 0);
  406. lua_pushvalue(L, lua_upvalueindex(1));
  407. aux_close(L); /* close it */
  408. }
  409. return 0;
  410. }
  411. }
  412. /* }====================================================== */
  413. static int g_write (lua_State *L, FILE *f, int arg) {
  414. int nargs = lua_gettop(L) - arg;
  415. int status = 1;
  416. for (; nargs--; arg++) {
  417. if (lua_type(L, arg) == LUA_TNUMBER) {
  418. /* optimization: could be done exactly as for strings */
  419. status = status &&
  420. fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;
  421. }
  422. else {
  423. size_t l;
  424. const char *s = luaL_checklstring(L, arg, &l);
  425. status = status && (fwrite(s, sizeof(char), l, f) == l);
  426. }
  427. }
  428. if (status) return 1; /* file handle already on stack top */
  429. else return pushresult(L, status, NULL);
  430. }
  431. static int io_write (lua_State *L) {
  432. return g_write(L, getiofile(L, IO_OUTPUT), 1);
  433. }
  434. static int f_write (lua_State *L) {
  435. FILE * f = tofile(L);
  436. lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
  437. return g_write(L, f, 2);
  438. }
  439. static int f_seek (lua_State *L) {
  440. static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  441. static const char *const modenames[] = {"set", "cur", "end", NULL};
  442. FILE *f = tofile(L);
  443. int op = luaL_checkoption(L, 2, "cur", modenames);
  444. long offset = luaL_optlong(L, 3, 0);
  445. op = fseek(f, offset, mode[op]);
  446. if (op)
  447. return pushresult(L, 0, NULL); /* error */
  448. else {
  449. lua_pushinteger(L, ftell(f));
  450. return 1;
  451. }
  452. }
  453. static int f_setvbuf (lua_State *L) {
  454. static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
  455. static const char *const modenames[] = {"no", "full", "line", NULL};
  456. FILE *f = tofile(L);
  457. int op = luaL_checkoption(L, 2, NULL, modenames);
  458. lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
  459. int res = setvbuf(f, NULL, mode[op], sz);
  460. return pushresult(L, res == 0, NULL);
  461. }
  462. static int io_flush (lua_State *L) {
  463. return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
  464. }
  465. static int f_flush (lua_State *L) {
  466. return pushresult(L, fflush(tofile(L)) == 0, NULL);
  467. }
  468. static const luaL_Reg iolib[] = {
  469. {"close", io_close},
  470. {"flush", io_flush},
  471. {"input", io_input},
  472. {"lines", io_lines},
  473. {"open", io_open},
  474. {"output", io_output},
  475. {"popen", io_popen},
  476. {"read", io_read},
  477. {"tmpfile", io_tmpfile},
  478. {"type", io_type},
  479. {"write", io_write},
  480. {NULL, NULL}
  481. };
  482. static const luaL_Reg flib[] = {
  483. {"close", io_close},
  484. {"flush", f_flush},
  485. {"lines", f_lines},
  486. {"read", f_read},
  487. {"seek", f_seek},
  488. {"setvbuf", f_setvbuf},
  489. {"write", f_write},
  490. {"__gc", io_gc},
  491. {"__tostring", io_tostring},
  492. {NULL, NULL}
  493. };
  494. static void createmeta (lua_State *L) {
  495. luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
  496. lua_pushvalue(L, -1); /* push metatable */
  497. lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
  498. luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
  499. lua_pop(L, 1); /* pop new metatable */
  500. }
  501. static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
  502. *newprefile(L) = f;
  503. if (k > 0) {
  504. lua_pushvalue(L, -1); /* copy new file */
  505. lua_rawseti(L, 1, k); /* add it to common upvalue */
  506. }
  507. lua_pushvalue(L, 3); /* get environment for default files */
  508. lua_setuservalue(L, -2); /* set it as environment for file */
  509. lua_setfield(L, 2, fname); /* add file to module */
  510. }
  511. /*
  512. ** pushes a new table with {__close = cls}
  513. */
  514. static void newenv (lua_State *L, lua_CFunction cls) {
  515. lua_createtable(L, 0, 1);
  516. lua_pushcfunction(L, cls);
  517. lua_setfield(L, -2, "__close");
  518. }
  519. LUAMOD_API int luaopen_io (lua_State *L) {
  520. lua_settop(L, 0);
  521. createmeta(L);
  522. /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
  523. newenv(L, io_fclose); /* upvalue for all io functions at index 1 */
  524. luaL_newlibtable(L, iolib); /* new module at index 2 */
  525. lua_pushvalue(L, 1); /* copy of env to be consumed by 'setfuncs' */
  526. luaL_setfuncs(L, iolib, 1);
  527. /* create (and set) default files */
  528. newenv(L, io_noclose); /* environment for default files at index 3 */
  529. createstdfile(L, stdin, IO_INPUT, "stdin");
  530. createstdfile(L, stdout, IO_OUTPUT, "stdout");
  531. createstdfile(L, stderr, 0, "stderr");
  532. lua_pop(L, 1); /* pop environment for default files */
  533. lua_getfield(L, 2, "popen");
  534. newenv(L, io_pclose); /* create environment for 'popen' streams */
  535. lua_setupvalue(L, -2, 1); /* set it as upvalue for 'popen' */
  536. lua_pop(L, 1); /* pop 'popen' */
  537. return 1;
  538. }