mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
2203c1f64f
Overhaul docs for examples Overhaul function_result and protected_function_result proxies
58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#define SOL_CHECK_ARGUMENTS 1
|
|
#define SOL_ENABLE_INTEROP 1
|
|
|
|
#include <sol.hpp>
|
|
|
|
#include <catch.hpp>
|
|
|
|
TEST_CASE("storage/registry construction", "ensure entries from the registry can be retrieved") {
|
|
const auto& code = R"(
|
|
function f()
|
|
return 2
|
|
end
|
|
)";
|
|
|
|
sol::state lua;
|
|
lua.script(code);
|
|
sol::function f = lua["f"];
|
|
sol::reference r = lua["f"];
|
|
sol::function regf(lua, f);
|
|
sol::reference regr(lua, sol::ref_index(f.registry_index()));
|
|
bool isequal = f == r;
|
|
REQUIRE(isequal);
|
|
isequal = f == regf;
|
|
REQUIRE(isequal);
|
|
isequal = f == regr;
|
|
REQUIRE(isequal);
|
|
}
|
|
|
|
TEST_CASE("storage/registry construction empty", "ensure entries from the registry can be retrieved") {
|
|
sol::state lua;
|
|
sol::function f = lua["f"];
|
|
sol::reference r = lua["f"];
|
|
sol::function regf(lua, f);
|
|
sol::reference regr(lua, sol::ref_index(f.registry_index()));
|
|
bool isequal = f == r;
|
|
REQUIRE(isequal);
|
|
isequal = f == regf;
|
|
REQUIRE(isequal);
|
|
isequal = f == regr;
|
|
REQUIRE(isequal);
|
|
}
|
|
|
|
TEST_CASE("storage/main thread", "ensure round-tripping and pulling out thread data even on 5.1 with a backup works") {
|
|
sol::state lua;
|
|
{
|
|
sol::stack_guard g(lua);
|
|
lua_State* orig = lua;
|
|
lua_State* ts = sol::main_thread(lua, lua);
|
|
REQUIRE(ts == orig);
|
|
}
|
|
{
|
|
sol::stack_guard g(lua);
|
|
lua_State* orig = lua;
|
|
lua_State* ts = sol::main_thread(lua);
|
|
REQUIRE(ts == orig);
|
|
}
|
|
}
|