├── .travis.yml ├── CMakeLists.txt ├── COPYRIGHT ├── README ├── cmake ├── FindLua.cmake ├── dist.cmake └── lua.cmake ├── dist.info └── src ├── lua-formatter.lua ├── lua-highlighter.lua └── luapretty ├── ast_helper.lua ├── formatter.lua ├── highlighter.lua └── templates └── default.lua /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # LuaDist Travis-CI Hook 3 | # 4 | 5 | # We assume C build environments 6 | language: C 7 | 8 | # Try using multiple Lua Implementations 9 | env: 10 | - TOOL="gcc" # Use native compiler (GCC usually) 11 | - TOOL="clang" # Use clang 12 | - TOOL="i686-w64-mingw32" # 32bit MinGW 13 | - TOOL="x86_64-w64-mingw32" # 64bit MinGW 14 | - TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux 15 | 16 | # Crosscompile builds may fail 17 | matrix: 18 | allow_failures: 19 | - env: TOOL="i686-w64-mingw32" 20 | - env: TOOL="x86_64-w64-mingw32" 21 | - env: TOOL="arm-linux-gnueabihf" 22 | 23 | # Install dependencies 24 | install: 25 | - git clone git://github.com/LuaDist/Tools.git ~/_tools 26 | - ~/_tools/travis/travis install 27 | 28 | # Bootstap 29 | before_script: 30 | - ~/_tools/travis/travis bootstrap 31 | 32 | # Build the module 33 | script: 34 | - ~/_tools/travis/travis build 35 | 36 | # Execute additional tests or commands 37 | after_script: 38 | - ~/_tools/travis/travis test 39 | 40 | # Only watch the master branch 41 | branches: 42 | only: 43 | - master 44 | 45 | # Notify the LuaDist Dev group if needed 46 | notifications: 47 | recipients: 48 | - luadist-dev@googlegroups.com 49 | email: 50 | on_success: change 51 | on_failure: always 52 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012 LuaDist. 2 | # Created by Peter Kapec 3 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 4 | # For details see the COPYRIGHT file distributed with LuaDist. 5 | # Please note that the package source code is licensed under its own license. 6 | 7 | project ( luapretty NONE ) 8 | cmake_minimum_required ( VERSION 2.8 ) 9 | include ( cmake/dist.cmake ) 10 | include ( lua ) 11 | 12 | # Install all files and documentation 13 | install_lua_executable ( lua-formatter src/lua-formatter.lua ) 14 | install_lua_executable ( lua-highlighter src/lua-highlighter.lua ) 15 | install ( DIRECTORY src/luapretty DESTINATION ${INSTALL_LMOD} COMPONENT Runtime ) 16 | install_data ( README COPYRIGHT ) 17 | #install_doc ( doc/ ) 18 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | LuaPretty License 2 | --------------- 3 | 4 | LuaPretty is licensed under the terms of the MIT license reproduced below. 5 | This means that LuaPretty is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | =============================================================================== 9 | 10 | Copyright (C) 2010-2011 LuaPretty. 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | THE SOFTWARE. 29 | 30 | =============================================================================== 31 | 32 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | * About LuaPretty 2 | --------------- 3 | LuaPretty is a syntax aware code highlighter and formatter for the Lua language. 4 | It can be used separately as a standalone application or as a library from 5 | within your own Lua project. 6 | 7 | Output of LuaPretty consists of reformatted input source code according to a 8 | given template, which can be later highlighted using custom CSS to produce 9 | a valid HTML document containing the highlighted and reformatted code. 10 | 11 | Formatter templates have the ability to make any change in the given source 12 | code. Reformatting the source code is only a small subset of changes that 13 | can be made inside a formatter user template. 14 | 15 | * Availability 16 | ------------ 17 | LuaPretty is freely available for both academic and commercial purposes under 18 | MIT license. See COPYRIGHT for details. 19 | 20 | * Dependecies 21 | ----------------------------------------- 22 | LuaPretty requires following modules to be installed: 23 | lua >= 5.1 (not tested with 5.2) 24 | alt_getopt >= 0.7 25 | cosmo >= 10.04.06 26 | leg == 0.1.3 (leg version 0.1.3 is provided by LuaDist and supports lpeg >= 0.10) 27 | lpeg >= 0.10 28 | 29 | * Installation 30 | ------------ 31 | Simplest way to install LuaPretty is to use the LuaDist (www.luadist.org) deployment 32 | tool by invoking: 33 | 34 | > ./luadist _luapretty install luapretty 35 | 36 | which will install LuaPretty and all it's dependecies into the _luapretty folder. 37 | LuaPretty can be also installed using CMake (www.cmake.org). For manual installation 38 | copy the luapretty folder from src into your LUA_PATH folder. 39 | 40 | * Running 41 | ------- 42 | When using LuaDist for installation, LuaPretty installs to a standalone directory 43 | and can be invoked from _luapretty/bin directory. LuaPretty provides two small 44 | applications: 45 | src/lua-formatter.lua - Lua source code reformater 46 | src/lua-highlighter.lua - Lua source code syntax highlighter 47 | 48 | Both scripts can be simply executed using the lua runtime interpreter in the install 49 | directory, e.g.: 50 | $ cd _luapretty/bin/ 51 | $ lua lua-formatter.lua 52 | 53 | LuaDist also installs binary versions of these sripts. 54 | 55 | * Compatibility 56 | ------------- 57 | LuaPretty was tested only on Linux platform, but should work on all main platforms. 58 | 59 | * Authors 60 | ------- 61 | LuaPretty is developed and maintained by: 62 | Viliam Kubis (main developer) 63 | Peter Kapec (project supervisor) 64 | -------------------------------------------------------------------------------- /cmake/FindLua.cmake: -------------------------------------------------------------------------------- 1 | # Locate Lua library 2 | # This module defines 3 | # LUA_EXECUTABLE, if found 4 | # LUA_FOUND, if false, do not try to link to Lua 5 | # LUA_LIBRARIES 6 | # LUA_INCLUDE_DIR, where to find lua.h 7 | # LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) 8 | # 9 | # Note that the expected include convention is 10 | # #include "lua.h" 11 | # and not 12 | # #include 13 | # This is because, the lua location is not standardized and may exist 14 | # in locations other than lua/ 15 | 16 | #============================================================================= 17 | # Copyright 2007-2009 Kitware, Inc. 18 | # Modified to support Lua 5.2 by LuaDist 2012 19 | # 20 | # Distributed under the OSI-approved BSD License (the "License"); 21 | # see accompanying file Copyright.txt for details. 22 | # 23 | # This software is distributed WITHOUT ANY WARRANTY; without even the 24 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | # See the License for more information. 26 | #============================================================================= 27 | # (To distribute this file outside of CMake, substitute the full 28 | # License text for the above reference.) 29 | # 30 | # The required version of Lua can be specified using the 31 | # standard syntax, e.g. FIND_PACKAGE(Lua 5.1) 32 | # Otherwise the module will search for any available Lua implementation 33 | 34 | # Always search for non-versioned lua first (recommended) 35 | SET(_POSSIBLE_LUA_INCLUDE include include/lua) 36 | SET(_POSSIBLE_LUA_EXECUTABLE lua) 37 | SET(_POSSIBLE_LUA_LIBRARY lua) 38 | 39 | # Determine possible naming suffixes (there is no standard for this) 40 | IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) 41 | SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") 42 | ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) 43 | SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1") 44 | ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) 45 | 46 | # Set up possible search names and locations 47 | FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) 48 | LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}") 49 | LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}") 50 | LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") 51 | ENDFOREACH(_SUFFIX) 52 | 53 | # Find the lua executable 54 | FIND_PROGRAM(LUA_EXECUTABLE 55 | NAMES ${_POSSIBLE_LUA_EXECUTABLE} 56 | ) 57 | 58 | # Find the lua header 59 | FIND_PATH(LUA_INCLUDE_DIR lua.h 60 | HINTS 61 | $ENV{LUA_DIR} 62 | PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE} 63 | PATHS 64 | ~/Library/Frameworks 65 | /Library/Frameworks 66 | /usr/local 67 | /usr 68 | /sw # Fink 69 | /opt/local # DarwinPorts 70 | /opt/csw # Blastwave 71 | /opt 72 | ) 73 | 74 | # Find the lua library 75 | FIND_LIBRARY(LUA_LIBRARY 76 | NAMES ${_POSSIBLE_LUA_LIBRARY} 77 | HINTS 78 | $ENV{LUA_DIR} 79 | PATH_SUFFIXES lib64 lib 80 | PATHS 81 | ~/Library/Frameworks 82 | /Library/Frameworks 83 | /usr/local 84 | /usr 85 | /sw 86 | /opt/local 87 | /opt/csw 88 | /opt 89 | ) 90 | 91 | IF(LUA_LIBRARY) 92 | # include the math library for Unix 93 | IF(UNIX AND NOT APPLE) 94 | FIND_LIBRARY(LUA_MATH_LIBRARY m) 95 | SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") 96 | # For Windows and Mac, don't need to explicitly include the math library 97 | ELSE(UNIX AND NOT APPLE) 98 | SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") 99 | ENDIF(UNIX AND NOT APPLE) 100 | ENDIF(LUA_LIBRARY) 101 | 102 | # Determine Lua version 103 | IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") 104 | FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") 105 | 106 | STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") 107 | UNSET(lua_version_str) 108 | ENDIF() 109 | 110 | INCLUDE(FindPackageHandleStandardArgs) 111 | # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if 112 | # all listed variables are TRUE 113 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua 114 | REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR 115 | VERSION_VAR LUA_VERSION_STRING) 116 | 117 | MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE) 118 | 119 | -------------------------------------------------------------------------------- /cmake/dist.cmake: -------------------------------------------------------------------------------- 1 | # LuaDist CMake utility library. 2 | # Provides sane project defaults and macros common to LuaDist CMake builds. 3 | # 4 | # Copyright (C) 2007-2012 LuaDist. 5 | # by David Manura, Peter Drahoš 6 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 7 | # For details see the COPYRIGHT file distributed with LuaDist. 8 | # Please note that the package source code is licensed under its own license. 9 | 10 | ## Extract information from dist.info 11 | if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info ) 12 | message ( FATAL_ERROR 13 | "Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." ) 14 | endif () 15 | file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO ) 16 | if ( "${DIST_INFO}" STREQUAL "" ) 17 | message ( FATAL_ERROR "Failed to load dist.info." ) 18 | endif () 19 | # Reads field `name` from dist.info string `DIST_INFO` into variable `var`. 20 | macro ( _parse_dist_field name var ) 21 | string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1" 22 | ${var} "${DIST_INFO}" ) 23 | if ( ${var} STREQUAL DIST_INFO ) 24 | message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" ) 25 | endif () 26 | endmacro () 27 | # 28 | _parse_dist_field ( name DIST_NAME ) 29 | _parse_dist_field ( version DIST_VERSION ) 30 | _parse_dist_field ( license DIST_LICENSE ) 31 | _parse_dist_field ( author DIST_AUTHOR ) 32 | _parse_dist_field ( maintainer DIST_MAINTAINER ) 33 | _parse_dist_field ( url DIST_URL ) 34 | _parse_dist_field ( desc DIST_DESC ) 35 | message ( "DIST_NAME: ${DIST_NAME}") 36 | message ( "DIST_VERSION: ${DIST_VERSION}") 37 | message ( "DIST_LICENSE: ${DIST_LICENSE}") 38 | message ( "DIST_AUTHOR: ${DIST_AUTHOR}") 39 | message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}") 40 | message ( "DIST_URL: ${DIST_URL}") 41 | message ( "DIST_DESC: ${DIST_DESC}") 42 | string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1" 43 | DIST_DEPENDS ${DIST_INFO} ) 44 | if ( DIST_DEPENDS STREQUAL DIST_INFO ) 45 | set ( DIST_DEPENDS "" ) 46 | endif () 47 | message ( "DIST_DEPENDS: ${DIST_DEPENDS}") 48 | ## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add 49 | 50 | 51 | ## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX) 52 | # Primary paths 53 | set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." ) 54 | set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." ) 55 | set ( INSTALL_INC include CACHE PATH "Where to install headers to." ) 56 | set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" ) 57 | set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." ) 58 | 59 | # Secondary paths 60 | option ( INSTALL_VERSION 61 | "Install runtime libraries and executables with version information." OFF) 62 | set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH 63 | "Directory the package can store documentation, tests or other data in.") 64 | set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH 65 | "Recommended directory to install documentation into.") 66 | set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH 67 | "Recommended directory to install examples into.") 68 | set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH 69 | "Recommended directory to install tests into.") 70 | set ( INSTALL_FOO ${INSTALL_DATA}/etc CACHE PATH 71 | "Where to install additional files") 72 | 73 | # Tweaks and other defaults 74 | # Setting CMAKE to use loose block and search for find modules in source directory 75 | set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) 76 | set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} ) 77 | option ( BUILD_SHARED_LIBS "Build shared libraries" ON ) 78 | 79 | # In MSVC, prevent warnings that can occur when using standard libraries. 80 | if ( MSVC ) 81 | add_definitions ( -D_CRT_SECURE_NO_WARNINGS ) 82 | endif () 83 | 84 | # RPath and relative linking 85 | option ( USE_RPATH "Use relative linking." ON) 86 | if ( USE_RPATH ) 87 | string ( REGEX REPLACE "[^!/]+" ".." UP_DIR ${INSTALL_BIN} ) 88 | set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE ) 89 | set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE ) 90 | set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB} 91 | CACHE STRING "" FORCE ) 92 | set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING "" FORCE ) 93 | set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB} 94 | CACHE STRING "" FORCE ) 95 | endif () 96 | 97 | ## MACROS 98 | # Parser macro 99 | macro ( parse_arguments prefix arg_names option_names) 100 | set ( DEFAULT_ARGS ) 101 | foreach ( arg_name ${arg_names} ) 102 | set ( ${prefix}_${arg_name} ) 103 | endforeach () 104 | foreach ( option ${option_names} ) 105 | set ( ${prefix}_${option} FALSE ) 106 | endforeach () 107 | 108 | set ( current_arg_name DEFAULT_ARGS ) 109 | set ( current_arg_list ) 110 | foreach ( arg ${ARGN} ) 111 | set ( larg_names ${arg_names} ) 112 | list ( FIND larg_names "${arg}" is_arg_name ) 113 | if ( is_arg_name GREATER -1 ) 114 | set ( ${prefix}_${current_arg_name} ${current_arg_list} ) 115 | set ( current_arg_name ${arg} ) 116 | set ( current_arg_list ) 117 | else () 118 | set ( loption_names ${option_names} ) 119 | list ( FIND loption_names "${arg}" is_option ) 120 | if ( is_option GREATER -1 ) 121 | set ( ${prefix}_${arg} TRUE ) 122 | else () 123 | set ( current_arg_list ${current_arg_list} ${arg} ) 124 | endif () 125 | endif () 126 | endforeach () 127 | set ( ${prefix}_${current_arg_name} ${current_arg_list} ) 128 | endmacro () 129 | 130 | 131 | # install_executable ( executable_targets ) 132 | # Installs any executables generated using "add_executable". 133 | # USE: install_executable ( lua ) 134 | # NOTE: subdirectories are NOT supported 135 | set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" ) 136 | set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION 137 | "Executables and runtime libraries. Installed into ${INSTALL_BIN}." ) 138 | macro ( install_executable ) 139 | foreach ( _file ${ARGN} ) 140 | if ( INSTALL_VERSION ) 141 | set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION} 142 | SOVERSION ${DIST_VERSION} ) 143 | endif () 144 | install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN} 145 | COMPONENT Runtime ) 146 | endforeach() 147 | endmacro () 148 | 149 | # install_library ( library_targets ) 150 | # Installs any libraries generated using "add_library" into apropriate places. 151 | # USE: install_library ( libexpat ) 152 | # NOTE: subdirectories are NOT supported 153 | set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" ) 154 | set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION 155 | "Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." ) 156 | macro ( install_library ) 157 | foreach ( _file ${ARGN} ) 158 | if ( INSTALL_VERSION ) 159 | set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION} 160 | SOVERSION ${DIST_VERSION} ) 161 | endif () 162 | install ( TARGETS ${_file} 163 | RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime 164 | LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime 165 | ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library ) 166 | endforeach() 167 | endmacro () 168 | 169 | # helper function for various install_* functions, for PATTERN/REGEX args. 170 | macro ( _complete_install_args ) 171 | if ( NOT("${_ARG_PATTERN}" STREQUAL "") ) 172 | set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} ) 173 | endif () 174 | if ( NOT("${_ARG_REGEX}" STREQUAL "") ) 175 | set ( _ARG_REGEX REGEX ${_ARG_REGEX} ) 176 | endif () 177 | endmacro () 178 | 179 | # install_header ( files/directories [INTO destination] ) 180 | # Install a directories or files into header destination. 181 | # USE: install_header ( lua.h luaconf.h ) or install_header ( GL ) 182 | # USE: install_header ( mylib.h INTO mylib ) 183 | # For directories, supports optional PATTERN/REGEX arguments like install(). 184 | set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" ) 185 | set ( CPACK_COMPONENT_HEADER_DESCRIPTION 186 | "Headers needed for development. Installed into ${INSTALL_INC}." ) 187 | macro ( install_header ) 188 | parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) 189 | _complete_install_args() 190 | foreach ( _file ${_ARG_DEFAULT_ARGS} ) 191 | if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) 192 | install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} 193 | COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} ) 194 | else () 195 | install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} 196 | COMPONENT Header ) 197 | endif () 198 | endforeach() 199 | endmacro () 200 | 201 | # install_data ( files/directories [INTO destination] ) 202 | # This installs additional data files or directories. 203 | # USE: install_data ( extra data.dat ) 204 | # USE: install_data ( image1.png image2.png INTO images ) 205 | # For directories, supports optional PATTERN/REGEX arguments like install(). 206 | set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" ) 207 | set ( CPACK_COMPONENT_DATA_DESCRIPTION 208 | "Application data. Installed into ${INSTALL_DATA}." ) 209 | macro ( install_data ) 210 | parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) 211 | _complete_install_args() 212 | foreach ( _file ${_ARG_DEFAULT_ARGS} ) 213 | if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) 214 | install ( DIRECTORY ${_file} 215 | DESTINATION ${INSTALL_DATA}/${_ARG_INTO} 216 | COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} ) 217 | else () 218 | install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO} 219 | COMPONENT Data ) 220 | endif () 221 | endforeach() 222 | endmacro () 223 | 224 | # INSTALL_DOC ( files/directories [INTO destination] ) 225 | # This installs documentation content 226 | # USE: install_doc ( doc/ doc.pdf ) 227 | # USE: install_doc ( index.html INTO html ) 228 | # For directories, supports optional PATTERN/REGEX arguments like install(). 229 | set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" ) 230 | set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION 231 | "Application documentation. Installed into ${INSTALL_DOC}." ) 232 | macro ( install_doc ) 233 | parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) 234 | _complete_install_args() 235 | foreach ( _file ${_ARG_DEFAULT_ARGS} ) 236 | if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) 237 | install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} 238 | COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} ) 239 | else () 240 | install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} 241 | COMPONENT Documentation ) 242 | endif () 243 | endforeach() 244 | endmacro () 245 | 246 | # install_example ( files/directories [INTO destination] ) 247 | # This installs additional examples 248 | # USE: install_example ( examples/ exampleA ) 249 | # USE: install_example ( super_example super_data INTO super) 250 | # For directories, supports optional PATTERN/REGEX argument like install(). 251 | set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" ) 252 | set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION 253 | "Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." ) 254 | macro ( install_example ) 255 | parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) 256 | _complete_install_args() 257 | foreach ( _file ${_ARG_DEFAULT_ARGS} ) 258 | if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) 259 | install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} 260 | COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} ) 261 | else () 262 | install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} 263 | COMPONENT Example ) 264 | endif () 265 | endforeach() 266 | endmacro () 267 | 268 | # install_test ( files/directories [INTO destination] ) 269 | # This installs tests and test files, DOES NOT EXECUTE TESTS 270 | # USE: install_test ( my_test data.sql ) 271 | # USE: install_test ( feature_x_test INTO x ) 272 | # For directories, supports optional PATTERN/REGEX argument like install(). 273 | set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" ) 274 | set ( CPACK_COMPONENT_TEST_DESCRIPTION 275 | "Tests and associated data. Installed into ${INSTALL_TEST}." ) 276 | macro ( install_test ) 277 | parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) 278 | _complete_install_args() 279 | foreach ( _file ${_ARG_DEFAULT_ARGS} ) 280 | if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) 281 | install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} 282 | COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} ) 283 | else () 284 | install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} 285 | COMPONENT Test ) 286 | endif () 287 | endforeach() 288 | endmacro () 289 | 290 | # install_foo ( files/directories [INTO destination] ) 291 | # This installs optional or otherwise unneeded content 292 | # USE: install_foo ( etc/ example.doc ) 293 | # USE: install_foo ( icon.png logo.png INTO icons) 294 | # For directories, supports optional PATTERN/REGEX argument like install(). 295 | set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" ) 296 | set ( CPACK_COMPONENT_OTHER_DESCRIPTION 297 | "Other unspecified content. Installed into ${INSTALL_FOO}." ) 298 | macro ( install_foo ) 299 | parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) 300 | _complete_install_args() 301 | foreach ( _file ${_ARG_DEFAULT_ARGS} ) 302 | if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) 303 | install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} 304 | COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} ) 305 | else () 306 | install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} 307 | COMPONENT Other ) 308 | endif () 309 | endforeach() 310 | endmacro () 311 | 312 | ## CTest defaults 313 | 314 | ## CPack defaults 315 | set ( CPACK_GENERATOR "ZIP" ) 316 | set ( CPACK_STRIP_FILES TRUE ) 317 | set ( CPACK_PACKAGE_NAME "${DIST_NAME}" ) 318 | set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}") 319 | set ( CPACK_PACKAGE_VENDOR "LuaDist" ) 320 | set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other ) 321 | include ( CPack ) 322 | -------------------------------------------------------------------------------- /cmake/lua.cmake: -------------------------------------------------------------------------------- 1 | # LuaDist CMake utility library for Lua. 2 | # 3 | # Copyright (C) 2007-2012 LuaDist. 4 | # by David Manura, Peter Drahos 5 | # Redistribution and use of this file is allowed according to the terms of the MIT license. 6 | # For details see the COPYRIGHT file distributed with LuaDist. 7 | # Please note that the package source code is licensed under its own license. 8 | 9 | set ( INSTALL_LMOD ${INSTALL_LIB}/lua 10 | CACHE PATH "Directory to install Lua modules." ) 11 | set ( INSTALL_CMOD ${INSTALL_LIB}/lua 12 | CACHE PATH "Directory to install Lua binary modules." ) 13 | 14 | option ( SKIP_LUA_WRAPPER 15 | "Do not build and install Lua executable wrappers." OFF) 16 | 17 | # List of (Lua module name, file path) pairs. 18 | # Used internally by add_lua_test. Built by add_lua_module. 19 | set ( _lua_modules ) 20 | 21 | # utility function: appends path `path` to path `basepath`, properly 22 | # handling cases when `path` may be relative or absolute. 23 | macro ( _append_path basepath path result ) 24 | if ( IS_ABSOLUTE "${path}" ) 25 | set ( ${result} "${path}" ) 26 | else () 27 | set ( ${result} "${basepath}/${path}" ) 28 | endif () 29 | endmacro () 30 | 31 | # install_lua_executable ( target source ) 32 | # Automatically generate a binary if srlua package is available 33 | # The application or its source will be placed into /bin 34 | # If the application source did not have .lua suffix then it will be added 35 | # USE: lua_executable ( sputnik src/sputnik.lua ) 36 | macro ( install_lua_executable _name _source ) 37 | get_filename_component ( _source_name ${_source} NAME_WE ) 38 | # Find srlua and glue 39 | find_program( SRLUA_EXECUTABLE NAMES srlua ) 40 | find_program( GLUE_EXECUTABLE NAMES glue ) 41 | # Executable output 42 | set ( _exe ${CMAKE_CURRENT_BINARY_DIR}/${_name}${CMAKE_EXECUTABLE_SUFFIX} ) 43 | if ( NOT SKIP_LUA_WRAPPER AND SRLUA_EXECUTABLE AND GLUE_EXECUTABLE ) 44 | # Generate binary gluing the lua code to srlua, this is a robuust approach for most systems 45 | add_custom_command( 46 | OUTPUT ${_exe} 47 | COMMAND ${GLUE_EXECUTABLE} 48 | ARGS ${SRLUA_EXECUTABLE} ${_source} ${_exe} 49 | DEPENDS ${_source} 50 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 51 | VERBATIM 52 | ) 53 | # Make sure we have a target associated with the binary 54 | add_custom_target(${_name} ALL 55 | DEPENDS ${_exe} 56 | ) 57 | # Install with run permissions 58 | install ( PROGRAMS ${_exe} DESTINATION ${INSTALL_BIN} COMPONENT Runtime) 59 | # Also install source as optional resurce 60 | install ( FILES ${_source} DESTINATION ${INSTALL_FOO} COMPONENT Other ) 61 | else() 62 | # Install into bin as is but without the lua suffix, we assume the executable uses UNIX shebang/hash-bang magic 63 | install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN} 64 | RENAME ${_source_name} 65 | COMPONENT Runtime 66 | ) 67 | endif() 68 | endmacro () 69 | 70 | macro ( _lua_module_helper is_install _name ) 71 | parse_arguments ( _MODULE "LINK;ALL_IN_ONE" "" ${ARGN} ) 72 | # _target is CMake-compatible target name for module (e.g. socket_core). 73 | # _module is relative path of target (e.g. socket/core), 74 | # without extension (e.g. .lua/.so/.dll). 75 | # _MODULE_SRC is list of module source files (e.g. .lua and .c files). 76 | # _MODULE_NAMES is list of module names (e.g. socket.core). 77 | if ( _MODULE_ALL_IN_ONE ) 78 | string ( REGEX REPLACE "\\..*" "" _target "${_name}" ) 79 | string ( REGEX REPLACE "\\..*" "" _module "${_name}" ) 80 | set ( _target "${_target}_all_in_one") 81 | set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} ) 82 | set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} ) 83 | else () 84 | string ( REPLACE "." "_" _target "${_name}" ) 85 | string ( REPLACE "." "/" _module "${_name}" ) 86 | set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} ) 87 | set ( _MODULE_NAMES ${_name} ) 88 | endif () 89 | if ( NOT _MODULE_SRC ) 90 | message ( FATAL_ERROR "no module sources specified" ) 91 | endif () 92 | list ( GET _MODULE_SRC 0 _first_source ) 93 | 94 | get_filename_component ( _ext ${_first_source} EXT ) 95 | if ( _ext STREQUAL ".lua" ) # Lua source module 96 | list ( LENGTH _MODULE_SRC _len ) 97 | if ( _len GREATER 1 ) 98 | message ( FATAL_ERROR "more than one source file specified" ) 99 | endif () 100 | 101 | set ( _module "${_module}.lua" ) 102 | 103 | get_filename_component ( _module_dir ${_module} PATH ) 104 | get_filename_component ( _module_filename ${_module} NAME ) 105 | _append_path ( "${CMAKE_CURRENT_SOURCE_DIR}" "${_first_source}" _module_path ) 106 | list ( APPEND _lua_modules "${_name}" "${_module_path}" ) 107 | 108 | if ( ${is_install} ) 109 | install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir} 110 | RENAME ${_module_filename} 111 | COMPONENT Runtime 112 | ) 113 | endif () 114 | else () # Lua C binary module 115 | enable_language ( C ) 116 | find_package ( Lua REQUIRED ) 117 | include_directories ( ${LUA_INCLUDE_DIR} ) 118 | 119 | set ( _module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" ) 120 | 121 | get_filename_component ( _module_dir ${_module} PATH ) 122 | get_filename_component ( _module_filenamebase ${_module} NAME_WE ) 123 | foreach ( _thisname ${_MODULE_NAMES} ) 124 | list ( APPEND _lua_modules "${_thisname}" 125 | "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_CFG_INTDIR}/${_module}" ) 126 | endforeach () 127 | 128 | add_library( ${_target} MODULE ${_MODULE_SRC}) 129 | target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} ) 130 | set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY 131 | "${_module_dir}" PREFIX "" OUTPUT_NAME "${_module_filenamebase}" ) 132 | if ( ${is_install} ) 133 | install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_dir} COMPONENT Runtime) 134 | endif () 135 | endif () 136 | endmacro () 137 | 138 | # add_lua_module 139 | # Builds a Lua source module into a destination locatable by Lua 140 | # require syntax. 141 | # Binary modules are also supported where this function takes sources and 142 | # libraries to compile separated by LINK keyword. 143 | # USE: add_lua_module ( socket.http src/http.lua ) 144 | # USE2: add_lua_module ( mime.core src/mime.c ) 145 | # USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} ) 146 | # USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c ) 147 | # This form builds an "all-in-one" module (e.g. ssl.so or ssl.dll containing 148 | # both modules ssl.context and ssl.core). The CMake target name will be 149 | # ssl_all_in_one. 150 | # Also sets variable _module_path (relative path where module typically 151 | # would be installed). 152 | macro ( add_lua_module ) 153 | _lua_module_helper ( 0 ${ARGN} ) 154 | endmacro () 155 | 156 | 157 | # install_lua_module 158 | # This is the same as `add_lua_module` but also installs the module. 159 | # USE: install_lua_module ( socket.http src/http.lua ) 160 | # USE2: install_lua_module ( mime.core src/mime.c ) 161 | # USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} ) 162 | macro ( install_lua_module ) 163 | _lua_module_helper ( 1 ${ARGN} ) 164 | endmacro () 165 | 166 | # Builds string representing Lua table mapping Lua modules names to file 167 | # paths. Used internally. 168 | macro ( _make_module_table _outvar ) 169 | set ( ${_outvar} ) 170 | list ( LENGTH _lua_modules _n ) 171 | if ( ${_n} GREATER 0 ) # avoids cmake complaint 172 | foreach ( _i RANGE 1 ${_n} 2 ) 173 | list ( GET _lua_modules ${_i} _path ) 174 | math ( EXPR _ii ${_i}-1 ) 175 | list ( GET _lua_modules ${_ii} _name ) 176 | set ( ${_outvar} "${_table} ['${_name}'] = '${_path}'\;\n") 177 | endforeach () 178 | endif () 179 | set ( ${_outvar} 180 | "local modules = { 181 | ${_table}}" ) 182 | endmacro () 183 | 184 | # add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] ) 185 | # Runs Lua script `_testfile` under CTest tester. 186 | # Optional named argument `WORKING_DIRECTORY` is current working directory to 187 | # run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}). 188 | # Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}. 189 | # Any modules previously defined with install_lua_module are automatically 190 | # preloaded (via package.preload) prior to running the test script. 191 | # Under LuaDist, set test=true in config.lua to enable testing. 192 | # USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir]) 193 | macro ( add_lua_test _testfile ) 194 | if ( NOT SKIP_TESTING ) 195 | parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} ) 196 | include ( CTest ) 197 | find_program ( LUA NAMES lua lua.bat ) 198 | get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE ) 199 | get_filename_component ( TESTFILENAME ${_testfile} NAME ) 200 | get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE ) 201 | 202 | # Write wrapper script. 203 | # Note: One simple way to allow the script to find modules is 204 | # to just put them in package.preload. 205 | set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} ) 206 | _make_module_table ( _table ) 207 | set ( TESTWRAPPERSOURCE 208 | "local CMAKE_CFG_INTDIR = ... or '.' 209 | ${_table} 210 | local function preload_modules(modules) 211 | for name, path in pairs(modules) do 212 | if path:match'%.lua' then 213 | package.preload[name] = assert(loadfile(path)) 214 | else 215 | local name = name:gsub('.*%-', '') -- remove any hyphen prefix 216 | local symbol = 'luaopen_' .. name:gsub('%.', '_') 217 | --improve: generalize to support all-in-one loader? 218 | local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR) 219 | package.preload[name] = assert(package.loadlib(path, symbol)) 220 | end 221 | end 222 | end 223 | preload_modules(modules) 224 | arg[0] = '${TESTFILEABS}' 225 | table.remove(arg, 1) 226 | return assert(loadfile '${TESTFILEABS}')(unpack(arg)) 227 | " ) 228 | if ( _ARG_WORKING_DIRECTORY ) 229 | get_filename_component ( 230 | TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE ) 231 | # note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter. 232 | set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" ) 233 | endif () 234 | file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE}) 235 | add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA} 236 | ${TESTWRAPPER} "${CMAKE_CFG_INTDIR}" 237 | ${_ARG_DEFAULT_ARGS} ) 238 | endif () 239 | # see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake 240 | # Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper 241 | # expansion by the native build tool. 242 | endmacro () 243 | 244 | 245 | # Converts Lua source file `_source` to binary string embedded in C source 246 | # file `_target`. Optionally compiles Lua source to byte code (not available 247 | # under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua 248 | # versions of bin2c [1] and luac [2] may be passed respectively as additional 249 | # arguments. 250 | # 251 | # [1] http://lua-users.org/wiki/BinToCee 252 | # [2] http://lua-users.org/wiki/LuaCompilerInLua 253 | function ( add_lua_bin2c _target _source ) 254 | find_program ( LUA NAMES lua lua.bat ) 255 | execute_process ( COMMAND ${LUA} -e "string.dump(function()end)" 256 | RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET ) 257 | if ( NOT ${_LUA_DUMP_RESULT} ) 258 | SET ( HAVE_LUA_DUMP true ) 259 | endif () 260 | message ( "-- string.dump=${HAVE_LUA_DUMP}" ) 261 | 262 | if ( ARGV2 ) 263 | get_filename_component ( BIN2C ${ARGV2} ABSOLUTE ) 264 | set ( BIN2C ${LUA} ${BIN2C} ) 265 | else () 266 | find_program ( BIN2C NAMES bin2c bin2c.bat ) 267 | endif () 268 | if ( HAVE_LUA_DUMP ) 269 | if ( ARGV3 ) 270 | get_filename_component ( LUAC ${ARGV3} ABSOLUTE ) 271 | set ( LUAC ${LUA} ${LUAC} ) 272 | else () 273 | find_program ( LUAC NAMES luac luac.bat ) 274 | endif () 275 | endif ( HAVE_LUA_DUMP ) 276 | message ( "-- bin2c=${BIN2C}" ) 277 | message ( "-- luac=${LUAC}" ) 278 | 279 | get_filename_component ( SOURCEABS ${_source} ABSOLUTE ) 280 | if ( HAVE_LUA_DUMP ) 281 | get_filename_component ( SOURCEBASE ${_source} NAME_WE ) 282 | add_custom_command ( 283 | OUTPUT ${_target} DEPENDS ${_source} 284 | COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo 285 | ${SOURCEABS} 286 | COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo 287 | ">${_target}" ) 288 | else () 289 | add_custom_command ( 290 | OUTPUT ${_target} DEPENDS ${SOURCEABS} 291 | COMMAND ${BIN2C} ${_source} ">${_target}" ) 292 | endif () 293 | endfunction() 294 | -------------------------------------------------------------------------------- /dist.info: -------------------------------------------------------------------------------- 1 | --- This dist file is part of LuaDist project 2 | 3 | name = "luapretty" 4 | version = "0.2" 5 | 6 | desc = "LuaPretty is a Lua source code formater and pretty printer" 7 | author = "Viliam Kubis, Peter Kapec" 8 | license = "MIT" 9 | url = "https://github.com/LuaDist/luapretty" 10 | maintainer = "Peter Kapec" 11 | 12 | depends = { 13 | "lua ~> 5.1", 14 | "alt-getopt >= 0.7", 15 | "cosmo >= 10.04.06", 16 | "leg = 0.1.3 ", 17 | } 18 | -------------------------------------------------------------------------------- /src/lua-formatter.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | ------------------------------------------------------------------------------- 3 | -- LuaFormatter 4 | -- @release 2011/04/04 11:49:00, Viliam Kubis 5 | ------------------------------------------------------------------------------- 6 | 7 | local formatter=require("luapretty.formatter"); 8 | local getopt=require("alt_getopt"); 9 | 10 | local long_opts = { 11 | template = "t", 12 | force = "f", 13 | help = "h" 14 | } 15 | 16 | local function process_text(text,template) 17 | local result,err=formatter.format_text(text,template); 18 | if(not result) then 19 | error("ERROR: "..err); 20 | end 21 | return result 22 | end 23 | 24 | local subor=nil; --template file 25 | 26 | local function usage_info(args) 27 | print("\nUsage: "..arg[0].. 28 | [[ [] [-t