From 755217ea59aaaf083517c2d399af2f4af9d3781c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 15:51:18 -0500 Subject: [PATCH 01/35] Add LuaRocks as a submodule --- .gitmodules | 3 +++ third-party/luarocks | 1 + 2 files changed, 4 insertions(+) create mode 160000 third-party/luarocks diff --git a/.gitmodules b/.gitmodules index 89936f20..6a3260ac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "doc/generation/LDoc"] path = doc/generation/LDoc url = https://github.com/stevedonovan/LDoc.git +[submodule "third-party/luarocks"] + path = third-party/luarocks + url = https://github.com/vancegroup/luarocks.git diff --git a/third-party/luarocks b/third-party/luarocks new file mode 160000 index 00000000..39c431a5 --- /dev/null +++ b/third-party/luarocks @@ -0,0 +1 @@ +Subproject commit 39c431a5f8607cbf570bcbd7db371f11b338cb51 From ba2f6ae8db31b83f03ffbd4cecb36e8f25d66010 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:19:13 -0500 Subject: [PATCH 02/35] Set up and actually go into luarocks --- third-party/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 0d31eb54..435d7f6b 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -11,8 +11,10 @@ if(BUILD_EMBEDDED_LUA) set(LUA_DEFINITIONS ${LUA_DEFINITIONS} PARENT_SCOPE) endif() add_subdirectory(lua-5.1.5/src) - set(LUA_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lua-5.1.5/src") + set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lua-5.1.5/src") + set(LUA_INCLUDE_DIRS "${LUA_INCLUDE_DIR}") set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIRS} PARENT_SCOPE) + set(LUA_LIBRARY lua) set(LUA_LIBRARIES lua) set(LUA_LIBRARIES ${LUA_LIBRARIES} PARENT_SCOPE) set(LUA51_FOUND YES) @@ -37,3 +39,6 @@ endif() add_subdirectory(stdlib/modules) add_subdirectory(lua_modules) + +set(LUA_INTERPRETER "lua-interp") +add_subdirectory(luarocks) From 81a0f3097e2de5780c51d778bcd784a9adb9f0ee Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:19:47 -0500 Subject: [PATCH 03/35] Build luafilesystem --- third-party/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 435d7f6b..399d66d5 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -42,3 +42,6 @@ add_subdirectory(lua_modules) set(LUA_INTERPRETER "lua-interp") add_subdirectory(luarocks) +include(luarocks/UseLuarocks.cmake) + +luarocks_install(luarocks-luafilesystem luafilesystem ${CMAKE_CURRENT_BINARY_DIR}/rockstree) From b71b0885239e680625080b2e439393991d1d0f1e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:23:42 -0500 Subject: [PATCH 04/35] Shift things to be more correct --- third-party/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 399d66d5..024e660b 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -17,6 +17,7 @@ if(BUILD_EMBEDDED_LUA) set(LUA_LIBRARY lua) set(LUA_LIBRARIES lua) set(LUA_LIBRARIES ${LUA_LIBRARIES} PARENT_SCOPE) + set(LUA_INTERPRETER "lua-interp") set(LUA51_FOUND YES) add_definitions(${LUA_DEFINITIONS}) @@ -40,7 +41,6 @@ add_subdirectory(stdlib/modules) add_subdirectory(lua_modules) -set(LUA_INTERPRETER "lua-interp") add_subdirectory(luarocks) include(luarocks/UseLuarocks.cmake) From 2dab2bfcb497e13590271c86ec8158224b010a4c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:32:44 -0500 Subject: [PATCH 05/35] Tidy message if submodule is missing. --- third-party/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 024e660b..99ed0619 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -41,7 +41,11 @@ add_subdirectory(stdlib/modules) add_subdirectory(lua_modules) -add_subdirectory(luarocks) -include(luarocks/UseLuarocks.cmake) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/luarocks/CMakeLists.txt") + add_subdirectory(luarocks) + include(luarocks/UseLuarocks.cmake) -luarocks_install(luarocks-luafilesystem luafilesystem ${CMAKE_CURRENT_BINARY_DIR}/rockstree) + luarocks_install(luarocks-luafilesystem luafilesystem ${CMAKE_CURRENT_BINARY_DIR}/rockstree) +else() + message(STATUS "NOTE: Skipping LuaRocks because the submodule is missing. Try 'git submodule update --init --recursive'") +endif() From ead5160a7dccec7b92b8b202f4b6dfeb665743d4 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:32:54 -0500 Subject: [PATCH 06/35] Make the suffix empty --- third-party/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 99ed0619..f3094dbd 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -42,6 +42,7 @@ add_subdirectory(stdlib/modules) add_subdirectory(lua_modules) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/luarocks/CMakeLists.txt") + set(LUAROCKS_LUA_SUFFIX "") add_subdirectory(luarocks) include(luarocks/UseLuarocks.cmake) From a31c09032c6035a64db4742694beabb15b110b2c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:52:45 -0500 Subject: [PATCH 07/35] make achieving luarocks a gauntlet that we skip if building lua as cpp --- third-party/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index f3094dbd..97f659b0 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -41,12 +41,16 @@ add_subdirectory(stdlib/modules) add_subdirectory(lua_modules) -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/luarocks/CMakeLists.txt") +if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/luarocks/CMakeLists.txt") + message(STATUS "NOTE: Skipping LuaRocks because the submodule is missing. Try 'git submodule update --init --recursive'") + +elseif(BUILD_LUA_AS_CPP) + message(STATUS "NOTE: Skipping LuaRocks because BUILD_LUA_AS_CPP is set which would confuse most compiled modules.") + +else() set(LUAROCKS_LUA_SUFFIX "") add_subdirectory(luarocks) include(luarocks/UseLuarocks.cmake) luarocks_install(luarocks-luafilesystem luafilesystem ${CMAKE_CURRENT_BINARY_DIR}/rockstree) -else() - message(STATUS "NOTE: Skipping LuaRocks because the submodule is missing. Try 'git submodule update --init --recursive'") endif() From cad2a3a31d0828aeb82914bf8c9925b89c0ee8ae Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 14 Mar 2012 16:57:49 -0500 Subject: [PATCH 08/35] Install luasocket (using our modified rockspec) --- third-party/CMakeLists.txt | 2 + third-party/luasocket-2.0.2-5.rockspec | 65 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 third-party/luasocket-2.0.2-5.rockspec diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 97f659b0..580a18cb 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -53,4 +53,6 @@ else() include(luarocks/UseLuarocks.cmake) luarocks_install(luarocks-luafilesystem luafilesystem ${CMAKE_CURRENT_BINARY_DIR}/rockstree) + + luarocks_install(luarocks-luasocket "${CMAKE_CURRENT_SOURCE_DIR}/luasocket-2.0.2-5.rockspec" ${CMAKE_CURRENT_BINARY_DIR}/rockstree) endif() diff --git a/third-party/luasocket-2.0.2-5.rockspec b/third-party/luasocket-2.0.2-5.rockspec new file mode 100644 index 00000000..164d4319 --- /dev/null +++ b/third-party/luasocket-2.0.2-5.rockspec @@ -0,0 +1,65 @@ +-- This is an unofficial modified version of the 2.0.2-5 rockspec that replaces +-- the Windows build system so that it actually works. + +package = "LuaSocket" +version = "2.0.2-5" +source = { + url = "http://luaforge.net/frs/download.php/2664/luasocket-2.0.2.tar.gz", + md5 = "41445b138deb7bcfe97bff957503da8e" +} +description = { + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library that is composed by two parts: a C core + that provides support for the TCP and UDP transport layers, and a set of Lua + modules that add support for functionality commonly needed by applications + that deal with the Internet. + ]], + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.2" +} +build = { + type = "make", + build_variables = { + CFLAGS = "$(CFLAGS) -DLUASOCKET_DEBUG -I$(LUA_INCDIR)", + LDFLAGS = "$(LIBFLAG) -O -fpic", + LD = "$(CC)" + }, + install_variables = { + INSTALL_TOP_SHARE = "$(LUADIR)", + INSTALL_TOP_LIB = "$(LIBDIR)" + }, + platforms = { + macosx = { + build_variables = { + CFLAGS = "$(CFLAGS) -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN -fno-common -I$(LUA_INCDIR)" + } + }, + windows={ + type="builtin", + modules = { + ["ltn12"] = "src/ltn12.lua", + mime = "src/mime.lua", + socket = "src/socket.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.http"] = "src/http.lua", + ["socket.smtp"] = "src/smtp.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.url"] = "src/url.lua", + ["mime.core"] = { + sources = {"src/mime.c"}, + defines = {"MIME_EXPORTS", "MIME_API=__declspec(dllexport)"} + }, + ["socket.core"] = { + sources = {"src/auxiliar.c", "src/buffer.c", "src/except.c", "src/inet.c", "src/io.c", "src/luasocket.c", "src/options.c", "src/select.c", "src/tcp.c", "src/timeout.c", "src/udp.c", "src/wsocket.c"}, + defines = {"LUASOCKET_EXPORTS", "LUASOCKET_API=__declspec(dllexport)"}, + libraries = {"ws2_32"} + } + } + } + }, + copy_directories = { "doc", "samples", "etc", "test" } +} From 3abae51a05c23b8207836bdec7b8e6fedbaa45a4 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Mar 2013 12:27:39 -0500 Subject: [PATCH 09/35] Upgrade to luarocks post-2.0.12 --- third-party/luarocks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/luarocks b/third-party/luarocks index 39c431a5..7138a60c 160000 --- a/third-party/luarocks +++ b/third-party/luarocks @@ -1 +1 @@ -Subproject commit 39c431a5f8607cbf570bcbd7db371f11b338cb51 +Subproject commit 7138a60c834cfbebebb108ee2a342b8579ee27c0 From 67c58dfc1173e1580e4874f12833a54341f7bdd0 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Mar 2013 12:29:19 -0500 Subject: [PATCH 10/35] Quote more things in the luarocks build. --- third-party/luarocks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/luarocks b/third-party/luarocks index 7138a60c..d5798de5 160000 --- a/third-party/luarocks +++ b/third-party/luarocks @@ -1 +1 @@ -Subproject commit 7138a60c834cfbebebb108ee2a342b8579ee27c0 +Subproject commit d5798de50c799b855be758cc0af3e5bc2f3d5ab0 From 4dc5c3eecb452e5f92e72ed602ba2cff96b79627 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Mar 2013 15:03:39 -0500 Subject: [PATCH 11/35] Only define LUA_BUILD_AS_DLL on Win32. --- third-party/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 580a18cb..4d4d1669 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -6,7 +6,7 @@ endif() if(BUILD_EMBEDDED_LUA) # Lua 5.1.5 - if(BUILD_SHARED_LUA) + if(BUILD_SHARED_LUA AND WIN32) set(LUA_DEFINITIONS "-DLUA_BUILD_AS_DLL") set(LUA_DEFINITIONS ${LUA_DEFINITIONS} PARENT_SCOPE) endif() From 717001911ebb8592b626fbbc0be79be0738d495e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Mar 2013 15:03:50 -0500 Subject: [PATCH 12/35] Add define LUA_DL_USE_RTLD_GLOBAL to fix osgLua --- third-party/lua-5.1.5/src/luaconf.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third-party/lua-5.1.5/src/luaconf.h b/third-party/lua-5.1.5/src/luaconf.h index d678de50..0423724b 100644 --- a/third-party/lua-5.1.5/src/luaconf.h +++ b/third-party/lua-5.1.5/src/luaconf.h @@ -757,7 +757,8 @@ union luai_Cast { double l_d; long l_l; }; ** without modifying the main part of the file. */ - +/* Required for osgLua to work properly. */ +#define LUA_DL_USE_RTLD_GLOBAL #endif From 9c257fc0e5214d1903f1f579ec228a53c28dc639 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Mar 2013 15:43:04 -0500 Subject: [PATCH 13/35] More "no need to define LUA_BUILD_AS_DLL when not Windows" --- third-party/lua-5.1.5/src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/third-party/lua-5.1.5/src/CMakeLists.txt b/third-party/lua-5.1.5/src/CMakeLists.txt index 31d6e4cc..4f6b35a6 100644 --- a/third-party/lua-5.1.5/src/CMakeLists.txt +++ b/third-party/lua-5.1.5/src/CMakeLists.txt @@ -89,7 +89,9 @@ set(LUA_EXTRA_LIBS ${LUA_EXTRA_LIBS} CACHE INTERNAL "" FORCE) if(BUILD_SHARED_LUA) set(LIBTYPE SHARED) - set(LUALIB_EXTRA_DEFINES LUA_BUILD_AS_DLL) + if(WIN32) + set(LUALIB_EXTRA_DEFINES LUA_BUILD_AS_DLL) + endif() else() set(LIBTYPE STATIC) set(LUALIB_EXTRA_DEFINES) From 783c0e7a02dfefff4e94db0ec917bad8428cdded Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 12 Mar 2013 15:44:13 -0500 Subject: [PATCH 14/35] Adjust/extend search path for Lua. --- vrjugglua/LuaPath.cpp | 11 +++++++++-- vrjugglua/LuaPath.h | 1 + vrjugglua/LuaScript.cpp | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/vrjugglua/LuaPath.cpp b/vrjugglua/LuaPath.cpp index ecd61a6a..e0a7e4f6 100644 --- a/vrjugglua/LuaPath.cpp +++ b/vrjugglua/LuaPath.cpp @@ -257,11 +257,18 @@ namespace vrjLua { } void LuaPath::addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash) { - _searchPaths.push_front(dirEndingInSlash + "?.lua"); - _searchPaths.push_front(dirEndingInSlash + "?"); + if (_searchPaths.empty()) { + _populateSearchPathsVector(state); + } + _pushFrontLuaRequirePath(dirEndingInSlash); updateLuaRequirePath(state); } + void LuaPath::_pushFrontLuaRequirePath(std::string const& dirEndingInSlash) { + _searchPaths.push_front(dirEndingInSlash + "?.lua"); + _searchPaths.push_front(dirEndingInSlash + "?/init.lua"); + } + void LuaPath::updateLuaRequirePath(LuaStatePtr state) { if (_searchPaths.empty()) { _populateSearchPathsVector(state); diff --git a/vrjugglua/LuaPath.h b/vrjugglua/LuaPath.h index d1318e67..bb6468fa 100644 --- a/vrjugglua/LuaPath.h +++ b/vrjugglua/LuaPath.h @@ -61,6 +61,7 @@ namespace vrjLua { static std::string _findFilePath(std::vector const& startingPlaces, std::string const& qualified); static std::string _findFilePath(std::string const& startingAt, std::string const& fn); + void _pushFrontLuaRequirePath(std::string const& dirEndingInSlash); void _populateSearchPathsVector(LuaStatePtr state); void _setLuaSearchPaths(LuaStatePtr state); std::string _findJuggler(); diff --git a/vrjugglua/LuaScript.cpp b/vrjugglua/LuaScript.cpp index f43d1079..a7093a26 100644 --- a/vrjugglua/LuaScript.cpp +++ b/vrjugglua/LuaScript.cpp @@ -328,8 +328,10 @@ namespace vrjLua { it = std::find(_searchPaths.begin(), _searchPaths.end(), "?.lua"); } - _searchPaths.push_front(_luaDir + "?.lua"); - _searchPaths.push_front(_luaDir + "?"); + // Add the custom items based on where we know we are. + _pushFrontLuaRequirePath(_luaDir); + _pushFrontLuaRequirePath(_root + "/share/lua/5.1/"); + _pushFrontLuaRequirePath(_root + "/lib/lua/5.1/"); } void LuaPath::_setLuaSearchPaths(LuaStatePtr state) { From 80e55a4925d1dd960a3e4e933a24da1dbdd4d782 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 13:07:46 -0500 Subject: [PATCH 15/35] Generate/install in root output dir. --- CMakeLists.txt | 3 +++ third-party/CMakeLists.txt | 4 ++-- third-party/luarocks | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fa4e2c6..d03197d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ endif() if(NOT SHARE_OUTPUT_DIRECTORY) set(SHARE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/share) endif() +if(NOT ROOT_OUTPUT_DIRECTORY) + set(ROOT_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +endif() # Define Simple Options option(BUILD_DOCS "Add a target to build documentation" on) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 4d4d1669..ebd66438 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -52,7 +52,7 @@ else() add_subdirectory(luarocks) include(luarocks/UseLuarocks.cmake) - luarocks_install(luarocks-luafilesystem luafilesystem ${CMAKE_CURRENT_BINARY_DIR}/rockstree) + luarocks_install(luarocks-luafilesystem luafilesystem "${ROOT_OUTPUT_DIRECTORY}") - luarocks_install(luarocks-luasocket "${CMAKE_CURRENT_SOURCE_DIR}/luasocket-2.0.2-5.rockspec" ${CMAKE_CURRENT_BINARY_DIR}/rockstree) + luarocks_install(luarocks-luasocket "${CMAKE_CURRENT_SOURCE_DIR}/luasocket-2.0.2-5.rockspec" "${ROOT_OUTPUT_DIRECTORY}") endif() diff --git a/third-party/luarocks b/third-party/luarocks index d5798de5..0c715354 160000 --- a/third-party/luarocks +++ b/third-party/luarocks @@ -1 +1 @@ -Subproject commit d5798de50c799b855be758cc0af3e5bc2f3d5ab0 +Subproject commit 0c715354438c8285cf84607c375e2694bfd948aa From 1dcba8dce309dec3b9fc961729432a05b25d3026 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 13:08:39 -0500 Subject: [PATCH 16/35] Add SearchPath simple class --- vrjugglua/CMakeLists.txt | 2 ++ vrjugglua/SearchPath.cpp | 55 +++++++++++++++++++++++++++++++++++++++ vrjugglua/SearchPath.h | 56 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 vrjugglua/SearchPath.cpp create mode 100644 vrjugglua/SearchPath.h diff --git a/vrjugglua/CMakeLists.txt b/vrjugglua/CMakeLists.txt index 149ae27f..054ea032 100644 --- a/vrjugglua/CMakeLists.txt +++ b/vrjugglua/CMakeLists.txt @@ -39,6 +39,7 @@ set(SOURCES LuaPath.cpp OsgAppProxy.cpp Reconfiguration.cpp + SearchPath.cpp SynchronizedRunBuffer.cpp VRJLua_C_Interface.cpp VRJLuaConfig.h.in) @@ -58,6 +59,7 @@ set(API LuaScript.h OsgAppProxy.h Reconfiguration.h + SearchPath.h SynchronizedRunBuffer.h VRJLua_C_Interface.h VRJLuaOutput.h) diff --git a/vrjugglua/SearchPath.cpp b/vrjugglua/SearchPath.cpp new file mode 100644 index 00000000..f9b98ede --- /dev/null +++ b/vrjugglua/SearchPath.cpp @@ -0,0 +1,55 @@ +/** + @file + @brief Implementation + + @date 2013 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Internal Includes +#include "SearchPath.h" + +// Library/third-party includes +#include +#include +#include + +#include + +// Standard includes +// - none + +namespace vrjLua { + + SearchPath::SearchPath(std::string const& input, const char * delim) { + boost::algorithm::split(_data, input, boost::algorithm::is_any_of(delim)); + _reapplyUniqueness(); + } + + void SearchPath::insertAt(StringList const& elts, size_t position) { + BOOST_ASSERT(position <= _data.size() && "Position is bound by the size of the existing list!"); + _data.insert(_data.begin() + position, elts.begin(), elts.end()); + _reapplyUniqueness(); + } + + std::string SearchPath::toString(const char * delim) const { + return boost::algorithm::join(_data, delim); + } + + void SearchPath::_reapplyUniqueness() { + StringList::iterator it = std::unique(_data.begin(), _data.end()); + _data.resize(std::distance(_data.begin(), it)); + } + +} diff --git a/vrjugglua/SearchPath.h b/vrjugglua/SearchPath.h new file mode 100644 index 00000000..3f797211 --- /dev/null +++ b/vrjugglua/SearchPath.h @@ -0,0 +1,56 @@ +/** @file + @brief Header + + @date 2013 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#pragma once +#ifndef INCLUDED_SearchPath_h_GUID_1091ef29_04ea_4776_a191_3d2bf5a56ecd +#define INCLUDED_SearchPath_h_GUID_1091ef29_04ea_4776_a191_3d2bf5a56ecd + +// Internal Includes +// - none + +// Library/third-party includes +// - none + +// Standard includes +#include +#include + +namespace vrjLua { + class SearchPath { + public: + static const char * defaultDelimiter() { + return ";"; + } + + typedef std::vector StringList; + + SearchPath(std::string const& input, const char * delim = defaultDelimiter()); + + void insertAt(StringList const& elts, size_t position = 0); + + std::string toString(const char * delim = defaultDelimiter()) const; + private: + StringList _data; + + void _reapplyUniqueness(); + }; + + +} + +#endif // INCLUDED_SearchPath_h_GUID_1091ef29_04ea_4776_a191_3d2bf5a56ecd From 303cec46ffc6b944203194c98f30ec03c3ed96a2 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 15:46:30 -0500 Subject: [PATCH 17/35] Cleanup --- vrjugglua/SearchPath.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/vrjugglua/SearchPath.cpp b/vrjugglua/SearchPath.cpp index f9b98ede..2ee3915f 100644 --- a/vrjugglua/SearchPath.cpp +++ b/vrjugglua/SearchPath.cpp @@ -31,7 +31,6 @@ // - none namespace vrjLua { - SearchPath::SearchPath(std::string const& input, const char * delim) { boost::algorithm::split(_data, input, boost::algorithm::is_any_of(delim)); _reapplyUniqueness(); From 8707ebe07c03c518a5f119ede534e168f9d5b6ec Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 15:46:41 -0500 Subject: [PATCH 18/35] AddToLuaPath --- vrjugglua/AddToLuaPaths.cpp | 192 ++++++++++++++++++++++++++++++++++++ vrjugglua/AddToLuaPaths.h | 167 +++++++++++++++++++++++++++++++ vrjugglua/CMakeLists.txt | 2 + 3 files changed, 361 insertions(+) create mode 100644 vrjugglua/AddToLuaPaths.cpp create mode 100644 vrjugglua/AddToLuaPaths.h diff --git a/vrjugglua/AddToLuaPaths.cpp b/vrjugglua/AddToLuaPaths.cpp new file mode 100644 index 00000000..465e01a2 --- /dev/null +++ b/vrjugglua/AddToLuaPaths.cpp @@ -0,0 +1,192 @@ +/** + @file + @brief Implementation + + @date 2013 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Internal Includes +#include "AddToLuaPaths.h" + +// Library/third-party includes +#include + +// Standard includes +// - none + +namespace vrjLua { +#define LUA_VER "5.1" + +#if 0 + + static const char * luadirsFromRoot[] = { + "etc/vrjugglua/", + "share/vrjugglua/lua/", + "share/lua/" LUA_VER "/", + "lib/lua/" LUA_VER "/" + }; + + + + static const char * luacdirsFromRoot[] = { + "lib/lua/" LUA_VER "/", + "lib/" + }; + + template + inline void callWithLuaCSearchPatterns(std::string const& dir, F func) { + func(dir + luaCPattern); + } + + template + inline void callWithLuaRootSearchPatterns(std::string const& rootdir, F func) { + BOOST_FOREACH(const char * patt, luadirsFromRoot) { + callWithLuaSearchPatterns(rootdir + patt, func); + } + } + + template + inline void callWithLuaRootCSearchPatterns(std::string const& rootdir, F func) { + BOOST_FOREACH(const char * patt, luacdirsFromRoot) { + callWithLuaCSearchPatterns(rootdir + patt, func); + } + } + + void addRootToLuaPath(SearchPath & p, std::string const& root) { + std::string rootdir = ensureTrailingSlash(root); + StringList newpaths; + callWithLuaRootSearchPatterns(root, PushBackFunctor(newpaths)); + p.insertAt(newpaths, 1); + } + + void addRootToLuaCPath(SearchPath & p, std::string const& root) { + std::string rootdir = ensureTrailingSlash(root); + StringList newpaths; + callWithLuaRootCSearchPatterns(root, PushBackFunctor(newpaths)); + p.insertAt(newpaths, 1); + } + +#endif + + namespace { + typedef std::vector StringList; + template + class PushBackFunctor { + public: + PushBackFunctor(T & container) : _container(container) {} + void operator()(typename T::value_type a) { + _container.push_back(a); + } + private: + T & _container; + }; + + + } // end of namespace + + template + struct GetDirsFromRoot { + static const char * dirs[]; + }; + + /* + template<> + struct GetDirsFromRoot + template<> + struct GetDirsFromRoot { + static const char * dirs[] = { + "lib/lua/" LUA_VER "/", + "lib/" + }; + }; + */ + template<> + const char * GetDirsFromRoot::dirs[] = { + "etc/vrjugglua/", + "share/vrjugglua/lua/", + "share/lua/" LUA_VER "/", + "lib/lua/" LUA_VER "/" + }; + template<> + const char * GetDirsFromRoot::dirs[] = { + "etc/vrjugglua/", + "share/vrjugglua/lua/", + "share/lua/" LUA_VER "/", + "lib/lua/" LUA_VER "/" + }; + template + struct CallWithPatterns; + + template<> + struct CallWithPatterns { + template + static void apply(std::string const& dir, F func) { + static const char * luaPatterns[] = { + "?.lua", + "?/init.lua" + }; + BOOST_FOREACH(const char * patt, luaPatterns) { + func(dir + patt); + } + } + }; + + template<> + struct CallWithPatterns { + template + static void apply(std::string const& dir, F func) { +#ifdef _WIN32 + static const char luaCPattern[] = "?.dll"; +#else + static const char luaCPattern[] = "?.so"; +#endif + func(dir + luaCPattern); + } + }; + + + template + struct CallWithDirectory; + + template + struct CallWithDirectory { + template + static void apply(std::string const& rootdir, F func) { + BOOST_FOREACH(const char * patt, GetDirsFromRoot::dirs) { + CallWithPatterns::apply(rootdir + patt, func); + } + } + }; + + template + struct CallWithDirectory { + template + static void apply(std::string const& rootdir, F func) { + CallWithPatterns::apply(rootdir, func); + } + }; + + template + void extendLuaSearchPath(DirectoryBase & d, SearchPathContainerBase & s) { + StringList newpaths; + CallWithDirectory::apply(d.get(), PushBackFunctor(newpaths)); + s.insert(newpaths); + } + + template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); +} // end of namespace vrjLua diff --git a/vrjugglua/AddToLuaPaths.h b/vrjugglua/AddToLuaPaths.h new file mode 100644 index 00000000..1b87eeef --- /dev/null +++ b/vrjugglua/AddToLuaPaths.h @@ -0,0 +1,167 @@ +/** @file + @brief Header + + @date 2013 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#pragma once +#ifndef INCLUDED_AddToLuaPaths_h_GUID_7c879366_eb17_457c_be5c_cd606e6943a2 +#define INCLUDED_AddToLuaPaths_h_GUID_7c879366_eb17_457c_be5c_cd606e6943a2 + +// Internal Includes +#include "SearchPath.h" + +// Library/third-party includes +#include +#include +#include + +// Standard includes +// - none + + +namespace vrjLua { + + + + inline std::string ensureTrailingSlash(std::string dir) { + if (dir.size() > 0) { + const char back = *(dir.end() - 1); + if (back != '/' && back != '\\') { + dir += '/'; + } + } + return dir; + } + + namespace LuaPathTags { + struct RootDirectory; + struct SearchDirectory; + struct LuaSearch; + struct LuaCSearch; + }; + + template + class DirectoryBase { + public: + DirectoryBase(std::string const& dir) + : _dir(ensureTrailingSlash(dir)) + {} + std::string const& get() const { + return _dir; + } + private: + std::string const _dir; + + }; + + class RootDirectory : DirectoryBase { + public: + RootDirectory(std::string const& dir) + : DirectoryBase(dir) {} + }; + + class SearchDirectory : DirectoryBase { + public: + SearchDirectory(std::string const& dir) + : DirectoryBase(dir) {} + }; + + template + class SearchPathContainerBase { + public: + SearchPathContainerBase(SearchPath const& p) + : _path(p) {} + + void insert(std::vector const& patterns) { + _path.insertAt(patterns, 1); + } + std::string toString() { + return _path.toString(); + } + private: + SearchPath _path; + }; + + class LuaSearchPath : SearchPathContainerBase { + public: + LuaSearchPath(std::string const& s) : SearchPathContainerBase(s) {} + }; + class LuaCSearchPath : SearchPathContainerBase { + public: + LuaCSearchPath(std::string const& s) : SearchPathContainerBase(s) {} + }; + + template + void extendLuaSearchPath(DirectoryBase & d, SearchPathContainerBase & s); + + /* + class LuaSearchPattern { + + }; + + class CatFirstTransform { + public: + CatFirstTransform(std::string const& s) : _s(s) {} + template + std::string operator()(T const& a) { + return _s + a; + } + private: + std::string const _s; + }; + + class CatSecondTransform { + public: + CatSecondTransform(std::string const& s) : _s(s) {} + template + std::string operator()(T const& a) { + return a + _s; + } + private: + std::string const _s; + }; + + + class RootDirectory { + public: + RootDirectory(std::string const& dir) + : _dir(ensureTrailingSlash(dir)) + {} + + typedef boost::array LuaDirSuffixesType; + typedef boost::array LuaCDirSuffixesType; + + typedef boost::iterator_range > lua_dir_range_type; + getLuaDirs() const; + + typedef boost::iterator_range > lua_cdir_range_type; + boost::iterator_range > + getLuaCDirs() const; + std::string const& get() const { + return _dir; + } + private: + static const LuaDirSuffixesType s_luaDirs; + static const LuaCDirSuffixesType s_luaCDirs; + const std::string _dir; + }; + + */ + void addRootToLuaPath(SearchPath & p, std::string const& root); + +} // end of namespace vrjLua + +#endif // INCLUDED_AddToLuaPaths_h_GUID_7c879366_eb17_457c_be5c_cd606e6943a2 diff --git a/vrjugglua/CMakeLists.txt b/vrjugglua/CMakeLists.txt index 054ea032..cbb874d1 100644 --- a/vrjugglua/CMakeLists.txt +++ b/vrjugglua/CMakeLists.txt @@ -27,6 +27,7 @@ add_subdirectory(lua) add_subdirectory(constants) set(SOURCES + AddToLuaPaths.cpp FindVPRDLL.cpp FindVPRDLL.h Internal_AnalogInterface.cpp @@ -45,6 +46,7 @@ set(SOURCES VRJLuaConfig.h.in) set(API + AddToLuaPaths.h osgLuaBind.h Internal_AnalogInterface.h Internal_DigitalInterface.h From 26fdfc2b7496459d8febd4606e56daa92c52ac6e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 16:30:22 -0500 Subject: [PATCH 19/35] Clean up and fix --- vrjugglua/AddToLuaPaths.cpp | 79 +++++-------------------------------- vrjugglua/AddToLuaPaths.h | 75 ++++++++--------------------------- vrjugglua/SearchPath.cpp | 4 ++ vrjugglua/SearchPath.h | 3 ++ 4 files changed, 32 insertions(+), 129 deletions(-) diff --git a/vrjugglua/AddToLuaPaths.cpp b/vrjugglua/AddToLuaPaths.cpp index 465e01a2..8db0bc36 100644 --- a/vrjugglua/AddToLuaPaths.cpp +++ b/vrjugglua/AddToLuaPaths.cpp @@ -29,59 +29,7 @@ namespace vrjLua { #define LUA_VER "5.1" -#if 0 - - static const char * luadirsFromRoot[] = { - "etc/vrjugglua/", - "share/vrjugglua/lua/", - "share/lua/" LUA_VER "/", - "lib/lua/" LUA_VER "/" - }; - - - - static const char * luacdirsFromRoot[] = { - "lib/lua/" LUA_VER "/", - "lib/" - }; - - template - inline void callWithLuaCSearchPatterns(std::string const& dir, F func) { - func(dir + luaCPattern); - } - - template - inline void callWithLuaRootSearchPatterns(std::string const& rootdir, F func) { - BOOST_FOREACH(const char * patt, luadirsFromRoot) { - callWithLuaSearchPatterns(rootdir + patt, func); - } - } - - template - inline void callWithLuaRootCSearchPatterns(std::string const& rootdir, F func) { - BOOST_FOREACH(const char * patt, luacdirsFromRoot) { - callWithLuaCSearchPatterns(rootdir + patt, func); - } - } - - void addRootToLuaPath(SearchPath & p, std::string const& root) { - std::string rootdir = ensureTrailingSlash(root); - StringList newpaths; - callWithLuaRootSearchPatterns(root, PushBackFunctor(newpaths)); - p.insertAt(newpaths, 1); - } - - void addRootToLuaCPath(SearchPath & p, std::string const& root) { - std::string rootdir = ensureTrailingSlash(root); - StringList newpaths; - callWithLuaRootCSearchPatterns(root, PushBackFunctor(newpaths)); - p.insertAt(newpaths, 1); - } - -#endif - namespace { - typedef std::vector StringList; template class PushBackFunctor { public: @@ -92,8 +40,6 @@ namespace vrjLua { private: T & _container; }; - - } // end of namespace template @@ -101,17 +47,6 @@ namespace vrjLua { static const char * dirs[]; }; - /* - template<> - struct GetDirsFromRoot - template<> - struct GetDirsFromRoot { - static const char * dirs[] = { - "lib/lua/" LUA_VER "/", - "lib/" - }; - }; - */ template<> const char * GetDirsFromRoot::dirs[] = { "etc/vrjugglua/", @@ -119,6 +54,7 @@ namespace vrjLua { "share/lua/" LUA_VER "/", "lib/lua/" LUA_VER "/" }; + template<> const char * GetDirsFromRoot::dirs[] = { "etc/vrjugglua/", @@ -126,6 +62,7 @@ namespace vrjLua { "share/lua/" LUA_VER "/", "lib/lua/" LUA_VER "/" }; + template struct CallWithPatterns; @@ -179,14 +116,16 @@ namespace vrjLua { }; template - void extendLuaSearchPath(DirectoryBase & d, SearchPathContainerBase & s) { + void extendLuaSearchPath(DirectoryBase const& d, SearchPathContainerBase & s) { + typedef std::vector StringList; StringList newpaths; CallWithDirectory::apply(d.get(), PushBackFunctor(newpaths)); s.insert(newpaths); } - template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); - template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); - template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); - template void extendLuaSearchPath(DirectoryBase &, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + } // end of namespace vrjLua diff --git a/vrjugglua/AddToLuaPaths.h b/vrjugglua/AddToLuaPaths.h index 1b87eeef..125f84c8 100644 --- a/vrjugglua/AddToLuaPaths.h +++ b/vrjugglua/AddToLuaPaths.h @@ -67,13 +67,13 @@ namespace vrjLua { }; - class RootDirectory : DirectoryBase { + class RootDirectory : public DirectoryBase { public: RootDirectory(std::string const& dir) : DirectoryBase(dir) {} }; - class SearchDirectory : DirectoryBase { + class SearchDirectory : public DirectoryBase { public: SearchDirectory(std::string const& dir) : DirectoryBase(dir) {} @@ -85,9 +85,17 @@ namespace vrjLua { SearchPathContainerBase(SearchPath const& p) : _path(p) {} + SearchPathContainerBase() + : _path() {} + + void set(std::string const& s) { + _path.set(s); + } + void insert(std::vector const& patterns) { _path.insertAt(patterns, 1); } + std::string toString() { return _path.toString(); } @@ -95,72 +103,21 @@ namespace vrjLua { SearchPath _path; }; - class LuaSearchPath : SearchPathContainerBase { + class LuaSearchPath : public SearchPathContainerBase { public: LuaSearchPath(std::string const& s) : SearchPathContainerBase(s) {} + LuaSearchPath() : SearchPathContainerBase() {} }; - class LuaCSearchPath : SearchPathContainerBase { + + class LuaCSearchPath : public SearchPathContainerBase { public: LuaCSearchPath(std::string const& s) : SearchPathContainerBase(s) {} + LuaCSearchPath() : SearchPathContainerBase() {} }; template - void extendLuaSearchPath(DirectoryBase & d, SearchPathContainerBase & s); - - /* - class LuaSearchPattern { - - }; - - class CatFirstTransform { - public: - CatFirstTransform(std::string const& s) : _s(s) {} - template - std::string operator()(T const& a) { - return _s + a; - } - private: - std::string const _s; - }; - - class CatSecondTransform { - public: - CatSecondTransform(std::string const& s) : _s(s) {} - template - std::string operator()(T const& a) { - return a + _s; - } - private: - std::string const _s; - }; - - - class RootDirectory { - public: - RootDirectory(std::string const& dir) - : _dir(ensureTrailingSlash(dir)) - {} - - typedef boost::array LuaDirSuffixesType; - typedef boost::array LuaCDirSuffixesType; - - typedef boost::iterator_range > lua_dir_range_type; - getLuaDirs() const; - - typedef boost::iterator_range > lua_cdir_range_type; - boost::iterator_range > - getLuaCDirs() const; - std::string const& get() const { - return _dir; - } - private: - static const LuaDirSuffixesType s_luaDirs; - static const LuaCDirSuffixesType s_luaCDirs; - const std::string _dir; - }; + extern void extendLuaSearchPath(DirectoryBase const& d, SearchPathContainerBase & s); - */ - void addRootToLuaPath(SearchPath & p, std::string const& root); } // end of namespace vrjLua diff --git a/vrjugglua/SearchPath.cpp b/vrjugglua/SearchPath.cpp index 2ee3915f..023d385b 100644 --- a/vrjugglua/SearchPath.cpp +++ b/vrjugglua/SearchPath.cpp @@ -32,6 +32,10 @@ namespace vrjLua { SearchPath::SearchPath(std::string const& input, const char * delim) { + set(input, delim); + } + + void SearchPath::set(std::string const& input, const char * delim) { boost::algorithm::split(_data, input, boost::algorithm::is_any_of(delim)); _reapplyUniqueness(); } diff --git a/vrjugglua/SearchPath.h b/vrjugglua/SearchPath.h index 3f797211..1a5521ca 100644 --- a/vrjugglua/SearchPath.h +++ b/vrjugglua/SearchPath.h @@ -39,8 +39,11 @@ namespace vrjLua { typedef std::vector StringList; + SearchPath() {} SearchPath(std::string const& input, const char * delim = defaultDelimiter()); + void set(std::string const& input, const char * delim = defaultDelimiter()); + void insertAt(StringList const& elts, size_t position = 0); std::string toString(const char * delim = defaultDelimiter()) const; From cca7ed4515bf4ba6284788d225b7c6042248a187 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 16:30:46 -0500 Subject: [PATCH 20/35] Remove unused methods --- vrjugglua/LuaPath.cpp | 8 -------- vrjugglua/LuaPath.h | 3 --- 2 files changed, 11 deletions(-) diff --git a/vrjugglua/LuaPath.cpp b/vrjugglua/LuaPath.cpp index e0a7e4f6..aabd6277 100644 --- a/vrjugglua/LuaPath.cpp +++ b/vrjugglua/LuaPath.cpp @@ -248,14 +248,6 @@ namespace vrjLua { return _initialPath; } - std::string LuaPath::getPathToLuaScript(const std::string & scriptfn) const { - return (fs::path(_luaDir) / scriptfn).string(); - } - - void LuaPath::chdir(std::string const& path) { - fs::current_path(path); - } - void LuaPath::addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash) { if (_searchPaths.empty()) { _populateSearchPathsVector(state); diff --git a/vrjugglua/LuaPath.h b/vrjugglua/LuaPath.h index bb6468fa..bd93fe83 100644 --- a/vrjugglua/LuaPath.h +++ b/vrjugglua/LuaPath.h @@ -46,9 +46,6 @@ namespace vrjLua { std::string const& getShareDir() const; std::string const& getExeDir() const; std::string const& getInitialPath() const; - std::string getPathToLuaScript(const std::string & scriptfn) const; - - void chdir(std::string const& path); void addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash); void updateLuaRequirePath(LuaStatePtr state); From c0bd706a45ba45ee7ab062f15d990e54fc060c9c Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 16:41:43 -0500 Subject: [PATCH 21/35] add method to LuaPath to get the lua directory. --- vrjugglua/LuaPath.cpp | 3 +++ vrjugglua/LuaPath.h | 1 + 2 files changed, 4 insertions(+) diff --git a/vrjugglua/LuaPath.cpp b/vrjugglua/LuaPath.cpp index aabd6277..90e59cd2 100644 --- a/vrjugglua/LuaPath.cpp +++ b/vrjugglua/LuaPath.cpp @@ -247,6 +247,9 @@ namespace vrjLua { std::string const& LuaPath::getInitialPath() const { return _initialPath; } + std::string const& LuaPath::getLuaDir() const { + return _luaDir; + } void LuaPath::addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash) { if (_searchPaths.empty()) { diff --git a/vrjugglua/LuaPath.h b/vrjugglua/LuaPath.h index bd93fe83..b10b36ea 100644 --- a/vrjugglua/LuaPath.h +++ b/vrjugglua/LuaPath.h @@ -46,6 +46,7 @@ namespace vrjLua { std::string const& getShareDir() const; std::string const& getExeDir() const; std::string const& getInitialPath() const; + std::string const& getLuaDir() const; void addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash); void updateLuaRequirePath(LuaStatePtr state); From 1a442d86244bfe0919c66797bdb36fa96d497b2a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 16:43:11 -0500 Subject: [PATCH 22/35] Replace usage of the luapath object to do the dirty work of updating the package path --- vrjugglua/LuaScript.cpp | 13 ++++++++++++- vrjugglua/binding_detail/BindvrjLuaToLua.inl | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/vrjugglua/LuaScript.cpp b/vrjugglua/LuaScript.cpp index a7093a26..0af1b3fc 100644 --- a/vrjugglua/LuaScript.cpp +++ b/vrjugglua/LuaScript.cpp @@ -24,6 +24,7 @@ #include "OsgAppProxy.h" #include "LuaPath.h" +#include "AddToLuaPaths.h" #include "LuaGCBlock.h" #include "VRJLuaOutput.h" @@ -215,7 +216,17 @@ namespace vrjLua { // Extend the lua script search path for "require" LuaPath& lp = LuaPath::instance(); - lp.updateLuaRequirePath(_state); + { + luabind::object package(luabind::globals(_state.get())["package"]); + + LuaSearchPath searchpath(object_cast(package["path"])); + extendLuaSearchPath(SearchDirectory(lp.getLuaDir()), searchpath); + extendLuaSearchPath(RootDirectory(lp.getRootDir()), searchpath); + package["path"] = searchpath.toString(); + + /// @todo c search path + //LuaCSearchPath csearchpath(object_cast(package["path"])); + } // osgLua bindOsgToLua(_state); diff --git a/vrjugglua/binding_detail/BindvrjLuaToLua.inl b/vrjugglua/binding_detail/BindvrjLuaToLua.inl index 65e67bdd..690b88e1 100644 --- a/vrjugglua/binding_detail/BindvrjLuaToLua.inl +++ b/vrjugglua/binding_detail/BindvrjLuaToLua.inl @@ -22,6 +22,7 @@ #include "BindvrjLuaToLua.h" #include #include +#include #include // Library/third-party includes @@ -61,7 +62,11 @@ namespace vrjLua { if (p[p.size() - 1] != '/') { p.push_back('/'); } - LuaPath::instance().addLuaRequirePath(borrowStatePtr(s), path); + luabind::object package(luabind::globals(s)["package"]); + + LuaSearchPath searchpath(object_cast(package["path"])); + extendLuaSearchPath(SearchDirectory(path), searchpath); + package["path"] = searchpath.toString(); } static luabind::object getModelSearchPath(lua_State *L) { From 2fc416254ee5b5765d4bde0d3916bb206f00378a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 16:46:44 -0500 Subject: [PATCH 23/35] Remove dead code we just replaced. --- vrjugglua/LuaPath.cpp | 20 -------------------- vrjugglua/LuaPath.h | 9 --------- vrjugglua/LuaScript.cpp | 37 ------------------------------------- 3 files changed, 66 deletions(-) diff --git a/vrjugglua/LuaPath.cpp b/vrjugglua/LuaPath.cpp index 90e59cd2..8c67abaa 100644 --- a/vrjugglua/LuaPath.cpp +++ b/vrjugglua/LuaPath.cpp @@ -251,26 +251,6 @@ namespace vrjLua { return _luaDir; } - void LuaPath::addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash) { - if (_searchPaths.empty()) { - _populateSearchPathsVector(state); - } - _pushFrontLuaRequirePath(dirEndingInSlash); - updateLuaRequirePath(state); - } - - void LuaPath::_pushFrontLuaRequirePath(std::string const& dirEndingInSlash) { - _searchPaths.push_front(dirEndingInSlash + "?.lua"); - _searchPaths.push_front(dirEndingInSlash + "?/init.lua"); - } - - void LuaPath::updateLuaRequirePath(LuaStatePtr state) { - if (_searchPaths.empty()) { - _populateSearchPathsVector(state); - } - _setLuaSearchPaths(state); - } - bool LuaPath::_setJugglerEnvironment() const { bool ret; if (_foundJuggler) { diff --git a/vrjugglua/LuaPath.h b/vrjugglua/LuaPath.h index b10b36ea..20e891cb 100644 --- a/vrjugglua/LuaPath.h +++ b/vrjugglua/LuaPath.h @@ -48,10 +48,6 @@ namespace vrjLua { std::string const& getInitialPath() const; std::string const& getLuaDir() const; - void addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash); - void updateLuaRequirePath(LuaStatePtr state); - - protected: LuaPath(); void _init(std::string const& arg0, std::string const& vrjlua_base); @@ -59,9 +55,6 @@ namespace vrjLua { static std::string _findFilePath(std::vector const& startingPlaces, std::string const& qualified); static std::string _findFilePath(std::string const& startingAt, std::string const& fn); - void _pushFrontLuaRequirePath(std::string const& dirEndingInSlash); - void _populateSearchPathsVector(LuaStatePtr state); - void _setLuaSearchPaths(LuaStatePtr state); std::string _findJuggler(); bool _setJugglerEnvironment() const; @@ -76,8 +69,6 @@ namespace vrjLua { std::string _jugglerRoot; bool _valid; - - std::deque _searchPaths; }; // -- inline implementations -- / diff --git a/vrjugglua/LuaScript.cpp b/vrjugglua/LuaScript.cpp index 0af1b3fc..1c0f0ca8 100644 --- a/vrjugglua/LuaScript.cpp +++ b/vrjugglua/LuaScript.cpp @@ -319,41 +319,4 @@ namespace vrjLua { << VRJLUA_MSG_END(dbgVRJLUA_APP, MSG_STATUS); } } - - - void LuaPath::_populateSearchPathsVector(LuaStatePtr state) { - luabind::object package = luabind::globals(state.get())["package"]; - std::string input = luabind::object_cast(package["path"]); - boost::algorithm::split(_searchPaths, input, boost::is_any_of(";")); - - // Remove the items we'll add ourselves. - std::deque::iterator it = std::find(_searchPaths.begin(), _searchPaths.end(), "?"); - while (it != _searchPaths.end()) { - _searchPaths.erase(it); - it = std::find(_searchPaths.begin(), _searchPaths.end(), "?"); - } - - it = std::find(_searchPaths.begin(), _searchPaths.end(), "?.lua"); - while (it != _searchPaths.end()) { - _searchPaths.erase(it); - it = std::find(_searchPaths.begin(), _searchPaths.end(), "?.lua"); - } - - // Add the custom items based on where we know we are. - _pushFrontLuaRequirePath(_luaDir); - _pushFrontLuaRequirePath(_root + "/share/lua/5.1/"); - _pushFrontLuaRequirePath(_root + "/lib/lua/5.1/"); - } - - void LuaPath::_setLuaSearchPaths(LuaStatePtr state) { - std::ostringstream scr; - scr << "?;"; - scr << "?.lua;"; - for (unsigned int i = 0; i < _searchPaths.size(); ++i) { - scr << _searchPaths[i] << ";"; - } - luabind::object package = luabind::globals(state.get())["package"]; - package["path"] = scr.str(); - } - } // end of vrjLua namespace From 01aeff37b5b98a19ae8ce25bcaa9ba0812b2a3ce Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:00:43 -0500 Subject: [PATCH 24/35] Clean up and re-organize a bit. --- vrjugglua/AddToLuaPaths.cpp | 151 ++++++++++++++++++------------------ vrjugglua/AddToLuaPaths.h | 118 ++++++++++++++-------------- vrjugglua/SearchPath.cpp | 4 - vrjugglua/SearchPath.h | 3 - 4 files changed, 136 insertions(+), 140 deletions(-) diff --git a/vrjugglua/AddToLuaPaths.cpp b/vrjugglua/AddToLuaPaths.cpp index 8db0bc36..1a8ae5f9 100644 --- a/vrjugglua/AddToLuaPaths.cpp +++ b/vrjugglua/AddToLuaPaths.cpp @@ -42,90 +42,93 @@ namespace vrjLua { }; } // end of namespace - template - struct GetDirsFromRoot { - static const char * dirs[]; - }; - - template<> - const char * GetDirsFromRoot::dirs[] = { - "etc/vrjugglua/", - "share/vrjugglua/lua/", - "share/lua/" LUA_VER "/", - "lib/lua/" LUA_VER "/" - }; - - template<> - const char * GetDirsFromRoot::dirs[] = { - "etc/vrjugglua/", - "share/vrjugglua/lua/", - "share/lua/" LUA_VER "/", - "lib/lua/" LUA_VER "/" - }; - - template - struct CallWithPatterns; - - template<> - struct CallWithPatterns { - template - static void apply(std::string const& dir, F func) { - static const char * luaPatterns[] = { - "?.lua", - "?/init.lua" - }; - BOOST_FOREACH(const char * patt, luaPatterns) { - func(dir + patt); + namespace detail { + template + struct GetDirsFromRoot { + static const char * dirs[]; + }; + + template<> + const char * GetDirsFromRoot::dirs[] = { + "etc/vrjugglua/", + "share/vrjugglua/lua/", + "share/lua/" LUA_VER "/", + "lib/lua/" LUA_VER "/" + }; + + template<> + const char * GetDirsFromRoot::dirs[] = { + "etc/vrjugglua/", + "share/vrjugglua/lua/", + "share/lua/" LUA_VER "/", + "lib/lua/" LUA_VER "/" + }; + + template + struct CallWithPatterns; + + template<> + struct CallWithPatterns { + template + static void apply(std::string const& dir, F func) { + static const char * luaPatterns[] = { + "?.lua", + "?/init.lua" + }; + BOOST_FOREACH(const char * patt, luaPatterns) { + func(dir + patt); + } } - } - }; + }; - template<> - struct CallWithPatterns { - template - static void apply(std::string const& dir, F func) { + template<> + struct CallWithPatterns { + template + static void apply(std::string const& dir, F func) { #ifdef _WIN32 - static const char luaCPattern[] = "?.dll"; + static const char luaCPattern[] = "?.dll"; #else - static const char luaCPattern[] = "?.so"; + static const char luaCPattern[] = "?.so"; #endif - func(dir + luaCPattern); - } - }; + func(dir + luaCPattern); + } + }; - template - struct CallWithDirectory; + template + struct CallWithDirectory; - template - struct CallWithDirectory { - template - static void apply(std::string const& rootdir, F func) { - BOOST_FOREACH(const char * patt, GetDirsFromRoot::dirs) { - CallWithPatterns::apply(rootdir + patt, func); + template + struct CallWithDirectory { + template + static void apply(std::string const& rootdir, F func) { + BOOST_FOREACH(const char * patt, GetDirsFromRoot::dirs) { + CallWithPatterns::apply(rootdir + patt, func); + } } - } - }; + }; - template - struct CallWithDirectory { - template - static void apply(std::string const& rootdir, F func) { - CallWithPatterns::apply(rootdir, func); + template + struct CallWithDirectory { + template + static void apply(std::string const& rootdir, F func) { + CallWithPatterns::apply(rootdir, func); + } + }; + + template + void extendLuaSearchPath(DirectoryBase const& d, SearchPathContainerBase & s) { + typedef std::vector StringList; + StringList newpaths; + CallWithDirectory::apply(d.get(), PushBackFunctor(newpaths)); + s.insert(newpaths); } - }; - - template - void extendLuaSearchPath(DirectoryBase const& d, SearchPathContainerBase & s) { - typedef std::vector StringList; - StringList newpaths; - CallWithDirectory::apply(d.get(), PushBackFunctor(newpaths)); - s.insert(newpaths); - } - - template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); - template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); - template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); - template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + + // Explicit instantiation of function template above, so we can hide this all in the CPP file. + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + template void extendLuaSearchPath(DirectoryBase const&, SearchPathContainerBase &); + } // end of namespace detail } // end of namespace vrjLua diff --git a/vrjugglua/AddToLuaPaths.h b/vrjugglua/AddToLuaPaths.h index 125f84c8..a99a4e48 100644 --- a/vrjugglua/AddToLuaPaths.h +++ b/vrjugglua/AddToLuaPaths.h @@ -34,89 +34,89 @@ namespace vrjLua { - - - inline std::string ensureTrailingSlash(std::string dir) { - if (dir.size() > 0) { - const char back = *(dir.end() - 1); - if (back != '/' && back != '\\') { - dir += '/'; - } - } - return dir; - } - namespace LuaPathTags { struct RootDirectory; struct SearchDirectory; struct LuaSearch; struct LuaCSearch; - }; - - template - class DirectoryBase { - public: - DirectoryBase(std::string const& dir) - : _dir(ensureTrailingSlash(dir)) - {} - std::string const& get() const { - return _dir; + } // end of namespace LuaPathTags + + namespace detail { + inline std::string ensureTrailingSlash(std::string dir) { + if (dir.size() > 0) { + const char back = *(dir.end() - 1); + if (back != '/' && back != '\\') { + dir += '/'; + } } - private: - std::string const _dir; + return dir; + } - }; + template + class DirectoryBase { + public: + DirectoryBase(std::string const& dir) + : _dir(detail::ensureTrailingSlash(dir)) + {} + std::string const& get() const { + return _dir; + } + private: + std::string const _dir; + + }; + + template + class SearchPathContainerBase; + + template + extern void extendLuaSearchPath(DirectoryBase const& d, SearchPathContainerBase & s); + + template + class SearchPathContainerBase { + public: + SearchPathContainerBase(SearchPath const& p) + : _path(p) {} - class RootDirectory : public DirectoryBase { + void insert(std::vector const& patterns) { + _path.insertAt(patterns, 1); + } + + std::string toString() { + return _path.toString(); + } + private: + SearchPath _path; + }; + } // end of namespace detail + + + + + class RootDirectory : public detail::DirectoryBase { public: RootDirectory(std::string const& dir) - : DirectoryBase(dir) {} + : detail::DirectoryBase(dir) {} }; - class SearchDirectory : public DirectoryBase { + class SearchDirectory : public detail::DirectoryBase { public: SearchDirectory(std::string const& dir) - : DirectoryBase(dir) {} + : detail::DirectoryBase(dir) {} }; - template - class SearchPathContainerBase { - public: - SearchPathContainerBase(SearchPath const& p) - : _path(p) {} - - SearchPathContainerBase() - : _path() {} - void set(std::string const& s) { - _path.set(s); - } - - void insert(std::vector const& patterns) { - _path.insertAt(patterns, 1); - } - - std::string toString() { - return _path.toString(); - } - private: - SearchPath _path; - }; - class LuaSearchPath : public SearchPathContainerBase { + class LuaSearchPath : public detail::SearchPathContainerBase { public: - LuaSearchPath(std::string const& s) : SearchPathContainerBase(s) {} - LuaSearchPath() : SearchPathContainerBase() {} + LuaSearchPath(std::string const& s) : detail::SearchPathContainerBase(s) {} }; - class LuaCSearchPath : public SearchPathContainerBase { + class LuaCSearchPath : public detail::SearchPathContainerBase { public: - LuaCSearchPath(std::string const& s) : SearchPathContainerBase(s) {} - LuaCSearchPath() : SearchPathContainerBase() {} + LuaCSearchPath(std::string const& s) : detail::SearchPathContainerBase(s) {} }; - template - extern void extendLuaSearchPath(DirectoryBase const& d, SearchPathContainerBase & s); } // end of namespace vrjLua diff --git a/vrjugglua/SearchPath.cpp b/vrjugglua/SearchPath.cpp index 023d385b..2ee3915f 100644 --- a/vrjugglua/SearchPath.cpp +++ b/vrjugglua/SearchPath.cpp @@ -32,10 +32,6 @@ namespace vrjLua { SearchPath::SearchPath(std::string const& input, const char * delim) { - set(input, delim); - } - - void SearchPath::set(std::string const& input, const char * delim) { boost::algorithm::split(_data, input, boost::algorithm::is_any_of(delim)); _reapplyUniqueness(); } diff --git a/vrjugglua/SearchPath.h b/vrjugglua/SearchPath.h index 1a5521ca..3f797211 100644 --- a/vrjugglua/SearchPath.h +++ b/vrjugglua/SearchPath.h @@ -39,11 +39,8 @@ namespace vrjLua { typedef std::vector StringList; - SearchPath() {} SearchPath(std::string const& input, const char * delim = defaultDelimiter()); - void set(std::string const& input, const char * delim = defaultDelimiter()); - void insertAt(StringList const& elts, size_t position = 0); std::string toString(const char * delim = defaultDelimiter()) const; From 5ec86ac734469b41d9669837abeb95478ebe0522 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:01:11 -0500 Subject: [PATCH 25/35] Add extend as a member of the search path base. --- vrjugglua/AddToLuaPaths.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vrjugglua/AddToLuaPaths.h b/vrjugglua/AddToLuaPaths.h index a99a4e48..0ee041e8 100644 --- a/vrjugglua/AddToLuaPaths.h +++ b/vrjugglua/AddToLuaPaths.h @@ -82,6 +82,11 @@ namespace vrjLua { _path.insertAt(patterns, 1); } + template + void extend(DirectoryBase const& d) { + detail::extendLuaSearchPath(d, *this); + } + std::string toString() { return _path.toString(); } From 794364171baca4da62bc737da12fd4486bc70736 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:02:46 -0500 Subject: [PATCH 26/35] Use that member function to keep it tidy and expressive --- vrjugglua/LuaScript.cpp | 4 ++-- vrjugglua/binding_detail/BindvrjLuaToLua.inl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vrjugglua/LuaScript.cpp b/vrjugglua/LuaScript.cpp index 1c0f0ca8..c4d806f6 100644 --- a/vrjugglua/LuaScript.cpp +++ b/vrjugglua/LuaScript.cpp @@ -220,8 +220,8 @@ namespace vrjLua { luabind::object package(luabind::globals(_state.get())["package"]); LuaSearchPath searchpath(object_cast(package["path"])); - extendLuaSearchPath(SearchDirectory(lp.getLuaDir()), searchpath); - extendLuaSearchPath(RootDirectory(lp.getRootDir()), searchpath); + searchpath.extend(SearchDirectory(lp.getLuaDir())); + searchpath.extend(RootDirectory(lp.getRootDir())); package["path"] = searchpath.toString(); /// @todo c search path diff --git a/vrjugglua/binding_detail/BindvrjLuaToLua.inl b/vrjugglua/binding_detail/BindvrjLuaToLua.inl index 690b88e1..b84848e6 100644 --- a/vrjugglua/binding_detail/BindvrjLuaToLua.inl +++ b/vrjugglua/binding_detail/BindvrjLuaToLua.inl @@ -65,7 +65,7 @@ namespace vrjLua { luabind::object package(luabind::globals(s)["package"]); LuaSearchPath searchpath(object_cast(package["path"])); - extendLuaSearchPath(SearchDirectory(path), searchpath); + searchpath.extend(SearchDirectory(path)); package["path"] = searchpath.toString(); } From 1ee97db6c96c9b1868b08da4a62b06c2013f3b5d Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:02:55 -0500 Subject: [PATCH 27/35] Remove some old duplicated code --- vrjugglua/LuaPath.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/vrjugglua/LuaPath.cpp b/vrjugglua/LuaPath.cpp index 8c67abaa..48c467bd 100644 --- a/vrjugglua/LuaPath.cpp +++ b/vrjugglua/LuaPath.cpp @@ -30,7 +30,6 @@ #include #include -#include // for VPR_OS_Linux #include // for __VJ_version define // Standard includes @@ -39,24 +38,6 @@ namespace fs = boost::filesystem; -#ifdef VPR_OS_Linux - -#include - -extern "C" { - int sharedObjectCallback(struct dl_phdr_info *info, - size_t, void *data); -} - -int sharedObjectCallback(struct dl_phdr_info *info, size_t, void *data) { - std::string fn(info->dlpi_name); - if (fn.find("vpr") != std::string::npos) { - (*static_cast(data)) = fn; - } - return 0; -} - -#endif // VPR_OS_Linux namespace vrjLua { From 08f875f2fad9bae631b5723447027e3919d94dd9 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:07:25 -0500 Subject: [PATCH 28/35] Factor out duplicated code. --- vrjugglua/binding_detail/BindvrjLuaToLua.inl | 34 +++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/vrjugglua/binding_detail/BindvrjLuaToLua.inl b/vrjugglua/binding_detail/BindvrjLuaToLua.inl index b84848e6..c183c449 100644 --- a/vrjugglua/binding_detail/BindvrjLuaToLua.inl +++ b/vrjugglua/binding_detail/BindvrjLuaToLua.inl @@ -40,21 +40,12 @@ namespace vrjLua { using namespace luabind; - static void appendToModelSearchPath(std::string const& path) { - std::string p = path; - if (osgDB::fileExists(path)) { - p = osgDB::convertFileNameToUnixStyle(osgDB::getRealPath(path)); - if (osgDB::fileType(p) == osgDB::REGULAR_FILE) { - p = osgDB::getFilePath(p); - } + static inline std::string getDirectoryPart(std::string p) { + if (p.empty()) { + return p; } - osgDB::Registry::instance()->getDataFilePathList().push_back(p); - } - - static void appendToLuaRequirePath(LuaStateRawPtr s, std::string const& path) { - std::string p = path; - if (osgDB::fileExists(path)) { - p = osgDB::convertFileNameToUnixStyle(osgDB::getRealPath(path)); + if (osgDB::fileExists(p)) { + p = osgDB::convertFileNameToUnixStyle(osgDB::getRealPath(p)); if (osgDB::fileType(p) == osgDB::REGULAR_FILE) { p = osgDB::getFilePath(p); } @@ -62,10 +53,21 @@ namespace vrjLua { if (p[p.size() - 1] != '/') { p.push_back('/'); } - luabind::object package(luabind::globals(s)["package"]); + return p; + } + static void appendToModelSearchPath(std::string const& path) { + std::string p = getDirectoryPart(path); + osgDB::Registry::instance()->getDataFilePathList().push_back(p); + } + static void appendToLuaRequirePath(LuaStateRawPtr s, std::string const& path) { + std::string p = getDirectoryPart(path); + + luabind::object package(luabind::globals(s)["package"]); LuaSearchPath searchpath(object_cast(package["path"])); - searchpath.extend(SearchDirectory(path)); + + searchpath.extend(SearchDirectory(p)); + package["path"] = searchpath.toString(); } From 9da9b1d8bbfb7f1fbf0e187cea980ec29da63041 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:08:58 -0500 Subject: [PATCH 29/35] Put in some error checking. --- vrjugglua/binding_detail/BindvrjLuaToLua.inl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vrjugglua/binding_detail/BindvrjLuaToLua.inl b/vrjugglua/binding_detail/BindvrjLuaToLua.inl index c183c449..9def303f 100644 --- a/vrjugglua/binding_detail/BindvrjLuaToLua.inl +++ b/vrjugglua/binding_detail/BindvrjLuaToLua.inl @@ -57,11 +57,17 @@ namespace vrjLua { } static void appendToModelSearchPath(std::string const& path) { std::string p = getDirectoryPart(path); + if (p.empty()) { + throw std::runtime_error("Can't append an empty string to the model search path!"); + } osgDB::Registry::instance()->getDataFilePathList().push_back(p); } static void appendToLuaRequirePath(LuaStateRawPtr s, std::string const& path) { std::string p = getDirectoryPart(path); + if (p.empty()) { + throw std::runtime_error("Can't append an empty string to the require path!"); + } luabind::object package(luabind::globals(s)["package"]); LuaSearchPath searchpath(object_cast(package["path"])); From a9727d66866c8a646838cddcffcfa6e69a513e2f Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:11:18 -0500 Subject: [PATCH 30/35] Fix/simplify root dir paths --- vrjugglua/AddToLuaPaths.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/vrjugglua/AddToLuaPaths.cpp b/vrjugglua/AddToLuaPaths.cpp index 1a8ae5f9..cdd38964 100644 --- a/vrjugglua/AddToLuaPaths.cpp +++ b/vrjugglua/AddToLuaPaths.cpp @@ -50,7 +50,6 @@ namespace vrjLua { template<> const char * GetDirsFromRoot::dirs[] = { - "etc/vrjugglua/", "share/vrjugglua/lua/", "share/lua/" LUA_VER "/", "lib/lua/" LUA_VER "/" @@ -58,7 +57,6 @@ namespace vrjLua { template<> const char * GetDirsFromRoot::dirs[] = { - "etc/vrjugglua/", "share/vrjugglua/lua/", "share/lua/" LUA_VER "/", "lib/lua/" LUA_VER "/" From a0979fc1e04284483eaeb76c6c1b9c49a105467a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:40:09 -0500 Subject: [PATCH 31/35] Add LuaPathUpdater, which handles luabind interaction and RAII --- vrjugglua/AddToLuaPaths.h | 7 +++++ vrjugglua/CMakeLists.txt | 1 + vrjugglua/LuaPathUpdater.h | 58 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 vrjugglua/LuaPathUpdater.h diff --git a/vrjugglua/AddToLuaPaths.h b/vrjugglua/AddToLuaPaths.h index 0ee041e8..87b311cb 100644 --- a/vrjugglua/AddToLuaPaths.h +++ b/vrjugglua/AddToLuaPaths.h @@ -115,11 +115,18 @@ namespace vrjLua { class LuaSearchPath : public detail::SearchPathContainerBase { public: LuaSearchPath(std::string const& s) : detail::SearchPathContainerBase(s) {} + + static const char * getTableKey() { + return "path"; + } }; class LuaCSearchPath : public detail::SearchPathContainerBase { public: LuaCSearchPath(std::string const& s) : detail::SearchPathContainerBase(s) {} + static const char * getTableKey() { + return "cpath"; + } }; diff --git a/vrjugglua/CMakeLists.txt b/vrjugglua/CMakeLists.txt index cbb874d1..4f7ad3d2 100644 --- a/vrjugglua/CMakeLists.txt +++ b/vrjugglua/CMakeLists.txt @@ -57,6 +57,7 @@ set(API LuaIncludeFull.h LuaInclude.h LuaPath.h + LuaPathUpdater.h LuaRunBuffer.h LuaScript.h OsgAppProxy.h diff --git a/vrjugglua/LuaPathUpdater.h b/vrjugglua/LuaPathUpdater.h new file mode 100644 index 00000000..776fdb18 --- /dev/null +++ b/vrjugglua/LuaPathUpdater.h @@ -0,0 +1,58 @@ +/** @file + @brief Header + + @date 2013 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#pragma once +#ifndef INCLUDED_LuaPathUpdater_h_GUID_ebe0b3e8_34e2_442c_afa8_2ffbdf2f4864 +#define INCLUDED_LuaPathUpdater_h_GUID_ebe0b3e8_34e2_442c_afa8_2ffbdf2f4864 + +// Internal Includes +#include + +// Library/third-party includes +#include + +// Standard includes +// - none + +namespace vrjLua { + + template + class SearchPathUpdater { + public: + SearchPathUpdater(lua_State * L) + : package(luabind::globals(L)["package"]) + , _p(luabind::object_cast(package[Contained::getTableKey()])) + {} + ~SearchPathUpdater() { + package[Contained::getTableKey()] = _p.toString(); + } + template + void extend(detail::DirectoryBase const& d) { + _p.extend(d); + } + private: + luabind::object package; + Contained _p; + }; + + typedef SearchPathUpdater LuaSearchPathUpdater; + typedef SearchPathUpdater LuaCSearchPathUpdater; + +} // end of namespace vrjLua + +#endif // INCLUDED_LuaPathUpdater_h_GUID_ebe0b3e8_34e2_442c_afa8_2ffbdf2f4864 From 24c3d9caf15f498a2612e8c7e5908e8b6ea916b9 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:43:23 -0500 Subject: [PATCH 32/35] Use the LuaPathUpdater --- vrjugglua/LuaScript.cpp | 12 ++++++------ vrjugglua/binding_detail/BindvrjLuaToLua.inl | 8 ++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/vrjugglua/LuaScript.cpp b/vrjugglua/LuaScript.cpp index c4d806f6..24c4d2b2 100644 --- a/vrjugglua/LuaScript.cpp +++ b/vrjugglua/LuaScript.cpp @@ -24,7 +24,7 @@ #include "OsgAppProxy.h" #include "LuaPath.h" -#include "AddToLuaPaths.h" +#include "LuaPathUpdater.h" #include "LuaGCBlock.h" #include "VRJLuaOutput.h" @@ -217,17 +217,17 @@ namespace vrjLua { // Extend the lua script search path for "require" LuaPath& lp = LuaPath::instance(); { - luabind::object package(luabind::globals(_state.get())["package"]); - - LuaSearchPath searchpath(object_cast(package["path"])); + LuaSearchPathUpdater searchpath(_state.get()); searchpath.extend(SearchDirectory(lp.getLuaDir())); searchpath.extend(RootDirectory(lp.getRootDir())); - package["path"] = searchpath.toString(); + } + { /// @todo c search path - //LuaCSearchPath csearchpath(object_cast(package["path"])); + //LuaCSearchPathUpdater csearchpath(_state.get()); } + // osgLua bindOsgToLua(_state); diff --git a/vrjugglua/binding_detail/BindvrjLuaToLua.inl b/vrjugglua/binding_detail/BindvrjLuaToLua.inl index 9def303f..b82cd3b3 100644 --- a/vrjugglua/binding_detail/BindvrjLuaToLua.inl +++ b/vrjugglua/binding_detail/BindvrjLuaToLua.inl @@ -22,7 +22,7 @@ #include "BindvrjLuaToLua.h" #include #include -#include +#include #include // Library/third-party includes @@ -68,13 +68,9 @@ namespace vrjLua { if (p.empty()) { throw std::runtime_error("Can't append an empty string to the require path!"); } - - luabind::object package(luabind::globals(s)["package"]); - LuaSearchPath searchpath(object_cast(package["path"])); + LuaSearchPathUpdater searchpath(s); searchpath.extend(SearchDirectory(p)); - - package["path"] = searchpath.toString(); } static luabind::object getModelSearchPath(lua_State *L) { From d6966807cecdd65b8d58edab74f3affe962ec704 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:43:42 -0500 Subject: [PATCH 33/35] Add back a function to LuaPath because SPARTA uses it. Mark as deprecated. --- vrjugglua/CMakeLists.txt | 1 + vrjugglua/LuaPath.h | 3 +++ vrjugglua/LuaPathLuabind.cpp | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 vrjugglua/LuaPathLuabind.cpp diff --git a/vrjugglua/CMakeLists.txt b/vrjugglua/CMakeLists.txt index 4f7ad3d2..93edd39e 100644 --- a/vrjugglua/CMakeLists.txt +++ b/vrjugglua/CMakeLists.txt @@ -38,6 +38,7 @@ set(SOURCES LuaRunBuffer.cpp LuaScript.cpp LuaPath.cpp + LuaPathLuabind.cpp OsgAppProxy.cpp Reconfiguration.cpp SearchPath.cpp diff --git a/vrjugglua/LuaPath.h b/vrjugglua/LuaPath.h index 20e891cb..462a10e5 100644 --- a/vrjugglua/LuaPath.h +++ b/vrjugglua/LuaPath.h @@ -48,6 +48,9 @@ namespace vrjLua { std::string const& getInitialPath() const; std::string const& getLuaDir() const; + /// DEPRECATED + void addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash); + protected: LuaPath(); void _init(std::string const& arg0, std::string const& vrjlua_base); diff --git a/vrjugglua/LuaPathLuabind.cpp b/vrjugglua/LuaPathLuabind.cpp new file mode 100644 index 00000000..b0301eee --- /dev/null +++ b/vrjugglua/LuaPathLuabind.cpp @@ -0,0 +1,36 @@ +/** + @file + @brief Implementation + + @date 2013 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Internal Includes +#include "LuaPath.h" +#include "LuaPathUpdater.h" + +// Library/third-party includes +// - none + +// Standard includes +// - none + +namespace vrjLua { + void LuaPath::addLuaRequirePath(LuaStatePtr state, std::string const& dirEndingInSlash) { + LuaSearchPathUpdater searchpath(state.get()); + + searchpath.extend(SearchDirectory(dirEndingInSlash)); + } +} // end of namespace vrjLua From a1591a6c9c231c3936d4108fc1aa06d7d57e0089 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 Mar 2013 17:44:55 -0500 Subject: [PATCH 34/35] Fix paths to C libs --- vrjugglua/AddToLuaPaths.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vrjugglua/AddToLuaPaths.cpp b/vrjugglua/AddToLuaPaths.cpp index cdd38964..c40aa5c8 100644 --- a/vrjugglua/AddToLuaPaths.cpp +++ b/vrjugglua/AddToLuaPaths.cpp @@ -57,9 +57,12 @@ namespace vrjLua { template<> const char * GetDirsFromRoot::dirs[] = { - "share/vrjugglua/lua/", - "share/lua/" LUA_VER "/", - "lib/lua/" LUA_VER "/" + "lib/lua/" LUA_VER "/", + "lib/" +#ifdef _WIN32 + , + "bin/" +#endif }; template From cd8ae8c8f87b0f3afff299e0927a13242b058ff5 Mon Sep 17 00:00:00 2001 From: Patrick Carlson Date: Wed, 14 Aug 2013 14:14:04 -0500 Subject: [PATCH 35/35] fix luarocks submodule (old commit hash didn't exist, resulted in fatal reference error) --- third-party/luarocks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third-party/luarocks b/third-party/luarocks index 0c715354..d5798de5 160000 --- a/third-party/luarocks +++ b/third-party/luarocks @@ -1 +1 @@ -Subproject commit 0c715354438c8285cf84607c375e2694bfd948aa +Subproject commit d5798de50c799b855be758cc0af3e5bc2f3d5ab0