aboutsummaryrefslogtreecommitdiff
path: root/src/tools.c
diff options
context:
space:
mode:
authorBenoit Germain <bnt period germain arrobase gmail period com>2014-03-19 10:53:08 +0100
committerBenoit Germain <bnt period germain arrobase gmail period com>2014-03-19 10:53:08 +0100
commit43343cc59b54ebf216bc3519abcf4cd3e1f0243f (patch)
tree8dcef54c74fe8ff6a93a00c9ec2c81a40444a26d /src/tools.c
parent0ffafefaf5ef410fa0da95ac1860e817428531ed (diff)
downloadlanes-43343cc59b54ebf216bc3519abcf4cd3e1f0243f.tar.gz
lanes-43343cc59b54ebf216bc3519abcf4cd3e1f0243f.tar.bz2
lanes-43343cc59b54ebf216bc3519abcf4cd3e1f0243f.zip
Don't mutex-wrap require() more than once
Diffstat (limited to 'src/tools.c')
-rw-r--r--src/tools.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/tools.c b/src/tools.c
index 65387e5..ea7662b 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -735,7 +735,7 @@ lua_State* luaG_newstate( struct s_Universe* U, lua_State* from_, char const* li
735 } 735 }
736 lua_gc( L, LUA_GCRESTART, 0); 736 lua_gc( L, LUA_GCRESTART, 0);
737 737
738 serialize_require( L); 738 serialize_require( U, L);
739 739
740 // call this after the base libraries are loaded and GC is restarted 740 // call this after the base libraries are loaded and GC is restarted
741 // will raise an error in from_ in case of problem 741 // will raise an error in from_ in case of problem
@@ -2316,15 +2316,16 @@ int luaG_new_require( lua_State* L)
2316/* 2316/*
2317* Serialize calls to 'require', if it exists 2317* Serialize calls to 'require', if it exists
2318*/ 2318*/
2319void serialize_require( lua_State* L) 2319void serialize_require( struct s_Universe* U, lua_State* L)
2320{ 2320{
2321 STACK_GROW( L, 1); 2321 STACK_GROW( L, 1);
2322 STACK_CHECK( L); 2322 STACK_CHECK( L);
2323 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "serializing require()\n" INDENT_END));
2323 2324
2324 // Check 'require' is there; if not, do nothing 2325 // Check 'require' is there and not already wrapped; if not, do nothing
2325 // 2326 //
2326 lua_getglobal( L, "require"); 2327 lua_getglobal( L, "require");
2327 if( lua_isfunction( L, -1)) 2328 if( lua_isfunction( L, -1) && lua_tocfunction( L, -1) != luaG_new_require)
2328 { 2329 {
2329 // [-1]: original 'require' function 2330 // [-1]: original 'require' function
2330 lua_pushcclosure( L, luaG_new_require, 1 /*upvalues*/); 2331 lua_pushcclosure( L, luaG_new_require, 1 /*upvalues*/);