lbaselib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. ** $Id: lbaselib.c,v 1.9 2000/10/05 12:14:08 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 "luadebug.h"
  13. #include "lualib.h"
  14. /*
  15. ** If your system does not support `stderr', redefine this function, or
  16. ** redefine _ERRORMESSAGE so that it won't need _ALERT.
  17. */
  18. static int luaB__ALERT (lua_State *L) {
  19. fputs(luaL_check_string(L, 1), stderr);
  20. return 0;
  21. }
  22. /*
  23. ** Basic implementation of _ERRORMESSAGE.
  24. ** The library `liolib' redefines _ERRORMESSAGE for better error information.
  25. */
  26. static int luaB__ERRORMESSAGE (lua_State *L) {
  27. luaL_checktype(L, 1, LUA_TSTRING);
  28. lua_getglobal(L, LUA_ALERT);
  29. if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
  30. lua_Debug ar;
  31. lua_pushstring(L, "error: ");
  32. lua_pushvalue(L, 1);
  33. if (lua_getstack(L, 1, &ar)) {
  34. lua_getinfo(L, "Sl", &ar);
  35. if (ar.source && ar.currentline > 0) {
  36. char buff[100];
  37. sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline);
  38. lua_pushstring(L, buff);
  39. lua_concat(L, 2);
  40. }
  41. }
  42. lua_pushstring(L, "\n");
  43. lua_concat(L, 3);
  44. lua_rawcall(L, 1, 0);
  45. }
  46. return 0;
  47. }
  48. /*
  49. ** If your system does not support `stdout', you can just remove this function.
  50. ** If you need, you can define your own `print' function, following this
  51. ** model but changing `fputs' to put the strings at a proper place
  52. ** (a console window or a log file, for instance).
  53. */
  54. static int luaB_print (lua_State *L) {
  55. int n = lua_gettop(L); /* number of arguments */
  56. int i;
  57. lua_getglobal(L, "tostring");
  58. for (i=1; i<=n; i++) {
  59. const char *s;
  60. lua_pushvalue(L, -1); /* function to be called */
  61. lua_pushvalue(L, i); /* value to print */
  62. lua_rawcall(L, 1, 1);
  63. s = lua_tostring(L, -1); /* get result */
  64. if (s == NULL)
  65. lua_error(L, "`tostring' must return a string to `print'");
  66. if (i>1) fputs("\t", stdout);
  67. fputs(s, stdout);
  68. lua_pop(L, 1); /* pop result */
  69. }
  70. fputs("\n", stdout);
  71. return 0;
  72. }
  73. static int luaB_tonumber (lua_State *L) {
  74. int base = luaL_opt_int(L, 2, 10);
  75. if (base == 10) { /* standard conversion */
  76. luaL_checkany(L, 1);
  77. if (lua_isnumber(L, 1)) {
  78. lua_pushnumber(L, lua_tonumber(L, 1));
  79. return 1;
  80. }
  81. }
  82. else {
  83. const char *s1 = luaL_check_string(L, 1);
  84. char *s2;
  85. unsigned long n;
  86. luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range");
  87. n = strtoul(s1, &s2, base);
  88. if (s1 != s2) { /* at least one valid digit? */
  89. while (isspace((unsigned char)*s2)) s2++; /* skip trailing spaces */
  90. if (*s2 == '\0') { /* no invalid trailing characters? */
  91. lua_pushnumber(L, n);
  92. return 1;
  93. }
  94. }
  95. }
  96. lua_pushnil(L); /* else not a number */
  97. return 1;
  98. }
  99. static int luaB_error (lua_State *L) {
  100. lua_error(L, luaL_opt_string(L, 1, NULL));
  101. return 0; /* to avoid warnings */
  102. }
  103. static int luaB_setglobal (lua_State *L) {
  104. luaL_checkany(L, 2);
  105. lua_setglobal(L, luaL_check_string(L, 1));
  106. return 0;
  107. }
  108. static int luaB_getglobal (lua_State *L) {
  109. lua_getglobal(L, luaL_check_string(L, 1));
  110. return 1;
  111. }
  112. static int luaB_tag (lua_State *L) {
  113. luaL_checkany(L, 1);
  114. lua_pushnumber(L, lua_tag(L, 1));
  115. return 1;
  116. }
  117. static int luaB_settag (lua_State *L) {
  118. luaL_checktype(L, 1, LUA_TTABLE);
  119. lua_pushvalue(L, 1); /* push table */
  120. lua_settag(L, luaL_check_int(L, 2));
  121. lua_pop(L, 1); /* remove second argument */
  122. return 1; /* return first argument */
  123. }
  124. static int luaB_newtag (lua_State *L) {
  125. lua_pushnumber(L, lua_newtag(L));
  126. return 1;
  127. }
  128. static int luaB_copytagmethods (lua_State *L) {
  129. lua_pushnumber(L, lua_copytagmethods(L, luaL_check_int(L, 1),
  130. luaL_check_int(L, 2)));
  131. return 1;
  132. }
  133. static int luaB_globals (lua_State *L) {
  134. lua_getglobals(L); /* value to be returned */
  135. if (!lua_isnull(L, 1)) {
  136. luaL_checktype(L, 1, LUA_TTABLE);
  137. lua_pushvalue(L, 1); /* new table of globals */
  138. lua_setglobals(L);
  139. }
  140. return 1;
  141. }
  142. static int luaB_rawget (lua_State *L) {
  143. luaL_checktype(L, 1, LUA_TTABLE);
  144. luaL_checkany(L, 2);
  145. lua_rawget(L, -2);
  146. return 1;
  147. }
  148. static int luaB_rawset (lua_State *L) {
  149. luaL_checktype(L, 1, LUA_TTABLE);
  150. luaL_checkany(L, 2);
  151. luaL_checkany(L, 3);
  152. lua_rawset(L, -3);
  153. return 1;
  154. }
  155. static int luaB_settagmethod (lua_State *L) {
  156. int tag = (int)luaL_check_int(L, 1);
  157. const char *event = luaL_check_string(L, 2);
  158. luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3,
  159. "function or nil expected");
  160. if (strcmp(event, "gc") == 0)
  161. lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua");
  162. lua_settagmethod(L, tag, event);
  163. return 1;
  164. }
  165. static int luaB_gettagmethod (lua_State *L) {
  166. lua_gettagmethod(L, luaL_check_int(L, 1), luaL_check_string(L, 2));
  167. return 1;
  168. }
  169. static int luaB_gcinfo (lua_State *L) {
  170. lua_pushnumber(L, lua_getgccount(L));
  171. lua_pushnumber(L, lua_getgcthreshold(L));
  172. return 2;
  173. }
  174. static int luaB_collectgarbage (lua_State *L) {
  175. lua_setgcthreshold(L, luaL_opt_int(L, 1, 0));
  176. return 0;
  177. }
  178. static int luaB_type (lua_State *L) {
  179. luaL_checkany(L, 1);
  180. lua_pushstring(L, lua_typename(L, lua_type(L, 1)));
  181. return 1;
  182. }
  183. static int luaB_next (lua_State *L) {
  184. luaL_checktype(L, 1, LUA_TTABLE);
  185. lua_settop(L, 2); /* create a 2nd argument if there isn't one */
  186. if (lua_next(L, 1))
  187. return 2;
  188. else {
  189. lua_pushnil(L);
  190. return 1;
  191. }
  192. }
  193. static int passresults (lua_State *L, int status, int oldtop) {
  194. static const char *const errornames[] =
  195. {"ok", "run-time error", "file error", "syntax error", "memory error"};
  196. if (status == 0) {
  197. int nresults = lua_gettop(L) - oldtop;
  198. if (nresults > 0)
  199. return nresults; /* results are already on the stack */
  200. else {
  201. lua_pushuserdata(L, NULL); /* at least one result to signal no errors */
  202. return 1;
  203. }
  204. }
  205. else { /* error */
  206. lua_pushnil(L);
  207. lua_pushstring(L, errornames[status]); /* error code */
  208. return 2;
  209. }
  210. }
  211. static int luaB_dostring (lua_State *L) {
  212. int oldtop = lua_gettop(L);
  213. size_t l;
  214. const char *s = luaL_check_lstr(L, 1, &l);
  215. if (*s == '\27') /* binary files start with ESC... */
  216. lua_error(L, "`dostring' cannot run pre-compiled code");
  217. return passresults(L, lua_dobuffer(L, s, l, luaL_opt_string(L, 2, s)), oldtop);
  218. }
  219. static int luaB_dofile (lua_State *L) {
  220. int oldtop = lua_gettop(L);
  221. const char *fname = luaL_opt_string(L, 1, NULL);
  222. return passresults(L, lua_dofile(L, fname), oldtop);
  223. }
  224. static int luaB_call (lua_State *L) {
  225. int oldtop;
  226. const char *options = luaL_opt_string(L, 3, "");
  227. int err = 0; /* index of old error method */
  228. int i, status;
  229. int n;
  230. luaL_checktype(L, 2, LUA_TTABLE);
  231. n = lua_getn(L, 2);
  232. if (!lua_isnull(L, 4)) { /* set new error method */
  233. lua_getglobal(L, LUA_ERRORMESSAGE);
  234. err = lua_gettop(L); /* get index */
  235. lua_pushvalue(L, 4);
  236. lua_setglobal(L, LUA_ERRORMESSAGE);
  237. }
  238. oldtop = lua_gettop(L); /* top before function-call preparation */
  239. /* push function */
  240. lua_pushvalue(L, 1);
  241. luaL_checkstack(L, n, "too many arguments");
  242. for (i=0; i<n; i++) /* push arg[1...n] */
  243. lua_rawgeti(L, 2, i+1);
  244. status = lua_call(L, n, LUA_MULTRET);
  245. if (err != 0) { /* restore old error method */
  246. lua_pushvalue(L, err);
  247. lua_setglobal(L, LUA_ERRORMESSAGE);
  248. }
  249. if (status != 0) { /* error in call? */
  250. if (strchr(options, 'x'))
  251. lua_pushnil(L); /* return nil to signal the error */
  252. else
  253. lua_error(L, NULL); /* propagate error without additional messages */
  254. return 1;
  255. }
  256. if (strchr(options, 'p')) /* pack results? */
  257. lua_error(L, "deprecated option `p' in `call'");
  258. return lua_gettop(L) - oldtop; /* results are already on the stack */
  259. }
  260. static int luaB_tostring (lua_State *L) {
  261. char buff[64];
  262. switch (lua_type(L, 1)) {
  263. case LUA_TNUMBER:
  264. lua_pushstring(L, lua_tostring(L, 1));
  265. return 1;
  266. case LUA_TSTRING:
  267. lua_pushvalue(L, 1);
  268. return 1;
  269. case LUA_TTABLE:
  270. sprintf(buff, "table: %p", lua_topointer(L, 1));
  271. break;
  272. case LUA_TFUNCTION:
  273. sprintf(buff, "function: %p", lua_topointer(L, 1));
  274. break;
  275. case LUA_TUSERDATA:
  276. sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
  277. break;
  278. case LUA_TNIL:
  279. lua_pushstring(L, "nil");
  280. return 1;
  281. default:
  282. luaL_argerror(L, 1, "value expected");
  283. }
  284. lua_pushstring(L, buff);
  285. return 1;
  286. }
  287. static int luaB_foreachi (lua_State *L) {
  288. int n, i;
  289. luaL_checktype(L, 1, LUA_TTABLE);
  290. luaL_checktype(L, 2, LUA_TFUNCTION);
  291. n = lua_getn(L, 1);
  292. for (i=1; i<=n; i++) {
  293. lua_pushvalue(L, 2); /* function */
  294. lua_pushnumber(L, i); /* 1st argument */
  295. lua_rawgeti(L, 1, i); /* 2nd argument */
  296. lua_rawcall(L, 2, 1);
  297. if (!lua_isnil(L, -1))
  298. return 1;
  299. lua_pop(L, 1); /* remove nil result */
  300. }
  301. return 0;
  302. }
  303. static int luaB_foreach (lua_State *L) {
  304. luaL_checktype(L, 1, LUA_TTABLE);
  305. luaL_checktype(L, 2, LUA_TFUNCTION);
  306. lua_pushnil(L); /* first index */
  307. for (;;) {
  308. if (lua_next(L, 1) == 0)
  309. return 0;
  310. lua_pushvalue(L, 2); /* function */
  311. lua_pushvalue(L, -3); /* key */
  312. lua_pushvalue(L, -3); /* value */
  313. lua_rawcall(L, 2, 1);
  314. if (!lua_isnil(L, -1))
  315. return 1;
  316. lua_pop(L, 2); /* remove value and result */
  317. }
  318. }
  319. static int luaB_assert (lua_State *L) {
  320. luaL_checkany(L, 1);
  321. if (lua_isnil(L, 1))
  322. luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
  323. return 0;
  324. }
  325. static int luaB_getn (lua_State *L) {
  326. luaL_checktype(L, 1, LUA_TTABLE);
  327. lua_pushnumber(L, lua_getn(L, 1));
  328. return 1;
  329. }
  330. static int luaB_tinsert (lua_State *L) {
  331. int v = lua_gettop(L); /* last argument: to be inserted */
  332. int n, pos;
  333. luaL_checktype(L, 1, LUA_TTABLE);
  334. n = lua_getn(L, 1);
  335. if (v == 2) /* called with only 2 arguments */
  336. pos = n+1;
  337. else
  338. pos = luaL_check_int(L, 2); /* 2nd argument is the position */
  339. lua_pushstring(L, "n");
  340. lua_pushnumber(L, n+1);
  341. lua_rawset(L, 1); /* t.n = n+1 */
  342. for (; n>=pos; n--) {
  343. lua_rawgeti(L, 1, n);
  344. lua_rawseti(L, 1, n+1); /* t[n+1] = t[n] */
  345. }
  346. lua_pushvalue(L, v);
  347. lua_rawseti(L, 1, pos); /* t[pos] = v */
  348. return 0;
  349. }
  350. static int luaB_tremove (lua_State *L) {
  351. int pos, n;
  352. luaL_checktype(L, 1, LUA_TTABLE);
  353. n = lua_getn(L, 1);
  354. pos = luaL_opt_int(L, 2, n);
  355. if (n <= 0) return 0; /* table is "empty" */
  356. lua_rawgeti(L, 1, pos); /* result = t[pos] */
  357. for ( ;pos<n; pos++) {
  358. lua_rawgeti(L, 1, pos+1);
  359. lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */
  360. }
  361. lua_pushstring(L, "n");
  362. lua_pushnumber(L, n-1);
  363. lua_rawset(L, 1); /* t.n = n-1 */
  364. lua_pushnil(L);
  365. lua_rawseti(L, 1, n); /* t[n] = nil */
  366. return 1;
  367. }
  368. /*
  369. ** {======================================================
  370. ** Quicksort
  371. ** (based on `Algorithms in MODULA-3', Robert Sedgewick;
  372. ** Addison-Wesley, 1993.)
  373. */
  374. static void set2 (lua_State *L, int i, int j) {
  375. lua_rawseti(L, 1, i);
  376. lua_rawseti(L, 1, j);
  377. }
  378. static int sort_comp (lua_State *L, int a, int b) {
  379. /* WARNING: the caller (auxsort) must ensure stack space */
  380. if (!lua_isnil(L, 2)) { /* function? */
  381. int res;
  382. lua_pushvalue(L, 2);
  383. lua_pushvalue(L, a-1); /* -1 to compensate function */
  384. lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
  385. lua_rawcall(L, 2, 1);
  386. res = !lua_isnil(L, -1);
  387. lua_pop(L, 1);
  388. return res;
  389. }
  390. else /* a < b? */
  391. return lua_lessthan(L, a, b);
  392. }
  393. static void auxsort (lua_State *L, int l, int u) {
  394. while (l < u) { /* for tail recursion */
  395. int i, j;
  396. /* sort elements a[l], a[(l+u)/2] and a[u] */
  397. lua_rawgeti(L, 1, l);
  398. lua_rawgeti(L, 1, u);
  399. if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
  400. set2(L, l, u); /* swap a[l] - a[u] */
  401. else
  402. lua_pop(L, 2);
  403. if (u-l == 1) break; /* only 2 elements */
  404. i = (l+u)/2;
  405. lua_rawgeti(L, 1, i);
  406. lua_rawgeti(L, 1, l);
  407. if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */
  408. set2(L, i, l);
  409. else {
  410. lua_pop(L, 1); /* remove a[l] */
  411. lua_rawgeti(L, 1, u);
  412. if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */
  413. set2(L, i, u);
  414. else
  415. lua_pop(L, 2);
  416. }
  417. if (u-l == 2) break; /* only 3 elements */
  418. lua_rawgeti(L, 1, i); /* Pivot */
  419. lua_pushvalue(L, -1);
  420. lua_rawgeti(L, 1, u-1);
  421. set2(L, i, u-1);
  422. /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
  423. i = l; j = u-1;
  424. for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
  425. /* repeat ++i until a[i] >= P */
  426. while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
  427. if (i>u) lua_error(L, "invalid order function for sorting");
  428. lua_pop(L, 1); /* remove a[i] */
  429. }
  430. /* repeat --j until a[j] <= P */
  431. while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
  432. if (j<l) lua_error(L, "invalid order function for sorting");
  433. lua_pop(L, 1); /* remove a[j] */
  434. }
  435. if (j<i) {
  436. lua_pop(L, 3); /* pop pivot, a[i], a[j] */
  437. break;
  438. }
  439. set2(L, i, j);
  440. }
  441. lua_rawgeti(L, 1, u-1);
  442. lua_rawgeti(L, 1, i);
  443. set2(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */
  444. /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
  445. /* adjust so that smaller "half" is in [j..i] and larger one in [l..u] */
  446. if (i-l < u-i) {
  447. j=l; i=i-1; l=i+2;
  448. }
  449. else {
  450. j=i+1; i=u; u=j-2;
  451. }
  452. auxsort(L, j, i); /* call recursively the smaller one */
  453. } /* repeat the routine for the larger one */
  454. }
  455. static int luaB_sort (lua_State *L) {
  456. int n;
  457. luaL_checktype(L, 1, LUA_TTABLE);
  458. n = lua_getn(L, 1);
  459. if (!lua_isnull(L, 2)) /* is there a 2nd argument? */
  460. luaL_checktype(L, 2, LUA_TFUNCTION);
  461. lua_settop(L, 2); /* make sure there is two arguments */
  462. auxsort(L, 1, n);
  463. return 0;
  464. }
  465. /* }====================================================== */
  466. /*
  467. ** {======================================================
  468. ** Deprecated functions to manipulate global environment.
  469. ** =======================================================
  470. */
  471. #define num_deprecated 4
  472. static const struct luaL_reg deprecated_names [num_deprecated] = {
  473. {"foreachvar", luaB_foreach},
  474. {"nextvar", luaB_next},
  475. {"rawgetglobal", luaB_rawget},
  476. {"rawsetglobal", luaB_rawset}
  477. };
  478. #ifdef LUA_DEPRECATETFUNCS
  479. /*
  480. ** call corresponding function inserting `globals' as first argument
  481. */
  482. static int deprecated_func (lua_State *L) {
  483. lua_insert(L, 1); /* upvalue is the function to be called */
  484. lua_getglobals(L);
  485. lua_insert(L, 2); /* table of globals is 1o argument */
  486. lua_rawcall(L, lua_gettop(L)-1, LUA_MULTRET);
  487. return lua_gettop(L); /* return all results */
  488. }
  489. static void deprecated_funcs (lua_State *L) {
  490. int i;
  491. for (i=0; i<num_deprecated; i++) {
  492. lua_pushcfunction(L, deprecated_names[i].func);
  493. lua_pushcclosure(L, deprecated_func, 1);
  494. lua_setglobal(L, deprecated_names[i].name);
  495. }
  496. }
  497. #else
  498. /*
  499. ** gives an explicit error in any attempt to call a deprecated function
  500. */
  501. static int deprecated_func (lua_State *L) {
  502. luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1));
  503. return 0; /* to avoid warnings */
  504. }
  505. static void deprecated_funcs (lua_State *L) {
  506. int i;
  507. for (i=0; i<num_deprecated; i++) {
  508. lua_pushstring(L, deprecated_names[i].name);
  509. lua_pushcclosure(L, deprecated_func, 1);
  510. lua_setglobal(L, deprecated_names[i].name);
  511. }
  512. }
  513. #endif
  514. /* }====================================================== */
  515. static const struct luaL_reg base_funcs[] = {
  516. {LUA_ALERT, luaB__ALERT},
  517. {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE},
  518. {"call", luaB_call},
  519. {"collectgarbage", luaB_collectgarbage},
  520. {"copytagmethods", luaB_copytagmethods},
  521. {"dofile", luaB_dofile},
  522. {"dostring", luaB_dostring},
  523. {"error", luaB_error},
  524. {"foreach", luaB_foreach},
  525. {"foreachi", luaB_foreachi},
  526. {"gcinfo", luaB_gcinfo},
  527. {"getglobal", luaB_getglobal},
  528. {"gettagmethod", luaB_gettagmethod},
  529. {"globals", luaB_globals},
  530. {"newtag", luaB_newtag},
  531. {"next", luaB_next},
  532. {"print", luaB_print},
  533. {"rawget", luaB_rawget},
  534. {"rawset", luaB_rawset},
  535. {"rawgettable", luaB_rawget}, /* for compatibility */
  536. {"rawsettable", luaB_rawset}, /* for compatibility */
  537. {"setglobal", luaB_setglobal},
  538. {"settag", luaB_settag},
  539. {"settagmethod", luaB_settagmethod},
  540. {"tag", luaB_tag},
  541. {"tonumber", luaB_tonumber},
  542. {"tostring", luaB_tostring},
  543. {"type", luaB_type},
  544. {"assert", luaB_assert},
  545. {"getn", luaB_getn},
  546. {"sort", luaB_sort},
  547. {"tinsert", luaB_tinsert},
  548. {"tremove", luaB_tremove}
  549. };
  550. void lua_baselibopen (lua_State *L) {
  551. luaL_openl(L, base_funcs);
  552. lua_pushstring(L, LUA_VERSION);
  553. lua_setglobal(L, "_VERSION");
  554. deprecated_funcs(L);
  555. }