Eluna add boost support and fix warnings

This commit is contained in:
Rochet2
2014-07-24 23:37:42 +03:00
parent 62db0c601b
commit 38c516c527
8 changed files with 111 additions and 41 deletions

View File

@@ -119,10 +119,13 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/game/World
${CMAKE_SOURCE_DIR}/src/server/scripts/PrecompiledHeaders
${ACE_INCLUDE_DIR}
${Boost_LIBRARIES}
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
)
find_package(Boost COMPONENTS system filesystem REQUIRED)
add_library(LuaEngine STATIC
${LuaEngine_STAT_SRCS}
${game_STAT_SRCS}
@@ -131,6 +134,7 @@ add_library(LuaEngine STATIC
target_link_libraries(LuaEngine
game
${Boost_LIBRARIES}
)
add_dependencies(LuaEngine game)

View File

@@ -38,14 +38,14 @@ namespace LuaCreature
return 1;
}
int IsTargetAcceptable(lua_State* L, Creature* creature)
int IsTargetableForAttack(lua_State* L, Creature* creature)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);
bool inversAlive = Eluna::CHECKOBJ<bool>(L, 2);
#ifdef MANGOS
Eluna::Push(L, creature->IsTargetableForAttack(target));
Eluna::Push(L, creature->IsTargetableForAttack(inversAlive));
#else
Eluna::Push(L, creature->isTargetableForAttack(target));
Eluna::Push(L, creature->isTargetableForAttack(inversAlive));
#endif
return 1;
}

View File

