diff options
| author | Benoit Germain <bnt.germain@gmail.com> | 2013-10-03 11:46:18 +0200 |
|---|---|---|
| committer | Benoit Germain <bnt.germain@gmail.com> | 2013-10-03 11:46:18 +0200 |
| commit | d3df9bd6736bce840e752f87296162c5e1e73ce9 (patch) | |
| tree | 1bcf1c718c075b1580e7a91151b3f0d38a067345 | |
| parent | 69c42e1908f293498733eb5fa433f8742a513deb (diff) | |
| download | lanes-d3df9bd6736bce840e752f87296162c5e1e73ce9.tar.gz lanes-d3df9bd6736bce840e752f87296162c5e1e73ce9.tar.bz2 lanes-d3df9bd6736bce840e752f87296162c5e1e73ce9.zip | |
bugfix: no longer create a global named "lanes.core" inside lanes when libs list is "*"
| -rw-r--r-- | src/tools.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/tools.c b/src/tools.c index da6ffe5..b02177b 100644 --- a/src/tools.c +++ b/src/tools.c | |||
| @@ -178,22 +178,19 @@ static void open1lib( lua_State* L, char const* name, size_t len) | |||
| 178 | { | 178 | { |
| 179 | if( strncmp( name, libs[i].name, len) == 0) | 179 | if( strncmp( name, libs[i].name, len) == 0) |
| 180 | { | 180 | { |
| 181 | if( libs[i].func) | 181 | lua_CFunction libfunc = libs[i].func; |
| 182 | if( libfunc) | ||
| 182 | { | 183 | { |
| 184 | bool_t createGlobal = (libfunc != require_lanes_core) ? TRUE : FALSE; // don't want to create a global for "lanes.core" | ||
| 183 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, len, name)); | 185 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening %.*s library\n" INDENT_END, len, name)); |
| 184 | STACK_CHECK( L); | 186 | STACK_CHECK( L); |
| 185 | #if LUA_VERSION_NUM >= 502 | 187 | // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) |
| 186 | // open the library as if through require(), and create a global as well (the library table is left on the stack) | 188 | luaL_requiref( L, libs[i].name, libfunc, createGlobal); |
| 187 | luaL_requiref( L, libs[i].name, libs[i].func, 1); | 189 | if( createGlobal == FALSE) |
| 190 | { | ||
| 191 | populate_func_lookup_table( L, -1, name); | ||
| 192 | } | ||
| 188 | lua_pop( L, 1); | 193 | lua_pop( L, 1); |
| 189 | #else // LUA_VERSION_NUM | ||
| 190 | STACK_GROW( L, 1); | ||
| 191 | // push function and 1 argument on the stack | ||
| 192 | lua_pushcfunction( L, libs[i].func); | ||
| 193 | lua_pushstring( L, libs[i].name); | ||
| 194 | // call function, pushes the module table on the stack | ||
| 195 | lua_call( L, 1, 0); | ||
| 196 | #endif // LUA_VERSION_NUM | ||
| 197 | STACK_END( L, 0); | 194 | STACK_END( L, 0); |
| 198 | } | 195 | } |
| 199 | break; | 196 | break; |
| @@ -572,11 +569,8 @@ lua_State* luaG_newstate( lua_State* _from, int const _on_state_create, char con | |||
| 572 | { | 569 | { |
| 573 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening ALL standard libraries\n" INDENT_END)); | 570 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "opening ALL standard libraries\n" INDENT_END)); |
| 574 | luaL_openlibs( L); | 571 | luaL_openlibs( L); |
| 575 | if( libs[0] == '*') | 572 | // don't forget lanes.core for regular lane states |
| 576 | { | 573 | open1lib( L, "lanes.core", 10); |
| 577 | // don't forget lanes.core for regular lane states | ||
| 578 | open1lib( L, "lanes.core", 10); | ||
| 579 | } | ||
| 580 | libs = NULL; // done with libs | 574 | libs = NULL; // done with libs |
| 581 | } | 575 | } |
| 582 | else | 576 | else |
