diff options
Diffstat (limited to 'src/keeper.cpp')
-rw-r--r-- | src/keeper.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/keeper.cpp b/src/keeper.cpp index b0ed062..ff5fe26 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -45,6 +45,7 @@ | |||
45 | 45 | ||
46 | #include <algorithm> | 46 | #include <algorithm> |
47 | #include <cassert> | 47 | #include <cassert> |
48 | #include <ranges> | ||
48 | 49 | ||
49 | // ################################################################################################# | 50 | // ################################################################################################# |
50 | // Keeper implementation | 51 | // Keeper implementation |
@@ -112,7 +113,7 @@ static void fifo_push(lua_State* L_, keeper_fifo* fifo_, int count_) | |||
112 | int const _idx{ lua_gettop(L_) - count_ }; | 113 | int const _idx{ lua_gettop(L_) - count_ }; |
113 | int const _start{ fifo_->first + fifo_->count - 1 }; | 114 | int const _start{ fifo_->first + fifo_->count - 1 }; |
114 | // pop all additional arguments, storing them in the fifo | 115 | // pop all additional arguments, storing them in the fifo |
115 | for (int _i = count_; _i >= 1; --_i) { | 116 | for (int const _i : std::ranges::reverse_view{ std::ranges::iota_view{ 1, count_ + 1 } }) { |
116 | // store in the fifo the value at the top of the stack at the specified index, popping it from the stack | 117 | // store in the fifo the value at the top of the stack at the specified index, popping it from the stack |
117 | lua_rawseti(L_, _idx, _start + _i); | 118 | lua_rawseti(L_, _idx, _start + _i); |
118 | } | 119 | } |
@@ -126,10 +127,10 @@ static void fifo_push(lua_State* L_, keeper_fifo* fifo_, int count_) | |||
126 | // expects exactly 1 value on the stack! | 127 | // expects exactly 1 value on the stack! |
127 | // currently only called with a count of 1, but this may change in the future | 128 | // currently only called with a count of 1, but this may change in the future |
128 | // function assumes that there is enough data in the fifo to satisfy the request | 129 | // function assumes that there is enough data in the fifo to satisfy the request |
129 | static void fifo_peek(lua_State* L_, keeper_fifo* fifo_, int count_) | 130 | static void fifo_peek(lua_State* const L_, keeper_fifo const* const fifo_, int const count_) |
130 | { | 131 | { |
131 | STACK_GROW(L_, count_); | 132 | STACK_GROW(L_, count_); |
132 | for (int _i = 0; _i < count_; ++_i) { | 133 | for (int const _i : std::ranges::iota_view{ 0, count_ }) { |
133 | lua_rawgeti(L_, 1, (fifo_->first + _i)); | 134 | lua_rawgeti(L_, 1, (fifo_->first + _i)); |
134 | } | 135 | } |
135 | } | 136 | } |
@@ -145,20 +146,20 @@ static void fifo_pop(lua_State* L_, keeper_fifo* fifo_, int count_) | |||
145 | // each iteration pushes a value on the stack! | 146 | // each iteration pushes a value on the stack! |
146 | STACK_GROW(L_, count_ + 2); | 147 | STACK_GROW(L_, count_ + 2); |
147 | // skip first item, we will push it last | 148 | // skip first item, we will push it last |
148 | for (int i = 1; i < count_; ++i) { | 149 | for (int const _i : std::ranges::iota_view{ 1, count_ }) { |
149 | int const at{ fifo_->first + i }; | 150 | int const _at{ fifo_->first + _i }; |
150 | // push item on the stack | 151 | // push item on the stack |
151 | lua_rawgeti(L_, _fifo_idx, at); // L_: ... fifotbl val | 152 | lua_rawgeti(L_, _fifo_idx, _at); // L_: ... fifotbl val |
152 | // remove item from the fifo | 153 | // remove item from the fifo |
153 | lua_pushnil(L_); // L_: ... fifotbl val nil | 154 | lua_pushnil(L_); // L_: ... fifotbl val nil |
154 | lua_rawseti(L_, _fifo_idx, at); // L_: ... fifotbl val | 155 | lua_rawseti(L_, _fifo_idx, _at); // L_: ... fifotbl val |
155 | } | 156 | } |
156 | // now process first item | 157 | // now process first item |
157 | { | 158 | { |
158 | int const at{ fifo_->first }; | 159 | int const _at{ fifo_->first }; |
159 | lua_rawgeti(L_, _fifo_idx, at); // L_: ... fifotbl vals val | 160 | lua_rawgeti(L_, _fifo_idx, _at); // L_: ... fifotbl vals val |
160 | lua_pushnil(L_); // L_: ... fifotbl vals val nil | 161 | lua_pushnil(L_); // L_: ... fifotbl vals val nil |
161 | lua_rawseti(L_, _fifo_idx, at); // L_: ... fifotbl vals val | 162 | lua_rawseti(L_, _fifo_idx, _at); // L_: ... fifotbl vals val |
162 | lua_replace(L_, _fifo_idx); // L_: ... vals | 163 | lua_replace(L_, _fifo_idx); // L_: ... vals |
163 | } | 164 | } |
164 | 165 | ||