<commit_before>#pragma once

#include "detail_method.h"

// const getter, setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx,
	ValT(Cls::*getter)() const,
	void(Cls::*setter)(ValT),
	const char* name)
{
	dukglue_register_property<true, Cls, ValT>(ctx, getter, setter, name);
}

// const getter, no setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx,
	ValT(Cls::*getter)() const,
	std::nullptr_t setter,
	const char* name)
{
	dukglue_register_property<true, Cls, ValT>(ctx, getter, setter, name);
}

// non-const getter, setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx,
	ValT(Cls::*getter)(),
	void(Cls::*setter)(ValT),
	const char* name)
{
	dukglue_register_property<false, Cls, ValT>(ctx, getter, setter, name);
}

// non-const getter, no setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx,
	ValT(Cls::*getter)(),
	std::nullptr_t setter,
	const char* name)
{
	dukglue_register_property<false, Cls, ValT>(ctx, getter, setter, name);
}

// no getter, setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx,
	std::nullptr_t getter,
	void(Cls::*setter)(ValT),
	const char* name)
{
	dukglue_register_property<false, Cls, ValT>(ctx, getter, setter, name);
}


// no getter, no setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx, std::nullptr_t getter, std::nullptr_t setter, const char* name)
{
	// strictly speaking I think duktape can probably handle neither
	// (according to the wonderful API docs), but I don't know why you
	// would want to do this in the first place
	static_assert(std::is_void<Cls>::value, "Must have getter or setter");
}

inline duk_ret_t dukglue_throw_error(duk_context* ctx)
{
	duk_error(ctx, DUK_ERR_TYPE_ERROR, "Property does not have getter or setter.");
}

template <bool isConstGetter, typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx,
	typename std::conditional<isConstGetter, ValT(Cls::*)() const, ValT(Cls::*)()>::type getter,
	void(Cls::*setter)(ValT),
	const char* name)
{
	using namespace dukglue::detail;
	typedef MethodInfo<isConstGetter, Cls, ValT> GetterMethodInfo;
	typedef MethodInfo<false, Cls, void, ValT> SetterMethodInfo;
<commit_msg>Fixed dukglue_register_property breaking when return and set argument types didn't exactly match (e.g. void set(T) but const T& get()).<commit_after>#pragma once

#include "detail_method.h"

// const getter, setter
template <typename Cls, typename RetT, typename ArgT>
void dukglue_register_property(duk_context* ctx,
	RetT(Cls::*getter)() const,
	void(Cls::*setter)(ArgT),
	const char* name)
{
	dukglue_register_property<true, Cls, RetT, ArgT>(ctx, getter, setter, name);
}

// const getter, no setter
template <typename Cls, typename RetT>
void dukglue_register_property(duk_context* ctx,
	RetT(Cls::*getter)() const,
	std::nullptr_t setter,
	const char* name)
{
	dukglue_register_property<true, Cls, RetT, RetT>(ctx, getter, setter, name);
}

// non-const getter, setter
template <typename Cls, typename RetT, typename ArgT>
void dukglue_register_property(duk_context* ctx,
	RetT(Cls::*getter)(),
	void(Cls::*setter)(ArgT),
	const char* name)
{
	dukglue_register_property<false, Cls, RetT, ArgT>(ctx, getter, setter, name);
}

// non-const getter, no setter
template <typename Cls, typename RetT>
void dukglue_register_property(duk_context* ctx,
	RetT(Cls::*getter)(),
	std::nullptr_t setter,
	const char* name)
{
	dukglue_register_property<false, Cls, RetT, RetT>(ctx, getter, setter, name);
}

// no getter, setter
template <typename Cls, typename ArgT>
void dukglue_register_property(duk_context* ctx,
	std::nullptr_t getter,
	void(Cls::*setter)(ArgT),
	const char* name)
{
	dukglue_register_property<false, Cls, ArgT, ArgT>(ctx, getter, setter, name);
}

// no getter, no setter
template <typename Cls, typename ValT>
void dukglue_register_property(duk_context* ctx, std::nullptr_t getter, std::nullptr_t setter, const char* name)
{
	// strictly speaking I think duktape can probably handle neither
	// (according to the wonderful API docs), but I don't know why you
	// would want to do this in the first place
	static_assert(std::is_void<Cls>::value, "Must have getter or setter");
}

inline duk_ret_t dukglue_throw_error(duk_context* ctx)
{
	duk_error(ctx, DUK_ERR_TYPE_ERROR, "Property does not have getter or setter.");
}

template <bool isConstGetter, typename Cls, typename RetT, typename ArgT>
void dukglue_register_property(duk_context* ctx,
	typename std::conditional<isConstGetter, RetT(Cls::*)() const, RetT(Cls::*)()>::type getter,
	void(Cls::*setter)(ArgT),
	const char* name)
{
	using namespace dukglue::detail;
	typedef MethodInfo<isConstGetter, Cls, RetT> GetterMethodInfo;
	typedef MethodInfo<false, Cls, void, ArgT> SetterMethodInfo;

{'fraction_non_alphanumeric': 0.12530463038180342, 'fraction_numerical': 0.0, 'mean_word_length': 6.553680981595092, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '7230597', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1848, 'n_words': 475}