diff options
Diffstat (limited to 'src/lindafactory.cpp')
-rw-r--r-- | src/lindafactory.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp index 9bc56d9..015baf4 100644 --- a/src/lindafactory.cpp +++ b/src/lindafactory.cpp | |||
@@ -103,8 +103,7 @@ std::string_view LindaFactory::moduleName() const | |||
103 | 103 | ||
104 | DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const | 104 | DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const |
105 | { | 105 | { |
106 | size_t _name_len{ 0 }; | 106 | std::string_view _linda_name{}; |
107 | char const* _linda_name{ nullptr }; | ||
108 | LindaGroup _linda_group{ 0 }; | 107 | LindaGroup _linda_group{ 0 }; |
109 | // should have a string and/or a number of the stack as parameters (name and group) | 108 | // should have a string and/or a number of the stack as parameters (name and group) |
110 | switch (lua_gettop(L_)) { | 109 | switch (lua_gettop(L_)) { |
@@ -113,14 +112,14 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const | |||
113 | 112 | ||
114 | case 1: // 1 parameter, either a name or a group | 113 | case 1: // 1 parameter, either a name or a group |
115 | if (lua_type(L_, -1) == LUA_TSTRING) { | 114 | if (lua_type(L_, -1) == LUA_TSTRING) { |
116 | _linda_name = lua_tolstring(L_, -1, &_name_len); | 115 | _linda_name = lua_tostringview(L_, -1); |
117 | } else { | 116 | } else { |
118 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; | 117 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; |
119 | } | 118 | } |
120 | break; | 119 | break; |
121 | 120 | ||
122 | case 2: // 2 parameters, a name and group, in that order | 121 | case 2: // 2 parameters, a name and group, in that order |
123 | _linda_name = lua_tolstring(L_, -2, &_name_len); | 122 | _linda_name = lua_tostringview(L_, -2); |
124 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; | 123 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; |
125 | break; | 124 | break; |
126 | } | 125 | } |
@@ -128,6 +127,6 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const | |||
128 | // The deep data is allocated separately of Lua stack; we might no longer be around when last reference to it is being released. | 127 | // The deep data is allocated separately of Lua stack; we might no longer be around when last reference to it is being released. |
129 | // 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 | 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 |
130 | Universe* const _U{ universe_get(L_) }; | 129 | Universe* const _U{ universe_get(L_) }; |
131 | Linda* const _linda{ new (_U) Linda{ _U, _linda_group, _linda_name, _name_len } }; | 130 | Linda* const _linda{ new (_U) Linda{ _U, _linda_group, _linda_name.data(), _linda_name.size() } }; |
132 | return _linda; | 131 | return _linda; |
133 | } | 132 | } |