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

Function DoLuaPPrintTable

engine/script/src/script.cpp:480–582  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478 }
479
480 static int DoLuaPPrintTable(lua_State* L, int index, dmPPrint::Printer* printer, dmHashTable<uintptr_t, bool>& printed_tables) {
481 DM_LUA_STACK_CHECK(L, 0);
482
483 const void* table_data = (const void*)lua_topointer(L, index);
484
485 if (printed_tables.Get((uintptr_t)table_data) != 0x0)
486 {
487 printer->Printf("{ ... } --[[%p]]", table_data);
488 return 0;
489 }
490
491 if (printed_tables.Capacity() == printed_tables.Size())
492 {
493 uint32_t new_capacity = printed_tables.Capacity() + 10;
494 printed_tables.SetCapacity((new_capacity * 2) / 3, new_capacity * 2);
495 }
496 printed_tables.Put((uintptr_t)table_data, true);
497
498 lua_pushvalue(L, index);
499 lua_pushnil(L);
500 // [-2] table
501 // [-1] key
502
503 if(lua_next(L, -2) == 0)
504 {
505 // [-1] table
506 printer->Printf("{ } --[[%p]]", table_data);
507 lua_pop(L, 1);
508 return 0;
509 }
510
511 // [-3] table
512 // [-2] key
513 // [-1] value
514 printer->Printf("{ --[[%p]]", table_data);
515 printer->Indent(2);
516
517 bool is_first = true;
518 do
519 {
520 printer->Printf("%s\n", is_first ? "" : ",");
521 int value_type = lua_type(L, -1);
522
523 const char* key_string = PushValueAsString(L, -2);
524 if (key_string == 0x0)
525 {
526 return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
527 }
528 // [-4] table
529 // [-3] key
530 // [-2] value
531 // [-1] key name
532
533 printer->Printf("%s = ", key_string);
534 lua_pop(L, 1);
535 // [-3] table
536 // [-2] key
537 // [-1] value

Callers 1

LuaPPrintFunction · 0.85

Calls 15

lua_topointerFunction · 0.85
lua_pushvalueFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_typeFunction · 0.85
PushValueAsStringFunction · 0.85
luaL_errorFunction · 0.85
PrintfMethod · 0.80
GetMethod · 0.45
CapacityMethod · 0.45
SizeMethod · 0.45
SetCapacityMethod · 0.45

Tested by

no test coverage detected