Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Build now works on OSX and Linux.

  • Loading branch information...
commit 238719986128dc2e6eaa2c246396079b5d07ea8b 1 parent bc3e06d
@drahosp drahosp authored
View
1  .gitignore
@@ -1,3 +1,4 @@
+_*
*.[oa]
*.so
*.obj
View
282 CMakeLists.txt
@@ -4,68 +4,222 @@
# For details see the COPYRIGHT file distributed with LuaDist.
# Please note that the package source code is licensed under its own license.
-PROJECT ( luajit C)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-INCLUDE(dist.cmake )
-
-# Basic architecture detection
-IF( CMAKE_SIZEOF_VOID_P MATCHES 8 )
- MESSAGE(FATAL_ERROR "LuaJIT only supports 32bit machines")
-ENDIF()
-
-# Determine install host
-IF ( WIN32 AND NOT CYGWIN)
- ADD_DEFINITIONS ( -DLUA_BUILD_AS_DLL )
-ELSE ( )
- ADD_DEFINITIONS ( -DLUA_USE_POSIX -DLUA_USE_DLOPEN )
- SET ( LIBS m dl )
-ENDIF ( )
-
-# Add Readline support when available
-FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h)
-FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
-IF ( READLINE_LIBRARY )
- INCLUDE_DIRECTORIES ( ${READLINE_INCLUDE_DIR} )
- ADD_DEFINITIONS ( -DLUA_USE_READLINE )
- SET ( LIBS ${LIBS} ${READLINE_LIBRARY} )
-ENDIF ( )
-
-# Add Curses support when available
-INCLUDE(FindCurses)
-IF ( CURSES_LIBRARY )
- INCLUDE_DIRECTORIES ( ${CURSES_INCLUDE_DIR} )
- SET ( LIBS ${LIBS} ${CURSES_LIBRARY} )
-ENDIF ( )
-
-# Build Libraries
-SET(SRC_COCO src/lcoco.c)
-SET(SRC_LIBJIT src/ljit_core.c src/ljit_mem.c src/ljit_dasm.c src/ljit_backend.c)
-SET(SRC_LIBLUAJIT src/lauxlib.c src/lbaselib.c src/ldblib.c src/liolib.c src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c src/ljitlib.c)
-SET(SRC_JITCORE src/lapi.c src/lcode.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 ${SRC_COCO} ${SRC_LIBJIT})
-
-INCLUDE_DIRECTORIES (dynasm src)
-ADD_LIBRARY ( liblua SHARED ${SRC_JITCORE} ${SRC_LIBLUAJIT} src/lua.def src/lua_dll.rc)
-TARGET_LINK_LIBRARIES ( liblua ${LIBS})
-SET_TARGET_PROPERTIES ( liblua PROPERTIES OUTPUT_NAME lua CLEAN_DIRECT_OUTPUT 1 )
-
-ADD_LIBRARY ( liblua_static ${SRC_JITCORE} ${SRC_LIBLUAJIT})
-TARGET_LINK_LIBRARIES ( liblua_static ${LIBS})
-
-# Build Executables
-SET ( SRC_LUA src/lua.c )
-SET ( SRC_LUAC src/luac.c src/print.c )
-
-ADD_EXECUTABLE ( lua ${SRC_LUA} src/lua.rc)
-ADD_EXECUTABLE ( luac ${SRC_LUAC} src/lua_simple.rc)
-TARGET_LINK_LIBRARIES ( lua liblua )
-TARGET_LINK_LIBRARIES ( luac liblua_static )
-
-# Install
-INSTALL ( TARGETS lua luac liblua RUNTIME DESTINATION ${INSTALL_BIN} LIBRARY DESTINATION ${INSTALL_LIB} ARCHIVE DESTINATION ${INSTALL_LIB} )
-INSTALL ( FILES src/lua.h src/luaconf.h src/lualib.h src/lauxlib.h etc/lua.hpp DESTINATION ${INSTALL_INC} )
-INSTALL ( FILES etc/strict.lua DESTINATION ${INSTALL_LMOD} )
-INSTALL ( DIRECTORY jit DESTINATION ${INSTALL_LMOD} )
-INSTALL ( DIRECTORY doc etc DESTINATION ${INSTALL_DATA} PATTERN ".svn" EXCLUDE )
-INSTALL ( DIRECTORY jitdoc DESTINATION ${INSTALL_DOC} PATTERN ".svn" EXCLUDE )
-INSTALL ( FILES README COPYRIGHT DESTINATION ${INSTALL_DATA} )
+project ( luajit C ASM)
+cmake_minimum_required ( VERSION 2.6 )
+include ( dist.cmake )
+
+## CONFIGURATION
+# Default configuration (we assume POSIX by default)
+set ( LUA_PATH "LUA_PATH" CACHE STRING "Environment variable to use as package.path." )
+set ( LUA_CPATH "LUA_CPATH" CACHE STRING "Environment variable to use as package.cpath." )
+set ( LUA_INIT "LUA_INIT" CACHE STRING "Environment variable for initial script." )
+
+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)
+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.")
+
+# LuaJIT specific
+option ( LUAJIT_DISABLE_FFI "Disable FFI." OFF )
+option ( LUAJIT_ENABLE_LUA52COMPAT "Enable Lua 5.2 compatibility." OFF )
+option ( LUAJIT_DISABLE_JIT "Disable JIT." OFF )
+option ( LUAJIT_CPU_SSE2 "Disable SSE2." OFF )
+option ( LUAJIT_CPU_NOCMOV "Disable NOCMOV." OFF )
+
+#2DO: LUAI_* and LUAL_* settings, for now defaults are used.
+set ( LUA_DIRSEP "/" )
+set ( LUA_MODULE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX} )
+set ( LUA_ROOT ${CMAKE_INSTALL_PREFIX} CACHE STRING "Destination from which modules will be resolved. See INSTALL_LMOD and INSTALL_CMOD.")
+set ( LUA_LDIR ${INSTALL_LMOD} )
+set ( LUA_CDIR ${INSTALL_CMOD} )
+
+if ( WIN32 AND NOT CYGWIN )
+ # Windows systems
+ add_definitions ( -DLUAJIT_TARGET= -DLUA_BUILD_AS_DLL -DLUAJIT_OS=LUAJIT_OS_WINDOWS)
+ set ( LJVM_MODE coffasm )
+ # Paths (Double escapes needed)
+ set ( LUA_DIRSEP "\\\\" )
+ string ( REPLACE "/" ${LUA_DIRSEP} LUA_ROOT ${LUA_ROOT} )
+ string ( REPLACE "/" ${LUA_DIRSEP} LUA_LDIR ${LUA_LDIR} )
+ string ( REPLACE "/" ${LUA_DIRSEP} LUA_CDIR ${LUA_CDIR} )
+elseif ( APPLE )
+ set ( CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000" )
+ option ( LUA_USE_POSIX "Use POSIX functionality." ON )
+ option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
+ set ( LJVM_MODE machasm )
+else ()
+ option ( LUA_USE_POSIX "Use POSIX functionality." ON )
+ option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
+ set ( LJVM_MODE elfasm )
+endif ()
+
+## SETUP
+# Optional libraries
+find_package ( Readline )
+if ( READLINE_FOUND )
+ option ( LUA_USE_READLINE "Use readline in the Lua CLI." ON )
+endif ()
+
+find_package ( Curses )
+if ( CURSES_FOUND )
+ option ( LUA_USE_CURSES "Use curses in the Lua CLI." ON )
+endif ()
+
+# Setup needed variables and libraries
+if ( LUA_USE_POSIX )
+ # On POSIX Lua links to standard math library "m"
+ list ( APPEND LIBS m )
+endif ()
+
+if ( LUA_USE_DLOPEN )
+ # Link to dynamic linker library "dl"
+ list ( APPEND LIBS dl )
+endif ()
+
+if ( LUA_WIN )
+ # Add extra rc files to the windows build
+ if ( MSVC OR MINGW )
+ set ( LUA_DEF src/lua.def )
+ set ( LUA_DLL_RC src/lua_dll.rc )
+ set ( LUA_RC src/lua.rc )
+ set ( LUAC_RC src/luac.rc )
+ endif ()
+endif ()
+
+if ( LUA_USE_READLINE )
+ # Add readline
+ include_directories ( ${READLINE_INCLUDE_DIR} )
+ list ( APPEND LIBS ${READLINE_LIBRARY} )
+endif ()
+
+if ( LUA_USE_CURSES )
+ # Add curses
+ include_directories ( ${CURSES_INCLUDE_DIR} )
+ list ( APPEND LIBS ${CURSES_LIBRARY} )
+endif ()
+
+## SOURCES
+# Generate luaconf.h
+configure_file ( src/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )
+
+set ( SRC_LIB
+ src/lib_aux.c
+ src/lib_base.c
+ src/lib_bit.c
+ src/lib_debug.c
+ src/lib_ffi.c
+ src/lib_init.c
+ src/lib_io.c
+ src/lib_jit.c
+ src/lib_math.c
+ src/lib_os.c
+ src/lib_string.c
+ src/lib_table.c
+ )
+if ( LUA_USE_RELATIVE_LOADLIB )
+ list ( APPEND SRC_LIB src/lib_package_rel.c )
+else ()
+ list ( APPEND SRC_LIB src/lib_package.c )
+endif ()
+
+set ( SRC_BUILD
+ src/buildvm.c
+ src/buildvm_asm.c
+ src/buildvm_peobj.c
+ src/buildvm_lib.c
+ src/buildvm_fold.c
+ )
+
+set ( SRC_JIT
+ src/lj_gc.c
+ src/lj_err.c
+ src/lj_char.c
+ src/lj_bc.c
+ src/lj_obj.c
+ src/lj_str.c
+ src/lj_tab.c
+ src/lj_func.c
+ src/lj_udata.c
+ src/lj_meta.c
+ src/lj_state.c
+ src/lj_dispatch.c
+ src/lj_vmevent.c
+ src/lj_api.c
+ src/lj_lex.c
+ src/lj_parse.c
+ src/lj_ir.c
+ src/lj_opt_mem.c
+ src/lj_opt_fold.c
+ src/lj_opt_narrow.c
+ src/lj_opt_dce.c
+ src/lj_opt_loop.c
+ src/lj_opt_split.c
+ src/lj_mcode.c
+ src/lj_snap.c
+ src/lj_record.c
+ src/lj_crecord.c
+ src/lj_ffrecord.c
+ src/lj_asm.c
+ src/lj_trace.c
+ src/lj_gdbjit.c
+ src/lj_ctype.c
+ src/lj_cdata.c
+ src/lj_cconv.c
+ src/lj_ccall.c
+ src/lj_carith.c
+ src/lj_clib.c
+ src/lj_cparse.c
+ src/lj_lib.c
+ src/lj_alloc.c
+ src/lib_aux.c
+ )
+
+## GENERATE
+add_executable ( buildvm ${SRC_BUILD} )
+set ( BUILDVM ${CMAKE_CURRENT_BINARY_DIR}/buildvm )
+
+macro(add_buildvm_target _target _mode)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}
+ COMMAND ${BUILDVM} ARGS -m ${_mode} -o ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${ARGN}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${BUILDVM} ${ARGN}
+ )
+endmacro(add_buildvm_target)
+
+add_buildvm_target ( lj_vm.s ${LJVM_MODE} )
+add_buildvm_target ( lj_ffdef.h ffdef ${SRC_LIB} )
+add_buildvm_target ( lj_bcdef.h bcdef ${SRC_LIB} )
+add_buildvm_target ( lj_folddef.h folddef src/lj_opt_fold.c )
+add_buildvm_target ( lj_recdef.h recdef ${SRC_LIB} )
+add_buildvm_target ( lj_libdef.h libdef ${SRC_LIB} )
+
+SET(DEPS
+ ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.s
+ ${CMAKE_CURRENT_BINARY_DIR}/lj_ffdef.h
+ ${CMAKE_CURRENT_BINARY_DIR}/lj_bcdef.h
+ ${CMAKE_CURRENT_BINARY_DIR}/lj_libdef.h
+ ${CMAKE_CURRENT_BINARY_DIR}/lj_recdef.h
+ ${CMAKE_CURRENT_BINARY_DIR}/lj_folddef.h
+ )
+
+## COMPILE
+include_directories ( ${CMAKE_CURRENT_BINARY_DIR} dynasm src )
+add_library ( liblua SHARED ${SRC_JIT} ${SRC_LIB} src/lua.def src/lua_dll.rc ${DEPS} )
+target_link_libraries ( liblua ${LIBS} )
+set_target_properties ( liblua PROPERTIES OUTPUT_NAME lua51 CLEAN_DIRECT_OUTPUT 1 )
+
+add_executable ( lua src/luajit.c src/lua.rc )
+target_link_libraries ( lua liblua )
+
+## INSTALL
+install ( TARGETS lua liblua RUNTIME DESTINATION ${INSTALL_BIN} LIBRARY DESTINATION ${INSTALL_LIB} ARCHIVE DESTINATION ${INSTALL_LIB} )
+install ( FILES src/lua.h ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h src/lualib.h src/lauxlib.h DESTINATION ${INSTALL_INC} )
+
+install_lua_module ( strict etc/strict.lua )
+install_doc ( doc/ )
+install_foo ( etc/ )
+install_data ( COPYRIGHT README )
+install_data ( lib/ INTO lib )
View
25 FindReadline.cmake
@@ -0,0 +1,25 @@
+# - Try to find Readline
+# Once done this will define
+# READLINE_FOUND - System has readline
+# READLINE_INCLUDE_DIRS - The readline include directories
+# READLINE_LIBRARIES - The libraries needed to use readline
+# READLINE_DEFINITIONS - Compiler switches required for using readline
+
+find_package ( PkgConfig )
+pkg_check_modules ( PC_READLINE QUIET readline )
+set ( READLINE_DEFINITIONS ${PC_READLINE_CFLAGS_OTHER} )
+
+find_path ( READLINE_INCLUDE_DIR readline/readline.h
+ HINTS ${PC_READLINE_INCLUDEDIR} ${PC_READLINE_INCLUDE_DIRS}
+ PATH_SUFFIXES readline )
+
+find_library ( READLINE_LIBRARY NAMES readline
+ HINTS ${PC_READLINE_LIBDIR} ${PC_READLINE_LIBRARY_DIRS} )
+
+set ( READLINE_LIBRARIES ${READLINE_LIBRARY} )
+set ( READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR} )
+
+include ( FindPackageHandleStandardArgs )
+# handle the QUIETLY and REQUIRED arguments and set READLINE_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args ( readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR )
View
490 dist.cmake
@@ -1,86 +1,392 @@
# LuaDist CMake utility library.
# Provides variables and utility functions common to LuaDist CMake builds.
#
-# Copyright (C) 2007-2010 LuaDist.
+# 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.
-# Few convinence settings
-SET (CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
-SET (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})
+## 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." )
-# Where to install module parts:
-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 share/lua/lmod CACHE PATH "Directory to install Lua modules.")
-set(INSTALL_CMOD share/lua/cmod CACHE PATH "Directory to install Lua binary modules.")
-set(INSTALL_DATA 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")
+# 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(MSVC)
-
-# Adds Lua shared library module target `_target`.
-# Additional sources to build the module are listed after `_target`.
-macro(add_lua_module _target)
- find_package(Lua51 REQUIRED)
- include_directories(${LUA_INCLUDE_DIR}) #2DO: somehow apply only to _target?
-
- add_library(${_target} MODULE ${ARGN})
- set_target_properties(${_target} PROPERTIES PREFIX "")
- target_link_libraries(${_target} ${LUA_LIBRARY})
-
- IF(WIN32)
- set_target_properties(${_target} PROPERTIES LINK_FLAGS "-Wl,--enable-auto-import")
- ENDIF()
-
-endmacro(add_lua_module)
+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} )
+
+ get_filename_component ( _source_name ${_source} NAME_WE )
+ set ( _wrapper ${CMAKE_CURRENT_BINARY_DIR}/${_name}.c )
+ set ( _code
+"// Not so simple executable wrapper for Lua apps
+#include <stdio.h>
+#include <signal.h>
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+
+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(\"${_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)\;
+getargs(L, argv, 0)\;
+lua_setglobal(L, \"arg\")\;
+// _PROGDIR global is only available when loadlib_rel.c is used in Lua
+int status = luaL_dostring(L, \"return dofile ( (_PROGDIR or '.') .. '/${_source_name}.lua')\")\;
+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 argument `_testcurrentdir` 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.
-macro(add_lua_test _testfile)
- include(CTest)
- if(BUILD_TESTING)
- 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)
+# USE: add_lua_test ( test/test1.lua )
+macro ( add_lua_test _testfile )
+ if ( SKIP_TESTING )
+ 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
-"package.path = '${CMAKE_CURRENT_BINARY_DIR}/?.lua\;${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;' .. package.path
-package.cpath = '${CMAKE_CURRENT_BINARY_DIR}/?.so\;${CMAKE_CURRENT_BINARY_DIR}/?.dll\;' .. package.cpath
+ 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}'
return dofile '${TESTFILEABS}'
" )
- if(${ARGC} GREATER 1)
- set(_testcurrentdir ${ARGV1})
- get_filename_component(TESTCURRENTDIRABS ${_testcurrentdir} ABSOLUTE)
- set(TESTWRAPPERSOURCE
+ if ( ${ARGC} GREATER 1 )
+ set ( _testcurrentdir ${ARGV1} )
+ get_filename_component ( TESTCURRENTDIRABS ${_testcurrentdir} ABSOLUTE )
+ set ( TESTWRAPPERSOURCE
"require 'lfs'
-lfs.chdir('${TESTCURRENTDIRABS}')
-${TESTWRAPPERSOURCE}")
- endif()
- FILE(WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
-
- add_test(${TESTFILEBASE} ${LUA} ${TESTWRAPPER})
- endif(BUILD_TESTING)
-
+lfs.chdir('${TESTCURRENTDIRABS}' )
+${TESTWRAPPERSOURCE}" )
+ endif ()
+ file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
+ add_test ( NAME ${TESTFILEBASE} COMMAND ${LUA} ${TESTWRAPPER} $<CONFIGURATION> )
+ endif ()
# see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
-endmacro(add_lua_test)
+endmacro ()
# Converts Lua source file `_source` to binary string embedded in C source
# file `_target`. Optionally compiles Lua source to byte code (not available
@@ -90,41 +396,41 @@ endmacro(add_lua_test)
#
# [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(
+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(
+ else ()
+ add_custom_command (
OUTPUT ${_target} DEPENDS ${SOURCEABS}
COMMAND ${BIN2C} ${_source} ">${_target}" )
- endif()
-endfunction(add_lua_bin2c)
+ endif ()
+endfunction()
View
2  dist.info
@@ -1,7 +1,7 @@
--- This file is part of LuaDist project
name = "luajit"
-version = "2.0.0"
+version = "2.0.0-beta6"
desc = "LuaJIT is JIT compiler for the Lua language."
author = "Mike Pall"
View
BIN  etc/luajit.ico
Binary file not shown
View
576 src/lib_package_rel.c
@@ -0,0 +1,576 @@
+/*
+** Package library.
+** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lib_package_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_lib.h"
+
+/* ------------------------------------------------------------------------ */
+
+/* Error codes for ll_loadfunc. */
+#define PACKAGE_ERR_LIB 1
+#define PACKAGE_ERR_FUNC 2
+
+/* Redefined in platform specific part. */
+#define PACKAGE_LIB_FAIL "open"
+
+// LuaDist specific modification
+// We REALLY need relative paths on Unix systems
+#if defined(_WIN32) || defined(__CYGWIN__)
+ #include <windows.h>
+ #define _PATH_MAX MAX_PATH
+#elif defined(__APPLE__)
+ #include <sys/param.h>
+ #include <mach-o/dyld.h>
+ #define _PATH_MAX 2000
+#else
+ #define _PATH_MAX PATH_MAX
+#endif
+
+static void setprogdir (lua_State *L) {
+ char progdir[_PATH_MAX + 1];
+ char *lb;
+ int nsize = sizeof(progdir)/sizeof(char);
+ int n = 0;
+#if defined(__CYGWIN__)
+ char win_buff[_PATH_MAX + 1];
+ GetModuleFileNameA(NULL, win_buff, nsize);
+ cygwin_conv_to_posix_path(win_buff, progdir);
+ n = strlen(progdir);
+#elif defined(_WIN32)
+ n = GetModuleFileNameA(NULL, progdir, nsize);
+#elif defined(__linux__)
+ n = readlink("/proc/self/exe", progdir, nsize);
+ if (n > 0) progdir[n] = 0;
+#elif defined(__FreeBSD__)
+ n = readlink("/proc/curproc/file", progdir, nsize);
+ if (n > 0) progdir[n] = 0;
+#elif defined(__APPLE__)
+ uint32_t nsize_apple = nsize;
+ if (_NSGetExecutablePath(progdir, &nsize_apple) == 0)
+ n = strlen(progdir);
+#else
+ // FALLBACK
+ // Use 'lsof' ... should work on most UNIX systems (incl. OSX)
+ // lsof will list open files, this captures the 1st file listed (usually the executable)
+ int pid;
+ FILE* fd;
+ char cmd[80];
+ pid = getpid();
+
+ sprintf(cmd, "lsof -p %d | awk '{if ($5==\"REG\") { print $9 ; exit}}' 2> /dev/null", pid);
+ fd = popen(cmd, "r");
+ n = fread(progdir, 1, nsize, fd);
+
+ // remove newline
+ if (n > 1) progdir[--n] = '\0';
+#endif
+ if (n == 0 || n == nsize || (lb = strrchr(progdir, (int)LUA_DIRSEP[0])) == NULL)
+ luaL_error(L, "unable to get process executable path");
+ else {
+ *lb = '\0';
+ // Set progdir global
+ lua_pushstring(L, progdir);
+ lua_setglobal(L, "_PROGDIR");
+
+ // Replace the relative path placeholder
+ luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, progdir);
+ lua_remove(L, -2);
+ }
+}
+
+
+#if LJ_TARGET_DLOPEN
+
+#include <dlfcn.h>
+
+static void ll_unloadlib(void *lib)
+{
+ dlclose(lib);
+}
+
+static void *ll_load(lua_State *L, const char *path)
+{
+ void *lib = dlopen(path, RTLD_NOW);
+ if (lib == NULL) lua_pushstring(L, dlerror());
+ return lib;
+}
+
+static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
+{
+ lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
+ if (f == NULL) lua_pushstring(L, dlerror());
+ return f;
+}
+
+#elif LJ_TARGET_WINDOWS
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+static void pusherror(lua_State *L)
+{
+ DWORD error = GetLastError();
+ char buffer[128];
+ if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, error, 0, buffer, sizeof(buffer), NULL))
+ lua_pushstring(L, buffer);
+ else
+ lua_pushfstring(L, "system error %d\n", error);
+}
+
+static void ll_unloadlib(void *lib)
+{
+ FreeLibrary((HINSTANCE)lib);
+}
+
+static void *ll_load(lua_State *L, const char *path)
+{
+ HINSTANCE lib = LoadLibraryA(path);
+ if (lib == NULL) pusherror(L);
+ return lib;
+}
+
+static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
+{
+ lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);
+ if (f == NULL) pusherror(L);
+ return f;
+}
+
+#else
+
+#undef PACKAGE_LIB_FAIL
+#define PACKAGE_LIB_FAIL "absent"
+
+#define DLMSG "dynamic libraries not enabled; no support for target OS"
+
+static void ll_unloadlib(void *lib)
+{
+ (void)lib;
+}
+
+static void *ll_load(lua_State *L, const char *path)
+{
+ (void)path;
+ lua_pushliteral(L, DLMSG);
+ return NULL;
+}
+
+static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
+{
+ (void)lib; (void)sym;
+ lua_pushliteral(L, DLMSG);
+ return NULL;
+}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+static void **ll_register(lua_State *L, const char *path)
+{
+ void **plib;
+ lua_pushfstring(L, "LOADLIB: %s", path);
+ lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
+ if (!lua_isnil(L, -1)) { /* is there an entry? */
+ plib = (void **)lua_touserdata(L, -1);
+ } else { /* no entry yet; create one */
+ lua_pop(L, 1);
+ plib = (void **)lua_newuserdata(L, sizeof(void *));
+ *plib = NULL;
+ luaL_getmetatable(L, "_LOADLIB");
+ lua_setmetatable(L, -2);
+ lua_pushfstring(L, "LOADLIB: %s", path);
+ lua_pushvalue(L, -2);
+ lua_settable(L, LUA_REGISTRYINDEX);
+ }
+ return plib;
+}
+
+static int ll_loadfunc(lua_State *L, const char *path, const char *sym)
+{
+ void **reg = ll_register(L, path);
+ if (*reg == NULL) *reg = ll_load(L, path);
+ if (*reg == NULL) {
+ return PACKAGE_ERR_LIB; /* unable to load library */
+ } else {
+ lua_CFunction f = ll_sym(L, *reg, sym);
+ if (f == NULL)
+ return PACKAGE_ERR_FUNC; /* unable to find function */
+ lua_pushcfunction(L, f);
+ return 0; /* return function */
+ }
+}
+
+static int lj_cf_package_loadlib(lua_State *L)
+{
+ const char *path = luaL_checkstring(L, 1);
+ const char *init = luaL_checkstring(L, 2);
+ int st = ll_loadfunc(L, path, init);
+ if (st == 0) { /* no errors? */
+ return 1; /* return the loaded function */
+ } else { /* error; error message is on stack top */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ lua_pushstring(L, (st == PACKAGE_ERR_LIB) ? PACKAGE_LIB_FAIL : "init");
+ return 3; /* return nil, error message, and where */
+ }
+}
+
+static int lj_cf_package_unloadlib(lua_State *L)
+{
+ void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
+ if (*lib) ll_unloadlib(*lib);
+ *lib = NULL; /* mark library as closed */
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int readable(const char *filename)
+{
+ FILE *f = fopen(filename, "r"); /* try to open file */
+ if (f == NULL) return 0; /* open failed */
+ fclose(f);
+ return 1;
+}
+
+static const char *pushnexttemplate(lua_State *L, const char *path)
+{
+ const char *l;
+ while (*path == *LUA_PATHSEP) path++; /* skip separators */
+ if (*path == '\0') return NULL; /* no more templates */
+ l = strchr(path, *LUA_PATHSEP); /* find next separator */
+ if (l == NULL) l = path + strlen(path);
+ lua_pushlstring(L, path, (size_t)(l - path)); /* template */
+ return l;
+}
+
+static const char *searchpath (lua_State *L, const char *name,
+ const char *path)
+{
+ name = luaL_gsub(L, name, ".", LUA_DIRSEP);
+ lua_pushliteral(L, ""); /* error accumulator */
+ while ((path = pushnexttemplate(L, path)) != NULL) {
+ const char *filename = luaL_gsub(L, lua_tostring(L, -1),
+ LUA_PATH_MARK, name);
+ lua_remove(L, -2); /* remove path template */
+ if (readable(filename)) /* does file exist and is readable? */
+ return filename; /* return that file name */
+ lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
+ lua_remove(L, -2); /* remove file name */
+ lua_concat(L, 2); /* add entry to possible error message */
+ }
+ return NULL; /* not found */
+}
+
+static int lj_cf_package_searchpath(lua_State *L)
+{
+ const char *f = searchpath(L, luaL_checkstring(L, 1), luaL_checkstring(L, 2));
+ if (f != NULL) {
+ return 1;
+ } else { /* error message is on top of the stack */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ return 2; /* return nil + error message */
+ }
+}
+
+static const char *findfile(lua_State *L, const char *name,
+ const char *pname)
+{
+ const char *path;
+ lua_getfield(L, LUA_ENVIRONINDEX, pname);
+ path = lua_tostring(L, -1);
+ if (path == NULL)
+ luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
+ return searchpath(L, name, path);
+}
+
+static void loaderror(lua_State *L, const char *filename)
+{
+ luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
+ lua_tostring(L, 1), filename, lua_tostring(L, -1));
+}
+
+static int lj_cf_package_loader_lua(lua_State *L)
+{
+ const char *filename;
+ const char *name = luaL_checkstring(L, 1);
+ filename = findfile(L, name, "path");
+ if (filename == NULL) return 1; /* library not found in this path */
+ if (luaL_loadfile(L, filename) != 0)
+ loaderror(L, filename);
+ return 1; /* library loaded successfully */
+}
+
+static const char *mkfuncname(lua_State *L, const char *modname)
+{
+ const char *funcname;
+ const char *mark = strchr(modname, *LUA_IGMARK);
+ if (mark) modname = mark + 1;
+ funcname = luaL_gsub(L, modname, ".", "_");
+ funcname = lua_pushfstring(L, "luaopen_%s", funcname);
+ lua_remove(L, -2); /* remove 'gsub' result */
+ return funcname;
+}
+
+static int lj_cf_package_loader_c(lua_State *L)
+{
+ const char *funcname;
+ const char *name = luaL_checkstring(L, 1);
+ const char *filename = findfile(L, name, "cpath");
+ if (filename == NULL) return 1; /* library not found in this path */
+ funcname = mkfuncname(L, name);
+ if (ll_loadfunc(L, filename, funcname) != 0)
+ loaderror(L, filename);
+ return 1; /* library loaded successfully */
+}
+
+static int lj_cf_package_loader_croot(lua_State *L)
+{
+ const char *funcname;
+ const char *filename;
+ const char *name = luaL_checkstring(L, 1);
+ const char *p = strchr(name, '.');
+ int st;
+ if (p == NULL) return 0; /* is root */
+ lua_pushlstring(L, name, (size_t)(p - name));
+ filename = findfile(L, lua_tostring(L, -1), "cpath");
+ if (filename == NULL) return 1; /* root not found */
+ funcname = mkfuncname(L, name);
+ if ((st = ll_loadfunc(L, filename, funcname)) != 0) {
+ if (st != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */
+ lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
+ name, filename);
+ return 1; /* function not found */
+ }
+ return 1;
+}
+
+static int lj_cf_package_loader_preload(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ lua_getfield(L, LUA_ENVIRONINDEX, "preload");
+ if (!lua_istable(L, -1))
+ luaL_error(L, LUA_QL("package.preload") " must be a table");
+ lua_getfield(L, -1, name);
+ if (lua_isnil(L, -1)) /* not found? */
+ lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static const int sentinel_ = 0;
+#define sentinel ((void *)&sentinel_)
+
+static int lj_cf_package_require(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ int i;
+ lua_settop(L, 1); /* _LOADED table will be at index 2 */
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, 2, name);
+ if (lua_toboolean(L, -1)) { /* is it there? */
+ if (lua_touserdata(L, -1) == sentinel) /* check loops */
+ luaL_error(L, "loop or previous error loading module " LUA_QS, name);
+ return 1; /* package is already loaded */
+ }
+ /* else must load it; iterate over available loaders */
+ lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
+ if (!lua_istable(L, -1))
+ luaL_error(L, LUA_QL("package.loaders") " must be a table");
+ lua_pushliteral(L, ""); /* error message accumulator */
+ for (i = 1; ; i++) {
+ lua_rawgeti(L, -2, i); /* get a loader */
+ if (lua_isnil(L, -1))
+ luaL_error(L, "module " LUA_QS " not found:%s",
+ name, lua_tostring(L, -2));
+ lua_pushstring(L, name);
+ lua_call(L, 1, 1); /* call it */
+ if (lua_isfunction(L, -1)) /* did it find module? */
+ break; /* module loaded successfully */
+ else if (lua_isstring(L, -1)) /* loader returned error message? */
+ lua_concat(L, 2); /* accumulate it */
+ else
+ lua_pop(L, 1);
+ }
+ lua_pushlightuserdata(L, sentinel);
+ lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
+ lua_pushstring(L, name); /* pass name as argument to module */
+ lua_call(L, 1, 1); /* run loaded module */
+ if (!lua_isnil(L, -1)) /* non-nil return? */
+ lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
+ lua_getfield(L, 2, name);
+ if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
+ lua_pushboolean(L, 1); /* use true as result */
+ lua_pushvalue(L, -1); /* extra copy to be returned */
+ lua_setfield(L, 2, name); /* _LOADED[name] = true */
+ }
+ lj_lib_checkfpu(L);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static void setfenv(lua_State *L)
+{
+ lua_Debug ar;
+ if (lua_getstack(L, 1, &ar) == 0 ||
+ lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
+ lua_iscfunction(L, -1))
+ luaL_error(L, LUA_QL("module") " not called from a Lua function");
+ lua_pushvalue(L, -2);
+ lua_setfenv(L, -2);
+ lua_pop(L, 1);
+}
+
+static void dooptions(lua_State *L, int n)
+{
+ int i;
+ for (i = 2; i <= n; i++) {
+ lua_pushvalue(L, i); /* get option (a function) */
+ lua_pushvalue(L, -2); /* module */
+ lua_call(L, 1, 0);
+ }
+}
+
+static void modinit(lua_State *L, const char *modname)
+{
+ const char *dot;
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "_M"); /* module._M = module */
+ lua_pushstring(L, modname);
+ lua_setfield(L, -2, "_NAME");
+ dot = strrchr(modname, '.'); /* look for last dot in module name */
+ if (dot == NULL) dot = modname; else dot++;
+ /* set _PACKAGE as package name (full module name minus last part) */
+ lua_pushlstring(L, modname, (size_t)(dot - modname));
+ lua_setfield(L, -2, "_PACKAGE");
+}
+
+static int lj_cf_package_module(lua_State *L)
+{
+ const char *modname = luaL_checkstring(L, 1);
+ int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, loaded, modname); /* get _LOADED[modname] */
+ if (!lua_istable(L, -1)) { /* not found? */
+ lua_pop(L, 1); /* remove previous result */
+ /* try global variable (and create one if it does not exist) */
+ if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
+ lj_err_callerv(L, LJ_ERR_BADMODN, modname);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
+ }
+ /* check whether table already has a _NAME field */
+ lua_getfield(L, -1, "_NAME");
+ if (!lua_isnil(L, -1)) { /* is table an initialized module? */
+ lua_pop(L, 1);
+ } else { /* no; initialize it */
+ lua_pop(L, 1);
+ modinit(L, modname);
+ }
+ lua_pushvalue(L, -1);
+ setfenv(L);
+ dooptions(L, loaded - 1);
+ return 0;
+}
+
+static int lj_cf_package_seeall(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TTABLE);
+ if (!lua_getmetatable(L, 1)) {
+ lua_createtable(L, 0, 1); /* create new metatable */
+ lua_pushvalue(L, -1);
+ lua_setmetatable(L, 1);
+ }
+ lua_pushvalue(L, LUA_GLOBALSINDEX);
+ lua_setfield(L, -2, "__index"); /* mt.__index = _G */
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#define AUXMARK "\1"
+
+static void setpath(lua_State *L, const char *fieldname, const char *envname,
+ const char *def)
+{
+ const char *path = getenv(envname);
+ if (path == NULL) {
+ lua_pushstring(L, def);
+ } else {
+ path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
+ LUA_PATHSEP AUXMARK LUA_PATHSEP);
+ luaL_gsub(L, path, AUXMARK, def);
+ lua_remove(L, -2);
+ }
+ setprogdir(L);
+ lua_setfield(L, -2, fieldname);
+}
+
+static const luaL_Reg package_lib[] = {
+ { "loadlib", lj_cf_package_loadlib },
+ { "searchpath", lj_cf_package_searchpath },
+ { "seeall", lj_cf_package_seeall },
+ { NULL, NULL }
+};
+
+static const luaL_Reg package_global[] = {
+ { "module", lj_cf_package_module },
+ { "require", lj_cf_package_require },
+ { NULL, NULL }
+};
+
+static const lua_CFunction package_loaders[] =
+{
+ lj_cf_package_loader_preload,
+ lj_cf_package_loader_lua,
+ lj_cf_package_loader_c,
+ lj_cf_package_loader_croot,
+ NULL
+};
+
+LUALIB_API int luaopen_package(lua_State *L)
+{
+ int i;
+ luaL_newmetatable(L, "_LOADLIB");
+ lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
+ lua_setfield(L, -2, "__gc");
+ luaL_register(L, LUA_LOADLIBNAME, package_lib);
+ lua_pushvalue(L, -1);
+ lua_replace(L, LUA_ENVIRONINDEX);
+ lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0);
+ for (i = 0; package_loaders[i] != NULL; i++) {
+ lj_lib_pushcf(L, package_loaders[i], 1);
+ lua_rawseti(L, -2, i+1);
+ }
+ lua_setfield(L, -2, "loaders");
+ setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT);
+ setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT);
+ lua_pushliteral(L, LUA_PATH_CONFIG);
+ lua_setfield(L, -2, "config");
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
+ lua_setfield(L, -2, "loaded");
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4);
+ lua_setfield(L, -2, "preload");
+ lua_pushvalue(L, LUA_GLOBALSINDEX);
+ luaL_register(L, NULL, package_global);
+ lua_pop(L, 1);
+ return 1;
+}
+
View
131 src/lua.def
@@ -0,0 +1,131 @@
+EXPORTS
+ lua_tolstring
+ lua_typename
+ lua_pushfstring
+ lua_pushvfstring
+ lua_getlocal
+ lua_getupvalue
+ lua_setlocal
+ lua_setupvalue
+ lua_topointer
+ lua_iscfunction
+ lua_isnumber
+ lua_isstring
+ lua_isuserdata
+ lua_toboolean
+ lua_type
+ lua_equal
+ lua_lessthan
+ lua_rawequal
+ lua_checkstack
+ lua_cpcall
+ lua_error
+ lua_getmetatable
+ lua_gettop
+ lua_load
+ lua_next
+ lua_pcall
+ lua_pushthread
+ lua_setfenv
+ lua_setmetatable
+ lua_resume
+ lua_status
+ lua_yield
+ lua_dump
+ lua_gc
+ lua_gethook
+ lua_gethookcount
+ lua_gethookmask
+ lua_getinfo
+ lua_getstack
+ lua_sethook
+ lua_getallocf
+ lua_tocfunction
+ lua_atpanic
+ lua_tointeger
+ lua_tonumber
+ lua_tothread
+ lua_newstate
+ lua_newthread
+ lua_objlen
+ lua_touserdata
+ lua_close
+ lua_call
+ lua_concat
+ lua_createtable
+ lua_getfenv
+ lua_getfield
+ lua_gettable
+ lua_insert
+ lua_pushboolean
+ lua_pushcclosure
+ lua_pushinteger
+ lua_pushlightuserdata
+ lua_pushlstring
+ lua_pushnil
+ lua_pushnumber
+ lua_pushstring
+ lua_pushvalue
+ lua_rawget
+ lua_rawgeti
+ lua_rawset
+ lua_rawseti
+ lua_remove
+ lua_replace
+ lua_setfield
+ lua_settable
+ lua_settop
+ lua_xmove
+ lua_newuserdata
+ lua_setallocf
+ luaL_prepbuffer
+ luaL_checklstring
+ luaL_findtable
+ luaL_gsub
+ luaL_optlstring
+ luaL_newmetatable
+ luaL_argerror
+ luaL_callmeta
+ luaL_checkoption
+ luaL_error
+ luaL_getmetafield
+ luaL_loadbuffer
+ luaL_loadfile
+ luaL_loadstring
+ luaL_ref
+ luaL_typerror
+ luaL_checkinteger
+ luaL_optinteger
+ luaL_checknumber
+ luaL_optnumber
+ luaL_newstate
+ luaL_openlib
+ luaL_addlstring
+ luaL_addstring
+ luaL_addvalue
+ luaL_buffinit
+ luaL_checkany
+ luaL_checkstack
+ luaL_checktype
+ luaL_pushresult
+ luaL_register
+ luaL_unref
+ luaL_where
+ luaL_checkudata
+ luaopen_base
+ luaopen_debug
+ luaopen_io
+ luaopen_math
+ luaopen_os
+ luaopen_package
+ luaopen_string
+ luaopen_table
+ luaL_openlibs
+ luaU_dump
+ luaM_toobig
+ luaM_realloc_
+ luaS_newlstr
+ luaD_growstack
+ luaF_newproto
+ luaP_opmodes
+ luaP_opnames
View
28 src/lua.rc
@@ -0,0 +1,28 @@
+0 ICON "..\\etc\\luajit.ico"
+
+1 VERSIONINFO
+ FILEVERSION 2,0,0,0
+ PRODUCTVERSION 2,0,0,0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", "www.luajit.org\0"
+ VALUE "CompanyName", "luajit.org\0"
+ VALUE "FileDescription", "LuaJIT, JIT copmiler for the LuaLanguage\0"
+ VALUE "FileVersion", "2.0.0-beta6\0"
+ VALUE "LegalCopyright", "Copyright � Mike Pall.\0"
+ VALUE "OriginalFilename", "luajit.exe\0"
+ VALUE "ProductName", "LuaJIT, JIT copmiler for the LuaLanguage\0"
+ VALUE "ProductVersion", "2.0.0\0"
+ VALUE "PrivateBuild", "Built for LuaDist\0"
+ END
+ END
+END
+
+#ifdef MSVC8
+1 24 "lua_dll8.manifest"
+#elif MSVC9
+1 24 "lua_dll9.manifest"
+#endif
View
28 src/lua_dll.rc
@@ -0,0 +1,28 @@
+0 ICON "..\\etc\\luajit.ico"
+
+1 VERSIONINFO
+ FILEVERSION 2,0,0,0
+ PRODUCTVERSION 2,0,0,0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", "www.luajit.org\0"
+ VALUE "CompanyName", "luajit.org\0"
+ VALUE "FileDescription", "LuaJIT runtime library\0"
+ VALUE "FileVersion", "2.0.0-beta6\0"
+ VALUE "LegalCopyright", "Copyright � Mike Pall.\0"
+ VALUE "OriginalFilename", "luajit.exe\0"
+ VALUE "ProductName", "LuaJIT, JIT copmiler for the LuaLanguage\0"
+ VALUE "ProductVersion", "2.0.0\0"
+ VALUE "PrivateBuild", "Built for LuaDist\0"
+ END
+ END
+END
+
+#ifdef MSVC8
+1 24 "lua_dll8.manifest"
+#elif MSVC9
+1 24 "lua_dll9.manifest"
+#endif
View
110 src/luaconf.h.in
@@ -0,0 +1,110 @@
+/*
+** Configuration header.
+** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef luaconf_h
+#define luaconf_h
+
+#include <limits.h>
+#include <stddef.h>
+
+#cmakedefine LUAJIT_DISABLE_FFI
+#cmakedefine LUAJIT_ENABLE_LUA52COMPAT
+#cmakedefine LUAJIT_DISABLE_JIT
+#cmakedefine LUAJIT_CPU_SSE2
+#cmakedefine LUAJIT_CPU_NOCMOV
+
+/* Default path for loading Lua and C modules with require(). */
+#cmakedefine LUA_MODULE_SUFFIX "@LUA_MODULE_SUFFIX@"
+#cmakedefine LUA_ROOT "@LUA_ROOT@"
+#cmakedefine LUA_LDIR "@LUA_LDIR@"
+#cmakedefine LUA_CDIR "@LUA_CDIR@"
+
+#define LUA_PATH_DEFAULT "./?.lua;" LUA_ROOT "/" LUA_LDIR "/?.lua;" LUA_ROOT "/" LUA_LDIR "/?/init.lua"
+#define LUA_CPATH_DEFAULT "./?" LUA_MODULE_SUFFIX ";" LUA_ROOT "/" LUA_CDIR "/?" LUA_MODULE_SUFFIX ";" LUA_ROOT "/" LUA_CDIR "/loadall" LUA_MODULE_SUFFIX
+
+/* Environment variable names for path overrides and initialization code. */
+#cmakedefine LUA_PATH "@LUA_PATH@"
+#cmakedefine LUA_CPATH "@LUA_CPATH@"
+#cmakedefine LUA_INIT "@LUA_INIT@"
+
+/* Special file system characters. */
+#cmakedefine LUA_DIRSEP "@LUA_DIRSEP@"
+#define LUA_PATHSEP ";"
+#define LUA_PATH_MARK "?"
+#define LUA_EXECDIR "!"
+#define LUA_IGMARK "-"
+#define LUA_PATH_CONFIG \
+ LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \
+ LUA_EXECDIR "\n" LUA_IGMARK
+
+/* Quoting in error messages. */
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
+
+/* Various tunables. */
+#define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */
+#define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */
+#define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */
+#define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */
+#define LUA_MAXCAPTURES 32 /* Max. pattern captures. */
+
+/* Compatibility with older library function names. */
+#define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */
+#define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */
+
+/* Configuration for the frontend (the luajit executable). */
+#if defined(luajit_c)
+#define LUA_PROGNAME "luajit" /* Fallback frontend name. */
+#cmakedefine LUA_PROMPT "@LUA_PROMPT@" /* Interactive prompt. */
+#cmakedefine LUA_PROMPT2 "@LUA_PROMPT2@" /* Continuation prompt. */
+#cmakedefine LUA_MAXINPUT @LUA_MAXINPUT@ /* Max. input line length. */
+#endif
+
+/* Note: changing the following defines breaks the Lua 5.1 ABI. */
+#define LUA_INTEGER ptrdiff_t
+#define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */
+#define LUAL_BUFFERSIZE BUFSIZ /* Size of lauxlib and io.* buffers. */
+
+/* The following defines are here only for compatibility with luaconf.h
+** from the standard Lua distribution. They must not be changed for LuaJIT.
+*/
+#define LUA_NUMBER_DOUBLE
+#define LUA_NUMBER double
+#define LUAI_UACNUMBER double
+#define LUA_NUMBER_SCAN "%lf"
+#define LUA_NUMBER_FMT "%.14g"
+#define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR 32
+#define lua_str2number(s, p) strtod((s), (p))
+#define LUA_INTFRMLEN "l"
+#define LUA_INTFRM_T long
+
+/* Linkage of public API functions. */
+#if defined(LUA_BUILD_AS_DLL)
+#if defined(LUA_CORE) || defined(LUA_LIB)
+#define LUA_API __declspec(dllexport)
+#else
+#define LUA_API __declspec(dllimport)
+#endif
+#else
+#define LUA_API extern
+#endif
+
+#define LUALIB_API LUA_API
+
+/* Support for internal assertions. */
+#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)
+#include <assert.h>
+#endif
+#ifdef LUA_USE_ASSERT
+#define lua_assert(x) assert(x)
+#endif
+#ifdef LUA_USE_APICHECK
+#define luai_apicheck(L, o) { (void)L; assert(o); }
+#else
+#define luai_apicheck(L, o) { (void)L; }
+#endif
+
+#endif
View
0  src/luaconf.h → src/luaconf.h.orig
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.