diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..f94d40a1 --- /dev/null +++ b/CONTRIBUTING.md @@ -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`. + +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. diff --git a/README.md b/README.md index 7d4e2709..edca8132 100644 --- a/README.md +++ b/README.md @@ -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 `. +## 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. diff --git a/sol/function.hpp b/sol/function.hpp index e9833901..bf260ac0 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -63,7 +63,7 @@ public: template void operator()(Args&&... args) { - call<>(std::forward(args)...); + call<>(std::forward(args)...); } template diff --git a/sol/object.hpp b/sol/object.hpp index db374fd2..1c6f53d1 100644 --- a/sol/object.hpp +++ b/sol/object.hpp @@ -32,20 +32,36 @@ public: object() = default; template - T as() { + T as() const { push(); type_assert(state(), -1, type_of()); return stack::get(state()); } template - bool is() { + bool is() const { push(); auto expected = type_of(); auto actual = lua_type(state(), -1); return (static_cast(expected) == actual) || (expected == type::poly); } }; + +bool operator==(const object& lhs, const nil_t&) { + return lhs.is(); +} + +bool operator==(const nil_t&, const object& rhs) { + return rhs.is(); +} + +bool operator!=(const object& lhs, const nil_t&) { + return !lhs.is(); +} + +bool operator!=(const nil_t&, const object& rhs) { + return !rhs.is(); +} } // sol #endif // SOL_OBJECT_HPP \ No newline at end of file diff --git a/sol/traits.hpp b/sol/traits.hpp index b782973e..fdc70d93 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -89,58 +89,58 @@ struct function_traits; template struct function_traits { - static const std::size_t arity = sizeof...(Args); - static const bool is_member_function = true; - typedef std::tuple arg_tuple_type; - typedef types args_type; - typedef R(T::* function_pointer_type)(Args...); - typedef typename std::remove_pointer::type function_type; - typedef R(*free_function_pointer_type)(Args...); - typedef R return_type; - template - using arg = typename std::tuple_element::type; + static const std::size_t arity = sizeof...(Args); + static const bool is_member_function = true; + typedef std::tuple arg_tuple_type; + typedef types args_type; + typedef R(T::* function_pointer_type)(Args...); + typedef typename std::remove_pointer::type function_type; + typedef R(*free_function_pointer_type)(Args...); + typedef R return_type; + template + using arg = typename std::tuple_element::type; }; template struct function_traits { - static const std::size_t arity = sizeof...(Args); - static const bool is_member_function = true; - typedef std::tuple arg_tuple_type; - typedef types args_type; - typedef R(T::* function_pointer_type)(Args...); - typedef typename std::remove_pointer::type function_type; - typedef R(*free_function_pointer_type)(Args...); - typedef R return_type; - template - using arg = typename std::tuple_element::type; + static const std::size_t arity = sizeof...(Args); + static const bool is_member_function = true; + typedef std::tuple arg_tuple_type; + typedef types args_type; + typedef R(T::* function_pointer_type)(Args...); + typedef typename std::remove_pointer::type function_type; + typedef R(*free_function_pointer_type)(Args...); + typedef R return_type; + template + using arg = typename std::tuple_element::type; }; template struct function_traits { - static const std::size_t arity = sizeof...(Args); - static const bool is_member_function = false; - typedef std::tuple arg_tuple_type; - typedef types 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 - using arg = typename std::tuple_element::type; + static const std::size_t arity = sizeof...(Args); + static const bool is_member_function = false; + typedef std::tuple arg_tuple_type; + typedef types 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 + using arg = typename std::tuple_element::type; }; template struct function_traits { - static const std::size_t arity = sizeof...(Args); - static const bool is_member_function = false; - typedef std::tuple arg_tuple_type; - typedef types 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 - using arg = typename std::tuple_element::type; + static const std::size_t arity = sizeof...(Args); + static const bool is_member_function = false; + typedef std::tuple arg_tuple_type; + typedef types 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 + using arg = typename std::tuple_element::type; }; } // sol