MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / skr_lua_log

Function skr_lua_log

modules/engine/lua/src/build.skr_lua.cpp:482–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

480
481template<int level>
482int skr_lua_log(lua_State* L)
483{
484 lua_Debug ar;
485 lua_getinfo(L, 1, "nSl", &ar);
486 auto str = skr::format(u8"[{} : {}]:\t", (uint64_t)ar.what, (const char8_t*)ar.name);
487 int top = lua_gettop(L);
488 for(int n=1;n<=top;n++) {
489 size_t len;
490 const char8_t* s = (const char8_t*)luaL_tolstring(L, n, &len);
491 str += u8"\t";
492 //TODO: use string builder?
493 if(s) str += s;
494 }
495 const int line = ar.currentline;
496 auto src = (const char8_t*)ar.source;
497 if(line != -1)
498 {
499 skr::stl_u8string_view Source(src);
500 if (Source.ends_with(u8".lua"))
501 Source = Source.substr(0, Source.size() - 4);
502 if (Source.starts_with(u8"@"))
503 Source = Source.substr(1);
504 skr::Vector<skr::stl_u8string_view> tokens;
505 split(Source, tokens, u8"/");
506
507 const auto modulename = join(tokens, u8".");
508 auto lstr = skr::format(u8"{}", line);
509 skr_log_log(level, (const char*)modulename.c_str(), "unknown", lstr.c_str(), str.u8_str());
510 }
511 else
512 {
513 skr_log_log(level, "unknown", "unknown", 0, str.u8_str());
514 }
515 return 0;
516}
517
518void bind_skr_log(lua_State* L)
519{

Callers

nothing calls this directly

Calls 13

skr_log_logFunction · 0.85
splitFunction · 0.70
joinFunction · 0.70
lua_getinfoFunction · 0.50
formatFunction · 0.50
lua_gettopFunction · 0.50
luaL_tolstringFunction · 0.50
ends_withMethod · 0.45
substrMethod · 0.45
sizeMethod · 0.45
starts_withMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected