diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..57493ebb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,51 @@ +# +# LuaDist Travis-CI Hook +# + +# We assume C build environments +language: C + +# Try using multiple Lua Implementations +env: + - TOOL="gcc" # Use native compiler (GCC usually) + - TOOL="clang" # Use clang + - TOOL="i686-w64-mingw32" # 32bit MinGW + - TOOL="x86_64-w64-mingw32" # 64bit MinGW + - TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux + +# Crosscompile builds may fail +matrix: + allow_failures: + - env: TOOL="i686-w64-mingw32" + - env: TOOL="x86_64-w64-mingw32" + - env: TOOL="arm-linux-gnueabihf" + +# Install dependencies +install: + - git clone git://github.com/LuaDist/Tools.git ~/_tools + - ~/_tools/travis/travis install + +# Bootstap +before_script: + - ~/_tools/travis/travis bootstrap + +# Build the module +script: + - ~/_tools/travis/travis build + +# Execute additional tests or commands +after_script: + - ~/_tools/travis/travis test + +# Only watch the master branch +branches: + only: + - master + +# Notify the LuaDist Dev group if needed +notifications: + recipients: + - luadist-dev@googlegroups.com + email: + on_success: change + on_failure: always diff --git a/CMakeLists.txt b/CMakeLists.txt index cf521cac..cc303f5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ -# Copyright (C) 2007-2011 LuaDist. +# Copyright (C) 2007-2013 LuaDist. # Created by Peter Drahoš, Peter Kapec # Redistribution and use of this file is allowed according to the terms of the MIT license. # For details see the COPYRIGHT file distributed with LuaDist. # Please note that the package source code is licensed under its own license. project ( lua C ) -cmake_minimum_required ( VERSION 2.6 ) -include ( dist.cmake ) +cmake_minimum_required ( VERSION 2.8 ) +include ( cmake/dist.cmake ) ## CONFIGURATION # Default configuration (we assume POSIX by default) @@ -18,12 +18,8 @@ option ( LUA_ANSI "Use only ansi features." OFF ) option ( LUA_USE_RELATIVE_LOADLIB "Use modified loadlib.c with support for relative paths on posix systems." ON ) option ( LUA_COMPAT_ALL "Enable backwards compatibility options." ON ) set ( LUA_IDSIZE 60 CACHE NUMBER "gives the maximum size for the description of the source." ) -#set ( LUA_PROMPT "> " CACHE STRING "Is the default prompt used by stand-alone Lua." ) -#set ( LUA_PROMPT2 ">> " CACHE STRING "Is the default continuation prompt used by stand-alone Lua." ) -#set ( LUA_MAXINPUT 512 CACHE NUMBER "Is the maximum length for an input line in the stand-alone interpreter.") #2DO: LUAI_* and LUAL_* settings, for now defaults are used. - set ( LUA_DIRSEP "/" ) set ( LUA_MODULE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX} ) set ( LUA_LDIR ${INSTALL_LMOD} ) @@ -32,10 +28,10 @@ set ( LUA_CDIR ${INSTALL_CMOD} ) if ( LUA_USE_RELATIVE_LOADLIB ) # This will set up relative paths to lib string ( REGEX REPLACE "[^!/]+" ".." LUA_DIR "!/${INSTALL_BIN}/" ) -else () +else ( ) # Direct path to installation - set ( LUA_DIR ${CMAKE_INSTALL_PREFIX} CACHE STRING "Destination from which modules will be resolved. See INSTALL_LMOD and INSTALL_CMOD.") -endif () + set ( LUA_DIR ${CMAKE_INSTALL_PREFIX} CACHE STRING "Destination from which modules will be resolved. See INSTALL_LMOD and INSTALL_CMOD." ) +endif ( ) set ( LUA_PATH_DEFAULT "./?.lua;${LUA_DIR}${LUA_LDIR}/?.lua;${LUA_DIR}${LUA_LDIR}/?/init.lua" ) set ( LUA_CPATH_DEFAULT "./?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/loadall${LUA_MODULE_SUFFIX}" ) @@ -43,61 +39,70 @@ set ( LUA_CPATH_DEFAULT "./?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/?${LUA_MO if ( WIN32 AND NOT CYGWIN ) # Windows systems option ( LUA_WIN "Windows specific build." ON ) - option ( LUA_BUILD_AS_DLL "Build Lua library as Dll." ON ) - # Paths (Double escapes needed) + option ( LUA_BUILD_WLUA "Build wLua interpretter without console output." ON ) + option ( LUA_BUILD_AS_DLL "Build Lua library as Dll." ${BUILD_SHARED_LIBS} ) + + # Paths (Double escapes ne option needed) set ( LUA_DIRSEP "\\\\" ) - string ( REPLACE "/" ${LUA_DIRSEP} LUA_DIR "${LUA_DIR}" ) + string ( REPLACE " /" ${LUA_DIRSEP} LUA_DIR "${LUA_DIR}" ) string ( REPLACE "/" ${LUA_DIRSEP} LUA_LDIR "${LUA_LDIR}" ) string ( REPLACE "/" ${LUA_DIRSEP} LUA_CDIR "${LUA_CDIR}" ) string ( REPLACE "/" ${LUA_DIRSEP} LUA_PATH_DEFAULT "${LUA_PATH_DEFAULT}" ) string ( REPLACE "/" ${LUA_DIRSEP} LUA_CPATH_DEFAULT "${LUA_CPATH_DEFAULT}" ) -else () +else ( ) # Posix systems (incl. Cygwin) - option ( LUA_USE_POSIX "Use POSIX functionality." ON ) + option ( LUA_USE_POSIX "Use POSIX features." ON ) option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON ) option ( LUA_USE_MKSTEMP "Use mkstep." ON ) option ( LUA_USE_ISATTY "Use tty." ON ) option ( LUA_USE_POPEN "Use popen." ON ) - option ( LUA_USE_ULONGJMP "Use ulongjmp" ON) - option ( LUA_USE_STRTODHEX "assume 'strtod' handles hexa formats" ON ) - option ( LUA_USE_AFORMAT "assume 'printf' handles 'aA' specifiers" ON ) - option ( LUA_USE_LONGLONG "assume support for long long" ON) -endif () + option ( LUA_USE_ULONGJMP "Use ulongjmp" ON ) + option ( LUA_USE_GMTIME_R "Use GTIME_R" ON ) + # Apple and Linux specific + if ( LINUX OR APPLE ) + option ( LUA_USE_STRTODHEX "Assume 'strtod' handles hexa formats" ON ) + option ( LUA_USE_AFORMAT "Assume 'printf' handles 'aA' specifiers" ON ) + option ( LUA_USE_LONGLONG "Assume support for long long" ON ) + endif ( ) +endif ( ) ## SETUP # Optional libraries find_package ( Readline ) if ( READLINE_FOUND ) option ( LUA_USE_READLINE "Use readline in the Lua CLI." ON ) -endif () +endif ( ) find_package ( Curses ) if ( CURSES_FOUND ) option ( LUA_USE_CURSES "Use curses in the Lua CLI." ON ) -endif () +endif ( ) # Setup needed variables and libraries if ( LUA_USE_POSIX ) # On POSIX Lua links to standard math library "m" list ( APPEND LIBS m ) -endif () +endif ( ) if ( LUA_USE_DLOPEN ) # Link to dynamic linker library "dl" - list ( APPEND LIBS dl ) -endif () + find_library ( DL_LIBRARY NAMES dl ) + if ( DL_LIBRARY ) + list ( APPEND LIBS ${DL_LIBRARY} ) + endif ( ) +endif ( ) if ( LUA_USE_READLINE ) # Add readline include_directories ( ${READLINE_INCLUDE_DIR} ) list ( APPEND LIBS ${READLINE_LIBRARY} ) -endif () +endif ( ) if ( LUA_USE_CURSES ) # Add curses include_directories ( ${CURSES_INCLUDE_DIR} ) list ( APPEND LIBS ${CURSES_LIBRARY} ) -endif () +endif ( ) ## SOURCES # Generate luaconf.h @@ -105,66 +110,48 @@ configure_file ( src/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h ) # Sources and headers include_directories ( src ${CMAKE_CURRENT_BINARY_DIR} ) -set ( SRC_CORE - src/lapi.c - src/lcode.c - src/lctype.c - src/ldebug.c - src/ldo.c - src/ldump.c - src/lfunc.c - src/lgc.c - src/llex.c - src/lmem.c - src/lobject.c - src/lopcodes.c - src/lparser.c - src/lstate.c - src/lstring.c - src/ltable.c - src/ltm.c - src/lundump.c - src/lvm.c - src/lzio.c) -set ( SRC_LIB - src/lauxlib.c - src/lbaselib.c - src/lbitlib.c - src/lcorolib.c - src/ldblib.c - src/liolib.c - src/lmathlib.c - src/loslib.c - src/lstrlib.c - src/ltablib.c - src/linit.c) +set ( SRC_CORE src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src/ldump.c + src/lfunc.c src/lgc.c src/llex.c src/lmem.c src/lobject.c src/lopcodes.c src/lparser.c + src/lstate.c src/lstring.c src/ltable.c src/ltm.c src/lundump.c src/lvm.c src/lzio.c ) +set ( SRC_LIB src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c + src/liolib.c src/lmathlib.c src/loslib.c src/lstrlib.c src/ltablib.c src/linit.c ) set ( SRC_LUA src/lua.c ) set ( SRC_LUAC src/luac.c ) if ( LUA_USE_RELATIVE_LOADLIB ) # Use modified loadlib list ( APPEND SRC_LIB src/loadlib_rel.c ) -else () +else ( ) list ( APPEND SRC_LIB src/loadlib.c ) -endif () +endif ( ) ## BUILD # Create lua library -add_library ( liblua SHARED ${SRC_CORE} ${SRC_LIB} ${LUA_DLL_RC} ${LUA_DEF} ) +add_library ( liblua ${SRC_CORE} ${SRC_LIB} ${LUA_DLL_RC} ${LUA_DEF} ) target_link_libraries ( liblua ${LIBS} ) set_target_properties ( liblua PROPERTIES OUTPUT_NAME lua CLEAN_DIRECT_OUTPUT 1 ) +if ( LUA_BUILD_AS_DLL ) + set_target_properties ( liblua PROPERTIES COMPILE_DEFINITIONS LUA_BUILD_AS_DLL ) +endif () add_executable ( lua ${SRC_LUA} src/lua.rc ) target_link_libraries ( lua liblua ) -add_executable ( luac ${SRC_LUAC} src/luac.rc ) -target_link_libraries ( luac liblua ) +add_executable ( luac ${SRC_CORE} ${SRC_LIB} ${SRC_LUAC} src/luac.rc ) +target_link_libraries ( luac ${LIBS} ) + +# On windows a variant of the lua interpreter without console output needs to be built +if ( LUA_BUILD_WLUA ) + add_executable ( wlua WIN32 src/wmain.c ${SRC_LUA} src/lua.rc ) + target_link_libraries ( wlua liblua ) + install_executable ( wlua ) +endif ( ) install_executable ( lua luac ) install_library ( liblua ) -install_data ( README ) +install_data ( README.md ) #install_lua_module ( strict etc/strict.lua ) -install_header (src/lua.h src/lualib.h src/lauxlib.h ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h ) +install_header ( src/lua.h src/lualib.h src/lauxlib.h src/lua.hpp ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h ) install_doc ( doc/ ) install_foo ( etc/ ) #install_test ( test/ ) diff --git a/Makefile b/Makefile index ec53e1a2..b2a62cfd 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ TO_MAN= lua.1 luac.1 # Lua version and release. V= 5.2 -R= $V.0 +R= $V.4 # Targets start here. all: $(PLAT) diff --git a/README b/README.md similarity index 70% rename from README rename to README.md index 9c384675..710e3ee1 100644 --- a/README +++ b/README.md @@ -1,5 +1,5 @@ -This is Lua 5.2, released on 12 Dec 2011. +This is Lua 5.2.4, released on 25 Feb 2015. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake new file mode 100644 index 00000000..7fb7ca3f --- /dev/null +++ b/cmake/FindLua.cmake @@ -0,0 +1,118 @@ +# Locate Lua library +# This module defines +# LUA_EXECUTABLE, if found +# LUA_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# Modified to support Lua 5.2 by LuaDist 2012 +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) +# +# The required version of Lua can be specified using the +# standard syntax, e.g. FIND_PACKAGE(Lua 5.1) +# Otherwise the module will search for any available Lua implementation + +# Always search for non-versioned lua first (recommended) +SET(_POSSIBLE_LUA_INCLUDE include include/lua) +SET(_POSSIBLE_LUA_EXECUTABLE lua) +SET(_POSSIBLE_LUA_LIBRARY lua) + +# Determine possible naming suffixes (there is no standard for this) +IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + 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}") +ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1") +ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + +# Set up possible search names and locations +FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) + LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}") + LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}") + LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") +ENDFOREACH(_SUFFIX) + +# Find the lua executable +FIND_PROGRAM(LUA_EXECUTABLE + NAMES ${_POSSIBLE_LUA_EXECUTABLE} +) + +# Find the lua header +FIND_PATH(LUA_INCLUDE_DIR lua.h + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE} + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Find the lua library +FIND_LIBRARY(LUA_LIBRARY + NAMES ${_POSSIBLE_LUA_LIBRARY} + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +IF(LUA_LIBRARY) + # include the math library for Unix + IF(UNIX AND NOT APPLE) + FIND_LIBRARY(LUA_MATH_LIBRARY m) + SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + ELSE(UNIX AND NOT APPLE) + SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + ENDIF(UNIX AND NOT APPLE) +ENDIF(LUA_LIBRARY) + +# Determine Lua version +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + +INCLUDE(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE) + diff --git a/FindReadline.cmake b/cmake/FindReadline.cmake similarity index 100% rename from FindReadline.cmake rename to cmake/FindReadline.cmake diff --git a/cmake/dist.cmake b/cmake/dist.cmake new file mode 100644 index 00000000..310ef94c --- /dev/null +++ b/cmake/dist.cmake @@ -0,0 +1,321 @@ +# LuaDist CMake utility library. +# Provides sane project defaults and macros common to LuaDist CMake builds. +# +# Copyright (C) 2007-2012 LuaDist. +# by David Manura, Peter Drahoš +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the COPYRIGHT file distributed with LuaDist. +# Please note that the package source code is licensed under its own license. + +## Extract information from dist.info +if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info ) + message ( FATAL_ERROR + "Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." ) +endif () +file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO ) +if ( "${DIST_INFO}" STREQUAL "" ) + message ( FATAL_ERROR "Failed to load dist.info." ) +endif () +# Reads field `name` from dist.info string `DIST_INFO` into variable `var`. +macro ( _parse_dist_field name var ) + string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1" + ${var} "${DIST_INFO}" ) + if ( ${var} STREQUAL DIST_INFO ) + message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" ) + endif () +endmacro () +# +_parse_dist_field ( name DIST_NAME ) +_parse_dist_field ( version DIST_VERSION ) +_parse_dist_field ( license DIST_LICENSE ) +_parse_dist_field ( author DIST_AUTHOR ) +_parse_dist_field ( maintainer DIST_MAINTAINER ) +_parse_dist_field ( url DIST_URL ) +_parse_dist_field ( desc DIST_DESC ) +message ( "DIST_NAME: ${DIST_NAME}") +message ( "DIST_VERSION: ${DIST_VERSION}") +message ( "DIST_LICENSE: ${DIST_LICENSE}") +message ( "DIST_AUTHOR: ${DIST_AUTHOR}") +message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}") +message ( "DIST_URL: ${DIST_URL}") +message ( "DIST_DESC: ${DIST_DESC}") +string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1" + DIST_DEPENDS ${DIST_INFO} ) +if ( DIST_DEPENDS STREQUAL DIST_INFO ) + set ( DIST_DEPENDS "" ) +endif () +message ( "DIST_DEPENDS: ${DIST_DEPENDS}") +## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add + + +## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX) +# Primary paths +set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." ) +set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." ) +set ( INSTALL_INC include CACHE PATH "Where to install headers to." ) +set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" ) +set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." ) + +# Secondary paths +option ( INSTALL_VERSION + "Install runtime libraries and executables with version information." OFF) +set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH + "Directory the package can store documentation, tests or other data in.") +set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH + "Recommended directory to install documentation into.") +set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH + "Recommended directory to install examples into.") +set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH + "Recommended directory to install tests into.") +set ( INSTALL_FOO ${INSTALL_DATA}/etc CACHE PATH + "Where to install additional files") + +# Tweaks and other defaults +# Setting CMAKE to use loose block and search for find modules in source directory +set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) +set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} ) +option ( BUILD_SHARED_LIBS "Build shared libraries" ON ) + +# In MSVC, prevent warnings that can occur when using standard libraries. +if ( MSVC ) + add_definitions ( -D_CRT_SECURE_NO_WARNINGS ) +endif () + +# RPath and relative linking +option ( USE_RPATH "Use relative linking." ON) +if ( USE_RPATH ) + string ( REGEX REPLACE "[^!/]+" ".." UP_DIR ${INSTALL_BIN} ) + set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE ) + set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE ) + set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB} + CACHE STRING "" FORCE ) + set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING "" FORCE ) + set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB} + CACHE STRING "" FORCE ) +endif () + +## MACROS +# Parser macro +macro ( parse_arguments prefix arg_names option_names) + set ( DEFAULT_ARGS ) + foreach ( arg_name ${arg_names} ) + set ( ${prefix}_${arg_name} ) + endforeach () + foreach ( option ${option_names} ) + set ( ${prefix}_${option} FALSE ) + endforeach () + + set ( current_arg_name DEFAULT_ARGS ) + set ( current_arg_list ) + foreach ( arg ${ARGN} ) + set ( larg_names ${arg_names} ) + list ( FIND larg_names "${arg}" is_arg_name ) + if ( is_arg_name GREATER -1 ) + set ( ${prefix}_${current_arg_name} ${current_arg_list} ) + set ( current_arg_name ${arg} ) + set ( current_arg_list ) + else () + set ( loption_names ${option_names} ) + list ( FIND loption_names "${arg}" is_option ) + if ( is_option GREATER -1 ) + set ( ${prefix}_${arg} TRUE ) + else () + set ( current_arg_list ${current_arg_list} ${arg} ) + endif () + endif () + endforeach () + set ( ${prefix}_${current_arg_name} ${current_arg_list} ) +endmacro () + + +# install_executable ( executable_targets ) +# Installs any executables generated using "add_executable". +# USE: install_executable ( lua ) +# NOTE: subdirectories are NOT supported +set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" ) +set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION + "Executables and runtime libraries. Installed into ${INSTALL_BIN}." ) +macro ( install_executable ) + foreach ( _file ${ARGN} ) + if ( INSTALL_VERSION ) + set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION} + SOVERSION ${DIST_VERSION} ) + endif () + install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN} + COMPONENT Runtime ) + endforeach() +endmacro () + +# install_library ( library_targets ) +# Installs any libraries generated using "add_library" into apropriate places. +# USE: install_library ( libexpat ) +# NOTE: subdirectories are NOT supported +set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" ) +set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION + "Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." ) +macro ( install_library ) + foreach ( _file ${ARGN} ) + if ( INSTALL_VERSION ) + set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION} + SOVERSION ${DIST_VERSION} ) + endif () + install ( TARGETS ${_file} + RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime + LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime + ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library ) + endforeach() +endmacro () + +# helper function for various install_* functions, for PATTERN/REGEX args. +macro ( _complete_install_args ) + if ( NOT("${_ARG_PATTERN}" STREQUAL "") ) + set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} ) + endif () + if ( NOT("${_ARG_REGEX}" STREQUAL "") ) + set ( _ARG_REGEX REGEX ${_ARG_REGEX} ) + endif () +endmacro () + +# install_header ( files/directories [INTO destination] ) +# Install a directories or files into header destination. +# USE: install_header ( lua.h luaconf.h ) or install_header ( GL ) +# USE: install_header ( mylib.h INTO mylib ) +# For directories, supports optional PATTERN/REGEX arguments like install(). +set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" ) +set ( CPACK_COMPONENT_HEADER_DESCRIPTION + "Headers needed for development. Installed into ${INSTALL_INC}." ) +macro ( install_header ) + parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) + _complete_install_args() + foreach ( _file ${_ARG_DEFAULT_ARGS} ) + if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) + install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} + COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} ) + else () + install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} + COMPONENT Header ) + endif () + endforeach() +endmacro () + +# install_data ( files/directories [INTO destination] ) +# This installs additional data files or directories. +# USE: install_data ( extra data.dat ) +# USE: install_data ( image1.png image2.png INTO images ) +# For directories, supports optional PATTERN/REGEX arguments like install(). +set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" ) +set ( CPACK_COMPONENT_DATA_DESCRIPTION + "Application data. Installed into ${INSTALL_DATA}." ) +macro ( install_data ) + parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) + _complete_install_args() + foreach ( _file ${_ARG_DEFAULT_ARGS} ) + if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) + install ( DIRECTORY ${_file} + DESTINATION ${INSTALL_DATA}/${_ARG_INTO} + COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} ) + else () + install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO} + COMPONENT Data ) + endif () + endforeach() +endmacro () + +# INSTALL_DOC ( files/directories [INTO destination] ) +# This installs documentation content +# USE: install_doc ( doc/ doc.pdf ) +# USE: install_doc ( index.html INTO html ) +# For directories, supports optional PATTERN/REGEX arguments like install(). +set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" ) +set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION + "Application documentation. Installed into ${INSTALL_DOC}." ) +macro ( install_doc ) + parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) + _complete_install_args() + foreach ( _file ${_ARG_DEFAULT_ARGS} ) + if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) + install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} + COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} ) + else () + install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} + COMPONENT Documentation ) + endif () + endforeach() +endmacro () + +# install_example ( files/directories [INTO destination] ) +# This installs additional examples +# USE: install_example ( examples/ exampleA ) +# USE: install_example ( super_example super_data INTO super) +# For directories, supports optional PATTERN/REGEX argument like install(). +set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" ) +set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION + "Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." ) +macro ( install_example ) + parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) + _complete_install_args() + foreach ( _file ${_ARG_DEFAULT_ARGS} ) + if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) + install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} + COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} ) + else () + install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} + COMPONENT Example ) + endif () + endforeach() +endmacro () + +# install_test ( files/directories [INTO destination] ) +# This installs tests and test files, DOES NOT EXECUTE TESTS +# USE: install_test ( my_test data.sql ) +# USE: install_test ( feature_x_test INTO x ) +# For directories, supports optional PATTERN/REGEX argument like install(). +set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" ) +set ( CPACK_COMPONENT_TEST_DESCRIPTION + "Tests and associated data. Installed into ${INSTALL_TEST}." ) +macro ( install_test ) + parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) + _complete_install_args() + foreach ( _file ${_ARG_DEFAULT_ARGS} ) + if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) + install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} + COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} ) + else () + install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} + COMPONENT Test ) + endif () + endforeach() +endmacro () + +# install_foo ( files/directories [INTO destination] ) +# This installs optional or otherwise unneeded content +# USE: install_foo ( etc/ example.doc ) +# USE: install_foo ( icon.png logo.png INTO icons) +# For directories, supports optional PATTERN/REGEX argument like install(). +set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" ) +set ( CPACK_COMPONENT_OTHER_DESCRIPTION + "Other unspecified content. Installed into ${INSTALL_FOO}." ) +macro ( install_foo ) + parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} ) + _complete_install_args() + foreach ( _file ${_ARG_DEFAULT_ARGS} ) + if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) + install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} + COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} ) + else () + install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} + COMPONENT Other ) + endif () + endforeach() +endmacro () + +## CTest defaults + +## CPack defaults +set ( CPACK_GENERATOR "ZIP" ) +set ( CPACK_STRIP_FILES TRUE ) +set ( CPACK_PACKAGE_NAME "${DIST_NAME}" ) +set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}") +set ( CPACK_PACKAGE_VENDOR "LuaDist" ) +set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other ) +include ( CPack ) diff --git a/cmake/lua.cmake b/cmake/lua.cmake new file mode 100644 index 00000000..a0f3e67d --- /dev/null +++ b/cmake/lua.cmake @@ -0,0 +1,390 @@ +# LuaDist CMake utility library for Lua. +# +# Copyright (C) 2007-2012 LuaDist. +# by David Manura, Peter Drahos +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the COPYRIGHT file distributed with LuaDist. +# Please note that the package source code is licensed under its own license. + +set ( INSTALL_LMOD ${INSTALL_LIB}/lua + CACHE PATH "Directory to install Lua modules." ) +set ( INSTALL_CMOD ${INSTALL_LIB}/lua + CACHE PATH "Directory to install Lua binary modules." ) + +option ( SKIP_LUA_WRAPPER + "Do not build and install Lua executable wrappers." OFF) + +# List of (Lua module name, file path) pairs. +# Used internally by add_lua_test. Built by add_lua_module. +set ( _lua_modules ) + +# utility function: appends path `path` to path `basepath`, properly +# handling cases when `path` may be relative or absolute. +macro ( _append_path basepath path result ) + if ( IS_ABSOLUTE "${path}" ) + set ( ${result} "${path}" ) + else () + set ( ${result} "${basepath}/${path}" ) + endif () +endmacro () + +# install_lua_executable ( target source ) +# Automatically generate a binary wrapper for lua application and install it +# The wrapper and the source of the application will be placed into /bin +# If the application source did not have .lua suffix then it will be added +# USE: lua_executable ( sputnik src/sputnik.lua ) +macro ( install_lua_executable _name _source ) + get_filename_component ( _source_name ${_source} NAME_WE ) + if ( NOT SKIP_LUA_WRAPPER ) + enable_language ( C ) + + find_package ( Lua REQUIRED ) + include_directories ( ${LUA_INCLUDE_DIR} ) + + set ( _wrapper ${CMAKE_CURRENT_BINARY_DIR}/${_name}.c ) + set ( _code +"// Not so simple executable wrapper for Lua apps +#include +#include +#include +#include +#include + +lua_State *L\; + +static int getargs (lua_State *L, char **argv, int n) { +int narg\; +int i\; +int argc = 0\; +while (argv[argc]) argc++\; +narg = argc - (n + 1)\; +luaL_checkstack(L, narg + 3, \"too many arguments to script\")\; +for (i=n+1\; i < argc\; i++) + lua_pushstring(L, argv[i])\; +lua_createtable(L, narg, n + 1)\; +for (i=0\; i < argc\; i++) { + lua_pushstring(L, argv[i])\; + lua_rawseti(L, -2, i - n)\; +} +return narg\; +} + +static void lstop (lua_State *L, lua_Debug *ar) { +(void)ar\; +lua_sethook(L, NULL, 0, 0)\; +luaL_error(L, \"interrupted!\")\; +} + +static void laction (int i) { +signal(i, SIG_DFL)\; +lua_sethook(L, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1)\; +} + +static void l_message (const char *pname, const char *msg) { +if (pname) fprintf(stderr, \"%s: \", pname)\; +fprintf(stderr, \"%s\\n\", msg)\; +fflush(stderr)\; +} + +static int report (lua_State *L, int status) { +if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1)\; + if (msg == NULL) msg = \"(error object is not a string)\"\; + l_message(\"${_source_name}\", msg)\; + lua_pop(L, 1)\; +} +return status\; +} + +static int traceback (lua_State *L) { +if (!lua_isstring(L, 1)) + return 1\; +lua_getfield(L, LUA_GLOBALSINDEX, \"debug\")\; +if (!lua_istable(L, -1)) { + lua_pop(L, 1)\; + return 1\; +} +lua_getfield(L, -1, \"traceback\")\; +if (!lua_isfunction(L, -1)) { + lua_pop(L, 2)\; + return 1\; +} +lua_pushvalue(L, 1)\; +lua_pushinteger(L, 2)\; +lua_call(L, 2, 1)\; +return 1\; +} + +static int docall (lua_State *L, int narg, int clear) { +int status\; +int base = lua_gettop(L) - narg\; +lua_pushcfunction(L, traceback)\; +lua_insert(L, base)\; +signal(SIGINT, laction)\; +status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base)\; +signal(SIGINT, SIG_DFL)\; +lua_remove(L, base)\; +if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0)\; +return status\; +} + +int main (int argc, char **argv) { +L=lua_open()\; +lua_gc(L, LUA_GCSTOP, 0)\; +luaL_openlibs(L)\; +lua_gc(L, LUA_GCRESTART, 0)\; +int narg = getargs(L, argv, 0)\; +lua_setglobal(L, \"arg\")\; + +// Script +char script[500] = \"./${_source_name}.lua\"\; +lua_getglobal(L, \"_PROGDIR\")\; +if (lua_isstring(L, -1)) { + sprintf( script, \"%s/${_source_name}.lua\", lua_tostring(L, -1))\; +} +lua_pop(L, 1)\; + +// Run +int status = luaL_loadfile(L, script)\; +lua_insert(L, -(narg+1))\; +if (status == 0) + status = docall(L, narg, 0)\; +else + lua_pop(L, narg)\; + +report(L, status)\; +lua_close(L)\; +return status\; +}; +") + file ( WRITE ${_wrapper} ${_code} ) + add_executable ( ${_name} ${_wrapper} ) + target_link_libraries ( ${_name} ${LUA_LIBRARY} ) + install ( TARGETS ${_name} DESTINATION ${INSTALL_BIN} ) + endif() + install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN} + RENAME ${_source_name}.lua ) +endmacro () + +macro ( _lua_module_helper is_install _name ) + parse_arguments ( _MODULE "LINK;ALL_IN_ONE" "" ${ARGN} ) + # _target is CMake-compatible target name for module (e.g. socket_core). + # _module is relative path of target (e.g. socket/core), + # without extension (e.g. .lua/.so/.dll). + # _MODULE_SRC is list of module source files (e.g. .lua and .c files). + # _MODULE_NAMES is list of module names (e.g. socket.core). + if ( _MODULE_ALL_IN_ONE ) + string ( REGEX REPLACE "\\..*" "" _target "${_name}" ) + string ( REGEX REPLACE "\\..*" "" _module "${_name}" ) + set ( _target "${_target}_all_in_one") + set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} ) + set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} ) + else () + string ( REPLACE "." "_" _target "${_name}" ) + string ( REPLACE "." "/" _module "${_name}" ) + set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} ) + set ( _MODULE_NAMES ${_name} ) + endif () + if ( NOT _MODULE_SRC ) + message ( FATAL_ERROR "no module sources specified" ) + endif () + list ( GET _MODULE_SRC 0 _first_source ) + + get_filename_component ( _ext ${_first_source} EXT ) + if ( _ext STREQUAL ".lua" ) # Lua source module + list ( LENGTH _MODULE_SRC _len ) + if ( _len GREATER 1 ) + message ( FATAL_ERROR "more than one source file specified" ) + endif () + + set ( _module "${_module}.lua" ) + + get_filename_component ( _module_dir ${_module} PATH ) + get_filename_component ( _module_filename ${_module} NAME ) + _append_path ( "${CMAKE_CURRENT_SOURCE_DIR}" "${_first_source}" _module_path ) + list ( APPEND _lua_modules "${_name}" "${_module_path}" ) + + if ( ${is_install} ) + install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir} + RENAME ${_module_filename} ) + endif () + else () # Lua C binary module + enable_language ( C ) + find_package ( Lua REQUIRED ) + include_directories ( ${LUA_INCLUDE_DIR} ) + + set ( _module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" ) + + get_filename_component ( _module_dir ${_module} PATH ) + get_filename_component ( _module_filenamebase ${_module} NAME_WE ) + foreach ( _thisname ${_MODULE_NAMES} ) + list ( APPEND _lua_modules "${_thisname}" + "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_CFG_INTDIR}/${_module}" ) + endforeach () + + add_library( ${_target} MODULE ${_MODULE_SRC}) + target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} ) + set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY + "${_module_dir}" PREFIX "" OUTPUT_NAME "${_module_filenamebase}" ) + if ( ${is_install} ) + install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_dir}) + endif () + endif () +endmacro () + +# add_lua_module +# Builds a Lua source module into a destination locatable by Lua +# require syntax. +# Binary modules are also supported where this function takes sources and +# libraries to compile separated by LINK keyword. +# USE: add_lua_module ( socket.http src/http.lua ) +# USE2: add_lua_module ( mime.core src/mime.c ) +# USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} ) +# USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c ) +# This form builds an "all-in-one" module (e.g. ssl.so or ssl.dll containing +# both modules ssl.context and ssl.core). The CMake target name will be +# ssl_all_in_one. +# Also sets variable _module_path (relative path where module typically +# would be installed). +macro ( add_lua_module ) + _lua_module_helper ( 0 ${ARGN} ) +endmacro () + + +# install_lua_module +# This is the same as `add_lua_module` but also installs the module. +# USE: install_lua_module ( socket.http src/http.lua ) +# USE2: install_lua_module ( mime.core src/mime.c ) +# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} ) +macro ( install_lua_module ) + _lua_module_helper ( 1 ${ARGN} ) +endmacro () + +# Builds string representing Lua table mapping Lua modules names to file +# paths. Used internally. +macro ( _make_module_table _outvar ) + set ( ${_outvar} ) + list ( LENGTH _lua_modules _n ) + if ( ${_n} GREATER 0 ) # avoids cmake complaint + foreach ( _i RANGE 1 ${_n} 2 ) + list ( GET _lua_modules ${_i} _path ) + math ( EXPR _ii ${_i}-1 ) + list ( GET _lua_modules ${_ii} _name ) + set ( ${_outvar} "${_table} ['${_name}'] = '${_path}'\;\n") + endforeach () + endif () + set ( ${_outvar} +"local modules = { +${_table}}" ) +endmacro () + +# add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] ) +# Runs Lua script `_testfile` under CTest tester. +# Optional named argument `WORKING_DIRECTORY` is current working directory to +# run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}). +# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}. +# Any modules previously defined with install_lua_module are automatically +# preloaded (via package.preload) prior to running the test script. +# Under LuaDist, set test=true in config.lua to enable testing. +# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir]) +macro ( add_lua_test _testfile ) + if ( NOT SKIP_TESTING ) + parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} ) + include ( CTest ) + find_program ( LUA NAMES lua lua.bat ) + get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE ) + get_filename_component ( TESTFILENAME ${_testfile} NAME ) + get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE ) + + # Write wrapper script. + # Note: One simple way to allow the script to find modules is + # to just put them in package.preload. + set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} ) + _make_module_table ( _table ) + set ( TESTWRAPPERSOURCE +"local CMAKE_CFG_INTDIR = ... or '.' +${_table} +local function preload_modules(modules) + for name, path in pairs(modules) do + if path:match'%.lua' then + package.preload[name] = assert(loadfile(path)) + else + local name = name:gsub('.*%-', '') -- remove any hyphen prefix + local symbol = 'luaopen_' .. name:gsub('%.', '_') + --improve: generalize to support all-in-one loader? + local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR) + package.preload[name] = assert(package.loadlib(path, symbol)) + end + end +end +preload_modules(modules) +arg[0] = '${TESTFILEABS}' +table.remove(arg, 1) +return assert(loadfile '${TESTFILEABS}')(unpack(arg)) +" ) + if ( _ARG_WORKING_DIRECTORY ) + get_filename_component ( + TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE ) + # note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter. + set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" ) + endif () + file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE}) + add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA} + ${TESTWRAPPER} "${CMAKE_CFG_INTDIR}" + ${_ARG_DEFAULT_ARGS} ) + endif () + # see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake + # Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper + # expansion by the native build tool. +endmacro () + + +# Converts Lua source file `_source` to binary string embedded in C source +# file `_target`. Optionally compiles Lua source to byte code (not available +# under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua +# versions of bin2c [1] and luac [2] may be passed respectively as additional +# arguments. +# +# [1] http://lua-users.org/wiki/BinToCee +# [2] http://lua-users.org/wiki/LuaCompilerInLua +function ( add_lua_bin2c _target _source ) + find_program ( LUA NAMES lua lua.bat ) + execute_process ( COMMAND ${LUA} -e "string.dump(function()end)" + RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET ) + if ( NOT ${_LUA_DUMP_RESULT} ) + SET ( HAVE_LUA_DUMP true ) + endif () + message ( "-- string.dump=${HAVE_LUA_DUMP}" ) + + if ( ARGV2 ) + get_filename_component ( BIN2C ${ARGV2} ABSOLUTE ) + set ( BIN2C ${LUA} ${BIN2C} ) + else () + find_program ( BIN2C NAMES bin2c bin2c.bat ) + endif () + if ( HAVE_LUA_DUMP ) + if ( ARGV3 ) + get_filename_component ( LUAC ${ARGV3} ABSOLUTE ) + set ( LUAC ${LUA} ${LUAC} ) + else () + find_program ( LUAC NAMES luac luac.bat ) + endif () + endif ( HAVE_LUA_DUMP ) + message ( "-- bin2c=${BIN2C}" ) + message ( "-- luac=${LUAC}" ) + + get_filename_component ( SOURCEABS ${_source} ABSOLUTE ) + if ( HAVE_LUA_DUMP ) + get_filename_component ( SOURCEBASE ${_source} NAME_WE ) + add_custom_command ( + OUTPUT ${_target} DEPENDS ${_source} + COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo + ${SOURCEABS} + COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo + ">${_target}" ) + else () + add_custom_command ( + OUTPUT ${_target} DEPENDS ${SOURCEABS} + COMMAND ${BIN2C} ${_source} ">${_target}" ) + endif () +endfunction() diff --git a/dist.cmake b/dist.cmake deleted file mode 100644 index 10c6a68c..00000000 --- a/dist.cmake +++ /dev/null @@ -1,450 +0,0 @@ -# LuaDist CMake utility library. -# Provides variables and utility functions common to LuaDist CMake builds. -# -# Copyright (C) 2007-2011 LuaDist. -# by David Manura, Peter Drahos -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Please note that the package source code is licensed under its own license. - -## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX) -# Primary paths -set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." ) -set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." ) -set ( INSTALL_INC include CACHE PATH "Where to install headers to." ) -set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" ) -set ( INSTALL_LMOD ${INSTALL_LIB}/lua CACHE PATH "Directory to install Lua modules." ) -set ( INSTALL_CMOD ${INSTALL_LIB}/lua CACHE PATH "Directory to install Lua binary modules." ) -set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." ) - -# Secondary paths -set ( INSTALL_DATA ${INSTALL_SHARE}/${PROJECT_NAME} CACHE PATH "Directory the package can store documentation, tests or other data in.") -set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH "Recommended directory to install documentation into.") -set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH "Recommended directory to install examples into.") -set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH "Recommended directory to install tests into.") -set ( INSTALL_FOO ${INSTALL_DATA}/etc CACHE PATH "Where to install additional files") - -# Skipable content, headers, binaries and libraries are always required -option ( SKIP_TESTING "Do not add tests." OFF) -option ( SKIP_LUA_WRAPPER "Do not build and install Lua executable wrappers." OFF) -option ( SKIP_INSTALL_DATA "Skip installing all data." OFF ) -if ( NOT SKIP_INSTALL_DATA ) - option ( SKIP_INSTALL_DOC "Skip installation of documentation." OFF ) - option ( SKIP_INSTALL_EXAMPLE "Skip installation of documentation." OFF ) - option ( SKIP_INSTALL_TEST "Skip installation of tests." OFF) - option ( SKIP_INSTALL_FOO "Skip installation of optional package content." OFF) -endif () - -# TWEAKS -# Setting CMAKE to use loose block and search for find modules in source directory -set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) -set ( CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH} ) - -# In MSVC, prevent warnings that can occur when using standard libraries. -if ( MSVC ) - add_definitions ( -D_CRT_SECURE_NO_WARNINGS ) -endif () - -## MACROS -# Parser macro -macro ( parse_arguments prefix arg_names option_names) - set ( DEFAULT_ARGS ) - foreach ( arg_name ${arg_names} ) - set ( ${prefix}_${arg_name} ) - endforeach () - foreach ( option ${option_names} ) - set ( ${prefix}_${option} FALSE ) - endforeach () - - set ( current_arg_name DEFAULT_ARGS ) - set ( current_arg_list ) - foreach ( arg ${ARGN} ) - set ( larg_names ${arg_names} ) - list ( FIND larg_names "${arg}" is_arg_name ) - if ( is_arg_name GREATER -1 ) - set ( ${prefix}_${current_arg_name} ${current_arg_list} ) - set ( current_arg_name ${arg} ) - set ( current_arg_list ) - else () - set ( loption_names ${option_names} ) - list ( FIND loption_names "${arg}" is_option ) - if ( is_option GREATER -1 ) - set ( ${prefix}_${arg} TRUE ) - else () - set ( current_arg_list ${current_arg_list} ${arg} ) - endif () - endif () - endforeach () - set ( ${prefix}_${current_arg_name} ${current_arg_list} ) -endmacro () - -# INSTALL_LUA_EXECUTABLE ( target source ) -# Automatically generate a binary wrapper for lua application and install it -# The wrapper and the source of the application will be placed into /bin -# If the application source did not have .lua suffix then it will be added -# USE: lua_executable ( sputnik src/sputnik.lua ) -macro ( install_lua_executable _name _source ) - get_filename_component ( _source_name ${_source} NAME_WE ) - if ( NOT SKIP_LUA_WRAPPER ) - enable_language ( C ) - - find_package ( Lua51 REQUIRED ) - include_directories ( ${LUA_INCLUDE_DIR} ) - - set ( _wrapper ${CMAKE_CURRENT_BINARY_DIR}/${_name}.c ) - set ( _code -"// Not so simple executable wrapper for Lua apps -#include -#include -#include -#include -#include - -lua_State *L\; - -static int getargs (lua_State *L, char **argv, int n) { -int narg\; -int i\; -int argc = 0\; -while (argv[argc]) argc++\; -narg = argc - (n + 1)\; -luaL_checkstack(L, narg + 3, \"too many arguments to script\")\; -for (i=n+1\; i < argc\; i++) - lua_pushstring(L, argv[i])\; -lua_createtable(L, narg, n + 1)\; -for (i=0\; i < argc\; i++) { - lua_pushstring(L, argv[i])\; - lua_rawseti(L, -2, i - n)\; -} -return narg\; -} - -static void lstop (lua_State *L, lua_Debug *ar) { -(void)ar\; -lua_sethook(L, NULL, 0, 0)\; -luaL_error(L, \"interrupted!\")\; -} - -static void laction (int i) { -signal(i, SIG_DFL)\; -lua_sethook(L, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1)\; -} - -static void l_message (const char *pname, const char *msg) { -if (pname) fprintf(stderr, \"%s: \", pname)\; -fprintf(stderr, \"%s\\n\", msg)\; -fflush(stderr)\; -} - -static int report (lua_State *L, int status) { -if (status && !lua_isnil(L, -1)) { - const char *msg = lua_tostring(L, -1)\; - if (msg == NULL) msg = \"(error object is not a string)\"\; - l_message(\"${_source_name}\", msg)\; - lua_pop(L, 1)\; -} -return status\; -} - -static int traceback (lua_State *L) { -if (!lua_isstring(L, 1)) - return 1\; -lua_getfield(L, LUA_GLOBALSINDEX, \"debug\")\; -if (!lua_istable(L, -1)) { - lua_pop(L, 1)\; - return 1\; -} -lua_getfield(L, -1, \"traceback\")\; -if (!lua_isfunction(L, -1)) { - lua_pop(L, 2)\; - return 1\; -} -lua_pushvalue(L, 1)\; -lua_pushinteger(L, 2)\; -lua_call(L, 2, 1)\; -return 1\; -} - -static int docall (lua_State *L, int narg, int clear) { -int status\; -int base = lua_gettop(L) - narg\; -lua_pushcfunction(L, traceback)\; -lua_insert(L, base)\; -signal(SIGINT, laction)\; -status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base)\; -signal(SIGINT, SIG_DFL)\; -lua_remove(L, base)\; -if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0)\; -return status\; -} - -int main (int argc, char **argv) { -L=lua_open()\; -lua_gc(L, LUA_GCSTOP, 0)\; -luaL_openlibs(L)\; -lua_gc(L, LUA_GCRESTART, 0)\; -int narg = getargs(L, argv, 0)\; -lua_setglobal(L, \"arg\")\; - -// Script -char script[500] = \"./${_source_name}.lua\"\; -lua_getglobal(L, \"_PROGDIR\")\; -if (lua_isstring(L, -1)) { - sprintf( script, \"%s/${_source_name}.lua\", lua_tostring(L, -1))\; -} -lua_pop(L, 1)\; - -// Run -int status = luaL_loadfile(L, script)\; -lua_insert(L, -(narg+1))\; -if (status == 0) - status = docall(L, narg, 0)\; -else - lua_pop(L, narg)\; - -report(L, status)\; -lua_close(L)\; -return status\; -}; -") - file ( WRITE ${_wrapper} ${_code} ) - add_executable ( ${_name} ${_wrapper} ) - target_link_libraries ( ${_name} ${LUA_LIBRARY} ) - install ( TARGETS ${_name} DESTINATION ${INSTALL_BIN} ) - endif() - install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN} RENAME ${_source_name}.lua ) -endmacro () - -# INSTALL_LIBRARY -# Installs any libraries generated using "add_library" into apropriate places. -# USE: install_library ( libexpat ) -macro ( install_library ) - foreach ( _file ${ARGN} ) - install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN} LIBRARY DESTINATION ${INSTALL_LIB} ARCHIVE DESTINATION ${INSTALL_LIB} ) - endforeach() -endmacro () - -# INSTALL_EXECUTABLE -# Installs any executables generated using "add_executable". -# USE: install_executable ( lua ) -macro ( install_executable ) - foreach ( _file ${ARGN} ) - install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN} ) - endforeach() -endmacro () - -# INSTALL_HEADER -# Install a directories or files into header destination. -# USE: install_header ( lua.h luaconf.h ) or install_header ( GL ) -# NOTE: If headers need to be installed into subdirectories use the INSTALL command directly -macro ( install_header ) - parse_arguments ( _ARG "INTO" "" ${ARGN} ) - foreach ( _file ${_ARG_DEFAULT_ARGS} ) - if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) - install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} ) - else () - install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO} ) - endif () - endforeach() -endmacro () - -# INSTALL_DATA ( files/directories ) -# This installs additional data files or directories. -# USE: install_data ( extra data.dat ) -macro ( install_data ) - if ( NOT SKIP_INSTALL_DATA ) - parse_arguments ( _ARG "INTO" "" ${ARGN} ) - foreach ( _file ${_ARG_DEFAULT_ARGS} ) - if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) - install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO} ) - else () - install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO} ) - endif () - endforeach() - endif() -endmacro () - -# INSTALL_DOC ( files/directories ) -# This installs documentation content -# USE: install_doc ( doc/ ) -macro ( install_doc ) - if ( NOT SKIP_INSTALL_DATA AND NOT SKIP_INSTALL_DOC ) - parse_arguments ( _ARG "INTO" "" ${ARGN} ) - foreach ( _file ${_ARG_DEFAULT_ARGS} ) - if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) - install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} ) - else () - install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO} ) - endif () - endforeach() - endif() -endmacro () - -# INSTALL_EXAMPLE ( files/directories ) -# This installs additional data -# USE: install_example ( examples/ exampleA.lua ) -macro ( install_example ) - if ( NOT SKIP_INSTALL_DATA AND NOT SKIP_INSTALL_EXAMPLE ) - parse_arguments ( _ARG "INTO" "" ${ARGN} ) - foreach ( _file ${_ARG_DEFAULT_ARGS} ) - if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) - install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} ) - else () - install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO} ) - endif () - endforeach() - endif() -endmacro () - -# INSTALL_TEST ( files/directories ) -# This installs tests -# USE: install_example ( examples/ exampleA.lua ) -macro ( install_test ) - if ( NOT SKIP_INSTALL_DATA AND NOT SKIP_INSTALL_TEST ) - parse_arguments ( _ARG "INTO" "" ${ARGN} ) - foreach ( _file ${_ARG_DEFAULT_ARGS} ) - if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) - install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} ) - else () - install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO} ) - endif () - endforeach() - endif() -endmacro () - -# INSTALL_FOO ( files/directories ) -# This installs optional content -# USE: install_foo ( examples/ exampleA.lua ) -macro ( install_foo ) - if ( NOT SKIP_INSTALL_DATA AND NOT SKIP_INSTALL_FOO ) - parse_arguments ( _ARG "INTO" "" ${ARGN} ) - foreach ( _file ${_ARG_DEFAULT_ARGS} ) - if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" ) - install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} ) - else () - install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO} ) - endif () - endforeach() - endif() -endmacro () - -# INSTALL_LUA_MODULE -# This macro installs a lua source module into destination given by lua require syntax. -# Binary modules are also supported where this funcion takes sources and libraries to compile separated by LINK keyword -# USE: install_lua_module ( socket.http src/http.lua ) -# USE2: install_lua_module ( mime.core src/mime.c ) -# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} ) -macro (install_lua_module _name ) - string ( REPLACE "." "/" _module "${_name}" ) - string ( REPLACE "." "_" _target "${_name}" ) - - set ( _lua_module "${_module}.lua" ) - set ( _bin_module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" ) - - parse_arguments ( _MODULE "LINK" "" ${ARGN} ) - get_filename_component ( _ext ${ARGV1} EXT ) - if ( _ext STREQUAL ".lua" ) - get_filename_component ( _path ${_lua_module} PATH ) - get_filename_component ( _filename ${_lua_module} NAME ) - install ( FILES ${ARGV1} DESTINATION ${INSTALL_LMOD}/${_path} RENAME ${_filename} ) - else () - enable_language ( C ) - get_filename_component ( _module_name ${_bin_module} NAME_WE ) - get_filename_component ( _module_path ${_bin_module} PATH ) - - find_package ( Lua51 REQUIRED ) - include_directories ( ${LUA_INCLUDE_DIR} ) - - add_library( ${_target} MODULE ${_MODULE_DEFAULT_ARGS}) - target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} ) - set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${_module_path}" PREFIX "" OUTPUT_NAME "${_module_name}" ) - - install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_path}) - endif () -endmacro () - -# ADD_LUA_TEST -# Runs Lua script `_testfile` under CTest tester. -# Optional named argument `WORKING_DIRECTORY` is current working directory to run test under -# (defaults to ${CMAKE_CURRENT_BINARY_DIR}). -# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}. -# Under LuaDist, set test=true in config.lua to enable testing. -# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir]) -macro ( add_lua_test _testfile ) - if ( NOT SKIP_TESTING ) - parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} ) - include ( CTest ) - find_program ( LUA NAMES lua lua.bat ) - get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE ) - get_filename_component ( TESTFILENAME ${_testfile} NAME ) - get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE ) - - # Write wrapper script. - set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} ) - set ( TESTWRAPPERSOURCE -"local configuration = ... -local sodir = '${CMAKE_CURRENT_BINARY_DIR}' .. (configuration == '' and '' or '/' .. configuration) -package.path = sodir .. '/?.lua\;' .. sodir .. '/?.lua\;' .. package.path -package.cpath = sodir .. '/?.so\;' .. sodir .. '/?.dll\;' .. package.cpath -arg[0] = '${TESTFILEABS}' -table.remove(arg, 1) -return assert(loadfile '${TESTFILEABS}')(unpack(arg)) -" ) - if ( _ARG_WORKING_DIRECTORY ) - get_filename_component ( TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE ) - # note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter. -#old: set ( TESTWRAPPERSOURCE "require 'lfs'; lfs.chdir('${TESTCURRENTDIRABS}' ) ${TESTWRAPPERSOURCE}" ) - set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" ) - endif () - file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE}) - add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA} ${TESTWRAPPER} $ ${_ARG_DEFAULT_ARGS} ) - endif () - # see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake -endmacro () - -# Converts Lua source file `_source` to binary string embedded in C source -# file `_target`. Optionally compiles Lua source to byte code (not available -# under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua -# versions of bin2c [1] and luac [2] may be passed respectively as additional -# arguments. -# -# [1] http://lua-users.org/wiki/BinToCee -# [2] http://lua-users.org/wiki/LuaCompilerInLua -function ( add_lua_bin2c _target _source ) - find_program ( LUA NAMES lua lua.bat ) - execute_process ( COMMAND ${LUA} -e "string.dump(function()end)" RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET ) - if ( NOT ${_LUA_DUMP_RESULT} ) - SET ( HAVE_LUA_DUMP true ) - endif () - message ( "-- string.dump=${HAVE_LUA_DUMP}" ) - - if ( ARGV2 ) - get_filename_component ( BIN2C ${ARGV2} ABSOLUTE ) - set ( BIN2C ${LUA} ${BIN2C} ) - else () - find_program ( BIN2C NAMES bin2c bin2c.bat ) - endif () - if ( HAVE_LUA_DUMP ) - if ( ARGV3 ) - get_filename_component ( LUAC ${ARGV3} ABSOLUTE ) - set ( LUAC ${LUA} ${LUAC} ) - else () - find_program ( LUAC NAMES luac luac.bat ) - endif () - endif ( HAVE_LUA_DUMP ) - message ( "-- bin2c=${BIN2C}" ) - message ( "-- luac=${LUAC}" ) - - get_filename_component ( SOURCEABS ${_source} ABSOLUTE ) - if ( HAVE_LUA_DUMP ) - get_filename_component ( SOURCEBASE ${_source} NAME_WE ) - add_custom_command ( - OUTPUT ${_target} DEPENDS ${_source} - COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo ${SOURCEABS} - COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo ">${_target}" ) - else () - add_custom_command ( - OUTPUT ${_target} DEPENDS ${SOURCEABS} - COMMAND ${BIN2C} ${_source} ">${_target}" ) - endif () -endfunction() diff --git a/dist.info b/dist.info index 95e41d4e..50f91867 100644 --- a/dist.info +++ b/dist.info @@ -1,10 +1,15 @@ --- This file is part of LuaDist project name = "lua" -version = "5.2" +version = "5.2.4" desc = "Lua is a powerful, fast, light-weight, embeddable scripting language." author = "Roberto Ierusalimschy, Waldemar Celes, Luiz Henrique de Figueiredo" license = "MIT/X11" url = "http://www.lua.org" maintainer = "Peter Drahoš" + +-- Offers functionality of the following packages +provides = { + "bit32-5.2.0" +} diff --git a/doc/contents.html b/doc/contents.html index 5342723f..9d5202fa 100644 --- a/doc/contents.html +++ b/doc/contents.html @@ -7,7 +7,6 @@ @@ -23,7 +22,7 @@

