diff --git a/runtime/function_description.ml b/runtime/function_description.ml index 43d48dc8..4ea746a9 100644 --- a/runtime/function_description.ml +++ b/runtime/function_description.ml @@ -172,5 +172,11 @@ module Functions = struct (** Returns the name of a protocol. *) let get_name = foreign "protocol_getName" (_Protocol @-> returning string) + + (** Returns an array of method descriptions of methods meeting a given + specification for a given protocol. *) + let get_method_descriptions = + foreign "protocol_copyMethodDescriptionList" + (_Protocol @-> bool @-> bool @-> ptr uint @-> returning (ptr Method_description.t)) end end \ No newline at end of file diff --git a/runtime/inspect.ml b/runtime/inspect.ml index 97610f00..cdd5a88f 100644 --- a/runtime/inspect.ml +++ b/runtime/inspect.ml @@ -120,4 +120,25 @@ let method_names cls = |> List.map Method.get_name |> List.map Sel.get_name |> List.sort String.compare -;; \ No newline at end of file +;; + +let protocol_methods + ?(required = false) + ?(instance = true) + proto + = + let count = allocate uint Unsigned.UInt.zero in + let pm = Protocol.get_method_descriptions proto required instance count in + CArray.from_ptr pm (Unsigned.UInt.to_int (!@ count)) + |> CArray.to_list +;; + +let protocol_method_names + ?(required = false) + ?(instance = true) + proto + = + protocol_methods ~required ~instance proto + |> List.map Method_description.name + |> List.sort String.compare +;; diff --git a/runtime/type_description.ml b/runtime/type_description.ml index fa038086..4d0629f6 100644 --- a/runtime/type_description.ml +++ b/runtime/type_description.ml @@ -30,6 +30,17 @@ module Types = struct type ivar_t = objc_ivar structure ptr type _Enc = string + module Method_description = struct + let t : [`Method_desc] structure typ = structure "objc_method_description" + let name = field t "name" string + let types = field t "types" string + + let () = seal t + + let name t = getf t name + let types t = getf t types + end + let id = ptr void let _Class = ptr void let _SEL = ptr objc_selector