lbaselib.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. ** $Id: lbaselib.c,v 1.172 2005/03/22 16:04:29 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. #define lbaselib_c
  11. #define LUA_LIB
  12. #include "lua.h"
  13. #include "lauxlib.h"
  14. #include "lualib.h"
  15. /*
  16. ** If your system does not support `stdout', you can just remove this function.
  17. ** If you need, you can define your own `print' function, following this
  18. ** model but changing `fputs' to put the strings at a proper place
  19. ** (a console window or a log file, for instance).
  20. */
  21. static int luaB_print (lua_State *L) {
  22. int n = lua_gettop(L); /* number of arguments */
  23. int i;
  24. lua_getglobal(L, "tostring");
  25. for (i=1; i<=n; i++) {
  26. const char *s;
  27. lua_pushvalue(L, -1); /* function to be called */
  28. lua_pushvalue(L, i); /* value to print */
  29. lua_call(L, 1, 1);
  30. s = lua_tostring(L, -1); /* get result */
  31. if (s == NULL)
  32. return luaL_error(L, "`tostring' must return a string to `print'");
  33. if (i>1) fputs("\t", stdout);
  34. fputs(s, stdout);
  35. lua_pop(L, 1); /* pop result */
  36. }
  37. fputs("\n", stdout);
  38. return 0;
  39. }
  40. static int luaB_tonumber (lua_State *L) {
  41. int base = luaL_optint(L, 2, 10);
  42. if (base == 10) { /* standard conversion */
  43. luaL_checkany(L, 1);
  44. if (lua_isnumber(L, 1)) {
  45. lua_pushnumber(L, lua_tonumber(L, 1));
  46. return 1;
  47. }
  48. }
  49. else {
  50. const char *s1 = luaL_checkstring(L, 1);
  51. char *s2;
  52. unsigned long n;
  53. luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
  54. n = strtoul(s1, &s2, base);
  55. if (s1 != s2) { /* at least one valid digit? */
  56. while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
  57. if (*s2 == '\0') { /* no invalid trailing characters? */
  58. lua_pushnumber(L, (lua_Number)n);
  59. return 1;
  60. }
  61. }
  62. }
  63. lua_pushnil(L); /* else not a number */
  64. return 1;
  65. }
  66. static int luaB_error (lua_State *L) {
  67. int level = luaL_optint(L, 2, 1);
  68. lua_settop(L, 1);
  69. if (lua_isstring(L, 1) && level > 0) { /* 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_getmetatable (lua_State *L) {
  77. luaL_checkany(L, 1);
  78. if (!lua_getmetatable(L, 1)) {
  79. lua_pushnil(L);
  80. return 1; /* no metatable */
  81. }
  82. luaL_getmetafield(L, 1, "__metatable");
  83. return 1; /* returns either __metatable field (if present) or metatable */
  84. }
  85. static int luaB_setmetatable (lua_State *L) {
  86. int t = lua_type(L, 2);
  87. luaL_checktype(L, 1, LUA_TTABLE);
  88. luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
  89. "nil or table expected");
  90. if (luaL_getmetafield(L, 1, "__metatable"))
  91. luaL_error(L, "cannot change a protected metatable");
  92. lua_settop(L, 2);
  93. lua_setmetatable(L, 1);
  94. return 1;
  95. }
  96. static void getfunc (lua_State *L) {
  97. if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
  98. else {
  99. lua_Debug ar;
  100. int level = luaL_optint(L, 1, 1);
  101. luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
  102. if (lua_getstack(L, level, &ar) == 0)
  103. luaL_argerror(L, 1, "invalid level");
  104. lua_getinfo(L, "f", &ar);
  105. if (lua_isnil(L, -1))
  106. luaL_error(L, "no function environment for tail call at level %d",
  107. level);
  108. }
  109. }
  110. static int luaB_getfenv (lua_State *L) {
  111. getfunc(L);
  112. if (lua_iscfunction(L, -1)) /* is a C function? */
  113. lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */
  114. else
  115. lua_getfenv(L, -1);
  116. return 1;
  117. }
  118. static int luaB_setfenv (lua_State *L) {
  119. luaL_checktype(L, 2, LUA_TTABLE);
  120. getfunc(L);
  121. lua_pushvalue(L, 2);
  122. if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
  123. lua_replace(L, LUA_GLOBALSINDEX);
  124. return 0;
  125. }
  126. else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)
  127. luaL_error(L, "`setfenv' cannot change environment of given object");
  128. return 1;
  129. }
  130. static int luaB_rawequal (lua_State *L) {
  131. luaL_checkany(L, 1);
  132. luaL_checkany(L, 2);
  133. lua_pushboolean(L, lua_rawequal(L, 1, 2));
  134. return 1;
  135. }
  136. static int luaB_rawget (lua_State *L) {
  137. luaL_checktype(L, 1, LUA_TTABLE);
  138. luaL_checkany(L, 2);
  139. lua_settop(L, 2);
  140. lua_rawget(L, 1);
  141. return 1;
  142. }
  143. static int luaB_rawset (lua_State *L) {
  144. luaL_checktype(L, 1, LUA_TTABLE);
  145. luaL_checkany(L, 2);
  146. luaL_checkany(L, 3);
  147. lua_settop(L, 3);
  148. lua_rawset(L, 1);
  149. return 1;
  150. }
  151. static int luaB_gcinfo (lua_State *L) {
  152. lua_pushinteger(L, lua_getgccount(L));
  153. return 1;
  154. }
  155. static int luaB_collectgarbage (lua_State *L) {
  156. static const char *const opts[] = {"stop", "restart", "collect",
  157. "count", "step", "setpause", "setstepmul", NULL};
  158. static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
  159. LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL};
  160. int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
  161. int ex = luaL_optinteger(L, 2, 0);
  162. luaL_argcheck(L, o >= 0, 1, "invalid option");
  163. lua_pushinteger(L, lua_gc(L, optsnum[o], ex));
  164. return 1;
  165. }
  166. static int luaB_type (lua_State *L) {
  167. luaL_checkany(L, 1);
  168. lua_pushstring(L, luaL_typename(L, 1));
  169. return 1;
  170. }
  171. static int luaB_next (lua_State *L) {
  172. luaL_checktype(L, 1, LUA_TTABLE);
  173. lua_settop(L, 2); /* create a 2nd argument if there isn't one */
  174. if (lua_next(L, 1))
  175. return 2;
  176. else {
  177. lua_pushnil(L);
  178. return 1;
  179. }
  180. }
  181. static int luaB_pairs (lua_State *L) {
  182. luaL_checktype(L, 1, LUA_TTABLE);
  183. lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
  184. lua_pushvalue(L, 1); /* state, */
  185. lua_pushnil(L); /* and initial value */
  186. return 3;
  187. }
  188. static int ipairsaux (lua_State *L) {
  189. int i = luaL_checkint(L, 2);
  190. luaL_checktype(L, 1, LUA_TTABLE);
  191. i++; /* next value */
  192. lua_pushinteger(L, i);
  193. lua_rawgeti(L, 1, i);
  194. return (lua_isnil(L, -1)) ? 0 : 2;
  195. }
  196. static int luaB_ipairs (lua_State *L) {
  197. luaL_checktype(L, 1, LUA_TTABLE);
  198. lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
  199. lua_pushvalue(L, 1); /* state, */
  200. lua_pushinteger(L, 0); /* and initial value */
  201. return 3;
  202. }
  203. static int load_aux (lua_State *L, int status) {
  204. if (status == 0) /* OK? */
  205. return 1;
  206. else {
  207. lua_pushnil(L);
  208. lua_insert(L, -2); /* put before error message */
  209. return 2; /* return nil plus error message */
  210. }
  211. }
  212. static int luaB_loadstring (lua_State *L) {
  213. size_t l;
  214. const char *s = luaL_checklstring(L, 1, &l);
  215. const char *chunkname = luaL_optstring(L, 2, s);
  216. return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));
  217. }
  218. static int luaB_loadfile (lua_State *L) {
  219. const char *fname = luaL_optstring(L, 1, NULL);
  220. const char *path = luaL_optstring(L, 2, NULL);
  221. int status;
  222. if (path == NULL)
  223. status = luaL_loadfile(L, fname);
  224. else {
  225. fname = luaL_searchpath(L, fname, path);
  226. status = (fname) ? luaL_loadfile(L, fname) : 1;
  227. }
  228. return load_aux(L, status);
  229. }
  230. /*
  231. ** Reader for generic `load' function: `lua_load' uses the
  232. ** stack for internal stuff, so the reader cannot change the
  233. ** stack top. Instead, it keeps its resulting string in a
  234. ** reserved slot inside the stack.
  235. */
  236. static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
  237. (void)ud; /* to avoid warnings */
  238. luaL_checkstack(L, 2, "too many nested functions");
  239. lua_pushvalue(L, 1); /* get function */
  240. lua_call(L, 0, 1); /* call it */
  241. if (lua_isnil(L, -1)) {
  242. *size = 0;
  243. return NULL;
  244. }
  245. else if (lua_isstring(L, -1)) {
  246. const char *res;
  247. lua_replace(L, 3); /* save string in a reserved stack slot */
  248. res = lua_tostring(L, 3);
  249. *size = lua_strlen(L, 3);
  250. return res;
  251. }
  252. else luaL_error(L, "reader function must return a string");
  253. return NULL; /* to avoid warnings */
  254. }
  255. static int luaB_load (lua_State *L) {
  256. int status;
  257. const char *cname = luaL_optstring(L, 2, "=(load)");
  258. luaL_checktype(L, 1, LUA_TFUNCTION);
  259. lua_settop(L, 3); /* function, eventual name, plus one reserved slot */
  260. status = lua_load(L, generic_reader, NULL, cname);
  261. return load_aux(L, status);
  262. }
  263. static int luaB_dofile (lua_State *L) {
  264. const char *fname = luaL_optstring(L, 1, NULL);
  265. int n = lua_gettop(L);
  266. if (luaL_loadfile(L, fname) != 0) lua_error(L);
  267. lua_call(L, 0, LUA_MULTRET);
  268. return lua_gettop(L) - n;
  269. }
  270. static int luaB_assert (lua_State *L) {
  271. luaL_checkany(L, 1);
  272. if (!lua_toboolean(L, 1))
  273. return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
  274. return lua_gettop(L);
  275. }
  276. static int luaB_getn (lua_State *L) {
  277. luaL_checktype(L, 1, LUA_TTABLE);
  278. lua_pushinteger(L, lua_objsize(L, 1));
  279. return 1;
  280. }
  281. static int luaB_unpack (lua_State *L) {
  282. int i = luaL_optint(L, 2, 1);
  283. int e = luaL_optint(L, 3, -1);
  284. int n;
  285. luaL_checktype(L, 1, LUA_TTABLE);
  286. if (e == -1)
  287. e = luaL_getn(L, 1);
  288. n = e - i + 1; /* number of elements */
  289. if (n <= 0) return 0; /* empty range */
  290. luaL_checkstack(L, n, "table too big to unpack");
  291. for (; i<=e; i++) /* push arg[i...e] */
  292. lua_rawgeti(L, 1, i);
  293. return n;
  294. }
  295. static int luaB_select (lua_State *L) {
  296. int n = lua_gettop(L);
  297. if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
  298. lua_pushinteger(L, n-1);
  299. return 1;
  300. }
  301. else {
  302. int i = luaL_checkint(L, 1);
  303. if (i <= 0) i = 1;
  304. else if (i >= n) i = n;
  305. return n - i;
  306. }
  307. }
  308. static int luaB_pcall (lua_State *L) {
  309. int status;
  310. luaL_checkany(L, 1);
  311. status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
  312. lua_pushboolean(L, (status == 0));
  313. lua_insert(L, 1);
  314. return lua_gettop(L); /* return status + all results */
  315. }
  316. static int luaB_xpcall (lua_State *L) {
  317. int status;
  318. luaL_checkany(L, 2);
  319. lua_settop(L, 2);
  320. lua_insert(L, 1); /* put error function under function to be called */
  321. status = lua_pcall(L, 0, LUA_MULTRET, 1);
  322. lua_pushboolean(L, (status == 0));
  323. lua_replace(L, 1);
  324. return lua_gettop(L); /* return status + all results */
  325. }
  326. static int luaB_tostring (lua_State *L) {
  327. luaL_checkany(L, 1);
  328. if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
  329. return 1; /* use its value */
  330. switch (lua_type(L, 1)) {
  331. case LUA_TNUMBER:
  332. lua_pushstring(L, lua_tostring(L, 1));
  333. break;
  334. case LUA_TSTRING:
  335. lua_pushvalue(L, 1);
  336. break;
  337. case LUA_TBOOLEAN:
  338. lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false"));
  339. break;
  340. case LUA_TNIL:
  341. lua_pushliteral(L, "nil");
  342. break;
  343. default:
  344. lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1));
  345. break;
  346. }
  347. return 1;
  348. }
  349. static int luaB_newproxy (lua_State *L) {
  350. lua_settop(L, 1);
  351. lua_newuserdata(L, 0); /* create proxy */
  352. if (lua_toboolean(L, 1) == 0)
  353. return 1; /* no metatable */
  354. else if (lua_isboolean(L, 1)) {
  355. lua_newtable(L); /* create a new metatable `m' ... */
  356. lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */
  357. lua_pushboolean(L, 1);
  358. lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */
  359. }
  360. else {
  361. int validproxy = 0; /* to check if weaktable[metatable(u)] == true */
  362. if (lua_getmetatable(L, 1)) {
  363. lua_rawget(L, lua_upvalueindex(1));
  364. validproxy = lua_toboolean(L, -1);
  365. lua_pop(L, 1); /* remove value */
  366. }
  367. luaL_argcheck(L, validproxy, 1, "boolean or proxy expected");
  368. lua_getmetatable(L, 1); /* metatable is valid; get it */
  369. }
  370. lua_setmetatable(L, 2);
  371. return 1;
  372. }
  373. static const luaL_reg base_funcs[] = {
  374. {"error", luaB_error},
  375. {"getmetatable", luaB_getmetatable},
  376. {"setmetatable", luaB_setmetatable},
  377. {"getfenv", luaB_getfenv},
  378. {"setfenv", luaB_setfenv},
  379. {"next", luaB_next},
  380. {"print", luaB_print},
  381. {"tonumber", luaB_tonumber},
  382. {"tostring", luaB_tostring},
  383. {"type", luaB_type},
  384. {"assert", luaB_assert},
  385. {"getn", luaB_getn},
  386. {"unpack", luaB_unpack},
  387. {"select", luaB_select},
  388. {"rawequal", luaB_rawequal},
  389. {"rawget", luaB_rawget},
  390. {"rawset", luaB_rawset},
  391. {"pcall", luaB_pcall},
  392. {"xpcall", luaB_xpcall},
  393. {"collectgarbage", luaB_collectgarbage},
  394. {"gcinfo", luaB_gcinfo},
  395. {"loadfile", luaB_loadfile},
  396. {"dofile", luaB_dofile},
  397. {"loadstring", luaB_loadstring},
  398. {"load", luaB_load},
  399. {NULL, NULL}
  400. };
  401. /*
  402. ** {======================================================
  403. ** Coroutine library
  404. ** =======================================================
  405. */
  406. static int auxresume (lua_State *L, lua_State *co, int narg) {
  407. int status;
  408. if (!lua_checkstack(co, narg))
  409. luaL_error(L, "too many arguments to resume");
  410. if (lua_status(co) == 0 && lua_gettop(co) == 0) {
  411. lua_pushliteral(L, "cannot resume dead coroutine");
  412. return -1; /* error flag */
  413. }
  414. lua_xmove(L, co, narg);
  415. status = lua_resume(co, narg);
  416. if (status == 0 || status == LUA_YIELD) {
  417. int nres = lua_gettop(co);
  418. if (!lua_checkstack(L, nres))
  419. luaL_error(L, "too many results to resume");
  420. lua_xmove(co, L, nres); /* move yielded values */
  421. return nres;
  422. }
  423. else {
  424. lua_xmove(co, L, 1); /* move error message */
  425. return -1; /* error flag */
  426. }
  427. }
  428. static int luaB_coresume (lua_State *L) {
  429. lua_State *co = lua_tothread(L, 1);
  430. int r;
  431. luaL_argcheck(L, co, 1, "coroutine expected");
  432. r = auxresume(L, co, lua_gettop(L) - 1);
  433. if (r < 0) {
  434. lua_pushboolean(L, 0);
  435. lua_insert(L, -2);
  436. return 2; /* return false + error message */
  437. }
  438. else {
  439. lua_pushboolean(L, 1);
  440. lua_insert(L, -(r + 1));
  441. return r + 1; /* return true + `resume' returns */
  442. }
  443. }
  444. static int luaB_auxwrap (lua_State *L) {
  445. lua_State *co = lua_tothread(L, lua_upvalueindex(1));
  446. int r = auxresume(L, co, lua_gettop(L));
  447. if (r < 0) {
  448. if (lua_isstring(L, -1)) { /* error object is a string? */
  449. luaL_where(L, 1); /* add extra info */
  450. lua_insert(L, -2);
  451. lua_concat(L, 2);
  452. }
  453. lua_error(L); /* propagate error */
  454. }
  455. return r;
  456. }
  457. static int luaB_cocreate (lua_State *L) {
  458. lua_State *NL = lua_newthread(L);
  459. luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
  460. "Lua function expected");
  461. lua_pushvalue(L, 1); /* move function to top */
  462. lua_xmove(L, NL, 1); /* move function from L to NL */
  463. return 1;
  464. }
  465. static int luaB_cowrap (lua_State *L) {
  466. luaB_cocreate(L);
  467. lua_pushcclosure(L, luaB_auxwrap, 1);
  468. return 1;
  469. }
  470. static int luaB_yield (lua_State *L) {
  471. return lua_yield(L, lua_gettop(L));
  472. }
  473. static int luaB_costatus (lua_State *L) {
  474. lua_State *co = lua_tothread(L, 1);
  475. luaL_argcheck(L, co, 1, "coroutine expected");
  476. if (L == co) lua_pushliteral(L, "running");
  477. else {
  478. switch (lua_status(co)) {
  479. case LUA_YIELD:
  480. lua_pushliteral(L, "suspended");
  481. break;
  482. case 0: {
  483. lua_Debug ar;
  484. if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
  485. lua_pushliteral(L, "normal"); /* it is running */
  486. else if (lua_gettop(co) == 0)
  487. lua_pushliteral(L, "dead");
  488. else
  489. lua_pushliteral(L, "suspended"); /* initial state */
  490. break;
  491. }
  492. default: /* some error occured */
  493. lua_pushliteral(L, "dead");
  494. break;
  495. }
  496. }
  497. return 1;
  498. }
  499. static int luaB_corunning (lua_State *L) {
  500. if (lua_pushthread(L))
  501. return 0; /* main thread is not a coroutine */
  502. else
  503. return 1;
  504. }
  505. static const luaL_reg co_funcs[] = {
  506. {"create", luaB_cocreate},
  507. {"wrap", luaB_cowrap},
  508. {"resume", luaB_coresume},
  509. {"yield", luaB_yield},
  510. {"status", luaB_costatus},
  511. {"running", luaB_corunning},
  512. {NULL, NULL}
  513. };
  514. /* }====================================================== */
  515. static void auxopen (lua_State *L, const char *name,
  516. lua_CFunction f, lua_CFunction u) {
  517. lua_pushcfunction(L, u);
  518. lua_pushcclosure(L, f, 1);
  519. lua_setfield(L, -2, name);
  520. }
  521. static void base_open (lua_State *L) {
  522. lua_pushvalue(L, LUA_GLOBALSINDEX);
  523. luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */
  524. lua_pushliteral(L, LUA_VERSION);
  525. lua_setglobal(L, "_VERSION"); /* set global _VERSION */
  526. /* `ipairs' and `pairs' need auxiliary functions as upvalues */
  527. auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
  528. auxopen(L, "pairs", luaB_pairs, luaB_next);
  529. /* `newproxy' needs a weaktable as upvalue */
  530. lua_newtable(L); /* new table `w' */
  531. lua_pushvalue(L, -1); /* `w' will be its own metatable */
  532. lua_setmetatable(L, -2);
  533. lua_pushliteral(L, "kv");
  534. lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
  535. lua_pushcclosure(L, luaB_newproxy, 1);
  536. lua_setglobal(L, "newproxy"); /* set global `newproxy' */
  537. /* create register._LOADED to track loaded modules */
  538. lua_newtable(L);
  539. lua_setfield(L, LUA_REGISTRYINDEX, "_LOADED");
  540. /* set global _G */
  541. lua_pushvalue(L, LUA_GLOBALSINDEX);
  542. lua_setglobal(L, "_G");
  543. }
  544. LUALIB_API int luaopen_base (lua_State *L) {
  545. base_open(L);
  546. luaL_openlib(L, LUA_COLIBNAME, co_funcs, 0);
  547. return 2;
  548. }