The reference manual is the official definition of the Lua language. For a complete introduction to Lua programming, see the book -Programming in Lua. +Programming in Lua.

start @@ -33,9 +32,9 @@

index
-Copyright © 2011 Lua.org, PUC-Rio. +Copyright © 2011–2015 Lua.org, PUC-Rio. Freely available under the terms of the -Lua license. +Lua license.

Contents

@@ -139,18 +138,18 @@

Index

Lua functions

+basic
_G
_VERSION
-

assert
collectgarbage
dofile
error
getmetatable
ipairs
-loadfile
load
+loadfile
next
pairs
pcall
@@ -168,6 +167,7 @@

Lua functions

xpcall

+bit32
bit32.arshift
bit32.band
bit32.bnot
@@ -182,6 +182,7 @@

Lua functions

bit32.rshift

+coroutine
coroutine.create
coroutine.resume
coroutine.running
@@ -190,6 +191,7 @@

Lua functions

coroutine.yield

+debug
debug.debug
debug.getuservalue
debug.gethook
@@ -208,15 +210,7 @@

Lua functions

debug.upvaluejoin

-file:close
-file:flush
-file:lines
-file:read
-file:seek
-file:setvbuf
-file:write
- -

+io
io.close
io.flush
io.input
@@ -231,11 +225,19 @@

