{"id":18034761,"url":"https://github.com/possseidon/lua-class","last_synced_at":"2025-04-04T23:12:54.556Z","repository":{"id":110962612,"uuid":"328195737","full_name":"Possseidon/lua-class","owner":"Possseidon","description":"Yet another class library for Lua, because there aren't enough already. ¯\\_(ツ)_/¯","archived":false,"fork":false,"pushed_at":"2021-01-15T22:13:24.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T07:30:44.135Z","etag":null,"topics":["class-library","lua","lua-library","utility-library"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Possseidon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-01-09T16:20:44.000Z","updated_at":"2022-08-05T18:18:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d04c063-c984-4612-9ce9-88c372ae0e89","html_url":"https://github.com/Possseidon/lua-class","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/Possseidon%2Flua-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Possseidon","download_url":"https://codeload.github.com/Possseidon/lua-class/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261605,"owners_count":20910108,"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":["class-library","lua","lua-library","utility-library"],"created_at":"2024-10-30T11:14:00.186Z","updated_at":"2025-04-04T23:12:54.550Z","avatar_url":"https://github.com/Possseidon.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-class\n\nYet another class library for Lua, because there aren't enough already. ¯\\\\\\_(ツ)\\_/¯\n\n## Usage\n\nIt follows a small example showing its basic usage.\n\nPersonally I use PascalCase for my class names, which is fairly common in other languages as well. Of course, feel free to use whichever convention suits you best.\n\n```lua\nlocal class = require \"class\"\n\n-- Creating the class:\n\nlocal Value = class(\"Value\")\n\nfunction Value:create(value)\n  self._value = value\nend\n\nfunction Value:get()\n  return self._value\nend\n\nfunction Value:set(value)\n  self._value = value\nend\n\n-- Creating an instance:\n\nlocal value = Value(\"Hello World!\")\n\nprint(value:get()) --\u003e Hello World!\n\nvalue:set(\"How are you?\")\n\nprint(value:get()) --\u003e How are you?\n```\n\nA class `Value` with simple `create` (constructor), `get` and `set` methods.\n\nI generally put each class in its own file and name the file accordingly, similar to how [Object.lua](lib/Object.lua) and [Event.lua](lib/Event.lua) look.\n\n---\n\n## Library\n\n### [class.lua](lib/class.lua)\n\n- The core library.\n- Can be used standalone.\n- Supports creation of classes and inheritance.\n\n### [Object.lua](lib/Object.lua)\n\n- Can be used as a base class.\n- Enables the use of properties using custom `get` and `set` functions.\n- Comes with useful helper functions to create properties with common `get` and `set` functions.\n\n### [Event.lua](lib/Event.lua)\n\n- Provides a simple multicast event.\n- Handlers can be added and removed with the `add` and `remove` methods.\n- Calls all handlers in the order they were added, when the event is called.\n\n---\n\n## Examples\n\n### [1-simple.lua](examples/1-simple.lua)\n\n- Shows basic usage.\n- A simple class `Value` with `Value:get()` and `Value:set(value)` methods.\n\n### [2-constructor.lua](examples/2-constructor.lua)\n\n- Customize instance creation with a `MyClass:create()` method.\n- Creating instance fields.\n\n### [3-inheritance.lua](examples/3-inheritance.lua)\n\n- Creating a base class `Animal` and a subclass `Cat`.\n- Virtual and abstract methods.\n- Calling base methods in a derived method.\n- Checking if something is a class or an object using `class.isClass()` and `class.isObject()`.\n- Safely turning any value into its class (or `nil`) using `class.of()`.\n- Checking the inheritance hierachy of classes and objects using the comparison operators.\n\n### [4-customize-inheritance.lua](examples/4-customize-inheritance.lua)\n\n- Customize what happens, when a certain class is inherited from.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpossseidon%2Flua-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpossseidon%2Flua-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpossseidon%2Flua-class/lists"}