mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
commit
2f84be5c5e
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -18,3 +18,9 @@ liblua.a
|
|||
sol/include/
|
||||
.ninja*
|
||||
include/
|
||||
lib/liblua5.2.a
|
||||
*.config
|
||||
*.creator
|
||||
*.files
|
||||
*.includes
|
||||
main.cpp
|
||||
|
|
27
main.ninja
Normal file
27
main.ninja
Normal file
|
@ -0,0 +1,27 @@
|
|||
# This file has been generated by shinobi version 0.9.5
|
||||
|
||||
ninja_required_version = 1.3
|
||||
builddir = bin
|
||||
objdir = obj
|
||||
cxx = g++
|
||||
cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG
|
||||
incflags = -I"." -I"./include" -I"." -I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/"
|
||||
linkflags = -static -L"./lib" -llua5.2
|
||||
|
||||
rule compile
|
||||
command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags
|
||||
deps = gcc
|
||||
depfile = $out.d
|
||||
description = Compiling $in
|
||||
|
||||
rule link
|
||||
command = $cxx $in -o $out $linkflags
|
||||
description = Creating $out
|
||||
|
||||
build $objdir/main.o: compile main.cpp
|
||||
|
||||
build $builddir/tests: link $objdir/main.o
|
||||
|
||||
build install: phony $builddir/tests
|
||||
|
||||
default install
|
|
@ -19,8 +19,8 @@
|
|||
// 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 error_HPP
|
||||
#define error_HPP
|
||||
#ifndef SOL_ERROR_HPP
|
||||
#define SOL_ERROR_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
@ -32,4 +32,4 @@ public:
|
|||
};
|
||||
} // sol
|
||||
|
||||
#endif // error_HPP
|
||||
#endif // SOL_ERROR_HPP
|
|
@ -110,8 +110,9 @@ private:
|
|||
template<std::size_t N>
|
||||
void build_function_tables() {}
|
||||
|
||||
template<std::size_t N, typename... Args, typename Ret>
|
||||
void build_function_tables(std::string name, Ret T::* func, Args&&... args) {
|
||||
template<std::size_t N, typename... Args, typename TBase, typename Ret>
|
||||
void build_function_tables(std::string name, Ret TBase::* func, Args&&... args) {
|
||||
static_assert(std::is_base_of<TBase, T>::value, "Any registered function must be part of the class");
|
||||
typedef typename std::decay<decltype(func)>::type function_type;
|
||||
functionnames.push_back(std::move(name));
|
||||
functions.emplace_back(detail::make_unique<userdata_function<function_type, T>>(std::move(func)));
|
||||
|
|
45
tests.cpp
45
tests.cpp
|
@ -50,6 +50,27 @@ int plop_xyz(int x, int y, std::string z) {
|
|||
return 11;
|
||||
}
|
||||
|
||||
class Base {
|
||||
public:
|
||||
Base(int a_num) : m_num(a_num) { }
|
||||
|
||||
int get_num() {
|
||||
return m_num;
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_num;
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived(int a_num) : Base(a_num) { }
|
||||
|
||||
int get_num_10() {
|
||||
return 10 * m_num;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("simple/set_global", "Check if the set_global works properly.") {
|
||||
sol::state lua;
|
||||
|
||||
|
@ -448,3 +469,27 @@ TEST_CASE("tables/userdata utility", "Show internal management of classes regist
|
|||
REQUIRE(bresult == 1);
|
||||
REQUIRE(cresult == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("tables/userdata utility derived", "userdata classes must play nice when a derived class does not overload a publically visible base function") {
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
sol::constructors<sol::types<int>> basector;
|
||||
sol::userdata<Base> baseuserdata("Base", basector, "get_num", &Base::get_num);
|
||||
|
||||
lua.set_userdata(baseuserdata);
|
||||
|
||||
lua.script("base = Base.new(5)");
|
||||
lua.script("print(base:get_num())");
|
||||
|
||||
sol::constructors<sol::types<int>> derivedctor;
|
||||
sol::userdata<Derived> deriveduserdata("Derived", derivedctor, "get_num", &Derived::get_num, "get_num_10", &Derived::get_num_10);
|
||||
|
||||
lua.set_userdata(deriveduserdata);
|
||||
|
||||
lua.script("derived = Derived.new(7)");
|
||||
lua.script("dgn10 = derived:get_num_10()\nprint(dgn10)");
|
||||
lua.script("dgn = derived:get_num()\nprint(dgn)");
|
||||
|
||||
REQUIRE((lua.get<int>("dgn10") == 70));
|
||||
REQUIRE((lua.get<int>("dgn") == 7));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user