{"id":17214257,"url":"https://github.com/kalimehtar/gir","last_synced_at":"2025-04-13T22:57:20.475Z","repository":{"id":8858937,"uuid":"10569178","full_name":"Kalimehtar/gir","owner":"Kalimehtar","description":"Racket GObjectIntrospection FFI","archived":false,"fork":false,"pushed_at":"2021-10-13T03:47:28.000Z","size":43,"stargazers_count":15,"open_issues_count":1,"forks_count":7,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-13T22:57:00.958Z","etag":null,"topics":["gtk","racket","racket-gui"],"latest_commit_sha":null,"homepage":null,"language":"Racket","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kalimehtar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-08T14:00:39.000Z","updated_at":"2022-05-09T13:43:47.000Z","dependencies_parsed_at":"2022-08-27T20:52:27.724Z","dependency_job_id":null,"html_url":"https://github.com/Kalimehtar/gir","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalimehtar%2Fgir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalimehtar%2Fgir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalimehtar%2Fgir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kalimehtar%2Fgir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kalimehtar","download_url":"https://codeload.github.com/Kalimehtar/gir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248794572,"owners_count":21162614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gtk","racket","racket-gui"],"created_at":"2024-10-15T03:02:18.966Z","updated_at":"2025-04-13T22:57:20.452Z","avatar_url":"https://github.com/Kalimehtar.png","language":"Racket","funding_links":[],"categories":[],"sub_categories":[],"readme":"GObject Introspection\n\n```racket\n (require gir)\n```\n\n# 1. Main interface\n\nThis is Gobject FFI.\n\nUsage example:\n\n```racket\n(define gtk (gi-ffi \"Gtk\"))         \n(gtk 'init 0 #f)                    \n(let ([window (gtk 'Window 'new 0)])\n  (window 'show)                    \n  (gtk 'main))                      \n```\n\nInterface with the GObjectIntrospection is based on repositories. Main\nfunction is\n\n```racket\n(gi-ffi repository-name [version]) -\u003e procedure?\n  repository-name : string?                     \n  version : string? = \"\"                        \n```\n\nReturns interface to repository with name `repository-name`\n\n# 2. Get FFI element\n\n```racket\n(repository func-name func-arg ...) -\u003e any/c            \n  func-name : (or/c string? symbol?)                    \n  func-arg : any/c                                      \n(repository const-name) -\u003e any/c                        \n  const-name : (or/c string? symbol?)                   \n(repository enum-name enum-value-name) -\u003e exact-integer?\n  enum-name : (or/c string? symbol?)                    \n  enum-value-name : (or/c string? symbol?)              \n(repository class-name constructor-name) -\u003e procedure?  \n  class-name : (or/c string? symbol?)                   \n  constructor-name : (or/c string? symbol?)             \n```\n\nThis interface takes as a first argument name of foreign object. Name\ncould be `string?` or `symbol?`. In both cases it’s allowed to replace\n\"\\_\" with \"-\". So you can write either \"get\\_name\" or ’get-name with the\nsame result.\n\nIf first argument is a name of function, then rest arguments are the\narguments of the function and it returns result of the function. In\nexample\n\n```racket\n(define gtk (gi-ffi \"Gtk\"))\n(gtk 'init 0 #f)           \n```\n\ngtk\\_init is called with 0 and null pointer.\n\nIf first argument is a name of constant, then it returns value of the\nconstant. For example,\n\n`(gtk` `'MAJOR-VERSION)`\n\nreturns 2 for GTK2 or 3 for GTK3.\n\nIf first argument is a name of enumeration, then second arguments should\nbe value name. It returns integer value. For example,\n\n`(gtk` `'WindowType` `':toplevel)`\n\nReturns 0.\n\nIf first argument is a name of class (or struct), then the second\nargument should be a name of class constructor (in GTK it is usually\n\"new\"), rest arguments are the arguments of the constructor.\n\n`(define` `window` `(gtk` `'Window` `'new` `0))`\n\nThis call will return a representation of object.\n\n# 3. Foreign objects\n\n```racket\n(object method-name method-arg ...) -\u003e any/c\n  method-name : (or/c string? symbol?)      \n  method-arg : any/c                        \n```\n\nRepresentation of an object is also a function. First argument of it\nshould be either name of method (`string?` or `symbol?`) or special\nname.\n\n`(window` `'add` `button)`\n\nwill call method \"add\" with argument \"button\".\n\n## 3.1. Pointer to object\n\nTo get C pointer to an object call it with \"method\" :this.\n\n`(window` `':this)`\n\n## 3.2. Fields\n\nGetting and setting field values are done with :field and :set-field!.\n\n```racket\n(define entry (gtk 'TargetEntry 'new \"ok\" 0 0))\n                                               \n\u003e (entry ':field 'flags)                       \n0                                              \n\u003e (entry ':set-field! 'flags 1)                \n\u003e (entry ':field 'flags)                       \n1                                              \n```\n\nBut you cannot set with :set-field! complex types such as structs,\nunions or even strings. It is a restriction of GObjectIntrospection.\n\n## 3.3. Properties\n\nGetting and setting field values are done with :properties and\n:set-properties!. You may get or set several properties at once.\n\n```racket\n(define-values (width height)                                    \n  (window ':properties 'width-request 'height-request))          \n(window ':set-properties! 'width-request 100 'height-request 200)\n```\n\n# 4. Signals\n\n```racket\n(connect object signal-name handler) -\u003e void?\n  object : procedure?                        \n  signal-name : (or/c symbol? string?)       \n  handler : (or/c procedure? cpointer?)      \n```\n\n# 5. Alternative interface\n\nIf you like more traditional interface, you may use `gir/interface`\nmodule\n\n```racket\n (require gir/interface)\n```\n\nIt provides interface in style of `racket/class`: `send`, `send/apply`,\n`dynamic-send`, `set-field!`, `get-field`, `dynamic-get-field`,\n`dynamic-set-field!`.\n\nBesides, it provides functional interface for object pointers and\nproperties:\n\n```racket\n(pointer object) -\u003e cpointer?\n  object : procedure?        \n```\n\nReturns pointer to object\n\n```racket\n(get-properties object property-name ...+) -\u003e any/c ...+\n  object : procedure?                                   \n  property-name : (or/c string? symbol?)                \n```\n\n```racket\n(set-properties! object                      \n                 property-name               \n                 property-value ...+         \n                 ...+)               -\u003e void?\n  object : procedure?                        \n  property-name : (or/c string? symbol?)     \n  property-value : any/c                     \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkalimehtar%2Fgir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkalimehtar%2Fgir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkalimehtar%2Fgir/lists"}