lbaselib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. ** $Id: lbaselib.c,v 1.104 2002/11/06 19:08:00 roberto Exp roberto $
  3. ** Basic 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 "lua.h"
  11. #include "lauxlib.h"
  12. #include "lualib.h"
  13. /*
  14. ** If your system does not support `stdout', you can just remove this function.
  15. ** If you need, you can define your own `print' function, following this
  16. ** model but changing `fputs' to put the strings at a proper place
  17. ** (a console window or a log file, for instance).
  18. */
  19. static int luaB_print (lua_State *L) {
  20. int n = lua_gettop(L); /* number of arguments */
  21. int i;
  22. lua_getglobal(L, "tostring");
  23. for (i=1; i<=n; i++) {
  24. const char *s;
  25. lua_pushvalue(L, -1); /* function to be called */
  26. lua_pushvalue(L, i); /* value to print */
  27. lua_call(L, 1, 1);
  28. s = lua_tostring(L, -1); /* get result */
  29. if (s == NULL)
  30. return luaL_error(L, "`tostring' must return a string to `print'");
  31. if (i>1) fputs("\t", stdout);
  32. fputs(s, stdout);
  33. lua_pop(L, 1); /* pop result */
  34. }
  35. fputs("\n", stdout);
  36. return 0;
  37. }
  38. static int luaB_tonumber (lua_State *L) {
  39. int base = luaL_opt_int(L, 2, 10);
  40. if (base == 10) { /* standard conversion */
  41. luaL_check_any(L, 1);
  42. if (lua_isnumber(L, 1)) {
  43. lua_pushnumber(L, lua_tonumber(L, 1));
  44. return 1;
  45. }
  46. }
  47. else {
  48. const char *s1 = luaL_check_string(L, 1);
  49. char *s2;
  50. unsigned long n;
  51. luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range");
  52. n = strtoul(s1, &s2, base);
  53. if (s1 != s2) { /* at least one valid digit? */
  54. while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
  55. if (*s2 == '\0') { /* no invalid trailing characters? */
  56. lua_pushnumber(L, n);
  57. return 1;
  58. }
  59. }
  60. }
  61. lua_pushnil(L); /* else not a number */
  62. return 1;
  63. }
  64. static int luaB_error (lua_State *L) {
  65. int level = luaL_opt_int(L, 2, 1);
  66. luaL_check_any(L, 1);
  67. if (!lua_isstring(L, 1) || level == 0)
  68. lua_pushvalue(L, 1); /* propagate error mesage without changes */
  69. else { /* add extra information */
  70. luaL_where(L, level);
  71. lua_pushvalue(L, 1);
  72. lua_concat(L, 2);
  73. }
  74. return lua_error(L);
  75. }
  76. static int luaB_getmode (lua_State *L) {
  77. luaL_check_type(L, 1, LUA_TTABLE);
  78. lua_pushstring(L, lua_getmode(L, 1));
  79. return 1;
  80. }
  81. static int luaB_setmode (lua_State *L) {
  82. luaL_check_type(L, 1, LUA_TTABLE);
  83. lua_setmode(L, 1, luaL_check_string(L, 2));
  84. lua_settop(L, 1);
  85. return 1;
  86. }
  87. static int luaB_getmetatable (lua_State *L) {
  88. luaL_check_any(L, 1);
  89. if (!lua_getmetatable(L, 1)) {
  90. lua_pushnil(L);
  91. return 1; /* no metatable */
  92. }
  93. luaL_getmetafield(L, 1, "__metatable");
  94. return 1; /* returns either __metatable field (if present) or metatable */
  95. }
  96. static int luaB_setmetatable (lua_State *L) {
  97. int t = lua_type(L, 2);
  98. luaL_check_type(L, 1, LUA_TTABLE);
  99. luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
  100. "nil or table expected");
  101. if (luaL_getmetafield(L, 1, "__metatable"))
  102. luaL_error(L, "cannot change a protected metatable");
  103. lua_settop(L, 2);
  104. lua_setmetatable(L, 1);
  105. return 1;
  106. }
  107. static void getfunc (lua_State *L) {
  108. if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
  109. else {
  110. lua_Debug ar;
  111. int level = luaL_opt_int(L, 1, 1);
  112. luaL_arg_check(L, level >= 0, 1, "level must be non-negative");
  113. if (lua_getstack(L, level, &ar) == 0)
  114. luaL_argerror(L, 1, "invalid level");
  115. lua_getinfo(L, "f", &ar);
  116. }
  117. }
  118. static int aux_getglobals (lua_State *L) {
  119. lua_getglobals(L, -1);
  120. lua_pushliteral(L, "__globals");
  121. lua_rawget(L, -2);
  122. return !lua_isnil(L, -1);
  123. }
  124. static int luaB_getglobals (lua_State *L) {
  125. getfunc(L);
  126. if (!aux_getglobals(L)) /* __globals not defined? */
  127. lua_pop(L, 1); /* remove it, to return real globals */
  128. return 1;
  129. }
  130. static int luaB_setglobals (lua_State *L) {
  131. luaL_check_type(L, 2, LUA_TTABLE);
  132. getfunc(L);
  133. if (aux_getglobals(L)) /* __globals defined? */
  134. luaL_error(L, "cannot change a protected global table");
  135. else
  136. lua_pop(L, 2); /* remove __globals and real global table */
  137. lua_pushvalue(L, 2);
  138. if (lua_setglobals(L, -2) == 0)
  139. luaL_error(L, "cannot change global table of given function");
  140. return 0;
  141. }
  142. static int luaB_rawequal (lua_State *L) {
  143. luaL_check_any(L, 1);
  144. luaL_check_any(L, 2);
  145. lua_pushboolean(L, lua_rawequal(L, 1, 2));
  146. return 1;
  147. }
  148. static int luaB_rawget (lua_State *L) {
  149. luaL_check_type(L, 1, LUA_TTABLE);
  150. luaL_check_any(L, 2);
  151. lua_rawget(L, 1);
  152. return 1;
  153. }
  154. static int luaB_rawset (lua_State *L) {
  155. luaL_check_type(L, 1, LUA_TTABLE);
  156. luaL_check_any(L, 2);
  157. luaL_check_any(L, 3);
  158. lua_rawset(L, 1);
  159. return 1;
  160. }
  161. static int luaB_gcinfo (lua_State *L) {
  162. lua_pushnumber(L, lua_getgccount(L));
  163. lua_pushnumber(L, lua_getgcthreshold(L));
  164. return 2;
  165. }
  166. static int luaB_collectgarbage (lua_State *L) {
  167. lua_setgcthreshold(L, luaL_opt_int(L, 1, 0));
  168. return 0;
  169. }
  170. static int luaB_type (lua_State *L) {
  171. luaL_check_any(L, 1);
  172. lua_pushstring(L, lua_typename(L, lua_type(L, 1)));
  173. return 1;
  174. }
  175. static int luaB_next (lua_State *L) {
  176. luaL_check_type(L, 1, LUA_TTABLE);
  177. lua_settop(L, 2); /* create a 2nd argument if there isn't one */
  178. if (lua_next(L, 1))
  179. return 2;
  180. else {
  181. lua_pushnil(L);
  182. return 1;
  183. }
  184. }
  185. static int luaB_pairs (lua_State *L) {
  186. luaL_check_type(L, 1, LUA_TTABLE);
  187. lua_getglobal(L, "next"); /* return generator, */
  188. lua_pushvalue(L, 1); /* state, */
  189. lua_pushnil(L); /* and initial value */
  190. return 3;
  191. }
  192. static int luaB_ipairs (lua_State *L) {
  193. lua_Number i = lua_tonumber(L, 2);
  194. luaL_check_type(L, 1, LUA_TTABLE);
  195. if (i == 0 && lua_isnull(L, 2)) { /* `for' start? */
  196. lua_getglobal(L, "ipairs"); /* return generator, */
  197. lua_pushvalue(L, 1); /* state, */
  198. lua_pushnumber(L, 0); /* and initial value */
  199. return 3;
  200. }
  201. else { /* `for' step */
  202. i++; /* next value */
  203. lua_pushnumber(L, i);
  204. lua_rawgeti(L, 1, (int)i);
  205. return (lua_isnil(L, -1)) ? 0 : 2;
  206. }
  207. }
  208. static int passresults (lua_State *L, int status) {
  209. if (status == 0) return 1;
  210. else {
  211. lua_pushnil(L);
  212. lua_insert(L, -2);
  213. return 2;
  214. }
  215. }
  216. static int luaB_loadstring (lua_State *L) {
  217. size_t l;
  218. const char *s = luaL_check_lstr(L, 1, &l);
  219. const char *chunkname = luaL_opt_string(L, 2, s);
  220. return passresults(L, luaL_loadbuffer(L, s, l, chunkname));
  221. }
  222. static int writer (lua_State *L, const void* b, size_t size, void* B) {
  223. (void)L;
  224. luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
  225. return 1;
  226. }
  227. static int luaB_stringdump (lua_State *L) {
  228. luaL_Buffer b;
  229. luaL_check_type(L, 1, LUA_TFUNCTION);
  230. luaL_buffinit(L,&b);
  231. if (!lua_dump(L, writer, &b))
  232. luaL_error(L, "unable to dump given function");
  233. luaL_pushresult(&b);
  234. return 1;
  235. }
  236. static int luaB_loadfile (lua_State *L) {
  237. const char *fname = luaL_opt_string(L, 1, NULL);
  238. return passresults(L, luaL_loadfile(L, fname));
  239. }
  240. static int luaB_dofile (lua_State *L) {
  241. const char *fname = luaL_opt_string(L, 1, NULL);
  242. int status = luaL_loadfile(L, fname);
  243. if (status != 0) lua_error(L);
  244. lua_call(L, 0, LUA_MULTRET);
  245. return lua_gettop(L) - 1;
  246. }
  247. static int luaB_assert (lua_State *L) {
  248. luaL_check_any(L, 1);
  249. if (!lua_toboolean(L, 1))
  250. return luaL_error(L, "%s", luaL_opt_string(L, 2, "assertion failed!"));
  251. lua_settop(L, 1);
  252. return 1;
  253. }
  254. static int luaB_unpack (lua_State *L) {
  255. int n, i;
  256. luaL_check_type(L, 1, LUA_TTABLE);
  257. lua_pushliteral(L, "n");
  258. lua_rawget(L, 1);
  259. n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1;
  260. for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */
  261. luaL_check_stack(L, LUA_MINSTACK, "table too big to unpack");
  262. lua_rawgeti(L, 1, i+1);
  263. if (n == -1) { /* no explicit limit? */
  264. if (lua_isnil(L, -1)) { /* stop at first `nil' element */
  265. lua_pop(L, 1); /* remove `nil' */
  266. break;
  267. }
  268. }
  269. }
  270. return i;
  271. }
  272. static int luaB_pcall (lua_State *L) {
  273. int status;
  274. luaL_check_any(L, 1);
  275. status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
  276. lua_pushboolean(L, (status == 0));
  277. lua_insert(L, 1);
  278. return lua_gettop(L); /* return status + all results */
  279. }
  280. static int luaB_xpcall (lua_State *L) {
  281. int status;
  282. luaL_check_any(L, 2);
  283. lua_settop(L, 2);
  284. lua_insert(L, 1); /* put error function under function to be called */
  285. status = lua_pcall(L, 0, LUA_MULTRET, 1);
  286. lua_pushboolean(L, (status == 0));
  287. lua_replace(L, 1);
  288. return lua_gettop(L); /* return status + all results */
  289. }
  290. static int luaB_tostring (lua_State *L) {
  291. char buff[64];
  292. luaL_checkany(L, 1);
  293. if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
  294. return 1; /* use its value */
  295. switch (lua_type(L, 1)) {
  296. case LUA_TNUMBER:
  297. lua_pushstring(L, lua_tostring(L, 1));
  298. return 1;
  299. case LUA_TSTRING:
  300. lua_pushvalue(L, 1);
  301. return 1;
  302. case LUA_TBOOLEAN:
  303. lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false"));
  304. return 1;
  305. case LUA_TTABLE:
  306. sprintf(buff, "table: %p", lua_topointer(L, 1));
  307. break;
  308. case LUA_TFUNCTION:
  309. sprintf(buff, "function: %p", lua_topointer(L, 1));
  310. break;
  311. case LUA_TUSERDATA:
  312. case LUA_TLIGHTUSERDATA:
  313. sprintf(buff, "userdata: %p", lua_touserdata(L, 1));
  314. break;
  315. case LUA_TTHREAD:
  316. sprintf(buff, "thread: %p", (void *)lua_tothread(L, 1));
  317. break;
  318. case LUA_TNIL:
  319. lua_pushliteral(L, "nil");
  320. return 1;
  321. }
  322. lua_pushstring(L, buff);
  323. return 1;
  324. }
  325. static int luaB_newproxy (lua_State *L) {
  326. lua_settop(L, 1);
  327. lua_newuserdata(L, 0); /* create proxy */
  328. if (lua_toboolean(L, 1) == 0)
  329. return 1; /* no metatable */
  330. else if (lua_isboolean(L, 1)) {
  331. lua_newtable(L); /* create a new metatable `m' ... */
  332. lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */
  333. lua_pushboolean(L, 1);
  334. lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */
  335. }
  336. else {
  337. int validproxy = 0; /* to check if weaktable[metatable(u)] == true */
  338. if (lua_getmetatable(L, 1)) {
  339. lua_rawget(L, lua_upvalueindex(1));
  340. validproxy = lua_toboolean(L, -1);
  341. lua_pop(L, 1); /* remove value */
  342. }
  343. luaL_arg_check(L, validproxy, 1, "boolean/proxy expected");
  344. lua_getmetatable(L, 1); /* metatable is valid; get it */
  345. }
  346. lua_setmetatable(L, 2);
  347. return 1;
  348. }
  349. /*
  350. ** {======================================================
  351. ** `require' function
  352. ** =======================================================
  353. */
  354. /* name of global that holds table with loaded packages */
  355. #define REQTAB "_LOADED"
  356. /* name of global that holds the search path for packages */
  357. #define LUA_PATH "LUA_PATH"
  358. #ifndef LUA_PATH_SEP
  359. #define LUA_PATH_SEP ';'
  360. #endif
  361. #ifndef LUA_PATH_DEFAULT
  362. #define LUA_PATH_DEFAULT "?;?.lua"
  363. #endif
  364. static const char *getpath (lua_State *L) {
  365. const char *path;
  366. lua_getglobal(L, LUA_PATH); /* try global variable */
  367. path = lua_tostring(L, -1);
  368. lua_pop(L, 1);
  369. if (path) return path;
  370. path = getenv(LUA_PATH); /* else try environment variable */
  371. if (path) return path;
  372. return LUA_PATH_DEFAULT; /* else use default */
  373. }
  374. static const char *pushnextpath (lua_State *L, const char *path) {
  375. const char *l;
  376. if (*path == '\0') return NULL; /* no more pathes */
  377. if (*path == LUA_PATH_SEP) path++; /* skip separator */
  378. l = strchr(path, LUA_PATH_SEP); /* find next separator */
  379. if (l == NULL) l = path+strlen(path);
  380. lua_pushlstring(L, path, l - path); /* directory name */
  381. return l;
  382. }
  383. static void pushcomposename (lua_State *L) {
  384. const char *path = lua_tostring(L, -1);
  385. const char *wild = strchr(path, '?');
  386. if (wild == NULL) return; /* no wild char; path is the file name */
  387. lua_pushlstring(L, path, wild - path);
  388. lua_pushvalue(L, 1); /* package name */
  389. lua_pushstring(L, wild + 1);
  390. lua_concat(L, 3);
  391. }
  392. static int luaB_require (lua_State *L) {
  393. const char *path;
  394. int status = LUA_ERRFILE; /* not found (yet) */
  395. luaL_check_string(L, 1);
  396. lua_settop(L, 1);
  397. lua_pushvalue(L, 1);
  398. lua_setglobal(L, "_REQUIREDNAME");
  399. lua_getglobal(L, REQTAB);
  400. if (!lua_istable(L, 2)) return luaL_error(L, "`" REQTAB "' is not a table");
  401. path = getpath(L);
  402. lua_pushvalue(L, 1); /* check package's name in book-keeping table */
  403. lua_rawget(L, 2);
  404. if (!lua_isnil(L, -1)) /* is it there? */
  405. return 0; /* package is already loaded */
  406. else { /* must load it */
  407. while (status == LUA_ERRFILE) {
  408. lua_settop(L, 3); /* reset stack position */
  409. if ((path = pushnextpath(L, path)) == NULL) break;
  410. pushcomposename(L);
  411. status = luaL_loadfile(L, lua_tostring(L, -1)); /* try to load it */
  412. }
  413. }
  414. switch (status) {
  415. case 0: {
  416. lua_call(L, 0, 0); /* run loaded module */
  417. lua_pushvalue(L, 1);
  418. lua_pushboolean(L, 1);
  419. lua_rawset(L, 2); /* mark it as loaded */
  420. return 0;
  421. }
  422. case LUA_ERRFILE: { /* file not found */
  423. return luaL_error(L, "could not load package `%s' from path `%s'",
  424. lua_tostring(L, 1), getpath(L));
  425. }
  426. default: {
  427. return luaL_error(L, "error loading package\n%s", lua_tostring(L, -1));
  428. }
  429. }
  430. }
  431. /* }====================================================== */
  432. static const luaL_reg base_funcs[] = {
  433. {"error", luaB_error},
  434. {"getmetatable", luaB_getmetatable},
  435. {"setmetatable", luaB_setmetatable},
  436. {"getglobals", luaB_getglobals},
  437. {"setglobals", luaB_setglobals},
  438. {"getmode", luaB_getmode},
  439. {"setmode", luaB_setmode},
  440. {"next", luaB_next},
  441. {"ipairs", luaB_ipairs},
  442. {"pairs", luaB_pairs},
  443. {"print", luaB_print},
  444. {"tonumber", luaB_tonumber},
  445. {"tostring", luaB_tostring},
  446. {"type", luaB_type},
  447. {"assert", luaB_assert},
  448. {"unpack", luaB_unpack},
  449. {"rawequal", luaB_rawequal},
  450. {"rawget", luaB_rawget},
  451. {"rawset", luaB_rawset},
  452. {"pcall", luaB_pcall},
  453. {"xpcall", luaB_xpcall},
  454. {"collectgarbage", luaB_collectgarbage},
  455. {"gcinfo", luaB_gcinfo},
  456. {"loadfile", luaB_loadfile},
  457. {"stringdump", luaB_stringdump},
  458. {"dofile", luaB_dofile},
  459. {"loadstring", luaB_loadstring},
  460. {"require", luaB_require},
  461. {NULL, NULL}
  462. };
  463. /*
  464. ** {======================================================
  465. ** Coroutine library
  466. ** =======================================================
  467. */
  468. static int auxresume (lua_State *L, lua_State *co, int narg) {
  469. int status;
  470. if (!lua_checkstack(co, narg))
  471. luaL_error(L, "too many arguments to resume");
  472. lua_xmove(L, co, narg);
  473. status = lua_resume(co, narg);
  474. if (status == 0) {
  475. int nres = lua_gettop(co);
  476. if (!lua_checkstack(L, narg))
  477. luaL_error(L, "too many results to resume");
  478. lua_xmove(co, L, nres); /* move yielded values */
  479. return nres;
  480. }
  481. else {
  482. lua_xmove(co, L, 1); /* move error message */
  483. return -1; /* error flag */
  484. }
  485. }
  486. static int luaB_coresume (lua_State *L) {
  487. lua_State *co = lua_tothread(L, 1);
  488. int r;
  489. luaL_arg_check(L, co, 1, "coroutine/thread expected");
  490. r = auxresume(L, co, lua_gettop(L) - 1);
  491. if (r < 0) {
  492. lua_pushboolean(L, 0);
  493. lua_insert(L, -2);
  494. return 2; /* return false + error message */
  495. }
  496. else {
  497. lua_pushboolean(L, 1);
  498. lua_insert(L, -(r + 1));
  499. return r + 1; /* return true + `resume' returns */
  500. }
  501. }
  502. static int luaB_auxwrap (lua_State *L) {
  503. lua_State *co = lua_tothread(L, lua_upvalueindex(1));
  504. int r = auxresume(L, co, lua_gettop(L));
  505. if (r < 0) lua_error(L); /* propagate error */
  506. return r;
  507. }
  508. static int luaB_cocreate (lua_State *L) {
  509. lua_State *NL = lua_newthread(L);
  510. luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
  511. "Lua function expected");
  512. lua_pushvalue(L, 1); /* move function to top */
  513. lua_xmove(L, NL, 1); /* move function from L to NL */
  514. return 1;
  515. }
  516. static int luaB_cowrap (lua_State *L) {
  517. luaB_cocreate(L);
  518. lua_pushcclosure(L, luaB_auxwrap, 1);
  519. return 1;
  520. }
  521. static int luaB_yield (lua_State *L) {
  522. return lua_yield(L, lua_gettop(L));
  523. }
  524. static const luaL_reg co_funcs[] = {
  525. {"create", luaB_cocreate},
  526. {"wrap", luaB_cowrap},
  527. {"resume", luaB_coresume},
  528. {"yield", luaB_yield},
  529. {NULL, NULL}
  530. };
  531. /* }====================================================== */
  532. static void base_open (lua_State *L) {
  533. lua_pushliteral(L, "_G");
  534. lua_pushvalue(L, LUA_GLOBALSINDEX);
  535. luaL_openlib(L, base_funcs, 0); /* open lib into global table */
  536. lua_pushliteral(L, "_VERSION");
  537. lua_pushliteral(L, LUA_VERSION);
  538. lua_rawset(L, -3); /* set global _VERSION */
  539. /* `newproxy' needs a weaktable as upvalue */
  540. lua_pushliteral(L, "newproxy");
  541. lua_newtable(L); /* new table `w' */
  542. lua_setmode(L, -1, "k");
  543. lua_pushcclosure(L, luaB_newproxy, 1);
  544. lua_rawset(L, -3); /* set global `newproxy' */
  545. lua_rawset(L, -1); /* set global _G */
  546. }
  547. LUALIB_API int lua_baselibopen (lua_State *L) {
  548. base_open(L);
  549. luaL_opennamedlib(L, LUA_COLIBNAME, co_funcs, 0);
  550. lua_newtable(L);
  551. lua_setglobal(L, REQTAB);
  552. return 0;
  553. }