diff --git a/CMakeLists.txt b/CMakeLists.txt index 44e5fb70..2233320d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ option(USE_IMGUI_GL3 "Use OpenGL3+ imgui implementation" ON) option(WITH_OPENGL_MODERN "Compile with OpenGL modern renderer" ON) option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON) option(WITH_UART "Compile with libserialport" ON) +option(WITH_LUA "Compile with lua scripting support" ON) option(WITH_OPENVR "Compile with OpenVR" ON) option(WITH_ZMQ "Compile with cppzmq" OFF) option(WITH_CRASHPAD "Compile with crashpad" OFF) @@ -108,7 +109,6 @@ set(SOURCES "drivermouseinput.cpp" "translation.cpp" "material.cpp" -"lua.cpp" "stdafx.cpp" "messaging.cpp" "scene.cpp" @@ -232,6 +232,11 @@ if (WITH_OPENVR) set(SOURCES ${SOURCES} "vr/openvr_imp.cpp") endif() +if (WITH_LUA) + add_definitions(-DWITH_LUA) + set(SOURCES ${SOURCES} "lua.cpp") +endif() + if (WITH_OPENGL_MODERN) set(SOURCES ${SOURCES} "opengl33geometrybank.cpp" @@ -424,9 +429,11 @@ endif() find_package(SndFile REQUIRED) target_link_libraries(${PROJECT_NAME} SndFile::sndfile) -find_package(LuaJIT REQUIRED) -include_directories(${LUAJIT_INCLUDE_DIR}) -target_link_libraries(${PROJECT_NAME} ${LUAJIT_LIBRARIES}) +if (WITH_LUA) + find_package(LuaJIT REQUIRED) + include_directories(${LUAJIT_INCLUDE_DIR}) + target_link_libraries(${PROJECT_NAME} ${LUAJIT_LIBRARIES}) +endif() if (WITH_UART) find_package(libserialport REQUIRED) diff --git a/Event.cpp b/Event.cpp index 4818078c..8d5690c1 100644 --- a/Event.cpp +++ b/Event.cpp @@ -2075,6 +2075,7 @@ friction_event::export_as_text_( std::ostream &Output ) const { Output << m_friction << ' '; } +#ifdef WITH_LUA lua_event::lua_event(lua::eventhandler_t func) { lua_func = func; } @@ -2118,6 +2119,7 @@ lua_event::export_as_text_( std::ostream &Output ) const { bool lua_event::is_instant() const { return m_delay == 0.0 && m_delayrandom == 0.0; } +#endif // prepares event for use void diff --git a/Event.h b/Event.h index 41631efc..44a9c40d 100644 --- a/Event.h +++ b/Event.h @@ -14,10 +14,13 @@ http://mozilla.org/MPL/2.0/. #include "Names.h" #include "EvLaunch.h" #include "Logs.h" -#include "lua.h" #include "command.h" #include "comparison.h" +#ifdef WITH_LUA +#include "lua.h" +#endif + // common event interface class basic_event { @@ -585,6 +588,7 @@ private: float m_friction{ -1.f }; }; +#ifdef WITH_LUA class lua_event : public basic_event { public: lua_event(lua::eventhandler_t func); @@ -599,6 +603,7 @@ private: lua::eventhandler_t lua_func = nullptr; }; +#endif class message_event : public basic_event { diff --git a/simulation.cpp b/simulation.cpp index 6632e188..e5c0b433 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -41,9 +41,12 @@ instance_table Instances; vehicle_table Vehicles; train_table Trains; light_array Lights; -lua Lua; particle_manager Particles; +#ifdef WITH_LUA +lua Lua; +#endif + scene::basic_region *Region { nullptr }; TTrain *Train { nullptr }; diff --git a/simulation.h b/simulation.h index 15c425f2..6cc8ea53 100644 --- a/simulation.h +++ b/simulation.h @@ -11,11 +11,14 @@ http://mozilla.org/MPL/2.0/. #include "simulationstateserializer.h" #include "Classes.h" -#include "lua.h" #include "Event.h" #include "Train.h" #include "particles.h" +#ifdef WITH_LUA +#include "lua.h" +#endif + namespace simulation { class state_manager { @@ -78,8 +81,10 @@ extern vehicle_table Vehicles; extern train_table Trains; extern light_array Lights; extern sound_table Sounds; -extern lua Lua; extern particle_manager Particles; +#ifdef WITH_LUA +extern lua Lua; +#endif extern scene::basic_region *Region; extern TTrain *Train; diff --git a/simulationstateserializer.cpp b/simulationstateserializer.cpp index 948d8bee..5b712f7f 100644 --- a/simulationstateserializer.cpp +++ b/simulationstateserializer.cpp @@ -319,7 +319,11 @@ void state_serializer::deserialize_lua( cParser &Input, scene::scratch_data &Scr Input.getTokens(1, false); std::string file; Input >> file; +#ifdef WITH_LUA simulation::Lua.interpret(Global.asCurrentSceneryPath + file); +#else + ErrorLog(file + ": lua scripts not supported in this build."); +#endif } void