<commit_before>/*
** SelfPortrait API
** See Copyright Notice in lua_utils.h
*/
#include "lua_utils.h"
#include <stdexcept>
#include "str_conversion.h"
using namespace std;

namespace {
	void handleUserdata(lua_State* L, int index) {

		void* p = lua_touserdata(L, index);

		if (p != nullptr) {
			if (lua_getmetatable(L, index)) {
				lua_pushvalue(L, LUA_REGISTRYINDEX);

				/* table is in the stack at index 't' */
				bool found = false;
				lua_pushnil(L);
				while (lua_next(L, -2) != 0) {
					if (lua_istable(L, -1)) {
						if (lua_rawequal(L, -1, -4)) {
							printf("%d: lua_user_data, metatable: %s\n", index, lua_tostring(L, -2));
							lua_pop(L, 4); // pop the key-value pair, the registry and the metatable
							return;
						}
					}
					lua_pop(L, 1); // pop the value
				}
				lua_pop(L, 2); // pop the registry and the metatable
			}
		}

		printf("%d: lua_user_data\n", index);
	}
}

namespace LuaUtils {

	bool found = false;
	// modified version of luaL_checkudata
	bool isudata (lua_State *L, int ud, const char *tname) {
	  void *p = lua_touserdata(L, ud);
	  if (p != NULL) {  /* value is a userdata? */
		if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */
		  lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */
		  if (lua_rawequal(L, -1, -2)) {  /* does it have the correct mt? */
			found = true;
		  }
		  lua_pop(L, 2);  /* remove both metatables */
		}<commit_msg>Fix accidentally global variable<commit_after>/*
** SelfPortrait API
** See Copyright Notice in lua_utils.h
*/
#include "lua_utils.h"
#include <stdexcept>
#include "str_conversion.h"
using namespace std;

namespace {
	void handleUserdata(lua_State* L, int index) {

		void* p = lua_touserdata(L, index);

		if (p != nullptr) {
			if (lua_getmetatable(L, index)) {
				lua_pushvalue(L, LUA_REGISTRYINDEX);

				/* table is in the stack at index 't' */
				bool found = false;
				lua_pushnil(L);
				while (lua_next(L, -2) != 0) {
					if (lua_istable(L, -1)) {
						if (lua_rawequal(L, -1, -4)) {
							printf("%d: lua_user_data, metatable: %s\n", index, lua_tostring(L, -2));
							lua_pop(L, 4); // pop the key-value pair, the registry and the metatable
							return;
						}
					}
					lua_pop(L, 1); // pop the value
				}
				lua_pop(L, 2); // pop the registry and the metatable
			}
		}

		printf("%d: lua_user_data\n", index);
	}
}

namespace LuaUtils {

	// modified version of luaL_checkudata
	bool isudata (lua_State *L, int ud, const char *tname) {
      bool found = false;
	  void *p = lua_touserdata(L, ud);
	  if (p != NULL) {  /* value is a userdata? */
		if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */
		  lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */
		  if (lua_rawequal(L, -1, -2)) {  /* does it have the correct mt? */
			found = true;
		  }
		  lua_pop(L, 2);  /* remove both metatables */
		}
{'fraction_non_alphanumeric': 0.1481736733287388, 'fraction_numerical': 0.008270158511371467, 'mean_word_length': 2.8655126498002663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7425967', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1092, 'n_words': 309}