Lua 5.4, the embeddable scripting language, through C++23 modules.
English · 简体中文 · Upstream · Releases · mcpp · Index
The upstream C API is unchanged: lua_State, lua_pushinteger, luaL_newstate,
luaopen_base are the upstream globals of <lua.h>, <lauxlib.h> and
<lualib.h>. The library is compat.lua 5.4.7; this package maps Lua's macros
to constants and functions under their original names. Lua's own test suite
passes on every CI run, on a standalone interpreter written against the module.
import mcpplibs.mwrap.lua;: the C API (lua_*,luaL_*,luaopen_*, the types), re-exporting the one belowimport mcpplibs.mwrap.lua.macros;:LUA_OK,lua_pop,lua_tostring,luaL_dostring… inmcpplibs::mwrap::lua::macros
More Modules API -> Usage and API
mcpp new scripted --template mcpplibs.mwrap.lua@5.4.7.1
cd scripted
mcpp runThe default template registers a C++ function, runs a script that calls it, and prints what the script returns.
[dependencies]
mcpplibs.mwrap.lua = "5.4.7.1"import std;
import mcpplibs.mwrap.lua;
using namespace mcpplibs::mwrap::lua::macros; // lua_pop, lua_tostring, LUA_OK …
int main() {
lua_State* L = luaL_newstate();
luaL_openlibs(L);
if (luaL_dostring(L, "return ('modules'):upper()")) std::println("error: {}", lua_tostring(L, -1));
else std::println("{}", lua_tostring(L, -1));
lua_close(L);
}A named module cannot export a macro. Constants are inline constexpr
(macros::LUA_OK, macros::LUA_REGISTRYINDEX, macros::LUA_VERSION), and
function-like macros are functions that evaluate their arguments as the macro
does (lua_pop, lua_pcall, lua_upvalueindex, luaL_newlib …).
luaL_argcheck, luaL_argexpected, luaL_opt and luaL_intop cannot be
functions without changing what they evaluate; they stay macros in
<mwrap/lua/macros.hpp>, included before the import. The table of every macro
and why is in docs/usage.md.
- examples/lua: a standalone interpreter,
lua [-e stat] [-l name] [-v] [script [args]], written against the module; tools/run_conformance.py runs Lua's test suite on it.
Linux, macOS and Windows CI build the modules and run the tests, the export
audit (tools/check_exports.py: every declaration of the
three headers exported, every macro mapped or listed with its reason) and Lua's
own test suite (lua-5.4.7-tests). A separate job scaffolds the default
template as an installed package and runs it.
Apache-2.0 for the wrapper, by mcpp-community; Lua remains MIT (upstream/lua/LICENSE).