Пример #1
0
int Init(lua_State* L)
{
	gLua = Lua();

	CreateInterfaceFn engineFactory	= Sys_GetFactory("engine.dll");

	engine = (IVEngineServer*)engineFactory(INTERFACEVERSION_VENGINESERVER, NULL);

	if(!engine)
	{
		gLua->Error("gmsv_teleport: Failed to load IVEngineServer\n");
	}

	Msg("gmsv_teleport: Loaded\n");

	ILuaObject *oEntity = gLua->GetGlobal("Entity");
	oEntity->Push();
	refEntity = gLua->GetReference(-1, true);
	oEntity->UnReference();

	ILuaObject *ohook = gLua->GetGlobal("hook");
		ILuaObject *oCall = ohook->GetMember("Call");
		oCall->Push();
		refHookCall = gLua->GetReference(-1, true);
		oCall->UnReference();
	ohook->UnReference();

	ILuaObject *oEntityMeta = gLua->GetMetaTable("Entity", GLua::TYPE_ENTITY);
		ILuaObject *oEntIndex = oEntityMeta->GetMember("EntIndex");
		oEntIndex->Push();
		refEntIndex = gLua->GetReference(-1, true);
		oEntIndex->UnReference();
	oEntityMeta->UnReference();

	ILuaObject *entityMeta = gLua->GetMetaTable("Entity", GLua::TYPE_ENTITY);
	if(entityMeta)
	{
		entityMeta->SetMember("SetupTeleportHook", SetupTeleportHook);
	}
    entityMeta->UnReference();

	return 0;
}
Пример #2
0
void CLuaInterface_Hooks::ErrorFromLua_H( const char *err, ... )
{
	ILuaInterface *luaInterface = (ILuaInterface *)this;

	// Construct error string
	char szBuf[512];
	va_list arg_ptr;
	va_start( arg_ptr, err );
	_vsntprintf( szBuf, sizeof(szBuf)-1, (char *)err, arg_ptr );
	va_end( arg_ptr );

	// Only call hook if the state has the module loaded
	if ( g_LuaInterfaces.Find( luaInterface ) == -1 )
	{
		(this->*ErrorFromLua_T)( szBuf );

		return;
	}

	// Call LuaError hook

	ILuaObject *hookTable = luaInterface->GetGlobal( "hook" );
	ILuaObject *hookCallFunction = hookTable->GetMember( "Call" );
	hookCallFunction->Push();

	luaInterface->Push( "LuaError" );
	luaInterface->PushNil();
	luaInterface->Push( szBuf );
	luaInterface->Call( 3, 1 );

	hookTable->UnReference();
	hookCallFunction->UnReference();

	// Check return value

	ILuaObject *returnValue = luaInterface->GetReturn( 0 );

	// Call original if nothing is returned
	if ( returnValue->isNil() )
		(this->*ErrorFromLua_T)( szBuf );

	returnValue->UnReference();
}
Пример #3
0
void LuaObjectBase::pushObject()
{
	if (!m_luaState)
		return;

#ifdef FULL_USER_DATA
	m_gcRefCount++;
	GarrysMod::Lua::UserData* ud = (GarrysMod::Lua::UserData*)MLUA->NewUserdata(sizeof(GarrysMod::Lua::UserData));
	ud->data = this;
	ud->type = m_classInfo.typeId();
	MLUA->ReferencePush( m_classInfo.m_metatable );
	MLUA->SetMetaTable(-2);
#else
	if (latestRef())
	{
		latestRef()->Push();
	}
	else
	{
		ILuaObject* metaTable = m_luaInterface->GetNewTable();
		metaTable->SetMember("__gc", LuaObjectBase::gcDeleteWrapper );
		metaTable->SetMember("__tostring", LuaObjectBase::toStringWrapper);

		ILuaObject* object = m_luaInterface->GetNewTable();
		object->SetMemberUserDataLite("_this", this);
		const std::vector<LuaBoundFunction*>& list = m_classInfo.functionList();
		for (std::vector<LuaBoundFunction*>::const_iterator it = list.begin(); 
				it != list.end(); 
				++it)
		{
			object->SetMember( (*it)->functionName(), (*it)->function() );
		}
		object->SetMetaTable(metaTable);

		object->Push();
    
		metaTable->UnReference();
		object->UnReference();
	}
#endif
}
Пример #4
0
int Init(lua_State* L)
{
	CreateInterfaceFn interfaceFactory = Sys_GetFactory("engine.dll");

	engine = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL);

	if(!engine)
	{
		Lua()->Error("gm_navigation: Missing IVEngineServer interface.\n");
	}

