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
| 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 | { |
nothing calls this directly
no test coverage detected