update examples and fix error_result returns

This commit is contained in:
ThePhD 2017-12-07 09:04:19 -05:00
parent 7193115e24
commit a86e9ee62d
5 changed files with 111 additions and 102 deletions

View File

@ -40,5 +40,9 @@ int main(int, char*[]) {
std::cout << std::endl;
{
std::remove("a_lua_script.lua");
}
return 0;
}

View File

@ -3,6 +3,7 @@
#include <fstream>
#include <iostream>
#include <cstdio>
#include <cassert>
int main(int, char*[]) {
@ -40,5 +41,9 @@ int main(int, char*[]) {
std::cout << std::endl;
{
std::remove("a_lua_script.lua");
}
return 0;
}

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2017-12-07 13:23:41.409999 UTC
// This header was generated with sol v2.18.7 (revision e17c0a1)
// Generated 2017-12-07 14:04:12.736591 UTC
// This header was generated with sol v2.18.7 (revision 7193115)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -15258,7 +15258,7 @@ namespace sol {
return set_writable(is_writable(), L, self, it, std::move(value));
}
static void set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) {
static error_result set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) {
decltype(auto) key = okey.as<K>();
if (!is_writable::value) {
return error_result("cannot perform a 'set': '%s's iterator reference is not writable (non-copy-assignable or const)", detail::demangle<T>().data());

View File

@ -668,7 +668,7 @@ namespace sol {
return set_writable(is_writable(), L, self, it, std::move(value));
}
static void set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) {
static error_result set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) {
decltype(auto) key = okey.as<K>();
if (!is_writable::value) {
return error_result("cannot perform a 'set': '%s's iterator reference is not writable (non-copy-assignable or const)", detail::demangle<T>().data());

View File

@ -15,6 +15,104 @@
#include <set>
#include <unordered_set>
class int_shim {
public:
int_shim() = default;
int_shim(int x)
: x_(x) {
}
int val() const {
return x_;
}
private:
int x_ = -1;
};
class input_it {
public:
typedef std::input_iterator_tag iterator_category;
typedef int_shim value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* pointer;
typedef std::ptrdiff_t difference_type;
input_it() = default;
input_it(int n, int m)
: n_(n), m_(m), value_(n_) {
assert(n_ >= 0);
assert(m_ >= 0);
assert(n_ <= m_);
if (!n_ && !m_) {
n_ = -1;
m_ = -1;
value_ = -1;
}
}
const int_shim& operator*() const {
return value_;
}
const int_shim* operator->() const {
return &value_;
}
input_it& operator++() {
assert(n_ >= 0);
assert(m_ >= 0);
if (n_ == m_ - 1) {
n_ = m_ = -1;
}
else {
++n_;
}
value_ = n_;
return *this;
}
bool operator==(const input_it& i) const {
return n_ == i.n_ && m_ == i.m_;
}
bool operator!=(const input_it& i) const {
return !(*this == i);
}
private:
int n_ = -1;
int m_ = -1;
int_shim value_;
};
class not_really_a_container {
public:
using value_type = int_shim;
using iterator = input_it;
using const_iterator = input_it;
const_iterator begin() const {
return iterator(0, 100);
}
const_iterator end() const {
return iterator();
}
value_type gcc_warning_block() {
return int_shim();
}
std::size_t size() const {
return 100;
}
};
auto test_table_return_one() {
return sol::as_table(std::vector<int>{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
}
@ -821,104 +919,6 @@ TEST_CASE("containers/non_copyable", "make sure non-copyable types in containers
}
TEST_CASE("containers/input iterators", "test shitty input iterators that are all kinds of B L E H") {
class int_shim {
public:
int_shim() = default;
int_shim(int x)
: x_(x) {
}
int val() const {
return x_;
}
private:
int x_ = -1;
};
class input_it {
public:
typedef std::input_iterator_tag iterator_category;
typedef int_shim value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* pointer;
typedef std::ptrdiff_t difference_type;
input_it() = default;
input_it(int n, int m)
: n_(n), m_(m), value_(n_) {
assert(n_ >= 0);
assert(m_ >= 0);
assert(n_ <= m_);
if (!n_ && !m_) {
n_ = -1;
m_ = -1;
value_ = -1;
}
}
const int_shim& operator*() const {
return value_;
}
const int_shim* operator->() const {
return &value_;
}
input_it& operator++() {
assert(n_ >= 0);
assert(m_ >= 0);
if (n_ == m_ - 1) {
n_ = m_ = -1;
}
else {
++n_;
}
value_ = n_;
return *this;
}
bool operator==(const input_it& i) const {
return n_ == i.n_ && m_ == i.m_;
}
bool operator!=(const input_it& i) const {
return !(*this == i);
}
private:
int n_ = -1;
int m_ = -1;
int_shim value_;
};
class not_really_a_container {
public:
using value_type = int_shim;
using iterator = input_it;
using const_iterator = input_it;
const_iterator begin() const {
return iterator(0, 100);
}
const_iterator end() const {
return iterator();
}
value_type gcc_warning_block() {
return int_shim();
}
std::size_t size() const {
return 100;
}
};
sol::state lua;
lua.open_libraries(sol::lib::base, sol::lib::package);
lua.new_usertype<int_shim>("int_shim",