Changeset 2509 for code/branches/buildsystem2
- Timestamp:
- Dec 17, 2008, 8:59:48 PM (16 years ago)
- Location:
- code/branches/buildsystem2
- Files:
-
- 2 added
- 30 deleted
- 83 edited
- 33 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem2
- Property svn:ignore deleted
- Property svn:mergeinfo changed
/code/branches/buildsystem (added) merged: 1875,1882-1886,1975-1982,1991,1999,2054,2061,2135,2137-2139,2197-2199,2204,2214-2220,2223-2224,2229,2233-2244,2248-2249,2252-2253,2260,2275
-
code/branches/buildsystem2/CMakeLists.txt
r1889 r2509 1 1 PROJECT(Orxonox) 2 2 3 cmake_minimum_required(VERSION 2.4) 4 5 IF (COMMAND cmake_policy) 6 cmake_policy(SET CMP0003 NEW) 7 ENDIF (COMMAND cmake_policy) 8 9 # Allow for simple IF constructs (makes code a lot more readable) 10 #SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) 3 CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR) 11 4 12 5 # This sets where to look for modules (e.g. "Find*.cmake" files) 13 6 SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 14 7 15 # Check whether we are on a tardis box8 # Check for special include paths 16 9 INCLUDE(CheckTardis) 10 INCLUDE(CheckOrxonoxWinDeps) 17 11 12 ################ Test options ################### 18 13 19 ############## Testing options ################## 14 OPTION(ENABLE_TESTS "Enable build tests.") 15 IF(ENABLE_TESTS) 16 ENABLE_TESTING() 17 ENDIF(ENABLE_TESTS) 20 18 21 OPTION(TESTING_ENABLED "Do you want to enable Testing") 22 IF (TESTING_ENABLED) 23 ENABLE_TESTING() 24 ENDIF(TESTING_ENABLED) 25 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") 28 19 OPTION(NETWORK_TESTING_ENABLED "Build network testing tools: i.e. chatclient chatserver and alike.") 20 OPTION(NETWORKTRAFFIC_TESTING_ENABLED "Build dummyserver4 and dummyclient4.") 29 21 30 22 ########## Compiler/Linker options ############## 31 23 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) 24 # Set binary output directories 25 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 26 SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 27 MARK_AS_ADVANCED(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH) 44 28 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") 29 # Compiler/Linker flags. 30 IF(NOT CMAKE_BUILD_TYPE) 31 SET(CMAKE_BUILD_TYPE "Debug") 32 ENDIF(NOT CMAKE_BUILD_TYPE) 33 SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -Wall -Wextra -Wno-unused-parameter") 34 SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall -Wextra -Wno-unused-parameter") 35 SET(CMAKE_C_FLAGS_DEBUG "-g -ggdb") 36 SET(CMAKE_CXX_FLAGS_DEBUG "-g -ggdb") 37 SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") 38 SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") 39 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g -ggdb") 40 SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g -ggdb") 41 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG") 42 SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 54 43 55 44 SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}") … … 58 47 SET(CMAKE_MODULE_LINKER_FLAGS " --no-undefined") 59 48 60 # Use 'cmake -D make_verb:1 path' to get verbose make output when compiling61 IF (MAKE_VERB)62 SET(CMAKE_VERBOSE_MAKEFILE TRUE)63 ENDIF (MAKE_VERB)64 65 66 49 ############### Library finding ################# 67 50 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 51 # Performs the search and sets the variables 52 FIND_PACKAGE(OGRE REQUIRED) 53 FIND_PACKAGE(CEGUI REQUIRED) 54 # CEGUI_OGRE included in source 55 #FIND_PACKAGE(CEGUI_OGRE REQUIRED) 56 FIND_PACKAGE(ENet REQUIRED) 57 FIND_PACKAGE(Boost 1.34 REQUIRED thread filesystem) 58 FIND_PACKAGE(OpenAL REQUIRED) 59 FIND_PACKAGE(ALUT REQUIRED) 60 FIND_PACKAGE(OggVorbis REQUIRED) 61 FIND_PACKAGE(ZLIB REQUIRED) 62 FIND_PACKAGE(DirectX REQUIRED) 63 FIND_PACKAGE(Lua50 REQUIRED) 64 #FIND_PACKAGE(Lua51 QUIET) 70 65 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 ) 66 #don't require the whole tcl rat tail 67 FIND_PACKAGE(TCL QUIET) 68 IF(NOT TCL_FOUND) 69 MESSAGE(FATAL_ERROR "Tcl not found.") 70 ENDIF(NOT TCL_FOUND) 128 71 129 72 # Add main source dir 130 73 ADD_SUBDIRECTORY(src) 131 74 ADD_SUBDIRECTORY(bin) -
code/branches/buildsystem2/cmake/CheckTardis.cmake
r1505 r2509 6 6 # only run this test on a lunix/unix machine 7 7 IF (UNIX) 8 9 8 FIND_PROGRAM(UNAME_CMD "uname" 10 9 PATHS "/usr/bin /bin") … … 30 29 31 30 ENDIF (UNIX) 31 32 MARK_AS_ADVANCED(IS_TARDIS) 33 34 IF (IS_TARDIS) 35 MESSAGE(STATUS "Running on D-ITET isg.ee Tardis Computer. Using customized paths.") 36 SET(CMAKE_C_COMPILER "gcc-4.1") 37 SET(CMAKE_CXX_COMPILER "g++-4.1") 38 #SET(Boost_ADDITIONAL_VERSIONS "1.36") 39 SET(BOOST_INCLUDEDIR "/usr/pack/boost-1.34.1-sd/include") 40 SET(BOOST_LIBRARYDIR "/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/lib") 41 SET(ENV{LUA_DIR} "/usr/pack/lua-5.0.3-sd;/usr/pack/lua-5.0.3-sd/i686-debian-linux3.1") 42 SET(ENV{ALUTDIR} "/usr/pack/openal-0.0.8-cl;/usr/pack/openal-0.0.8-cl/i686-debian-linux3.1") 43 SET(ENV{OPENALDIR} "/usr/pack/openal-0.0.8-cl;/usr/pack/openal-0.0.8-cl/i686-debian-linux3.1") 44 SET(ENV{ENETDIR} "/usr/pack/enet-2007-sd;/usr/pack/enet-2007-sd/i686-debian-linux3.1") 45 SET(ENV{OGGVORBISDIR} "/usr/pack/oggvorbis-1.0-ds;/usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0") 46 #SET(TCL_INCLUDE_PATH "/usr/pack/tcltk-8.4.9.linux-mo/include") 47 SET(ENV{CEGUIDIR} "/usr/pack/cegui-0.5.0-sd;/usr/pack/cegui-0.5.0-sd/i686-debian-linux3.1") 48 SET(ENV{OGREDIR} "/usr/pack/ogre-1.4.5-sd;/usr/pack/ogre-1.4.5-sd/i686-debian-linux3.1") 49 ENDIF (IS_TARDIS) 50 51 MARK_AS_ADVANCED(UNAME_CMD IS_TARDIS) -
code/branches/buildsystem2/cmake/FindALUT.cmake
r1872 r2509 18 18 # 19 19 # Several changes and additions by Fabian 'x3n' Landau 20 # Some simplifications by Adrian Friedli 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)25 26 23 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 24 PATHS 25 $ENV{ALUTDIR} 26 ~/Library/Frameworks/OpenAL.framework 27 /Library/Frameworks/OpenAL.framework 28 /System/Library/Frameworks/OpenAL.framework # Tiger 29 /usr/local 30 /usr 31 /sw # Fink 32 /opt/local # DarwinPorts 33 /opt/csw # Blastwave 34 /opt 35 PATH_SUFFIXES include include/OpenAL include/AL Headers 52 36 ) 53 37 … … 78 62 NAMES alut 79 63 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 64 $ENV{ALUTDIR} 65 /usr/local 66 /usr 67 /sw 68 /opt/local 69 /opt/csw 70 /opt 71 PATH_SUFFIXES lib libs 92 72 ) 93 73 ENDIF(${ALUT_INCLUDE_DIR} MATCHES ".framework") 94 74 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) 75 # handle the QUIETLY and REQUIRED arguments and set ALUT_FOUND to TRUE if 76 # all listed variables are TRUE 77 INCLUDE(FindPackageHandleStandardArgs) 78 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALUT DEFAULT_MSG ALUT_LIBRARY ALUT_INCLUDE_DIR) 114 79 115 80 MARK_AS_ADVANCED(ALUT_LIBRARY ALUT_INCLUDE_DIR) -
code/branches/buildsystem2/cmake/FindCEGUI.cmake
r1872 r2509 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 8 7 # … … 17 16 # 18 17 # Several changes and additions by Fabian 'x3n' Landau 18 # Lots of simplifications by Adrian Friedli 19 19 # > www.orxonox.net < 20 20 21 IF (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) 21 # TODO: Determine CEGUI version 24 22 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 ) 23 FIND_PATH(CEGUI_INCLUDE_DIR CEGUI.h 24 PATHS 25 $ENV{CEGUIDIR} 26 /usr/local 27 /usr 28 PATH_SUFFIXES include include/CEGUI 29 ) 30 30 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 ) 36 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) 31 #SET(CEGUI_LIBRARIES debug CEGUIBase_d optimized CEGUIBase) 32 FIND_LIBRARY(CEGUI_LIBRARY 33 NAMES CEGUIBase 34 PATHS 35 $ENV{CEGUIDIR} 36 /usr/local 37 /usr 38 PATH_SUFFIXES lib 39 ) 42 40 43 41 # IF (NOT CEGUI_SCRIPT_LIBDIR) … … 58 56 # ENDIF (NOT CEGUI_SCRIPT_LIBDIR) 59 57 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) 58 INCLUDE(FindPackageHandleStandardArgs) 59 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CEGUI DEFAULT_MSG 60 CEGUI_LIBRARY 61 CEGUI_INCLUDE_DIR 62 #CEGUI_SCRIPT_LIBRARIES 63 ) 65 64 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) 75 76 IF (CEGUI_INCLUDE_DIR AND CEGUI_LIBRARIES AND CEGUI_LIB_DIR)# AND CEGUI_SCRIPT_LIBRARIES) 77 SET(CEGUI_FOUND TRUE) 78 79 #Do some preparation 80 SEPARATE_ARGUMENTS(CEGUI_INCLUDE_DIR) 81 SEPARATE_ARGUMENTS(CEGUI_LIBRARIES) 82 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) 88 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) 113 65 MARK_AS_ADVANCED( 66 CEGUI_LIBRARY 67 CEGUI_INCLUDE_DIR 68 #CEGUI_SCRIPT_LIBRARIES 69 ) -
code/branches/buildsystem2/cmake/FindENet.cmake
r1872 r2509 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_LIBRARIES - the libraries needed to use 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 13 15 # > www.orxonox.net < 14 16 15 IF (ENet_INCLUDE_DIR AND ENet_LIBRARY)16 SET(ENet_FIND_QUIETLY TRUE)17 ENDIF (ENet_INCLUDE_DIR AND ENet_LIBRARY)18 19 17 FIND_PATH(ENet_INCLUDE_DIR enet/enet.h 20 /usr/include21 /usr/local/include22 /usr/ pack/enet-2007-sd/include23 ../libs/enet-1.1/include24 ${DEPENDENCY_DIR}/enet-1.2/include18 PATHS 19 $ENV{ENETDIR} 20 /usr/local 21 /usr 22 PATH_SUFFIXES include 25 23 ) 26 24 27 25 FIND_LIBRARY(ENet_LIBRARY 28 26 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 27 PATHS 28 $ENV{ENETDIR} 29 /usr/local 30 /usr 31 PATH_SUFFIXES lib 32 32 ) 33 33 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})34 # handle the QUIETLY and REQUIRED arguments and set ENET_FOUND to TRUE if 35 # all listed variables are TRUE 36 INCLUDE(FindPackageHandleStandardArgs) 37 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ENet DEFAULT_MSG ENet_LIBRARY ENet_INCLUDE_DIR) 38 38 39 IF (ENET_FOUND) 39 40 IF(WIN32) 40 41 SET(WINDOWS_ENET_DEPENDENCIES "ws2_32;winmm") 41 SET(ENet_LIBRARY ${ENet_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES}) 42 SET(ENet_LIBRARIES ${ENet_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES}) 43 ELSE(WIN32) 44 SET(ENet_LIBRARIES ${ENet_LIBRARY}) 42 45 ENDIF(WIN32) 43 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 46 ENDIF (ENET_FOUND) 64 47 65 MARK_AS_ADVANCED(ENet_ INCLUDE_DIR ENet_LIBRARY)48 MARK_AS_ADVANCED(ENet_LIBRARY ENet_INCLUDE_DIR) -
code/branches/buildsystem2/cmake/FindOGRE.cmake
r1872 r2509 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 # … … 13 12 # 14 13 # Several changes and additions by Fabian 'x3n' Landau 14 # Lots of simplifications by Adrian Friedli 15 15 # > www.orxonox.net < 16 16 17 IF (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) 17 FIND_PATH(OGRE_INCLUDE_DIR Ogre.h 18 PATHS 19 $ENV{OGREDIR} 20 /usr/local 21 /usr 22 PATH_SUFFIXES include include/OGRE 23 ) 20 24 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 ) 25 #SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain) 26 FIND_LIBRARY(OGRE_LIBRARY 27 NAMES OgreMain 28 PATHS 29 $ENV{OGREDIR} 30 /usr/local 31 /usr 32 PATH_SUFFIXES lib 33 ) 26 34 27 SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain)28 FIND_LIBRARY(OGRE_LIBDIR NAMES ${OGRE_LIBRARIES} PATHS 29 ../libs/ogre/Samples/Common/bin/Release30 ${DEPENDENCY_DIR}/ogre-1.4.9/lib31 35 INCLUDE(FindPackageHandleStandardArgs) 36 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGRE DEFAULT_MSG 37 OGRE_LIBRARY 38 OGRE_INCLUDE_DIR 39 ) 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) 45 46 #Do some preparation 47 SEPARATE_ARGUMENTS(OGRE_INCLUDE_DIR) 48 SEPARATE_ARGUMENTS(OGRE_LIBRARIES) 49 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) 41 MARK_AS_ADVANCED( 42 OGRE_LIBRARY 43 OGRE_INCLUDE_DIR 44 ) -
code/branches/buildsystem2/cmake/FindOggVorbis.cmake
r1873 r2509 1 # - Try to find ogg/vorbis 2 # Once done this will define 3 # 4 # OGG_FOUND - system has ogg 5 # OGG_INCLUDE_DIR 6 # OGG_LIBRARY 7 # VORBIS_FOUND - system has vorbis 8 # VORBIS_INCLUDE_DIR 9 # VORBIS_LIBRARY 10 # VORBISENC_LIBRARY 11 # VORBISFILE_LIBRARY 12 # 13 # $OGGVORBISDIR is an environment variable used for finding ogg/vorbis. 14 # 1 15 # Several changes and additions by Fabian 'x3n' Landau 16 # Most of all rewritten by Adrian Friedli 2 17 # > www.orxonox.net < 3 18 4 IF (OGG_INCLUDE_DIR AND OGG_LIBRARY) 5 SET(OGG_FIND_QUIETLY TRUE) 6 ENDIF (OGG_INCLUDE_DIR AND OGG_LIBRARY) 7 8 IF (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISENC_LIBRARY AND VORBISFILE_LIBRARY) 9 SET(VORBIS_FIND_QUIETLY TRUE) 10 ENDIF (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISENC_LIBRARY AND VORBISFILE_LIBRARY) 11 12 13 #SET(OGGVORBIS_LIBRARY_DIR "/usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0/lib") 14 #SET(OGGVORBIS_LIBRARY "-L ${OGGVORBIS_LIBRARY_DIR} -lvorbisenc -lvorbisfile -logg -lvorbis ") 15 #SET(OGGVORBIS_INCLUDE_DIR "/usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0/include") 16 17 # 18 # Includes 19 # 19 SET(OGG_SEARCH_PATHS 20 $ENV{OGGVORBISDIR} 21 /usr/local 22 /usr 23 /sw 24 /opt/local 25 /opt/csw 26 /opt 27 ) 20 28 21 29 FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h 22 /usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0/include # Tardis specific hack 23 /usr/local/include 24 /usr/include 25 /sw/include 26 /opt/local/include 27 /opt/csw/include 28 /opt/csw/include 29 /opt/include 30 ../libs/libogg-1.1.3/include 31 ${DEPENDENCY_DIR}/libogg-1.1.3/include 32 ) 30 PATHS ${OGG_SEARCH_PATHS} 31 PATH_SUFFIXES include 32 ) 33 33 34 34 FIND_PATH(VORBIS_INCLUDE_DIR vorbis/codec.h 35 /usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0/include # Tardis specific hack 36 /usr/local/include 37 /usr/include 38 /sw/include 39 /opt/local/include 40 /opt/csw/include 41 /opt/csw/include 42 /opt/include 43 ../libs/libvorbis-1.2.0/include 44 ${DEPENDENCY_DIR}/libvorbis-1.2.0/include 45 ) 35 PATHS ${OGG_SEARCH_PATHS} 36 PATH_SUFFIXES include 37 ) 46 38 47 # 48 # Libs 49 # 39 FIND_LIBRARY(OGG_LIBRARY NAMES ogg 40 PATHS ${OGG_SEARCH_PATHS} 41 PATH_SUFFIXES lib 42 ) 50 43 51 FIND_LIBRARY(OGG_LIBRARY 52 NAMES ogg 53 PATHS 54 /usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.1/lib 55 /usr/local/lib 56 /usr/lib 57 /sw/lib 58 /opt/local/lib 59 /opt/csw/lib 60 /opt/lib 61 ../libs/libogg-1.1.3/src/.libs 62 ${DEPENDENCY_DIR}/libogg-1.1.3/lib 63 ) 44 FIND_LIBRARY(VORBIS_LIBRARY NAMES vorbis 45 PATHS ${OGG_SEARCH_PATHS} 46 PATH_SUFFIXES lib 47 ) 64 48 65 FIND_LIBRARY(VORBIS_LIBRARY 66 NAMES vorbis 67 PATHS 68 /usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.1/lib 69 /usr/local/lib 70 /usr/lib 71 /sw/lib 72 /opt/local/lib 73 /opt/csw/lib 74 /opt/lib 75 ../libs/libvorbis-1.2.0/lib/.libs 76 ${DEPENDENCY_DIR}/libvorbis-1.2.0/lib 77 ) 49 #FIND_LIBRARY(VORBISENC_LIBRARY NAMES vorbisenc 50 # PATHS ${OGG_SEARCH_PATHS} 51 # PATH_SUFFIXES lib 52 #) 78 53 79 #FIND_LIBRARY(VORBISENC_LIBRARY 80 # NAMES vorbisenc 81 # PATHS 82 # /usr/pack/oggvorbis-1.0-ds/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/libvorbis-1.2.0/lib/.libs 90 # ) 54 FIND_LIBRARY(VORBISFILE_LIBRARY NAMES vorbisfile 55 PATHS ${OGG_SEARCH_PATHS} 56 PATH_SUFFIXES lib 57 ) 91 58 92 FIND_LIBRARY(VORBISFILE_LIBRARY 93 NAMES vorbisfile 94 PATHS 95 /usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.1/lib 96 /usr/local/lib 97 /usr/lib 98 /sw/lib 99 /opt/local/lib 100 /opt/csw/lib 101 /opt/lib 102 ../libs/libvorbis-1.2.0/lib/.libs 103 ${DEPENDENCY_DIR}/libvorbis-1.2.0/lib 104 ) 59 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE if 60 # all listed variables are TRUE 61 INCLUDE(FindPackageHandleStandardArgs) 62 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGG DEFAULT_MSG OGG_LIBRARY OGG_INCLUDE_DIR) 63 FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBIS DEFAULT_MSG 64 VORBIS_LIBRARY 65 VORBISFILE_LIBRARY 66 #VORBISENC_LIBRARY 67 VORBIS_INCLUDE_DIR 68 ) 105 69 106 SET (OGG_FOUND "NO") 107 108 IF (OGG_INCLUDE_DIR AND OGG_LIBRARY) 109 SET (OGG_FOUND "YES") 110 IF (NOT OGG_FIND_QUIETLY) 111 MESSAGE (STATUS "Ogg was found.") 112 IF (VERBOSE_FIND) 113 MESSAGE (STATUS " include path: ${OGG_INCLUDE_DIR}") 114 MESSAGE (STATUS " library path: ${OGG_LIBRARY}") 115 MESSAGE (STATUS " libraries: ogg") 116 ENDIF (VERBOSE_FIND) 117 ENDIF (NOT OGG_FIND_QUIETLY) 118 ELSE (OGG_INCLUDE_DIR AND OGG_LIBRARY) 119 IF (NOT OGG_INCLUDE_DIR) 120 MESSAGE (SEND_ERROR "Ogg include path was not found.") 121 ENDIF (NOT OGG_INCLUDE_DIR) 122 IF (NOT OGG_LIBRARY) 123 MESSAGE (SEND_ERROR "Ogg library was not found.") 124 ENDIF (NOT OGG_LIBRARY) 125 ENDIF (OGG_INCLUDE_DIR AND OGG_LIBRARY) 126 127 128 SET (VORBIS_FOUND "NO") 129 130 IF (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY)# AND VORBISENC_LIBRARY) 131 SET (VORBIS_FOUND "YES") 132 IF (NOT VORBIS_FIND_QUIETLY) 133 MESSAGE (STATUS "Vorbis was found.") 134 IF (VERBOSE_FIND) 135 MESSAGE (STATUS " include path: ${VORBIS_INCLUDE_DIR}") 136 MESSAGE (STATUS " library path: ${VORBIS_LIBRARY}") 137 #MESSAGE (STATUS " library path: ${VORBISENC_LIBRARY}") 138 MESSAGE (STATUS " library path: ${VORBISFILE_LIBRARY}") 139 MESSAGE (STATUS " libraries: vorbis vorbisenc vorbisfile") 140 ENDIF (VERBOSE_FIND) 141 ENDIF (NOT VORBIS_FIND_QUIETLY) 142 ELSE (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY)# AND VORBISENC_LIBRARY) 143 IF (NOT VORBIS_INCLUDE_DIR) 144 MESSAGE (SEND_ERROR "Vorbis include path was not found.") 145 ENDIF (NOT VORBIS_INCLUDE_DIR) 146 IF (NOT VORBIS_LIBRARY) 147 MESSAGE (SEND_ERROR "Vorbis library \"vorbis\" was not found.") 148 ENDIF (NOT VORBIS_LIBRARY) 149 #IF (NOT VORBISENC_LIBRARY) 150 # MESSAGE (SEND_ERROR "Vorbis library \"vorbisenc\" was not found.") 151 #ENDIF (NOT VORBISENC_LIBRARY) 152 IF (NOT VORBISFILE_LIBRARY) 153 MESSAGE (SEND_ERROR "Vorbis library \"vorbisfile\" was not found.") 154 ENDIF (NOT VORBISFILE_LIBRARY) 155 ENDIF (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY)# AND VORBISENC_LIBRARY) 156 70 MARK_AS_ADVANCED( 71 OGG_LIBRARY 72 OGG_INCLUDE_DIR 73 VORBIS_LIBRARY 74 VORBISFILE_LIBRARY 75 VORBIS_INCLUDE_DIR 76 ) -
code/branches/buildsystem2/run
r1506 r2509 1 #!/bin/ bash2 cd bin 3 ./run-script $@ 4 cd ..1 #!/bin/sh 2 # convenience script for starting orxonox 3 4 cd build/bin && exec ./run-script $@ -
code/branches/buildsystem2/src/CMakeLists.txt
r2129 r2509 1 INCLUDE_DIRECTORIES(.) 2 INCLUDE_DIRECTORIES(..) 3 INCLUDE_DIRECTORIES(orxonox) 1 # Set the search paths for include files 2 INCLUDE_DIRECTORIES( 3 ${OGRE_INCLUDE_DIR} 4 ${CEGUI_INCLUDE_DIR} 5 # ${CEGUI_OGRE_INCLUDE_DIR} 6 ${ENet_INCLUDE_DIR} 7 ${Boost_INCLUDE_DIRS} 8 ${OPENAL_INCLUDE_DIR} 9 ${ALUT_INCLUDE_DIR} 10 ${VORBIS_INCLUDE_DIR} 11 ${OGG_INCLUDE_DIR} 12 ${LUA_INCLUDE_DIR} 13 ${TCL_INCLUDE_PATH} 14 ${DirectX_INCLUDE_DIR} 15 ${ZLIB_INCLUDE_DIR} 16 ) 17 18 INCLUDE_DIRECTORIES( 19 . 20 ois 21 orxonox 22 tolua 23 # Required for tolua bind files that are in the build folder 24 ${CMAKE_CURRENT_BINARY_DIR} 25 ) 26 27 # Set special macro symbols across all libraries 28 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTIXML_USE_TICPP") 4 29 5 30 ADD_SUBDIRECTORY(cpptcl) 6 31 ADD_SUBDIRECTORY(ois) 7 32 ADD_SUBDIRECTORY(tinyxml) 8 ADD_SUBDIRECTORY(lua)9 33 ADD_SUBDIRECTORY(tolua) 10 34 35 # TODO: write include file for this stuff 11 36 # Some people may not have CEGUILua installed, espc. with version 0.5 12 37 # And we don't know what lua version it was linked against, so we compile … … 18 43 INCLUDE_DIRECTORIES(ceguilua-0.6.1) 19 44 ELSE (WIN32) 20 IF (${CEGUI_VERSION} LESS 0.6.0) 21 ADD_SUBDIRECTORY(ceguilua-0.5.0b/ceguilua) 22 INCLUDE_DIRECTORIES(ceguilua-0.5.0b) 23 ELSE (${CEGUI_VERSION} LESS 0.6.0) 24 ADD_SUBDIRECTORY(ceguilua-0.6.1/ceguilua) 25 INCLUDE_DIRECTORIES(ceguilua-0.6.1) 26 ENDIF (${CEGUI_VERSION} LESS 0.6.0) 45 # FIXME 46 #IF (${CEGUI_VERSION} LESS 0.6.0) 47 ADD_SUBDIRECTORY(ceguilua-0.5.0/ceguilua) 48 INCLUDE_DIRECTORIES(ceguilua-0.5.0) 49 #ELSE (${CEGUI_VERSION} LESS 0.6.0) 50 # ADD_SUBDIRECTORY(ceguilua-0.6.1/ceguilua) 51 # INCLUDE_DIRECTORIES(ceguilua-0.6.1) 52 #ENDIF (${CEGUI_VERSION} LESS 0.6.0) 27 53 ENDIF (WIN32) 28 54 -
code/branches/buildsystem2/src/ceguilua-0.6.1/ceguilua/CEGUILua.cpp
r1810 r2509 28 28 * OTHER DEALINGS IN THE SOFTWARE. 29 29 ***************************************************************************/ 30 #ifdef HAVE_CONFIG_H 31 # include "config.h" 32 #endif 30 33 31 34 #include "CEGUI.h" … … 37 40 38 41 // include Lua libs and tolua++ 39 #include "lua/lua.hpp" 40 #include "tolua/tolua++.h" 42 extern "C" { 43 #include "lua.h" 44 #include "lualib.h" 45 #include "lauxlib.h" 46 } 47 48 #include "tolua++.h" 41 49 42 50 // prototype for bindings initialisation function … … 53 61 LuaScriptModule::LuaScriptModule() 54 62 { 55 static const luaL_Reg lualibs[] = { 56 {"", luaopen_base}, 57 {LUA_LOADLIBNAME, luaopen_package}, 58 {LUA_TABLIBNAME, luaopen_table}, 59 {LUA_IOLIBNAME, luaopen_io}, 60 {LUA_OSLIBNAME, luaopen_os}, 61 {LUA_STRLIBNAME, luaopen_string}, 62 {LUA_MATHLIBNAME, luaopen_math}, 63 #if defined(DEBUG) || defined (_DEBUG) 64 {LUA_DBLIBNAME, luaopen_debug}, 65 #endif 66 {0, 0} 67 }; 63 #if LUA_VERSION_NUM >= 501 64 static const luaL_Reg lualibs[] = { 65 {"", luaopen_base}, 66 {LUA_LOADLIBNAME, luaopen_package}, 67 {LUA_TABLIBNAME, luaopen_table}, 68 {LUA_IOLIBNAME, luaopen_io}, 69 {LUA_OSLIBNAME, luaopen_os}, 70 {LUA_STRLIBNAME, luaopen_string}, 71 {LUA_MATHLIBNAME, luaopen_math}, 72 #if defined(DEBUG) || defined (_DEBUG) 73 {LUA_DBLIBNAME, luaopen_debug}, 74 #endif 75 {0, 0} 76 }; 77 #endif /* CEGUI_LUA_VER >= 51 */ 68 78 69 79 // create a lua state … … 72 82 73 83 // init all standard libraries 74 const luaL_Reg *lib = lualibs; 75 for (; lib->func; lib++) 76 { 77 lua_pushcfunction(d_state, lib->func); 78 lua_pushstring(d_state, lib->name); 79 lua_call(d_state, 1, 0); 80 } 84 #if LUA_VERSION_NUM >= 501 85 const luaL_Reg *lib = lualibs; 86 for (; lib->func; lib++) 87 { 88 lua_pushcfunction(d_state, lib->func); 89 lua_pushstring(d_state, lib->name); 90 lua_call(d_state, 1, 0); 91 } 92 #else /* CEGUI_LUA_VER >= 51 */ 93 luaopen_base(d_state); 94 luaopen_io(d_state); 95 luaopen_string(d_state); 96 luaopen_table(d_state); 97 luaopen_math(d_state); 98 #if defined(DEBUG) || defined (_DEBUG) 99 luaopen_debug(d_state); 100 #endif 101 #endif /* CEGUI_LUA_VER >= 51 */ 81 102 82 103 setModuleIdentifierString(); -
code/branches/buildsystem2/src/ceguilua-0.6.1/ceguilua/CEGUILuaFunctor.cpp
r1810 r2509 34 34 35 35 // include Lua libs and tolua++ 36 #include "lua/lua.hpp" 37 #include "tolua/tolua++.h" 36 extern "C" { 37 #include "lua.h" 38 #include "lualib.h" 39 #include "lauxlib.h" 40 } 41 42 #include "tolua++.h" 38 43 39 44 // Start of CEGUI namespace section -
code/branches/buildsystem2/src/ceguilua-0.6.1/ceguilua/CMakeLists.txt
r1854 r2509 1 INCLUDE_DIRECTORIES(.)2 3 1 SET( CEGUILUA_SRC_FILES 4 2 CEGUILua.cpp … … 11 9 12 10 TARGET_LINK_LIBRARIES(ceguilua_orxonox 13 lua_orxonox14 11 tolualib_orxonox 15 ${CEGUI_LIBRARIES} 12 ${LUA_LIBRARIES} 13 ${CEGUI_LIBRARY} 16 14 ) -
code/branches/buildsystem2/src/ceguilua-0.6.1/ceguilua/lua_CEGUI.cpp
r1810 r2509 9 9 #include "string.h" 10 10 11 #include "tolua /tolua++.h"11 #include "tolua++.h" 12 12 13 13 /* Exported function */ -
code/branches/buildsystem2/src/core/CMakeLists.txt
r2131 r2509 42 42 TclThreadManager.cc 43 43 44 tolua/tolua_bind.cc45 44 ) 46 45 47 46 ADD_SOURCE_DIRECTORY(CORE_SRC_FILES input) 48 47 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 ) 48 INCLUDE(UseTolua) 49 TOLUA(Core CORE_SRC_FILES INPUTFILES LuaBind.h CommandExecutor.h) 60 50 61 51 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES}) 62 52 63 53 TARGET_LINK_LIBRARIES(core 64 ${OGRE_LIBRAR IES}65 ${Boost_ thread_LIBRARIES}66 ${Boost_ filesystem_LIBRARIES}67 lua_orxonox54 ${OGRE_LIBRARY} 55 ${Boost_THREAD_LIBRARY} 56 ${Boost_FILESYSTEM_LIBRARY} 57 ${LUA_LIBRARIES} 68 58 cpptcl_orxonox 69 59 ois_orxonox -
code/branches/buildsystem2/src/core/CommandExecutor.h
r1771 r2509 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/branches/buildsystem2/src/core/LuaBind.cc
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem/src/core/Script.cc merged eligible /code/branches/questsystem2/src/core/LuaBind.cc merged eligible /code/branches/buildsystem/src/core/LuaBind.cc 1874-2276 /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/objecthierarchy/src/core/LuaBind.cc 1911-2085,2100,2110-2169 /code/branches/pickups/src/core/LuaBind.cc 1926-2086 /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
r2087 r2509 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++.h" 39 #include "core/ToluaBindCore.h" 37 40 #include "util/String.h" 38 41 #include "CoreIncludes.h" -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/branches/buildsystem2/src/core/LuaBind.h
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem/src/core/Script.h merged eligible /code/branches/questsystem2/src/core/LuaBind.h merged eligible /code/branches/buildsystem/src/core/LuaBind.h 1874-2276 /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/objecthierarchy/src/core/LuaBind.h 1911-2085,2100,2110-2169 /code/branches/pickups/src/core/LuaBind.h 1926-2086 /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
r2087 r2509 39 39 40 40 extern "C" { 41 #include <lua /lua.h>41 #include <lua.h> 42 42 } 43 43 … … 45 45 #include <string> 46 46 47 namespace orxonox // tolua_export 48 { // tolua_export 47 // tolua_begin 48 namespace orxonox 49 { 49 50 class _CoreExport LuaBind 50 51 { 51 /* 52 class LuaBind { // tolua_export 53 */ 52 53 // tolua_end 54 54 struct LoadS { 55 55 const char *s; -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/branches/buildsystem2/src/core/XMLIncludes.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/src/network/CMakeLists.txt
r2131 r2509 25 25 TARGET_LINK_LIBRARIES( network 26 26 ${ZLIB_LIBRARY} 27 ${ENet_LIBRAR Y}28 ${Boost_ thread_LIBRARIES}27 ${ENet_LIBRARIES} 28 ${Boost_THREAD_LIBRARY} 29 29 core 30 30 ) … … 39 39 ADD_EXECUTABLE(networktest ${TEST_SRC_FILES}) 40 40 TARGET_LINK_LIBRARIES( networktest 41 ${OGRE_LIBRAR IES}41 ${OGRE_LIBRARY} 42 42 network 43 ${ENet_LIBRAR Y}43 ${ENet_LIBRARIES} 44 44 ${ZLIB_LIBRARY} 45 ${WINDOWS_ENET_DEPENDENCIES}46 45 ) 47 46 ##### end test for gamestate stuff ##### -
code/branches/buildsystem2/src/ois/CMakeLists.txt
r1555 r2509 1 INCLUDE_DIRECTORIES(.)2 3 1 SET( OIS_SRC_FILES 4 2 OISEffect.cpp -
code/branches/buildsystem2/src/orxonox/CMakeLists.txt
r2171 r2509 6 6 PlayerManager.cc 7 7 Settings.cc 8 9 tolua/tolua_bind.cc10 8 ) 11 9 … … 16 14 ADD_SOURCE_DIRECTORY(ORXONOX_SRC_FILES tools) 17 15 18 GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION) 19 ADD_CUSTOM_COMMAND( 20 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h 21 COMMAND ${TOLUA_EXE} -n Orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg 22 DEPENDS 23 tolua_orxonox 24 tolua/tolua.pkg 25 gui/GUIManager.h 26 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib 27 ) 16 INCLUDE(UseTolua) 17 TOLUA(Orxonox ORXONOX_SRC_FILES INPUTFILES gui/GUIManager.h) 28 18 29 19 … … 42 32 43 33 TARGET_LINK_LIBRARIES( orxonox 44 ${OGRE_LIBRARIES} 45 ${CEGUI_LIBRARIES} 46 lua_orxonox 34 ${OGRE_LIBRARY} 35 ${CEGUI_LIBRARY} 36 ${LUA_LIBRARIES} 37 #${CEGUI_SCRIPT_LIBRARIES} 47 38 ceguilua_orxonox 48 39 tinyxml_orxonox … … 53 44 network 54 45 ) 55 -
code/branches/buildsystem2/src/orxonox/Settings.cc
r2087 r2509 63 63 void Settings::setConfigValues() 64 64 { 65 SetConfigValue(dataPath_, "../../ media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged);65 SetConfigValue(dataPath_, "../../../media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged); 66 66 } 67 67 -
code/branches/buildsystem2/src/orxonox/gamestates/GSGraphics.cc
r2171 r2509 44 44 #include "util/Debug.h" 45 45 #include "util/Exception.h" 46 #include "util/String.h" 47 #include "util/SubString.h" 46 48 #include "core/ConsoleCommand.h" 47 49 #include "core/ConfigValueIncludes.h" … … 96 98 SetConfigValue(ogreConfigFile_, "ogre.cfg") 97 99 .description("Location of the Ogre config file"); 98 SetConfigValue(ogrePluginsFile_, "plugins.cfg") 99 .description("Location of the Ogre plugins file"); 100 SetConfigValue(ogrePluginsFolder_, ".") 101 .description("Folder where the Ogre plugins are located."); 102 SetConfigValue(ogrePlugins_, "RenderSystem_GL, Plugin_ParticleFX") 103 .description("Comma separated list of all plugins to load."); 100 104 SetConfigValue(ogreLogFile_, "ogre.log") 101 105 .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation."); … … 121 125 // Ogre setup procedure 122 126 setupOgre(); 127 // load all the required plugins for Ogre 128 loadOgrePlugins(); 129 // read resource declaration file 123 130 this->declareResources(); 124 this->loadRenderer(); // creates the render window 131 // Reads ogre config and creates the render window 132 this->loadRenderer(); 133 125 134 // TODO: Spread this so that this call only initialises things needed for the Console and GUI 126 135 this->initialiseResources(); … … 345 354 probe.close(); 346 355 347 ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 356 // Leave plugins file empty. We're going to do that part manually later 357 ogreRoot_ = new Ogre::Root("", ogreConfigFile_, ogreLogFile_); 348 358 349 359 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.) … … 358 368 359 369 COUT(3) << "Ogre set up done." << std::endl; 370 } 371 372 void GSGraphics::loadOgrePlugins() 373 { 374 // just to make sure the next statement doesn't segfault 375 if (ogrePluginsFolder_ == "") 376 ogrePluginsFolder_ = "."; 377 378 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 379 convertToWindowsPath(&ogrePluginsFolder_); 380 #else 381 convertToUnixPath(&ogrePluginsFolder_); 382 #endif 383 384 // Do some SubString magic to get the comma separated list of plugins 385 SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0'); 386 for (unsigned int i = 0; i < plugins.size(); ++i) 387 ogreRoot_->loadPlugin(ogrePluginsFolder_ + plugins[i]); 360 388 } 361 389 -
code/branches/buildsystem2/src/orxonox/gamestates/GSGraphics.h
r2103 r2509 60 60 61 61 void setupOgre(); 62 void loadOgrePlugins(); 62 63 void declareResources(); 63 64 void loadRenderer(); … … 105 106 std::string resourceFile_; //!< resources file name 106 107 std::string ogreConfigFile_; //!< ogre config file name 107 std::string ogrePluginsFile_; //!< ogre plugins file name 108 std::string ogrePluginsFolder_; //!< Folder where the Ogre plugins are located 109 std::string ogrePlugins_; //!< Comma separated list of all plugins to load 108 110 std::string ogreLogFile_; //!< log file name for Ogre log messages 109 111 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL -
code/branches/buildsystem2/src/orxonox/gui/GUIManager.cc
r2087 r2509 39 39 #include <OgreRoot.h> 40 40 #include <CEGUI.h> 41 #include "ceguilua/CEGUILua.h"41 #include <CEGUILua.h> 42 42 #include "util/Exception.h" 43 43 #include "core/input/InputManager.h" 44 44 #include "core/input/SimpleInputState.h" 45 #include "core/tolua/tolua_bind.h"46 45 #include "core/ConsoleCommand.h" 47 46 #include "core/Core.h" 48 #include "tolua/tolua_bind.h" 47 #include "core/ToluaBindCore.h" 48 #include "orxonox/ToluaBindOrxonox.h" 49 49 #include "OgreCEGUIRenderer.h" 50 50 51 #include "lua/lua.hpp" 51 extern "C" { 52 #include "lua.h" 53 } 52 54 53 55 namespace orxonox -
code/branches/buildsystem2/src/orxonox/gui/GUIManager.h
r1887 r2509 42 42 #include "core/input/InputInterfaces.h" 43 43 44 namespace orxonox // tolua_export 45 { // tolua_export 44 // tolua_begin 45 namespace orxonox 46 { 46 47 /** 47 48 @brief 48 49 Provides a simple interface to CEGUI with tolua methods and console commands 49 50 */ 50 class _OrxonoxExport GUIManager : public KeyHandler, public MouseHandler51 /* 52 class GUIManager { // tolua_export53 */ 51 class _OrxonoxExport GUIManager 52 // tolua_end 53 : public KeyHandler, public MouseHandler 54 // tolua_begin 54 55 { 56 // tolua_end 55 57 public: 56 58 enum State -
code/branches/buildsystem2/src/tinyxml/ticpp.cc
r1625 r2509 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 http://code.google.com/p/ticpp/ … … 23 21 */ 24 22 25 /*26 Modifications by the orxonox team:27 In function: void Document::Parse( const std::string& xml, bool throwIfParseError, TiXmlEncoding encoding )28 change: Added row and column number to the error description.29 author: Reto Grieder30 */31 32 23 #ifdef TIXML_USE_TICPP 33 24 … … 164 155 165 156 Attribute* temp = new Attribute( attribute ); 166 m_spawnedWrappers.push_back( temp );157 attribute->m_spawnedWrappers.push_back( temp ); 167 158 168 159 return temp; … … 186 177 187 178 Attribute* temp = new Attribute( attribute ); 188 m_spawnedWrappers.push_back( temp );179 attribute->m_spawnedWrappers.push_back( temp ); 189 180 190 181 return temp; … … 262 253 if ( rememberSpawnedWrapper ) 263 254 { 264 m_spawnedWrappers.push_back( temp );255 tiXmlNode->m_spawnedWrappers.push_back( temp ); 265 256 } 266 257 return temp; … … 386 377 } 387 378 379 TiXmlNode* pointer = GetTiXmlPointer()->InsertEndChild( *addThis.GetTiXmlPointer() ); 380 if ( 0 == pointer ) 381 { 382 TICPPTHROW( "Node can't be inserted" ); 383 } 384 385 return NodeFactory( pointer ); 386 } 387 388 Node* Node::LinkEndChild( Node* childNode ) 389 { 390 if ( childNode->Type() == TiXmlNode::DOCUMENT ) 391 { 392 TICPPTHROW( "Node is a Document and can't be linked" ); 393 } 394 395 // Increment reference count when adding to the tree 396 childNode->m_impRC->IncRef(); 397 398 if ( 0 == GetTiXmlPointer()->LinkEndChild( childNode->GetTiXmlPointer() ) ) 399 { 400 TICPPTHROW( "Node can't be linked" ); 401 } 402 403 return childNode; 404 } 405 406 Node* Node::InsertBeforeChild( Node* beforeThis, Node& addThis ) 407 { 408 if ( addThis.Type() == TiXmlNode::DOCUMENT ) 409 { 410 TICPPTHROW( "Node is a Document and can't be inserted" ); 411 } 412 388 413 // Increment reference count when adding to the tree 389 414 addThis.m_impRC->IncRef(); 390 415 391 TiXmlNode* pointer = GetTiXmlPointer()->Insert EndChild(*addThis.GetTiXmlPointer() );416 TiXmlNode* pointer = GetTiXmlPointer()->InsertBeforeChild( beforeThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() ); 392 417 if ( 0 == pointer ) 393 418 { … … 398 423 } 399 424 400 Node* Node::LinkEndChild( Node* childNode ) 401 { 402 if ( childNode->Type() == TiXmlNode::DOCUMENT ) 403 { 404 TICPPTHROW( "Node is a Document and can't be linked" ); 405 } 406 407 // Increment reference count when adding to the tree 408 childNode->m_impRC->IncRef(); 409 410 if ( 0 == GetTiXmlPointer()->LinkEndChild( childNode->GetTiXmlPointer() ) ) 411 { 412 TICPPTHROW( "Node can't be linked" ); 413 } 414 415 return childNode; 416 } 417 418 Node* Node::InsertBeforeChild( Node* beforeThis, Node& addThis ) 425 Node* Node::InsertAfterChild( Node* afterThis, Node& addThis ) 419 426 { 420 427 if ( addThis.Type() == TiXmlNode::DOCUMENT ) … … 426 433 addThis.m_impRC->IncRef(); 427 434 428 TiXmlNode* pointer = GetTiXmlPointer()->InsertBeforeChild( beforeThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() );429 if ( 0 == pointer )430 {431 TICPPTHROW( "Node can't be inserted" );432 }433 434 return NodeFactory( pointer );435 }436 437 Node* Node::InsertAfterChild( Node* afterThis, Node& addThis )438 {439 if ( addThis.Type() == TiXmlNode::DOCUMENT )440 {441 TICPPTHROW( "Node is a Document and can't be inserted" );442 }443 444 // Increment reference count when adding to the tree445 addThis.m_impRC->IncRef();446 447 435 TiXmlNode* pointer = GetTiXmlPointer()->InsertAfterChild( afterThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() ); 448 436 if ( 0 == pointer ) … … 576 564 577 565 Element* temp = new Element( sibling ); 578 m_spawnedWrappers.push_back( temp );566 sibling->m_spawnedWrappers.push_back( temp ); 579 567 580 568 return temp; … … 616 604 617 605 Element* temp = new Element( element ); 618 m_spawnedWrappers.push_back( temp );606 element->m_spawnedWrappers.push_back( temp ); 619 607 620 608 return temp; … … 641 629 } 642 630 Document* temp = new Document( doc ); 643 m_spawnedWrappers.push_back( temp );631 doc->m_spawnedWrappers.push_back( temp ); 644 632 645 633 return temp; … … 659 647 } 660 648 Document* temp = new Document( doc ); 661 m_spawnedWrappers.push_back( temp );649 doc->m_spawnedWrappers.push_back( temp ); 662 650 663 651 return temp; … … 672 660 } 673 661 Element* temp = new Element( doc ); 674 m_spawnedWrappers.push_back( temp );662 doc->m_spawnedWrappers.push_back( temp ); 675 663 676 664 return temp; … … 685 673 } 686 674 Comment* temp = new Comment( doc ); 687 m_spawnedWrappers.push_back( temp );675 doc->m_spawnedWrappers.push_back( temp ); 688 676 689 677 return temp; … … 698 686 } 699 687 Text* temp = new Text( doc ); 700 m_spawnedWrappers.push_back( temp );688 doc->m_spawnedWrappers.push_back( temp ); 701 689 702 690 return temp; … … 711 699 } 712 700 Declaration* temp = new Declaration( doc ); 713 m_spawnedWrappers.push_back( temp );701 doc->m_spawnedWrappers.push_back( temp ); 714 702 715 703 return temp; … … 724 712 } 725 713 StylesheetReference* temp = new StylesheetReference( doc ); 726 m_spawnedWrappers.push_back( temp );714 doc->m_spawnedWrappers.push_back( temp ); 727 715 728 716 return temp; … … 860 848 if( throwIfParseError && m_tiXmlPointer->Error() ) 861 849 { 862 TICPPTHROW( "Error parsing xml: " << m_tiXmlPointer->ErrorDesc() 863 << " In row " << m_tiXmlPointer->ErrorRow() << ", column " << m_tiXmlPointer->ErrorCol() << "."); 850 TICPPTHROW( "Error parsing xml." ); 864 851 } 865 852 } … … 912 899 913 900 Attribute* temp = new Attribute( attribute ); 914 m_spawnedWrappers.push_back( temp );901 attribute->m_spawnedWrappers.push_back( temp ); 915 902 916 903 return temp; … … 939 926 940 927 Attribute* temp = new Attribute( attribute ); 941 m_spawnedWrappers.push_back( temp );928 attribute->m_spawnedWrappers.push_back( temp ); 942 929 943 930 return temp; … … 957 944 { 958 945 return GetAttributeOrDefault( name, std::string() ); 946 } 947 948 bool Element::HasAttribute( const std::string& name ) const 949 { 950 ValidatePointer(); 951 return ( 0 != m_tiXmlPointer->Attribute( name.c_str() ) ); 952 } 953 954 void Element::RemoveAttribute( const std::string& name ) 955 { 956 ValidatePointer(); 957 m_tiXmlPointer->RemoveAttribute( name.c_str() ); 959 958 } 960 959 … … 1086 1085 } 1087 1086 1087 void TiCppRC::DeleteSpawnedWrappers() 1088 { 1089 std::vector< Base* >::reverse_iterator wrapper; 1090 for ( wrapper = m_spawnedWrappers.rbegin(); wrapper != m_spawnedWrappers.rend(); ++wrapper ) 1091 { 1092 delete *wrapper; 1093 } 1094 m_spawnedWrappers.clear(); 1095 } 1096 1088 1097 TiCppRC::~TiCppRC() 1089 { 1098 { 1099 DeleteSpawnedWrappers(); 1100 1090 1101 // Set pointer held by reference counter to NULL 1091 1102 this->m_tiRC->Nullify(); -
code/branches/buildsystem2/src/tinyxml/ticpp.h
r2087 r2509 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/branches/buildsystem2/src/tinyxml/ticpprc.h
r1505 r2509 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/branches/buildsystem2/src/tinyxml/tinyxml.h
r1505 r2509 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 www.sourceforge.net/projects/tinyxml -
code/branches/buildsystem2/src/tolua/CMakeLists.txt
r1815 r2509 1 SET 1 SET(TOLUALIB_SRC_FILES 2 2 tolua_event.c 3 3 tolua_is.c … … 7 7 ) 8 8 9 ADD_LIBRARY (tolualib_orxonox SHARED ${TOLUALIB_SRC_FILES}) 9 ADD_LIBRARY (tolualib_orxonox SHARED ${TOLUALIB_SRC_FILES}) 10 TARGET_LINK_LIBRARIES(tolualib_orxonox ${LUA_LIBRARIES}) 10 11 11 TARGET_LINK_LIBRARIES (tolualib_orxonox 12 lua_orxonox 12 13 SET(TOLUAGEN_SRC_FILES 14 tolua.c 13 15 ) 14 16 17 ADD_EXECUTABLE (toluaexe_orxonox ${TOLUAGEN_SRC_FILES}) 18 TARGET_LINK_LIBRARIES(toluaexe_orxonox tolualib_orxonox ${LUA_LIBRARIES}) 15 19 16 SET (TOLUAGEN_SRC_FILES 17 tolua.c 18 toluabind.c 20 # TODO: determine lua version and set appropriate pack file 21 SET(TOLUA_ALL_PACK all-5.1.lua) 22 SET(TOLUA_PARSER_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/${TOLUA_ALL_PACK}" PARENT_SCOPE) 23 SET(TOLUA_PARSER_DEPENDENCIES 24 ${CMAKE_CURRENT_SOURCE_DIR}/${TOLUA_ALL_PACK} 25 ${CMAKE_CURRENT_SOURCE_DIR}/lua/compat-5.1.lua 26 ${CMAKE_CURRENT_SOURCE_DIR}/lua/compat.lua 27 ${CMAKE_CURRENT_SOURCE_DIR}/lua/basic.lua 28 ${CMAKE_CURRENT_SOURCE_DIR}/lua/feature.lua 29 ${CMAKE_CURRENT_SOURCE_DIR}/lua/verbatim.lua 30 ${CMAKE_CURRENT_SOURCE_DIR}/lua/code.lua 31 ${CMAKE_CURRENT_SOURCE_DIR}/lua/typedef.lua 32 ${CMAKE_CURRENT_SOURCE_DIR}/lua/container.lua 33 ${CMAKE_CURRENT_SOURCE_DIR}/lua/package.lua 34 ${CMAKE_CURRENT_SOURCE_DIR}/lua/module.lua 35 ${CMAKE_CURRENT_SOURCE_DIR}/lua/namespace.lua 36 ${CMAKE_CURRENT_SOURCE_DIR}/lua/define.lua 37 ${CMAKE_CURRENT_SOURCE_DIR}/lua/enumerate.lua 38 ${CMAKE_CURRENT_SOURCE_DIR}/lua/declaration.lua 39 ${CMAKE_CURRENT_SOURCE_DIR}/lua/variable.lua 40 ${CMAKE_CURRENT_SOURCE_DIR}/lua/array.lua 41 ${CMAKE_CURRENT_SOURCE_DIR}/lua/function.lua 42 ${CMAKE_CURRENT_SOURCE_DIR}/lua/operator.lua 43 ${CMAKE_CURRENT_SOURCE_DIR}/lua/class.lua 44 ${CMAKE_CURRENT_SOURCE_DIR}/lua/clean.lua 45 ${CMAKE_CURRENT_SOURCE_DIR}/lua/doit.lua 46 47 PARENT_SCOPE 19 48 ) 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/branches/buildsystem2/src/tolua/lua/array.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/basic.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/class.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/clean.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/code.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/compat-5.1.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/compat.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/container.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/custom.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/custom_hide.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/declaration.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/define.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/doit.lua
r2087 r2509 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) == '\\' 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) == '\\' 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) == '\\' 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) == '\\' 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/branches/buildsystem2/src/tolua/lua/enumerate.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/feature.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/function.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/module.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/namespace.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/operator.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/package.lua
r2087 r2509 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++.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 "'..package_lower..'/'..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) == '\\' 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/branches/buildsystem2/src/tolua/lua/typedef.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/variable.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/lua/verbatim.lua
r2087 r2509 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/branches/buildsystem2/src/tolua/tolua++.h
r1810 r2509 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/branches/buildsystem2/src/tolua/tolua.c
r1810 r2509 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/branches/buildsystem2/src/tolua/tolua_is.c
r1810 r2509 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/branches/buildsystem2/src/tolua/tolua_map.c
r1810 r2509 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/branches/buildsystem2/src/tolua/tolua_push.c
r1810 r2509 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/branches/buildsystem2/src/util
- Property svn:mergeinfo changed
/code/branches/buildsystem/src/util (added) merged: 2197-2198,2244
- Property svn:mergeinfo changed
-
code/branches/buildsystem2/src/util/CMakeLists.txt
r2295 r2509 14 14 15 15 ADD_LIBRARY(util SHARED ${UTIL_SRC_FILES}) 16 TARGET_LINK_LIBRARIES(util ${OGRE_LIBRARY}) 16 17 17 TARGET_LINK_LIBRARIES(util18 ${OGRE_LIBRARIES}19 18 ) 19 -
code/branches/buildsystem2/src/util/Exception.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/src/util/Exception.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/src/util/String.cc
r2171 r2509 493 493 } 494 494 } 495 496 /** 497 @brief Converts a path string to windows with "\" instead of "/". 498 @param str String pointer to be manipulated 499 */ 500 void convertToWindowsPath(std::string* str) 501 { 502 std::string& path = *str; 503 // replace all occurences of "/" with "\" 504 for (unsigned int i = 0; i < path.length(); ++i) 505 { 506 if (path[i] == '/') 507 path[i] = '\\'; 508 } 509 // add an extra '\\' at the end to make it a complete path 510 if (path != "" && path[path.length() - 1] != '\\') 511 path.append("\\"); 512 } 513 514 /** 515 @brief Converts a path string to unix with "/" instead of "\". 516 @param str String pointer to be manipulated 517 */ 518 void convertToUnixPath(std::string* str) 519 { 520 std::string& path = *str; 521 // replace all occurences of "\" with "/" 522 for (unsigned int i = 0; i < path.length(); ++i) 523 { 524 if (path[i] == '\\') 525 path[i] = '/'; 526 } 527 // add an extra '\\' at the end to make it a complete path 528 if (path != "" && path[path.length() - 1] != '/') 529 path.append("/"); 530 } -
code/branches/buildsystem2/src/util/String.h
r2171 r2509 81 81 } 82 82 83 _UtilExport void convertToWindowsPath(std::string* str); 84 _UtilExport void convertToUnixPath(std::string* str); 85 83 86 #endif /* _Util_String_H__ */ -
code/branches/buildsystem2/visual_studio/vc8/audio.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/base.vsprops
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/base.vsprops (added) merged: 2217,2220
r2261 r2509 8 8 <Tool 9 9 Name="VCCLCompilerTool" 10 AdditionalIncludeDirectories=""$(RootDir) ";"$(RootDir)src";"$(RootDir)src\orxonox";"$(RootDir)src\ceguilua-0.6.1";"$(LibDir)ogre-1.4.9\include";"$(LibDir)boost-1.35.0\include";"$(LibDir)cegui-0.6.1\include";"$(LibDir)enet-1.2\include";"$(LibDir)libogg-1.1.3\include";"$(LibDir)libvorbis-1.2.0\include";"$(LibDir)openal-1.1\include";"$(LibDir)freealut-1.1.0\include";"$(LibDir)tcl-8.5.2\include";"$(LibDir)zlib-1.2.3\include""11 PreprocessorDefinitions="WIN32;__WIN32__;_WIN32;_WINDOWS;BOOST_ALL_DYN_LINK;OIS_DYNAMIC_LIB;ZLIB_WINAPI "10 AdditionalIncludeDirectories=""$(RootDir)src";"$(RootDir)src\tolua";"$(RootDir)src\orxonox";"$(RootDir)src\ceguilua-0.6.1\ceguilua";"$(LibDir)ogre-1.4.9\include";"$(LibDir)boost-1.35.0\include";"$(LibDir)cegui-0.6.1\include";"$(LibDir)enet-1.2\include";"$(LibDir)libogg-1.1.3\include";"$(LibDir)libvorbis-1.2.0\include";"$(LibDir)openal-1.1\include";"$(LibDir)freealut-1.1.0\include";"$(LibDir)tcl-8.5.2\include";"$(LibDir)zlib-1.2.3\include";"$(LibDir)lua-5.1.3\include"" 11 PreprocessorDefinitions="WIN32;__WIN32__;_WIN32;_WINDOWS;BOOST_ALL_DYN_LINK;OIS_DYNAMIC_LIB;ZLIB_WINAPI;LUA_BUILD_AS_DLL;TIXML_USE_TICPP;_CRT_SECURE_NO_WARNINGS" 12 12 WarningLevel="3" 13 13 DisableSpecificWarnings="4522;4251;4800" … … 21 21 Name="VCLinkerTool" 22 22 OutputFile="$(OutDir)$(ProjectName)$(CS).dll" 23 AdditionalLibraryDirectories=""$(LibDir)boost-1.35.0\lib\$(ConfigurationName)";"$(LibDir)cegui-0.6.1\lib\$(ConfigurationName)";"$(LibDir)enet-1.2\lib\$(ConfigurationName)";"$(LibDir)freealut-1.1.0\lib\$(ConfigurationName)";"$(LibDir)libogg-1.1.3\lib\$(ConfigurationName)";"$(LibDir)libvorbis-1.2.0\lib\$(ConfigurationName)";"$(LibDir)ogre-1.4.9\lib\$(ConfigurationName)";"$(LibDir)openal-1.1\lib\$(ConfigurationName)";"$(LibDir)tcl-8.5.2\lib\$(ConfigurationName)";"$(LibDir)zlib-1.2.3\lib\$(ConfigurationName)" "23 AdditionalLibraryDirectories=""$(LibDir)boost-1.35.0\lib\$(ConfigurationName)";"$(LibDir)cegui-0.6.1\lib\$(ConfigurationName)";"$(LibDir)enet-1.2\lib\$(ConfigurationName)";"$(LibDir)freealut-1.1.0\lib\$(ConfigurationName)";"$(LibDir)libogg-1.1.3\lib\$(ConfigurationName)";"$(LibDir)libvorbis-1.2.0\lib\$(ConfigurationName)";"$(LibDir)ogre-1.4.9\lib\$(ConfigurationName)";"$(LibDir)openal-1.1\lib\$(ConfigurationName)";"$(LibDir)tcl-8.5.2\lib\$(ConfigurationName)";"$(LibDir)zlib-1.2.3\lib\$(ConfigurationName)";"$(LibDir)lua-5.1.3\lib\$(ConfigurationName)"" 24 24 SubSystem="1" 25 25 ImportLibrary="$(IntDir)\$(TargetName).lib" 26 26 TargetMachine="1" 27 /> 28 <UserMacro 29 Name="LibOutDir" 30 Value="$(RootDir)build\" 27 31 /> 28 32 <UserMacro - Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/ceguilua.vsprops
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/ceguilua.vsprops (added) merged: 2217
r2261 r2509 13 13 <Tool 14 14 Name="VCLinkerTool" 15 AdditionalDependencies="CEGUIBase$(CS).lib "15 AdditionalDependencies="CEGUIBase$(CS).lib lua$(CS).lib" 16 16 /> 17 17 </VisualStudioPropertySheet> - Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/core.vcproj
r2087 r2509 153 153 </File> 154 154 <File 155 RelativePath="..\..\src\core\CMakeLists.txt" 156 > 157 <FileConfiguration 158 Name="Debug|Win32" 159 > 160 <Tool 161 Name="VCCustomBuildTool" 162 Description="Generating tolua bind files..." 163 CommandLine="path $(LibDir)\..\..\bin\$(SolutionName)\$(ConfigurationName); %path%
cd $(RootDir)\bin
echo $cfile "CommandExecutor.h" > $(RootDir)\src\core\tolua.pkg
echo $cfile "Script.h" >> $(RootDir)\src\core\tolua.pkg
$(OutDir)\toluaexe$(CS).exe -n Core -w $(RootDir)\src\core\ -s $(RootDir)\src\tolua\all.lua -o ToluaBindCore.cc -H ToluaBindCore.h tolua.pkg
" 164 AdditionalDependencies="$(RootDir)\src\core\Script.h;$(RootDir)\src\core\CommandExecutor.h" 165 Outputs="$(RootDir)\src\core\ToluaBindCore.cc; $(RootDir)\src\core\ToluaBindCore.h" 166 /> 167 </FileConfiguration> 168 <FileConfiguration 169 Name="Release|Win32" 170 > 171 <Tool 172 Name="VCCustomBuildTool" 173 Description="Generating tolua bind files..." 174 CommandLine="path $(LibDir)\..\..\bin\$(SolutionName)\$(ConfigurationName); %path%
cd $(RootDir)\bin
echo $cfile "CommandExecutor.h" > $(RootDir)\src\core\tolua.pkg
echo $cfile "Script.h" >> $(RootDir)\src\core\tolua.pkg
$(OutDir)\toluaexe$(CS).exe -n Core -w $(RootDir)\src\core\ -s $(RootDir)\src\tolua\all.lua -o ToluaBindCore.cc -H ToluaBindCore.h tolua.pkg
" 175 AdditionalDependencies="$(RootDir)\src\core\Script.h;$(RootDir)\src\core\CommandExecutor.h" 176 Outputs="$(RootDir)\src\core\ToluaBindCore.cc; $(RootDir)\src\core\ToluaBindCore.h" 177 /> 178 </FileConfiguration> 179 </File> 180 <File 155 181 RelativePath="..\..\src\core\ConfigFileManager.cc" 156 182 > … … 196 222 > 197 223 </File> 198 <Filter 199 Name="tolua" 200 > 201 <File 202 RelativePath="..\..\src\core\tolua\tolua.pkg" 203 > 204 <FileConfiguration 205 Name="Debug|Win32" 206 > 207 <Tool 208 Name="VCCustomBuildTool" 209 Description="Generating tolua bind files..." 210 CommandLine=""$(RootDir)\build\$(SolutionName)\$(ConfigurationName)\toluagen_orxonox\toluagen_orxonox$(CS).exe" -n Core -o $(RootDir)/src/core/tolua/tolua_bind.cc -H $(RootDir)/src/core/tolua/tolua_bind.h $(RootDir)/src/core/tolua/tolua.pkg
" 211 AdditionalDependencies="$(RootDir)\src\core\Script.h;$(RootDir)\src\core\CommandExecutor.h" 212 Outputs="$(RootDir)\src\core\tolua\tolua_bind.cc; $(RootDir)\src\core\tolua\tolua_bind.h" 213 /> 214 </FileConfiguration> 215 <FileConfiguration 216 Name="Release|Win32" 217 > 218 <Tool 219 Name="VCCustomBuildTool" 220 Description="Generating tolua bind files..." 221 CommandLine=""$(RootDir)\build\$(SolutionName)\$(ConfigurationName)\toluagen_orxonox\toluagen_orxonox$(CS).exe" -n Core -o $(RootDir)/src/core/tolua/tolua_bind.cc -H $(RootDir)/src/core/tolua/tolua_bind.h $(RootDir)/src/core/tolua/tolua.pkg
" 222 AdditionalDependencies="$(RootDir)\src\core\Script.h;$(RootDir)\src\core\CommandExecutor.h" 223 Outputs="$(RootDir)\src\core\tolua\tolua_bind.cc; $(RootDir)\src\core\tolua\tolua_bind.h" 224 /> 225 </FileConfiguration> 226 </File> 227 <File 228 RelativePath="..\..\src\core\tolua\tolua_bind.cc" 229 > 230 </File> 231 </Filter> 224 <File 225 RelativePath="..\..\src\core\ToluaBindCore.cc" 226 > 227 </File> 232 228 <Filter 233 229 Name="command" … … 445 441 </File> 446 442 <File 443 RelativePath="..\..\src\core\tolua_bind.h" 444 > 445 </File> 446 <File 447 RelativePath="..\..\src\core\ToluaBindCore.h" 448 > 449 </File> 450 <File 447 451 RelativePath="..\..\src\core\XMLIncludes.h" 448 452 > … … 641 645 <File 642 646 RelativePath="..\..\src\core\XMLPort.h" 643 >644 </File>645 </Filter>646 <Filter647 Name="tolua"648 >649 <File650 RelativePath="..\..\src\core\tolua\tolua_bind.h"651 647 > 652 648 </File> -
code/branches/buildsystem2/visual_studio/vc8/core.vsprops
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/core.vsprops (added) merged: 2217
r2261 r2509 13 13 <Tool 14 14 Name="VCLinkerTool" 15 AdditionalDependencies="OgreMain$(CS).lib tcl85t.lib "15 AdditionalDependencies="OgreMain$(CS).lib tcl85t.lib lua$(CS).lib" 16 16 /> 17 17 </VisualStudioPropertySheet> - Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/cpptcl.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/debug.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/directories.vsprops
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/directories.vsprops (added) merged: 2217
- Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/network.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/orxonox.vcproj
r2171 r2509 76 76 <Tool 77 77 Name="VCPostBuildEventTool" 78 Description="Copying files from init folder..." 79 CommandLine="for %%a in ($(RootDir)\bin\msvc\$(ConfigurationName)\*) do replace %%a $(OutDir). /A >nul
rem for %%a in ($(RootDir)\init\common\*) do replace %%a $(OutDir). /A >nul
" 78 80 /> 79 81 </Configuration> … … 139 141 <Tool 140 142 Name="VCPostBuildEventTool" 143 Description="Copying files from init folder..." 144 CommandLine="for %%a in ($(RootDir)\bin\msvc\$(ConfigurationName)\*) do replace %%a $(OutDir). /A >nul
rem for %%a in ($(RootDir)\init\common\*) do replace %%a $(OutDir). /A >nul
" 141 145 /> 142 146 </Configuration> … … 155 159 </File> 156 160 <File 161 RelativePath="..\..\src\orxonox\CMakeLists.txt" 162 > 163 <FileConfiguration 164 Name="Debug|Win32" 165 > 166 <Tool 167 Name="VCCustomBuildTool" 168 Description="Generating tolua bind files..." 169 CommandLine="path $(LibDir)\..\..\bin\$(SolutionName)\$(ConfigurationName); %path%
cd $(RootDir)\bin
echo $cfile "gui/GUIManager.h" > $(RootDir)\src\orxonox\tolua.pkg
"$(OutDir)\toluaexe$(CS).exe" -n Orxonox -w $(RootDir)\src\orxonox\ -s $(RootDir)\src\tolua\all.lua -o ToluaBindOrxonox.cc -H ToluaBindOrxonox.h tolua.pkg
" 170 AdditionalDependencies="$(RootDir)\src\orxonox\gui\GUIManager.h" 171 Outputs="$(RootDir)\src\orxonox\ToluaBindOrxonox.cc; $(RootDir)\src\orxonox\ToluaBindOrxonox.h" 172 /> 173 </FileConfiguration> 174 <FileConfiguration 175 Name="Release|Win32" 176 > 177 <Tool 178 Name="VCCustomBuildTool" 179 Description="Generating tolua bind files..." 180 CommandLine="path $(LibDir)\..\..\bin\$(SolutionName)\$(ConfigurationName); %path%
cd $(RootDir)\bin
echo $cfile "gui/GUIManager.h" > $(RootDir)\src\orxonox\tolua.pkg
"$(OutDir)\toluaexe$(CS).exe" -n Orxonox -w $(RootDir)\src\orxonox\ -s $(RootDir)\src\tolua\all.lua -o ToluaBindOrxonox.cc -H ToluaBindOrxonox.h tolua.pkg
" 181 AdditionalDependencies="$(RootDir)\src\orxonox\gui\GUIManager.h" 182 Outputs="$(RootDir)\src\orxonox\ToluaBindOrxonox.cc; $(RootDir)\src\orxonox\ToluaBindOrxonox.h" 183 /> 184 </FileConfiguration> 185 </File> 186 <File 157 187 RelativePath="..\..\src\orxonox\GraphicsEngine.cc" 158 188 > … … 193 223 RelativePath="..\..\src\orxonox\Settings.cc" 194 224 > 225 </File> 226 <File 227 RelativePath="..\..\src\orxonox\ToluaBindOrxonox.cc" 228 > 229 <FileConfiguration 230 Name="Debug|Win32" 231 > 232 <Tool 233 Name="VCCLCompilerTool" 234 UsePrecompiledHeader="0" 235 /> 236 </FileConfiguration> 237 <FileConfiguration 238 Name="Release|Win32" 239 > 240 <Tool 241 Name="VCCLCompilerTool" 242 UsePrecompiledHeader="0" 243 /> 244 </FileConfiguration> 195 245 </File> 196 246 <Filter … … 635 685 </Filter> 636 686 <Filter 637 Name="tolua"638 >639 <File640 RelativePath="..\..\src\orxonox\tolua\tolua.pkg"641 >642 <FileConfiguration643 Name="Debug|Win32"644 >645 <Tool646 Name="VCCustomBuildTool"647 Description="Generating tolua bind files..."648 CommandLine=""$(RootDir)\build\$(SolutionName)\$(ConfigurationName)\toluagen_orxonox\toluagen_orxonox$(CS).exe" -n Orxonox -o $(RootDir)/src/orxonox/tolua/tolua_bind.cc -H $(RootDir)/src/orxonox/tolua/tolua_bind.h $(RootDir)/src/orxonox/tolua/tolua.pkg
"649 AdditionalDependencies="$(RootDir)\src\orxonox\gui\GUIManager.h"650 Outputs="$(RootDir)\src\orxonox\tolua\tolua_bind.cc; $(RootDir)\src\orxonox\tolua\tolua_bind.h"651 />652 </FileConfiguration>653 <FileConfiguration654 Name="Release|Win32"655 >656 <Tool657 Name="VCCustomBuildTool"658 Description="Generating tolua bind files..."659 CommandLine=""$(RootDir)\build\$(SolutionName)\$(ConfigurationName)\toluagen_orxonox\toluagen_orxonox$(CS).exe" -n Orxonox -o $(RootDir)/src/orxonox/tolua/tolua_bind.cc -H $(RootDir)/src/orxonox/tolua/tolua_bind.h $(RootDir)/src/orxonox/tolua/tolua.pkg
"660 AdditionalDependencies="$(RootDir)\src\orxonox\gui\GUIManager.h"661 Outputs="$(RootDir)\src\orxonox\tolua\tolua_bind.cc; $(RootDir)\src\orxonox\tolua\tolua_bind.h"662 />663 </FileConfiguration>664 </File>665 <File666 RelativePath="..\..\src\orxonox\tolua\tolua_bind.cc"667 >668 <FileConfiguration669 Name="Debug|Win32"670 >671 <Tool672 Name="VCCLCompilerTool"673 UsePrecompiledHeader="0"674 />675 </FileConfiguration>676 <FileConfiguration677 Name="Release|Win32"678 >679 <Tool680 Name="VCCLCompilerTool"681 UsePrecompiledHeader="0"682 />683 </FileConfiguration>684 </File>685 </Filter>686 <Filter687 687 Name="overlays" 688 688 > … … 838 838 > 839 839 </File> 840 <File 841 RelativePath="..\..\src\orxonox\tolua_bind.h" 842 > 843 </File> 844 <File 845 RelativePath="..\..\src\orxonox\ToluaBindOrxonox.h" 846 > 847 </File> 840 848 <Filter 841 849 Name="objects" … … 1159 1167 <File 1160 1168 RelativePath="..\..\src\orxonox\tools\WindowEventListener.h" 1161 >1162 </File>1163 </Filter>1164 <Filter1165 Name="tolua"1166 >1167 <File1168 RelativePath="..\..\src\orxonox\tolua\tolua_bind.h"1169 1169 > 1170 1170 </File> -
code/branches/buildsystem2/visual_studio/vc8/orxonox.vsprops
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/orxonox.vsprops (added) merged: 2217
r2261 r2509 15 15 <Tool 16 16 Name="VCLinkerTool" 17 AdditionalDependencies="OgreMain$(CS).lib tcl85t.lib enet$(CS).lib zlib$(CS).lib CEGUIBase$(CS).lib "17 AdditionalDependencies="OgreMain$(CS).lib tcl85t.lib enet$(CS).lib zlib$(CS).lib CEGUIBase$(CS).lib lua$(CS).lib" 18 18 OutputFile="$(OutDir)$(ProjectName)$(CS).exe" 19 19 IgnoreDefaultLibraryNames="" - Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/orxonox_vc8.sln
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/orxonox_vc8.sln (added) merged: 2217
r2261 r2509 2 2 Microsoft Visual Studio Solution File, Format Version 9.00 3 3 # Visual Studio 2005 4 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "orxonox", "orxonox.vcproj", "{0B6C5CFD-F91B-432A-80A3-2610F61E060B}"5 ProjectSection(WebsiteProperties) = preProject6 Debug.AspNetCompiler.Debug = "True"7 Release.AspNetCompiler.Debug = "False"8 EndProjectSection9 ProjectSection(ProjectDependencies) = postProject10 {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F} = {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F}11 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F}12 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}13 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}14 {35575B59-E1AE-40E8-89C4-2862B5B09B68} = {35575B59-E1AE-40E8-89C4-2862B5B09B68}15 {4733BD1A-E04C-458D-8BFB-5010250EA497} = {4733BD1A-E04C-458D-8BFB-5010250EA497}16 {63B3E57A-4382-42F3-85EC-E869CFCCA88F} = {63B3E57A-4382-42F3-85EC-E869CFCCA88F}17 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}18 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0} = {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}19 EndProjectSection20 EndProject21 4 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpptcl", "cpptcl.vcproj", "{53C56131-E2AA-4A27-B460-7AC05D61A0E6}" 22 ProjectSection(WebsiteProperties) = preProject23 Debug.AspNetCompiler.Debug = "True"24 Release.AspNetCompiler.Debug = "False"25 EndProjectSection26 5 EndProject 27 6 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tinyxml", "tinyxml.vcproj", "{F101C2F0-1CB9-4A57-827B-6C399A99B28F}" 28 ProjectSection(WebsiteProperties) = preProject29 Debug.AspNetCompiler.Debug = "True"30 Release.AspNetCompiler.Debug = "False"31 EndProjectSection32 7 EndProject 33 8 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tolua", "tolua.vcproj", "{35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}" 34 ProjectSection(WebsiteProperties) = preProject 35 Debug.AspNetCompiler.Debug = "True" 36 Release.AspNetCompiler.Debug = "False" 37 EndProjectSection 9 EndProject 10 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "toluaexe", "toluaexe.vcproj", "{A0724246-CB7C-420B-BCF0-68EF205AFE34}" 38 11 ProjectSection(ProjectDependencies) = postProject 39 {63B3E57A-4382-42F3-85EC-E869CFCCA88F} = {63B3E57A-4382-42F3-85EC-E869CFCCA88F} 40 EndProjectSection 41 EndProject 42 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "toluagen_orxonox", "toluagen_orxonox.vcproj", "{71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}" 43 ProjectSection(WebsiteProperties) = preProject 44 Debug.AspNetCompiler.Debug = "True" 45 Release.AspNetCompiler.Debug = "False" 46 EndProjectSection 47 ProjectSection(ProjectDependencies) = postProject 48 {8F5B7ED0-D380-4B4F-A744-3A568718176C} = {8F5B7ED0-D380-4B4F-A744-3A568718176C} 49 {C6692661-9160-49E6-B109-A155F9485402} = {C6692661-9160-49E6-B109-A155F9485402} 50 {A0724246-CB7C-420B-BCF0-68EF205AFE34} = {A0724246-CB7C-420B-BCF0-68EF205AFE34} 51 EndProjectSection 52 EndProject 53 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "toluagen", "toluagen.vcproj", "{A0724246-CB7C-420B-BCF0-68EF205AFE34}" 54 ProjectSection(WebsiteProperties) = preProject 55 Debug.AspNetCompiler.Debug = "True" 56 Release.AspNetCompiler.Debug = "False" 57 EndProjectSection 58 ProjectSection(ProjectDependencies) = postProject 59 {8F5B7ED0-D380-4B4F-A744-3A568718176C} = {8F5B7ED0-D380-4B4F-A744-3A568718176C} 60 {C6692661-9160-49E6-B109-A155F9485402} = {C6692661-9160-49E6-B109-A155F9485402} 12 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} 61 13 EndProjectSection 62 14 EndProject 63 15 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "util", "util.vcproj", "{2240ECD7-2F48-4431-8E1B-25466A384CCC}" 64 ProjectSection(WebsiteProperties) = preProject65 Debug.AspNetCompiler.Debug = "True"66 Release.AspNetCompiler.Debug = "False"67 EndProjectSection68 16 EndProject 69 17 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "core.vcproj", "{271715F3-5B90-4110-A552-70C788084A86}" 70 ProjectSection(WebsiteProperties) = preProject71 Debug.AspNetCompiler.Debug = "True"72 Release.AspNetCompiler.Debug = "False"73 EndProjectSection74 18 ProjectSection(ProjectDependencies) = postProject 19 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} 20 {A0724246-CB7C-420B-BCF0-68EF205AFE34} = {A0724246-CB7C-420B-BCF0-68EF205AFE34} 21 {53C56131-E2AA-4A27-B460-7AC05D61A0E6} = {53C56131-E2AA-4A27-B460-7AC05D61A0E6} 22 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC} 23 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F} 75 24 {EA969DF2-70AF-46E6-BBE2-E03112E04CB8} = {EA969DF2-70AF-46E6-BBE2-E03112E04CB8} 76 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F}77 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}78 {53C56131-E2AA-4A27-B460-7AC05D61A0E6} = {53C56131-E2AA-4A27-B460-7AC05D61A0E6}79 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}80 {63B3E57A-4382-42F3-85EC-E869CFCCA88F} = {63B3E57A-4382-42F3-85EC-E869CFCCA88F}81 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0} = {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}82 25 EndProjectSection 83 26 EndProject 84 27 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "audio", "audio.vcproj", "{4733BD1A-E04C-458D-8BFB-5010250EA497}" 85 ProjectSection(WebsiteProperties) = preProject86 Debug.AspNetCompiler.Debug = "True"87 Release.AspNetCompiler.Debug = "False"88 EndProjectSection89 28 ProjectSection(ProjectDependencies) = postProject 29 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC} 90 30 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86} 91 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}92 31 EndProjectSection 93 32 EndProject 94 33 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "network", "network.vcproj", "{35575B59-E1AE-40E8-89C4-2862B5B09B68}" 95 ProjectSection(WebsiteProperties) = preProject96 Debug.AspNetCompiler.Debug = "True"97 Release.AspNetCompiler.Debug = "False"98 EndProjectSection99 34 ProjectSection(ProjectDependencies) = postProject 35 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC} 100 36 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86} 101 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}102 37 EndProjectSection 103 38 EndProject 104 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua", "lua.vcproj", "{63B3E57A-4382-42F3-85EC-E869CFCCA88F}" 105 ProjectSection(WebsiteProperties) = preProject 106 Debug.AspNetCompiler.Debug = "True" 107 Release.AspNetCompiler.Debug = "False" 39 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "orxonox", "orxonox.vcproj", "{0B6C5CFD-F91B-432A-80A3-2610F61E060B}" 40 ProjectSection(ProjectDependencies) = postProject 41 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} 42 {A0724246-CB7C-420B-BCF0-68EF205AFE34} = {A0724246-CB7C-420B-BCF0-68EF205AFE34} 43 {4733BD1A-E04C-458D-8BFB-5010250EA497} = {4733BD1A-E04C-458D-8BFB-5010250EA497} 44 {35575B59-E1AE-40E8-89C4-2862B5B09B68} = {35575B59-E1AE-40E8-89C4-2862B5B09B68} 45 {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F} = {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F} 46 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC} 47 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86} 48 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F} 108 49 EndProjectSection 109 50 EndProject 110 51 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ceguilua", "ceguilua.vcproj", "{4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F}" 111 ProjectSection(WebsiteProperties) = preProject112 Debug.AspNetCompiler.Debug = "True"113 Release.AspNetCompiler.Debug = "False"114 EndProjectSection115 52 ProjectSection(ProjectDependencies) = postProject 116 53 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} 117 {63B3E57A-4382-42F3-85EC-E869CFCCA88F} = {63B3E57A-4382-42F3-85EC-E869CFCCA88F}118 54 EndProjectSection 119 55 EndProject 120 56 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ois", "ois.vcproj", "{EA969DF2-70AF-46E6-BBE2-E03112E04CB8}" 121 ProjectSection(WebsiteProperties) = preProject122 Debug.AspNetCompiler.Debug = "True"123 Release.AspNetCompiler.Debug = "False"124 EndProjectSection125 57 EndProject 126 58 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "externals", "externals", "{B9D56701-B4DB-43F8-9920-241CA418C1CE}" 127 ProjectSection(WebsiteProperties) = preProject128 Debug.AspNetCompiler.Debug = "True"129 Release.AspNetCompiler.Debug = "False"130 EndProjectSection131 EndProject132 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tolua_static", "tolua_static.vcproj", "{C6692661-9160-49E6-B109-A155F9485402}"133 ProjectSection(WebsiteProperties) = preProject134 Debug.AspNetCompiler.Debug = "True"135 Release.AspNetCompiler.Debug = "False"136 EndProjectSection137 EndProject138 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua_static", "lua_static.vcproj", "{8F5B7ED0-D380-4B4F-A744-3A568718176C}"139 ProjectSection(WebsiteProperties) = preProject140 Debug.AspNetCompiler.Debug = "True"141 Release.AspNetCompiler.Debug = "False"142 EndProjectSection143 59 EndProject 144 60 Global … … 160 76 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.Release|Win32.ActiveCfg = Release|Win32 161 77 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.Release|Win32.Build.0 = Release|Win32 162 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}.Debug|Win32.ActiveCfg = Debug|Win32163 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}.Debug|Win32.Build.0 = Debug|Win32164 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}.Release|Win32.ActiveCfg = Release|Win32165 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0}.Release|Win32.Build.0 = Release|Win32166 78 {A0724246-CB7C-420B-BCF0-68EF205AFE34}.Debug|Win32.ActiveCfg = Debug|Win32 167 79 {A0724246-CB7C-420B-BCF0-68EF205AFE34}.Debug|Win32.Build.0 = Debug|Win32 … … 188 100 {0B6C5CFD-F91B-432A-80A3-2610F61E060B}.Release|Win32.ActiveCfg = Release|Win32 189 101 {0B6C5CFD-F91B-432A-80A3-2610F61E060B}.Release|Win32.Build.0 = Release|Win32 190 {63B3E57A-4382-42F3-85EC-E869CFCCA88F}.Debug|Win32.ActiveCfg = Debug|Win32191 {63B3E57A-4382-42F3-85EC-E869CFCCA88F}.Debug|Win32.Build.0 = Debug|Win32192 {63B3E57A-4382-42F3-85EC-E869CFCCA88F}.Release|Win32.ActiveCfg = Release|Win32193 {63B3E57A-4382-42F3-85EC-E869CFCCA88F}.Release|Win32.Build.0 = Release|Win32194 102 {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F}.Debug|Win32.ActiveCfg = Debug|Win32 195 103 {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F}.Debug|Win32.Build.0 = Debug|Win32 … … 200 108 {EA969DF2-70AF-46E6-BBE2-E03112E04CB8}.Release|Win32.ActiveCfg = Release|Win32 201 109 {EA969DF2-70AF-46E6-BBE2-E03112E04CB8}.Release|Win32.Build.0 = Release|Win32 202 {C6692661-9160-49E6-B109-A155F9485402}.Debug|Win32.ActiveCfg = Debug|Win32203 {C6692661-9160-49E6-B109-A155F9485402}.Debug|Win32.Build.0 = Debug|Win32204 {C6692661-9160-49E6-B109-A155F9485402}.Release|Win32.ActiveCfg = Release|Win32205 {C6692661-9160-49E6-B109-A155F9485402}.Release|Win32.Build.0 = Release|Win32206 {8F5B7ED0-D380-4B4F-A744-3A568718176C}.Debug|Win32.ActiveCfg = Debug|Win32207 {8F5B7ED0-D380-4B4F-A744-3A568718176C}.Debug|Win32.Build.0 = Debug|Win32208 {8F5B7ED0-D380-4B4F-A744-3A568718176C}.Release|Win32.ActiveCfg = Release|Win32209 {8F5B7ED0-D380-4B4F-A744-3A568718176C}.Release|Win32.Build.0 = Release|Win32210 110 EndGlobalSection 211 111 GlobalSection(SolutionProperties) = preSolution … … 215 115 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {B9D56701-B4DB-43F8-9920-241CA418C1CE} 216 116 {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {B9D56701-B4DB-43F8-9920-241CA418C1CE} 217 {71FC0211-5EB5-4637-BE8A-A48EC3CC27D0} = {B9D56701-B4DB-43F8-9920-241CA418C1CE}218 117 {A0724246-CB7C-420B-BCF0-68EF205AFE34} = {B9D56701-B4DB-43F8-9920-241CA418C1CE} 219 {63B3E57A-4382-42F3-85EC-E869CFCCA88F} = {B9D56701-B4DB-43F8-9920-241CA418C1CE}220 118 {4BBBB49F-3203-4BB4-AAE3-48BCA96FCB4F} = {B9D56701-B4DB-43F8-9920-241CA418C1CE} 221 119 {EA969DF2-70AF-46E6-BBE2-E03112E04CB8} = {B9D56701-B4DB-43F8-9920-241CA418C1CE} 222 120 {53C56131-E2AA-4A27-B460-7AC05D61A0E6} = {B9D56701-B4DB-43F8-9920-241CA418C1CE} 223 {C6692661-9160-49E6-B109-A155F9485402} = {B9D56701-B4DB-43F8-9920-241CA418C1CE}224 {8F5B7ED0-D380-4B4F-A744-3A568718176C} = {B9D56701-B4DB-43F8-9920-241CA418C1CE}225 121 EndGlobalSection 226 122 EndGlobal - Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/release.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/tinyxml.vcproj
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/tinyxml.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/buildsystem2/visual_studio/vc8/tolua.vsprops
- Property svn:mergeinfo changed
/code/branches/buildsystem/visual_studio/vc8/tolua.vsprops (added) merged: 2217
r2261 r2509 12 12 DisableSpecificWarnings="4996" 13 13 /> 14 <Tool 15 Name="VCLinkerTool" 16 AdditionalDependencies="lua$(CS).lib" 17 /> 14 18 </VisualStudioPropertySheet> - Property svn:mergeinfo changed
-
code/branches/buildsystem2/visual_studio/vc8/util.vsprops
- Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset
for help on using the changeset viewer.