Coverage Report

Created: 2025-07-11 06:33

/src/testdir/build/lua-master/source/linit.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
** $Id: linit.c $
3
** Initialization of libraries for lua.c and other clients
4
** See Copyright Notice in lua.h
5
*/
6
7
8
#define linit_c
9
#define LUA_LIB
10
11
12
#include "lprefix.h"
13
14
15
#include <stddef.h>
16
17
#include "lua.h"
18
19
#include "lualib.h"
20
#include "lauxlib.h"
21
#include "llimits.h"
22
23
24
/*
25
** Standard Libraries. (Must be listed in the same ORDER of their
26
** respective constants LUA_<libname>K.)
27
*/
28
static const luaL_Reg stdlibs[] = {
29
  {LUA_GNAME, luaopen_base},
30
  {LUA_LOADLIBNAME, luaopen_package},
31
  {LUA_COLIBNAME, luaopen_coroutine},
32
  {LUA_DBLIBNAME, luaopen_debug},
33
  {LUA_IOLIBNAME, luaopen_io},
34
  {LUA_MATHLIBNAME, luaopen_math},
35
  {LUA_OSLIBNAME, luaopen_os},
36
  {LUA_STRLIBNAME, luaopen_string},
37
  {LUA_TABLIBNAME, luaopen_table},
38
  {LUA_UTF8LIBNAME, luaopen_utf8},
39
  {NULL, NULL}
40
};
41
42
43
/*
44
** require and preload selected standard libraries
45
*/
46
29.9k
LUALIB_API void luaL_openselectedlibs (lua_State *L, int load, int preload) {
47
29.9k
  int mask;
48
29.9k
  const luaL_Reg *lib;
49
29.9k
  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
50
329k
  for (lib = stdlibs, mask = 1; lib->name != NULL; lib++, mask <<= 1) {
51
299k
    if (load & mask) {  /* selected? */
52
299k
      luaL_requiref(L, lib->name, lib->func, 1);  /* require library */
53
299k
      lua_pop(L, 1);  /* remove result from the stack */
54
299k
    }
55
0
    else if (preload & mask) {  /* selected? */
56
0
      lua_pushcfunction(L, lib->func);
57
0
      lua_setfield(L, -2, lib->name);  /* add library to PRELOAD table */
58
0
    }
59
299k
  }
60
29.9k
  lua_assert((mask >> 1) == LUA_UTF8LIBK);
61
29.9k
  lua_pop(L, 1);  /* remove PRELOAD table */
62
29.9k
}
63