From 677ffbc924995743149afa7747b9b1a6a8f0cbc3 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Fri, 21 Aug 2009 12:59:45 +0200 Subject: [PATCH] Add test for extending exported classes in Lua. Test that it's possible to add functions to exported C++ classes in Lua. --- test/Jamfile | 1 + test/test_extend_class_in_lua.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/test_extend_class_in_lua.cpp diff --git a/test/Jamfile b/test/Jamfile index 47dc61e..b7dd2fa 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -40,6 +40,7 @@ SOURCES = test_dynamic_type.cpp test_virtual_inheritance.cpp test_create_in_thread.cpp + test_extend_class_in_lua.cpp ; obj main : main.cpp : ..//luabind : : ..//luabind ; diff --git a/test/test_extend_class_in_lua.cpp b/test/test_extend_class_in_lua.cpp new file mode 100644 index 0000000..0323afc --- /dev/null +++ b/test/test_extend_class_in_lua.cpp @@ -0,0 +1,37 @@ +// Copyright Daniel Wallin 2009. Use, modification and distribution is +// subject to the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "test.hpp" +#include + +struct CppClass +{ + int f(int x) + { + return x; + } +}; + +void test_main(lua_State* L) +{ + using namespace luabind; + + module(L) [ + class_("CppClass") + .def(constructor<>()) + .def("f", &CppClass::f) + ]; + + DOSTRING(L, + "function CppClass:f_in_lua(x)\n" + " return self:f(x) * 2\n" + "end\n" + ); + + DOSTRING(L, + "x = CppClass()\n" + "assert(x:f(1) == 1)\n" + "assert(x:f_in_lua(1) == 2)\n" + ); +} -- 2.11.4.GIT