luabind-0.9.1+dfsg.orig/ 0000755 0003720 0000144 00000000000 11453027062 014407 5 ustar roberto users luabind-0.9.1+dfsg.orig/INSTALL 0000644 0003720 0000144 00000003701 11437201244 015437 0 ustar roberto users luabind installation
====================
The build system used by luabind is Boost Build V2, which can be found
at:
http://www.boost.org/doc/tools/build/index.html
The installation instructions are available at:
http://www.boost.org/doc/tools/build/doc/html/bbv2/installation.html
If you are using Debian or Ubuntu, you can simply install the
"boost-build" package:
$ sudo apt-get install boost-build
Other distributions may have similar packages.
On Windows, you can download pre-built "bjam" binaries, and follow the
installation instructions on the page linked above.
Windows
-------
The environment variable "BOOST_ROOT" must be set to the directory where Boost
was extracted. "LUA_PATH" must be set to a directory where Lua binaries and
headers reside. The recommended way to get the Lua libraries is to download the
"DLL and Includes" package from:
http://luabinaries.luaforge.net/download.html
With these enviroment variables properly set:
$ set BOOST_ROOT=...
$ set LUA_PATH=...
$ bjam stage
Will build the default library variants and place them in a directory called
"stage". This can be controlled with the "--stagedir" option:
$ bjam --stagedir=libs stage
Would place the libraries in a "libs" directory.
Note that there is nothing magic going on here. If you don't want to
build the libraries this way, or run the tests, there is nothing
stopping you from using whatever build system you want. For example,
simply dropping the source files in a Visual Studio project should just
work. The only requirement is that "LUABIND_DYNAMIC_LINK" must be
defined when building and linking to a shared library.
\*nix
-----
$ bjam install
Will build and install the default library variants, and install them together
with the header files to the default prefix, which is "/usr/local". The install
prefix can be controlled with the "--prefix" option. For example:
$ bjam --prefix=/usr install
Will install to "/usr/lib" and "/usr/include".
luabind-0.9.1+dfsg.orig/Jamroot 0000755 0003720 0000144 00000013033 11437201244 015746 0 ustar roberto users import docutils ;
import os ;
import errors ;
import notfile ;
import package ;
import path ;
import virtual-target ;
VERSION = 0.9.0 ;
BOOST_ROOT = [ os.environ BOOST_ROOT ] ;
rule debug-message ( txt * )
{
if --debug-build in [ modules.peek : ARGV ]
{
echo [luabind DEBUG] $(txt) ;
}
}
debug-message figuring out which libraries to link to... ;
debug-message os.name is [ os.name ] ;
if [ os.name ] = NT
{
if ! $(BOOST_ROOT)
{
errors.user-error "*** BOOST_ROOT must be set to a Boost installation." ;
}
LUA_PATH = [ os.environ LUA_PATH ] ;
if ! $(LUA_PATH)
{
errors.user-error "*** LUA_PATH must be set." ;
}
local includes = [ GLOB $(LUA_PATH)/include $(LUA_PATH)/src : lua.h ] ;
if ! $(includes)
{
errors.user-error "*** Unable to determine Lua include directory." ;
}
includes = $(includes:D) ;
debug-message found include directory in $(includes) ;
if [ GLOB $(LUA_PATH) : lib ]
{
lib lua : : static lua5.1 $(LUA_PATH)/lib/static : : $(includes) ;
lib lua : : shared lua5.1 $(LUA_PATH)/lib : : $(includes) ;
}
else if [ GLOB $(LUA_PATH) : lua5.1.dll ]
{
lib lua : : lua5.1 $(LUA_PATH) : : $(includes) ;
}
}
else if [ os.name ] in LINUX MACOSX FREEBSD
{
LUA_PATH = [ os.environ LUA_PATH ] ;
HOME = [ os.environ HOME ] ;
local possible-prefixes =
$(LUA_PATH) $(HOME)/Library/Frameworks /Library/Frameworks /usr /usr/local /opt/local /opt ;
local possible-suffixes =
include/lua5.1 include/lua51 include/lua include ;
local includes = [ GLOB $(possible-prefixes)/$(possible-suffixes) : lua.h ] ;
if ! $(includes)
{
errors.user-error "*** Unable to determine Lua include directory." ;
}
local includes = $(includes[1]:D) ;
local prefix = $(includes:D) ;
if $(prefix:B) = "include"
{
prefix = $(prefix:D) ;
}
local lib = $(prefix)/lib ;
local names = liblua5.1 liblua51 liblua ;
local extensions = .a .so ;
library = [ GLOB $(lib)/lua51 $(lib)/lua5.1 $(lib)/lua $(lib) :
$(names)$(extensions) ] ;
lib-name = [ MATCH "lib(.*)" : $(library[1]:B) ] ;
debug-message prefix: $(prefix) ;
debug-message includes: $(includes) ;
debug-message lib: $(library:D) ;
debug-message candidates: $(library) ;
debug-message linking to: $(lib-name) ;
if ! $(lib-name)
{
errors.user-error "*** Unable to find Lua library." ;
}
lib m : : shared ;
if [ os.name ] = LINUX
{
lib dl : : shared ;
}
else
{
alias dl ;
}
lib lua : m dl : $(lib-name) $(library:D) : : $(includes) ;
}
rule tag-names ( name : type ? : property-set )
{
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB &&
[ $(property-set).get ] = debug
{
name = $(name)d ;
}
local result = [ virtual-target.add-prefix-and-suffix $(name) : $(type) : $(property-set) ] ;
if $(type) = SHARED_LIB &&
( ! ( [ $(property-set).get ] in windows cygwin darwin aix ) &&
! ( [ $(property-set).get ] in pgi ) )
{
result = $(result).$(VERSION) ;
}
return $(result) ;
}
SOURCES =
class.cpp
class_info.cpp
class_registry.cpp
class_rep.cpp
create_class.cpp
error.cpp
exception_handler.cpp
function.cpp
inheritance.cpp
link_compatibility.cpp
object_rep.cpp
open.cpp
pcall.cpp
scope.cpp
stack_content_by_name.cpp
weak_ref.cpp
wrapper_base.cpp ;
usage-requirements =
lua
msvc,shared:/wd4251
shared:LUABIND_DYNAMIC_LINK
@tag-names ;
lib luabind
: src/$(SOURCES)
# requirements
: . $(BOOST_ROOT)
$(usage-requirements)
# default-build
:
# usage-requirements
: . $(BOOST_ROOT)
$(usage-requirements)
;
alias test
: test//test
# requirements
:
# default-build
: static shared release debug ;
explicit test ;
rule git-describe ( )
{
local result = [ SHELL "git describe HEAD 2>&1" : exit-status ] ;
if $(result[2]) = 0
{
return [ MATCH "^v([a-zA-Z.0-9\\-]+)" : $(result[1]) ] ;
}
}
version-tag = [ git-describe ] ;
if $(version-tag)
{
actions make-version-file
{
echo ".. |version| replace:: $(version-tag)" > doc/version.rst
}
notfile make-version-file : @make-version-file ;
}
else
{
alias make-version-file ;
}
if docs in [ modules.peek : ARGV ]
{
local result = [ SHELL "rst2html.py --version 2>&1" : exit-status ] ;
if $(result[2]) = 0
{
found-rst2html = rst2html.py ;
}
}
html docs.html
: doc/docs.rst
: make-version-file
$(found-rst2html)
"--traceback -gdt --stylesheet=style.css --link-stylesheet" ;
stage docs : docs.html : doc ;
explicit docs docs.html make-version-file ;
headers = [ path.glob-tree luabind : *.hpp ] ;
package.install install
: luabind
luabind
on
:
: luabind
: $(headers)
;
local stage-locate = [ MATCH "^--stagedir=(.*)" : [ modules.peek : ARGV ] ] ;
stage-locate ?= stage ;
install stage
: luabind
: $(stage-locate)
on
on
LIB
;
explicit stage ;
luabind-0.9.1+dfsg.orig/test/ 0000755 0003720 0000144 00000000000 11437201244 015364 5 ustar roberto users luabind-0.9.1+dfsg.orig/test/test_operators.cpp 0000644 0003720 0000144 00000011762 11437201244 021154 0 ustar roberto users // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
#include
#include
struct operator_tester : counted_type
{
int operator+(int a) const
{
return 1 + a;
}
int operator-() const
{
return 46;
}
float operator()() const
{
return 3.5f;
}
float operator()(int a) const
{
return 3.5f + a;
}
float operator()(int a)
{
return 2.5f + a;
}
};
float operator*(operator_tester const& lhs, operator_tester const& rhs)
{
return 35.f;
}
std::string operator*(operator_tester const&, int v)
{
return "(operator_tester, int) overload";
}
int operator+(int a, const operator_tester&)
{
return 2 + a;
}
struct operator_tester2 : counted_type
{
};
int operator+(const operator_tester&, const operator_tester2&)
{
return 73;
}
struct operator_tester3: operator_tester, counted_type {};
std::ostream& operator<<(std::ostream& os, const operator_tester&)
{
os << "operator_tester"; return os;
}
struct op_test1
{
bool operator==(op_test1 const& rhs) const { return true; }
};
struct op_test2 : public op_test1
{
bool operator==(op_test2 const& rhs) const { return true; }
};
COUNTER_GUARD(operator_tester);
COUNTER_GUARD(operator_tester2);
COUNTER_GUARD(operator_tester3);
struct len_tester
{
len_tester(int len)
: len_(len)
{}
int len() const
{
return len_;
}
int len_;
};
void test_main(lua_State* L)
{
using namespace luabind;
module(L)
[
class_("operator_tester")
.def(constructor<>())
.def(tostring(const_self))
.def(self + int())
.def(other() + self)
.def(-self)
.def(self + other())
.def(self())
.def(const_self(int()))
.def(self(int()))
// .def(const_self * other())
.def(const_self * const_self)
.def(const_self * other()),
// .def("clone", &clone, adopt(return_value)),
class_("operator_tester2")
.def(constructor<>())
.def(other() + self),
class_("operator_tester3")
.def(constructor<>()),
class_("op_test1")
.def(constructor<>())
.def(const_self == const_self),
class_("op_test2")
.def(constructor<>())
.def(self == self),
class_("len_tester")
.def(constructor())
.def("__len", &len_tester::len)
];
DOSTRING(L, "test = operator_tester()");
DOSTRING(L, "test2 = operator_tester2()");
DOSTRING(L, "test3 = operator_tester3()");
DOSTRING(L, "assert(tostring(test) == 'operator_tester')");
DOSTRING(L, "assert(test() == 3.5)");
DOSTRING(L, "assert(test(5) == 2.5 + 5)");
DOSTRING(L, "assert(-test == 46)");
DOSTRING(L, "assert(test * test == 35)");
DOSTRING(L, "assert(test * 3 == '(operator_tester, int) overload')")
DOSTRING(L, "assert(test + test2 == 73)");
DOSTRING(L, "assert(2 + test == 2 + 2)");
DOSTRING(L, "assert(test + 2 == 1 + 2)");
DOSTRING(L, "assert(test3 + 6 == 1 + 6)");
DOSTRING(L, "assert(test3 + test2 == 73)");
// DOSTRING(L, "assert(tostring(test) == 'operator_tester')");
const char* prog =
"class 'my_class'\n"
"function my_class:__add(lhs)\n"
" return my_class(self.val + lhs.val)\n"
"end\n"
"function my_class:__init(a)\n"
" self.val = a\n"
"end\n"
"function my_class:__sub(v)\n"
" if (type(self) == 'number') then\n"
" return my_class(self - v.val)\n"
" elseif (type(v) == 'number') then\n"
" return my_class(self.val - v)\n"
" else\n"
" return my_class(self.val - v.val)\n"
" end\n"
"end\n"
"a = my_class(3)\n"
"b = my_class(7)\n"
"c = a + b\n"
"d = a - 2\n"
"d = 10 - d\n"
"d = d - b\n";
DOSTRING(L, prog);
DOSTRING(L, "assert(c.val == 10)");
DOSTRING(L, "assert(d.val == 2)");
DOSTRING(L,
"a = op_test1()\n"
"b = op_test2()\n"
"assert(a == b)");
DOSTRING(L,
"x = len_tester(0)\n");
DOSTRING(L,
"x = len_tester(3)\n"
"assert(#x == 3)");
}
luabind-0.9.1+dfsg.orig/test/test_scope.cpp 0000755 0003720 0000144 00000005505 11437201244 020250 0 ustar roberto users // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
int f() { return 1; }
int f_(int a) { return 2; }
int f__(int a) { return 3; }
int g() { return 4; }
int g_(int) { return 5; }
int h() { return 6; }
struct test_class : counted_type
{
test_class()
: test(1)
{}
int test;
};
struct test_class2 : counted_type
{
test_class2() {}
int string_string(std::string const& s1, std::string const& s2)
{ return 1; }
};
COUNTER_GUARD(test_class);
COUNTER_GUARD(test_class2);
void test_main(lua_State* L)
{
using namespace luabind;
module(L)
[
class_("test_class2")
.def(constructor<>())
.def("string_string", &test_class2::string_string)
];
module(L, "test")
[
class_("test_class")
.def(constructor<>())
.def_readonly("test", &test_class::test)
.scope
[
def("inner_fun", &f)
]
.def("inner_fun2", &f) // this should become static
.enum_("vals")
[
value("val1", 1),
value("val2", 2)
],
def("f", &f),
def("f", &f_),
namespace_("inner")
[
def("g", &g),
def("f", &f__)
],
namespace_("inner")
[
def("g", &g_)
]
];
module(L, "test")
[
namespace_("inner")
[
def("h", &h)
]
];
DOSTRING(L, "assert(test.f() == 1)");
DOSTRING(L, "assert(test.f(3) == 2)");
DOSTRING(L, "assert(test.test_class.inner_fun() == 1)");
DOSTRING(L,
"a = test.test_class()\n"
"assert(a.test == 1)");
DOSTRING(L, "assert(a.inner_fun2() == 1)"); // free function
DOSTRING(L,
"b = test.test_class.val2\n"
"assert(b == 2)");
DOSTRING(L, "assert(test.inner.g() == 4)");
DOSTRING(L, "assert(test.inner.g(7) == 5)");
DOSTRING(L, "assert(test.inner.f(4) == 3)");
DOSTRING(L, "assert(test.inner.h() == 6)");
}
luabind-0.9.1+dfsg.orig/test/test_create_in_thread.cpp 0000644 0003720 0000144 00000002171 11437201244 022410 0 ustar roberto users // 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;
}
};
struct Y
{
virtual ~Y()
{}
};
struct Y_wrap : Y, luabind::wrap_base
{};
void test_main(lua_State* L)
{
using namespace luabind;
module(L) [
class_("X")
.def(constructor<>()),
class_("Y")
.def(constructor<>())
];
DOSTRING(L,
"class 'Y_lua' (Y)\n"
" function Y_lua.__init(self)\n"
" Y.__init(self)\n"
" end\n"
);
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"
);
DOSTRING(thread,
"local y = Y_lua()\n"
);
luaL_unref(L, LUA_REGISTRYINDEX, ref);
}
}
luabind-0.9.1+dfsg.orig/test/test_object.cpp 0000644 0003720 0000144 00000025267 11437201244 020411 0 ustar roberto users // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
#include
#include
#include
#include
#include
#include
using namespace luabind;
int test_object_param(const object& table)
{
LUABIND_CHECK_STACK(table.interpreter());
object current_object;
current_object = table;
lua_State* L = table.interpreter();
if (type(table) == LUA_TTABLE)
{
int sum1 = 0;
for (iterator i(table), e; i != e; ++i)
{
assert(type(*i) == LUA_TNUMBER);
sum1 += object_cast(*i);
}
int sum2 = 0;
for (raw_iterator i(table), e; i != e; ++i)
{
assert(type(*i) == LUA_TNUMBER);
sum2 += object_cast(*i);
}
// test iteration of empty table
object empty_table = newtable(L);
for (iterator i(empty_table), e; i != e; ++i)
{}
table["sum1"] = sum1;
table["sum2"] = sum2;
table["blurp"] = 5;
table["sum3"] = table["sum1"];
return 0;
}
else
{
if (type(table) != LUA_TNIL)
{
return 1;
}
else
{
return 2;
}
}
}
int test_fun()
{
return 42;
}
struct test_param : counted_type
{
luabind::object obj;
luabind::object obj2;
bool operator==(test_param const& rhs) const
{ return obj == rhs.obj && obj2 == rhs.obj2; }
};
COUNTER_GUARD(test_param);
int test_match(const luabind::object& o)
{
return 0;
}
int test_match(int i)
{
return 1;
}
void test_match_object(
luabind::object p1
, luabind::object p2
, luabind::object p3)
{
p1["ret"] = 1;
p2["ret"] = 2;
p3["ret"] = 3;
}
void test_call(lua_State* L)
{
DOSTRING(L,
"function sum(...)\n"
" local result = 0\n"
" for _,x in pairs({...}) do\n"
" result = result + x\n"
" end\n"
" return result\n"
"end\n"
);
object sum = globals(L)["sum"];
TEST_CHECK(object_cast(sum()) == 0);
TEST_CHECK(object_cast(sum(1)) == 1);
TEST_CHECK(object_cast(sum(1,2)) == 3);
TEST_CHECK(object_cast(sum(1,2,3)) == 6);
TEST_CHECK(object_cast(sum(1,2,3,4)) == 10);
TEST_CHECK(object_cast(sum(1,2,3,4,5)) == 15);
}
void test_metatable(lua_State* L)
{
object metatable = newtable(L);
object G = globals(L);
DOSTRING(L,
"function index_function(table, key)\n"
" return key*2\n"
"end\n"
"index_table = {}"
);
metatable["__index"] = G["index_function"];
setmetatable(G["index_table"], metatable);
DOSTRING(L,
"assert(index_table[0] == 0)\n"
"assert(index_table[1] == 2)\n"
"assert(index_table[2] == 4)\n"
);
DOSTRING(L,
"setmetatable(index_table, { ['luabind.metatable'] = 1 })"
);
assert(getmetatable(G["index_table"])["luabind.metatable"] == 1);
assert(type(getmetatable(G["index_table"])["nonexistent"]) == LUA_TNIL);
}
int with_upvalues(lua_State *)
{
return 0;
}
void test_upvalues(lua_State* L)
{
lua_pushnumber(L, 3);
lua_pushnumber(L, 4);
lua_pushcclosure(L, &with_upvalues, 2);
object f(from_stack(L, -1));
lua_pop(L, 1);
assert(getupvalue(f, 1) == 3);
assert(getupvalue(f, 2) == 4);
setupvalue(f, 1, object(L, 4));
assert(getupvalue(f, 1) == 4);
assert(getupvalue(f, 2) == 4);
setupvalue(f, 2, object(L, 5));
assert(getupvalue(f, 1) == 4);
assert(getupvalue(f, 2) == 5);
}
void test_explicit_conversions(lua_State* L)
{
lua_pushcclosure(L, &with_upvalues, 0);
object f(from_stack(L, -1));
lua_pop(L, 1);
assert(tocfunction(f) == &with_upvalues);
int* p = static_cast(lua_newuserdata(L, sizeof(int)));
*p = 1234;
object x(from_stack(L, -1));
lua_pop(L, 1);
assert(*touserdata(x) == 1234);
}
int with_argument(argument const& arg)
{
return object_cast(arg) * 2;
}
int with_table_argument(argument const& arg, argument const& key)
{
return object_cast(arg[key]);
}
void test_argument(lua_State* L)
{
module(L) [
def("with_argument", &with_argument),
def("with_table_argument", &with_table_argument)
];
DOSTRING(L,
"assert(with_argument(1) == 2)\n"
"assert(with_argument(2) == 4)\n"
);
DOSTRING(L,
"x = { foo = 1, bar = 2 }\n"
"assert(with_table_argument(x, 'foo') == 1)\n"
"assert(with_table_argument(x, 'bar') == 2)\n"
);
}
void test_bool_convertible(lua_State* L)
{
DOSTRING(L,
"x1 = nil\n"
"x2 = false\n"
"x3 = 0\n"
"x4 = 1\n"
);
DOSTRING(L,
"assert(not x1)\n"
"assert(not x2)\n"
"assert(x3)\n"
"assert(x4)\n"
);
object G = globals(L);
object x1 = G["x1"];
object x2 = G["x2"];
object x3 = G["x3"];
object x4 = G["x4"];
assert(!x1);
assert(!x2);
assert(x3);
assert(x4);
assert(!G["x1"]);
assert(!G["x2"]);
assert(G["x3"]);
assert(G["x4"]);
}
void test_main(lua_State* L)
{
using namespace luabind;
module(L)
[
def("test_object_param", &test_object_param),
def("test_fun", &test_fun),
def("test_match", (int(*)(const luabind::object&))&test_match),
def("test_match", (int(*)(int))&test_match),
def("test_match_object", &test_match_object),
class_("test_param")
.def(constructor<>())
.def_readwrite("obj", &test_param::obj)
.def_readonly("obj2", &test_param::obj2)
.def(const_self == const_self)
];
object uninitialized;
TEST_CHECK(!uninitialized);
TEST_CHECK(!uninitialized.is_valid());
test_param temp_object;
globals(L)["temp"] = temp_object;
TEST_CHECK(object_cast(globals(L)["temp"]) == temp_object);
globals(L)["temp"] = &temp_object;
TEST_CHECK(object_cast(globals(L)["temp"]) == &temp_object);
TEST_CHECK(globals(L)["temp"] == temp_object);
// test the registry
object reg = registry(L);
reg["__a"] = "foobar";
TEST_CHECK(object_cast(registry(L)["__a"]) == "foobar");
DOSTRING(L,
"t = 2\n"
"assert(test_object_param(t) == 1)");
DOSTRING(L, "assert(test_object_param(nil) == 2)");
DOSTRING(L, "t = { ['oh'] = 4, 3, 5, 7, 13 }");
DOSTRING(L, "assert(test_object_param(t) == 0)");
DOSTRING(L, "assert(t.sum1 == 4 + 3 + 5 + 7 + 13)");
DOSTRING(L, "assert(t.sum2 == 4 + 3 + 5 + 7 + 13)");
DOSTRING(L, "assert(t.blurp == 5)");
object g = globals(L);
object ret = g["test_fun"]();
TEST_CHECK(object_cast(ret) == 42);
DOSTRING(L, "function test_param_policies(x, y) end");
object test_param_policies = g["test_param_policies"];
int a = type(test_param_policies);
TEST_CHECK(a == LUA_TFUNCTION);
luabind::object obj;
obj = luabind::object();
// call the function and tell lua to adopt the pointer passed as first argument
test_param_policies(5, new test_param())[adopt(_2)];
DOSTRING(L, "assert(test_match(7) == 1)");
DOSTRING(L, "assert(test_match('oo') == 0)");
DOSTRING(L,
"t = test_param()\n"
"t.obj = 'foo'\n"
"assert(t.obj == 'foo')\n"
"assert(t.obj2 == nil)");
DOSTRING(L,
"function test_object_policies(a) glob = a\n"
"return 6\n"
"end");
object test_object_policies = g["test_object_policies"];
object ret_val = test_object_policies("teststring")[detail::null_type()];
TEST_CHECK(object_cast(ret_val) == 6);
TEST_CHECK(ret_val == 6);
TEST_CHECK(6 == ret_val);
g["temp_val"] = 6;
TEST_CHECK(ret_val == g["temp_val"]);
object temp_val = g["temp_val"];
TEST_CHECK(ret_val == temp_val);
g["temp"] = "test string";
TEST_CHECK(boost::lexical_cast(g["temp"]) == "test string");
g["temp"] = 6;
TEST_CHECK(boost::lexical_cast(g["temp"]) == "6");
TEST_CHECK(object_cast(g["glob"]) == "teststring");
TEST_CHECK(object_cast(gettable(g, "glob")) == "teststring");
TEST_CHECK(object_cast(rawget(g, "glob")) == "teststring");
object t = newtable(L);
TEST_CHECK(iterator(t) == iterator());
TEST_CHECK(raw_iterator(t) == raw_iterator());
t["foo"] = "bar";
TEST_CHECK(object_cast(t["foo"]) == "bar");
TEST_CHECK(object_cast(*iterator(t)) == "bar");
TEST_CHECK(object_cast(*raw_iterator(t)) == "bar");
t["foo"] = nil; // luabind::nil_type
TEST_CHECK(iterator(t) == iterator());
TEST_CHECK(raw_iterator(t) == raw_iterator());
t["foo"] = "bar";
iterator it1(t);
*it1 = nil;
TEST_CHECK(iterator(t) == iterator());
TEST_CHECK(raw_iterator(t) == raw_iterator());
t["foo"] = "bar";
raw_iterator it2(t);
*it2 = nil;
TEST_CHECK(iterator(t) == iterator());
TEST_CHECK(raw_iterator(t) == raw_iterator());
DOSTRING(L,
"p1 = {}\n"
"p2 = {}\n"
"p3 = {}\n"
"test_match_object(p1, p2, p3)\n"
"assert(p1.ret == 1)\n"
"assert(p2.ret == 2)\n"
"assert(p3.ret == 3)\n");
#ifndef LUABIND_NO_EXCEPTIONS
try
{
object not_initialized;
int i = object_cast(not_initialized);
(void)i;
TEST_ERROR("invalid cast succeeded");
}
catch(luabind::cast_failed&) {}
#endif
object not_initialized;
TEST_CHECK(!object_cast_nothrow(not_initialized));
TEST_CHECK(!not_initialized.is_valid());
TEST_CHECK(!not_initialized);
DOSTRING(L, "t = { {1}, {2}, {3}, {4} }");
int inner_sum = 0;
for (iterator i(globals(L)["t"]), e; i != e; ++i)
{
inner_sum += object_cast((*i)[1]);
}
TEST_CHECK(inner_sum == 1 + 2 + 3 + 4);
DOSTRING(L, "t = { {1, 2}, {3, 4}, {5, 6}, {7, 8} }");
inner_sum = 0;
for (iterator i(globals(L)["t"]), e; i != e; ++i)
{
for (iterator j(*i), e; j != e; ++j)
{
inner_sum += object_cast(*j);
}
}
TEST_CHECK(inner_sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
TEST_CHECK(object_cast(globals(L)["t"][2][2]) == 4);
test_call(L);
test_metatable(L);
test_upvalues(L);
test_explicit_conversions(L);
test_argument(L);
test_bool_convertible(L);
}
luabind-0.9.1+dfsg.orig/test/test_implicit_cast.cpp 0000644 0003720 0000144 00000007443 11437201244 021763 0 ustar roberto users // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
#include
struct A : counted_type
{ virtual ~A() {} };
struct B : A, counted_type
{};
struct enum_placeholder {};
typedef enum { VAL1 = 1, VAL2 = 2 } LBENUM_t;
LBENUM_t enum_by_val(LBENUM_t e) { return e; }
LBENUM_t enum_by_const_ref(const LBENUM_t &e) { return e; }
struct test_implicit : counted_type
{
char const* f(A*) { return "f(A*)"; }
char const* f(B*) { return "f(B*)"; }
};
struct char_pointer_convertable
: counted_type
{
operator const char*() const { return "foo!"; }
};
void func(const char_pointer_convertable& f)
{
}
void not_convertable(boost::shared_ptr)
{
TEST_CHECK(false);
}
int f(int& a)
{
return a;
}
COUNTER_GUARD(A);
COUNTER_GUARD(B);
COUNTER_GUARD(test_implicit);
COUNTER_GUARD(char_pointer_convertable);
void test_main(lua_State* L)
{
using namespace luabind;
typedef char const*(test_implicit::*f1)(A*);
typedef char const*(test_implicit::*f2)(B*);
module(L)
[
class_("A")
.def(constructor<>()),
class_("B")
.def(constructor<>()),
class_("test")
.def(constructor<>())
.def("f", (f1)&test_implicit::f)
.def("f", (f2)&test_implicit::f),
class_("char_ptr")
.def(constructor<>()),
class_("LBENUM")
.enum_("constants")
[
value("VAL1", VAL1),
value("VAL2", VAL2)
],
def("enum_by_val", &enum_by_val),
def("enum_by_const_ref", &enum_by_const_ref),
def("func", &func),
def("no_convert", ¬_convertable),
def("f", &f)
];
DOSTRING(L, "a = A()");
DOSTRING(L, "b = B()");
DOSTRING(L, "t = test()");
DOSTRING(L, "assert(t:f(a) == 'f(A*)')");
DOSTRING(L, "assert(t:f(b) == 'f(B*)')");
DOSTRING(L,
"a = char_ptr()\n"
"func(a)");
DOSTRING(L, "assert(LBENUM.VAL1 == 1)");
DOSTRING(L, "assert(LBENUM.VAL2 == 2)");
DOSTRING(L, "assert(enum_by_val(LBENUM.VAL1) == LBENUM.VAL1)");
DOSTRING(L, "assert(enum_by_val(LBENUM.VAL2) == LBENUM.VAL2)");
DOSTRING(L, "assert(enum_by_const_ref(LBENUM.VAL1) == LBENUM.VAL1)");
DOSTRING(L, "assert(enum_by_const_ref(LBENUM.VAL2) == LBENUM.VAL2)");
DOSTRING_EXPECTED(L,
"a = A()\n"
"no_convert(a)",
("No matching overload found, candidates:\n"
"void no_convert(custom ["
+ std::string(typeid(boost::shared_ptr).name()) + "])").c_str());
DOSTRING_EXPECTED(L,
"a = nil\n"
"f(a)",
"No matching overload found, candidates:\n"
"int f(int&)");
}
luabind-0.9.1+dfsg.orig/test/test_table.cpp 0000644 0003720 0000144 00000001636 11437201244 020224 0 ustar roberto users // 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
void f(luabind::table<> const& x)
{
TEST_CHECK(luabind::type(x) == LUA_TTABLE);
}
void g(luabind::table const& x)
{
TEST_CHECK(luabind::type(x) == LUA_TTABLE);
}
void test_main(lua_State* L)
{
using namespace luabind;
module(L) [
def("f", &f),
def("g", &g)
];
DOSTRING(L,
"f {1,2,3}\n"
"g {1,2,3}\n"
);
DOSTRING_EXPECTED(L,
"f(1)\n",
"No matching overload found, candidates:\n"
"void f(table const&)"
);
DOSTRING_EXPECTED(L,
"g(1)\n",
"No matching overload found, candidates:\n"
"void g(table const&)"
);
}
luabind-0.9.1+dfsg.orig/test/test_tag_function.cpp 0000644 0003720 0000144 00000001746 11437201244 021617 0 ustar roberto users // Copyright Daniel Wallin 2008. 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
#include
#include
int f(int x, int y)
{
return x + y;
}
struct X
{
int f(int x, int y)
{
return x + y;
}
};
void test_main(lua_State* L)
{
using namespace luabind;
module(L) [
def("f", tag_function(boost::bind(&f, 5, _1))),
class_("X")
.def(constructor<>())
.def("f", tag_function(boost::bind(&X::f, _1, 10, _2)))
];
DOSTRING(L,
"assert(f(0) == 5)\n"
"assert(f(1) == 6)\n"
"assert(f(5) == 10)\n"
);
DOSTRING(L,
"x = X()\n"
"assert(x:f(0) == 10)\n"
"assert(x:f(1) == 11)\n"
"assert(x:f(5) == 15)\n"
);
}
luabind-0.9.1+dfsg.orig/test/test_collapse_converter.cpp 0000644 0003720 0000144 00000002321 11437201244 023016 0 ustar roberto users // 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 X
{
X(int x, int y)
: x(x)
, y(y)
{}
int x;
int y;
};
namespace luabind {
int combine_score(int s1, int s2)
{
if (s1 < 0 || s2 < 0) return -1;
return s1 + s2;
}
template <>
struct default_converter
: native_converter_base
{
int const consumed_args(...)
{
return 2;
}
int compute_score(lua_State* L, int index)
{
return combine_score(
c1.compute_score(L, index), c2.compute_score(L, index + 1));
}
X from(lua_State* L, int index)
{
return X(lua_tonumber(L, index), lua_tonumber(L, index + 1));
}
default_converter c1;
default_converter c2;
};
} // namespace luabind
int take(X x)
{
return x.x + x.y;
}
void test_main(lua_State* L)
{
using namespace luabind;
module(L) [
def("take", &take)
];
DOSTRING(L,
"assert(take(1,1) == 2)\n"
"assert(take(2,3) == 5)\n"
);
}
luabind-0.9.1+dfsg.orig/test/test_super_leak.cpp 0000644 0003720 0000144 00000002015 11437201244 021257 0 ustar roberto users // 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 Foo
{
static std::size_t count;
Foo()
{
++count;
}
~Foo()
{
--count;
}
};
std::size_t Foo::count = 0;
void test_main(lua_State* L)
{
using namespace luabind;
module(L) [
class_("Foo")
.def(constructor<>())
];
// This used to leak the last created instance in one of the
// upvalues to the "super" function.
disable_super_deprecation();
DOSTRING(L,
"class 'Bar' (Foo)\n"
"function Bar.__init(self)\n"
" Foo.__init(self)\n"
"end\n"
);
DOSTRING(L,
"x = Bar()\n"
);
assert(Foo::count == 1);
DOSTRING(L,
"x = nil\n"
);
lua_gc(L, LUA_GCCOLLECT, 0);
assert(Foo::count == 0);
}
luabind-0.9.1+dfsg.orig/test/test_has_get_pointer.cpp 0000755 0003720 0000144 00000003674 11437201244 022316 0 ustar roberto users // Copyright (c) 2005 Daniel Wallin
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include
#include
#include
#include
#include
namespace lb = luabind::detail;
namespace test
{
struct X
{
};
struct Y
{
};
Y* get_pointer(Y const&);
struct Z : boost::enable_shared_from_this {};
} // namespace test
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
namespace luabind
{
using test::get_pointer;
using boost::get_pointer;
} // namespace luabind
#endif
BOOST_MPL_ASSERT(( lb::has_get_pointer > ));
BOOST_MPL_ASSERT(( lb::has_get_pointer ));
BOOST_MPL_ASSERT(( lb::has_get_pointer ));
BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer ));
BOOST_MPL_ASSERT_NOT(( lb::has_get_pointer ));
BOOST_MPL_ASSERT(( lb::has_get_pointer ));
luabind-0.9.1+dfsg.orig/test/test_separation.cpp 0000755 0003720 0000144 00000003313 11437201244 021277 0 ustar roberto users // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
#include
namespace {
struct X {};
struct Y {};
} // namespace unnamed
luabind::scope test_separate_registration()
{
using namespace luabind;
return class_("X")
.def(constructor<>()),
class_("Y")
.def(constructor<>())
;
}
void test_main(lua_State* L)
{
using namespace luabind;
module(L)
[
namespace_("Z") [
test_separate_registration()
]
];
DOSTRING(L, "x = Z.X()");
DOSTRING(L, "y = Z.Y()");
}
luabind-0.9.1+dfsg.orig/test/test_set_instance_value.cpp 0000644 0003720 0000144 00000001501 11437201244 022777 0 ustar roberto users // 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
void test_main(lua_State* L)
{
DOSTRING(L,
"class 'X'\n"
" function X:__init()\n"
" self.value = 1\n"
" self.second = 2\n"
" end\n"
"\n"
"x = X()\n"
"assert(x.value == 1)\n"
"assert(x.second == 2)\n"
"x.value = 2\n"
"assert(x.value == 2)\n"
"assert(x.second == 2)\n"
"x.second = 3\n"
"y = X()\n"
"assert(y.value == 1)\n"
"assert(y.second == 2)\n"
"assert(x.value == 2)\n"
"assert(x.second == 3)\n"
);
}
luabind-0.9.1+dfsg.orig/test/test.hpp 0000755 0003720 0000144 00000010362 11437201244 017061 0 ustar roberto users // Copyright (c) 2005 Daniel Wallin, Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef TEST_050415_HPP
#define TEST_050415_HPP
#include
#include
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
void report_failure(char const* str, char const* file, int line);
#if defined(_MSC_VER)
#define COUNTER_GUARD(x)
#else
#define COUNTER_GUARD(type) \
struct BOOST_PP_CAT(type, _counter_guard) \
{ \
~BOOST_PP_CAT(type, _counter_guard()) \
{ \
TEST_CHECK(counted_type::count == 0); \
} \
} BOOST_PP_CAT(type, _guard)
#endif
#define TEST_REPORT_AUX(x, line, file) \
report_failure(x, line, file)
#define TEST_CHECK(x) \
if (!(x)) \
TEST_REPORT_AUX("TEST_CHECK failed: \"" #x "\"", __FILE__, __LINE__)
#define TEST_ERROR(x) \
TEST_REPORT_AUX((std::string("ERROR: \"") + x + "\"").c_str(), __FILE__, __LINE__)
#define TEST_NOTHROW(x) \
try \
{ \
x; \
} \
catch (...) \
{ \
TEST_ERROR("Exception thrown: " #x); \
}
void dostring(lua_State* L, char const* str);
template
struct counted_type
{
static int count;
counted_type()
{
++count;
}
counted_type(counted_type const&)
{
++count;
}
~counted_type()
{
TEST_CHECK(--count >= 0);
}
};
template
int counted_type::count = 0;
#define DOSTRING_EXPECTED(state_, str, expected) \
{ \
try \
{ \
dostring(state_, str); \
} \
catch (luabind::error const& e) \
{ \
using namespace std; \
if (std::strcmp( \
lua_tostring(e.state(), -1) \
, (char const*)expected)) \
{ \
TEST_ERROR(lua_tostring(e.state(), -1)); \
lua_pop(L, 1); \
} \
} \
catch (std::string const& s) \
{ \
if (s != expected) \
TEST_ERROR(s.c_str()); \
} \
}
#define DOSTRING(state_, str) \
{ \
try \
{ \
dostring(state_, str); \
} \
catch (luabind::error const& e) \
{ \
TEST_ERROR(lua_tostring(e.state(), -1)); \
lua_pop(L, 1); \
} \
catch (std::string const& s) \
{ \
TEST_ERROR(s.c_str()); \
} \
}
#endif // TEST_050415_HPP
luabind-0.9.1+dfsg.orig/test/test_const.cpp 0000644 0003720 0000144 00000003205 11437201244 020255 0 ustar roberto users // Copyright (c) 2004 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
struct A
{
const A* f() { return this; }
int g1() const { return 1; }
int g2() { return 2; }
};
void test_main(lua_State* L)
{
using namespace luabind;
module(L)
[
class_("A")
.def(constructor<>())
.def("f", &A::f)
.def("g", &A::g1)
.def("g", &A::g2)
];
DOSTRING(L, "a = A()");
DOSTRING(L, "assert(a:g() == 2)");
DOSTRING(L, "a2 = a:f()");
DOSTRING(L, "assert(a2:g() == 1)");
}
luabind-0.9.1+dfsg.orig/test/test_adopt_wrapper.cpp 0000644 0003720 0000144 00000001300 11437201244 021770 0 ustar roberto users // Copyright Daniel Wallin 2008. 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
#include
struct X
{
virtual ~X()
{}
};
struct X_wrap : X, luabind::wrap_base
{};
X* make()
{
return new X;
}
void take(X* p)
{
delete p;
}
void test_main(lua_State* L)
{
using namespace luabind;
module(L) [
class_("X"),
def("make", &make, adopt(result)),
def("take", &take, adopt(_1))
];
DOSTRING(L,
"take(make())\n"
);
}
luabind-0.9.1+dfsg.orig/test/test_vector_of_object.cpp 0000755 0003720 0000144 00000002527 11437201244 022454 0 ustar roberto users // Copyright (c) 2005 Daniel Wallin
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#include "test.hpp"
#include
using namespace luabind;
void test_main(lua_State* L)
{
std::vector