#ifdef LUA_SERVER
	enginetrace = (IEngineTrace*)interfaceFactory(INTERFACEVERSION_ENGINETRACE_SERVER, NULL);
#else
	enginetrace = (IEngineTrace*)interfaceFactory(INTERFACEVERSION_ENGINETRACE_CLIENT, NULL);
#endif
	
	if(!enginetrace)
	{
		Lua()->Error("gm_navigation: Missing IEngineTrace interface.\n");
	}

#ifndef USE_BOOST_THREADS
	threadPool = CreateThreadPool();

	ThreadPoolStartParams_t params;
	params.nThreads = 2;

	if(!threadPool->Start(params))
	{
		SafeRelease(threadPool);
		Lua()->Error("gm_navigation: Thread pool is null\n");
	}
#endif

	ILuaObject* navTable = Lua()->GetNewTable();
		navTable->SetMember("Create", nav_Create);
		navTable->SetMember("Poll", nav_Poll);

		navTable->SetMember("NORTH", (float)NORTH);
		navTable->SetMember("SOUTH", (float)SOUTH);
		navTable->SetMember("EAST", (float)EAST);
		navTable->SetMember("WEST", (float)WEST);

		navTable->SetMember("NORTHEAST", (float)NORTHEAST);
		navTable->SetMember("NORTHWEST", (float)NORTHWEST);
		navTable->SetMember("SOUTHEAST", (float)SOUTHEAST);
		navTable->SetMember("SOUTHWEST", (float)SOUTHWEST);

		navTable->SetMember("UP", (float)UP);
		navTable->SetMember("DOWN", (float)DOWN);
		navTable->SetMember("LEFT", (float)LEFT);
		navTable->SetMember("RIGHT", (float)RIGHT);
		navTable->SetMember("FORWARD", (float)FORWARD);
		navTable->SetMember("BACKWARD", (float)BACKWARD);

		navTable->SetMember("NUM_DIRECTIONS", (float)NUM_DIRECTIONS);
		navTable->SetMember("NUM_DIRECTIONS_DIAGONAL", (float)NUM_DIRECTIONS_DIAGONAL);
		navTable->SetMember("NUM_DIRECTIONS_MAX", (float)NUM_DIRECTIONS_MAX);

		navTable->SetMember("HEURISTIC_MANHATTAN", (float)Nav::HEURISTIC_MANHATTAN);
		navTable->SetMember("HEURISTIC_EUCLIDEAN", (float)Nav::HEURISTIC_EUCLIDEAN);
		navTable->SetMember("HEURISTIC_CUSTOM", (float)Nav::HEURISTIC_CUSTOM);

	Lua()->SetGlobal("nav", navTable);
	navTable->UnReference();

	ILuaObject *MetaNav = Lua()->GetMetaTable(NAV_NAME, NAV_TYPE);
		ILuaObject *NavIndex = Lua()->GetNewTable();
			NavIndex->SetMember("GetNodeByID", Nav_GetNodeByID);
			NavIndex->SetMember("GetNodes", Nav_GetNodes);
			NavIndex->SetMember("GetNearestNodes", Nav_GetNearestNodes);

			NavIndex->SetMember("GetNodeTotal", Nav_GetNodeTotal);

			NavIndex->SetMember("AddWalkableSeed", Nav_AddGroundSeed); // TODO: Remove
			NavIndex->SetMember("AddGroundSeed", Nav_AddGroundSeed);
			NavIndex->SetMember("AddAirSeed", Nav_AddAirSeed);

			NavIndex->SetMember("ClearWalkableSeeds", Nav_ClearGroundSeeds); // TODO: Remove
			NavIndex->SetMember("ClearGroundSeeds", Nav_ClearGroundSeeds);
			NavIndex->SetMember("ClearAirSeeds", Nav_ClearAirSeeds);

			NavIndex->SetMember("SetupMaxDistance", Nav_SetupMaxDistance);
			NavIndex->SetMember("Generate", Nav_Generate);
			NavIndex->SetMember("FullGeneration", Nav_FullGeneration);
			NavIndex->SetMember("IsGenerated", Nav_IsGenerated);
			NavIndex->SetMember("FindPath", Nav_FindPath);
			NavIndex->SetMember("FindPathImmediate", Nav_FindPathImmediate);
			NavIndex->SetMember("FindPathHull", Nav_FindPathHull);
			NavIndex->SetMember("GetHeuristic", Nav_GetHeuristic);
			NavIndex->SetMember("GetStart", Nav_GetStart);
			NavIndex->SetMember("GetEnd", Nav_GetEnd);
			NavIndex->SetMember("SetHeuristic", Nav_SetHeuristic);
			NavIndex->SetMember("SetStart", Nav_SetStart);
			NavIndex->SetMember("SetEnd", Nav_SetEnd);
			NavIndex->SetMember("GetNode", Nav_GetNode);
			NavIndex->SetMember("GetClosestNode", Nav_GetClosestNode);
			NavIndex->SetMember("GetNearestNodes", Nav_GetNearestNodes);
			NavIndex->SetMember("GetNodesInSphere", Nav_GetNearestNodes);
			NavIndex->SetMember("Save", Nav_Save);
			NavIndex->SetMember("Load", Nav_Load);
			NavIndex->SetMember("GetDiagonal", Nav_GetDiagonal);
			NavIndex->SetMember("SetDiagonal", Nav_SetDiagonal);
			NavIndex->SetMember("GetGridSize", Nav_GetGridSize);
			NavIndex->SetMember("SetGridSize", Nav_SetGridSize);
			NavIndex->SetMember("GetMask", Nav_GetMask);
			NavIndex->SetMember("SetMask", Nav_SetMask);
			NavIndex->SetMember("CreateNode", Nav_CreateNode);
			NavIndex->SetMember("RemoveNode", Nav_RemoveNode);
		MetaNav->SetMember("__index", NavIndex);
		NavIndex->UnReference();
	MetaNav->UnReference();

	ILuaObject *MetaNode = Lua()->GetMetaTable(NODE_NAME, NODE_TYPE);
		ILuaObject *NodeIndex = Lua()->GetNewTable();
			NodeIndex->SetMember("GetID", Node_GetID);
			NodeIndex->SetMember("GetPosition", Node_GetPosition);
			NodeIndex->SetMember("GetPos", Node_GetPosition);
			NodeIndex->SetMember("GetNormal", Node_GetNormal);
			NodeIndex->SetMember("GetConnections", Node_GetConnections);
			NodeIndex->SetMember("GetConnectedNode", Node_GetConnectedNode);
			NodeIndex->SetMember("GetScoreF", Node_GetScoreF);
			NodeIndex->SetMember("GetScoreG", Node_GetScoreG);
			NodeIndex->SetMember("IsConnected", Node_IsConnected);
			NodeIndex->SetMember("IsDisabled", Node_IsDisabled);
			NodeIndex->SetMember("SetDisabled", Node_SetDisabled);
			NodeIndex->SetMember("SetNormal", Node_SetNormal);
			NodeIndex->SetMember("SetPosition", Node_SetPosition);
			NodeIndex->SetMember("ConnectTo", Node_ConnectTo);
			NodeIndex->SetMember("RemoveConnection", Node_RemoveConnection);
		MetaNode->SetMember("__index", NodeIndex);
		MetaNode->SetMember("__eq", Node__eq);
		NodeIndex->UnReference();
	MetaNode->UnReference();

	// Based on azuisleet's method.
	// hook.Add("Think", "NavPoll", nav.Poll)
	ILuaObject *hook = Lua()->GetGlobal("hook");
	ILuaObject *add = hook->GetMember("Add");
	add->Push();
		Lua()->Push("Think");
		Lua()->Push("NavPoll");
		Lua()->Push(nav_Poll);
	Lua()->Call(3);
	hook->UnReference();
	add->UnReference();

