lbaselib.c 17 KB

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