Skip to content

Commit

Permalink
为方法中的回调参数生成文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Daylily-Zeleen committed Jan 6, 2025
1 parent 98d4ca5 commit cee2b5a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions gd_eos/eos_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ def __is_api_version_field(type: str, name: str) -> bool:
return type == "int32_t" and name == "ApiVersion"


def __get_struct_fields(type: str) -> dict[str, str]:
def __get_struct_fields(type: str) -> dict[str, dict]:
return structs[_decay_eos_type(type)]["fields"]


Expand Down Expand Up @@ -2350,7 +2350,7 @@ def _gen_method(
if method_name == "EOS_Logging_SetCallback":
declare_args.append(f"const Callable& p_{snake_name}")
bind_args.append(f'"{snake_name}"')
prepare_lines.append(f"EOS::get_log_message_callback() = p_{snake_name};")
prepare_lines.append(f"\tEOS::get_log_message_callback() = p_{snake_name};")
else:
# 回调参数
declare_args.append(f"const Callable& p_{snake_name} = {{}}")
Expand Down Expand Up @@ -2382,7 +2382,8 @@ def _gen_method(
call_args.append(f"{_gen_callback(decayed_type, [])}")

bind_defvals.append("DEFVAL(Callable())")

# 插入回调的文档
expended_args_doc[name] = __make_callback_doc(decayed_type)
elif __is_client_data(type, name):
# Client Data, 必定配合回调使用
next_decayed_type = _decay_eos_type(info["args"][i + 1]["type"])
Expand Down Expand Up @@ -4065,6 +4066,31 @@ def _get_callback_infos(callback_type: str) -> dict:
exit(1)


def __make_callback_doc(callback_type: str) -> list[str]:
info = _get_callback_infos(callback_type)
ret :list[str] = []

for arg in info["args"]:
name = arg["name"]
type = arg["type"]
decayed_type = _decay_eos_type(type)
if not _is_expanded_struct(decayed_type):
ret.append(f"{name}: {type}\n")
for l in structs[decayed_type]["doc"]:
ret.append(f"\t{l}")
else:
arg_fields = __get_struct_fields(decayed_type)

for f in arg_fields:
info = arg_fields[f]
f_type = info["type"]
ret.append(f"{f}: {f_type}\n")
for l in info["doc"]:
ret.append(f"\t{l}\n")

return ret


def _insert_doc_property(typename: str, prop: str, doc: list[str]):
lines :list[str] = __get_doc_file(typename=typename)
if len(lines) == 0:
Expand Down Expand Up @@ -4137,7 +4163,7 @@ def _insert_doc_method(typename: str, method: str, doc: list[str], additional_ar
__insert_doc_to(lines, insert_idx, doc, indent_count)
if len(additional_args_doc) > 0:
insert_idx += len(doc)
__insert_doc_to(lines, insert_idx, ["\n", "-------------- Expanded Struct Fileds --------------\n"], indent_count)
__insert_doc_to(lines, insert_idx, ["\n", "-------------- Arguments Additional Descriptions --------------\n"], indent_count)
insert_idx += 2

for arg in additional_args_doc:
Expand Down

0 comments on commit cee2b5a

Please sign in to comment.