- Timestamp:
- Feb 28, 2009, 7:46:37 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 56 deleted
- 216 edited
- 233 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:ignore deleted
- Property svn:mergeinfo changed
-
code/trunk/CMakeLists.txt
r1889 r2710 1 PROJECT(Orxonox) 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR) 2 21 3 cmake_minimum_required(VERSION 2.4) 22 # Keep devs from using the root directory as binary directory (messes up the source tree) 23 IF(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) 24 MESSAGE(FATAL_ERROR "Please do not use the root directory as CMake output directory! 25 mkdir build; cd build; cmake .. 26 And you will have to clean the source directory by deleting CMakeCache.txt and the folder CMakeFiles") 27 ENDIF() 4 28 5 IF (COMMAND cmake_policy)6 cmake_policy(SET CMP0003 NEW)7 ENDIF (COMMAND cmake_policy)8 29 9 # Allow for simple IF constructs (makes code a lot more readable) 10 #SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) 30 PROJECT(Orxonox C CXX) 31 32 SET(ORXONOX_VERSION_MAJOR 0) 33 SET(ORXONOX_VERSION_MINOR 0) 34 SET(ORXONOX_VERSION_PATCH 3) 35 SET(ORXONOX_VERSION 0.0.3) 36 SET(ORXONOX_VERSION_NAME "Castor") 37 11 38 12 39 # This sets where to look for modules (e.g. "Find*.cmake" files) 13 SET(CMAKE_MODULE_PATH ${CMAKE_ CURRENT_SOURCE_DIR}/cmake)40 SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 14 41 15 # Check whether we are on a tardis box 16 INCLUDE(CheckTardis) 42 IF(UNIX AND NOT APPLE) 43 INCLUDE(FlagUtilities) 44 SET_CACHE(CMAKE_INSTALL_PREFIX PATH "" /usr) # default: /usr/local 45 ENDIF() 17 46 47 # Library finding 48 INCLUDE(LibraryConfig) 18 49 19 ############## Testing options ################## 50 # General build and compiler options and configurations 51 INCLUDE(BuildConfig) 20 52 21 OPTION(TESTING_ENABLED "Do you want to enable Testing") 22 IF (TESTING_ENABLED) 23 ENABLE_TESTING() 24 ENDIF(TESTING_ENABLED) 53 # Configure media directory location and installation 54 ADD_SUBDIRECTORY(media) 25 55 26 OPTION (NETWORK_TESTING_ENABLED "Do you want to build network testing tools: i.e. chatclient chatserver and alike") 27 OPTION (NETWORKTRAFFIC_TESTING_ENABLED "Do you want to build dummyserver4 and dummyclient4")56 # Remaining tardis hack 57 ADD_SUBDIRECTORY(config) 28 58 29 30 ########## Compiler/Linker options ############## 31 32 # if on tardis change compiler and reset boost include directory 33 IF(IS_TARDIS) 34 MESSAGE("System is a TARDIS: Setting Compiler to g++-4.1.1") 35 # Force-set the compiler on tardis machines, as default points to g++-3.3 36 SET(CMAKE_CXX_COMPILER "g++-4.1.1") 37 # Reset Boost serach path 38 SET(Boost_INCLUDE_DIR "/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/include") 39 ELSE (IS_TARDIS) 40 IF (NOT WIN32) 41 SET(Boost_INCLUDE_DIR "/usr/include/boost") 42 ENDIF (NOT WIN32) 43 ENDIF(IS_TARDIS) 44 45 # Set binary output directories 46 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 47 SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/lib) 48 49 # Global compiler/linker flags. force -O2! 50 SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O0 -Wall -g -ggdb") 51 SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") 52 #SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O3 -s") 53 #SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O3 -s") 54 55 SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}") 56 SET(CMAKE_EXE_LINKER_FLAGS " --no-undefined") 57 SET(CMAKE_SHARED_LINKER_FLAGS " --no-undefined") 58 SET(CMAKE_MODULE_LINKER_FLAGS " --no-undefined") 59 60 # Use 'cmake -D make_verb:1 path' to get verbose make output when compiling 61 IF (MAKE_VERB) 62 SET(CMAKE_VERBOSE_MAKEFILE TRUE) 63 ENDIF (MAKE_VERB) 64 65 66 ############### Library finding ################# 67 68 # Uncomment the following line if you want the include and library paths to be shown 69 # Alternatively use the "-D VERBOSE_FIND:BOOL=true" option when executing cmake 70 71 # SET (VERBOSE_FIND true) 72 73 # Set the library directory when using precompiled tarballs for the dependencies under windows 74 IF (WIN32) 75 IF (MSVC) 76 IF ($ENV{ORXONOX_DEV}) 77 SET (DEPENDENCY_DIR ${CMAKE_SOURCE_DIR}/../lib_dist/dependencies/) 78 ELSE ($ENV{ORXONOX_DEV}) 79 SET (DEPENDENCY_DIR ${CMAKE_SOURCE_DIR}/dependencies/) 80 ENDIF ($ENV{ORXONOX_DEV}) 81 SET(Boost_LIB_SUFFIX_DEBUG vc80-mt-gd-1_35) 82 ENDIF (MSVC) 83 ENDIF (WIN32) 84 MESSAGE(STATUS ${DEPENDENCY_DIR}) 85 86 # Performs the search and sets the variables 87 FIND_PACKAGE(OGRE) 88 FIND_PACKAGE(CEGUI) 89 # FIND_PACKAGE(CEGUI_OGRE) 90 FIND_PACKAGE(ENet) 91 FIND_PACKAGE(Boost REQUIRED thread filesystem) 92 FIND_PACKAGE(OpenAL) 93 FIND_PACKAGE(ALUT) 94 FIND_PACKAGE(OggVorbis) 95 FIND_PACKAGE(ZLIB) 96 #FIND_PACKAGE(Lua) 97 FIND_PACKAGE(TCL) 98 FIND_PACKAGE(DirectX) 99 100 # Set the search paths for the linking 101 LINK_DIRECTORIES( 102 ${OGRE_LIB_DIR} 103 ${CEGUI_LIB_DIR} 104 # ${CEGUI_SCRIPT_LIB_DIR} 105 # ${CEGUI_OGRE_LIB_DIR} 106 ${ENet_LIBRARY} 107 ${Boost_LIBRARY_DIRS} 108 ${Zlib_LIBRARY_DIR} 109 ${TCL_LIBRARY} 110 ) 111 112 # Set the search paths for include files 113 INCLUDE_DIRECTORIES( 114 ${OGRE_INCLUDE_DIR} 115 ${CEGUI_INCLUDE_DIR} 116 # ${CEGUI_OGRE_INCLUDE_DIR} 117 ${ENet_INCLUDE_DIR} 118 ${Boost_INCLUDE_DIRS} 119 ${OPENAL_INCLUDE_DIR} 120 ${ALUT_INCLUDE_DIR} 121 ${VORBIS_INCLUDE_DIR} 122 ${OGG_INCLUDE_DIR} 123 # ${Lua_INCLUDE_DIR} 124 ${TCL_INCLUDE_PATH} 125 ${DirectX_INCLUDE_DIR} 126 ${ZLIB_INCLUDE_DIR} 127 ) 128 129 # Add main source dir 59 # Create the actual project 130 60 ADD_SUBDIRECTORY(src) 131 61 62 # Configure the binary output directory. Do this after src! 63 ADD_SUBDIRECTORY(bin) 64 65 # Last but not least: Try to make doxygen target 66 ADD_SUBDIRECTORY(doc) -
code/trunk/INSTALL
r1505 r2710 1 Here our installing directions 1 ************* Build System ************** 2 To make platform support as easy as possible we have decided to use CMake as our build system. 3 Therefore the first thing you need to do is to get 4 CMake v.2.6 or later. 2 5 3 requirements: 4 ogre-1.4.5 5 ois-1.0 6 cegui-0.5.0b 7 enet-1.1 8 boost-1.34.1 9 cmake-2.4.7 10 openal-0.0.8 11 freealut-1.1.0 12 libvorbis-1.2.0 13 (all named version were tested. lower version requirement may be possible) 6 ************** Libraries **************** 14 7 15 It is assumed, that you have a working graphical environment (i.e X11), including some sort of 3d acceleration (OpenGL, Direct3D) 8 In order to compile Orxonox you will need the following libraries: 9 (for windows there are already precompiled packages on the website) 16 10 17 Further information about installing and running this application can be found on http://www.orxonox.net/wiki/Running 11 OGRE 3D Graphics Engine 1.4 (1.6 not yet supported) 12 CEGUI (Crazy Eddie's GUI System) 0.5 13 Boost libraries 1.34 14 ENet (Network library) 1.1 15 Lua (scripting language) 5.0 or 5.1 16 Tcl (shell script language) 8.4 or 8.5 17 OpenAL (audio) (no version requirements specified yet) 18 ALUT (audio) (no version requirements specified yet) 19 LibOgg (no version requirements specified yet) 20 LibVorbis (no version requirements specified yet) 21 ZLib (compression) (no version requirements specified yet) 22 23 OGRE supports both OpenGL and DirectX9 rendering. You will also need OGRE for the dedicated server! 24 25 Further information about installing and running this application can be found on 26 http://www.orxonox.net/wiki/Running -
code/trunk/cmake/FindALUT.cmake
r1872 r2710 2 2 # This module defines 3 3 # ALUT_LIBRARY 4 # ALUT_FOUND, if false, do not try to link toAlut4 # ALUT_FOUND, if false, do not try to link against Alut 5 5 # ALUT_INCLUDE_DIR, where to find the headers 6 6 # … … 18 18 # 19 19 # Several changes and additions by Fabian 'x3n' Landau 20 # Some simplifications by Adrian Friedli and Reto Grieder 20 21 # > www.orxonox.net < 21 22 22 IF (ALUT_LIBRARY AND ALUT_INCLUDE_DIR) 23 SET (ALUT_FIND_QUIETLY TRUE) 24 ENDIF (ALUT_LIBRARY AND ALUT_INCLUDE_DIR) 23 INCLUDE(FindPackageHandleStandardArgs) 24 INCLUDE(HandleLibraryTypes) 25 25 26 26 FIND_PATH(ALUT_INCLUDE_DIR AL/alut.h 27 $ENV{ALUTDIR}/include 28 ~/Library/Frameworks/OpenAL.framework/Headers 29 /Library/Frameworks/OpenAL.framework/Headers 30 /System/Library/Frameworks/OpenAL.framework/Headers # Tiger 31 /usr/pack/openal-0.0.8-cl/include # Tardis specific hack 32 /usr/local/include/ 33 /usr/local/include/OpenAL 34 /usr/local/include 35 /usr/include/ 36 /usr/include/OpenAL 37 /usr/include 38 /sw/include/ # Fink 39 /sw/include/OpenAL 40 /sw/include 41 /opt/local/include/AL # DarwinPorts 42 /opt/local/include/OpenAL 43 /opt/local/include 44 /opt/csw/include/ # Blastwave 45 /opt/csw/include/OpenAL 46 /opt/csw/include 47 /opt/include/ 48 /opt/include/OpenAL 49 /opt/include 50 ../libs/freealut-1.1.0/include 51 ${DEPENDENCY_DIR}/freealut-1.1.0/include 52 ) 27 PATHS 28 $ENV{ALUTDIR} 29 ~/Library/Frameworks/OpenAL.framework 30 /Library/Frameworks/OpenAL.framework 31 /System/Library/Frameworks/OpenAL.framework # Tiger 32 PATH_SUFFIXES include include/OpenAL include/AL Headers 33 ) 53 34 54 35 # I'm not sure if I should do a special casing for Apple. It is … … 57 38 # do they want the -framework option also? 58 39 IF(${ALUT_INCLUDE_DIR} MATCHES ".framework") 40 59 41 STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" ALUT_FRAMEWORK_PATH_TMP ${ALUT_INCLUDE_DIR}) 60 42 IF("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" … … 62 44 ) 63 45 # String is in default search path, don't need to use -F 64 SET (ALUT_LIBRARY "-framework OpenAL" CACHE STRING "OpenAL framework for OSX") 65 ELSE("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" 66 OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks" 67 ) 46 SET (ALUT_LIBRARY_OPTIMIZED "-framework OpenAL" CACHE STRING "OpenAL framework for OSX") 47 ELSE() 68 48 # String is not /Library/Frameworks, need to use -F 69 SET(ALUT_LIBRARY "-F${ALUT_FRAMEWORK_PATH_TMP} -framework OpenAL" CACHE STRING "OpenAL framework for OSX") 70 ENDIF("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" 71 OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks" 72 ) 49 SET(ALUT_LIBRARY_OPTIMIZED "-F${ALUT_FRAMEWORK_PATH_TMP} -framework OpenAL" CACHE STRING "OpenAL framework for OSX") 50 ENDIF() 73 51 # Clear the temp variable so nobody can see it 74 52 SET(ALUT_FRAMEWORK_PATH_TMP "" CACHE INTERNAL "") 75 53 76 ELSE( ${ALUT_INCLUDE_DIR} MATCHES ".framework")77 FIND_LIBRARY(ALUT_LIBRARY 54 ELSE() 55 FIND_LIBRARY(ALUT_LIBRARY_OPTIMIZED 78 56 NAMES alut 79 PATHS 80 $ENV{ALUTDIR}/lib 81 $ENV{ALUTDIR}/libs 82 /usr/pack/openal-0.0.8-cl/i686-debian-linux3.1/lib 83 /usr/local/lib 84 /usr/lib 85 /sw/lib 86 /opt/local/lib 87 /opt/csw/lib 88 /opt/lib 89 ../libs/freealut-1.1.0/src/.libs 90 ../libs/freealut-1.1.0/lib 91 ${DEPENDENCY_DIR}/freealut-1.1.0/lib 92 ) 93 ENDIF(${ALUT_INCLUDE_DIR} MATCHES ".framework") 57 PATHS $ENV{ALUTDIR} 58 PATH_SUFFIXES lib libs 59 ) 60 FIND_LIBRARY(ALUT_LIBRARY_DEBUG 61 NAMES alutd alut_d alutD alut_D 62 PATHS $ENV{ALUTDIR} 63 PATH_SUFFIXES lib libs 64 ) 65 ENDIF() 94 66 95 SET (ALUT_FOUND "NO") 96 IF (ALUT_LIBRARY AND ALUT_INCLUDE_DIR) 97 SET (ALUT_FOUND "YES") 98 IF (NOT ALUT_FIND_QUIETLY) 99 MESSAGE (STATUS "FreeAlut was found.") 100 IF (VERBOSE_FIND) 101 MESSAGE (STATUS " include path: ${ALUT_INCLUDE_DIR}") 102 MESSAGE (STATUS " library path: ${ALUT_LIBRARY}") 103 MESSAGE (STATUS " libraries: alut") 104 ENDIF (VERBOSE_FIND) 105 ENDIF (NOT ALUT_FIND_QUIETLY) 106 ELSE (ALUT_LIBRARY AND ALUT_INCLUDE_DIR) 107 IF (NOT ALUT_INCLUDE_DIR) 108 MESSAGE (SEND_ERROR "FreeAlut include path was not found.") 109 ENDIF (NOT ALUT_INCLUDE_DIR) 110 IF (NOT ALUT_LIBRARY) 111 MESSAGE (SEND_ERROR "FreeAlut library was not found.") 112 ENDIF (NOT ALUT_LIBRARY) 113 ENDIF (ALUT_LIBRARY AND ALUT_INCLUDE_DIR) 67 # Handle the REQUIRED argument and set ALUT_FOUND 68 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALUT DEFAULT_MSG 69 ALUT_LIBRARY_OPTIMIZED 70 ALUT_INCLUDE_DIR 71 ) 114 72 73 # Collect optimized and debug libraries 74 HANDLE_LIBRARY_TYPES(ALUT) 115 75 76 MARK_AS_ADVANCED( 77 ALUT_INCLUDE_DIR 78 ALUT_LIBRARY_OPTIMIZED 79 ALUT_LIBRARY_DEBUG 80 ) -
code/trunk/cmake/FindCEGUI.cmake
r1872 r2710 3 3 # This module defines 4 4 # CEGUI_INCLUDE_DIR 5 # CEGUI_LIBRARIES, the libraries to link against to use CEGUI. 6 # CEGUI_LIB_DIR, the location of the libraries 5 # CEGUI_LIBRARY, the library to link against to use CEGUI. 7 6 # CEGUI_FOUND, If false, do not try to use CEGUI 7 # CEGUI_VERSION, the version as string "x.y.z" 8 # CEGUILUA_LIBRARY, Script module library 9 # CEGUILUA_USE_INTERNAL_LIBRARY, True if CEGUILUA_LIBRARY was not defined here 10 # 11 # Input: 12 # ENV{CEGUIDIR}, CEGUI path, optional 13 # FIND CEGUILUA_INTERNAL_SUPPORT, List of all CEGUILua version supported 14 # in the source repository 15 # CEGUILUA_USE_EXTERNAL_LIBRARY, Force finding of CEGUILua 8 16 # 9 17 # Created by Matt Williams to find OGRE libraries … … 17 25 # 18 26 # Several changes and additions by Fabian 'x3n' Landau 27 # Lots of simplifications by Adrian Friedli and Reto Grieder 28 # Version checking and CEGUILua finding by Reto Grieder 19 29 # > www.orxonox.net < 20 30 21 I F (CEGUI_LIBRARIES AND CEGUI_INCLUDE_DIR AND CEGUI_LIB_DIR)# AND CEGUI_SCRIPT_LIBRARIES)22 SET(CEGUI_FIND_QUIETLY TRUE) # Already in cache, be silent 23 ENDIF (CEGUI_LIBRARIES AND CEGUI_INCLUDE_DIR AND CEGUI_LIB_DIR)# AND CEGUI_SCRIPT_LIBRARIES)31 INCLUDE(DetermineVersion) 32 INCLUDE(FindPackageHandleAdvancedArgs) 33 INCLUDE(HandleLibraryTypes) 24 34 25 IF (WIN32) #Windows 26 FIND_PATH(CEGUI_INCLUDE_DIR CEGUI.h 27 ../libs/cegui-0.6.1/include 28 ${DEPENDENCY_DIR}/cegui-0.6.1/include 29 ) 35 FIND_PATH(CEGUI_INCLUDE_DIR CEGUI.h 36 PATHS $ENV{CEGUIDIR} 37 PATH_SUFFIXES include include/CEGUI CEGUI.framework/Headers 38 ) 39 FIND_LIBRARY(CEGUI_LIBRARY_OPTIMIZED 40 NAMES CEGUIBase CEGUI 41 PATHS $ENV{CEGUIDIR} 42 PATH_SUFFIXES lib bin 43 ) 44 FIND_LIBRARY(CEGUI_LIBRARY_DEBUG 45 NAMES 46 CEGUIBased CEGUIBase_d CEGUIBaseD CEGUIBase_D 47 CEGUId CEGUI_d CEGUID CEGUI_D 48 PATHS $ENV{CEGUIDIR} 49 PATH_SUFFIXES lib bin 50 ) 30 51 31 SET(CEGUI_LIBRARIES debug CEGUIBase_d optimized CEGUIBase) 32 FIND_LIBRARY(CEGUI_LIBDIR NAMES ${CEGUI_LIBRARIES} PATHS 33 ../libs/cegui-0.6.1/bin 34 ${DEPENDENCY_DIR}/cegui-0.6.1/lib 35 ) 52 # Inspect CEGUIVersion.h for the version number 53 DETERMINE_VERSION(CEGUI ${CEGUI_INCLUDE_DIR}/CEGUIVersion.h) 36 54 37 # Strip the filename from the path 38 IF (CEGUI_LIBDIR) 39 GET_FILENAME_COMPONENT(CEGUI_LIBDIR ${CEGUI_LIBDIR} PATH) 40 SET (CEGUI_LIB_DIR ${CEGUI_LIBDIR} CACHE FILEPATH "") 41 ENDIF (CEGUI_LIBDIR) 55 # Handle the REQUIRED argument and set CEGUI_FOUND 56 # Also checks the version requirements if given 57 FIND_PACKAGE_HANDLE_ADVANCED_ARGS(CEGUI DEFAULT_MSG "${CEGUI_VERSION}" 58 CEGUI_LIBRARY_OPTIMIZED 59 CEGUI_INCLUDE_DIR 60 ) 42 61 43 # IF (NOT CEGUI_SCRIPT_LIBDIR) 44 # # Search Lua script module 45 # SET(CEGUI_SCRIPT_LIBRARIES "CEGUILuaScriptModule") 46 # FIND_LIBRARY(CEGUI_SCRIPT_LIBDIR NAMES ${CEGUI_SCRIPT_LIBRARIES} PATHS 47 # ../libs/cegui-0.6.1/bin 48 # ) 49 # IF (NOT CEGUI_SCRIPT_LIBDIR) 50 # SET(CEGUI_SCRIPT_LIBRARIES "CEGUILua") 51 # FIND_LIBRARY(CEGUI_SCRIPT_LIBDIR NAMES ${CEGUI_SCRIPT_LIBRARIES} PATHS 52 # ../libs/cegui-0.6.1/bin 53 # ) 54 # IF (NOT CEGUI_SCRIPT_LIBDIR) 55 # SET(CEGUI_SCRIPT_LIBRARIES) 56 # ENDIF (NOT CEGUI_SCRIPT_LIBDIR) 57 # ENDIF (NOT CEGUI_SCRIPT_LIBDIR) 58 # ENDIF (NOT CEGUI_SCRIPT_LIBDIR) 62 # Collect optimized and debug libraries 63 HANDLE_LIBRARY_TYPES(CEGUI) 59 64 60 # # Strip the filename from the path 61 # IF (CEGUI_SCRIPT_LIBDIR) 62 # GET_FILENAME_COMPONENT(CEGUI_SCRIPT_LIBDIR ${CEGUI_SCRIPT_LIBDIR} PATH) 63 # SET (CEGUI_SCRIPT_LIB_DIR ${CEGUI_SCRIPT_LIBDIR} CACHE FILEPATH "") 64 # ENDIF (CEGUI_SCRIPT_LIBDIR)65 MARK_AS_ADVANCED( 66 CEGUI_INCLUDE_DIR 67 CEGUI_LIBRARY_OPTIMIZED 68 CEGUI_LIBRARY_DEBUG 69 ) 65 70 66 ELSE (WIN32) #Unix 67 FIND_PACKAGE(PkgConfig) 68 PKG_SEARCH_MODULE(CEGUI CEGUI /usr/pack/cegui-0.5.0-sd/i686-debian-linux3.1/lib/pkgconfig/CEGUI.pc) # tardis specific hack 69 SET(CEGUI_INCLUDE_DIR ${CEGUI_INCLUDE_DIRS}) 70 SET(CEGUI_LIB_DIR ${CEGUI_LIBDIR}) 71 SET(CEGUI_LIBRARIES ${CEGUI_LIBRARIES} CACHE STRING "") 72 # SET(CEGUI_SCRIPT_LIBRARIES "CEGUILuaScriptModule") 73 # SET(CEGUI_SCRIPT_LIB_DIR) 74 ENDIF (WIN32) 71 LIST(FIND CEGUILUA_INTERNAL_SUPPORT "${CEGUI_VERSION}" _find_result) 72 IF(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1) 73 # Also try to find the CEGUILua libraries. 74 # There would already be libraries in src/ for versions 0.5 and 0.6 75 FIND_LIBRARY(CEGUILUA_LIBRARY_OPTIMIZED 76 NAMES CEGUILua 77 PATHS $ENV{CEGUIDIR} 78 PATH_SUFFIXES lib bin 79 ) 80 FIND_LIBRARY(CEGUILUA_LIBRARY_DEBUG 81 NAMES CEGUILuad CEGUILua_d 82 PATHS $ENV{CEGUIDIR} 83 PATH_SUFFIXES lib bin 84 ) 75 85 76 IF (CEGUI_INCLUDE_DIR AND CEGUI_LIBRARIES AND CEGUI_LIB_DIR)# AND CEGUI_SCRIPT_LIBRARIES) 77 SET(CEGUI_FOUND TRUE) 86 SET(CEGUILua_FIND_REQUIRED ${CEGUI_FIND_REQUIRED}) 87 # Handle the REQUIRED argument and set CEGUILUA_FOUND 88 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CEGUILua DEFAULT_MSG 89 CEGUILUA_LIBRARY_OPTIMIZED 90 ) 78 91 79 #Do some preparation 80 SEPARATE_ARGUMENTS(CEGUI_INCLUDE_DIR) 81 SEPARATE_ARGUMENTS(CEGUI_LIBRARIES) 92 # Collect optimized and debug libraries 93 HANDLE_LIBRARY_TYPES(CEGUILUA) 82 94 83 SET(CEGUI_INCLUDE_DIR ${CEGUI_INCLUDE_DIR} CACHE PATH "") 84 SET(CEGUI_LIBRARIES ${CEGUI_LIBRARIES} CACHE STRING "") 85 SET(CEGUI_LIB_DIR ${CEGUI_LIB_DIR} CACHE PATH "") 86 # SET(CEGUI_SCRIPT_LIBRARIES ${CEGUI_SCRIPT_LIBRARIES} CACHE PATH "") 87 ENDIF (CEGUI_INCLUDE_DIR AND CEGUI_LIBRARIES AND CEGUI_LIB_DIR)# AND CEGUI_SCRIPT_LIBRARIES) 95 MARK_AS_ADVANCED( 96 CEGUILUA_LIBRARY_OPTIMIZED 97 CEGUILUA_LIBRARY_DEBUG 98 ) 88 99 89 IF (CEGUI_FOUND) 90 IF (NOT CEGUI_FIND_QUIETLY) 91 MESSAGE(STATUS "CEGUI was found.") 92 IF (VERBOSE_FIND) 93 MESSAGE (STATUS " include path: ${CEGUI_INCLUDE_DIR}") 94 MESSAGE (STATUS " library path: ${CEGUI_LIB_DIR}") 95 MESSAGE (STATUS " libraries: ${CEGUI_LIBRARIES}") 96 # MESSAGE (STATUS " : ${CEGUI_SCRIPT_LIBRARIES}") 97 ENDIF (VERBOSE_FIND) 98 ENDIF (NOT CEGUI_FIND_QUIETLY) 99 ELSE (CEGUI_FOUND) 100 IF (NOT CEGUI_INCLUDE_DIR) 101 MESSAGE(SEND_ERROR "CEGUI include path was not found.") 102 ENDIF (NOT CEGUI_INCLUDE_DIR) 103 IF (NOT CEGUI_LIB_DIR) 104 MESSAGE(SEND_ERROR "CEGUI library was not found.") 105 ENDIF (NOT CEGUI_LIB_DIR) 106 IF (NOT CEGUI_LIBRARIES) 107 MESSAGE(SEND_ERROR "CEGUI libraries not known.") 108 ENDIF (NOT CEGUI_LIBRARIES) 109 # IF (NOT CEGUI_SCRIPT_LIBRARIES) 110 # MESSAGE(SEND_ERROR "CEGUI Lua script module was not found.") 111 # ENDIF (NOT CEGUI_SCRIPT_LIBRARIES) 112 ENDIF (CEGUI_FOUND) 100 ELSE(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1) 101 SET(CEGUILUA_USE_INTERNAL_LIBRARY TRUE) 102 ENDIF(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1) 113 103 -
code/trunk/cmake/FindDirectX.cmake
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem3/cmake/FindDirectX.cmake merged eligible /code/branches/lodfinal/cmake/FindDirectX.cmake merged eligible /code/branches/network/cmake/FindDirectX.cmake merged eligible /code/branches/objecthierarchy2/cmake/FindDirectX.cmake merged eligible /code/branches/pickups2/cmake/FindDirectX.cmake merged eligible /code/branches/presentation/cmake/FindDirectX.cmake merged eligible /code/branches/questsystem2/cmake/FindDirectX.cmake merged eligible /code/branches/weapon2/cmake/FindDirectX.cmake merged eligible /code/branches/buildsystem/cmake/FindDirectX.cmake 1874-2400 /code/branches/buildsystem2/cmake/FindDirectX.cmake 2506-2658 /code/branches/ceguilua/cmake/FindDirectX.cmake 1802-1808 /code/branches/core3/cmake/FindDirectX.cmake 1572-1739 /code/branches/gcc43/cmake/FindDirectX.cmake 1580 /code/branches/gui/cmake/FindDirectX.cmake 1635-1723 /code/branches/input/cmake/FindDirectX.cmake 1629-1636 /code/branches/network64/cmake/FindDirectX.cmake 2210-2355 /code/branches/objecthierarchy/cmake/FindDirectX.cmake 1911-2085,2100,2110-2169 /code/branches/overlay/cmake/FindDirectX.cmake 2117-2385 /code/branches/physics/cmake/FindDirectX.cmake 1912-2055,2107-2439 /code/branches/physics_merge/cmake/FindDirectX.cmake 2436-2457 /code/branches/pickups/cmake/FindDirectX.cmake 1926-2086,2127 /code/branches/questsystem/cmake/FindDirectX.cmake 1894-2088 /code/branches/script_trigger/cmake/FindDirectX.cmake 1295-1953,1955 /code/branches/weapon/cmake/FindDirectX.cmake 1925-2094
r1889 r2710 1 IF(WIN32) 2 # - Test for DirectX 3 # Once loaded this will define 4 # DirectX_FOUND - system has DirectX 5 # DirectX_INCLUDE_DIR - include directory for DirectX 6 # DirectX_LIB_DIR - lib directory for DirectX 7 # 8 # Several changes and additions by Fabian 'x3n' Landau 9 # > www.orxonox.net < 1 # Find script for DirectX on Windows 2 # Specifically designed to find dxguid and dinput8 for OIS 3 # Once loaded this will define 4 # DIRECTX_FOUND - system has DirectX 5 # DIRECTX_INCLUDE_DIR - include directory for DirectX 6 # DIRECTX_LIBRARIES - libraries for DirectX 7 # 8 # Set ENV{DXSD_DIR} if that has not been done the SDK installation. 9 # 10 # Several changes and additions by Fabian 'x3n' Landau 11 # Simplifications and CMake 2.6.0 bugfix by Reto Grieder 12 # > www.orxonox.net < 10 13 11 IF (DirectX_INCLUDE_DIR AND DirectX_LIB_DIR) 12 SET(DirectX_FIND_QUIETLY TRUE) 13 ENDIF (DirectX_INCLUDE_DIR AND DirectX_LIB_DIR) 14 INCLUDE(FindPackageHandleStandardArgs) 15 INCLUDE(HandleLibraryTypes) 14 16 15 set(DirectX_FOUND "NO") 17 FIND_PATH(DIRECTX_INCLUDE_DIR dinput.h 18 PATHS $ENV{DXSDK_DIR} 19 PATH_SUFFIXES include 20 ) 21 FIND_LIBRARY(DIRECTX_LIBRARY_input dinput8 22 PATHS $ENV{DXSDK_DIR} 23 PATH_SUFFIXES lib Lib lib/x86 Lib/x86 24 NO_DEFAULT_PATH # Or else CMake 2.6.0 will find the dll in system32 on windows 25 ) 26 FIND_LIBRARY(DIRECTX_LIBRARY_input dinput8 27 PATHS $ENV{DXSDK_DIR} 28 PATH_SUFFIXES lib Lib lib/x86 Lib/x86 29 ) 30 FIND_LIBRARY(DIRECTX_LIBRARY_guid dxguid 31 PATHS $ENV{DXSDK_DIR} 32 PATH_SUFFIXES lib Lib lib/x86 Lib/x86 33 NO_DEFAULT_PATH # Or else CMake 2.6.0 will find the dll in system32 on windows 34 ) 35 FIND_LIBRARY(DIRECTX_LIBRARY_guid dxguid 36 PATHS $ENV{DXSDK_DIR} 37 PATH_SUFFIXES lib Lib lib/x86 Lib/x86 38 ) 16 39 17 FIND_PATH(DirectX_INCLUDE_DIR "dinput.h" 18 ../libs/DXSDK/Include 19 $ENV{DXSDK_DIR}/Include 20 ) 40 # Handle the REQUIRED argument and set DIRECTX_FOUND 41 FIND_PACKAGE_HANDLE_STANDARD_ARGS(DirectX DEFAULT_MSG 42 DIRECTX_LIBRARY_input 43 DIRECTX_LIBRARY_guid 44 DIRECTX_INCLUDE_DIR 45 ) 21 46 22 FIND_PATH(DirectX_LIB_DIR "dinput8.lib" 23 ../libs/DXSDK/Lib 24 ../libs/DXSDK/Lib/x86 25 $ENV{DXSDK_DIR}/lib/x86 26 ) 47 SET(DIRECTX_LIBRARIES ${DIRECTX_LIBRARY_input} ${DIRECTX_LIBRARY_guid}) 27 48 28 IF (DirectX_INCLUDE_DIR AND DirectX_LIB_DIR) 29 SET (DirectX_FOUND "YES") 30 ENDIF (DirectX_INCLUDE_DIR AND DirectX_LIB_DIR) 31 32 IF (DirectX_FOUND) 33 IF (NOT DirectX_FIND_QUIETLY) 34 MESSAGE(STATUS "DirectX was found.") 35 IF (VERBOSE_FIND) 36 MESSAGE (STATUS " include path: ${DirectX_INCLUDE_DIR}") 37 MESSAGE (STATUS " library path: ${DirectX_LIB_DIR}") 38 MESSAGE (STATUS " libraries: dinput8.lib") 39 ENDIF (VERBOSE_FIND) 40 ENDIF (NOT DirectX_FIND_QUIETLY) 41 ELSE (DirectX_FOUND) 42 IF (NOT DirectX_INCLUDE_DIR) 43 MESSAGE(SEND_ERROR "DirectX include path was not found.") 44 ENDIF (NOT DirectX_INCLUDE_DIR) 45 IF (NOT DirectX_LIB_DIR) 46 MESSAGE(SEND_ERROR "DirectX library was not found.") 47 ENDIF (NOT DirectX_LIB_DIR) 48 ENDIF (DirectX_FOUND) 49 ENDIF(WIN32) 49 MARK_AS_ADVANCED( 50 DIRECTX_INCLUDE_DIR 51 DIRECTX_LIBRARY_input 52 DIRECTX_LIBRARY_guid 53 ) -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/cmake/FindENet.cmake
r1872 r2710 3 3 # 4 4 # ENET_FOUND - system has enet 5 # ENET_INCLUDE_DIR - the enet include directory 6 # ENET_LIBRARIES - the libraries needed to use enet 7 # ENET_DEFINITIONS - Compiler switches required for using enet 5 # ENet_INCLUDE_DIR - the enet include directory 6 # ENet_LIBRARY - the library needed to link against enet 7 # 8 # $ENETDIR is an environment variable used for finding enet. 8 9 # 9 10 # Borrowed from The Mana World … … 11 12 # 12 13 # Several changes and additions by Fabian 'x3n' Landau 14 # Lots of simplifications by Adrian Friedli and Reto Grieder 15 # Version checking by Reto Grieder 13 16 # > www.orxonox.net < 14 17 15 IF (ENet_INCLUDE_DIR AND ENet_LIBRARY) 16 SET(ENet_FIND_QUIETLY TRUE) 17 ENDIF (ENet_INCLUDE_DIR AND ENet_LIBRARY) 18 INCLUDE(FindPackageHandleAdvancedArgs) 19 INCLUDE(HandleLibraryTypes) 18 20 19 FIND_PATH(ENet_INCLUDE_DIR enet/enet.h 20 /usr/include 21 /usr/local/include 22 /usr/pack/enet-2007-sd/include 23 ../libs/enet-1.1/include 24 ${DEPENDENCY_DIR}/enet-1.2/include 25 ) 21 FIND_PATH(ENET_INCLUDE_DIR enet/enet.h 22 PATHS $ENV{ENETDIR} 23 PATH_SUFFIXES include 24 ) 25 FIND_LIBRARY(ENET_LIBRARY_OPTIMIZED 26 NAMES enet 27 PATHS $ENV{ENETDIR} 28 PATH_SUFFIXES lib 29 ) 30 FIND_LIBRARY(ENET_LIBRARY_DEBUG 31 NAMES enetd enet_d enet_D 32 PATHS $ENV{ENETDIR} 33 PATH_SUFFIXES lib 34 ) 26 35 27 FIND_LIBRARY(ENet_LIBRARY 28 NAMES enet 29 PATHS /usr/lib /usr/local/lib /usr/pack/enet-2007-sd/i686-debian-linux3.1/lib/ 30 ../libs/enet-1.1 31 ${DEPENDENCY_DIR}/enet-1.2/lib 32 ) 36 # Try to determine the version. Note that enet only stores the major 37 # version in the header file. So we check for existing functions. 38 # Hence the this script only distinguishes between 1.0, 1.1 and 1.2 39 FILE(STRINGS ${ENET_INCLUDE_DIR}/enet/enet.h _enet_header REGEX "ENET_") 40 IF(_enet_header MATCHES "ENET_VERSION[ \t]*=[ \t]*1") 41 IF(_enet_header MATCHES "enet_socket_set_option") 42 SET(ENET_VERSION 1.2) 43 ELSEIF(_enet_header MATCHES "enet_peer_disconnect_later") 44 SET(ENET_VERSION 1.1) 45 ELSE() 46 SET(ENET_VERSION 1.0) 47 ENDIF() 48 ELSE() 49 SET(ENET_VERSION 0) # Script doesn't support versions below 1.0 50 ENDIF() 33 51 34 SET(ENET_FOUND FALSE) 35 IF (ENet_INCLUDE_DIR AND ENet_LIBRARY) 36 SET(ENET_FOUND TRUE) 37 SET(ENET_INCLUDE_DIR ${ENet_INCLUDE_DIR}) 52 # Handle the REQUIRED argument and set ENET_FOUND 53 # Also check the the version requirements 54 FIND_PACKAGE_HANDLE_ADVANCED_ARGS(ENet DEFAULT_MSG ${ENET_VERSION} 55 ENET_LIBRARY_OPTIMIZED 56 ENET_INCLUDE_DIR 57 ) 38 58 39 IF(WIN32) 40 SET(WINDOWS_ENET_DEPENDENCIES "ws2_32;winmm") 41 SET(ENet_LIBRARY ${ENet_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES}) 42 ENDIF(WIN32) 59 # Collect optimized and debug libraries 60 IF(NOT LINK_ENET_DYNAMIC AND WIN32) 61 # ENet is linked statically, hence we need to add some windows dependencies 62 HANDLE_LIBRARY_TYPES(ENET ws2_32 winmm) 63 ELSE() 64 HANDLE_LIBRARY_TYPES(ENET) 65 ENDIF() 43 66 44 SET(ENET_LIBRARIES ${ENet_LIBRARY}) 45 ENDIF (ENet_INCLUDE_DIR AND ENet_LIBRARY) 46 47 IF (ENET_FOUND) 48 IF (NOT ENet_FIND_QUIETLY) 49 MESSAGE(STATUS "ENet was found.") 50 IF (VERBOSE_FIND) 51 MESSAGE (STATUS " include path: ${ENet_INCLUDE_DIR}") 52 MESSAGE (STATUS " library path: ${ENet_LIBRARY}") 53 MESSAGE (STATUS " libraries: enet") 54 ENDIF (VERBOSE_FIND) 55 ENDIF (NOT ENet_FIND_QUIETLY) 56 ELSE (ENET_FOUND) 57 IF (NOT ENet_INCLUDE_DIR) 58 MESSAGE(SEND_ERROR "ENet include path was not found.") 59 ENDIF (NOT ENet_INCLUDE_DIR) 60 IF (NOT ENet_LIBRARY) 61 MESSAGE(SEND_ERROR "ENet library was not found.") 62 ENDIF (NOT ENet_LIBRARY) 63 ENDIF (ENET_FOUND) 64 65 MARK_AS_ADVANCED(ENet_INCLUDE_DIR ENet_LIBRARY) 67 MARK_AS_ADVANCED( 68 ENET_INCLUDE_DIR 69 ENET_LIBRARY_OPTIMIZED 70 ENET_LIBRARY_DEBUG 71 ) -
code/trunk/cmake/FindOGRE.cmake
r1872 r2710 3 3 # This module defines 4 4 # OGRE_INCLUDE_DIR 5 # OGRE_LIBRARIES, the libraries to link against to use OGRE. 6 # OGRE_LIB_DIR, the location of the libraries 5 # OGRE_LIBRARY, the library to link against to use OGRE. 7 6 # OGRE_FOUND, If false, do not try to use OGRE 8 7 # 9 8 # Copyright © 2007, Matt Williams 10 # Modified by Nicolas Schlumberger to make it work on the Tardis-Infrastucture of the ETH Zurich 9 # Modified by Nicolas Schlumberger to make it work on the Tardis-Infrastucture 10 # of the ETH Zurich (removed later on) 11 11 # 12 12 # Redistribution and use is allowed according to the terms of the BSD license. 13 13 # 14 14 # Several changes and additions by Fabian 'x3n' Landau 15 # Lots of simplifications by Adrian Friedli 16 # Version checking by Reto Grieder 15 17 # > www.orxonox.net < 16 18 17 I F (OGRE_LIBRARIES AND OGRE_INCLUDE_DIR AND OGRE_LIB_DIR)18 SET (OGRE_FIND_QUIETLY TRUE) # Already in cache, be silent 19 ENDIF (OGRE_LIBRARIES AND OGRE_INCLUDE_DIR AND OGRE_LIB_DIR)19 INCLUDE(DetermineVersion) 20 INCLUDE(FindPackageHandleAdvancedArgs) 21 INCLUDE(HandleLibraryTypes) 20 22 21 IF (WIN32) #Windows 22 FIND_PATH(OGRE_INCLUDE_DIR Ogre.h 23 ../libs/ogre/OgreMain/include 24 ${DEPENDENCY_DIR}/ogre-1.4.9/include 25 ) 23 FIND_PATH(OGRE_INCLUDE_DIR Ogre.h 24 PATHS $ENV{OGRE_HOME} 25 PATH_SUFFIXES include include/OGRE Ogre.framework/Headers 26 ) 27 FIND_LIBRARY(OGRE_LIBRARY_OPTIMIZED 28 NAMES OgreMain Ogre 29 PATHS $ENV{OGRE_HOME} 30 PATH_SUFFIXES lib bin/Release bin/release Release release 31 ) 32 FIND_LIBRARY(OGRE_LIBRARY_DEBUG 33 NAMES OgreMaind OgreMain_d OgreMainD OgreMain_D Ogred Ogre_d OgreD Ogre_d 34 PATHS $ENV{OGRE_HOME} 35 PATH_SUFFIXES lib bin/Debug bin/debug Debug debug Versions/A 36 ) 26 37 27 SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain) 28 FIND_LIBRARY(OGRE_LIBDIR NAMES ${OGRE_LIBRARIES} PATHS 29 ../libs/ogre/Samples/Common/bin/Release 30 ${DEPENDENCY_DIR}/ogre-1.4.9/lib 31 ) 38 # Inspect OgrePrerquisites.h for the version number 39 DETERMINE_VERSION(OGRE ${OGRE_INCLUDE_DIR}/OgrePrerequisites.h) 32 40 33 # Strip the filename from the path 34 IF (OGRE_LIBDIR) 35 GET_FILENAME_COMPONENT(OGRE_LIBDIR ${OGRE_LIBDIR} PATH) 36 SET (OGRE_LIB_DIR ${OGRE_LIBDIR} CACHE FILEPATH "") 37 ENDIF (OGRE_LIBDIR) 38 ELSE (WIN32) #Unix 39 FIND_PACKAGE(PkgConfig) 40 PKG_SEARCH_MODULE(OGRE OGRE /usr/pack/ogre-1.4.5-sd/i686-debian-linux3.1/lib/pkgconfig/OGRE.pc) # tardis specific hack 41 SET(OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIRS}) 42 SET(OGRE_LIB_DIR ${OGRE_LIBDIR}) 43 SET(OGRE_LIBRARIES ${OGRE_LIBRARIES}) 44 ENDIF (WIN32) 41 # Handle the REQUIRED argument and set OGRE_FOUND 42 # Also check the version requirements 43 FIND_PACKAGE_HANDLE_ADVANCED_ARGS(OGRE DEFAULT_MSG ${OGRE_VERSION} 44 OGRE_LIBRARY_OPTIMIZED 45 OGRE_INCLUDE_DIR 46 ) 45 47 46 #Do some preparation 47 SEPARATE_ARGUMENTS(OGRE_INCLUDE_DIR) 48 SEPARATE_ARGUMENTS(OGRE_LIBRARIES) 48 # Collect optimized and debug libraries 49 HANDLE_LIBRARY_TYPES(OGRE) 49 50 50 SET (OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIR} CACHE PATH "") 51 SET (OGRE_LIBRARIES ${OGRE_LIBRARIES} CACHE STRING "") 52 SET (OGRE_LIB_DIR ${OGRE_LIB_DIR} CACHE PATH "") 53 54 IF (OGRE_INCLUDE_DIR AND OGRE_LIBRARIES AND OGRE_LIB_DIR) 55 SET(OGRE_FOUND TRUE) 56 ENDIF (OGRE_INCLUDE_DIR AND OGRE_LIBRARIES AND OGRE_LIB_DIR) 57 58 IF (OGRE_FOUND) 59 IF (NOT OGRE_FIND_QUIETLY) 60 MESSAGE(STATUS "Ogre was found.") 61 IF (VERBOSE_FIND) 62 MESSAGE (STATUS " include path: ${OGRE_INCLUDE_DIR}") 63 MESSAGE (STATUS " library path: ${OGRE_LIB_DIR}") 64 MESSAGE (STATUS " libraries: ${OGRE_LIBRARIES}") 65 ENDIF (VERBOSE_FIND) 66 ENDIF (NOT OGRE_FIND_QUIETLY) 67 ELSE (OGRE_FOUND) 68 IF (NOT OGRE_INCLUDE_DIR) 69 MESSAGE(SEND_ERROR "Ogre include path was not found.") 70 ENDIF (NOT OGRE_INCLUDE_DIR) 71 IF (NOT OGRE_LIB_DIR) 72 MESSAGE(SEND_ERROR "Ogre library was not found.") 73 ENDIF (NOT OGRE_LIB_DIR) 74 IF (NOT OGRE_LIBRARIES) 75 MESSAGE(SEND_ERROR "Ogre libraries not known.") 76 ENDIF (NOT OGRE_LIBRARIES) 77 ENDIF (OGRE_FOUND) 51 MARK_AS_ADVANCED( 52 OGRE_INCLUDE_DIR 53 OGRE_LIBRARY_OPTIMIZED 54 OGRE_LIBRARY_DEBUG 55 ) -
code/trunk/src/CMakeLists.txt
r2662 r2710 1 INCLUDE_DIRECTORIES(.) 2 INCLUDE_DIRECTORIES(..) 3 INCLUDE_DIRECTORIES(orxonox) 4 INCLUDE_DIRECTORIES(bullet) 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 5 19 20 ################ Various Options ################ 21 22 # various macro includes 23 INCLUDE(FlagUtilities) 24 INCLUDE(GenerateToluaBindings) 25 INCLUDE(InstallUtilities) 26 INCLUDE(SourceFileUtilities) 27 28 # Use TinyXML++ 29 ADD_COMPILER_FLAGS("-DTIXML_USE_TICPP") 30 # OIS dynamic linking requires macro definition, at least for Windows 31 ADD_COMPILER_FLAGS("-DOIS_DYNAMIC_LIB") 32 # Tolua binding speedup if required 33 ADD_COMPILER_FLAGS("-DTOLUA_RELEASE" Release MinSizeRel TOLUA_PARSER_RELEASE) 34 35 ################ OrxonoxConfig.h ################ 36 37 # Check endianness 38 INCLUDE(TestBigEndian) 39 TEST_BIG_ENDIAN(ORXONOX_BIG_ENDIAN) 40 IF(NOT ORXONOX_BIG_ENDIAN) 41 SET(ORXONOX_LITTLE_ENDIAN TRUE) 42 ENDIF() 43 44 # 32/64 bit system check 45 IF(CMAKE_SIZEOF_VOID_P EQUAL 8) 46 SET(ORXONOX_ARCH_64 TRUE) 47 ELSE() 48 SET(ORXONOX_ARCH_32 TRUE) 49 ENDIF() 50 51 # Platforms 52 SET(ORXONOX_PLATFORM_WINDOWS ${WIN32}) 53 SET(ORXONOX_PLATFORM_APPLE ${APPLE}) 54 SET(ORXONOX_PLATFORM_UNIX ${UNIX}) 55 IF(UNIX AND NOT APPLE) 56 SET(ORXONOX_PLATFORM_LINUX TRUE) 57 ENDIF() 58 59 # Check __forceinline 60 INCLUDE(CheckCXXSourceCompiles) 61 SET(_source "int main() { return 0; } __forceinline void test() { return; }") 62 CHECK_CXX_SOURCE_COMPILES("${_source}" HAVE_FORCEINLINE) 63 64 # Check ciso646 include (literal operators) 65 INCLUDE(CheckIncludeFileCXX) 66 CHECK_INCLUDE_FILE_CXX(iso646.h HAVE_ISO646_H) 67 68 # XCode and Visual Studio support multiple configurations. In order to tell the 69 # which one we have to define the macros separately for each configuration 70 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=Debug" Debug) 71 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=Release" Release) 72 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=RelWithDebInfo" RelWithDebInfo) 73 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=MinSizeRel" MinSizeRel) 74 75 SET(GENERATED_FILE_COMMENT 76 "DO NOT EDIT THIS FILE! 77 It has been automatically generated by CMake from OrxonoxConfig.h.in") 78 # Copy and configure OrxonoxConfig which gets included in every file 79 CONFIGURE_FILE(OrxonoxConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/OrxonoxConfig.h) 80 # This file only gets included by very few classes to avoid a large recompilation 81 CONFIGURE_FILE(SpecialConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/SpecialConfig.h) 82 83 84 ############## Include Directories ############## 85 86 # Set the search paths for include files 87 INCLUDE_DIRECTORIES( 88 # External 89 ${OGRE_INCLUDE_DIR} 90 ${CEGUI_INCLUDE_DIR} 91 ${ENET_INCLUDE_DIR} 92 ${Boost_INCLUDE_DIRS} 93 ${OPENAL_INCLUDE_DIRS} 94 ${ALUT_INCLUDE_DIR} 95 ${VORBIS_INCLUDE_DIR} 96 ${OGG_INCLUDE_DIR} 97 ${LUA_INCLUDE_DIR} 98 ${TCL_INCLUDE_PATH} 99 ${DIRECTX_INCLUDE_DIR} 100 ${ZLIB_INCLUDE_DIR} 101 102 # All library includes are prefixed with the path to avoid conflicts 103 ${CMAKE_CURRENT_SOURCE_DIR} 104 # Bullet headers really need the include directory 105 ${CMAKE_CURRENT_SOURCE_DIR}/bullet 106 # Convenience directory 107 ${CMAKE_CURRENT_SOURCE_DIR}/orxonox 108 # OrxonoxConfig.h 109 ${CMAKE_CURRENT_BINARY_DIR} 110 # Tolua bind files for Core 111 ${CMAKE_CURRENT_BINARY_DIR}/core/${CMAKE_CFG_INTDIR} 112 # Tolua bind files for Orxonox 113 ${CMAKE_CURRENT_BINARY_DIR}/orxonox/${CMAKE_CFG_INTDIR} 114 ) 115 116 117 ################ Sub Directories ################ 118 119 # Third party libraries 120 ADD_SUBDIRECTORY(tolua) 121 122 # Include CEGUILua if not requested otherwise 123 IF(CEGUILUA_USE_INTERNAL_LIBRARY) 124 IF(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ceguilua/ceguilua-${CEGUI_VERSION}) 125 MESSAGE(FATAL_ERROR "CEGUILua version not found in src folder. Update list of supported versions in LibraryConfig.cmake!") 126 ENDIF() 127 128 INCLUDE_DIRECTORIES(ceguilua/ceguilua-${CEGUI_VERSION}) 129 ADD_SUBDIRECTORY(ceguilua) 130 ENDIF() 131 132 ADD_SUBDIRECTORY(bullet) 6 133 ADD_SUBDIRECTORY(cpptcl) 134 ADD_SUBDIRECTORY(ogreceguirenderer) 7 135 ADD_SUBDIRECTORY(ois) 8 136 ADD_SUBDIRECTORY(tinyxml) 9 ADD_SUBDIRECTORY(bullet)10 ADD_SUBDIRECTORY(lua)11 ADD_SUBDIRECTORY(tolua)12 137 13 # Some people may not have CEGUILua installed, espc. with version 0.5 14 # And we don't know what lua version it was linked against, so we compile 15 # it ourselves. 16 # So first, find out what CEGUI version we have. 17 18 IF (WIN32) 19 ADD_SUBDIRECTORY(ceguilua-0.6.1/ceguilua) 20 INCLUDE_DIRECTORIES(ceguilua-0.6.1) 21 ELSE (WIN32) 22 IF (${CEGUI_VERSION} LESS 0.6.0) 23 ADD_SUBDIRECTORY(ceguilua-0.5.0b/ceguilua) 24 INCLUDE_DIRECTORIES(ceguilua-0.5.0b) 25 ELSE (${CEGUI_VERSION} LESS 0.6.0) 26 ADD_SUBDIRECTORY(ceguilua-0.6.1/ceguilua) 27 INCLUDE_DIRECTORIES(ceguilua-0.6.1) 28 ENDIF (${CEGUI_VERSION} LESS 0.6.0) 29 ENDIF (WIN32) 30 31 # Include macro to easily add source files in subdirectories 32 INCLUDE(AddSourceFiles) 33 34 # Our own libraries 138 # Orxonox code 35 139 ADD_SUBDIRECTORY(util) 36 140 ADD_SUBDIRECTORY(core) 37 ADD_SUBDIRECTORY(audio)141 #ADD_SUBDIRECTORY(audio) 38 142 ADD_SUBDIRECTORY(network) 39 143 ADD_SUBDIRECTORY(orxonox) 144 145 # Apply version info 146 SET_TARGET_PROPERTIES(util core network orxonox 147 PROPERTIES VERSION ${ORXONOX_VERSION}) -
code/trunk/src/audio/AudioBuffer.h
r2171 r2710 33 33 34 34 #include <string> 35 #include < AL/al.h>35 #include <al.h> 36 36 37 37 namespace orxonox -
code/trunk/src/audio/AudioIncludes.h
r1784 r2710 39 39 #include <string> 40 40 41 #include < AL/al.h>42 #include < AL/alc.h>41 #include <al.h> 42 #include <alc.h> 43 43 #include <AL/alut.h> 44 44 #include <ogg/ogg.h> -
code/trunk/src/audio/AudioPrereqs.h
r2171 r2710 35 35 #define _AudioPrereqs_H__ 36 36 37 #include " util/OrxonoxPlatform.h"37 #include "OrxonoxConfig.h" 38 38 39 39 //----------------------------------------------------------------------- 40 40 // Shared library settings 41 41 //----------------------------------------------------------------------- 42 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( AUDIO_STATIC_BUILD )42 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( AUDIO_STATIC_BUILD ) 43 43 # ifdef AUDIO_SHARED_BUILD 44 44 # define _AudioExport __declspec(dllexport) … … 68 68 } 69 69 70 //-----------------------------------------------------------------------71 // Warnings72 //-----------------------------------------------------------------------73 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC74 75 // set to 4: conversion from 'ogg_int64_t' to 'long', possible loss of data76 #pragma warning (4 : 4244)77 78 #endif79 80 81 70 #endif /* _AudioPrereqs_H__ */ -
code/trunk/src/audio/AudioStream.h
r2171 r2710 34 34 #include <string> 35 35 #include <iostream> 36 #include < AL/al.h>36 #include <al.h> 37 37 #include <vorbis/vorbisfile.h> 38 38 #include <vorbis/codec.h> -
code/trunk/src/audio/CMakeLists.txt
r1505 r2710 1 SET ( AUDIO_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(AUDIO_FILES 21 AudioBuffer.h 22 AudioIncludes.h 23 AudioManager.h 24 AudioPrereqs.h 25 AudioSource.h 26 AudioStream.h 27 2 28 AudioBuffer.cc 3 29 AudioManager.cc … … 5 31 AudioStream.cc 6 32 ) 33 #GET_ALL_HEADER_FILES(AUDIO_HDR_FILES) 34 #SET(AUDIO_FILES ${AUDIO_SRC_FILES} ${AUDIO_HDR_FILES}) 35 GENERATE_SOURCE_GROUPS(${AUDIO_FILES}) 7 36 8 IF (WIN32) 9 ADD_LIBRARY( audio ${AUDIO_SRC_FILES} ) 10 ELSE (WIN32) 11 ADD_LIBRARY( audio SHARED ${AUDIO_SRC_FILES} ) 12 ENDIF (WIN32) 37 ADD_COMPILER_FLAGS("-w44244" MSVC) 13 38 14 TARGET_LINK_LIBRARIES( audio 39 ADD_LIBRARY(audio SHARED ${AUDIO_FILES}) 40 SET_TARGET_PROPERTIES(audio PROPERTIES DEFINE_SYMBOL "AUDIO_SHARED_BUILD") 41 TARGET_LINK_LIBRARIES(audio 15 42 ${OPENAL_LIBRARY} 16 43 ${ALUT_LIBRARY} … … 19 46 ${OGG_LIBRARY} 20 47 core 48 util 21 49 ) 22 50 23 51 ORXONOX_INSTALL(audio) -
code/trunk/src/bullet/AUTHORS
- Property svn:eol-style set to native
-
code/trunk/src/bullet/BulletCollision/CMakeLists.txt
r2662 r2710 1 SET(BulletCollision_SRCS1 ADD_SOURCE_FILES(BULLET_FILES 2 2 BroadphaseCollision/btAxisSweep3.cpp 3 3 BroadphaseCollision/btBroadphaseProxy.cpp … … 10 10 BroadphaseCollision/btQuantizedBvh.cpp 11 11 BroadphaseCollision/btSimpleBroadphase.cpp 12 12 13 CollisionDispatch/btActivatingCollisionAlgorithm.cpp 13 14 CollisionDispatch/btCollisionDispatcher.cpp … … 30 31 CollisionDispatch/btUnionFind.cpp 31 32 CollisionDispatch/SphereTriangleDetector.cpp 33 32 34 CollisionShapes/btBoxShape.cpp 33 35 CollisionShapes/btBvhTriangleMeshShape.cpp … … 63 65 CollisionShapes/btTriangleMeshShape.cpp 64 66 CollisionShapes/btUniformScalingShape.cpp 67 65 68 Gimpact/btContactProcessing.cpp 66 69 Gimpact/btGImpactShape.cpp … … 74 77 Gimpact/btGImpactQuantizedBvh.cpp 75 78 Gimpact/gim_box_set.cpp 79 76 80 NarrowPhaseCollision/btContinuousConvexCollision.cpp 77 81 NarrowPhaseCollision/btGjkEpa2.cpp … … 85 89 NarrowPhaseCollision/btSubSimplexConvexCast.cpp 86 90 NarrowPhaseCollision/btVoronoiSimplexSolver.cpp 91 92 # Headers 93 BroadphaseCollision/btAxisSweep3.h 94 BroadphaseCollision/btBroadphaseInterface.h 95 BroadphaseCollision/btBroadphaseProxy.h 96 BroadphaseCollision/btCollisionAlgorithm.h 97 BroadphaseCollision/btDispatcher.h 98 BroadphaseCollision/btDbvtBroadphase.h 99 BroadphaseCollision/btDbvt.h 100 BroadphaseCollision/btMultiSapBroadphase.h 101 BroadphaseCollision/btOverlappingPairCache.h 102 BroadphaseCollision/btOverlappingPairCallback.h 103 BroadphaseCollision/btQuantizedBvh.h 104 BroadphaseCollision/btSimpleBroadphase.h 105 106 CollisionDispatch/btActivatingCollisionAlgorithm.h 107 CollisionDispatch/btCollisionConfiguration.h 108 CollisionDispatch/btCollisionCreateFunc.h 109 CollisionDispatch/btCollisionDispatcher.h 110 CollisionDispatch/btCollisionObject.h 111 CollisionDispatch/btCollisionWorld.h 112 CollisionDispatch/btCompoundCollisionAlgorithm.h 113 CollisionDispatch/btConvexConcaveCollisionAlgorithm.h 114 CollisionDispatch/btDefaultCollisionConfiguration.h 115 CollisionDispatch/btSphereSphereCollisionAlgorithm.h 116 CollisionDispatch/btBoxBoxCollisionAlgorithm.h 117 CollisionDispatch/btBoxBoxDetector.h 118 CollisionDispatch/btGhostObject.h 119 CollisionDispatch/btSphereBoxCollisionAlgorithm.h 120 CollisionDispatch/btConvexPlaneCollisionAlgorithm.h 121 CollisionDispatch/btSphereTriangleCollisionAlgorithm.h 122 CollisionDispatch/btConvexConvexAlgorithm.h 123 CollisionDispatch/btEmptyCollisionAlgorithm.h 124 CollisionDispatch/btManifoldResult.h 125 CollisionDispatch/btSimulationIslandManager.h 126 CollisionDispatch/btUnionFind.h 127 CollisionDispatch/SphereTriangleDetector.h 128 129 CollisionShapes/btBoxShape.h 130 CollisionShapes/btBvhTriangleMeshShape.h 131 CollisionShapes/btCapsuleShape.h 132 CollisionShapes/btCollisionMargin 133 CollisionShapes/btCollisionShape.h 134 CollisionShapes/btCompoundShape.h 135 CollisionShapes/btConcaveShape.h 136 CollisionShapes/btConeShape.h 137 CollisionShapes/btConvexHullShape.h 138 CollisionShapes/btConvexPointCloudShape.h 139 CollisionShapes/btConvexShape.h 140 CollisionShapes/btConvexInternalShape.h 141 CollisionShapes/btConvexTriangleMeshShape.h 142 CollisionShapes/btCylinderShape.h 143 CollisionShapes/btEmptyShape.h 144 CollisionShapes/btHeightfieldTerrainShape.h 145 CollisionShapes/btMinkowskiSumShape.h 146 CollisionShapes/btMaterial.h 147 CollisionShapes/btMultimaterialTriangleMeshShape.h 148 CollisionShapes/btMultiSphereShape.h 149 CollisionShapes/btOptimizedBvh.h 150 CollisionShapes/btPolyhedralConvexShape.h 151 CollisionShapes/btScaledBvhTriangleMeshShape.h 152 CollisionShapes/btTetrahedronShape.h 153 CollisionShapes/btSphereShape.h 154 CollisionShapes/btShapeHull.h 155 CollisionShapes/btStaticPlaneShape.h 156 CollisionShapes/btStridingMeshInterface.h 157 CollisionShapes/btTriangleCallback.h 158 CollisionShapes/btTriangleBuffer.h 159 CollisionShapes/btTriangleIndexVertexArray.h 160 CollisionShapes/btTriangleIndexVertexMaterialArray.h 161 CollisionShapes/btTriangleMesh.h 162 CollisionShapes/btTriangleMeshShape.h 163 CollisionShapes/btUniformScalingShape.h 164 165 Gimpact/btGImpactShape.h 166 Gimpact/gim_contact.h 167 Gimpact/btGImpactBvh.h 168 Gimpact/btGenericPoolAllocator.h 169 Gimpact/gim_memory.h 170 Gimpact/btGImpactCollisionAlgorithm.h 171 Gimpact/btTriangleShapeEx.h 172 Gimpact/gim_tri_collision.h 173 Gimpact/btGImpactQuantizedBvh.h 174 Gimpact/gim_box_set.h 175 176 NarrowPhaseCollision/btContinuousConvexCollision.h 177 NarrowPhaseCollision/btConvexCast.h 178 NarrowPhaseCollision/btConvexPenetrationDepthSolver.h 179 NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h 180 NarrowPhaseCollision/btGjkConvexCast.h 181 NarrowPhaseCollision/btGjkEpa2.h 182 NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h 183 NarrowPhaseCollision/btGjkPairDetector.h 184 NarrowPhaseCollision/btManifoldPoint.h 185 NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h 186 NarrowPhaseCollision/btPersistentManifold.h 187 NarrowPhaseCollision/btPointCollector.h 188 NarrowPhaseCollision/btRaycastCallback.h 189 NarrowPhaseCollision/btSimplexSolverInterface.h 190 NarrowPhaseCollision/btSubSimplexConvexCast.h 191 NarrowPhaseCollision/btVoronoiSimplexSolver.h 87 192 ) 88 89 ADD_LIBRARY(BulletCollision ${BulletCollision_SRCS}) -
code/trunk/src/bullet/BulletDynamics/CMakeLists.txt
r2662 r2710 1 SET(BulletDynamics_SRCS1 ADD_SOURCE_FILES(BULLET_FILES 2 2 ConstraintSolver/btContactConstraint.cpp 3 3 ConstraintSolver/btConeTwistConstraint.cpp … … 9 9 ConstraintSolver/btSolve2LinearConstraint.cpp 10 10 ConstraintSolver/btTypedConstraint.cpp 11 11 12 Dynamics/Bullet-C-API.cpp 12 13 Dynamics/btDiscreteDynamicsWorld.cpp 13 14 Dynamics/btSimpleDynamicsWorld.cpp 14 15 Dynamics/btRigidBody.cpp 16 15 17 Vehicle/btRaycastVehicle.cpp 16 18 Vehicle/btWheelInfo.cpp 19 17 20 Character/btKinematicCharacterController.cpp 21 22 # Headers 23 ConstraintSolver/btConstraintSolver.h 24 ConstraintSolver/btContactConstraint.h 25 ConstraintSolver/btContactSolverInfo.h 26 ConstraintSolver/btConeTwistConstraint.h 27 ConstraintSolver/btGeneric6DofConstraint.h 28 ConstraintSolver/btHingeConstraint.h 29 ConstraintSolver/btJacobianEntry.h 30 ConstraintSolver/btPoint2PointConstraint.h 31 ConstraintSolver/btSequentialImpulseConstraintSolver.h 32 ConstraintSolver/btSliderConstraint.h 33 ConstraintSolver/btSolve2LinearConstraint.h 34 ConstraintSolver/btSolverBody.h 35 ConstraintSolver/btSolverConstraint.h 36 ConstraintSolver/btTypedConstraint.h 37 38 Dynamics/btContinuousDynamicsWorld.h 39 Dynamics/btDiscreteDynamicsWorld.h 40 Dynamics/btDynamicsWorld.h 41 Dynamics/btSimpleDynamicsWorld.h 42 Dynamics/btRigidBody.h 43 44 Vehicle/btRaycastVehicle.h 45 Vehicle/btVehicleRaycaster.h 46 Vehicle/btWheelInfo.h 47 48 Character/btCharacterControllerInterface.h 49 Character/btKinematicCharacterController.h 18 50 ) 19 20 ADD_LIBRARY(BulletDynamics ${BulletDynamics_SRCS}) -
code/trunk/src/bullet/CMakeLists.txt
r2662 r2710 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(BULLET_FILES 21 btBulletCollisionCommon.h 22 btBulletDynamicsCommon.h 23 Bullet-C-Api.h 24 ) 1 25 ADD_SUBDIRECTORY(BulletCollision) 2 26 ADD_SUBDIRECTORY(BulletDynamics) 3 27 ADD_SUBDIRECTORY(LinearMath) 28 29 GENERATE_SOURCE_GROUPS(${BULLET_FILES}) 30 31 # No warnings needed from third party libraries 32 REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) 33 ADD_COMPILER_FLAGS("-w") 34 35 IF(MSVC) 36 ADD_LIBRARY(bullet_orxonox STATIC ${BULLET_FILES}) 37 ELSE(MSVC) 38 ADD_LIBRARY(bullet_orxonox SHARED ${BULLET_FILES}) 39 ORXONOX_INSTALL(bullet_orxonox) 40 ENDIF(MSVC) 41 42 SET_TARGET_PROPERTIES(bullet_orxonox PROPERTIES VERSION 2.73) -
code/trunk/src/bullet/ChangeLog
- Property svn:eol-style set to native
-
code/trunk/src/bullet/LICENSE
- Property svn:eol-style set to native
-
code/trunk/src/bullet/LinearMath/CMakeLists.txt
r2662 r2710 1 SET(LinearMath_SRCS1 ADD_SOURCE_FILES(BULLET_FILES 2 2 btConvexHull.cpp 3 3 btQuickprof.cpp 4 4 btGeometryUtil.cpp 5 5 btAlignedAllocator.cpp 6 7 # Headers 8 btAlignedObjectArray.h 9 btList.h 10 btPoolAllocator.h 11 btRandom.h 12 btVector3.h 13 btDefaultMotionState.h 14 btMatrix3x3.h 15 btQuadWord.h 16 btHashMap.h 17 btScalar.h 18 btAabbUtil2.h 19 btConvexHull.h 20 btMinMax.h 21 btQuaternion.h 22 btStackAlloc.h 23 btGeometryUtil.h 24 btMotionState.h 25 btTransform.h 26 btAlignedAllocator.h 27 btIDebugDraw.h 28 btQuickprof.h 29 btTransformUtil.h 6 30 ) 7 8 ADD_LIBRARY(LinearMath ${LinearMath_SRCS}) -
code/trunk/src/bullet/NEWS
- Property svn:eol-style set to native
-
code/trunk/src/bullet/README
- Property svn:eol-style set to native
-
code/trunk/src/bullet/VERSION
- Property svn:eol-style set to native
-
code/trunk/src/core/ArgumentCompletionFunctions.cc
r2087 r2710 27 27 */ 28 28 29 #include "ArgumentCompletionFunctions.h" 30 29 31 #include <iostream> 30 32 #include <map> 31 32 33 #include <boost/filesystem.hpp> 33 34 34 #include "ArgumentCompletionFunctions.h"35 35 #include "CoreIncludes.h" 36 36 #include "Identifier.h" … … 63 63 startdirectory = "."; 64 64 } 65 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN3265 #ifdef ORXONOX_PLATFORM_WINDOWS 66 66 else 67 67 { 68 68 std::string dir = startdirectory.string(); 69 69 if (dir.size() > 0 && dir[dir.size() - 1] == ':') 70 startdirectory = dir + "/";70 startdirectory = dir + CP_SLASH; 71 71 } 72 72 #endif … … 78 78 { 79 79 if (boost::filesystem::is_directory(*file)) 80 dirlist.push_back(ArgumentCompletionListElement((*file).string() + "/", getLowercase((*file).string()) + "/", (*file).leaf() + "/"));80 dirlist.push_back(ArgumentCompletionListElement((*file).string() + CP_SLASH, getLowercase((*file).string()) + "/", (*file).leaf() + "/")); 81 81 else 82 82 filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf())); -
code/trunk/src/core/BaseObject.cc
r2662 r2710 33 33 34 34 #include "BaseObject.h" 35 #include "tinyxml/tinyxml.h" 35 36 #include <tinyxml/tinyxml.h> 37 36 38 #include "CoreIncludes.h" 37 39 #include "EventIncludes.h" -
code/trunk/src/core/CMakeLists.txt
r2131 r2710 1 SET(CORE_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(CORE_SRC_FILES 2 21 Clock.cc 3 22 ConfigFileManager.cc … … 41 60 TclBind.cc 42 61 TclThreadManager.cc 62 ) 63 ADD_SUBDIRECTORY(input) 64 GET_ALL_HEADER_FILES(CORE_HDR_FILES) 65 SET(CORE_FILES ${CORE_SRC_FILES} ${CORE_HDR_FILES}) 43 66 44 tolua/tolua_bind.cc 67 GENERATE_SOURCE_GROUPS(${CORE_FILES}) 68 GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h) 69 70 ADD_LIBRARY(core SHARED ${CORE_FILES}) 71 72 SET_TARGET_PROPERTIES(core PROPERTIES DEFINE_SYMBOL "CORE_SHARED_BUILD") 73 TARGET_LINK_LIBRARIES(core 74 ${OGRE_LIBRARY} 75 ${Boost_THREAD_LIBRARY} 76 ${Boost_FILESYSTEM_LIBRARY} 77 ${Boost_SYSTEM_LIBRARY} 78 ${Boost_DATE_TIME_LIBRARY} # MSVC only 79 ${LUA_LIBRARIES} 80 cpptcl_orxonox 81 ois_orxonox 82 tinyxml++_orxonox 83 tolua++_orxonox 84 util 45 85 ) 46 86 47 ADD_SOURCE_DIRECTORY(CORE_SRC_FILES input) 48 49 GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION) 50 ADD_CUSTOM_COMMAND( 51 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h 52 COMMAND ${TOLUA_EXE} -n Core -o ../../src/core/tolua/tolua_bind.cc -H ../../src/core/tolua/tolua_bind.h ../../src/core/tolua/tolua.pkg 53 DEPENDS 54 tolua_orxonox 55 tolua/tolua.pkg 56 LuaBind.h 57 CommandExecutor.h 58 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib 59 ) 60 61 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES}) 62 63 TARGET_LINK_LIBRARIES(core 64 ${OGRE_LIBRARIES} 65 ${Boost_thread_LIBRARIES} 66 ${Boost_filesystem_LIBRARIES} 67 lua_orxonox 68 cpptcl_orxonox 69 ois_orxonox 70 tinyxml_orxonox 71 tolualib_orxonox 72 util 73 ) 87 ORXONOX_INSTALL(core) -
code/trunk/src/core/CommandExecutor.h
r2662 r2710 36 36 #include "CommandEvaluation.h" 37 37 38 namespace orxonox // tolua_export 39 { // tolua_export 38 // tolua_begin 39 namespace orxonox 40 { 40 41 class _CoreExport CommandExecutor 41 /*42 class CommandExecutor { // tolua_export43 */44 42 { 43 // tolua_end 45 44 public: 46 45 static bool execute(const std::string& command, bool useTcl = true); // tolua_export -
code/trunk/src/core/CommandLine.cc
r2662 r2710 29 29 #include "CommandLine.h" 30 30 31 #include <boost/filesystem.hpp> 31 32 #include "util/String.h" 32 33 #include "util/SubString.h" 34 #include "Core.h" 33 35 34 36 namespace orxonox … … 299 301 this->_parse(args); 300 302 303 std::string filename = CommandLine::getValue("optionsFile").getString(); 304 boost::filesystem::path filepath(Core::getConfigPath() / filename); 305 301 306 // look for additional arguments in given file or start.ini as default 302 307 // They will not overwrite the arguments given directly 303 308 std::ifstream file; 304 std::string filename = CommandLine::getValue("optionsFile").getString(); 305 file.open(filename.c_str()); 309 file.open(filepath.file_string().c_str()); 306 310 args.clear(); 307 311 if (file) -
code/trunk/src/core/ConfigFileManager.cc
r2662 r2710 30 30 31 31 #include <cassert> 32 #include <boost/filesystem.hpp> 33 32 34 #include "util/Convert.h" 33 35 #include "util/String.h" 34 36 #include "ConsoleCommand.h" 35 37 #include "ConfigValueContainer.h" 38 #include "Core.h" 36 39 37 40 namespace orxonox … … 220 223 void ConfigFile::load(bool bCreateIfNotExisting) 221 224 { 222 // Be sure we start from new 225 // Be sure we start from new in the memory 223 226 this->clear(); 224 227 225 // This creates the config file if it's not existing 226 std::ofstream createFile; 227 createFile.open(this->filename_.c_str(), std::fstream::app); 228 createFile.close(); 228 // Get default file if necessary and available 229 boost::filesystem::path filepath(Core::getConfigPath() / this->filename_); 230 if (!boost::filesystem::exists(filepath)) 231 { 232 // Try to get default one from the media folder 233 boost::filesystem::path defaultFilepath(Core::getMediaPath() / "defaultConfig" / this->filename_); 234 if (boost::filesystem::exists(defaultFilepath)) 235 { 236 boost::filesystem::copy_file(defaultFilepath, filepath); 237 } 238 } 229 239 230 240 // Open the file 231 241 std::ifstream file; 232 file.open(this->filename_.c_str(), std::fstream::in); 233 234 if (!file.is_open()) 235 { 236 COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl; 237 COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl; 238 return; 239 } 240 241 char linearray[CONFIG_FILE_MAX_LINELENGHT]; 242 243 ConfigFileSection* newsection = 0; 244 245 while (file.good() && !file.eof()) 246 { 247 file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); 248 249 std::string line = std::string(linearray); 250 251 std::string temp = getStripped(line); 252 if (!isEmpty(temp) && !isComment(temp)) 253 { 254 size_t pos1 = temp.find('['); 255 if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; 256 size_t pos2 = line.find(']'); 257 258 if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) 242 file.open(filepath.file_string().c_str(), std::fstream::in); 243 if (file.is_open()) 244 { 245 246 char linearray[CONFIG_FILE_MAX_LINELENGHT]; 247 248 ConfigFileSection* newsection = 0; 249 250 while (file.good() && !file.eof()) 251 { 252 file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); 253 254 std::string line = std::string(linearray); 255 256 std::string temp = getStripped(line); 257 if (!isEmpty(temp) && !isComment(temp)) 259 258 { 260 // New section 261 std::string comment = line.substr(pos2 + 1); 262 if (isComment(comment)) 263 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); 264 else 265 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); 266 this->sections_.insert(this->sections_.end(), newsection); 267 continue; 268 } 269 } 270 271 if (newsection != 0) 272 { 273 if (isComment(line)) 274 { 275 // New comment 276 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); 277 continue; 278 } 279 else 280 { 281 size_t pos1 = line.find('='); 282 283 if (pos1 != std::string::npos && pos1 > 0) 259 size_t pos1 = temp.find('['); 260 if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; 261 size_t pos2 = line.find(']'); 262 263 if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) 284 264 { 285 // New entry 286 size_t pos2 = line.find('['); 287 size_t pos3 = line.find(']'); 288 size_t commentposition = getNextCommentPosition(line, pos1 + 1); 289 while (isBetweenQuotes(line, commentposition)) 290 { 291 commentposition = getNextCommentPosition(line, commentposition + 1); 292 } 293 std::string value = "", comment = ""; 294 if (commentposition == std::string::npos) 295 { 296 value = removeTrailingWhitespaces(line.substr(pos1 + 1)); 297 } 265 // New section 266 std::string comment = line.substr(pos2 + 1); 267 if (isComment(comment)) 268 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); 298 269 else 299 { 300 value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1)); 301 comment = removeTrailingWhitespaces(line.substr(commentposition)); 302 } 303 304 if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) 305 { 306 // There might be an array index 307 unsigned int index = 0; 308 if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1))) 309 { 310 // New array 311 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); 312 (*it)->setValue(value); 313 (*it)->setComment(comment); 314 continue; 315 } 316 } 317 318 // New value 319 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment)); 270 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); 271 this->sections_.insert(this->sections_.end(), newsection); 320 272 continue; 321 273 } 322 274 } 323 } 324 } 325 326 file.close(); 327 328 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 329 330 // Save the file in case something changed (like stripped whitespaces) 331 this->save(); 332 333 // Update all ConfigValueContainers 334 this->updateConfigValues(); 275 276 if (newsection != 0) 277 { 278 if (isComment(line)) 279 { 280 // New comment 281 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); 282 continue; 283 } 284 else 285 { 286 size_t pos1 = line.find('='); 287 288 if (pos1 != std::string::npos && pos1 > 0) 289 { 290 // New entry 291 size_t pos2 = line.find('['); 292 size_t pos3 = line.find(']'); 293 size_t commentposition = getNextCommentPosition(line, pos1 + 1); 294 while (isBetweenQuotes(line, commentposition)) 295 { 296 commentposition = getNextCommentPosition(line, commentposition + 1); 297 } 298 std::string value = "", comment = ""; 299 if (commentposition == std::string::npos) 300 { 301 value = removeTrailingWhitespaces(line.substr(pos1 + 1)); 302 } 303 else 304 { 305 value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1)); 306 comment = removeTrailingWhitespaces(line.substr(commentposition)); 307 } 308 309 if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) 310 { 311 // There might be an array index 312 unsigned int index = 0; 313 if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1))) 314 { 315 // New array 316 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); 317 (*it)->setValue(value); 318 (*it)->setComment(comment); 319 continue; 320 } 321 } 322 323 // New value 324 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment)); 325 continue; 326 } 327 } 328 } 329 } 330 331 file.close(); 332 333 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 334 335 // Save the file in case something changed (like stripped whitespaces) 336 this->save(); 337 338 // Update all ConfigValueContainers 339 this->updateConfigValues(); 340 } // end file.is_open() 335 341 } 336 342 337 343 void ConfigFile::save() const 338 344 { 345 boost::filesystem::path filepath(Core::getConfigPath() / this->filename_); 346 339 347 std::ofstream file; 340 file.open( this->filename_.c_str(), std::fstream::out);348 file.open(filepath.file_string().c_str(), std::fstream::out); 341 349 file.setf(std::ios::fixed, std::ios::floatfield); 342 350 file.precision(6); -
code/trunk/src/core/Core.cc
r2662 r2710 33 33 34 34 #include "Core.h" 35 35 36 #include <cassert> 37 #include <fstream> 38 #include <cstdlib> 39 #include <cstdio> 40 #include <boost/filesystem.hpp> 41 42 #ifdef ORXONOX_PLATFORM_WINDOWS 43 # include <windows.h> 44 #elif defined(ORXONOX_PLATFORM_APPLE) 45 # include <sys/param.h> 46 # include <mach-o/dyld.h> 47 #else /* Linux */ 48 # include <sys/types.h> 49 # include <unistd.h> 50 #endif 51 52 #include "SpecialConfig.h" 53 #include "util/Exception.h" 36 54 #include "Language.h" 37 55 #include "CoreIncludes.h" 38 56 #include "ConfigValueIncludes.h" 57 #include "LuaBind.h" 58 #include "CommandLine.h" 39 59 40 60 namespace orxonox 41 61 { 62 //! Path to the parent directory of the ones above if program was installed with relativ pahts 63 static boost::filesystem::path rootPath_g; 64 static boost::filesystem::path executablePath_g; //!< Path to the executable 65 static boost::filesystem::path mediaPath_g; //!< Path to the media file folder 66 static boost::filesystem::path configPath_g; //!< Path to the config file folder 67 static boost::filesystem::path logPath_g; //!< Path to the log file folder 68 42 69 bool Core::bShowsGraphics_s = false; 43 70 bool Core::bHasServer_s = false; … … 46 73 bool Core::bIsMaster_s = false; 47 74 48 Core* Core::singletonRef_s = 0; 75 bool Core::isDevBuild_s = false; 76 Core* Core::singletonRef_s = 0; 77 78 SetCommandLineArgument(mediaPath, "").information("PATH"); 79 SetCommandLineArgument(directory, "").information("DIR"); 49 80 50 81 /** … … 58 89 assert(Core::singletonRef_s == 0); 59 90 Core::singletonRef_s = this; 91 60 92 this->bInitializeRandomNumberGenerator_ = false; 61 62 93 this->setConfigValues(); 94 95 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 96 OutputHandler::getOutStream().setLogPath(Core::getLogPathString()); 97 98 // Possible media path override by the command line 99 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) 100 { 101 //std::string mediaPath = CommandLine::getValue("mediaPath"); 102 Core::tsetMediaPath(CommandLine::getValue("mediaPath")); 103 } 63 104 } 64 105 … … 77 118 void Core::setConfigValues() 78 119 { 79 SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); 80 SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); 81 SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 120 #ifdef NDEBUG 121 const unsigned int defaultLevelConsole = 1; 122 const unsigned int defaultLevelLogfile = 3; 123 const unsigned int defaultLevelShell = 1; 124 #else 125 const unsigned int defaultLevelConsole = 3; 126 const unsigned int defaultLevelLogfile = 4; 127 const unsigned int defaultLevelShell = 3; 128 #endif 129 SetConfigValue(softDebugLevelConsole_, defaultLevelConsole) 130 .description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); 131 SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile) 132 .description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); 133 SetConfigValue(softDebugLevelShell_, defaultLevelShell) 134 .description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 135 82 136 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); 83 137 SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator); 138 139 SetConfigValue(mediaPathString_, Core::getMediaPathPOSIXString()) 140 .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged); 84 141 } 85 142 … … 109 166 // Read the translation file after the language was configured 110 167 Language::getLanguage().readTranslatedLanguageFile(); 168 } 169 170 /** 171 @brief 172 Callback function if the media path has changed. 173 */ 174 void Core::mediaPathChanged() 175 { 176 mediaPath_g = boost::filesystem::path(this->mediaPathString_); 111 177 } 112 178 … … 177 243 } 178 244 245 /** 246 @brief 247 Temporary sets the media path 248 @param path 249 The new media path 250 */ 251 void Core::_tsetMediaPath(const std::string& path) 252 { 253 ModifyConfigValue(mediaPathString_, tset, path); 254 } 255 256 /*static*/ const boost::filesystem::path& Core::getMediaPath() 257 { 258 return mediaPath_g; 259 } 260 /*static*/ std::string Core::getMediaPathString() 261 { 262 return mediaPath_g.directory_string() + CP_SLASH; 263 } 264 /*static*/ std::string Core::getMediaPathPOSIXString() 265 { 266 return mediaPath_g.string() + '/'; 267 268 } 269 270 /*static*/ const boost::filesystem::path& Core::getConfigPath() 271 { 272 return configPath_g; 273 } 274 /*static*/ std::string Core::getConfigPathString() 275 { 276 return configPath_g.directory_string() + CP_SLASH; 277 } 278 /*static*/ std::string Core::getConfigPathPOSIXString() 279 { 280 return configPath_g.string() + '/'; 281 } 282 283 /*static*/ const boost::filesystem::path& Core::getLogPath() 284 { 285 return logPath_g; 286 } 287 /*static*/ std::string Core::getLogPathString() 288 { 289 return logPath_g.directory_string() + CP_SLASH; 290 } 291 /*static*/ std::string Core::getLogPathPOSIXString() 292 { 293 return logPath_g.string() + '/'; 294 } 295 179 296 void Core::initializeRandomNumberGenerator() 180 297 { … … 187 304 } 188 305 } 306 307 /** 308 @brief 309 Performs the rather lower level operations just after 310 int main() has been called. 311 @remarks 312 This gets called AFTER pre-main stuff like AddFactory, 313 SetConsoleCommand, etc. 314 */ 315 /*static*/ void Core::postMainInitialisation() 316 { 317 // set location of the executable 318 Core::setExecutablePath(); 319 320 // Determine whether we have an installed or a binary dir run 321 // The latter occurs when simply running from the build directory 322 Core::checkDevBuild(); 323 324 // Make sure the directories we write in exist or else make them 325 Core::createDirectories(); 326 } 327 328 /** 329 @brief 330 Compares the executable path with the working directory 331 */ 332 /*static*/ void Core::setExecutablePath() 333 { 334 #ifdef ORXONOX_PLATFORM_WINDOWS 335 // get executable module 336 TCHAR buffer[1024]; 337 if (GetModuleFileName(NULL, buffer, 1024) == 0) 338 ThrowException(General, "Could not retrieve executable path."); 339 340 #elif defined(ORXONOX_PLATFORM_APPLE) 341 char buffer[1024]; 342 unsigned long path_len = 1023; 343 if (_NSGetExecutablePath(buffer, &path_len)) 344 ThrowException(General, "Could not retrieve executable path."); 345 346 #else /* Linux */ 347 /* written by Nicolai Haehnle <prefect_@gmx.net> */ 348 349 /* Get our PID and build the name of the link in /proc */ 350 char linkname[64]; /* /proc/<pid>/exe */ 351 if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0) 352 { 353 /* This should only happen on large word systems. I'm not sure 354 what the proper response is here. 355 Since it really is an assert-like condition, aborting the 356 program seems to be in order. */ 357 assert(false); 358 } 359 360 /* Now read the symbolic link */ 361 char buffer[1024]; 362 int ret; 363 ret = readlink(linkname, buffer, 1024); 364 /* In case of an error, leave the handling up to the caller */ 365 if (ret == -1) 366 ThrowException(General, "Could not retrieve executable path."); 367 368 /* Ensure proper NUL termination */ 369 buffer[ret] = 0; 370 #endif 371 372 executablePath_g = boost::filesystem::path(buffer); 373 #ifndef ORXONOX_PLATFORM_APPLE 374 executablePath_g = executablePath_g.branch_path(); // remove executable name 375 #endif 376 } 377 378 /** 379 @brief 380 Checks for "orxonox_dev_build.keep_me" in the executable diretory. 381 If found it means that this is not an installed run, hence we 382 don't write the logs and config files to ~/.orxonox 383 */ 384 /*static*/ void Core::checkDevBuild() 385 { 386 if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me")) 387 { 388 COUT(1) << "Running from the build tree." << std::endl; 389 Core::isDevBuild_s = true; 390 mediaPath_g = ORXONOX_MEDIA_DEV_PATH; 391 configPath_g = ORXONOX_CONFIG_DEV_PATH; 392 logPath_g = ORXONOX_LOG_DEV_PATH; 393 } 394 else 395 { 396 #ifdef INSTALL_COPYABLE // --> relative paths 397 // Also set the root path 398 boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH); 399 rootPath_g = executablePath_g; 400 while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) || rootPath_g.empty()) 401 rootPath_g = rootPath_g.branch_path(); 402 if (rootPath_g.empty()) 403 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?"); 404 405 // Using paths relative to the install prefix, complete them 406 mediaPath_g = rootPath_g / ORXONOX_MEDIA_INSTALL_PATH; 407 configPath_g = rootPath_g / ORXONOX_CONFIG_INSTALL_PATH; 408 logPath_g = rootPath_g / ORXONOX_LOG_INSTALL_PATH; 409 #else 410 // There is no root path, so don't set it at all 411 412 mediaPath_g = ORXONOX_MEDIA_INSTALL_PATH; 413 414 // Get user directory 415 # ifdef ORXONOX_PLATFORM_UNIX /* Apple? */ 416 char* userDataPathPtr(getenv("HOME")); 417 # else 418 char* userDataPathPtr(getenv("APPDATA")); 419 # endif 420 if (userDataPathPtr == NULL) 421 ThrowException(General, "Could not retrieve user data path."); 422 boost::filesystem::path userDataPath(userDataPathPtr); 423 userDataPath /= ".orxonox"; 424 425 configPath_g = userDataPath / ORXONOX_CONFIG_INSTALL_PATH; 426 logPath_g = userDataPath / ORXONOX_LOG_INSTALL_PATH; 427 #endif 428 } 429 430 // Option to put all the config and log files in a separate folder 431 if (!CommandLine::getArgument("directory")->hasDefaultValue()) 432 { 433 std::string directory(CommandLine::getValue("directory")); 434 configPath_g = configPath_g / directory; 435 logPath_g = logPath_g / directory; 436 } 437 } 438 439 /* 440 @brief 441 Checks for the log and the config directory and creates them 442 if necessary. Otherwise me might have problems opening those files. 443 */ 444 /*static*/ void Core::createDirectories() 445 { 446 std::vector<std::pair<boost::filesystem::path, std::string> > directories; 447 directories.push_back(std::pair<boost::filesystem::path, std::string> 448 (boost::filesystem::path(configPath_g), "config")); 449 directories.push_back(std::pair<boost::filesystem::path, std::string> 450 (boost::filesystem::path(logPath_g), "log")); 451 452 for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin(); 453 it != directories.end(); ++it) 454 { 455 if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first)) 456 { 457 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \ 458 Please remove " + it->first.file_string()); 459 } 460 if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?) 461 { 462 COUT(4) << "Created " << it->second << " directory" << std::endl; 463 } 464 } 465 } 189 466 } -
code/trunk/src/core/Core.h
r2662 r2710 44 44 #include "util/OutputHandler.h" 45 45 46 // Only allow main to access postMainInitialisation, so we need a forward declaration 47 int main(int, char**); 48 // boost::filesystem header has quite a large tail, use forward declaration 49 namespace boost { namespace filesystem 50 { 51 struct path_traits; 52 template<class String, class Traits> class basic_path; 53 typedef basic_path< std::string, path_traits> path; 54 } } 55 46 56 namespace orxonox 47 57 { … … 49 59 class _CoreExport Core : public OrxonoxClass 50 60 { 61 friend int ::main(int, char**); // sets isDevBuild_s 62 51 63 public: 52 64 Core(); 53 65 ~Core(); 54 66 void setConfigValues(); 55 void debugLevelChanged();56 void languageChanged();57 67 58 68 static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; } … … 62 72 static const std::string& getLanguage(); 63 73 static void resetLanguage(); 74 75 static bool isDevBuild() { return Core::isDevBuild_s; } 76 77 static void tsetMediaPath(const std::string& path) 78 { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); } 79 static const boost::filesystem::path& getMediaPath(); 80 static const boost::filesystem::path& getConfigPath(); 81 static const boost::filesystem::path& getLogPath(); 82 static std::string getMediaPathString(); 83 static std::string getConfigPathString(); 84 static std::string getLogPathString(); 85 static std::string getMediaPathPOSIXString(); 86 static std::string getConfigPathPOSIXString(); 87 static std::string getLogPathPOSIXString(); 64 88 65 89 // fast access global variables. … … 79 103 void resetLanguageIntern(); 80 104 void initializeRandomNumberGenerator(); 105 void debugLevelChanged(); 106 void languageChanged(); 107 void mediaPathChanged(); 108 void _tsetMediaPath(const std::string& path); 109 110 static void postMainInitialisation(); 111 static void checkDevBuild(); 112 static void setExecutablePath(); 113 static void createDirectories(); 81 114 82 115 int softDebugLevel_; //!< The debug level … … 85 118 int softDebugLevelShell_; //!< The debug level for the ingame shell 86 119 std::string language_; //!< The language 87 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 120 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 121 std::string mediaPathString_; //!< Path to the data/media file folder as string 88 122 89 123 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics … … 93 127 static bool bIsMaster_s; 94 128 129 static bool isDevBuild_s; //!< True for builds in the build directory (not installed) 130 95 131 static Core* singletonRef_s; 96 132 }; -
code/trunk/src/core/CorePrereqs.h
r2662 r2710 35 35 #define _CorePrereqs_H__ 36 36 37 #include " util/OrxonoxPlatform.h"37 #include "OrxonoxConfig.h" 38 38 39 39 #include <string> … … 42 42 // Shared library settings 43 43 //----------------------------------------------------------------------- 44 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( CORE_STATIC_BUILD )44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD ) 45 45 # ifdef CORE_SHARED_BUILD 46 46 # define _CoreExport __declspec(dllexport) -
code/trunk/src/core/Factory.h
r2662 r2710 49 49 #include <map> 50 50 #include <string> 51 #include "util/Integers.h"52 51 53 52 namespace orxonox -
code/trunk/src/core/Functor.h
r2662 r2710 436 436 437 437 // disable annoying warning about forcing value to boolean 438 #if ORXONOX_COMPILER ==ORXONOX_COMPILER_MSVC438 #ifdef ORXONOX_COMPILER_MSVC 439 439 #pragma warning(push) 440 440 #pragma warning(disable:4100 4800) … … 475 475 } 476 476 477 #if ORXONOX_COMPILER ==ORXONOX_COMPILER_MSVC477 #ifdef ORXONOX_COMPILER_MSVC 478 478 #pragma warning(pop) 479 479 #endif -
code/trunk/src/core/IRC.h
r1505 r2710 32 32 #include "CorePrereqs.h" 33 33 34 #include <cpptcl/cpptcl.h> 34 35 #include "OrxonoxClass.h" 35 #include "cpptcl/CppTcl.h"36 36 37 37 namespace orxonox -
code/trunk/src/core/Identifier.h
r2662 r2710 61 61 #include <utility> 62 62 #include <typeinfo> 63 #include < stdlib.h>63 #include <cstdlib> 64 64 #include <cassert> 65 65 … … 68 68 #include "Super.h" 69 69 #include "Functor.h" 70 #include "util/Integers.h"71 70 #include "util/Debug.h" 72 71 #include "util/String.h" -
code/trunk/src/core/Language.cc
r2662 r2710 35 35 36 36 #include <fstream> 37 #include <boost/filesystem.hpp> 37 38 38 39 #include "Core.h" … … 205 206 COUT(4) << "Read default language file." << std::endl; 206 207 208 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_)); 209 207 210 // This creates the file if it's not existing 208 211 std::ofstream createFile; 209 createFile.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::app);212 createFile.open(filepath.file_string().c_str(), std::fstream::app); 210 213 createFile.close(); 211 214 212 215 // Open the file 213 216 std::ifstream file; 214 file.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::in);217 file.open(filepath.file_string().c_str(), std::fstream::in); 215 218 216 219 if (!file.is_open()) … … 254 257 COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl; 255 258 259 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage())); 260 256 261 // Open the file 257 262 std::ifstream file; 258 file.open( getFilename(Core::getLanguage()).c_str(), std::fstream::in);263 file.open(filepath.file_string().c_str(), std::fstream::in); 259 264 260 265 if (!file.is_open()) … … 308 313 COUT(4) << "Language: Write default language file." << std::endl; 309 314 315 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_)); 316 310 317 // Open the file 311 318 std::ofstream file; 312 file.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::out);319 file.open(filepath.file_string().c_str(), std::fstream::out); 313 320 314 321 if (!file.is_open()) -
code/trunk/src/core/Loader.cc
r2662 r2710 28 28 29 29 #include "Loader.h" 30 31 #include <tinyxml/ticpp.h> 32 30 33 #include "XMLFile.h" 31 34 #include "BaseObject.h" … … 39 42 #include "util/Exception.h" 40 43 41 #include "tinyxml/ticpp.h"42 43 44 namespace orxonox 44 45 { -
code/trunk/src/core/LuaBind.cc
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem3/src/core/LuaBind.cc merged eligible /code/branches/lodfinal/src/core/LuaBind.cc merged eligible /code/branches/network/src/core/LuaBind.cc merged eligible /code/branches/objecthierarchy2/src/core/LuaBind.cc merged eligible /code/branches/pickups2/src/core/LuaBind.cc merged eligible /code/branches/presentation/src/core/LuaBind.cc merged eligible /code/branches/questsystem2/src/core/LuaBind.cc merged eligible /code/branches/weapon2/src/core/LuaBind.cc merged eligible /code/branches/buildsystem/src/core/LuaBind.cc 1874-2276,2278-2400 /code/branches/buildsystem/src/core/Script.cc 1874-2238 /code/branches/buildsystem2/src/core/LuaBind.cc 2506-2658 /code/branches/ceguilua/src/core/LuaBind.cc 1802-1808 /code/branches/core3/src/core/LuaBind.cc 1572-1739 /code/branches/gcc43/src/core/LuaBind.cc 1580 /code/branches/gui/src/core/LuaBind.cc 1635-1723 /code/branches/input/src/core/LuaBind.cc 1629-1636 /code/branches/network64/src/core/LuaBind.cc 2210-2355 /code/branches/objecthierarchy/src/core/LuaBind.cc 1911-2085,2100,2110-2169 /code/branches/overlay/src/core/LuaBind.cc 2117-2385 /code/branches/physics/src/core/LuaBind.cc 1912-2055,2107-2439 /code/branches/physics_merge/src/core/LuaBind.cc 2436-2457 /code/branches/pickups/src/core/LuaBind.cc 1926-2086,2127 /code/branches/questsystem/src/core/LuaBind.cc 1894-2088 /code/branches/script_trigger/src/core/LuaBind.cc 1295-1953,1955 /code/branches/weapon/src/core/LuaBind.cc 1925-2094
r2662 r2710 32 32 #include <map> 33 33 34 #include "lua/lua.hpp" 35 #include "tolua/tolua++.h" 36 #include "tolua/tolua_bind.h" 34 extern "C" { 35 #include <lua.h> 36 #include <lualib.h> 37 } 38 #include <tolua/tolua++.h> 39 #include <boost/filesystem.hpp> 40 37 41 #include "util/String.h" 38 #include "CoreIncludes.h" 42 #include "util/Debug.h" 43 #include "ToluaBindCore.h" 44 #include "Core.h" 39 45 40 46 namespace orxonox … … 46 52 assert(LuaBind::singletonRef_s == 0); 47 53 LuaBind::singletonRef_s = this; 54 55 this->includePath_ = Core::getMediaPathPOSIXString(); 48 56 49 57 luaState_ = lua_open(); … … 78 86 void LuaBind::loadFile(std::string filename, bool luaTags) 79 87 { 88 boost::filesystem::path filepath(filename); 89 80 90 output_ = ""; 81 91 std::ifstream file; 82 file.open(file name.c_str(), std::fstream::in);92 file.open(filepath.file_string().c_str(), std::fstream::in); 83 93 84 94 if (!file.is_open()) -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/src/core/LuaBind.h
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem3/src/core/LuaBind.h merged eligible /code/branches/lodfinal/src/core/LuaBind.h merged eligible /code/branches/network/src/core/LuaBind.h merged eligible /code/branches/objecthierarchy2/src/core/LuaBind.h merged eligible /code/branches/pickups2/src/core/LuaBind.h merged eligible /code/branches/presentation/src/core/LuaBind.h merged eligible /code/branches/questsystem2/src/core/LuaBind.h merged eligible /code/branches/weapon2/src/core/LuaBind.h merged eligible /code/branches/buildsystem/src/core/LuaBind.h 1874-2276,2278-2400 /code/branches/buildsystem/src/core/Script.h 1874-2233 /code/branches/buildsystem2/src/core/LuaBind.h 2506-2658 /code/branches/ceguilua/src/core/LuaBind.h 1802-1808 /code/branches/core3/src/core/LuaBind.h 1572-1739 /code/branches/gcc43/src/core/LuaBind.h 1580 /code/branches/gui/src/core/LuaBind.h 1635-1723 /code/branches/input/src/core/LuaBind.h 1629-1636 /code/branches/network64/src/core/LuaBind.h 2210-2355 /code/branches/objecthierarchy/src/core/LuaBind.h 1911-2085,2100,2110-2169 /code/branches/overlay/src/core/LuaBind.h 2117-2385 /code/branches/physics/src/core/LuaBind.h 1912-2055,2107-2439 /code/branches/physics_merge/src/core/LuaBind.h 2436-2457 /code/branches/pickups/src/core/LuaBind.h 1926-2086,2127 /code/branches/questsystem/src/core/LuaBind.h 1894-2088 /code/branches/script_trigger/src/core/LuaBind.h 1295-1953,1955 /code/branches/weapon/src/core/LuaBind.h 1925-2094
r2662 r2710 39 39 40 40 extern "C" { 41 #include <lua /lua.h>41 #include <lua.h> 42 42 } 43 43 … … 46 46 #include <string> 47 47 48 namespace orxonox // tolua_export 49 { // tolua_export 48 // tolua_begin 49 namespace orxonox 50 { 50 51 class _CoreExport LuaBind 51 52 { 52 /* 53 class LuaBind { // tolua_export 54 */ 53 54 // tolua_end 55 55 struct LoadS { 56 56 const char *s; -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/src/core/RootGameState.cc
r2662 r2710 135 135 { 136 136 // Don't catch errors when having a debugger in msvc 137 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC|| defined(NDEBUG)137 #if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG) 138 138 try 139 139 { … … 158 158 159 159 this->deactivate(); 160 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC|| defined(NDEBUG)160 #if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG) 161 161 } 162 162 // Note: These are all unhandled exceptions that should not have made its way here! -
code/trunk/src/core/TclBind.cc
r1792 r2710 62 62 void TclBind::setDataPath(const std::string& datapath) 63 63 { 64 this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/"; 64 // String has POSIX slashes 65 this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/'; 65 66 this->bSetTclLibPath_ = true; 66 67 -
code/trunk/src/core/TclBind.h
r1792 r2710 32 32 #include "CorePrereqs.h" 33 33 34 #include "cpptcl/CppTcl.h"34 #include <cpptcl/cpptcl.h> 35 35 36 36 namespace orxonox -
code/trunk/src/core/TclThreadManager.h
r1792 r2710 40 40 #include <boost/thread/thread.hpp> 41 41 42 #include "cpptcl/CppTcl.h"42 #include <cpptcl/cpptcl.h> 43 43 #include "core/OrxonoxClass.h" 44 44 -
code/trunk/src/core/Template.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/core/Template.cc (added) merged: 2567,2610 /code/branches/buildsystem3/src/core/Template.cc (added) merged: 2664
r2662 r2710 29 29 #include "Template.h" 30 30 31 #include <tinyxml/ticpp.h> 32 31 33 #include "core/CoreIncludes.h" 32 34 #include "core/XMLPort.h" 33 35 #include "util/Debug.h" 34 #include "tinyxml/ticpp.h"35 36 36 37 namespace orxonox - Property svn:mergeinfo changed
-
code/trunk/src/core/Template.h
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/core/Template.h (added) merged: 2567,2610 /code/branches/buildsystem3/src/core/Template.h (added) merged: 2664
r2662 r2710 34 34 #include "CorePrereqs.h" 35 35 36 #include <tinyxml/tinyxml.h> 36 37 #include "BaseObject.h" 37 #include "tinyxml/tinyxml.h"38 38 39 39 namespace orxonox - Property svn:mergeinfo changed
-
code/trunk/src/core/XMLFile.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/core/XMLFile.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/core/XMLIncludes.h
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/core/XMLIncludes.h (added) merged: 2509-2510 /code/branches/buildsystem3/src/core/XMLIncludes.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/core/XMLPort.h
r2662 r2710 44 44 45 45 #include <cassert> 46 #include <tinyxml/ticpp.h> 46 47 #include "util/Debug.h" 47 48 #include "util/Exception.h" 48 49 #include "util/MultiType.h" 49 #include "tinyxml/ticpp.h"50 50 #include "XMLIncludes.h" 51 51 #include "Executor.h" -
code/trunk/src/core/input/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(CORE_SRC_FILES 2 2 Button.cc 3 3 CalibratorCallback.cc … … 12 12 SimpleInputState.cc 13 13 ) 14 15 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/core/input/KeyBinder.cc
r2662 r2710 36 36 #include <fstream> 37 37 #include <string> 38 #include <boost/filesystem.hpp> 38 39 39 40 #include "util/Convert.h" … … 42 43 #include "core/CoreIncludes.h" 43 44 #include "core/ConfigFileManager.h" 45 #include "core/Core.h" 44 46 #include "InputCommands.h" 45 47 #include "InputManager.h" … … 246 248 True if loading succeeded. 247 249 */ 248 void KeyBinder::loadBindings(const std::string& filename , const std::string& defaultFilename)250 void KeyBinder::loadBindings(const std::string& filename) 249 251 { 250 252 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; … … 253 255 return; 254 256 255 // get bindings from default file if filename doesn't exist.256 std::ifstream infile;257 infile.open(filename.c_str());258 if (!infile)259 {260 ConfigFileManager::getInstance().setFilename(this->configFile_, defaultFilename);261 ConfigFileManager::getInstance().saveAs(this->configFile_, filename);262 }263 else264 infile.close();265 257 ConfigFileManager::getInstance().setFilename(this->configFile_, filename); 266 258 -
code/trunk/src/core/input/KeyBinder.h
r2662 r2710 61 61 virtual ~KeyBinder(); 62 62 63 void loadBindings(const std::string& filename , const std::string& defaultFilename);63 void loadBindings(const std::string& filename); 64 64 void clearBindings(); 65 65 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); -
code/trunk/src/cpptcl/CMakeLists.txt
r1810 r2710 1 ADD_LIBRARY(cpptcl_orxonox SHARED CppTcl.cc) 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 2 19 3 TARGET_LINK_LIBRARIES(cpptcl_orxonox 4 ${TCL_LIBRARY} 20 SET(CPPTCL_FILES 21 cpptcl.h 22 cpptcl.cc 23 24 details/callbacks.h 25 details/callbacks_v.h 26 details/constructors.h 27 details/conversions.h 28 details/dispatchers.h 29 details/metahelpers.h 30 details/methods.h 31 details/methods_v.h 5 32 ) 33 GENERATE_SOURCE_GROUPS(${CPPTCL_FILES}) 34 35 # No warnings needed from third party libraries 36 REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) 37 ADD_COMPILER_FLAGS("-w") 38 39 IF(MSVC) 40 ADD_LIBRARY(cpptcl_orxonox STATIC ${CPPTCL_FILES}) 41 ELSE() 42 ADD_LIBRARY(cpptcl_orxonox SHARED ${CPPTCL_FILES}) 43 ORXONOX_INSTALL(cpptcl_orxonox) 44 ENDIF() 45 46 TARGET_LINK_LIBRARIES(cpptcl_orxonox ${TCL_LIBRARY}) 47 48 SET_TARGET_PROPERTIES(cpptcl_orxonox PROPERTIES VERSION 1.1.3) -
code/trunk/src/network/CMakeLists.txt
r2662 r2710 1 SET( NETWORK_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(NETWORK_SRC_FILES 2 21 ChatListener.cc 3 22 Client.cc … … 14 33 Host.cc 15 34 ) 35 ADD_SUBDIRECTORY(packet) 36 ADD_SUBDIRECTORY(synchronisable) 37 GET_ALL_HEADER_FILES(NETWORK_HDR_FILES) 38 SET(NETWORK_FILES ${NETWORK_SRC_FILES} ${NETWORK_HDR_FILES}) 16 39 17 ADD_SOURCE_DIRECTORY(NETWORK_SRC_FILES packet) 18 ADD_SOURCE_DIRECTORY(NETWORK_SRC_FILES synchronisable) 40 GENERATE_SOURCE_GROUPS(${NETWORK_FILES}) 19 41 20 21 IF(WIN32) 22 ADD_LIBRARY( network ${NETWORK_SRC_FILES} ) 23 ELSE(WIN32) 24 ADD_LIBRARY( network SHARED ${NETWORK_SRC_FILES} ) 25 ENDIF(WIN32) 26 27 TARGET_LINK_LIBRARIES( network 42 ADD_LIBRARY(network SHARED ${NETWORK_FILES}) 43 SET_TARGET_PROPERTIES(network PROPERTIES DEFINE_SYMBOL "NETWORK_SHARED_BUILD") 44 TARGET_LINK_LIBRARIES(network 28 45 ${ZLIB_LIBRARY} 29 ${ENet_LIBRARY} 30 ${Boost_thread_LIBRARIES} 46 ${ENET_LIBRARY} 47 ${Boost_THREAD_LIBRARY} 48 util 31 49 core 32 50 ) 33 51 52 ORXONOX_INSTALL(network) 34 53 35 54 # build those parts only on request. 36 55 IF(NETWORK_TESTING_ENABLED) 37 56 ##### test for gamestate stuff ##### 38 SET( 57 SET(TEST_SRC_FILES 39 58 ${NETWORK_SRC_FILES} 40 59 ) 41 60 ADD_EXECUTABLE(networktest ${TEST_SRC_FILES}) 42 TARGET_LINK_LIBRARIES( 43 ${OGRE_LIBRAR IES}61 TARGET_LINK_LIBRARIES(networktest 62 ${OGRE_LIBRARY} 44 63 network 45 ${EN et_LIBRARY}64 ${ENET_LIBRARY} 46 65 ${ZLIB_LIBRARY} 47 ${WINDOWS_ENET_DEPENDENCIES}48 66 ) 49 67 ##### end test for gamestate stuff ##### -
code/trunk/src/network/GamestateManager.cc
r2662 r2710 118 118 return 0; 119 119 gs = reference->doSelection(clientID, 10000); 120 // gs = new packet::Gamestate(*reference);121 120 // save the (undiffed) gamestate in the clients gamestate map 122 121 gamestateMap_[clientID][gs->getID()]=gs; -
code/trunk/src/network/NetworkPrereqs.h
r2662 r2710 35 35 #define _NetworkPrereqs_H__ 36 36 37 #include " util/OrxonoxPlatform.h"37 #include "OrxonoxConfig.h" 38 38 39 39 //----------------------------------------------------------------------- 40 40 // Shared library settings 41 41 //----------------------------------------------------------------------- 42 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( NETWORK_STATIC_BUILD )42 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( NETWORK_STATIC_BUILD ) 43 43 # ifdef NETWORK_SHARED_BUILD 44 44 # define _NetworkExport __declspec(dllexport) … … 55 55 # define _NetworkExport 56 56 #endif 57 58 //-----------------------------------------------------------------------59 // Includes60 //-----------------------------------------------------------------------61 #include "util/Integers.h"62 57 63 58 //----------------------------------------------------------------------- -
code/trunk/src/network/TrafficControl.h
r2662 r2710 36 36 #include <utility> 37 37 #include <algorithm> 38 #include "util/Integers.h"39 38 #include "core/OrxonoxClass.h" 40 39 #include "network/ClientConnectionListener.h" -
code/trunk/src/network/packet/Acknowledgement.cc
r2662 r2710 64 64 65 65 bool Acknowledgement::process(){ 66 COUT( 0) << "processing ACK with ID: " << getAckID() << endl;66 COUT(6) << "processing ACK with ID: " << getAckID() << endl; 67 67 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_); 68 68 delete this; -
code/trunk/src/network/packet/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(NETWORK_SRC_FILES 2 2 Packet.cc 3 3 Chat.cc … … 8 8 DeleteObjects.cc 9 9 ) 10 11 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/network/packet/Gamestate.cc
r2662 r2710 110 110 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 111 111 112 tempsize=it->getSize(id, mode); 112 113 #ifndef NDEBUG 113 tempsize=it->getSize(id, mode);114 114 if(currentsize+tempsize > size){ 115 115 assert(0); // if we don't use multithreading this part shouldn't be neccessary … … 184 184 { 185 185 bool b = s->updateData(mem, mode); 186 // if(!b) 187 // COUT(0) << "data could not be updated" << endl; 186 188 assert(b); 187 189 } -
code/trunk/src/network/packet/Packet.cc
r2662 r2710 167 167 assert(ClientInformation::findClient(&peer->address)->getID() != (unsigned int)-2 || !Host::isServer()); 168 168 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 169 Packet *p ;169 Packet *p = 0; 170 170 COUT(5) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl; 171 171 switch( *(ENUM::Type *)(data + _PACKETID) ) -
code/trunk/src/network/packet/Packet.h
r2171 r2710 34 34 #include <enet/enet.h> 35 35 #include <boost/thread/recursive_mutex.hpp> 36 37 #include "util/Integers.h"38 36 39 37 namespace orxonox { -
code/trunk/src/network/synchronisable/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(NETWORK_SRC_FILES 2 2 NetworkCallbackManager.cc 3 3 Synchronisable.cc … … 5 5 SynchronisableVariable.cc 6 6 ) 7 8 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/network/synchronisable/NetworkCallback.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/network/synchronisable/Synchronisable.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/network/synchronisable/Synchronisable.cc (added) merged: 2706
r2662 r2710 236 236 return NULL; 237 237 } 238 239 240 /**241 * This function is used to register a variable to be synchronized242 * also counts the total datasize needed to save the variables243 * @param var pointer to the variable244 * @param size size of the datatype the variable consists of245 * @param t the type of the variable (DATA or STRING246 * @param mode same as in getData247 * @param cb callback object that should get called, if the value of the variable changes248 */249 250 /* void Synchronisable::registerVariable(void *var, int size, variableType t, uint8_t mode, NetworkCallbackBase *cb){251 assert( mode==variableDirection::toclient || mode==variableDirection::toserver || mode==variableDirection::serverMaster || mode==variableDirection::clientMaster);252 // create temporary synch.Var struct253 synchronisableVariable *temp = new synchronisableVariable;254 temp->size = size;255 temp->var = var;256 temp->mode = mode;257 temp->type = t;258 temp->callback = cb;259 if( ( mode & variableDirection::bidirectional ) )260 {261 if(t!=STRING)262 {263 temp->varBuffer = new uint8_t[size];264 memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time265 }266 else267 {268 temp->varBuffer=new std::string( *static_cast<std::string*>(var) );269 }270 temp->varReference = 0;271 }272 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;273 //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl;274 COUT(5) << "Syncronisable::objectID: " << objectID << " this: " << this << " name: " << this->getIdentifier()->getName() << " networkID: " << this->getIdentifier()->getNetworkID() << std::endl;275 syncList->push_back(temp);276 #ifndef NDEBUG277 std::list<synchronisableVariable *>::iterator it = syncList->begin();278 while(it!=syncList->end()){279 assert(*it!=var);280 it++;281 }282 #endif283 }*/284 238 285 239 - Property svn:mergeinfo changed
-
code/trunk/src/network/synchronisable/Synchronisable.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/network/synchronisable/Synchronisable.h (added) merged: 2671
r2662 r2710 153 153 uint32_t getSize(int32_t id, uint8_t mode=0x0); 154 154 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); 155 inlinebool isMyData(uint8_t* mem);156 inlinebool doSync(int32_t id, uint8_t mode=0x0);155 bool isMyData(uint8_t* mem); 156 bool doSync(int32_t id, uint8_t mode=0x0); 157 157 158 158 uint32_t objectID; - Property svn:mergeinfo changed
-
code/trunk/src/network/synchronisable/SynchronisableVariable.cc
r2662 r2710 362 362 { 363 363 double temp; 364 *(uint64_t*)(&temp) = *(uint64_t*)(mem);364 memcpy(&temp, mem, sizeof(uint64_t)); 365 365 *(long double*)(&this->variable_) = static_cast<const long double>(temp); 366 366 mem += SynchronisableVariable<const long double>::returnSize(); … … 370 370 { 371 371 double temp = static_cast<double>(this->variable_); 372 *(uint64_t*)(mem) = *(uint64_t*)(&temp);372 memcpy(mem, &temp, sizeof(uint64_t)); 373 373 mem += SynchronisableVariable<const long double>::returnSize(); 374 374 } … … 377 377 { 378 378 double temp = static_cast<double>(this->variable_); 379 return *(uint64_t*)(mem) == *(uint64_t*)(&temp);379 return memcmp(&temp, mem, sizeof(uint64_t))==0; 380 380 } 381 381 -
code/trunk/src/network/synchronisable/SynchronisableVariable.h
r2662 r2710 35 35 #include <string> 36 36 #include <cassert> 37 #include "util/Integers.h"38 37 #include "core/Core.h" 39 38 #include "core/CoreIncludes.h" -
code/trunk/src/ois/CMakeLists.txt
r1555 r2710 1 INCLUDE_DIRECTORIES(.) 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 2 19 3 SET( OIS_SRC_FILES 20 SET_SOURCE_FILES(OIS_FILES 21 OIS.h 22 OISConfig.h 23 OISEffect.h 24 OISEvents.h 25 OISException.h 26 OISFactoryCreator.h 27 OISForceFeedback.h 28 OISInputManager.h 29 OISInterface.h 30 OISJoyStick.h 31 OISKeyboard.h 32 OISMouse.h 33 OISObject.h 34 OISPrereqs.h 35 4 36 OISEffect.cpp 5 37 OISException.cpp … … 10 42 OISObject.cpp 11 43 ) 44 IF(WIN32) 45 ADD_SUBDIRECTORY(win32) 46 ELSEIF(APPLE) 47 ADD_SUBDIRECTORY(mac) 48 ELSEIF(UNIX) 49 ADD_SUBDIRECTORY(linux) 50 ENDIF() 51 52 GENERATE_SOURCE_GROUPS(${OIS_FILES}) 53 54 # No warnings needed from third party libraries 55 REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) 56 ADD_COMPILER_FLAGS("-w") 57 58 INCLUDE_DIRECTORIES(.) 59 60 ADD_LIBRARY(ois_orxonox SHARED ${OIS_FILES}) 61 SET_TARGET_PROPERTIES(ois_orxonox PROPERTIES DEFINE_SYMBOL "OIS_NONCLIENT_BUILD") 12 62 13 63 IF(WIN32) 14 SET( OIS_SRC_FILES ${OIS_SRC_FILES} 15 win32/Win32ForceFeedback.cpp 16 win32/Win32InputManager.cpp 17 win32/Win32JoyStick.cpp 18 win32/Win32KeyBoard.cpp 19 win32/Win32Mouse.cpp 20 ) 21 ELSEIF (APPLE) 22 SET( OIS_SRC_FILES ${OIS_SRC_FILES} 23 mac/MacHelpers.cpp 24 mac/MacHIDManager.cpp 25 mac/MacInputManager.cpp 26 mac/MacKeyboard.cpp 27 mac/MacMouse.cpp 28 ) 29 ELSEIF (UNIX) 30 SET( OIS_SRC_FILES ${OIS_SRC_FILES} 31 linux/EventHelpers.cpp 32 linux/LinuxForceFeedback.cpp 33 linux/LinuxInputManager.cpp 34 linux/LinuxJoyStickEvents.cpp 35 linux/LinuxKeyboard.cpp 36 linux/LinuxMouse.cpp 37 ) 38 ENDIF (WIN32) 64 TARGET_LINK_LIBRARIES(ois_orxonox ${DIRECTX_LIBRARIES}) 65 ENDIF() 39 66 40 ADD_LIBRARY( ois_orxonox SHARED ${OIS_SRC_FILES})67 SET_TARGET_PROPERTIES(ois_orxonox PROPERTIES VERSION 1.2) 41 68 42 IF(WIN32) 43 LINK_DIRECTORIES(${DirectX_LIB_DIR}) 44 TARGET_LINK_LIBRARIES( ois_orxonox 45 dxguid 46 dinput8 47 ) 48 ENDIF(WIN32) 49 69 ORXONOX_INSTALL(ois_orxonox) -
code/trunk/src/ois/OISException.cpp
r1505 r2710 26 26 27 27 //----------------------------------------------------------------------------// 28 /*const char* Exception::what() const throw()28 const char* Exception::what() const throw() 29 29 { 30 30 return eText; 31 31 } 32 */ 32 -
code/trunk/src/ois/OISException.h
r1505 r2710 58 58 : eType(err), eLine(line), eFile(file), eText(str) {} 59 59 60 virtual const char* what() const throw() 61 { return eText; } 60 ~Exception() throw() {} 61 62 virtual const char* what() const throw(); 62 63 63 64 //! The type of exception raised -
code/trunk/src/ois/linux/LinuxKeyboard.cpp
r1786 r2710 283 283 } 284 284 285 for( unsignedint i = 1; i < len; i++)285 for(int i = 1; i < len; i++) 286 286 val = (val << 6) | (buf[i] & 0x3F); 287 287 … … 303 303 304 304 while( XPending(display) > 0 ) 305 { 306 XNextEvent(display, &event); 307 308 if( KeyPress == event.type ) 305 { XNextEvent(display, &event); if( KeyPress == event.type ) 309 306 { 310 307 unsigned int character = 0; … … 335 332 if( event.xkey.state & Mod1Mask && key == XK_Tab ) 336 333 linMan->_setGrabState(false); 337 } 338 else if( KeyRelease == event.type ) 334 } else if( KeyRelease == event.type ) 339 335 { 340 336 //Mask out the modifier states X sets.. or we will get improper values … … 344 340 //Else, it is a valid key release 345 341 XLookupString(&event.xkey,NULL,0,&key,NULL); 346 _injectKeyUp(key); 347 } 342 _injectKeyUp(key); } 348 343 } 349 344 -
code/trunk/src/orxonox/CMakeLists.txt
r2662 r2710 1 SET( ORXONOX_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(ORXONOX_SRC_FILES 2 21 CameraManager.cc 3 22 GraphicsEngine.cc … … 6 25 PawnManager.cc 7 26 PlayerManager.cc 8 Settings.cc9 10 tolua/tolua_bind.cc11 27 ) 28 ADD_SUBDIRECTORY(gamestates) 29 ADD_SUBDIRECTORY(gui) 30 ADD_SUBDIRECTORY(objects) 31 ADD_SUBDIRECTORY(overlays) 32 ADD_SUBDIRECTORY(tools) 33 GET_ALL_HEADER_FILES(ORXONOX_HDR_FILES) 34 SET(ORXONOX_FILES ${ORXONOX_SRC_FILES} ${ORXONOX_HDR_FILES}) 12 35 13 ADD_SOURCE_DIRECTORY(ORXONOX_SRC_FILES gamestates) 14 ADD_SOURCE_DIRECTORY(ORXONOX_SRC_FILES gui) 15 ADD_SOURCE_DIRECTORY(ORXONOX_SRC_FILES objects) 16 ADD_SOURCE_DIRECTORY(ORXONOX_SRC_FILES overlays) 17 ADD_SOURCE_DIRECTORY(ORXONOX_SRC_FILES tools) 36 GENERATE_SOURCE_GROUPS(${ORXONOX_FILES}) 37 GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h) 18 38 19 GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION) 20 ADD_CUSTOM_COMMAND( 21 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h 22 COMMAND ${TOLUA_EXE} -n Orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg 23 DEPENDS 24 tolua_orxonox 25 tolua/tolua.pkg 26 gui/GUIManager.h 27 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib 28 ) 39 # Not using precompiled header files: Avoid dependencies 40 INCLUDE_DIRECTORIES(pch/nopch) 29 41 30 31 ADD_EXECUTABLE( orxonox ${ORXONOX_SRC_FILES} ) 42 ADD_EXECUTABLE(orxonox ${ORXONOX_FILES}) 43 GET_TARGET_PROPERTY(_exec_loc orxonox LOCATION) 44 GET_FILENAME_COMPONENT(_exec_name ${_exec_loc} NAME) 45 SET(ORXONOX_EXECUTABLE_NAME ${_exec_name} CACHE INTERNAL "") 32 46 33 47 IF(NETWORKTRAFFIC_TESTING_ENABLED) 34 35 SET( ORXONOXS_SRC_FILES 48 SET(ORXONOXS_SRC_FILES 36 49 GraphicsEngine.cc 37 50 objects/Camera.cc 38 51 CameraManager.cc 39 52 ) 40 41 ADD_LIBRARY(orxonoxs SHARED ${ORXONOX_SRC_FILES}) 53 ADD_LIBRARY(orxonoxs SHARED ${ORXONOXS_SRC_FILES}) 42 54 ENDIF(NETWORKTRAFFIC_TESTING_ENABLED) 43 55 44 TARGET_LINK_LIBRARIES( 45 ${OGRE_LIBRAR IES}46 ${CEGUI_LIBRAR IES}47 lua_orxonox48 ceguilua_orxonox49 tinyxml_orxonox50 tolualib_orxonox51 BulletDynamics52 BulletCollision53 LinearMath56 TARGET_LINK_LIBRARIES(orxonox 57 ${OGRE_LIBRARY} 58 ${CEGUI_LIBRARY} 59 ${LUA_LIBRARIES} 60 ${CEGUILUA_LIBRARY} 61 ${Boost_SYSTEM_LIBRARY} 62 ogreceguirenderer_orxonox 63 tinyxml++_orxonox 64 tolua++_orxonox 65 bullet_orxonox 54 66 util 55 67 core 56 audio57 68 network 69 #audio 58 70 ) 59 71 72 ORXONOX_INSTALL(orxonox) 73 74 75 # When using Visual Studio we want to use the output directory as working 76 # directory and we also want to specify where the external dlls 77 # (lua, ogre, etc.) are. The problem hereby is that these information cannot 78 # be specified in CMake because they are not stored in the actual project file. 79 # This workaround will create a configured *.vcproj.user file that holds the 80 # right values. When starting the solution for the first time, 81 # these get written to the *vcproj.yourPCname.yourname.user 82 IF(MSVC) 83 IF(CMAKE_CL_64) 84 SET(MSVC_PLATFORM "x64") 85 ELSE() 86 SET(MSVC_PLATFORM "Win32") 87 ENDIF() 88 STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?) .*$" "\\1" 89 VISUAL_STUDIO_VERSION_SIMPLE "${CMAKE_GENERATOR}") 90 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox.vcproj.user" "${CMAKE_CURRENT_BINARY_DIR}/orxonox.vcproj.user") 91 ENDIF(MSVC) -
code/trunk/src/orxonox/CameraManager.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/CameraManager.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/CameraManager.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/CameraManager.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/Main.cc
r2662 r2710 30 30 /** 31 31 @file 32 @brief Entry point of the program. Platform specific code.32 @brief Entry point of the program. 33 33 */ 34 34 … … 38 38 #include <cassert> 39 39 40 #include " util/OrxonoxPlatform.h"40 #include "OrxonoxConfig.h" 41 41 #include "util/Debug.h" 42 42 #include "util/SignalHandler.h" … … 57 57 #include "gamestates/GSIOConsole.h" 58 58 59 #if ORXONOX_PLATFORM ==ORXONOX_PLATFORM_APPLE59 #ifdef ORXONOX_PLATFORM_APPLE 60 60 #include <CoreFoundation/CoreFoundation.h> 61 61 … … 85 85 86 86 87 //#ifdef __cplusplus88 //extern "C" {89 //#endif90 91 87 SetCommandLineArgument(settingsFile, "orxonox.ini"); 88 SetCommandLineArgument(configFileDirectory, ""); 92 89 93 90 int main(int argc, char** argv) … … 95 92 using namespace orxonox; 96 93 97 // create a signal handler (only worksfor linux)94 // create a signal handler (only active for linux) 98 95 SignalHandler signalHandler; 99 signalHandler.doCatch(argv[0], "orxonox.log");96 signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log"); 100 97 101 98 // Parse command line arguments … … 109 106 COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl; 110 107 } 108 109 // Do this after parsing the command line to allow customisation 110 Core::postMainInitialisation(); 111 111 112 112 // Create the ConfigFileManager before creating the GameStates in order to have … … 157 157 return 0; 158 158 } 159 160 //#ifdef __cplusplus161 //}162 //#endif -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r2662 r2710 35 35 #define _OrxonoxPrereqs_H__ 36 36 37 #include " util/OrxonoxPlatform.h"37 #include "OrxonoxConfig.h" 38 38 39 39 //----------------------------------------------------------------------- 40 40 // Shared library settings 41 41 //----------------------------------------------------------------------- 42 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !(defined(ORXONOX_STATIC_BUILD) || defined(ORXONOX_NO_EXPORTS)) 42 #define ORXONOX_NO_EXPORTS // This is an executable that needs no exports 43 #if defined(ORXONOX_PLATFORM_WINDOWS) && !(defined(ORXONOX_STATIC_BUILD) || defined(ORXONOX_NO_EXPORTS)) 43 44 # ifdef ORXONOX_SHARED_BUILD 44 45 # define _OrxonoxExport __declspec(dllexport) -
code/trunk/src/orxonox/gamestates/CMakeLists.txt
- Property svn:eol-style set to native
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 GSDedicated.cc 3 3 GSClient.cc … … 10 10 GSStandalone.cc 11 11 ) 12 13 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r2662 r2710 31 31 32 32 #include <fstream> 33 #include <boost/filesystem.hpp> 34 33 35 #include <OgreCompositorManager.h> 34 36 #include <OgreConfigFile.h> … … 43 45 #include <OgreWindowEventUtilities.h> 44 46 47 #include "SpecialConfig.h" 45 48 #include "util/Debug.h" 46 49 #include "util/Exception.h" 50 #include "util/String.h" 51 #include "util/SubString.h" 47 52 #include "core/ConsoleCommand.h" 48 53 #include "core/ConfigValueIncludes.h" … … 57 62 #include "gui/GUIManager.h" 58 63 #include "tools/WindowEventListener.h" 59 #include "Settings.h"60 64 61 65 // for compatibility … … 92 96 SetConfigValue(ogreConfigFile_, "ogre.cfg") 93 97 .description("Location of the Ogre config file"); 94 SetConfigValue(ogrePluginsFile_, "plugins.cfg") 95 .description("Location of the Ogre plugins file"); 98 SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER) 99 .description("Folder where the Ogre plugins are located."); 100 SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS) 101 .description("Comma separated list of all plugins to load."); 96 102 SetConfigValue(ogreLogFile_, "ogre.log") 97 103 .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); … … 102 108 SetConfigValue(ogreLogLevelCritical_, 2) 103 109 .description("Corresponding orxonox debug level for ogre Critical"); 104 SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini")105 .description("Filename of default master keybindings.");106 110 } 107 111 … … 115 119 // Ogre setup procedure 116 120 setupOgre(); 121 // load all the required plugins for Ogre 122 loadOgrePlugins(); 123 // read resource declaration file 117 124 this->declareResources(); 118 this->loadRenderer(); // creates the render window 125 // Reads ogre config and creates the render window 126 this->loadRenderer(); 127 119 128 // TODO: Spread this so that this call only initialises things needed for the Console and GUI 120 129 this->initialiseResources(); … … 127 136 // load debug overlay 128 137 COUT(3) << "Loading Debug Overlay..." << std::endl; 129 this->debugOverlay_ = new XMLFile( Settings::getDataPath() + "overlay/debug.oxo");138 this->debugOverlay_ = new XMLFile((Core::getMediaPath() / "overlay" / "debug.oxo").file_string()); 130 139 Loader::open(debugOverlay_); 131 140 … … 138 147 // Configure master input state with a KeyBinder 139 148 masterKeyBinder_ = new KeyBinder(); 140 masterKeyBinder_->loadBindings("masterKeybindings.ini" , defaultMasterKeybindings_);149 masterKeyBinder_->loadBindings("masterKeybindings.ini"); 141 150 inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_); 142 151 … … 200 209 delete this->ogreRoot_; 201 210 202 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32203 211 // delete the ogre log and the logManager (since we have created it). 204 212 this->ogreLogger_->getDefaultLog()->removeListener(this); 205 213 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 206 214 delete this->ogreLogger_; 207 //#endif208 215 209 216 delete graphicsEngine_; … … 276 283 COUT(3) << "Setting up Ogre..." << std::endl; 277 284 278 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 279 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 285 if (ogreConfigFile_ == "") 286 { 287 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl; 288 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); 289 } 290 if (ogreLogFile_ == "") 291 { 292 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl; 293 ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); 294 } 295 296 boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_); 297 boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_); 298 280 299 // create a new logManager 300 // Ogre::Root will detect that we've already created a Log 281 301 ogreLogger_ = new Ogre::LogManager(); 282 302 COUT(4) << "Ogre LogManager created" << std::endl; … … 284 304 // create our own log that we can listen to 285 305 Ogre::Log *myLog; 286 if (this->ogreLogFile_ == "") 287 myLog = ogreLogger_->createLog("ogre.log", true, false, true); 288 else 289 myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false); 306 myLog = ogreLogger_->createLog(ogreLogFilepath.file_string(), true, false, false); 290 307 COUT(4) << "Ogre Log created" << std::endl; 291 308 292 309 myLog->setLogDetail(Ogre::LL_BOREME); 293 310 myLog->addListener(this); 294 //#endif 295 296 // Root will detect that we've already created a Log 311 297 312 COUT(4) << "Creating Ogre Root..." << std::endl; 298 313 299 if (ogrePluginsFile_ == "")300 {301 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;302 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");303 }304 if (ogreConfigFile_ == "")305 {306 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;307 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");308 }309 if (ogreLogFile_ == "")310 {311 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;312 ModifyConfigValue(ogreLogFile_, tset, "ogre.log");313 }314 315 314 // check for config file existence because Ogre displays (caught) exceptions if not 316 std::ifstream probe; 317 probe.open(ogreConfigFile_.c_str()); 318 if (!probe) 315 if (!boost::filesystem::exists(ogreConfigFilepath)) 319 316 { 320 317 // create a zero sized file 321 318 std::ofstream creator; 322 creator.open(ogreConfigFile _.c_str());319 creator.open(ogreConfigFilepath.file_string().c_str()); 323 320 creator.close(); 324 321 } 325 else 326 probe.close(); 327 328 ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 329 330 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.) 331 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 332 // tame the ogre ouput so we don't get all the mess in the console 333 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 334 defaultLog->setDebugOutputEnabled(false); 335 defaultLog->setLogDetail(Ogre::LL_BOREME); 336 defaultLog->addListener(this); 337 #endif 338 #endif 322 323 // Leave plugins file empty. We're going to do that part manually later 324 ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.file_string(), ogreLogFilepath.file_string()); 339 325 340 326 COUT(3) << "Ogre set up done." << std::endl; 327 } 328 329 void GSGraphics::loadOgrePlugins() 330 { 331 // just to make sure the next statement doesn't segfault 332 if (ogrePluginsFolder_ == "") 333 ogrePluginsFolder_ = "."; 334 335 boost::filesystem::path folder(ogrePluginsFolder_); 336 // Do some SubString magic to get the comma separated list of plugins 337 SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0'); 338 for (unsigned int i = 0; i < plugins.size(); ++i) 339 ogreRoot_->loadPlugin((folder / plugins[i]).file_string()); 341 340 } 342 341 … … 357 356 try 358 357 { 359 cf.load( Settings::getDataPath() + resourceFile_);358 cf.load((Core::getMediaPath() / resourceFile_).file_string()); 360 359 } 361 360 catch (...) … … 383 382 384 383 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( 385 std::string(Settings::getDataPath() + archName), typeName, secName);384 (Core::getMediaPath() / archName).directory_string(), typeName, secName); 386 385 } 387 386 } -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r2662 r2710 60 60 61 61 void setupOgre(); 62 void loadOgrePlugins(); 62 63 void declareResources(); 63 64 void loadRenderer(); … … 98 99 std::string resourceFile_; //!< resources file name 99 100 std::string ogreConfigFile_; //!< ogre config file name 100 std::string ogrePluginsFile_; //!< ogre plugins file name 101 std::string ogrePluginsFolder_; //!< Folder where the Ogre plugins are located 102 std::string ogrePlugins_; //!< Comma separated list of all plugins to load 101 103 std::string ogreLogFile_; //!< log file name for Ogre log messages 102 104 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 103 105 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 104 106 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 105 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings.106 107 107 108 // console commands -
code/trunk/src/orxonox/gamestates/GSLevel.cc
r2662 r2710 46 46 #include "LevelManager.h" 47 47 #include "PlayerManager.h" 48 #include "Settings.h"49 48 50 49 namespace orxonox … … 76 75 { 77 76 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName="); 78 SetConfigValue(defaultKeybindings_, "def_keybindings.ini")79 .description("Filename of default keybindings.");80 77 } 81 78 … … 86 83 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 87 84 keyBinder_ = new KeyBinder(); 88 keyBinder_->loadBindings("keybindings.ini" , defaultKeybindings_);85 keyBinder_->loadBindings("keybindings.ini"); 89 86 inputState_->setHandler(keyBinder_); 90 87 … … 205 202 std::string levelName; 206 203 CommandLine::getValue("level", &levelName); 207 startFile_ = new XMLFile( Settings::getDataPath() + std::string("levels/")+ levelName);204 startFile_ = new XMLFile(Core::getMediaPathString() + "levels" + CP_SLASH + levelName); 208 205 Loader::open(startFile_); 209 206 } -
code/trunk/src/orxonox/gamestates/GSLevel.h
r2662 r2710 66 66 //##### ConfigValues ##### 67 67 std::string keyDetectorCallbackCode_; 68 //! Filename of default keybindings.69 std::string defaultKeybindings_;70 68 71 69 // console commands -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r2662 r2710 44 44 #include "tools/Timer.h" 45 45 #include "objects/Tickable.h" 46 #include "Settings.h" 47 48 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 46 47 #ifdef ORXONOX_PLATFORM_WINDOWS 49 48 # ifndef WIN32_LEAN_AND_MEAN 50 49 # define WIN32_LEAN_AND_MEAN … … 63 62 namespace orxonox 64 63 { 65 SetCommandLineArgument(dataPath, "").information("PATH");66 64 SetCommandLineArgument(limitToCPU, 1).information("0: off | #cpu"); 67 65 … … 71 69 , bPaused_(false) 72 70 , timeFactorPauseBackup_(1.0f) 73 , settings_(0)74 71 , tclBind_(0) 75 72 , tclThreadManager_(0) … … 113 110 this->luaBind_ = new LuaBind(); 114 111 115 // instantiate Settings class116 this->settings_ = new Settings();117 118 std::string dataPath = CommandLine::getValue("dataPath");119 if (dataPath != "")120 {121 if (*dataPath.end() != '/' && *dataPath.end() != '\\')122 Settings::tsetDataPath(dataPath + "/");123 else124 Settings::tsetDataPath(dataPath);125 }126 127 112 // initialise TCL 128 this->tclBind_ = new TclBind( Settings::getDataPath());113 this->tclBind_ = new TclBind(Core::getMediaPathPOSIXString()); 129 114 this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter()); 130 115 … … 182 167 delete this->tclBind_; 183 168 184 delete this->settings_;185 169 delete this->luaBind_; 186 170 … … 269 253 void GSRoot::setThreadAffinity(unsigned int limitToCPU) 270 254 { 271 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32255 #ifdef ORXONOX_PLATFORM_WINDOWS 272 256 // Get the current process core mask 273 257 DWORD procMask; -
code/trunk/src/orxonox/gamestates/GSRoot.h
r2662 r2710 81 81 bool bPaused_; 82 82 float timeFactorPauseBackup_; 83 Settings* settings_;84 83 TclBind* tclBind_; 85 84 TclThreadManager* tclThreadManager_; -
code/trunk/src/orxonox/gui/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 GUIManager.cc 3 OgreCEGUIRenderer.cpp4 OgreCEGUIResourceProvider.cpp5 OgreCEGUITexture.cpp6 3 ) 7 8 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/gui/GUIManager.cc
r2662 r2710 36 36 #include "GUIManager.h" 37 37 38 #include <boost/filesystem.hpp> 38 39 #include <OgreRenderWindow.h> 39 40 #include <OgreRoot.h> 40 41 #include <CEGUI.h> 41 #include "ceguilua/CEGUILua.h" 42 #include <CEGUIDefaultLogger.h> 43 #include <ogreceguirenderer/OgreCEGUIRenderer.h> 44 #include "SpecialConfig.h" // Configures the macro below 45 #ifdef CEGUILUA_USE_INTERNAL_LIBRARY 46 # include <ceguilua/CEGUILua.h> 47 #else 48 # include <CEGUILua.h> 49 #endif 50 42 51 #include "util/Exception.h" 43 52 #include "core/input/InputManager.h" 44 53 #include "core/input/SimpleInputState.h" 45 #include "core/tolua/tolua_bind.h"46 54 #include "core/ConsoleCommand.h" 47 55 #include "core/Core.h" 48 #include "tolua/tolua_bind.h" 49 #include "OgreCEGUIRenderer.h" 50 51 #include "lua/lua.hpp" 56 #include "ToluaBindCore.h" 57 #include "ToluaBindOrxonox.h" 58 59 extern "C" { 60 #include <lua.h> 61 } 52 62 53 63 namespace orxonox … … 100 110 lua_pushnil(luaState_); 101 111 lua_setglobal(luaState_, "Core"); 102 // TODO: deleting the script module fails an assert ation.112 // TODO: deleting the script module fails an assertion. 103 113 // However there is not much we can do about it since it occurs too when 104 114 // we don't open Core or Orxonox. Might be a CEGUI issue. … … 141 151 this->luaState_ = this->scriptModule_->getLuaState(); 142 152 153 // Create our own logger to specify the filepath 154 boost::filesystem::path ceguiLogFilepath(Core::getLogPath() / "cegui.log"); 155 this->ceguiLogger_ = new DefaultLogger(); 156 this->ceguiLogger_->setLogFilename(ceguiLogFilepath.file_string()); 157 // set the log level according to ours (translate by subtracting 1) 158 this->ceguiLogger_->setLoggingLevel( 159 (LoggingLevel)(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1)); 160 143 161 // create the CEGUI system singleton 144 162 this->guiSystem_ = new System(this->guiRenderer_, this->resourceProvider_, 0, this->scriptModule_); 145 146 // set the log level according to ours (translate by subtracting 1)147 Logger::getSingleton().setLoggingLevel(148 (LoggingLevel)(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));149 163 150 164 // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place -
code/trunk/src/orxonox/gui/GUIManager.h
r1887 r2710 42 42 #include "core/input/InputInterfaces.h" 43 43 44 namespace orxonox // tolua_export 45 { // tolua_export 44 // Forward declaration 45 namespace CEGUI { class DefaultLogger; } 46 47 // tolua_begin 48 namespace orxonox 49 { 46 50 /** 47 51 @brief 48 52 Provides a simple interface to CEGUI with tolua methods and console commands 49 53 */ 50 class _OrxonoxExport GUIManager : public KeyHandler, public MouseHandler51 /* 52 class GUIManager { // tolua_export53 */ 54 class _OrxonoxExport GUIManager 55 // tolua_end 56 : public KeyHandler, public MouseHandler 57 // tolua_begin 54 58 { 59 // tolua_end 55 60 public: 56 61 enum State … … 117 122 CEGUI::ResourceProvider* resourceProvider_; 118 123 CEGUI::LuaScriptModule* scriptModule_; 124 CEGUI::DefaultLogger* ceguiLogger_; 119 125 CEGUI::System* guiSystem_; 120 126 CEGUI::Imageset* backgroundImage_; -
code/trunk/src/orxonox/objects/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 EventListener.cc 3 3 EventDispatcher.cc … … 14 14 ) 15 15 16 ADD_S OURCE_DIRECTORY(SRC_FILEScollisionshapes)17 ADD_S OURCE_DIRECTORY(SRC_FILEScontrollers)18 ADD_S OURCE_DIRECTORY(SRC_FILESgametypes)19 ADD_S OURCE_DIRECTORY(SRC_FILESinfos)20 ADD_S OURCE_DIRECTORY(SRC_FILESitems)21 ADD_S OURCE_DIRECTORY(SRC_FILESpickup)22 ADD_S OURCE_DIRECTORY(SRC_FILESquest)23 ADD_S OURCE_DIRECTORY(SRC_FILESweaponSystem)24 ADD_S OURCE_DIRECTORY(SRC_FILESworldentities)16 ADD_SUBDIRECTORY(collisionshapes) 17 ADD_SUBDIRECTORY(controllers) 18 ADD_SUBDIRECTORY(gametypes) 19 ADD_SUBDIRECTORY(infos) 20 ADD_SUBDIRECTORY(items) 21 ADD_SUBDIRECTORY(pickup) 22 ADD_SUBDIRECTORY(quest) 23 ADD_SUBDIRECTORY(weaponSystem) 24 ADD_SUBDIRECTORY(worldentities) 25 25 26 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/Level.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/Level.cc (added) merged: 2664,2685,2702
r2662 r2710 35 35 #include "core/XMLFile.h" 36 36 #include "core/Template.h" 37 #include "core/Core.h" 37 38 38 #include "Settings.h"39 39 #include "LevelManager.h" 40 40 #include "objects/infos/PlayerInfo.h" … … 55 55 this->xmlfilename_ = this->getFilename(); 56 56 57 if (this->xmlfilename_.length() >= Settings::getDataPath().length())58 this->xmlfilename_ = this->xmlfilename_.substr( Settings::getDataPath().length());57 if (this->xmlfilename_.length() >= Core::getMediaPathString().length()) 58 this->xmlfilename_ = this->xmlfilename_.substr(Core::getMediaPathString().length()); 59 59 } 60 60 … … 97 97 mask.include(Class(OverlayGroup)); // HACK to include the ChatOverlay 98 98 99 this->xmlfile_ = new XMLFile( Settings::getDataPath() + this->xmlfilename_, mask);99 this->xmlfile_ = new XMLFile(Core::getMediaPathString() + this->xmlfilename_, mask); 100 100 101 101 Loader::open(this->xmlfile_); - Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/Level.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/Level.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/collisionshapes
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/collisionshapes (added) merged: 2665
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/collisionshapes/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 BoxCollisionShape.cc 3 3 CollisionShape.cc … … 8 8 WorldEntityCollisionShape.cc 9 9 ) 10 11 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/controllers/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Controller.cc 3 3 HumanController.cc … … 6 6 ScriptController.cc 7 7 ) 8 9 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/gametypes/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Gametype.cc 3 3 ) 4 5 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/gametypes/Gametype.cc
r2662 r2710 43 43 #include "objects/worldentities/SpawnPoint.h" 44 44 #include "objects/worldentities/Camera.h" 45 #include "Settings.h"46 45 47 46 #include "network/Host.h" -
code/trunk/src/orxonox/objects/infos/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Bot.cc 3 3 Info.cc … … 6 6 GametypeInfo.cc 7 7 ) 8 9 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/items/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Item.cc 3 3 Engine.cc 4 4 MultiStateEngine.cc 5 5 ) 6 7 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/pickup/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 PickupSpawner.cc 3 3 BaseItem.cc … … 5 5 ShipEquipment.cc 6 6 ) 7 8 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/pickup/Usable.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/pickup/Usable.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddQuest.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/AddQuest.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddQuest.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/AddQuest.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddQuestHint.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/AddQuestHint.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddQuestHint.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/AddQuestHint.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddReward.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/AddReward.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddReward.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/AddReward.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 AddQuest.cc 3 3 AddQuestHint.cc … … 18 18 Rewardable.cc 19 19 ) 20 21 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/quest/ChangeQuestStatus.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/ChangeQuestStatus.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/ChangeQuestStatus.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/ChangeQuestStatus.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/CompleteQuest.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/CompleteQuest.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/CompleteQuest.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/CompleteQuest.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/FailQuest.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/FailQuest.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/FailQuest.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/FailQuest.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/GlobalQuest.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/GlobalQuest.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/GlobalQuest.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/GlobalQuest.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/LocalQuest.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/LocalQuest.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/LocalQuest.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/LocalQuest.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/Quest.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/Quest.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/Quest.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/Quest.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestDescription.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestDescription.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestDescription.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestDescription.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestEffect.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestEffect.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestEffect.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestEffect.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestHint.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestHint.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestHint.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestHint.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestItem.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestItem.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestItem.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestItem.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestManager.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestManager.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/QuestManager.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/QuestManager.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/Rewardable.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/Rewardable.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/Rewardable.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/quest/Rewardable.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/weaponSystem/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Munition.cc 3 3 Weapon.cc … … 8 8 ) 9 9 10 ADD_SOURCE_DIRECTORY(SRC_FILES munitions) 11 ADD_SOURCE_DIRECTORY(SRC_FILES projectiles) 12 ADD_SOURCE_DIRECTORY(SRC_FILES weapons) 13 14 ADD_SOURCE_FILES(SRC_FILES) 10 ADD_SUBDIRECTORY(munitions) 11 ADD_SUBDIRECTORY(projectiles) 12 ADD_SUBDIRECTORY(weapons) -
code/trunk/src/orxonox/objects/weaponSystem/WeaponPack.cc
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/objects/weaponSystem/WeaponPack.h
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/weaponSystem/WeaponSystem.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/weaponSystem/WeaponSystem.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/weaponSystem/munitions/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 LaserGunMunition.cc 3 3 ) 4 5 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 BillboardProjectile.cc 3 3 ParticleProjectile.cc 4 4 Projectile.cc 5 5 ) 6 7 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Fusion.cc 3 3 LaserGun.cc 4 4 # Missile.cc 5 5 ) 6 7 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/weaponSystem/weapons/Fusion.cc
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/objects/weaponSystem/weapons/Fusion.h
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/objects/worldentities/Backlight.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/Backlight.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/Backlight.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/Backlight.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 WorldEntity.cc 3 3 StaticEntity.cc … … 21 21 ) 22 22 23 ADD_SOURCE_DIRECTORY(SRC_FILES pawns) 24 ADD_SOURCE_DIRECTORY(SRC_FILES triggers) 25 26 ADD_SOURCE_FILES(SRC_FILES) 23 ADD_SUBDIRECTORY(pawns) 24 ADD_SUBDIRECTORY(triggers) -
code/trunk/src/orxonox/objects/worldentities/Camera.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/Camera.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/Camera.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/Camera.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/MobileEntity.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/MobileEntity.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/ParticleSpawner.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/ParticleSpawner.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/Planet.cc
r2662 r2710 74 74 if(activeCamera) 75 75 { 76 Realdistance = this->getPosition().distance( activeCamera->getWorldPosition() );76 float distance = this->getPosition().distance( activeCamera->getWorldPosition() ); 77 77 // COUT(2) << distance << std::endl; 78 RealplanetRadius = this->getScale();78 float planetRadius = this->getScale(); 79 79 80 RealnewScale = 2 * distance / sqrt(distance*distance - planetRadius*planetRadius);81 Real tempTest = newScale*(1+Real(this->atmosphereSize)/Real(this->imageSize));80 float newScale = 2 * distance / sqrt(distance*distance - planetRadius*planetRadius); 81 float tempTest = newScale*(1+float(this->atmosphereSize)/float(this->imageSize)); 82 82 newScale = tempTest; 83 83 … … 90 90 void Planet::init() 91 91 { 92 RealscaleFactor = this->getScale();92 float scaleFactor = this->getScale(); 93 93 94 94 this->distList.push_back(10.0*scaleFactor); … … 103 103 this->distList.push_back(55.0*scaleFactor); 104 104 105 RealreductionValue = 0.2;105 float reductionValue = 0.2; 106 106 107 107 this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue); -
code/trunk/src/orxonox/objects/worldentities/Planet.h
r2662 r2710 71 71 } 72 72 73 inline void setAtmosphereSize( Realsize){73 inline void setAtmosphereSize(float size){ 74 74 this->atmosphereSize = size; 75 75 } 76 76 77 inline RealgetAtmosphereSize(){77 inline float getAtmosphereSize(){ 78 78 return this->atmosphereSize; 79 79 } … … 87 87 } 88 88 89 inline void setImageSize( Realsize){89 inline void setImageSize(float size){ 90 90 this->imageSize = size; 91 91 } 92 92 93 inline RealgetImageSize(){93 inline float getImageSize(){ 94 94 return this->imageSize; 95 95 } … … 106 106 std::string atmosphere_; 107 107 Mesh mesh_; 108 RealatmosphereSize;109 RealimageSize;108 float atmosphereSize; 109 float imageSize; 110 110 Ogre::Mesh::LodDistanceList distList; 111 111 BillboardSet billboard_; -
code/trunk/src/orxonox/objects/worldentities/StaticEntity.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/StaticEntity.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/pawns/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Spectator.cc 3 3 Pawn.cc 4 4 SpaceShip.cc 5 5 ) 6 7 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/worldentities/triggers/CMakeLists.txt
r2261 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Trigger.cc 3 3 DistanceTrigger.cc … … 5 5 PlayerTrigger.cc 6 6 ) 7 8 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/triggers/Trigger.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/orxonox/objects/worldentities/triggers/Trigger.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/overlays/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 OrxonoxOverlay.cc 3 3 OverlayGroup.cc … … 5 5 ) 6 6 7 ADD_S OURCE_DIRECTORY(SRC_FILESconsole)8 ADD_S OURCE_DIRECTORY(SRC_FILESdebug)9 ADD_S OURCE_DIRECTORY(SRC_FILEShud)10 ADD_S OURCE_DIRECTORY(SRC_FILESnotifications)11 ADD_S OURCE_DIRECTORY(SRC_FILESstats)7 ADD_SUBDIRECTORY(console) 8 ADD_SUBDIRECTORY(debug) 9 ADD_SUBDIRECTORY(hud) 10 ADD_SUBDIRECTORY(notifications) 11 ADD_SUBDIRECTORY(stats) 12 12 13 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/overlays/console/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 InGameConsole.cc 3 3 ) 4 5 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/overlays/debug/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 DebugFPSText.cc 3 3 DebugRTRText.cc 4 4 ) 5 6 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/overlays/hud/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 HUDBar.cc 3 3 HUDNavigation.cc … … 8 8 GametypeStatus.cc 9 9 ) 10 11 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/overlays/hud/HUDBar.cc
r2662 r2710 117 117 if (this->colours_.size() > 0) 118 118 { 119 ColourValue colour1, colour2 = (*this->colours_.rbegin()).second; 120 float value1, value2 = (*this->colours_.rbegin()).first; 119 ColourValue colour1(0, 0, 0, 1); 120 ColourValue colour2 = (*this->colours_.rbegin()).second; 121 float value1(0); 122 float value2 = (*this->colours_.rbegin()).first; 121 123 for (std::map<float, ColourValue>::reverse_iterator it = this->colours_.rbegin(); it != this->colours_.rend(); ++it) 122 124 { -
code/trunk/src/orxonox/overlays/notifications/CMakeLists.txt
- Property svn:eol-style set to native
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Notification.cc 3 3 NotificationManager.cc 4 4 NotificationQueue.cc 5 5 ) 6 7 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/overlays/stats/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 CreateLines.cc 3 3 Scoreboard.cc … … 5 5 StatsTest.cc 6 6 ) 7 8 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/tools/CMakeLists.txt
r2662 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 BillboardSet.cc 3 3 Mesh.cc … … 8 8 WindowEventListener.cc 9 9 ) 10 11 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/tinyxml/CMakeLists.txt
r1810 r2710 1 SET( TINYXML_SRC_FILES 2 ticpp.cc 3 tinystr.cc 4 tinyxml.cc 5 tinyxmlerror.cc 6 tinyxmlparser.cc 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET(TINYXML++_FILES 21 ticpp.h 22 ticpprc.h 23 tinystr.h 24 tinyxml.h 25 26 ticpp.cpp 27 tinystr.cpp 28 tinyxml.cpp 29 tinyxmlerror.cpp 30 tinyxmlparser.cpp 7 31 ) 32 GENERATE_SOURCE_GROUPS(${TINYXML++_FILES}) 8 33 9 ADD_LIBRARY(tinyxml_orxonox SHARED ${TINYXML_SRC_FILES}) 34 # No warnings needed from third party libraries 35 REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) 36 ADD_COMPILER_FLAGS("-w") 37 38 IF(MSVC) 39 ADD_LIBRARY(tinyxml++_orxonox STATIC ${TINYXML++_FILES}) 40 ELSE() 41 ADD_LIBRARY(tinyxml++_orxonox SHARED ${TINYXML++_FILES}) 42 ORXONOX_INSTALL(tinyxml++_orxonox) 43 ENDIF() 44 45 SET_TARGET_PROPERTIES(tinyxml++_orxonox PROPERTIES VERSION 2.5.3) -
code/trunk/src/tinyxml/ticpp.h
r2087 r2710 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 http://code.google.com/p/ticpp/ … … 30 28 @date 04/11/2006 31 29 32 @version 0.04b by nico@orxonox.net: gcc-4.3 compilation hotfixes33 30 @version 0.04a by edam@waxworlds.org: based Exception based on std::exception; added stream 34 31 << and >> support; added Document::Parse(); bug fix; improved THROW() macro. … … 94 91 file = file.substr( file.find_last_of( "\\/" ) + 1 ); \ 95 92 full_message << message << " <" << file << "@" << __LINE__ << ">"; \ 93 full_message << BuildDetailedErrorString(); \ 96 94 throw Exception( full_message.str() ); \ 97 95 } … … 221 219 222 220 /** 221 Compare internal TiXml pointers to determine is both are wrappers around the same node 222 */ 223 bool operator == ( const Base& rhs ) const 224 { 225 return ( GetBasePointer() == rhs.GetBasePointer() ); 226 } 227 228 /** 229 Compare internal TiXml pointers to determine is both are wrappers around the same node 230 */ 231 bool operator != ( const Base& rhs ) const 232 { 233 return ( GetBasePointer() != rhs.GetBasePointer() ); 234 } 235 236 /** 237 Builds detailed error string using TiXmlDocument::Error() and others 238 */ 239 std::string BuildDetailedErrorString() const 240 { 241 std::ostringstream full_message; 242 #ifndef TICPP_NO_RTTI 243 TiXmlNode* node = dynamic_cast< TiXmlNode* >( GetBasePointer() ); 244 if ( node != 0 ) 245 { 246 TiXmlDocument* doc = node->GetDocument(); 247 if ( doc != 0 ) 248 { 249 if ( doc->Error() ) 250 { 251 full_message << "\nDescription: " << doc->ErrorDesc() 252 << "\nFile: " << (strlen( doc->Value() ) > 0 ? doc->Value() : "<unnamed-file>") 253 << "\nLine: " << doc->ErrorRow() 254 << "\nColumn: " << doc->ErrorCol(); 255 } 256 } 257 } 258 #endif 259 return full_message.str(); 260 } 261 262 /** 223 263 Destructor 224 264 */ 225 265 virtual ~Base() 226 266 { 227 DeleteSpawnedWrappers();228 267 } 229 268 … … 231 270 mutable TiCppRCImp* m_impRC; /**< Holds status of internal TiXmlPointer - use this to determine if object has been deleted already */ 232 271 233 mutable std::vector< Base* > m_spawnedWrappers; /**< Remember all wrappers that we've created with 'new' - ( e.g. NodeFactory, FirstChildElement, etc. )*/234 235 272 /** 236 273 @internal … … 250 287 TICPPTHROW( "Internal TiXml Pointer is NULL" ); 251 288 } 252 } 253 254 /** 255 @internal 256 Delete all container objects we've spawned with 'new'. 257 */ 258 void DeleteSpawnedWrappers() 259 { 260 std::vector< Base* >::reverse_iterator wrapper; 261 for ( wrapper = m_spawnedWrappers.rbegin(); wrapper != m_spawnedWrappers.rend(); ++wrapper ) 262 { 263 delete *wrapper; 264 } 265 m_spawnedWrappers.clear(); 266 } 289 } 267 290 268 291 /** … … 875 898 bool NoChildren() const; 876 899 900 #ifndef TICPP_NO_RTTI 877 901 /** 878 902 Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument, TiXmlNode::ToComment, etc. … … 895 919 return pointer; 896 920 } 921 #endif 897 922 898 923 /** … … 1085 1110 1086 1111 /// Constructor 1087 Iterator( const Iterator& it , const std::string& value = "")1088 : m_p( it.m_p ), m_value( value )1112 Iterator( const Iterator& it ) 1113 : m_p( it.m_p ), m_value( it.m_value ) 1089 1114 { 1090 1115 } … … 1103 1128 { 1104 1129 m_p = it.m_p; 1130 m_value = it.m_value; 1105 1131 return *this; 1106 1132 } … … 1121 1147 1122 1148 /** Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings */ 1123 Iterator& operator++(int) 1124 { 1125 return this->operator ++(); 1149 Iterator operator++(int) 1150 { 1151 Iterator tmp(*this); 1152 ++(*this); 1153 return tmp; 1126 1154 } 1127 1155 … … 1134 1162 1135 1163 /** Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings */ 1136 Iterator& operator--(int) 1137 { 1138 return this->operator --(); 1164 Iterator operator--(int) 1165 { 1166 Iterator tmp(*this); 1167 --(*this); 1168 return tmp; 1139 1169 } 1140 1170 1141 1171 /** Compares internal pointer */ 1142 bool operator!=( T* p ) const 1143 { 1144 return m_p != p; 1172 bool operator!=( const T* p ) const 1173 { 1174 if ( m_p == p ) 1175 { 1176 return false; 1177 } 1178 if ( 0 == m_p || 0 == p ) 1179 { 1180 return true; 1181 } 1182 return *m_p != *p; 1145 1183 } 1146 1184 … … 1148 1186 bool operator!=( const Iterator& it ) const 1149 1187 { 1150 return m_p != it.m_p;1188 return operator!=( it.m_p ); 1151 1189 } 1152 1190 … … 1154 1192 bool operator==( T* p ) const 1155 1193 { 1156 return m_p == p; 1194 if ( m_p == p ) 1195 { 1196 return true; 1197 } 1198 if ( 0 == m_p || 0 == p ) 1199 { 1200 return false; 1201 } 1202 return *m_p == *p; 1157 1203 } 1158 1204 … … 1160 1206 bool operator==( const Iterator& it ) const 1161 1207 { 1162 return m_p == it.m_p;1208 return operator==( it.m_p ); 1163 1209 } 1164 1210 … … 1220 1266 if ( 0 == tiXmlPointer ) 1221 1267 { 1222 TICPPTHROW( "Can not create a " << typeid( T ).name() ); 1268 #ifdef TICPP_NO_RTTI 1269 TICPPTHROW( "Can not create TinyXML objext" ); 1270 #else 1271 TICPPTHROW( "Can not create a " << typeid( T ).name() ); 1272 #endif 1223 1273 } 1224 1274 SetTiXmlPointer( tiXmlPointer ); … … 1233 1283 virtual void operator=( const NodeImp<T>& copy ) 1234 1284 { 1235 DeleteSpawnedWrappers();1236 1237 1285 // Dropping the reference to the old object 1238 1286 this->m_impRC->DecRef(); … … 1267 1315 virtual ~NodeImp() 1268 1316 { 1269 // The spawnedWrappers need to be deleted before m_tiXmlPointer1270 DeleteSpawnedWrappers();1271 1317 m_impRC->DecRef(); 1272 1318 } … … 1685 1731 1686 1732 /** 1733 Returns an attribute of @a name from an element. 1734 Uses FromString to convert the string to the type of choice. 1735 1736 @param name The name of the attribute you are querying. 1737 @param throwIfNotFound [DEF] If true, will throw an exception if the attribute doesn't exist 1738 @throws Exception When the attribute doesn't exist and throwIfNotFound is true 1739 @see GetAttributeOrDefault 1740 */ 1741 template < class T > 1742 T GetAttribute( const std::string& name, bool throwIfNotFound = true ) const 1743 { 1744 // Get the attribute's value as a std::string 1745 std::string temp; 1746 T value; 1747 if ( !GetAttributeImp( name, &temp ) ) 1748 { 1749 if ( throwIfNotFound ) 1750 { 1751 TICPPTHROW( "Attribute does not exist" ); 1752 } 1753 } 1754 else 1755 { 1756 // Stream the value from the string to T 1757 FromString( temp, &value ); 1758 } 1759 1760 return value; 1761 } 1762 1763 /** 1687 1764 Gets an attribute of @a name from an element. 1688 1765 Uses FromString to convert the string to the type of choice. … … 1727 1804 std::string GetAttribute( const std::string& name ) const; 1728 1805 1806 /** 1807 Returns true, if attribute exists 1808 1809 @param name The name of the attribute you are checking. 1810 @return Existence of attribute 1811 */ 1812 bool HasAttribute( const std::string& name ) const; 1813 1814 /** 1815 Removes attribute from element. 1816 1817 @param name The name of the attribute to remove. 1818 */ 1819 void RemoveAttribute( const std::string& name ); 1820 1729 1821 private: 1730 1822 -
code/trunk/src/tinyxml/ticpprc.h
r1505 r2710 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 http://code.google.com/p/ticpp/ … … 28 26 #define TICPPRC_INCLUDED 29 27 28 #include <vector> 30 29 31 30 // Forward declare ticpp::Node, so it can be made a friend of TiCppRC … … 64 63 */ 65 64 virtual ~TiCppRC(); 65 66 std::vector< ticpp::Base* > m_spawnedWrappers; /**< Remember all wrappers that we've created with 'new' - ( e.g. NodeFactory, FirstChildElement, etc. )*/ 67 68 /** 69 Delete all container objects we've spawned with 'new'. 70 */ 71 void DeleteSpawnedWrappers(); 66 72 }; 67 73 -
code/trunk/src/tinyxml/tinyxml.h
r1505 r2710 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 www.sourceforge.net/projects/tinyxml -
code/trunk/src/tolua/CMakeLists.txt
r1815 r2710 1 SET (TOLUALIB_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 ################### Tolua++ library ################### 21 22 SET(TOLUA++_FILES 23 tolua_event.h 24 tolua++.h 25 2 26 tolua_event.c 3 27 tolua_is.c … … 6 30 tolua_to.c 7 31 ) 32 GENERATE_SOURCE_GROUPS(${TOLUA++_FILES}) 8 33 9 ADD_LIBRARY (tolualib_orxonox SHARED ${TOLUALIB_SRC_FILES}) 34 # No warnings needed from third party libraries 35 REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) 36 ADD_COMPILER_FLAGS("-w") 10 37 11 TARGET_LINK_LIBRARIES (tolualib_orxonox 12 lua_orxonox 13 ) 38 ADD_LIBRARY(tolua++_orxonox SHARED ${TOLUA++_FILES}) 39 SET_TARGET_PROPERTIES(tolua++_orxonox PROPERTIES DEFINE_SYMBOL "TOLUA_SHARED_BUILD") 40 TARGET_LINK_LIBRARIES(tolua++_orxonox ${LUA_LIBRARIES}) 41 42 SET_TARGET_PROPERTIES(tolua++_orxonox PROPERTIES VERSION 1.0.92) 43 44 ORXONOX_INSTALL(tolua++_orxonox) 14 45 15 46 16 SET (TOLUAGEN_SRC_FILES 17 tolua.c 18 toluabind.c 47 ################## Tolua++ generator ################## 48 49 ADD_EXECUTABLE(tolua++app_orxonox tolua.c) 50 TARGET_LINK_LIBRARIES(tolua++app_orxonox tolua++_orxonox ${LUA_LIBRARIES}) 51 52 OPTION(TOLUA_PARSER_RELEASE "Disable all debug messages from tolua bind files for Release and MinSizeRel build types." FALSE) 53 54 # Set some variables to the cache in order to use them in the TOLUA macro 55 SET(TOLUA_PARSER_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/all-${LUA_VERSION}.lua" CACHE INTERNAL "") 56 SET(TOLUA_PARSER_DEPENDENCIES 57 tolua++app_orxonox 58 ${CMAKE_CURRENT_SOURCE_DIR}/all-${LUA_VERSION}.lua 59 ${CMAKE_CURRENT_SOURCE_DIR}/lua/compat-5.1.lua 60 ${CMAKE_CURRENT_SOURCE_DIR}/lua/compat.lua 61 ${CMAKE_CURRENT_SOURCE_DIR}/lua/basic.lua 62 ${CMAKE_CURRENT_SOURCE_DIR}/lua/feature.lua 63 ${CMAKE_CURRENT_SOURCE_DIR}/lua/verbatim.lua 64 ${CMAKE_CURRENT_SOURCE_DIR}/lua/code.lua 65 ${CMAKE_CURRENT_SOURCE_DIR}/lua/typedef.lua 66 ${CMAKE_CURRENT_SOURCE_DIR}/lua/container.lua 67 ${CMAKE_CURRENT_SOURCE_DIR}/lua/package.lua 68 ${CMAKE_CURRENT_SOURCE_DIR}/lua/module.lua 69 ${CMAKE_CURRENT_SOURCE_DIR}/lua/namespace.lua 70 ${CMAKE_CURRENT_SOURCE_DIR}/lua/define.lua 71 ${CMAKE_CURRENT_SOURCE_DIR}/lua/enumerate.lua 72 ${CMAKE_CURRENT_SOURCE_DIR}/lua/declaration.lua 73 ${CMAKE_CURRENT_SOURCE_DIR}/lua/variable.lua 74 ${CMAKE_CURRENT_SOURCE_DIR}/lua/array.lua 75 ${CMAKE_CURRENT_SOURCE_DIR}/lua/function.lua 76 ${CMAKE_CURRENT_SOURCE_DIR}/lua/operator.lua 77 ${CMAKE_CURRENT_SOURCE_DIR}/lua/class.lua 78 ${CMAKE_CURRENT_SOURCE_DIR}/lua/clean.lua 79 ${CMAKE_CURRENT_SOURCE_DIR}/lua/doit.lua 80 81 CACHE INTERNAL "" 19 82 ) 20 21 ADD_EXECUTABLE (toluagen_orxonox ${TOLUAGEN_SRC_FILES})22 23 TARGET_LINK_LIBRARIES (toluagen_orxonox24 lua_orxonox25 tolualib_orxonox26 m27 )28 29 30 SET (TOLUA_PACKAGE "../../src/tolua/tolua-5.1.pkg")31 GET_TARGET_PROPERTY(TOLUAGEN_EXE toluagen_orxonox LOCATION)32 ADD_CUSTOM_COMMAND(33 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/toluabind_orxonox.c34 COMMAND ${TOLUAGEN_EXE} -n tolua -o ../../src/tolua/toluabind_orxonox.c -H ../../src/tolua/toluabind_orxonox.h ${TOLUA_PACKAGE}35 DEPENDS36 toluagen_orxonox37 tolua-5.1.pkg38 lua/compat-5.1.lua39 lua/compat.lua40 lua/basic.lua41 lua/feature.lua42 lua/verbatim.lua43 lua/code.lua44 lua/typedef.lua45 lua/container.lua46 lua/package.lua47 lua/module.lua48 lua/namespace.lua49 lua/define.lua50 lua/enumerate.lua51 lua/declaration.lua52 lua/variable.lua53 lua/array.lua54 lua/function.lua55 lua/operator.lua56 lua/class.lua57 lua/clean.lua58 lua/doit.lua59 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib60 )61 62 SET (TOLUAEXE_SRC_FILES63 tolua.c64 toluabind_orxonox.c65 )66 67 ADD_EXECUTABLE (tolua_orxonox ${TOLUAEXE_SRC_FILES})68 69 TARGET_LINK_LIBRARIES (tolua_orxonox70 lua_orxonox71 tolualib_orxonox72 m73 ) -
code/trunk/src/tolua/lua/array.lua
r2087 r2710 21 21 -- Print method 22 22 function classArray:print (ident,close) 23 print(ident.."Array{")24 print(ident.." mod = '"..self.mod.."',")25 print(ident.." type = '"..self.type.."',")26 print(ident.." ptr = '"..self.ptr.."',")27 print(ident.." name = '"..self.name.."',")28 print(ident.." def = '"..self.def.."',")29 print(ident.." dim = '"..self.dim.."',")30 print(ident.." ret = '"..self.ret.."',")31 print(ident.."}"..close)23 print(ident.."Array{") 24 print(ident.." mod = '"..self.mod.."',") 25 print(ident.." type = '"..self.type.."',") 26 print(ident.." ptr = '"..self.ptr.."',") 27 print(ident.." name = '"..self.name.."',") 28 print(ident.." def = '"..self.def.."',") 29 print(ident.." dim = '"..self.dim.."',") 30 print(ident.." ret = '"..self.ret.."',") 31 print(ident.."}"..close) 32 32 end 33 33 34 34 -- check if it is a variable 35 35 function classArray:isvariable () 36 return true36 return true 37 37 end 38 38 … … 40 40 -- get variable value 41 41 function classArray:getvalue (class,static) 42 if class and static then43 return class..'::'..self.name..'[tolua_index]'44 elseif class then45 return 'self->'..self.name..'[tolua_index]'46 else47 return self.name..'[tolua_index]'48 end42 if class and static then 43 return class..'::'..self.name..'[tolua_index]' 44 elseif class then 45 return 'self->'..self.name..'[tolua_index]' 46 else 47 return self.name..'[tolua_index]' 48 end 49 49 end 50 50 51 51 -- Write binding functions 52 52 function classArray:supcode () 53 local class = self:inclass() 54 55 -- get function ------------------------------------------------ 56 if class then 57 output("/* get function:",self.name," of class ",class," */") 58 else 59 output("/* get function:",self.name," */") 60 end 61 self.cgetname = self:cfuncname("tolua_get") 62 output("#ifndef TOLUA_DISABLE_"..self.cgetname) 63 output("\nstatic int",self.cgetname,"(lua_State* tolua_S)") 64 output("{") 65 output(" int tolua_index;") 66 67 -- declare self, if the case 68 local _,_,static = strfind(self.mod,'^%s*(static)') 69 if class and static==nil then 70 output(' ',self.parent.type,'*','self;') 71 output(' lua_pushstring(tolua_S,".self");') 72 output(' lua_rawget(tolua_S,1);') 73 output(' self = ') 74 output('(',self.parent.type,'*) ') 75 output('lua_touserdata(tolua_S,-1);') 76 elseif static then 77 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 78 end 79 80 -- check index 81 output('#ifndef TOLUA_RELEASE\n') 82 output(' {') 83 output(' tolua_Error tolua_err;') 84 output(' if (!tolua_isnumber(tolua_S,2,0,&tolua_err))') 85 output(' tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);') 86 output(' }') 87 output('#endif\n') 88 if flags['1'] then -- for compatibility with tolua5 ? 89 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;') 90 else 91 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);') 92 end 93 output('#ifndef TOLUA_RELEASE\n') 94 if self.dim and self.dim ~= '' then 95 output(' if (tolua_index<0 || tolua_index>='..self.dim..')') 96 else 97 output(' if (tolua_index<0)') 98 end 99 output(' tolua_error(tolua_S,"array indexing out of range.",NULL);') 100 output('#endif\n') 101 102 -- return value 103 local t,ct = isbasic(self.type) 104 if t then 105 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static)..');') 106 else 107 t = self.type 108 if self.ptr == '&' or self.ptr == '' then 109 output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");') 110 else 111 output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");') 112 end 113 end 114 output(' return 1;') 115 output('}') 116 output('#endif //#ifndef TOLUA_DISABLE\n') 117 output('\n') 118 119 -- set function ------------------------------------------------ 120 if not strfind(self.type,'const') then 121 if class then 122 output("/* set function:",self.name," of class ",class," */") 123 else 124 output("/* set function:",self.name," */") 125 end 126 self.csetname = self:cfuncname("tolua_set") 127 output("#ifndef TOLUA_DISABLE_"..self.csetname) 128 output("\nstatic int",self.csetname,"(lua_State* tolua_S)") 129 output("{") 130 131 -- declare index 132 output(' int tolua_index;') 133 134 -- declare self, if the case 135 local _,_,static = strfind(self.mod,'^%s*(static)') 136 if class and static==nil then 137 output(' ',self.parent.type,'*','self;') 138 output(' lua_pushstring(tolua_S,".self");') 139 output(' lua_rawget(tolua_S,1);') 140 output(' self = ') 141 output('(',self.parent.type,'*) ') 142 output('lua_touserdata(tolua_S,-1);') 143 elseif static then 144 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 145 end 146 147 -- check index 148 output('#ifndef TOLUA_RELEASE\n') 149 output(' {') 150 output(' tolua_Error tolua_err;') 151 output(' if (!tolua_isnumber(tolua_S,2,0,&tolua_err))') 152 output(' tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);') 153 output(' }') 154 output('#endif\n') 155 156 if flags['1'] then -- for compatibility with tolua5 ? 157 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;') 158 else 159 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);') 160 end 161 162 output('#ifndef TOLUA_RELEASE\n') 163 if self.dim and self.dim ~= '' then 164 output(' if (tolua_index<0 || tolua_index>='..self.dim..')') 165 else 166 output(' if (tolua_index<0)') 167 end 168 output(' tolua_error(tolua_S,"array indexing out of range.",NULL);') 169 output('#endif\n') 170 171 -- assign value 172 local ptr = '' 173 if self.ptr~='' then ptr = '*' end 174 output(' ') 175 if class and static then 176 output(class..'::'..self.name..'[tolua_index]') 177 elseif class then 178 output('self->'..self.name..'[tolua_index]') 179 else 180 output(self.name..'[tolua_index]') 181 end 182 local t = isbasic(self.type) 183 output(' = ') 184 if not t and ptr=='' then output('*') end 185 output('((',self.mod,self.type) 186 if not t then 187 output('*') 188 end 189 output(') ') 190 local def = 0 191 if self.def ~= '' then def = self.def end 192 if t then 193 output('tolua_to'..t,'(tolua_S,3,',def,'));') 194 else 195 output('tolua_tousertype(tolua_S,3,',def,'));') 196 end 197 output(' return 0;') 198 output('}') 199 output('#endif //#ifndef TOLUA_DISABLE\n') 200 output('\n') 201 end 202 53 local class = self:inclass() 54 55 -- get function ------------------------------------------------ 56 if class then 57 output("/* get function:",self.name," of class ",class," */") 58 else 59 output("/* get function:",self.name," */") 60 end 61 self.cgetname = self:cfuncname("tolua_get") 62 output("#ifndef TOLUA_DISABLE_"..self.cgetname) 63 output("\nstatic int",self.cgetname,"(lua_State* tolua_S)") 64 output("{") 65 output(" int tolua_index;") 66 67 -- declare self, if the case 68 local _,_,static = strfind(self.mod,'^%s*(static)') 69 if class and static==nil then 70 output(' ',self.parent.type,'*','self;') 71 output(' lua_pushstring(tolua_S,".self");') 72 output(' lua_rawget(tolua_S,1);') 73 output(' self = ') 74 output('(',self.parent.type,'*) ') 75 output('lua_touserdata(tolua_S,-1);') 76 elseif static then 77 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 78 end 79 80 -- check index 81 output('#ifndef TOLUA_RELEASE\n') 82 output(' {') 83 output(' tolua_Error tolua_err;') 84 output(' if (!tolua_isnumber(tolua_S,2,0,&tolua_err))') 85 output(' tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);') 86 output(' }') 87 output('#endif\n') 88 if flags['1'] then -- for compatibility with tolua5 ? 89 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;') 90 else 91 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);') 92 end 93 output('#ifndef TOLUA_RELEASE\n') 94 if self.dim and self.dim ~= '' then 95 output(' if (tolua_index<0 || tolua_index>='..self.dim..')') 96 else 97 output(' if (tolua_index<0)') 98 end 99 output(' tolua_error(tolua_S,"array indexing out of range.",NULL);') 100 output('#endif\n') 101 102 -- return value 103 local t,ct = isbasic(self.type) 104 if t then 105 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static)..');') 106 else 107 t = self.type 108 if self.ptr == '&' or self.ptr == '' then 109 output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");') 110 else 111 output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");') 112 end 113 end 114 output(' return 1;') 115 output('}') 116 output('#endif //#ifndef TOLUA_DISABLE\n') 117 output('\n') 118 119 -- set function ------------------------------------------------ 120 if not strfind(self.type,'const') then 121 if class then 122 output("/* set function:",self.name," of class ",class," */") 123 else 124 output("/* set function:",self.name," */") 125 end 126 self.csetname = self:cfuncname("tolua_set") 127 output("#ifndef TOLUA_DISABLE_"..self.csetname) 128 output("\nstatic int",self.csetname,"(lua_State* tolua_S)") 129 output("{") 130 131 -- declare index 132 output(' int tolua_index;') 133 134 -- declare self, if the case 135 local _,_,static = strfind(self.mod,'^%s*(static)') 136 if class and static==nil then 137 output(' ',self.parent.type,'*','self;') 138 output(' lua_pushstring(tolua_S,".self");') 139 output(' lua_rawget(tolua_S,1);') 140 output(' self = ') 141 output('(',self.parent.type,'*) ') 142 output('lua_touserdata(tolua_S,-1);') 143 elseif static then 144 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 145 end 146 147 -- check index 148 output('#ifndef TOLUA_RELEASE\n') 149 output(' {') 150 output(' tolua_Error tolua_err;') 151 output(' if (!tolua_isnumber(tolua_S,2,0,&tolua_err))') 152 output(' tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);') 153 output(' }') 154 output('#endif\n') 155 156 if flags['1'] then -- for compatibility with tolua5 ? 157 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;') 158 else 159 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);') 160 end 161 162 output('#ifndef TOLUA_RELEASE\n') 163 if self.dim and self.dim ~= '' then 164 output(' if (tolua_index<0 || tolua_index>='..self.dim..')') 165 else 166 output(' if (tolua_index<0)') 167 end 168 output(' tolua_error(tolua_S,"array indexing out of range.",NULL);') 169 output('#endif\n') 170 171 -- assign value 172 local ptr = '' 173 if self.ptr~='' then ptr = '*' end 174 output(' ') 175 if class and static then 176 output(class..'::'..self.name..'[tolua_index]') 177 elseif class then 178 output('self->'..self.name..'[tolua_index]') 179 else 180 output(self.name..'[tolua_index]') 181 end 182 local t = isbasic(self.type) 183 output(' = ') 184 if not t and ptr=='' then output('*') end 185 output('((',self.mod,self.type) 186 if not t then 187 output('*') 188 end 189 output(') ') 190 local def = 0 191 if self.def ~= '' then def = self.def end 192 if t then 193 output('tolua_to'..t,'(tolua_S,3,',def,'));') 194 else 195 output('tolua_tousertype(tolua_S,3,',def,'));') 196 end 197 output(' return 0;') 198 output('}') 199 output('#endif //#ifndef TOLUA_DISABLE\n') 200 output('\n') 201 end 203 202 end 204 203 205 204 function classArray:register (pre) 206 pre = pre or ''207 if self.csetname then208 output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');')209 else210 output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);')211 end205 pre = pre or '' 206 if self.csetname then 207 output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');') 208 else 209 output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);') 210 end 212 211 end 213 212 214 213 -- Internal constructor 215 214 function _Array (t) 216 setmetatable(t,classArray)217 append(t)218 return t215 setmetatable(t,classArray) 216 append(t) 217 return t 219 218 end 220 219 … … 222 221 -- Expects a string representing the variable declaration. 223 222 function Array (s) 224 return _Array (Declaration(s,'var'))225 end 226 227 223 return _Array (Declaration(s,'var')) 224 end 225 226 -
code/trunk/src/tolua/lua/basic.lua
r2087 r2710 16 16 -- and all occurrences of "void*" will be replaced by "_userdata" 17 17 _basic = { 18 ['void'] = '',19 ['char'] = 'number',20 ['int'] = 'number',21 ['short'] = 'number',22 ['long'] = 'number',23 ['unsigned'] = 'number',24 ['float'] = 'number',25 ['double'] = 'number',26 ['_cstring'] = 'string',27 ['_userdata'] = 'userdata',28 ['char*'] = 'string',29 ['void*'] = 'userdata',30 ['bool'] = 'boolean',31 ['lua_Object'] = 'value',32 ['LUA_VALUE'] = 'value', -- for compatibility with tolua 4.033 ['lua_State*'] = 'state',34 ['_lstate'] = 'state',35 ['lua_Function'] = 'value',18 ['void'] = '', 19 ['char'] = 'number', 20 ['int'] = 'number', 21 ['short'] = 'number', 22 ['long'] = 'number', 23 ['unsigned'] = 'number', 24 ['float'] = 'number', 25 ['double'] = 'number', 26 ['_cstring'] = 'string', 27 ['_userdata'] = 'userdata', 28 ['char*'] = 'string', 29 ['void*'] = 'userdata', 30 ['bool'] = 'boolean', 31 ['lua_Object'] = 'value', 32 ['LUA_VALUE'] = 'value', -- for compatibility with tolua 4.0 33 ['lua_State*'] = 'state', 34 ['_lstate'] = 'state', 35 ['lua_Function'] = 'value', 36 36 } 37 37 38 38 _basic_ctype = { 39 number = "lua_Number",40 string = "const char*",41 userdata = "void*",42 boolean = "bool",43 value = "int",44 state = "lua_State*",39 number = "lua_Number", 40 string = "const char*", 41 userdata = "void*", 42 boolean = "bool", 43 value = "int", 44 state = "lua_State*", 45 45 } 46 46 … … 68 68 _renaming = {} 69 69 function appendrenaming (s) 70 local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$")71 72 73 74 70 local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$") 71 if not b then 72 error("#Invalid renaming syntax; it should be of the form: pattern@pattern") 73 end 74 tinsert(_renaming,{old=old, new=new}) 75 75 end 76 76 77 77 function applyrenaming (s) 78 79 80 81 82 83 84 78 for i=1,getn(_renaming) do 79 local m,n = gsub(s,_renaming[i].old,_renaming[i].new) 80 if n ~= 0 then 81 return m 82 end 83 end 84 return nil 85 85 end 86 86 87 87 -- Error handler 88 88 function tolua_error (s,f) 89 if _curr_code then90 91 92 end93 local out = _OUTPUT94 _OUTPUT = _STDERR95 if strsub(s,1,1) == '#' then96 write("\n** tolua: "..strsub(s,2)..".\n\n")97 if _curr_code then98 local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line99 if s==nil then s = _curr_code end100 s = gsub(s,"_userdata","void*") -- return with 'void*'101 s = gsub(s,"_cstring","char*") -- return with 'char*'102 s = gsub(s,"_lstate","lua_State*") -- return with 'lua_State*'103 write("Code being processed:\n"..s.."\n")104 end105 else106 if not f then f = "(f is nil)" end107 print("\n** tolua internal error: "..f..s..".\n\n")108 return109 end110 _OUTPUT = out89 if _curr_code then 90 print("***curr code for error is "..tostring(_curr_code)) 91 print(debug.traceback()) 92 end 93 local out = _OUTPUT 94 _OUTPUT = _STDERR 95 if strsub(s,1,1) == '#' then 96 write("\n** tolua: "..strsub(s,2)..".\n\n") 97 if _curr_code then 98 local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line 99 if s==nil then s = _curr_code end 100 s = gsub(s,"_userdata","void*") -- return with 'void*' 101 s = gsub(s,"_cstring","char*") -- return with 'char*' 102 s = gsub(s,"_lstate","lua_State*") -- return with 'lua_State*' 103 write("Code being processed:\n"..s.."\n") 104 end 105 else 106 if not f then f = "(f is nil)" end 107 print("\n** tolua internal error: "..f..s..".\n\n") 108 return 109 end 110 _OUTPUT = out 111 111 end 112 112 113 113 function warning (msg) 114 local out = _OUTPUT115 _OUTPUT = _STDERR116 write("\n** tolua warning: "..msg..".\n\n")117 _OUTPUT = out114 local out = _OUTPUT 115 _OUTPUT = _STDERR 116 write("\n** tolua warning: "..msg..".\n\n") 117 _OUTPUT = out 118 118 end 119 119 120 120 -- register an user defined type: returns full type 121 121 function regtype (t) 122 123 --return t124 125 126 127 128 129 130 122 --if isbasic(t) then 123 -- return t 124 --end 125 local ft = findtype(t) 126 127 if not _usertype[ft] then 128 return appendusertype(t) 129 end 130 return ft 131 131 end 132 132 133 133 -- return type name: returns full type 134 134 function typevar(type) 135 136 137 138 139 140 141 142 143 144 135 if type == '' or type == 'void' then 136 return type 137 else 138 local ft = findtype(type) 139 if ft then 140 return ft 141 end 142 _usertype[type] = type 143 return type 144 end 145 145 end 146 146 147 147 -- check if basic type 148 148 function isbasic (type) 149 local t = gsub(type,'const ','')150 local m,t = applytypedef('', t)151 local b = _basic[t]152 if b then153 return b,_basic_ctype[b]154 end155 return nil149 local t = gsub(type,'const ','') 150 local m,t = applytypedef('', t) 151 local b = _basic[t] 152 if b then 153 return b,_basic_ctype[b] 154 end 155 return nil 156 156 end 157 157 158 158 -- split string using a token 159 159 function split (s,t) 160 local l = {n=0}161 local f = function (s)162 l.n = l.n + 1163 l[l.n] = s164 return ""165 end166 local p = "%s*(.-)%s*"..t.."%s*"167 s = gsub(s,"^%s+","")168 s = gsub(s,"%s+$","")169 s = gsub(s,p,f)170 l.n = l.n + 1171 l[l.n] = gsub(s,"(%s%s*)$","")172 return l160 local l = {n=0} 161 local f = function (s) 162 l.n = l.n + 1 163 l[l.n] = s 164 return "" 165 end 166 local p = "%s*(.-)%s*"..t.."%s*" 167 s = gsub(s,"^%s+","") 168 s = gsub(s,"%s+$","") 169 s = gsub(s,p,f) 170 l.n = l.n + 1 171 l[l.n] = gsub(s,"(%s%s*)$","") 172 return l 173 173 end 174 174 … … 178 178 function split_c_tokens(s, pat) 179 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 --ret.n=1231 --ret[1] = ""232 233 234 180 s = string.gsub(s, "^%s*", "") 181 s = string.gsub(s, "%s*$", "") 182 183 local token_begin = 1 184 local token_end = 1 185 local ofs = 1 186 local ret = {n=0} 187 188 function add_token(ofs) 189 190 local t = string.sub(s, token_begin, ofs) 191 t = string.gsub(t, "^%s*", "") 192 t = string.gsub(t, "%s*$", "") 193 ret.n = ret.n + 1 194 ret[ret.n] = t 195 end 196 197 while ofs <= string.len(s) do 198 199 local sub = string.sub(s, ofs, -1) 200 local b,e = string.find(sub, "^"..pat) 201 if b then 202 add_token(ofs-1) 203 ofs = ofs+e 204 token_begin = ofs 205 else 206 local char = string.sub(s, ofs, ofs) 207 if char == "(" or char == "<" then 208 209 local block 210 if char == "(" then block = "^%b()" end 211 if char == "<" then block = "^%b<>" end 212 213 b,e = string.find(sub, block) 214 if not b then 215 -- unterminated block? 216 ofs = ofs+1 217 else 218 ofs = ofs + e 219 end 220 221 else 222 ofs = ofs+1 223 end 224 end 225 226 end 227 add_token(ofs) 228 --if ret.n == 0 then 229 230 -- ret.n=1 231 -- ret[1] = "" 232 --end 233 234 return ret 235 235 236 236 end … … 238 238 -- concatenate strings of a table 239 239 function concat (t,f,l,jstr) 240 241 local s = ''242 local i=f243 while i<=l do244 s = s..t[i]245 i = i+1246 if i <= l then s = s..jstr end247 end248 return s240 jstr = jstr or " " 241 local s = '' 242 local i=f 243 while i<=l do 244 s = s..t[i] 245 i = i+1 246 if i <= l then s = s..jstr end 247 end 248 return s 249 249 end 250 250 251 251 -- concatenate all parameters, following output rules 252 252 function concatparam (line, ...) 253 local i=1254 while i<=arg.n do255 if _cont and not strfind(_cont,'[%(,"]') and256 strfind(arg[i],"^[%a_~]") then257 258 end259 line = line .. arg[i]260 if arg[i] ~= '' then261 _cont = strsub(arg[i],-1,-1)262 end263 i = i+1264 end265 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then266 _cont=nil line = line .. '\n'267 end268 253 local i=1 254 while i<=arg.n do 255 if _cont and not strfind(_cont,'[%(,"]') and 256 strfind(arg[i],"^[%a_~]") then 257 line = line .. ' ' 258 end 259 line = line .. arg[i] 260 if arg[i] ~= '' then 261 _cont = strsub(arg[i],-1,-1) 262 end 263 i = i+1 264 end 265 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then 266 _cont=nil line = line .. '\n' 267 end 268 return line 269 269 end 270 270 271 271 -- output line 272 272 function output (...) 273 local i=1274 while i<=arg.n do275 if _cont and not strfind(_cont,'[%(,"]') and276 strfind(arg[i],"^[%a_~]") then277 278 end279 write(arg[i])280 if arg[i] ~= '' then281 _cont = strsub(arg[i],-1,-1)282 end283 i = i+1284 end285 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then286 _cont=nil write('\n')287 end273 local i=1 274 while i<=arg.n do 275 if _cont and not strfind(_cont,'[%(,"]') and 276 strfind(arg[i],"^[%a_~]") then 277 write(' ') 278 end 279 write(arg[i]) 280 if arg[i] ~= '' then 281 _cont = strsub(arg[i],-1,-1) 282 end 283 i = i+1 284 end 285 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then 286 _cont=nil write('\n') 287 end 288 288 end 289 289 290 290 function get_property_methods(ptype, name) 291 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 292 if get_property_methods_hook and get_property_methods_hook(ptype,name) then 293 return get_property_methods_hook(ptype, name) 294 end 295 296 if ptype == "default" then -- get_name, set_name 297 return "get_"..name, "set_"..name 298 end 299 300 if ptype == "qt" then -- name, setName 301 return name, "set"..string.upper(string.sub(name, 1, 1))..string.sub(name, 2, -1) 302 end 303 304 if ptype == "overload" then -- name, name 305 return name,name 306 end 307 308 return nil 309 309 end 310 310 … … 315 315 -- takes the package object as the parameter 316 316 function preprocess_hook(p) 317 317 -- p.code has all the input code from the pkg 318 318 end 319 319 … … 351 351 function parser_hook(s) 352 352 353 354 end 355 356 353 return nil 354 end 355 356 -
code/trunk/src/tolua/lua/class.lua
r2087 r2710 18 18 -- {i} = list of members 19 19 classClass = { 20 classtype = 'class',21 name = '',22 base = '',23 type = '',24 btype = '',25 ctype = '',20 classtype = 'class', 21 name = '', 22 base = '', 23 type = '', 24 btype = '', 25 ctype = '', 26 26 } 27 27 classClass.__index = classClass … … 31 31 -- register class 32 32 function classClass:register (pre) 33 34 35 36 37 pre = pre or ''38 push(self)39 40 41 output(pre..'tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",'.._collect[self.type]..');')42 43 output(pre..'tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",NULL);')44 45 46 output(pre..'tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",NULL);')47 48 49 50 51 --output(pre..' tolua_addbase(tolua_S, "'..self.type..'", "'..base..'");')52 53 54 output(pre..'tolua_beginmodule(tolua_S,"'..self.lname..'");')55 local i=156 while self[i] do57 self[i]:register(pre..' ')58 i = i+159 end60 output(pre..'tolua_endmodule(tolua_S);')61 33 if not self:check_public_access() then 34 return 35 end 36 37 pre = pre or '' 38 push(self) 39 if _collect[self.type] then 40 output(pre,'#ifdef __cplusplus\n') 41 output(pre..'tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",'.._collect[self.type]..');') 42 output(pre,'#else\n') 43 output(pre..'tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",NULL);') 44 output(pre,'#endif\n') 45 else 46 output(pre..'tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",NULL);') 47 end 48 if self.extra_bases then 49 for k,base in ipairs(self.extra_bases) do 50 -- not now 51 --output(pre..' tolua_addbase(tolua_S, "'..self.type..'", "'..base..'");') 52 end 53 end 54 output(pre..'tolua_beginmodule(tolua_S,"'..self.lname..'");') 55 local i=1 56 while self[i] do 57 self[i]:register(pre..' ') 58 i = i+1 59 end 60 output(pre..'tolua_endmodule(tolua_S);') 61 pop() 62 62 end 63 63 64 64 -- return collection requirement 65 65 function classClass:requirecollection (t) 66 67 68 69 push(self)70 71 local i=172 while self[i] do73 r = self[i]:requirecollection(t) or r74 i = i+175 end76 77 78 79 80 81 82 83 84 return r66 if self.flags.protected_destructor then 67 return false 68 end 69 push(self) 70 local r = false 71 local i=1 72 while self[i] do 73 r = self[i]:requirecollection(t) or r 74 i = i+1 75 end 76 pop() 77 -- only class that exports destructor can be appropriately collected 78 -- classes that export constructors need to have a collector (overrided by -D flag on command line) 79 if self._delete or ((not flags['D']) and self._new) then 80 --t[self.type] = "tolua_collect_" .. gsub(self.type,"::","_") 81 t[self.type] = "tolua_collect_" .. clean_template(self.type) 82 r = true 83 end 84 return r 85 85 end 86 86 87 87 -- output tags 88 88 function classClass:decltype () 89 push(self)90 91 92 93 94 95 96 97 98 local i=199 while self[i] do100 self[i]:decltype()101 i = i+1102 end103 89 push(self) 90 self.type = regtype(self.original_name or self.name) 91 self.btype = typevar(self.base) 92 self.ctype = 'const '..self.type 93 if self.extra_bases then 94 for i=1,table.getn(self.extra_bases) do 95 self.extra_bases[i] = typevar(self.extra_bases[i]) 96 end 97 end 98 local i=1 99 while self[i] do 100 self[i]:decltype() 101 i = i+1 102 end 103 pop() 104 104 end 105 105 … … 107 107 -- Print method 108 108 function classClass:print (ident,close) 109 print(ident.."Class{")110 print(ident.." name = '"..self.name.."',")111 print(ident.." base = '"..self.base.."';")112 print(ident.." lname = '"..self.lname.."',")113 print(ident.." type = '"..self.type.."',")114 print(ident.." btype = '"..self.btype.."',")115 print(ident.." ctype = '"..self.ctype.."',")116 local i=1117 while self[i] do118 self[i]:print(ident.." ",",")119 i = i+1120 end121 print(ident.."}"..close)109 print(ident.."Class{") 110 print(ident.." name = '"..self.name.."',") 111 print(ident.." base = '"..self.base.."';") 112 print(ident.." lname = '"..self.lname.."',") 113 print(ident.." type = '"..self.type.."',") 114 print(ident.." btype = '"..self.btype.."',") 115 print(ident.." ctype = '"..self.ctype.."',") 116 local i=1 117 while self[i] do 118 self[i]:print(ident.." ",",") 119 i = i+1 120 end 121 print(ident.."}"..close) 122 122 end 123 123 124 124 function classClass:set_protected_destructor(p) 125 125 self.flags.protected_destructor = self.flags.protected_destructor or p 126 126 end 127 127 128 128 -- Internal constructor 129 129 function _Class (t) 130 setmetatable(t,classClass)131 t:buildnames()132 append(t)133 return t130 setmetatable(t,classClass) 131 t:buildnames() 132 append(t) 133 return t 134 134 end 135 135 … … 138 138 function Class (n,p,b) 139 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 end 220 140 if table.getn(p) > 1 then 141 b = string.sub(b, 1, -2) 142 for i=2,table.getn(p),1 do 143 b = b.."\n tolua_inherits "..p[i].." __"..p[i].."__;\n" 144 end 145 b = b.."\n}" 146 end 147 148 -- check for template 149 b = string.gsub(b, "^{%s*TEMPLATE_BIND", "{\nTOLUA_TEMPLATE_BIND") 150 local t,_,T,I = string.find(b, "^{%s*TOLUA_TEMPLATE_BIND%s*%(+%s*\"?([^\",]*)\"?%s*,%s*([^%)]*)%s*%)+") 151 if t then 152 153 -- remove quotes 154 I = string.gsub(I, "\"", "") 155 T = string.gsub(T, "\"", "") 156 -- get type list 157 local types = split_c_tokens(I, ",") 158 -- remove TEMPLATE_BIND line 159 local bs = string.gsub(b, "^{%s*TOLUA_TEMPLATE_BIND[^\n]*\n", "{\n") 160 161 -- replace 162 for i =1 , types.n do 163 164 local Tl = split(T, " ") 165 local Il = split_c_tokens(types[i], " ") 166 local bI = bs 167 local pI = {} 168 for j = 1,Tl.n do 169 Tl[j] = findtype(Tl[j]) or Tl[j] 170 bI = string.gsub(bI, "([^_%w])"..Tl[j].."([^_%w])", "%1"..Il[j].."%2") 171 if p then 172 for i=1,table.getn(p) do 173 pI[i] = string.gsub(p[i], "([^_%w]?)"..Tl[j].."([^_%w]?)", "%1"..Il[j].."%2") 174 end 175 end 176 end 177 --local append = "<"..string.gsub(types[i], "%s+", ",")..">" 178 local append = "<"..concat(Il, 1, table.getn(Il), ",")..">" 179 append = string.gsub(append, "%s*,%s*", ",") 180 append = string.gsub(append, ">>", "> >") 181 for i=1,table.getn(pI) do 182 --pI[i] = string.gsub(pI[i], ">>", "> >") 183 pI[i] = resolve_template_types(pI[i]) 184 end 185 bI = string.gsub(bI, ">>", "> >") 186 Class(n..append, pI, bI) 187 end 188 return 189 end 190 191 local mbase 192 193 if p then 194 mbase = table.remove(p, 1) 195 if not p[1] then p = nil end 196 end 197 198 mbase = mbase and resolve_template_types(mbase) 199 200 local c 201 local oname = string.gsub(n, "@.*$", "") 202 oname = getnamespace(classContainer.curr)..oname 203 204 if _global_classes[oname] then 205 c = _global_classes[oname] 206 if mbase and ((not c.base) or c.base == "") then 207 c.base = mbase 208 end 209 else 210 c = _Class(_Container{name=n, base=mbase, extra_bases=p}) 211 212 local ft = getnamespace(c.parent)..c.original_name 213 append_global_type(ft, c) 214 end 215 216 push(c) 217 c:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces 218 pop() 219 end 220 -
code/trunk/src/tolua/lua/clean.lua
r2087 r2710 10 10 11 11 MASK = { -- the substitution order is important 12 {ESC1, "\\'"},13 {ESC2, '\\"'},14 {STR1, "'"},15 {STR2, '"'},16 {STR3, "%[%["},17 {STR4, "%]%]"},18 {REM , "%-%-"},12 {ESC1, "\\'"}, 13 {ESC2, '\\"'}, 14 {STR1, "'"}, 15 {STR2, '"'}, 16 {STR3, "%[%["}, 17 {STR4, "%]%]"}, 18 {REM , "%-%-"}, 19 19 } 20 20 21 21 function mask (s) 22 for i = 1,getn(MASK) do23 s = gsub(s,MASK[i][2],MASK[i][1])24 end25 return s22 for i = 1,getn(MASK) do 23 s = gsub(s,MASK[i][2],MASK[i][1]) 24 end 25 return s 26 26 end 27 27 28 28 function unmask (s) 29 for i = 1,getn(MASK) do30 s = gsub(s,MASK[i][1],MASK[i][2])31 end32 return s29 for i = 1,getn(MASK) do 30 s = gsub(s,MASK[i][1],MASK[i][2]) 31 end 32 return s 33 33 end 34 34 35 35 function clean (s) 36 -- check for compilation error37 local code = "return function ()\n" .. s .. "\n end"38 if not dostring(code) then39 return nil40 end36 -- check for compilation error 37 local code = "return function ()\n" .. s .. "\n end" 38 if not dostring(code) then 39 return nil 40 end 41 41 42 if flags['C'] then43 44 end42 if flags['C'] then 43 return s 44 end 45 45 46 local S = "" -- saved string46 local S = "" -- saved string 47 47 48 s = mask(s)48 s = mask(s) 49 49 50 -- remove blanks and comments51 while 1 do52 local b,e,d = strfind(s,ANY)53 if b then54 S = S..strsub(s,1,b-1)55 s = strsub(s,b+1)56 if d==STR1 or d==STR2 then57 e = strfind(s,d)58 S = S ..d..strsub(s,1,e)59 s = strsub(s,e+1)60 elseif d==STR3 then61 e = strfind(s,STR4)62 S = S..d..strsub(s,1,e)63 s = strsub(s,e+1)64 elseif d==REM then65 s = gsub(s,"[^\n]*(\n?)","%1",1)66 end67 else68 S = S..s69 break70 end71 end72 -- eliminate unecessary spaces73 S = gsub(S,"[ \t]+"," ")74 S = gsub(S,"[ \t]*\n[ \t]*","\n")75 76 S = unmask(S)77 return S50 -- remove blanks and comments 51 while 1 do 52 local b,e,d = strfind(s,ANY) 53 if b then 54 S = S..strsub(s,1,b-1) 55 s = strsub(s,b+1) 56 if d==STR1 or d==STR2 then 57 e = strfind(s,d) 58 S = S ..d..strsub(s,1,e) 59 s = strsub(s,e+1) 60 elseif d==STR3 then 61 e = strfind(s,STR4) 62 S = S..d..strsub(s,1,e) 63 s = strsub(s,e+1) 64 elseif d==REM then 65 s = gsub(s,"[^\n]*(\n?)","%1",1) 66 end 67 else 68 S = S..s 69 break 70 end 71 end 72 -- eliminate unecessary spaces 73 S = gsub(S,"[ \t]+"," ") 74 S = gsub(S,"[ \t]*\n[ \t]*","\n") 75 S = gsub(S,"\n+","\n") 76 S = unmask(S) 77 return S 78 78 end 79 79 -
code/trunk/src/tolua/lua/code.lua
r2087 r2710 19 19 -- text = text code 20 20 classCode = { 21 text = '',21 text = '', 22 22 } 23 23 classCode.__index = classCode … … 26 26 -- register code 27 27 function classCode:register (pre) 28 pre = pre or ''29 -- clean Lua code30 local s = clean(self.text)31 if not s then32 --print(self.text)33 error("parser error in embedded code")34 end28 pre = pre or '' 29 -- clean Lua code 30 local s = clean(self.text) 31 if not s then 32 --print(self.text) 33 error("parser error in embedded code") 34 end 35 35 36 -- get first line37 local _, _, first_line=string.find(self.text, "^([^\n\r]*)")38 if string.find(first_line, "^%s*%-%-") then39 40 41 42 43 44 45 else46 47 end36 -- get first line 37 local _, _, first_line=string.find(self.text, "^([^\n\r]*)") 38 if string.find(first_line, "^%s*%-%-") then 39 if string.find(first_line, "^%-%-##") then 40 first_line = string.gsub(first_line, "^%-%-##", "") 41 if flags['C'] then 42 s = string.gsub(s, "^%-%-##[^\n\r]*\n", "") 43 end 44 end 45 else 46 first_line = "" 47 end 48 48 49 -- convert to C 50 output('\n'..pre..'{ /* begin embedded lua code */\n') 51 output(pre..' int top = lua_gettop(tolua_S);') 52 output(pre..' static unsigned char B[] = {\n ') 53 local t={n=0} 54 local b = gsub(s,'(.)',function (c) 55 local e = '' 56 t.n=t.n+1 if t.n==15 then t.n=0 e='\n'..pre..' ' end 57 return format('%3u,%s',strbyte(c),e) 58 end 59 ) 60 output(b..strbyte(" ")) 61 output('\n'..pre..' };\n') 62 if first_line and first_line ~= "" then 63 output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: '..first_line..'");') 64 else 65 output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code '..code_n..'");') 66 end 67 output(pre..' lua_settop(tolua_S, top);') 68 output(pre..'} /* end of embedded lua code */\n\n') 69 code_n = code_n +1 49 -- convert to C 50 output('\n'..pre..'{ /* begin embedded lua code */\n') 51 output(pre..' int top = lua_gettop(tolua_S);') 52 output(pre..' static unsigned char B[] = {\n ') 53 local t={n=0} 54 local b = gsub(s, '(.)', 55 function (c) 56 local e = '' 57 t.n=t.n+1 58 if t.n==15 then 59 t.n=0 e='\n'..pre..' ' 60 end 61 return format('%3u,%s',strbyte(c),e) 62 end 63 ) 64 output(b..strbyte(" ")) 65 output('\n'..pre..' };\n') 66 if first_line and first_line ~= "" then 67 output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: '..first_line..'");') 68 else 69 output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code '..code_n..'");') 70 end 71 output(pre..' lua_settop(tolua_S, top);') 72 output(pre..'} /* end of embedded lua code */\n\n') 73 code_n = code_n +1 70 74 end 71 75 … … 73 77 -- Print method 74 78 function classCode:print (ident,close) 75 print(ident.."Code{")76 print(ident.." text = [["..self.text.."]],")77 print(ident.."}"..close)79 print(ident.."Code{") 80 print(ident.." text = [["..self.text.."]],") 81 print(ident.."}"..close) 78 82 end 79 83 … … 81 85 -- Internal constructor 82 86 function _Code (t) 83 setmetatable(t,classCode)84 append(t)85 return t87 setmetatable(t,classCode) 88 append(t) 89 return t 86 90 end 87 91 … … 89 93 -- Expects a string representing the code text 90 94 function Code (l) 91 return _Code {92 text = l93 }95 return _Code { 96 text = l 97 } 94 98 end 95 99 -
code/trunk/src/tolua/lua/compat-5.1.lua
r2087 r2710 1 1 if string.find(_VERSION, "5%.0") then 2 2 return 3 3 end 4 4 5 5 -- "loadfile" 6 6 local function pp_dofile(path) 7 local loaded = false 8 local getfile = function() 7 9 8 local loaded = false 9 local getfile = function() 10 if loaded then 11 return 12 else 13 local file,err = io.open(path) 14 if not file then 15 error("error loading file "..path..": "..err) 16 end 17 local ret = file:read("*a") 18 file:close() 10 19 11 if loaded then 12 return 13 else 14 local file,err = io.open(path) 15 if not file then 16 error("error loading file "..path..": "..err) 17 end 18 local ret = file:read("*a") 19 file:close() 20 ret = string.gsub(ret, "%.%.%.%s*%)", "...) local arg = {n=select('#', ...), ...};") 20 21 21 ret = string.gsub(ret, "%.%.%.%s*%)", "...) local arg = {n=select('#', ...), ...};") 22 loaded = true 23 return ret 24 end 25 end 22 26 23 loaded = true 24 return ret 25 end 26 end 27 28 local f = load(getfile, path) 29 return f() 27 local f = load(getfile, path) 28 return f() 30 29 end 31 30 … … 38 37 local ogsub = string.gsub 39 38 local function compgsub(a,b,c,d) 40 if type(c) == "function" then41 local oc = c42 c = function (...) return oc(...) or '' end43 end44 return ogsub(a,b,c,d)39 if type(c) == "function" then 40 local oc = c 41 c = function (...) return oc(...) or '' end 42 end 43 return ogsub(a,b,c,d) 45 44 end 46 45 string.repl = ogsub -
code/trunk/src/tolua/lua/compat.lua
r2087 r2710 34 34 35 35 function do_ (f, err) 36 if not f then print(err); return end37 local a,b = pcall(f)38 if not a then print(b); return nil39 else return b or true40 end36 if not f then print(err); return end 37 local a,b = pcall(f) 38 if not a then print(b); return nil 39 else return b or true 40 end 41 41 end 42 42 … … 141 141 142 142 function flush (f) 143 if f then f:flush()144 else _OUTPUT:flush()145 end143 if f then f:flush() 144 else _OUTPUT:flush() 145 end 146 146 end 147 147 148 148 function readfrom (name) 149 if name == nil then150 local f, err, cod = io.close(_INPUT)151 _INPUT = io.stdin152 return f, err, cod153 else154 local f, err, cod = io.open(name, "r")155 _INPUT = f or _INPUT156 return f, err, cod157 end149 if name == nil then 150 local f, err, cod = io.close(_INPUT) 151 _INPUT = io.stdin 152 return f, err, cod 153 else 154 local f, err, cod = io.open(name, "r") 155 _INPUT = f or _INPUT 156 return f, err, cod 157 end 158 158 end 159 159 160 160 function writeto (name) 161 if name == nil then162 local f, err, cod = io.close(_OUTPUT)163 _OUTPUT = io.stdout164 return f, err, cod165 else166 local f, err, cod = io.open(name, "w")167 _OUTPUT = f or _OUTPUT168 return f, err, cod169 end161 if name == nil then 162 local f, err, cod = io.close(_OUTPUT) 163 _OUTPUT = io.stdout 164 return f, err, cod 165 else 166 local f, err, cod = io.open(name, "w") 167 _OUTPUT = f or _OUTPUT 168 return f, err, cod 169 end 170 170 end 171 171 172 172 function appendto (name) 173 local f, err, cod = io.open(name, "a")174 _OUTPUT = f or _OUTPUT175 return f, err, cod173 local f, err, cod = io.open(name, "a") 174 _OUTPUT = f or _OUTPUT 175 return f, err, cod 176 176 end 177 177 178 178 function read (...) 179 local f = _INPUT180 if rawtype(arg[1]) == 'userdata' then181 f = tab.remove(arg, 1)182 end183 return f:read(unpack(arg))179 local f = _INPUT 180 if rawtype(arg[1]) == 'userdata' then 181 f = tab.remove(arg, 1) 182 end 183 return f:read(unpack(arg)) 184 184 end 185 185 186 186 function write (...) 187 local f = _OUTPUT188 if rawtype(arg[1]) == 'userdata' then189 f = tab.remove(arg, 1)190 end191 return f:write(unpack(arg))187 local f = _OUTPUT 188 if rawtype(arg[1]) == 'userdata' then 189 f = tab.remove(arg, 1) 190 end 191 return f:write(unpack(arg)) 192 192 end 193 193 -
code/trunk/src/tolua/lua/container.lua
r2087 r2710 19 19 classContainer = 20 20 { 21 curr = nil,21 curr = nil, 22 22 } 23 23 classContainer.__index = classContainer … … 26 26 -- output tags 27 27 function classContainer:decltype () 28 push(self)29 local i=130 while self[i] do31 self[i]:decltype()32 i = i+133 end34 pop()28 push(self) 29 local i=1 30 while self[i] do 31 self[i]:decltype() 32 i = i+1 33 end 34 pop() 35 35 end 36 36 … … 39 39 function classContainer:supcode () 40 40 41 42 43 44 45 push(self)46 local i=147 while self[i] do48 if self[i]:check_public_access() then49 50 end51 i = i+152 end53 pop()41 if not self:check_public_access() then 42 return 43 end 44 45 push(self) 46 local i=1 47 while self[i] do 48 if self[i]:check_public_access() then 49 self[i]:supcode() 50 end 51 i = i+1 52 end 53 pop() 54 54 end 55 55 56 56 function classContainer:hasvar () 57 local i=158 while self[i] do59 if self[i]:isvariable() then60 61 62 i = i+163 end64 57 local i=1 58 while self[i] do 59 if self[i]:isvariable() then 60 return 1 61 end 62 i = i+1 63 end 64 return 0 65 65 end 66 66 67 67 -- Internal container constructor 68 68 function _Container (self) 69 setmetatable(self,classContainer)70 self.n = 071 self.typedefs = {tolua_n=0}72 self.usertypes = {}73 self.enums = {tolua_n=0}74 self.lnames = {}75 return self69 setmetatable(self,classContainer) 70 self.n = 0 71 self.typedefs = {tolua_n=0} 72 self.usertypes = {} 73 self.enums = {tolua_n=0} 74 self.lnames = {} 75 return self 76 76 end 77 77 78 78 -- push container 79 79 function push (t) 80 81 classContainer.curr = t80 t.prox = classContainer.curr 81 classContainer.curr = t 82 82 end 83 83 84 84 -- pop container 85 85 function pop () 86 --print("name",classContainer.curr.name)87 --foreach(classContainer.curr.usertypes,print)88 --print("______________")89 classContainer.curr = classContainer.curr.prox86 --print("name",classContainer.curr.name) 87 --foreach(classContainer.curr.usertypes,print) 88 --print("______________") 89 classContainer.curr = classContainer.curr.prox 90 90 end 91 91 92 92 -- get current namespace 93 93 function getcurrnamespace () 94 94 return getnamespace(classContainer.curr) 95 95 end 96 96 97 97 -- append to current container 98 98 function append (t) 99 return classContainer.curr:append(t)99 return classContainer.curr:append(t) 100 100 end 101 101 102 102 -- append typedef to current container 103 103 function appendtypedef (t) 104 return classContainer.curr:appendtypedef(t)104 return classContainer.curr:appendtypedef(t) 105 105 end 106 106 107 107 -- append usertype to current container 108 108 function appendusertype (t) 109 return classContainer.curr:appendusertype(t)109 return classContainer.curr:appendusertype(t) 110 110 end 111 111 112 112 -- append enum to current container 113 113 function appendenum (t) 114 return classContainer.curr:appendenum(t)114 return classContainer.curr:appendenum(t) 115 115 end 116 116 117 117 -- substitute typedef 118 118 function applytypedef (mod,type) 119 return classContainer.curr:applytypedef(mod,type)119 return classContainer.curr:applytypedef(mod,type) 120 120 end 121 121 122 122 -- check if is type 123 123 function findtype (type) 124 local t = classContainer.curr:findtype(type)125 124 local t = classContainer.curr:findtype(type) 125 return t 126 126 end 127 127 128 128 -- check if is typedef 129 129 function istypedef (type) 130 return classContainer.curr:istypedef(type)130 return classContainer.curr:istypedef(type) 131 131 end 132 132 133 133 -- get fulltype (with namespace) 134 134 function fulltype (t) 135 local curr = classContainer.curr136 137 138 139 140 141 142 143 144 145 146 135 local curr = classContainer.curr 136 while curr do 137 if curr then 138 if curr.typedefs and curr.typedefs[t] then 139 return curr.typedefs[t] 140 elseif curr.usertypes and curr.usertypes[t] then 141 return curr.usertypes[t] 142 end 143 end 144 curr = curr.prox 145 end 146 return t 147 147 end 148 148 149 149 -- checks if it requires collection 150 150 function classContainer:requirecollection (t) 151 push(self)152 local i=1153 154 while self[i] do155 r = self[i]:requirecollection(t) or r156 i = i+1157 end158 159 151 push(self) 152 local i=1 153 local r = false 154 while self[i] do 155 r = self[i]:requirecollection(t) or r 156 i = i+1 157 end 158 pop() 159 return r 160 160 end 161 161 … … 163 163 -- get namesapce 164 164 function getnamespace (curr) 165 166 167 168 169 170 171 172 173 174 175 165 local namespace = '' 166 while curr do 167 if curr and 168 ( curr.classtype == 'class' or curr.classtype == 'namespace') 169 then 170 namespace = (curr.original_name or curr.name) .. '::' .. namespace 171 --namespace = curr.name .. '::' .. namespace 172 end 173 curr = curr.prox 174 end 175 return namespace 176 176 end 177 177 178 178 -- get namespace (only namespace) 179 179 function getonlynamespace () 180 local curr = classContainer.curr181 182 183 184 185 186 187 188 189 190 180 local curr = classContainer.curr 181 local namespace = '' 182 while curr do 183 if curr.classtype == 'class' then 184 return namespace 185 elseif curr.classtype == 'namespace' then 186 namespace = curr.name .. '::' .. namespace 187 end 188 curr = curr.prox 189 end 190 return namespace 191 191 end 192 192 193 193 -- check if is enum 194 194 function isenum (type) 195 return classContainer.curr:isenum(type)195 return classContainer.curr:isenum(type) 196 196 end 197 197 198 198 -- append feature to container 199 199 function classContainer:append (t) 200 self.n = self.n + 1201 self[self.n] = t202 t.parent = self200 self.n = self.n + 1 201 self[self.n] = t 202 t.parent = self 203 203 end 204 204 205 205 -- append typedef 206 206 function classContainer:appendtypedef (t) 207 local namespace = getnamespace(classContainer.curr) 208 self.typedefs.tolua_n = self.typedefs.tolua_n + 1 209 self.typedefs[self.typedefs.tolua_n] = t 210 self.typedefs[t.utype] = namespace .. t.utype 211 global_typedefs[namespace..t.utype] = t 212 t.ftype = findtype(t.type) or t.type 213 --print("appending typedef "..t.utype.." as "..namespace..t.utype.." with ftype "..t.ftype) 214 append_global_type(namespace..t.utype) 215 if t.ftype and isenum(t.ftype) then 216 217 global_enums[namespace..t.utype] = true 218 end 207 local namespace = getnamespace(classContainer.curr) 208 self.typedefs.tolua_n = self.typedefs.tolua_n + 1 209 self.typedefs[self.typedefs.tolua_n] = t 210 self.typedefs[t.utype] = namespace .. t.utype 211 global_typedefs[namespace..t.utype] = t 212 t.ftype = findtype(t.type) or t.type 213 --print("appending typedef "..t.utype.." as "..namespace..t.utype.." with ftype "..t.ftype) 214 append_global_type(namespace..t.utype) 215 if t.ftype and isenum(t.ftype) then 216 global_enums[namespace..t.utype] = true 217 end 219 218 end 220 219 221 220 -- append usertype: return full type 222 221 function classContainer:appendusertype (t) 223 224 225 226 227 228 229 230 231 232 222 local container 223 if t == (self.original_name or self.name) then 224 container = self.prox 225 else 226 container = self 227 end 228 local ft = getnamespace(container) .. t 229 container.usertypes[t] = ft 230 _usertype[ft] = ft 231 return ft 233 232 end 234 233 235 234 -- append enum 236 235 function classContainer:appendenum (t) 237 local namespace = getnamespace(classContainer.curr)238 self.enums.tolua_n = self.enums.tolua_n + 1239 self.enums[self.enums.tolua_n] = t240 236 local namespace = getnamespace(classContainer.curr) 237 self.enums.tolua_n = self.enums.tolua_n + 1 238 self.enums[self.enums.tolua_n] = t 239 global_enums[namespace..t.name] = t 241 240 end 242 241 243 242 -- determine lua function name overload 244 243 function classContainer:overload (lname) 245 if not self.lnames[lname] then246 self.lnames[lname] = 0247 else248 self.lnames[lname] = self.lnames[lname] + 1249 end250 return format("%02d",self.lnames[lname])244 if not self.lnames[lname] then 245 self.lnames[lname] = 0 246 else 247 self.lnames[lname] = self.lnames[lname] + 1 248 end 249 return format("%02d",self.lnames[lname]) 251 250 end 252 251 253 252 -- applies typedef: returns the 'the facto' modifier and type 254 253 function classContainer:applytypedef (mod,type) 255 256 257 258 259 260 261 262 254 if global_typedefs[type] then 255 --print("found typedef "..global_typedefs[type].type) 256 local mod1, type1 = global_typedefs[type].mod, global_typedefs[type].ftype 257 local mod2, type2 = applytypedef(mod.." "..mod1, type1) 258 --return mod2 .. ' ' .. mod1, type2 259 return mod2, type2 260 end 261 do return mod,type end 263 262 end 264 263 265 264 -- check if it is a typedef 266 265 function classContainer:istypedef (type) 267 local env = self268 while env do269 if env.typedefs then270 local i=1271 while env.typedefs[i] do272 if env.typedefs[i].utype == type then273 return type274 end275 i = i+1276 end277 end278 env = env.parent279 end280 return nil266 local env = self 267 while env do 268 if env.typedefs then 269 local i=1 270 while env.typedefs[i] do 271 if env.typedefs[i].utype == type then 272 return type 273 end 274 i = i+1 275 end 276 end 277 env = env.parent 278 end 279 return nil 281 280 end 282 281 283 282 function find_enum_var(var) 284 283 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 284 if tonumber(var) then return var end 285 286 local c = classContainer.curr 287 while c do 288 local ns = getnamespace(c) 289 for k,v in pairs(_global_enums) do 290 if match_type(var, v, ns) then 291 return v 292 end 293 end 294 if c.base and c.base ~= '' then 295 c = _global_classes[c:findtype(c.base)] 296 else 297 c = nil 298 end 299 end 300 301 return var 303 302 end 304 303 … … 306 305 function classContainer:findtype (t) 307 306 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 307 t = string.gsub(t, "=.*", "") 308 if _basic[t] then 309 return t 310 end 311 312 local _,_,em = string.find(t, "([&%*])%s*$") 313 t = string.gsub(t, "%s*([&%*])%s*$", "") 314 p = self 315 while p and type(p)=='table' do 316 local st = getnamespace(p) 317 318 for i=_global_types.n,1,-1 do -- in reverse order 319 320 if match_type(t, _global_types[i], st) then 321 return _global_types[i]..(em or "") 322 end 323 end 324 if p.base and p.base ~= '' and p.base ~= t then 325 --print("type is "..t..", p is "..p.base.." self.type is "..self.type.." self.name is "..self.name) 326 p = _global_classes[p:findtype(p.base)] 327 else 328 p = nil 329 end 330 end 331 332 return nil 334 333 end 335 334 336 335 function append_global_type(t, class) 337 338 339 340 336 _global_types.n = _global_types.n +1 337 _global_types[_global_types.n] = t 338 _global_types_hash[t] = 1 339 if class then append_class_type(t, class) end 341 340 end 342 341 343 342 function append_class_type(t,class) 344 345 346 347 348 349 350 351 352 343 if _global_classes[t] then 344 class.flags = _global_classes[t].flags 345 class.lnames = _global_classes[t].lnames 346 if _global_classes[t].base and (_global_classes[t].base ~= '') then 347 class.base = _global_classes[t].base or class.base 348 end 349 end 350 _global_classes[t] = class 351 class.flags = class.flags or {} 353 352 end 354 353 355 354 function match_type(childtype, regtype, st) 356 355 --print("findtype "..childtype..", "..regtype..", "..st) 357 358 359 360 361 362 363 364 365 366 367 356 local b,e = string.find(regtype, childtype, -string.len(childtype), true) 357 if b then 358 359 if e == string.len(regtype) and 360 (b == 1 or (string.sub(regtype, b-1, b-1) == ':' and 361 string.sub(regtype, 1, b-1) == string.sub(st, 1, b-1))) then 362 return true 363 end 364 end 365 366 return false 368 367 end 369 368 370 369 function findtype_on_childs(self, t) 371 370 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 371 local tchild 372 if self.classtype == 'class' or self.classtype == 'namespace' then 373 for k,v in ipairs(self) do 374 if v.classtype == 'class' or v.classtype == 'namespace' then 375 if v.typedefs and v.typedefs[t] then 376 return v.typedefs[t] 377 elseif v.usertypes and v.usertypes[t] then 378 return v.usertypes[t] 379 end 380 tchild = findtype_on_childs(v, t) 381 if tchild then return tchild end 382 end 383 end 384 end 385 return nil 387 386 388 387 end 389 388 390 389 function classContainer:isenum (type) 391 if global_enums[type] then392 393 else394 395 end396 397 local basetype = gsub(type,"^.*::","")398 local env = self399 while env do400 if env.enums then401 local i=1402 while env.enums[i] do403 if env.enums[i].name == basetype then404 return true405 end406 i = i+1407 end408 end409 env = env.parent410 end411 return false390 if global_enums[type] then 391 return type 392 else 393 return false 394 end 395 396 local basetype = gsub(type,"^.*::","") 397 local env = self 398 while env do 399 if env.enums then 400 local i=1 401 while env.enums[i] do 402 if env.enums[i].name == basetype then 403 return true 404 end 405 i = i+1 406 end 407 end 408 env = env.parent 409 end 410 return false 412 411 end 413 412 … … 416 415 -- parse chunk 417 416 function classContainer:doparse (s) 418 --print ("parse "..s)419 420 -- try the parser hook421 do422 423 424 425 426 end427 428 -- try the null statement429 do430 431 432 433 434 end435 436 -- try empty verbatim line437 do438 439 440 441 442 end443 444 -- try Lua code445 do446 local b,e,code = strfind(s,"^%s*(%b\1\2)")447 if b then448 Code(strsub(code,2,-2))449 return strsub(s,e+1)450 end451 end452 453 -- try C code454 do455 local b,e,code = strfind(s,"^%s*(%b\3\4)")456 if b then457 458 459 460 end461 end462 463 -- try C code for preamble section464 do465 466 467 468 469 470 471 end472 473 -- try default_property directive474 do475 476 477 478 479 480 481 482 483 end484 485 -- try protected_destructor directive486 do487 488 489 490 491 492 493 494 end495 496 -- try 'extern' keyword497 do498 499 500 501 502 503 end504 505 -- try 'virtual' keyworkd506 do507 508 509 510 511 512 end513 514 -- try labels (public, private, etc)515 do516 517 518 519 520 end521 522 -- try module523 do524 local b,e,name,body = strfind(s,"^%s*module%s%s*([_%w][_%w]*)%s*(%b{})%s*")525 if b then526 _curr_code = strsub(s,b,e)527 Module(name,body)528 return strsub(s,e+1)529 end530 end531 532 -- try namesapce533 do534 local b,e,name,body = strfind(s,"^%s*namespace%s%s*([_%w][_%w]*)%s*(%b{})%s*;?")535 if b then536 _curr_code = strsub(s,b,e)537 Namespace(name,body)538 return strsub(s,e+1)539 end540 end541 542 -- try define543 do544 local b,e,name = strfind(s,"^%s*#define%s%s*([^%s]*)[^\n]*\n%s*")545 if b then546 _curr_code = strsub(s,b,e)547 Define(name)548 return strsub(s,e+1)549 end550 end551 552 -- try enumerates553 554 do555 local b,e,name,body,varname = strfind(s,"^%s*enum%s+(%S*)%s*(%b{})%s*([^%s;]*)%s*;?%s*")556 if b then557 --error("#Sorry, declaration of enums and variables on the same statement is not supported.\nDeclare your variable separately (example: '"..name.." "..varname..";')")558 _curr_code = strsub(s,b,e)559 Enumerate(name,body,varname)560 return strsub(s,e+1)561 end562 end563 564 -- do565 --local b,e,name,body = strfind(s,"^%s*enum%s+(%S*)%s*(%b{})%s*;?%s*")566 --if b then567 --_curr_code = strsub(s,b,e)568 --Enumerate(name,body)569 --return strsub(s,e+1)570 --end571 -- end572 573 do574 local b,e,body,name = strfind(s,"^%s*typedef%s+enum[^{]*(%b{})%s*([%w_][^%s]*)%s*;%s*")575 if b then576 _curr_code = strsub(s,b,e)577 Enumerate(name,body)578 return strsub(s,e+1)579 end580 end581 582 -- try operator583 do584 local b,e,decl,kind,arg,const = strfind(s,"^%s*([_%w][_%w%s%*&:<>,]-%s+operator)%s*([^%s][^%s]*)%s*(%b())%s*(c?o?n?s?t?)%s*;%s*")585 if not b then586 587 b,e,decl,kind,arg,const = strfind(s,"^%s*([_%w][_%w%s%*&:<>,]-%s+operator)%s*([^%s][^%s]*)%s*(%b())%s*(c?o?n?s?t?)[%s\n]*%b{}%s*;?%s*")588 end589 if not b then590 591 592 593 594 595 596 597 598 end599 if b then600 _curr_code = strsub(s,b,e)601 Operator(decl,kind,arg,const)602 return strsub(s,e+1)603 end604 end605 606 -- try function607 do608 --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*")609 local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*(=?%s*0?)%s*;%s*")610 if not b then611 612 613 end614 if not b then615 -- try a single letter function name616 b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*")617 end618 if b then619 620 621 622 623 624 _curr_code = strsub(s,b,e)625 Function(decl,arg,const)626 return strsub(s,e+1)627 end628 end629 630 -- try inline function631 do632 local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)[^;{]*%b{}%s*;?%s*")633 --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*")634 if not b then635 -- try a single letter function name636 b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?).-%b{}%s*;?%s*")637 end638 if b then639 _curr_code = strsub(s,b,e)640 Function(decl,arg,const)641 return strsub(s,e+1)642 end643 end644 645 -- try class646 do647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 -- try typedef683 do684 local b,e,types = strfind(s,"^%s*typedef%s%s*(.-)%s*;%s*")685 if b then686 _curr_code = strsub(s,b,e)687 Typedef(types)688 return strsub(s,e+1)689 end690 end691 692 -- try variable693 do694 local b,e,decl = strfind(s,"^%s*([_%w][_@%s%w%d%*&:<>,]*[_%w%d])%s*;%s*")695 if b then696 _curr_code = strsub(s,b,e)697 698 699 700 701 702 703 704 705 706 707 708 709 --Variable(decl)710 return strsub(s,e+1)711 end712 end713 714 715 do716 local b,e,decl = strfind(s,"^%s*([_%w]?[_%s%w%d]-char%s+[_@%w%d]*%s*%[%s*%S+%s*%])%s*;%s*")717 if b then718 _curr_code = strsub(s,b,e)719 Variable(decl)720 return strsub(s,e+1)721 end722 end723 724 -- try array725 do726 local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:]*[]_%w%d])%s*;%s*")727 if b then728 _curr_code = strsub(s,b,e)729 Array(decl)730 return strsub(s,e+1)731 end732 end733 734 -- no matching735 if gsub(s,"%s%s*","") ~= "" then736 _curr_code = s737 error("#parse error")738 else739 return ""740 end417 --print ("parse "..s) 418 419 -- try the parser hook 420 do 421 local sub = parser_hook(s) 422 if sub then 423 return sub 424 end 425 end 426 427 -- try the null statement 428 do 429 local b,e,code = string.find(s, "^%s*;") 430 if b then 431 return strsub(s,e+1) 432 end 433 end 434 435 -- try empty verbatim line 436 do 437 local b,e,code = string.find(s, "^%s*$\n") 438 if b then 439 return strsub(s,e+1) 440 end 441 end 442 443 -- try Lua code 444 do 445 local b,e,code = strfind(s,"^%s*(%b\1\2)") 446 if b then 447 Code(strsub(code,2,-2)) 448 return strsub(s,e+1) 449 end 450 end 451 452 -- try C code 453 do 454 local b,e,code = strfind(s,"^%s*(%b\3\4)") 455 if b then 456 code = '{'..strsub(code,2,-2)..'\n}\n' 457 Verbatim(code,'r') -- verbatim code for 'r'egister fragment 458 return strsub(s,e+1) 459 end 460 end 461 462 -- try C code for preamble section 463 do 464 local b,e,code = string.find(s, "^%s*(%b\5\6)") 465 if b then 466 code = string.sub(code, 2, -2).."\n" 467 Verbatim(code, '') 468 return string.sub(s, e+1) 469 end 470 end 471 472 -- try default_property directive 473 do 474 local b,e,ptype = strfind(s, "^%s*TOLUA_PROPERTY_TYPE%s*%(+%s*([^%)%s]*)%s*%)+%s*;?") 475 if b then 476 if not ptype or ptype == "" then 477 ptype = "default" 478 end 479 self:set_property_type(ptype) 480 return strsub(s, e+1) 481 end 482 end 483 484 -- try protected_destructor directive 485 do 486 local b,e = string.find(s, "^%s*TOLUA_PROTECTED_DESTRUCTOR%s*;?") 487 if b then 488 if self.set_protected_destructor then 489 self:set_protected_destructor(true) 490 end 491 return strsub(s, e+1) 492 end 493 end 494 495 -- try 'extern' keyword 496 do 497 local b,e = string.find(s, "^%s*extern%s+") 498 if b then 499 -- do nothing 500 return strsub(s, e+1) 501 end 502 end 503 504 -- try 'virtual' keyworkd 505 do 506 local b,e = string.find(s, "^%s*virtual%s+") 507 if b then 508 methodisvirtual = true 509 return strsub(s, e+1) 510 end 511 end 512 513 -- try labels (public, private, etc) 514 do 515 local b,e = string.find(s, "^%s*%w*%s*:[^:]") 516 if b then 517 return strsub(s, e) -- preserve the [^:] 518 end 519 end 520 521 -- try module 522 do 523 local b,e,name,body = strfind(s,"^%s*module%s%s*([_%w][_%w]*)%s*(%b{})%s*") 524 if b then 525 _curr_code = strsub(s,b,e) 526 Module(name,body) 527 return strsub(s,e+1) 528 end 529 end 530 531 -- try namesapce 532 do 533 local b,e,name,body = strfind(s,"^%s*namespace%s%s*([_%w][_%w]*)%s*(%b{})%s*;?") 534 if b then 535 _curr_code = strsub(s,b,e) 536 Namespace(name,body) 537 return strsub(s,e+1) 538 end 539 end 540 541 -- try define 542 do 543 local b,e,name = strfind(s,"^%s*#define%s%s*([^%s]*)[^\n]*\n%s*") 544 if b then 545 _curr_code = strsub(s,b,e) 546 Define(name) 547 return strsub(s,e+1) 548 end 549 end 550 551 -- try enumerates 552 553 do 554 local b,e,name,body,varname = strfind(s,"^%s*enum%s+(%S*)%s*(%b{})%s*([^%s;]*)%s*;?%s*") 555 if b then 556 --error("#Sorry, declaration of enums and variables on the same statement is not supported.\nDeclare your variable separately (example: '"..name.." "..varname..";')") 557 _curr_code = strsub(s,b,e) 558 Enumerate(name,body,varname) 559 return strsub(s,e+1) 560 end 561 end 562 563 -- do 564 -- local b,e,name,body = strfind(s,"^%s*enum%s+(%S*)%s*(%b{})%s*;?%s*") 565 -- if b then 566 -- _curr_code = strsub(s,b,e) 567 -- Enumerate(name,body) 568 -- return strsub(s,e+1) 569 -- end 570 -- end 571 572 do 573 local b,e,body,name = strfind(s,"^%s*typedef%s+enum[^{]*(%b{})%s*([%w_][^%s]*)%s*;%s*") 574 if b then 575 _curr_code = strsub(s,b,e) 576 Enumerate(name,body) 577 return strsub(s,e+1) 578 end 579 end 580 581 -- try operator 582 do 583 local b,e,decl,kind,arg,const = strfind(s,"^%s*([_%w][_%w%s%*&:<>,]-%s+operator)%s*([^%s][^%s]*)%s*(%b())%s*(c?o?n?s?t?)%s*;%s*") 584 if not b then 585 -- try inline 586 b,e,decl,kind,arg,const = strfind(s,"^%s*([_%w][_%w%s%*&:<>,]-%s+operator)%s*([^%s][^%s]*)%s*(%b())%s*(c?o?n?s?t?)[%s\n]*%b{}%s*;?%s*") 587 end 588 if not b then 589 -- try cast operator 590 b,e,decl,kind,arg,const = strfind(s, "^%s*(operator)%s+([%w_:%d<>%*%&%s]+)%s*(%b())%s*(c?o?n?s?t?)"); 591 if b then 592 local _,ie = string.find(s, "^%s*%b{}", e+1) 593 if ie then 594 e = ie 595 end 596 end 597 end 598 if b then 599 _curr_code = strsub(s,b,e) 600 Operator(decl,kind,arg,const) 601 return strsub(s,e+1) 602 end 603 end 604 605 -- try function 606 do 607 --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") 608 local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*(=?%s*0?)%s*;%s*") 609 if not b then 610 -- try function with template 611 b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*") 612 end 613 if not b then 614 -- try a single letter function name 615 b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*") 616 end 617 if b then 618 if virt and string.find(virt, "[=0]") then 619 if self.flags then 620 self.flags.pure_virtual = true 621 end 622 end 623 _curr_code = strsub(s,b,e) 624 Function(decl,arg,const) 625 return strsub(s,e+1) 626 end 627 end 628 629 -- try inline function 630 do 631 local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)[^;{]*%b{}%s*;?%s*") 632 --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*") 633 if not b then 634 -- try a single letter function name 635 b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?).-%b{}%s*;?%s*") 636 end 637 if b then 638 _curr_code = strsub(s,b,e) 639 Function(decl,arg,const) 640 return strsub(s,e+1) 641 end 642 end 643 644 -- try class 645 do 646 local b,e,name,base,body 647 base = '' body = '' 648 b,e,name = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*;") -- dummy class 649 if not b then 650 b,e,name = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*;") -- dummy struct 651 if not b then 652 b,e,name,base,body = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*") 653 if not b then 654 b,e,name,base,body = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*") 655 if not b then 656 b,e,name,base,body = strfind(s,"^%s*union%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*") 657 if not b then 658 base = '' 659 b,e,body,name = strfind(s,"^%s*typedef%s%s*struct%s%s*[_%w]*%s*(%b{})%s*([_%w][_%w@]*)%s*;%s*") 660 end 661 end 662 end 663 end 664 end 665 if b then 666 if base ~= '' then 667 base = string.gsub(base, "^%s*:%s*", "") 668 base = string.gsub(base, "%s*public%s*", "") 669 base = split(base, ",") 670 --local b,e 671 --b,e,base = strfind(base,".-([_%w][_%w<>,:]*)$") 672 else 673 base = {} 674 end 675 _curr_code = strsub(s,b,e) 676 Class(name,base,body) 677 return strsub(s,e+1) 678 end 679 end 680 681 -- try typedef 682 do 683 local b,e,types = strfind(s,"^%s*typedef%s%s*(.-)%s*;%s*") 684 if b then 685 _curr_code = strsub(s,b,e) 686 Typedef(types) 687 return strsub(s,e+1) 688 end 689 end 690 691 -- try variable 692 do 693 local b,e,decl = strfind(s,"^%s*([_%w][_@%s%w%d%*&:<>,]*[_%w%d])%s*;%s*") 694 if b then 695 _curr_code = strsub(s,b,e) 696 697 local list = split_c_tokens(decl, ",") 698 Variable(list[1]) 699 if list.n > 1 then 700 local _,_,type = strfind(list[1], "(.-)%s+([^%s]*)$"); 701 702 local i =2; 703 while list[i] do 704 Variable(type.." "..list[i]) 705 i=i+1 706 end 707 end 708 --Variable(decl) 709 return strsub(s,e+1) 710 end 711 end 712 713 -- try string 714 do 715 local b,e,decl = strfind(s,"^%s*([_%w]?[_%s%w%d]-char%s+[_@%w%d]*%s*%[%s*%S+%s*%])%s*;%s*") 716 if b then 717 _curr_code = strsub(s,b,e) 718 Variable(decl) 719 return strsub(s,e+1) 720 end 721 end 722 723 -- try array 724 do 725 local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:]*[]_%w%d])%s*;%s*") 726 if b then 727 _curr_code = strsub(s,b,e) 728 Array(decl) 729 return strsub(s,e+1) 730 end 731 end 732 733 -- no matching 734 if gsub(s,"%s%s*","") ~= "" then 735 _curr_code = s 736 error("#parse error") 737 else 738 return "" 739 end 741 740 742 741 end … … 744 743 function classContainer:parse (s) 745 744 746 747 748 while s ~= '' do749 s = self:doparse(s)750 methodisvirtual = false751 end745 self.curr_member_access = nil 746 747 while s ~= '' do 748 s = self:doparse(s) 749 methodisvirtual = false 750 end 752 751 end 753 752 … … 757 756 function get_property_type() 758 757 759 758 return classContainer.curr:get_property_type() 760 759 end 761 760 762 761 function classContainer:set_property_type(ptype) 763 764 765 766 762 ptype = string.gsub(ptype, "^%s*", "") 763 ptype = string.gsub(ptype, "%s*$", "") 764 765 self.property_type = ptype 767 766 end 768 767 769 768 function classContainer:get_property_type() 770 771 end 769 return self.property_type or (self.parent and self.parent:get_property_type()) or "default" 770 end -
code/trunk/src/tolua/lua/custom.lua
r2087 r2710 1 1 2 2 function extract_code(fn,s) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 3 local code = "" 4 if fn then 5 code = '\n$#include "'..fn..'"\n' 6 end 7 s= "\n" .. s .. "\n" -- add blank lines as sentinels 8 local _,e,c,t = strfind(s, "\n([^\n]-)SCRIPT_([%w_]*)[^\n]*\n") 9 while e do 10 t = strlower(t) 11 if t == "bind_begin" then 12 _,e,c = strfind(s,"(.-)\n[^\n]*SCRIPT_BIND_END[^\n]*\n",e) 13 if not e then 14 tolua_error("Unbalanced 'SCRIPT_BIND_BEGIN' directive in header file") 15 end 16 end 17 if t == "bind_class" or t == "bind_block" then 18 local b 19 _,e,c,b = string.find(s, "([^{]-)(%b{})", e) 20 c = c..'{\n'..extract_code(nil, b)..'\n};\n' 21 end 22 code = code .. c .. "\n" 23 _,e,c,t = strfind(s, "\n([^\n]-)SCRIPT_([%w_]*)[^\n]*\n",e) 24 end 25 return code 26 26 end 27 27 … … 33 33 34 34 function include_file_hook(p, filename) 35 35 do return end 36 36 --print("FILENAME is "..filename) 37 38 39 40 41 42 43 37 p.code = string.gsub(p.code, "\n%s*SigC::Signal", "\n\ttolua_readonly SigC::Signal") 38 p.code = string.gsub(p.code, "#ifdef __cplusplus\nextern \"C\" {\n#endif", "") 39 p.code = string.gsub(p.code, "#ifdef __cplusplus\n};?\n#endif", "") 40 p.code = string.gsub(p.code, "DECLSPEC", "") 41 p.code = string.gsub(p.code, "SDLCALL", "") 42 p.code = string.gsub(p.code, "DLLINTERFACE", "") 43 p.code = string.gsub(p.code, "#define[^\n]*_[hH]_?%s*\n", "\n") 44 44 --print("code is "..p.code) 45 45 end -
code/trunk/src/tolua/lua/custom_hide.lua
r2087 r2710 1 1 -- extract code with tolua_hide, and also 2 2 function extract_code(fn,s) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 3 local code = '\n$#include "'..fn..'"\n' 4 s= "\n" .. s .. "\n" -- add blank lines as sentinels 5 local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n") 6 while e do 7 t = strlower(t) 8 if t == "begin" then 9 _,e,c = strfind(s,"(.-)\n[^\n]*[Tt][Oo][Ll][Uu][Aa]_[Ee][Nn][Dd][^\n]*\n",e) 10 if not e then 11 tolua_error("Unbalanced 'tolua_begin' directive in header file") 12 end 13 end 14 c = c.."\n" 15 c = string.gsub(c, "\n[^\n]*[Tt][Oo][Ll][Uu][Aa]_[hH][iI][Dd][eE][^\n]*\n", "\n"); 16 c = string.gsub(c, "#define[^%(\n]*%(.-\n", "\n") 17 code = code .. c 18 _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n",e) 19 end 20 return code 21 21 end -
code/trunk/src/tolua/lua/declaration.lua
r2087 r2710 22 22 -- ret = "*" or "&", if value is to be returned (only for arguments) 23 23 classDeclaration = { 24 mod = '',25 type = '',26 ptr = '',27 name = '',28 dim = '',29 ret = '',30 def = ''24 mod = '', 25 type = '', 26 ptr = '', 27 name = '', 28 dim = '', 29 ret = '', 30 def = '' 31 31 } 32 32 classDeclaration.__index = classDeclaration … … 35 35 -- Create an unique variable name 36 36 function create_varname () 37 if not _varnumber then _varnumber = 0 end38 _varnumber = _varnumber + 139 return "tolua_var_".._varnumber37 if not _varnumber then _varnumber = 0 end 38 _varnumber = _varnumber + 1 39 return "tolua_var_".._varnumber 40 40 end 41 41 … … 44 44 function classDeclaration:checkname () 45 45 46 if strsub(self.name,1,1) == '[' and not findtype(self.type) then47 self.name = self.type..self.name48 local m = split(self.mod,'%s%s*')49 self.type = m[m.n]50 self.mod = concat(m,1,m.n-1)51 end52 53 local t = split(self.name,'=')54 if t.n==2 then55 self.name = t[1]56 self.def = find_enum_var(t[t.n])57 end58 59 local b,e,d = strfind(self.name,"%[(.-)%]")60 if b then61 self.name = strsub(self.name,1,b-1)62 self.dim = find_enum_var(d)63 end64 65 66 if self.type ~= '' and self.type ~= 'void' and self.name == '' then67 self.name = create_varname()68 elseif self.kind=='var' then69 if self.type=='' and self.name~='' then70 self.type = self.type..self.name71 self.name = create_varname()72 elseif findtype(self.name) then73 if self.type=='' then self.type = self.name74 else self.type = self.type..' '..self.name end75 self.name = create_varname()76 end77 end78 79 -- adjust type of string80 if self.type == 'char' and self.dim ~= '' then81 82 end83 84 85 86 46 if strsub(self.name,1,1) == '[' and not findtype(self.type) then 47 self.name = self.type..self.name 48 local m = split(self.mod,'%s%s*') 49 self.type = m[m.n] 50 self.mod = concat(m,1,m.n-1) 51 end 52 53 local t = split(self.name,'=') 54 if t.n==2 then 55 self.name = t[1] 56 self.def = find_enum_var(t[t.n]) 57 end 58 59 local b,e,d = strfind(self.name,"%[(.-)%]") 60 if b then 61 self.name = strsub(self.name,1,b-1) 62 self.dim = find_enum_var(d) 63 end 64 65 66 if self.type ~= '' and self.type ~= 'void' and self.name == '' then 67 self.name = create_varname() 68 elseif self.kind=='var' then 69 if self.type=='' and self.name~='' then 70 self.type = self.type..self.name 71 self.name = create_varname() 72 elseif findtype(self.name) then 73 if self.type=='' then self.type = self.name 74 else self.type = self.type..' '..self.name end 75 self.name = create_varname() 76 end 77 end 78 79 -- adjust type of string 80 if self.type == 'char' and self.dim ~= '' then 81 self.type = 'char*' 82 end 83 84 if self.kind and self.kind == 'var' then 85 self.name = string.gsub(self.name, ":.*$", "") -- ??? 86 end 87 87 end 88 88 … … 91 91 function classDeclaration:checktype () 92 92 93 -- check if there is a pointer to basic type94 local basic = isbasic(self.type)95 if self.kind == 'func' and basic=='number' and string.find(self.ptr, "%*") then96 97 98 end99 if basic and self.ptr~='' then100 self.ret = self.ptr101 self.ptr = nil102 if isbasic(self.type) == 'number' then103 104 end105 end106 107 -- check if there is array to be returned108 if self.dim~='' and self.ret~='' then109 error('#invalid parameter: cannot return an array of values')110 end111 -- restore 'void*' and 'string*'112 if self.type == '_userdata' then self.type = 'void*'113 elseif self.type == '_cstring' then self.type = 'char*'114 elseif self.type == '_lstate' then self.type = 'lua_State*'115 end116 117 -- resolve types inside the templates118 if self.type then119 120 end121 122 --123 -- -- if returning value, automatically set default value124 -- if self.ret ~= '' and self.def == '' then125 -- self.def = '0'126 -- end127 --93 -- check if there is a pointer to basic type 94 local basic = isbasic(self.type) 95 if self.kind == 'func' and basic=='number' and string.find(self.ptr, "%*") then 96 self.type = '_userdata' 97 self.ptr = "" 98 end 99 if basic and self.ptr~='' then 100 self.ret = self.ptr 101 self.ptr = nil 102 if isbasic(self.type) == 'number' then 103 self.return_userdata = true 104 end 105 end 106 107 -- check if there is array to be returned 108 if self.dim~='' and self.ret~='' then 109 error('#invalid parameter: cannot return an array of values') 110 end 111 -- restore 'void*' and 'string*' 112 if self.type == '_userdata' then self.type = 'void*' 113 elseif self.type == '_cstring' then self.type = 'char*' 114 elseif self.type == '_lstate' then self.type = 'lua_State*' 115 end 116 117 -- resolve types inside the templates 118 if self.type then 119 self.type = resolve_template_types(self.type) 120 end 121 122 -- 123 -- -- if returning value, automatically set default value 124 -- if self.ret ~= '' and self.def == '' then 125 -- self.def = '0' 126 -- end 127 -- 128 128 129 129 end … … 131 131 function resolve_template_types(type) 132 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 133 if isbasic(type) then 134 return type 135 end 136 local b,_,m = string.find(type, "(%b<>)") 137 if b then 138 139 m = split_c_tokens(string.sub(m, 2, -2), ",") 140 for i=1, table.getn(m) do 141 m[i] = string.gsub(m[i],"%s*([%*&])", "%1") 142 m[i] = findtype(m[i]) or m[i] 143 m[i] = resolve_template_types(m[i]) 144 end 145 146 local b,i 147 type,b,i = break_template(type) 148 local template_part = "<"..string.gsub(concat(m, 1, m.n), " ", ",")..">" 149 type = rebuild_template(type, b, template_part) 150 type = string.gsub(type, ">>", "> >") 151 end 152 return type 153 153 end 154 154 155 155 function break_template(s) 156 157 158 159 160 161 162 156 local b,e,timpl = string.find(s, "(%b<>)") 157 if timpl then 158 s = string.gsub(s, "%b<>", "") 159 return s, b, timpl 160 else 161 return s, 0, nil 162 end 163 163 end 164 164 165 165 function rebuild_template(s, b, timpl) 166 166 167 168 169 170 171 167 if b == 0 then 168 return s 169 end 170 171 return string.sub(s, 1, b-1)..timpl..string.sub(s, b, -1) 172 172 end 173 173 174 174 -- Print method 175 175 function classDeclaration:print (ident,close) 176 print(ident.."Declaration{")177 print(ident.." mod = '"..self.mod.."',")178 print(ident.." type = '"..self.type.."',")179 print(ident.." ptr = '"..self.ptr.."',")180 print(ident.." name = '"..self.name.."',")181 print(ident.." dim = '"..self.dim.."',")182 print(ident.." def = '"..self.def.."',")183 print(ident.." ret = '"..self.ret.."',")184 print(ident.."}"..close)176 print(ident.."Declaration{") 177 print(ident.." mod = '"..self.mod.."',") 178 print(ident.." type = '"..self.type.."',") 179 print(ident.." ptr = '"..self.ptr.."',") 180 print(ident.." name = '"..self.name.."',") 181 print(ident.." dim = '"..self.dim.."',") 182 print(ident.." def = '"..self.def.."',") 183 print(ident.." ret = '"..self.ret.."',") 184 print(ident.."}"..close) 185 185 end 186 186 … … 188 188 function classDeclaration:requirecollection (t) 189 189 if self.mod ~= 'const' and 190 191 192 193 194 195 196 197 190 self.dim and self.dim ~= '' and 191 not isbasic(self.type) and 192 self.ptr == '' then 193 local type = gsub(self.type,"%s*const%s+","") 194 t[type] = "tolua_collect_" .. clean_template(type) 195 return true 196 end 197 return false 198 198 end 199 199 … … 201 201 function classDeclaration:decltype () 202 202 203 204 205 206 207 203 self.type = typevar(self.type) 204 if strfind(self.mod,'const') then 205 self.type = 'const '..self.type 206 self.mod = gsub(self.mod,'const%s*','') 207 end 208 208 end 209 209 … … 211 211 -- output type checking 212 212 function classDeclaration:outchecktype (narg) 213 local def214 local t = isbasic(self.type)215 if self.def~='' then216 def = 1217 else218 def = 0219 end220 if self.dim ~= '' then221 222 --return 'tolua_isstringarray(tolua_S,'..narg..','..def..',&tolua_err)'223 224 225 226 elseif t then227 228 else229 return 'tolua_isusertype(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err)'230 end213 local def 214 local t = isbasic(self.type) 215 if self.def~='' then 216 def = 1 217 else 218 def = 0 219 end 220 if self.dim ~= '' then 221 --if t=='string' then 222 -- return 'tolua_isstringarray(tolua_S,'..narg..','..def..',&tolua_err)' 223 --else 224 return 'tolua_istable(tolua_S,'..narg..',0,&tolua_err)' 225 --end 226 elseif t then 227 return 'tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' 228 else 229 return 'tolua_isusertype(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err)' 230 end 231 231 end 232 232 233 233 function classDeclaration:builddeclaration (narg, cplusplus) 234 local array = self.dim ~= '' and tonumber(self.dim)==nil235 236 local ptr = ''237 238 239 if self.dim ~= '' then240 241 end242 if self.ptr~='' and not isbasic(type) then ptr = '*' end243 line = concatparam(line," ",self.mod,type,ptr)244 if array then245 line = concatparam(line,'*')246 end247 line = concatparam(line,self.name)248 if self.dim ~= '' then249 if tonumber(self.dim)~=nil then250 line = concatparam(line,'[',self.dim,'];')251 else252 253 254 255 256 257 258 end259 else260 local t = isbasic(type)261 line = concatparam(line,' = ')262 if t == 'state' then263 264 else265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 end291 end292 234 local array = self.dim ~= '' and tonumber(self.dim)==nil 235 local line = "" 236 local ptr = '' 237 local mod 238 local type = self.type 239 if self.dim ~= '' then 240 type = gsub(self.type,'const%s+','') -- eliminates const modifier for arrays 241 end 242 if self.ptr~='' and not isbasic(type) then ptr = '*' end 243 line = concatparam(line," ",self.mod,type,ptr) 244 if array then 245 line = concatparam(line,'*') 246 end 247 line = concatparam(line,self.name) 248 if self.dim ~= '' then 249 if tonumber(self.dim)~=nil then 250 line = concatparam(line,'[',self.dim,'];') 251 else 252 if cplusplus then 253 line = concatparam(line,' = new',type,ptr,'['..self.dim..'];') 254 else 255 line = concatparam(line,' = (',type,ptr,'*)', 256 'malloc((',self.dim,')*sizeof(',type,ptr,'));') 257 end 258 end 259 else 260 local t = isbasic(type) 261 line = concatparam(line,' = ') 262 if t == 'state' then 263 line = concatparam(line, 'tolua_S;') 264 else 265 --print("t is "..tostring(t)..", ptr is "..tostring(self.ptr)) 266 if t == 'number' and string.find(self.ptr, "%*") then 267 t = 'userdata' 268 end 269 if not t and ptr=='' then line = concatparam(line,'*') end 270 line = concatparam(line,'((',self.mod,type) 271 if not t then 272 line = concatparam(line,'*') 273 end 274 line = concatparam(line,') ') 275 if isenum(type) then 276 line = concatparam(line,'(int) ') 277 end 278 local def = 0 279 if self.def ~= '' then 280 def = self.def 281 if (ptr == '' or self.ptr == '&') and not t then 282 def = "(void*)&(const "..type..")"..def 283 end 284 end 285 if t then 286 line = concatparam(line,'tolua_to'..t,'(tolua_S,',narg,',',def,'));') 287 else 288 line = concatparam(line,'tolua_tousertype(tolua_S,',narg,',',def,'));') 289 end 290 end 291 end 292 return line 293 293 end 294 294 295 295 -- Declare variable 296 296 function classDeclaration:declare (narg) 297 if self.dim ~= '' and tonumber(self.dim)==nil then298 299 300 301 302 303 304 305 297 if self.dim ~= '' and tonumber(self.dim)==nil then 298 output('#ifdef __cplusplus\n') 299 output(self:builddeclaration(narg,true)) 300 output('#else\n') 301 output(self:builddeclaration(narg,false)) 302 output('#endif\n') 303 else 304 output(self:builddeclaration(narg,false)) 305 end 306 306 end 307 307 308 308 -- Get parameter value 309 309 function classDeclaration:getarray (narg) 310 if self.dim ~= '' then311 312 output(' {')313 314 local def; if self.def~='' then def=1 else def=0 end315 316 317 output(' if (!tolua_is'..t..'array(tolua_S,',narg,',',self.dim,',',def,',&tolua_err))')318 319 output(' if (!tolua_isusertypearray(tolua_S,',narg,',"',type,'",',self.dim,',',def,',&tolua_err))')320 321 output(' goto tolua_lerror;')322 output(' else\n')323 324 output(' {')325 output(' int i;')326 output(' for(i=0; i<'..self.dim..';i++)')327 local t = isbasic(type)328 local ptr = ''329 if self.ptr~='' then ptr = '*' end330 output(' ',self.name..'[i] = ')331 if not t and ptr=='' then output('*') end332 output('((',type)333 if not t then334 output('*')335 end336 output(') ')337 local def = 0338 if self.def ~= '' then def = self.def end339 if t then340 output('tolua_tofield'..t..'(tolua_S,',narg,',i+1,',def,'));')341 else342 output('tolua_tofieldusertype(tolua_S,',narg,',i+1,',def,'));')343 end344 output(' }')345 output(' }')346 end310 if self.dim ~= '' then 311 local type = gsub(self.type,'const ','') 312 output(' {') 313 output('#ifndef TOLUA_RELEASE\n') 314 local def; if self.def~='' then def=1 else def=0 end 315 local t = isbasic(type) 316 if (t) then 317 output(' if (!tolua_is'..t..'array(tolua_S,',narg,',',self.dim,',',def,',&tolua_err))') 318 else 319 output(' if (!tolua_isusertypearray(tolua_S,',narg,',"',type,'",',self.dim,',',def,',&tolua_err))') 320 end 321 output(' goto tolua_lerror;') 322 output(' else\n') 323 output('#endif\n') 324 output(' {') 325 output(' int i;') 326 output(' for(i=0; i<'..self.dim..';i++)') 327 local t = isbasic(type) 328 local ptr = '' 329 if self.ptr~='' then ptr = '*' end 330 output(' ',self.name..'[i] = ') 331 if not t and ptr=='' then output('*') end 332 output('((',type) 333 if not t then 334 output('*') 335 end 336 output(') ') 337 local def = 0 338 if self.def ~= '' then def = self.def end 339 if t then 340 output('tolua_tofield'..t..'(tolua_S,',narg,',i+1,',def,'));') 341 else 342 output('tolua_tofieldusertype(tolua_S,',narg,',i+1,',def,'));') 343 end 344 output(' }') 345 output(' }') 346 end 347 347 end 348 348 349 349 -- Get parameter value 350 350 function classDeclaration:setarray (narg) 351 if not strfind(self.type,'const%s+') and self.dim ~= '' then352 353 output(' {')354 output(' int i;')355 output(' for(i=0; i<'..self.dim..';i++)')356 local t,ct = isbasic(type)357 if t then358 output(' tolua_pushfield'..t..'(tolua_S,',narg,',i+1,(',ct,')',self.name,'[i]);')359 else360 if self.ptr == '' then361 output(' {')362 output('#ifdef __cplusplus\n')363 output(' void* tolua_obj = new',type,'(',self.name,'[i]);')364 output(' tolua_pushfieldusertype_and_takeownership(tolua_S,',narg,',i+1,tolua_obj,"',type,'");')365 output('#else\n')366 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&',self.name,'[i],sizeof(',type,'));')367 output(' tolua_pushfieldusertype(tolua_S,',narg,',i+1,tolua_obj,"',type,'");')368 output('#endif\n')369 output(' }')370 else371 output(' tolua_pushfieldusertype(tolua_S,',narg,',i+1,(void*)',self.name,'[i],"',type,'");')372 end373 end374 output(' }')375 end351 if not strfind(self.type,'const%s+') and self.dim ~= '' then 352 local type = gsub(self.type,'const ','') 353 output(' {') 354 output(' int i;') 355 output(' for(i=0; i<'..self.dim..';i++)') 356 local t,ct = isbasic(type) 357 if t then 358 output(' tolua_pushfield'..t..'(tolua_S,',narg,',i+1,(',ct,')',self.name,'[i]);') 359 else 360 if self.ptr == '' then 361 output(' {') 362 output('#ifdef __cplusplus\n') 363 output(' void* tolua_obj = new',type,'(',self.name,'[i]);') 364 output(' tolua_pushfieldusertype_and_takeownership(tolua_S,',narg,',i+1,tolua_obj,"',type,'");') 365 output('#else\n') 366 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&',self.name,'[i],sizeof(',type,'));') 367 output(' tolua_pushfieldusertype(tolua_S,',narg,',i+1,tolua_obj,"',type,'");') 368 output('#endif\n') 369 output(' }') 370 else 371 output(' tolua_pushfieldusertype(tolua_S,',narg,',i+1,(void*)',self.name,'[i],"',type,'");') 372 end 373 end 374 output(' }') 375 end 376 376 end 377 377 378 378 -- Free dynamically allocated array 379 379 function classDeclaration:freearray () 380 if self.dim ~= '' and tonumber(self.dim)==nil then381 382 383 384 output(' free(',self.name,');')385 386 end380 if self.dim ~= '' and tonumber(self.dim)==nil then 381 output('#ifdef __cplusplus\n') 382 output(' delete []',self.name,';') 383 output('#else\n') 384 output(' free(',self.name,');') 385 output('#endif\n') 386 end 387 387 end 388 388 389 389 -- Pass parameter 390 390 function classDeclaration:passpar () 391 if self.ptr=='&' and not isbasic(self.type) then392 output('*'..self.name)393 elseif self.ret=='*' then394 output('&'..self.name)395 else396 output(self.name)397 end391 if self.ptr=='&' and not isbasic(self.type) then 392 output('*'..self.name) 393 elseif self.ret=='*' then 394 output('&'..self.name) 395 else 396 output(self.name) 397 end 398 398 end 399 399 400 400 -- Return parameter value 401 401 function classDeclaration:retvalue () 402 if self.ret ~= '' then403 local t,ct = isbasic(self.type)404 if t and t~='' then405 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self.name..');')406 else407 output(' tolua_pushusertype(tolua_S,(void*)'..self.name..',"',self.type,'");')408 end409 return 1410 end411 return 0402 if self.ret ~= '' then 403 local t,ct = isbasic(self.type) 404 if t and t~='' then 405 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self.name..');') 406 else 407 output(' tolua_pushusertype(tolua_S,(void*)'..self.name..',"',self.type,'");') 408 end 409 return 1 410 end 411 return 0 412 412 end 413 413 … … 415 415 function _Declaration (t) 416 416 417 setmetatable(t,classDeclaration)418 t:buildnames()419 t:checkname()420 t:checktype()421 local ft = findtype(t.type) or t.type422 if not isenum(ft) then423 424 end425 426 if t.kind=="var" and (string.find(t.mod, "tolua_property%s") or string.find(t.mod, "tolua_property$")) then427 428 end429 430 return t417 setmetatable(t,classDeclaration) 418 t:buildnames() 419 t:checkname() 420 t:checktype() 421 local ft = findtype(t.type) or t.type 422 if not isenum(ft) then 423 t.mod, t.type = applytypedef(t.mod, ft) 424 end 425 426 if t.kind=="var" and (string.find(t.mod, "tolua_property%s") or string.find(t.mod, "tolua_property$")) then 427 t.mod = string.gsub(t.mod, "tolua_property", "tolua_property__"..get_property_type()) 428 end 429 430 return t 431 431 end 432 432 … … 436 436 function Declaration (s,kind,is_parameter) 437 437 438 -- eliminate spaces if default value is provided439 s = gsub(s,"%s*=%s*","=")440 s = gsub(s, "%s*<", "<")441 442 local defb,tmpdef443 defb,_,tmpdef = string.find(s, "(=.*)$")444 if defb then445 446 else447 448 end449 if kind == "var" then450 -- check the form: void451 if s == '' or s == 'void' then452 return _Declaration{type = 'void', kind = kind, is_parameter = is_parameter}453 end454 end455 456 -- check the form: mod type*& name457 local t = split_c_tokens(s,'%*%s*&')458 if t.n == 2 then459 if kind == 'func' then460 error("#invalid function return type: "..s)461 end462 --local m = split(t[1],'%s%s*')463 local m = split_c_tokens(t[1],'%s+')464 return _Declaration{465 name = t[2]..tmpdef,466 ptr = '*',467 ret = '&',468 --type = rebuild_template(m[m.n], tb, timpl),469 type = m[m.n],470 mod = concat(m,1,m.n-1),471 is_parameter = is_parameter,472 kind = kind473 }474 end475 476 -- check the form: mod type** name477 t = split_c_tokens(s,'%*%s*%*')478 if t.n == 2 then479 if kind == 'func' then480 error("#invalid function return type: "..s)481 end482 --local m = split(t[1],'%s%s*')483 local m = split_c_tokens(t[1],'%s+')484 return _Declaration{485 name = t[2]..tmpdef,486 ptr = '*',487 ret = '*',488 --type = rebuild_template(m[m.n], tb, timpl),489 type = m[m.n],490 mod = concat(m,1,m.n-1),491 is_parameter = is_parameter,492 kind = kind493 }494 end495 496 -- check the form: mod type& name497 t = split_c_tokens(s,'&')498 if t.n == 2 then499 --local m = split(t[1],'%s%s*')500 local m = split_c_tokens(t[1],'%s+')501 return _Declaration{502 name = t[2]..tmpdef,503 ptr = '&',504 --type = rebuild_template(m[m.n], tb, timpl),505 type = m[m.n],506 mod = concat(m,1,m.n-1),507 is_parameter = is_parameter,508 kind = kind509 }510 end511 512 -- check the form: mod type* name513 local s1 = gsub(s,"(%b\[\])",function (n) return gsub(n,'%*','\1') end)514 t = split_c_tokens(s1,'%*')515 if t.n == 2 then516 t[2] = gsub(t[2],'\1','%*') -- restore * in dimension expression517 --local m = split(t[1],'%s%s*')518 local m = split_c_tokens(t[1],'%s+')519 return _Declaration{520 name = t[2]..tmpdef,521 ptr = '*',522 type = m[m.n],523 --type = rebuild_template(m[m.n], tb, timpl),524 mod = concat(m,1,m.n-1) ,525 is_parameter = is_parameter,526 kind = kind527 }528 end529 530 if kind == 'var' then531 -- check the form: mod type name532 --t = split(s,'%s%s*')533 t = split_c_tokens(s,'%s+')534 local v535 if findtype(t[t.n]) then v = create_varname() else v = t[t.n]; t.n = t.n-1 end536 return _Declaration{537 name = v..tmpdef,538 --type = rebuild_template(t[t.n], tb, timpl),539 type = t[t.n],540 mod = concat(t,1,t.n-1),541 is_parameter = is_parameter,542 kind = kind543 }544 545 else -- kind == "func"546 547 -- check the form: mod type name548 --t = split(s,'%s%s*')549 t = split_c_tokens(s,'%s+')550 local v = t[t.n] -- last word is the function name551 local tp,md552 if t.n>1 then553 tp = t[t.n-1]554 md = concat(t,1,t.n-2)555 end556 --if tp then tp = rebuild_template(tp, tb, timpl) end557 return _Declaration{558 name = v,559 type = tp,560 mod = md,561 is_parameter = is_parameter,562 kind = kind563 }564 end565 566 end 567 438 -- eliminate spaces if default value is provided 439 s = gsub(s,"%s*=%s*","=") 440 s = gsub(s, "%s*<", "<") 441 442 local defb,tmpdef 443 defb,_,tmpdef = string.find(s, "(=.*)$") 444 if defb then 445 s = string.gsub(s, "=.*$", "") 446 else 447 tmpdef = '' 448 end 449 if kind == "var" then 450 -- check the form: void 451 if s == '' or s == 'void' then 452 return _Declaration{type = 'void', kind = kind, is_parameter = is_parameter} 453 end 454 end 455 456 -- check the form: mod type*& name 457 local t = split_c_tokens(s,'%*%s*&') 458 if t.n == 2 then 459 if kind == 'func' then 460 error("#invalid function return type: "..s) 461 end 462 --local m = split(t[1],'%s%s*') 463 local m = split_c_tokens(t[1],'%s+') 464 return _Declaration { 465 name = t[2]..tmpdef, 466 ptr = '*', 467 ret = '&', 468 --type = rebuild_template(m[m.n], tb, timpl), 469 type = m[m.n], 470 mod = concat(m,1,m.n-1), 471 is_parameter = is_parameter, 472 kind = kind 473 } 474 end 475 476 -- check the form: mod type** name 477 t = split_c_tokens(s,'%*%s*%*') 478 if t.n == 2 then 479 if kind == 'func' then 480 error("#invalid function return type: "..s) 481 end 482 --local m = split(t[1],'%s%s*') 483 local m = split_c_tokens(t[1],'%s+') 484 return _Declaration { 485 name = t[2]..tmpdef, 486 ptr = '*', 487 ret = '*', 488 --type = rebuild_template(m[m.n], tb, timpl), 489 type = m[m.n], 490 mod = concat(m,1,m.n-1), 491 is_parameter = is_parameter, 492 kind = kind 493 } 494 end 495 496 -- check the form: mod type& name 497 t = split_c_tokens(s,'&') 498 if t.n == 2 then 499 --local m = split(t[1],'%s%s*') 500 local m = split_c_tokens(t[1],'%s+') 501 return _Declaration { 502 name = t[2]..tmpdef, 503 ptr = '&', 504 --type = rebuild_template(m[m.n], tb, timpl), 505 type = m[m.n], 506 mod = concat(m,1,m.n-1), 507 is_parameter = is_parameter, 508 kind = kind 509 } 510 end 511 512 -- check the form: mod type* name 513 local s1 = gsub(s,"(%b\[\])",function (n) return gsub(n,'%*','\1') end) 514 t = split_c_tokens(s1,'%*') 515 if t.n == 2 then 516 t[2] = gsub(t[2],'\1','%*') -- restore * in dimension expression 517 --local m = split(t[1],'%s%s*') 518 local m = split_c_tokens(t[1],'%s+') 519 return _Declaration { 520 name = t[2]..tmpdef, 521 ptr = '*', 522 type = m[m.n], 523 --type = rebuild_template(m[m.n], tb, timpl), 524 mod = concat(m,1,m.n-1) , 525 is_parameter = is_parameter, 526 kind = kind 527 } 528 end 529 530 if kind == 'var' then 531 -- check the form: mod type name 532 --t = split(s,'%s%s*') 533 t = split_c_tokens(s,'%s+') 534 local v 535 if findtype(t[t.n]) then v = create_varname() else v = t[t.n]; t.n = t.n-1 end 536 return _Declaration { 537 name = v..tmpdef, 538 --type = rebuild_template(t[t.n], tb, timpl), 539 type = t[t.n], 540 mod = concat(t,1,t.n-1), 541 is_parameter = is_parameter, 542 kind = kind 543 } 544 545 else -- kind == "func" 546 547 -- check the form: mod type name 548 --t = split(s,'%s%s*') 549 t = split_c_tokens(s,'%s+') 550 local v = t[t.n] -- last word is the function name 551 local tp,md 552 if t.n>1 then 553 tp = t[t.n-1] 554 md = concat(t,1,t.n-2) 555 end 556 --if tp then tp = rebuild_template(tp, tb, timpl) end 557 return _Declaration { 558 name = v, 559 type = tp, 560 mod = md, 561 is_parameter = is_parameter, 562 kind = kind 563 } 564 end 565 566 end 567 -
code/trunk/src/tolua/lua/define.lua
r2087 r2710 16 16 -- name = constant name 17 17 classDefine = { 18 name = '',18 name = '', 19 19 } 20 20 classDefine.__index = classDefine … … 23 23 -- register define 24 24 function classDefine:register (pre) 25 26 27 25 if not self:check_public_access() then 26 return 27 end 28 28 29 pre = pre or ''30 output(pre..'tolua_constant(tolua_S,"'..self.lname..'",'..self.name..');')29 pre = pre or '' 30 output(pre..'tolua_constant(tolua_S,"'..self.lname..'",'..self.name..');') 31 31 end 32 32 33 33 -- Print method 34 34 function classDefine:print (ident,close) 35 print(ident.."Define{")36 print(ident.." name = '"..self.name.."',")37 print(ident.." lname = '"..self.lname.."',")38 print(ident.."}"..close)35 print(ident.."Define{") 36 print(ident.." name = '"..self.name.."',") 37 print(ident.." lname = '"..self.lname.."',") 38 print(ident.."}"..close) 39 39 end 40 40 … … 42 42 -- Internal constructor 43 43 function _Define (t) 44 setmetatable(t,classDefine)45 t:buildnames()44 setmetatable(t,classDefine) 45 t:buildnames() 46 46 47 if t.name == '' then48 error("#invalid define")49 end47 if t.name == '' then 48 error("#invalid define") 49 end 50 50 51 append(t)52 return t51 append(t) 52 return t 53 53 end 54 54 … … 56 56 -- Expects a string representing the constant name 57 57 function Define (n) 58 return _Define{59 name = n60 }58 return _Define { 59 name = n 60 } 61 61 end 62 62 -
code/trunk/src/tolua/lua/doit.lua
r2087 r2710 14 14 function parse_extra() 15 15 16 17 18 19 20 21 22 23 24 16 for k,v in ipairs(_extra_parameters or {}) do 17 18 local b,e,name,value = string.find(v, "^([^=])=(.*)$") 19 if b then 20 _extra_parameters[name] = value 21 else 22 _extra_parameters[v] = true 23 end 24 end 25 25 end 26 26 27 27 function doit () 28 29 30 31 32 33 34 35 36 28 -- define package name, if not provided 29 if not flags.n then 30 if flags.f then 31 flags.n = gsub(flags.f,"%..*$","") 32 _,_,flags.n = string.find(flags.n, "([^/\\]*)$") 33 else 34 error("#no package name nor input file provided") 35 end 36 end 37 37 38 39 38 -- parse table with extra paramters 39 parse_extra() 40 40 41 -- do this after setting the package name 42 if flags['L']then43 dofile(flags['L']) 44 41 -- get potential working directory 42 if not flags.w then 43 flags.w = '' 44 end 45 45 46 -- add cppstring 47 if not flags['S'] then 48 _basic['string'] = 'cppstring' 49 _basic['std::string'] = 'cppstring' 50 _basic_ctype.cppstring = 'const char*' 51 end 46 -- do this after setting the package name 47 if flags.L then 48 if string.sub(flags.L, 1, 1) == '/' or string.sub(flags.L, 1, 1) == '\\' or (string.len(flags.L) > 1 and string.sub(flags.L, 2, 2) == ':') then 49 dofile(flags.L) 50 else 51 dofile(flags.w..'/'..flags.L) 52 end 53 end 52 54 53 -- proccess package 54 local p = Package(flags.n,flags.f) 55 -- add cppstring 56 if not flags.S then 57 _basic['string'] = 'cppstring' 58 _basic['std::string'] = 'cppstring' 59 _basic_ctype.cppstring = 'const char*' 60 end 55 61 56 if flags.p then 57 return -- only parse 58 end 62 -- proccess package 63 local file 64 if flags.f then 65 if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then 66 file = flags.f 67 else 68 file = flags.w..'/'..flags.f 69 end 70 else 71 file = flags.f 72 end 73 local p = Package(flags.n, file) 59 74 60 if flags.o then 61 local st,msg = writeto(flags.o) 62 if not st then 63 error('#'..msg) 64 end 65 end 75 if flags.p then 76 return -- only parse 77 end 66 78 67 p:decltype() 68 if flags.P then 69 p:print() 70 else 71 p:preamble() 72 p:supcode() 73 p:register() 74 push(p) 75 post_output_hook(p) 76 pop() 77 end 79 if flags.o then 80 local file 81 if string.sub(flags.o, 1, 1) == '/' or string.sub(flags.o, 1, 1) == '\\' or (string.len(flags.o) > 1 and string.sub(flags.o, 2, 2) == ':') then 82 file = flags.o 83 else 84 file = flags.w..'/'..flags.o 85 end 86 local st,msg = writeto(file) 87 if not st then 88 error('#'..msg) 89 end 90 end 78 91 79 if flags.o then 80 writeto() 81 end 92 p:decltype() 93 if flags.P then 94 p:print() 95 else 96 p:preamble() 97 p:supcode() 98 p:register() 99 push(p) 100 post_output_hook(p) 101 pop() 102 end 82 103 83 -- write header file 84 if not flags.P then 85 if flags.H then 86 local st,msg = writeto(flags.H) 87 if not st then 88 error('#'..msg) 89 end 90 p:header() 91 writeto() 92 end 93 end 104 if flags.o then 105 writeto() 106 end 107 108 -- write header file 109 if not flags.P then 110 if flags.H then 111 local file 112 if string.sub(flags.H, 1, 1) == '/' or string.sub(flags.H, 1, 1) == '\\' or (string.len(flags.H) > 1 and string.sub(flags.H, 2, 2) == ':') then 113 file = flags.H 114 else 115 file = flags.w..'/'..flags.H 116 end 117 local st,msg = writeto(file) 118 if not st then 119 error('#'..msg) 120 end 121 p:header() 122 writeto() 123 end 124 end 94 125 end 95 126 -
code/trunk/src/tolua/lua/enumerate.lua
r2087 r2710 22 22 -- register enumeration 23 23 function classEnumerate:register (pre) 24 pre = pre or ''25 local nspace = getnamespace(classContainer.curr)26 local i=127 while self[i] do28 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');')29 i = i+130 end24 pre = pre or '' 25 local nspace = getnamespace(classContainer.curr) 26 local i=1 27 while self[i] do 28 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');') 29 i = i+1 30 end 31 31 end 32 32 33 33 -- Print method 34 34 function classEnumerate:print (ident,close) 35 print(ident.."Enumerate{")36 print(ident.." name = "..self.name)37 local i=138 while self[i] do39 print(ident.." '"..self[i].."'("..self.lnames[i].."),")40 i = i+141 end42 print(ident.."}"..close)35 print(ident.."Enumerate{") 36 print(ident.." name = "..self.name) 37 local i=1 38 while self[i] do 39 print(ident.." '"..self[i].."'("..self.lnames[i].."),") 40 i = i+1 41 end 42 print(ident.."}"..close) 43 43 end 44 44 45 45 -- Internal constructor 46 46 function _Enumerate (t,varname) 47 setmetatable(t,classEnumerate)48 append(t)49 appendenum(t)50 51 52 53 54 55 56 57 58 59 return t47 setmetatable(t,classEnumerate) 48 append(t) 49 appendenum(t) 50 if varname and varname ~= "" then 51 if t.name ~= "" then 52 Variable(t.name.." "..varname) 53 else 54 local ns = getcurrnamespace() 55 warning("Variable "..ns..varname.." of type <anonymous enum> is declared as read-only") 56 Variable("tolua_readonly int "..varname) 57 end 58 end 59 return t 60 60 end 61 61 … … 63 63 -- Expects a string representing the enumerate body 64 64 function Enumerate (n,b,varname) 65 66 local t = split(strsub(b,2,-2),',') -- eliminate braces67 local i = 168 local e = {n=0}69 while t[i] do70 local tt = split(t[i],'=') -- discard initial value71 e.n = e.n + 172 e[e.n] = tt[1]73 i = i+174 end75 -- set lua names76 i = 177 e.lnames = {}78 local ns = getcurrnamespace()79 while e[i] do80 local t = split(e[i],'@')81 e[i] = t[1]82 83 84 85 e.lnames[i] = t[2] or t[1]86 _global_enums[ ns..e[i] ] = (ns..e[i])87 i = i+188 end89 90 91 92 93 return _Enumerate(e, varname)65 b = string.gsub(b, ",[%s\n]*}", "\n}") -- eliminate last ',' 66 local t = split(strsub(b,2,-2),',') -- eliminate braces 67 local i = 1 68 local e = {n=0} 69 while t[i] do 70 local tt = split(t[i],'=') -- discard initial value 71 e.n = e.n + 1 72 e[e.n] = tt[1] 73 i = i+1 74 end 75 -- set lua names 76 i = 1 77 e.lnames = {} 78 local ns = getcurrnamespace() 79 while e[i] do 80 local t = split(e[i],'@') 81 e[i] = t[1] 82 if not t[2] then 83 t[2] = applyrenaming(t[1]) 84 end 85 e.lnames[i] = t[2] or t[1] 86 _global_enums[ ns..e[i] ] = (ns..e[i]) 87 i = i+1 88 end 89 e.name = n 90 if n ~= "" then 91 Typedef("int "..n) 92 end 93 return _Enumerate(e, varname) 94 94 end 95 95 -
code/trunk/src/tolua/lua/feature.lua
r2087 r2710 40 40 -- check if it requires collection 41 41 function classFeature:requirecollection (t) 42 return false42 return false 43 43 end 44 44 45 45 -- build names 46 46 function classFeature:buildnames () 47 if self.name and self.name~='' then48 local n = split(self.name,'@')49 self.name = n[1]50 if not n[2] then51 n[2] = applyrenaming(n[1])52 end53 self.lname = n[2] or gsub(n[1],"%[.-%]","")54 self.original_name = self.name55 self.lname = clean_template(self.lname)56 end57 if not self.is_parameter then58 59 end47 if self.name and self.name~='' then 48 local n = split(self.name,'@') 49 self.name = n[1] 50 if not n[2] then 51 n[2] = applyrenaming(n[1]) 52 end 53 self.lname = n[2] or gsub(n[1],"%[.-%]","") 54 self.original_name = self.name 55 self.lname = clean_template(self.lname) 56 end 57 if not self.is_parameter then 58 self.name = getonlynamespace() .. self.name 59 end 60 60 61 local parent = classContainer.curr62 if parent then63 64 else65 end61 local parent = classContainer.curr 62 if parent then 63 self.access = parent.curr_member_access 64 else 65 end 66 66 end 67 67 68 68 function classFeature:check_public_access() 69 69 70 71 72 70 if self.access and self.access ~= 0 then 71 return false 72 end 73 73 74 75 76 77 78 79 80 81 74 local parent = classContainer.curr 75 while parent do 76 if parent.access and parent.access ~= 0 then 77 return false 78 end 79 parent = parent.prox 80 end 81 return true 82 82 end 83 83 84 84 function clean_template(t) 85 85 86 86 return string.gsub(t, "[<>:, %*]", "_") 87 87 end 88 88 … … 90 90 -- it returns the container class name or nil. 91 91 function classFeature:incontainer (which) 92 if self.parent then93 local parent = self.parent94 while parent do95 if parent.classtype == which then96 return parent.name97 end98 parent = parent.parent99 end100 end101 return nil92 if self.parent then 93 local parent = self.parent 94 while parent do 95 if parent.classtype == which then 96 return parent.name 97 end 98 parent = parent.parent 99 end 100 end 101 return nil 102 102 end 103 103 104 104 function classFeature:inclass () 105 return self:incontainer('class')105 return self:incontainer('class') 106 106 end 107 107 108 108 function classFeature:inmodule () 109 return self:incontainer('module')109 return self:incontainer('module') 110 110 end 111 111 112 112 function classFeature:innamespace () 113 return self:incontainer('namespace')113 return self:incontainer('namespace') 114 114 end 115 115 … … 118 118 function classFeature:cfuncname (n) 119 119 120 if self.parent then121 n = self.parent:cfuncname(n)122 end120 if self.parent then 121 n = self.parent:cfuncname(n) 122 end 123 123 124 n = string.gsub(n..'_'.. (self.lname or self.name), "[<>:, \.%*&]", "_")124 n = string.gsub(n..'_'.. (self.lname or self.name), "[<>:, \.%*&]", "_") 125 125 126 return n126 return n 127 127 end 128 128 -
code/trunk/src/tolua/lua/function.lua
r2087 r2710 52 52 if e.ret == "nil" then 53 53 output("catch(",nameToEcho," CEGUIDeadException(",exceptionDefs[e.name].var,"))\n{\n") 54 55 56 54 else 55 output("catch(",nameToEcho,exceptionDefs[e.name].var,")\n{\n") 56 end 57 57 58 58 -- if just a nil … … 141 141 -- const = if it is a method receiving a const "this". 142 142 classFunction = { 143 mod = '',144 type = '',145 ptr = '',146 name = '',147 args = {n=0},148 const = '',143 mod = '', 144 type = '', 145 ptr = '', 146 name = '', 147 args = {n=0}, 148 const = '', 149 149 } 150 150 classFunction.__index = classFunction … … 153 153 -- declare tags 154 154 function classFunction:decltype () 155 self.type = typevar(self.type)156 if strfind(self.mod,'const') then157 158 159 160 local i=1161 while self.args[i] do162 self.args[i]:decltype()163 i = i+1164 end155 self.type = typevar(self.type) 156 if strfind(self.mod,'const') then 157 self.type = 'const '..self.type 158 self.mod = gsub(self.mod,'const','') 159 end 160 local i=1 161 while self.args[i] do 162 self.args[i]:decltype() 163 i = i+1 164 end 165 165 end 166 166 … … 170 170 function classFunction:supcode (local_constructor) 171 171 172 local overload = strsub(self.cname,-2,-1) - 1 -- indicate overloaded func173 local nret = 0 -- number of returned values174 local class = self:inclass()175 local _,_,static = strfind(self.mod,'^%s*(static)')176 if class then177 178 179 180 181 182 183 184 185 186 187 188 else189 output("/* function:",self.name," */")190 end191 192 if local_constructor then193 output("#ifndef TOLUA_DISABLE_"..self.cname.."_local")194 output("\nstatic int",self.cname.."_local","(lua_State* tolua_S)")195 else196 output("#ifndef TOLUA_DISABLE_"..self.cname)197 output("\nstatic int",self.cname,"(lua_State* tolua_S)")198 end199 output("{")200 201 -- check types202 203 204 205 206 output(' if (\n')207 -- check self208 local narg209 if class then narg=2 else narg=1 end210 if class then211 212 213 214 215 216 217 218 219 220 221 end222 -- check args223 if self.args[1].type ~= 'void' then224 local i=1225 while self.args[i] do226 local btype = isbasic(self.args[i].type)227 if btype ~= 'value' and btype ~= 'state' then228 output(' !'..self.args[i]:outchecktype(narg)..' ||\n')229 end230 if btype ~= 'state' then231 232 end233 i = i+1234 end235 end236 -- check end of list237 output(' !tolua_isnoobj(tolua_S,'..narg..',&tolua_err)\n )')238 239 240 output(' else\n')241 242 243 244 245 246 -- declare self, if the case247 local narg248 if class then narg=2 else narg=1 end249 if class and self.name~='new' and static==nil then250 output(' ',self.const,self.parent.type,'*','self = ')251 output('(',self.const,self.parent.type,'*) ')252 output('tolua_tousertype(tolua_S,1,0);')253 elseif static then254 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')255 end256 -- declare parameters257 if self.args[1].type ~= 'void' then258 local i=1259 while self.args[i] do260 self.args[i]:declare(narg)261 if isbasic(self.args[i].type) ~= "state" then262 263 end264 i = i+1265 end266 end267 268 -- check self269 if class and self.name~='new' and static==nil then270 271 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);');272 273 end274 275 -- get array element values276 if class then narg=2 else narg=1 end277 if self.args[1].type ~= 'void' then278 local i=1279 while self.args[i] do280 self.args[i]:getarray(narg)281 narg = narg+1282 i = i+1283 end284 end285 286 --------------------------------------------------287 -- CEGUILua mod288 -- init exception handling289 local throws = false290 do291 local pattern = "tolua_throws|.*|"292 local i,j = string.find(self.mod, pattern)293 if i then294 throws = {}295 -- ensure table is empty. Used to be: table.setn(throws,0)296 for x in pairs(throws) do297 throws[x] = nil298 end299 local excepts = string.sub(self.mod, i+12,j)300 local epattern = "|.-|"301 local i,j = string.find(excepts, epattern)302 while i do303 local e = string.sub(excepts,i+1,j-1)304 local _,_,name,rest = string.find(e, "([%w:_]+),?(.*)")305 table.insert(throws,{name=name, ret=rest})306 i,j = string.find(excepts, epattern, j)307 end308 self.mod = string.gsub(self.mod, pattern, "")309 end310 end311 local exRaiseError = false312 --------------------------------------------------313 314 local out = string.find(self.mod, "tolua_outside")315 316 ---------------317 -- CEGUILua mod318 -- remove "tolua_outside" from self.mod319 if out then320 self.mod = string.gsub(self.mod, "tolua_outside", "")321 end322 323 -- call function324 if class and self.name=='delete' then325 output(' delete self;')326 elseif class and self.name == 'operator&[]' then327 if flags['1'] then -- for compatibility with tolua5 ?328 329 else330 output(' self->operator[](',self.args[1].name,') = ',self.args[2].name,';')331 end332 else333 -- CEGUILua mod begin- throws334 if throws then335 for i=1,table.getn(throws) do336 if string.find(throws[i].ret, "error") then337 output("char errorBuffer["..exceptionMessageBufferSize.."];\n")338 output("bool errorDoIt = false;\n")339 exRaiseError = true340 break341 end342 end343 output("try\n")344 end345 -- CEGUILua mod end - throws346 output(' {')347 if self.type ~= '' and self.type ~= 'void' then348 output(' ',self.mod,self.type,self.ptr,'tolua_ret = ')349 output('(',self.mod,self.type,self.ptr,') ')350 else351 output(' ')352 end353 if class and self.name=='new' then354 output('new',self.type,'(')355 elseif class and static then356 357 358 359 360 361 elseif class then362 363 364 365 366 367 368 369 370 371 else372 output(self.name,'(')373 end374 375 if out and not static then376 377 378 379 380 end381 -- write parameters382 local i=1383 while self.args[i] do384 self.args[i]:passpar()385 i = i+1386 if self.args[i] then387 output(',')388 end389 end390 391 if class and self.name == 'operator[]' and flags['1'] then392 393 else394 395 end396 397 -- return values398 if self.type ~= '' and self.type ~= 'void' then399 nret = nret + 1400 local t,ct = isbasic(self.type)401 if t then402 403 404 405 406 407 else408 409 410 if self.ptr == '' then411 output(' {')412 output('#ifdef __cplusplus\n')413 output(' void* tolua_obj = new',new_t,'(tolua_ret);')414 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");')415 output('#else\n')416 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));')417 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");')418 output('#endif\n')419 output(' }')420 elseif self.ptr == '&' then421 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')422 else423 424 425 426 427 428 end429 end430 end431 local i=1432 while self.args[i] do433 nret = nret + self.args[i]:retvalue()434 i = i+1435 end436 output(' }')437 438 ------------------------------------------439 -- CEGUILua mod440 -- finish exception handling441 -- catch442 if throws then443 outputExceptionCatchBlocks(self.name, throws, exRaiseError)444 end445 ------------------------------------------446 447 -- set array element values448 if class then narg=2 else narg=1 end449 if self.args[1].type ~= 'void' then450 local i=1451 while self.args[i] do452 self.args[i]:setarray(narg)453 narg = narg+1454 i = i+1455 end456 end457 458 -- free dynamically allocated array459 if self.args[1].type ~= 'void' then460 local i=1461 while self.args[i] do462 self.args[i]:freearray()463 i = i+1464 end465 end466 end467 468 output(' }')469 output(' return '..nret..';')470 471 -- call overloaded function or generate error472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 output('}')488 output('#endif //#ifndef TOLUA_DISABLE\n')489 output('\n')490 491 492 493 494 495 172 local overload = strsub(self.cname,-2,-1) - 1 -- indicate overloaded func 173 local nret = 0 -- number of returned values 174 local class = self:inclass() 175 local _,_,static = strfind(self.mod,'^%s*(static)') 176 if class then 177 178 if self.name == 'new' and self.parent.flags.pure_virtual then 179 -- no constructor for classes with pure virtual methods 180 return 181 end 182 183 if local_constructor then 184 output("/* method: new_local of class ",class," */") 185 else 186 output("/* method:",self.name," of class ",class," */") 187 end 188 else 189 output("/* function:",self.name," */") 190 end 191 192 if local_constructor then 193 output("#ifndef TOLUA_DISABLE_"..self.cname.."_local") 194 output("\nstatic int",self.cname.."_local","(lua_State* tolua_S)") 195 else 196 output("#ifndef TOLUA_DISABLE_"..self.cname) 197 output("\nstatic int",self.cname,"(lua_State* tolua_S)") 198 end 199 output("{") 200 201 -- check types 202 if overload < 0 then 203 output('#ifndef TOLUA_RELEASE\n') 204 end 205 output(' tolua_Error tolua_err;') 206 output(' if (\n') 207 -- check self 208 local narg 209 if class then narg=2 else narg=1 end 210 if class then 211 local func = 'tolua_isusertype' 212 local type = self.parent.type 213 if self.name=='new' or static~=nil then 214 func = 'tolua_isusertable' 215 type = self.parent.type 216 end 217 if self.const ~= '' then 218 type = "const "..type 219 end 220 output(' !'..func..'(tolua_S,1,"'..type..'",0,&tolua_err) ||\n') 221 end 222 -- check args 223 if self.args[1].type ~= 'void' then 224 local i=1 225 while self.args[i] do 226 local btype = isbasic(self.args[i].type) 227 if btype ~= 'value' and btype ~= 'state' then 228 output(' !'..self.args[i]:outchecktype(narg)..' ||\n') 229 end 230 if btype ~= 'state' then 231 narg = narg+1 232 end 233 i = i+1 234 end 235 end 236 -- check end of list 237 output(' !tolua_isnoobj(tolua_S,'..narg..',&tolua_err)\n )') 238 output(' goto tolua_lerror;') 239 240 output(' else\n') 241 if overload < 0 then 242 output('#endif\n') 243 end 244 output(' {') 245 246 -- declare self, if the case 247 local narg 248 if class then narg=2 else narg=1 end 249 if class and self.name~='new' and static==nil then 250 output(' ',self.const,self.parent.type,'*','self = ') 251 output('(',self.const,self.parent.type,'*) ') 252 output('tolua_tousertype(tolua_S,1,0);') 253 elseif static then 254 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 255 end 256 -- declare parameters 257 if self.args[1].type ~= 'void' then 258 local i=1 259 while self.args[i] do 260 self.args[i]:declare(narg) 261 if isbasic(self.args[i].type) ~= "state" then 262 narg = narg+1 263 end 264 i = i+1 265 end 266 end 267 268 -- check self 269 if class and self.name~='new' and static==nil then 270 output('#ifndef TOLUA_RELEASE\n') 271 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);'); 272 output('#endif\n') 273 end 274 275 -- get array element values 276 if class then narg=2 else narg=1 end 277 if self.args[1].type ~= 'void' then 278 local i=1 279 while self.args[i] do 280 self.args[i]:getarray(narg) 281 narg = narg+1 282 i = i+1 283 end 284 end 285 286 -------------------------------------------------- 287 -- CEGUILua mod 288 -- init exception handling 289 local throws = false 290 do 291 local pattern = "tolua_throws|.*|" 292 local i,j = string.find(self.mod, pattern) 293 if i then 294 throws = {} 295 -- ensure table is empty. Used to be: table.setn(throws,0) 296 for x in pairs(throws) do 297 throws[x] = nil 298 end 299 local excepts = string.sub(self.mod, i+12,j) 300 local epattern = "|.-|" 301 local i,j = string.find(excepts, epattern) 302 while i do 303 local e = string.sub(excepts,i+1,j-1) 304 local _,_,name,rest = string.find(e, "([%w:_]+),?(.*)") 305 table.insert(throws,{name=name, ret=rest}) 306 i,j = string.find(excepts, epattern, j) 307 end 308 self.mod = string.gsub(self.mod, pattern, "") 309 end 310 end 311 local exRaiseError = false 312 -------------------------------------------------- 313 314 local out = string.find(self.mod, "tolua_outside") 315 316 --------------- 317 -- CEGUILua mod 318 -- remove "tolua_outside" from self.mod 319 if out then 320 self.mod = string.gsub(self.mod, "tolua_outside", "") 321 end 322 323 -- call function 324 if class and self.name=='delete' then 325 output(' delete self;') 326 elseif class and self.name == 'operator&[]' then 327 if flags['1'] then -- for compatibility with tolua5 ? 328 output(' self->operator[](',self.args[1].name,'-1) = ',self.args[2].name,';') 329 else 330 output(' self->operator[](',self.args[1].name,') = ',self.args[2].name,';') 331 end 332 else 333 -- CEGUILua mod begin- throws 334 if throws then 335 for i=1,table.getn(throws) do 336 if string.find(throws[i].ret, "error") then 337 output("char errorBuffer["..exceptionMessageBufferSize.."];\n") 338 output("bool errorDoIt = false;\n") 339 exRaiseError = true 340 break 341 end 342 end 343 output("try\n") 344 end 345 -- CEGUILua mod end - throws 346 output(' {') 347 if self.type ~= '' and self.type ~= 'void' then 348 output(' ',self.mod,self.type,self.ptr,'tolua_ret = ') 349 output('(',self.mod,self.type,self.ptr,') ') 350 else 351 output(' ') 352 end 353 if class and self.name=='new' then 354 output('new',self.type,'(') 355 elseif class and static then 356 if out then 357 output(self.name,'(') 358 else 359 output(class..'::'..self.name,'(') 360 end 361 elseif class then 362 if out then 363 output(self.name,'(') 364 else 365 if self.cast_operator then 366 output('static_cast<',self.mod,self.type,self.ptr,'>(*self') 367 else 368 output('self->'..self.name,'(') 369 end 370 end 371 else 372 output(self.name,'(') 373 end 374 375 if out and not static then 376 output('self') 377 if self.args[1] and self.args[1].name ~= '' then 378 output(',') 379 end 380 end 381 -- write parameters 382 local i=1 383 while self.args[i] do 384 self.args[i]:passpar() 385 i = i+1 386 if self.args[i] then 387 output(',') 388 end 389 end 390 391 if class and self.name == 'operator[]' and flags['1'] then 392 output('-1);') 393 else 394 output(');') 395 end 396 397 -- return values 398 if self.type ~= '' and self.type ~= 'void' then 399 nret = nret + 1 400 local t,ct = isbasic(self.type) 401 if t then 402 if self.cast_operator and _basic_raw_push[t] then 403 output(' ',_basic_raw_push[t],'(tolua_S,(',ct,')tolua_ret);') 404 else 405 output(' tolua_push'..t..'(tolua_S,(',ct,')tolua_ret);') 406 end 407 else 408 t = self.type 409 new_t = string.gsub(t, "const%s+", "") 410 if self.ptr == '' then 411 output(' {') 412 output('#ifdef __cplusplus\n') 413 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 414 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 415 output('#else\n') 416 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 417 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 418 output('#endif\n') 419 output(' }') 420 elseif self.ptr == '&' then 421 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");') 422 else 423 if local_constructor then 424 output(' tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");') 425 else 426 output(' tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");') 427 end 428 end 429 end 430 end 431 local i=1 432 while self.args[i] do 433 nret = nret + self.args[i]:retvalue() 434 i = i+1 435 end 436 output(' }') 437 438 ------------------------------------------ 439 -- CEGUILua mod 440 -- finish exception handling 441 -- catch 442 if throws then 443 outputExceptionCatchBlocks(self.name, throws, exRaiseError) 444 end 445 ------------------------------------------ 446 447 -- set array element values 448 if class then narg=2 else narg=1 end 449 if self.args[1].type ~= 'void' then 450 local i=1 451 while self.args[i] do 452 self.args[i]:setarray(narg) 453 narg = narg+1 454 i = i+1 455 end 456 end 457 458 -- free dynamically allocated array 459 if self.args[1].type ~= 'void' then 460 local i=1 461 while self.args[i] do 462 self.args[i]:freearray() 463 i = i+1 464 end 465 end 466 end 467 468 output(' }') 469 output(' return '..nret..';') 470 471 -- call overloaded function or generate error 472 if overload < 0 then 473 474 output('#ifndef TOLUA_RELEASE\n') 475 output('tolua_lerror:\n') 476 output(' tolua_error(tolua_S,"#ferror in function \''..self.lname..'\'.",&tolua_err);') 477 output(' return 0;') 478 output('#endif\n') 479 else 480 local _local = "" 481 if local_constructor then 482 _local = "_local" 483 end 484 output('tolua_lerror:\n') 485 output(' return '..strsub(self.cname,1,-3)..format("%02d",overload).._local..'(tolua_S);') 486 end 487 output('}') 488 output('#endif //#ifndef TOLUA_DISABLE\n') 489 output('\n') 490 491 -- recursive call to write local constructor 492 if class and self.name=='new' and not local_constructor then 493 494 self:supcode(1) 495 end 496 496 497 497 end … … 501 501 function classFunction:register (pre) 502 502 503 504 505 506 507 508 509 510 511 512 output(pre..'tolua_function(tolua_S,"'..self.lname..'",'..self.cname..');')513 if self.name == 'new' then514 515 516 517 end503 if not self:check_public_access() then 504 return 505 end 506 507 if self.name == 'new' and self.parent.flags.pure_virtual then 508 -- no constructor for classes with pure virtual methods 509 return 510 end 511 512 output(pre..'tolua_function(tolua_S,"'..self.lname..'",'..self.cname..');') 513 if self.name == 'new' then 514 output(pre..'tolua_function(tolua_S,"new_local",'..self.cname..'_local);') 515 output(pre..'tolua_function(tolua_S,".call",'..self.cname..'_local);') 516 --output(' tolua_set_call_event(tolua_S,'..self.cname..'_local, "'..self.parent.type..'");') 517 end 518 518 end 519 519 520 520 -- Print method 521 521 function classFunction:print (ident,close) 522 print(ident.."Function{")523 print(ident.." mod = '"..self.mod.."',")524 print(ident.." type = '"..self.type.."',")525 print(ident.." ptr = '"..self.ptr.."',")526 print(ident.." name = '"..self.name.."',")527 print(ident.." lname = '"..self.lname.."',")528 print(ident.." const = '"..self.const.."',")529 print(ident.." cname = '"..self.cname.."',")530 print(ident.." lname = '"..self.lname.."',")531 print(ident.." args = {")532 local i=1533 while self.args[i] do534 self.args[i]:print(ident.." ",",")535 i = i+1536 end537 print(ident.." }")538 print(ident.."}"..close)522 print(ident.."Function{") 523 print(ident.." mod = '"..self.mod.."',") 524 print(ident.." type = '"..self.type.."',") 525 print(ident.." ptr = '"..self.ptr.."',") 526 print(ident.." name = '"..self.name.."',") 527 print(ident.." lname = '"..self.lname.."',") 528 print(ident.." const = '"..self.const.."',") 529 print(ident.." cname = '"..self.cname.."',") 530 print(ident.." lname = '"..self.lname.."',") 531 print(ident.." args = {") 532 local i=1 533 while self.args[i] do 534 self.args[i]:print(ident.." ",",") 535 i = i+1 536 end 537 print(ident.." }") 538 print(ident.."}"..close) 539 539 end 540 540 541 541 -- check if it returns an object by value 542 542 function classFunction:requirecollection (t) 543 544 545 546 547 548 549 550 551 552 553 554 543 local r = false 544 if self.type ~= '' and not isbasic(self.type) and self.ptr=='' then 545 local type = gsub(self.type,"%s*const%s+","") 546 t[type] = "tolua_collect_" .. clean_template(type) 547 r = true 548 end 549 local i=1 550 while self.args[i] do 551 r = self.args[i]:requirecollection(t) or r 552 i = i+1 553 end 554 return r 555 555 end 556 556 557 557 -- determine lua function name overload 558 558 function classFunction:overload () 559 return self.parent:overload(self.lname)559 return self.parent:overload(self.lname) 560 560 end 561 561 … … 563 563 function param_object(par) -- returns true if the parameter has an object as its default value 564 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 --if string.find(def, ":") or string.find(def, "^%s*new%s+") then590 591 ---- it's a reference with default to something like Class::member, or 'new Class'592 --return true593 --end594 595 596 565 if not string.find(par, '=') then return false end -- it has no default value 566 567 local _,_,def = string.find(par, "=(.*)$") 568 569 if string.find(par, "|") then -- a list of flags 570 571 return true 572 end 573 574 if string.find(par, "%*") then -- it's a pointer with a default value 575 576 if string.find(par, '=%s*new') then -- it's a pointer with an instance as default parameter.. is that valid? 577 return true 578 end 579 return false -- default value is 'NULL' or something 580 end 581 582 583 if string.find(par, "[%(&]") then 584 return true 585 end -- default value is a constructor call (most likely for a const reference) 586 587 --if string.find(par, "&") then 588 589 -- if string.find(def, ":") or string.find(def, "^%s*new%s+") then 590 591 -- -- it's a reference with default to something like Class::member, or 'new Class' 592 -- return true 593 -- end 594 --end 595 596 return false -- ? 597 597 end 598 598 599 599 function strip_last_arg(all_args, last_arg) -- strips the default value from the last argument 600 600 601 602 603 604 601 local _,_,s_arg = string.find(last_arg, "^([^=]+)") 602 last_arg = string.gsub(last_arg, "([%%%(%)])", "%%%1"); 603 all_args = string.gsub(all_args, "%s*,%s*"..last_arg.."%s*%)%s*$", ")") 604 return all_args, s_arg 605 605 end 606 606 … … 609 609 -- Internal constructor 610 610 function _Function (t) 611 setmetatable(t,classFunction)612 613 if t.const ~= 'const' and t.const ~= '' then614 error("#invalid 'const' specification")615 end616 617 append(t)618 if t:inclass() then619 --print ('t.name is '..t.name..', parent.name is '..t.parent.name)620 if string.gsub(t.name, "%b<>", "") == string.gsub(t.parent.original_name or t.parent.name, "%b<>", "") then621 t.name = 'new'622 t.lname = 'new'623 t.parent._new = true624 t.type = t.parent.name625 t.ptr = '*'626 elseif string.gsub(t.name, "%b<>", "") == '~'..string.gsub(t.parent.original_name or t.parent.name, "%b<>", "") then627 t.name = 'delete'628 t.lname = 'delete'629 t.parent._delete = true630 end631 end632 t.cname = t:cfuncname("tolua")..t:overload(t)633 return t611 setmetatable(t,classFunction) 612 613 if t.const ~= 'const' and t.const ~= '' then 614 error("#invalid 'const' specification") 615 end 616 617 append(t) 618 if t:inclass() then 619 --print ('t.name is '..t.name..', parent.name is '..t.parent.name) 620 if string.gsub(t.name, "%b<>", "") == string.gsub(t.parent.original_name or t.parent.name, "%b<>", "") then 621 t.name = 'new' 622 t.lname = 'new' 623 t.parent._new = true 624 t.type = t.parent.name 625 t.ptr = '*' 626 elseif string.gsub(t.name, "%b<>", "") == '~'..string.gsub(t.parent.original_name or t.parent.name, "%b<>", "") then 627 t.name = 'delete' 628 t.lname = 'delete' 629 t.parent._delete = true 630 end 631 end 632 t.cname = t:cfuncname("tolua")..t:overload(t) 633 return t 634 634 end 635 635 … … 639 639 -- the "const" or empty string. 640 640 function Function (d,a,c) 641 --local t = split(strsub(a,2,-2),',') -- eliminate braces642 --local t = split_params(strsub(a,2,-2))643 644 645 646 647 648 649 650 651 local i=1652 local l = {n=0}653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 while t[i] do670 l.n = l.n+1671 l[l.n] = Declaration(t[i],'var',true)672 i = i+1673 end674 local f = Declaration(d,'func')675 f.args = l676 f.const = c677 return _Function(f)641 --local t = split(strsub(a,2,-2),',') -- eliminate braces 642 --local t = split_params(strsub(a,2,-2)) 643 644 if not flags['W'] and string.find(a, "%.%.%.%s*%)") then 645 646 warning("Functions with variable arguments (`...') are not supported. Ignoring "..d..a..c) 647 return nil 648 end 649 650 651 local i=1 652 local l = {n=0} 653 654 a = string.gsub(a, "%s*([%(%)])%s*", "%1") 655 local t,strip,last = strip_pars(strsub(a,2,-2)); 656 if strip then 657 --local ns = string.sub(strsub(a,1,-2), 1, -(string.len(last)+1)) 658 local ns = join(t, ",", 1, last-1) 659 660 ns = "("..string.gsub(ns, "%s*,%s*$", "")..')' 661 --ns = strip_defaults(ns) 662 663 Function(d, ns, c) 664 for i=1,last do 665 t[i] = string.gsub(t[i], "=.*$", "") 666 end 667 end 668 669 while t[i] do 670 l.n = l.n+1 671 l[l.n] = Declaration(t[i],'var',true) 672 i = i+1 673 end 674 local f = Declaration(d,'func') 675 f.args = l 676 f.const = c 677 return _Function(f) 678 678 end 679 679 680 680 function join(t, sep, first, last) 681 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 682 first = first or 1 683 last = last or table.getn(t) 684 local lsep = "" 685 local ret = "" 686 local loop = false 687 for i = first,last do 688 689 ret = ret..lsep..t[i] 690 lsep = sep 691 loop = true 692 end 693 if not loop then 694 return "" 695 end 696 697 return ret 698 698 end 699 699 700 700 function strip_pars(s) 701 701 702 703 704 705 706 707 708 709 710 711 712 713 --t[i] = string.gsub(t[i], "=.*$", "")714 715 716 717 702 local t = split_c_tokens(s, ',') 703 local strip = false 704 local last 705 706 for i=t.n,1,-1 do 707 708 if not strip and param_object(t[i]) then 709 last = i 710 strip = true 711 end 712 --if strip then 713 -- t[i] = string.gsub(t[i], "=.*$", "") 714 --end 715 end 716 717 return t,strip,last 718 718 719 719 end … … 721 721 function strip_defaults(s) 722 722 723 724 725 726 727 728 729 730 731 732 733 734 735 end 736 737 723 s = string.gsub(s, "^%(", "") 724 s = string.gsub(s, "%)$", "") 725 726 local t = split_c_tokens(s, ",") 727 local sep, ret = "","" 728 for i=1,t.n do 729 t[i] = string.gsub(t[i], "=.*$", "") 730 ret = ret..sep..t[i] 731 sep = "," 732 end 733 734 return "("..ret..")" 735 end 736 737 -
code/trunk/src/tolua/lua/module.lua
r2087 r2710 17 17 -- {i} = list of objects in the module. 18 18 classModule = { 19 classtype = 'module'19 classtype = 'module' 20 20 } 21 21 classModule.__index = classModule … … 24 24 -- register module 25 25 function classModule:register (pre) 26 pre = pre or ''27 push(self)28 output(pre..'tolua_module(tolua_S,"'..self.name..'",',self:hasvar(),');')29 output(pre..'tolua_beginmodule(tolua_S,"'..self.name..'");')30 local i=131 while self[i] do32 self[i]:register(pre..' ')33 i = i+134 end35 output(pre..'tolua_endmodule(tolua_S);')36 26 pre = pre or '' 27 push(self) 28 output(pre..'tolua_module(tolua_S,"'..self.name..'",',self:hasvar(),');') 29 output(pre..'tolua_beginmodule(tolua_S,"'..self.name..'");') 30 local i=1 31 while self[i] do 32 self[i]:register(pre..' ') 33 i = i+1 34 end 35 output(pre..'tolua_endmodule(tolua_S);') 36 pop() 37 37 end 38 38 39 39 -- Print method 40 40 function classModule:print (ident,close) 41 print(ident.."Module{")42 print(ident.." name = '"..self.name.."';")43 local i=144 while self[i] do45 self[i]:print(ident.." ",",")46 i = i+147 end48 print(ident.."}"..close)41 print(ident.."Module{") 42 print(ident.." name = '"..self.name.."';") 43 local i=1 44 while self[i] do 45 self[i]:print(ident.." ",",") 46 i = i+1 47 end 48 print(ident.."}"..close) 49 49 end 50 50 51 51 -- Internal constructor 52 52 function _Module (t) 53 setmetatable(t,classModule)54 append(t)55 return t53 setmetatable(t,classModule) 54 append(t) 55 return t 56 56 end 57 57 … … 59 59 -- Expects two string representing the module name and body. 60 60 function Module (n,b) 61 local t = _Module(_Container{name=n})62 push(t)63 t:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces64 pop()65 return t61 local t = _Module(_Container{name=n}) 62 push(t) 63 t:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces 64 pop() 65 return t 66 66 end 67 67 -
code/trunk/src/tolua/lua/namespace.lua
r2087 r2710 17 17 -- {i} = list of members 18 18 classNamespace = { 19 classtype = 'namespace',20 name = '',19 classtype = 'namespace', 20 name = '', 21 21 } 22 22 classNamespace.__index = classNamespace … … 25 25 -- Print method 26 26 function classNamespace:print (ident,close) 27 print(ident.."Namespace{")28 print(ident.." name = '"..self.name.."',")29 local i=130 while self[i] do31 self[i]:print(ident.." ",",")32 i = i+133 end34 print(ident.."}"..close)27 print(ident.."Namespace{") 28 print(ident.." name = '"..self.name.."',") 29 local i=1 30 while self[i] do 31 self[i]:print(ident.." ",",") 32 i = i+1 33 end 34 print(ident.."}"..close) 35 35 end 36 36 37 37 -- Internal constructor 38 38 function _Namespace (t) 39 setmetatable(t,classNamespace)40 append(t)41 return t39 setmetatable(t,classNamespace) 40 append(t) 41 return t 42 42 end 43 43 … … 45 45 -- Expects the name and the body of the namespace. 46 46 function Namespace (n,b) 47 local c = _Namespace(_Container{name=n})48 push(c)49 c:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces50 pop()47 local c = _Namespace(_Container{name=n}) 48 push(c) 49 c:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces 50 pop() 51 51 end 52 52 -
code/trunk/src/tolua/lua/operator.lua
r2087 r2710 16 16 -- kind = set of character representing the operator (as it appers in C++ code) 17 17 classOperator = { 18 kind = '',18 kind = '', 19 19 } 20 20 classOperator.__index = classOperator … … 22 22 23 23 -- table to transform operator kind into the appropriate tag method name 24 _TM = {['+'] = 'add', 25 ['-'] = 'sub', 26 ['*'] = 'mul', 27 ['/'] = 'div', 28 ['<'] = 'lt', 29 ['<='] = 'le', 30 ['=='] = 'eq', 31 ['[]'] = 'geti', 32 ['&[]'] = 'seti', 33 --['->'] = 'flechita', 34 } 24 _TM = { 25 ['+'] = 'add', 26 ['-'] = 'sub', 27 ['*'] = 'mul', 28 ['/'] = 'div', 29 ['<'] = 'lt', 30 ['<='] = 'le', 31 ['=='] = 'eq', 32 ['[]'] = 'geti', 33 ['&[]'] = 'seti', 34 --['->'] = 'flechita', 35 } 35 36 36 37 37 38 -- Print method 38 39 function classOperator:print (ident,close) 39 print(ident.."Operator{")40 print(ident.." kind = '"..self.kind.."',")41 print(ident.." mod = '"..self.mod.."',")42 print(ident.." type = '"..self.type.."',")43 print(ident.." ptr = '"..self.ptr.."',")44 print(ident.." name = '"..self.name.."',")45 print(ident.." const = '"..self.const.."',")46 print(ident.." cname = '"..self.cname.."',")47 print(ident.." lname = '"..self.lname.."',")48 print(ident.." args = {")49 local i=150 while self.args[i] do51 self.args[i]:print(ident.." ",",")52 i = i+153 end54 print(ident.." }")55 print(ident.."}"..close)40 print(ident.."Operator{") 41 print(ident.." kind = '"..self.kind.."',") 42 print(ident.." mod = '"..self.mod.."',") 43 print(ident.." type = '"..self.type.."',") 44 print(ident.." ptr = '"..self.ptr.."',") 45 print(ident.." name = '"..self.name.."',") 46 print(ident.." const = '"..self.const.."',") 47 print(ident.." cname = '"..self.cname.."',") 48 print(ident.." lname = '"..self.lname.."',") 49 print(ident.." args = {") 50 local i=1 51 while self.args[i] do 52 self.args[i]:print(ident.." ",",") 53 i = i+1 54 end 55 print(ident.." }") 56 print(ident.."}"..close) 56 57 end 57 58 58 59 function classOperator:supcode_tmp() 59 60 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 61 if not _TM[self.kind] then 62 return classFunction.supcode(self) 63 end 64 65 -- no overload, no parameters, always inclass 66 output("/* method:",self.name," of class ",self:inclass()," */") 67 68 output("#ifndef TOLUA_DISABLE_"..self.cname) 69 output("\nstatic int",self.cname,"(lua_State* tolua_S)") 70 71 if overload < 0 then 72 output('#ifndef TOLUA_RELEASE\n') 73 end 74 output(' tolua_Error tolua_err;') 75 output(' if (\n') 76 -- check self 77 output(' !'..'tolua_isusertype(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n') 78 output(' !tolua_isnoobj(tolua_S,2,&tolua_err)\n )') 79 output(' goto tolua_lerror;') 80 81 output(' else\n') 82 output('#endif\n') -- tolua_release 83 output(' {') 84 85 -- declare self 86 output(' ',self.const,self.parent.type,'*','self = ') 87 output('(',self.const,self.parent.type,'*) ') 88 output('tolua_tousertype(tolua_S,1,0);') 89 90 -- check self 91 output('#ifndef TOLUA_RELEASE\n') 92 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);'); 93 output('#endif\n') 94 95 -- cast self 96 output(' ',self.mod,self.type,self.ptr,'tolua_ret = ') 97 output('(',self.mod,self.type,self.ptr,')(*self);') 98 99 -- return value 100 local t,ct = isbasic(self.type) 101 if t then 102 output(' tolua_push'..t..'(tolua_S,(',ct,')tolua_ret);') 103 else 104 t = self.type 105 new_t = string.gsub(t, "const%s+", "") 106 if self.ptr == '' then 107 output(' {') 108 output('#ifdef __cplusplus\n') 109 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 110 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 111 output('#else\n') 112 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 113 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 114 output('#endif\n') 115 output(' }') 116 elseif self.ptr == '&' then 117 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");') 118 else 119 if local_constructor then 120 output(' tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");') 121 else 122 output(' tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");') 123 end 124 end 125 end 126 127 output(' }') 128 output(' return 1;') 129 130 output('#ifndef TOLUA_RELEASE\n') 131 output('tolua_lerror:\n') 132 output(' tolua_error(tolua_S,"#ferror in function \''..self.lname..'\'.",&tolua_err);') 133 output(' return 0;') 134 output('#endif\n') 135 136 137 output('}') 138 output('#endif //#ifndef TOLUA_DISABLE\n') 139 output('\n') 139 140 end 140 141 141 142 -- Internal constructor 142 143 function _Operator (t) 143 setmetatable(t,classOperator)144 145 if t.const ~= 'const' and t.const ~= '' then146 error("#invalid 'const' specification")147 end148 149 append(t)150 if not t:inclass() then151 error("#operator can only be defined as class member")152 end153 154 --t.name = t.name .. "_" .. (_TM[t.kind] or t.kind)155 t.cname = t:cfuncname("tolua")..t:overload(t)156 t.name = "operator" .. t.kind -- set appropriate calling name157 return t144 setmetatable(t,classOperator) 145 146 if t.const ~= 'const' and t.const ~= '' then 147 error("#invalid 'const' specification") 148 end 149 150 append(t) 151 if not t:inclass() then 152 error("#operator can only be defined as class member") 153 end 154 155 --t.name = t.name .. "_" .. (_TM[t.kind] or t.kind) 156 t.cname = t:cfuncname("tolua")..t:overload(t) 157 t.name = "operator" .. t.kind -- set appropriate calling name 158 return t 158 159 end 159 160 … … 161 162 function Operator (d,k,a,c) 162 163 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 local t = split_c_tokens(strsub(a,2,strlen(a)-1),',') -- eliminate braces181 local i=1182 local l = {n=0}183 while t[i] do184 l.n = l.n+1185 l[l.n] = Declaration(t[i],'var')186 i = i+1187 end188 if k == '[]' then189 190 191 d = gsub(d,'&','')192 elseif k=='&[]' then193 l.n = l.n+1194 l[l.n] = Declaration(d,'var')195 l[l.n].name = 'tolua_value'196 end197 local f = Declaration(d,'func')198 if k == '[]' and (l[1]==nil or isbasic(l[1].type)~='number') then199 error('operator[] can only be defined for numeric index.')200 end201 f.args = l202 f.const = c203 f.kind = op_k204 f.lname = "."..(_TM[f.kind] or f.kind)205 if not _TM[f.kind] then206 207 end208 if f.kind == '[]' and ref=='&' and f.const~='const' then209 Operator(d,'&'..k,a,c)-- create correspoding set operator210 end211 return _Operator(f)212 end 213 214 164 local op_k = string.gsub(k, "^%s*", "") 165 op_k = string.gsub(k, "%s*$", "") 166 --if string.find(k, "^[%w_:%d<>%*%&]+$") then 167 if d == "operator" and k ~= '' then 168 169 d = k.." operator" 170 elseif not _TM[op_k] then 171 172 if flags['W'] then 173 error("tolua: no support for operator" .. f.kind) 174 else 175 warning("No support for operator "..op_k..", ignoring") 176 return nil 177 end 178 end 179 180 local ref = '' 181 local t = split_c_tokens(strsub(a,2,strlen(a)-1),',') -- eliminate braces 182 local i=1 183 local l = {n=0} 184 while t[i] do 185 l.n = l.n+1 186 l[l.n] = Declaration(t[i],'var') 187 i = i+1 188 end 189 if k == '[]' then 190 local _ 191 _, _, ref = strfind(d,'(&)') 192 d = gsub(d,'&','') 193 elseif k=='&[]' then 194 l.n = l.n+1 195 l[l.n] = Declaration(d,'var') 196 l[l.n].name = 'tolua_value' 197 end 198 local f = Declaration(d,'func') 199 if k == '[]' and (l[1]==nil or isbasic(l[1].type)~='number') then 200 error('operator[] can only be defined for numeric index.') 201 end 202 f.args = l 203 f.const = c 204 f.kind = op_k 205 f.lname = "."..(_TM[f.kind] or f.kind) 206 if not _TM[f.kind] then 207 f.cast_operator = true 208 end 209 if f.kind == '[]' and ref=='&' and f.const~='const' then 210 Operator(d,'&'..k,a,c) -- create correspoding set operator 211 end 212 return _Operator(f) 213 end 214 215 -
code/trunk/src/tolua/lua/package.lua
r2087 r2710 17 17 -- {i} = list of objects in the package. 18 18 classPackage = { 19 classtype = 'package'19 classtype = 'package' 20 20 } 21 21 classPackage.__index = classPackage … … 24 24 -- Print method 25 25 function classPackage:print () 26 print("Package: "..self.name)27 local i=128 while self[i] do29 self[i]:print("","")30 i = i+131 end26 print("Package: "..self.name) 27 local i=1 28 while self[i] do 29 self[i]:print("","") 30 i = i+1 31 end 32 32 end 33 33 34 34 function classPackage:preprocess () 35 35 36 -- avoid preprocessing embedded Lua code37 local L = {}38 self.code = gsub(self.code,"\n%s*%$%[","\1") -- deal with embedded lua code39 self.code = gsub(self.code,"\n%s*%$%]","\2")40 self.code = gsub(self.code,"(%b\1\2)",function (c)36 -- avoid preprocessing embedded Lua code 37 local L = {} 38 self.code = gsub(self.code,"\n%s*%$%[","\1") -- deal with embedded lua code 39 self.code = gsub(self.code,"\n%s*%$%]","\2") 40 self.code = gsub(self.code,"(%b\1\2)", function (c) 41 41 tinsert(L,c) 42 42 return "\n#["..getn(L).."]#" 43 end) 44 -- avoid preprocessing embedded C code 45 local C = {} 46 self.code = gsub(self.code,"\n%s*%$%<","\3") -- deal with embedded C code 47 self.code = gsub(self.code,"\n%s*%$%>","\4") 48 self.code = gsub(self.code,"(%b\3\4)", function (c) 43 end 44 ) 45 -- avoid preprocessing embedded C code 46 local C = {} 47 self.code = gsub(self.code,"\n%s*%$%<","\3") -- deal with embedded C code 48 self.code = gsub(self.code,"\n%s*%$%>","\4") 49 self.code = gsub(self.code,"(%b\3\4)", function (c) 49 50 tinsert(C,c) 50 51 return "\n#<"..getn(C)..">#" 51 end) 52 -- avoid preprocessing embedded C code 53 self.code = gsub(self.code,"\n%s*%$%{","\5") -- deal with embedded C code 54 self.code = gsub(self.code,"\n%s*%$%}","\6") 55 self.code = gsub(self.code,"(%b\5\6)", function (c) 52 end 53 ) 54 -- avoid preprocessing embedded C code 55 self.code = gsub(self.code,"\n%s*%$%{","\5") -- deal with embedded C code 56 self.code = gsub(self.code,"\n%s*%$%}","\6") 57 self.code = gsub(self.code,"(%b\5\6)", function (c) 56 58 tinsert(C,c) 57 59 return "\n#<"..getn(C)..">#" 58 end) 59 60 --self.code = gsub(self.code,"\n%s*#[^d][^\n]*\n", "\n\n") -- eliminate preprocessor directives that don't start with 'd' 61 self.code = gsub(self.code,"\n[ \t]*#[ \t]*[^d%<%[]", "\n//") -- eliminate preprocessor directives that don't start with 'd' 62 63 -- avoid preprocessing verbatim lines 64 local V = {} 65 self.code = gsub(self.code,"\n(%s*%$[^%[%]][^\n]*)",function (v) 66 tinsert(V,v) 67 return "\n#"..getn(V).."#" 68 end) 69 70 -- perform global substitution 71 72 self.code = gsub(self.code,"(//[^\n]*)","") -- eliminate C++ comments 73 self.code = gsub(self.code,"/%*","\1") 74 self.code = gsub(self.code,"%*/","\2") 75 self.code = gsub(self.code,"%b\1\2","") 76 self.code = gsub(self.code,"\1","/%*") 77 self.code = gsub(self.code,"\2","%*/") 78 self.code = gsub(self.code,"%s*@%s*","@") -- eliminate spaces beside @ 79 self.code = gsub(self.code,"%s?inline(%s)","%1") -- eliminate 'inline' keyword 80 --self.code = gsub(self.code,"%s?extern(%s)","%1") -- eliminate 'extern' keyword 81 --self.code = gsub(self.code,"%s?virtual(%s)","%1") -- eliminate 'virtual' keyword 82 --self.code = gsub(self.code,"public:","") -- eliminate 'public:' keyword 83 self.code = gsub(self.code,"([^%w_])void%s*%*","%1_userdata ") -- substitute 'void*' 84 self.code = gsub(self.code,"([^%w_])void%s*%*","%1_userdata ") -- substitute 'void*' 85 self.code = gsub(self.code,"([^%w_])char%s*%*","%1_cstring ") -- substitute 'char*' 86 self.code = gsub(self.code,"([^%w_])lua_State%s*%*","%1_lstate ") -- substitute 'lua_State*' 87 88 -- restore embedded Lua code 89 self.code = gsub(self.code,"%#%[(%d+)%]%#",function (n) 90 return L[tonumber(n)] 91 end) 92 -- restore embedded C code 93 self.code = gsub(self.code,"%#%<(%d+)%>%#",function (n) 94 return C[tonumber(n)] 95 end) 96 -- restore verbatim lines 97 self.code = gsub(self.code,"%#(%d+)%#",function (n) 98 return V[tonumber(n)] 99 end) 100 101 self.code = string.gsub(self.code, "\n%s*%$([^\n]+)", function (l) 102 Verbatim(l.."\n") 103 return "\n" 104 end) 60 end 61 ) 62 63 --self.code = gsub(self.code,"\n%s*#[^d][^\n]*\n", "\n\n") -- eliminate preprocessor directives that don't start with 'd' 64 self.code = gsub(self.code,"\n[ \t]*#[ \t]*[^d%<%[]", "\n//") -- eliminate preprocessor directives that don't start with 'd' 65 66 -- avoid preprocessing verbatim lines 67 local V = {} 68 self.code = gsub(self.code,"\n(%s*%$[^%[%]][^\n]*)", function (v) 69 tinsert(V,v) 70 return "\n#"..getn(V).."#" 71 end 72 ) 73 74 -- perform global substitution 75 76 self.code = gsub(self.code,"(//[^\n]*)","") -- eliminate C++ comments 77 self.code = gsub(self.code,"/%*","\1") 78 self.code = gsub(self.code,"%*/","\2") 79 self.code = gsub(self.code,"%b\1\2","") 80 self.code = gsub(self.code,"\1","/%*") 81 self.code = gsub(self.code,"\2","%*/") 82 self.code = gsub(self.code,"%s*@%s*","@") -- eliminate spaces beside @ 83 self.code = gsub(self.code,"%s?inline(%s)","%1") -- eliminate 'inline' keyword 84 --self.code = gsub(self.code,"%s?extern(%s)","%1") -- eliminate 'extern' keyword 85 --self.code = gsub(self.code,"%s?virtual(%s)","%1") -- eliminate 'virtual' keyword 86 --self.code = gsub(self.code,"public:","") -- eliminate 'public:' keyword 87 self.code = gsub(self.code,"([^%w_])void%s*%*","%1_userdata ") -- substitute 'void*' 88 self.code = gsub(self.code,"([^%w_])void%s*%*","%1_userdata ") -- substitute 'void*' 89 self.code = gsub(self.code,"([^%w_])char%s*%*","%1_cstring ") -- substitute 'char*' 90 self.code = gsub(self.code,"([^%w_])lua_State%s*%*","%1_lstate ") -- substitute 'lua_State*' 91 92 -- restore embedded Lua code 93 self.code = gsub(self.code,"%#%[(%d+)%]%#", function (n) 94 return L[tonumber(n)] 95 end 96 ) 97 -- restore embedded C code 98 self.code = gsub(self.code,"%#%<(%d+)%>%#", function (n) 99 return C[tonumber(n)] 100 end 101 ) 102 -- restore verbatim lines 103 self.code = gsub(self.code,"%#(%d+)%#", function (n) 104 return V[tonumber(n)] 105 end 106 ) 107 108 self.code = string.gsub(self.code, "\n%s*%$([^\n]+)", function (l) 109 Verbatim(l.."\n") 110 return "\n" 111 end 112 ) 105 113 end 106 114 107 115 -- translate verbatim 108 116 function classPackage:preamble () 109 output('/*\n') 110 output('** Lua binding: '..self.name..'\n') 111 output('** Generated automatically by '..TOLUA_VERSION..' on '..date()..'.\n') 112 output('*/\n\n') 113 114 output('#ifndef __cplusplus\n') 115 output('#include "stdlib.h"\n') 116 output('#endif\n') 117 output('#include "string.h"\n\n') 118 output('#include "tolua/tolua++.h"\n\n') 119 120 if not flags.h then 121 -- local temp = string.reverse(flags.H) 122 -- local start1, end1 = string.find(temp, '/') 123 -- local start2, end2 = string.find(temp, '\\') 124 -- local res 125 -- if not start1 == nil then 126 -- if not start2 == nil then 127 -- if start1 > start2 then 128 -- res = string.sub(temp, 1, start2) 129 -- else 130 -- res = string.sub(temp, 1, start1) 131 -- end 132 -- else 133 -- res = string.sub(temp, 1, start1) 134 -- end 135 -- elseif not start2 == nil then 136 -- res = string.sub(temp, 1, start2) 137 -- end 138 -- res = string.reverse(res) 139 output('#include "tolua_bind.h"') 140 output('\n') 141 end 142 143 local i=1 144 while self[i] do 145 self[i]:preamble() 146 i = i+1 147 end 148 149 if self:requirecollection(_collect) then 150 output('\n') 151 output('/* function to release collected object via destructor */') 152 output('#ifdef __cplusplus\n') 153 for i,v in pairs(_collect) do 154 output('\nstatic int '..v..' (lua_State* tolua_S)') 155 output('{') 156 output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);') 157 output(' delete self;') 158 output(' return 0;') 159 output('}') 160 end 161 output('#endif\n\n') 162 end 163 164 output('\n') 165 output('/* function to register type */') 166 output('static void tolua_reg_types (lua_State* tolua_S)') 167 output('{') 168 foreach(_usertype,function(n,v) output(' tolua_usertype(tolua_S,"',v,'");') end) 169 if flags.t then 170 output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n") 171 foreach(_usertype,function(n,v) output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') end) 172 end 173 output('}') 174 output('\n') 117 output('/*\n') 118 output('** Lua binding: '..self.name..'\n') 119 output('** Generated automatically by '..TOLUA_VERSION..' on '..date()..'.\n') 120 output('*/\n\n') 121 122 output('#ifndef __cplusplus\n') 123 output('#include <stdlib.h>\n') 124 output('#endif\n') 125 output('#include <string.h>\n\n') 126 output('#include <tolua/tolua++.h>\n\n') 127 128 if flags.H then 129 local header = gsub(flags.H, '^.-([%w_]*%.[%w_]*)$', '%1') 130 local package_lower = string.lower(self.name) 131 output('#include "'..header..'"\n') 132 end 133 134 local i=1 135 while self[i] do 136 self[i]:preamble() 137 i = i+1 138 end 139 140 if self:requirecollection(_collect) then 141 output('\n') 142 output('/* function to release collected object via destructor */') 143 output('#ifdef __cplusplus\n') 144 for i,v in pairs(_collect) do 145 output('\nstatic int '..v..' (lua_State* tolua_S)') 146 output('{') 147 output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);') 148 output(' delete self;') 149 output(' return 0;') 150 output('}') 151 end 152 output('#endif\n\n') 153 end 154 155 output('\n') 156 output('/* function to register type */') 157 output('static void tolua_reg_types (lua_State* tolua_S)') 158 output('{') 159 foreach(_usertype,function(n,v) output(' tolua_usertype(tolua_S,"',v,'");') end) 160 if flags.t then 161 output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n") 162 foreach(_usertype,function(n,v) output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') end) 163 end 164 output('}') 165 output('\n') 175 166 end 176 167 … … 178 169 -- write package open function 179 170 function classPackage:register (pre) 180 pre = pre or ''181 push(self)182 output(pre.."/* Open function */")183 output(pre.."int tolua_"..self.name.."_open (lua_State* tolua_S)")184 output(pre.."{")185 output(pre.." tolua_open(tolua_S);")186 output(pre.." tolua_reg_types(tolua_S);")187 output(pre.." tolua_module(tolua_S,NULL,",self:hasvar(),");")188 output(pre.." tolua_beginmodule(tolua_S,NULL);")189 local i=1190 while self[i] do191 self[i]:register(pre.." ")192 i = i+1193 end194 output(pre.." tolua_endmodule(tolua_S);")195 output(pre.." return 1;")196 output(pre.."}")197 198 output("\n\n")199 output("#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501\n");200 output(pre.."int luaopen_"..self.name.." (lua_State* tolua_S) {")201 output(pre.." return tolua_"..self.name.."_open(tolua_S);")202 output(pre.."};")203 output("#endif\n\n")204 205 171 pre = pre or '' 172 push(self) 173 output(pre.."/* Open function */") 174 output(pre.."int tolua_"..self.name.."_open (lua_State* tolua_S)") 175 output(pre.."{") 176 output(pre.." tolua_open(tolua_S);") 177 output(pre.." tolua_reg_types(tolua_S);") 178 output(pre.." tolua_module(tolua_S,NULL,",self:hasvar(),");") 179 output(pre.." tolua_beginmodule(tolua_S,NULL);") 180 local i=1 181 while self[i] do 182 self[i]:register(pre.." ") 183 i = i+1 184 end 185 output(pre.." tolua_endmodule(tolua_S);") 186 output(pre.." return 1;") 187 output(pre.."}") 188 189 output("\n\n") 190 output("#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501\n"); 191 output(pre.."int luaopen_"..self.name.." (lua_State* tolua_S) {") 192 output(pre.." return tolua_"..self.name.."_open(tolua_S);") 193 output(pre.."};") 194 output("#endif\n\n") 195 196 pop() 206 197 end 207 198 208 199 -- write header file 209 200 function classPackage:header () 210 output('/*\n') output('** Lua binding: '..self.name..'\n') 211 output('** Generated automatically by '..TOLUA_VERSION..' on '..date()..'.\n') 212 output('*/\n\n') 213 214 if not flags.h then 215 output('#include "../'..self.name..'Prereqs.h"\n') 216 output('/* Exported function */') 217 output('_'..self.name..'Export int tolua_'..self.name..'_open (lua_State* tolua_S);') 218 output('\n') 219 end 201 output('/*\n') output('** Lua binding: '..self.name..'\n') 202 output('** Generated automatically by '..TOLUA_VERSION..' on '..date()..'.\n') 203 output('*/\n\n') 204 205 if flags.H then 206 local package_lower = string.lower(self.name) 207 output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n') 208 output('/* Exported function */') 209 output('_'..self.name..'Export') 210 output('int tolua_'..self.name..'_open (lua_State* tolua_S);') 211 output('\n') 212 end 220 213 end 221 214 222 215 -- Internal constructor 223 216 function _Package (self) 224 setmetatable(self,classPackage)225 return self217 setmetatable(self,classPackage) 218 return self 226 219 end 227 220 … … 229 222 -- *** Thanks to Ariel Manzur for fixing bugs in nested directives *** 230 223 function extract_code(fn,s) 231 local code = '\n$#include "'..fn..'"\n' 232 s= "\n" .. s .. "\n" -- add blank lines as sentinels 233 local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n") 234 while e do 235 t = strlower(t) 236 if t == "begin" then 237 _,e,c = strfind(s,"(.-)\n[^\n]*[Tt][Oo][Ll][Uu][Aa]_[Ee][Nn][Dd][^\n]*\n",e) 238 if not e then 239 tolua_error("Unbalanced 'tolua_begin' directive in header file") 240 end 241 end 242 code = code .. c .. "\n" 243 _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n",e) 244 end 245 return code 224 local code = '\n$#include "'..string.lower(flags.n)..'/'..fn..'"\n' 225 s= "\n" .. s .. "\n" -- add blank lines as sentinels 226 227 -- eliminate export macro problems in class declarations 228 s = gsub(s, ' _%w*Export ', ' ') 229 230 local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n") 231 while e do 232 t = strlower(t) 233 if t == "begin" then 234 _,e,c = strfind(s,"(.-)\n[^\n]*[Tt][Oo][Ll][Uu][Aa]_[Ee][Nn][Dd][^\n]*\n",e) 235 if not e then 236 tolua_error("Unbalanced 'tolua_begin' directive in header file") 237 end 238 end 239 code = code .. c .. "\n" 240 _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n",e) 241 end 242 return code 246 243 end 247 244 … … 249 246 -- Expects the package name, the file extension, and the file text. 250 247 function Package (name,fn) 251 local ext = "pkg" 252 253 -- open input file, if any 254 if fn then 255 local st, msg = readfrom(flags.f) 256 if not st then 257 error('#'..msg) 258 end 259 local _; _, _, ext = strfind(fn,".*%.(.*)$") 260 end 261 local code = "\n" .. read('*a') 262 if ext == 'h' or ext == 'hpp' then 263 code = extract_code(fn,code) 264 end 265 266 -- close file 267 if fn then 268 readfrom() 269 end 270 271 -- deal with include directive 272 local nsubst 273 repeat 274 code,nsubst = gsub(code,'\n%s*%$(.)file%s*"(.-)"([^\n]*)\n', 275 function (kind,fn,extra) 276 local _, _, ext = strfind(fn,".*%.(.*)$") 277 local fp,msg = openfile(fn,'r') 278 if not fp then 279 error('#'..msg..': '..fn) 280 end 281 local s = read(fp,'*a') 282 closefile(fp) 283 if kind == 'c' or kind == 'h' then 284 return extract_code(fn,s) 285 elseif kind == 'p' then 286 return "\n\n" .. s 287 elseif kind == 'l' then 288 return "\n$[--##"..fn.."\n" .. s .. "\n$]\n" 289 elseif kind == 'i' then 290 local t = {code=s} 291 extra = string.gsub(extra, "^%s*,%s*", "") 292 local pars = split_c_tokens(extra, ",") 293 include_file_hook(t, fn, unpack(pars)) 294 return "\n\n" .. t.code 295 else 296 error('#Invalid include directive (use $cfile, $pfile, $lfile or $ifile)') 297 end 298 end) 299 until nsubst==0 300 301 -- deal with renaming directive 302 repeat -- I don't know why this is necesary 303 code,nsubst = gsub(code,'\n%s*%$renaming%s*(.-)%s*\n', function (r) appendrenaming(r) return "\n" end) 304 until nsubst == 0 305 306 local t = _Package(_Container{name=name, code=code}) 307 push(t) 308 preprocess_hook(t) 309 t:preprocess() 310 preparse_hook(t) 311 t:parse(t.code) 312 pop() 313 return t 314 end 315 316 248 local ext = "pkg" 249 250 -- open input file, if any 251 if fn then 252 local file 253 if flags.f then 254 if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then 255 file = flags.f 256 else 257 file = flags.w..'/'..flags.f 258 end 259 else 260 file = flags.f 261 end 262 local st, msg = readfrom(file) 263 if not st then 264 error('#'..msg..' path: '..flags.f) 265 end 266 local _; _, _, ext = strfind(fn,".*%.(.*)$") 267 end 268 local code = "\n" .. read('*a') 269 if ext == 'h' or ext == 'hpp' then 270 code = extract_code(fn,code) 271 end 272 273 -- close file 274 if fn then 275 readfrom() 276 end 277 278 -- prepare working directory 279 local current_path 280 if not flags.w and flags.f then 281 current_path = gsub(flags.f, '(/)[^/]*%.?[^/]*$', '%1') 282 elseif flags.w then 283 if not (string.sub(flags.w, string.len(flags.w)) == '/') then 284 current_path = flags.w..'/' 285 else 286 current_path = flags.w 287 end 288 else 289 current_path = '' 290 end 291 292 -- deal with include directive 293 local nsubst 294 repeat 295 code,nsubst = gsub(code,'\n%s*%$(.)file%s*"(.-)"([^\n]*)\n', 296 function (kind,fn,extra) 297 local _, _, ext = strfind(fn,".*%.(.*)$") 298 local fp,msg = openfile(current_path..fn,'r') 299 if not fp then 300 error('#'..msg..': '..fn) 301 end 302 local s = read(fp,'*a') 303 closefile(fp) 304 if kind == 'c' or kind == 'h' then 305 return extract_code(fn,s) 306 elseif kind == 'p' then 307 return "\n\n" .. s 308 elseif kind == 'l' then 309 return "\n$[--##"..fn.."\n" .. s .. "\n$]\n" 310 elseif kind == 'i' then 311 local t = {code=s} 312 extra = string.gsub(extra, "^%s*,%s*", "") 313 local pars = split_c_tokens(extra, ",") 314 include_file_hook(t, fn, unpack(pars)) 315 return "\n\n" .. t.code 316 else 317 error('#Invalid include directive (use $cfile, $pfile, $lfile or $ifile)') 318 end 319 end 320 ) 321 until nsubst==0 322 323 -- deal with renaming directive 324 repeat -- I don't know why this is necesary 325 code,nsubst = gsub(code,'\n%s*%$renaming%s*(.-)%s*\n', function (r) appendrenaming(r) return "\n" end) 326 until nsubst == 0 327 328 local t = _Package(_Container{name=name, code=code}) 329 push(t) 330 preprocess_hook(t) 331 t:preprocess() 332 preparse_hook(t) 333 t:parse(t.code) 334 pop() 335 return t 336 end 337 338 -
code/trunk/src/tolua/lua/typedef.lua
r2087 r2710 21 21 -- mod = modifiers to the 'de facto' type 22 22 classTypedef = { 23 utype = '',24 mod = '',25 type = ''23 utype = '', 24 mod = '', 25 type = '' 26 26 } 27 27 classTypedef.__index = classTypedef … … 29 29 -- Print method 30 30 function classTypedef:print (ident,close) 31 print(ident.."Typedef{")32 print(ident.." utype = '"..self.utype.."',")33 print(ident.." mod = '"..self.mod.."',")34 print(ident.." type = '"..self.type.."',")35 print(ident.."}"..close)31 print(ident.."Typedef{") 32 print(ident.." utype = '"..self.utype.."',") 33 print(ident.." mod = '"..self.mod.."',") 34 print(ident.." type = '"..self.type.."',") 35 print(ident.."}"..close) 36 36 end 37 37 38 38 -- Return it's not a variable 39 39 function classTypedef:isvariable () 40 return false40 return false 41 41 end 42 42 43 43 -- Internal constructor 44 44 function _Typedef (t) 45 setmetatable(t,classTypedef)46 t.type = resolve_template_types(t.type)47 appendtypedef(t)48 return t45 setmetatable(t,classTypedef) 46 t.type = resolve_template_types(t.type) 47 appendtypedef(t) 48 return t 49 49 end 50 50 … … 52 52 -- Expects one string representing the type definition. 53 53 function Typedef (s) 54 if strfind(string.gsub(s, '%b<>', ''),'[%*&]') then55 tolua_error("#invalid typedef: pointers (and references) are not supported")56 end57 local o = {mod = ''}58 if string.find(s, "[<>]") then59 60 else61 62 63 64 65 66 67 end68 return _Typedef(o)54 if strfind(string.gsub(s, '%b<>', ''),'[%*&]') then 55 tolua_error("#invalid typedef: pointers (and references) are not supported") 56 end 57 local o = {mod = ''} 58 if string.find(s, "[<>]") then 59 _,_,o.type,o.utype = string.find(s, "^%s*([^<>]+%b<>[^%s]*)%s+(.-)$") 60 else 61 local t = split(gsub(s,"%s%s*"," ")," ") 62 o = { 63 utype = t[t.n], 64 type = t[t.n-1], 65 mod = concat(t,1,t.n-2), 66 } 67 end 68 return _Typedef(o) 69 69 end 70 70 -
code/trunk/src/tolua/lua/variable.lua
r2087 r2710 15 15 -- Stores all fields present in a declaration. 16 16 classVariable = { 17 _get = {}, -- mapped get functions18 _set = {}, -- mapped set functions17 _get = {}, -- mapped get functions 18 _set = {}, -- mapped set functions 19 19 } 20 20 classVariable.__index = classVariable … … 23 23 -- Print method 24 24 function classVariable:print (ident,close) 25 print(ident.."Variable{")26 print(ident.." mod = '"..self.mod.."',")27 print(ident.." type = '"..self.type.."',")28 print(ident.." ptr = '"..self.ptr.."',")29 print(ident.." name = '"..self.name.."',")30 if self.dim then print(ident.." dim = '"..self.dim.."',") end31 print(ident.." def = '"..self.def.."',")32 print(ident.." ret = '"..self.ret.."',")33 print(ident.."}"..close)25 print(ident.."Variable{") 26 print(ident.." mod = '"..self.mod.."',") 27 print(ident.." type = '"..self.type.."',") 28 print(ident.." ptr = '"..self.ptr.."',") 29 print(ident.." name = '"..self.name.."',") 30 if self.dim then print(ident.." dim = '"..self.dim.."',") end 31 print(ident.." def = '"..self.def.."',") 32 print(ident.." ret = '"..self.ret.."',") 33 print(ident.."}"..close) 34 34 end 35 35 36 36 -- Generates C function name 37 37 function classVariable:cfuncname (prefix) 38 local parent = ""39 local unsigned = ""40 local ptr = ""41 42 local p = self:inmodule() or self:innamespace() or self:inclass()43 44 if p then45 46 47 48 49 50 end51 52 if strfind(self.mod,"(unsigned)") then53 unsigned = "_unsigned"54 end55 56 if self.ptr == "*" then ptr = "_ptr"57 elseif self.ptr == "&" then ptr = "_ref"58 end59 60 local name = prefix .. parent .. unsigned .. "_" .. gsub(self.lname or self.name,".*::","") .. ptr61 62 63 return name38 local parent = "" 39 local unsigned = "" 40 local ptr = "" 41 42 local p = self:inmodule() or self:innamespace() or self:inclass() 43 44 if p then 45 if self.parent.classtype == 'class' then 46 parent = "_" .. self.parent.type 47 else 48 parent = "_" .. p 49 end 50 end 51 52 if strfind(self.mod,"(unsigned)") then 53 unsigned = "_unsigned" 54 end 55 56 if self.ptr == "*" then ptr = "_ptr" 57 elseif self.ptr == "&" then ptr = "_ref" 58 end 59 60 local name = prefix .. parent .. unsigned .. "_" .. gsub(self.lname or self.name,".*::","") .. ptr 61 62 name = clean_template(name) 63 return name 64 64 65 65 end … … 67 67 -- check if it is a variable 68 68 function classVariable:isvariable () 69 return true69 return true 70 70 end 71 71 … … 73 73 function classVariable:getvalue (class,static, prop_get) 74 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 75 local name 76 if prop_get then 77 78 name = prop_get.."()" 79 else 80 name = self.name 81 end 82 83 if class and static then 84 return self.parent.type..'::'..name 85 elseif class then 86 return 'self->'..name 87 else 88 return name 89 end 90 90 end 91 91 92 92 -- get variable pointer value 93 93 function classVariable:getpointervalue (class,static) 94 if class and static then95 return class..'::p'96 elseif class then97 return 'self->p'98 else99 return 'p'100 end94 if class and static then 95 return class..'::p' 96 elseif class then 97 return 'self->p' 98 else 99 return 'p' 100 end 101 101 end 102 102 … … 106 106 local class = self:inclass() 107 107 108 109 110 111 112 113 114 115 116 117 -- get function ------------------------------------------------118 if class then119 output("/* get function:",self.name," of class ",class," */")120 else121 output("/* get function:",self.name," */")122 end123 self.cgetname = self:cfuncname("tolua_get")124 output("#ifndef TOLUA_DISABLE_"..self.cgetname)125 output("\nstatic int",self.cgetname,"(lua_State* tolua_S)")126 output("{")127 128 -- declare self, if the case129 local _,_,static = strfind(self.mod,'^%s*(static)')130 if class and static==nil then131 output(' ',self.parent.type,'*','self = ')132 output('(',self.parent.type,'*) ')133 output('tolua_tousertype(tolua_S,1,0);')134 elseif static then135 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')136 end137 138 139 -- check self value140 if class and static==nil then141 142 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);');143 144 end145 146 -- return value147 if string.find(self.mod, 'tolua_inherits') then148 149 150 151 152 153 else154 155 156 157 158 159 160 161 162 163 164 165 end166 output(' return 1;')167 output('}')168 output('#endif //#ifndef TOLUA_DISABLE\n')169 output('\n')170 171 -- set function ------------------------------------------------172 if not (strfind(self.type,'const%s+') or string.find(self.mod, 'tolua_readonly') or string.find(self.mod, 'tolua_inherits')) then173 if class then174 output("/* set function:",self.name," of class ",class," */")175 else176 output("/* set function:",self.name," */")177 end178 self.csetname = self:cfuncname("tolua_set")179 output("#ifndef TOLUA_DISABLE_"..self.csetname)180 output("\nstatic int",self.csetname,"(lua_State* tolua_S)")181 output("{")182 183 -- declare self, if the case184 if class and static==nil then185 output(' ',self.parent.type,'*','self = ')186 output('(',self.parent.type,'*) ')187 output('tolua_tousertype(tolua_S,1,0);')188 -- check self value189 190 -- check types191 192 193 if class and static==nil then194 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);');195 elseif static then196 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')197 end198 199 -- check variable type200 output(' if (!'..self:outchecktype(2)..')')201 output(' tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);')202 203 204 -- assign value205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 output(' return 0;')255 output('}')256 output('#endif //#ifndef TOLUA_DISABLE\n')257 output('\n')258 end108 local prop_get,prop_set 109 if string.find(self.mod, 'tolua_property') then 110 111 _,_,type = string.find(self.mod, "tolua_property__([^%s]*)") 112 type = type or "default" 113 prop_get,prop_set = get_property_methods(type, self.name) 114 self.mod = string.gsub(self.mod, "tolua_property[^%s]*", "") 115 end 116 117 -- get function ------------------------------------------------ 118 if class then 119 output("/* get function:",self.name," of class ",class," */") 120 else 121 output("/* get function:",self.name," */") 122 end 123 self.cgetname = self:cfuncname("tolua_get") 124 output("#ifndef TOLUA_DISABLE_"..self.cgetname) 125 output("\nstatic int",self.cgetname,"(lua_State* tolua_S)") 126 output("{") 127 128 -- declare self, if the case 129 local _,_,static = strfind(self.mod,'^%s*(static)') 130 if class and static==nil then 131 output(' ',self.parent.type,'*','self = ') 132 output('(',self.parent.type,'*) ') 133 output('tolua_tousertype(tolua_S,1,0);') 134 elseif static then 135 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 136 end 137 138 139 -- check self value 140 if class and static==nil then 141 output('#ifndef TOLUA_RELEASE\n') 142 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); 143 output('#endif\n') 144 end 145 146 -- return value 147 if string.find(self.mod, 'tolua_inherits') then 148 output('#ifdef __cplusplus\n') 149 output(' tolua_pushusertype(tolua_S,(void*)static_cast<'..self.type..'*>(self), "',self.type,'");') 150 output('#else\n') 151 output(' tolua_pushusertype(tolua_S,(void*)(('..self.type..'*)self), "',self.type,'");') 152 output('#endif\n') 153 else 154 local t,ct = isbasic(self.type) 155 if t then 156 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static,prop_get)..');') 157 else 158 t = self.type 159 if self.ptr == '&' or self.ptr == '' then 160 output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static,prop_get)..',"',t,'");') 161 else 162 output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static,prop_get)..',"',t,'");') 163 end 164 end 165 end 166 output(' return 1;') 167 output('}') 168 output('#endif //#ifndef TOLUA_DISABLE\n') 169 output('\n') 170 171 -- set function ------------------------------------------------ 172 if not (strfind(self.type,'const%s+') or string.find(self.mod, 'tolua_readonly') or string.find(self.mod, 'tolua_inherits')) then 173 if class then 174 output("/* set function:",self.name," of class ",class," */") 175 else 176 output("/* set function:",self.name," */") 177 end 178 self.csetname = self:cfuncname("tolua_set") 179 output("#ifndef TOLUA_DISABLE_"..self.csetname) 180 output("\nstatic int",self.csetname,"(lua_State* tolua_S)") 181 output("{") 182 183 -- declare self, if the case 184 if class and static==nil then 185 output(' ',self.parent.type,'*','self = ') 186 output('(',self.parent.type,'*) ') 187 output('tolua_tousertype(tolua_S,1,0);') 188 -- check self value 189 end 190 -- check types 191 output('#ifndef TOLUA_RELEASE\n') 192 output(' tolua_Error tolua_err;') 193 if class and static==nil then 194 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); 195 elseif static then 196 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') 197 end 198 199 -- check variable type 200 output(' if (!'..self:outchecktype(2)..')') 201 output(' tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);') 202 output('#endif\n') 203 204 -- assign value 205 local def = 0 206 if self.def ~= '' then def = self.def end 207 if self.type == 'char*' and self.dim ~= '' then -- is string 208 output(' strncpy(') 209 if class and static then 210 output(self.parent.type..'::'..self.name) 211 elseif class then 212 output('self->'..self.name) 213 else 214 output(self.name) 215 end 216 output(',tolua_tostring(tolua_S,2,',def,'),',self.dim,'-1);') 217 else 218 local ptr = '' 219 if self.ptr~='' then ptr = '*' end 220 output(' ') 221 local name = prop_set or self.name 222 if class and static then 223 output(self.parent.type..'::'..name) 224 elseif class then 225 output('self->'..name) 226 else 227 output(name) 228 end 229 local t = isbasic(self.type) 230 if prop_set then 231 output('(') 232 else 233 output(' = ') 234 end 235 if not t and ptr=='' then output('*') end 236 output('((',self.mod,self.type) 237 if not t then 238 output('*') 239 end 240 output(') ') 241 if t then 242 if isenum(self.type) then 243 output('(int) ') 244 end 245 output('tolua_to'..t,'(tolua_S,2,',def,'))') 246 else 247 output('tolua_tousertype(tolua_S,2,',def,'))') 248 end 249 if prop_set then 250 output(")") 251 end 252 output(";") 253 end 254 output(' return 0;') 255 output('}') 256 output('#endif //#ifndef TOLUA_DISABLE\n') 257 output('\n') 258 end 259 259 260 260 end … … 262 262 function classVariable:register (pre) 263 263 264 265 266 267 pre = pre or ''268 local parent = self:inmodule() or self:innamespace() or self:inclass()269 if not parent then270 if classVariable._warning==nil then271 warning("Mapping variable to global may degrade performance")272 classVariable._warning = 1273 end274 end275 if self.csetname then276 output(pre..'tolua_variable(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');')277 else278 output(pre..'tolua_variable(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);')279 end264 if not self:check_public_access() then 265 return 266 end 267 pre = pre or '' 268 local parent = self:inmodule() or self:innamespace() or self:inclass() 269 if not parent then 270 if classVariable._warning==nil then 271 warning("Mapping variable to global may degrade performance") 272 classVariable._warning = 1 273 end 274 end 275 if self.csetname then 276 output(pre..'tolua_variable(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');') 277 else 278 output(pre..'tolua_variable(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);') 279 end 280 280 end 281 281 282 282 -- Internal constructor 283 283 function _Variable (t) 284 setmetatable(t,classVariable)285 append(t)286 return t284 setmetatable(t,classVariable) 285 append(t) 286 return t 287 287 end 288 288 … … 290 290 -- Expects a string representing the variable declaration. 291 291 function Variable (s) 292 return _Variable (Declaration(s,'var'))293 end 294 295 292 return _Variable (Declaration(s,'var')) 293 end 294 295 -
code/trunk/src/tolua/lua/verbatim.lua
r2087 r2710 17 17 -- line = line text 18 18 classVerbatim = { 19 line = '',20 19 line = '', 20 cond = nil, -- condition: where to generate the code (s=suport, r=register) 21 21 } 22 22 classVerbatim.__index = classVerbatim … … 25 25 -- preamble verbatim 26 26 function classVerbatim:preamble () 27 if self.cond == '' then28 write(self.line)29 end27 if self.cond == '' then 28 write(self.line) 29 end 30 30 end 31 31 32 32 -- support code 33 33 function classVerbatim:supcode () 34 if strfind(self.cond,'s') then35 write(self.line)36 write('\n')37 end34 if strfind(self.cond,'s') then 35 write(self.line) 36 write('\n') 37 end 38 38 end 39 39 40 40 -- register code 41 41 function classVerbatim:register (pre) 42 if strfind(self.cond,'r') then43 write(self.line)44 end42 if strfind(self.cond,'r') then 43 write(self.line) 44 end 45 45 end 46 46 … … 48 48 -- Print method 49 49 function classVerbatim:print (ident,close) 50 print(ident.."Verbatim{")51 print(ident.." line = '"..self.line.."',")52 print(ident.."}"..close)53 end50 print(ident.."Verbatim{") 51 print(ident.." line = '"..self.line.."',") 52 print(ident.."}"..close) 53 end 54 54 55 55 56 56 -- Internal constructor 57 57 function _Verbatim (t) 58 setmetatable(t,classVerbatim)59 append(t)60 return t58 setmetatable(t,classVerbatim) 59 append(t) 60 return t 61 61 end 62 62 … … 64 64 -- Expects a string representing the text line 65 65 function Verbatim (l,cond) 66 if strsub(l,1,1) == "'" then67 l = strsub(l,2)68 elseif strsub(l,1,1) == '$' then69 cond = 'sr' -- generates in both suport and register fragments70 l = strsub(l,2)71 end72 return _Verbatim {73 line = l,74 cond = cond or '',75 }66 if strsub(l,1,1) == "'" then 67 l = strsub(l,2) 68 elseif strsub(l,1,1) == '$' then 69 cond = 'sr' -- generates in both suport and register fragments 70 l = strsub(l,2) 71 end 72 return _Verbatim { 73 line = l, 74 cond = cond or '', 75 } 76 76 end 77 77 -
code/trunk/src/tolua/tolua++.h
r1810 r2710 65 65 typedef int lua_Object; 66 66 67 #include "lua /lua.h"68 #include "l ua/lauxlib.h"67 #include "lua.h" 68 #include "lauxlib.h" 69 69 70 70 struct tolua_Error -
code/trunk/src/tolua/tolua.c
r1810 r2710 5 5 ** Aug 2003 6 6 ** $Id:$ 7 ** Extension by Orxonox (Reto Grieder) to support working directory 8 ** and direct usage of lua files. (2008) 7 9 */ 8 10 … … 15 17 #include "tolua++.h" 16 18 17 #include "lua /lua.h"18 #include "lua /lualib.h"19 #include "l ua/lauxlib.h"19 #include "lua.h" 20 #include "lualib.h" 21 #include "lauxlib.h" 20 22 21 23 #include <stdio.h> … … 34 36 " -H file : create include file.\n" 35 37 " -n name : set package name; default is input file root name.\n" 38 " -w directory : set working directory; default is location of package file.\n" 39 " -s file : specify source lua code for the parser; all.lua is default.\n" 36 40 " -p : parse only.\n" 37 41 " -P : parse and print structure information (for debug).\n" … … 65 69 66 70 static void add_extra (lua_State* L, char* value) { 67 68 69 70 71 72 71 int len; 72 lua_getglobal(L, "_extra_parameters"); 73 len = luaL_getn(L, -1); 74 lua_pushstring(L, value); 75 lua_rawseti(L, -2, len+1); 76 lua_pop(L, 1); 73 77 }; 74 78 … … 82 86 int main (int argc, char* argv[]) 83 87 { 88 char* working_directory = ""; 89 char* lua_source = ""; 90 84 91 #ifdef LUA_VERSION_NUM /* lua 5.1 */ 85 92 lua_State* L = luaL_newstate(); … … 97 104 lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION"); 98 105 lua_pushstring(L,LUA_VERSION); lua_setglobal(L,"TOLUA_LUA_VERSION"); 106 99 107 100 108 if (argc==1) … … 125 133 case 'n': setfield(L,t,"n",argv[++i]); break; 126 134 case 'H': setfield(L,t,"H",argv[++i]); break; 135 case 'w': 136 working_directory = argv[++i]; 137 setfield(L,t,"w",argv[i]); 138 break; 139 case 's': 140 lua_source = argv[++i]; 141 setfield(L,t,"s",argv[i]); 142 break; 127 143 case 'S': setfield(L,t,"S",""); break; 128 144 case '1': setfield(L,t,"1",""); break; … … 144 160 lua_pop(L,1); 145 161 } 146 /* #define TOLUA_SCRIPT_RUN */ 147 #ifndef TOLUA_SCRIPT_RUN 162 148 163 { 149 int tolua_tolua_open (lua_State* L); 150 tolua_tolua_open(L); 164 char path[BUFSIZ]; 165 char file[BUFSIZ]; 166 path[0] = '\0'; 167 file[0] = '\0'; 168 169 if (strlen(lua_source) > 0 && 170 lua_source[0] != '/' && 171 lua_source[0] != '\\' && 172 strlen(lua_source) > 1 && 173 lua_source[1] != ':') 174 { 175 /* Relative path, prefix working directory */ 176 strcpy(path, working_directory); 177 /* Make sure there is '\\' or '/' at the end of the path */ 178 if (strlen(path) > 0) 179 { 180 char last = path[strlen(path) - 1]; 181 if (last != '\\' && last != '/') 182 strcat(path, "/"); 183 } 184 } 185 186 strcat(path, lua_source); 187 188 /* Extract the full path */ 189 { 190 char* p; 191 p = strrchr(path, '/'); 192 if (p == NULL) 193 p = strrchr(path, '\\'); 194 p = (p == NULL) ? path : p + 1; 195 strcpy(file, p); 196 *p = '\0'; 197 } 198 if (strlen(file) == 0) 199 strcpy(file, "all.lua"); 200 201 lua_pushstring(L, path); 202 lua_setglobal(L, "path"); 203 strcat(path, file); 204 #ifdef LUA_VERSION_NUM /* lua 5.1 */ 205 luaL_dofile(L, path); 206 #else 207 lua_dofile(L, path); 208 #endif 151 209 } 152 #else153 {154 char* p;155 char path[BUFSIZ];156 strcpy(path,argv[0]);157 p = strrchr(path,'/');158 if (p==NULL) p = strrchr(path,'\\');159 p = (p==NULL) ? path : p+1;160 sprintf(p,"%s","../src/bin/lua/");161 lua_pushstring(L,path); lua_setglobal(L,"path");162 strcat(path,"all.lua");163 lua_dofile(L,path);164 }165 #endif166 210 return 0; 167 211 } -
code/trunk/src/tolua/tolua_is.c
r1810 r2710 14 14 15 15 #include "tolua++.h" 16 #include "l ua/lauxlib.h"16 #include "lauxlib.h" 17 17 18 18 #include <stdlib.h> -
code/trunk/src/tolua/tolua_map.c
r1810 r2710 15 15 #include "tolua++.h" 16 16 #include "tolua_event.h" 17 #include "l ua/lauxlib.h"17 #include "lauxlib.h" 18 18 19 19 #include <string.h> -
code/trunk/src/tolua/tolua_push.c
r1810 r2710 14 14 15 15 #include "tolua++.h" 16 #include "l ua/lauxlib.h"16 #include "lauxlib.h" 17 17 18 18 #include <stdlib.h> -
code/trunk/src/util
- Property svn:mergeinfo changed
-
code/trunk/src/util/CMakeLists.txt
r2295 r2710 1 SET(UTIL_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(UTIL_FILES 21 CRC32.h 22 Clipboard.h 23 Convert.h 24 Debug.h 25 Exception.h 26 ExprParser.h 27 Math.h 28 MathConvert.h 29 MultiType.h 30 MultiTypeValue.h 31 OutputBuffer.h 32 OutputHandler.h 33 SignalHandler.h 34 Sleep.h 35 String.h 36 SubString.h 37 UtilPrereqs.h 38 mbool.h 39 2 40 Clipboard.cc 3 41 CRC32.cc … … 12 50 SubString.cc 13 51 ) 52 #GET_ALL_HEADER_FILES(UTIL_HDR_FILES) 53 #SET(UTIL_FILES ${UTIL_SRC_FILES} ${UTIL_HDR_FILES}) 54 GENERATE_SOURCE_GROUPS(${UTIL_FILES}) 55 # Also add OrxonoxConfig to have it least somewhere in the IDE 56 LIST(APPEND UTIL_FILES 57 ${CMAKE_BINARY_DIR}/src/OrxonoxConfig.h 58 ${CMAKE_SOURCE_DIR}/src/OrxonoxConfig.h.in 59 ${CMAKE_BINARY_DIR}/src/SpecialConfig.h 60 ${CMAKE_SOURCE_DIR}/src/SpecialConfig.h.in 61 ) 62 SOURCE_GROUP("" FILES 63 ${CMAKE_BINARY_DIR}/src/OrxonoxConfig.h 64 ${CMAKE_SOURCE_DIR}/src/OrxonoxConfig.h.in 65 ${CMAKE_BINARY_DIR}/src/SpecialConfig.h 66 ${CMAKE_SOURCE_DIR}/src/SpecialConfig.h.in 67 ) 14 68 15 ADD_LIBRARY(util SHARED ${UTIL_SRC_FILES}) 69 IF(GCC_NO_SYSTEM_HEADER_SUPPORT) 70 # Get around displaying a few hundred lines of warning code 71 SET_SOURCE_FILES_PROPERTIES(MultiType.cc PROPERTIES COMPILE_FLAGS "-w") 72 ENDIF() 16 73 17 TARGET_LINK_LIBRARIES(util 18 ${OGRE_LIBRARIES} 19 ) 74 ADD_LIBRARY(util SHARED ${UTIL_FILES}) 75 SET_TARGET_PROPERTIES(util PROPERTIES DEFINE_SYMBOL "UTIL_SHARED_BUILD") 76 TARGET_LINK_LIBRARIES(util ${OGRE_LIBRARY}) 77 78 ORXONOX_INSTALL(util) -
code/trunk/src/util/CRC32.h
r2171 r2710 32 32 #include "UtilPrereqs.h" 33 33 #include <iostream> 34 #include "Integers.h"35 34 36 35 namespace orxonox -
code/trunk/src/util/Clipboard.cc
r2171 r2710 36 36 #include "Clipboard.h" 37 37 38 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN3238 #ifdef ORXONOX_PLATFORM_WINDOWS 39 39 40 40 ///////////// … … 104 104 } 105 105 106 #else /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32*/106 #else /* ORXONOX_PLATFORM_WINDOWS */ 107 107 108 108 ///////////// … … 135 135 } 136 136 137 #endif /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32*/137 #endif /* ORXONOX_PLATFORM_WINDOWS */ -
code/trunk/src/util/Convert.h
r2662 r2710 50 50 // This is however exactly what convertValue does, so we need to suppress these warnings. 51 51 // They only occur when using the ImplicitConversion template. 52 #if ORXONOX_COMPILER == ORXONOX_COMPILER_GNUC52 #ifdef ORXONOX_COMPILER_GCC 53 53 # pragma GCC system_header 54 54 #endif … … 63 63 64 64 // disable warnings about possible loss of data 65 #if ORXONOX_COMPILER ==ORXONOX_COMPILER_MSVC65 #ifdef ORXONOX_COMPILER_MSVC 66 66 # pragma warning(push) 67 67 # pragma warning(disable:4244) … … 88 88 } 89 89 90 #if ORXONOX_COMPILER ==ORXONOX_COMPILER_MSVC90 #ifdef ORXONOX_COMPILER_MSVC 91 91 # pragma warning(pop) 92 92 #endif -
code/trunk/src/util/Exception.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/util/Exception.cc (added) merged: 2509-2510 /code/branches/buildsystem3/src/util/Exception.cc (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/util/Exception.h
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/util/Exception.h (added) merged: 2509-2510 /code/branches/buildsystem3/src/util/Exception.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/util/Math.h
r2662 r2710 52 52 53 53 //Get around Windows hackery 54 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN3254 #ifdef ORXONOX_PLATFORM_WINDOWS 55 55 # ifdef max 56 56 # undef max -
code/trunk/src/util/OutputBuffer.cc
r2171 r2710 68 68 OutputBuffer& OutputBuffer::operator<<(std::ostream& (*manipulator)(std::ostream&)) 69 69 { 70 71 72 70 this->stream_ << manipulator; 71 this->callListeners(); 72 return *this; 73 73 } 74 74 … … 79 79 OutputBuffer& OutputBuffer::operator<<(std::ios& (*manipulator)(std::ios&)) 80 80 { 81 82 83 81 this->stream_ << manipulator; 82 this->callListeners(); 83 return *this; 84 84 } 85 85 … … 90 90 OutputBuffer& OutputBuffer::operator<<(std::ios_base& (*manipulator)(std::ios_base&)) 91 91 { 92 93 94 92 this->stream_ << manipulator; 93 this->callListeners(); 94 return *this; 95 95 } 96 96 -
code/trunk/src/util/OutputHandler.cc
r2662 r2710 33 33 34 34 #include "OutputHandler.h" 35 #include <time.h> 35 36 #include <ctime> 37 #include <cstdlib> 36 38 37 39 namespace orxonox … … 41 43 @param logfilename The name of the logfile 42 44 */ 43 OutputHandler::OutputHandler(const std::string& logfilename) 44 { 45 OutputHandler::OutputHandler() 46 { 47 #ifdef ORXONOX_PLATFORM_WINDOWS 48 char* pTempDir = getenv("TEMP"); 49 this->logfilename_ = std::string(pTempDir) + "/orxonox.log"; 50 #else 51 this->logfilename_ = "/tmp/orxonox.log"; 52 #endif 53 #ifdef NDEBUG 54 this->softDebugLevel_[LD_All] = this->softDebugLevel_[LD_Logfile] = 2; 55 this->softDebugLevel_[LD_Console] = this->softDebugLevel_[LD_Shell] = 1; 56 #else 57 this->softDebugLevel_[LD_All] = this->softDebugLevel_[LD_Logfile] = 3; 58 this->softDebugLevel_[LD_Console] = this->softDebugLevel_[LD_Shell] = 2; 59 #endif 60 45 61 this->outputBuffer_ = &this->fallbackBuffer_; 46 this->softDebugLevel_[0] = this->softDebugLevel_[1] = this->softDebugLevel_[2] = this->softDebugLevel_[3] = 2;47 this->logfilename_ = logfilename;48 62 this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); 49 63 … … 53 67 timeinfo = localtime(&rawtime); 54 68 55 this->logfile_ << "Started log at" << asctime(timeinfo) << std::endl;69 this->logfile_ << "Started log on " << asctime(timeinfo) << std::endl; 56 70 this->logfile_.flush(); 57 71 } … … 72 86 OutputHandler& OutputHandler::getOutStream() 73 87 { 74 static OutputHandler orxout ("orxonox.log");88 static OutputHandler orxout; 75 89 return orxout; 76 90 } … … 112 126 113 127 /** 128 @brief Sets the path where to create orxonox.log 129 @param Path string with trailing slash 130 */ 131 void OutputHandler::setLogPath(const std::string& path) 132 { 133 OutputHandler::getOutStream().logfile_.close(); 134 // store old content 135 std::ifstream old; 136 old.open(OutputHandler::getOutStream().logfilename_.c_str()); 137 OutputHandler::getOutStream().logfilename_ = path + "orxonox.log"; 138 OutputHandler::getOutStream().logfile_.open(OutputHandler::getOutStream().logfilename_.c_str(), std::fstream::out); 139 OutputHandler::getOutStream().logfile_ << old.rdbuf(); 140 old.close(); 141 OutputHandler::getOutStream().logfile_.flush(); 142 } 143 144 /** 114 145 @brief Overloaded << operator, redirects the output to the console and the logfile. 115 146 @param sb The streambuffer that should be shown in the console -
code/trunk/src/util/OutputHandler.h
r2662 r2710 101 101 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 102 102 103 static void setLogPath(const std::string& path); 104 103 105 void setOutputBuffer(OutputBuffer* buffer); 104 106 … … 142 144 143 145 private: 144 explicit OutputHandler( const std::string& logfilename);145 OutputHandler(const OutputHandler& oh); // don't copy146 explicit OutputHandler(); 147 OutputHandler(const OutputHandler& oh); 146 148 virtual ~OutputHandler(); 147 149 -
code/trunk/src/util/SignalHandler.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/util/SignalHandler.cc (added) merged: 2596,2639 /code/branches/buildsystem3/src/util/SignalHandler.cc (added) merged: 2664,2685
r2662 r2710 44 44 } 45 45 46 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN3246 #ifdef ORXONOX_PLATFORM_LINUX 47 47 48 48 #include <wait.h> … … 159 159 } 160 160 161 COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox .log" << std::endl;161 COUT(0) << "recieved signal " << sigName.c_str() << std::endl << "try to write backtrace to file orxonox_crash.log" << std::endl; 162 162 163 163 int sigPipe[2]; … … 353 353 } 354 354 355 #endif /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32*/355 #endif /* ORXONOX_PLATFORM_LINUX */ - Property svn:mergeinfo changed
-
code/trunk/src/util/SignalHandler.h
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/util/SignalHandler.h (added) merged: 2596,2639 /code/branches/buildsystem3/src/util/SignalHandler.h (added) merged: 2664
r2662 r2710 46 46 } 47 47 48 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN3248 #ifdef ORXONOX_PLATFORM_LINUX 49 49 #include <signal.h> 50 50 … … 97 97 } 98 98 99 #else /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32*/99 #else /* ORXONOX_PLATFORM_LINUX */ 100 100 101 101 namespace orxonox … … 116 116 } 117 117 118 #endif /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32*/118 #endif /* ORXONOX_PLATFORM_LINUX */ 119 119 120 120 #endif /* _SignalHandler_H__ */ - Property svn:mergeinfo changed
-
code/trunk/src/util/Sleep.h
r2171 r2710 36 36 #define _Sleep_H__ 37 37 38 #include " OrxonoxPlatform.h"38 #include "UtilPrereqs.h" 39 39 40 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN3240 #ifdef ORXONOX_PLATFORM_WINDOWS 41 41 #include <winbase.h> 42 42 -
code/trunk/src/util/UtilPrereqs.h
r2171 r2710 35 35 #define _UtilPrereqs_H__ 36 36 37 #include " util/OrxonoxPlatform.h"37 #include "OrxonoxConfig.h" 38 38 39 39 //----------------------------------------------------------------------- 40 40 // Shared library settings 41 41 //----------------------------------------------------------------------- 42 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( UTIL_STATIC_BUILD )42 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( UTIL_STATIC_BUILD ) 43 43 # ifdef UTIL_SHARED_BUILD 44 44 # define _UtilExport __declspec(dllexport)
Note: See TracChangeset
for help on using the changeset viewer.