# lua_reg **Repository Path**: banbanlu/lua_reg ## Basic Information - **Project Name**: lua_reg - **Description**: C++ register function to lua - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-07-06 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README lua_reg ======= C++ register function to lua Copyright (c) 2013, Chen Yu. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the License file. 一个lua与C++交互粘合层,支持C++函数导出到lua、C++调用lua函数、C++引用lua对象,等等。 设计目标:接口简单、不依赖第三方库 std::allocator std_allocator; luareg::state_t state(std_allocator); try { test_t t; // free function & class method luareg::module(state, "cpp") << lua::def("test0", &test0) << lua::def("test1", &test1) << lua::def("test2", &test2) << lua::def("test3", &test3) << lua::def("test4", &test4) << lua::def("test5", &test5) << lua::def("test6", &t, &test_t::test6); luareg::module(state, "cpp") << lua::def("test7", &test7) << lua::def("test8", &test8) << lua::def("test9", &test9) << lua::def("test10", &test10) << lua::def("test11", &t, &test_t::test11) << lua::def("test12", &test12) << lua::def("test13", &test13) << lua::def("test14", &test14) << lua::def("test15", &test15) << lua::def("test16", &test16) << lua::def("test17", &test17) << lua::def("test18", &test18) //<< lua::def("test19", [](int n, const std::string &msg)->int{ return n; }) << lua::def("test20", &test20); base_t base; luareg::module(state) << lua::def("test21", &test21) << lua::def("base_print", &base, &base_t::print); // object method luareg::module(state, "cpp") [ luareg::class_t(state, "foo_t") << luareg::constructor() << luareg::destructor() << luareg::def("add", &foo_t::add) << luareg::def("get", &foo_t::get) << luareg::def("get_pointer", &foo_t::get_pointer) << luareg::def("get_base", &foo_t::get_base) ] << lua::def("test21", &test21); lua::execute(state, "test.lua"); } catch (const luareg::parameter_error_t &e) { std::cout << e.what() << std::endl; e.dump(std::cout); } catch(const luareg::fatal_error_t &e) { std::cout << e.what() << std::endl; e.dump(std::cout); } try { lua::execute(state, "test2.lua"); std::pair n = lua::call(state, "test_call", 1, "haha", 10.2, false); auto val = std::make_pair("test abc", 10.2); lua::call(state, "test_call2", 1, "haha", val); } catch(const luareg::fatal_error_t &e) { std::cout << e.what() << std::endl; e.dump(std::cout); }