<commit_before>#!/usr/bin/lua

lqt = lqt or {}
lqt.classes = lqt.classes or {}


local pointer_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a pointer to class
		push = function(n)
			return 'lqtL_passudata(L, '..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return 'static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local pointer_const_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a pointer to constant class instance
		push = function(n)
			return 'lqtL_passudata(L, '..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return 'static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local ref_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a reference to class
		push = function(n)
			return 'lqtL_pushudata(L, &'..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return '*static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local instance_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is the class itself
		push = function(n)
			return 'lqtL_copyudata(L, &'..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return '*static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local const_ref_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a pointer to class
		push = function(n)
			return 'lqtL_copyudata(L, &'..n..', "'..cn..'*")', 1, string.gsub(fn, ' const&$', '')
		end,
		get = function(n)
			return '*static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end

lqt.classes.insert = function(cname, types) --, cancopy)
	if types[cname]==nil then
		types[cname..'*'] = pointer_t(cname)
		types[cname..' const*'] =  pointer_const_t(cname)
		types[cname..'&'] = ref_t(cname)
		--if cancopy then
		types[cname] = instance_t(cname)
		types[cname..' const&'] = const_ref_t(cname)
		--end
		return true
	else
		return nil
	end
end


<commit_msg>treat pointer const references as pointers<commit_after>#!/usr/bin/lua

lqt = lqt or {}
lqt.classes = lqt.classes or {}


local pointer_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a pointer to class
		push = function(n)
			return 'lqtL_passudata(L, '..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return 'static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local pointer_const_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a pointer to constant class instance
		push = function(n)
			return 'lqtL_passudata(L, '..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return 'static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local ref_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a reference to class
		push = function(n)
			return 'lqtL_pushudata(L, &'..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return '*static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local instance_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is the class itself
		push = function(n)
			return 'lqtL_copyudata(L, &'..n..', "'..cn..'*")', 1
		end,
		get = function(n)
			return '*static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end
local const_ref_t = function(fn)
	local cn = string.gsub(fn, '::', '.')
	return {
		-- the argument is a pointer to class
		push = function(n)
			return 'lqtL_copyudata(L, &'..n..', "'..cn..'*")', 1, string.gsub(fn, ' const&$', '')
		end,
		get = function(n)
			return '*static_cast<'..fn..'*>'
			..'(lqtL_toudata(L, '..n..', "'..cn..'*"))', 1
		end,
		test = function(n)
			return 'lqtL_isudata(L, '..n..', "'..cn..'*")', 1
		end,
		onstack = cn..'*,',
	}
end

local const_ptr_ref_t = pointer_const_t

lqt.classes.insert = function(cname, types) --, cancopy)
	if types[cname]==nil then
		types[cname..'*'] = pointer_t(cname)
		types[cname..' const*'] =  pointer_const_t(cname)
		types[cname..'&'] = ref_t(cname)
		--if cancopy then
		types[cname] = instance_t(cname)
		types[cname..' const&'] = const_ref_t(cname)
		types[cname..'* const&'] = const_ptr_ref_t(cname)
		--end
		return true
	else
		return nil
	end
end



{'fraction_non_alphanumeric': 0.2616407982261641, 'fraction_numerical': 0.005543237250554324, 'mean_word_length': 2.79859649122807, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5686623', 'n_tokens_mistral': 2574, 'n_tokens_neox': 2410, 'n_words': 511}