mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Merge remote-tracking branch 'root/master'
This commit is contained in:
commit
b655c07258
58
CONTRIBUTING.md
Normal file
58
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,58 @@
|
|||
## Contributing to Sol
|
||||
|
||||
Looking to contribute to Sol? Well, first thing I want to mention is thank you!
|
||||
Second of all, this is probably where you should look :)
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
If you found a bug, please make sure to make an issue in the issue tracker.
|
||||
|
||||
The guidelines for reporting a bug are relatively simple and are as follows:
|
||||
|
||||
1. Produce a simple, short, compilable test case that reproduces your problem.
|
||||
2. Make a descriptive title that summarises the bug as a whole.
|
||||
3. Explain the bug in as much detail as you can in the body of the issue.
|
||||
|
||||
If you have all of those requirements set, then your issue reporting is golden.
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't
|
||||
manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is
|
||||
consistent to those found in the repository.
|
||||
|
||||
They are as follows (more will be added as they come up):
|
||||
|
||||
- No spaces between parentheses. e.g. `f(g())` not `f ( g ( ) )`.
|
||||
- No tabs allowed. Use 4 space indentation.
|
||||
- Bracing style is
|
||||
|
||||
```cpp
|
||||
if(my_bool) {
|
||||
|
||||
}
|
||||
else if(my_other_bool) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
- Variable names follow those in the C++ standard, basically snake_case.
|
||||
- Maximum column length is 125
|
||||
- Trailing return type will always be in the same line. Even if it goes off the column length. e.g.
|
||||
`auto f() -> decltype(/* my long expression */) {`
|
||||
- Since this is a header-only library, all free functions must be marked `inline`.
|
||||
- Use braces in optional contexts like `if`, `for`, `else`, `while`, etc. e.g.
|
||||
|
||||
```cpp
|
||||
if(x > 12) {
|
||||
return x * 2;
|
||||
}
|
||||
```
|
||||
|
||||
- Use `typename` instead of `class` for template parameters. e.g. `template<typename T>`.
|
||||
|
||||
If you don't meet all of these style guidelines, don't fret. I'll probably fix it. But please
|
||||
do make an effort to actually meet them. Otherwise I'm more likely to reject the pull request.
|
|
@ -11,6 +11,10 @@ Lua errors are thrown as exceptions instead. This allows you to handle the error
|
|||
It should be noted that the library itself depends on `lua.hpp` to be found by your compiler. It uses angle brackets, e.g.
|
||||
`#include <lua.hpp>`.
|
||||
|
||||
## Contributing
|
||||
|
||||
If you want to contribute, please check CONTRIBUTING.md for details. Thank you!
|
||||
|
||||
## Example
|
||||
|
||||
Here's an example on how to load a basic configuration struct with a Lua script.
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
template<typename... Args>
|
||||
void operator()(Args&&... args) {
|
||||
call<>(std::forward<Args>(args)...);
|
||||
call<>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Ret, typename... Args>
|
||||
|
|
|
@ -32,20 +32,36 @@ public:
|
|||
object() = default;
|
||||
|
||||
template<typename T>
|
||||
T as() {
|
||||
T as() const {
|
||||
push();
|
||||
type_assert(state(), -1, type_of<T>());
|
||||
return stack::get<T>(state());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool is() {
|
||||
bool is() const {
|
||||
push();
|
||||
auto expected = type_of<T>();
|
||||
auto actual = lua_type(state(), -1);
|
||||
return (static_cast<int>(expected) == actual) || (expected == type::poly);
|
||||
}
|
||||
};
|
||||
|
||||
bool operator==(const object& lhs, const nil_t&) {
|
||||
return lhs.is<nil_t>();
|
||||
}
|
||||
|
||||
bool operator==(const nil_t&, const object& rhs) {
|
||||
return rhs.is<nil_t>();
|
||||
}
|
||||
|
||||
bool operator!=(const object& lhs, const nil_t&) {
|
||||
return !lhs.is<nil_t>();
|
||||
}
|
||||
|
||||
bool operator!=(const nil_t&, const object& rhs) {
|
||||
return !rhs.is<nil_t>();
|
||||
}
|
||||
} // sol
|
||||
|
||||
#endif // SOL_OBJECT_HPP
|
|
@ -89,58 +89,58 @@ struct function_traits;
|
|||
|
||||
template<typename T, typename R, typename... Args>
|
||||
struct function_traits<R(T::*)(Args...)> {
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = true;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(T::* function_pointer_type)(Args...);
|
||||
typedef typename std::remove_pointer<function_pointer_type>::type function_type;
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = true;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(T::* function_pointer_type)(Args...);
|
||||
typedef typename std::remove_pointer<function_pointer_type>::type function_type;
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
};
|
||||
|
||||
template<typename T, typename R, typename... Args>
|
||||
struct function_traits<R(T::*)(Args...) const> {
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = true;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(T::* function_pointer_type)(Args...);
|
||||
typedef typename std::remove_pointer<function_pointer_type>::type function_type;
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = true;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(T::* function_pointer_type)(Args...);
|
||||
typedef typename std::remove_pointer<function_pointer_type>::type function_type;
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
};
|
||||
|
||||
template<typename R, typename... Args>
|
||||
struct function_traits<R(Args...)> {
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = false;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(function_type)(Args...);
|
||||
typedef R(*function_pointer_type)(Args...);
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = false;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(function_type)(Args...);
|
||||
typedef R(*function_pointer_type)(Args...);
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
};
|
||||
|
||||
template<typename R, typename... Args>
|
||||
struct function_traits<R(*)(Args...)> {
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = false;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(function_type)(Args...);
|
||||
typedef R(*function_pointer_type)(Args...);
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
static const std::size_t arity = sizeof...(Args);
|
||||
static const bool is_member_function = false;
|
||||
typedef std::tuple<Args...> arg_tuple_type;
|
||||
typedef types<Args...> args_type;
|
||||
typedef R(function_type)(Args...);
|
||||
typedef R(*function_pointer_type)(Args...);
|
||||
typedef R(*free_function_pointer_type)(Args...);
|
||||
typedef R return_type;
|
||||
template<std::size_t i>
|
||||
using arg = typename std::tuple_element<i, arg_tuple_type>::type;
|
||||
};
|
||||
} // sol
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user