diff options
Diffstat (limited to 'source/squirrelbindings')
-rw-r--r-- | source/squirrelbindings/SquirrelArray.h | 56 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelBaseClass.h | 66 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelBindings.cpp | 195 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelBindings.h | 32 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelFunctions.cpp | 94 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelFunctions.h | 28 | ||||
-rw-r--r-- | source/squirrelbindings/SquirrelObject.h | 55 |
7 files changed, 0 insertions, 526 deletions
diff --git a/source/squirrelbindings/SquirrelArray.h b/source/squirrelbindings/SquirrelArray.h deleted file mode 100644 index de5027f86..000000000 --- a/source/squirrelbindings/SquirrelArray.h +++ /dev/null @@ -1,56 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -template <typename T> -class SquirrelArray -{ -public: - SquirrelArray() - { - } - - unsigned int Size() - { - return m_Values.size(); - } - - T Get(unsigned int a_Index) - { - if(m_Values.size() < a_Index) - { - return T(); - } - return m_Values.at(a_Index); - } - - void Add(T a_Value) - { - m_Values.push_back(a_Value); - } - -protected: - std::vector<T> m_Values; - -}; - -class SquirrelStringArray : public SquirrelArray<std::string> { }; - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelBaseClass.h b/source/squirrelbindings/SquirrelBaseClass.h deleted file mode 100644 index fb5e95c05..000000000 --- a/source/squirrelbindings/SquirrelBaseClass.h +++ /dev/null @@ -1,66 +0,0 @@ - -#pragma once - - - - -#ifdef USE_SQUIRREL - - - - - -#include "SquirrelBindings.h" -#include "../Plugin_Squirrel.h" -#include "../PluginManager.h" -#include "../Root.h" -#include "../SquirrelCommandBinder.h" - - - - - -// The baseclass for squirrel plugins -class cSquirrelBaseClass -{ -public: - cSquirrelBaseClass() - : m_Instance(0) - { - } - - void setInstance(cPlugin_Squirrel *a_Instance) - { - m_Instance = a_Instance; - } - - void AddHook(short a_Hook) - { - if(m_Instance) - cRoot::Get()->GetPluginManager()->AddHook(m_Instance, (cPluginManager::PluginHook) a_Hook); - } - - void AddCommand( std::string a_Command, std::string a_Description, std::string a_Permission ) - { - if(m_Instance) m_Instance->AddCommand(a_Command, a_Description, a_Permission); - } - - bool BindCommand( const std::string a_Command, const std::string a_Permission, Sqrat::Function a_Callback) - { - if(!m_Instance) return false; - return cRoot::Get()->GetPluginManager()->GetSquirrelCommandBinder()->BindCommand(a_Command, a_Permission, m_Instance, a_Callback); - } - -protected: - cPlugin_Squirrel *m_Instance; -}; - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelBindings.cpp b/source/squirrelbindings/SquirrelBindings.cpp deleted file mode 100644 index 51acc184f..000000000 --- a/source/squirrelbindings/SquirrelBindings.cpp +++ /dev/null @@ -1,195 +0,0 @@ - -#include "Globals.h" - - - - - -#ifdef USE_SQUIRREL - - - - -#include "SquirrelBindings.h" -#include "SquirrelFunctions.h" - -#include "SquirrelBaseClass.h" -#include "SquirrelArray.h" - -#include "../Player.h" - - - - - -using namespace Sqrat; - - - - - -void BindSquirrel(HSQUIRRELVM vm) -{ - RootTable() - .Bind("Plugin", Class<cSquirrelBaseClass>() - .Func("AddHook", &cSquirrelBaseClass::AddHook) - .Func("AddCommand", &cSquirrelBaseClass::AddCommand) - .Func("BindCommand", &cSquirrelBaseClass::BindCommand) - ); - - RootTable().Bind("Vector3f", Class<Vector3f, NoConstructor>() - .Func("Set", &Vector3f::Set) - .Func("Normalize", &Vector3f::Normalize) - .Func("Length", &Vector3f::Length) - .Func("SqrLength", &Vector3f::SqrLength) - .Var("x", &Vector3f::x) - .Var("y", &Vector3f::y) - .Var("z", &Vector3f::z) - ); - - RootTable().Bind("Vector3d", Class<Vector3d, NoConstructor>() - .Func("Set", &Vector3d::Set) - .Func("Normalize", &Vector3d::Normalize) - .Func("Length", &Vector3d::Length) - .Func("SqrLength", &Vector3d::SqrLength) - .Var("x", &Vector3d::x) - .Var("y", &Vector3d::y) - .Var("z", &Vector3d::z) - ); - - RootTable().Bind("cEntity", Class<cEntity, NoConstructor>() - .Func("GetEntityType", &cEntity::GetEntityType) - .Func("IsA", &cEntity::IsA) - .Func("GetWorld", &cEntity::GetWorld) - .Func("GetPosition", &cEntity::GetPosition) - .Func("GetPosX", &cEntity::GetPosX) - .Func("GetPosY", &cEntity::GetPosY) - .Func("GetPosZ", &cEntity::GetPosZ) - .Func("GetRot", &cEntity::GetRot) - .Func("GetRotation", &cEntity::GetRotation) - .Func("GetPitch", &cEntity::GetPitch) - .Func("GetRoll", &cEntity::GetRoll) - .Func("SetRotation", &cEntity::SetRotation) - .Func("SetPitch", &cEntity::SetPitch) - .Func("SetRoll", &cEntity::SetRoll) - .Func("GetLookVector", &cEntity::GetLookVector) - .Func("GetChunkX", &cEntity::GetChunkX) - .Func("GetChunkY", &cEntity::GetChunkY) - .Func("GetChunkZ", &cEntity::GetChunkZ) - .Func("SetPosX", &cEntity::SetPosX) - .Func("SetPosY", &cEntity::SetPosY) - .Func("SetPosZ", &cEntity::SetPosZ) - .Func<void (cEntity::*) (double, double, double)>("SetPosition", &cEntity::SetPosition) - .Func("GetUniqueID", &cEntity::GetUniqueID) - .Func("IsDestroyed", &cEntity::IsDestroyed) - .Func("Destroy", &cEntity::Destroy) - ); - - ConstTable().Enum("MetaData", Enumeration() - .Const("Normal", cPawn::NORMAL) - .Const("Burning", cPawn::BURNING) - .Const("Crouched", cPawn::CROUCHED) - .Const("Riding", cPawn::RIDING) - .Const("Sprinting", cPawn::SPRINTING) - .Const("Eating", cPawn::EATING) - .Const("Blocking", cPawn::BLOCKING) - ); - - RootTable().Bind("cPawn", DerivedClass<cPawn, cEntity, NoConstructor>() - .Func("TeleportToEntity", &cPawn::TeleportToEntity) - .Func("TeleportTo", &cPawn::TeleportTo) - .Func("Heal", &cPawn::Heal) - .Func("TakeDamage", &cPawn::TakeDamage) - .Func("KilledBy", &cPawn::KilledBy) - .Func("GetHealth", &cPawn::GetHealth) - .Func("SetMetaData", &cPawn::SetMetaData) - .Func("GetMetaData", &cPawn::GetMetaData) - .Func("SetMaxHealth", &cPawn::SetMaxHealth) - .Func("GetMaxHealth", &cPawn::GetMaxHealth) - ); - - RootTable().Bind("cPlayer", DerivedClass<cPlayer, cPawn, NoConstructor>() - .Func("GetName", &cPlayer::GetName) - .Func("SetTouchGround", &cPlayer::SetTouchGround) - .Func("SetStance", &cPlayer::SetStance) - .Func("GetEyeHeight", &cPlayer::GetEyeHeight) - .Func("GetEyePosition", &cPlayer::GetEyePosition) - .Func("GetFlying", &cPlayer::GetFlying) - .Func("GetStance", &cPlayer::GetStance) - //TODO .Func("GetInventory", &cPlayer::GetInventory) - .Func("TeleportTo", &cPlayer::TeleportTo) - .Func("GetGameMode", &cPlayer::GetGameMode) - .Func("GetIP", &cPlayer::GetIP) - .Func("GetLastBlockActionTime", &cPlayer::GetLastBlockActionTime) - .Func("GetLastBlockActionCnt", &cPlayer::GetLastBlockActionCnt) - .Func("SetLastBlockActionCnt", &cPlayer::SetLastBlockActionCnt) - .Func("SetLastBlockActionTime", &cPlayer::SetLastBlockActionTime) - .Func("SetGameMode", &cPlayer::SetGameMode) - .Func("LoginSetGameMode", &cPlayer::LoginSetGameMode) - .Func("SetIP", &cPlayer::SetIP) - .Func("MoveTo", &cPlayer::MoveTo) - .Func("GetClientHandle", &cPlayer::GetClientHandle) - .Func("SendMessage", &cPlayer::SendMessage) - .Func("AddToGroup", &cPlayer::AddToGroup) - .Func("CanUseCommand", &cPlayer::CanUseCommand) - .Func("HasPermission", &cPlayer::HasPermission) - .Func("IsInGroup", &cPlayer::IsInGroup) - .Func("GetColor", &cPlayer::GetColor) - .Func("TossItem", &cPlayer::TossItem) - .Func("Heal", &cPlayer::Heal) - .Func("Feed", &cPlayer::Feed) - .Func("TakeDamage", &cPlayer::TakeDamage) - .Func("KilledBy", &cPlayer::KilledBy) - .Func("Respawn", &cPlayer::Respawn) - .Func("SetVisible", &cPlayer::SetVisible) - .Func("IsVisible", &cPlayer::IsVisible) - .Func("MoveToWorld", &cPlayer::MoveToWorld) - .Func("GetLoadedWorldName", &cPlayer::GetLoadedWorldName) - .Func("UseEquippedItem", &cPlayer::UseEquippedItem) - ); - - RootTable().Bind("StringArray", Class<SquirrelStringArray>() - .Func("Get", &SquirrelStringArray::Get) - .Func("Add", &SquirrelStringArray::Add) - .Func("Size", &SquirrelStringArray::Size) - ); - - - RootTable().Func("print", &sqPrint); - - - ConstTable().Enum("Hook", Enumeration() - .Const("Tick", cPluginManager::HOOK_TICK) - .Const("Chat", cPluginManager::HOOK_CHAT) - .Const("CollectPickup", cPluginManager::HOOK_COLLECT_PICKUP) - .Const("BlockDig", cPluginManager::HOOK_BLOCK_DIG) - .Const("BlockPlace", cPluginManager::HOOK_BLOCK_PLACE) - .Const("Disconnect", cPluginManager::HOOK_DISCONNECT) - .Const("Handshake", cPluginManager::HOOK_HANDSHAKE) - .Const("Login", cPluginManager::HOOK_LOGIN) - .Const("PlayerSpawn", cPluginManager::HOOK_PLAYER_SPAWN) - .Const("PlayerJoin", cPluginManager::HOOK_PLAYER_JOIN) - .Const("PlayerMove", cPluginManager::HOOK_PLAYER_MOVE) - .Const("TakeDamage", cPluginManager::HOOK_TAKE_DAMAGE) - .Const("Killed", cPluginManager::HOOK_KILLED) - .Const("ChunkGenerated", cPluginManager::HOOK_CHUNK_GENERATED) - .Const("ChunkGenerating", cPluginManager::HOOK_CHUNK_GENERATING) - .Const("BlockToDrops", cPluginManager::HOOK_BLOCK_TO_DROPS) - .Const("PreCrafting", cPluginManager::HOOK_PRE_CRAFTING) - .Const("CraftingNoRecipe", cPluginManager::HOOK_CRAFTING_NO_RECIPE) - .Const("PostCrafting", cPluginManager::HOOK_POST_CRAFTING) - .Const("BlockToPickup", cPluginManager::HOOK_BLOCK_TO_PICKUP) - .Const("WeatherChanged", cPluginManager::HOOK_WEATHER_CHANGED) - .Const("UpdatingSign", cPluginManager::HOOK_UPDATING_SIGN) - .Const("UpdatedSign", cPluginManager::HOOK_UPDATED_SIGN)); -} - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelBindings.h b/source/squirrelbindings/SquirrelBindings.h deleted file mode 100644 index dd2affda0..000000000 --- a/source/squirrelbindings/SquirrelBindings.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -#include <squirrel.h> -#include <sqrat.h> - - - - - -void BindSquirrel(HSQUIRRELVM vm); - - - - - -#endif // USE_SQUIRREL - - - - - diff --git a/source/squirrelbindings/SquirrelFunctions.cpp b/source/squirrelbindings/SquirrelFunctions.cpp deleted file mode 100644 index 9407670d4..000000000 --- a/source/squirrelbindings/SquirrelFunctions.cpp +++ /dev/null @@ -1,94 +0,0 @@ - -#include "Globals.h" - - - - - -#ifdef USE_SQUIRREL - - - - - -#include "SquirrelFunctions.h" -#include "SquirrelBindings.h" - - - - - -static HSQUIRRELVM squirrelvm = NULL; - - - - - -SQInteger runtimeErrorHandler(HSQUIRRELVM a_VM) -{ - const SQChar *sErr = 0; - if(sq_gettop(a_VM) >= 1) - { - if(SQ_SUCCEEDED(sq_getstring(a_VM, 2, &sErr))) - { - LOGERROR("Squirrel Error: %s", sErr); - } - else - { - LOGERROR("Squirrel Error: Unknown Error"); - } - } - return 0; -} - -void compilerErrorHandler(HSQUIRRELVM v, - const SQChar* a_Desc, - const SQChar* a_Source, - SQInteger a_Line, - SQInteger a_Column) -{ - - LOGERROR("Squirrel Error: %s (%d:%d) %s", a_Source, a_Line, a_Column, a_Desc); -} - -HSQUIRRELVM OpenSquirrelVM() -{ - if(!squirrelvm) - { - squirrelvm = sq_open(1024); - Sqrat::DefaultVM::Set(squirrelvm); - - sq_newclosure(squirrelvm, runtimeErrorHandler, 0); - sq_seterrorhandler(squirrelvm); - - sq_setcompilererrorhandler(squirrelvm, compilerErrorHandler); - - BindSquirrel(squirrelvm); - } - return squirrelvm; -} - -void CloseSquirrelVM() -{ - if(squirrelvm) - { - sq_close(squirrelvm); - squirrelvm = NULL; - } -} - - -void sqPrint(SQChar * text) -{ - LOGINFO("%s", text); -} - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelFunctions.h b/source/squirrelbindings/SquirrelFunctions.h deleted file mode 100644 index 272b79c3e..000000000 --- a/source/squirrelbindings/SquirrelFunctions.h +++ /dev/null @@ -1,28 +0,0 @@ - -#pragma once - -#ifdef USE_SQUIRREL - - - - -#include <sqrat.h> - - - - - -HSQUIRRELVM OpenSquirrelVM(); -void CloseSquirrelVM(); - -void sqPrint(SQChar * text); - - - - - -#endif // USE_SQUIRREL - - - - diff --git a/source/squirrelbindings/SquirrelObject.h b/source/squirrelbindings/SquirrelObject.h deleted file mode 100644 index 248a5e02c..000000000 --- a/source/squirrelbindings/SquirrelObject.h +++ /dev/null @@ -1,55 +0,0 @@ - -#pragma once - - - - - -#ifdef USE_SQUIRREL - - - - - -#include <sqrat.h> - - - - - -class SquirrelObject -{ -public: - SquirrelObject(Sqrat::Object a_Obj) - { - m_SquirrelObject = a_Obj; - } - - Sqrat::Function GetFunction(const char *a_MethodName) - { - if(m_SquirrelObject.IsNull()) - return Sqrat::Function(); - - Sqrat::Function method(m_SquirrelObject, a_MethodName); - return method; - } - - bool HasFunction(const char *a_MethodName) - { - return !this->GetFunction(a_MethodName).IsNull(); - } - -protected: - Sqrat::Object m_SquirrelObject; - -}; - - - - - -#endif // USE_SQUIRREL - - - - |