lbaselib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. ** $Id: lbaselib.c,v 1.10 2000/10/06 19:13: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. #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",
  196. "memory error", "error in error handling"};
  197. if (status == 0) {
  198. int nresults = lua_gettop(L) - oldtop;
  199. if (nresults > 0)
  200. return nresults; /* results are already on the stack */
  201. else {
  202. lua_pushuserdata(L, NULL); /* at least one result to signal no errors */
  203. return 1;
  204. }
  205. }
  206. else { /* error */
  207. lua_pushnil(L);
  208. lua_pushstring(L, errornames[status]); /* error code */
  209. return 2;
  210. }
  211. }
  212. static int luaB_dostring (lua_State *L) {
  213. int oldtop = lua_gettop(L);
  214. size_t l;
  215. const char *s = luaL_check_lstr(L, 1, &l);
  216. if (*s == '\27') /* binary files start with ESC... */
  217. lua_error(L, "`dostring' cannot run pre-compiled code");
  218. return passresults(L, lua_dobuffer(L, s, l, luaL_opt_string(L, 2, s)), oldtop);
  219. }
  220. static int luaB_dofile (lua_State *L) {
  221. int oldtop = lua_gettop(L);
  222. const char *fname = luaL_opt_string(L, 1, NULL);
  223. return passresults(L, lua_dofile(L, fname), oldtop);
  224. }
  225. static int luaB_call (lua_State *L) {
  226. int oldtop;
  227. const char *options = luaL_opt_string(L, 3, "");
  228. int err = 0; /* index of old error method */
  229. int i, status;
  230. int n;
  231. luaL_checktype(L, 2, LUA_TTABLE);
  232. n = lua_getn(L, 2);
  233. if (!lua_isnull(L, 4)) { /* set new error method */
  234. lua_getglobal(L, LUA_ERRORMESSAGE);
  235. err = lua_gettop(L); /* get index */
  236. lua_pushvalue(L, 4);
  237. lua_setglobal(L, LUA_ERRORMESSAGE);
  238. }
  239. oldtop = lua_gettop(L); /* top before function-call preparation */
  240. /* push function */
  241. lua_pushvalue(L, 1);
  242. luaL_checkstack(L, n, "too many arguments");
  243. for (i=0; i<n; i++) /* push arg[1...n] */
  244. lua_rawgeti(L, 2, i+1);
  245. status = lua_call(L, n, LUA_MULTRET);
  246. if (err != 0) { /* restore old error method */
  247. lua_pushvalue(L, err);
  248. lua_setglobal(L, LUA_ERRORMESSAGE);
  249. }
  250. if (status != 0) { /* error in call? */
  251. if (strchr(options, 'x'))
  252. lua_pushnil(L); /* return nil to signal the error */
  253. else
  254. lua_error(L, NULL); /* propagate error without additional messages */
  255. return 1;
  256. }
  257. if (strchr(options, 'p')) /* pack results? */
  258. lua_error(L, "deprecated option `p' in `call'");
  259. return lua_gettop(L) - oldtop; /* results are already on the stack */
  260. }
  261. static int luaB_tostring (lua_State *L) {
  262. char buff[64];
  263. switch (lua_type(L, 1)) {
  264. case LUA_TNUMBER:
  265. lua_pushstring(L, lua_tostring(L, 1));
  266. return 1;
  267. case LUA_TSTRING:
  268. lua_pushvalue(L, 1);
  269. return 1;
  270. case LUA_TTABLE:
  271. sprintf(buff, "table: %p", lua_topointer(L, 1));
  272. break;
  273. case LUA_TFUNCTION:
  274. sprintf(buff, "function: %p", lua_topointer(L, 1));
  275. break;
  276. case LUA_TUSERDATA:
  277. sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
  278. break;
  279. case LUA_TNIL:
  280. lua_pushstring(L, "nil");
  281. return 1;
  282. default:
  283. luaL_argerror(L, 1, "value expected");
  284. }
  285. lua_pushstring(L, buff);
  286. return 1;
  287. }
  288. static int luaB_foreachi (lua_State *L) {
  289. int n, i;
  290. luaL_checktype(L, 1, LUA_TTABLE);
  291. luaL_checktype(L, 2, LUA_TFUNCTION);
  292. n = lua_getn(L, 1);
  293. for (i=1; i<=n; i++) {
  294. lua_pushvalue(L, 2); /* function */
  295. lua_pushnumber(L, i); /* 1st argument */
  296. lua_rawgeti(L, 1, i); /* 2nd argument */
  297. lua_rawcall(L, 2, 1);
  298. if (!lua_isnil(L, -1))
  299. return 1;
  300. lua_pop(L, 1); /* remove nil result */
  301. }
  302. return 0;
  303. }
  304. static int luaB_foreach (lua_State *L) {
  305. luaL_checktype(L, 1, LUA_TTABLE);
  306. luaL_checktype(L, 2, LUA_TFUNCTION);
  307. lua_pushnil(L); /* first index */
  308. for (;;) {
  309. if (lua_next(L, 1) == 0)
  310. return 0;
  311. lua_pushvalue(L, 2); /* function */
  312. lua_pushvalue(L, -3); /* key */
  313. lua_pushvalue(L, -3); /* value */
  314. lua_rawcall(L, 2, 1);
  315. if (!lua_isnil(L, -1))
  316. return 1;
  317. lua_pop(L, 2); /* remove value and result */
  318. }
  319. }
  320. static int luaB_assert (lua_State *L) {
  321. luaL_checkany(L, 1);
  322. if (lua_isnil(L, 1))
  323. luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
  324. return 0;
  325. }
  326. static int luaB_getn (lua_State *L) {
  327. luaL_checktype(L, 1, LUA_TTABLE);
  328. lua_pushnumber(L, lua_getn(L, 1));
  329. return 1;
  330. }
  331. static int luaB_tinsert (lua_State *L) {
  332. int v = lua_gettop(L); /* last argument: to be inserted */
  333. int n, pos;
  334. luaL_checktype(L, 1, LUA_TTABLE);
  335. n = lua_getn(L, 1);
  336. if (v == 2) /* called with only 2 arguments */
  337. pos = n+1;
  338. else
  339. pos = luaL_check_int(L, 2); /* 2nd argument is the position */
  340. lua_pushstring(L, "n");
  341. lua_pushnumber(L, n+1);
  342. lua_rawset(L, 1); /* t.n = n+1 */
  343. for (; n>=pos; n--) {
  344. lua_rawgeti(L, 1, n);
  345. lua_rawseti(L, 1, n+1); /* t[n+1] = t[n] */
  346. }
  347. lua_pushvalue(L, v);
  348. lua_rawseti(L, 1, pos); /* t[pos] = v */
  349. return 0;
  350. }
  351. static int luaB_tremove (lua_State *L) {
  352. int pos, n;
  353. luaL_checktype(L, 1, LUA_TTABLE);
  354. n = lua_getn(L, 1);
  355. pos = luaL_opt_int(L, 2, n);
  356. if (n <= 0) return 0; /* table is "empty" */
  357. lua_rawgeti(L, 1, pos); /* result = t[pos] */
  358. for ( ;pos<n; pos++) {
  359. lua_rawgeti(L, 1, pos+1);
  360. lua_rawseti(L, 1, pos); /* a[pos] = a[pos+1] */
  361. }
  362. lua_pushstring(L, "n");
  363. lua_pushnumber(L, n-1);
  364. lua_rawset(L, 1); /* t.n = n-1 */
  365. lua_pushnil(L);
  366. lua_rawseti(L, 1, n); /* t[n] = nil */
  367. return 1;
  368. }
  369. /*
  370. ** {======================================================
  371. ** Quicksort
  372. ** (based on `Algorithms in MODULA-3', Robert Sedgewick;
  373. ** Addison-Wesley, 1993.)
  374. */
  375. static void set2 (lua_State *L, int i, int j) {
  376. lua_rawseti(L, 1, i);
  377. lua_rawseti(L, 1, j);
  378. }
  379. static int sort_comp (lua_State *L, int a, int b) {
  380. /* WARNING: the caller (auxsort) must ensure stack space */
  381. if (!lua_isnil(L, 2)) { /* function? */
  382. int res;
  383. lua_pushvalue(L, 2);
  384. lua_pushvalue(L, a-1); /* -1 to compensate function */
  385. lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
  386. lua_rawcall(L, 2, 1);
  387. res = !lua_isnil(L, -1);
  388. lua_pop(L, 1);
  389. return res;
  390. }
  391. else /* a < b? */
  392. return lua_lessthan(L, a, b);
  393. }
  394. static void auxsort (lua_State *L, int l, int u) {
  395. while (l < u) { /* for tail recursion */
  396. int i, j;
  397. /* sort elements a[l], a[(l+u)/2] and a[u] */
  398. lua_rawgeti(L, 1, l);
  399. lua_rawgeti(L, 1, u);
  400. if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
  401. set2(L, l, u); /* swap a[l] - a[u] */
  402. else
  403. lua_pop(L, 2);
  404. if (u-l == 1) break; /* only 2 elements */
  405. i = (l+u)/2;
  406. lua_rawgeti(L, 1, i);
  407. lua_rawgeti(L, 1, l);
  408. if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */
  409. set2(L, i, l);
  410. else {
  411. lua_pop(L, 1); /* remove a[l] */
  412. lua_rawgeti(L, 1, u);
  413. if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */
  414. set2(L, i, u);
  415. else
  416. lua_pop(L, 2);
  417. }
  418. if (u-l == 2) break; /* only 3 elements */
  419. lua_rawgeti(L, 1, i); /* Pivot */
  420. lua_pushvalue(L, -1);
  421. lua_rawgeti(L, 1, u-1);
  422. set2(L, i, u-1);
  423. /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
  424. i = l; j = u-1;
  425. for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
  426. /* repeat ++i until a[i] >= P */
  427. while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
  428. if (i>u) lua_error(L, "invalid order function for sorting");
  429. lua_pop(L, 1); /* remove a[i] */
  430. }
  431. /* repeat --j until a[j] <= P */
  432. while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
  433. if (j<l) lua_error(L, "invalid order function for sorting");
  434. lua_pop(L, 1); /* remove a[j] */
  435. }
  436. if (j<i) {
  437. lua_pop(L, 3); /* pop pivot, a[i], a[j] */
  438. break;
  439. }
  440. set2(L, i, j);
  441. }
  442. lua_rawgeti(L, 1, u-1);
  443. lua_rawgeti(L, 1, i);
  444. set2(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */
  445. /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
  446. /* adjust so that smaller "half" is in [j..i] and larger one in [l..u] */
  447. if (i-l < u-i) {
  448. j=l; i=i-1; l=i+2;
  449. }
  450. else {
  451. j=i+1; i=u; u=j-2;
  452. }
  453. auxsort(L, j, i); /* call recursively the smaller one */
  454. } /* repeat the routine for the larger one */
  455. }
  456. static int luaB_sort (lua_State *L) {
  457. int n;
  458. luaL_checktype(L, 1, LUA_TTABLE);
  459. n = lua_getn(L, 1);
  460. if (!lua_isnull(L, 2)) /* is there a 2nd argument? */
  461. luaL_checktype(L, 2, LUA_TFUNCTION);
  462. lua_settop(L, 2); /* make sure there is two arguments */
  463. auxsort(L, 1, n);
  464. return 0;
  465. }
  466. /* }====================================================== */
  467. /*
  468. ** {======================================================
  469. ** Deprecated functions to manipulate global environment.
  470. ** =======================================================
  471. */
  472. #define num_deprecated 4
  473. static const struct luaL_reg deprecated_names [num_deprecated] = {
  474. {"foreachvar", luaB_foreach},
  475. {"nextvar", luaB_next},
  476. {"rawgetglobal", luaB_rawget},
  477. {"rawsetglobal", luaB_rawset}
  478. };
  479. #ifdef LUA_DEPRECATETFUNCS
  480. /*
  481. ** call corresponding function inserting `globals' as first argument
  482. */
  483. static int deprecated_func (lua_State *L) {
  484. lua_insert(L, 1); /* upvalue is the function to be called */
  485. lua_getglobals(L);
  486. lua_insert(L, 2); /* table of globals is 1o argument */
  487. lua_rawcall(L, lua_gettop(L)-1, LUA_MULTRET);
  488. return lua_gettop(L); /* return all results */
  489. }
  490. static void deprecated_funcs (lua_State *L) {
  491. int i;
  492. for (i=0; i<num_deprecated; i++) {
  493. lua_pushcfunction(L, deprecated_names[i].func);
  494. lua_pushcclosure(L, deprecated_func, 1);
  495. lua_setglobal(L, deprecated_names[i].name);
  496. }
  497. }
  498. #else
  499. /*
  500. ** gives an explicit error in any attempt to call a deprecated function
  501. */
  502. static int deprecated_func (lua_State *L) {
  503. luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1));
  504. return 0; /* to avoid warnings */
  505. }
  506. static void deprecated_funcs (lua_State *L) {
  507. int i;
  508. for (i=0; i<num_deprecated; i++) {
  509. lua_pushstring(L, deprecated_names[i].name);
  510. lua_pushcclosure(L, deprecated_func, 1);
  511. lua_setglobal(L, deprecated_names[i].name);
  512. }
  513. }
  514. #endif
  515. /* }====================================================== */
  516. static const struct luaL_reg base_funcs[] = {
  517. {LUA_ALERT, luaB__ALERT},
  518. {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE},
  519. {"call", luaB_call},
  520. {"collectgarbage", luaB_collectgarbage},
  521. {"copytagmethods", luaB_copytagmethods},
  522. {"dofile", luaB_dofile},
  523. {"dostring", luaB_dostring},
  524. {"error", luaB_error},
  525. {"foreach", luaB_foreach},
  526. {"foreachi", luaB_foreachi},
  527. {"gcinfo", luaB_gcinfo},
  528. {"getglobal", luaB_getglobal},
  529. {"gettagmethod", luaB_gettagmethod},
  530. {"globals", luaB_globals},
  531. {"newtag", luaB_newtag},
  532. {"next", luaB_next},
  533. {"print", luaB_print},
  534. {"rawget", luaB_rawget},
  535. {"rawset", luaB_rawset},
  536. {"rawgettable", luaB_rawget}, /* for compatibility */
  537. {"rawsettable", luaB_rawset}, /* for compatibility */
  538. {"setglobal", luaB_setglobal},
  539. {"settag", luaB_settag},
  540. {"settagmethod", luaB_settagmethod},
  541. {"tag", luaB_tag},
  542. {"tonumber", luaB_tonumber},
  543. {"tostring", luaB_tostring},
  544. {"type", luaB_type},
  545. {"assert", luaB_assert},
  546. {"getn", luaB_getn},
  547. {"sort", luaB_sort},
  548. {"tinsert", luaB_tinsert},
  549. {"tremove", luaB_tremove}
  550. };
  551. void lua_baselibopen (lua_State *L) {
  552. luaL_openl(L, base_funcs);
  553. lua_pushstring(L, LUA_VERSION);
  554. lua_setglobal(L, "_VERSION");
  555. deprecated_funcs(L);
  556. }