{"id":21852448,"url":"https://github.com/congard/solgen","last_synced_at":"2025-10-08T11:31:47.275Z","repository":{"id":51564075,"uuid":"520224578","full_name":"congard/solgen","owner":"congard","description":"C++ code generator for creating Lua bindings using sol2 library","archived":false,"fork":false,"pushed_at":"2023-09-16T09:38:13.000Z","size":118,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-28T01:16:34.325Z","etag":null,"topics":["code-generation","cpp","cpp20","lua","lua-bindings","sol2"],"latest_commit_sha":null,"homepage":"","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/congard.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":"2022-08-01T18:40:58.000Z","updated_at":"2024-01-11T05:14:37.000Z","dependencies_parsed_at":"2023-01-19T21:34:17.699Z","dependency_job_id":null,"html_url":"https://github.com/congard/solgen","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/congard%2Fsolgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/congard%2Fsolgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/congard%2Fsolgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/congard%2Fsolgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/congard","download_url":"https://codeload.github.com/congard/solgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235707169,"owners_count":19032784,"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":["code-generation","cpp","cpp20","lua","lua-bindings","sol2"],"created_at":"2024-11-28T01:17:06.272Z","updated_at":"2025-10-08T11:31:41.914Z","avatar_url":"https://github.com/congard.png","language":"C++","readme":"# Solgen\n\nSolgen – C++ code generator for creating Lua bindings using [sol2](https://github.com/ThePhD/sol2) library.\n\n\u003e [!WARNING]  \n\u003e There is no any guarantee that this project will work for you as you expect.\n\u003e **solgen** was created as a part of [algine](https://github.com/congard/algine)\n\u003e infrastructure, so its main goal is to automate Lua bindings generation for this\n\u003e project. However, **solgen** is open to contributions.\n\n## Motivation\n\nI created this code generator \u003cu\u003emainly for my project [algine](https://github.com/congard/algine)\u003c/u\u003e since I noticed,\nthat writing class bindings by hand is too boring, takes a lot of time and hard to maintain\n(especially when you have advanced inheritance).\n\nNote: it is very possible that something will not work for you.\n\n## Features\n\n1. Lua bindings generation **for C++ classes** (inner classes, constructors, operators, methods, fields, enums)\n2. Ability to generate custom factories instead of constructors for selected classes\n3. Ability to bind custom implementations for selected methods\n4. Properties generation based on getters \u0026 setters\n5. Operators bindings (temporary limited)\n6. Default function arguments support\n7. \"Bad\" (i.e. not auto-convertible from / to Lua table) arguments detector (e.g. such as `const std::vector\u003cT\u003e \u0026`)\n8. You can specify additional options for classes, methods, fields etc by using `///` or `//!` comments or by creating conf file.\n9. Can rebuild only changed files (by default). See `--regenerate`, `--regenerate-derived` for more info\n10. For more info see `--help`\n\n## Dependencies\n\nSolgen has only one dependency - `libclang`.\n\n### Linux\n\nFedora: `sudo dnf install clang-devel`\n\n### Windows\n\nIn order to build `solgen` on Windows, you should install [LLVM](https://releases.llvm.org/download.html).\n\n\u003e [!NOTE]\n\u003e If you have installed LLVM in the default location (i.e., `$Env:ProgramW6432\\LLVM`),\n\u003e there is no need to specify the LLVM location.\n\n## Requirements\n\nC++20 compatible compiler.\n\n### Windows\n\nAfter the building process, a symlink to the `libclang.dll` will be created in order\nto ensure that `solgen` can be executed even when LLVM is not included in the PATH.\n\nBy default, in Windows, symlinks can be created only with elevated privileges. To change\nthis, you need to enable Developer mode in the settings.\n\n**For Windows 11:** _Settings -\u003e Privacy \u0026 security -\u003e For developers -\u003e Developer Mode (on)_.\n\n## Flags\n\n| Flag        | Description             | Platform | Mandatory | Default                  |\n|-------------|-------------------------|----------|-----------|--------------------------|\n| `LLVM_PATH` | Specifies LLVM location | Windows  | No        | `$Env:ProgramW6432\\LLVM` |\n\n## Support\n\nTested on:\n\n- Fedora 38\n- Windows 11, clang version 16.0.0, target: x86_64-pc-windows-msvc\n\n## Notes\n\nIt's important to run solgen from your project's root and pass absolute paths or relative from the project root.\n\nIf you see the error `stddef.h: No such file or directory` (or something similar),\nyou should add your compiler's include directories to solgen includes (`--includes`).\nYou can get that directories using the following commands:\n\n- ```bash\n  clang++ -E -x c++ - -v \u003c /dev/null\n  ```\n\n- ```bash\n  gcc -E -x c++ - -v \u003c /dev/null\n  ```\n\n## Limitations\n\nMost limitations are coming from the sol2 library itself.\nFor example, you can't bind `std::set` or `std::vector` in some cases.\nPossible workarounds: you can provide your own custom implementations for these types\n(i.e. convert them to lua table and vice versa) or you can just ignore them. Possible\nsolution - detect these types and generate custom bindings for them.\n\n## Roadmap\n\n1. [x] **High Priority**: refactor: move functionality from `SolGen.cpp` to the corresponding \n       classes (`Class`, `Enum` etc)\n2. [ ] Add templates support\n3. [x] Add Windows support\n4. [ ] Add ability to disable properties (flag `--disable-properties` and option `prop_disable`)\n5. [ ] Register types that were used in class (args, fields, return types etc)\n6. [ ] Link getters of type `const std::string\u0026` and setters of type `std::string_view`\n7. [ ] Add multiline support for conf\n8. [x] Generate bindings for enums located in namespaces\n9. [ ] Detect deleted constructors\n10. [ ] Complete TODOs in the project\n11. [ ] Make conf files less type sensitive (?)\n\nI will update this list when I will need more features \u0026 functionality for my own projects.\n\n## How to use\n\nSolgen generates only source (`cpp`) files which contain specialized templates.\nTo use them you can do something like that:\n\n```cpp\n// NOTE: you can specify OutputNamespace by using --output-namespace\n// By default it is solgen\nnamespace OutputNamespace {\ntemplate\u003ctypename T\u003e void registerLuaUsertype(sol::table \u0026table);\n}\n\nvoid registerMyTypes(sol::table \u0026table) {\n    registerLuaUsertype\u003cFoo\u003e(table);\n    registerLuaUsertype\u003cBar\u003e(table);\n    registerLuaUsertype\u003cBaz\u003e(table);\n}\n```\n\nYou can get list of generated files by setting `--print-paths` flag.\nThis option is very useful for build systems like CMake.\n\n## Conf file syntax\n\n```conf\n[canonical-signature-1]\noption1     value1\noption2     value2\nswitcher0\n\n# comment\n\n[canonical-signature-2]\noption1     value1\noption2     value2\nswitcher0\n```\n\nCanonical signature means that you should write full type names, e.g.:\n\n```cpp\nconst std::string\u0026 MyClass::modify(std::string_view str)\n// becomes\nconst std::basic_string\u003cchar\u003e \u0026MyNamespace::MyClass::modify(std::basic_string_view\u003cchar\u003e)\n```\n\nAvailable options you can find in `--help-options`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcongard%2Fsolgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcongard%2Fsolgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcongard%2Fsolgen/lists"}