lbaselib.c 17 KB

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