diff options
Diffstat (limited to '')
-rw-r--r-- | src/lindafactory.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
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 | ||
104 | DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const | 104 | DeepPrelude* 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_) }; |