Reduce binary bloat from static_trampoline and check_metatable

This commit is contained in:
Brent Davis 2020-06-19 23:18:13 -05:00 committed by The Phantom Derpstorm
parent a21fef97e9
commit 428767b8cd
4 changed files with 32 additions and 16 deletions

View File

@ -38,9 +38,7 @@
namespace sol { namespace stack {
namespace stack_detail {
template <typename T, bool poptable = true>
inline bool check_metatable(lua_State* L, int index = -2) {
const auto& metakey = usertype_traits<T>::metatable();
inline bool impl_check_metatable(lua_State* L, int index, const std::string& metakey, bool poptable) {
luaL_getmetatable(L, &metakey[0]);
const type expectedmetatabletype = static_cast<type>(lua_type(L, -1));
if (expectedmetatabletype != type::lua_nil) {
@ -53,6 +51,11 @@ namespace sol { namespace stack {
return false;
}
template <typename T, bool poptable = true>
inline bool check_metatable(lua_State* L, int index = -2) {
return impl_check_metatable(L, index, usertype_traits<T>::metatable(), poptable);
}
template <type expected, int (*check_func)(lua_State*, int)>
struct basic_check {
template <typename Handler>

View File

@ -99,8 +99,8 @@ namespace sol {
return trampoline(L, f);
}
#else
template <lua_CFunction f>
int static_trampoline(lua_State* L) {
inline int impl_static_trampoline(lua_State* L, lua_CFunction f) {
#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT)
return f(L);
@ -119,7 +119,7 @@ namespace sol {
}
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
// LuaJIT cannot have the catchall when the safe propagation is on
// but LuaJIT will swallow all C++ errors
// but LuaJIT will swallow all C++ errors
// if we don't at least catch std::exception ones
catch (...) {
call_exception_handler(L, optional<const std::exception&>(nullopt), "caught (...) exception");
@ -129,6 +129,11 @@ namespace sol {
#endif // Safe exceptions
}
template <lua_CFunction f>
int static_trampoline(lua_State* L) {
return impl_static_trampoline(L, f);
}
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if 0
// impossible: g++/clang++ choke as they think this function is ambiguous:

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 2020-06-18 22:17:10.413702 UTC
// This header was generated with sol v3.2.1 (revision 162fdd74)
// Generated 2020-06-20 04:08:19.579717 UTC
// This header was generated with sol v3.2.1 (revision 5e40ef09)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

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 2020-06-18 22:17:10.286043 UTC
// This header was generated with sol v3.2.1 (revision 162fdd74)
// Generated 2020-06-20 04:08:19.416569 UTC
// This header was generated with sol v3.2.1 (revision 5e40ef09)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -7476,8 +7476,8 @@ namespace sol {
return trampoline(L, f);
}
#else
template <lua_CFunction f>
int static_trampoline(lua_State* L) {
inline int impl_static_trampoline(lua_State* L, lua_CFunction f) {
#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT)
return f(L);
@ -7496,7 +7496,7 @@ namespace sol {
}
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
// LuaJIT cannot have the catchall when the safe propagation is on
// but LuaJIT will swallow all C++ errors
// but LuaJIT will swallow all C++ errors
// if we don't at least catch std::exception ones
catch (...) {
call_exception_handler(L, optional<const std::exception&>(nullopt), "caught (...) exception");
@ -7506,6 +7506,11 @@ namespace sol {
#endif // Safe exceptions
}
template <lua_CFunction f>
int static_trampoline(lua_State* L) {
return impl_static_trampoline(L, f);
}
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if 0
// impossible: g++/clang++ choke as they think this function is ambiguous:
@ -10671,9 +10676,7 @@ namespace sol {
namespace sol { namespace stack {
namespace stack_detail {
template <typename T, bool poptable = true>
inline bool check_metatable(lua_State* L, int index = -2) {
const auto& metakey = usertype_traits<T>::metatable();
inline bool impl_check_metatable(lua_State* L, int index, const std::string& metakey, bool poptable) {
luaL_getmetatable(L, &metakey[0]);
const type expectedmetatabletype = static_cast<type>(lua_type(L, -1));
if (expectedmetatabletype != type::lua_nil) {
@ -10686,6 +10689,11 @@ namespace sol { namespace stack {
return false;
}
template <typename T, bool poptable = true>
inline bool check_metatable(lua_State* L, int index = -2) {
return impl_check_metatable(L, index, usertype_traits<T>::metatable(), poptable);
}
template <type expected, int (*check_func)(lua_State*, int)>
struct basic_check {
template <typename Handler>