LCOV - code coverage report
Current view: top level - external/lua/src - ldblib.c (source / functions) Hit Total Coverage
Test: rapport Lines: 3 270 1.1 %
Date: 2021-12-10 16:22:55 Functions: 1 29 3.4 %
Branches: 0 104 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            : ** $Id: ldblib.c $
       3                 :            : ** Interface from Lua to its debug API
       4                 :            : ** See Copyright Notice in lua.h
       5                 :            : */
       6                 :            : 
       7                 :            : #define ldblib_c
       8                 :            : #define LUA_LIB
       9                 :            : 
      10                 :            : #include "lprefix.h"
      11                 :            : 
      12                 :            : 
      13                 :            : #include <stdio.h>
      14                 :            : #include <stdlib.h>
      15                 :            : #include <string.h>
      16                 :            : 
      17                 :            : #include "lua.h"
      18                 :            : 
      19                 :            : #include "lauxlib.h"
      20                 :            : #include "lualib.h"
      21                 :            : 
      22                 :            : 
      23                 :            : /*
      24                 :            : ** The hook table at registry[HOOKKEY] maps threads to their current
      25                 :            : ** hook function.
      26                 :            : */
      27                 :            : static const char *const HOOKKEY = "_HOOKKEY";
      28                 :            : 
      29                 :            : 
      30                 :            : /*
      31                 :            : ** If L1 != L, L1 can be in any state, and therefore there are no
      32                 :            : ** guarantees about its stack space; any push in L1 must be
      33                 :            : ** checked.
      34                 :            : */
      35                 :          0 : static void checkstack (lua_State *L, lua_State *L1, int n) {
      36   [ #  #  #  # ]:          0 :   if (L != L1 && !lua_checkstack(L1, n))
      37                 :          0 :     luaL_error(L, "stack overflow");
      38                 :          0 : }
      39                 :            : 
      40                 :            : 
      41                 :          0 : static int db_getregistry (lua_State *L) {
      42                 :          0 :   lua_pushvalue(L, LUA_REGISTRYINDEX);
      43                 :          0 :   return 1;
      44                 :            : }
      45                 :            : 
      46                 :            : 
      47                 :          0 : static int db_getmetatable (lua_State *L) {
      48                 :          0 :   luaL_checkany(L, 1);
      49         [ #  # ]:          0 :   if (!lua_getmetatable(L, 1)) {
      50                 :          0 :     lua_pushnil(L);  /* no metatable */
      51                 :          0 :   }
      52                 :          0 :   return 1;
      53                 :            : }
      54                 :            : 
      55                 :            : 
      56                 :          0 : static int db_setmetatable (lua_State *L) {
      57                 :          0 :   int t = lua_type(L, 2);
      58   [ #  #  #  # ]:          0 :   luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");
      59                 :          0 :   lua_settop(L, 2);
      60                 :          0 :   lua_setmetatable(L, 1);
      61                 :          0 :   return 1;  /* return 1st argument */
      62                 :            : }
      63                 :            : 
      64                 :            : 
      65                 :          0 : static int db_getuservalue (lua_State *L) {
      66                 :          0 :   int n = (int)luaL_optinteger(L, 2, 1);
      67         [ #  # ]:          0 :   if (lua_type(L, 1) != LUA_TUSERDATA)
      68                 :          0 :     luaL_pushfail(L);
      69         [ #  # ]:          0 :   else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) {
      70                 :          0 :     lua_pushboolean(L, 1);
      71                 :          0 :     return 2;
      72                 :            :   }
      73                 :          0 :   return 1;
      74                 :          0 : }
      75                 :            : 
      76                 :            : 
      77                 :          0 : static int db_setuservalue (lua_State *L) {
      78                 :          0 :   int n = (int)luaL_optinteger(L, 3, 1);
      79                 :          0 :   luaL_checktype(L, 1, LUA_TUSERDATA);
      80                 :          0 :   luaL_checkany(L, 2);
      81                 :          0 :   lua_settop(L, 2);
      82         [ #  # ]:          0 :   if (!lua_setiuservalue(L, 1, n))
      83                 :          0 :     luaL_pushfail(L);
      84                 :          0 :   return 1;
      85                 :            : }
      86                 :            : 
      87                 :            : 
      88                 :            : /*
      89                 :            : ** Auxiliary function used by several library functions: check for
      90                 :            : ** an optional thread as function's first argument and set 'arg' with
      91                 :            : ** 1 if this argument is present (so that functions can skip it to
      92                 :            : ** access their other arguments)
      93                 :            : */
      94                 :          0 : static lua_State *getthread (lua_State *L, int *arg) {
      95         [ #  # ]:          0 :   if (lua_isthread(L, 1)) {
      96                 :          0 :     *arg = 1;
      97                 :          0 :     return lua_tothread(L, 1);
      98                 :            :   }
      99                 :            :   else {
     100                 :          0 :     *arg = 0;
     101                 :          0 :     return L;  /* function will operate over current thread */
     102                 :            :   }
     103                 :          0 : }
     104                 :            : 
     105                 :            : 
     106                 :            : /*
     107                 :            : ** Variations of 'lua_settable', used by 'db_getinfo' to put results
     108                 :            : ** from 'lua_getinfo' into result table. Key is always a string;
     109                 :            : ** value can be a string, an int, or a boolean.
     110                 :            : */
     111                 :          0 : static void settabss (lua_State *L, const char *k, const char *v) {
     112                 :          0 :   lua_pushstring(L, v);
     113                 :          0 :   lua_setfield(L, -2, k);
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : static void settabsi (lua_State *L, const char *k, int v) {
     117                 :          0 :   lua_pushinteger(L, v);
     118                 :          0 :   lua_setfield(L, -2, k);
     119                 :          0 : }
     120                 :            : 
     121                 :          0 : static void settabsb (lua_State *L, const char *k, int v) {
     122                 :          0 :   lua_pushboolean(L, v);
     123                 :          0 :   lua_setfield(L, -2, k);
     124                 :          0 : }
     125                 :            : 
     126                 :            : 
     127                 :            : /*
     128                 :            : ** In function 'db_getinfo', the call to 'lua_getinfo' may push
     129                 :            : ** results on the stack; later it creates the result table to put
     130                 :            : ** these objects. Function 'treatstackoption' puts the result from
     131                 :            : ** 'lua_getinfo' on top of the result table so that it can call
     132                 :            : ** 'lua_setfield'.
     133                 :            : */
     134                 :          0 : static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
     135         [ #  # ]:          0 :   if (L == L1)
     136                 :          0 :     lua_rotate(L, -2, 1);  /* exchange object and table */
     137                 :            :   else
     138                 :          0 :     lua_xmove(L1, L, 1);  /* move object to the "main" stack */
     139                 :          0 :   lua_setfield(L, -2, fname);  /* put object into table */
     140                 :          0 : }
     141                 :            : 
     142                 :            : 
     143                 :            : /*
     144                 :            : ** Calls 'lua_getinfo' and collects all results in a new table.
     145                 :            : ** L1 needs stack space for an optional input (function) plus
     146                 :            : ** two optional outputs (function and line table) from function
     147                 :            : ** 'lua_getinfo'.
     148                 :            : */
     149                 :          0 : static int db_getinfo (lua_State *L) {
     150                 :            :   lua_Debug ar;
     151                 :            :   int arg;
     152                 :          0 :   lua_State *L1 = getthread(L, &arg);
     153                 :          0 :   const char *options = luaL_optstring(L, arg+2, "flnSrtu");
     154                 :          0 :   checkstack(L, L1, 3);
     155         [ #  # ]:          0 :   if (lua_isfunction(L, arg + 1)) {  /* info about a function? */
     156                 :          0 :     options = lua_pushfstring(L, ">%s", options);  /* add '>' to 'options' */
     157                 :          0 :     lua_pushvalue(L, arg + 1);  /* move function to 'L1' stack */
     158                 :          0 :     lua_xmove(L, L1, 1);
     159                 :          0 :   }
     160                 :            :   else {  /* stack level */
     161         [ #  # ]:          0 :     if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {
     162                 :          0 :       luaL_pushfail(L);  /* level out of range */
     163                 :          0 :       return 1;
     164                 :            :     }
     165                 :            :   }
     166         [ #  # ]:          0 :   if (!lua_getinfo(L1, options, &ar))
     167                 :          0 :     return luaL_argerror(L, arg+2, "invalid option");
     168                 :          0 :   lua_newtable(L);  /* table to collect results */
     169         [ #  # ]:          0 :   if (strchr(options, 'S')) {
     170                 :          0 :     lua_pushlstring(L, ar.source, ar.srclen);
     171                 :          0 :     lua_setfield(L, -2, "source");
     172                 :          0 :     settabss(L, "short_src", ar.short_src);
     173                 :          0 :     settabsi(L, "linedefined", ar.linedefined);
     174                 :          0 :     settabsi(L, "lastlinedefined", ar.lastlinedefined);
     175                 :          0 :     settabss(L, "what", ar.what);
     176                 :          0 :   }
     177         [ #  # ]:          0 :   if (strchr(options, 'l'))
     178                 :          0 :     settabsi(L, "currentline", ar.currentline);
     179         [ #  # ]:          0 :   if (strchr(options, 'u')) {
     180                 :          0 :     settabsi(L, "nups", ar.nups);
     181                 :          0 :     settabsi(L, "nparams", ar.nparams);
     182                 :          0 :     settabsb(L, "isvararg", ar.isvararg);
     183                 :          0 :   }
     184         [ #  # ]:          0 :   if (strchr(options, 'n')) {
     185                 :          0 :     settabss(L, "name", ar.name);
     186                 :          0 :     settabss(L, "namewhat", ar.namewhat);
     187                 :          0 :   }
     188         [ #  # ]:          0 :   if (strchr(options, 'r')) {
     189                 :          0 :     settabsi(L, "ftransfer", ar.ftransfer);
     190                 :          0 :     settabsi(L, "ntransfer", ar.ntransfer);
     191                 :          0 :   }
     192         [ #  # ]:          0 :   if (strchr(options, 't'))
     193                 :          0 :     settabsb(L, "istailcall", ar.istailcall);
     194         [ #  # ]:          0 :   if (strchr(options, 'L'))
     195                 :          0 :     treatstackoption(L, L1, "activelines");
     196         [ #  # ]:          0 :   if (strchr(options, 'f'))
     197                 :          0 :     treatstackoption(L, L1, "func");
     198                 :          0 :   return 1;  /* return table */
     199                 :          0 : }
     200                 :            : 
     201                 :            : 
     202                 :          0 : static int db_getlocal (lua_State *L) {
     203                 :            :   int arg;
     204                 :          0 :   lua_State *L1 = getthread(L, &arg);
     205                 :          0 :   int nvar = (int)luaL_checkinteger(L, arg + 2);  /* local-variable index */
     206         [ #  # ]:          0 :   if (lua_isfunction(L, arg + 1)) {  /* function argument? */
     207                 :          0 :     lua_pushvalue(L, arg + 1);  /* push function */
     208                 :          0 :     lua_pushstring(L, lua_getlocal(L, NULL, nvar));  /* push local name */
     209                 :          0 :     return 1;  /* return only name (there is no value) */
     210                 :            :   }
     211                 :            :   else {  /* stack-level argument */
     212                 :            :     lua_Debug ar;
     213                 :            :     const char *name;
     214                 :          0 :     int level = (int)luaL_checkinteger(L, arg + 1);
     215         [ #  # ]:          0 :     if (!lua_getstack(L1, level, &ar))  /* out of range? */
     216                 :          0 :       return luaL_argerror(L, arg+1, "level out of range");
     217                 :          0 :     checkstack(L, L1, 1);
     218                 :          0 :     name = lua_getlocal(L1, &ar, nvar);
     219         [ #  # ]:          0 :     if (name) {
     220                 :          0 :       lua_xmove(L1, L, 1);  /* move local value */
     221                 :          0 :       lua_pushstring(L, name);  /* push name */
     222                 :          0 :       lua_rotate(L, -2, 1);  /* re-order */
     223                 :          0 :       return 2;
     224                 :            :     }
     225                 :            :     else {
     226                 :          0 :       luaL_pushfail(L);  /* no name (nor value) */
     227                 :          0 :       return 1;
     228                 :            :     }
     229                 :            :   }
     230                 :          0 : }
     231                 :            : 
     232                 :            : 
     233                 :          0 : static int db_setlocal (lua_State *L) {
     234                 :            :   int arg;
     235                 :            :   const char *name;
     236                 :          0 :   lua_State *L1 = getthread(L, &arg);
     237                 :            :   lua_Debug ar;
     238                 :          0 :   int level = (int)luaL_checkinteger(L, arg + 1);
     239                 :          0 :   int nvar = (int)luaL_checkinteger(L, arg + 2);
     240         [ #  # ]:          0 :   if (!lua_getstack(L1, level, &ar))  /* out of range? */
     241                 :          0 :     return luaL_argerror(L, arg+1, "level out of range");
     242                 :          0 :   luaL_checkany(L, arg+3);
     243                 :          0 :   lua_settop(L, arg+3);
     244                 :          0 :   checkstack(L, L1, 1);
     245                 :          0 :   lua_xmove(L, L1, 1);
     246                 :          0 :   name = lua_setlocal(L1, &ar, nvar);
     247         [ #  # ]:          0 :   if (name == NULL)
     248                 :          0 :     lua_pop(L1, 1);  /* pop value (if not popped by 'lua_setlocal') */
     249                 :          0 :   lua_pushstring(L, name);
     250                 :          0 :   return 1;
     251                 :          0 : }
     252                 :            : 
     253                 :            : 
     254                 :            : /*
     255                 :            : ** get (if 'get' is true) or set an upvalue from a closure
     256                 :            : */
     257                 :          0 : static int auxupvalue (lua_State *L, int get) {
     258                 :            :   const char *name;
     259                 :          0 :   int n = (int)luaL_checkinteger(L, 2);  /* upvalue index */
     260                 :          0 :   luaL_checktype(L, 1, LUA_TFUNCTION);  /* closure */
     261         [ #  # ]:          0 :   name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
     262         [ #  # ]:          0 :   if (name == NULL) return 0;
     263                 :          0 :   lua_pushstring(L, name);
     264                 :          0 :   lua_insert(L, -(get+1));  /* no-op if get is false */
     265                 :          0 :   return get + 1;
     266                 :          0 : }
     267                 :            : 
     268                 :            : 
     269                 :          0 : static int db_getupvalue (lua_State *L) {
     270                 :          0 :   return auxupvalue(L, 1);
     271                 :            : }
     272                 :            : 
     273                 :            : 
     274                 :          0 : static int db_setupvalue (lua_State *L) {
     275                 :          0 :   luaL_checkany(L, 3);
     276                 :          0 :   return auxupvalue(L, 0);
     277                 :            : }
     278                 :            : 
     279                 :            : 
     280                 :            : /*
     281                 :            : ** Check whether a given upvalue from a given closure exists and
     282                 :            : ** returns its index
     283                 :            : */
     284                 :          0 : static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) {
     285                 :            :   void *id;
     286                 :          0 :   int nup = (int)luaL_checkinteger(L, argnup);  /* upvalue index */
     287                 :          0 :   luaL_checktype(L, argf, LUA_TFUNCTION);  /* closure */
     288                 :          0 :   id = lua_upvalueid(L, argf, nup);
     289         [ #  # ]:          0 :   if (pnup) {
     290         [ #  # ]:          0 :     luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index");
     291                 :          0 :     *pnup = nup;
     292                 :          0 :   }
     293                 :          0 :   return id;
     294                 :            : }
     295                 :            : 
     296                 :            : 
     297                 :          0 : static int db_upvalueid (lua_State *L) {
     298                 :          0 :   void *id = checkupval(L, 1, 2, NULL);
     299         [ #  # ]:          0 :   if (id != NULL)
     300                 :          0 :     lua_pushlightuserdata(L, id);
     301                 :            :   else
     302                 :          0 :     luaL_pushfail(L);
     303                 :          0 :   return 1;
     304                 :            : }
     305                 :            : 
     306                 :            : 
     307                 :          0 : static int db_upvaluejoin (lua_State *L) {
     308                 :            :   int n1, n2;
     309                 :          0 :   checkupval(L, 1, 2, &n1);
     310                 :          0 :   checkupval(L, 3, 4, &n2);
     311         [ #  # ]:          0 :   luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
     312         [ #  # ]:          0 :   luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
     313                 :          0 :   lua_upvaluejoin(L, 1, n1, 3, n2);
     314                 :          0 :   return 0;
     315                 :            : }
     316                 :            : 
     317                 :            : 
     318                 :            : /*
     319                 :            : ** Call hook function registered at hook table for the current
     320                 :            : ** thread (if there is one)
     321                 :            : */
     322                 :          0 : static void hookf (lua_State *L, lua_Debug *ar) {
     323                 :            :   static const char *const hooknames[] =
     324                 :            :     {"call", "return", "line", "count", "tail call"};
     325                 :          0 :   lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);
     326                 :          0 :   lua_pushthread(L);
     327         [ #  # ]:          0 :   if (lua_rawget(L, -2) == LUA_TFUNCTION) {  /* is there a hook function? */
     328                 :          0 :     lua_pushstring(L, hooknames[(int)ar->event]);  /* push event name */
     329         [ #  # ]:          0 :     if (ar->currentline >= 0)
     330                 :          0 :       lua_pushinteger(L, ar->currentline);  /* push current line */
     331                 :          0 :     else lua_pushnil(L);
     332                 :            :     lua_assert(lua_getinfo(L, "lS", ar));
     333                 :          0 :     lua_call(L, 2, 0);  /* call hook function */
     334                 :          0 :   }
     335                 :          0 : }
     336                 :            : 
     337                 :            : 
     338                 :            : /*
     339                 :            : ** Convert a string mask (for 'sethook') into a bit mask
     340                 :            : */
     341                 :          0 : static int makemask (const char *smask, int count) {
     342                 :          0 :   int mask = 0;
     343         [ #  # ]:          0 :   if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
     344         [ #  # ]:          0 :   if (strchr(smask, 'r')) mask |= LUA_MASKRET;
     345         [ #  # ]:          0 :   if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
     346         [ #  # ]:          0 :   if (count > 0) mask |= LUA_MASKCOUNT;
     347                 :          0 :   return mask;
     348                 :            : }
     349                 :            : 
     350                 :            : 
     351                 :            : /*
     352                 :            : ** Convert a bit mask (for 'gethook') into a string mask
     353                 :            : */
     354                 :          0 : static char *unmakemask (int mask, char *smask) {
     355                 :          0 :   int i = 0;
     356         [ #  # ]:          0 :   if (mask & LUA_MASKCALL) smask[i++] = 'c';
     357         [ #  # ]:          0 :   if (mask & LUA_MASKRET) smask[i++] = 'r';
     358         [ #  # ]:          0 :   if (mask & LUA_MASKLINE) smask[i++] = 'l';
     359                 :          0 :   smask[i] = '\0';
     360                 :          0 :   return smask;
     361                 :            : }
     362                 :            : 
     363                 :            : 
     364                 :          0 : static int db_sethook (lua_State *L) {
     365                 :            :   int arg, mask, count;
     366                 :            :   lua_Hook func;
     367                 :          0 :   lua_State *L1 = getthread(L, &arg);
     368         [ #  # ]:          0 :   if (lua_isnoneornil(L, arg+1)) {  /* no hook? */
     369                 :          0 :     lua_settop(L, arg+1);
     370                 :          0 :     func = NULL; mask = 0; count = 0;  /* turn off hooks */
     371                 :          0 :   }
     372                 :            :   else {
     373                 :          0 :     const char *smask = luaL_checkstring(L, arg+2);
     374                 :          0 :     luaL_checktype(L, arg+1, LUA_TFUNCTION);
     375                 :          0 :     count = (int)luaL_optinteger(L, arg + 3, 0);
     376                 :          0 :     func = hookf; mask = makemask(smask, count);
     377                 :            :   }
     378         [ #  # ]:          0 :   if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
     379                 :            :     /* table just created; initialize it */
     380                 :          0 :     lua_pushstring(L, "k");
     381                 :          0 :     lua_setfield(L, -2, "__mode");  /** hooktable.__mode = "k" */
     382                 :          0 :     lua_pushvalue(L, -1);
     383                 :          0 :     lua_setmetatable(L, -2);  /* metatable(hooktable) = hooktable */
     384                 :          0 :   }
     385                 :          0 :   checkstack(L, L1, 1);
     386                 :          0 :   lua_pushthread(L1); lua_xmove(L1, L, 1);  /* key (thread) */
     387                 :          0 :   lua_pushvalue(L, arg + 1);  /* value (hook function) */
     388                 :          0 :   lua_rawset(L, -3);  /* hooktable[L1] = new Lua hook */
     389                 :          0 :   lua_sethook(L1, func, mask, count);
     390                 :          0 :   return 0;
     391                 :            : }
     392                 :            : 
     393                 :            : 
     394                 :          0 : static int db_gethook (lua_State *L) {
     395                 :            :   int arg;
     396                 :          0 :   lua_State *L1 = getthread(L, &arg);
     397                 :            :   char buff[5];
     398                 :          0 :   int mask = lua_gethookmask(L1);
     399                 :          0 :   lua_Hook hook = lua_gethook(L1);
     400         [ #  # ]:          0 :   if (hook == NULL) {  /* no hook? */
     401                 :          0 :     luaL_pushfail(L);
     402                 :          0 :     return 1;
     403                 :            :   }
     404         [ #  # ]:          0 :   else if (hook != hookf)  /* external hook? */
     405                 :          0 :     lua_pushliteral(L, "external hook");
     406                 :            :   else {  /* hook table must exist */
     407                 :          0 :     lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);
     408                 :          0 :     checkstack(L, L1, 1);
     409                 :          0 :     lua_pushthread(L1); lua_xmove(L1, L, 1);
     410                 :          0 :     lua_rawget(L, -2);   /* 1st result = hooktable[L1] */
     411                 :          0 :     lua_remove(L, -2);  /* remove hook table */
     412                 :            :   }
     413                 :          0 :   lua_pushstring(L, unmakemask(mask, buff));  /* 2nd result = mask */
     414                 :          0 :   lua_pushinteger(L, lua_gethookcount(L1));  /* 3rd result = count */
     415                 :          0 :   return 3;
     416                 :          0 : }
     417                 :            : 
     418                 :            : 
     419                 :          0 : static int db_debug (lua_State *L) {
     420                 :          0 :   for (;;) {
     421                 :            :     char buffer[250];
     422                 :          0 :     lua_writestringerror("%s", "lua_debug> ");
     423   [ #  #  #  # ]:          0 :     if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
     424                 :          0 :         strcmp(buffer, "cont\n") == 0)
     425                 :          0 :       return 0;
     426   [ #  #  #  # ]:          0 :     if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
     427                 :          0 :         lua_pcall(L, 0, 0, 0))
     428                 :          0 :       lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL));
     429                 :          0 :     lua_settop(L, 0);  /* remove eventual returns */
     430                 :            :   }
     431                 :            : }
     432                 :            : 
     433                 :            : 
     434                 :          0 : static int db_traceback (lua_State *L) {
     435                 :            :   int arg;
     436                 :          0 :   lua_State *L1 = getthread(L, &arg);
     437                 :          0 :   const char *msg = lua_tostring(L, arg + 1);
     438   [ #  #  #  # ]:          0 :   if (msg == NULL && !lua_isnoneornil(L, arg + 1))  /* non-string 'msg'? */
     439                 :          0 :     lua_pushvalue(L, arg + 1);  /* return it untouched */
     440                 :            :   else {
     441                 :          0 :     int level = (int)luaL_optinteger(L, arg + 2, (L == L1) ? 1 : 0);
     442                 :          0 :     luaL_traceback(L, L1, msg, level);
     443                 :            :   }
     444                 :          0 :   return 1;
     445                 :            : }
     446                 :            : 
     447                 :            : 
     448                 :          0 : static int db_setcstacklimit (lua_State *L) {
     449                 :          0 :   int limit = (int)luaL_checkinteger(L, 1);
     450                 :          0 :   int res = lua_setcstacklimit(L, limit);
     451                 :          0 :   lua_pushinteger(L, res);
     452                 :          0 :   return 1;
     453                 :            : }
     454                 :            : 
     455                 :            : 
     456                 :            : static const luaL_Reg dblib[] = {
     457                 :            :   {"debug", db_debug},
     458                 :            :   {"getuservalue", db_getuservalue},
     459                 :            :   {"gethook", db_gethook},
     460                 :            :   {"getinfo", db_getinfo},
     461                 :            :   {"getlocal", db_getlocal},
     462                 :            :   {"getregistry", db_getregistry},
     463                 :            :   {"getmetatable", db_getmetatable},
     464                 :            :   {"getupvalue", db_getupvalue},
     465                 :            :   {"upvaluejoin", db_upvaluejoin},
     466                 :            :   {"upvalueid", db_upvalueid},
     467                 :            :   {"setuservalue", db_setuservalue},
     468                 :            :   {"sethook", db_sethook},
     469                 :            :   {"setlocal", db_setlocal},
     470                 :            :   {"setmetatable", db_setmetatable},
     471                 :            :   {"setupvalue", db_setupvalue},
     472                 :            :   {"traceback", db_traceback},
     473                 :            :   {"setcstacklimit", db_setcstacklimit},
     474                 :            :   {NULL, NULL}
     475                 :            : };
     476                 :            : 
     477                 :            : 
     478                 :        810 : LUAMOD_API int luaopen_debug (lua_State *L) {
     479                 :        810 :   luaL_newlib(L, dblib);
     480                 :        810 :   return 1;
     481                 :            : }
     482                 :            : 

Generated by: LCOV version 1.15