Lua functions

io.tmpfile
io.type
io.write
+file:close
+file:flush
+file:lines
+file:read
+file:seek
+file:setvbuf
+file:write

 

+math
math.abs
math.acos
math.asin
@@ -267,6 +269,7 @@

 

math.tanh

+os
os.clock
os.date
os.difftime
@@ -280,6 +283,7 @@

 

os.tmpname

+package
package.config
package.cpath
package.loaded
@@ -290,6 +294,7 @@

 

package.searchpath

+string
string.byte
string.char
string.dump
@@ -306,6 +311,7 @@

 

string.upper

+table
table.concat
table.insert
table.pack
@@ -313,6 +319,14 @@

 

table.sort
table.unpack
+

environment
variables

+LUA_CPATH
+LUA_CPATH_5_2
+LUA_INIT
+LUA_INIT_5_2
+LUA_PATH
+LUA_PATH_5_2
+

C API

@@ -385,6 +399,7 @@

C API

lua_pushcclosure
lua_pushcfunction
lua_pushfstring
+lua_pushglobaltable
lua_pushinteger
lua_pushlightuserdata
lua_pushliteral
@@ -393,15 +408,16 @@

C API

lua_pushnumber
lua_pushstring
lua_pushthread
+lua_pushunsigned
lua_pushvalue
lua_pushvfstring
lua_rawequal
lua_rawget
lua_rawgeti
+lua_rawgetp
lua_rawlen
lua_rawset
lua_rawseti
-lua_rawgetp
lua_rawsetp
lua_register
lua_remove
@@ -460,8 +476,8 @@

