aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-06 17:22:45 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-06 17:22:45 +0200
commit91a34bd09900967e8b9cccdbd6d94a9f8cc8506c (patch)
tree26ca2e83a6841361ac2d104c9d06bf78edd166e5 /src
parentd9a149a230f9b320113020789beb78a883da3b40 (diff)
downloadlanes-91a34bd09900967e8b9cccdbd6d94a9f8cc8506c.tar.gz
lanes-91a34bd09900967e8b9cccdbd6d94a9f8cc8506c.tar.bz2
lanes-91a34bd09900967e8b9cccdbd6d94a9f8cc8506c.zip
lanes.linda("auto")
Diffstat (limited to 'src')
-rw-r--r--src/linda.cpp3
-rw-r--r--src/lindafactory.cpp16
2 files changed, 17 insertions, 2 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index 33d9f0b..8b6df8e 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -88,7 +88,8 @@ template <bool OPT>
88 if (!_lindaName.empty()) { 88 if (!_lindaName.empty()) {
89 std::ignore = luaG_pushstringview(L_, _lindaName); 89 std::ignore = luaG_pushstringview(L_, _lindaName);
90 } else { 90 } else {
91 lua_pushfstring(L_, "%p", _linda); 91 // obfuscate the pointer so that we can't read the value with our eyes out of a script
92 std::ignore = luaG_pushstringview(L_, "%p", std::bit_cast<uintptr_t>(_linda) ^ kConfigRegKey.storage);
92 } 93 }
93 lua_concat(L_, 2); 94 lua_concat(L_, 2);
94 return 1; 95 return 1;
diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp
index d99d546..3f4b9b0 100644
--- a/src/lindafactory.cpp
+++ b/src/lindafactory.cpp
@@ -101,7 +101,7 @@ std::string_view LindaFactory::moduleName() const
101 101
102// ################################################################################################# 102// #################################################################################################
103 103
104DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const 104DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* const L_) const
105{ 105{
106 std::string_view _linda_name{}; 106 std::string_view _linda_name{};
107 LindaGroup _linda_group{ 0 }; 107 LindaGroup _linda_group{ 0 };
@@ -124,6 +124,20 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const
124 break; 124 break;
125 } 125 }
126 126
127 // store in the linda the location of the script that created it
128 if (_linda_name == "auto") {
129 lua_Debug _ar;
130 if (lua_getstack(L_, 1, &_ar) == 1) { // 1 because we want the name of the function that called lanes.linda (where we currently are)
131 lua_getinfo(L_, "Sln", &_ar);
132 _linda_name = luaG_pushstringview(L_, "%s:%d", _ar.short_src, _ar.currentline);
133 } else {
134 _linda_name = luaG_pushstringview(L_, "<unresolved>");
135 }
136 // since the name is not empty, it is at slot 1, and we can replace "auto" with the result, just in case
137 LUA_ASSERT(L_, luaG_tostringview(L_, 1) == "auto");
138 lua_replace(L_, 1);
139 }
140
127 // The deep data is allocated separately of Lua stack; we might no longer be around when last reference to it is being released. 141 // The deep data is allocated separately of Lua stack; we might no longer be around when last reference to it is being released.
128 // One can use any memory allocation scheme. Just don't use L's allocF because we don't know which state will get the honor of GCing the linda 142 // One can use any memory allocation scheme. Just don't use L's allocF because we don't know which state will get the honor of GCing the linda
129 Universe* const _U{ Universe::Get(L_) }; 143 Universe* const _U{ Universe::Get(L_) };