objc.odin 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package objc_Foundation
  2. foreign import "system:Foundation.framework"
  3. // NOTE: Most of our bindings are reliant on Cocoa (everything under appkit) so just unconditionally import it
  4. @(require) foreign import "system:Cocoa.framework"
  5. import "base:intrinsics"
  6. import "core:c"
  7. IMP :: proc "c" (object: id, sel: SEL, #c_vararg args: ..any) -> id
  8. foreign Foundation {
  9. objc_getMetaClass :: proc "c" (name: cstring) -> id ---
  10. objc_lookUpClass :: proc "c" (name: cstring) -> Class ---
  11. objc_allocateClassPair :: proc "c" (superclass : Class, name : cstring, extraBytes : c.size_t) -> Class ---
  12. objc_registerClassPair :: proc "c" (cls : Class) ---
  13. sel_registerName :: proc "c" (name: cstring) -> SEL ---
  14. class_addMethod :: proc "c" (cls: Class, name: SEL, imp: IMP, types: cstring) -> BOOL ---
  15. class_getInstanceMethod :: proc "c" (cls: Class, name: SEL) -> Method ---
  16. class_createInstance :: proc "c" (cls: Class, extraBytes: c.size_t) -> id ---
  17. method_setImplementation :: proc "c" (method: Method, imp: IMP) ---
  18. object_getClass :: proc "c" (obj: id) -> Class ---
  19. object_setClass :: proc "c" (obj: id, cls: Class) -> Class ---
  20. object_getClassName :: proc "c" (obj: id) -> cstring ---
  21. object_getIndexedIvars :: proc "c" (obj: id) -> rawptr ---
  22. }
  23. @(objc_class="NSZone")
  24. Zone :: struct {using _: Object}
  25. @(link_prefix="NS")
  26. foreign Foundation {
  27. AllocateObject :: proc "c" (aClass: Class, extraBytes: UInteger, zone: ^Zone) -> id ---
  28. DeallocateObject :: proc "c" (object: id) ---
  29. }
  30. Method :: ^objc_method
  31. objc_method :: struct {
  32. method_name: SEL,
  33. method_types: cstring,
  34. method_imp: IMP,
  35. }
  36. objc_method_list :: struct {}
  37. objc_ivar :: struct {}
  38. objc_ivar_list :: struct {}
  39. objc_cache :: struct {
  40. mask: u32,
  41. occupied: u32,
  42. buckets: [1]Method,
  43. }
  44. objc_protocol_list :: struct {
  45. next: ^objc_protocol_list,
  46. count: c.int,
  47. list: [1]^Protocol,
  48. }
  49. @(objc_class="Protocol")
  50. Protocol :: struct{using _: intrinsics.objc_object}
  51. objc_object_internals :: struct {
  52. isa: ^objc_class_internals,
  53. }
  54. objc_class_internals :: struct {
  55. isa: Class,
  56. super_class: Class,
  57. name: cstring,
  58. version: c.long,
  59. info: c.long,
  60. instance_size: c.long,
  61. ivars: ^objc_ivar_list,
  62. methodLists: ^^objc_method_list,
  63. cache: rawptr,
  64. protocols: rawptr,
  65. }