auxiliary library

luaL_buffinitsize
luaL_callmeta
luaL_checkany
-luaL_checkinteger
luaL_checkint
+luaL_checkinteger
luaL_checklong
luaL_checklstring
luaL_checknumber
@@ -492,8 +508,8 @@

auxiliary library

luaL_newmetatable
luaL_newstate
luaL_openlibs
-luaL_optinteger
luaL_optint
+luaL_optinteger
luaL_optlong
luaL_optlstring
luaL_optnumber
@@ -514,6 +530,67 @@

auxiliary library

luaL_unref
luaL_where
+

standard library

+

+luaopen_base
+luaopen_bit32
+luaopen_coroutine
+luaopen_debug
+luaopen_io
+luaopen_math
+luaopen_os
+luaopen_package
+luaopen_string
+luaopen_table
+ +

constants

+LUA_ERRERR
+LUA_ERRFILE
+LUA_ERRGCMM
+LUA_ERRMEM
+LUA_ERRRUN
+LUA_ERRSYNTAX
+LUA_HOOKCALL
+LUA_HOOKCOUNT
+LUA_HOOKLINE
+LUA_HOOKRET
+LUA_HOOKTAILCALL
+LUA_MASKCALL
+LUA_MASKCOUNT
+LUA_MASKLINE
+LUA_MASKRET
+LUA_MINSTACK
+LUA_MULTRET
+LUA_NOREF
+LUA_OK
+LUA_OPADD
+LUA_OPDIV
+LUA_OPEQ
+LUA_OPLE
+LUA_OPLT
+LUA_OPMOD
+LUA_OPMUL
+LUA_OPPOW
+LUA_OPSUB
+LUA_OPUNM
+LUA_REFNIL
+LUA_REGISTRYINDEX
+LUA_RIDX_GLOBALS
+LUA_RIDX_MAINTHREAD
+LUA_TBOOLEAN
+LUA_TFUNCTION
+LUA_TLIGHTUSERDATA
+LUA_TNIL
+LUA_TNONE
+LUA_TNUMBER
+LUA_TSTRING
+LUA_TTABLE
+LUA_TTHREAD
+LUA_TUSERDATA
+LUA_USE_APICHECK
+LUA_YIELD
+LUAL_BUFFERSIZE
+ @@ -521,10 +598,10 @@

