diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-20 15:49:28 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-20 15:49:28 +0200 |
commit | 9a0781e52fd0f9eac8ac75c18d7f58936fb6c981 (patch) | |
tree | b0766998fe71a89e4f968dac1e669684d7cb7d88 /src | |
parent | 5e5f08558010890206e1d2d11045870c35eb23cf (diff) | |
download | lanes-9a0781e52fd0f9eac8ac75c18d7f58936fb6c981.tar.gz lanes-9a0781e52fd0f9eac8ac75c18d7f58936fb6c981.tar.bz2 lanes-9a0781e52fd0f9eac8ac75c18d7f58936fb6c981.zip |
linda:limit uses nil instead of -1 to unblock
Diffstat (limited to 'src')
-rw-r--r-- | src/keeper.cpp | 10 | ||||
-rw-r--r-- | src/linda.cpp | 11 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/keeper.cpp b/src/keeper.cpp index 2f8817c..9bde2d5 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -359,14 +359,14 @@ int keepercall_receive_batched(lua_State* L_) | |||
359 | 359 | ||
360 | // ################################################################################################# | 360 | // ################################################################################################# |
361 | 361 | ||
362 | // in: linda_ud key n | 362 | // in: linda_ud key [n|nil] |
363 | // out: true or nil | 363 | // out: true or nil |
364 | int keepercall_limit(lua_State* L_) | 364 | int keepercall_limit(lua_State* L_) |
365 | { | 365 | { |
366 | int const _limit{ static_cast<int>(lua_tointeger(L_, 3)) }; | 366 | int const _limit{ static_cast<int>(luaL_optinteger(L_, 3, -1)) }; // -1 if we read nil because the argument is absent |
367 | push_table(L_, 1); // L_: ud key n fifos | 367 | push_table(L_, 1); // L_: ud key n? fifos |
368 | lua_replace(L_, 1); // L_: fifos key n | 368 | lua_replace(L_, 1); // L_: fifos key n? |
369 | lua_pop(L_, 1); // L_: fifos key | 369 | lua_settop(L_, 2); // L_: fifos key |
370 | lua_pushvalue(L_, -1); // L_: fifos key key | 370 | lua_pushvalue(L_, -1); // L_: fifos key key |
371 | lua_rawget(L_, -3); // L_: fifos key fifo|nil | 371 | lua_rawget(L_, -3); // L_: fifos key fifo|nil |
372 | keeper_fifo* _fifo{ keeper_fifo::getPtr(L_, -1) }; | 372 | keeper_fifo* _fifo{ keeper_fifo::getPtr(L_, -1) }; |
diff --git a/src/linda.cpp b/src/linda.cpp index 76607a4..48da1cf 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -354,21 +354,22 @@ LUAG_FUNC(linda_get) | |||
354 | // ################################################################################################# | 354 | // ################################################################################################# |
355 | 355 | ||
356 | /* | 356 | /* |
357 | * [true] = linda_limit( linda_ud, key_num|str|bool|lightuserdata, int) | 357 | * [true] = linda_limit( linda_ud, key_num|str|bool|lightuserdata, [int]) |
358 | * | 358 | * |
359 | * Set limit to 1 Linda keys. | 359 | * Set limit to 1 Linda keys. |
360 | * Optionally wake threads waiting to write on the linda, in case the limit enables them to do so | 360 | * Optionally wake threads waiting to write on the linda, in case the limit enables them to do so |
361 | * Limit can be 0 to completely block everything | 361 | * Limit can be 0 to completely block everything, nil to reset |
362 | */ | 362 | */ |
363 | LUAG_FUNC(linda_limit) | 363 | LUAG_FUNC(linda_limit) |
364 | { | 364 | { |
365 | auto _limit = [](lua_State* L_) { | 365 | auto _limit = [](lua_State* L_) { |
366 | Linda* const _linda{ ToLinda<false>(L_, 1) }; | 366 | Linda* const _linda{ ToLinda<false>(L_, 1) }; |
367 | // make sure we got 3 arguments: the linda, a key and a limit | 367 | // make sure we got 3 arguments: the linda, a key and a limit |
368 | luaL_argcheck(L_, lua_gettop(L_) == 3, 2, "wrong number of arguments"); | 368 | int const _nargs{ lua_gettop(L_) }; |
369 | luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); | ||
369 | // make sure we got a numeric limit | 370 | // make sure we got a numeric limit |
370 | lua_Number const _limit{ luaL_checknumber(L_, 3) }; | 371 | lua_Integer const _limit{ luaL_optinteger(L_, 3, 0) }; |
371 | if (_limit < 1) { | 372 | if (_limit < 0) { |
372 | raise_luaL_argerror(L_, 3, "limit must be >= 0"); | 373 | raise_luaL_argerror(L_, 3, "limit must be >= 0"); |
373 | } | 374 | } |
374 | // make sure the key is of a valid type | 375 | // make sure the key is of a valid type |