From 0df32acccab584579b04b6e3dc9277aea2a6a15e Mon Sep 17 00:00:00 2001 From: Koncord Date: Sun, 20 Jan 2019 17:16:19 +0800 Subject: [PATCH] [Server] Fix ARM build --- apps/openmw-mp/Script/LangLua/LangLua.cpp | 33 +++++++++++++++++++++-- apps/openmw-mp/Script/Types.hpp | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/Script/LangLua/LangLua.cpp b/apps/openmw-mp/Script/LangLua/LangLua.cpp index e853e7aaa..f813776e8 100644 --- a/apps/openmw-mp/Script/LangLua/LangLua.cpp +++ b/apps/openmw-mp/Script/LangLua/LangLua.cpp @@ -107,6 +107,32 @@ template<> struct F_<1> { static constexpr LuaFuctionData F{"CreateTimerEx", Lan template<> struct F_<2> { static constexpr LuaFuctionData F{"MakePublic", LangLua::MakePublic}; }; template<> struct F_<3> { static constexpr LuaFuctionData F{"CallPublic", LangLua::CallPublic}; }; +#ifdef __arm__ +template +struct indices {}; +template +struct build_indices : build_indices {}; +template +struct build_indices<0, Is...> : indices {}; +template +using IndicesFor = build_indices; + +template +LuaFuctionData *functions(indices) +{ + + static LuaFuctionData functions_[sizeof...(Indices)]{ + F_::F... + }; + + static_assert( + sizeof(functions_) / sizeof(functions_[0]) == + sizeof(ScriptFunctions::functions) / sizeof(ScriptFunctions::functions[0]), + "Not all functions have been mapped to Lua"); + + return functions_; +} +#else template struct C { @@ -117,7 +143,6 @@ struct C } }; - template<> struct C<0> { @@ -141,6 +166,7 @@ LuaFuctionData *functions() return functions_; } +#endif void LangLua::LoadProgram(const char *filename) { @@ -152,8 +178,11 @@ void LangLua::LoadProgram(const char *filename) constexpr auto functions_n = sizeof(ScriptFunctions::functions) / sizeof(ScriptFunctions::functions[0]); +#if __arm__ + LuaFuctionData *functions_ = functions(IndicesFor{}); +#else LuaFuctionData *functions_ = functions(); - +#endif luabridge::Namespace tes3mp = luabridge::getGlobalNamespace(lua).beginNamespace("tes3mp"); for (unsigned i = 0; i < functions_n; i++) diff --git a/apps/openmw-mp/Script/Types.hpp b/apps/openmw-mp/Script/Types.hpp index cca05c42b..be365cfb8 100644 --- a/apps/openmw-mp/Script/Types.hpp +++ b/apps/openmw-mp/Script/Types.hpp @@ -105,7 +105,7 @@ struct ScriptFunctionPointer : public ScriptIdentity void *addr; #if (!defined(__clang__) && defined(__GNUC__)) template - constexpr ScriptFunctionPointer(Function addr) : ScriptIdentity(addr), addr(reinterpret_cast(addr)) {} + constexpr ScriptFunctionPointer(Function addr) : ScriptIdentity(addr), addr((void*)(addr)) {} #else template constexpr ScriptFunctionPointer(Function addr) : ScriptIdentity(addr), addr(addr) {}