diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 24 |
1 files changed, 4 insertions, 20 deletions
@@ -1178,31 +1178,15 @@ static lua_State *getstate (lua_State *L) { | |||
1178 | 1178 | ||
1179 | 1179 | ||
1180 | static int loadlib (lua_State *L) { | 1180 | static int loadlib (lua_State *L) { |
1181 | static const luaL_Reg libs[] = { | ||
1182 | {LUA_GNAME, luaopen_base}, | ||
1183 | {"coroutine", luaopen_coroutine}, | ||
1184 | {"debug", luaopen_debug}, | ||
1185 | {"io", luaopen_io}, | ||
1186 | {"os", luaopen_os}, | ||
1187 | {"math", luaopen_math}, | ||
1188 | {"string", luaopen_string}, | ||
1189 | {"table", luaopen_table}, | ||
1190 | {"T", luaB_opentests}, | ||
1191 | {NULL, NULL} | ||
1192 | }; | ||
1193 | lua_State *L1 = getstate(L); | 1181 | lua_State *L1 = getstate(L); |
1194 | int i; | 1182 | int what = luaL_checkinteger(L, 2); |
1195 | luaL_requiref(L1, "package", luaopen_package, 0); | 1183 | luaL_openselectedlibs(L1, what); |
1184 | luaL_requiref(L1, "T", luaB_opentests, 0); | ||
1196 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); | 1185 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); |
1197 | /* 'requiref' should not reload module already loaded... */ | 1186 | /* 'requiref' should not reload module already loaded... */ |
1198 | luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */ | 1187 | luaL_requiref(L1, "T", NULL, 1); /* seg. fault if it reloads */ |
1199 | /* ...but should return the same module */ | 1188 | /* ...but should return the same module */ |
1200 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); | 1189 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); |
1201 | luaL_getsubtable(L1, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); | ||
1202 | for (i = 0; libs[i].name; i++) { | ||
1203 | lua_pushcfunction(L1, libs[i].func); | ||
1204 | lua_setfield(L1, -2, libs[i].name); | ||
1205 | } | ||
1206 | return 0; | 1190 | return 0; |
1207 | } | 1191 | } |
1208 | 1192 | ||