mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
const qq
This commit is contained in:
parent
c03073e059
commit
f1965a4364
|
@ -63,13 +63,13 @@ namespace sol {
|
||||||
return stack::push(L, nil);
|
return stack::push(L, nil);
|
||||||
T** pref = static_cast<T**>(lua_newuserdata(L, sizeof(T*)));
|
T** pref = static_cast<T**>(lua_newuserdata(L, sizeof(T*)));
|
||||||
*pref = obj;
|
*pref = obj;
|
||||||
luaL_getmetatable(L, &k[0]);
|
luaL_newmetatable(L, &k[0]);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int push(lua_State* L, T* obj) {
|
static int push(lua_State* L, T* obj) {
|
||||||
return push_keyed(L, usertype_traits<T*>::metatable, obj);
|
return push_keyed(L, usertype_traits<meta::unqualified_t<T>*>::metatable, obj);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ namespace sol {
|
||||||
std::allocator<T> alloc;
|
std::allocator<T> alloc;
|
||||||
alloc.construct(data, std::forward<Args>(args)...);
|
alloc.construct(data, std::forward<Args>(args)...);
|
||||||
if (with_meta) {
|
if (with_meta) {
|
||||||
const auto name = &usertype_traits<T>::user_gc_metatable[0];
|
const auto name = &usertype_traits<meta::unqualified_t<T>>::user_gc_metatable[0];
|
||||||
lua_CFunction cdel = stack_detail::alloc_destroy<T>;
|
lua_CFunction cdel = stack_detail::alloc_destroy<T>;
|
||||||
// Make sure we have a plain GC set for this data
|
// Make sure we have a plain GC set for this data
|
||||||
if (luaL_newmetatable(L, name) != 0) {
|
if (luaL_newmetatable(L, name) != 0) {
|
||||||
|
|
|
@ -1139,3 +1139,37 @@ TEST_CASE("usertype/double-deleter-guards", "usertype metatables internally must
|
||||||
lua = sol::state();
|
lua = sol::state();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("usertype/const-correctness", "usertype metatable names should reasonably ignore const attributes") {
|
||||||
|
struct Vec {
|
||||||
|
int x, y, z;
|
||||||
|
};
|
||||||
|
|
||||||
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base);
|
||||||
|
lua.new_usertype<Vec>("Vec", "x", &Vec::x, "y", &Vec::y, "z", &Vec::z);
|
||||||
|
|
||||||
|
Vec vec;
|
||||||
|
vec.x = 1;
|
||||||
|
vec.y = 2;
|
||||||
|
vec.z = -3;
|
||||||
|
|
||||||
|
std::vector<Vec> foo;
|
||||||
|
foo.push_back(vec);
|
||||||
|
|
||||||
|
std::vector<Vec const *> bar;
|
||||||
|
bar.push_back(&vec);
|
||||||
|
|
||||||
|
lua.script(R"(
|
||||||
|
func = function(vecs)
|
||||||
|
for i, vec in ipairs(vecs) do
|
||||||
|
print(i, ":", vec.x, vec.y, vec.z)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)");
|
||||||
|
|
||||||
|
REQUIRE_NOTHROW({
|
||||||
|
lua["func"](foo);
|
||||||
|
lua["func"](bar);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user