diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-12-07 15:12:52 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-12-07 15:12:52 -0300 |
commit | d738c8d18bcc5651109b3a46103d6aa983772e68 (patch) | |
tree | e66f2f38d7cc1600da3ea19b134c7c21636a3870 /lualib.h | |
parent | 0270c204c235a495ce4702ac3891eb30752d0c8d (diff) | |
download | lua-d738c8d18bcc5651109b3a46103d6aa983772e68.tar.gz lua-d738c8d18bcc5651109b3a46103d6aa983772e68.tar.bz2 lua-d738c8d18bcc5651109b3a46103d6aa983772e68.zip |
New function 'luaL_openselectedlibs'
Makes it easier to start Lua with only some standard libraries.
Diffstat (limited to 'lualib.h')
-rw-r--r-- | lualib.h | 39 |
1 files changed, 26 insertions, 13 deletions
@@ -14,39 +14,52 @@ | |||
14 | /* version suffix for environment variable names */ | 14 | /* version suffix for environment variable names */ |
15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR | 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR |
16 | 16 | ||
17 | 17 | #define LUA_GK 1 | |
18 | LUAMOD_API int (luaopen_base) (lua_State *L); | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); |
19 | 19 | ||
20 | #define LUA_LOADLIBNAME "package" | ||
21 | #define LUA_LOADLIBK (LUA_GK << 1) | ||
22 | LUAMOD_API int (luaopen_package) (lua_State *L); | ||
23 | |||
24 | |||
20 | #define LUA_COLIBNAME "coroutine" | 25 | #define LUA_COLIBNAME "coroutine" |
26 | #define LUA_COLIBK (LUA_LOADLIBK << 1) | ||
21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); | 27 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); |
22 | 28 | ||
23 | #define LUA_TABLIBNAME "table" | 29 | #define LUA_DBLIBNAME "debug" |
24 | LUAMOD_API int (luaopen_table) (lua_State *L); | 30 | #define LUA_DBLIBK (LUA_COLIBK << 1) |
31 | LUAMOD_API int (luaopen_debug) (lua_State *L); | ||
25 | 32 | ||
26 | #define LUA_IOLIBNAME "io" | 33 | #define LUA_IOLIBNAME "io" |
34 | #define LUA_IOLIBK (LUA_DBLIBK << 1) | ||
27 | LUAMOD_API int (luaopen_io) (lua_State *L); | 35 | LUAMOD_API int (luaopen_io) (lua_State *L); |
28 | 36 | ||
37 | #define LUA_MATHLIBNAME "math" | ||
38 | #define LUA_MATHLIBK (LUA_IOLIBK << 1) | ||
39 | LUAMOD_API int (luaopen_math) (lua_State *L); | ||
40 | |||
29 | #define LUA_OSLIBNAME "os" | 41 | #define LUA_OSLIBNAME "os" |
42 | #define LUA_OSLIBK (LUA_MATHLIBK << 1) | ||
30 | LUAMOD_API int (luaopen_os) (lua_State *L); | 43 | LUAMOD_API int (luaopen_os) (lua_State *L); |
31 | 44 | ||
32 | #define LUA_STRLIBNAME "string" | 45 | #define LUA_STRLIBNAME "string" |
46 | #define LUA_STRLIBK (LUA_OSLIBK << 1) | ||
33 | LUAMOD_API int (luaopen_string) (lua_State *L); | 47 | LUAMOD_API int (luaopen_string) (lua_State *L); |
34 | 48 | ||
49 | #define LUA_TABLIBNAME "table" | ||
50 | #define LUA_TABLIBK (LUA_STRLIBK << 1) | ||
51 | LUAMOD_API int (luaopen_table) (lua_State *L); | ||
52 | |||
35 | #define LUA_UTF8LIBNAME "utf8" | 53 | #define LUA_UTF8LIBNAME "utf8" |
54 | #define LUA_UTF8LIBK (LUA_TABLIBK << 1) | ||
36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); | 55 | LUAMOD_API int (luaopen_utf8) (lua_State *L); |
37 | 56 | ||
38 | #define LUA_MATHLIBNAME "math" | ||
39 | LUAMOD_API int (luaopen_math) (lua_State *L); | ||
40 | |||
41 | #define LUA_DBLIBNAME "debug" | ||
42 | LUAMOD_API int (luaopen_debug) (lua_State *L); | ||
43 | |||
44 | #define LUA_LOADLIBNAME "package" | ||
45 | LUAMOD_API int (luaopen_package) (lua_State *L); | ||
46 | 57 | ||
58 | /* open selected libraries */ | ||
59 | LUALIB_API void (luaL_openselectedlibs) (lua_State *L, int what); | ||
47 | 60 | ||
48 | /* open all previous libraries */ | 61 | /* open all libraries */ |
49 | LUALIB_API void (luaL_openlibs) (lua_State *L); | 62 | #define luaL_openlibs(L) luaL_openselectedlibs(L, ~0) |
50 | 63 | ||
51 | 64 | ||
52 | #endif | 65 | #endif |