liolib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. ** $Id: liolib.c,v 1.92 2000/11/23 13:49:35 roberto Exp roberto $
  3. ** Standard I/O (and system) library
  4. ** See Copyright Notice in lua.h
  5. */
  6. #include <ctype.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <time.h>
  11. #include "lua.h"
  12. #include "lauxlib.h"
  13. #include "luadebug.h"
  14. #include "lualib.h"
  15. #ifndef OLD_ANSI
  16. #include <errno.h>
  17. #include <locale.h>
  18. #define realloc(b,s) ((b) == NULL ? malloc(s) : (realloc)(b, s))
  19. #define free(b) if (b) (free)(b)
  20. #else
  21. /* no support for locale and for strerror: fake them */
  22. #define setlocale(a,b) ((void)a, strcmp((b),"C")==0?"C":NULL)
  23. #define LC_ALL 0
  24. #define LC_COLLATE 0
  25. #define LC_CTYPE 0
  26. #define LC_MONETARY 0
  27. #define LC_NUMERIC 0
  28. #define LC_TIME 0
  29. #define strerror(e) "generic I/O error"
  30. #define errno (-1)
  31. #endif
  32. #ifdef POPEN
  33. /* FILE *popen();
  34. int pclose(); */
  35. #define CLOSEFILE(L, f) ((pclose(f) == -1) ? fclose(f) : 0)
  36. #else
  37. /* no support for popen */
  38. #define popen(x,y) NULL /* that is, popen always fails */
  39. #define CLOSEFILE(L, f) (fclose(f))
  40. #endif
  41. #define INFILE 0
  42. #define OUTFILE 1
  43. #define NOFILE 2
  44. typedef struct IOCtrl {
  45. int ref[2]; /* ref for strings _INPUT/_OUTPUT */
  46. int iotag; /* tag for file handles */
  47. int closedtag; /* tag for closed handles */
  48. } IOCtrl;
  49. static const char *const filenames[] = {"_INPUT", "_OUTPUT"};
  50. static int pushresult (lua_State *L, int i) {
  51. if (i) {
  52. lua_pushuserdata(L, NULL);
  53. return 1;
  54. }
  55. else {
  56. lua_pushnil(L);
  57. lua_pushstring(L, strerror(errno));
  58. lua_pushnumber(L, errno);
  59. return 3;;
  60. }
  61. }
  62. /*
  63. ** {======================================================
  64. ** FILE Operations
  65. ** =======================================================
  66. */
  67. static FILE *gethandle (lua_State *L, IOCtrl *ctrl, int f) {
  68. void *p = lua_touserdata(L, f);
  69. if (p != NULL) { /* is `f' a userdata ? */
  70. int ftag = lua_tag(L, f);
  71. if (ftag == ctrl->iotag) /* does it have the correct tag? */
  72. return (FILE *)p;
  73. else if (ftag == ctrl->closedtag)
  74. lua_error(L, "cannot access a closed file");
  75. /* else go through */
  76. }
  77. return NULL;
  78. }
  79. static FILE *getnonullfile (lua_State *L, IOCtrl *ctrl, int arg) {
  80. FILE *f = gethandle(L, ctrl, arg);
  81. luaL_arg_check(L, f, arg, "invalid file handle");
  82. return f;
  83. }
  84. static FILE *getfilebyref (lua_State *L, IOCtrl *ctrl, int inout) {
  85. FILE *f;
  86. lua_getglobals(L);
  87. lua_getref(L, ctrl->ref[inout]);
  88. lua_rawget(L, -2);
  89. f = gethandle(L, ctrl, -1);
  90. if (f == NULL)
  91. luaL_verror(L, "global variable `%.10s' is not a file handle",
  92. filenames[inout]);
  93. return f;
  94. }
  95. static void setfilebyname (lua_State *L, IOCtrl *ctrl, FILE *f,
  96. const char *name) {
  97. lua_pushusertag(L, f, ctrl->iotag);
  98. lua_setglobal(L, name);
  99. }
  100. #define setfile(L,ctrl,f,inout) (setfilebyname(L,ctrl,f,filenames[inout]))
  101. static int setreturn (lua_State *L, IOCtrl *ctrl, FILE *f, int inout) {
  102. if (f == NULL)
  103. return pushresult(L, 0);
  104. else {
  105. if (inout != NOFILE)
  106. setfile(L, ctrl, f, inout);
  107. lua_pushusertag(L, f, ctrl->iotag);
  108. return 1;
  109. }
  110. }
  111. static int closefile (lua_State *L, IOCtrl *ctrl, FILE *f) {
  112. if (f == stdin || f == stdout || f == stderr)
  113. return 1;
  114. else {
  115. lua_pushusertag(L, f, ctrl->iotag);
  116. lua_settag(L, ctrl->closedtag);
  117. return (CLOSEFILE(L, f) == 0);
  118. }
  119. }
  120. static int io_close (lua_State *L) {
  121. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  122. lua_pop(L, 1); /* remove upvalue */
  123. return pushresult(L, closefile(L, ctrl, getnonullfile(L, ctrl, 1)));
  124. }
  125. static int file_collect (lua_State *L) {
  126. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  127. FILE *f = getnonullfile(L, ctrl, 1);
  128. if (f != stdin && f != stdout && f != stderr)
  129. CLOSEFILE(L, f);
  130. return 0;
  131. }
  132. static int io_open (lua_State *L) {
  133. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  134. FILE *f;
  135. lua_pop(L, 1); /* remove upvalue */
  136. f = fopen(luaL_check_string(L, 1), luaL_check_string(L, 2));
  137. return setreturn(L, ctrl, f, NOFILE);
  138. }
  139. static int io_tmpfile (lua_State *L) {
  140. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  141. return setreturn(L, ctrl, tmpfile(), NOFILE);
  142. }
  143. static int io_fromto (lua_State *L, int inout, const char *mode) {
  144. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  145. FILE *current;
  146. lua_pop(L, 1); /* remove upvalue */
  147. if (lua_isnull(L, 1)) {
  148. closefile(L, ctrl, getfilebyref(L, ctrl, inout));
  149. current = (inout == 0) ? stdin : stdout;
  150. }
  151. else if (lua_tag(L, 1) == ctrl->iotag) /* deprecated option */
  152. current = (FILE *)lua_touserdata(L, 1);
  153. else {
  154. const char *s = luaL_check_string(L, 1);
  155. current = (*s == '|') ? popen(s+1, mode) : fopen(s, mode);
  156. }
  157. return setreturn(L, ctrl, current, inout);
  158. }
  159. static int io_readfrom (lua_State *L) {
  160. return io_fromto(L, INFILE, "r");
  161. }
  162. static int io_writeto (lua_State *L) {
  163. return io_fromto(L, OUTFILE, "w");
  164. }
  165. static int io_appendto (lua_State *L) {
  166. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  167. FILE *current;
  168. lua_pop(L, 1); /* remove upvalue */
  169. current = fopen(luaL_check_string(L, 1), "a");
  170. return setreturn(L, ctrl, current, OUTFILE);
  171. }
  172. /*
  173. ** {======================================================
  174. ** READ
  175. ** =======================================================
  176. */
  177. #define read_pattern(L, f, p) (lua_error(L, "read patterns are deprecated"), 0)
  178. static int read_number (lua_State *L, FILE *f) {
  179. double d;
  180. if (fscanf(f, "%lf", &d) == 1) {
  181. lua_pushnumber(L, d);
  182. return 1;
  183. }
  184. else return 0; /* read fails */
  185. }
  186. static int read_word (lua_State *L, FILE *f) {
  187. int c;
  188. luaL_Buffer b;
  189. luaL_buffinit(L, &b);
  190. do { c = fgetc(f); } while (isspace(c)); /* skip spaces */
  191. while (c != EOF && !isspace(c)) {
  192. luaL_putchar(&b, c);
  193. c = fgetc(f);
  194. }
  195. ungetc(c, f);
  196. luaL_pushresult(&b); /* close buffer */
  197. return (lua_strlen(L, -1) > 0);
  198. }
  199. static int read_line (lua_State *L, FILE *f) {
  200. int n = 0;
  201. luaL_Buffer b;
  202. luaL_buffinit(L, &b);
  203. for (;;) {
  204. char *p = luaL_prepbuffer(&b);
  205. if (!fgets(p, LUAL_BUFFERSIZE, f)) /* read fails? */
  206. break;
  207. n = strlen(p);
  208. if (p[n-1] != '\n')
  209. luaL_addsize(&b, n);
  210. else {
  211. luaL_addsize(&b, n-1); /* do not add the `\n' */
  212. break;
  213. }
  214. }
  215. luaL_pushresult(&b); /* close buffer */
  216. return (n > 0); /* read something? */
  217. }
  218. static void read_file (lua_State *L, FILE *f) {
  219. size_t len = 0;
  220. size_t size = BUFSIZ;
  221. char *buffer = NULL;
  222. for (;;) {
  223. char *newbuffer = (char *)realloc(buffer, size);
  224. if (newbuffer == NULL) {
  225. free(buffer);
  226. lua_error(L, "not enough memory to read a file");
  227. }
  228. buffer = newbuffer;
  229. len += fread(buffer+len, sizeof(char), size-len, f);
  230. if (len < size) break; /* did not read all it could */
  231. size *= 2;
  232. }
  233. lua_pushlstring(L, buffer, len);
  234. free(buffer);
  235. }
  236. static int read_chars (lua_State *L, FILE *f, size_t n) {
  237. char *buffer;
  238. size_t n1;
  239. char statbuff[BUFSIZ];
  240. if (n <= BUFSIZ)
  241. buffer = statbuff;
  242. else {
  243. buffer = (char *)malloc(n);
  244. if (buffer == NULL)
  245. lua_error(L, "not enough memory to read a file");
  246. }
  247. n1 = fread(buffer, sizeof(char), n, f);
  248. lua_pushlstring(L, buffer, n1);
  249. if (buffer != statbuff) free(buffer);
  250. return (n1 > 0 || n == 0);
  251. }
  252. static int io_read (lua_State *L) {
  253. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  254. int lastarg = lua_gettop(L) - 1;
  255. int firstarg = 1;
  256. FILE *f = gethandle(L, ctrl, firstarg);
  257. int n;
  258. if (f) firstarg++;
  259. else f = getfilebyref(L, ctrl, INFILE); /* get _INPUT */
  260. lua_pop(L, 1);
  261. if (firstarg > lastarg) { /* no arguments? */
  262. lua_settop(L, 0); /* erase upvalue and other eventual garbage */
  263. firstarg = lastarg = 1; /* correct indices */
  264. lua_pushstring(L, "*l"); /* push default argument */
  265. }
  266. else /* ensure stack space for all results and for auxlib's buffer */
  267. luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments");
  268. for (n = firstarg; n<=lastarg; n++) {
  269. int success;
  270. if (lua_isnumber(L, n))
  271. success = read_chars(L, f, (size_t)lua_tonumber(L, n));
  272. else {
  273. const char *p = luaL_check_string(L, n);
  274. if (p[0] != '*') {
  275. lua_error(L, "read patterns are deprecated");
  276. success = 0; /* to avoid warnings */
  277. }
  278. else {
  279. switch (p[1]) {
  280. case 'n': /* number */
  281. if (!read_number(L, f)) goto endloop; /* read fails */
  282. continue; /* number is already pushed; avoid the "pushstring" */
  283. case 'l': /* line */
  284. success = read_line(L, f);
  285. break;
  286. case 'a': /* file */
  287. read_file(L, f);
  288. success = 1; /* always success */
  289. break;
  290. case 'w': /* word */
  291. success = read_word(L, f);
  292. break;
  293. default:
  294. luaL_argerror(L, n, "invalid format");
  295. success = 0; /* to avoid warnings */
  296. }
  297. }
  298. }
  299. if (!success) {
  300. lua_pop(L, 1); /* remove last result */
  301. break; /* read fails */
  302. }
  303. } endloop:
  304. return n - firstarg;
  305. }
  306. /* }====================================================== */
  307. static int io_write (lua_State *L) {
  308. int lastarg = lua_gettop(L) - 1;
  309. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  310. int arg = 1;
  311. int status = 1;
  312. FILE *f = gethandle(L, ctrl, arg);
  313. if (f) arg++;
  314. else f = getfilebyref(L, ctrl, OUTFILE); /* get _OUTPUT */
  315. for (; arg <= lastarg; arg++) {
  316. if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */
  317. /* optimization: could be done exactly as for strings */
  318. status = status && fprintf(f, "%.16g", lua_tonumber(L, arg)) > 0;
  319. }
  320. else {
  321. size_t l;
  322. const char *s = luaL_check_lstr(L, arg, &l);
  323. status = status && (fwrite(s, sizeof(char), l, f) == l);
  324. }
  325. }
  326. pushresult(L, status);
  327. return 1;
  328. }
  329. static int io_seek (lua_State *L) {
  330. static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  331. static const char *const modenames[] = {"set", "cur", "end", NULL};
  332. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  333. FILE *f;
  334. int op;
  335. long offset;
  336. lua_pop(L, 1); /* remove upvalue */
  337. f = getnonullfile(L, ctrl, 1);
  338. op = luaL_findstring(luaL_opt_string(L, 2, "cur"), modenames);
  339. offset = luaL_opt_long(L, 3, 0);
  340. luaL_arg_check(L, op != -1, 2, "invalid mode");
  341. op = fseek(f, offset, mode[op]);
  342. if (op)
  343. return pushresult(L, 0); /* error */
  344. else {
  345. lua_pushnumber(L, ftell(f));
  346. return 1;
  347. }
  348. }
  349. static int io_flush (lua_State *L) {
  350. IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  351. FILE *f;
  352. lua_pop(L, 1); /* remove upvalue */
  353. f = gethandle(L, ctrl, 1);
  354. luaL_arg_check(L, f || lua_isnull(L, 1), 1, "invalid file handle");
  355. return pushresult(L, fflush(f) == 0);
  356. }
  357. /* }====================================================== */
  358. /*
  359. ** {======================================================
  360. ** Other O.S. Operations
  361. ** =======================================================
  362. */
  363. static int io_execute (lua_State *L) {
  364. lua_pushnumber(L, system(luaL_check_string(L, 1)));
  365. return 1;
  366. }
  367. static int io_remove (lua_State *L) {
  368. return pushresult(L, remove(luaL_check_string(L, 1)) == 0);
  369. }
  370. static int io_rename (lua_State *L) {
  371. return pushresult(L, rename(luaL_check_string(L, 1),
  372. luaL_check_string(L, 2)) == 0);
  373. }
  374. static int io_tmpname (lua_State *L) {
  375. char buff[L_tmpnam];
  376. if (tmpnam(buff) != buff)
  377. lua_error(L, "unable to generate a unique filename");
  378. lua_pushstring(L, buff);
  379. return 1;
  380. }
  381. static int io_getenv (lua_State *L) {
  382. lua_pushstring(L, getenv(luaL_check_string(L, 1))); /* if NULL push nil */
  383. return 1;
  384. }
  385. static int io_clock (lua_State *L) {
  386. lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
  387. return 1;
  388. }
  389. static int io_date (lua_State *L) {
  390. char b[256];
  391. const char *s = luaL_opt_string(L, 1, "%c");
  392. struct tm *stm;
  393. time_t t;
  394. time(&t); stm = localtime(&t);
  395. if (strftime(b, sizeof(b), s, stm))
  396. lua_pushstring(L, b);
  397. else
  398. lua_error(L, "invalid `date' format");
  399. return 1;
  400. }
  401. static int io_setloc (lua_State *L) {
  402. static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
  403. LC_NUMERIC, LC_TIME};
  404. static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
  405. "numeric", "time", NULL};
  406. int op = luaL_findstring(luaL_opt_string(L, 2, "all"), catnames);
  407. luaL_arg_check(L, op != -1, 2, "invalid option");
  408. lua_pushstring(L, setlocale(cat[op], luaL_check_string(L, 1)));
  409. return 1;
  410. }
  411. static int io_exit (lua_State *L) {
  412. exit(luaL_opt_int(L, 1, EXIT_SUCCESS));
  413. return 0; /* to avoid warnings */
  414. }
  415. /* }====================================================== */
  416. static int io_debug (lua_State *L) {
  417. for (;;) {
  418. char buffer[250];
  419. fprintf(stderr, "lua_debug> ");
  420. if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
  421. strcmp(buffer, "cont\n") == 0)
  422. return 0;
  423. lua_dostring(L, buffer);
  424. lua_settop(L, 0); /* remove eventual returns */
  425. }
  426. }
  427. #define LEVELS1 12 /* size of the first part of the stack */
  428. #define LEVELS2 10 /* size of the second part of the stack */
  429. static int errorfb (lua_State *L) {
  430. int level = 1; /* skip level 0 (it's this function) */
  431. int firstpart = 1; /* still before eventual `...' */
  432. lua_Debug ar;
  433. luaL_Buffer b;
  434. luaL_buffinit(L, &b);
  435. luaL_addstring(&b, "error: ");
  436. luaL_addstring(&b, luaL_check_string(L, 1));
  437. luaL_addstring(&b, "\n");
  438. while (lua_getstack(L, level++, &ar)) {
  439. char buff[120]; /* enough to fit following `sprintf's */
  440. if (level == 2)
  441. luaL_addstring(&b, "stack traceback:\n");
  442. else if (level > LEVELS1 && firstpart) {
  443. /* no more than `LEVELS2' more levels? */
  444. if (!lua_getstack(L, level+LEVELS2, &ar))
  445. level--; /* keep going */
  446. else {
  447. luaL_addstring(&b, " ...\n"); /* too many levels */
  448. while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */
  449. level++;
  450. }
  451. firstpart = 0;
  452. continue;
  453. }
  454. sprintf(buff, "%4d: ", level-1);
  455. luaL_addstring(&b, buff);
  456. lua_getinfo(L, "Snl", &ar);
  457. switch (*ar.namewhat) {
  458. case 'g': case 'l': /* global, local */
  459. sprintf(buff, "function `%.50s'", ar.name);
  460. break;
  461. case 'f': /* field */
  462. sprintf(buff, "method `%.50s'", ar.name);
  463. break;
  464. case 't': /* tag method */
  465. sprintf(buff, "`%.50s' tag method", ar.name);
  466. break;
  467. default: {
  468. if (*ar.what == 'm') /* main? */
  469. sprintf(buff, "main of %.70s", ar.short_src);
  470. else if (*ar.what == 'C') /* C function? */
  471. sprintf(buff, "%.70s", ar.short_src);
  472. else
  473. sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.short_src);
  474. ar.source = NULL; /* do not print source again */
  475. }
  476. }
  477. luaL_addstring(&b, buff);
  478. if (ar.currentline > 0) {
  479. sprintf(buff, " at line %d", ar.currentline);
  480. luaL_addstring(&b, buff);
  481. }
  482. if (ar.source) {
  483. sprintf(buff, " [%.70s]", ar.short_src);
  484. luaL_addstring(&b, buff);
  485. }
  486. luaL_addstring(&b, "\n");
  487. }
  488. luaL_pushresult(&b);
  489. lua_getglobal(L, LUA_ALERT);
  490. if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */
  491. lua_pushvalue(L, -2); /* error message */
  492. lua_rawcall(L, 1, 0);
  493. }
  494. return 0;
  495. }
  496. static const struct luaL_reg iolib[] = {
  497. {LUA_ERRORMESSAGE, errorfb},
  498. {"clock", io_clock},
  499. {"date", io_date},
  500. {"debug", io_debug},
  501. {"execute", io_execute},
  502. {"exit", io_exit},
  503. {"getenv", io_getenv},
  504. {"remove", io_remove},
  505. {"rename", io_rename},
  506. {"setlocale", io_setloc},
  507. {"tmpname", io_tmpname}
  508. };
  509. static const struct luaL_reg iolibtag[] = {
  510. {"appendto", io_appendto},
  511. {"closefile", io_close},
  512. {"flush", io_flush},
  513. {"openfile", io_open},
  514. {"read", io_read},
  515. {"readfrom", io_readfrom},
  516. {"seek", io_seek},
  517. {"tmpfile", io_tmpfile},
  518. {"write", io_write},
  519. {"writeto", io_writeto}
  520. };
  521. static void openwithcontrol (lua_State *L) {
  522. IOCtrl *ctrl = (IOCtrl *)lua_newuserdata(L, sizeof(IOCtrl));
  523. unsigned int i;
  524. ctrl->iotag = lua_newtag(L);
  525. ctrl->closedtag = lua_newtag(L);
  526. for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
  527. /* put `ctrl' as upvalue for these functions */
  528. lua_pushvalue(L, -1);
  529. lua_pushcclosure(L, iolibtag[i].func, 1);
  530. lua_setglobal(L, iolibtag[i].name);
  531. }
  532. /* create references to variable names */
  533. lua_pushstring(L, filenames[INFILE]);
  534. ctrl->ref[INFILE] = lua_ref(L, 1);
  535. lua_pushstring(L, filenames[OUTFILE]);
  536. ctrl->ref[OUTFILE] = lua_ref(L, 1);
  537. /* predefined file handles */
  538. setfile(L, ctrl, stdin, INFILE);
  539. setfile(L, ctrl, stdout, OUTFILE);
  540. setfilebyname(L, ctrl, stdin, "_STDIN");
  541. setfilebyname(L, ctrl, stdout, "_STDOUT");
  542. setfilebyname(L, ctrl, stderr, "_STDERR");
  543. /* close files when collected */
  544. lua_pushcclosure(L, file_collect, 1); /* pops `ctrl' from stack */
  545. lua_settagmethod(L, ctrl->iotag, "gc");
  546. }
  547. LUALIB_API void lua_iolibopen (lua_State *L) {
  548. luaL_openl(L, iolib);
  549. openwithcontrol(L);
  550. }