Skip to content

Commit

Permalink
mark ref_id const
Browse files Browse the repository at this point in the history
  • Loading branch information
peacalm committed Jun 26, 2023
1 parent bc627b8 commit 863ac1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/peacalm/luaw.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class luaw {
if (L) {
lua_pushvalue(L, idx); // make a copy
// pops the value on top and returns its ref_id.
int ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
const int ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
ref_sptr_.reset(new int(ref_id), [L](const int* p) {
luaL_unref(L, LUA_REGISTRYINDEX, *p);
delete p;
Expand Down Expand Up @@ -2894,8 +2894,8 @@ struct luaw::convertor<luaw::placeholder_tag> {
template <typename Return, typename... Args>
class luaw::function<Return(Args...)> {
// component
lua_State* L_ = nullptr;
std::shared_ptr<int> ref_sptr_;
lua_State* L_ = nullptr;
std::shared_ptr<const int> ref_sptr_;
// parameters put in
bool disable_log_ = false;
// states put out
Expand Down Expand Up @@ -2931,8 +2931,8 @@ class luaw::function<Return(Args...)> {
}

lua_pushvalue(L_, idx);
int ref_ = luaL_ref(L, LUA_REGISTRYINDEX);
ref_sptr_.reset(new int(ref_), [L](int* p) {
const int ref_id = luaL_ref(L, LUA_REGISTRYINDEX);
ref_sptr_.reset(new int(ref_id), [L](const int* p) {
luaL_unref(L, LUA_REGISTRYINDEX, *p);
delete p;
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit_test/register_member.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,4 +1325,4 @@ TEST(register_member, luavalueref) {

l.lset("foo", "a", "x", 1);
EXPECT_EQ(l.eval<int>("return foo.a.x"), 1);
}
}

0 comments on commit 863ac1f

Please sign in to comment.