<commit_before>// Copyright (c) 2003 <NAME> and <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.

#if !BOOST_PP_IS_ITERATING

#ifndef LUABIND_OBJECT_HPP_INCLUDED
#define LUABIND_OBJECT_HPP_INCLUDED

#include <iterator>

#include <luabind/config.hpp>
#include <luabind/detail/error.hpp>

#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum.hpp> 
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/tuple/tuple.hpp>

namespace luabind
{
	// object might need to be able to store values temporarily
	// without knowing about a lua_State.
	//
	// globals["f"] = function(&f);
	//
	// Creates the need for this, since function() doesn't know
	// about the state and thus can't return a fully initialized
	// object.
	//
	// Current solution is to allow for objects to store a pointer
	// to a commiter-object. This object has a virtual method which
	// converts it's value to the lua_State.
	//
	// This has some serious issues. For example, how would
	// two 'pseude-initialized' objects be able to compare?
	//
	// Perhaps attempting to perform operations on non-intialised
	// objects could throw?
	// 
	// Perhaps we could perform some not-so-smart comparisions? like:
	//
	//	template<class T>
	// struct commiter : base_commiter
	// {
	//		commiter(const T& v): val(v), base_commiter(typeid(T)) {}
	//
	//		virtual bool compare(void* rhs)
	//		{
	//			T* other = static_cast<T*>(rhs);
	//			return val == *other;
	//		}
	//
	//		T val;
	// };
	//
	// This would at least allow for the most intuitive use.. like:
	//
	// object a = 5;
	// object b = 5;
	//
	// return a == b;
	//
	// However, comparing an initialized object with a non-initialized
	// would always return false. Is this ok? Better to disallow it?

	// the current implementation does not have commiters, all objects
	// knows about the lua_State* or is uninitialized.

	class object;

	namespace detail
	{
		class proxy_object;
		class proxy_raw_object;
		class proxy_array_object;

		template<class T>
		void convert_to_lua(lua_State*, const T&);

		template<int Index, class T, class Policies>
		void convert_to_lua_p(lua_State*, const T&, const Policies&);

		template<int Index>
		struct push_args_from_tuple
		{
			template<class H, class T, class Policies>
			inline static void apply(lua_State* L, const boost::tuples::cons<H, T>& x, const Policies& p) 
			{
				convert_to_lua_p<Index>(L, *x.get_head(), p);
				push_args_from_tuple<Index+1>::apply(L, x.get_tail(), p);
			}

			template<class H, class T>
			inline static void apply(lua_State* L, const boost::tuples::cons<H, T>& x) 
			{
				convert_to_lua(L, *x.get_head());
				push_args_from_tuple<Index+1>::apply(L, x.get_tail());
			}

			template<class Policies>
			inline static void apply(lua_State*, const boost::tuples::null_type&, const Policies&) {};

			inline static void apply(lua_State*, const boost::tuples::null_type&) {};

		};

		template<class Tuple>
		class proxy_caller
		{
		friend class luabind::object;
		public:

			proxy_caller(luabind::object* o, const Tuple args)
				: m_obj(o)
				, m_args(args)
				, m_called(false)
			{
			}

			proxy_caller(const detail::proxy_caller<Tuple>& rhs)
				: m_obj(rhs.m_obj)
				, m_args(rhs.m_args)
				, m_called(rhs.m_called)
			{
				rhs.m_called = true;
			}

			~proxy_caller();
			operator luabind::object();

			template<class Policies>
			luabind::object operator[](const Policies& p)
			{
				m_called = true;
				lua_State* L = m_obj->lua_state();
				m_obj->pushvalue();
				detail::push_args_from_tuple<1>::apply(L, m_args, p);
				if (lua_pcall(L, boost::tuples::length<Tuple>::value, 1, 0))
				{ 
#ifndef LUABIND_NO_EXCEPTIONS
					throw error();
#else
					assert(0);
#endif
				}
				int ref = detail::ref(L);
				return luabind::object(m_obj->lua_state(), ref, true/*luabind::object::reference()*/);
			}

		private:

			luabind::object* m_obj;
			Tuple m_args;
			mutable bool m_called;

		};




		struct stack_pop
		{
			stack_pop(lua_State* L, int n)
				: m_state(L)
				, m_n(n)
				{
				}

			~stack_pop() 
			{
				lua_pop(m_state, m_n);
			}

		private:

			lua_State* m_state;
			int m_n;
		};



<commit_msg>fixed namespace error in at/raw_at<commit_after>// Copyright (c) 2003 <NAME> and <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.

#if !BOOST_PP_IS_ITERATING

#ifndef LUABIND_OBJECT_HPP_INCLUDED
#define LUABIND_OBJECT_HPP_INCLUDED

#include <iterator>

#include <luabind/config.hpp>
#include <luabind/detail/error.hpp>

#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum.hpp> 
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/tuple/tuple.hpp>

namespace luabind
{
	// object might need to be able to store values temporarily
	// without knowing about a lua_State.
	//
	// globals["f"] = function(&f);
	//
	// Creates the need for this, since function() doesn't know
	// about the state and thus can't return a fully initialized
	// object.
	//
	// Current solution is to allow for objects to store a pointer
	// to a commiter-object. This object has a virtual method which
	// converts it's value to the lua_State.
	//
	// This has some serious issues. For example, how would
	// two 'pseude-initialized' objects be able to compare?
	//
	// Perhaps attempting to perform operations on non-intialised
	// objects could throw?
	// 
	// Perhaps we could perform some not-so-smart comparisions? like:
	//
	//	template<class T>
	// struct commiter : base_commiter
	// {
	//		commiter(const T& v): val(v), base_commiter(typeid(T)) {}
	//
	//		virtual bool compare(void* rhs)
	//		{
	//			T* other = static_cast<T*>(rhs);
	//			return val == *other;
	//		}
	//
	//		T val;
	// };
	//
	// This would at least allow for the most intuitive use.. like:
	//
	// object a = 5;
	// object b = 5;
	//
	// return a == b;
	//
	// However, comparing an initialized object with a non-initialized
	// would always return false. Is this ok? Better to disallow it?

	// the current implementation does not have commiters, all objects
	// knows about the lua_State* or is uninitialized.

	class object;

	namespace detail
	{
		class proxy_object;
		class proxy_raw_object;
		class proxy_array_object;

		template<class T>
		void convert_to_lua(lua_State*, const T&);

		template<int Index, class T, class Policies>
		void convert_to_lua_p(lua_State*, const T&, const Policies&);

		template<int Index>
		struct push_args_from_tuple
		{
			template<class H, class T, class Policies>
			inline static void apply(lua_State* L, const boost::tuples::cons<H, T>& x, const Policies& p) 
			{
				convert_to_lua_p<Index>(L, *x.get_head(), p);
				push_args_from_tuple<Index+1>::apply(L, x.get_tail(), p);
			}

			template<class H, class T>
			inline static void apply(lua_State* L, const boost::tuples::cons<H, T>& x) 
			{
				convert_to_lua(L, *x.get_head());
				push_args_from_tuple<Index+1>::apply(L, x.get_tail());
			}

			template<class Policies>
			inline static void apply(lua_State*, const boost::tuples::null_type&, const Policies&) {};

			inline static void apply(lua_State*, const boost::tuples::null_type&) {};

		};

		template<class Tuple>
		class proxy_caller
		{
		friend class luabind::object;
		public:

			proxy_caller(luabind::object* o, const Tuple args)
				: m_obj(o)
				, m_args(args)
				, m_called(false)
			{
			}

			proxy_caller(const detail::proxy_caller<Tuple>& rhs)
				: m_obj(rhs.m_obj)
				, m_args(rhs.m_args)
				, m_called(rhs.m_called)
			{
				rhs.m_called = true;
			}

			~proxy_caller();
			operator luabind::object();

			template<class Policies>
			luabind::object operator[](const Policies& p)
			{
				m_called = true;
				lua_State* L = m_obj->lua_state();
				m_obj->pushvalue();
				detail::push_args_from_tuple<1>::apply(L, m_args, p);
				if (lua_pcall(L, boost::tuples::length<Tuple>::value, 1, 0))
				{ 
#ifndef LUABIND_NO_EXCEPTIONS
					throw error();
#else
					assert(0);
#endif
				}
				int ref = detail::ref(L);
				return luabind::object(m_obj->lua_state(), ref, true/*luabind::object::reference()*/);
			}

		private:

			luabind::object* m_obj;
			Tuple m_args;
			mutable bool m_called;

		};



		struct stack_pop
		{
			stack_pop(lua_State* L, int n)
				: m_state(L)
				, m_n(n)
				{
				}

			~stack_pop() 
			{
				lua_pop(m_state, m_n);
			}

		private:

			lua_State* m_state;
			int m_n;
		};




{'fraction_non_alphanumeric': 0.11945743685687558, 'fraction_numerical': 0.002245088868101029, 'mean_word_length': 3.4638830897703548, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 67, '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': '4395822', 'n_tokens_mistral': 4000, 'n_tokens_neox': 3533, 'n_words': 1092}