auxiliary library


Last update: -Tue Nov 29 22:30:23 BRST 2011 +Mon Feb 23 22:24:36 BRT 2015 diff --git a/doc/lua.css b/doc/lua.css index 54708f82..5dc9a8b9 100644 --- a/doc/lua.css +++ b/doc/lua.css @@ -1,30 +1,38 @@ +html { + background-color: #F8F8F8 ; +} + body { + border: solid #a0a0a0 1px ; + border-radius: 20px ; + padding: 26px ; + margin: 16px ; color: #000000 ; background-color: #FFFFFF ; font-family: Helvetica, Arial, sans-serif ; text-align: justify ; - margin-right: 20px ; - margin-left: 20px ; + line-height: 1.25 ; } h1, h2, h3, h4 { font-family: Verdana, Geneva, sans-serif ; font-weight: normal ; - font-style: italic ; + font-style: normal ; } h2 { padding-top: 0.4em ; padding-bottom: 0.4em ; - padding-left: 20px ; - padding-right: 20px ; - margin-left: -20px ; - background-color: #E0E0FF ; + padding-left: 0.8em ; + padding-right: 0.8em ; + background-color: #D0D0FF ; + border-radius: 8px ; + border: solid #a0a0a0 1px ; } h3 { padding-left: 0.5em ; - border-left: solid #E0E0FF 1em ; + border-left: solid #D0D0FF 1em ; } table h3 { @@ -45,39 +53,54 @@ a:visited { a:link:hover, a:visited:hover { color: #000080 ; - background-color: #E0E0FF ; + background-color: #D0D0FF ; + border-radius: 4px ; } a:link:active, a:visited:active { color: #FF0000 ; } +h1 a img { + vertical-align: text-bottom ; +} + hr { border: 0 ; height: 1px ; color: #a0a0a0 ; background-color: #a0a0a0 ; + display: none ; +} + +table hr { + display: block ; } :target { background-color: #F8F8F8 ; padding: 8px ; border: solid #a0a0a0 2px ; + border-radius: 8px ; } .footer { color: gray ; - font-size: small ; + font-size: x-small ; } input[type=text] { border: solid #a0a0a0 2px ; border-radius: 2em ; - -moz-border-radius: 2em ; background-image: url('images/search.png') ; - background-repeat: no-repeat; + background-repeat: no-repeat ; background-position: 4px center ; padding-left: 20px ; height: 2em ; } +pre.session { + background-color: #F8F8F8 ; + padding: 1em ; + border-radius: 8px ; +} diff --git a/doc/manual.css b/doc/manual.css index ac357a89..ca613cd9 100644 --- a/doc/manual.css +++ b/doc/manual.css @@ -16,9 +16,12 @@ span.apii { } p+h1, ul+h1 { + font-style: normal ; padding-top: 0.4em ; padding-bottom: 0.4em ; - padding-left: 20px ; - margin-left: -20px ; - background-color: #E0E0FF ; + padding-left: 16px ; + margin-left: -16px ; + background-color: #D0D0FF ; + border-radius: 8px ; + border: solid #000080 1px ; } diff --git a/doc/manual.html b/doc/manual.html index 360d3168..0a95e9e0 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -19,9 +19,9 @@

by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes

-Copyright © 2011 Lua.org, PUC-Rio. +Copyright © 2011–2015 Lua.org, PUC-Rio. Freely available under the terms of the -Lua license. +Lua license.


@@ -33,7 +33,7 @@

- + @@ -424,7 +424,6 @@

2.4 – Metatables and Metamethods

      rawget(getmetatable(obj) or {}, event)
 

- This means that the access to a metamethod does not invoke other metamethods, and access to objects with no metatables does not fail (it simply results in nil). @@ -913,6 +912,14 @@

2.5.1 – Garbage-Collection Metamethods

its finalizer will never be called twice. +

+When you close a state (see lua_close), +Lua calls the finalizers of all objects marked for finalization, +following the reverse order that they were marked. +If any finalizer marks new objects for collection during that phase, +these new objects will not be finalized. + + @@ -1206,7 +1213,7 @@

3.1 – Lexical Conventions

The escape sequence '\z' skips the following span of white-space characters, including line breaks; -it is particularly useful to break and indent a long string +it is particularly useful to break and indent a long literal string into multiple lines without adding the newlines and spaces into the string contents. @@ -1234,7 +1241,7 @@

3.1 – Lexical Conventions

and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. -A long string starts with an opening long bracket of any level and +A long literal starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. It can contain any text except a closing bracket of the proper level. Literals in this bracketed form can run for several lines, @@ -1247,8 +1254,7 @@

3.1 – Lexical Conventions

-When parsing a from a string source, -any byte in a literal string not +Any byte in a literal string not explicitly affected by the previous rules represents itself. However, Lua opens files for parsing in text mode, and the system file functions may have problems with @@ -1401,6 +1407,35 @@

3.3.1 – Blocks

stat ::= ‘;’ +

+Function calls and assignments +can start with an open parenthesis. +This possibility leads to an ambiguity in Lua's grammar. +Consider the following fragment: + +

+     a = b + c
+     (print or io.write)('done')
+

+The grammar could see it in two ways: + +

+     a = b + c(print or io.write)('done')
+     
+     a = b + c; (print or io.write)('done')
+

+The current parser always sees such constructions +in the first way, +interpreting the open parenthesis +as the start of the arguments to a call. +To avoid this ambiguity, +it is a good practice to always precede with a semicolon +statements that start with a parenthesis: + +

+     ;(print or io.write)('done')
+
+

A block can be explicitly delimited to produce a single statement: @@ -1420,7 +1455,7 @@

3.3.1 – Blocks

3.3.2 – Chunks

-The unit of execution of Lua is called a chunk. +The unit of compilation of Lua is called a chunk. Syntactically, a chunk is simply a block: @@ -1851,7 +1886,8 @@

3.4 – Expressions

(unless the expression is enclosed in parentheses). In all other contexts, Lua adjusts the result list to one element, -discarding all values except the first one. +either discarding all values except the first one +or adding a single nil if there are no values.

@@ -2052,7 +2088,7 @@

3.4.6 – The Length Operator

table is a sequence, that is, the set of its positive numeric keys is equal to {1..n} -for some integer n. +for some non-negative integer n. In that case, n is its length. Note that a table like @@ -2551,32 +2587,35 @@

4.3 – Valid and Acceptable Indices

A valid index is an index that refers to a -valid position within the stack, that is, -it lies between 1 and the stack top +real position within the stack, that is, +its position lies between 1 and the stack top (1 ≤ abs(index) ≤ top). -Usually, functions that need a specific stack position -(e.g., lua_remove) require valid indices. +Usually, functions that can modify the value at an index +require valid indices. + + +

+Unless otherwise noted, +any function that accepts valid indices also accepts pseudo-indices, +which represent some Lua values that are accessible to C code +but which are not in the stack. +Pseudo-indices are used to access the registry +and the upvalues of a C function (see §4.4).

Functions that do not need a specific stack position, but only a value in the stack (e.g., query functions), can be called with acceptable indices. -An acceptable index refers to a position within -the space allocated for the stack, +An acceptable index can be any valid index, +including the pseudo-indices, +but it also can be any positive index after the stack top +within the space allocated for the stack, that is, indices up to the stack size. -More formally, we define an acceptable index -as follows: - -

-     (index < 0 && abs(index) <= top) ||
-     (index > 0 && index <= stack size)
-

(Note that 0 is never an acceptable index.) -When a function is called, -its stack size is top + LUA_MINSTACK. -You can change its stack size through function lua_checkstack. +Except when noted otherwise, +functions in the API work with acceptable indices.

@@ -2590,16 +2629,8 @@

4.3 – Valid and Acceptable Indices

For functions that can be called with acceptable indices, any non-valid index is treated as if it -contains a value of a virtual type LUA_TNONE. - - -

-Unless otherwise noted, -any function that accepts valid indices also accepts pseudo-indices, -which represent some Lua values that are accessible to C code -but which are not in the stack. -Pseudo-indices are used to access the registry -and the upvalues of a C function (see §4.4). +contains a value of a virtual type LUA_TNONE, +which behaves like a nil value. @@ -2620,13 +2651,13 @@

4.4 – C Closures

Whenever a C function is called, its upvalues are located at specific pseudo-indices. These pseudo-indices are produced by the macro -lua_upvalueindex. +lua_upvalueindex. The first value associated with a function is at position lua_upvalueindex(1), and so on. Any access to lua_upvalueindex(n), where n is greater than the number of upvalues of the current function (but not greater than 256), -produces an acceptable (but invalid) index. +produces an acceptable but invalid index. @@ -2639,7 +2670,8 @@

4.5 – Registry

a predefined table that can be used by any C code to store whatever Lua values it needs to store. The registry table is always located at pseudo-index -LUA_REGISTRYINDEX. +LUA_REGISTRYINDEX, +which is a valid index. Any C library can store data into this table, but it should take care to choose keys that are different from those used @@ -2684,8 +2716,8 @@

4.6 – Error Handling in C

Internally, Lua uses the C longjmp facility to handle errors. -(You can also choose to use exceptions if you use C++; -see file luaconf.h.) +(You can also choose to use exceptions if you compile Lua as C++; +search for LUAI_THROW in the source code.) When Lua faces any error (such as a memory allocation error, type errors, syntax errors, and runtime errors) @@ -2820,8 +2852,7 @@

4.8 – Functions and Types

The third field, x, tells whether the function may throw errors: '-' means the function never throws any error; -'m' means the function may throw only memory allocation errors; -'e' means the function may throw other kinds of errors; +'e' means the function may throw errors; 'v' means the function may throw an error on purpose. @@ -2922,7 +2953,7 @@

4.8 – Functions and Types


lua_arith

[-(2|1), +1, e] -

int lua_arith (lua_State *L, int op);
+
void lua_arith (lua_State *L, int op);

Performs an arithmetic operation over the two values @@ -3129,8 +3160,8 @@

4.8 – Functions and Types

Compares two Lua values. -Returns 1 if the value at acceptable index index1 satisfies op -when compared with the value at acceptable index index2, +Returns 1 if the value at index index1 satisfies op +when compared with the value at index index2, following the semantics of the corresponding Lua operator (that is, it may call metamethods). Otherwise returns 0. @@ -3173,7 +3204,7 @@

4.8 – Functions and Types

void lua_copy (lua_State *L, int fromidx, int toidx);

-Moves the element at the valid index fromidx +Moves the element at index fromidx into the valid index toidx without shifting any element (therefore replacing the value at that position). @@ -3183,7 +3214,7 @@

4.8 – Functions and Types


lua_createtable

-[-0, +1, m] +[-0, +1, e]

void lua_createtable (lua_State *L, int narr, int nrec);

@@ -3202,7 +3233,7 @@

4.8 – Functions and Types


lua_dump

-[-0, +0, m] +[-0, +0, e]

int lua_dump (lua_State *L, lua_Writer writer, void *data);

@@ -3343,7 +3374,7 @@

4.8 – Functions and Types


lua_getctx

[-0, +0, –] -

int lua_getctx  (lua_State *L, int *ctx);
+
int lua_getctx (lua_State *L, int *ctx);

This function is called by a continuation function (see §4.7) @@ -3383,7 +3414,7 @@

4.8 – Functions and Types

Pushes onto the stack the value t[k], -where t is the value at the given valid index. +where t is the value at the given index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.4). @@ -3407,8 +3438,7 @@

