diff --git a/.gitignore b/.gitignore index 8da23996..ecf0b987 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ build_web/* wasm-python.py lua54* include/* -save/* \ No newline at end of file +save/* +lib/Lua/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 989feb86..61846c20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray) add_subdirectory(${PROJECT_SOURCE_DIR}/lib/LuaGate) if (EMSCRIPTEN) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s INITIAL_MEMORY=33554432") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s INITIAL_MEMORY=33554432") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_DISABLE_EXCEPTION_CATCHING --shell-file ../sources/wasm/frontend.html --preload-file ../assets") set(CMAKE_EXECUTABLE_SUFFIX ".html") endif () diff --git a/lib/LuaGate/CMakeLists.txt b/lib/LuaGate/CMakeLists.txt index eb227570..a2fd0d46 100644 --- a/lib/LuaGate/CMakeLists.txt +++ b/lib/LuaGate/CMakeLists.txt @@ -17,17 +17,33 @@ set(SRC sources/LuaGate.cpp ) -include(FindLua) -if (NOT LUA_FOUND) - if (EXISTS ${CMAKE_SOURCE_DIR}/include/lua.hpp) - message("Using local lua") - set(LUA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/) - set(LUA_LIBRARIES ${CMAKE_SOURCE_DIR}/lua54.lib) - else() - message(FATAL_ERROR "Lua could not be found.") +add_library(LuaGate STATIC ${SRC} ${HEADERS}) +if (EMSCRIPTEN) + include(ExternalProject) + ExternalProject_Add(LUA + SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib/Lua + URL http://www.lua.org/ftp/lua-5.4.3.tar.gz + DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/lib/Lua + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND echo "Trololol" + BUILD_COMMAND make generic CC="emcc" 'AR="emar rcu"' RANLIB="emranlib" + INSTALL_COMMAND cmake -E echo "Ta mere en slip" + ) + set(LUA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lib/Lua/src) + set(LUA_LIBRARIES ${CMAKE_SOURCE_DIR}/lib/Lua/src/liblua.a) + add_dependencies(LuaGate LUA) +else() + include(FindLua) + if (NOT LUA_FOUND) + if (EXISTS ${CMAKE_SOURCE_DIR}/include/lua.hpp) + message("Using local lua") + set(LUA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/) + set(LUA_LIBRARIES ${CMAKE_SOURCE_DIR}/lua54.lib) + else() + message(FATAL_ERROR "Lua could not be found.") + endif() endif() endif() -add_library(LuaGate STATIC ${SRC} ${HEADERS}) target_include_directories(LuaGate PUBLIC ${LUA_INCLUDE_DIR}) target_link_libraries(LuaGate ${LUA_LIBRARIES}) diff --git a/sources/Parser/ParserYaml.hpp b/sources/Parser/ParserYaml.hpp index ff8a73f6..3b79042b 100644 --- a/sources/Parser/ParserYaml.hpp +++ b/sources/Parser/ParserYaml.hpp @@ -15,10 +15,10 @@ namespace BBM { private: //! @brief The number of chars for endl - #ifdef __linux__ - static constexpr int endlNbChars = 1; - #elif _WIN32 + #ifdef _WIN32 static constexpr int endlNbChars = 2; + #else + static constexpr int endlNbChars = 1; #endif //!@brief file block of the parser diff --git a/wasm-server.py b/wasm-server.py new file mode 100644 index 00000000..77aad1db --- /dev/null +++ b/wasm-server.py @@ -0,0 +1,24 @@ +# Python 3 + +import sys +import socketserver +from http.server import SimpleHTTPRequestHandler + +class WasmHandler(SimpleHTTPRequestHandler): + def end_headers(self): + # Include additional response headers here. CORS for example: + #self.send_header('Access-Control-Allow-Origin', '*') + SimpleHTTPRequestHandler.end_headers(self) + + +# Python 3.7.5 adds in the WebAssembly Media Type. If this is an older +# version, add in the Media Type. +if sys.version_info < (3, 7, 5): + WasmHandler.extensions_map['.wasm'] = 'application/wasm' + + +if __name__ == '__main__': + PORT = 8080 + with socketserver.TCPServer(("", PORT), WasmHandler) as httpd: + print("Listening on port {}. Press Ctrl+C to stop.".format(PORT)) + httpd.serve_forever()