| 733 | } |
| 734 | |
| 735 | static bool resolve_lua_table(DynamicString &table_prefix, lua_State *L, const char *table_path) |
| 736 | { |
| 737 | lua_getglobal(L, "_G"); |
| 738 | table_prefix = ""; |
| 739 | if (table_path[0] == '\0') |
| 740 | return true; |
| 741 | |
| 742 | const char *segment = table_path; |
| 743 | const char *cursor = table_path; |
| 744 | for (;;) { |
| 745 | if (*cursor == '.' || *cursor == '\0') { |
| 746 | if (cursor == segment) { |
| 747 | lua_pop(L, 1); |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | char key[128]; |
| 752 | const u32 key_len = u32(cursor - segment); |
| 753 | const u32 copy_len = key_len < countof(key) - 1 ? key_len : countof(key) - 1; |
| 754 | memcpy(key, segment, copy_len); |
| 755 | key[copy_len] = '\0'; |
| 756 | |
| 757 | lua_getfield(L, -1, key); |
| 758 | lua_remove(L, -2); |
| 759 | if (!lua_istable(L, -1)) { |
| 760 | lua_pop(L, 1); |
| 761 | return false; |
| 762 | } |
| 763 | |
| 764 | table_prefix += key; |
| 765 | table_prefix += "."; |
| 766 | |
| 767 | if (*cursor == '\0') |
| 768 | break; |
| 769 | |
| 770 | segment = cursor + 1; |
| 771 | } |
| 772 | ++cursor; |
| 773 | } |
| 774 | |
| 775 | return true; |
| 776 | } |
| 777 | |
| 778 | static void console_command_suggest(ConsoleServer &cs, u32 client_id, const char *json, void *user_data) |
| 779 | { |
no test coverage detected