aboutsummaryrefslogtreecommitdiff
path: root/src/tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.cpp')
-rw-r--r--src/tools.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/tools.cpp b/src/tools.cpp
index e7d1775..302a0df 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -78,7 +78,7 @@ static constexpr int kWriterReturnCode{ 666 };
78 // the provided writer fails with code kWriterReturnCode 78 // the provided writer fails with code kWriterReturnCode
79 // therefore, anytime we get kWriterReturnCode, 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{ luaG_dump(L_, dummy_writer, nullptr, 0) };
82 lua_pop(L_, _mustpush); 82 lua_pop(L_, _mustpush);
83 if (_dumpres == kWriterReturnCode) { 83 if (_dumpres == kWriterReturnCode) {
84 return FuncSubType::Bytecode; 84 return FuncSubType::Bytecode;
@@ -111,7 +111,7 @@ namespace tools {
111 // &b is popped at that point (-> replaced by the result) 111 // &b is popped at that point (-> replaced by the result)
112 luaL_pushresult(&_b); // L_: ... {} ... "<result>" 112 luaL_pushresult(&_b); // L_: ... {} ... "<result>"
113 STACK_CHECK(L_, 1); 113 STACK_CHECK(L_, 1);
114 return lua_tostringview(L_, -1); 114 return luaG_tostringview(L_, -1);
115 } 115 }
116 116
117} // namespace tools 117} // namespace tools
@@ -141,10 +141,10 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_)
141 // first, raise an error if the function is already known 141 // first, raise an error if the function is already known
142 lua_pushvalue(L_, -1); // L_: ... {bfc} k o o 142 lua_pushvalue(L_, -1); // L_: ... {bfc} k o o
143 lua_rawget(L_, _dest); // L_: ... {bfc} k o name? 143 lua_rawget(L_, _dest); // L_: ... {bfc} k o name?
144 std::string_view const _prevName{ lua_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object) 144 std::string_view const _prevName{ luaG_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object)
145 // push name in fqn stack (note that concatenation will crash if name is a not string or a number) 145 // push name in fqn stack (note that concatenation will crash if name is a not string or a number)
146 lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k 146 lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k
147 LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER || lua_type(L_, -1) == LUA_TSTRING); 147 LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER || luaG_type(L_, -1) == LuaType::STRING);
148 ++depth_; 148 ++depth_;
149 lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k o name? 149 lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k o name?
150 // generate name 150 // generate name
@@ -157,7 +157,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_)
157 // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name 157 // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name
158 // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded 158 // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded
159 if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { 159 if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) {
160 DEBUGSPEW_CODE(DebugSpew(_U) << lua_typename(L_, lua_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); 160 DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, luaG_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl);
161 // the previous name is 'smaller' than the one we just generated: keep it! 161 // the previous name is 'smaller' than the one we just generated: keep it!
162 lua_pop(L_, 3); // L_: ... {bfc} k 162 lua_pop(L_, 3); // L_: ... {bfc} k
163 } else { 163 } else {
@@ -171,7 +171,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_)
171 } else { 171 } else {
172 lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" 172 lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n"
173 } 173 }
174 DEBUGSPEW_CODE(DebugSpew(_U) << lua_typename(L_, lua_type(L_, -2)) << " '" << _newName << "'" << std::endl); 174 DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, luaG_type(L_, -2)) << " '" << _newName << "'" << std::endl);
175 // prepare the stack for database feed 175 // prepare the stack for database feed
176 lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" 176 lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n"
177 lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o 177 lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o
@@ -207,7 +207,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_,
207 STACK_CHECK_START_REL(L_, 0); // L_: ... {i_} 207 STACK_CHECK_START_REL(L_, 0); // L_: ... {i_}
208 208
209 // if object is a userdata, replace it by its metatable 209 // if object is a userdata, replace it by its metatable
210 if (lua_type(L_, i_) == LUA_TUSERDATA) { 210 if (luaG_type(L_, i_) == LuaType::USERDATA) {
211 lua_getmetatable(L_, i_); // L_: ... {i_} mt 211 lua_getmetatable(L_, i_); // L_: ... {i_} mt
212 lua_replace(L_, i_); // L_: ... {i_} 212 lua_replace(L_, i_); // L_: ... {i_}
213 } 213 }
@@ -236,7 +236,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_,
236 lua_pushnil(L_); // L_: ... {i_} {bfc} nil 236 lua_pushnil(L_); // L_: ... {i_} {bfc} nil
237 while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v 237 while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v
238 // just for debug, not actually needed 238 // just for debug, not actually needed
239 // std::string_view const _key{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostringview(L_, -2) : "not a string" }; 239 // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : "not a string" };
240 // subtable: process it recursively 240 // subtable: process it recursively
241 if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {} 241 if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {}
242 // increment visit count to make sure we will actually scan it at this recursive level 242 // increment visit count to make sure we will actually scan it at this recursive level
@@ -266,13 +266,13 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_,
266 ++depth_; 266 ++depth_;
267 lua_pushnil(L_); // L_: ... {i_} {bfc} nil 267 lua_pushnil(L_); // L_: ... {i_} {bfc} nil
268 while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} 268 while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {}
269 DEBUGSPEW_CODE(std::string_view const _key{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostringview(L_, -2) : std::string_view{ "<not a string>" } }); 269 DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : std::string_view{ "<not a string>" } });
270 DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); 270 DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl);
271 DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); 271 DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U });
272 // un-visit this table in case we do need to process it 272 // un-visit this table in case we do need to process it
273 lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} 273 lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {}
274 lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n 274 lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n
275 LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER); 275 LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER);
276 _visit_count = lua_tointeger(L_, -1) - 1; 276 _visit_count = lua_tointeger(L_, -1) - 1;
277 lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} 277 lua_pop(L_, 1); // L_: ... {i_} {bfc} k {}
278 lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} 278 lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {}
@@ -317,23 +317,23 @@ namespace tools {
317 int const _dbIdx{ lua_gettop(L_) }; 317 int const _dbIdx{ lua_gettop(L_) };
318 STACK_CHECK(L_, 1); 318 STACK_CHECK(L_, 1);
319 LUA_ASSERT(L_, lua_istable(L_, -1)); 319 LUA_ASSERT(L_, lua_istable(L_, -1));
320 if (lua_type(L_, _in_base) == LUA_TFUNCTION) { // for example when a module is a simple function 320 if (luaG_type(L_, _in_base) == LuaType::FUNCTION) { // for example when a module is a simple function
321 if (_name.empty()) { 321 if (_name.empty()) {
322 _name = "nullptr"; 322 _name = "nullptr";
323 } 323 }
324 lua_pushvalue(L_, _in_base); // L_: {} f 324 lua_pushvalue(L_, _in_base); // L_: {} f
325 std::ignore = lua_pushstringview(L_, _name); // L_: {} f name_ 325 std::ignore = luaG_pushstringview(L_, _name); // L_: {} f name_
326 lua_rawset(L_, -3); // L_: {} 326 lua_rawset(L_, -3); // L_: {}
327 std::ignore = lua_pushstringview(L_, _name); // L_: {} name_ 327 std::ignore = luaG_pushstringview(L_, _name); // L_: {} name_
328 lua_pushvalue(L_, _in_base); // L_: {} name_ f 328 lua_pushvalue(L_, _in_base); // L_: {} name_ f
329 lua_rawset(L_, -3); // L_: {} 329 lua_rawset(L_, -3); // L_: {}
330 lua_pop(L_, 1); // L_: 330 lua_pop(L_, 1); // L_:
331 } else if (lua_type(L_, _in_base) == LUA_TTABLE) { 331 } else if (luaG_type(L_, _in_base) == LuaType::TABLE) {
332 lua_newtable(L_); // L_: {} {fqn} 332 lua_newtable(L_); // L_: {} {fqn}
333 int _startDepth{ 0 }; 333 int _startDepth{ 0 };
334 if (!_name.empty()) { 334 if (!_name.empty()) {
335 STACK_CHECK(L_, 2); 335 STACK_CHECK(L_, 2);
336 std::ignore = lua_pushstringview(L_, _name); // L_: {} {fqn} "name" 336 std::ignore = luaG_pushstringview(L_, _name); // L_: {} {fqn} "name"
337 // generate a name, and if we already had one name, keep whichever is the shorter 337 // generate a name, and if we already had one name, keep whichever is the shorter
338 lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t 338 lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t
339 update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" 339 update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name"
@@ -348,7 +348,7 @@ namespace tools {
348 lua_pop(L_, 3); // L_: 348 lua_pop(L_, 3); // L_:
349 } else { 349 } else {
350 lua_pop(L_, 1); // L_: 350 lua_pop(L_, 1); // L_:
351 raise_luaL_error(L_, "unsupported module type %s", lua_typename(L_, lua_type(L_, _in_base))); 351 raise_luaL_error(L_, "unsupported module type %s", luaG_typename(L_, luaG_type(L_, _in_base)));
352 } 352 }
353 STACK_CHECK(L_, 0); 353 STACK_CHECK(L_, 0);
354 } 354 }
@@ -366,7 +366,7 @@ namespace tools {
366 +[](lua_State* L_) 366 +[](lua_State* L_)
367 { 367 {
368 int const _args{ lua_gettop(L_) }; // L_: args... 368 int const _args{ lua_gettop(L_) }; // L_: args...
369 //[[maybe_unused]] std::string_view const _modname{ luaL_checkstringview(L_, 1) }; 369 //[[maybe_unused]] std::string_view const _modname{ luaG_checkstringview(L_, 1) };
370 370
371 STACK_GROW(L_, 1); 371 STACK_GROW(L_, 1);
372 372