<commit_before>// GALua.cpp

#include <windows.h>
#include "GALua.h"
#include "Env.h"
#include "Def.h"
#include "String.h"
#include "BinaryOp.h"
#include "UnaryOp.h"

//=========================================================================================
BOOL APIENTRY DllMain( HANDLE module, DWORD reason, LPVOID reserved )
{
	switch( reason )
	{
		case DLL_PROCESS_ATTACH:
		{
			gaLuaEnv = new GALuaEnv();
			if( !gaLuaEnv )
				return FALSE;
			break;
		}
		case DLL_PROCESS_DETACH:
		{
			delete gaLuaEnv;
			gaLuaEnv = 0;
			break;
		}
		case DLL_THREAD_ATTACH:
		{
			break;
		}
		case DLL_THREAD_DETACH:
		{
			break;
		}
	}

	return TRUE;
}

//=========================================================================================
static luaL_Reg galua[] =
{
	{ "def_basis", l_def_basis },
	{ "def_sig", l_def_sig },
	{ "from_string", l_from_string },
	{ "to_string", l_to_string },
	{ "sum", l_sum },
	{ "gp", l_gp },
	{ "ip", l_ip },
	{ "op", l_op },
	{ "copy", l_copy },
	{ "negate", l_negate },
	{ "invert", l_invert },
	{ "reverse", l_reverse },
	{ "mag", l_mag },
	{ NULL, NULL },
};

//=========================================================================================
extern "C" {
GALUA_FUNC int luaopen_galua( lua_State* L )
{
	luaL_newlib( L, galua );

	// Using the API table in function syntax should be a nice way to create multi-vectors.
	lua_newtable( L );
	lua_pushcfunction( L, &l_from_string );
	lua_setfield( L, -2, "__call" );
	lua_setmetatable( L, -2 );

	return 1;
}
} //extern "C"

// GALua.cpp<commit_msg>Josh recommends getting rid of DllMain for portability<commit_after>// GALua.cpp

#include <windows.h>
#include "GALua.h"
#include "Env.h"
#include "Def.h"
#include "String.h"
#include "BinaryOp.h"
#include "UnaryOp.h"

//=========================================================================================
// By avoiding the use of DllMain, our Lua module has the potential to be portable to other platforms.
#if 0
BOOL APIENTRY DllMain( HANDLE module, DWORD reason, LPVOID reserved )
{
	return TRUE;
}
#endif

//=========================================================================================
static luaL_Reg galua_api[] =
{
	{ "def_basis", l_def_basis },
	{ "def_sig", l_def_sig },
	{ "from_string", l_from_string },
	{ "to_string", l_to_string },
	{ "sum", l_sum },
	{ "gp", l_gp },
	{ "ip", l_ip },
	{ "op", l_op },
	{ "copy", l_copy },
	{ "negate", l_negate },
	{ "invert", l_invert },
	{ "reverse", l_reverse },
	{ "mag", l_mag },
	{ NULL, NULL },
};

//=========================================================================================
static void ModuleInitialize( void )
{
	// Create our GA calculation environment.
	gaLuaEnv = new GALuaEnv();
}

//=========================================================================================
static void ModuleFinalize( void )
{
	delete gaLuaEnv;
	gaLuaEnv = 0;
}

//=========================================================================================
// Unfortunately, Lua doesn't call this itself.  We have to rig it into the system.
int luaclose_galua( lua_State* L )
{
	ModuleFinalize();

	return 0;
}

//=========================================================================================
// Lua will find this symbol and call it to open our library module.
extern "C" {
GALUA_FUNC int luaopen_galua( lua_State* L )
{
	ModuleInitialize();

	luaL_newlib( L, galua_api );

	// Using the API table in function syntax should be a nice way to create multi-vectors.
	lua_newtable( L );
	lua_pushcfunction( L, &luaclose_galua );
	lua_setfield( L, -2, "__gc" );
	lua_pushcfunction( L, &l_from_string );
	lua_setfield( L, -2, "__call" );
	lua_setmetatable( L, -2 );

	return 1;
}
} //extern "C"

// GALua.cpp
{'fraction_non_alphanumeric': 0.33600427350427353, 'fraction_numerical': 0.002938034188034188, 'mean_word_length': 4.770416024653313, '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': '1743077', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1231, 'n_words': 314}