mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
update tests and single again
add assert.hpp for better code understanding prepare to rewrite all the damn docs, and update the tutorials...
This commit is contained in:
parent
acade465f1
commit
002303d52b
|
@ -30,7 +30,7 @@ before_install:
|
||||||
- sudo docker ps -a
|
- sudo docker ps -a
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- sudo docker
|
- sudo docker run -it ubuntu
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks:
|
webhooks:
|
||||||
|
|
|
@ -92,6 +92,8 @@ option(SINGLE "Enable build of single header files" ON)
|
||||||
# Single tests will only be turned on if both SINGLE and TESTS are defined
|
# Single tests will only be turned on if both SINGLE and TESTS are defined
|
||||||
CMAKE_DEPENDENT_OPTION(TESTS_SINGLE "Enable build of tests using the generated single headers" ON
|
CMAKE_DEPENDENT_OPTION(TESTS_SINGLE "Enable build of tests using the generated single headers" ON
|
||||||
"SINGLE;TESTS" OFF)
|
"SINGLE;TESTS" OFF)
|
||||||
|
CMAKE_DEPENDENT_OPTION(EXAMPLES_SINGLE "Enable build of tests using the generated single headers" OFF
|
||||||
|
"SINGLE;EXAMPLES" OFF)
|
||||||
if (TESTS AND EXAMPLES)
|
if (TESTS AND EXAMPLES)
|
||||||
option(TESTS_EXAMPLES "Enable build of examples as tests" ON)
|
option(TESTS_EXAMPLES "Enable build of examples as tests" ON)
|
||||||
else()
|
else()
|
||||||
|
|
23
appveyor.yml
23
appveyor.yml
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
version: 1.0.{build}
|
version: 1.0.{build}
|
||||||
|
|
||||||
|
max_jobs: 4
|
||||||
|
|
||||||
pull_requests:
|
pull_requests:
|
||||||
do_not_increment_build_number: true
|
do_not_increment_build_number: true
|
||||||
|
|
||||||
|
@ -29,18 +31,15 @@ image:
|
||||||
- Visual Studio 2017
|
- Visual Studio 2017
|
||||||
- Visual Studio 2015
|
- Visual Studio 2015
|
||||||
|
|
||||||
configuration:
|
|
||||||
- Release
|
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- LUA_VERSION: 5.3.4
|
|
||||||
- LUA_VERSION: 5.2.4
|
|
||||||
- LUA_VERSION: 5.1.5
|
|
||||||
- LUA_VERSION: 5.3.4
|
- LUA_VERSION: 5.3.4
|
||||||
MINGW_VERSION: 6.3.0
|
MINGW_VERSION: 6.3.0
|
||||||
- LUA_VERSION: 5.3.4
|
- LUA_VERSION: 5.3.4
|
||||||
MINGW_VERSION: 5.3.0
|
MINGW_VERSION: 5.3.0
|
||||||
|
- LUA_VERSION: 5.3.4
|
||||||
|
- LUA_VERSION: 5.2.4
|
||||||
|
- LUA_VERSION: 5.1.5
|
||||||
|
|
||||||
platform:
|
platform:
|
||||||
- x86
|
- x86
|
||||||
|
@ -48,8 +47,10 @@ platform:
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
# oldest compiler is allowed to fail here due to esoteric bugs
|
||||||
- MINGW_VERSION: 5.3.0
|
- MINGW_VERSION: 5.3.0
|
||||||
- MINGW_VERSION: 6.3.0
|
# 32-bit builds are temperamental with exceptions
|
||||||
|
- platform: x86
|
||||||
exclude:
|
exclude:
|
||||||
- platform: x86
|
- platform: x86
|
||||||
LUA_VERSION: 5.2.4
|
LUA_VERSION: 5.2.4
|
||||||
|
@ -57,12 +58,16 @@ matrix:
|
||||||
LUA_VERSION: 5.1.5
|
LUA_VERSION: 5.1.5
|
||||||
- platform: x86
|
- platform: x86
|
||||||
MINGW_VERSION: 6.3.0
|
MINGW_VERSION: 6.3.0
|
||||||
- platform: x86
|
|
||||||
MINGW_VERSION: 5.3.0
|
|
||||||
- image: Visual Studio 2017
|
- image: Visual Studio 2017
|
||||||
MINGW_VERSION: 6.3.0
|
MINGW_VERSION: 6.3.0
|
||||||
- image: Visual Studio 2017
|
- image: Visual Studio 2017
|
||||||
MINGW_VERSION: 5.3.0
|
MINGW_VERSION: 5.3.0
|
||||||
|
- image: Visual Studio 2015
|
||||||
|
LUA_VERSION: 5.1.5
|
||||||
|
- image: Visual Studio 2015
|
||||||
|
LUA_VERSION: 5.2.4
|
||||||
|
- image: Visual Studio 2015
|
||||||
|
platform: x86
|
||||||
|
|
||||||
init:
|
init:
|
||||||
# make sure we have Ninja
|
# make sure we have Ninja
|
||||||
|
|
|
@ -246,13 +246,13 @@ if (LUA_VANILLA_GENERATE_LUA_HPP)
|
||||||
|
|
||||||
extern \"C\" {
|
extern \"C\" {
|
||||||
#include \"lua.h\"
|
#include \"lua.h\"
|
||||||
#include \"liblua.h\"
|
#include \"lualib.h\"
|
||||||
#include \"lauxlib.h\"
|
#include \"lauxlib.h\"
|
||||||
}
|
}
|
||||||
")
|
")
|
||||||
set(LUA_VANILLA_SOURCE_LUA_HPP "${LUA_BUILD_TOPLEVEL}-tmp/lua.hpp")
|
set(LUA_VANILLA_SOURCE_LUA_HPP "${LUA_BUILD_TOPLEVEL}-tmp/lua.hpp")
|
||||||
set(LUA_VANILLA_DESTINATION_LUA_HPP "${LUA_VANILLA_SOURCE_DIR}/lua.hpp")
|
set(LUA_VANILLA_DESTINATION_LUA_HPP "${LUA_VANILLA_SOURCE_DIR}/lua.hpp")
|
||||||
file(WRITE "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_HPP_CONTENT}")
|
file(WRITE "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_LUA_HPP_CONTENT}")
|
||||||
file(TO_NATIVE_PATH "${LUA_VANILLA_SOURCE_LUA_HPP}" LUA_VANILLA_SOURCE_LUA_HPP)
|
file(TO_NATIVE_PATH "${LUA_VANILLA_SOURCE_LUA_HPP}" LUA_VANILLA_SOURCE_LUA_HPP)
|
||||||
file(TO_NATIVE_PATH "${LUA_VANILLA_DESTINATION_LUA_HPP}" LUA_VANILLA_DESTINATION_LUA_HPP)
|
file(TO_NATIVE_PATH "${LUA_VANILLA_DESTINATION_LUA_HPP}" LUA_VANILLA_DESTINATION_LUA_HPP)
|
||||||
ExternalProject_Add_Step(LUA_VANILLA
|
ExternalProject_Add_Step(LUA_VANILLA
|
||||||
|
@ -261,6 +261,7 @@ extern \"C\" {
|
||||||
DEPENDEES download
|
DEPENDEES download
|
||||||
DEPENDERS build
|
DEPENDERS build
|
||||||
BYPRODUCTS "${LUA_VANILLA_TARGET_LUA_HPP}"
|
BYPRODUCTS "${LUA_VANILLA_TARGET_LUA_HPP}"
|
||||||
|
COMMENT "Moving \"${LUA_VANILLA_SOURCE_LUA_HPP}\" to \"${LUA_VANILLA_DeSTINATION_LUA_HPP}\"..."
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_DESTINATION_LUA_HPP}")
|
COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_DESTINATION_LUA_HPP}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,10 @@ endfunction(MAKE_EXAMPLE)
|
||||||
|
|
||||||
foreach(example_source_file ${EXAMPLES_SRC})
|
foreach(example_source_file ${EXAMPLES_SRC})
|
||||||
MAKE_EXAMPLE(${example_source_file} FALSE)
|
MAKE_EXAMPLE(${example_source_file} FALSE)
|
||||||
if (TESTS_SINGLE AND SOL2_SINGLE_FOUND)
|
|
||||||
MAKE_EXAMPLE(${example_source_file} TRUE)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
if (EXAMPLES_SINGLE AND SOL2_SINGLE_FOUND)
|
||||||
|
foreach(example_source_file ${EXAMPLES_SRC})
|
||||||
|
MAKE_EXAMPLE(${example_source_file} TRUE)
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// Uses some of the fancier bits of sol2, including the "transparent argument",
|
// Uses some of the fancier bits of sol2, including the "transparent argument",
|
||||||
// sol::this_state, which gets the current state and does not increment
|
// sol::this_state, which gets the current state and does not increment
|
||||||
|
@ -27,17 +27,17 @@ int main() {
|
||||||
|
|
||||||
int result = lua["f"](1, 2);
|
int result = lua["f"](1, 2);
|
||||||
// result == 3
|
// result == 3
|
||||||
assert(result == 3);
|
c_assert(result == 3);
|
||||||
double result2 = lua["f"](false, 2.5);
|
double result2 = lua["f"](false, 2.5);
|
||||||
// result2 == 2.5
|
// result2 == 2.5
|
||||||
assert(result2 == 2.5);
|
c_assert(result2 == 2.5);
|
||||||
|
|
||||||
// call in Lua, get result
|
// call in Lua, get result
|
||||||
// notice we only need 2 arguments here, not 3 (sol::this_state is transparent)
|
// notice we only need 2 arguments here, not 3 (sol::this_state is transparent)
|
||||||
lua.script("result3 = f(true, 5.5)");
|
lua.script("result3 = f(true, 5.5)");
|
||||||
double result3 = lua["result3"];
|
double result3 = lua["result3"];
|
||||||
// result3 == 16.5
|
// result3 == 16.5
|
||||||
assert(result3 == 16.5);
|
c_assert(result3 == 16.5);
|
||||||
|
|
||||||
std::cout << "=== any_return example ===" << std::endl;
|
std::cout << "=== any_return example ===" << std::endl;
|
||||||
std::cout << "result : " << result << std::endl;
|
std::cout << "result : " << result << std::endl;
|
||||||
|
|
30
examples/assert.hpp
Normal file
30
examples/assert.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef MY_ASSERT_HPP
|
||||||
|
#define MY_ASSERT_HPP
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
# define m_assert(condition, message) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << ": " << message << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
# define c_assert(condition) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
#else
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false)
|
||||||
|
# define c_assert(condition) do { (void)sizeof(condition); } while (false)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MY_ASSERT_HPP
|
|
@ -2,6 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "=== basic example ===" << std::endl;
|
std::cout << "=== basic example ===" << std::endl;
|
||||||
|
@ -37,7 +38,7 @@ int main() {
|
||||||
if (result.valid()) {
|
if (result.valid()) {
|
||||||
std::cout << "the third script worked, and a double-hello statement should appear above this one!" << std::endl;
|
std::cout << "the third script worked, and a double-hello statement should appear above this one!" << std::endl;
|
||||||
int value = result;
|
int value = result;
|
||||||
assert(value == 24);
|
c_assert(value == 24);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "the third script failed, check the result type for more information!" << std::endl;
|
std::cout << "the third script failed, check the result type for more information!" << std::endl;
|
||||||
|
@ -49,7 +50,7 @@ int main() {
|
||||||
if (result.valid()) {
|
if (result.valid()) {
|
||||||
std::cout << "the fourth script worked, which it wasn't supposed to! Panic!" << std::endl;
|
std::cout << "the fourth script worked, which it wasn't supposed to! Panic!" << std::endl;
|
||||||
int value = result;
|
int value = result;
|
||||||
assert(value == 24);
|
c_assert(value == 24);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sol::error err = result;
|
sol::error err = result;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
|
#include "assert.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -31,9 +32,9 @@ height = 1080
|
||||||
screen.name = lua.get<std::string>("name");
|
screen.name = lua.get<std::string>("name");
|
||||||
screen.width = lua.get<int>("width");
|
screen.width = lua.get<int>("width");
|
||||||
screen.height = lua.get<int>("height");
|
screen.height = lua.get<int>("height");
|
||||||
assert(screen.name == "Asus");
|
c_assert(screen.name == "Asus");
|
||||||
assert(screen.width == 1920);
|
c_assert(screen.width == 1920);
|
||||||
assert(screen.height == 1080);
|
c_assert(screen.height == 1080);
|
||||||
|
|
||||||
std::cout << "=== config example ===" << std::endl;
|
std::cout << "=== config example ===" << std::endl;
|
||||||
screen.print();
|
screen.print();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class number_storage {
|
class number_storage {
|
||||||
|
@ -64,8 +64,8 @@ print("accumulate after :", ns:accumulate())
|
||||||
|
|
||||||
number_storage& ns = lua["ns"];
|
number_storage& ns = lua["ns"];
|
||||||
number_storage& ns_container = lua["ns_container"];
|
number_storage& ns_container = lua["ns_container"];
|
||||||
assert(&ns == &ns_container);
|
c_assert(&ns == &ns_container);
|
||||||
assert(ns.size() == 3);
|
c_assert(ns.size() == 3);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
||||||
void demo(sol::nested<std::map<std::string, std::vector<std::string>>> src) {
|
void demo(sol::nested<std::map<std::string, std::vector<std::string>>> src) {
|
||||||
std::cout << "demo, sol::nested<...>" << std::endl;
|
std::cout << "demo, sol::nested<...>" << std::endl;
|
||||||
const auto& listmap = src.source;
|
const auto& listmap = src.source;
|
||||||
assert(listmap.size() == 2);
|
c_assert(listmap.size() == 2);
|
||||||
for (const auto& kvp : listmap) {
|
for (const auto& kvp : listmap) {
|
||||||
const std::vector<std::string>& strings = kvp.second;
|
const std::vector<std::string>& strings = kvp.second;
|
||||||
assert(strings.size() == 3);
|
c_assert(strings.size() == 3);
|
||||||
std::cout << "\t" << kvp.first << " = ";
|
std::cout << "\t" << kvp.first << " = ";
|
||||||
for (const auto& s : strings) {
|
for (const auto& s : strings) {
|
||||||
std::cout << "'" << s << "'" << " ";
|
std::cout << "'" << s << "'" << " ";
|
||||||
|
@ -39,11 +39,11 @@ void demo_explicit (sol::as_table_t<std::map<std::string, sol::as_table_t<std::v
|
||||||
std::cout << "demo, explicit sol::as_table_t<...>" << std::endl;
|
std::cout << "demo, explicit sol::as_table_t<...>" << std::endl;
|
||||||
// Have to access the "source" member variable for as_table_t
|
// Have to access the "source" member variable for as_table_t
|
||||||
const auto& listmap = src.source;
|
const auto& listmap = src.source;
|
||||||
assert(listmap.size() == 2);
|
c_assert(listmap.size() == 2);
|
||||||
for (const auto& kvp : listmap) {
|
for (const auto& kvp : listmap) {
|
||||||
// Have to access the internal "source" for the inner as_table_t, as well
|
// Have to access the internal "source" for the inner as_table_t, as well
|
||||||
const std::vector<std::string>& strings = kvp.second.source;
|
const std::vector<std::string>& strings = kvp.second.source;
|
||||||
assert(strings.size() == 3);
|
c_assert(strings.size() == 3);
|
||||||
std::cout << "\t" << kvp.first << " = ";
|
std::cout << "\t" << kvp.first << " = ";
|
||||||
for (const auto& s : strings) {
|
for (const auto& s : strings) {
|
||||||
std::cout << "'" << s << "'" << " ";
|
std::cout << "'" << s << "'" << " ";
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS
|
#define SOL_CHECK_ARGUMENTS
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
|
@ -41,7 +42,7 @@ int main(int, char*[]) {
|
||||||
transferred_into();
|
transferred_into();
|
||||||
// check
|
// check
|
||||||
int i = lua["i"];
|
int i = lua["i"];
|
||||||
assert(i == 1);
|
c_assert(i == 1);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
struct two_things {
|
struct two_things {
|
||||||
int a;
|
int a;
|
||||||
|
@ -85,8 +85,8 @@ int main() {
|
||||||
sol::function f = lua["f"];
|
sol::function f = lua["f"];
|
||||||
|
|
||||||
two_things things = f(two_things{ 24, false });
|
two_things things = f(two_things{ 24, false });
|
||||||
assert(things.a == 24);
|
c_assert(things.a == 24);
|
||||||
assert(things.b == false);
|
c_assert(things.b == false);
|
||||||
// things.a == 24
|
// things.a == 24
|
||||||
// things.b == true
|
// things.b == true
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
struct number_shim {
|
struct number_shim {
|
||||||
double num = 0;
|
double num = 0;
|
||||||
|
@ -61,8 +61,8 @@ int main() {
|
||||||
number_shim thingsf = lua["vf"];
|
number_shim thingsf = lua["vf"];
|
||||||
number_shim thingsg = lua["vg"];
|
number_shim thingsg = lua["vg"];
|
||||||
|
|
||||||
assert(thingsf.num == 25);
|
c_assert(thingsf.num == 25);
|
||||||
assert(thingsg.num == 35);
|
c_assert(thingsg.num == 35);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// use as-is,
|
// use as-is,
|
||||||
// add as a member of your class,
|
// add as a member of your class,
|
||||||
|
@ -75,7 +75,7 @@ assert(value == 15)
|
||||||
|
|
||||||
// does not work on d1: 'run' wasn't added to d1, only d2
|
// does not work on d1: 'run' wasn't added to d1, only d2
|
||||||
auto script_result = lua.safe_script("local value = d1:run(5)", sol::script_pass_on_error);
|
auto script_result = lua.safe_script("local value = d1:run(5)", sol::script_pass_on_error);
|
||||||
assert(!script_result.valid());
|
c_assert(!script_result.valid());
|
||||||
sol::error err = script_result;
|
sol::error err = script_result;
|
||||||
std::cout << "received expected error: " << err.what() << std::endl;
|
std::cout << "received expected error: " << err.what() << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Simple sol2 version of the below
|
// Simple sol2 version of the below
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
|
@ -20,7 +20,7 @@ int main(int, char**) {
|
||||||
|
|
||||||
// the function returns the value from the environment table
|
// the function returns the value from the environment table
|
||||||
int result = f();
|
int result = f();
|
||||||
assert(result == 31);
|
c_assert(result == 31);
|
||||||
|
|
||||||
|
|
||||||
// You can also protect from variables
|
// You can also protect from variables
|
||||||
|
@ -33,13 +33,13 @@ int main(int, char**) {
|
||||||
g();
|
g();
|
||||||
// the value can be retrieved from the env table
|
// the value can be retrieved from the env table
|
||||||
int test = env_g["test"];
|
int test = env_g["test"];
|
||||||
assert(test == 5);
|
c_assert(test == 5);
|
||||||
|
|
||||||
|
|
||||||
// the global environment
|
// the global environment
|
||||||
// is not polluted at all, despite both functions being used and set
|
// is not polluted at all, despite both functions being used and set
|
||||||
sol::object global_test = lua["test"];
|
sol::object global_test = lua["test"];
|
||||||
assert(!global_test.valid());
|
c_assert(!global_test.valid());
|
||||||
|
|
||||||
|
|
||||||
// You can retrieve environments in C++
|
// You can retrieve environments in C++
|
||||||
|
@ -58,9 +58,9 @@ int main(int, char**) {
|
||||||
int test_target_env = target_env["test"];
|
int test_target_env = target_env["test"];
|
||||||
// the environment for f the one gotten from `target`
|
// the environment for f the one gotten from `target`
|
||||||
// are the same
|
// are the same
|
||||||
assert(test_env_f == test_target_env);
|
c_assert(test_env_f == test_target_env);
|
||||||
assert(test_env_f == 31);
|
c_assert(test_env_f == 31);
|
||||||
assert(env_f == target_env);
|
c_assert(env_f == target_env);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
lua.set_function("check_g_env",
|
lua.set_function("check_g_env",
|
||||||
|
@ -69,9 +69,9 @@ int main(int, char**) {
|
||||||
sol::environment target_env = sol::get_environment(target);
|
sol::environment target_env = sol::get_environment(target);
|
||||||
int test_env_g = env_g["test"];
|
int test_env_g = env_g["test"];
|
||||||
int test_target_env = target_env["test"];
|
int test_target_env = target_env["test"];
|
||||||
assert(test_env_g == test_target_env);
|
c_assert(test_env_g == test_target_env);
|
||||||
assert(test_env_g == 5);
|
c_assert(test_env_g == 5);
|
||||||
assert(env_g == target_env);
|
c_assert(env_g == target_env);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
inline int my_add(int x, int y) {
|
inline int my_add(int x, int y) {
|
||||||
|
@ -35,10 +35,10 @@ int main() {
|
||||||
lua.set_function("mult_by_five", &multiplier::by_five);
|
lua.set_function("mult_by_five", &multiplier::by_five);
|
||||||
|
|
||||||
// assert that the functions work
|
// assert that the functions work
|
||||||
lua.script("assert(my_add(10, 11) == 21)");
|
lua.script("c_assert(my_add(10, 11) == 21)");
|
||||||
lua.script("assert(my_mul(4.5, 10) == 45)");
|
lua.script("c_assert(my_mul(4.5, 10) == 45)");
|
||||||
lua.script("assert(mult_by_ten(50) == 500)");
|
lua.script("c_assert(mult_by_ten(50) == 500)");
|
||||||
lua.script("assert(mult_by_five(10) == 50)");
|
lua.script("c_assert(mult_by_five(10) == 50)");
|
||||||
|
|
||||||
// using lambdas, functions can have state.
|
// using lambdas, functions can have state.
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
@ -46,7 +46,7 @@ int main() {
|
||||||
|
|
||||||
// calling a stateful lambda modifies the value
|
// calling a stateful lambda modifies the value
|
||||||
lua.script("inc()");
|
lua.script("inc()");
|
||||||
assert(x == 10);
|
c_assert(x == 10);
|
||||||
if (x == 10) {
|
if (x == 10) {
|
||||||
// Do something based on this information
|
// Do something based on this information
|
||||||
std::cout << "Yahoo! x is " << x << std::endl;
|
std::cout << "Yahoo! x is " << x << std::endl;
|
||||||
|
@ -58,7 +58,7 @@ inc()
|
||||||
inc()
|
inc()
|
||||||
inc()
|
inc()
|
||||||
)");
|
)");
|
||||||
assert(x == 40);
|
c_assert(x == 40);
|
||||||
if (x == 40) {
|
if (x == 40) {
|
||||||
// Do something based on this information
|
// Do something based on this information
|
||||||
std::cout << "Yahoo! x is " << x << std::endl;
|
std::cout << "Yahoo! x is " << x << std::endl;
|
||||||
|
@ -70,8 +70,8 @@ inc()
|
||||||
int value = add(10, 11);
|
int value = add(10, 11);
|
||||||
// second way to call the function
|
// second way to call the function
|
||||||
int value2 = add.call<int>(10, 11);
|
int value2 = add.call<int>(10, 11);
|
||||||
assert(value == 21);
|
c_assert(value == 21);
|
||||||
assert(value2 == 21);
|
c_assert(value2 == 21);
|
||||||
if (value == 21 && value2 == 21) {
|
if (value == 21 && value2 == 21) {
|
||||||
std::cout << "Woo, value is 21!" << std::endl;
|
std::cout << "Woo, value is 21!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
sol::variadic_results call_it(sol::object function_name, sol::variadic_args args, sol::this_environment env, sol::this_state L) {
|
sol::variadic_results call_it(sol::object function_name, sol::variadic_args args, sol::this_environment env, sol::this_state L) {
|
||||||
|
@ -66,8 +67,8 @@ end
|
||||||
int subtract_result = lua["subtract_result"];
|
int subtract_result = lua["subtract_result"];
|
||||||
int add_result = lua["add_result"];
|
int add_result = lua["add_result"];
|
||||||
|
|
||||||
assert(add_result == 6);
|
c_assert(add_result == 6);
|
||||||
assert(subtract_result == 4);
|
c_assert(subtract_result == 4);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <LuaBridge/LuaBridge.h>
|
#include <LuaBridge/LuaBridge.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// LuaBridge,
|
// LuaBridge,
|
||||||
// no longer maintained by VinnieFalco:
|
// no longer maintained by VinnieFalco:
|
||||||
|
@ -79,7 +79,7 @@ void check_with_sol(lua_State* L) {
|
||||||
sol::state_view lua(L);
|
sol::state_view lua(L);
|
||||||
A& obj = lua["obj"];
|
A& obj = lua["obj"];
|
||||||
(void)obj;
|
(void)obj;
|
||||||
assert(obj.value() == 24);
|
c_assert(obj.value() == 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
|
|
30
examples/interop/assert.hpp
Normal file
30
examples/interop/assert.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef MY_ASSERT_HPP
|
||||||
|
#define MY_ASSERT_HPP
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
# define m_assert(condition, message) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << ": " << message << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
# define c_assert(condition) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
#else
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false)
|
||||||
|
# define c_assert(condition) do { (void)sizeof(condition); } while (false)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MY_ASSERT_HPP
|
|
@ -5,7 +5,7 @@
|
||||||
#include <kaguya/kaguya.hpp>
|
#include <kaguya/kaguya.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// kaguya code lifted from README.md,
|
// kaguya code lifted from README.md,
|
||||||
// written by satoren:
|
// written by satoren:
|
||||||
|
@ -98,7 +98,7 @@ void check_with_sol(lua_State* L) {
|
||||||
sol::state_view lua(L);
|
sol::state_view lua(L);
|
||||||
ABC& obj = lua["obj"];
|
ABC& obj = lua["obj"];
|
||||||
(void)obj;
|
(void)obj;
|
||||||
assert(obj.value() == 24);
|
c_assert(obj.value() == 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <luwra.hpp>
|
#include <luwra.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// luwra,
|
// luwra,
|
||||||
// another C++ wrapper library:
|
// another C++ wrapper library:
|
||||||
|
@ -91,7 +91,7 @@ void check_with_sol(lua_State* L) {
|
||||||
sol::state_view lua(L);
|
sol::state_view lua(L);
|
||||||
ABC& obj = lua["obj"];
|
ABC& obj = lua["obj"];
|
||||||
(void)obj;
|
(void)obj;
|
||||||
assert(obj.value() == 24);
|
c_assert(obj.value() == 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "tolua_Player.h"
|
#include "tolua_Player.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// tolua code lifted from some blog, if the link dies
|
// tolua code lifted from some blog, if the link dies
|
||||||
// I don't know where else you're gonna find the reference,
|
// I don't know where else you're gonna find the reference,
|
||||||
|
@ -52,7 +52,7 @@ void check_with_sol(lua_State* L) {
|
||||||
sol::state_view lua(L);
|
sol::state_view lua(L);
|
||||||
Player& obj = lua["obj"];
|
Player& obj = lua["obj"];
|
||||||
(void)obj;
|
(void)obj;
|
||||||
assert(obj.getHealth() == 4);
|
c_assert(obj.getHealth() == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -21,7 +21,7 @@ int main() {
|
||||||
lua.script("print('calling multi_tuple')");
|
lua.script("print('calling multi_tuple')");
|
||||||
lua.script("print(multi_tuple())");
|
lua.script("print(multi_tuple())");
|
||||||
lua.script("x, y = multi_tuple()");
|
lua.script("x, y = multi_tuple()");
|
||||||
lua.script("assert(x == 10 and y == 'goodbye')");
|
lua.script("c_assert(x == 10 and y == 'goodbye')");
|
||||||
|
|
||||||
auto multi = lua.get<sol::function>("multi_tuple");
|
auto multi = lua.get<sol::function>("multi_tuple");
|
||||||
int first;
|
int first;
|
||||||
|
@ -30,8 +30,8 @@ int main() {
|
||||||
sol::tie(first, second) = multi();
|
sol::tie(first, second) = multi();
|
||||||
|
|
||||||
// use the values
|
// use the values
|
||||||
assert(first == 10);
|
c_assert(first == 10);
|
||||||
assert(second == "goodbye");
|
c_assert(second == "goodbye");
|
||||||
|
|
||||||
// sol::as_returns
|
// sol::as_returns
|
||||||
// works with any iterable,
|
// works with any iterable,
|
||||||
|
@ -50,9 +50,9 @@ int main() {
|
||||||
int b = lua["b"];
|
int b = lua["b"];
|
||||||
int c = lua["c"];
|
int c = lua["c"];
|
||||||
|
|
||||||
assert(a == 55);
|
c_assert(a == 55);
|
||||||
assert(b == 66);
|
c_assert(b == 66);
|
||||||
assert(c == 77);
|
c_assert(c == 77);
|
||||||
|
|
||||||
// sol::variadic_results
|
// sol::variadic_results
|
||||||
// you can push objects of different types
|
// you can push objects of different types
|
||||||
|
@ -73,9 +73,9 @@ int main() {
|
||||||
bool u = lua["u"];
|
bool u = lua["u"];
|
||||||
std::string v = lua["v"];
|
std::string v = lua["v"];
|
||||||
|
|
||||||
assert(t == 42);
|
c_assert(t == 42);
|
||||||
assert(u);
|
c_assert(u);
|
||||||
assert(v == "awoo");
|
c_assert(v == "awoo");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
inline int my_add(int x, int y) {
|
inline int my_add(int x, int y) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
struct some_class {
|
struct some_class {
|
||||||
|
@ -38,7 +38,7 @@ s = my_lib.some_class.new()
|
||||||
s.bark = 20;
|
s.bark = 20;
|
||||||
)");
|
)");
|
||||||
some_class& s = lua["s"];
|
some_class& s = lua["s"];
|
||||||
assert(s.bark == 20);
|
c_assert(s.bark == 20);
|
||||||
std::cout << "s.bark = " << s.bark << std::endl;
|
std::cout << "s.bark = " << s.bark << std::endl;
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
30
examples/require_dll_example/assert.hpp
Normal file
30
examples/require_dll_example/assert.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef MY_ASSERT_HPP
|
||||||
|
#define MY_ASSERT_HPP
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
# define m_assert(condition, message) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << ": " << message << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
# define c_assert(condition) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
#else
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false)
|
||||||
|
# define c_assert(condition) do { (void)sizeof(condition); } while (false)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MY_ASSERT_HPP
|
|
@ -2,9 +2,9 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include "my_object.hpp"
|
#include "my_object.hpp"
|
||||||
|
#include "assert.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
std::cout << "=== require from DLL example ===" << std::endl;
|
std::cout << "=== require from DLL example ===" << std::endl;
|
||||||
|
@ -20,7 +20,7 @@ print(obj.value)
|
||||||
)");
|
)");
|
||||||
|
|
||||||
my_object::test& obj = lua["obj"];
|
my_object::test& obj = lua["obj"];
|
||||||
assert(obj.value == 24);
|
c_assert(obj.value == 24);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
struct object {
|
struct object {
|
||||||
|
@ -35,7 +35,7 @@ obj:print()
|
||||||
)");
|
)");
|
||||||
|
|
||||||
object& obj = lua["obj"];
|
object& obj = lua["obj"];
|
||||||
assert(obj.value == 1);
|
c_assert(obj.value == 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
|
@ -26,7 +27,7 @@ return 24
|
||||||
int value = lua.script(code, sol::script_default_on_error);
|
int value = lua.script(code, sol::script_default_on_error);
|
||||||
// This will never be reached
|
// This will never be reached
|
||||||
std::cout << value << std::endl;
|
std::cout << value << std::endl;
|
||||||
assert(value == 24);
|
c_assert(value == 24);
|
||||||
}
|
}
|
||||||
catch (const sol::error& err) {
|
catch (const sol::error& err) {
|
||||||
std::cout << "Something went horribly wrong: thrown error" << "\n\t" << err.what() << std::endl;
|
std::cout << "Something went horribly wrong: thrown error" << "\n\t" << err.what() << std::endl;
|
||||||
|
@ -40,7 +41,7 @@ return 24
|
||||||
// This will check code validity and also whether or not it runs well
|
// This will check code validity and also whether or not it runs well
|
||||||
{
|
{
|
||||||
sol::protected_function_result result = lua.script(code, sol::script_pass_on_error);
|
sol::protected_function_result result = lua.script(code, sol::script_pass_on_error);
|
||||||
assert(!result.valid());
|
c_assert(!result.valid());
|
||||||
if (!result.valid()) {
|
if (!result.valid()) {
|
||||||
sol::error err = result;
|
sol::error err = result;
|
||||||
sol::call_status status = result.status();
|
sol::call_status status = result.status();
|
||||||
|
@ -58,7 +59,7 @@ return 24
|
||||||
// The two previous approaches are recommended
|
// The two previous approaches are recommended
|
||||||
{
|
{
|
||||||
sol::load_result loaded_chunk = lua.load(code);
|
sol::load_result loaded_chunk = lua.load(code);
|
||||||
assert(!loaded_chunk.valid());
|
c_assert(!loaded_chunk.valid());
|
||||||
if (!loaded_chunk.valid()) {
|
if (!loaded_chunk.valid()) {
|
||||||
sol::error err = loaded_chunk;
|
sol::error err = loaded_chunk;
|
||||||
sol::load_status status = loaded_chunk.status();
|
sol::load_status status = loaded_chunk.status();
|
||||||
|
@ -66,7 +67,7 @@ return 24
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Because the syntax is bad, this will never be reached
|
// Because the syntax is bad, this will never be reached
|
||||||
assert(false);
|
c_assert(false);
|
||||||
// If there is a runtime error (lua GC memory error, nil access, etc.)
|
// If there is a runtime error (lua GC memory error, nil access, etc.)
|
||||||
// it will be caught here
|
// it will be caught here
|
||||||
sol::protected_function script_func = loaded_chunk;
|
sol::protected_function script_func = loaded_chunk;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
// NOTE:
|
// NOTE:
|
||||||
// There are TWO ways to retrieve the "this"
|
// There are TWO ways to retrieve the "this"
|
||||||
|
@ -22,7 +22,7 @@ int main() {
|
||||||
|
|
||||||
// definitely the same
|
// definitely the same
|
||||||
thing& self = selfobj.as<thing>();
|
thing& self = selfobj.as<thing>();
|
||||||
assert(&self == this);
|
c_assert(&self == this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void func(sol::this_state ts) const {
|
void func(sol::this_state ts) const {
|
||||||
|
@ -35,7 +35,7 @@ int main() {
|
||||||
thing& self = selfobj.as<thing>();
|
thing& self = selfobj.as<thing>();
|
||||||
|
|
||||||
// definitely the same
|
// definitely the same
|
||||||
assert(&self == this);
|
c_assert(&self == this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -27,8 +27,8 @@ int main(int, char*[]) {
|
||||||
int result = func(sol::stack_count(2));
|
int result = func(sol::stack_count(2));
|
||||||
|
|
||||||
// make sure everything is clean
|
// make sure everything is clean
|
||||||
assert(result == 22);
|
c_assert(result == 22);
|
||||||
assert(lua.stack_top() == 0); // stack is empty/balanced
|
c_assert(lua.stack_top() == 0); // stack is empty/balanced
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
struct test {
|
struct test {
|
||||||
static int muh_variable;
|
static int muh_variable;
|
||||||
|
@ -23,15 +23,15 @@ int main() {
|
||||||
|
|
||||||
int direct_value = lua["test"]["direct"];
|
int direct_value = lua["test"]["direct"];
|
||||||
// direct_value == 2
|
// direct_value == 2
|
||||||
assert(direct_value == 2);
|
c_assert(direct_value == 2);
|
||||||
std::cout << "direct_value: " << direct_value << std::endl;
|
std::cout << "direct_value: " << direct_value << std::endl;
|
||||||
|
|
||||||
int global = lua["test"]["global"];
|
int global = lua["test"]["global"];
|
||||||
int global2 = lua["test"]["ref_global"];
|
int global2 = lua["test"]["ref_global"];
|
||||||
// global == 25
|
// global == 25
|
||||||
// global2 == 25
|
// global2 == 25
|
||||||
assert(global == 25);
|
c_assert(global == 25);
|
||||||
assert(global2 == 25);
|
c_assert(global2 == 25);
|
||||||
|
|
||||||
std::cout << "First round of values --" << std::endl;
|
std::cout << "First round of values --" << std::endl;
|
||||||
std::cout << global << std::endl;
|
std::cout << global << std::endl;
|
||||||
|
@ -50,8 +50,8 @@ int main() {
|
||||||
// if muh_variable goes out of scope or is deleted
|
// if muh_variable goes out of scope or is deleted
|
||||||
// problems could arise, so be careful!
|
// problems could arise, so be careful!
|
||||||
|
|
||||||
assert(global == 25);
|
c_assert(global == 25);
|
||||||
assert(global2 == 542);
|
c_assert(global2 == 542);
|
||||||
|
|
||||||
std::cout << "Second round of values --" << std::endl;
|
std::cout << "Second round of values --" << std::endl;
|
||||||
std::cout << "global : " << global << std::endl;
|
std::cout << "global : " << global << std::endl;
|
||||||
|
|
30
examples/tutorials/quick_n_dirty/assert.hpp
Normal file
30
examples/tutorials/quick_n_dirty/assert.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef MY_ASSERT_HPP
|
||||||
|
#define MY_ASSERT_HPP
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
# define m_assert(condition, message) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << ": " << message << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
# define c_assert(condition) \
|
||||||
|
do { \
|
||||||
|
if (! (condition)) { \
|
||||||
|
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
|
||||||
|
<< " line " << __LINE__ << std::endl; \
|
||||||
|
std::terminate(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
#else
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false)
|
||||||
|
# define c_assert(condition) do { (void)sizeof(condition); } while (false)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MY_ASSERT_HPP
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void some_function() {
|
void some_function() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -18,15 +18,15 @@ int main(int, char*[]) {
|
||||||
std::function<int(int, double, int, std::string)> stdfx = fx;
|
std::function<int(int, double, int, std::string)> stdfx = fx;
|
||||||
|
|
||||||
int is_one = stdfx(1, 34.5, 3, "bark");
|
int is_one = stdfx(1, 34.5, 3, "bark");
|
||||||
assert(is_one == 1);
|
c_assert(is_one == 1);
|
||||||
int is_also_one = fx(1, "boop", 3, "bark");
|
int is_also_one = fx(1, "boop", 3, "bark");
|
||||||
assert(is_also_one == 1);
|
c_assert(is_also_one == 1);
|
||||||
|
|
||||||
// call through operator[]
|
// call through operator[]
|
||||||
int is_three = lua["g"](1, 2);
|
int is_three = lua["g"](1, 2);
|
||||||
assert(is_three == 3);
|
c_assert(is_three == 3);
|
||||||
double is_4_8 = lua["g"](2.4, 2.4);
|
double is_4_8 = lua["g"](2.4, 2.4);
|
||||||
assert(is_4_8 == 4.8);
|
c_assert(is_4_8 == 4.8);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -15,9 +15,9 @@ int main(int, char* []) {
|
||||||
int b;
|
int b;
|
||||||
std::string c;
|
std::string c;
|
||||||
sol::tie(a, b, c) = lua["f"](100, 200, "bark");
|
sol::tie(a, b, c) = lua["f"](100, 200, "bark");
|
||||||
assert(a == 100);
|
c_assert(a == 100);
|
||||||
assert(b == 200);
|
c_assert(b == 200);
|
||||||
assert(c == "bark");
|
c_assert(c == "bark");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char* []) {
|
int main(int, char* []) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -14,19 +14,19 @@ int main(int, char* []) {
|
||||||
|
|
||||||
std::tuple<int, int, int> result = lua["f"](100, 200, 300);
|
std::tuple<int, int, int> result = lua["f"](100, 200, 300);
|
||||||
const std::tuple<int, int, int> expected(100, 200, 300);
|
const std::tuple<int, int, int> expected(100, 200, 300);
|
||||||
assert(result == expected);
|
c_assert(result == expected);
|
||||||
|
|
||||||
std::tuple<int, int, std::string> result2;
|
std::tuple<int, int, std::string> result2;
|
||||||
result2 = lua["f"](100, 200, "BARK BARK BARK!");
|
result2 = lua["f"](100, 200, "BARK BARK BARK!");
|
||||||
const std::tuple<int, int, std::string> expected2(100, 200, "BARK BARK BARK!");
|
const std::tuple<int, int, std::string> expected2(100, 200, "BARK BARK BARK!");
|
||||||
assert(result2 == expected2);
|
c_assert(result2 == expected2);
|
||||||
|
|
||||||
int a, b;
|
int a, b;
|
||||||
std::string c;
|
std::string c;
|
||||||
sol::tie(a, b, c) = lua["f"](100, 200, "bark");
|
sol::tie(a, b, c) = lua["f"](100, 200, "bark");
|
||||||
assert(a == 100);
|
c_assert(a == 100);
|
||||||
assert(b == 200);
|
c_assert(b == 200);
|
||||||
assert(c == "bark");
|
c_assert(c == "bark");
|
||||||
|
|
||||||
lua.script(R"(
|
lua.script(R"(
|
||||||
a, b, c = f(150, 250, "woofbark")
|
a, b, c = f(150, 250, "woofbark")
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "=== namespacing example ===" << std::endl;
|
std::cout << "=== namespacing example ===" << std::endl;
|
||||||
|
@ -39,7 +39,7 @@ int main() {
|
||||||
// calling this function also works
|
// calling this function also works
|
||||||
lua.script("bark.print_my_class(obj)");
|
lua.script("bark.print_my_class(obj)");
|
||||||
my_class& obj = lua["obj"];
|
my_class& obj = lua["obj"];
|
||||||
assert(obj.b == 25);
|
c_assert(obj.b == 25);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
std::cout << "=== opening a state example ===" << std::endl;
|
std::cout << "=== opening a state example ===" << std::endl;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
std::cout << "=== running lua code example ===" << std::endl;
|
std::cout << "=== running lua code example ===" << std::endl;
|
||||||
|
@ -23,7 +23,7 @@ int main(int, char*[]) {
|
||||||
|
|
||||||
// run a script, get the result
|
// run a script, get the result
|
||||||
int value = lua.script("return 54");
|
int value = lua.script("return 54");
|
||||||
assert(value == 54);
|
c_assert(value == 54);
|
||||||
|
|
||||||
auto bad_code_result = lua.script("123 herp.derp", [](lua_State*, sol::protected_function_result pfr) {
|
auto bad_code_result = lua.script("123 herp.derp", [](lua_State*, sol::protected_function_result pfr) {
|
||||||
// pfr will contain things that went wrong, for either loading or executing the script
|
// pfr will contain things that went wrong, for either loading or executing the script
|
||||||
|
@ -32,7 +32,7 @@ int main(int, char*[]) {
|
||||||
return pfr;
|
return pfr;
|
||||||
});
|
});
|
||||||
// it did not work
|
// it did not work
|
||||||
assert(!bad_code_result.valid());
|
c_assert(!bad_code_result.valid());
|
||||||
|
|
||||||
// the default handler panics or throws, depending on your settings
|
// the default handler panics or throws, depending on your settings
|
||||||
// uncomment for explosions:
|
// uncomment for explosions:
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
std::cout << "=== running lua code (low level) example ===" << std::endl;
|
std::cout << "=== running lua code (low level) example ===" << std::endl;
|
||||||
|
@ -37,7 +37,7 @@ int main(int, char*[]) {
|
||||||
sol::load_result script3 = lua.load("return 24");
|
sol::load_result script3 = lua.load("return 24");
|
||||||
// execute, get return value
|
// execute, get return value
|
||||||
int value2 = script3();
|
int value2 = script3();
|
||||||
assert(value2 == 24);
|
c_assert(value2 == 24);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -44,40 +44,40 @@ int main(int, char*[]) {
|
||||||
|
|
||||||
// implicit conversion
|
// implicit conversion
|
||||||
int number = lua["number"];
|
int number = lua["number"];
|
||||||
assert(number == 24);
|
c_assert(number == 24);
|
||||||
// explicit get
|
// explicit get
|
||||||
auto number2 = lua.get<double>("number2");
|
auto number2 = lua.get<double>("number2");
|
||||||
assert(number2 == 24.5);
|
c_assert(number2 == 24.5);
|
||||||
// strings too
|
// strings too
|
||||||
std::string important_string = lua["important_string"];
|
std::string important_string = lua["important_string"];
|
||||||
assert(important_string == "woof woof");
|
c_assert(important_string == "woof woof");
|
||||||
// dig into a table
|
// dig into a table
|
||||||
int value = lua["some_table"]["value"];
|
int value = lua["some_table"]["value"];
|
||||||
assert(value == 24);
|
c_assert(value == 24);
|
||||||
// get a function
|
// get a function
|
||||||
sol::function a_function = lua["a_function"];
|
sol::function a_function = lua["a_function"];
|
||||||
int value_is_100 = a_function();
|
int value_is_100 = a_function();
|
||||||
// convertible to std::function
|
// convertible to std::function
|
||||||
std::function<int()> a_std_function = a_function;
|
std::function<int()> a_std_function = a_function;
|
||||||
int value_is_still_100 = a_std_function();
|
int value_is_still_100 = a_std_function();
|
||||||
assert(value_is_100 == 100);
|
c_assert(value_is_100 == 100);
|
||||||
assert(value_is_still_100 == 100);
|
c_assert(value_is_still_100 == 100);
|
||||||
|
|
||||||
sol::object number_obj = lua.get<sol::object>("number");
|
sol::object number_obj = lua.get<sol::object>("number");
|
||||||
// sol::type::number
|
// sol::type::number
|
||||||
sol::type t1 = number_obj.get_type();
|
sol::type t1 = number_obj.get_type();
|
||||||
assert(t1 == sol::type::number);
|
c_assert(t1 == sol::type::number);
|
||||||
|
|
||||||
sol::object function_obj = lua["a_function"];
|
sol::object function_obj = lua["a_function"];
|
||||||
// sol::type::function
|
// sol::type::function
|
||||||
sol::type t2 = function_obj.get_type();
|
sol::type t2 = function_obj.get_type();
|
||||||
assert(t2 == sol::type::function);
|
c_assert(t2 == sol::type::function);
|
||||||
bool is_it_really = function_obj.is<std::function<int()>>();
|
bool is_it_really = function_obj.is<std::function<int()>>();
|
||||||
assert(is_it_really);
|
c_assert(is_it_really);
|
||||||
|
|
||||||
// will not contain data
|
// will not contain data
|
||||||
sol::optional<int> check_for_me = lua["a_function"];
|
sol::optional<int> check_for_me = lua["a_function"];
|
||||||
assert(check_for_me == sol::nullopt);
|
c_assert(check_for_me == sol::nullopt);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -10,11 +10,11 @@ int main(int, char*[]) {
|
||||||
lua.script("exists = 250");
|
lua.script("exists = 250");
|
||||||
|
|
||||||
int first_try = lua.get_or("exists", 322);
|
int first_try = lua.get_or("exists", 322);
|
||||||
assert(first_try == 250);
|
c_assert(first_try == 250);
|
||||||
|
|
||||||
lua.set("exists", sol::lua_nil);
|
lua.set("exists", sol::lua_nil);
|
||||||
int second_try = lua.get_or("exists", 322);
|
int second_try = lua.get_or("exists", 322);
|
||||||
assert(second_try == 322);
|
c_assert(second_try == 322);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
int main(int, char*[]) {
|
int main(int, char*[]) {
|
||||||
|
|
||||||
|
@ -24,19 +24,19 @@ int main(int, char*[]) {
|
||||||
|
|
||||||
int bark1 = def["ghi"]["bark"];
|
int bark1 = def["ghi"]["bark"];
|
||||||
int bark2 = lua["def"]["ghi"]["bark"];
|
int bark2 = lua["def"]["ghi"]["bark"];
|
||||||
assert(bark1 == 50);
|
c_assert(bark1 == 50);
|
||||||
assert(bark2 == 50);
|
c_assert(bark2 == 50);
|
||||||
|
|
||||||
int abcval1 = abc[0];
|
int abcval1 = abc[0];
|
||||||
int abcval2 = ghi["woof"][0];
|
int abcval2 = ghi["woof"][0];
|
||||||
assert(abcval1 == 24);
|
c_assert(abcval1 == 24);
|
||||||
assert(abcval2 == 24);
|
c_assert(abcval2 == 24);
|
||||||
|
|
||||||
sol::optional<int> will_not_error = lua["abc"]["DOESNOTEXIST"]["ghi"];
|
sol::optional<int> will_not_error = lua["abc"]["DOESNOTEXIST"]["ghi"];
|
||||||
assert(will_not_error == sol::nullopt);
|
c_assert(will_not_error == sol::nullopt);
|
||||||
|
|
||||||
int also_will_not_error = lua["abc"]["def"]["ghi"]["jklm"].get_or(25);
|
int also_will_not_error = lua["abc"]["def"]["ghi"]["jklm"].get_or(25);
|
||||||
assert(also_will_not_error == 25);
|
c_assert(also_will_not_error == 25);
|
||||||
|
|
||||||
// if you don't go safe,
|
// if you don't go safe,
|
||||||
// will throw (or do at_panic if no exceptions)
|
// will throw (or do at_panic if no exceptions)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
struct Doge {
|
struct Doge {
|
||||||
|
@ -49,11 +50,11 @@ int main(int, char* []) {
|
||||||
Doge& lua_dog_move = lua["dog_move"];
|
Doge& lua_dog_move = lua["dog_move"];
|
||||||
Doge& lua_dog_unique_ptr = lua["dog_unique_ptr"];
|
Doge& lua_dog_unique_ptr = lua["dog_unique_ptr"];
|
||||||
Doge& lua_dog_shared_ptr = lua["dog_shared_ptr"];
|
Doge& lua_dog_shared_ptr = lua["dog_shared_ptr"];
|
||||||
assert(lua_dog.tailwag == 50);
|
c_assert(lua_dog.tailwag == 50);
|
||||||
assert(lua_dog_copy.tailwag == 30);
|
c_assert(lua_dog_copy.tailwag == 30);
|
||||||
assert(lua_dog_move.tailwag == 30);
|
c_assert(lua_dog_move.tailwag == 30);
|
||||||
assert(lua_dog_unique_ptr.tailwag == 25);
|
c_assert(lua_dog_unique_ptr.tailwag == 25);
|
||||||
assert(lua_dog_shared_ptr.tailwag == 31);
|
c_assert(lua_dog_shared_ptr.tailwag == 31);
|
||||||
|
|
||||||
// lua will treat these types as opaque, and you will be able to pass them around
|
// lua will treat these types as opaque, and you will be able to pass them around
|
||||||
// to C++ functions and Lua functions alike
|
// to C++ functions and Lua functions alike
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
struct foo {
|
struct foo {
|
||||||
|
@ -96,7 +96,7 @@ int main() {
|
||||||
lua.script("v = vector.new()\n"
|
lua.script("v = vector.new()\n"
|
||||||
"v = vector.new(12)\n"
|
"v = vector.new(12)\n"
|
||||||
"v = vector.new(10, 10)\n"
|
"v = vector.new(10, 10)\n"
|
||||||
"assert(not v:is_unit())\n");
|
"c_assert(not v:is_unit())\n");
|
||||||
|
|
||||||
// You can even have C++-like member-variable-access
|
// You can even have C++-like member-variable-access
|
||||||
// just pass is public member variables in the same style as functions
|
// just pass is public member variables in the same style as functions
|
||||||
|
@ -108,7 +108,7 @@ int main() {
|
||||||
"assert(not vars.low_gravity)\n"
|
"assert(not vars.low_gravity)\n"
|
||||||
"vars.low_gravity = true\n"
|
"vars.low_gravity = true\n"
|
||||||
"local x = vars.low_gravity\n"
|
"local x = vars.low_gravity\n"
|
||||||
"assert(x)");
|
"c_assert(x)");
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace itsy_bitsy {
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
@ -154,9 +154,9 @@ int main() {
|
||||||
std::cout << "N: " << N << std::endl;
|
std::cout << "N: " << N << std::endl;
|
||||||
std::cout << "D: " << D << std::endl;
|
std::cout << "D: " << D << std::endl;
|
||||||
|
|
||||||
assert(C);
|
c_assert(C);
|
||||||
assert(N);
|
c_assert(N);
|
||||||
assert(D == 0xDF);
|
c_assert(D == 0xDF);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
// Note that this is a bunch of if/switch statements
|
// Note that this is a bunch of if/switch statements
|
||||||
|
@ -149,8 +149,8 @@ int main() {
|
||||||
sol::userdata v1 = lua["v1"];
|
sol::userdata v1 = lua["v1"];
|
||||||
double v1x = v1["x"];
|
double v1x = v1["x"];
|
||||||
double v1y = v1["y"];
|
double v1y = v1["y"];
|
||||||
assert(v1x == 1.000);
|
c_assert(v1x == 1.000);
|
||||||
assert(v1y == 0.000);
|
c_assert(v1y == 0.000);
|
||||||
v1[0] = 2.000;
|
v1[0] = 2.000;
|
||||||
|
|
||||||
lua.script(R"(
|
lua.script(R"(
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
struct holy {
|
struct holy {
|
||||||
private:
|
private:
|
||||||
|
@ -61,8 +61,8 @@ print('h2.data is ' .. h2.data)
|
||||||
)");
|
)");
|
||||||
holy& h1 = lua["h1"];
|
holy& h1 = lua["h1"];
|
||||||
holy& h2 = lua["h2"];
|
holy& h2 = lua["h2"];
|
||||||
assert(h1.data == 50);
|
c_assert(h1.data == 50);
|
||||||
assert(h2.data == 0);
|
c_assert(h2.data == 0);
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
|
|
||||||
class generator {
|
class generator {
|
||||||
private:
|
private:
|
||||||
|
@ -84,13 +84,13 @@ end
|
||||||
std::vector<int>& list1 = lua["list1"];
|
std::vector<int>& list1 = lua["list1"];
|
||||||
std::vector<int>& list2 = lua["list2"];
|
std::vector<int>& list2 = lua["list2"];
|
||||||
std::vector<int>& list3 = lua["list3"];
|
std::vector<int>& list3 = lua["list3"];
|
||||||
assert(list1.size() == 5);
|
c_assert(list1.size() == 5);
|
||||||
assert(list2.size() == 5);
|
c_assert(list2.size() == 5);
|
||||||
assert(list3.size() == 5);
|
c_assert(list3.size() == 5);
|
||||||
for (int i = 1; i <= 5; ++i) {
|
for (int i = 1; i <= 5; ++i) {
|
||||||
assert(list1[i - 1] == (mdata.first % 10) * i);
|
c_assert(list1[i - 1] == (mdata.first % 10) * i);
|
||||||
assert(list2[i - 1] == (mdata.second % 10) * i);
|
c_assert(list2[i - 1] == (mdata.second % 10) * i);
|
||||||
assert(list3[i - 1] == (mdata.third % 10) * i);
|
c_assert(list3[i - 1] == (mdata.third % 10) * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include "assert.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
struct vec {
|
struct vec {
|
||||||
|
@ -57,8 +57,8 @@ int main() {
|
||||||
vec& a1 = lua["a1"];
|
vec& a1 = lua["a1"];
|
||||||
vec& s1 = lua["s1"];
|
vec& s1 = lua["s1"];
|
||||||
|
|
||||||
assert(a1.x == 1 && a1.y == 1);
|
c_assert(a1.x == 1 && a1.y == 1);
|
||||||
assert(s1.x == 1 && s1.y == -1);
|
c_assert(s1.x == 1 && s1.y == -1);
|
||||||
|
|
||||||
lua["a2"] = lua["a1"];
|
lua["a2"] = lua["a1"];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define SOL_CHECK_ARGUMENTS 1
|
#define SOL_CHECK_ARGUMENTS 1
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
|
||||||
|
#include "assert.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
struct test {
|
struct test {
|
||||||
|
@ -19,21 +20,21 @@ int main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
int direct_value = lua["test"]["direct"];
|
int direct_value = lua["test"]["direct"];
|
||||||
assert(direct_value == 2);
|
c_assert(direct_value == 2);
|
||||||
// direct_value == 2
|
// direct_value == 2
|
||||||
|
|
||||||
int number = lua["test"]["number"];
|
int number = lua["test"]["number"];
|
||||||
assert(number == 25);
|
c_assert(number == 25);
|
||||||
int ref_number = lua["test"]["ref_number"];
|
int ref_number = lua["test"]["ref_number"];
|
||||||
assert(ref_number == 25);
|
c_assert(ref_number == 25);
|
||||||
|
|
||||||
test::number = 542;
|
test::number = 542;
|
||||||
|
|
||||||
assert(lua["test"]["number"] == 25);
|
c_assert(lua["test"]["number"] == 25);
|
||||||
// number is its own memory: was passed by value
|
// number is its own memory: was passed by value
|
||||||
// So does not change
|
// So does not change
|
||||||
|
|
||||||
assert(lua["test"]["ref_number"] == 542);
|
c_assert(lua["test"]["ref_number"] == 542);
|
||||||
// ref_number is just test::number
|
// ref_number is just test::number
|
||||||
// passed through std::ref
|
// passed through std::ref
|
||||||
// so, it holds a reference
|
// so, it holds a reference
|
||||||
|
|
|
@ -17,8 +17,8 @@ int main() {
|
||||||
lua.set("y", "hello");
|
lua.set("y", "hello");
|
||||||
|
|
||||||
// assert values are as given
|
// assert values are as given
|
||||||
lua.script("assert(x == 10)");
|
lua.script("c_assert(x == 10)");
|
||||||
lua.script("assert(y == 'hello')");
|
lua.script("c_assert(y == 'hello')");
|
||||||
|
|
||||||
|
|
||||||
// basic retrieval of a variable
|
// basic retrieval of a variable
|
||||||
|
|
|
@ -32,9 +32,9 @@ int main() {
|
||||||
// will error: not enough arguments
|
// will error: not enough arguments
|
||||||
//lua.script("x4 = v(1)");
|
//lua.script("x4 = v(1)");
|
||||||
|
|
||||||
lua.script("assert(x == 50)");
|
lua.script("c_assert(x == 50)");
|
||||||
lua.script("assert(x2 == 600)");
|
lua.script("c_assert(x2 == 600)");
|
||||||
lua.script("assert(x3 == 21)");
|
lua.script("c_assert(x3 == 21)");
|
||||||
lua.script("print(x)"); // 50
|
lua.script("print(x)"); // 50
|
||||||
lua.script("print(x2)"); // 600
|
lua.script("print(x2)"); // 600
|
||||||
lua.script("print(x3)"); // 21
|
lua.script("print(x3)"); // 21
|
||||||
|
|
|
@ -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 2017-12-11 17:29:42.822392 UTC
|
// Generated 2017-12-26 04:26:55.295046 UTC
|
||||||
// This header was generated with sol v2.19.0 (revision cf81d81)
|
// This header was generated with sol v2.19.0 (revision acade46)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -64,17 +64,19 @@
|
||||||
|
|
||||||
// beginning of sol/feature_test.hpp
|
// beginning of sol/feature_test.hpp
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L)))
|
#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L))))
|
||||||
#ifndef SOL_CXX17_FEATURES
|
#ifndef SOL_CXX17_FEATURES
|
||||||
#define SOL_CXX17_FEATURES 1
|
#define SOL_CXX17_FEATURES 1
|
||||||
#endif // C++17 features macro
|
#endif // C++17 features macro
|
||||||
#endif // C++17 features check
|
#endif // C++17 features check
|
||||||
|
|
||||||
#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)))
|
#ifdef SOL_CXX17_FEATURES
|
||||||
|
#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201703L) && defined(_WIN64))))
|
||||||
#ifndef SOL_NOEXCEPT_FUNCTION_TYPE
|
#ifndef SOL_NOEXCEPT_FUNCTION_TYPE
|
||||||
#define SOL_NOEXCEPT_FUNCTION_TYPE 1
|
#define SOL_NOEXCEPT_FUNCTION_TYPE 1
|
||||||
#endif // noexcept is part of a function's type
|
#endif // noexcept is part of a function's type
|
||||||
#endif
|
#endif // compiler-specific checks
|
||||||
|
#endif // C++17 only
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_MSC_VER)
|
#if defined(_WIN32) || defined(_MSC_VER)
|
||||||
#ifndef SOL_CODECVT_SUPPORT
|
#ifndef SOL_CODECVT_SUPPORT
|
||||||
|
@ -430,10 +432,10 @@ namespace sol {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <std::size_t N, typename Tuple>
|
template <std::size_t N, typename Tuple>
|
||||||
using tuple_element = std::tuple_element<N, unqualified_t<Tuple>>;
|
using tuple_element = std::tuple_element<N, std::remove_reference_t<Tuple>>;
|
||||||
|
|
||||||
template <std::size_t N, typename Tuple>
|
template <std::size_t N, typename Tuple>
|
||||||
using tuple_element_t = std::tuple_element_t<N, unqualified_t<Tuple>>;
|
using tuple_element_t = std::tuple_element_t<N, std::remove_reference_t<Tuple>>;
|
||||||
|
|
||||||
template <std::size_t N, typename Tuple>
|
template <std::size_t N, typename Tuple>
|
||||||
using unqualified_tuple_element = unqualified<tuple_element_t<N, Tuple>>;
|
using unqualified_tuple_element = unqualified<tuple_element_t<N, Tuple>>;
|
||||||
|
@ -1175,9 +1177,9 @@ namespace sol {
|
||||||
struct always_true : std::true_type {};
|
struct always_true : std::true_type {};
|
||||||
struct is_invokable_tester {
|
struct is_invokable_tester {
|
||||||
template <typename Fun, typename... Args>
|
template <typename Fun, typename... Args>
|
||||||
always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
|
static always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> test(int);
|
||||||
template <typename...>
|
template <typename...>
|
||||||
std::false_type static test(...);
|
static std::false_type test(...);
|
||||||
};
|
};
|
||||||
} // namespace meta_detail
|
} // namespace meta_detail
|
||||||
|
|
||||||
|
@ -1406,6 +1408,11 @@ namespace sol {
|
||||||
std::true_type supports_adl_to_string(const T&);
|
std::true_type supports_adl_to_string(const T&);
|
||||||
std::false_type supports_adl_to_string(...);
|
std::false_type supports_adl_to_string(...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <typename T, bool b>
|
||||||
|
struct is_matched_lookup_impl : std::false_type {};
|
||||||
|
template <typename T>
|
||||||
|
struct is_matched_lookup_impl<T, true> : std::is_same<typename T::key_type, typename T::value_type> {};
|
||||||
} // namespace meta_detail
|
} // namespace meta_detail
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1910
|
#if defined(_MSC_VER) && _MSC_VER <= 1910
|
||||||
|
@ -1473,6 +1480,9 @@ namespace sol {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_lookup : meta::all<has_key_type<T>, has_value_type<T>> {};
|
struct is_lookup : meta::all<has_key_type<T>, has_value_type<T>> {};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct is_matched_lookup : meta_detail::is_matched_lookup_impl<T, meta::all<has_key_type<T>, has_value_type<T>>::value> {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using is_string_constructible = any<
|
using is_string_constructible = any<
|
||||||
std::is_same<unqualified_t<T>, const char*>, std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>>
|
std::is_same<unqualified_t<T>, const char*>, std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>>
|
||||||
|
@ -3085,38 +3095,38 @@ namespace sol {
|
||||||
// workaround for missing traits in GCC and CLANG
|
// workaround for missing traits in GCC and CLANG
|
||||||
template <class T>
|
template <class T>
|
||||||
struct is_nothrow_move_constructible {
|
struct is_nothrow_move_constructible {
|
||||||
constexpr static bool value = ::std::is_nothrow_constructible<T, T&&>::value;
|
static constexprbool value = ::std::is_nothrow_constructible<T, T&&>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T, class U>
|
template <class T, class U>
|
||||||
struct is_assignable {
|
struct is_assignable {
|
||||||
template <class X, class Y>
|
template <class X, class Y>
|
||||||
constexpr static bool has_assign(...) {
|
static constexprbool has_assign(...) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X, class Y, size_t S = sizeof((::std::declval<X>() = ::std::declval<Y>(), true))>
|
template <class X, class Y, size_t S = sizeof((::std::declval<X>() = ::std::declval<Y>(), true))>
|
||||||
// the comma operator is necessary for the cases where operator= returns void
|
// the comma operator is necessary for the cases where operator= returns void
|
||||||
constexpr static bool has_assign(bool) {
|
static constexprbool has_assign(bool) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static bool value = has_assign<T, U>(true);
|
static constexprbool value = has_assign<T, U>(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct is_nothrow_move_assignable {
|
struct is_nothrow_move_assignable {
|
||||||
template <class X, bool has_any_move_assign>
|
template <class X, bool has_any_move_assign>
|
||||||
struct has_nothrow_move_assign {
|
struct has_nothrow_move_assign {
|
||||||
constexpr static bool value = false;
|
static constexprbool value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
struct has_nothrow_move_assign<X, true> {
|
struct has_nothrow_move_assign<X, true> {
|
||||||
constexpr static bool value = noexcept(::std::declval<X&>() = ::std::declval<X&&>());
|
static constexprbool value = noexcept(::std::declval<X&>() = ::std::declval<X&&>());
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr static bool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value;
|
static constexprbool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value;
|
||||||
};
|
};
|
||||||
// end workaround
|
// end workaround
|
||||||
|
|
||||||
|
@ -3159,16 +3169,16 @@ namespace sol {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct has_overloaded_addressof {
|
struct has_overloaded_addressof {
|
||||||
template <class X>
|
template <class X>
|
||||||
constexpr static bool has_overload(...) {
|
static constexpr bool has_overload(...) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X, size_t S = sizeof(::std::declval<X&>().operator&())>
|
template <class X, size_t S = sizeof(::std::declval<X&>().operator&())>
|
||||||
constexpr static bool has_overload(bool) {
|
static constexpr bool has_overload(bool) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static bool value = has_overload<T>(true);
|
static constexpr bool value = has_overload<T>(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
|
template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
|
||||||
|
@ -5650,7 +5660,7 @@ namespace detail {
|
||||||
inline std::string ctti_get_type_name() {
|
inline std::string ctti_get_type_name() {
|
||||||
// cardinal sins from MINGW
|
// cardinal sins from MINGW
|
||||||
using namespace std;
|
using namespace std;
|
||||||
const static std::array<std::string, 2> removals = {{"{anonymous}", "(anonymous namespace)"}};
|
static const std::array<std::string, 2> removals = {{"{anonymous}", "(anonymous namespace)"}};
|
||||||
std::string name = __PRETTY_FUNCTION__;
|
std::string name = __PRETTY_FUNCTION__;
|
||||||
std::size_t start = name.find_first_of('[');
|
std::size_t start = name.find_first_of('[');
|
||||||
start = name.find_first_of('=', start);
|
start = name.find_first_of('=', start);
|
||||||
|
@ -5684,7 +5694,7 @@ namespace detail {
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::string ctti_get_type_name() {
|
inline std::string ctti_get_type_name() {
|
||||||
const static std::array<std::string, 7> removals = {{"public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'"}};
|
static const std::array<std::string, 7> removals = {{"public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'"}};
|
||||||
std::string name = __FUNCSIG__;
|
std::string name = __FUNCSIG__;
|
||||||
std::size_t start = name.find("get_type_name");
|
std::size_t start = name.find("get_type_name");
|
||||||
if (start == std::string::npos)
|
if (start == std::string::npos)
|
||||||
|
@ -10070,14 +10080,18 @@ namespace stack {
|
||||||
struct popper {
|
struct popper {
|
||||||
inline static decltype(auto) pop(lua_State* L) {
|
inline static decltype(auto) pop(lua_State* L) {
|
||||||
record tracking{};
|
record tracking{};
|
||||||
|
#ifdef __INTEL_COMPILER
|
||||||
|
auto&& r = get<T>(L, -lua_size<T>::value, tracking);
|
||||||
|
#else
|
||||||
decltype(auto) r = get<T>(L, -lua_size<T>::value, tracking);
|
decltype(auto) r = get<T>(L, -lua_size<T>::value, tracking);
|
||||||
|
#endif
|
||||||
lua_pop(L, tracking.used);
|
lua_pop(L, tracking.used);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct popper<T, std::enable_if_t<std::is_base_of<stack_reference, meta::unqualified_t<T>>::value>> {
|
struct popper<T, std::enable_if_t<is_stack_based<meta::unqualified_t<T>>::value>> {
|
||||||
static_assert(meta::neg<std::is_base_of<stack_reference, meta::unqualified_t<T>>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!");
|
static_assert(meta::neg<std::is_base_of<stack_reference, meta::unqualified_t<T>>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -10435,10 +10449,10 @@ namespace sol {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline int push_as_upvalues(lua_State* L, T& item) {
|
inline int push_as_upvalues(lua_State* L, T& item) {
|
||||||
typedef std::decay_t<T> TValue;
|
typedef std::decay_t<T> TValue;
|
||||||
const static std::size_t itemsize = sizeof(TValue);
|
static const std::size_t itemsize = sizeof(TValue);
|
||||||
const static std::size_t voidsize = sizeof(void*);
|
static const std::size_t voidsize = sizeof(void*);
|
||||||
const static std::size_t voidsizem1 = voidsize - 1;
|
static const std::size_t voidsizem1 = voidsize - 1;
|
||||||
const static std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize;
|
static const std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize;
|
||||||
typedef std::array<void*, data_t_count> data_t;
|
typedef std::array<void*, data_t_count> data_t;
|
||||||
|
|
||||||
data_t data{ {} };
|
data_t data{ {} };
|
||||||
|
@ -10452,7 +10466,7 @@ namespace sol {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::pair<T, int> get_as_upvalues(lua_State* L, int index = 2) {
|
inline std::pair<T, int> get_as_upvalues(lua_State* L, int index = 2) {
|
||||||
const static std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*);
|
static const std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*);
|
||||||
typedef std::array<void*, data_t_count> data_t;
|
typedef std::array<void*, data_t_count> data_t;
|
||||||
data_t voiddata{ {} };
|
data_t voiddata{ {} };
|
||||||
for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) {
|
for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) {
|
||||||
|
@ -15188,25 +15202,36 @@ namespace sol {
|
||||||
typedef container_traits<X> deferred_traits;
|
typedef container_traits<X> deferred_traits;
|
||||||
typedef meta::is_associative<T> is_associative;
|
typedef meta::is_associative<T> is_associative;
|
||||||
typedef meta::is_lookup<T> is_lookup;
|
typedef meta::is_lookup<T> is_lookup;
|
||||||
|
typedef meta::is_matched_lookup<T> is_matched_lookup;
|
||||||
typedef typename T::iterator iterator;
|
typedef typename T::iterator iterator;
|
||||||
typedef typename T::value_type value_type;
|
typedef typename T::value_type value_type;
|
||||||
typedef std::conditional_t<is_associative::value,
|
typedef std::conditional_t<is_matched_lookup::value,
|
||||||
value_type,
|
std::pair<value_type, value_type>,
|
||||||
std::conditional_t<is_lookup::value, std::pair<value_type, value_type>, std::pair<std::ptrdiff_t, value_type>>>
|
std::conditional_t<is_associative::value || is_lookup::value,
|
||||||
KV;
|
value_type,
|
||||||
|
std::pair<std::ptrdiff_t, value_type>
|
||||||
|
>
|
||||||
|
> KV;
|
||||||
typedef typename KV::first_type K;
|
typedef typename KV::first_type K;
|
||||||
typedef typename KV::second_type V;
|
typedef typename KV::second_type V;
|
||||||
typedef decltype(*std::declval<iterator&>()) iterator_return;
|
typedef decltype(*std::declval<iterator&>()) iterator_return;
|
||||||
|
typedef std::conditional_t<is_associative::value || is_matched_lookup::value,
|
||||||
|
std::add_lvalue_reference_t<V>,
|
||||||
|
std::conditional_t<is_lookup::value,
|
||||||
|
V,
|
||||||
|
iterator_return
|
||||||
|
>
|
||||||
|
> captured_type;
|
||||||
typedef typename meta::iterator_tag<iterator>::type iterator_category;
|
typedef typename meta::iterator_tag<iterator>::type iterator_category;
|
||||||
typedef std::is_same<iterator_category, std::input_iterator_tag> is_input_iterator;
|
typedef std::is_same<iterator_category, std::input_iterator_tag> is_input_iterator;
|
||||||
typedef std::conditional_t<is_input_iterator::value,
|
typedef std::conditional_t<is_input_iterator::value,
|
||||||
V,
|
V,
|
||||||
decltype(detail::deref(std::declval<std::conditional_t<is_associative::value, std::add_lvalue_reference_t<V>, iterator_return>>()))>
|
decltype(detail::deref(std::declval<captured_type>()))
|
||||||
push_type;
|
> push_type;
|
||||||
typedef std::is_copy_assignable<V> is_copyable;
|
typedef std::is_copy_assignable<V> is_copyable;
|
||||||
typedef meta::neg<meta::any<
|
typedef meta::neg<meta::any<
|
||||||
std::is_const<V>, std::is_const<std::remove_reference_t<iterator_return>>, meta::neg<is_copyable>>>
|
std::is_const<V>, std::is_const<std::remove_reference_t<iterator_return>>, meta::neg<is_copyable>
|
||||||
is_writable;
|
>> is_writable;
|
||||||
typedef meta::unqualified_t<decltype(get_key(is_associative(), std::declval<std::add_lvalue_reference_t<value_type>>()))> key_type;
|
typedef meta::unqualified_t<decltype(get_key(is_associative(), std::declval<std::add_lvalue_reference_t<value_type>>()))> key_type;
|
||||||
typedef meta::all<std::is_integral<K>, meta::neg<meta::any<is_associative, is_lookup>>> is_linear_integral;
|
typedef meta::all<std::is_integral<K>, meta::neg<meta::any<is_associative, is_lookup>>> is_linear_integral;
|
||||||
|
|
||||||
|
@ -15231,7 +15256,7 @@ namespace sol {
|
||||||
}
|
}
|
||||||
return *p.value();
|
return *p.value();
|
||||||
#else
|
#else
|
||||||
return stack::get<Tu>(L, 1);
|
return stack::get<T>(L, 1);
|
||||||
#endif // Safe getting with error
|
#endif // Safe getting with error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15763,7 +15788,8 @@ namespace sol {
|
||||||
|
|
||||||
template <bool ip>
|
template <bool ip>
|
||||||
static int next(lua_State* L) {
|
static int next(lua_State* L) {
|
||||||
return next_associative<ip>(is_associative(), L);
|
typedef meta::any<is_associative, meta::all<is_lookup, meta::neg<is_matched_lookup>>> is_assoc;
|
||||||
|
return next_associative<ip>(is_assoc(), L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -15851,11 +15877,13 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pairs(lua_State* L) {
|
static int pairs(lua_State* L) {
|
||||||
return pairs_associative<false>(is_associative(), L);
|
typedef meta::any<is_associative, meta::all<is_lookup, meta::neg<is_matched_lookup>>> is_assoc;
|
||||||
|
return pairs_associative<false>(is_assoc(), L);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ipairs(lua_State* L) {
|
static int ipairs(lua_State* L) {
|
||||||
return pairs_associative<true>(is_associative(), L);
|
typedef meta::any<is_associative, meta::all<is_lookup, meta::neg<is_matched_lookup>>> is_assoc;
|
||||||
|
return pairs_associative<true>(is_assoc(), L);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18352,8 +18380,8 @@ namespace sol {
|
||||||
stack::check<basic_table_core>(lua_state(), -1, handler);
|
stack::check<basic_table_core>(lua_state(), -1, handler);
|
||||||
#endif // Safety
|
#endif // Safety
|
||||||
}
|
}
|
||||||
basic_table_core(lua_State* L, new_table nt)
|
basic_table_core(lua_State* L, const new_table& nt)
|
||||||
: base_t(L, (lua_createtable(L, nt.sequence_hint, nt.map_hint), -1)) {
|
: base_t(L, -stack::push(L, nt)) {
|
||||||
if (!is_stack_based<meta::unqualified_t<base_type>>::value) {
|
if (!is_stack_based<meta::unqualified_t<base_type>>::value) {
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 2017-12-11 17:29:42.995868 UTC
|
// Generated 2017-12-26 04:26:55.501596 UTC
|
||||||
// This header was generated with sol v2.19.0 (revision cf81d81)
|
// This header was generated with sol v2.19.0 (revision acade46)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||||
|
@ -31,17 +31,19 @@
|
||||||
|
|
||||||
// beginning of sol/feature_test.hpp
|
// beginning of sol/feature_test.hpp
|
||||||
|
|
||||||
#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L)))
|
#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L))))
|
||||||
#ifndef SOL_CXX17_FEATURES
|
#ifndef SOL_CXX17_FEATURES
|
||||||
#define SOL_CXX17_FEATURES 1
|
#define SOL_CXX17_FEATURES 1
|
||||||
#endif // C++17 features macro
|
#endif // C++17 features macro
|
||||||
#endif // C++17 features check
|
#endif // C++17 features check
|
||||||
|
|
||||||
#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)))
|
#ifdef SOL_CXX17_FEATURES
|
||||||
|
#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201703L) && defined(_WIN64))))
|
||||||
#ifndef SOL_NOEXCEPT_FUNCTION_TYPE
|
#ifndef SOL_NOEXCEPT_FUNCTION_TYPE
|
||||||
#define SOL_NOEXCEPT_FUNCTION_TYPE 1
|
#define SOL_NOEXCEPT_FUNCTION_TYPE 1
|
||||||
#endif // noexcept is part of a function's type
|
#endif // noexcept is part of a function's type
|
||||||
#endif
|
#endif // compiler-specific checks
|
||||||
|
#endif // C++17 only
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_MSC_VER)
|
#if defined(_WIN32) || defined(_MSC_VER)
|
||||||
#ifndef SOL_CODECVT_SUPPORT
|
#ifndef SOL_CODECVT_SUPPORT
|
||||||
|
|
Loading…
Reference in New Issue
Block a user