aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.c
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2012-09-26 21:22:30 +0200
committerBenoit Germain <bnt.germain@gmail.com>2012-09-26 21:22:30 +0200
commitbba4ecea15320dfbf8edf35f7361de374d895ace (patch)
tree73bd0bfd29d2c4dbfe3a46681b0e3b2261352207 /src/lanes.c
parent282f59ca02d1d1f304b9126b84a8b1427caf3172 (diff)
downloadlanes-bba4ecea15320dfbf8edf35f7361de374d895ace.tar.gz
lanes-bba4ecea15320dfbf8edf35f7361de374d895ace.tar.bz2
lanes-bba4ecea15320dfbf8edf35f7361de374d895ace.zip
version 3.4.0
* new method linda:dump() that outputs the full contents of a linda as a table, also linked to __towatch for Decoda support * linda:receive() API change! * instead of [val, key], linda:receive( timeout, key) returns [key, val] * instead of [val, [...]], linda:receive( timeout, linda.batched key) returns [key, val[, ...]] this is to unify the return values of regular and batched mode, and to be able to tell when batched mode is interrupted by a lane cancellation * fixed Lua 5.2 build to take into account the "loaders"->"searchers" name change in 'package' module. * a bit of html cleanup and added some infos in the documentation regarding the Lanes internals
Diffstat (limited to 'src/lanes.c')
-rw-r--r--src/lanes.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/lanes.c b/src/lanes.c
index eac4753..f2e8aa7 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -51,7 +51,7 @@
51 * ... 51 * ...
52 */ 52 */
53 53
54char const* VERSION = "3.3.0"; 54char const* VERSION = "3.4.0";
55 55
56/* 56/*
57=============================================================================== 57===============================================================================
@@ -348,7 +348,7 @@ LUAG_FUNC( linda_send)
348 STACK_CHECK(L) 348 STACK_CHECK(L)
349 lua_pushlightuserdata( L, CANCEL_TEST_KEY); 349 lua_pushlightuserdata( L, CANCEL_TEST_KEY);
350 lua_rawget( L, LUA_REGISTRYINDEX); 350 lua_rawget( L, LUA_REGISTRYINDEX);
351 s = lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) / nil 351 s = lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) or nil if in the main Lua state
352 lua_pop(L, 1); 352 lua_pop(L, 1);
353 STACK_END(L,0) 353 STACK_END(L,0)
354 if( s) 354 if( s)
@@ -445,6 +445,9 @@ LUAG_FUNC( linda_receive)
445 // we expect a user-defined amount of return value 445 // we expect a user-defined amount of return value
446 expected_pushed_min = (int)luaL_checkinteger( L, key_i + 1); 446 expected_pushed_min = (int)luaL_checkinteger( L, key_i + 1);
447 expected_pushed_max = (int)luaL_optinteger( L, key_i + 2, expected_pushed_min); 447 expected_pushed_max = (int)luaL_optinteger( L, key_i + 2, expected_pushed_min);
448 // don't forget to count the key in addition to the values
449 ++ expected_pushed_min;
450 ++ expected_pushed_max;
448 if( expected_pushed_min > expected_pushed_max) 451 if( expected_pushed_min > expected_pushed_max)
449 { 452 {
450 return luaL_error( L, "batched min/max error"); 453 return luaL_error( L, "batched min/max error");
@@ -503,7 +506,7 @@ LUAG_FUNC( linda_receive)
503 STACK_CHECK(L) 506 STACK_CHECK(L)
504 lua_pushlightuserdata( L, CANCEL_TEST_KEY); 507 lua_pushlightuserdata( L, CANCEL_TEST_KEY);
505 lua_rawget( L, LUA_REGISTRYINDEX); 508 lua_rawget( L, LUA_REGISTRYINDEX);
506 s= lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) / nil 509 s = lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) or nil if in the main Lua state
507 lua_pop(L, 1); 510 lua_pop(L, 1);
508 STACK_END(L, 0) 511 STACK_END(L, 0)
509 if( s) 512 if( s)
@@ -771,6 +774,16 @@ LUAG_FUNC( linda_concat)
771} 774}
772 775
773/* 776/*
777 * table = linda:dump()
778 * return a table listing all pending data inside the linda
779 */
780LUAG_FUNC( linda_dump)
781{
782 struct s_Linda* linda = lua_toLinda( L, 1);
783 return keeper_push_linda_storage( L, linda);
784}
785
786/*
774* Identity function of a shared userdata object. 787* Identity function of a shared userdata object.
775* 788*
776* lightuserdata= linda_id( "new" [, ...] ) 789* lightuserdata= linda_id( "new" [, ...] )
@@ -860,6 +873,10 @@ static void linda_id( lua_State *L, char const * const which)
860 lua_pushcfunction( L, LG_linda_tostring); 873 lua_pushcfunction( L, LG_linda_tostring);
861 lua_setfield( L, -2, "__tostring"); 874 lua_setfield( L, -2, "__tostring");
862 875
876 // Decoda __towatch support
877 lua_pushcfunction( L, LG_linda_dump);
878 lua_setfield( L, -2, "__towatch");
879
863 lua_pushcfunction( L, LG_linda_concat); 880 lua_pushcfunction( L, LG_linda_concat);
864 lua_setfield( L, -2, "__concat"); 881 lua_setfield( L, -2, "__concat");
865 882
@@ -886,6 +903,9 @@ static void linda_id( lua_State *L, char const * const which)
886 lua_pushcfunction( L, LG_linda_deep ); 903 lua_pushcfunction( L, LG_linda_deep );
887 lua_setfield( L, -2, "deep" ); 904 lua_setfield( L, -2, "deep" );
888 905
906 lua_pushcfunction( L, LG_linda_dump);
907 lua_setfield( L, -2, "dump" );
908
889 lua_pushliteral( L, BATCH_SENTINEL); 909 lua_pushliteral( L, BATCH_SENTINEL);
890 lua_setfield(L, -2, "batched"); 910 lua_setfield(L, -2, "batched");
891 911
@@ -1752,7 +1772,8 @@ LUAG_FUNC( thread_new )
1752 if( !lua_isnil( L2, -1)) // package library not loaded: do nothing 1772 if( !lua_isnil( L2, -1)) // package library not loaded: do nothing
1753 { 1773 {
1754 int i; 1774 int i;
1755 char const *entries[] = { "path", "cpath", "preload", "loaders", NULL}; 1775 // package.loaders is renamed package.searchers in Lua 5.2
1776 char const* entries[] = { "path", "cpath", "preload", (LUA_VERSION_NUM == 501) ? "loaders" : "searchers", NULL};
1756 for( i = 0; entries[i]; ++ i) 1777 for( i = 0; entries[i]; ++ i)
1757 { 1778 {
1758 lua_getfield( L, package, entries[i]); 1779 lua_getfield( L, package, entries[i]);