MCPcopy Create free account
hub / github.com/defold/defold / LuaPPrint

Function LuaPPrint

engine/script/src/script.cpp:618–652  ·  view source on GitHub ↗

pretty printing * Pretty printing of Lua values. This function prints Lua values * in a manner similar to +print()+, but will also recurse into tables * and pretty print them. There is a limit to how deep the function * will recurse. * * @name pprint * @param v [type:any] value to print * @examples * * Pretty printing a Lua table with a nested tabl

Source from the content-addressed store, hash-verified

616 * ```
617 */
618 int LuaPPrint(lua_State* L)
619 {
620 DM_LUA_STACK_CHECK(L, 0);
621 int n = lua_gettop(L);
622
623 char buf[dmLog::MAX_STRING_SIZE];
624 dmPPrint::Printer printer(buf, sizeof(buf));
625 dmHashTable<uintptr_t, bool> printed_tables;
626 for (int s = 1; s <= n; ++s)
627 {
628 printed_tables.Clear();
629 if (lua_type(L, s) == LUA_TTABLE)
630 {
631 if (s == 1)
632 {
633 printer.Printf("\n");
634 }
635 DoLuaPPrintTable(L, s, &printer, printed_tables);
636 printer.Printf("%s", (n > s) ? ",\n" : "");
637 }
638 else
639 {
640 const char* value_str = PushValueAsString(L, s);
641 if (value_str == 0x0)
642 {
643 return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
644 }
645 printer.Printf("%s%s", value_str, (n > s) ? ",\n" : "");
646 lua_pop(L, 1);
647 }
648 }
649
650 dmLogUserDebug("%s", buf);
651 return 0;
652 }
653
654 HContext GetScriptContext(lua_State* L)
655 {

Callers

nothing calls this directly

Calls 7

lua_gettopFunction · 0.85
lua_typeFunction · 0.85
DoLuaPPrintTableFunction · 0.85
PushValueAsStringFunction · 0.85
luaL_errorFunction · 0.85
PrintfMethod · 0.80
ClearMethod · 0.45

Tested by

no test coverage detected