mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
New Workflows, More Optional Tests
- Add a test for picking deeply nested / constructible values out of an optional - Fix up the readme to show where users can get support
This commit is contained in:
parent
220335d95c
commit
4649a76507
33
.github/workflows/macosx.yml
vendored
Normal file
33
.github/workflows/macosx.yml
vendored
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
name: Mac OSX
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: macos-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: configure
|
||||||
|
run: |
|
||||||
|
cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
||||||
|
cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
||||||
|
- name: build
|
||||||
|
run: |
|
||||||
|
cmake --build build/debug --config Debug
|
||||||
|
cmake --build build/release --config Release
|
||||||
|
- name: test
|
||||||
|
run: |
|
||||||
|
cd build/debug
|
||||||
|
ctest --build-config Debug
|
||||||
|
cd ../..
|
||||||
|
cd build/release
|
||||||
|
ctest --build-config Release
|
||||||
|
cd ../..
|
33
.github/workflows/ubuntu.yml
vendored
Normal file
33
.github/workflows/ubuntu.yml
vendored
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
name: Mac OSX
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CTEST_OUTPUT_ON_FAILURE: 1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: configure
|
||||||
|
run: |
|
||||||
|
cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
||||||
|
cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
||||||
|
- name: build
|
||||||
|
run: |
|
||||||
|
cmake --build build/debug --config Debug
|
||||||
|
cmake --build build/release --config Release
|
||||||
|
- name: test
|
||||||
|
run: |
|
||||||
|
cd build/debug
|
||||||
|
ctest --build-config Debug
|
||||||
|
cd ../..
|
||||||
|
cd build/release
|
||||||
|
ctest --build-config Release
|
||||||
|
cd ../..
|
4
.github/workflows/windows.yml
vendored
4
.github/workflows/windows.yml
vendored
|
@ -17,8 +17,8 @@ jobs:
|
||||||
|
|
||||||
- name: configure
|
- name: configure
|
||||||
run: |
|
run: |
|
||||||
cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
||||||
cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON
|
||||||
- name: build
|
- name: build
|
||||||
run: |
|
run: |
|
||||||
cmake --build build/debug --config Debug
|
cmake --build build/debug --config Debug
|
||||||
|
|
148
README.md
148
README.md
|
@ -1,21 +1,12 @@
|
||||||
## sol3 (sol2 v3.2.3)
|
# sol2
|
||||||
|
|
||||||
[![Linux & Max OSX Build Status](https://travis-ci.org/ThePhD/sol2.svg?branch=develop)](https://travis-ci.org/ThePhD/sol2)
|
|
||||||
[![Windows Build status](https://ci.appveyor.com/api/projects/status/n38suofr21e9uk7h?svg=true)](https://ci.appveyor.com/project/ThePhD/sol2)
|
|
||||||
[![Documentation Status](https://readthedocs.org/projects/sol2/badge/?version=latest)](http://sol2.readthedocs.io/en/latest/?badge=latest)
|
[![Documentation Status](https://readthedocs.org/projects/sol2/badge/?version=latest)](http://sol2.readthedocs.io/en/latest/?badge=latest)
|
||||||
|
|
||||||
[![Support via Github Sponsors](https://img.shields.io/badge/Github-Become%20a%20Sponsor-ff69b4.svg?style=flat&logo=GitHub)](https://github.com/users/ThePhD/sponsorship)
|
|
||||||
[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/Soasis)
|
|
||||||
[![Support via Ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Soasis)
|
|
||||||
[![Support via Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.herokuapp.com%2FSoasis)](https://patreon.com/soasis)
|
|
||||||
[![Support via Liberapay](https://img.shields.io/liberapay/patrons/ThePhD.svg)](https://liberapay.com/Soasis/)
|
|
||||||
|
|
||||||
sol2 is a C++ library binding to Lua. It currently supports all Lua versions 5.1+ (LuaJIT 2.x included). sol2 aims to be easy to use and easy to add to a project.
|
|
||||||
The library is header-only for easy integration with projects.
|
|
||||||
|
|
||||||
## Documentation
|
sol2 is a C++ library binding to Lua. It currently supports all Lua versions 5.1+ (LuaJIT 2.0+ and MoonJIT included). sol2 aims to be easy to use and easy to add to a project. The library is header-only for easy integration with projects, and a single header can be used for drag-and-drop start up.
|
||||||
|
|
||||||
|
|
||||||
Find it [here](http://sol2.rtfd.io/). A run-through kind of tutorial is [here](http://sol2.readthedocs.io/en/latest/tutorial/all-the-things.html)! The API documentation goes over most cases (particularly, the "api/usertype" and "api/table_proxy" and "api/function" sections) that should still get you off your feet and going, and there's an examples directory [here](https://github.com/ThePhD/sol2/tree/develop/examples) as well.
|
|
||||||
|
|
||||||
## Sneak Peek
|
## Sneak Peek
|
||||||
|
|
||||||
|
@ -52,14 +43,83 @@ int main() {
|
||||||
More examples are given in the examples directory [here](https://github.com/ThePhD/sol2/tree/develop/examples).
|
More examples are given in the examples directory [here](https://github.com/ThePhD/sol2/tree/develop/examples).
|
||||||
|
|
||||||
|
|
||||||
## Supporting
|
## Documentation
|
||||||
|
|
||||||
Please use the buttons above and help this project grow.
|
Find it [here](http://sol2.rtfd.io/). A run-through kind of tutorial is [here](http://sol2.readthedocs.io/en/latest/tutorial/all-the-things.html)! The API documentation goes over most cases (particularly, the "api/usertype" and "api/table_proxy" and "api/function" sections) that should still get you off your feet and going, and there's an examples directory [here](https://github.com/ThePhD/sol2/tree/develop/examples) as well.
|
||||||
|
|
||||||
You can also help out the library by submitting pull requests to fix anything or add anything you think would be helpful! This includes making small, useful examples of something you haven't seen, or fixing typos and bad code in the documentation.
|
|
||||||
|
|
||||||
|
|
||||||
## Presentations
|
|
||||||
|
|
||||||
|
# "I need X Feature or Fix, Right Now™"
|
||||||
|
|
||||||
|
Find the support option that's right for you, [here](https://github.com/ThePhD/.github/blob/main/SUPPORT.md)! If you're happy to wait, you can just file a boring issue and we'll get to it Whenever There Is Time™.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## I want to donate to help!
|
||||||
|
|
||||||
|
You can find [donation and sponorship options here](https://github.com/ThePhD/.github/blob/main/SUPPORT.md#support-in-general) and from the little heart button near the top of this repository that will take you to a bevy of links in which you can donate and show support for this project and others!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Features
|
||||||
|
|
||||||
|
- [Fastest in the land](http://sol2.readthedocs.io/en/latest/benchmarks.html) (see: sol3 bar in graph).
|
||||||
|
- Supports retrieval and setting of multiple types including:
|
||||||
|
* `std::string`, `std::wstring`, `std::u16string` and `std::u32string` support (and for views).
|
||||||
|
* understands and works with containers such as `std::map/unordered_map`, c-style arrays, vectors, non-standard custom containers and more.
|
||||||
|
* user-defined types, with or **without** registering that type
|
||||||
|
* `std::unique_ptr`, `std::shared_ptr`, and optional support of other pointer types like `boost::shared_ptr`.
|
||||||
|
* custom `optional<T>` that works with references, and support for the inferior `std::optional`.
|
||||||
|
* C++17 support for variants and similar new types.
|
||||||
|
- Lambda, function, and member function bindings are supported.
|
||||||
|
- Intermediate type for checking if a variable exists.
|
||||||
|
- Simple API that completely abstracts away the C stack API, including `protected_function` with the ability to use an error-handling function.
|
||||||
|
- `operator[]`-style manipulation of tables
|
||||||
|
- C++ type representations in Lua userdata as `usertype`s with guaranteed cleanup.
|
||||||
|
- Customization points to allow your C++ objects to be pushed and retrieved from Lua as multiple consecutive objects, or anything else you desire!
|
||||||
|
- Overloaded function calls: `my_function(1); my_function("Hello")` in the same Lua script route to different function calls based on parameters
|
||||||
|
- Support for tables, nested tables, table iteration with `table.for_each` / `begin()` and `end()` iterators.
|
||||||
|
- Zero string overhead for usertype function lookup.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Compilers
|
||||||
|
|
||||||
|
sol2 makes use of C++17 features. GCC 7.x.x and Clang 3.9.x (with `-std=c++1z` and appropriate standard library) or higher should be able to compile without problems. However, the officially supported and CI-tested compilers are:
|
||||||
|
|
||||||
|
- GCC 7.x.x+ (MinGW 7.x.x+)
|
||||||
|
- Clang 3.9.x+
|
||||||
|
- Visual Studio 2017 Community (Visual C++ 15.0)+
|
||||||
|
|
||||||
|
Please make sure you use the `-std=c++2a`, `-std=c++1z`, `-std=c++17` or better standard flags
|
||||||
|
(some of these flags are the defaults in later versions of GCC, such as 7+ and better).
|
||||||
|
|
||||||
|
If you would like support for an older compiler (at the cost of some features), use the latest tagged sol2 branch. If you would like support for an even older compiler, feel free to contact me for a Custom Solution.
|
||||||
|
|
||||||
|
sol3 is checked by-hand for other platforms as well, including Android-based builds with GCC and iOS-based builds out of XCode with Apple-clang. It should work on both of these platforms, so long as you have the proper standards flags. If something doesn't work or you need special options, you may need to look into the different ways to support the project to have it done for you!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Creating a single header
|
||||||
|
|
||||||
|
You can grab a single header (and the single forward header) out of the library [here](https://github.com/ThePhD/sol2/tree/develop/single). For stable version, check the releases tab on GitHub for a provided single header file for maximum ease of use. A script called [`single.py`](https://github.com/ThePhD/sol2/blob/develop/single/single.py) is provided in the repository if there's some bleeding edge change that hasn't been published on the releases page. You can run this script to create a single file version of the library so you can only include that part of it. Check `single.py --help` for more info.
|
||||||
|
|
||||||
|
If you use CMake, you can also configure and generate a project that will generate the `sol2_single_header` for you. You can also include the project using CMake. Run CMake for more details. Thanks @Nava2, @alkino, @mrgreywater and others for help with making the CMake build a reality.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
|
||||||
|
Testing turns on certain CI-only variables in the CMake to test a myriad of configuration options. You can generate the tests by running CMake and configuring `SOL2_TESTS`, `SOL2_TESTS_SINGLE`, `SOL2_TESTS_EXAMPLES`, and `SOL2_EXAMPLES` to be on. Make sure `SOL2_SINGLE` is also on.
|
||||||
|
|
||||||
|
You will need any flavor of python3 and an available compiler. The testing suite will build its own version of Lua and LuaJIT, so you do not have to provide one (you may provide one with the `LUA_LOCAL_DIR` variable).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Presentations
|
||||||
|
|
||||||
"A Sun For the Moon - A Zero-Overhead Lua Abstraction using C++"
|
"A Sun For the Moon - A Zero-Overhead Lua Abstraction using C++"
|
||||||
ThePhD
|
ThePhD
|
||||||
|
@ -92,60 +152,10 @@ C++Now 2019 - Flug Auditorium, Aspen Physics Center, Aspen, Colorado
|
||||||
[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2019.05.10%20-%20ThePhD%20-%20The%20Plan%20for%20Tomorrow%20-%20Compile-Time%20Extension%20Points%20in%20C%2b%2b.pdf)
|
[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2019.05.10%20-%20ThePhD%20-%20The%20Plan%20for%20Tomorrow%20-%20Compile-Time%20Extension%20Points%20in%20C%2b%2b.pdf)
|
||||||
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- [Fastest in the land](http://sol2.readthedocs.io/en/latest/benchmarks.html) (see: sol3 bar in graph).
|
|
||||||
- Supports retrieval and setting of multiple types including:
|
|
||||||
* `std::string`, `std::wstring`, `std::u16string` and `std::u32string` support (and for views).
|
|
||||||
* understands and works with containers such as `std::map/unordered_map`, c-style arrays, vectors, non-standard custom containers and more.
|
|
||||||
* user-defined types, with or **without** registering that type
|
|
||||||
* `std::unique_ptr`, `std::shared_ptr`, and optional support of other pointer types like `boost::shared_ptr`.
|
|
||||||
* custom `optional<T>` that works with references, and support for the inferior `std::optional`.
|
|
||||||
* C++17 support for variants and similar new types.
|
|
||||||
- Lambda, function, and member function bindings are supported.
|
|
||||||
- Intermediate type for checking if a variable exists.
|
|
||||||
- Simple API that completely abstracts away the C stack API, including `protected_function` with the ability to use an error-handling function.
|
|
||||||
- `operator[]`-style manipulation of tables
|
|
||||||
- C++ type representations in Lua userdata as `usertype`s with guaranteed cleanup.
|
|
||||||
- Customization points to allow your C++ objects to be pushed and retrieved from Lua as multiple consecutive objects, or anything else you desire!
|
|
||||||
- Overloaded function calls: `my_function(1); my_function("Hello")` in the same Lua script route to different function calls based on parameters
|
|
||||||
- Support for tables, nested tables, table iteration with `table.for_each` / `begin()` and `end()` iterators.
|
|
||||||
- Zero string overhead for usertype function lookup.
|
|
||||||
|
|
||||||
|
|
||||||
## Supported Compilers
|
# License
|
||||||
|
|
||||||
sol2 makes use of C++17 features. GCC 7.x.x and Clang 3.9.x (with `-std=c++1z` and appropriate standard library)
|
|
||||||
or higher should be able to compile without problems. However, the officially supported and CI-tested compilers are:
|
|
||||||
|
|
||||||
- GCC 7.x.x+ (MinGW 7.x.x+)
|
|
||||||
- Clang 3.9.x+
|
|
||||||
- Visual Studio 2017 Community (Visual C++ 15.0)+
|
|
||||||
|
|
||||||
Please make sure you use the `-std=c++2a`, `-std=c++1z`, `-std=c++17` or better standard flags
|
|
||||||
(some of these flags are the defaults in later versions of GCC, such as 7+ and better).
|
|
||||||
|
|
||||||
If you would like support for an older compiler (at the cost of some features), use the latest tagged sol2 branch. If you would like support for an even older compiler, feel free to contact me for a Custom Solution.
|
|
||||||
|
|
||||||
sol3 is checked by-hand for other platforms as well, including Android-based builds with GCC and iOS-based builds out of XCode with Apple-clang. It should work on both of these platforms, so long as you have the proper standards flags.
|
|
||||||
|
|
||||||
|
|
||||||
## Creating a single header
|
|
||||||
|
|
||||||
You can grab a single header (and the single forward header) out of the library [here](https://github.com/ThePhD/sol2/tree/develop/single). For stable version, check the releases tab on GitHub for a provided single header file for maximum ease of use. A script called [`single.py`](https://github.com/ThePhD/sol2/blob/develop/single/single.py) is provided in the repository if there's some bleeding edge change that hasn't been published on the releases page. You can run this script to create a single file version of the library so you can only include that part of it. Check `single.py --help` for more info.
|
|
||||||
|
|
||||||
If you use CMake, you can also configure and generate a project that will generate the `sol2_single_header` for you. You can also include the project using CMake. Run CMake for more details. Thanks @Nava2, @alkino, @mrgreywater and others for help with making the CMake build a reality.
|
|
||||||
|
|
||||||
|
|
||||||
## Running the Tests
|
|
||||||
|
|
||||||
Testing on Travis-CI and Appveyor use CMake. You can generate the tests by running CMake and configuring `SOL2_TESTS`, `SOL2_TESTS_SINGLE`, `SOL2_TESTS_EXAMPLES`, and `SOL2_EXAMPLES` to be on. Make sure `SOL2_SINGLE` is also on.
|
|
||||||
|
|
||||||
You will need any flavor of python3 and an available compiler. The testing suite will build its own version of Lua and LuaJIT, so you do not have to provide one (you may provide one with the `LUA_LOCAL_DIR` variable).
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
sol2 is distributed with an MIT License. You can see LICENSE.txt for more info.
|
sol2 is distributed with an MIT License. You can see LICENSE.txt for more info.
|
||||||
|
|
||||||
If you need a custom solution, feel free to contact me.
|
If you need a custom solution, [feel free to reach out](https://soasis.org/contact/opensource/).
|
||||||
|
|
|
@ -48,9 +48,16 @@ namespace sol { namespace function_detail {
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct on_success {
|
||||||
|
template <typename... Args>
|
||||||
|
int operator()(Args&&... args) const {
|
||||||
|
return call(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int operator()(lua_State* L) {
|
int operator()(lua_State* L) {
|
||||||
auto mfx = [](auto&&... args) { return call(std::forward<decltype(args)>(args)...); };
|
on_success call_obj {};
|
||||||
return call_detail::overload_match<Functions...>(mfx, L, 1 + start_skew, overloads);
|
return call_detail::overload_match<Functions...>(call_obj, L, 1 + start_skew, overloads);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}} // namespace sol::function_detail
|
}} // namespace sol::function_detail
|
||||||
|
|
|
@ -70,14 +70,14 @@ namespace sol { namespace stack {
|
||||||
tracking.use(static_cast<int>(success));
|
tracking.use(static_cast<int>(success));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return stack_detail::unchecked_get<ValueType>(L, index, tracking);
|
return T(stack_detail::unchecked_get<ValueType>(L, index, tracking));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!check<ValueType>(L, index, &no_panic)) {
|
if (!check<ValueType>(L, index, &no_panic)) {
|
||||||
tracking.use(static_cast<int>(!lua_isnone(L, index)));
|
tracking.use(static_cast<int>(!lua_isnone(L, index)));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return stack_detail::unchecked_get<ValueType>(L, index, tracking);
|
return T(stack_detail::unchecked_get<ValueType>(L, index, tracking));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -853,7 +853,7 @@ namespace sol {
|
||||||
template <>
|
template <>
|
||||||
struct is_transparent_argument<variadic_args> : std::true_type { };
|
struct is_transparent_argument<variadic_args> : std::true_type { };
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_variadic_arguments : std::is_same<T, variadic_args> { };
|
struct is_variadic_arguments : meta::any<std::is_same<T, variadic_args>, meta::is_optional<T>> { };
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_container
|
struct is_container
|
||||||
|
|
|
@ -53,7 +53,7 @@ inline namespace sol2_test_container_table {
|
||||||
|
|
||||||
TEST_CASE("containers/vector table roundtrip", "make sure vectors can be round-tripped") {
|
TEST_CASE("containers/vector table roundtrip", "make sure vectors can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::vector<int> v{ 1, 2, 3 };
|
std::vector<int> v { 1, 2, 3 };
|
||||||
lua.set_function("f", as_table_callable<std::vector<int>>(v));
|
lua.set_function("f", as_table_callable<std::vector<int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -64,7 +64,7 @@ TEST_CASE("containers/vector table roundtrip", "make sure vectors can be round-t
|
||||||
|
|
||||||
TEST_CASE("containers/deque table roundtrip", "make sure deques can be round-tripped") {
|
TEST_CASE("containers/deque table roundtrip", "make sure deques can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::deque<int> v{ 1, 2, 3 };
|
std::deque<int> v { 1, 2, 3 };
|
||||||
lua.set_function("f", as_table_callable<std::deque<int>>(v));
|
lua.set_function("f", as_table_callable<std::deque<int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -75,7 +75,7 @@ TEST_CASE("containers/deque table roundtrip", "make sure deques can be round-tri
|
||||||
|
|
||||||
TEST_CASE("containers/array table roundtrip", "make sure arrays can be round-tripped") {
|
TEST_CASE("containers/array table roundtrip", "make sure arrays can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::array<int, 3> v{ { 1, 2, 3 } };
|
std::array<int, 3> v { { 1, 2, 3 } };
|
||||||
lua.set_function("f", as_table_callable<std::array<int, 3>>(v));
|
lua.set_function("f", as_table_callable<std::array<int, 3>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -86,7 +86,7 @@ TEST_CASE("containers/array table roundtrip", "make sure arrays can be round-tri
|
||||||
|
|
||||||
TEST_CASE("containers/list table roundtrip", "make sure lists can be round-tripped") {
|
TEST_CASE("containers/list table roundtrip", "make sure lists can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::list<int> v{ 1, 2, 3 };
|
std::list<int> v { 1, 2, 3 };
|
||||||
lua.set_function("f", as_table_callable<std::list<int>>(v));
|
lua.set_function("f", as_table_callable<std::list<int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -97,7 +97,7 @@ TEST_CASE("containers/list table roundtrip", "make sure lists can be round-tripp
|
||||||
|
|
||||||
TEST_CASE("containers/forward_list table roundtrip", "make sure forward_lists can be round-tripped") {
|
TEST_CASE("containers/forward_list table roundtrip", "make sure forward_lists can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::forward_list<int> v{ 1, 2, 3 };
|
std::forward_list<int> v { 1, 2, 3 };
|
||||||
lua.set_function("f", as_table_callable<std::forward_list<int>>(v));
|
lua.set_function("f", as_table_callable<std::forward_list<int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -108,7 +108,7 @@ TEST_CASE("containers/forward_list table roundtrip", "make sure forward_lists ca
|
||||||
|
|
||||||
TEST_CASE("containers/map table roundtrip", "make sure maps can be round-tripped") {
|
TEST_CASE("containers/map table roundtrip", "make sure maps can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::map<std::string, int> v{ { "a", 1 }, { "b", 2 }, { "c", 3 } };
|
std::map<std::string, int> v { { "a", 1 }, { "b", 2 }, { "c", 3 } };
|
||||||
lua.set_function("f", as_table_callable<std::map<std::string, int>>(v));
|
lua.set_function("f", as_table_callable<std::map<std::string, int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -119,7 +119,7 @@ TEST_CASE("containers/map table roundtrip", "make sure maps can be round-tripped
|
||||||
|
|
||||||
TEST_CASE("containers/unordered_map table roundtrip", "make sure unordered_maps can be round-tripped") {
|
TEST_CASE("containers/unordered_map table roundtrip", "make sure unordered_maps can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::unordered_map<std::string, int> v{ { "a", 1 }, { "b", 2 }, { "c", 3 } };
|
std::unordered_map<std::string, int> v { { "a", 1 }, { "b", 2 }, { "c", 3 } };
|
||||||
lua.set_function("f", as_table_callable<std::unordered_map<std::string, int>>(v));
|
lua.set_function("f", as_table_callable<std::unordered_map<std::string, int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -130,7 +130,7 @@ TEST_CASE("containers/unordered_map table roundtrip", "make sure unordered_maps
|
||||||
|
|
||||||
TEST_CASE("containers/unordered_set table roundtrip", "make sure unordered_sets can be round-tripped") {
|
TEST_CASE("containers/unordered_set table roundtrip", "make sure unordered_sets can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::unordered_set<int> v{ 1, 2, 3 };
|
std::unordered_set<int> v { 1, 2, 3 };
|
||||||
lua.set_function("f", as_table_callable<std::unordered_set<int>>(v));
|
lua.set_function("f", as_table_callable<std::unordered_set<int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -141,7 +141,7 @@ TEST_CASE("containers/unordered_set table roundtrip", "make sure unordered_sets
|
||||||
|
|
||||||
TEST_CASE("containers/set table roundtrip", "make sure sets can be round-tripped") {
|
TEST_CASE("containers/set table roundtrip", "make sure sets can be round-tripped") {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
std::set<int> v{ 1, 2, 3 };
|
std::set<int> v { 1, 2, 3 };
|
||||||
lua.set_function("f", as_table_callable<std::set<int>>(v));
|
lua.set_function("f", as_table_callable<std::set<int>>(v));
|
||||||
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("x = f()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -230,9 +230,9 @@ TEST_CASE("containers/table conversion", "test table conversions with as_table a
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.open_libraries(sol::lib::base);
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
lua.set_function("bark", []() { return sol::as_nested(std::vector<std::string>{ "bark", "woof" }); });
|
lua.set_function("bark", []() { return sol::as_nested(std::vector<std::string> { "bark", "woof" }); });
|
||||||
|
|
||||||
lua.set_function("woof", []() { return sol::as_nested(std::vector<std::string>{ "bark", "woof" }); });
|
lua.set_function("woof", []() { return sol::as_nested(std::vector<std::string> { "bark", "woof" }); });
|
||||||
|
|
||||||
auto result1 = lua.safe_script("v1 = bark()", sol::script_pass_on_error);
|
auto result1 = lua.safe_script("v1 = bark()", sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
|
@ -242,13 +242,13 @@ TEST_CASE("containers/table conversion", "test table conversions with as_table a
|
||||||
sol::as_table_t<std::vector<std::string>> as_table_strings = lua["v1"];
|
sol::as_table_t<std::vector<std::string>> as_table_strings = lua["v1"];
|
||||||
sol::nested<std::vector<std::string>> nested_strings = lua["v2"];
|
sol::nested<std::vector<std::string>> nested_strings = lua["v2"];
|
||||||
|
|
||||||
std::vector<std::string> expected_values{ "bark", "woof" };
|
std::vector<std::string> expected_values { "bark", "woof" };
|
||||||
REQUIRE(as_table_strings.value() == expected_values);
|
REQUIRE(as_table_strings.value() == expected_values);
|
||||||
REQUIRE(nested_strings.value() == expected_values);
|
REQUIRE(nested_strings.value() == expected_values);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("containers/from table argument conversions", "test table conversions without as_table and nested for function args") {
|
TEST_CASE("containers/from table argument conversions", "test table conversions without as_table and nested for function args") {
|
||||||
const std::vector<std::string> expected_values{ "bark", "woof" };
|
const std::vector<std::string> expected_values { "bark", "woof" };
|
||||||
|
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.open_libraries(sol::lib::base);
|
lua.open_libraries(sol::lib::base);
|
||||||
|
@ -276,7 +276,7 @@ TEST_CASE("containers/deeply nested", "make sure nested works for deeply-nested
|
||||||
info_vector list;
|
info_vector list;
|
||||||
|
|
||||||
ModList() {
|
ModList() {
|
||||||
list.push_back(info_t{ { "a", "b" } });
|
list.push_back(info_t { { "a", "b" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::nested<info_vector&> getList() {
|
sol::nested<info_vector&> getList() {
|
||||||
|
@ -300,3 +300,18 @@ assert(type(modlist[1]) == "table")
|
||||||
auto result1 = lua.safe_script(code, sol::script_pass_on_error);
|
auto result1 = lua.safe_script(code, sol::script_pass_on_error);
|
||||||
REQUIRE(result1.valid());
|
REQUIRE(result1.valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("containers/nested with optional", "optionals should not change the behavior of getting or setting types such as nested") {
|
||||||
|
const std::vector<int> color = { 1, 2, 3, 0 };
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
sol::optional<sol::nested<std::vector<int>>> maybe_color_no = lua["color"];
|
||||||
|
|
||||||
|
lua["color"] = color;
|
||||||
|
sol::optional<sol::nested<std::vector<int>>> maybe_color_yes = lua["color"];
|
||||||
|
|
||||||
|
REQUIRE_FALSE(maybe_color_no.has_value());
|
||||||
|
REQUIRE(maybe_color_yes.has_value());
|
||||||
|
std::vector<int>& color_yes = maybe_color_yes.value().value();
|
||||||
|
REQUIRE(color == color_yes);
|
||||||
|
}
|
||||||
|
|
|
@ -45,7 +45,20 @@ TEST_CASE("plain/alignment", "test that aligned classes in certain compilers don
|
||||||
A& la = lua["a"];
|
A& la = lua["a"];
|
||||||
REQUIRE(&a == &la);
|
REQUIRE(&a == &la);
|
||||||
#else
|
#else
|
||||||
REQUIRE(true);
|
alignof(16) struct aligned_class { alignof(16) int var; };
|
||||||
|
|
||||||
|
struct A {
|
||||||
|
aligned_class a;
|
||||||
|
};
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base, sol::lib::math);
|
||||||
|
|
||||||
|
lua.new_usertype<A>("A");
|
||||||
|
A a;
|
||||||
|
lua["a"] = &a;
|
||||||
|
A& la = lua["a"];
|
||||||
|
REQUIRE(&a == &la);
|
||||||
#endif // VC++ stuff
|
#endif // VC++ stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user