#ifdef LUA_SERVER
	Msg("gmsv_navigation_win32: Loaded\n");
#else
	Msg("gmcl_navigation_win32: Loaded\n");
#endif

#ifdef FILEBUG
	pDebugFile = fopen("garrysmod/filebug.txt", "a+");
	FILEBUG_WRITE("Opened Module\n");
#endif

	return 0;
}
Пример #5
0
int Init(lua_State* L)
{
	gLua = Lua();

	CreateInterfaceFn interfaceFactory = Sys_GetFactory("engine.dll");

	engine = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL);
	if(!engine)
	{
		gLua->Error("gm_astar: Missing IVEngineServer interface.\n");
	}
	
	CreateInterfaceFn fsFactory;

	if(gLua->IsDedicatedServer())
	{
		fsFactory = GetFactories().fileSystemFactory;
	}
	else
	{
		fsFactory = Sys_GetFactory("filesystem_steam.dll");
	}

	if(!fsFactory)
	{
		gLua->Error("gm_astar: Missing fsFactory\n");
	}

	filesystem = (IFileSystem*)fsFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
	if(!filesystem)
	{
		gLua->Error("gm_astar: Missing IFileSystem interface.\n");
	}

	// Get a reference to the function to survive past 510 calls!
	ILuaObject *VectorMeta = gLua->GetGlobal("Vector");
		VectorMeta->Push();
		VectorMetaRef = gLua->GetReference(-1, true);
	VectorMeta->UnReference();

	gLua->SetGlobal("HEURISTIC_MANHATTAN", (float)AStar::HEURISTIC_MANHATTAN);
	gLua->SetGlobal("HEURISTIC_EUCLIDEAN", (float)AStar::HEURISTIC_EUCLIDEAN);
	gLua->SetGlobal("HEURISTIC_DISTANCE", (float)AStar::HEURISTIC_DISTANCE);
	gLua->SetGlobal("HEURISTIC_CUSTOM", (float)AStar::HEURISTIC_CUSTOM);

	gLua->SetGlobal("CreateAStar", CreateAStar);

	ILuaObject *MetaAStar = gLua->GetMetaTable(ASTAR_NAME, ASTAR_TYPE);
		ILuaObject *AStarIndex = gLua->GetNewTable();
			AStarIndex->SetMember("GetNode", AStar_GetNode);
			AStarIndex->SetMember("GetNodeTotal", AStar_GetNodeTotal);
			AStarIndex->SetMember("GetNodes", AStar_GetNodes);
			AStarIndex->SetMember("FindPath", AStar_FindPath);
			AStarIndex->SetMember("AddNode", AStar_AddNode);
			AStarIndex->SetMember("GetHeuristic", AStar_GetHeuristic);
			AStarIndex->SetMember("GetStart", AStar_GetStart);
			AStarIndex->SetMember("GetEnd", AStar_GetEnd);
			AStarIndex->SetMember("SetHeuristic", AStar_SetHeuristic);
			AStarIndex->SetMember("SetStart", AStar_SetStart);
			AStarIndex->SetMember("SetEnd", AStar_SetEnd);
			AStarIndex->SetMember("Save", AStar_Save);
			AStarIndex->SetMember("Load", AStar_Load);
			AStarIndex->SetMember("NearestNode", AStar_NearestNode);
			AStarIndex->SetMember("LinkNodes", AStar_LinkNodes);
			AStarIndex->SetMember("AutoLinkNodes", AStar_AutoLinkNodes);
		MetaAStar->SetMember("__index", AStarIndex);
		AStarIndex->UnReference();
	MetaAStar->UnReference();

	ILuaObject *MetaAStarNode = gLua->GetMetaTable(ASTAR_NODE_NAME, ASTAR_NODE_TYPE);
		ILuaObject *AStarNodeIndex = gLua->GetNewTable();
			AStarNodeIndex->SetMember("Link", AStarNode_Link);
			AStarNodeIndex->SetMember("IsLink", AStarNode_IsLink);
			AStarNodeIndex->SetMember("GetPos", AStarNode_GetPos);
			AStarNodeIndex->SetMember("GetLinks", AStarNode_GetLinks);
		MetaAStarNode->SetMember("__index", AStarNodeIndex);
		AStarNodeIndex->UnReference();
	MetaAStarNode->UnReference();

	Msg("gm_astar: Programmed by Spacetech; Not for Troin's eyes!\n");

	return 0;
}