mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Weee, script return value tests
This commit is contained in:
parent
9836aba51d
commit
d863a56760
@ -20,8 +20,8 @@
|
|||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2016-11-01 23:23:32.715464 UTC
|
// Generated 2016-11-02 22:59:47.937773 UTC
|
||||||
// This header was generated with sol v2.14.12 (revision 0a165dc)
|
// This header was generated with sol v2.14.12 (revision 9836aba)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
@ -11962,7 +11962,7 @@ namespace sol {
|
|||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
decltype(auto) call(Args&&... args) {
|
decltype(auto) call(Args&&... args) {
|
||||||
return get<function>().template call<Ret...>(std::forward<Args>(args)...);
|
return get<protected_function>().template call<Ret...>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
@ -12069,6 +12069,10 @@ namespace sol {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state_view(this_state L) : state_view(L.L){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
lua_State* lua_state() const {
|
lua_State* lua_state() const {
|
||||||
return L;
|
return L;
|
||||||
}
|
}
|
||||||
@ -12187,17 +12191,19 @@ namespace sol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function_result script(const std::string& code) {
|
function_result script(const std::string& code) {
|
||||||
int index = (::std::max)(lua_gettop(L), 1);
|
int index = lua_gettop(L);
|
||||||
stack::script(L, code);
|
stack::script(L, code);
|
||||||
int returns = lua_gettop(L) - (index - 1);
|
int postindex = lua_gettop(L);
|
||||||
return function_result(L, index, returns);
|
int returns = postindex - index;
|
||||||
|
return function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
|
||||||
}
|
}
|
||||||
|
|
||||||
function_result script_file(const std::string& filename) {
|
function_result script_file(const std::string& filename) {
|
||||||
int index = (::std::max)(lua_gettop(L), 1);
|
int index = lua_gettop(L);
|
||||||
stack::script_file(L, filename);
|
stack::script_file(L, filename);
|
||||||
int returns = lua_gettop(L) - (index - 1);
|
int postindex = lua_gettop(L);
|
||||||
return function_result(L, index, returns);
|
int returns = postindex - index;
|
||||||
|
return function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
|
||||||
}
|
}
|
||||||
|
|
||||||
load_result load(const std::string& code) {
|
load_result load(const std::string& code) {
|
||||||
|
@ -119,7 +119,7 @@ namespace sol {
|
|||||||
|
|
||||||
template<typename... Ret, typename... Args>
|
template<typename... Ret, typename... Args>
|
||||||
decltype(auto) call(Args&&... args) {
|
decltype(auto) call(Args&&... args) {
|
||||||
return get<function>().template call<Ret...>(std::forward<Args>(args)...);
|
return get<protected_function>().template call<Ret...>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
@ -115,6 +115,10 @@ namespace sol {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state_view(this_state L) : state_view(L.L){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
lua_State* lua_state() const {
|
lua_State* lua_state() const {
|
||||||
return L;
|
return L;
|
||||||
}
|
}
|
||||||
@ -233,17 +237,19 @@ namespace sol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function_result script(const std::string& code) {
|
function_result script(const std::string& code) {
|
||||||
int index = (::std::max)(lua_gettop(L), 1);
|
int index = lua_gettop(L);
|
||||||
stack::script(L, code);
|
stack::script(L, code);
|
||||||
int returns = lua_gettop(L) - (index - 1);
|
int postindex = lua_gettop(L);
|
||||||
return function_result(L, index, returns);
|
int returns = postindex - index;
|
||||||
|
return function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
|
||||||
}
|
}
|
||||||
|
|
||||||
function_result script_file(const std::string& filename) {
|
function_result script_file(const std::string& filename) {
|
||||||
int index = (::std::max)(lua_gettop(L), 1);
|
int index = lua_gettop(L);
|
||||||
stack::script_file(L, filename);
|
stack::script_file(L, filename);
|
||||||
int returns = lua_gettop(L) - (index - 1);
|
int postindex = lua_gettop(L);
|
||||||
return function_result(L, index, returns);
|
int returns = postindex - index;
|
||||||
|
return function_result(L, (std::max)(postindex - (returns - 1), 1), returns);
|
||||||
}
|
}
|
||||||
|
|
||||||
load_result load(const std::string& code) {
|
load_result load(const std::string& code) {
|
||||||
|
76
tests.cpp
76
tests.cpp
@ -716,3 +716,79 @@ TEST_CASE("numbers/integers", "make sure integers are detectable on most platfor
|
|||||||
REQUIRE_FALSE(b_is_int);
|
REQUIRE_FALSE(b_is_int);
|
||||||
REQUIRE(b_is_double);
|
REQUIRE(b_is_double);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("state/script-returns", "make sure script returns are done properly") {
|
||||||
|
std::string script =
|
||||||
|
R"(
|
||||||
|
local example =
|
||||||
|
{
|
||||||
|
str = "this is a string",
|
||||||
|
num = 1234,
|
||||||
|
|
||||||
|
func = function(self)
|
||||||
|
print(self.str)
|
||||||
|
return "fstr"
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
return example;
|
||||||
|
)";
|
||||||
|
|
||||||
|
auto bar = [&script](sol::this_state l) {
|
||||||
|
sol::state_view lua = l;
|
||||||
|
sol::table data = lua.script(script);
|
||||||
|
|
||||||
|
std::string str = data["str"];
|
||||||
|
int num = data["num"];
|
||||||
|
std::string fstr = data["func"](data);
|
||||||
|
REQUIRE(str == "this is a string");
|
||||||
|
REQUIRE(fstr == "fstr");
|
||||||
|
REQUIRE(num == 1234);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto foo = [&script](int, sol::this_state l) {
|
||||||
|
sol::state_view lua = l;
|
||||||
|
sol::table data = lua.script(script);
|
||||||
|
|
||||||
|
std::string str = data["str"];
|
||||||
|
int num = data["num"];
|
||||||
|
std::string fstr = data["func"](data);
|
||||||
|
REQUIRE(str == "this is a string");
|
||||||
|
REQUIRE(fstr == "fstr");
|
||||||
|
REQUIRE(num == 1234);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto bar2 = [&script](sol::this_state l) {
|
||||||
|
sol::state_view lua = l;
|
||||||
|
sol::table data = lua.do_string(script);
|
||||||
|
|
||||||
|
std::string str = data["str"];
|
||||||
|
int num = data["num"];
|
||||||
|
std::string fstr = data["func"](data);
|
||||||
|
REQUIRE(str == "this is a string");
|
||||||
|
REQUIRE(fstr == "fstr");
|
||||||
|
REQUIRE(num == 1234);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto foo2 = [&script](int, sol::this_state l) {
|
||||||
|
sol::state_view lua = l;
|
||||||
|
sol::table data = lua.do_string(script);
|
||||||
|
|
||||||
|
std::string str = data["str"];
|
||||||
|
int num = data["num"];
|
||||||
|
std::string fstr = data["func"](data);
|
||||||
|
REQUIRE(str == "this is a string");
|
||||||
|
REQUIRE(fstr == "fstr");
|
||||||
|
REQUIRE(num == 1234);
|
||||||
|
};
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
lua.open_libraries();
|
||||||
|
|
||||||
|
lua.set_function("foo", foo);
|
||||||
|
lua.set_function("foo2", foo2);
|
||||||
|
lua.set_function("bar", bar);
|
||||||
|
lua.set_function("bar2", bar2);
|
||||||
|
|
||||||
|
lua.script("bar() bar2() foo(1) foo2(1)");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user