diff options
author | Li Jin <dragon-fly@qq.com> | 2020-06-22 16:50:40 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-06-22 16:50:40 +0800 |
commit | cd2b60b101a398cb9356d746364e70eaed1860f1 (patch) | |
tree | a1fe71b76faabc4883f16905a94164ce5c23e692 /src/lua/linit.c | |
parent | 88c1052e700f38cf3d8ad82d469da4c487760b7e (diff) | |
download | yuescript-cd2b60b101a398cb9356d746364e70eaed1860f1.tar.gz yuescript-cd2b60b101a398cb9356d746364e70eaed1860f1.tar.bz2 yuescript-cd2b60b101a398cb9356d746364e70eaed1860f1.zip |
add support for local variable declared with attribute 'close' and 'const' for Lua 5.4.
Diffstat (limited to 'src/lua/linit.c')
-rw-r--r-- | src/lua/linit.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lua/linit.c b/src/lua/linit.c new file mode 100644 index 0000000..69808f8 --- /dev/null +++ b/src/lua/linit.c | |||
@@ -0,0 +1,65 @@ | |||
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 | ** If you embed Lua in your program and need to open the standard | ||
13 | ** libraries, call luaL_openlibs in your program. If you need a | ||
14 | ** different set of libraries, copy this file to your project and edit | ||
15 | ** it to suit your needs. | ||
16 | ** | ||
17 | ** You can also *preload* libraries, so that a later 'require' can | ||
18 | ** open the library, which is already linked to the application. | ||
19 | ** For that, do the following code: | ||
20 | ** | ||
21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); | ||
22 | ** lua_pushcfunction(L, luaopen_modname); | ||
23 | ** lua_setfield(L, -2, modname); | ||
24 | ** lua_pop(L, 1); // remove PRELOAD table | ||
25 | */ | ||
26 | |||
27 | #include "lprefix.h" | ||
28 | |||
29 | |||
30 | #include <stddef.h> | ||
31 | |||
32 | #include "lua.h" | ||
33 | |||
34 | #include "lualib.h" | ||
35 | #include "lauxlib.h" | ||
36 | |||
37 | |||
38 | /* | ||
39 | ** these libs are loaded by lua.c and are readily available to any Lua | ||
40 | ** program | ||
41 | */ | ||
42 | static const luaL_Reg loadedlibs[] = { | ||
43 | {LUA_GNAME, luaopen_base}, | ||
44 | {LUA_LOADLIBNAME, luaopen_package}, | ||
45 | {LUA_COLIBNAME, luaopen_coroutine}, | ||
46 | {LUA_TABLIBNAME, luaopen_table}, | ||
47 | {LUA_IOLIBNAME, luaopen_io}, | ||
48 | {LUA_OSLIBNAME, luaopen_os}, | ||
49 | {LUA_STRLIBNAME, luaopen_string}, | ||
50 | {LUA_MATHLIBNAME, luaopen_math}, | ||
51 | {LUA_UTF8LIBNAME, luaopen_utf8}, | ||
52 | {LUA_DBLIBNAME, luaopen_debug}, | ||
53 | {NULL, NULL} | ||
54 | }; | ||
55 | |||
56 | |||
57 | LUALIB_API void luaL_openlibs (lua_State *L) { | ||
58 | const luaL_Reg *lib; | ||
59 | /* "require" functions from 'loadedlibs' and set results to global table */ | ||
60 | for (lib = loadedlibs; lib->func; lib++) { | ||
61 | luaL_requiref(L, lib->name, lib->func, 1); | ||
62 | lua_pop(L, 1); /* remove lib */ | ||
63 | } | ||
64 | } | ||
65 | |||