aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-05-20 11:48:41 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-05-20 11:48:41 +0200
commit0ec260c12ee6a37e763bc60ef587dbd891136e76 (patch)
tree26a738c47f8a4c264546feb5bccb507b3330456a /src
parent08040747494fe7839d2ab049e37f8e23fb8141b4 (diff)
downloadlanes-0ec260c12ee6a37e763bc60ef587dbd891136e76.tar.gz
lanes-0ec260c12ee6a37e763bc60ef587dbd891136e76.tar.bz2
lanes-0ec260c12ee6a37e763bc60ef587dbd891136e76.zip
Start using string_view
Diffstat (limited to 'src')
-rw-r--r--src/deep.cpp8
-rw-r--r--src/deep.h3
-rw-r--r--src/intercopycontext.cpp89
-rw-r--r--src/intercopycontext.h3
-rw-r--r--src/lanes.cpp8
-rw-r--r--src/lindafactory.cpp4
-rw-r--r--src/lindafactory.h2
-rw-r--r--src/tools.cpp42
8 files changed, 81 insertions, 78 deletions
diff --git a/src/deep.cpp b/src/deep.cpp
index 2f4f1ed..5515a62 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -244,12 +244,12 @@ char const* DeepFactory::PushDeepProxy(DestState L_, DeepPrelude* prelude_, int
244 factory.storeDeepLookup(L_); 244 factory.storeDeepLookup(L_);
245 245
246 // 2 - cause the target state to require the module that exported the factory 246 // 2 - cause the target state to require the module that exported the factory
247 if (char const* const _modname{ factory.moduleName() }; _modname) { // we actually got a module name 247 if (std::string_view const _modname{ factory.moduleName() }; !_modname.empty()) { // we actually got a module name
248 // L.registry._LOADED exists without having registered the 'package' library. 248 // L.registry._LOADED exists without having registered the 'package' library.
249 lua_getglobal(L_, "require"); // DPC proxy metatable require() 249 lua_getglobal(L_, "require"); // L_: DPC proxy metatable require()
250 // check that the module is already loaded (or being loaded, we are happy either way) 250 // check that the module is already loaded (or being loaded, we are happy either way)
251 if (lua_isfunction(L_, -1)) { 251 if (lua_isfunction(L_, -1)) {
252 lua_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" 252 lua_pushlstring(L_, _modname.data(), _modname.size()); // L_: DPC proxy metatable require() "module"
253 lua_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // L_: DPC proxy metatable require() "module" _R._LOADED 253 lua_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // L_: DPC proxy metatable require() "module" _R._LOADED
254 if (lua_istable(L_, -1)) { 254 if (lua_istable(L_, -1)) {
255 lua_pushvalue(L_, -2); // L_: DPC proxy metatable require() "module" _R._LOADED "module" 255 lua_pushvalue(L_, -2); // L_: DPC proxy metatable require() "module" _R._LOADED "module"
@@ -262,7 +262,7 @@ char const* DeepFactory::PushDeepProxy(DestState L_, DeepPrelude* prelude_, int
262 require_result = lua_pcall(L_, 1, 0, 0); // L_: DPC proxy metatable error? 262 require_result = lua_pcall(L_, 1, 0, 0); // L_: DPC proxy metatable error?
263 if (require_result != LUA_OK) { 263 if (require_result != LUA_OK) {
264 // failed, return the error message 264 // failed, return the error message
265 lua_pushfstring(L_, "error while requiring '%s' identified by DeepFactory::moduleName: ", _modname); 265 lua_pushfstring(L_, "error while requiring '%s' identified by DeepFactory::moduleName: ", _modname.data());
266 lua_insert(L_, -2); // L_: DPC proxy metatable prefix error 266 lua_insert(L_, -2); // L_: DPC proxy metatable prefix error
267 lua_concat(L_, 2); // L_: DPC proxy metatable error 267 lua_concat(L_, 2); // L_: DPC proxy metatable error
268 return lua_tostring(L_, -1); 268 return lua_tostring(L_, -1);
diff --git a/src/deep.h b/src/deep.h
index 87e5329..96461d6 100644
--- a/src/deep.h
+++ b/src/deep.h
@@ -18,6 +18,7 @@ extern "C"
18#include "uniquekey.h" 18#include "uniquekey.h"
19 19
20#include <atomic> 20#include <atomic>
21#include <string_view>
21 22
22// forwards 23// forwards
23enum class LookupMode; 24enum class LookupMode;
@@ -67,7 +68,7 @@ class DeepFactory
67 [[nodiscard]] virtual DeepPrelude* newDeepObjectInternal(lua_State* L_) const = 0; 68 [[nodiscard]] virtual DeepPrelude* newDeepObjectInternal(lua_State* L_) const = 0;
68 virtual void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const = 0; 69 virtual void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const = 0;
69 virtual void createMetatable(lua_State* L_) const = 0; 70 virtual void createMetatable(lua_State* L_) const = 0;
70 [[nodiscard]] virtual char const* moduleName() const = 0; 71 [[nodiscard]] virtual std::string_view moduleName() const = 0;
71 72
72 public: 73 public:
73 // NVI: public interface 74 // NVI: public interface
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp
index e2e3d31..2f83400 100644
--- a/src/intercopycontext.cpp
+++ b/src/intercopycontext.cpp
@@ -73,60 +73,61 @@ THE SOFTWARE.
73// ################################################################################################# 73// #################################################################################################
74 74
75// retrieve the name of a function/table in the lookup database 75// retrieve the name of a function/table in the lookup database
76[[nodiscard]] static char const* find_lookup_name(lua_State* L_, int i_, LookupMode mode_, char const* upName_, size_t* len_) 76[[nodiscard]] std::string_view InterCopyContext::findLookupName() const
77{ 77{
78 LUA_ASSERT(L_, lua_isfunction(L_, i_) || lua_istable(L_, i_)); // L_: ... v ... 78 LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i)); // L1: ... v ...
79 STACK_CHECK_START_REL(L_, 0); 79 STACK_CHECK_START_REL(L1, 0);
80 STACK_GROW(L_, 3); // up to 3 slots are necessary on error 80 STACK_GROW(L1, 3); // up to 3 slots are necessary on error
81 if (mode_ == LookupMode::FromKeeper) { 81 if (mode == LookupMode::FromKeeper) {
82 lua_CFunction const _f{ lua_tocfunction(L_, i_) }; // should *always* be one of the function sentinels 82 lua_CFunction const _f{ lua_tocfunction(L1, L1_i) }; // should *always* be one of the function sentinels
83 if (_f == func_lookup_sentinel || _f == table_lookup_sentinel || _f == userdata_clone_sentinel) { 83 if (_f == func_lookup_sentinel || _f == table_lookup_sentinel || _f == userdata_clone_sentinel) {
84 lua_getupvalue(L_, i_, 1); // L_: ... v ... "f.q.n" 84 lua_getupvalue(L1, L1_i, 1); // L1: ... v ... "f.q.n"
85 } else { 85 } else {
86 // if this is not a sentinel, this is some user-created table we wanted to lookup 86 // if this is not a sentinel, this is some user-created table we wanted to lookup
87 LUA_ASSERT(L_, nullptr == _f && lua_istable(L_, i_)); 87 LUA_ASSERT(L1, nullptr == _f && lua_istable(L1, L1_i));
88 // push anything that will convert to nullptr string 88 // push anything that will convert to nullptr string
89 lua_pushnil(L_); // L_: ... v ... nil 89 lua_pushnil(L1); // L1: ... v ... nil
90 } 90 }
91 } else { 91 } else {
92 // fetch the name from the source state's lookup table 92 // fetch the name from the source state's lookup table
93 kLookupRegKey.pushValue(L_); // L_: ... v ... {} 93 kLookupRegKey.pushValue(L1); // L1: ... v ... {}
94 STACK_CHECK(L_, 1); 94 STACK_CHECK(L1, 1);
95 LUA_ASSERT(L_, lua_istable(L_, -1)); 95 LUA_ASSERT(L1, lua_istable(L1, -1));
96 lua_pushvalue(L_, i_); // L_: ... v ... {} v 96 lua_pushvalue(L1, L1_i); // L1: ... v ... {} v
97 lua_rawget(L_, -2); // L_: ... v ... {} "f.q.n" 97 lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n"
98 } 98 }
99 char const* _fqn{ lua_tolstring(L_, -1, len_) }; 99 size_t _len{ 0 };
100 DEBUGSPEW_CODE(Universe* const _U = universe_get(L_)); 100 char const* _fqn{ lua_tolstring(L1, -1, &_len) };
101 DEBUGSPEW_CODE(Universe* const _U = universe_get(L1));
101 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn)); 102 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn));
102 // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database 103 // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database
103 lua_pop(L_, (mode_ == LookupMode::FromKeeper) ? 1 : 2); // L_: ... v ... 104 lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ...
104 STACK_CHECK(L_, 0); 105 STACK_CHECK(L1, 0);
105 if (nullptr == _fqn && !lua_istable(L_, i_)) { // raise an error if we try to send an unknown function (but not for tables) 106 if (nullptr == _fqn && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function (but not for tables)
106 *len_ = 0; // just in case 107 _len = 0; // just in case
107 // try to discover the name of the function we want to send 108 // try to discover the name of the function we want to send
108 lua_getglobal(L_, "decoda_name"); // L_: ... v ... decoda_name 109 lua_getglobal(L1, "decoda_name"); // L1: ... v ... decoda_name
109 char const* from{ lua_tostring(L_, -1) }; 110 char const* from{ lua_tostring(L1, -1) };
110 lua_pushcfunction(L_, luaG_nameof); // L_: ... v ... decoda_name luaG_nameof 111 lua_pushcfunction(L1, luaG_nameof); // L1: ... v ... decoda_name luaG_nameof
111 lua_pushvalue(L_, i_); // L_: ... v ... decoda_name luaG_nameof t 112 lua_pushvalue(L1, L1_i); // L1: ... v ... decoda_name luaG_nameof t
112 lua_call(L_, 1, 2); // L_: ... v ... decoda_name "type" "name"|nil 113 lua_call(L1, 1, 2); // L1: ... v ... decoda_name "type" "name"|nil
113 char const* typewhat{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostring(L_, -2) : luaL_typename(L_, -2) }; 114 char const* typewhat{ (lua_type(L1, -2) == LUA_TSTRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) };
114 // second return value can be nil if the table was not found 115 // second return value can be nil if the table was not found
115 // probable reason: the function was removed from the source Lua state before Lanes was required. 116 // probable reason: the function was removed from the source Lua state before Lanes was required.
116 char const *what, *gotchaA, *gotchaB; 117 char const *what, *gotchaA, *gotchaB;
117 if (lua_isnil(L_, -1)) { 118 if (lua_isnil(L1, -1)) {
118 gotchaA = " referenced by"; 119 gotchaA = " referenced by";
119 gotchaB = "\n(did you remove it from the source Lua state before requiring Lanes?)"; 120 gotchaB = "\n(did you remove it from the source Lua state before requiring Lanes?)";
120 what = upName_; 121 what = name;
121 } else { 122 } else {
122 gotchaA = ""; 123 gotchaA = "";
123 gotchaB = ""; 124 gotchaB = "";
124 what = (lua_type(L_, -1) == LUA_TSTRING) ? lua_tostring(L_, -1) : luaL_typename(L_, -1); 125 what = (lua_type(L1, -1) == LUA_TSTRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1);
125 } 126 }
126 raise_luaL_error(L_, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); 127 raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB);
127 } 128 }
128 STACK_CHECK(L_, 0); 129 STACK_CHECK(L1, 0);
129 return _fqn; 130 return std::string_view{ _fqn, _len };
130} 131}
131 132
132// ################################################################################################# 133// #################################################################################################
@@ -312,8 +313,7 @@ void InterCopyContext::copy_func() const
312void InterCopyContext::lookup_native_func() const 313void InterCopyContext::lookup_native_func() const
313{ 314{
314 // get the name of the function we want to send 315 // get the name of the function we want to send
315 size_t _len; 316 std::string_view const _fqn{ findLookupName() };
316 char const* const _fqn{ find_lookup_name(L1, L1_i, mode, name, &_len) };
317 // push the equivalent function in the destination's stack, retrieved from the lookup table 317 // push the equivalent function in the destination's stack, retrieved from the lookup table
318 STACK_CHECK_START_REL(L2, 0); 318 STACK_CHECK_START_REL(L2, 0);
319 STACK_GROW(L2, 3); // up to 3 slots are necessary on error 319 STACK_GROW(L2, 3); // up to 3 slots are necessary on error
@@ -324,7 +324,7 @@ void InterCopyContext::lookup_native_func() const
324 324
325 case LookupMode::ToKeeper: 325 case LookupMode::ToKeeper:
326 // push a sentinel closure that holds the lookup name as upvalue 326 // push a sentinel closure that holds the lookup name as upvalue
327 lua_pushlstring(L2, _fqn, _len); // L1: ... f ... L2: "f.q.n" 327 lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L1: ... f ... L2: "f.q.n"
328 lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f 328 lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f
329 break; 329 break;
330 330
@@ -333,7 +333,7 @@ void InterCopyContext::lookup_native_func() const
333 kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} 333 kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {}
334 STACK_CHECK(L2, 1); 334 STACK_CHECK(L2, 1);
335 LUA_ASSERT(L1, lua_istable(L2, -1)); 335 LUA_ASSERT(L1, lua_istable(L2, -1));
336 lua_pushlstring(L2, _fqn, _len); // L1: ... f ... L2: {} "f.q.n" 336 lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L1: ... f ... L2: {} "f.q.n"
337 lua_rawget(L2, -2); // L1: ... f ... L2: {} f 337 lua_rawget(L2, -2); // L1: ... f ... L2: {} f
338 // nil means we don't know how to transfer stuff: user should do something 338 // nil means we don't know how to transfer stuff: user should do something
339 // anything other than function or table should not happen! 339 // anything other than function or table should not happen!
@@ -413,7 +413,7 @@ void InterCopyContext::copy_cached_func() const
413 // pushes a copy of the func, stores a reference in the cache 413 // pushes a copy of the func, stores a reference in the cache
414 copy_func(); // L2: ... {cache} ... function 414 copy_func(); // L2: ... {cache} ... function
415 } else { // found function in the cache 415 } else { // found function in the cache
416 lua_remove(L2, -2); // L2: ... {cache} ... function 416 lua_remove(L2, -2); // L2: ... {cache} ... function
417 } 417 }
418 STACK_CHECK(L2, 1); 418 STACK_CHECK(L2, 1);
419 LUA_ASSERT(L1, lua_isfunction(L2, -1)); 419 LUA_ASSERT(L1, lua_isfunction(L2, -1));
@@ -430,9 +430,8 @@ void InterCopyContext::copy_cached_func() const
430[[nodiscard]] bool InterCopyContext::lookup_table() const 430[[nodiscard]] bool InterCopyContext::lookup_table() const
431{ 431{
432 // get the name of the table we want to send 432 // get the name of the table we want to send
433 size_t _len; 433 std::string_view const _fqn{ findLookupName() };
434 char const* const _fqn{ find_lookup_name(L1, L1_i, mode, name, &_len) }; 434 if (_fqn.empty()) { // name not found, it is some user-created table
435 if (nullptr == _fqn) { // name not found, it is some user-created table
436 return false; 435 return false;
437 } 436 }
438 // push the equivalent table in the destination's stack, retrieved from the lookup table 437 // push the equivalent table in the destination's stack, retrieved from the lookup table
@@ -445,7 +444,7 @@ void InterCopyContext::copy_cached_func() const
445 444
446 case LookupMode::ToKeeper: 445 case LookupMode::ToKeeper:
447 // push a sentinel closure that holds the lookup name as upvalue 446 // push a sentinel closure that holds the lookup name as upvalue
448 lua_pushlstring(L2, _fqn, _len); // L1: ... t ... L2: "f.q.n" 447 lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L1: ... t ... L2: "f.q.n"
449 lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f 448 lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f
450 break; 449 break;
451 450
@@ -454,12 +453,12 @@ void InterCopyContext::copy_cached_func() const
454 kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} 453 kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {}
455 STACK_CHECK(L2, 1); 454 STACK_CHECK(L2, 1);
456 LUA_ASSERT(L1, lua_istable(L2, -1)); 455 LUA_ASSERT(L1, lua_istable(L2, -1));
457 lua_pushlstring(L2, _fqn, _len); // L2: {} "f.q.n" 456 lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L2: {} "f.q.n"
458 lua_rawget(L2, -2); // L2: {} t 457 lua_rawget(L2, -2); // L2: {} t
459 // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) 458 // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead)
460 // but not when we extract something out of a keeper, as there is nothing to clone! 459 // but not when we extract something out of a keeper, as there is nothing to clone!
461 if (lua_isnil(L2, -1) && mode == LookupMode::LaneBody) { 460 if (lua_isnil(L2, -1) && mode == LookupMode::LaneBody) {
462 lua_pop(L2, 2); // L1: ... t ... L2: 461 lua_pop(L2, 2); // L1: ... t ... L2:
463 STACK_CHECK(L2, 0); 462 STACK_CHECK(L2, 0);
464 return false; 463 return false;
465 } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table 464 } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table
@@ -932,7 +931,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const
932 931
933[[nodiscard]] bool InterCopyContext::inter_copy_string() const 932[[nodiscard]] bool InterCopyContext::inter_copy_string() const
934{ 933{
935 size_t _len; 934 size_t _len{ 0 };
936 char const* const _s{ lua_tolstring(L1, L1_i, &_len) }; 935 char const* const _s{ lua_tolstring(L1, L1_i, &_len) };
937 DEBUGSPEW_CODE(fprintf(stderr, "'%s'\n", _s)); 936 DEBUGSPEW_CODE(fprintf(stderr, "'%s'\n", _s));
938 lua_pushlstring(L2, _s, _len); 937 lua_pushlstring(L2, _s, _len);
diff --git a/src/intercopycontext.h b/src/intercopycontext.h
index 28e1ead..4f6ed89 100644
--- a/src/intercopycontext.h
+++ b/src/intercopycontext.h
@@ -2,6 +2,8 @@
2 2
3#include "tools.h" 3#include "tools.h"
4 4
5#include <string_view>
6
5// forwards 7// forwards
6class Universe; 8class Universe;
7 9
@@ -41,6 +43,7 @@ class InterCopyContext
41 // when mode == LookupMode::FromKeeper, L1 is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error 43 // when mode == LookupMode::FromKeeper, L1 is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error
42 // whon mode != LookupMode::FromKeeper, L1 is not a keeper state, therefore L1 is the state where we want to raise the error 44 // whon mode != LookupMode::FromKeeper, L1 is not a keeper state, therefore L1 is the state where we want to raise the error
43 lua_State* getErrL() const { return (mode == LookupMode::FromKeeper) ? L2 : L1; } 45 lua_State* getErrL() const { return (mode == LookupMode::FromKeeper) ? L2 : L1; }
46 [[nodiscard]] std::string_view findLookupName() const;
44 47
45 // for use in copy_cached_func 48 // for use in copy_cached_func
46 void copy_func() const; 49 void copy_func() const;
diff --git a/src/lanes.cpp b/src/lanes.cpp
index afcac1d..aa614b7 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -395,8 +395,8 @@ LUAG_FUNC(lane_new)
395 raise_luaL_error(L_, "required module list should be a list of strings"); 395 raise_luaL_error(L_, "required module list should be a list of strings");
396 } else { 396 } else {
397 // require the module in the target state, and populate the lookup table there too 397 // require the module in the target state, and populate the lookup table there too
398 size_t len; 398 size_t _len{ 0 };
399 char const* name = lua_tolstring(L_, -1, &len); 399 char const* _name{ lua_tolstring(L_, -1, &_len) };
400 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require '%s'\n" INDENT_END(_U), name)); 400 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require '%s'\n" INDENT_END(_U), name));
401 401
402 // require the module in the target lane 402 // require the module in the target lane
@@ -405,7 +405,7 @@ LUAG_FUNC(lane_new)
405 lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: 405 lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2:
406 raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); 406 raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first");
407 } else { 407 } else {
408 lua_pushlstring(_L2, name, len); // L_: [fixed] args... n "modname" L2: require() name 408 lua_pushlstring(_L2, _name, _len); // L_: [fixed] args... n "modname" L2: require() name
409 if (lua_pcall(_L2, 1, 1, 0) != LUA_OK) { // L_: [fixed] args... n "modname" L2: ret/errcode 409 if (lua_pcall(_L2, 1, 1, 0) != LUA_OK) { // L_: [fixed] args... n "modname" L2: ret/errcode
410 // propagate error to main state if any 410 // propagate error to main state if any
411 InterCopyContext _c{ _U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }; 411 InterCopyContext _c{ _U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} };
@@ -414,7 +414,7 @@ LUAG_FUNC(lane_new)
414 } 414 }
415 // here the module was successfully required // L_: [fixed] args... n "modname" L2: ret 415 // here the module was successfully required // L_: [fixed] args... n "modname" L2: ret
416 // after requiring the module, register the functions it exported in our name<->function database 416 // after requiring the module, register the functions it exported in our name<->function database
417 populate_func_lookup_table(_L2, -1, name); 417 populate_func_lookup_table(_L2, -1, _name);
418 lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: 418 lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2:
419 } 419 }
420 } 420 }
diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp
index 16c653f..9bc56d9 100644
--- a/src/lindafactory.cpp
+++ b/src/lindafactory.cpp
@@ -91,12 +91,12 @@ void LindaFactory::deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) cons
91 91
92// ################################################################################################# 92// #################################################################################################
93 93
94char const* LindaFactory::moduleName() const 94std::string_view LindaFactory::moduleName() const
95{ 95{
96 // linda is a special case because we know lanes must be loaded from the main lua state 96 // linda is a special case because we know lanes must be loaded from the main lua state
97 // to be able to ever get here, so we know it will remain loaded as long a the main state is around 97 // to be able to ever get here, so we know it will remain loaded as long a the main state is around
98 // in other words, forever. 98 // in other words, forever.
99 return nullptr; 99 return std::string_view{};
100} 100}
101 101
102// ################################################################################################# 102// #################################################################################################
diff --git a/src/lindafactory.h b/src/lindafactory.h
index 271f9a7..06eab44 100644
--- a/src/lindafactory.h
+++ b/src/lindafactory.h
@@ -21,6 +21,6 @@ class LindaFactory
21 21
22 void createMetatable(lua_State* L_) const override; 22 void createMetatable(lua_State* L_) const override;
23 void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const override; 23 void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const override;
24 [[nodiscard]] char const* moduleName() const override; 24 [[nodiscard]] std::string_view moduleName() const override;
25 [[nodiscard]] DeepPrelude* newDeepObjectInternal(lua_State* L_) const override; 25 [[nodiscard]] DeepPrelude* newDeepObjectInternal(lua_State* L_) const override;
26}; 26};
diff --git a/src/tools.cpp b/src/tools.cpp
index eff865c..8ddce75 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -44,24 +44,24 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull };
44 44
45// ################################################################################################# 45// #################################################################################################
46 46
47static constexpr int kWriterReturnCode{ 666 };
47[[nodiscard]] static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_) 48[[nodiscard]] static int dummy_writer([[maybe_unused]] lua_State* L_, [[maybe_unused]] void const* p_, [[maybe_unused]] size_t sz_, [[maybe_unused]] void* ud_)
48{ 49{
49 return 666; 50 return kWriterReturnCode;
50} 51}
51 52
52/* 53/*
53 * differentiation between C, bytecode and JIT-fast functions 54 * differentiation between C, bytecode and JIT-fast functions
54 * 55 *
55 * 56 * +-------------------+------------+----------+
56 * +----------+------------+----------+ 57 * | bytecode | C function | JIT-fast |
57 * | bytecode | C function | JIT-fast | 58 * +-----------------+-------------------+------------+----------+
58 * +-----------------+----------+------------+----------+ 59 * | lua_topointer | | | |
59 * | lua_topointer | | | | 60 * +-----------------+-------------------+------------+----------+
60 * +-----------------+----------+------------+----------+ 61 * | lua_tocfunction | nullptr | | nullptr |
61 * | lua_tocfunction | nullptr | | nullptr | 62 * +-----------------+-------------------+------------+----------+
62 * +-----------------+----------+------------+----------+ 63 * | lua_dump | kWriterReturnCode | 1 | 1 |
63 * | lua_dump | 666 | 1 | 1 | 64 * +-----------------+-------------------+------------+----------+
64 * +-----------------+----------+------------+----------+
65 */ 65 */
66 66
67[[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* L_, int _i) 67[[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* L_, int _i)
@@ -75,12 +75,12 @@ static constexpr RegistryUniqueKey kLookupCacheRegKey{ 0x9BF75F84E54B691Bull };
75 lua_pushvalue(L_, _i); 75 lua_pushvalue(L_, _i);
76 _mustpush = 1; 76 _mustpush = 1;
77 } 77 }
78 // the provided writer fails with code 666 78 // the provided writer fails with code kWriterReturnCode
79 // therefore, anytime we get 666, this means that lua_dump() attempted a dump 79 // therefore, anytime we get kWriterReturnCode, this means that lua_dump() attempted a dump
80 // all other cases mean this is either a C or LuaJIT-fast function 80 // all other cases mean this is either a C or LuaJIT-fast function
81 int const dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) }; 81 int const _dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) };
82 lua_pop(L_, _mustpush); 82 lua_pop(L_, _mustpush);
83 if (dumpres == 666) { 83 if (_dumpres == kWriterReturnCode) {
84 return FuncSubType::Bytecode; 84 return FuncSubType::Bytecode;
85 } 85 }
86 } 86 }
@@ -438,13 +438,13 @@ void populate_func_lookup_table(lua_State* L_, int i_, char const* name_)
438 lua_rawseti(L_, kFQN, depth_); // L_: o "r" {c} {fqn} ... {?} k U {mt} 438 lua_rawseti(L_, kFQN, depth_); // L_: o "r" {c} {fqn} ... {?} k U {mt}
439 --depth_; 439 --depth_;
440 } 440 }
441 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U 441 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U
442 } 442 }
443 STACK_CHECK(L_, 2); 443 STACK_CHECK(L_, 2);
444 // search in the object's uservalues 444 // search in the object's uservalues
445 { 445 {
446 int uvi = 1; 446 int _uvi{ 1 };
447 while (lua_getiuservalue(L_, -1, uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... {?} k U {u} 447 while (lua_getiuservalue(L_, -1, _uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... {?} k U {u}
448 if (lua_istable(L_, -1)) { // if it is a table, look inside 448 if (lua_istable(L_, -1)) { // if it is a table, look inside
449 ++depth_; 449 ++depth_;
450 lua_pushliteral(L_, "uservalue"); // L_: o "r" {c} {fqn} ... {?} k v {u} "uservalue" 450 lua_pushliteral(L_, "uservalue"); // L_: o "r" {c} {fqn} ... {?} k v {u} "uservalue"
@@ -455,7 +455,7 @@ void populate_func_lookup_table(lua_State* L_, int i_, char const* name_)
455 --depth_; 455 --depth_;
456 } 456 }
457 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U 457 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U
458 ++uvi; 458 ++_uvi;
459 } 459 }
460 // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now 460 // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now
461 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U 461 lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... {?} k U
@@ -510,13 +510,13 @@ int luaG_nameof(lua_State* L_)
510 lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} 510 lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn}
511 // this is where we start the search 511 // this is where we start the search
512 lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G 512 lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G
513 std::ignore = DiscoverObjectNameRecur(L_, 6666, 1); 513 std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1);
514 if (lua_isnil(L_, 2)) { // try again with registry, just in case... 514 if (lua_isnil(L_, 2)) { // try again with registry, just in case...
515 lua_pop(L_, 1); // L_: o nil {c} {fqn} 515 lua_pop(L_, 1); // L_: o nil {c} {fqn}
516 lua_pushliteral(L_, "_R"); // L_: o nil {c} {fqn} "_R" 516 lua_pushliteral(L_, "_R"); // L_: o nil {c} {fqn} "_R"
517 lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} 517 lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn}
518 lua_pushvalue(L_, LUA_REGISTRYINDEX); // L_: o nil {c} {fqn} _R 518 lua_pushvalue(L_, LUA_REGISTRYINDEX); // L_: o nil {c} {fqn} _R
519 std::ignore = DiscoverObjectNameRecur(L_, 6666, 1); 519 std::ignore = DiscoverObjectNameRecur(L_, std::numeric_limits<int>::max(), 1);
520 } 520 }
521 lua_pop(L_, 3); // L_: o "result" 521 lua_pop(L_, 3); // L_: o "result"
522 STACK_CHECK(L_, 1); 522 STACK_CHECK(L_, 1);