<commit_before>// The MIT License (MIT)

// Copyright (c) 2013 <NAME>., Rapptz

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#ifndef SOL_STACK_HPP
#define SOL_STACK_HPP

#include "error.hpp"
#include "reference.hpp"
#include "tuple.hpp"
#include "traits.hpp"
#include "userdata_traits.hpp"
#include <utility>
#include <array>
#include <cstring>
#include <functional>

namespace sol {
namespace detail {
template<typename T>
inline T* get_ptr(T& val) {
    return std::addressof(val);
}

template<typename T>
inline T* get_ptr(std::reference_wrapper<T> val) {
    return std::addressof(val.get());
}

template<typename T>
inline T* get_ptr(T* val) {
    return val;
}

template<typename Decorated>
struct return_forward {
    typedef Unqualified<Decorated> T;

    T& operator()(T& value) const {
        return value;
    }

    T&& operator()(T&& value) const {
        return std::move(value);
    }

    T operator()(const T& value) const {
        return value;
    }

    // handle retarded libraries
    T operator()(const T&& value) const {
        return value;
    }
};
} // detail

namespace stack {
namespace detail {
template<typename T, typename Key, typename... Args>
inline void push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
    T* pdatum = static_cast<T*>(lua_newuserdata(L, sizeof(T)));
    std::allocator<T> alloc{};
    alloc.construct(pdatum, std::forward<Args>(args)...);
    luaL_getmetatable(L, std::addressof(metatablekey[0]));
    lua_setmetatable(L, -2);
}
} // detail
template<typename T, typename X = void>
struct getter;
template<typename T, typename X = void>
struct pusher;

template<typename T, typename>
struct getter {
    template<typename U = T, EnableIf<std::is_floating_point<U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return lua_tonumber(L, index);
    }

    template<typename U = T, EnableIf<std::is_integral<U>, std::is_signed<U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return lua_tounsigned(L, index);
    }

    template<typename U = T, EnableIf<std::is_integral<U>, std::is_unsigned<U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return static_cast<T>(lua_tointeger(L, index));
    }

    template<typename U = T, EnableIf<std::is_base_of<reference, U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return T(L, index);
    }

    template<typename U = T, EnableIf<Not<std::is_base_of<reference, U>>, Not<std::is_integral<U>>, Not<std::is_floating_point<U>>> = 0>
    static U& get(lua_State* L, int index = -1) {
        void* udata = lua_touserdata(L, index);
        T* obj = static_cast<T*>(udata);
        return *obj;
    }
};

template<typename T>
struct getter<T*> {
    static T* get(lua_State* L, int index = -1) {
        void* udata = lua_touserdata(L, index);
        T** obj = static_cast<T**>(udata);
        return *obj;
    }
};

template<>
struct getter<type> {
    static type get(lua_State *L, int index){
        return static_cast<type>(lua_type(L, index));
    }
};

template<>
struct getter<bool> {
    static bool get(lua_State* L, int index) {
        return lua_toboolean(L, index) != 0;
    }
};

template<>
struct getter<std::string> {
    static std::string get(lua_State* L, int index = -1) {
        std::string::size_type len;
        auto str = lua_tolstring(L, index, &len);
        return{ str, len };
    }
};
<commit_msg>Fix implicit conversion warnings for getter.<commit_after>// The MIT License (MIT)

// Copyright (c) 2013 <NAME>

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#ifndef SOL_STACK_HPP
#define SOL_STACK_HPP

#include "error.hpp"
#include "reference.hpp"
#include "tuple.hpp"
#include "traits.hpp"
#include "userdata_traits.hpp"
#include <utility>
#include <array>
#include <cstring>
#include <functional>

namespace sol {
namespace detail {
template<typename T>
inline T* get_ptr(T& val) {
    return std::addressof(val);
}

template<typename T>
inline T* get_ptr(std::reference_wrapper<T> val) {
    return std::addressof(val.get());
}

template<typename T>
inline T* get_ptr(T* val) {
    return val;
}

template<typename Decorated>
struct return_forward {
    typedef Unqualified<Decorated> T;

    T& operator()(T& value) const {
        return value;
    }

    T&& operator()(T&& value) const {
        return std::move(value);
    }

    T operator()(const T& value) const {
        return value;
    }

    // handle retarded libraries
    T operator()(const T&& value) const {
        return value;
    }
};
} // detail

namespace stack {
namespace detail {
template<typename T, typename Key, typename... Args>
inline void push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) {
    T* pdatum = static_cast<T*>(lua_newuserdata(L, sizeof(T)));
    std::allocator<T> alloc{};
    alloc.construct(pdatum, std::forward<Args>(args)...);
    luaL_getmetatable(L, std::addressof(metatablekey[0]));
    lua_setmetatable(L, -2);
}
} // detail
template<typename T, typename X = void>
struct getter;
template<typename T, typename X = void>
struct pusher;

template<typename T, typename>
struct getter {
    template<typename U = T, EnableIf<std::is_floating_point<U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return static_cast<U>(lua_tonumber(L, index));
    }

    template<typename U = T, EnableIf<std::is_integral<U>, std::is_signed<U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return static_cast<U>(lua_tounsigned(L, index));
    }

    template<typename U = T, EnableIf<std::is_integral<U>, std::is_unsigned<U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return static_cast<T>(lua_tointeger(L, index));
    }

    template<typename U = T, EnableIf<std::is_base_of<reference, U>> = 0>
    static U get(lua_State* L, int index = -1) {
        return T(L, index);
    }

    template<typename U = T, EnableIf<Not<std::is_base_of<reference, U>>, Not<std::is_integral<U>>, Not<std::is_floating_point<U>>> = 0>
    static U& get(lua_State* L, int index = -1) {
        void* udata = lua_touserdata(L, index);
        T* obj = static_cast<T*>(udata);
        return *obj;
    }
};

template<typename T>
struct getter<T*> {
    static T* get(lua_State* L, int index = -1) {
        void* udata = lua_touserdata(L, index);
        T** obj = static_cast<T**>(udata);
        return *obj;
    }
};

template<>
struct getter<type> {
    static type get(lua_State *L, int index){
        return static_cast<type>(lua_type(L, index));
    }
};

template<>
struct getter<bool> {
    static bool get(lua_State* L, int index) {
        return lua_toboolean(L, index) != 0;
    }
};

template<>
struct getter<std::string> {
    static std::string get(lua_State* L, int index = -1) {
        std::string::size_type len;
        auto str = lua_tolstring(L, index, &len);
        return { str, len };
    }
};

{'fraction_non_alphanumeric': 0.12832603570225665, 'fraction_numerical': 0.004266307398675199, 'mean_word_length': 3.605997931747673, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4841471', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2826, 'n_words': 926}