objc.odin 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_lookUpClass :: proc "c" (name: cstring) -> Class ---
  10. sel_registerName :: proc "c" (name: cstring) -> SEL ---
  11. objc_allocateClassPair :: proc "c" (superclass : Class, name : cstring, extraBytes : c.size_t) -> Class ---
  12. objc_registerClassPair :: proc "c" (cls : Class) ---
  13. class_addMethod :: proc "c" (cls: Class, name: SEL, imp: IMP, types: cstring) -> BOOL ---
  14. class_getInstanceMethod :: proc "c" (cls: Class, name: SEL) -> Method ---
  15. class_createInstance :: proc "c" (cls: Class, extraBytes: c.size_t) -> id ---
  16. method_setImplementation :: proc "c" (method: Method, imp: IMP) ---
  17. object_getIndexedIvars :: proc(obj: id) -> rawptr ---
  18. }
  19. @(objc_class="NSZone")
  20. Zone :: struct {using _: Object}
  21. @(link_prefix="NS")
  22. foreign Foundation {
  23. AllocateObject :: proc "c" (aClass: Class, extraBytes: UInteger, zone: ^Zone) -> id ---
  24. DeallocateObject :: proc "c" (object: id) ---
  25. }
  26. Method :: ^objc_method
  27. objc_method :: struct {
  28. method_name: SEL,
  29. method_types: cstring,
  30. method_imp: IMP,
  31. }
  32. objc_method_list :: struct {}
  33. objc_ivar :: struct {}
  34. objc_ivar_list :: struct {}
  35. objc_cache :: struct {
  36. mask: u32,
  37. occupied: u32,
  38. buckets: [1]Method,
  39. }
  40. objc_protocol_list :: struct {
  41. next: ^objc_protocol_list,
  42. count: c.int,
  43. list: [1]^Protocol,
  44. }
  45. @(objc_class="Protocol")
  46. Protocol :: struct{using _: intrinsics.objc_object}
  47. objc_object_internals :: struct {
  48. isa: ^objc_class_internals,
  49. }
  50. objc_class_internals :: struct {
  51. isa: Class,
  52. super_class: Class,
  53. name: cstring,
  54. version: c.long,
  55. info: c.long,
  56. instance_size: c.long,
  57. ivars: ^objc_ivar_list,
  58. methodLists: ^^objc_method_list,
  59. cache: rawptr,
  60. protocols: rawptr,
  61. }