{"id":20732912,"url":"https://github.com/montyanderson/foop","last_synced_at":"2025-04-23T22:52:11.636Z","repository":{"id":69223834,"uuid":"94631364","full_name":"montyanderson/foop","owner":"montyanderson","description":"C Framework for Object-Orientated Programming","archived":false,"fork":false,"pushed_at":"2017-07-03T00:23:06.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T22:51:51.899Z","etag":null,"topics":["c","framework","object-oriented","oop"],"latest_commit_sha":null,"homepage":"http://montyanderson.net/foop/","language":"C","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/montyanderson.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-17T15:12:52.000Z","updated_at":"2025-03-02T09:07:03.000Z","dependencies_parsed_at":"2023-04-20T17:22:18.920Z","dependency_job_id":null,"html_url":"https://github.com/montyanderson/foop","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/montyanderson%2Ffoop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montyanderson%2Ffoop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montyanderson%2Ffoop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/montyanderson%2Ffoop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/montyanderson","download_url":"https://codeload.github.com/montyanderson/foop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528694,"owners_count":21445511,"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":["c","framework","object-oriented","oop"],"created_at":"2024-11-17T05:22:32.907Z","updated_at":"2025-04-23T22:52:11.630Z","avatar_url":"https://github.com/montyanderson.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# foop\nC Framework for Object-Orientated Programming\n\n* Normal C Code\n\n``` C\nstruct User user;\n\nuser_init(\u0026user);\n\nuser_setName(\u0026user, \"John\");\nuser_setAge(\u0026user, 37);\nuser_print(\u0026user, 37);\n\nuser_free(\u0026user);\n```\n\n* With *foop*\n\n``` C\nstruct User *user = new(User);\n\n$(user)-\u003esetName(\"John\");\n$(user)-\u003esetAge(37);\n$(user)-\u003eprint();\n\ndelete(user);\n```\n\n## Features\n\n* Standardised utility libraries such as [foop-string](https://github.com/montyanderson/foop-string).\n* Almost non-existent CPU overhead; requires a single extra pointer for a method call.\n* Requires only slightly more memory, used for storing reference to the class in an instance and pointers to function methods.\n* Very small codebase with large compatibility.\n\n## Documentation\n\n### class_t\n\nStructure for a class definition.\n\n#### Members\n\n* **void (\\*constructor)()** - pointer to a function that constructs the object pointed to at *\\_this*. Can be NULL.\n* **void (\\*destructor)()** - pointer to a function that destructs the object pointed to at *\\_this*. Can be NULL.\n* **size_t size** - size of the object (instance) structure in bytes.\n\n``` C\nvoid UserConstructor() {\n\tstruct User *this = _this;\n\n\tstrcpy(this-\u003ename, \"Monty\"):\n\tthis-\u003eage = 16;\n}\n\nvoid UserDestructor() {\n\tprintf(\"Deleting User!\\n\");\n}\n\nconst class_t _User = {\n\t\u0026UserConstructor,\n\t\u0026UserDestructor,\n\tsizeof(struct User)\n};\n\nconst class_t *User = \u0026_User;\n```\n\n### void \\*new(const class_t \\*class)\n\nReturns a pointer to the new object (instance) of the passed class.\n\n* Allocates memory for the object structure + reference to original class\n* Call the class *constructor*\n* Returns the object\n\n``` C\nstruct User *user = new(User);\n```\n\n### void delete(void \\*object)\n\nDeletes the passed object pointer.\n\n* Calls the class destructor\n* Frees memory allocated to object structure + reference to class\n\n``` C\ndelete(user);\n```\n\n### const class_t \\*instanceOf(void \\*object)\n\nReturns a pointer to the original class used to create the object (instance).\n\n``` C\ninstanceOf(user) == User; // true\ninstanceOf(user) == AnotherClass; // false;\n```\n\n### void foop_reconstruct(void \\*object)\n\nDestructs the object and creates a new one in it's place.\n\n* Calls the class destructor\n* Zeros out associated memory\n* Calls the class constructor\n\n### void \\*\\_this\n\nPointer to the object about to be acted upon.\n\n``` C\nstruct User {\n\tint age;\n\tvoid (*birthday)();\n}\n\nvoid UserBirthday() {\n\tUser *this = _this;\n\n\tuser-\u003eage++;\n}\n\nvoid UserConstructor() {\n\tUser *this = _this;\n\n\tuser-\u003eage = 20;\n\tusser-\u003ebirthday = \u0026UserBirthday;\n}\n\nconst class_t _User {\n\t\u0026UserConstructor,\n\tNULL, // no destructor needed\n\tsizeof(struct User)\n}\n\nconst class_t *User = \u0026_User;\n\nint main() {\n\tstruct User *user = new(User);\n\n\tuser-\u003eage; // 20\n\t$(user)-\u003ebirthday();\n\tuser-\u003eage; // 21\n}\n```\n\n### $(void \\*object)\n\nSets *\\_this* to the object and returns the object casted to the type it was passed as.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmontyanderson%2Ffoop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmontyanderson%2Ffoop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmontyanderson%2Ffoop/lists"}