4.8 – Functions and Types

int lua_getmetatable (lua_State *L, int index);

-Pushes onto the stack the metatable of the value at the given -acceptable index. +Pushes onto the stack the metatable of the value at the given index. If the value does not have a metatable, the function returns 0 and pushes nothing on the stack. @@ -3422,7 +3452,7 @@

4.8 – Functions and Types

Pushes onto the stack the value t[k], -where t is the value at the given valid index +where t is the value at the given index and k is the value at the top of the stack. @@ -3470,7 +3500,7 @@

4.8 – Functions and Types

Moves the top element into the given valid index, shifting up the elements above this index to open space. -Cannot be called with a pseudo-index, +This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. @@ -3498,7 +3528,7 @@

4.8 – Functions and Types

int lua_isboolean (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a boolean, +Returns 1 if the value at the given index is a boolean, and 0 otherwise. @@ -3510,7 +3540,7 @@

4.8 – Functions and Types

int lua_iscfunction (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a C function, +Returns 1 if the value at the given index is a C function, and 0 otherwise. @@ -3522,7 +3552,7 @@

4.8 – Functions and Types

int lua_isfunction (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a function +Returns 1 if the value at the given index is a function (either C or Lua), and 0 otherwise. @@ -3534,7 +3564,7 @@

4.8 – Functions and Types

int lua_islightuserdata (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a light userdata, +Returns 1 if the value at the given index is a light userdata, and 0 otherwise. @@ -3546,7 +3576,7 @@

4.8 – Functions and Types

int lua_isnil (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is nil, +Returns 1 if the value at the given index is nil, and 0 otherwise. @@ -3558,8 +3588,7 @@

4.8 – Functions and Types

int lua_isnone (lua_State *L, int index);

-Returns 1 if the given acceptable index is not valid -(that is, it refers to an element outside the current stack), +Returns 1 if the given index is not valid, and 0 otherwise. @@ -3571,8 +3600,7 @@

4.8 – Functions and Types

int lua_isnoneornil (lua_State *L, int index);

-Returns 1 if the given acceptable index is not valid -(that is, it refers to an element outside the current stack) +Returns 1 if the given index is not valid or if the value at this index is nil, and 0 otherwise. @@ -3585,7 +3613,7 @@

4.8 – Functions and Types

int lua_isnumber (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a number +Returns 1 if the value at the given index is a number or a string convertible to a number, and 0 otherwise. @@ -3598,7 +3626,7 @@

4.8 – Functions and Types

int lua_isstring (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a string +Returns 1 if the value at the given index is a string or a number (which is always convertible to a string), and 0 otherwise. @@ -3611,7 +3639,7 @@

4.8 – Functions and Types

int lua_istable (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a table, +Returns 1 if the value at the given index is a table, and 0 otherwise. @@ -3623,7 +3651,7 @@

4.8 – Functions and Types

int lua_isthread (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a thread, +Returns 1 if the value at the given index is a thread, and 0 otherwise. @@ -3635,7 +3663,7 @@

4.8 – Functions and Types

int lua_isuserdata (lua_State *L, int index);

-Returns 1 if the value at the given acceptable index is a userdata +Returns 1 if the value at the given index is a userdata (either full or light), and 0 otherwise. @@ -3647,7 +3675,7 @@

4.8 – Functions and Types

void lua_len (lua_State *L, int index);

-Returns the "length" of the value at the given acceptable index; +Returns the "length" of the value at the given index; it is equivalent to the '#' operator in Lua (see §3.4.6). The result is pushed on the stack. @@ -3711,6 +3739,12 @@

4.8 – Functions and Types

a NULL value is equivalent to the string "bt". +

+lua_load uses the stack internally, +so the reader function should always leave the stack +unmodified when returning. + +

If the resulting function has one upvalue, this upvalue is set to the value of the global environment @@ -3740,7 +3774,7 @@

4.8 – Functions and Types


lua_newtable

-[-0, +1, m] +[-0, +1, e]

void lua_newtable (lua_State *L);

@@ -3752,7 +3786,7 @@

4.8 – Functions and Types


lua_newthread

-[-0, +1, m] +[-0, +1, e]

lua_State *lua_newthread (lua_State *L);

@@ -3773,7 +3807,7 @@

4.8 – Functions and Types


lua_newuserdata

-[-0, +1, m] +[-0, +1, e]

void *lua_newuserdata (lua_State *L, size_t size);

@@ -3959,7 +3993,7 @@

4.8 – Functions and Types


lua_pushcclosure

-[-n, +1, m] +[-n, +1, e]

void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);

@@ -4025,13 +4059,13 @@

4.8 – Functions and Types


lua_pushfstring

-[-0, +1, m] +[-0, +1, e]

const char *lua_pushfstring (lua_State *L, const char *fmt, ...);

Pushes onto the stack a formatted string and returns a pointer to this string. -It is similar to the C function sprintf, +It is similar to the ISO C function sprintf, but has some important differences:

    @@ -4059,6 +4093,17 @@

    4.8 – Functions and Types

    +

    lua_pushglobaltable

    +[-0, +1, –] +

    void lua_pushglobaltable (lua_State *L);
    + +

    +Pushes the global environment onto the stack. + + + + +


    lua_pushinteger

    [-0, +1, –]

    void lua_pushinteger (lua_State *L, lua_Integer n);
    @@ -4092,7 +4137,7 @@

    4.8 – Functions and Types


    lua_pushliteral

    -[-0, +1, m] +[-0, +1, e]

    const char *lua_pushliteral (lua_State *L, const char *s);

    @@ -4105,7 +4150,7 @@

    4.8 – Functions and Types


    lua_pushlstring

    -[-0, +1, m] +[-0, +1, e]

    const char *lua_pushlstring (lua_State *L, const char *s, size_t len);

    @@ -4148,7 +4193,7 @@

    4.8 – Functions and Types


    lua_pushstring

    -[-0, +1, m] +[-0, +1, e]

    const char *lua_pushstring (lua_State *L, const char *s);

    @@ -4182,12 +4227,23 @@

    4.8 – Functions and Types

    +

    lua_pushunsigned

    +[-0, +1, –] +

    void lua_pushunsigned (lua_State *L, lua_Unsigned n);
    + +

    +Pushes a number with value n onto the stack. + + + + +


    lua_pushvalue

    [-0, +1, –]

    void lua_pushvalue (lua_State *L, int index);

    -Pushes a copy of the element at the given valid index +Pushes a copy of the element at the given index onto the stack. @@ -4195,7 +4251,7 @@

    4.8 – Functions and Types


    lua_pushvfstring

    -[-0, +1, m] +[-0, +1, e]

    const char *lua_pushvfstring (lua_State *L,
                                   const char *fmt,
                                   va_list argp);
    @@ -4213,7 +4269,7 @@

    4.8 – Functions and Types

    int lua_rawequal (lua_State *L, int index1, int index2);

    -Returns 1 if the two values in acceptable indices index1 and +Returns 1 if the two values in indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns 0. @@ -4241,7 +4297,7 @@

    4.8 – Functions and Types

    Pushes onto the stack the value t[n], -where t is the table at the given valid index. +where t is the table at the given index. The access is raw; that is, it does not invoke metamethods. @@ -4255,7 +4311,7 @@

    4.8 – Functions and Types

    Pushes onto the stack the value t[k], -where t is the table at the given valid index and +where t is the table at the given index and k is the pointer p represented as a light userdata. The access is raw; that is, it does not invoke metamethods. @@ -4269,7 +4325,7 @@

    4.8 – Functions and Types

    size_t lua_rawlen (lua_State *L, int index);

    -Returns the raw "length" of the value at the given acceptable index: +Returns the raw "length" of the value at the given index: for strings, this is the string length; for tables, this is the result of the length operator ('#') with no metamethods; @@ -4282,7 +4338,7 @@

    4.8 – Functions and Types


    lua_rawset

    -[-2, +0, m] +[-2, +0, e]

    void lua_rawset (lua_State *L, int index);

    @@ -4294,12 +4350,12 @@

    4.8 – Functions and Types


    lua_rawseti

    -[-1, +0, m] +[-1, +0, e]

    void lua_rawseti (lua_State *L, int index, int n);

    Does the equivalent of t[n] = v, -where t is the table at the given valid index +where t is the table at the given index and v is the value at the top of the stack. @@ -4313,12 +4369,12 @@

    4.8 – Functions and Types


    lua_rawsetp

    -[-1, +0, m] +[-1, +0, e]

    void lua_rawsetp (lua_State *L, int index, const void *p);

    Does the equivalent of t[k] = v, -where t is the table at the given valid index, +where t is the table at the given index, k is the pointer p represented as a light userdata, and v is the value at the top of the stack. @@ -4377,7 +4433,7 @@

    4.8 – Functions and Types

    Removes the element at the given valid index, shifting down the elements above this index to fill the gap. -Cannot be called with a pseudo-index, +This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position. @@ -4389,9 +4445,9 @@

    4.8 – Functions and Types

    void lua_replace (lua_State *L, int index);

    -Moves the top element into the given position +Moves the top element into the given valid index without shifting any element -(therefore replacing the value at the given position), +(therefore replacing the value at the given index), and then pops the top element. @@ -4400,7 +4456,7 @@

    4.8 – Functions and Types


    lua_resume

    [-?, +?, –] -

    int lua_resume (lua_State *L, lua_State *from, int narg);
    +
    int lua_resume (lua_State *L, lua_State *from, int nargs);

    Starts and resumes a coroutine in a given thread. @@ -4410,7 +4466,7 @@

    4.8 – Functions and Types

    To start a coroutine, you push onto the thread stack the main function plus any arguments; then you call lua_resume, -with narg being the number of arguments. +with nargs being the number of arguments. This call returns when the coroutine suspends or finishes its execution. When it returns, the stack contains all values passed to lua_yield, or all values returned by the body function. @@ -4429,7 +4485,9 @@

    4.8 – Functions and Types

    -To resume a coroutine, you put on its stack only the values to +To resume a coroutine, +you remove any results from the last lua_yield, +put on its stack only the values to be passed as results from yield, and then call lua_resume. @@ -4461,7 +4519,7 @@

    4.8 – Functions and Types

    Does the equivalent to t[k] = v, -where t is the value at the given valid index +where t is the value at the given index and v is the value at the top of the stack. @@ -4492,8 +4550,7 @@

    4.8 – Functions and Types

    Pops a table from the stack and -sets it as the new metatable for the value at the given -acceptable index. +sets it as the new metatable for the value at the given index. @@ -4505,7 +4562,7 @@

    4.8 – Functions and Types

    Does the equivalent to t[k] = v, -where t is the value at the given valid index, +where t is the value at the given index, v is the value at the top of the stack, and k is the value just below the top. @@ -4524,7 +4581,7 @@

    4.8 – Functions and Types

    void lua_settop (lua_State *L, int index);

    -Accepts any acceptable index, or 0, +Accepts any index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. @@ -4550,14 +4607,15 @@

    4.8 – Functions and Types

    typedef struct lua_State lua_State;

    -An opaque structure that keeps the whole state of a Lua interpreter. +An opaque structure that points to a thread and indirectly +(through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. -All information about a state is kept in this structure. +All information about a state is accessible through this structure.

    -A pointer to this state must be passed as the first argument to +A pointer to this structure must be passed as the first argument to every function in the library, except to lua_newstate, which creates a Lua state from scratch. @@ -4595,13 +4653,12 @@

    4.8 – Functions and Types

    int lua_toboolean (lua_State *L, int index);

    -Converts the Lua value at the given acceptable index to a C boolean +Converts the Lua value at the given index to a C boolean value (0 or 1). Like all tests in Lua, lua_toboolean returns true for any Lua value different from false and nil; otherwise it returns false. -It also returns false when called with a non-valid index. (If you want to accept only actual boolean values, use lua_isboolean to test the value's type.) @@ -4614,7 +4671,7 @@

    4.8 – Functions and Types

    lua_CFunction lua_tocfunction (lua_State *L, int index);

    -Converts a value at the given acceptable index to a C function. +Converts a value at the given index to a C function. That value must be a C function; otherwise, returns NULL. @@ -4638,7 +4695,7 @@

    4.8 – Functions and Types

    lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);

    -Converts the Lua value at the given acceptable index +Converts the Lua value at the given index to the signed integral type lua_Integer. The Lua value must be a number or a string convertible to a number (see §3.4.2); @@ -4660,11 +4717,11 @@

    4.8 – Functions and Types


    lua_tolstring

    -[-0, +0, m] +[-0, +0, e]

    const char *lua_tolstring (lua_State *L, int index, size_t *len);

    -Converts the Lua value at the given acceptable index to a C string. +Converts the Lua value at the given index to a C string. If len is not NULL, it also sets *len with the string length. The Lua value must be a string or a number; @@ -4706,7 +4763,7 @@

    4.8 – Functions and Types

    lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);

    -Converts the Lua value at the given acceptable index +Converts the Lua value at the given index to the C type lua_Number (see lua_Number). The Lua value must be a number or a string convertible to a number (see §3.4.2); @@ -4727,7 +4784,7 @@

    4.8 – Functions and Types

    const void *lua_topointer (lua_State *L, int index);

    -Converts the value at the given acceptable index to a generic +Converts the value at the given index to a generic C pointer (void*). The value can be a userdata, a table, a thread, or a function; otherwise, lua_topointer returns NULL. @@ -4743,7 +4800,7 @@

    4.8 – Functions and Types


    lua_tostring

    -[-0, +0, m] +[-0, +0, e]

    const char *lua_tostring (lua_State *L, int index);

    @@ -4758,7 +4815,7 @@

    4.8 – Functions and Types

    lua_State *lua_tothread (lua_State *L, int index);

    -Converts the value at the given acceptable index to a Lua thread +Converts the value at the given index to a Lua thread (represented as lua_State*). This value must be a thread; otherwise, the function returns NULL. @@ -4783,7 +4840,7 @@

    4.8 – Functions and Types

    lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);

    -Converts the Lua value at the given acceptable index +Converts the Lua value at the given index to the unsigned integral type lua_Unsigned. The Lua value must be a number or a string convertible to a number (see §3.4.2); @@ -4812,7 +4869,7 @@

    4.8 – Functions and Types

    void *lua_touserdata (lua_State *L, int index);

    -If the value at the given acceptable index is a full userdata, +If the value at the given index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. @@ -4827,8 +4884,8 @@

    4.8 – Functions and Types

    int lua_type (lua_State *L, int index);

    -Returns the type of the value in the given acceptable index, -or LUA_TNONE for a non-valid index. +Returns the type of the value in the given valid index, +or LUA_TNONE for a non-valid (but acceptable) index. The types returned by lua_type are coded by the following constants defined in lua.h: LUA_TNIL, @@ -4848,7 +4905,7 @@

    4.8 – Functions and Types


    lua_typename

    [-0, +0, –] -

    const char *lua_typename  (lua_State *L, int tp);
    +
    const char *lua_typename (lua_State *L, int tp);

    Returns the name of the type encoded by the value tp, @@ -4874,6 +4931,18 @@

    4.8 – Functions and Types

    +

    lua_upvalueindex

    +[-0, +0, –] +

    int lua_upvalueindex (int i);
    + +

    +Returns the pseudo-index that represents the i-th upvalue of +the running function (see §4.4). + + + + +


    lua_version

    [-0, +0, v]

    const lua_Number *lua_version (lua_State *L);
    @@ -4932,7 +5001,7 @@

    4.8 – Functions and Types


    lua_yield

    [-?, +?, –] -

    int lua_yield  (lua_State *L, int nresults);
    +
    int lua_yield (lua_State *L, int nresults);

    This function is equivalent to lua_yieldk, @@ -4947,7 +5016,7 @@

    4.8 – Functions and Types


    lua_yieldk

    [-?, +?, –] -

    int lua_yieldk  (lua_State *L, int nresults, int ctx, lua_CFunction k);
    +
    int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);

    Yields a coroutine. @@ -5145,11 +5214,11 @@

    4.9 – The Debug Interface


    lua_getinfo

    -[-(0|1), +(0|1|2), m] +[-(0|1), +(0|1|2), e]

    int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);

    -Returns information about a specific function or function invocation. +Gets information about a specific function or function invocation.

    @@ -5268,7 +5337,7 @@

    4.9 – The Debug Interface

    int lua_getstack (lua_State *L, int level, lua_Debug *ar);

    -Get information about the interpreter runtime stack. +Gets information about the interpreter runtime stack.

    @@ -5345,6 +5414,20 @@

    4.9 – The Debug Interface

    this execution occurs without any calls to hooks. +

    +Hook functions cannot have continuations, +that is, they cannot call lua_yieldk, +lua_pcallk, or lua_callk with a non-null k. + + +

    +Hook functions can yield under the following conditions: +Only count and line events can yield +and they cannot yield any value; +to yield a hook function must finish its execution +calling lua_yield with nresults equal to zero. + + @@ -5450,7 +5533,7 @@

    4.9 – The Debug Interface

    Returns an unique identifier for the upvalue numbered n -from the closure at index fidx. +from the closure at index funcindex. Parameters funcindex and n are as in the lua_getupvalue (see lua_getupvalue) (but n cannot be greater than the number of upvalues). @@ -5467,13 +5550,14 @@

    4.9 – The Debug Interface

    -

    lua_upvaluejoin

    -
    void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
    -                                    int fidx2, int n2);
    +

    lua_upvaluejoin

    +[-0, +0, –] +

    void lua_upvaluejoin (lua_State *L, int funcindex1, int n1,
    +                                    int funcindex2, int n2);

    -Make the n1-th upvalue of the Lua closure at index fidx1 -refer to the n2-th upvalue of the Lua closure at index fidx2. +Make the n1-th upvalue of the Lua closure at index funcindex1 +refer to the n2-th upvalue of the Lua closure at index funcindex2. @@ -5538,7 +5622,7 @@

    5.1 – Functions and Types


    luaL_addchar

    -[-?, +?, m] +[-?, +?, e]

    void luaL_addchar (luaL_Buffer *B, char c);

    @@ -5550,7 +5634,7 @@

    5.1 – Functions and Types


    luaL_addlstring

    -[-?, +?, m] +[-?, +?, e]

    void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);

    @@ -5564,7 +5648,7 @@

    5.1 – Functions and Types


    luaL_addsize

    -[-?, +?, m] +[-?, +?, e]

    void luaL_addsize (luaL_Buffer *B, size_t n);

    @@ -5577,7 +5661,7 @@

    5.1 – Functions and Types


    luaL_addstring

    -[-?, +?, m] +[-?, +?, e]

    void luaL_addstring (luaL_Buffer *B, const char *s);

    @@ -5591,7 +5675,7 @@

    5.1 – Functions and Types


    luaL_addvalue

    -[-1, +?, m] +[-1, +?, e]

    void luaL_addvalue (luaL_Buffer *B);

    @@ -5614,7 +5698,7 @@

    5.1 – Functions and Types

    [-0, +0, v]
    void luaL_argcheck (lua_State *L,
                         int cond,
    -                    int narg,
    +                    int arg,
                         const char *extramsg);

    @@ -5627,7 +5711,7 @@

    5.1 – Functions and Types


    luaL_argerror

    [-0, +0, v] -

    int luaL_argerror (lua_State *L, int narg, const char *extramsg);
    +
    int luaL_argerror (lua_State *L, int arg, const char *extramsg);

    Raises an error with a standard message @@ -5686,7 +5770,7 @@

    5.1 – Functions and Types

  • Then copy the string into that space.
  • -Finish by calling luaL_pushresult(&b, sz), +Finish by calling luaL_pushresultsize(&b, sz), where sz is the total size of the resulting string copied into that space.
  • @@ -5728,7 +5812,7 @@

    5.1 – Functions and Types


    luaL_buffinitsize

    -[-?, +?, m] +[-?, +?, e]

    char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz);

    @@ -5762,11 +5846,11 @@

    5.1 – Functions and Types


    luaL_checkany

    [-0, +0, v] -

    void luaL_checkany (lua_State *L, int narg);
    +
    void luaL_checkany (lua_State *L, int arg);

    Checks whether the function has an argument -of any type (including nil) at position narg. +of any type (including nil) at position arg. @@ -5774,10 +5858,10 @@

    5.1 – Functions and Types


    luaL_checkint

    [-0, +0, v] -

    int luaL_checkint (lua_State *L, int narg);
    +
    int luaL_checkint (lua_State *L, int arg);

    -Checks whether the function argument narg is a number +Checks whether the function argument arg is a number and returns this number cast to an int. @@ -5786,10 +5870,10 @@

    5.1 – Functions and Types


    luaL_checkinteger

    [-0, +0, v] -

    lua_Integer luaL_checkinteger (lua_State *L, int narg);
    +
    lua_Integer luaL_checkinteger (lua_State *L, int arg);

    -Checks whether the function argument narg is a number +Checks whether the function argument arg is a number and returns this number cast to a lua_Integer. @@ -5798,10 +5882,10 @@

    5.1 – Functions and Types


    luaL_checklong

    [-0, +0, v] -

    long luaL_checklong (lua_State *L, int narg);
    +
    long luaL_checklong (lua_State *L, int arg);

    -Checks whether the function argument narg is a number +Checks whether the function argument arg is a number and returns this number cast to a long. @@ -5810,10 +5894,10 @@

    5.1 – Functions and Types


    luaL_checklstring

    [-0, +0, v] -

    const char *luaL_checklstring (lua_State *L, int narg, size_t *l);
    +
    const char *luaL_checklstring (lua_State *L, int arg, size_t *l);

    -Checks whether the function argument narg is a string +Checks whether the function argument arg is a string and returns this string; if l is not NULL fills *l with the string's length. @@ -5829,10 +5913,10 @@

    5.1 – Functions and Types


    luaL_checknumber

    [-0, +0, v] -

    lua_Number luaL_checknumber (lua_State *L, int narg);
    +
    lua_Number luaL_checknumber (lua_State *L, int arg);

    -Checks whether the function argument narg is a number +Checks whether the function argument arg is a number and returns this number. @@ -5842,12 +5926,12 @@

    5.1 – Functions and Types


    luaL_checkoption

    [-0, +0, v]

    int luaL_checkoption (lua_State *L,
    -                      int narg,
    +                      int arg,
                           const char *def,
                           const char *const lst[]);

    -Checks whether the function argument narg is a string and +Checks whether the function argument arg is a string and searches for this string in the array lst (which must be NULL-terminated). Returns the index in the array where the string was found. @@ -5858,7 +5942,7 @@

    5.1 – Functions and Types

    If def is not NULL, the function uses def as a default value when -there is no argument narg or when this argument is nil. +there is no argument arg or when this argument is nil.

    @@ -5886,10 +5970,10 @@

    5.1 – Functions and Types


    luaL_checkstring

    [-0, +0, v] -

    const char *luaL_checkstring (lua_State *L, int narg);
    +
    const char *luaL_checkstring (lua_State *L, int arg);

    -Checks whether the function argument narg is a string +Checks whether the function argument arg is a string and returns this string. @@ -5903,10 +5987,10 @@

    5.1 – Functions and Types


    luaL_checktype

    [-0, +0, v] -

    void luaL_checktype (lua_State *L, int narg, int t);
    +
    void luaL_checktype (lua_State *L, int arg, int t);

    -Checks whether the function argument narg has type t. +Checks whether the function argument arg has type t. See lua_type for the encoding of types for t. @@ -5915,10 +5999,10 @@

    5.1 – Functions and Types


    luaL_checkudata

    [-0, +0, v] -

    void *luaL_checkudata (lua_State *L, int narg, const char *tname);
    +
    void *luaL_checkudata (lua_State *L, int arg, const char *tname);

    -Checks whether the function argument narg is a userdata +Checks whether the function argument arg is a userdata of the type tname (see luaL_newmetatable) and returns the userdata address (see lua_touserdata). @@ -5928,10 +6012,10 @@

    5.1 – Functions and Types


    luaL_checkunsigned

    [-0, +0, v] -

    lua_Unsigned luaL_checkunsigned (lua_State *L, int narg);
    +
    lua_Unsigned luaL_checkunsigned (lua_State *L, int arg);

    -Checks whether the function argument narg is a number +Checks whether the function argument arg is a number and returns this number cast to a lua_Unsigned. @@ -5955,7 +6039,7 @@

    5.1 – Functions and Types


    luaL_dofile

    -[-0, +?, m] +[-0, +?, e]

    int luaL_dofile (lua_State *L, const char *filename);

    @@ -6014,7 +6098,7 @@

    5.1 – Functions and Types


    luaL_execresult

    -[-0, +3, m] +[-0, +3, e]

    int luaL_execresult (lua_State *L, int stat);

    @@ -6027,7 +6111,7 @@

    5.1 – Functions and Types


    luaL_fileresult

    -[-0, +(1|3), m] +[-0, +(1|3), e]

    int luaL_fileresult (lua_State *L, int stat, const char *fname);

    @@ -6040,7 +6124,7 @@

    5.1 – Functions and Types


    luaL_getmetafield

    -[-0, +(0|1), m] +[-0, +(0|1), e]

    int luaL_getmetafield (lua_State *L, int obj, const char *e);

    @@ -6067,12 +6151,12 @@

    5.1 – Functions and Types


    luaL_getsubtable

    -[-0, +1, m] +[-0, +1, e]

    int luaL_getsubtable (lua_State *L, int idx, const char *fname);

    Ensures that the value t[fname], -where t is the value at the valid index idx, +where t is the value at index idx, is a table, and pushes that table onto the stack. Returns true if it finds a previous table there @@ -6083,7 +6167,7 @@

    5.1 – Functions and Types


    luaL_gsub

    -[-0, +1, m] +[-0, +1, e]

    const char *luaL_gsub (lua_State *L,
                            const char *s,
                            const char *p,
    @@ -6100,15 +6184,15 @@ 

    5.1 – Functions and Types


    luaL_len

    -[-0, +1, e] +[-0, +0, e]

    int luaL_len (lua_State *L, int index);

    -Returns the "length" of the value at the given acceptable index +Returns the "length" of the value at the given index as a number; it is equivalent to the '#' operator in Lua (see §3.4.6). Raises an error if the result of the operation is not a number. -(This only can happen through metamethods.) +(This case only can happen through metamethods.) @@ -6153,7 +6237,7 @@

    5.1 – Functions and Types


    luaL_loadfile

    -[-0, +1, m] +[-0, +1, e]

    int luaL_loadfile (lua_State *L, const char *filename);

    @@ -6164,7 +6248,7 @@

    5.1 – Functions and Types


    luaL_loadfilex

    -[-0, +1, m] +[-0, +1, e]

    int luaL_loadfilex (lua_State *L, const char *filename,
                                                 const char *mode);
    @@ -6218,8 +6302,8 @@

    5.1 – Functions and Types


    luaL_newlib

    -[-0, +1, m] -

    int luaL_newlib (lua_State *L, const luaL_Reg *l);
    +[-0, +1, e] +
    void luaL_newlib (lua_State *L, const luaL_Reg *l);

    Creates a new table and registers there @@ -6234,8 +6318,8 @@

    5.1 – Functions and Types


    luaL_newlibtable

    -[-0, +1, m] -

    int luaL_newlibtable (lua_State *L, const luaL_Reg l[]);
    +[-0, +1, e] +
    void luaL_newlibtable (lua_State *L, const luaL_Reg l[]);

    Creates a new table with a size optimized @@ -6255,7 +6339,7 @@

    5.1 – Functions and Types


    luaL_newmetatable

    -[-0, +1, m] +[-0, +1, e]

    int luaL_newmetatable (lua_State *L, const char *tname);

    @@ -6309,10 +6393,10 @@

    5.1 – Functions and Types


    luaL_optint

    [-0, +0, v] -

    int luaL_optint (lua_State *L, int narg, int d);
    +
    int luaL_optint (lua_State *L, int arg, int d);

    -If the function argument narg is a number, +If the function argument arg is a number, returns this number cast to an int. If this argument is absent or is nil, returns d. @@ -6325,11 +6409,11 @@

    5.1 – Functions and Types


    luaL_optinteger

    [-0, +0, v]

    lua_Integer luaL_optinteger (lua_State *L,
    -                             int narg,
    +                             int arg,
                                  lua_Integer d);

    -If the function argument narg is a number, +If the function argument arg is a number, returns this number cast to a lua_Integer. If this argument is absent or is nil, returns d. @@ -6341,10 +6425,10 @@

    5.1 – Functions and Types


    luaL_optlong

    [-0, +0, v] -

    long luaL_optlong (lua_State *L, int narg, long d);
    +
    long luaL_optlong (lua_State *L, int arg, long d);

    -If the function argument narg is a number, +If the function argument arg is a number, returns this number cast to a long. If this argument is absent or is nil, returns d. @@ -6357,12 +6441,12 @@

    5.1 – Functions and Types


    luaL_optlstring

    [-0, +0, v]

    const char *luaL_optlstring (lua_State *L,
    -                             int narg,
    +                             int arg,
                                  const char *d,
                                  size_t *l);

    -If the function argument narg is a string, +If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d. @@ -6379,10 +6463,10 @@

    5.1 – Functions and Types


    luaL_optnumber

    [-0, +0, v] -

    lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number d);
    +
    lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number d);

    -If the function argument narg is a number, +If the function argument arg is a number, returns this number. If this argument is absent or is nil, returns d. @@ -6395,11 +6479,11 @@

    5.1 – Functions and Types


    luaL_optstring

    [-0, +0, v]

    const char *luaL_optstring (lua_State *L,
    -                            int narg,
    +                            int arg,
                                 const char *d);

    -If the function argument narg is a string, +If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d. @@ -6412,11 +6496,11 @@

    5.1 – Functions and Types


    luaL_optunsigned

    [-0, +0, v]

    lua_Unsigned luaL_optunsigned (lua_State *L,
    -                               int narg,
    +                               int arg,
                                    lua_Unsigned u);

    -If the function argument narg is a number, +If the function argument arg is a number, returns this number cast to a lua_Unsigned. If this argument is absent or is nil, returns u. @@ -6427,7 +6511,7 @@

    5.1 – Functions and Types


    luaL_prepbuffer

    -[-?, +?, m] +[-?, +?, e]

    char *luaL_prepbuffer (luaL_Buffer *B);

    @@ -6439,7 +6523,7 @@

    5.1 – Functions and Types


    luaL_prepbuffsize

    -[-?, +?, m] +[-?, +?, e]

    char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz);

    @@ -6455,7 +6539,7 @@

    5.1 – Functions and Types


    luaL_pushresult

    -[-?, +1, m] +[-?, +1, e]

    void luaL_pushresult (luaL_Buffer *B);

    @@ -6467,7 +6551,7 @@

    5.1 – Functions and Types


    luaL_pushresultsize

    -[-?, +1, m] +[-?, +1, e]

    void luaL_pushresultsize (luaL_Buffer *B, size_t sz);

    @@ -6478,7 +6562,7 @@

    5.1 – Functions and Types


    luaL_ref

    -[-1, +0, m] +[-1, +0, e]

    int luaL_ref (lua_State *L, int t);

    @@ -6582,8 +6666,8 @@

    5.1 – Functions and Types


    luaL_testudata

    -[-0, +0, m] -

    void *luaL_testudata (lua_State *L, int narg, const char *tname);
    +[-0, +0, e] +
    void *luaL_testudata (lua_State *L, int arg, const char *tname);

    This function works like luaL_checkudata, @@ -6599,7 +6683,7 @@

    5.1 – Functions and Types

    const char *luaL_tolstring (lua_State *L, int idx, size_t *len);

    -Converts any Lua value at the given acceptable index to a C string +Converts any Lua value at the given index to a C string in a reasonable format. The resulting string is pushed onto the stack and also returned by the function. @@ -6618,7 +6702,7 @@

    5.1 – Functions and Types


    luaL_traceback

    -[-0, +1, m] +[-0, +1, e]

    void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
                          int level);
    @@ -6665,7 +6749,7 @@

    5.1 – Functions and Types


    luaL_where

    -[-0, +1, m] +[-0, +1, e]

    void luaL_where (lua_State *L, int lvl);

    @@ -6749,7 +6833,7 @@

    6 – Standard Libraries

    luaopen_string (for the string library), luaopen_table (for the table library), luaopen_math (for the mathematical library), -luaopen_bitlib (for the bit library), +luaopen_bit32 (for the bit library), luaopen_io (for the I/O library), luaopen_os (for the Operating System library), and luaopen_debug (for the debug library). @@ -6963,11 +7047,14 @@

    6.1 – Basic Functions

    If the resulting function has upvalues, -the first upvalue is set to the value of the -global environment or to env, -if that parameter is given. -When loading main chunks, -the first upvalue will be the _ENV variable (see §2.2). +the first upvalue is set to the value of env, +if that parameter is given, +or to the value of the global environment. +(When you load a main chunk, +the resulting function will always have exactly one upvalue, +the _ENV variable (see §2.2). +When you load a binary chunk created from a function (see string.dump), +the resulting function can have arbitrary upvalues.)

    @@ -7487,7 +7574,6 @@

    6.3 – Modules

    -


    package.loaded

    @@ -7523,7 +7609,8 @@

    6.3 – Modules

    Otherwise, it looks for a function funcname inside the library and returns this function as a C function. -(So, funcname must follow the prototype lua_CFunction). +So, funcname must follow the lua_CFunction prototype +(see lua_CFunction).

    @@ -7819,7 +7906,7 @@

    6.4 – String Manipulation

    Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). -The format string follows the same rules as the C function sprintf. +The format string follows the same rules as the ISO C function sprintf. The only differences are that the options/modifiers *, h, L, l, n, and p are not supported @@ -7914,24 +8001,26 @@

    6.4 – String Manipulation

    The character % works as an escape character: any sequence in repl of the form %d, with d between 1 and 9, -stands for the value of the d-th captured substring (see below). +stands for the value of the d-th captured substring. The sequence %0 stands for the whole match. The sequence %% stands for a single %.

    If repl is a table, then the table is queried for every match, -using the first capture as the key; -if the pattern specifies no captures, -then the whole match is used as the key. +using the first capture as the key.

    If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, -in order; +in order. + + +

    +In any case, if the pattern specifies no captures, -then the whole match is passed as a sole argument. +then it behaves as if the whole pattern was inside a capture.

    @@ -8281,7 +8370,7 @@

    6.5 – Table Manipulation

    Given a list where all elements are strings or numbers, -returns list[i]..sep..list[i+1] ··· sep..list[j]. +returns the string list[i]..sep..list[i+1] ··· sep..list[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is #list. @@ -8323,10 +8412,17 @@

    6.5 – Table Manipulation

    Removes from list the element at position pos, -shifting down the elements +returning the value of the removed element. +When pos is an integer between 1 and #list, +it shifts down the elements list[pos+1], list[pos+2], ···, list[#list] -and erasing element list[#list]. -Returns the value of the removed element. +and erases element list[#list]; +The index pos can also be 0 when #list is 0, +or #list + 1; +in those cases, the function erases the element list[pos]. + + +

    The default value for pos is #list, so that a call table.remove(t) removes the last element of list t. @@ -8965,6 +9061,11 @@

    6.8 – Input and Output Facilities

    (plus an error message as a second result and a system-dependent error code as a third result) and some value different from nil on success. +On non-Posix systems, +the computation of the error message and error code +in case of errors +may be not thread safe, +because they rely on the global C variable errno.

    @@ -9385,7 +9486,7 @@

    6.9 – Operating System Facilities

    If format is not "*t", then date returns the date as a string, -formatted according to the same rules as the C function strftime. +formatted according to the same rules as the ISO C function strftime.

    @@ -9396,8 +9497,9 @@

    6.9 – Operating System Facilities

    -On some systems, -this function may be not thread safe. +On non-Posix systems, +this function may be not thread safe +because of its reliance on C function gmtime and C function localtime. @@ -9419,7 +9521,7 @@

    6.9 – Operating System Facilities

    -This function is equivalent to the C function system. +This function is equivalent to the ISO C function system. It passes command to be executed by an operating system shell. Its first result is true if the command terminated successfully, @@ -9454,7 +9556,7 @@

    6.9 – Operating System Facilities

    -Calls the C function exit to terminate the host program. +Calls the ISO C function exit to terminate the host program. If code is true, the returned status is EXIT_SUCCESS; if code is false, @@ -9535,6 +9637,11 @@

    6.9 – Operating System Facilities

    for the given category. +

    +This function may be not thread safe +because of its reliance on C function setlocale. + +

    @@ -9721,7 +9828,7 @@

    6.10 – The Debug Library

    -Variable names starting with '(' (open parentheses) +Variable names starting with '(' (open parenthesis) represent internal variables (loop control variables, temporaries, varargs, and C function locals). @@ -9786,7 +9893,7 @@

    6.10 – The Debug Library

    Sets the given function as a hook. The string mask and the number count describe when the hook will be called. -The string mask may have the following characters, +The string mask may have any combination of the following characters, with the given meaning:
      @@ -9794,8 +9901,9 @@

      6.10 – The Debug Library

    • 'r': the hook is called every time Lua returns from a function;
    • 'l': the hook is called every time Lua enters a new line of code.

    -With a count different from zero, -the hook is called after every count instructions. +Moreover, +with a count different from zero, +the hook is called also after every count instructions.

    @@ -10091,6 +10199,9 @@

    8 – Incompatibilities with the Previous Version

    appropriate options (see file luaconf.h). However, all these compatibility options will be removed in the next version of Lua. +Similarly, +all features marked as deprecated in Lua 5.1 +have been removed in Lua 5.2. @@ -10387,10 +10498,10 @@

    9 – The Complete Syntax of Lua


    Last update: -Mon Dec 12 15:21:08 BRST 2011 +Mon Feb 23 22:24:44 BRT 2015 diff --git a/doc/readme.html b/doc/readme.html index f0c77a16..a4ee9919 100644 --- a/doc/readme.html +++ b/doc/readme.html @@ -7,6 +7,7 @@