From 13d3962124fac90ab8dd453b3146f341214db193 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Sat, 21 Mar 2009 14:07:34 +0100 Subject: [PATCH] Add test for creating instances in Lua threads. --- test/Jamfile | 1 + test/test_create_in_thread.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/test_create_in_thread.cpp diff --git a/test/Jamfile b/test/Jamfile index 9340fbd..28ab536 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -32,6 +32,7 @@ SOURCES = test_adopt_wrapper.cpp test_builtin_converters.cpp test_class_info.cpp + test_create_in_thread.cpp ; obj main : main.cpp : ..//luabind : : ..//luabind ; diff --git a/test/test_create_in_thread.cpp b/test/test_create_in_thread.cpp new file mode 100644 index 0000000..9cf38d5 --- /dev/null +++ b/test/test_create_in_thread.cpp @@ -0,0 +1,45 @@ +// 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 + +int count = 0; + +struct X +{ + X() + { + ++count; + } + + ~X() + { + --count; + } +}; + +#include + +void test_main(lua_State* L) +{ + using namespace luabind; + + module(L) [ + class_("X") + .def(constructor<>()) + ]; + + for (int i = 0; i < 100; ++i) + { + lua_State* thread = lua_newthread(L); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + + DOSTRING(thread, + "local x = X()\n" + ); + + luaL_unref(L, LUA_REGISTRYINDEX, ref); + } +} -- 2.11.4.GIT