lbaselib.c
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 17k
Category:

Graph program

Development Platform:

Visual C++

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