MCPcopy Create free account
hub / github.com/crownengine/crown / console_command_suggest

Function console_command_suggest

src/lua/lua_environment.cpp:778–898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778static void console_command_suggest(ConsoleServer &cs, u32 client_id, const char *json, void *user_data)
779{
780 TempAllocator4096 ta;
781 JsonObject obj(ta);
782 DynamicString expr(ta);
783 DynamicString token(ta);
784 DynamicString table_path(ta);
785 DynamicString key_prefix(ta);
786 DynamicString table_prefix(ta);
787 s32 request_id;
788 StringStream ss(ta);
789
790 sjson::parse(obj, json);
791 sjson::parse_verbatim(expr, obj["expr"]);
792 const s32 requested_limit = json_object::has(obj, "limit")
793 ? sjson::parse_int(obj["limit"])
794 : 1000
795 ;
796 const s32 max_emitted = max(0, requested_limit);
797 request_id = sjson::parse_int(obj["id"]);
798
799 // Extract the identifier token at the end of the typed expression.
800 const char *str = expr.c_str();
801 const u32 len = strlen32(str);
802 u32 token_start = len;
803 while (token_start > 0 && is_lua_identifier_char(str[token_start - 1]))
804 --token_start;
805
806 token = "";
807 table_path = "";
808 key_prefix = "";
809 if (token_start < len)
810 token += str + token_start;
811
812 // Split token into table path and key prefix for completion filtering.
813 if (token.length() > 0) {
814 const char *dot = strrchr(token.c_str(), '.');
815 if (dot != NULL) {
816 table_path.set(token.c_str(), u32(dot - token.c_str()));
817 key_prefix += dot + 1;
818 } else {
819 key_prefix += token.c_str();
820 }
821 }
822
823 // Start response and resolve the target table from the dotted path.
824 lua_State *L = ((LuaEnvironment *)user_data)->L;
825 ss << "{\"type\":\"expr_suggestions\",\"id\":";
826 ss << request_id;
827 ss << ",\"items\":[";
828 if (token.length() == 0 || !resolve_lua_table(table_prefix, L, table_path.c_str())) {
829 ss << "]}";
830 cs.send(client_id, string_stream::c_str(ss));
831 return;
832 }
833
834 bool first = true;
835 const char *prefix = key_prefix.c_str();

Callers

nothing calls this directly

Calls 15

parse_verbatimFunction · 0.85
is_lua_identifier_charFunction · 0.85
resolve_lua_tableFunction · 0.85
is_lua_identifierFunction · 0.85
append_suggestion_itemFunction · 0.85
sendMethod · 0.80
parseFunction · 0.50
hasFunction · 0.50
parse_intFunction · 0.50
maxFunction · 0.50
lua_pushnilFunction · 0.50
lua_nextFunction · 0.50

Tested by

no test coverage detected