diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2026-02-27 10:59:11 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2026-02-27 10:59:11 +0100 |
| commit | 7e4b6e1526c5b2f85079df6a6ecfe08244a7dbcc (patch) | |
| tree | 3efb69b5a2d40fd1c226b72f3d0f99dcc30afc83 /src/lanes.cpp | |
| parent | 68355c7dd6bef53d264eca53567df9fb9c8684b6 (diff) | |
| download | lanes-7e4b6e1526c5b2f85079df6a6ecfe08244a7dbcc.tar.gz lanes-7e4b6e1526c5b2f85079df6a6ecfe08244a7dbcc.tar.bz2 lanes-7e4b6e1526c5b2f85079df6a6ecfe08244a7dbcc.zip | |
Unify sleep() timeout with send() and receive (nil means forever)v4.0.0
Diffstat (limited to 'src/lanes.cpp')
| -rw-r--r-- | src/lanes.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index ef8577b..cf227f9 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
| @@ -169,25 +169,23 @@ LUAG_FUNC(sleep) | |||
| 169 | extern LUAG_FUNC(linda_receive); | 169 | extern LUAG_FUNC(linda_receive); |
| 170 | 170 | ||
| 171 | Universe* const _U{ Universe::Get(L_) }; | 171 | Universe* const _U{ Universe::Get(L_) }; |
| 172 | lua_settop(L_, 1); | 172 | lua_settop(L_, 1); // L_: duration? |
| 173 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() | 173 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration? receive() |
| 174 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments | 174 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments |
| 175 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda | 175 | _U->timerLinda->push(L_); // L_: duration? receive() timerLinda |
| 176 | if (luaW_tostring(L_, StackIndex{ 1 }) == "indefinitely") { | 176 | if (lua_isnumber(L_, 1)) { |
| 177 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil | ||
| 178 | } else if (lua_isnoneornil(L_, 1)) { | ||
| 179 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 | ||
| 180 | } else if (!lua_isnumber(L_, 1)) { | ||
| 181 | raise_luaL_argerror(L_, StackIndex{ 1 }, "duration must be a number"); | ||
| 182 | } | ||
| 183 | else { | ||
| 184 | auto const _n{ lua_tonumber(L_, 1) }; | 177 | auto const _n{ lua_tonumber(L_, 1) }; |
| 185 | if (_n < 0) { | 178 | if (_n < 0) { |
| 186 | raise_luaL_argerror(L_, StackIndex{ 1 }, "duration must be >= 0"); | 179 | raise_luaL_argerror(L_, StackIndex{ 1 }, "duration must be >= 0"); |
| 187 | } | 180 | } |
| 188 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration | 181 | lua_pushvalue(L_, StackIndex{ 1 }); // L_: duration? receive() timerLinda timeout |
| 182 | } else if (lua_isnoneornil(L_, 1)) { | ||
| 183 | lua_pushnil(L_); // L_: duration? receive() timerLinda timeout | ||
| 184 | } else { | ||
| 185 | raise_luaL_argerror(L_, StackIndex{ 1 }, "duration must be a number"); | ||
| 189 | } | 186 | } |
| 190 | luaW_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key | 187 | |
| 188 | luaW_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda timeout key | ||
| 191 | STACK_CHECK(L_, 3); // 3 arguments ready | 189 | STACK_CHECK(L_, 3); // 3 arguments ready |
| 192 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... | 190 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... |
| 193 | return lua_gettop(L_) - 1; | 191 | return lua_gettop(L_) - 1; |
