diff options
Diffstat (limited to 'src/keeper.c')
-rw-r--r-- | src/keeper.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/keeper.c b/src/keeper.c index 01e8880..5b355cb 100644 --- a/src/keeper.c +++ b/src/keeper.c | |||
@@ -103,15 +103,10 @@ char const *init_keepers( int const _nbKeepers) | |||
103 | luaG_openlibs( L, "io,table,package" ); // 'io' for debugging messages, package because we need to require modules exporting idfuncs | 103 | luaG_openlibs( L, "io,table,package" ); // 'io' for debugging messages, package because we need to require modules exporting idfuncs |
104 | serialize_require( L); | 104 | serialize_require( L); |
105 | 105 | ||
106 | /* We could use an empty table in 'keeper.lua' as the sentinel, but maybe | ||
107 | * checking for a lightuserdata is faster. (any unique value will do -> take the address of some global of ours) | ||
108 | */ | ||
109 | lua_pushlightuserdata( L, &GNbKeepers); | ||
110 | lua_setglobal( L, "nil_sentinel"); | ||
111 | 106 | ||
112 | // Read in the preloaded chunk (and run it) | 107 | // Read in the preloaded chunk (and run it) |
113 | // | 108 | // |
114 | if (luaL_loadbuffer( L, keeper_chunk, sizeof(keeper_chunk), "=lanes_keeper" )) | 109 | if (luaL_loadbuffer( L, keeper_chunk, sizeof(keeper_chunk), "@keeper.lua")) |
115 | return "luaL_loadbuffer() failed"; // LUA_ERRMEM | 110 | return "luaL_loadbuffer() failed"; // LUA_ERRMEM |
116 | 111 | ||
117 | if (lua_pcall( L, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/ )) | 112 | if (lua_pcall( L, 0 /*args*/, 0 /*results*/, 0 /*errfunc*/ )) |
@@ -152,6 +147,34 @@ void keeper_release( struct s_Keeper *K) | |||
152 | MUTEX_UNLOCK( &K->lock_); | 147 | MUTEX_UNLOCK( &K->lock_); |
153 | } | 148 | } |
154 | 149 | ||
150 | void keeper_toggle_nil_sentinels( lua_State *L, int _val_i, int _nil_to_sentinel) | ||
151 | { | ||
152 | int i, n = lua_gettop( L); | ||
153 | /* We could use an empty table in 'keeper.lua' as the sentinel, but maybe | ||
154 | * checking for a lightuserdata is faster. (any unique value will do -> take the address of some global of ours) | ||
155 | */ | ||
156 | void *nil_sentinel = &GNbKeepers; | ||
157 | for( i = _val_i; i <= n; ++ i) | ||
158 | { | ||
159 | if( _nil_to_sentinel) | ||
160 | { | ||
161 | if( lua_isnil( L, i)) | ||
162 | { | ||
163 | lua_pushlightuserdata( L, nil_sentinel); | ||
164 | lua_replace( L, i); | ||
165 | } | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | if( lua_touserdata( L, i) == nil_sentinel) | ||
170 | { | ||
171 | lua_pushnil( L); | ||
172 | lua_replace( L, i); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
155 | /* | 178 | /* |
156 | * Call a function ('func_name') in the keeper state, and pass on the returned | 179 | * Call a function ('func_name') in the keeper state, and pass on the returned |
157 | * values to 'L'. | 180 | * values to 'L'. |
@@ -197,6 +220,7 @@ void close_keepers(void) | |||
197 | lua_close( GKeepers[i].L); | 220 | lua_close( GKeepers[i].L); |
198 | GKeepers[i].L = 0; | 221 | GKeepers[i].L = 0; |
199 | //assert( GKeepers[i].count == 0); | 222 | //assert( GKeepers[i].count == 0); |
223 | MUTEX_FREE( &GKeepers[i].lock_); | ||
200 | } | 224 | } |
201 | if( GKeepers) free( GKeepers); | 225 | if( GKeepers) free( GKeepers); |
202 | GKeepers = NULL; | 226 | GKeepers = NULL; |