{"id":18853720,"url":"https://github.com/skaarj1989/entt-meets-sol2","last_synced_at":"2025-08-21T15:33:03.160Z","repository":{"id":133121157,"uuid":"326941043","full_name":"skaarj1989/entt-meets-sol2","owner":"skaarj1989","description":"Use EnTT in Lua with Sol2","archived":false,"fork":false,"pushed_at":"2024-11-12T19:36:20.000Z","size":266,"stargazers_count":50,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T12:46:28.028Z","etag":null,"topics":["cpp17","ecs","entt","gamedev","lua","scripting","sol2"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skaarj1989.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":"2021-01-05T08:54:35.000Z","updated_at":"2025-03-25T12:10:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"c4595be7-0724-465d-84fd-199e71afdcb6","html_url":"https://github.com/skaarj1989/entt-meets-sol2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skaarj1989/entt-meets-sol2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2Fentt-meets-sol2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2Fentt-meets-sol2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2Fentt-meets-sol2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2Fentt-meets-sol2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skaarj1989","download_url":"https://codeload.github.com/skaarj1989/entt-meets-sol2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skaarj1989%2Fentt-meets-sol2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271500361,"owners_count":24770375,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cpp17","ecs","entt","gamedev","lua","scripting","sol2"],"created_at":"2024-11-08T03:45:24.432Z","updated_at":"2025-08-21T15:33:02.867Z","avatar_url":"https://github.com/skaarj1989.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EnTT meets Sol2\n\n[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/skaarj1989/entt-meets-sol2)](https://www.codefactor.io/repository/github/skaarj1989/entt-meets-sol2)\n![GitHub](https://img.shields.io/github/license/skaarj1989/entt-meets-sol2.svg)\n\n## Requirements\n\n- EnTT v.3.14.0 (latest)\n- sol2 v3.2.2 (latest)\n\n## Building\n\n```bash\n\u003e git clone https://github.com/skaarj1989/entt-meets-sol2.git\n\u003e cd entt-meets-sol2\n\u003e cmake -S . -B build\n```\n\n### vcpkg quickstart\n\nhttps://github.com/microsoft/vcpkg#getting-started\n\n```bash\n\u003e git clone https://github.com/microsoft/vcpkg\n\u003e ./vcpkg/bootstrap-vcpkg.bat\n```\n\nAdd the following environment variables\n\n```bash\nVCPKG_ROOT=path_to_vcpkg\nVCPKG_DEFAULT_TRIPLET=x64-windows\n```\n\nInstall required dependencies\n\n```bash\n\u003e ./vcpkg install entt sol2 lua\n```\n\n## Registry\n\n[entt/wiki/registry](https://github.com/skypjack/entt/wiki/Crash-Course:-entity-component-system#the-registry-the-entity-and-the-component)\n\n### Goal\n\n- Expose `registry` to Lua scripts:\n  - Manage entity lifetime\n  - Set components\n  - Get component by reference\n  - `runtime_view`\n  - Some of **MonoBehaviour** functionality\n\n### c++ setup\n\n[examples/registry](https://github.com/skaarj1989/entt-meets-sol2/blob/main/examples/registry/)\n\n```cpp\nstruct Transform { int x, y; };\n\nregister_meta_component\u003cTransform\u003e();\n\nsol::state lua{};\nlua.require(\"dispatcher\" ...);\n\nlua.new_usertype\u003cTransform\u003e(\"Transform\",\n  \"type_id\", \u0026entt::type_hash\u003cTransform\u003e::value,\n  sol::call_constructor,\n  sol::factories([](int x, int y) {\n    return Transform{ x, y };\n  }),\n  \"x\", \u0026Transform::x,\n  \"y\", \u0026Transform::y\n);\n```\n\n```cpp\nentt::registry registry{};\nlua[\"registry\"] = std::ref(registry); // Make the registry available to Lua\n```\n\n### Lua script\n\n```lua\n-- Create a registry inside a script\nregistry = entt.registry.new()\n```\n\n```lua\nmario = registry:create()\nregistry:emplace(mario, Transform(1, 2))\nmaterial = registry:get(mario, Material)\n\nif (registry:has(mario, Transform)) then\n  registry:emplace(mario, DeletionFlag())\nend\n```\n\n```lua\n-- Utilizes variadic args - pass as many types as you want\nregistry:runtime_view(Transform, DeletionFlag):each(\n  function(entity)\n    registry:remove(entity, DeletionFlag)\n  end\n)\n```\n\nWant something like **MonoBehaviour** in Unity?\n[examples/system](https://github.com/skaarj1989/entt-meets-sol2/tree/main/examples/system)\n\n### Lua script\n\n```lua\nlocal node = {}\nfunction node:init()\n  self.owner:emplace(self.id(), Transform(5, 9))\nend\nfunction node:update(dt)\n  local transform = self.owner:get(self.id(), Transform)\n  transform.x = transform.x + 1\nend\nfunction node:destroy()\n  -- ...\nend\n\nreturn node\n```\n\n### c++ setup\n\n```cpp\nstruct ScriptComponent {\n  sol::table self;\n  struct {\n    sol::function update;\n  } hooks;\n};\n\nregistry.emplace\u003cScriptComponent\u003e(entity, lua.script_file(\"behavior.lua\"));\n\nwhile (true) {\n  auto view = registry.view\u003cScriptComponent\u003e();\n  for (auto entity : view) {\n    auto \u0026script = view.get\u003cScriptComponent\u003e(entity);\n    script.hooks.update(script.self, delta_time);\n  }\n}\n```\n\n## Event dispatcher\n\n[entt/wiki/dispatcher](https://github.com/skypjack/entt/wiki/Crash-Course:-events,-signals-and-everything-in-between#event-dispatcher)\n\n### Goal\n\n- Either create new (inside script) or connect existing (native c++) dispatcher\n- Trigger/enqueue events from Lua side\n- Listen for events in Lua scripts\n- Support disconnection of listeners\n\n### c++ setup\n\n[examples/dispatcher](https://github.com/skaarj1989/entt-meets-sol2/tree/main/examples/dispatcher)\n\n```cpp\nstruct an_event { int value; };\n\nregister_meta_event\u003can_event\u003e();\n\nsol::state lua{}\nlua.require(\"dispatcher\", ...)\n\nlua.new_usertype\u003can_event\u003e(\"an_event\",\n  \"type_id\", \u0026entt::type_hash\u003can_event\u003e::value,\n  sol::call_constructor,\n  sol::factories([](int value) {\n    return an_event{ value };\n  }),\n  \"value\", \u0026an_event::value\n);\n```\n\n```cpp\nentt::dispatcher dispatcher{};\nlua[\"dispatcher\"] = std::ref(dispatcher); // Make the dispatcher available to Lua\n\n// load a script ...\n\ndispatcher.update(); // inside loop\n```\n\n### Lua script\n\n```lua\n-- Create a dispatcher in a script\ndispatcher = entt.dispatcher.new()\n```\n\n```lua\nlistener = {}\nfunction listener.receive(evt)\n    -- ...\nend\nfunction listener.method(evt)\n    -- ...\nend\n\n-- You have to store result of 'connect()', otherwise listener will be\n-- disconnected in lua garbage collection step.\nconn = dispatcher:connect(an_event, listener.receive)\ndispatcher:connect(another_event, listener.method)\n\n-- Event type is deduced from bound 'type_id()' method\ndispatcher:trigger(an_event(42))\ndispatcher:enqueue(another_event())\n\nconn = nil -- to disconnect listener\n```\n\n## Cooperative scheduler\n\n[entt/wiki/cooperative-scheduler](https://github.com/skypjack/entt/wiki/Crash-Course:-cooperative-scheduler)\n\n### Goal\n\n- Define process class in Lua and attach it to `scheduler` either native c++ or dedicated to script\n- Allow process chaining\n\n### c++ setup\n\n[examples/scheduler](https://github.com/skaarj1989/entt-meets-sol2/tree/main/examples/scheduler)\n\n```cpp\nsol::state lua{};\nlua.require(\"scheduler\", ...);\n```\n\n```cpp\nentt::scheduler scheduler{};\nlua[\"scheduler\"] = std::ref(scheduler); // Make the scheduler available to Lua\n\nscheduler.update(dt); // inside loop\n```\n\n### Lua script\n\n```lua\n-- Create a scheduler in a script\nscheduler = entt.scheduler.new()\n```\n\n```lua\nlocal process_a = {}\nfunction process:update(dt)\n    -- ...\nend\n-- define init, succeeded and other methods ...\n\n-- This one differs from entt attach().then().then ... but works the same\nscheduler:attach(\n    process_a,\n    process_b,\n    process_n\n    -- etc ...\n)\n```\n\n## License\n\nCode released under [CC0 1.0 Universal](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskaarj1989%2Fentt-meets-sol2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskaarj1989%2Fentt-meets-sol2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskaarj1989%2Fentt-meets-sol2/lists"}