{"id":15047349,"url":"https://github.com/bridgedeck/luacxx","last_synced_at":"2026-01-02T03:40:39.812Z","repository":{"id":242048460,"uuid":"808375061","full_name":"BridgeDeck/LuaCXX","owner":"BridgeDeck","description":"A C++ library for working with Lua more easily","archived":false,"fork":false,"pushed_at":"2024-11-18T08:11:55.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T23:13:27.063Z","etag":null,"topics":["cpp","cpp11","lua"],"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/BridgeDeck.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-05-31T00:11:28.000Z","updated_at":"2024-11-18T08:11:59.000Z","dependencies_parsed_at":"2024-06-05T13:27:49.675Z","dependency_job_id":"653f559a-013b-4bd8-9cfd-345c2b381a9f","html_url":"https://github.com/BridgeDeck/LuaCXX","commit_stats":null,"previous_names":["bridgedeck/luacxx"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BridgeDeck%2FLuaCXX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BridgeDeck%2FLuaCXX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BridgeDeck%2FLuaCXX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BridgeDeck%2FLuaCXX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BridgeDeck","download_url":"https://codeload.github.com/BridgeDeck/LuaCXX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243495495,"owners_count":20299923,"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":["cpp","cpp11","lua"],"created_at":"2024-09-24T20:56:56.504Z","updated_at":"2026-01-02T03:40:39.784Z","avatar_url":"https://github.com/BridgeDeck.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LuaCXX\n\nThis is a C++ library that makes it easier to use Lua by providing an intuitive abstraction over the Lua state. Allowing you to easily put it into any existing project that integrates Lua.\n\n\n## Does it work on version *?\n\n|Version       |Linux    |Windows  |OSX      |\n|--------------|---------|---------|---------|\n|Lua 5.1.*     |Unknown  |Unknown  |Unknown  |\n|Lua 5.2.*     |Unknown  |Unknown  |Unknown  |\n|Lua 5.3.*     |Unknown  |Unknown  |Unknown  |\n|Lua 5.4.*     |Unknown  |Unknown  |Unknown  |\n|LuaJIT 2.0    |Unknown  |Unknown  |Unknown  |\n|LuaJIT 2.1    |Yes      |Unknown  |Unknown  |\n\nFeel free to add more Lua versions and platforms Lua is available on to the above table, aswell as testing them out to see if LuaCXX works there or not.\n## Building\nThis library does not need a prebuilt Lua library, only Lua header files.\nThe Lua library is only needed for building and running tests.\n\nTo build it does require CMake 3.28+ and the C++11 standard, both of which should not be too difficult to set up.\n\n### Including in a CMake Project\nSet the `LUA_INCLUDE_DIR` option to a directory containing Lua headers.\n```cmake\nset(LUA_INCLUDE_DIR \"/my/path/to/lua/include\")\nadd_subdirectory(LuaCXX)\n# Do something with LuaCXX\n```\n\n### Linux\n\nBuild LuaCXX using the utility Makefile in the root.\n```\nmake build INCLUA=/path/to/lua/include\n```\n\nIf you want to optimize it for release.\n```\nmake build CMAKE_BUILD_TYPE=Release INCLUA=/path/to/lua/include\n```\n\nThe utility Makefile chooses Ninja by default to generate build files, to choose something else, set the CMAKE_GENERATOR variable.\n```\nmake build CMAKE_GENERATOR=\"Unix Makefiles\"\n```\n\n### Building documentation with Doxygen\n\nThe utility Makefile also has a command to build the documentation using doxygen.\n\n```\nmake docs\n```\n\nUse something like Python's `http.server` module to serve the files and view them.\n```\ncd docs/html\npython -m http.server\n```\n\n\n## Code Samples\n\nSimply wrap `LuaCXX::Lua` around an existing `lua_State*` and you are ready.\n```cpp\nusing namespace LuaCXX; // All LuaCXX classes are wrapped in this namespace\n\nlua_State* L = luaL_newstate();\nLua luacxx = Lua(L); // Use LuaCXX from here\n```\n\nLua's globals and registry tables are available as plain Tables.\n```cpp\nluacxx.globals();\nluacxx.registry();\n```\n\nCompile Lua source code and run it. (in protected mode)\n```cpp\nint err;\nluacxx.compile(\"print(\\\"Hello World!\\\")\", \"My Lua Code\").pcall(luacxx.new_nil(), err); \n```\n\nCreate a table and set its properties\n```cpp\nTable Player = luacxx.new_table();\n\n// We are working to make it less ugly\n\n// set properties using Variant::set\nPlayer.set(luacxx.new_string(\"Health\"), luacxx.new_number(175.0));\n\n// set properties without invoking metamethods using Variant::rawset\nPlayer.rawset(luacxx.new_string(\"CurrentWeapon\"), luacxx.new_string(\"The Eyelander\")); \n\n// get properties using Variant::get\nPlayer.get(luacxx.new_string(\"Health\"));\n\n// get properties without invoking metamethods using Variant::rawget\nPlayer.rawget(luacxx.new_string(\"CurrentWeapon\"))\n```\n\nIterate through the contents of a table.\n```cpp\nVariant key;\nVariant value;\n\nwhile(Player.next(key, value))\n{\n    // Do something with `key` or `value`\n}\n```\n\nCreate a metatable and assign it to the above table\n```cpp\n// a table that will become a metatable\nTable mt = luacxx.new_table();\n\n// give it a __index metamethod. Replace YOUR_FUNCTION with a valid c function\nmt.rawset(luacxx.new_string(\"__index\"), luacxx.new_function(YOUR_FUNCTION));\n\n// give it a __newindex metamethod. Replace YOUR_FUNCTION with a valid c function\nmt.rawset(luacxx.new_string(\"__newindex\"), luacxx.new_function(YOUR_FUNCTION));\n\n// Assign the Player table this metatable.\nPlayer.set_metatable(mt);\n```\n\nUse `Stack` to read arguments easier.\n```cpp\n\nusing namespace LuaCXX;\n\nclass Game\n{\n    public:\n    int blu_points;\n    int red_points;\n}\n\n/*\n    Suppose this is a global Lua function that takes the parameters `game` and `team`\n    `game` is a Userdata that points to an instance of the `Game` class above.\n    `team` is a string.\n*/\nint _get_team_points(lua_State* L)\n{\n    Lua luacxx = Lua(L); // To use LuaCXX\n\n    Userdata\u003cGame\u003e game = luacxx[1]; // First argument\n    String team = luacxx[2]; // Second argument\n\n    // `String` converts to a `const char*` automatically.\n    if (strcmp(team, \"red\")==0)\n        return stack._return(luacxx.new_number(Game-\u003ered_points)); // Returns Game::red_points\n    else if (strcmp(team, \"blu\")==0)\n        return luacxx.return_values(luacxx.new_number(Game-\u003eblu_points)); // Returns Game::blu_points\n    else\n        return luacxx.return_values(luacxx.new_nil()); // Returns a nil\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbridgedeck%2Fluacxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbridgedeck%2Fluacxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbridgedeck%2Fluacxx/lists"}