aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2012-11-22 10:53:00 +0100
committerBenoit Germain <bnt.germain@gmail.com>2012-11-22 10:53:00 +0100
commit0d14c12289f03b6d550ebcb200022482a2eadbaa (patch)
tree7c20eabdfe458afaa287907d47743c84010f0745
parentf154e1f1b6cea07163f364986fb11ccfcb87c3ad (diff)
downloadlanes-0d14c12289f03b6d550ebcb200022482a2eadbaa.tar.gz
lanes-0d14c12289f03b6d550ebcb200022482a2eadbaa.tar.bz2
lanes-0d14c12289f03b6d550ebcb200022482a2eadbaa.zip
fix issue #39
linda:set() no longer clears the storage limit.
-rw-r--r--src/keeper.c49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/keeper.c b/src/keeper.c
index 29f9c71..44790d6 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -369,28 +369,57 @@ int keepercall_limit( lua_State* L)
369//in: linda_ud key [val] 369//in: linda_ud key [val]
370int keepercall_set( lua_State* L) 370int keepercall_set( lua_State* L)
371{ 371{
372 STACK_GROW( L, 6);
372 // make sure we have a value on the stack 373 // make sure we have a value on the stack
373 if( lua_gettop( L) == 2) 374 if( lua_gettop( L) == 2) // ud key val?
374 { 375 {
375 lua_pushnil( L); 376 lua_pushnil( L); // ud key nil
376 } 377 }
378
379 // retrieve fifos associated with the linda
377 push_table( L, 1); // ud key val fifos 380 push_table( L, 1); // ud key val fifos
378 lua_replace( L, 1); // fifos key val 381 lua_replace( L, 1); // fifos key val
379 if( !lua_isnil( L, 3)) // replace contents stored at the specified key? 382
383 if( !lua_isnil( L, 3)) // set/replace contents stored at the specified key?
380 { 384 {
381 keeper_fifo* fifo; 385 keeper_fifo* fifo;
382 fifo_new( L); // fifos key val fifo 386 lua_pushvalue( L, -2); // fifos key val key
383 lua_pushvalue( L, 2); // fifos key val fifo key 387 lua_rawget( L, 1); // fifos key val fifo|nil
384 lua_pushvalue( L, -2); // fifos key val fifo key fifo 388 fifo = (keeper_fifo*) lua_touserdata( L, -1);
385 lua_rawset( L, 1); // fifos key val fifo 389 if( fifo == NULL) // might be NULL if we set a nonexistent key to nil
390 {
391 lua_pop( L, 1); // fifos key val
392 fifo_new( L); // fifos key val fifo
393 lua_pushvalue( L, 2); // fifos key val fifo key
394 lua_pushvalue( L, -2); // fifos key val fifo key fifo
395 lua_rawset( L, 1); // fifos key val fifo
396 }
397 else // the fifo exists, we just want to clear its contents
398 {
399 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
400 lua_newtable( L); // fifos key val fifo {}
401 lua_setuservalue( L, -2); // fifos key val fifo
402 fifo->first = 1;
403 fifo->count = 0;
404 }
386 fifo = prepare_fifo_access( L, -1); 405 fifo = prepare_fifo_access( L, -1);
387 lua_insert( L, -2); // fifos key fifo val 406 lua_insert( L, -2); // fifos key fifo val
388 fifo_push( L, fifo, 1); // fifos key fifo 407 fifo_push( L, fifo, 1); // fifos key fifo
389 } 408 }
390 else 409 else // val == nil // fifos key nil
391 { 410 {
392 // val == nil => stack contents: fifos key nil => remove the fifo associated with the current key 411 keeper_fifo* fifo;
393 lua_rawset( L, 1); // fifos 412 lua_pop( L, 1); // fifos key
413 lua_rawget( L, 1); // fifos fifo|nil
414 // empty the fifo for the specified key: replace uservalue with a virgin table, reset counters, but leave limit unchanged!
415 fifo = (keeper_fifo*) lua_touserdata( L, -1);
416 if( fifo != NULL) // might be NULL if we set a nonexistent key to nil
417 {
418 lua_newtable( L); // fifos fifo {}
419 lua_setuservalue( L, -2); // fifos fifo
420 fifo->first = 1;
421 fifo->count = 0;
422 }
394 } 423 }
395 return 0; 424 return 0;
396} 425}