aboutsummaryrefslogtreecommitdiff
path: root/src/uniquekey.h
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-03-21 15:41:54 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-03-21 15:41:54 +0100
commitf0170ce8f1a90337637d387b87280f121d0578fe (patch)
tree32065aa3470b54e6058e5f47e4931171b7ec28f2 /src/uniquekey.h
parent0b13436b835ea96ecdf930a380e9e5c8add8cb45 (diff)
downloadlanes-f0170ce8f1a90337637d387b87280f121d0578fe.tar.gz
lanes-f0170ce8f1a90337637d387b87280f121d0578fe.tar.bz2
lanes-f0170ce8f1a90337637d387b87280f121d0578fe.zip
C++ migration: REGISTRY_SET and REGISTRY_GET are gone, welcome templates and lambdas
Diffstat (limited to 'src/uniquekey.h')
-rw-r--r--src/uniquekey.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/uniquekey.h b/src/uniquekey.h
index fb98628..777d640 100644
--- a/src/uniquekey.h
+++ b/src/uniquekey.h
@@ -1,6 +1,7 @@
1#pragma once 1#pragma once
2 2
3#include "compat.h" 3#include "compat.h"
4#include "macros_and_utils.h"
4 5
5class UniqueKey 6class UniqueKey
6{ 7{
@@ -38,4 +39,17 @@ class UniqueKey
38 // unfortunately, converting a scalar to a pointer must go through a C cast 39 // unfortunately, converting a scalar to a pointer must go through a C cast
39 return lua_touserdata(L, i) == (void*) m_storage; 40 return lua_touserdata(L, i) == (void*) m_storage;
40 } 41 }
42 void query_registry(lua_State* const L) const
43 {
44 push(L);
45 lua_rawget(L, LUA_REGISTRYINDEX);
46 }
47 template <typename OP>
48 void set_registry(lua_State* L, OP operation_) const
49 {
50 // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever)
51 push(L); // ... key
52 operation_(L); // ... key value
53 lua_rawset(L, LUA_REGISTRYINDEX); // ...
54 }
41}; 55};