@@ -205,7 +205,7 @@ public:
lua_pushfstring(L, "%p", *ptrHold);
lua_gettable(L, -2);
lua_remove(L, -2);
bool valid = lua_isuserdata(L, -1);
bool valid = lua_isuserdata(L, -1) != 0;
lua_remove(L, -1);
if (!valid)
{

View File

@@ -4,9 +4,6 @@
* Please see the included DOCS/LICENSE.md for more information
*/
#include <ace/ACE.h>
#include <ace/Dirent.h>
#include <ace/OS_NS_sys_stat.h>
#include "HookMgr.h"
#include "LuaEngine.h"
#include "ElunaBinding.h"
@@ -15,6 +12,16 @@
#include "ElunaTemplate.h"
#include "ElunaUtility.h"
// Some dummy includes containing BOOST_VERSION:
// ObjectAccessor.h Config.h Log.h
#ifdef BOOST_VERSION
#include <boost/filesystem.hpp>
#else
#include <ace/ACE.h>
#include <ace/Dirent.h>
#include <ace/OS_NS_sys_stat.h>
#endif
extern "C"
{
#include "lua.h"
@@ -70,12 +77,15 @@ void Eluna::ReloadEluna()
#ifdef TRINITY
// Re initialize creature AI restoring C++ AI or applying lua AI
{
#ifdef BOOST_VERSION
boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Creature>::GetLock());
#else
TRINITY_READ_GUARD(HashMapHolder<Creature>::LockType, *HashMapHolder<Creature>::GetLock());
#endif
HashMapHolder<Creature>::MapType const& m = ObjectAccessor::GetCreatures();
for (HashMapHolder<Creature>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
{
iter->second->AIM_Initialize();
}
if (iter->second->IsInWorld())
iter->second->AIM_Initialize();
}
#endif
@@ -150,11 +160,66 @@ Eluna::~Eluna()
lua_close(L);
}
void Eluna::AddScriptPath(std::string filename, std::string fullpath, ScriptList& scripts)
{
ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath Checking file `%s`", fullpath.c_str());
// split file name
std::size_t extDot = filename.find_last_of('.');
if (extDot == std::string::npos)
return;
std::string ext = filename.substr(extDot);
filename = filename.substr(0, extDot);
// check extension and add path to scripts to load
bool luascript = ext == ".lua" || ext == ".dll";
bool extension = ext == ".ext" || (filename.length() >= 4 && filename.find_last_of("_ext") == filename.length() - 4);
if (!luascript && !extension)
return;
LuaScript script;
script.fileext = ext;
script.filename = filename;
script.filepath = fullpath;
script.modulepath = fullpath.substr(0, fullpath.length() - ext.length());
if (extension)
lua_extensions.push_back(script);
else
scripts.push_back(script);
ELUNA_LOG_DEBUG("[Eluna]: GetScripts add path `%s`", fullpath.c_str());
}
// Finds lua script files from given path (including subdirectories) and pushes them to scripts
void Eluna::GetScripts(std::string path, ScriptList& scripts)
{
ELUNA_LOG_DEBUG("[Eluna]: GetScripts from path `%s`", path.c_str());
#ifdef BOOST_VERSION
boost::filesystem::path someDir(path);
boost::filesystem::directory_iterator end_iter;
if (boost::filesystem::exists(someDir) && boost::filesystem::is_directory(someDir))
{
for (boost::filesystem::directory_iterator dir_iter(someDir); dir_iter != end_iter; ++dir_iter)
{
std::string fullpath = dir_iter->path().generic_string();
// load subfolder
if (boost::filesystem::is_directory(dir_iter->status()))
{
GetScripts(fullpath, scripts);
continue;
}
if (boost::filesystem::is_regular_file(dir_iter->status()))
{
// was file, try add
std::string filename = dir_iter->path().filename().generic_string();
AddScriptPath(filename, fullpath, scripts);
}
}
}
#else
ACE_Dirent dir;
if (dir.open(path.c_str()) == -1)
{
@@ -183,34 +248,16 @@ void Eluna::GetScripts(std::string path, ScriptList& scripts)
continue;
}
// was file, check extension
ELUNA_LOG_DEBUG("[Eluna]: GetScripts Checking file `%s`", fullpath.c_str());
// split file name
// was file, try add
std::string filename = directory->d_name;
std::size_t extDot = filename.find_last_of('.');
if (extDot == std::string::npos)
continue;
std::string ext = filename.substr(extDot);
filename = filename.substr(0, extDot);
// check extension and add path to scripts to load
bool luascript = ext == ".lua" || ext == ".dll";
bool extension = ext == ".ext" || (filename.length() >= 4 && filename.find_last_of("_ext") == filename.length() - 4);
if (!luascript && !extension)
continue;
LuaScript script;
script.fileext = ext;
script.filename = filename;
script.filepath = fullpath;
script.modulepath = fullpath.substr(0, fullpath.length() - ext.length());
if (extension)
lua_extensions.push_back(script);
else
scripts.push_back(script);
ELUNA_LOG_DEBUG("[Eluna]: GetScripts add path `%s`", fullpath.c_str());
AddScriptPath(filename, fullpath, scripts);
}
#endif
}
static bool ScriptpathComparator(const LuaScript& first, const LuaScript& second)
{
return first.filepath.compare(second.filepath) < 0;
}
void Eluna::RunScripts()
@@ -219,6 +266,8 @@ void Eluna::RunScripts()
uint32 count = 0;
ScriptList scripts;
lua_extensions.sort(ScriptpathComparator);
lua_scripts.sort(ScriptpathComparator);
scripts.insert(scripts.end(), lua_extensions.begin(), lua_extensions.end());
scripts.insert(scripts.end(), lua_scripts.begin(), lua_scripts.end());
@@ -415,11 +464,11 @@ void Eluna::Push(lua_State* L, Object const* obj)
}
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg)
{
return lua_isnumber(L, narg) ? luaL_optnumber(L, narg, 1) ? true : false : lua_toboolean(L, narg);
return lua_isnumber(L, narg) != 0 ? luaL_optnumber(L, narg, 1) ? true : false : lua_toboolean(L, narg) != 0;
}
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg, bool def)
{
return lua_isnone(L, narg) ? def : lua_isnumber(L, narg) ? luaL_optnumber(L, narg, 1) ? true : false : lua_toboolean(L, narg);
return lua_isnone(L, narg) != 0 ? def : lua_isnumber(L, narg) != 0 ? luaL_optnumber(L, narg, 1) != 0 ? true : false : lua_toboolean(L, narg) != 0;
}
template<> float Eluna::CHECKVAL<float>(lua_State* L, int narg)
{

View File

@@ -132,6 +132,7 @@ public:
// This will be called on next update
static void ReloadEluna();
static void GetScripts(std::string path, ScriptList& scripts);
static void AddScriptPath(std::string filename, std::string fullpath, ScriptList& scripts);
static void report(lua_State*);
static void ExecuteCall(lua_State* L, int params, int res);

View File

@@ -763,7 +763,7 @@ ElunaRegister<Creature> CreatureMethods[] =
{ "IsTappedBy", &LuaCreature::IsTappedBy }, // :IsTappedBy(player)
{ "HasLootRecipient", &LuaCreature::HasLootRecipient }, // :HasLootRecipient() - Returns true if the creature has a loot recipient
{ "CanAssistTo", &LuaCreature::CanAssistTo }, // :CanAssistTo(unit, enemy[, checkfaction]) - Returns true if the creature can assist unit with enemy
{ "IsTargetAcceptable", &LuaCreature::IsTargetAcceptable }, // :IsTargetAcceptable(unit) - Returns true if the creature can target unit
{ "IsTargetableForAttack", &LuaCreature::IsTargetableForAttack }, // :IsTargetableForAttack([inversAlive]) - Returns true if the creature can be attacked
{ "HasInvolvedQuest", &LuaCreature::HasInvolvedQuest }, // :HasInvolvedQuest(questId) - Returns true if the creature can finish the quest for players
{ "IsRegeneratingHealth", &LuaCreature::IsRegeneratingHealth }, // :IsRegeneratingHealth() - Returns true if the creature is regenerating health
{ "IsReputationGainDisabled", &LuaCreature::IsReputationGainDisabled }, // :IsReputationGainDisabled() - Returns true if the creature has reputation gain disabled

View File

@@ -1624,8 +1624,12 @@ namespace LuaPlayer
{
#ifdef CATA
Eluna::Push(L, player->GetNextResetTalentsCost());
#else
#ifdef TRINITY
Eluna::Push(L, player->ResetTalentsCost());
#else
Eluna::Push(L, player->resetTalentsCost());
#endif
#endif
return 1;
}
@@ -1636,9 +1640,13 @@ namespace LuaPlayer
#ifdef CATA
player->ResetTalents(no_cost);
#else
#ifdef TRINITY
player->ResetTalents(no_cost);
#else
player->resetTalents(no_cost);
#endif
#endif
#if (!defined(TBC) && !defined(CLASSIC))
player->SendTalentsInfoData(false);
#endif
@@ -1651,7 +1659,11 @@ namespace LuaPlayer
bool disabled = Eluna::CHECKVAL<bool>(L, 3, false);
bool learn_low_rank = Eluna::CHECKVAL<bool>(L, 4, true);
#ifdef TRINITY
player->RemoveSpell(entry, disabled, learn_low_rank);
#else
player->removeSpell(entry, disabled, learn_low_rank);
#endif
return 0;
}
@@ -2094,7 +2106,11 @@ namespace LuaPlayer
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
#ifdef TRINITY
player->LearnSpell(id, false);
#else
player->learnSpell(id, false);
#endif
return 0;
}

View File

@@ -1593,7 +1593,7 @@ namespace LuaUnit
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);
uint32 spell = Eluna::CHECKVAL<uint32>(L, 3);
uint32 amount = Eluna::CHECKVAL<uint32>(L, 4);
uint32 critical = Eluna::CHECKVAL<uint32>(L, 5, false);
bool critical = Eluna::CHECKVAL<bool>(L, 5, false);
#ifndef TRINITY
if (const SpellInfo* info = sSpellStore.LookupEntry(spell))