freeze changes

This commit is contained in:
ThePhD 2018-11-20 11:59:36 -05:00
parent 9b47849110
commit 094ace3c7b
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
6 changed files with 65 additions and 62 deletions

View File

@ -41,7 +41,12 @@ namespace sol {
call_status stats = call_status::yielded;
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) {
#if SOL_LUA_VERSION >= 504
int nresults;
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount), &nresults));
#else
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount)));
#endif
}
template <std::size_t... I, typename... Ret>

View File

@ -502,10 +502,8 @@ namespace sol {
return &usertype_alloc_destruct<T>;
}
}
else {
return &cannot_destruct<T>;
}
}
struct no_comp {
template <typename A, typename B>

View File

@ -131,7 +131,9 @@ namespace sol {
int index = 0;
detail::indexed_insert insert_fx(l, index);
detail::insert_default_registrations<P>(insert_fx, detail::property_always_true);
if constexpr (!std::is_pointer_v<T>) {
l[index] = luaL_Reg{ to_string(meta_function::garbage_collect).c_str(), detail::make_destructor<P>() };
}
luaL_setfuncs(L, l, 0);
// __type table

View File

@ -453,16 +453,17 @@ namespace u_detail {
this->storage.push_back(std::move(p_binding));
std::string s = u_detail::make_string(std::forward<Key>(key));
bool is_index = is_var_bind::value || (s == to_string(meta_function::index));
bool is_new_index = is_var_bind::value || (s == to_string(meta_function::new_index));
bool is_index = (s == to_string(meta_function::index));
bool is_new_index = (s == to_string(meta_function::new_index));
bool no_use_named = s == to_string(meta_function::call);
bool poison_indexing = is_var_bind::value || is_index || is_new_index;
index_call_storage ics;
ics.binding_data = b.data();
ics.index = &b.index_call_with_<true, is_var_bind::value>;
ics.new_index = &b.index_call_with_<false, is_var_bind::value>;
ics.index = is_index ? &b.call_with_<true, is_var_bind::value> : &b.index_call_with_<true, is_var_bind::value>;
ics.new_index = is_new_index ? &b.call_with_<false, is_var_bind::value> : &b.index_call_with_<false, is_var_bind::value>;
// need to swap everything to use fast indexing here
auto fet = [&](lua_State* L, submetatable submetatable_type, reference& fast_index_table) {
if (submetatable_type == submetatable::named && (no_use_named || is_index || is_new_index)) {
if (submetatable_type == submetatable::named && (no_use_named || poison_indexing)) {
// do not override __call or
// other specific meta functions on named metatable:
// we need that for call construction
@ -477,7 +478,7 @@ namespace u_detail {
else {
stack::set_field<false, true>(L, s, make_closure(&b.call<false, is_var_bind::value>, nullptr, ics.binding_data), t.stack_index());
}
if (is_index || is_new_index) {
if (poison_indexing) {
change_indexing<T>(L, submetatable_type, t);
}
t.pop();
@ -781,7 +782,7 @@ namespace u_detail {
stack::set_field(L, detail::base_class_cast_key(), (void*)&detail::inheritance<T>::type_cast, t.stack_index());
}
auto prop_fx = properties_enrollment_allowed(storage.properties, enrollments);
auto prop_fx = detail::properties_enrollment_allowed(storage.properties, enrollments);
auto insert_fx = [&](meta_function mf, lua_CFunction reg) {
stack::set_field(L, mf, reg, t.stack_index());
storage.properties[static_cast<int>(mf)] = true;

View File

@ -372,15 +372,6 @@ TEST_CASE("operators/container-like", "test that generic begin/end and iterator
REQUIRE(i == 10);
}
}
SECTION("simple") {
lua.new_simple_usertype<container>("container");
{
lua.safe_script("obj = container.new()");
lua.safe_script("i = 0 for k, v in pairs(obj) do i = i + 1 assert(k == v) end");
std::size_t i = lua["i"];
REQUIRE(i == 10);
}
}
#else
SUCCEED("");
#endif

View File

@ -41,6 +41,25 @@ bool func_opt_ret_bool(sol::optional<int> i) {
return true;
}
struct base1 {
int a1 = 250;
};
struct base2 {
int a2 = 500;
};
struct simple : base1 {
};
struct complex : base1, base2 {
};
SOL_BASE_CLASSES(complex, base1, base2);
SOL_BASE_CLASSES(simple, base1);
SOL_DERIVED_CLASSES(base1, simple, complex);
SOL_DERIVED_CLASSES(base2, complex);
TEST_CASE("table/traversal", "ensure that we can chain requests and tunnel down into a value if we desire") {
sol::state lua;
@ -409,11 +428,12 @@ TEST_CASE("feature/indexing overrides", "make sure index functions can be overri
sol::usertype<DynamicObject> utdo = lua.new_usertype<DynamicObject>("DynamicObject");
utdo["props"] = sol::property(&DynamicObject::get_dynamic_props);
lua.safe_script(R"__(
auto result = lua.safe_script(R"__(
obj = DynamicObject:new()
obj.props.name = 'test name'
print('name = ' .. obj.props.name)
)__");
)__", sol::script_pass_on_error);
REQUIRE(result.valid());
std::string name = lua["obj"]["props"]["name"];
REQUIRE(name == "test name");
@ -459,20 +479,6 @@ TEST_CASE("features/indexing numbers", "make sure indexing functions can be over
}
TEST_CASE("features/multiple inheritance", "Ensure that multiple inheritance works as advertised") {
struct base1 {
int a1 = 250;
};
struct base2 {
int a2 = 500;
};
struct simple : base1 {
};
struct complex : base1, base2 {
};
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<base1>("base1",
@ -596,14 +602,14 @@ TEST_CASE("compilation/const regression", "make sure constness in tables is resp
struct State {
public:
State() {
this->state_.registry()["state"] = this;
this->state_.globals()["state"] = this;
}
sol::state state_;
};
State state;
State* s = state.state_.registry()["state"];
State* s = state.state_.globals()["state"];
REQUIRE(s == &state);
}