<commit_before>#include "Selection.hpp"

namespace lpp
{
	Selection::Selection(lua_State* s, const std::string& n)
	:	state(s),
		name(n),
		index(0)
		
	{}
	
	Selection::Selection(lua_State* s, const std::string& n, int idx)
	:	state(s),
		name(n),
		index(idx)
	{}

	Selection::~Selection()
	{}
	
	/* Selection operators */
	Selection Selection::operator [](const std::string& n) const
	{
		lua_getglobal(state, name.c_str());
		std::string newName = name + '.' + n;
		
		if(!lua_istable(state, -1))
			luaL_error(state, "Value on top of stack is not a table");
		
		lua_pushlstring(state, n.c_str(), n.size());
		lua_rawget(state, -2);
		
		return Selection(state, newName, -1);
	}
	
	Selection Selection::operator [](const int i) const
	{
		lua_getglobal(state, name.c_str());<commit_msg>Selections now clear the stack on destruction, just to be safe.<commit_after>#include "Selection.hpp"

namespace lpp
{
	Selection::Selection(lua_State* s, const std::string& n)
	:	state(s),
		name(n),
		index(0)
	{}
	
	Selection::Selection(lua_State* s, const std::string& n, int idx)
	:	state(s),
		name(n),
		index(idx)
	{}

	Selection::~Selection()
	{
		lua_settop(state, 0);
	}
	
	/* Selection operators */
	Selection Selection::operator [](const std::string& n) const
	{
		if(index == 0)
			lua_getglobal(state, name.c_str());
		
		std::string newName = name + '.' + n;
		
		if(!lua_istable(state, -1))
			luaL_error(state, "Value on top of stack is not a table");
		
		lua_pushlstring(state, n.c_str(), n.size());
		lua_rawget(state, -2);
		
		return Selection(state, newName, -1);
	}
	
	Selection Selection::operator [](const int i) const
	{
		if(index == 0)
			lua_getglobal(state, name.c_str());
			
{'fraction_non_alphanumeric': 0.16823529411764707, 'fraction_numerical': 0.006470588235294118, 'mean_word_length': 4.092814371257485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4199435', 'n_tokens_mistral': 692, 'n_tokens_neox': 618, 'n_words': 147}