diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index ca5028a53..635a85635 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -37,15 +37,20 @@ endif(BUILD_WITH_PAWN) option(BUILD_WITH_LUA "Enable Terra/Lua language" ON) if(BUILD_WITH_LUA) #set(Terra_ROOT ${CMAKE_SOURCE_DIR}/external/terra/) - find_package(Terra REQUIRED) + if(WIN32) + find_package(Lua REQUIRED) + else() + find_package(Terra REQUIRED) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_TERRA") + endif() set(LuaScript_Sources Script/LangLua/LangLua.cpp Script/LangLua/LuaFunc.cpp) - set(LuaScript_Headers ${Terra_INCLUDES} ${CMAKE_SOURCE_DIR}/extern/LuaBridge ${CMAKE_SOURCE_DIR}/extern/LuaBridge/detail + set(LuaScript_Headers ${Terra_INCLUDES} ${Lua_INCLUDES} ${CMAKE_SOURCE_DIR}/extern/LuaBridge ${CMAKE_SOURCE_DIR}/extern/LuaBridge/detail Script/LangLua/LangLua.hpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_LUA") - include_directories(${Terra_INCLUDES} ${CMAKE_SOURCE_DIR}/extern/LuaBridge) + include_directories(${Terra_INCLUDES} ${Lua_INCLUDES} ${CMAKE_SOURCE_DIR}/extern/LuaBridge) endif(BUILD_WITH_LUA) set(NativeScript_Sources @@ -105,6 +110,7 @@ target_link_libraries(tes3mp-server ${RakNet_LIBRARY} components ${Terra_LIBRARY} + ${Lua_LIBRARY} ${Pawn_LIBRARY} ${Breakpad_Library} ) diff --git a/apps/openmw-mp/Script/LangLua/LangLua.cpp b/apps/openmw-mp/Script/LangLua/LangLua.cpp index a85ea2a47..89b39405b 100644 --- a/apps/openmw-mp/Script/LangLua/LangLua.cpp +++ b/apps/openmw-mp/Script/LangLua/LangLua.cpp @@ -23,7 +23,9 @@ LangLua::LangLua() { lua = luaL_newstate(); luaL_openlibs(lua); // load all lua std libs +#if defined(ENABLE_TERRA) terra_init(lua); +#endif } LangLua::~LangLua() @@ -98,7 +100,11 @@ void LangLua::LoadProgram(const char *filename) { int err = 0; +#if defined(ENABLE_TERRA) if ((err = terra_loadfile(lua, filename)) != 0) +#else + if ((err =luaL_loadfile(lua, filename)) != 0) +#endif throw runtime_error("Lua script " + string(filename) + " error (" + to_string(err) + "): \"" + string(lua_tostring(lua, -1)) + "\""); diff --git a/apps/openmw-mp/Script/LangLua/LangLua.hpp b/apps/openmw-mp/Script/LangLua/LangLua.hpp index 04e7d4046..3c2db031a 100644 --- a/apps/openmw-mp/Script/LangLua/LangLua.hpp +++ b/apps/openmw-mp/Script/LangLua/LangLua.hpp @@ -5,7 +5,13 @@ #ifndef PLUGINSYSTEM3_LANGLUA_HPP #define PLUGINSYSTEM3_LANGLUA_HPP +#ifdef ENABLE_TERRA #include +#else +#include +#endif + +#include #include #include diff --git a/apps/openmw-mp/Script/Script.cpp b/apps/openmw-mp/Script/Script.cpp index 7392e753e..41e69be46 100644 --- a/apps/openmw-mp/Script/Script.cpp +++ b/apps/openmw-mp/Script/Script.cpp @@ -96,7 +96,7 @@ void Script::UnloadScripts() { //Public::DeleteAll(); scripts.clear(); -#if defined (ENABLE_LUA) +#if defined (ENABLE_TERRA) terra_llvmshutdown(); #endif } diff --git a/apps/openmw-mp/Script/Script.hpp b/apps/openmw-mp/Script/Script.hpp index 3931542dc..282f3a606 100644 --- a/apps/openmw-mp/Script/Script.hpp +++ b/apps/openmw-mp/Script/Script.hpp @@ -15,11 +15,6 @@ #include #include -#if defined (ENABLE_LUA) -#include -#include -#endif - class Script : private ScriptFunctions { // http://imgur.com/hU0N4EH diff --git a/apps/openmw-mp/Script/ScriptFunction.hpp b/apps/openmw-mp/Script/ScriptFunction.hpp index 09892f986..1884ab8dd 100644 --- a/apps/openmw-mp/Script/ScriptFunction.hpp +++ b/apps/openmw-mp/Script/ScriptFunction.hpp @@ -9,7 +9,7 @@ #include #include #if defined (ENABLE_LUA) -#include +#include "LangLua/LangLua.hpp" #endif #if defined (ENABLE_PAWN) diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake new file mode 100644 index 000000000..646aaaf6b --- /dev/null +++ b/cmake/FindLua.cmake @@ -0,0 +1,70 @@ +# - Try to find Lua +# Once done this will define +# +# Lua_FOUND - system has Lua +# Lua_INCLUDES - the Lua include directory +# Lua_LIBRARY - Link these to use Lua + +FIND_LIBRARY (Lua_LIBRARY_RELEASE NAMES lua5.1 + PATHS + ENV LD_LIBRARY_PATH + ENV LIBRARY_PATH + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /opt/local/lib + $ENV{Lua_ROOT}/lib + ) + +FIND_LIBRARY (Lua_LIBRARY_DEBUG NAMES lua5.1 + PATHS + ENV LD_LIBRARY_PATH + ENV LIBRARY_PATH + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /opt/local/lib + $ENV{Lua_ROOT}/lib + ) + + + +FIND_PATH (Lua_INCLUDES lua5.1/lua.h + ENV CPATH + /usr/include + /usr/local/include + /opt/local/include + $ENV{Lua_ROOT}/include + ) + +IF(Lua_INCLUDES AND Lua_LIBRARY_RELEASE) + SET(Lua_FOUND TRUE) +ENDIF(Lua_INCLUDES AND Lua_LIBRARY_RELEASE) + +IF(NOT Lua_LIBRARY_DEBUG) + SET(Lua_LIBRARY_DEBUG ${Lua_LIBRARY_RELEASE}) +ENDIF() + +IF(Lua_FOUND) + SET(Lua_INCLUDES ${Lua_INCLUDES}) + + find_package(ZLIB REQUIRED) + + IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) + SET(Lua_LIBRARY optimized ${Lua_LIBRARY_RELEASE} debug ${Lua_LIBRARY_DEBUG} ${ZLIB_LIBRARIES}) + ELSE() + # if there are no configuration types and CMAKE_BUILD_TYPE has no value + # then just use the release libraries + SET(Lua_LIBRARY ${Lua_LIBRARY_RELEASE} ${ZLIB_LIBRARIES}) + ENDIF() + IF(NOT Lua_FIND_QUIETLY) + MESSAGE(STATUS "Found Lua: ${Lua_LIBRARIES}") + ENDIF(NOT Lua_FIND_QUIETLY) +ELSE(Lua_FOUND) + IF(Lua_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Lua") + ENDIF(Lua_FIND_REQUIRED) +ENDIF(Lua_FOUND) +