Skip to content

Commit

Permalink
Inspect protocol methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboris committed Oct 11, 2024
1 parent badd0a2 commit 9b92610
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions runtime/function_description.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 22 additions & 1 deletion runtime/inspect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,25 @@ let method_names cls =
|> List.map Method.get_name
|> List.map Sel.get_name
|> List.sort String.compare
;;
;;

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
;;
11 changes: 11 additions & 0 deletions runtime/type_description.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b92610

Please sign in to comment.