[
  {
    "path": ".gitignore",
    "content": "build\nllvm-lua/*.bc\nllvm-lua/*_bc.h\nsrc/.libs\nsrc/*.o\nsrc/*.lo\nsrc/*.la\nsrc/*.a\nsrc/lua\nsrc/luac\nsrc/lua_test\n.*.swp\n"
  },
  {
    "path": ".hgignore",
    "content": "# Backup files\n.*~$\n# Rejected patches\n.*\\.orig$\n.*\\.rej$\n# Build directory\n^build$\n"
  },
  {
    "path": "AUTHORS",
    "content": "bobby@neoawareness.com:Robert G. Jakabosky <bobby@neoawareness.com>\n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "#\n# llvm-lua\n#\ncmake_minimum_required(VERSION 2.4 FATAL_ERROR)\n\nif(COMMAND cmake_policy)\n  cmake_policy(SET CMP0003 NEW)\nendif(COMMAND cmake_policy)\n\nproject(llvm_lua C CXX)\n\nset(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)\n\ninclude(CustomMacros)\ninclude(CMakeDependentOption)\ninclude(FindLLVM)\n\nenable_testing()\n\nset(LLVM_LUA_NAME \"llvm-lua\")\nset(LLVM_LUA_COPYRIGHT \"Copyright (C) 2008-2009 Robert G. Jakabosky, http://code.google.com/p/llvm-lua/\")\n\n#\n# Lua version\n#\nset(LUA_VERSION_MAJOR 5)\nset(LUA_VERSION_MINOR 1)\nset(LUA_VERSION_PATCH 4)\nset(LUA_VERSION\n\t\t\t\t\"${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}\")\nset(LUA_SOVERSION\n\t\t\t\t\"${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}\")\n\n#\n# llvm-lua version\n#\nset(LLVM_LUA_VERSION_MAJOR 1)\nset(LLVM_LUA_VERSION_MINOR 3)\nset(LLVM_LUA_VERSION_PATCH 1)\nset(LLVM_LUA_VERSION\n\t\"${LLVM_LUA_VERSION_MAJOR}.${LLVM_LUA_VERSION_MINOR}.${LLVM_LUA_VERSION_PATCH}\")\nset(LLVM_LUA_SOVERSION\n\t\"${LLVM_LUA_VERSION_MAJOR}.${LLVM_LUA_VERSION_MINOR}\")\n\n#\n# Lua package info.\n#\nset(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_LUA_VERSION_MAJOR})\nset(CPACK_PACKAGE_VERSION_MINOR ${LLVM_LUA_VERSION_MINOR})\nset(CPACK_PACKAGE_VERSION_PATCH ${LLVM_LUA_VERSION_PATCH})\nset(CPACK_RESOURCE_FILE_LICENSE \"${CMAKE_SOURCE_DIR}/COPYRIGHT\")\nset(CPACK_RESOURCE_FILE_README \"${CMAKE_SOURCE_DIR}/README\")\nset(CPACK_PACKAGE_VENDOR \"\")\nset(CPACK_SOURCE_GENERATOR \"TGZ\")\nset(CPACK_SOURCE_IGNORE_FILES\n\"/\\\\\\\\.;/\\\\\\\\.git.*/;~$;build/;CMakeFiles/;CMakeCache;Testing/;cmake_install;CPack;Dart;Makefile$\")\nset(CPACK_SOURCE_PACKAGE_FILE_NAME\n\t\"${LLVM_LUA_NAME}-${LLVM_LUA_VERSION_MAJOR}.${LLVM_LUA_VERSION_MINOR}.${LLVM_LUA_VERSION_PATCH}\")\n# MUST be after CPACK_* variables.\ninclude(CPack)\n\nset(COMMON_CFLAGS)\nset(COMMON_LDFLAGS)\nset(LIBS)\n#\n# Detect system type\n#\nif(CMAKE_SYSTEM_NAME STREQUAL \"Linux\")\n\tset(DEFAULT_POSIX TRUE)\n\tset(DEFAULT_DLOPEN ON)\n\tset(DEFAULT_READLINE ON)\n\tset(COMMON_LDFLAGS \"${COMMON_LDFLAGS} -Wl,-E\")\n\tset(USE_RPATH TRUE)\n\t# This is a HACK.  We need to put the flags from `llvm-config --lflags` at\n\t# the end of the linker command.  If you know a better way to fix this let\n\t# me know.\n\tset(CMAKE_CXX_LINK_EXECUTABLE\n\t\t\"<CMAKE_CXX_COMPILER>  <FLAGS> <CMAKE_CXX_LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> <LINK_FLAGS>\")\n\tSET(CMAKE_C_LINK_EXECUTABLE\n\t\t\"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> <LINK_FLAGS>\")\nelseif(APPLE)\n\tset(DEFAULT_POSIX TRUE)\n\tset(DEFAULT_DLOPEN ON)\n\t# use this on Mac OS X 10.3-\n\toption(LUA_USE_MACOSX \"Mac OS X 10.3-\" OFF)\n\tset(OSX_ARCHITECTURES \"x86_64\" CACHE STRING \"Build architectures for OSX\")\n\tCMAKE_DEPENDENT_OPTION(WANT_FRAMEWORK\n\t\t\"Set to ON to build framework instead of dylib.\" ON\n\t\t\"WANT_SHARED_LIBRARY\" ON\n\t)\n\tCMAKE_DEPENDENT_OPTION(LUA_FRAMEWORK_SYMLINKS\n\t\t\"Set to ON to create symlinks to llvm-lua & llvm-luac to CMAKE_PREFIX_PATH/bin.\" ON\n\t\t\"WANT_FRAMEWORK;WANT_SHARED_LIBRARY\" ON\n\t)\n\tset(CMAKE_FRAMEWORK_INSTALL_DIR \"/Library/Frameworks\" CACHE STRING \"Directory to install frameworks to.\")\n\tset(CMAKE_FRAMEWORK_INSTALL_NAME_DIR \"@executable_path/../Frameworks\" CACHE STRING \"install_name path for framework.\")\n\tset(CMAKE_DYLIB_INSTALL_NAME_DIR \"${CMAKE_INSTALL_PREFIX}/lib\" CACHE STRING \"install_name path for dylib.\")\n\tset(LUA_FRAMEWORK_NAME \"llvm-lua.framework\")\n\tset(LUA_FRAMEWORK_VERSION_NUMBER \"${LLVM_LUA_VERSION_MAJOR}.${LLVM_LUA_VERSION_MINOR}\")\n\tset(LUA_FRAMEWORK_VERSIONED_EXECUTABLE_DIR \"Versions/${LUA_FRAMEWORK_VERSION_NUMBER}/MacOS\")\n\tset(LUA_FRAMEWORK_VERSIONED_LIB_DIR \"Versions/${LUA_FRAMEWORK_VERSION_NUMBER}/lib\")\n\tset(LUA_FRAMEWORK_CURRENT_EXECUTABLE_DIR \"Versions/Current/MacOS\")\n\n\t# For Apple install_name, is it better to detect if Xcode vs Makefile?\n\t# Xcode default=1, Makefile=0? Or detect if Framework vs. dylib,\n\t# Framework=1, dylib=0?\n\toption(CMAKE_BUILD_WITH_INSTALL_RPATH \"Set to YES to set the rpath or install_name on build instead of install.\" ON)\n\n\tset(LUA_SOVERSION\n\t\t\t\t\"${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.0\")\nelseif(CYGWIN)\n\tset(DEFAULT_POSIX TRUE)\n\tset(USE_RPATH TRUE)\nelseif(UNIX)\n\tset(DEFAULT_POSIX TRUE)\n\tset(USE_RPATH TRUE)\nelseif(WIN32)\n\tset(LUA_WIN TRUE)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_BUILD_AS_DLL\")\nelse(APPLE)\n\tset(DEFAULT_ANSI TRUE)\nendif(CMAKE_SYSTEM_NAME STREQUAL \"Linux\")\n\n#\n# setup config options with default values.\n#\noption(WANT_SHARED_LIBRARY \"Set to ON to build dynamic library.\" ON)\nif(WIN32)\n\tset(WANT_STATIC_LIBRARY OFF)\nelse(WIN32)\n\toption(WANT_STATIC_LIBRARY \"Set to ON to build static library.\" ON)\nendif(WIN32)\n\noption(WANT_NOJIT_LIBRARIES \"Set to ON to build nojit libraries.\" ON)\n\nif(USE_RPATH)\n\tset(CMAKE_INSTALL_RPATH \"${CMAKE_INSTALL_PREFIX}/lib\" CACHE STRING \"rpaths separated by semicolons.\")\n\toption(CMAKE_BUILD_WITH_INSTALL_RPATH \"Set to YES to set the rpath or install_name on build instead of install.\" OFF)\nendif(USE_RPATH)\n\nif(DEFAULT_DLOPEN)\n\toption(LUA_USE_DLOPEN \"Enable dlopen support.\" ON)\nelse(DEFAULT_DLOPEN)\n\toption(LUA_USE_DLOPEN \"Enable dlopen support.\" OFF)\nendif(DEFAULT_DLOPEN)\n\nif(DEFAULT_POSIX)\n\toption(LUA_USE_CURSES \"Enable Curses support.\" ON)\n\toption(LUA_USE_MKSTEMP \"Use mkstemp.\" ON)\n\toption(LUA_USE_ISATTY \"Enable isatty support.\" ON)\n\toption(LUA_USE_POPEN \"Enable lua_popen support.\" ON)\n\toption(LUA_USE_ULONGJMP \"Try using _longjmp/_setjmp (more efficient)\" ON)\nelse(DEFAULT_POSIX)\n\toption(LUA_USE_CURSES \"Enable Curses support.\" OFF)\n\toption(LUA_USE_MKSTEMP \"Use mkstemp.\" OFF)\n\toption(LUA_USE_ISATTY \"Enable isatty support.\" OFF)\n\toption(LUA_USE_POPEN \"Enable lua_popen support.\" OFF)\n\toption(LUA_USE_ULONGJMP \"Try using _longjmp/_setjmp (more efficient)\" OFF)\nendif(DEFAULT_POSIX)\n\nif(DEFAULT_READLINE)\n\toption(LUA_USE_READLINE \"Enable readline support.\" ON)\nelse(DEFAULT_READLINE)\n\toption(LUA_USE_READLINE \"Enable readline support.\" OFF)\nendif(DEFAULT_READLINE)\n\nif(DEFAULT_ANSI)\n\toption(LUA_ANSI \"Disable non-ansi features.\" ON)\nelse(DEFAULT_ANSI)\n\toption(LUA_ANSI \"Disable non-ansi features.\" OFF)\nendif(DEFAULT_ANSI)\n\noption(LUA_USE_APICHECK \"Enable API checks.\" OFF)\n\n#\n# llvm-lua options.\n#\noption(LUA_CPP_SUPPORT \"Enable c++ support\" OFF)\nset(LLVM_PATH \"/usr\" CACHE STRING \"Path to LLVM/Clang.\")\nset(LLVM_CC \"${LLVM_PATH}/bin/clang\" CACHE STRING \"Command to compile C-code to LLVM bitcode (clang or llvm-gcc)\")\nset(LLVM_LD \"${LLVM_PATH}/bin/llvm-link\" CACHE STRING \"Command to link LLVM bitcode files into one bitcode file.\")\n\n#\n# Cross-compile options.\n#\noption(CROSS_COMPILE \"Build llvm-luac as a cross-compiler\" OFF)\nset(CROSS_ARCH \"arm\" CACHE STRING \"Cross-compiler target.\")\nset(CROSS_TRIPLE \"arm-linux-gnueabi\" CACHE STRING \"Cross-compiler target triple.\")\nset(CROSS_CPU \"arm926ej-s\" CACHE STRING \"Cross-compiler target cpu name.\")\nset(CROSS_ISYSTEM\n\t\"/usr/lib/gcc/arm-linux-gnueabi/4.6.3/include:/usr/lib/gcc/arm-linux-gnueabi/4.6.3/include-fixed:/usr/arm-linux-gnueabi/usr/include/\"\n\tCACHE STRING \"Path to target system includes.\")\n\n#\n# LuaCoco options\n#\noption(COCO_USE_SETJMP \"Coco: Force use of setjmp (instead of gccasm)\" OFF)\noption(COCO_USE_UCONTEXT \"Coco: Force use of ucontext (instead of gccasm or setjmp)\" OFF)\noption(COCO_USE_VALGRIND \"Enable valgrind debugging support\" OFF)\noption(COCO_DISABLE \"Disable coco\" OFF)\nset(COCO_DEFAULT_CSTACKSIZE \"\" CACHE STRING \"Coco default cstacksize\")\n\n#\n# libs & cflags\n#\nset(COMMON_LDFLAGS \"${COMMON_LDFLAGS} -lm \")\n\n# For \"Mac OS X 10.3-\"\nif(LUA_USE_MACOSX)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_MACOSX\")\n\tset(LUA_USE_DLOPEN FALSE)\nendif(LUA_USE_MACOSX)\n\n# enable options\nif(LUA_USE_DLOPEN)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_DLOPEN\")\n\tif(NOT APPLE)\n\t\tset(COMMON_LDFLAGS \"${COMMON_LDFLAGS} -ldl \")\n\tendif(NOT APPLE)\nendif(LUA_USE_DLOPEN)\nif(LUA_USE_MKSTEMP)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_MKSTEMP\")\nendif(LUA_USE_MKSTEMP)\nif(LUA_USE_ISATTY)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_ISATTY\")\nendif(LUA_USE_ISATTY)\nif(LUA_USE_POPEN)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_POPEN\")\nendif(LUA_USE_POPEN)\nif(LUA_USE_ULONGJMP)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_ULONGJMP\")\nendif(LUA_USE_ULONGJMP)\nif(LUA_USE_APICHECK)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_APICHECK\")\nendif(LUA_USE_APICHECK)\nif(LUA_ANSI)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_ANSI\")\nendif(LUA_ANSI)\n\n# readline support\nif(LUA_USE_READLINE AND NOT CROSS_COMPILE)\n\tFIND_PATH(READLINE_INCLUDE_DIR readline/readline.h)\n\tFIND_LIBRARY(READLINE_LIBRARY NAMES readline)\n\tif(READLINE_LIBRARY)\n\t\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_USE_READLINE\")\n\t\tset(COMMON_LDFLAGS \"${COMMON_LDFLAGS} -lreadline -lhistory\")\n\t\tinclude_directories(${READLINE_INCLUDE_DIR})\n\tendif(READLINE_LIBRARY)\nendif()\n\n# curses\nif(LUA_USE_CURSES AND NOT CROSS_COMPILE)\n\tinclude(FindCurses)\n\tif(CURSES_LIBRARY)\n\t\tinclude_directories(${CURSES_INCLUDE_DIR})\n\t\tset(LIBS ${LIBS} ${CURSES_LIBRARY})\n\tendif(CURSES_LIBRARY)\nendif()\n\n# LuaCoco flags\nif(COCO_DISABLE)\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DCOCO_DISABLE\")\nelse(COCO_DISABLE)\n\tif(COCO_USE_SETJMP)\n\t\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DCOCO_USE_SETJMP\")\n\telseif(COCO_USE_UCONTEXT)\n\t\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DCOCO_USE_UCONTEXT\")\n\tendif(COCO_USE_SETJMP)\n\n\t# check cstacksize variable.\n\tif(COCO_DEFAULT_CSTACKSIZE)\n\t\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DCOCO_DEFAULT_CSTACKSIZE=${COCO_DEFAULT_CSTACKSIZE}\")\n\tendif(COCO_DEFAULT_CSTACKSIZE)\nendif(COCO_DISABLE)\n\n#\n# Support for embedding llvm-lua into c++ programs with exception support.\n#\nif(LUA_CPP_SUPPORT)\n\tmessage(STATUS \"Lua C++ support enabled, forcing usage of g++ & llvm-g++\")\n\tset(COMMON_CFLAGS \"${COMMON_CFLAGS} -DLUA_CPP_SUPPORT\")\n\tinclude(CMakeForceCompiler)\n\tCMAKE_FORCE_C_COMPILER(${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ID})\n\tset(LLVM_CC \"llvm-g++\")\nendif(LUA_CPP_SUPPORT)\n\n#\n# standard flags to use for each build type.\n#\nif(CMAKE_COMPILER_IS_GNUCC)\n\tset(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} -pipe -Wall -Wshadow -W -std=gnu89 \")\n\tset(CMAKE_C_FLAGS_RELEASE        \"${CMAKE_C_FLAGS_RELEASE}     -O2\")\n\tset(CMAKE_C_FLAGS_DEBUG          \"${CMAKE_C_FLAGS_DEBUG}       -O0 -g\")\n\tset(CMAKE_C_FLAGS_PROFILE        \"${CMAKE_C_FLAGS_PROFILE}     -O1 -g\")\n\tset(CMAKE_C_FLAGS_RELWITHDEBINFO \"${CMAKE_C_FLAGS_WITHDEBINFO} -O2 -g\")\nendif(CMAKE_COMPILER_IS_GNUCC)\nif(CMAKE_COMPILER_IS_GNUCXX)\n\tset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -pipe -Wall -Wshadow -W -pedantic\")\n\tset(CMAKE_CXX_FLAGS_RELEASE        \"${CMAKE_CXX_FLAGS_RELEASE}     -O2\")\n\tset(CMAKE_CXX_FLAGS_DEBUG          \"${CMAKE_CXX_FLAGS_DEBUG}       -O0 -g\")\n\tset(CMAKE_CXX_FLAGS_PROFILE        \"${CMAKE_CXX_FLAGS_PROFILE}     -O2 -g\")\n\tset(CMAKE_CXX_FLAGS_RELWITHDEBINFO \"${CMAKE_CXX_FLAGS_WITHDEBINFO} -O2 -g\")\nendif(CMAKE_COMPILER_IS_GNUCXX)\n\n#\n# For uninstall (needs cmake_uninstall.cmake.in in the top-level directory)\n#\nconfigure_file(\n  \"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in\"\n  \"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake\"\n  IMMEDIATE @ONLY)\nadd_custom_target(uninstall\n  \"${CMAKE_COMMAND}\" -P \"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake\")\n\n#\n# sub-folders\n#\nadd_subdirectory(llvm-lua build)\n\n"
  },
  {
    "path": "COPYRIGHT",
    "content": "Lua License\n-----------\n\nLua is licensed under the terms of the MIT license reproduced below.\nThis means that Lua is free software and can be used for both academic\nand commercial purposes at absolutely no cost.\n\nFor details and rationale, see http://www.lua.org/license.html .\n\n===============================================================================\n\nCopyright (C) 1994-2008 Lua.org, PUC-Rio.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n===============================================================================\n\n(end of COPYRIGHT)\n"
  },
  {
    "path": "ChangeLog",
    "content": "2009-11-05  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/CMakeLists.txt, llvm-lua/run_tests.sh, src/ldo.c,\n\t  src/lgc.c, src/lgc.h, src/lobject.h, src/lvm.c, src/lzio.h:\n\t  Emergency GC fixes.\n\n2009-10-18  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* CMakeLists.txt:\n\t  Fixed bug\n\t* AUTHORS, ChangeLog, gen_changelog.sh, llvm-lua/CMakeLists.txt,\n\t  llvm-lua/lua-compiler, llvm-lua/lua-compiler.in,\n\t  llvm-lua/lua-cross-compiler.in, llvm-lua/lua_compiler.c,\n\t  llvm-lua/run_tests.sh:\n\t  Added ChangeLog, Improved lua-compiler & lua-cross-compiler.\n\t  \n\t  Added -mcpu option to *-compiler scripts.\n\t  Changed -arch to -target option.\n\t  Embed the install prefix into lua-compiler so it can find\n\t  liblua_main.a\n\t  Added gen_changelog.sh script to generate ChangeLog from svn\n\t  history.\n\n2009-10-17  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* CMakeLists.txt, README.llvm-lua, src/loadlib.c:\n\t  Last commit missed these files.\n\t* llvm-lua/CMakeLists.txt, llvm-lua/Makefile,\n\t  llvm-lua/llvm-lua.cpp, llvm-lua/llvm-luac.cpp,\n\t  llvm-lua/lua-compiler, llvm-lua/lua_compiler.c:\n\t  Added support for preloading libraries during static compilling.\n\t  \n\t  Updated README.llvm-lua file.\n\t  Improved lua-compilers argument parsing.\n\t  \n\t  Now it is possible to static compile multiple Lua scripts and\n\t  there required sub-scripts into one standalone executable.\n\n2009-10-15  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/compile_all.sh:\n\t  Wrong compiler in compile_all.sh.\n\t* cmake/CustomMacros.cmake, llvm-lua/CMakeLists.txt,\n\t  llvm-lua/compile_all.sh, llvm-lua/lua-compiler,\n\t  llvm-lua/lua-cross-compiler.in, llvm-lua/lua_core.h,\n\t  llvm-lua/lua_vm_ops.c, src/ldo.c:\n\t  Fixed bugs. Improved cross-compiler support.\n\t* src/lcoco.c, src/lcoco.h:\n\t  Update LuaCoco patch to 1.1.6\n\n2009-10-14  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* CMakeLists.txt, llvm-lua/CMakeLists.txt,\n\t  llvm-lua/lua-cross-compiler.in:\n\t  Adding cross-compiler support to CMake build scripts.\n\n2009-10-07  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* .svnignore, CMakeLists.txt, cmake_uninstall.cmake.in,\n\t  llvm-lua/CMakeLists.txt, llvm-lua/load_jit_proto.c,\n\t  llvm-lua/lua_core.c, llvm-lua/lua_vm_ops_static.c, src/loadlib.c,\n\t  src/lobject.h, src/lstate.h, src/ltable.c, src/luaconf.h:\n\t  Added MacOSX framework support.\n\n2009-09-27  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/CMakeLists.txt:\n\t  Remove duplicate source files\n\t* CMakeLists.txt, llvm-lua/CMakeLists.txt:\n\t  Added lua-compiler to CMake build.\n\t* CMakeLists.txt, cmake, cmake/CustomMacros.cmake,\n\t  cmake/FindLLVM.cmake, llvm-lua/CMakeLists.txt, llvm-lua/Makefile:\n\t  Add CMake build scripts.\n\n2009-09-23  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/Makefile,\n\t  llvm-lua/hook_parser.c, llvm-lua/llvm-lua.cpp,\n\t  llvm-lua/llvm_lmathlib.c, llvm-lua/lua_vm_ops.c,\n\t  llvm-lua/lua_vm_ops_static.c, llvm-lua/tests/coroutine.lua,\n\t  llvm-lua/tests/test_lineerror.lua, llvm-lua/tests/test_tail.lua,\n\t  llvm-lua/tests/test_tail_nil_multret.lua, src/lauxlib.c,\n\t  src/ldo.c, src/lvm.c:\n\t  Fixed memory leak, tailcalls, memlimit.\n\t  Release LLVM Function objects when Lua Proto's are garbage\n\t  collected.\n\t  Fixed a few of tailcall bugs.\n\t  Fixed a bug with the memlimit code.\n\t  Improved command line option parsing.\n\t  Added hack for iPhone support.\n\n2009-09-22  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/tests/test_varg_tail2.lua:\n\t  Add testcase: tailcall from varg function.\n\t* llvm-lua/lua_vm_ops_static.c, src/ldo.c:\n\t  Fixed tailcall inside varg function bug.\n\n2009-09-18  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/Makefile, llvm-lua/llvm-lua.cpp, llvm-lua/llvm-luac.cpp,\n\t  llvm-lua/llvm_compiler.cpp:\n\t  Fixed memory leaks and a memory access error.\n\n2009-09-17  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/compile_all.sh,\n\t  llvm-lua/load_jit_proto.c, llvm-lua/lua-compiler:\n\t  Improved cross-compiling support.\n\t* llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h,\n\t  llvm-lua/load_jit_proto.c, llvm-lua/load_jit_proto.h:\n\t  Made jit_proto & constant_type structures more portable.\n\t  Added correct amount of padding for target architecture.\n\n2009-09-16  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/llvm-luac.cpp:\n\t  Adding support for all native backends to llvm-luac.\n\t* README.llvm-lua, etc/embed_jit.c, etc/embed_jit.cpp:\n\t  Added example 'embed_jit.c' & 'embed_jit.cpp' files.\n\t* llvm-lua/llvm_compiler.cpp:\n\t  Fixed bug with native target initialization.\n\t* llvm-lua/lua-compiler:\n\t  Add better support for -arch flag\n\t* llvm-lua/lua-compiler:\n\t  Removed debug messages.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/lua-compiler:\n\t  Added support for compiling static lua-modules.\n\t* llvm-lua/lua-compiler:\n\t  Removed unneeded \"-rdynamic -Wl,-E\" from 'lua-compiler' script.\n\n2009-09-15  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h,\n\t  llvm-lua/Makefile, llvm-lua/llvm_compiler.cpp,\n\t  llvm-lua/load_embedded_bc.cpp, llvm-lua/load_embedded_bc.h,\n\t  llvm-lua/load_liblua_main.cpp, llvm-lua/load_liblua_main.h,\n\t  llvm-lua/load_vm_ops.cpp, llvm-lua/load_vm_ops.h, src/lcode.c,\n\t  src/ldblib.c, src/lvm.c:\n\t  Ported code to LLVM 2.6 API.\n\t  Applied patches for Lua 5.1.4:\n\t  3. Wrong code generation for some particular boolean expressions\n\t  4. luaV_settable may invalidate a reference to a table and try to\n\t  reuse it.\n\t  5. debug.getfenv does not check whether it has an argument.\n\n2009-06-16  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile:\n\t  Fixing MinGW support.\n\n2009-06-07  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* Makefile, llvm-lua/Makefile:\n\t  Add support for compiling shared library liblua-llvm.so\n\n2009-06-04  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/lua-compiler:\n\t  Fixed bug with lua-compiler.\n\t  Added '-c++' option for static compiling Lua code with C++\n\t  exception support.\n\t* README.llvm-lua, llvm-lua/LLVMCompiler.cpp,\n\t  llvm-lua/LLVMCompiler.h, llvm-lua/LLVMDumper.cpp,\n\t  llvm-lua/LLVMDumper.h, llvm-lua/Makefile, llvm-lua/TODO,\n\t  llvm-lua/hook_parser.c, llvm-lua/llvm-lua.cpp,\n\t  llvm-lua/llvm-lua.h, llvm-lua/llvm-luac.cpp,\n\t  llvm-lua/llvm-luac.h, llvm-lua/llvm_compiler.cpp,\n\t  llvm-lua/llvm_compiler.h, llvm-lua/llvm_compiler_private.h,\n\t  llvm-lua/llvm_dumper.cpp, llvm-lua/llvm_dumper.h,\n\t  llvm-lua/llvm_lmathlib.c, llvm-lua/load_embedded_bc.cpp,\n\t  llvm-lua/load_embedded_bc.h, llvm-lua/load_jit_proto.c,\n\t  llvm-lua/load_jit_proto.h, llvm-lua/load_liblua_main.cpp,\n\t  llvm-lua/load_liblua_main.h, llvm-lua/load_vm_ops.cpp,\n\t  llvm-lua/load_vm_ops.h, llvm-lua/lua-compiler,\n\t  llvm-lua/lua_compiler.c, llvm-lua/lua_core.c,\n\t  llvm-lua/lua_core.h, llvm-lua/lua_interpreter.c,\n\t  llvm-lua/lua_main.c, llvm-lua/lua_normal.c,\n\t  llvm-lua/lua_vm_ops.c, llvm-lua/lua_vm_ops.h,\n\t  llvm-lua/lua_vm_ops_static.c, llvm-lua/no_jit.c, src/lcoco.h,\n\t  src/ldebug.c, src/ldebug.h, src/lstate.c, src/lstate.h,\n\t  src/luaconf.h, src/lvm.c, src/print.c:\n\t  Add C++ exception support. llvm-lua is now thread-safe.\n\t  \n\t  Moved LLVMCompiler instance from global variable to\n\t  'global_State'\n\t  to help make llvm-lua thread-safe.\n\n2009-05-31  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* README.llvm-lua, llvm-lua/lua-compiler:\n\t  Fixed bug with lua-compiler script and the 'cbe' mode.\n\t  Fixed example compile/link commands in README.llvm-lua.\n\t* README.llvm-lua, llvm-lua/Makefile, llvm-lua/compile_all.sh,\n\t  llvm-lua/llvm_compiler.cpp, llvm-lua/llvm_compiler.h,\n\t  llvm-lua/lua-compiler:\n\t  Bump version to 1.0.\n\t  Add for information to README.llvm-lua\n\t  Fixed some bugs with embedding llvm-lua.\n\t  Added -help option to lua-compiler script.\n\n2009-05-30  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/tests, llvm-lua/tests/NOTES, llvm-lua/tests/add.lua,\n\t  llvm-lua/tests/arg_test.lua, llvm-lua/tests/big_table.lua,\n\t  llvm-lua/tests/dump.lua, llvm-lua/tests/for.lua,\n\t  llvm-lua/tests/hash2.lua, llvm-lua/tests/loadk.lua,\n\t  llvm-lua/tests/local_nil.lua, llvm-lua/tests/loops.lua,\n\t  llvm-lua/tests/lua_tail.lua, llvm-lua/tests/nestedloop.lua,\n\t  llvm-lua/tests/nestedloop2.lua, llvm-lua/tests/nums.lua,\n\t  llvm-lua/tests/scimark_loop.lua, llvm-lua/tests/scimark_rand.lua,\n\t  llvm-lua/tests/stress_for.lua, llvm-lua/tests/test.lua,\n\t  llvm-lua/tests/test2.lua, llvm-lua/tests/test3.lua,\n\t  llvm-lua/tests/test4.lua, llvm-lua/tests/test_math.lua,\n\t  llvm-lua/tests/test_tail.lua:\n\t  Added lua scripts used for regression testing.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/TODO,\n\t  llvm-lua/llvm_lmathlib.c, llvm-lua/lua_core.c, src/lauxlib.c,\n\t  src/lauxlib.h, src/ldo.c:\n\t  Improved speed of math.* functions by lowering the call overhead.\n\n2009-05-28  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp:\n\t  Fixed some bugs with numeric forloop optimizations.\n\n2009-05-24  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/TODO, llvm-lua/lua-compiler, llvm-lua/lua_vm_ops.c,\n\t  llvm-lua/lua_vm_ops.h, llvm-lua/lua_vm_ops_static.c, src/ldo.c:\n\t  Improved performance of numeric for loops.\n\n2009-05-21  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/llvm_dumper.cpp, llvm-lua/llvm_dumper.h,\n\t  llvm-lua/lua_compiler.c, llvm-lua/lua_vm_ops.c,\n\t  llvm-lua/lua_vm_ops.h, llvm-lua/lua_vm_ops_static.c,\n\t  llvm-lua/no_jit.c:\n\t  Added some optimizations.\n\t  Fixed a few bugs.\n\n2009-05-20  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* Makefile, llvm-lua/LLVMDumper.cpp, llvm-lua/Makefile,\n\t  llvm-lua/compile_all.sh, llvm-lua/lua-compiler,\n\t  llvm-lua/lua_compiler.c:\n\t  Fixed support for using c-backend to compile Lua scripts to\n\t  standalone binaries.\n\t* Makefile, llvm-lua/Makefile, llvm-lua/compile.sh,\n\t  llvm-lua/compile_all.sh, llvm-lua/llvm_compiler.h,\n\t  llvm-lua/lua-compiler:\n\t  Bump version number to 0.9\n\t  Cleaned up Makefile.\n\t  Renamed llvm-luac wrapper script from compile.sh to lua-compiler.\n\t* Makefile, README.llvm-lua, llvm-lua/LLVMDumper.cpp,\n\t  llvm-lua/Makefile, llvm-lua/bin2c.c, llvm-lua/compile.sh,\n\t  llvm-lua/llvm_compiler.cpp, llvm-lua/llvm_compiler.h,\n\t  llvm-lua/llvm_dumper.cpp, llvm-lua/llvm_dumper.h,\n\t  llvm-lua/load_embedded_bc.cpp, llvm-lua/load_embedded_bc.h,\n\t  llvm-lua/load_liblua_main.cpp, llvm-lua/load_liblua_main.h,\n\t  llvm-lua/load_vm_ops.cpp, llvm-lua/lua_vm_ops_module.cpp,\n\t  llvm-lua/lua_vm_ops_module.h:\n\t  Embedded lua_vm_ops.bc & liblua_main.bc instead of\n\t  loading/linking them at run-time.\n\n2009-05-19  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* Makefile, llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h,\n\t  llvm-lua/Makefile, llvm-lua/TODO, llvm-lua/compile.sh,\n\t  llvm-lua/hook_parser.c, llvm-lua/load_jit_proto.c,\n\t  llvm-lua/load_jit_proto.h, llvm-lua/lua_main.c,\n\t  llvm-lua/lua_vm_ops.c, llvm-lua/lua_vm_ops.h,\n\t  llvm-lua/lua_vm_ops_static.c, llvm-lua/no_jit.c, src/ldo.c,\n\t  src/luaconf.h:\n\t  Fixed bugs with debug hooks.\n\t  Added line/upvalues/locals info to jit_proto, to support\n\t  debugging info of JITed code.\n\t  Allow debuging info be stripped when compling Lua scripts.\n\n2009-05-17  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* Makefile, etc/lua.pc, llvm-lua/LLVMCompiler.cpp,\n\t  llvm-lua/compile.sh, llvm-lua/load_vm_ops.cpp, src/ldebug.c:\n\t  Fixed compile bug.\n\t  Fixed lua debug libraries handling of JIT functions that have Lua\n\t  bytecode stripped.\n\n2009-03-12  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h,\n\t  llvm-lua/Makefile, llvm-lua/TODO, llvm-lua/compile.sh,\n\t  llvm-lua/compile_all.sh, llvm-lua/compile_bc.sh,\n\t  llvm-lua/compile_c.sh, llvm-lua/hook_parser.c,\n\t  llvm-lua/llvm-lua.cpp, llvm-lua/llvm-luac.cpp,\n\t  llvm-lua/llvm_compiler.cpp, llvm-lua/llvm_compiler.h,\n\t  llvm-lua/load_jit_proto.c, llvm-lua/load_jit_proto.h,\n\t  llvm-lua/lua_compiler.c, llvm-lua/lua_core.c,\n\t  llvm-lua/lua_main.c, llvm-lua/lua_vm_ops.h,\n\t  llvm-lua/lua_vm_ops_static.c:\n\t  Added support for stripping Lua opcodes from compiled Lua code\n\t  (can be used for obfucation).\n\t  Added support for compiling Lua code as native code modules\n\t  instead of just standalone binaries.\n\t  Added support for compiling llvm-lua as an embeddable library\n\t  with JIT support.\n\t  Improved compile.sh wrapper script.\n\n2009-03-06  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/lua_vm_ops.c, src/lvm.c:\n\t  Fixed bug with Lua stack re-allocation.\n\n2009-01-22  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/compile_c.sh, llvm-lua/llvm-lua.cpp,\n\t  llvm-lua/llvm-luac.cpp:\n\t  fixed bug with llvm asserts.\n\t  Added bash script for compiling lua scripts to C code.\n\n2008-10-09  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/compile.sh, llvm-lua/compile_all.sh,\n\t  llvm-lua/compile_bc.sh:\n\t  compile llvm bitcode to assembly instead of 'C' code.\n\n2008-10-08  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/compile.sh:\n\t  remove '-foptimize-sibling-calls'\n\t  disabled '-march=athlon64'\n\t* llvm-lua/llvm_compiler.h:\n\t  bump version to 0.5\n\t* src/ldo.h:\n\t  Added 'PCRTAILRECUR' for tail-recursive calls from JIT functions.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/compile.sh,\n\t  llvm-lua/hook_parser.c, llvm-lua/llvm-lua.cpp,\n\t  llvm-lua/llvm-luac.cpp, llvm-lua/llvm_compiler.cpp,\n\t  llvm-lua/lua_vm_ops.c, llvm-lua/lua_vm_ops_static.c:\n\t  Fixed memory offset bug & memory leaks.\n\t  Fixed '-time-passes' to display info about passes run by JIT.\n\t  Changed default Optimization level to '3'.\n\n2008-10-07  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h, llvm-lua/TODO,\n\t  llvm-lua/compile.sh, llvm-lua/hook_parser.c,\n\t  llvm-lua/llvm-lua.cpp, llvm-lua/llvm-luac.cpp,\n\t  llvm-lua/llvm_compiler.cpp, llvm-lua/llvm_compiler.h,\n\t  llvm-lua/lua_compiler.c, llvm-lua/lua_main.c,\n\t  llvm-lua/lua_vm_ops.c, llvm-lua/lua_vm_ops.h,\n\t  llvm-lua/lua_vm_ops_static.c:\n\t  Added specialized functions for OP_EQ.\n\t  Added support to Lower for loop's internal idx variable from the\n\t  Lua stack to the c-stack.\n\t  Added support to remove \"LOADK\" opcodes used for constant for\n\t  loop parameters and turn then into llvm constants.\n\t  Added command-line options for controlling the optimization\n\t  level.\n\t  Fixed bug with passing command-line options to the Lua core\n\t  interpreter & compiler.\n\n2008-10-05  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMDumper.cpp,\n\t  llvm-lua/lua_vm_ops_static.c:\n\t  Fixed a few bugs.\n\t  Improved tail-calls from JIT function to non-JIT Lua function.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/TODO, llvm-lua/llvm-lua.cpp,\n\t  llvm-lua/llvm-luac.cpp, llvm-lua/llvm_compiler.h:\n\t  Added LLVM command options to llvm-luac.\n\t  Don't compiled inlined opcode functions, since they will not be\n\t  called.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/LLVMDumper.cpp, llvm-lua/Makefile, llvm-lua/compile.sh,\n\t  llvm-lua/hook_parser.c, llvm-lua/lua_vm_ops.c,\n\t  llvm-lua/lua_vm_ops.h, llvm-lua/lua_vm_ops_static.c, src/ldo.c,\n\t  src/ldo.h:\n\t  Fixed tail-call support, now lua scripts can make tail-calls\n\t  without the c-stack/lua callstack growing.\n\t  Added some optimizations of the Lua bytecode and generated\n\t  machine code.\n\t  Lowered the opcode limit from 800 down to 200 for the max\n\t  function size that is JITed.\n\t  Added support for specialized versions of each opcode function to\n\t  support more optimizations.\n\n2008-10-03  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/lua_vm_ops.h, llvm-lua/lua_vm_ops_static.c:\n\t  remove unused argument.\n\t* llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h,\n\t  llvm-lua/load_jit_proto.h, llvm-lua/lua_main.c:\n\t  Fixed 32bit support for static compiling Lua scripts.\n\t* Makefile, README.llvm-lua, llvm-lua/Makefile:\n\t  Improve Makefile support for other platforms.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/Makefile, llvm-lua/compile.sh, llvm-lua/compile_bc.sh,\n\t  llvm-lua/hook_parser.c, llvm-lua/llvm_compiler.cpp,\n\t  llvm-lua/llvm_compiler.h, llvm-lua/lua_core.c,\n\t  llvm-lua/lua_vm_ops.c, llvm-lua/lua_vm_ops.h,\n\t  llvm-lua/lua_vm_ops_static.c:\n\t  Improved true tailcall support when calling a JIT/C function from\n\t  a JIT function.\n\t  Removed 'func_state' structure from JIT functions to allow\n\t  tailcalls into vm_OP_* functions.\n\t* src/ldo.c, src/ldo.h, src/luaconf.h:\n\t  Export 'tryfuncTM' function as 'luaD_tryfuncTM' from ldo.c\n\t  disable HARDSTACKTESTS tests.\n\n2008-09-29  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/Makefile, llvm-lua/compile.sh, llvm-lua/lua_compiler.h,\n\t  llvm-lua/lua_core.c, llvm-lua/lua_core.h, llvm-lua/lua_vm_ops.c,\n\t  llvm-lua/lua_vm_ops.h, llvm-lua/lua_vm_ops_module.cpp,\n\t  llvm-lua/lua_vm_ops_static.c:\n\t  Moved some large vm_OP_* functions from loadable bitcode file\n\t  into llvm-lua.\n\t  Added LLVM timers to compiler.\n\t  Added support for LLVM command line options.\n\t  Some code clean up.\n\n2008-09-28  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/lua_vm_ops_module.cpp:\n\t  fixed compile bug.\n\n2008-09-27  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/llvm-lua.cpp:\n\t  Add command line parsing support for LLVM options.\n\t* llvm-lua/load_vm_ops.cpp:\n\t  search current directory & LLVM_LIB_SEARCH_PATH for lua_vm_ops.bc\n\t  file.\n\t* llvm-lua/LLVMCompiler.cpp, llvm-lua/LLVMCompiler.h,\n\t  llvm-lua/LLVMDumper.cpp, llvm-lua/LLVMDumper.h,\n\t  llvm-lua/Makefile, llvm-lua/compile.sh, llvm-lua/hook_parser.c,\n\t  llvm-lua/llvm-compiler.cpp, llvm-lua/llvm-compiler.h,\n\t  llvm-lua/llvm-lua.cpp, llvm-lua/llvm-luac.cpp,\n\t  llvm-lua/llvm_compiler.cpp, llvm-lua/llvm_compiler.h,\n\t  llvm-lua/load_jit_proto.c, llvm-lua/load_vm_ops.cpp,\n\t  llvm-lua/load_vm_ops.h, llvm-lua/lua_compiler.c,\n\t  llvm-lua/lua_core.c, llvm-lua/lua_main.c, llvm-lua/lua_vm_ops.c,\n\t  llvm-lua/lua_vm_ops_module.cpp, llvm-lua/lua_vm_ops_module.h:\n\t  Added a new way to load the lua_vm_ops.bc by compiling it into\n\t  C++ LLVM API calls and embedding it into the llvm-lua & llvm-luac\n\t  programs.\n\t  Re-factored Lua bytecode to LLVM IR compiler code into two\n\t  classes LLVMCompiler & LLVMDumper.\n\t  Fixed some other bugs.\n\n2008-09-23  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* src/lcoco.c:\n\t  Mac OS X 64bit fix from Mike Pall\n\n2008-09-19  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* Makefile, doc/manual.html, doc/readme.html, etc/lua.pc,\n\t  src/lapi.c, src/loadlib.c, src/lobject.h, src/lstrlib.c,\n\t  src/lua.h:\n\t  Update to Official Lua-5.1.4\n\n2008-08-30  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* src/lcoco.c:\n\t  Changed from using %rbp & %rbx to %r12 & %r13 for wrap function.\n\t* llvm-lua/lua_vm_ops.c, src/lvm.c, src/lvm.h:\n\t  Fixed support for line/count debug hooks.\n\t* src/lcoco.c:\n\t  Added wrap function to set register %rdi (to lua_State *) on\n\t  first resume of a coroutine, instead of very resume/yield.\n\n2008-08-28  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/llvm-compiler.cpp:\n\t  Patch from \"Kay Ropke\" fixes bug with compiling on OS X with the\n\t  latest LLVM revision(55456).\n\n2008-08-27  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/llvm-compiler.cpp, llvm-lua/load_jit_proto.h:\n\t  fixed bug with boolean constants when static compiling Lua\n\t  scripts.\n\n2008-08-26  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/compile_all.sh:\n\t  add message\n\n2008-08-25  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* llvm-lua/Makefile, llvm-lua/compile.sh, llvm-lua/compile_all.sh,\n\t  llvm-lua/hook_parser.c, llvm-lua/llvm-compiler.cpp,\n\t  llvm-lua/lua_vm_ops.c:\n\t  Fixed bugs with calling non-JITed Lua functions.\n\t  Manually inline opcode functions instead of using the inliner\n\t  pass.\n\t  Code cleanup.\n\n2008-08-23  Robert G. Jakabosky <bobby@neoawareness.com>\n\n\t* src/lcoco.c:\n\t  fixed bug with assembly coco_switcher for x86_64.\n\t* src/Makefile, src/lcoco.c:\n\t  Added added assembly ctx_switcher for x86_64-linux to LuaCoco.\n\t* .svnignore, COPYRIGHT, HISTORY, INSTALL, Makefile, README,\n\t  README.llvm-lua, doc, doc/amazon.gif, doc/contents.html,\n\t  doc/cover.png, doc/logo.gif, doc/lua.1, doc/lua.css,\n\t  doc/lua.html, doc/luac.1, doc/luac.html, doc/manual.css,\n\t  doc/manual.html, doc/readme.html, etc, etc/Makefile, etc/README,\n\t  etc/all.c, etc/lua.hpp, etc/lua.ico, etc/lua.pc, etc/luavs.bat,\n\t  etc/min.c, etc/noparser.c, etc/strict.lua, llvm-lua,\n\t  llvm-lua/COPYRIGHT.llvm-lua, llvm-lua/Makefile,\n\t  llvm-lua/compile.sh, llvm-lua/hook_parser.c,\n\t  llvm-lua/llvm-compiler.cpp, llvm-lua/llvm-compiler.h,\n\t  llvm-lua/llvm-lua.cpp, llvm-lua/llvm-lua.h,\n\t  llvm-lua/llvm-luac.cpp, llvm-lua/llvm-luac.h,\n\t  llvm-lua/load_jit_proto.c, llvm-lua/load_jit_proto.h,\n\t  llvm-lua/lua_compiler.c, llvm-lua/lua_compiler.h,\n\t  llvm-lua/lua_core.c, llvm-lua/lua_core.h,\n\t  llvm-lua/lua_interpreter.c, llvm-lua/lua_interpreter.h,\n\t  llvm-lua/lua_main.c, llvm-lua/lua_normal.c,\n\t  llvm-lua/lua_vm_ops.c, llvm-lua/lua_vm_ops.h, src, src/Makefile,\n\t  src/lapi.c, src/lapi.h, src/lauxlib.c, src/lauxlib.h,\n\t  src/lbaselib.c, src/lcoco.c, src/lcoco.h, src/lcode.c,\n\t  src/lcode.h, src/ldblib.c, src/ldebug.c, src/ldebug.h, src/ldo.c,\n\t  src/ldo.h, src/ldump.c, src/lfunc.c, src/lfunc.h, src/lgc.c,\n\t  src/lgc.h, src/linit.c, src/liolib.c, src/llex.c, src/llex.h,\n\t  src/llimits.h, src/lmathlib.c, src/lmem.c, src/lmem.h,\n\t  src/loadlib.c, src/lobject.c, src/lobject.h, src/lopcodes.c,\n\t  src/lopcodes.h, src/loslib.c, src/lparser.c, src/lparser.h,\n\t  src/lstate.c, src/lstate.h, src/lstring.c, src/lstring.h,\n\t  src/lstrlib.c, src/ltable.c, src/ltable.h, src/ltablib.c,\n\t  src/ltm.c, src/ltm.h, src/lua.c, src/lua.h, src/luac.c,\n\t  src/luaconf.h, src/lualib.h, src/lundump.c, src/lundump.h,\n\t  src/lvm.c, src/lvm.h, src/lzio.c, src/lzio.h, src/print.c, test,\n\t  test/README, test/bisect.lua, test/cf.lua, test/echo.lua,\n\t  test/env.lua, test/factorial.lua, test/fib.lua, test/fibfor.lua,\n\t  test/globals.lua, test/hello.lua, test/life.lua, test/luac.lua,\n\t  test/printf.lua, test/readonly.lua, test/sieve.lua,\n\t  test/sort.lua, test/table.lua, test/trace-calls.lua,\n\t  test/trace-globals.lua, test/xd.lua:\n\t  Initial 0.1 release\n\n2008-08-23  \n\n\t* .:\n\t  Initial directory structure.\n\n"
  },
  {
    "path": "HISTORY",
    "content": "HISTORY for Lua 5.1\n\n* Changes from version 5.0 to 5.1\n  -------------------------------\n  Language:\n  + new module system.\n  + new semantics for control variables of fors.\n  + new semantics for setn/getn.\n  + new syntax/semantics for varargs.\n  + new long strings and comments.\n  + new `mod' operator (`%')\n  + new length operator #t\n  + metatables for all types\n  API:\n  + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer.\n  + user supplies memory allocator (lua_open becomes lua_newstate).\n  + luaopen_* functions must be called through Lua.\n  Implementation:\n  + new configuration scheme via luaconf.h.\n  + incremental garbage collection.\n  + better handling of end-of-line in the lexer.\n  + fully reentrant parser (new Lua function `load')\n  + better support for 64-bit machines.\n  + native loadlib support for Mac OS X.\n  + standard distribution in only one library (lualib.a merged into lua.a)\n\n* Changes from version 4.0 to 5.0\n  -------------------------------\n  Language:\n  + lexical scoping.\n  + Lua coroutines.\n  + standard libraries now packaged in tables.\n  + tags replaced by metatables and tag methods replaced by metamethods,\n    stored in metatables.\n  + proper tail calls.\n  + each function can have its own global table, which can be shared.\n  + new __newindex metamethod, called when we insert a new key into a table.\n  + new block comments: --[[ ... ]].\n  + new generic for.\n  + new weak tables.\n  + new boolean type.\n  + new syntax \"local function\".\n  + (f()) returns the first value returned by f.\n  + {f()} fills a table with all values returned by f.\n  + \\n ignored in [[\\n .\n  + fixed and-or priorities.\n  + more general syntax for function definition (e.g. function a.x.y:f()...end).\n  + more general syntax for function calls (e.g. (print or write)(9)).\n  + new functions (time/date, tmpfile, unpack, require, load*, etc.).\n  API:\n  + chunks are loaded by using lua_load; new luaL_loadfile and luaL_loadbuffer.\n  + introduced lightweight userdata, a simple \"void*\" without a metatable.\n  + new error handling protocol: the core no longer prints error messages;\n    all errors are reported to the caller on the stack.\n  + new lua_atpanic for host cleanup.\n  + new, signal-safe, hook scheme.\n  Implementation:\n  + new license: MIT.\n  + new, faster, register-based virtual machine.\n  + support for external multithreading and coroutines.\n  + new and consistent error message format.\n  + the core no longer needs \"stdio.h\" for anything (except for a single\n    use of sprintf to convert numbers to strings).\n  + lua.c now runs the environment variable LUA_INIT, if present. It can\n    be \"@filename\", to run a file, or the chunk itself.\n  + support for user extensions in lua.c.\n    sample implementation given for command line editing.\n  + new dynamic loading library, active by default on several platforms.\n  + safe garbage-collector metamethods.\n  + precompiled bytecodes checked for integrity (secure binary dostring).\n  + strings are fully aligned.\n  + position capture in string.find.\n  + read('*l') can read lines with embedded zeros.\n\n* Changes from version 3.2 to 4.0\n  -------------------------------\n  Language:\n  + new \"break\" and \"for\" statements (both numerical and for tables).\n  + uniform treatment of globals: globals are now stored in a Lua table.\n  + improved error messages.\n  + no more '$debug': full speed *and* full debug information.\n  + new read form: read(N) for next N bytes.\n  + general read patterns now deprecated.\n    (still available with -DCOMPAT_READPATTERNS.)\n  + all return values are passed as arguments for the last function\n    (old semantics still available with -DLUA_COMPAT_ARGRET)\n  + garbage collection tag methods for tables now deprecated.\n  + there is now only one tag method for order.\n  API:\n  + New API: fully re-entrant, simpler, and more efficient.\n  + New debug API.\n  Implementation:\n  + faster than ever: cleaner virtual machine and new hashing algorithm.\n  + non-recursive garbage-collector algorithm.\n  + reduced memory usage for programs with many strings.\n  + improved treatment for memory allocation errors.\n  + improved support for 16-bit machines (we hope).\n  + code now compiles unmodified as both ANSI C and C++.\n  + numbers in bases other than 10 are converted using strtoul.\n  + new -f option in Lua to support #! scripts.\n  + luac can now combine text and binaries.\n\n* Changes from version 3.1 to 3.2\n  -------------------------------\n  + redirected all output in Lua's core to _ERRORMESSAGE and _ALERT.\n  + increased limit on the number of constants and globals per function\n    (from 2^16 to 2^24).\n  + debugging info (lua_debug and hooks) moved into lua_state and new API\n    functions provided to get and set this info.\n  + new debug lib gives full debugging access within Lua.\n  + new table functions \"foreachi\", \"sort\", \"tinsert\", \"tremove\", \"getn\".\n  + new io functions \"flush\", \"seek\".\n\n* Changes from version 3.0 to 3.1\n  -------------------------------\n  + NEW FEATURE: anonymous functions with closures (via \"upvalues\").\n  + new syntax:\n    - local variables in chunks.\n    - better scope control with DO block END.\n    - constructors can now be also written: { record-part; list-part }.\n    - more general syntax for function calls and lvalues, e.g.:\n      f(x).y=1\n      o:f(x,y):g(z)\n      f\"string\" is sugar for f(\"string\")\n  + strings may now contain arbitrary binary data (e.g., embedded zeros).\n  + major code re-organization and clean-up; reduced module interdependecies.\n  + no arbitrary limits on the total number of constants and globals.\n  + support for multiple global contexts.\n  + better syntax error messages.\n  + new traversal functions \"foreach\" and \"foreachvar\".\n  + the default for numbers is now double.\n    changing it to use floats or longs is easy.\n  + complete debug information stored in pre-compiled chunks.\n  + sample interpreter now prompts user when run interactively, and also\n    handles control-C interruptions gracefully.\n\n* Changes from version 2.5 to 3.0\n  -------------------------------\n  + NEW CONCEPT: \"tag methods\".\n    Tag methods replace fallbacks as the meta-mechanism for extending the\n    semantics of Lua. Whereas fallbacks had a global nature, tag methods\n    work on objects having the same tag (e.g., groups of tables).\n    Existing code that uses fallbacks should work without change.\n  + new, general syntax for constructors {[exp] = exp, ... }.\n  + support for handling variable number of arguments in functions (varargs).\n  + support for conditional compilation ($if ... $else ... $end).\n  + cleaner semantics in API simplifies host code.\n  + better support for writing libraries (auxlib.h).\n  + better type checking and error messages in the standard library.\n  + luac can now also undump.\n\n* Changes from version 2.4 to 2.5\n  -------------------------------\n  + io and string libraries are now based on pattern matching;\n    the old libraries are still available for compatibility\n  + dofile and dostring can now return values (via return statement)\n  + better support for 16- and 64-bit machines\n  + expanded documentation, with more examples\n\n* Changes from version 2.2 to 2.4\n  -------------------------------\n  + external compiler creates portable binary files that can be loaded faster\n  + interface for debugging and profiling\n  + new \"getglobal\" fallback\n  + new functions for handling references to Lua objects\n  + new functions in standard lib\n  + only one copy of each string is stored\n  + expanded documentation, with more examples\n\n* Changes from version 2.1 to 2.2\n  -------------------------------\n  + functions now may be declared with any \"lvalue\" as a name\n  + garbage collection of functions\n  + support for pipes\n\n* Changes from version 1.1 to 2.1\n  -------------------------------\n  + object-oriented support\n  + fallbacks\n  + simplified syntax for tables\n  + many internal improvements\n\n(end of HISTORY)\n"
  },
  {
    "path": "INSTALL",
    "content": "INSTALL for Lua 5.1\n\n* Building Lua\n  ------------\n  Lua is built in the src directory, but the build process can be\n  controlled from the top-level Makefile.\n\n  Building Lua on Unix systems should be very easy. First do \"make\" and\n  see if your platform is listed. If so, just do \"make xxx\", where xxx\n  is your platform name. The platforms currently supported are:\n    aix ansi bsd freebsd generic linux macosx mingw posix solaris\n\n  If your platform is not listed, try the closest one or posix, generic,\n  ansi, in this order.\n\n  See below for customization instructions and for instructions on how\n  to build with other Windows compilers.\n\n  If you want to check that Lua has been built correctly, do \"make test\"\n  after building Lua. Also, have a look at the example programs in test.\n\n* Installing Lua\n  --------------\n  Once you have built Lua, you may want to install it in an official\n  place in your system. In this case, do \"make install\". The official\n  place and the way to install files are defined in Makefile. You must\n  have the right permissions to install files.\n\n  If you want to build and install Lua in one step, do \"make xxx install\",\n  where xxx is your platform name.\n\n  If you want to install Lua locally, then do \"make local\". This will\n  create directories bin, include, lib, man, and install Lua there as\n  follows:\n\n    bin:\tlua luac\n    include:\tlua.h luaconf.h lualib.h lauxlib.h lua.hpp\n    lib:\tliblua.a\n    man/man1:\tlua.1 luac.1\n\n  These are the only directories you need for development.\n\n  There are man pages for lua and luac, in both nroff and html, and a\n  reference manual in html in doc, some sample code in test, and some\n  useful stuff in etc. You don't need these directories for development.\n\n  If you want to install Lua locally, but in some other directory, do\n  \"make install INSTALL_TOP=xxx\", where xxx is your chosen directory.\n\n  See below for instructions for Windows and other systems.\n\n* Customization\n  -------------\n  Three things can be customized by editing a file:\n    - Where and how to install Lua -- edit Makefile.\n    - How to build Lua -- edit src/Makefile.\n    - Lua features -- edit src/luaconf.h.\n\n  You don't actually need to edit the Makefiles because you may set the\n  relevant variables when invoking make.\n\n  On the other hand, if you need to select some Lua features, you'll need\n  to edit src/luaconf.h. The edited file will be the one installed, and\n  it will be used by any Lua clients that you build, to ensure consistency.\n\n  We strongly recommend that you enable dynamic loading. This is done\n  automatically for all platforms listed above that have this feature\n  (and also Windows). See src/luaconf.h and also src/Makefile.\n\n* Building Lua on Windows and other systems\n  -----------------------------------------\n  If you're not using the usual Unix tools, then the instructions for\n  building Lua depend on the compiler you use. You'll need to create\n  projects (or whatever your compiler uses) for building the library,\n  the interpreter, and the compiler, as follows:\n\n  library:\tlapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c\n\t\tlmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c\n\t\tltable.c ltm.c lundump.c lvm.c lzio.c\n\t\tlauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c\n\t\tltablib.c lstrlib.c loadlib.c linit.c\n\n  interpreter:\tlibrary, lua.c\n\n  compiler:\tlibrary, luac.c print.c\n\n  If you use Visual Studio .NET, you can use etc/luavs.bat in its\n  \"Command Prompt\".\n\n  If all you want is to build the Lua interpreter, you may put all .c files\n  in a single project, except for luac.c and print.c. Or just use etc/all.c.\n\n  To use Lua as a library in your own programs, you'll need to know how to\n  create and use libraries with your compiler.\n\n  As mentioned above, you may edit luaconf.h to select some features before\n  building Lua.\n\n(end of INSTALL)\n"
  },
  {
    "path": "README",
    "content": "README for Lua 5.1\n\nSee INSTALL for installation instructions.\nSee HISTORY for a summary of changes since the last released version.\n\n* What is Lua?\n  ------------\n  Lua is a powerful, light-weight programming language designed for extending\n  applications. Lua is also frequently used as a general-purpose, stand-alone\n  language. Lua is free software.\n\n  For complete information, visit Lua's web site at http://www.lua.org/ .\n  For an executive summary, see http://www.lua.org/about.html .\n\n  Lua has been used in many different projects around the world.\n  For a short list, see http://www.lua.org/uses.html .\n\n* Availability\n  ------------\n  Lua is freely available for both academic and commercial purposes.\n  See COPYRIGHT and http://www.lua.org/license.html for details.\n  Lua can be downloaded at http://www.lua.org/download.html .\n\n* Installation\n  ------------\n  Lua is implemented in pure ANSI C, and compiles unmodified in all known\n  platforms that have an ANSI C compiler. In most Unix-like platforms, simply\n  do \"make\" with a suitable target. See INSTALL for detailed instructions.\n\n* Origin\n  ------\n  Lua is developed at Lua.org, a laboratory of the Department of Computer\n  Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro\n  in Brazil).\n  For more information about the authors, see http://www.lua.org/authors.html .\n\n(end of README)\n"
  },
  {
    "path": "README.llvm-lua",
    "content": "README for llvm-lua\n\n=== Requires ===\n * LLVM 2.8\n * Clang or llvm-gcc 4.2.x from llvm.org\n\n=== Compile ===\n * mkdir build\n * cd build\n for Release build:\n * cmake .. -DLLVM_PATH=<path to llvm+clan> -DCMAKE_BUILD_TYPE=Release\n for Debug build:\n * cmake .. -DLLVM_PATH=<path to llvm+clan> -DCMAKE_BUILD_TYPE=Debug\n * make\n\n=== Install ===\n * make install\n\n=== Patches to lua/src ===\n * Emergency Garbage Collector: http://lua-users.org/wiki/EmergencyGarbageCollector\n * LuaCoco-1.1.6: http://luajit.org/coco.html + (x86_64 support added)\n * a few hooks where added to support JIT compiled functions.\n\n=== Programs ===\n * llvm-lua: This command can be used to run Lua script.  It uses the LLVM backend to JIT Lua scripts to machine code for faster execution.\n * llvm-luac: This command compiles Lua scripts into LLVM bitcode.\n * lua-compiler: This is a bash script that wraps llvm-luac to compile Lua scripts into standalone executables or loadable modules.\n\n=== Libraries ===\n -- Lua core without LLVM JIT support, but compatible with compiled modules.  Can be used as drop-in replacements of the normal Lua libraries.\n * liblua_static.a & liblua.so\n\n -- Static library with LLVM JIT support requires static linking with LLVM libraries.\n * libllvm-lua_static.a & libllvm-lua.so\n\n -- Used for compling Lua scripts to standalone executables.\n * liblua_main.a\n\n=== Using llvm-lua ===\nThe JIT/interpreter command 'llvm-lua' can be used just like the normal 'lua'.  There are a lot of extra command line options that expose some options from LLVM, they are not required for normal use.  The JIT will compile Lua code with optimization level 3 by default.\n\n=== Static compiling Lua scripts ===\n'llvm-luac' alone can only compile Lua scripts to Lua bytecode or LLVM bitcode.  A wrapper script called 'lua-compiler' is provided that wraps 'llvm-luac', the LLVM tools (llc & opt), and gcc.\n\nCompile standalone Lua script:\nlua-compiler script.lua\noutputs: ./script\n\nCompile Lua script as a module:\nlua-compiler -lua-module script.lua\noutputs: ./script.so\n\n=== Embedding 'llvm-lua' with JIT support ===\nThe Lua C API is unchanged and no extra API functions are exposed by llvm-lua.  The only change is how host app. is linked with the 'liblua-llvm.a' library instead of the normal 'liblua.a' library.\n\nUse the following command to link your C app with llvm-lua:\ngcc -o embed.o -c etc/embed_jit.c\ng++ -o embed embed.o -lllvm-lua `llvm-config --ldflags --libs core jit native linker` -rdynamic -Wl,-E -lm -ldl\n\nUse the following command to link your C++ app with llvm-lua:\ng++ -o embed.o -c etc/embed_jit.cpp\ng++ -o embed embed.o -lllvm-lua `llvm-config --ldflags --libs core jit native linker` -rdynamic -Wl,-E -lm -ldl\n\n"
  },
  {
    "path": "TODO",
    "content": "-- TODO list\n\nmisc:\n* Port lua-compiler bash script to a Lua script.\n* handle coroutine c-stack alignment issues on x86_64 when compiling in DEBUG mode.\n* Add option to compile liblua_main.a without lua parser, lundump/ldump code.\n* Update to latest EGC patch.\n\nmodule naming issues:\n* change how the compiler names modules.\n* give the compiler a search path + module name \"A.B.C\" and have it compile A/B/C.lua into A/B/C.so\n* remove output file extension when nameing the module, instead of just the last three letters.\n\nlua-compiler script:\n* fix linking bug reported by DigitalKiwi:\n <DigitalKiwi> #CFLAGS=\" -ggdb -O3 -fomit-frame-pointer -pipe -Wall \"\n <DigitalKiwi> CFLAGS=\" -O3 -fomit-frame-pointer -pipe -Wl,-E \"\n <DigitalKiwi> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html\n\n"
  },
  {
    "path": "cmake/CustomMacros.cmake",
    "content": "\nmacro(add_llvm_bc_library _target)\n\tset(_llvm_cflags)\n\tget_property(_idirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)\n\tforeach(_idir ${_idirs})\n\t\tset(_llvm_cflags ${_llvm_cflags} -I${_idir})\n\tendforeach(_idir)\n\n\tif(${ARGC} GREATER 2)\n\t\tset(_bc_files)\n\t\tforeach(_file ${ARGN})\n\t\t\tset(_bc_file \"${CMAKE_CURRENT_BINARY_DIR}/${_file}.bc\")\n\t\t\tset(_bc_files ${_bc_files} ${_bc_file})\n\t\t\tadd_custom_command(OUTPUT ${_bc_file}\n\t\t\t\tCOMMAND ${LLVM_CC} ARGS ${BC_CFLAGS} ${_llvm_cflags} -o ${_bc_file} ${_file}\n\t\t\t\tWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}\n\t\t\t\tDEPENDS ${_file}\n\t\t\t)\n\t\tendforeach(_file)\n\t\tadd_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc\n\t\t\tCOMMAND ${LLVM_LD} ARGS -o ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc ${_bc_files}\n\t\t\tWORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}\n\t\t\tDEPENDS ${_bc_files}\n\t\t)\n\telse(${ARGC} GREATER 2)\n\t\tadd_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc\n\t\t\tCOMMAND ${LLVM_CC} ARGS ${BC_CFLAGS} ${_llvm_cflags} -o ${CMAKE_CURRENT_BINARY_DIR}/${_target}.bc ${ARGV1}\n\t\t\tWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}\n\t\t\tDEPENDS ${ARGV1}\n\t\t)\n\tendif(${ARGC} GREATER 2)\nendmacro(add_llvm_bc_library)\n\nmacro(add_target_properties _target _name)\n\tset(_properties)\n\tforeach(_prop ${ARGN})\n\t\tset(_properties \"${_properties} ${_prop}\")\n\tendforeach(_prop)\n\tget_target_property(_old_properties ${_target} ${_name})\n\tif(NOT _old_properties)\n\t\t# in case it's NOTFOUND\n\t\tset(_old_properties)\n\tendif(NOT _old_properties)\n\tset_target_properties(${_target} PROPERTIES ${_name} \"${_old_properties} ${_properties}\")\nendmacro(add_target_properties)\n\n"
  },
  {
    "path": "cmake/FindLLVM.cmake",
    "content": "# - Find libev\n# Find the native LLVM includes and library\n#\n#  LLVM_INCLUDE_DIR - where to find ev.h, etc.\n#  LLVM_LIBRARIES   - List of libraries when using libev.\n#  LLVM_FOUND       - True if libev found.\n\nfind_program(LLVM_CONFIG_EXECUTABLE NAMES \"${LLVM_PATH}/bin/llvm-config\" DOC \"llvm-config executable\")\n\nexecute_process(\n\tCOMMAND ${LLVM_CONFIG_EXECUTABLE} --cppflags\n\tOUTPUT_VARIABLE LLVM_CFLAGS\n\tOUTPUT_STRIP_TRAILING_WHITESPACE\n)\n\nexecute_process(\n\tCOMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags\n\tOUTPUT_VARIABLE LLVM_LFLAGS\n\tOUTPUT_STRIP_TRAILING_WHITESPACE\n)\nexecute_process(\n\tCOMMAND ${LLVM_CONFIG_EXECUTABLE} --libs core jit native linker bitreader bitwriter ipo\n\tOUTPUT_VARIABLE LLVM_JIT_LIBS\n\tOUTPUT_STRIP_TRAILING_WHITESPACE\n)\nexecute_process(\n\tCOMMAND ${LLVM_CONFIG_EXECUTABLE} --libs all\n\tOUTPUT_VARIABLE LLVM_ALL_LIBS\n\tOUTPUT_STRIP_TRAILING_WHITESPACE\n)\n\n"
  },
  {
    "path": "cmake_uninstall.cmake.in",
    "content": "IF(NOT EXISTS \"@CMAKE_BINARY_DIR@/install_manifest.txt\")\n  MESSAGE(FATAL_ERROR \"Cannot find install manifest: \\\"@CMAKE_BINARY_DIR@/install_manifest.txt\\\"\")\nENDIF(NOT EXISTS \"@CMAKE_BINARY_DIR@/install_manifest.txt\")\n\nFILE(READ \"@CMAKE_BINARY_DIR@/install_manifest.txt\" files)\nSTRING(REGEX REPLACE \"\\n\" \";\" files \"${files}\")\nFOREACH(file ${files})\n  MESSAGE(STATUS \"Uninstalling \\\"$ENV{DESTDIR}${file}\\\"\")\n  EXEC_PROGRAM(\n    \"@CMAKE_COMMAND@\" ARGS \"-E remove \\\"$ENV{DESTDIR}${file}\\\"\"\n    OUTPUT_VARIABLE rm_out\n    RETURN_VALUE rm_retval\n    )\n  IF(NOT \"${rm_retval}\" STREQUAL 0)\n    MESSAGE(FATAL_ERROR \"Problem when removing \\\"$ENV{DESTDIR}${file}\\\"\")\n  ENDIF(NOT \"${rm_retval}\" STREQUAL 0)\nENDFOREACH(file)\n\n"
  },
  {
    "path": "doc/contents.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Lua 5.1 Reference Manual - contents</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n<STYLE TYPE=\"text/css\">\nul {\n\tlist-style-type: none ;\n\tlist-style-position: outside ;\n}\n</STYLE>\n</HEAD>\n\n<BODY>\n\n<HR>\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"\" BORDER=0></A>\nLua 5.1 Reference Manual\n</H1>\n\nThis is an online version of\n<BLOCKQUOTE>\n<A HREF=\"http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20\">\n<IMG SRC=\"cover.png\" ALT=\"\" TITLE=\"buy from Amazon\" BORDER=1 ALIGN=\"left\" HSPACE=12>\n</A>\n<B>Lua 5.1 Reference Manual</B>\n<BR>by R. Ierusalimschy, L. H. de Figueiredo, W. Celes\n<BR>Lua.org, August 2006\n<BR>ISBN 85-903798-3-3\n<BR><A HREF=\"http://www.amazon.com/exec/obidos/ASIN/8590379833/lua-indexmanual-20\">\n<IMG SRC=\"amazon.gif\" ALT=\"[Buy from Amazon]\" BORDER=0></A>\n<BR CLEAR=\"all\">\n</BLOCKQUOTE>\n<P>\n\nBuy a copy of this book and \n<A HREF=\"http://www.lua.org/donations.html\">help to support</A>\nthe Lua project.\n<P>\n\nThe reference manual is the official definition of the Lua language.\nFor a complete introduction to Lua programming, see the book\n<A HREF=\"http://www.lua.org/docs.html#books\">Programming in Lua</A>.\n<P>\n\n<A HREF=\"manual.html\">start</A>\n&middot;\n<A HREF=\"#contents\">contents</A>\n&middot;\n<A HREF=\"#index\">index</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/5.1/pt/\">portugus</A>\n&middot;\n<A HREF=\"http://www.lua.org/manual/5.1/es/\">espaol</A>\n<HR>\n<SMALL>\nCopyright &copy; 2006-2008 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html#5\">Lua license</a>.\n</SMALL>\n<P>\n\n<H2><A NAME=\"contents\">Contents</A></H2>\n<UL style=\"padding: 0\">\n<LI><A HREF=\"manual.html\">1 - Introduction</A>\n<P>\n<LI><A HREF=\"manual.html#2\">2 - The Language</A>\n<UL>\n<LI><A HREF=\"manual.html#2.1\">2.1 - Lexical Conventions</A>\n<LI><A HREF=\"manual.html#2.2\">2.2 - Values and Types</A>\n<UL>\n<LI><A HREF=\"manual.html#2.2.1\">2.2.1 - Coercion</A>\n</UL>\n<LI><A HREF=\"manual.html#2.3\">2.3 - Variables</A>\n<LI><A HREF=\"manual.html#2.4\">2.4 - Statements</A>\n<UL>\n<LI><A HREF=\"manual.html#2.4.1\">2.4.1 - Chunks</A>\n<LI><A HREF=\"manual.html#2.4.2\">2.4.2 - Blocks</A>\n<LI><A HREF=\"manual.html#2.4.3\">2.4.3 - Assignment</A>\n<LI><A HREF=\"manual.html#2.4.4\">2.4.4 - Control Structures</A>\n<LI><A HREF=\"manual.html#2.4.5\">2.4.5 - For Statement</A>\n<LI><A HREF=\"manual.html#2.4.6\">2.4.6 - Function Calls as Statements</A>\n<LI><A HREF=\"manual.html#2.4.7\">2.4.7 - Local Declarations</A>\n</UL>\n<LI><A HREF=\"manual.html#2.5\">2.5 - Expressions</A>\n<UL>\n<LI><A HREF=\"manual.html#2.5.1\">2.5.1 - Arithmetic Operators</A>\n<LI><A HREF=\"manual.html#2.5.2\">2.5.2 - Relational Operators</A>\n<LI><A HREF=\"manual.html#2.5.3\">2.5.3 - Logical Operators</A>\n<LI><A HREF=\"manual.html#2.5.4\">2.5.4 - Concatenation</A>\n<LI><A HREF=\"manual.html#2.5.5\">2.5.5 - The Length Operator</A>\n<LI><A HREF=\"manual.html#2.5.6\">2.5.6 - Precedence</A>\n<LI><A HREF=\"manual.html#2.5.7\">2.5.7 - Table Constructors</A>\n<LI><A HREF=\"manual.html#2.5.8\">2.5.8 - Function Calls</A>\n<LI><A HREF=\"manual.html#2.5.9\">2.5.9 - Function Definitions</A>\n</UL>\n<LI><A HREF=\"manual.html#2.6\">2.6 - Visibility Rules</A>\n<LI><A HREF=\"manual.html#2.7\">2.7 - Error Handling</A>\n<LI><A HREF=\"manual.html#2.8\">2.8 - Metatables</A>\n<LI><A HREF=\"manual.html#2.9\">2.9 - Environments</A>\n<LI><A HREF=\"manual.html#2.10\">2.10 - Garbage Collection</A>\n<UL>\n<LI><A HREF=\"manual.html#2.10.1\">2.10.1 - Garbage-Collection Metamethods</A>\n<LI><A HREF=\"manual.html#2.10.2\">2.10.2 - Weak Tables</A>\n</UL>\n<LI><A HREF=\"manual.html#2.11\">2.11 - Coroutines</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#3\">3 - The Application Program Interface</A>\n<UL>\n<LI><A HREF=\"manual.html#3.1\">3.1 - The Stack</A>\n<LI><A HREF=\"manual.html#3.2\">3.2 - Stack Size</A>\n<LI><A HREF=\"manual.html#3.3\">3.3 - Pseudo-Indices</A>\n<LI><A HREF=\"manual.html#3.4\">3.4 - C Closures</A>\n<LI><A HREF=\"manual.html#3.5\">3.5 - Registry</A>\n<LI><A HREF=\"manual.html#3.6\">3.6 - Error Handling in C</A>\n<LI><A HREF=\"manual.html#3.7\">3.7 - Functions and Types</A>\n<LI><A HREF=\"manual.html#3.8\">3.8 - The Debug Interface</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#4\">4 - The Auxiliary Library</A>\n<UL>\n<LI><A HREF=\"manual.html#4.1\">4.1 - Functions and Types</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#5\">5 - Standard Libraries</A>\n<UL>\n<LI><A HREF=\"manual.html#5.1\">5.1 - Basic Functions</A>\n<LI><A HREF=\"manual.html#5.2\">5.2 - Coroutine Manipulation</A>\n<LI><A HREF=\"manual.html#5.3\">5.3 - Modules</A>\n<LI><A HREF=\"manual.html#5.4\">5.4 - String Manipulation</A>\n<UL>\n<LI><A HREF=\"manual.html#5.4.1\">5.4.1 - Patterns</A>\n</UL>\n<LI><A HREF=\"manual.html#5.5\">5.5 - Table Manipulation</A>\n<LI><A HREF=\"manual.html#5.6\">5.6 - Mathematical Functions</A>\n<LI><A HREF=\"manual.html#5.7\">5.7 - Input and Output Facilities</A>\n<LI><A HREF=\"manual.html#5.8\">5.8 - Operating System Facilities</A>\n<LI><A HREF=\"manual.html#5.9\">5.9 - The Debug Library</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#6\">6 - Lua Stand-alone</A>\n<P>\n<LI><A HREF=\"manual.html#7\">7 - Incompatibilities with the Previous Version</A>\n<UL>\n<LI><A HREF=\"manual.html#7.1\">7.1 - Changes in the Language</A>\n<LI><A HREF=\"manual.html#7.2\">7.2 - Changes in the Libraries</A>\n<LI><A HREF=\"manual.html#7.3\">7.3 - Changes in the API</A>\n</UL>\n<P>\n<LI><A HREF=\"manual.html#8\">8 - The Complete Syntax of Lua</A>\n</UL>\n\n<H2><A NAME=\"index\">Index</A></H2>\n<TABLE WIDTH=\"100%\">\n<TR VALIGN=\"top\">\n<TD>\n<H3><A NAME=\"functions\">Lua functions</A></H3>\n<A HREF=\"manual.html#pdf-_G\">_G</A><BR>\n<A HREF=\"manual.html#pdf-_VERSION\">_VERSION</A><BR>\n<A HREF=\"manual.html#pdf-assert\">assert</A><BR>\n<A HREF=\"manual.html#pdf-collectgarbage\">collectgarbage</A><BR>\n<A HREF=\"manual.html#pdf-dofile\">dofile</A><BR>\n<A HREF=\"manual.html#pdf-error\">error</A><BR>\n<A HREF=\"manual.html#pdf-getfenv\">getfenv</A><BR>\n<A HREF=\"manual.html#pdf-getmetatable\">getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-ipairs\">ipairs</A><BR>\n<A HREF=\"manual.html#pdf-load\">load</A><BR>\n<A HREF=\"manual.html#pdf-loadfile\">loadfile</A><BR>\n<A HREF=\"manual.html#pdf-loadstring\">loadstring</A><BR>\n<A HREF=\"manual.html#pdf-module\">module</A><BR>\n<A HREF=\"manual.html#pdf-next\">next</A><BR>\n<A HREF=\"manual.html#pdf-pairs\">pairs</A><BR>\n<A HREF=\"manual.html#pdf-pcall\">pcall</A><BR>\n<A HREF=\"manual.html#pdf-print\">print</A><BR>\n<A HREF=\"manual.html#pdf-rawequal\">rawequal</A><BR>\n<A HREF=\"manual.html#pdf-rawget\">rawget</A><BR>\n<A HREF=\"manual.html#pdf-rawset\">rawset</A><BR>\n<A HREF=\"manual.html#pdf-require\">require</A><BR>\n<A HREF=\"manual.html#pdf-select\">select</A><BR>\n<A HREF=\"manual.html#pdf-setfenv\">setfenv</A><BR>\n<A HREF=\"manual.html#pdf-setmetatable\">setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-tonumber\">tonumber</A><BR>\n<A HREF=\"manual.html#pdf-tostring\">tostring</A><BR>\n<A HREF=\"manual.html#pdf-type\">type</A><BR>\n<A HREF=\"manual.html#pdf-unpack\">unpack</A><BR>\n<A HREF=\"manual.html#pdf-xpcall\">xpcall</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-coroutine.create\">coroutine.create</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.resume\">coroutine.resume</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.running\">coroutine.running</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.status\">coroutine.status</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.wrap\">coroutine.wrap</A><BR>\n<A HREF=\"manual.html#pdf-coroutine.yield\">coroutine.yield</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-debug.debug\">debug.debug</A><BR>\n<A HREF=\"manual.html#pdf-debug.getfenv\">debug.getfenv</A><BR>\n<A HREF=\"manual.html#pdf-debug.gethook\">debug.gethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.getinfo\">debug.getinfo</A><BR>\n<A HREF=\"manual.html#pdf-debug.getlocal\">debug.getlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.getmetatable\">debug.getmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.getregistry\">debug.getregistry</A><BR>\n<A HREF=\"manual.html#pdf-debug.getupvalue\">debug.getupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.setfenv\">debug.setfenv</A><BR>\n<A HREF=\"manual.html#pdf-debug.sethook\">debug.sethook</A><BR>\n<A HREF=\"manual.html#pdf-debug.setlocal\">debug.setlocal</A><BR>\n<A HREF=\"manual.html#pdf-debug.setmetatable\">debug.setmetatable</A><BR>\n<A HREF=\"manual.html#pdf-debug.setupvalue\">debug.setupvalue</A><BR>\n<A HREF=\"manual.html#pdf-debug.traceback\">debug.traceback</A><BR>\n\n</TD>\n<TD>\n<H3>&nbsp;</H3>\n<A HREF=\"manual.html#pdf-file:close\">file:close</A><BR>\n<A HREF=\"manual.html#pdf-file:flush\">file:flush</A><BR>\n<A HREF=\"manual.html#pdf-file:lines\">file:lines</A><BR>\n<A HREF=\"manual.html#pdf-file:read\">file:read</A><BR>\n<A HREF=\"manual.html#pdf-file:seek\">file:seek</A><BR>\n<A HREF=\"manual.html#pdf-file:setvbuf\">file:setvbuf</A><BR>\n<A HREF=\"manual.html#pdf-file:write\">file:write</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-io.close\">io.close</A><BR>\n<A HREF=\"manual.html#pdf-io.flush\">io.flush</A><BR>\n<A HREF=\"manual.html#pdf-io.input\">io.input</A><BR>\n<A HREF=\"manual.html#pdf-io.lines\">io.lines</A><BR>\n<A HREF=\"manual.html#pdf-io.open\">io.open</A><BR>\n<A HREF=\"manual.html#pdf-io.output\">io.output</A><BR>\n<A HREF=\"manual.html#pdf-io.popen\">io.popen</A><BR>\n<A HREF=\"manual.html#pdf-io.read\">io.read</A><BR>\n<A HREF=\"manual.html#pdf-io.stderr\">io.stderr</A><BR>\n<A HREF=\"manual.html#pdf-io.stdin\">io.stdin</A><BR>\n<A HREF=\"manual.html#pdf-io.stdout\">io.stdout</A><BR>\n<A HREF=\"manual.html#pdf-io.tmpfile\">io.tmpfile</A><BR>\n<A HREF=\"manual.html#pdf-io.type\">io.type</A><BR>\n<A HREF=\"manual.html#pdf-io.write\">io.write</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-math.abs\">math.abs</A><BR>\n<A HREF=\"manual.html#pdf-math.acos\">math.acos</A><BR>\n<A HREF=\"manual.html#pdf-math.asin\">math.asin</A><BR>\n<A HREF=\"manual.html#pdf-math.atan\">math.atan</A><BR>\n<A HREF=\"manual.html#pdf-math.atan2\">math.atan2</A><BR>\n<A HREF=\"manual.html#pdf-math.ceil\">math.ceil</A><BR>\n<A HREF=\"manual.html#pdf-math.cos\">math.cos</A><BR>\n<A HREF=\"manual.html#pdf-math.cosh\">math.cosh</A><BR>\n<A HREF=\"manual.html#pdf-math.deg\">math.deg</A><BR>\n<A HREF=\"manual.html#pdf-math.exp\">math.exp</A><BR>\n<A HREF=\"manual.html#pdf-math.floor\">math.floor</A><BR>\n<A HREF=\"manual.html#pdf-math.fmod\">math.fmod</A><BR>\n<A HREF=\"manual.html#pdf-math.frexp\">math.frexp</A><BR>\n<A HREF=\"manual.html#pdf-math.huge\">math.huge</A><BR>\n<A HREF=\"manual.html#pdf-math.ldexp\">math.ldexp</A><BR>\n<A HREF=\"manual.html#pdf-math.log\">math.log</A><BR>\n<A HREF=\"manual.html#pdf-math.log10\">math.log10</A><BR>\n<A HREF=\"manual.html#pdf-math.max\">math.max</A><BR>\n<A HREF=\"manual.html#pdf-math.min\">math.min</A><BR>\n<A HREF=\"manual.html#pdf-math.modf\">math.modf</A><BR>\n<A HREF=\"manual.html#pdf-math.pi\">math.pi</A><BR>\n<A HREF=\"manual.html#pdf-math.pow\">math.pow</A><BR>\n<A HREF=\"manual.html#pdf-math.rad\">math.rad</A><BR>\n<A HREF=\"manual.html#pdf-math.random\">math.random</A><BR>\n<A HREF=\"manual.html#pdf-math.randomseed\">math.randomseed</A><BR>\n<A HREF=\"manual.html#pdf-math.sin\">math.sin</A><BR>\n<A HREF=\"manual.html#pdf-math.sinh\">math.sinh</A><BR>\n<A HREF=\"manual.html#pdf-math.sqrt\">math.sqrt</A><BR>\n<A HREF=\"manual.html#pdf-math.tan\">math.tan</A><BR>\n<A HREF=\"manual.html#pdf-math.tanh\">math.tanh</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-os.clock\">os.clock</A><BR>\n<A HREF=\"manual.html#pdf-os.date\">os.date</A><BR>\n<A HREF=\"manual.html#pdf-os.difftime\">os.difftime</A><BR>\n<A HREF=\"manual.html#pdf-os.execute\">os.execute</A><BR>\n<A HREF=\"manual.html#pdf-os.exit\">os.exit</A><BR>\n<A HREF=\"manual.html#pdf-os.getenv\">os.getenv</A><BR>\n<A HREF=\"manual.html#pdf-os.remove\">os.remove</A><BR>\n<A HREF=\"manual.html#pdf-os.rename\">os.rename</A><BR>\n<A HREF=\"manual.html#pdf-os.setlocale\">os.setlocale</A><BR>\n<A HREF=\"manual.html#pdf-os.time\">os.time</A><BR>\n<A HREF=\"manual.html#pdf-os.tmpname\">os.tmpname</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-package.cpath\">package.cpath</A><BR>\n<A HREF=\"manual.html#pdf-package.loaded\">package.loaded</A><BR>\n<A HREF=\"manual.html#pdf-package.loaders\">package.loaders</A><BR>\n<A HREF=\"manual.html#pdf-package.loadlib\">package.loadlib</A><BR>\n<A HREF=\"manual.html#pdf-package.path\">package.path</A><BR>\n<A HREF=\"manual.html#pdf-package.preload\">package.preload</A><BR>\n<A HREF=\"manual.html#pdf-package.seeall\">package.seeall</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-string.byte\">string.byte</A><BR>\n<A HREF=\"manual.html#pdf-string.char\">string.char</A><BR>\n<A HREF=\"manual.html#pdf-string.dump\">string.dump</A><BR>\n<A HREF=\"manual.html#pdf-string.find\">string.find</A><BR>\n<A HREF=\"manual.html#pdf-string.format\">string.format</A><BR>\n<A HREF=\"manual.html#pdf-string.gmatch\">string.gmatch</A><BR>\n<A HREF=\"manual.html#pdf-string.gsub\">string.gsub</A><BR>\n<A HREF=\"manual.html#pdf-string.len\">string.len</A><BR>\n<A HREF=\"manual.html#pdf-string.lower\">string.lower</A><BR>\n<A HREF=\"manual.html#pdf-string.match\">string.match</A><BR>\n<A HREF=\"manual.html#pdf-string.rep\">string.rep</A><BR>\n<A HREF=\"manual.html#pdf-string.reverse\">string.reverse</A><BR>\n<A HREF=\"manual.html#pdf-string.sub\">string.sub</A><BR>\n<A HREF=\"manual.html#pdf-string.upper\">string.upper</A><BR>\n<P>\n\n<A HREF=\"manual.html#pdf-table.concat\">table.concat</A><BR>\n<A HREF=\"manual.html#pdf-table.insert\">table.insert</A><BR>\n<A HREF=\"manual.html#pdf-table.maxn\">table.maxn</A><BR>\n<A HREF=\"manual.html#pdf-table.remove\">table.remove</A><BR>\n<A HREF=\"manual.html#pdf-table.sort\">table.sort</A><BR>\n\n</TD>\n<TD>\n<H3>C API</H3>\n<A HREF=\"manual.html#lua_Alloc\">lua_Alloc</A><BR>\n<A HREF=\"manual.html#lua_CFunction\">lua_CFunction</A><BR>\n<A HREF=\"manual.html#lua_Debug\">lua_Debug</A><BR>\n<A HREF=\"manual.html#lua_Hook\">lua_Hook</A><BR>\n<A HREF=\"manual.html#lua_Integer\">lua_Integer</A><BR>\n<A HREF=\"manual.html#lua_Number\">lua_Number</A><BR>\n<A HREF=\"manual.html#lua_Reader\">lua_Reader</A><BR>\n<A HREF=\"manual.html#lua_State\">lua_State</A><BR>\n<A HREF=\"manual.html#lua_Writer\">lua_Writer</A><BR>\n<P>\n\n<A HREF=\"manual.html#lua_atpanic\">lua_atpanic</A><BR>\n<A HREF=\"manual.html#lua_call\">lua_call</A><BR>\n<A HREF=\"manual.html#lua_checkstack\">lua_checkstack</A><BR>\n<A HREF=\"manual.html#lua_close\">lua_close</A><BR>\n<A HREF=\"manual.html#lua_concat\">lua_concat</A><BR>\n<A HREF=\"manual.html#lua_cpcall\">lua_cpcall</A><BR>\n<A HREF=\"manual.html#lua_createtable\">lua_createtable</A><BR>\n<A HREF=\"manual.html#lua_dump\">lua_dump</A><BR>\n<A HREF=\"manual.html#lua_equal\">lua_equal</A><BR>\n<A HREF=\"manual.html#lua_error\">lua_error</A><BR>\n<A HREF=\"manual.html#lua_gc\">lua_gc</A><BR>\n<A HREF=\"manual.html#lua_getallocf\">lua_getallocf</A><BR>\n<A HREF=\"manual.html#lua_getfenv\">lua_getfenv</A><BR>\n<A HREF=\"manual.html#lua_getfield\">lua_getfield</A><BR>\n<A HREF=\"manual.html#lua_getglobal\">lua_getglobal</A><BR>\n<A HREF=\"manual.html#lua_gethook\">lua_gethook</A><BR>\n<A HREF=\"manual.html#lua_gethookcount\">lua_gethookcount</A><BR>\n<A HREF=\"manual.html#lua_gethookmask\">lua_gethookmask</A><BR>\n<A HREF=\"manual.html#lua_getinfo\">lua_getinfo</A><BR>\n<A HREF=\"manual.html#lua_getlocal\">lua_getlocal</A><BR>\n<A HREF=\"manual.html#lua_getmetatable\">lua_getmetatable</A><BR>\n<A HREF=\"manual.html#lua_getstack\">lua_getstack</A><BR>\n<A HREF=\"manual.html#lua_gettable\">lua_gettable</A><BR>\n<A HREF=\"manual.html#lua_gettop\">lua_gettop</A><BR>\n<A HREF=\"manual.html#lua_getupvalue\">lua_getupvalue</A><BR>\n<A HREF=\"manual.html#lua_insert\">lua_insert</A><BR>\n<A HREF=\"manual.html#lua_isboolean\">lua_isboolean</A><BR>\n<A HREF=\"manual.html#lua_iscfunction\">lua_iscfunction</A><BR>\n<A HREF=\"manual.html#lua_isfunction\">lua_isfunction</A><BR>\n<A HREF=\"manual.html#lua_islightuserdata\">lua_islightuserdata</A><BR>\n<A HREF=\"manual.html#lua_isnil\">lua_isnil</A><BR>\n<A HREF=\"manual.html#lua_isnone\">lua_isnone</A><BR>\n<A HREF=\"manual.html#lua_isnoneornil\">lua_isnoneornil</A><BR>\n<A HREF=\"manual.html#lua_isnumber\">lua_isnumber</A><BR>\n<A HREF=\"manual.html#lua_isstring\">lua_isstring</A><BR>\n<A HREF=\"manual.html#lua_istable\">lua_istable</A><BR>\n<A HREF=\"manual.html#lua_isthread\">lua_isthread</A><BR>\n<A HREF=\"manual.html#lua_isuserdata\">lua_isuserdata</A><BR>\n<A HREF=\"manual.html#lua_lessthan\">lua_lessthan</A><BR>\n<A HREF=\"manual.html#lua_load\">lua_load</A><BR>\n<A HREF=\"manual.html#lua_newstate\">lua_newstate</A><BR>\n<A HREF=\"manual.html#lua_newtable\">lua_newtable</A><BR>\n<A HREF=\"manual.html#lua_newthread\">lua_newthread</A><BR>\n<A HREF=\"manual.html#lua_newuserdata\">lua_newuserdata</A><BR>\n<A HREF=\"manual.html#lua_next\">lua_next</A><BR>\n<A HREF=\"manual.html#lua_objlen\">lua_objlen</A><BR>\n<A HREF=\"manual.html#lua_pcall\">lua_pcall</A><BR>\n<A HREF=\"manual.html#lua_pop\">lua_pop</A><BR>\n<A HREF=\"manual.html#lua_pushboolean\">lua_pushboolean</A><BR>\n<A HREF=\"manual.html#lua_pushcclosure\">lua_pushcclosure</A><BR>\n<A HREF=\"manual.html#lua_pushcfunction\">lua_pushcfunction</A><BR>\n<A HREF=\"manual.html#lua_pushfstring\">lua_pushfstring</A><BR>\n<A HREF=\"manual.html#lua_pushinteger\">lua_pushinteger</A><BR>\n<A HREF=\"manual.html#lua_pushlightuserdata\">lua_pushlightuserdata</A><BR>\n<A HREF=\"manual.html#lua_pushliteral\">lua_pushliteral</A><BR>\n<A HREF=\"manual.html#lua_pushlstring\">lua_pushlstring</A><BR>\n<A HREF=\"manual.html#lua_pushnil\">lua_pushnil</A><BR>\n<A HREF=\"manual.html#lua_pushnumber\">lua_pushnumber</A><BR>\n<A HREF=\"manual.html#lua_pushstring\">lua_pushstring</A><BR>\n<A HREF=\"manual.html#lua_pushthread\">lua_pushthread</A><BR>\n<A HREF=\"manual.html#lua_pushvalue\">lua_pushvalue</A><BR>\n<A HREF=\"manual.html#lua_pushvfstring\">lua_pushvfstring</A><BR>\n<A HREF=\"manual.html#lua_rawequal\">lua_rawequal</A><BR>\n<A HREF=\"manual.html#lua_rawget\">lua_rawget</A><BR>\n<A HREF=\"manual.html#lua_rawgeti\">lua_rawgeti</A><BR>\n<A HREF=\"manual.html#lua_rawset\">lua_rawset</A><BR>\n<A HREF=\"manual.html#lua_rawseti\">lua_rawseti</A><BR>\n<A HREF=\"manual.html#lua_register\">lua_register</A><BR>\n<A HREF=\"manual.html#lua_remove\">lua_remove</A><BR>\n<A HREF=\"manual.html#lua_replace\">lua_replace</A><BR>\n<A HREF=\"manual.html#lua_resume\">lua_resume</A><BR>\n<A HREF=\"manual.html#lua_setallocf\">lua_setallocf</A><BR>\n<A HREF=\"manual.html#lua_setfenv\">lua_setfenv</A><BR>\n<A HREF=\"manual.html#lua_setfield\">lua_setfield</A><BR>\n<A HREF=\"manual.html#lua_setglobal\">lua_setglobal</A><BR>\n<A HREF=\"manual.html#lua_sethook\">lua_sethook</A><BR>\n<A HREF=\"manual.html#lua_setlocal\">lua_setlocal</A><BR>\n<A HREF=\"manual.html#lua_setmetatable\">lua_setmetatable</A><BR>\n<A HREF=\"manual.html#lua_settable\">lua_settable</A><BR>\n<A HREF=\"manual.html#lua_settop\">lua_settop</A><BR>\n<A HREF=\"manual.html#lua_setupvalue\">lua_setupvalue</A><BR>\n<A HREF=\"manual.html#lua_status\">lua_status</A><BR>\n<A HREF=\"manual.html#lua_toboolean\">lua_toboolean</A><BR>\n<A HREF=\"manual.html#lua_tocfunction\">lua_tocfunction</A><BR>\n<A HREF=\"manual.html#lua_tointeger\">lua_tointeger</A><BR>\n<A HREF=\"manual.html#lua_tolstring\">lua_tolstring</A><BR>\n<A HREF=\"manual.html#lua_tonumber\">lua_tonumber</A><BR>\n<A HREF=\"manual.html#lua_topointer\">lua_topointer</A><BR>\n<A HREF=\"manual.html#lua_tostring\">lua_tostring</A><BR>\n<A HREF=\"manual.html#lua_tothread\">lua_tothread</A><BR>\n<A HREF=\"manual.html#lua_touserdata\">lua_touserdata</A><BR>\n<A HREF=\"manual.html#lua_type\">lua_type</A><BR>\n<A HREF=\"manual.html#lua_typename\">lua_typename</A><BR>\n<A HREF=\"manual.html#lua_upvalueindex\">lua_upvalueindex</A><BR>\n<A HREF=\"manual.html#lua_xmove\">lua_xmove</A><BR>\n<A HREF=\"manual.html#lua_yield\">lua_yield</A><BR>\n\n</TD>\n<TD>\n<H3>auxiliary library</H3>\n<A HREF=\"manual.html#luaL_Buffer\">luaL_Buffer</A><BR>\n<A HREF=\"manual.html#luaL_Reg\">luaL_Reg</A><BR>\n<P>\n\n<A HREF=\"manual.html#luaL_addchar\">luaL_addchar</A><BR>\n<A HREF=\"manual.html#luaL_addlstring\">luaL_addlstring</A><BR>\n<A HREF=\"manual.html#luaL_addsize\">luaL_addsize</A><BR>\n<A HREF=\"manual.html#luaL_addstring\">luaL_addstring</A><BR>\n<A HREF=\"manual.html#luaL_addvalue\">luaL_addvalue</A><BR>\n<A HREF=\"manual.html#luaL_argcheck\">luaL_argcheck</A><BR>\n<A HREF=\"manual.html#luaL_argerror\">luaL_argerror</A><BR>\n<A HREF=\"manual.html#luaL_buffinit\">luaL_buffinit</A><BR>\n<A HREF=\"manual.html#luaL_callmeta\">luaL_callmeta</A><BR>\n<A HREF=\"manual.html#luaL_checkany\">luaL_checkany</A><BR>\n<A HREF=\"manual.html#luaL_checkint\">luaL_checkint</A><BR>\n<A HREF=\"manual.html#luaL_checkinteger\">luaL_checkinteger</A><BR>\n<A HREF=\"manual.html#luaL_checklong\">luaL_checklong</A><BR>\n<A HREF=\"manual.html#luaL_checklstring\">luaL_checklstring</A><BR>\n<A HREF=\"manual.html#luaL_checknumber\">luaL_checknumber</A><BR>\n<A HREF=\"manual.html#luaL_checkoption\">luaL_checkoption</A><BR>\n<A HREF=\"manual.html#luaL_checkstack\">luaL_checkstack</A><BR>\n<A HREF=\"manual.html#luaL_checkstring\">luaL_checkstring</A><BR>\n<A HREF=\"manual.html#luaL_checktype\">luaL_checktype</A><BR>\n<A HREF=\"manual.html#luaL_checkudata\">luaL_checkudata</A><BR>\n<A HREF=\"manual.html#luaL_dofile\">luaL_dofile</A><BR>\n<A HREF=\"manual.html#luaL_dostring\">luaL_dostring</A><BR>\n<A HREF=\"manual.html#luaL_error\">luaL_error</A><BR>\n<A HREF=\"manual.html#luaL_getmetafield\">luaL_getmetafield</A><BR>\n<A HREF=\"manual.html#luaL_getmetatable\">luaL_getmetatable</A><BR>\n<A HREF=\"manual.html#luaL_gsub\">luaL_gsub</A><BR>\n<A HREF=\"manual.html#luaL_loadbuffer\">luaL_loadbuffer</A><BR>\n<A HREF=\"manual.html#luaL_loadfile\">luaL_loadfile</A><BR>\n<A HREF=\"manual.html#luaL_loadstring\">luaL_loadstring</A><BR>\n<A HREF=\"manual.html#luaL_newmetatable\">luaL_newmetatable</A><BR>\n<A HREF=\"manual.html#luaL_newstate\">luaL_newstate</A><BR>\n<A HREF=\"manual.html#luaL_openlibs\">luaL_openlibs</A><BR>\n<A HREF=\"manual.html#luaL_optint\">luaL_optint</A><BR>\n<A HREF=\"manual.html#luaL_optinteger\">luaL_optinteger</A><BR>\n<A HREF=\"manual.html#luaL_optlong\">luaL_optlong</A><BR>\n<A HREF=\"manual.html#luaL_optlstring\">luaL_optlstring</A><BR>\n<A HREF=\"manual.html#luaL_optnumber\">luaL_optnumber</A><BR>\n<A HREF=\"manual.html#luaL_optstring\">luaL_optstring</A><BR>\n<A HREF=\"manual.html#luaL_prepbuffer\">luaL_prepbuffer</A><BR>\n<A HREF=\"manual.html#luaL_pushresult\">luaL_pushresult</A><BR>\n<A HREF=\"manual.html#luaL_ref\">luaL_ref</A><BR>\n<A HREF=\"manual.html#luaL_register\">luaL_register</A><BR>\n<A HREF=\"manual.html#luaL_typename\">luaL_typename</A><BR>\n<A HREF=\"manual.html#luaL_typerror\">luaL_typerror</A><BR>\n<A HREF=\"manual.html#luaL_unref\">luaL_unref</A><BR>\n<A HREF=\"manual.html#luaL_where\">luaL_where</A><BR>\n\n</TD>\n</TR>\n</TABLE>\n<P>\n\n<HR>\n<SMALL>\nLast update:\nSat Jan 19 13:24:29 BRST 2008\n</SMALL>\n<!--\nLast change: revised for Lua 5.1.3\n-->\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "doc/lua.1",
    "content": ".\\\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $\n.TH LUA 1 \"$Date: 2006/01/06 16:03:34 $\"\n.SH NAME\nlua \\- Lua interpreter\n.SH SYNOPSIS\n.B lua\n[\n.I options\n]\n[\n.I script\n[\n.I args\n]\n]\n.SH DESCRIPTION\n.B lua\nis the stand-alone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n.BR luac ,\nthe Lua compiler.)\n.B lua\ncan be used as a batch interpreter and also interactively.\n.LP\nThe given\n.I options\n(see below)\nare executed and then\nthe Lua program in file\n.I script\nis loaded and executed.\nThe given\n.I args\nare available to\n.I script\nas strings in a global table named\n.BR arg .\nIf these arguments contain spaces or other characters special to the shell,\nthen they should be quoted\n(but note that the quotes will be removed by the shell).\nThe arguments in\n.B arg\nstart at 0,\nwhich contains the string\n.RI ' script '.\nThe index of the last argument is stored in\n.BR arg.n .\nThe arguments given in the command line before\n.IR script ,\nincluding the name of the interpreter,\nare available in negative indices in\n.BR arg .\n.LP\nAt the very start,\nbefore even handling the command line,\n.B lua\nexecutes the contents of the environment variable\n.BR LUA_INIT ,\nif it is defined.\nIf the value of\n.B LUA_INIT\nis of the form\n.RI '@ filename ',\nthen\n.I filename\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n.LP\nOptions start with\n.B '\\-'\nand are described below.\nYou can use\n.B \"'\\--'\"\nto signal the end of options.\n.LP\nIf no arguments are given,\nthen\n.B \"\\-v \\-i\"\nis assumed when the standard input is a terminal;\notherwise,\n.B \"\\-\"\nis assumed.\n.LP\nIn interactive mode,\n.B lua\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\nSo, one way to interrupt the reading of an incomplete statement is\nto force a syntax error:\nadding a\n.B ';' \nin the middle of a statement is a sure way of forcing a syntax error\n(except inside multiline strings and comments; these must be closed explicitly).\nIf a line starts with\n.BR '=' ,\nthen\n.B lua\ndisplays the values of all the expressions in the remainder of the\nline. The expressions must be separated by commas.\nThe primary prompt is the value of the global variable\n.BR _PROMPT ,\nif this value is a string;\notherwise, the default prompt is used.\nSimilarly, the secondary prompt is the value of the global variable\n.BR _PROMPT2 .\nSo,\nto change the prompts,\nset the corresponding variable to a string of your choice.\nYou can do that after calling the interpreter\nor on the command line\n(but in this case you have to be careful with quotes\nif the prompt string contains a space; otherwise you may confuse the shell.)\nThe default prompts are \"> \" and \">> \".\n.SH OPTIONS\n.TP\n.B \\-\nload and execute the standard input as a file,\nthat is,\nnot interactively,\neven when the standard input is a terminal.\n.TP\n.BI \\-e \" stat\"\nexecute statement\n.IR stat .\nYou need to quote\n.I stat \nif it contains spaces, quotes,\nor other characters special to the shell.\n.TP\n.B \\-i\nenter interactive mode after\n.I script\nis executed.\n.TP\n.BI \\-l \" name\"\ncall\n.BI require(' name ')\nbefore executing\n.IR script .\nTypically used to load libraries.\n.TP\n.B \\-v\nshow version information.\n.SH \"SEE ALSO\"\n.BR luac (1)\n.br\nhttp://www.lua.org/\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nR. Ierusalimschy,\nL. H. de Figueiredo,\nand\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "doc/lua.css",
    "content": "body {\n\tcolor: #000000 ;\n\tbackground-color: #FFFFFF ;\n\tfont-family: sans-serif ;\n\ttext-align: justify ;\n\tmargin-right: 20px ;\n\tmargin-left: 20px ;\n}\n\nh1, h2, h3, h4 {\n\tfont-weight: normal ;\n\tfont-style: italic ;\n}\n\na:link {\n\tcolor: #000080 ;\n\tbackground-color: inherit ;\n\ttext-decoration: none ;\n}\n\na:visited {\n\tbackground-color: inherit ;\n\ttext-decoration: none ;\n}\n\na:link:hover, a:visited:hover {\n\tcolor: #000080 ;\n\tbackground-color: #E0E0FF ;\n}\n\na:link:active, a:visited:active {\n\tcolor: #FF0000 ;\n}\n\nhr {\n\tborder: 0 ;\n\theight: 1px ;\n\tcolor: #a0a0a0 ;\n\tbackground-color: #a0a0a0 ;\n}\n\n"
  },
  {
    "path": "doc/lua.html",
    "content": "<!-- $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -->\n<HTML>\n<HEAD>\n<TITLE>LUA man page</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n</HEAD>\n\n<BODY BGCOLOR=\"#FFFFFF\">\n\n<H2>NAME</H2>\nlua - Lua interpreter\n<H2>SYNOPSIS</H2>\n<B>lua</B>\n[\n<I>options</I>\n]\n[\n<I>script</I>\n[\n<I>args</I>\n]\n]\n<H2>DESCRIPTION</H2>\n<B>lua</B>\nis the stand-alone Lua interpreter.\nIt loads and executes Lua programs,\neither in textual source form or\nin precompiled binary form.\n(Precompiled binaries are output by\n<B>luac</B>,\nthe Lua compiler.)\n<B>lua</B>\ncan be used as a batch interpreter and also interactively.\n<P>\nThe given\n<I>options</I>\n(see below)\nare executed and then\nthe Lua program in file\n<I>script</I>\nis loaded and executed.\nThe given\n<I>args</I>\nare available to\n<I>script</I>\nas strings in a global table named\n<B>arg</B>.\nIf these arguments contain spaces or other characters special to the shell,\nthen they should be quoted\n(but note that the quotes will be removed by the shell).\nThe arguments in\n<B>arg</B>\nstart at 0,\nwhich contains the string\n'<I>script</I>'.\nThe index of the last argument is stored in\n<B>arg.n</B>.\nThe arguments given in the command line before\n<I>script</I>,\nincluding the name of the interpreter,\nare available in negative indices in\n<B>arg</B>.\n<P>\nAt the very start,\nbefore even handling the command line,\n<B>lua</B>\nexecutes the contents of the environment variable\n<B>LUA_INIT</B>,\nif it is defined.\nIf the value of\n<B>LUA_INIT</B>\nis of the form\n'@<I>filename</I>',\nthen\n<I>filename</I>\nis executed.\nOtherwise, the string is assumed to be a Lua statement and is executed.\n<P>\nOptions start with\n<B>'-'</B>\nand are described below.\nYou can use\n<B>'--'</B>\nto signal the end of options.\n<P>\nIf no arguments are given,\nthen\n<B>\"-v -i\"</B>\nis assumed when the standard input is a terminal;\notherwise,\n<B>\"-\"</B>\nis assumed.\n<P>\nIn interactive mode,\n<B>lua</B>\nprompts the user,\nreads lines from the standard input,\nand executes them as they are read.\nIf a line does not contain a complete statement,\nthen a secondary prompt is displayed and\nlines are read until a complete statement is formed or\na syntax error is found.\nSo, one way to interrupt the reading of an incomplete statement is\nto force a syntax error:\nadding a\n<B>';'</B>\nin the middle of a statement is a sure way of forcing a syntax error\n(except inside multiline strings and comments; these must be closed explicitly).\nIf a line starts with\n<B>'='</B>,\nthen\n<B>lua</B>\ndisplays the values of all the expressions in the remainder of the\nline. The expressions must be separated by commas.\nThe primary prompt is the value of the global variable\n<B>_PROMPT</B>,\nif this value is a string;\notherwise, the default prompt is used.\nSimilarly, the secondary prompt is the value of the global variable\n<B>_PROMPT2</B>.\nSo,\nto change the prompts,\nset the corresponding variable to a string of your choice.\nYou can do that after calling the interpreter\nor on the command line\n(but in this case you have to be careful with quotes\nif the prompt string contains a space; otherwise you may confuse the shell.)\nThe default prompts are \"&gt; \" and \"&gt;&gt; \".\n<H2>OPTIONS</H2>\n<P>\n<B>-</B>\nload and execute the standard input as a file,\nthat is,\nnot interactively,\neven when the standard input is a terminal.\n<P>\n<B>-e </B><I>stat</I>\nexecute statement\n<I>stat</I>.\nYou need to quote\n<I>stat </I>\nif it contains spaces, quotes,\nor other characters special to the shell.\n<P>\n<B>-i</B>\nenter interactive mode after\n<I>script</I>\nis executed.\n<P>\n<B>-l </B><I>name</I>\ncall\n<B>require</B>('<I>name</I>')\nbefore executing\n<I>script</I>.\nTypically used to load libraries.\n<P>\n<B>-v</B>\nshow version information.\n<H2>SEE ALSO</H2>\n<B>luac</B>(1)\n<BR>\n<A HREF=\"http://www.lua.org/\">http://www.lua.org/</A>\n<H2>DIAGNOSTICS</H2>\nError messages should be self explanatory.\n<H2>AUTHORS</H2>\nR. Ierusalimschy,\nL. H. de Figueiredo,\nand\nW. Celes\n<!-- EOF -->\n</BODY>\n</HTML>\n"
  },
  {
    "path": "doc/luac.1",
    "content": ".\\\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $\n.TH LUAC 1 \"$Date: 2006/01/06 16:03:34 $\"\n.SH NAME\nluac \\- Lua compiler\n.SH SYNOPSIS\n.B luac\n[\n.I options\n] [\n.I filenames\n]\n.SH DESCRIPTION\n.B luac\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files that can be later loaded and executed.\n.LP\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\n.LP\nPre-compiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n.B luac\nsimply allows those bytecodes to be saved in a file for later execution.\n.LP\nPre-compiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in pre-compiling is faster loading.\n.LP\nThe binary files created by\n.B luac\nare portable only among architectures with the same word size and byte order.\n.LP\n.B luac\nproduces a single output file containing the bytecodes\nfor all source files given.\nBy default,\nthe output file is named\n.BR luac.out ,\nbut you can change this with the\n.B \\-o\noption.\n.LP\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\nThis is useful to combine several precompiled chunks,\neven from different (but compatible) platforms,\ninto a single precompiled chunk.\n.LP\nYou can use\n.B \"'\\-'\"\nto indicate the standard input as a source file\nand\n.B \"'\\--'\"\nto signal the end of options\n(that is,\nall remaining arguments will be treated as files even if they start with\n.BR \"'\\-'\" ).\n.LP\nThe internal format of the binary files produced by\n.B luac\nis likely to change when a new version of Lua is released.\nSo,\nsave the source files of all Lua programs that you precompile.\n.LP\n.SH OPTIONS\nOptions must be separate.\n.TP\n.B \\-l\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand lists its contents.\n.TP\n.BI \\-o \" file\"\noutput to\n.IR file ,\ninstead of the default\n.BR luac.out .\n(You can use\n.B \"'\\-'\"\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be a source file because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n.TP\n.B \\-p\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nLua always performs a thorough integrity test on precompiled chunks.\nBytecode that passes this test is completely safe,\nin the sense that it will not break the interpreter.\nHowever,\nthere is no guarantee that such code does anything sensible.\n(None can be given, because the halting problem is unsolvable.)\nIf no files are given, then\n.B luac\nloads\n.B luac.out\nand tests its contents.\nNo messages are displayed if the file passes the integrity test.\n.TP\n.B \\-s\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nFor instance,\nline numbers and names of local variables are lost.\n.TP\n.B \\-v\nshow version information.\n.SH FILES\n.TP 15\n.B luac.out\ndefault output file\n.SH \"SEE ALSO\"\n.BR lua (1)\n.br\nhttp://www.lua.org/\n.SH DIAGNOSTICS\nError messages should be self explanatory.\n.SH AUTHORS\nL. H. de Figueiredo,\nR. Ierusalimschy and\nW. Celes\n.\\\" EOF\n"
  },
  {
    "path": "doc/luac.html",
    "content": "<!-- $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ -->\n<HTML>\n<HEAD>\n<TITLE>LUAC man page</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n</HEAD>\n\n<BODY BGCOLOR=\"#FFFFFF\">\n\n<H2>NAME</H2>\nluac - Lua compiler\n<H2>SYNOPSIS</H2>\n<B>luac</B>\n[\n<I>options</I>\n] [\n<I>filenames</I>\n]\n<H2>DESCRIPTION</H2>\n<B>luac</B>\nis the Lua compiler.\nIt translates programs written in the Lua programming language\ninto binary files that can be later loaded and executed.\n<P>\nThe main advantages of precompiling chunks are:\nfaster loading,\nprotecting source code from accidental user changes,\nand\noff-line syntax checking.\n<P>\nPrecompiling does not imply faster execution\nbecause in Lua chunks are always compiled into bytecodes before being executed.\n<B>luac</B>\nsimply allows those bytecodes to be saved in a file for later execution.\n<P>\nPrecompiled chunks are not necessarily smaller than the corresponding source.\nThe main goal in precompiling is faster loading.\n<P>\nThe binary files created by\n<B>luac</B>\nare portable only among architectures with the same word size and byte order.\n<P>\n<B>luac</B>\nproduces a single output file containing the bytecodes\nfor all source files given.\nBy default,\nthe output file is named\n<B>luac.out</B>,\nbut you can change this with the\n<B>-o</B>\noption.\n<P>\nIn the command line,\nyou can mix\ntext files containing Lua source and\nbinary files containing precompiled chunks.\nThis is useful because several precompiled chunks,\neven from different (but compatible) platforms,\ncan be combined into a single precompiled chunk.\n<P>\nYou can use\n<B>'-'</B>\nto indicate the standard input as a source file\nand\n<B>'--'</B>\nto signal the end of options\n(that is,\nall remaining arguments will be treated as files even if they start with\n<B>'-'</B>).\n<P>\nThe internal format of the binary files produced by\n<B>luac</B>\nis likely to change when a new version of Lua is released.\nSo,\nsave the source files of all Lua programs that you precompile.\n<P>\n<H2>OPTIONS</H2>\nOptions must be separate.\n<P>\n<B>-l</B>\nproduce a listing of the compiled bytecode for Lua's virtual machine.\nListing bytecodes is useful to learn about Lua's virtual machine.\nIf no files are given, then\n<B>luac</B>\nloads\n<B>luac.out</B>\nand lists its contents.\n<P>\n<B>-o </B><I>file</I>\noutput to\n<I>file</I>,\ninstead of the default\n<B>luac.out</B>.\n(You can use\n<B>'-'</B>\nfor standard output,\nbut not on platforms that open standard output in text mode.)\nThe output file may be a source file because\nall files are loaded before the output file is written.\nBe careful not to overwrite precious files.\n<P>\n<B>-p</B>\nload files but do not generate any output file.\nUsed mainly for syntax checking and for testing precompiled chunks:\ncorrupted files will probably generate errors when loaded.\nLua always performs a thorough integrity test on precompiled chunks.\nBytecode that passes this test is completely safe,\nin the sense that it will not break the interpreter.\nHowever,\nthere is no guarantee that such code does anything sensible.\n(None can be given, because the halting problem is unsolvable.)\nIf no files are given, then\n<B>luac</B>\nloads\n<B>luac.out</B>\nand tests its contents.\nNo messages are displayed if the file passes the integrity test.\n<P>\n<B>-s</B>\nstrip debug information before writing the output file.\nThis saves some space in very large chunks,\nbut if errors occur when running a stripped chunk,\nthen the error messages may not contain the full information they usually do.\nFor instance,\nline numbers and names of local variables are lost.\n<P>\n<B>-v</B>\nshow version information.\n<H2>FILES</H2>\n<P>\n<B>luac.out</B>\ndefault output file\n<H2>SEE ALSO</H2>\n<B>lua</B>(1)\n<BR>\n<A HREF=\"http://www.lua.org/\">http://www.lua.org/</A>\n<H2>DIAGNOSTICS</H2>\nError messages should be self explanatory.\n<H2>AUTHORS</H2>\nL. H. de Figueiredo,\nR. Ierusalimschy and\nW. Celes\n<!-- EOF -->\n</BODY>\n</HTML>\n"
  },
  {
    "path": "doc/manual.css",
    "content": "h3 code {\n\tfont-family: inherit ;\n}\n\npre {\n\tfont-size: 105% ;\n}\n\nspan.apii {\n\tfloat: right ;\n\tfont-family: inherit ;\n}\n\n"
  },
  {
    "path": "doc/manual.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html>\n\n<head>\n<title>Lua 5.1 Reference Manual</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"lua.css\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"manual.css\">\n<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</head>\n\n<body>\n\n<hr>\n<h1>\n<a href=\"http://www.lua.org/\"><img src=\"logo.gif\" alt=\"\" border=\"0\"></a>\nLua 5.1 Reference Manual\n</h1>\n\nby Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes\n<p>\n<small>\nCopyright &copy; 2006-2008 Lua.org, PUC-Rio.\nFreely available under the terms of the\n<a href=\"http://www.lua.org/license.html#5\">Lua license</a>.\n</small>\n<hr>\n<p>\n\n<a href=\"contents.html#contents\">contents</A>\n&middot;\n<a href=\"contents.html#index\">index</A>\n\n<!-- ====================================================================== -->\n<p>\n\n<!-- $Id: manual.of,v 1.48 2008/08/18 15:24:20 roberto Exp $ -->\n\n\n\n\n<h1>1 - <a name=\"1\">Introduction</a></h1>\n\n<p>\nLua is an extension programming language designed to support\ngeneral procedural programming with data description\nfacilities.\nIt also offers good support for object-oriented programming,\nfunctional programming, and data-driven programming.\nLua is intended to be used as a powerful, light-weight\nscripting language for any program that needs one.\nLua is implemented as a library, written in <em>clean</em> C\n(that is, in the common subset of ANSI&nbsp;C and C++).\n\n\n<p>\nBeing an extension language, Lua has no notion of a \"main\" program:\nit only works <em>embedded</em> in a host client,\ncalled the <em>embedding program</em> or simply the <em>host</em>.\nThis host program can invoke functions to execute a piece of Lua code,\ncan write and read Lua variables,\nand can register C&nbsp;functions to be called by Lua code.\nThrough the use of C&nbsp;functions, Lua can be augmented to cope with\na wide range of different domains,\nthus creating customized programming languages sharing a syntactical framework.\nThe Lua distribution includes a sample host program called <code>lua</code>,\nwhich uses the Lua library to offer a complete, stand-alone Lua interpreter.\n\n\n<p>\nLua is free software,\nand is provided as usual with no guarantees,\nas stated in its license.\nThe implementation described in this manual is available\nat Lua's official web site, <code>www.lua.org</code>.\n\n\n<p>\nLike any other reference manual,\nthis document is dry in places.\nFor a discussion of the decisions behind the design of Lua,\nsee the technical papers available at Lua's web site.\nFor a detailed introduction to programming in Lua,\nsee Roberto's book, <em>Programming in Lua (Second Edition)</em>.\n\n\n\n<h1>2 - <a name=\"2\">The Language</a></h1>\n\n<p>\nThis section describes the lexis, the syntax, and the semantics of Lua.\nIn other words,\nthis section describes\nwhich tokens are valid,\nhow they can be combined,\nand what their combinations mean.\n\n\n<p>\nThe language constructs will be explained using the usual extended BNF notation,\nin which\n{<em>a</em>}&nbsp;means&nbsp;0 or more <em>a</em>'s, and\n[<em>a</em>]&nbsp;means an optional <em>a</em>.\nNon-terminals are shown like non-terminal,\nkeywords are shown like <b>kword</b>,\nand other terminal symbols are shown like `<b>=</b>&acute;.\nThe complete syntax of Lua can be found in <a href=\"#8\">&sect;8</a>\nat the end of this manual.\n\n\n\n<h2>2.1 - <a name=\"2.1\">Lexical Conventions</a></h2>\n\n<p>\n<em>Names</em>\n(also called <em>identifiers</em>)\nin Lua can be any string of letters,\ndigits, and underscores,\nnot beginning with a digit.\nThis coincides with the definition of names in most languages.\n(The definition of letter depends on the current locale:\nany character considered alphabetic by the current locale\ncan be used in an identifier.)\nIdentifiers are used to name variables and table fields.\n\n\n<p>\nThe following <em>keywords</em> are reserved\nand cannot be used as names:\n\n\n<pre>\n     and       break     do        else      elseif\n     end       false     for       function  if\n     in        local     nil       not       or\n     repeat    return    then      true      until     while\n</pre>\n\n<p>\nLua is a case-sensitive language:\n<code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>\nare two different, valid names.\nAs a convention, names starting with an underscore followed by\nuppercase letters (such as <a href=\"#pdf-_VERSION\"><code>_VERSION</code></a>)\nare reserved for internal global variables used by Lua.\n\n\n<p>\nThe following strings denote other tokens:\n\n<pre>\n     +     -     *     /     %     ^     #\n     ==    ~=    &lt;=    &gt;=    &lt;     &gt;     =\n     (     )     {     }     [     ]\n     ;     :     ,     .     ..    ...\n</pre>\n\n<p>\n<em>Literal strings</em>\ncan be delimited by matching single or double quotes,\nand can contain the following C-like escape sequences:\n'<code>\\a</code>' (bell),\n'<code>\\b</code>' (backspace),\n'<code>\\f</code>' (form feed),\n'<code>\\n</code>' (newline),\n'<code>\\r</code>' (carriage return),\n'<code>\\t</code>' (horizontal tab),\n'<code>\\v</code>' (vertical tab),\n'<code>\\\\</code>' (backslash),\n'<code>\\\"</code>' (quotation mark [double quote]),\nand '<code>\\'</code>' (apostrophe [single quote]).\nMoreover, a backslash followed by a real newline\nresults in a newline in the string.\nA character in a string can also be specified by its numerical value\nusing the escape sequence <code>\\<em>ddd</em></code>,\nwhere <em>ddd</em> is a sequence of up to three decimal digits.\n(Note that if a numerical escape is to be followed by a digit,\nit must be expressed using exactly three digits.)\nStrings in Lua can contain any 8-bit value, including embedded zeros,\nwhich can be specified as '<code>\\0</code>'.\n\n\n<p>\nLiteral strings can also be defined using a long format\nenclosed by <em>long brackets</em>.\nWe define an <em>opening long bracket of level <em>n</em></em> as an opening\nsquare bracket followed by <em>n</em> equal signs followed by another\nopening square bracket.\nSo, an opening long bracket of level&nbsp;0 is written as <code>[[</code>,\nan opening long bracket of level&nbsp;1 is written as <code>[=[</code>,\nand so on.\nA <em>closing long bracket</em> is defined similarly;\nfor instance, a closing long bracket of level&nbsp;4 is written as <code>]====]</code>.\nA long string starts with an opening long bracket of any level and\nends at the first closing long bracket of the same level.\nLiterals in this bracketed form can run for several lines,\ndo not interpret any escape sequences,\nand ignore long brackets of any other level.\nThey can contain anything except a closing bracket of the proper level.\n\n\n<p>\nFor convenience,\nwhen the opening long bracket is immediately followed by a newline,\nthe newline is not included in the string.\nAs an example, in a system using ASCII\n(in which '<code>a</code>' is coded as&nbsp;97,\nnewline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),\nthe five literal strings below denote the same string:\n\n<pre>\n     a = 'alo\\n123\"'\n     a = \"alo\\n123\\\"\"\n     a = '\\97lo\\10\\04923\"'\n     a = [[alo\n     123\"]]\n     a = [==[\n     alo\n     123\"]==]\n</pre>\n\n<p>\nA <em>numerical constant</em> can be written with an optional decimal part\nand an optional decimal exponent.\nLua also accepts integer hexadecimal constants,\nby prefixing them with <code>0x</code>.\nExamples of valid numerical constants are\n\n<pre>\n     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56\n</pre>\n\n<p>\nA <em>comment</em> starts with a double hyphen (<code>--</code>)\nanywhere outside a string.\nIf the text immediately after <code>--</code> is not an opening long bracket,\nthe comment is a <em>short comment</em>,\nwhich runs until the end of the line.\nOtherwise, it is a <em>long comment</em>,\nwhich runs until the corresponding closing long bracket.\nLong comments are frequently used to disable code temporarily.\n\n\n\n\n\n<h2>2.2 - <a name=\"2.2\">Values and Types</a></h2>\n\n<p>\nLua is a <em>dynamically typed language</em>.\nThis means that\nvariables do not have types; only values do.\nThere are no type definitions in the language.\nAll values carry their own type.\n\n\n<p>\nAll values in Lua are <em>first-class values</em>.\nThis means that all values can be stored in variables,\npassed as arguments to other functions, and returned as results.\n\n\n<p>\nThere are eight basic types in Lua:\n<em>nil</em>, <em>boolean</em>, <em>number</em>,\n<em>string</em>, <em>function</em>, <em>userdata</em>,\n<em>thread</em>, and <em>table</em>.\n<em>Nil</em> is the type of the value <b>nil</b>,\nwhose main property is to be different from any other value;\nit usually represents the absence of a useful value.\n<em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.\nBoth <b>nil</b> and <b>false</b> make a condition false;\nany other value makes it true.\n<em>Number</em> represents real (double-precision floating-point) numbers.\n(It is easy to build Lua interpreters that use other\ninternal representations for numbers,\nsuch as single-precision float or long integers;\nsee file <code>luaconf.h</code>.)\n<em>String</em> represents arrays of characters.\n\nLua is 8-bit clean:\nstrings can contain any 8-bit character,\nincluding embedded zeros ('<code>\\0</code>') (see <a href=\"#2.1\">&sect;2.1</a>).\n\n\n<p>\nLua can call (and manipulate) functions written in Lua and\nfunctions written in C\n(see <a href=\"#2.5.8\">&sect;2.5.8</a>).\n\n\n<p>\nThe type <em>userdata</em> is provided to allow arbitrary C&nbsp;data to\nbe stored in Lua variables.\nThis type corresponds to a block of raw memory\nand has no pre-defined operations in Lua,\nexcept assignment and identity test.\nHowever, by using <em>metatables</em>,\nthe programmer can define operations for userdata values\n(see <a href=\"#2.8\">&sect;2.8</a>).\nUserdata values cannot be created or modified in Lua,\nonly through the C&nbsp;API.\nThis guarantees the integrity of data owned by the host program.\n\n\n<p>\nThe type <em>thread</em> represents independent threads of execution\nand it is used to implement coroutines (see <a href=\"#2.11\">&sect;2.11</a>).\nDo not confuse Lua threads with operating-system threads.\nLua supports coroutines on all systems,\neven those that do not support threads.\n\n\n<p>\nThe type <em>table</em> implements associative arrays,\nthat is, arrays that can be indexed not only with numbers,\nbut with any value (except <b>nil</b>).\nTables can be <em>heterogeneous</em>;\nthat is, they can contain values of all types (except <b>nil</b>).\nTables are the sole data structuring mechanism in Lua;\nthey can be used to represent ordinary arrays,\nsymbol tables, sets, records, graphs, trees, etc.\nTo represent records, Lua uses the field name as an index.\nThe language supports this representation by\nproviding <code>a.name</code> as syntactic sugar for <code>a[\"name\"]</code>.\nThere are several convenient ways to create tables in Lua\n(see <a href=\"#2.5.7\">&sect;2.5.7</a>).\n\n\n<p>\nLike indices,\nthe value of a table field can be of any type (except <b>nil</b>).\nIn particular,\nbecause functions are first-class values,\ntable fields can contain functions.\nThus tables can also carry <em>methods</em> (see <a href=\"#2.5.9\">&sect;2.5.9</a>).\n\n\n<p>\nTables, functions, threads, and (full) userdata values are <em>objects</em>:\nvariables do not actually <em>contain</em> these values,\nonly <em>references</em> to them.\nAssignment, parameter passing, and function returns\nalways manipulate references to such values;\nthese operations do not imply any kind of copy.\n\n\n<p>\nThe library function <a href=\"#pdf-type\"><code>type</code></a> returns a string describing the type\nof a given value.\n\n\n\n<h3>2.2.1 - <a name=\"2.2.1\">Coercion</a></h3>\n\n<p>\nLua provides automatic conversion between\nstring and number values at run time.\nAny arithmetic operation applied to a string tries to convert\nthis string to a number, following the usual conversion rules.\nConversely, whenever a number is used where a string is expected,\nthe number is converted to a string, in a reasonable format.\nFor complete control over how numbers are converted to strings,\nuse the <code>format</code> function from the string library\n(see <a href=\"#pdf-string.format\"><code>string.format</code></a>).\n\n\n\n\n\n\n\n<h2>2.3 - <a name=\"2.3\">Variables</a></h2>\n\n<p>\nVariables are places that store values.\n\nThere are three kinds of variables in Lua:\nglobal variables, local variables, and table fields.\n\n\n<p>\nA single name can denote a global variable or a local variable\n(or a function's formal parameter,\nwhich is a particular kind of local variable):\n\n<pre>\n\tvar ::= Name\n</pre><p>\nName denotes identifiers, as defined in <a href=\"#2.1\">&sect;2.1</a>.\n\n\n<p>\nAny variable is assumed to be global unless explicitly declared\nas a local (see <a href=\"#2.4.7\">&sect;2.4.7</a>).\nLocal variables are <em>lexically scoped</em>:\nlocal variables can be freely accessed by functions\ndefined inside their scope (see <a href=\"#2.6\">&sect;2.6</a>).\n\n\n<p>\nBefore the first assignment to a variable, its value is <b>nil</b>.\n\n\n<p>\nSquare brackets are used to index a table:\n\n<pre>\n\tvar ::= prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute;\n</pre><p>\nThe meaning of accesses to global variables \nand table fields can be changed via metatables.\nAn access to an indexed variable <code>t[i]</code> is equivalent to\na call <code>gettable_event(t,i)</code>.\n(See <a href=\"#2.8\">&sect;2.8</a> for a complete description of the\n<code>gettable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nThe syntax <code>var.Name</code> is just syntactic sugar for\n<code>var[\"Name\"]</code>:\n\n<pre>\n\tvar ::= prefixexp `<b>.</b>&acute; Name\n</pre>\n\n<p>\nAll global variables live as fields in ordinary Lua tables,\ncalled <em>environment tables</em> or simply\n<em>environments</em> (see <a href=\"#2.9\">&sect;2.9</a>).\nEach function has its own reference to an environment,\nso that all global variables in this function\nwill refer to this environment table.\nWhen a function is created,\nit inherits the environment from the function that created it.\nTo get the environment table of a Lua function,\nyou call <a href=\"#pdf-getfenv\"><code>getfenv</code></a>.\nTo replace it,\nyou call <a href=\"#pdf-setfenv\"><code>setfenv</code></a>.\n(You can only manipulate the environment of C&nbsp;functions\nthrough the debug library; (see <a href=\"#5.9\">&sect;5.9</a>).)\n\n\n<p>\nAn access to a global variable <code>x</code>\nis equivalent to <code>_env.x</code>,\nwhich in turn is equivalent to\n\n<pre>\n     gettable_event(_env, \"x\")\n</pre><p>\nwhere <code>_env</code> is the environment of the running function.\n(See <a href=\"#2.8\">&sect;2.8</a> for a complete description of the\n<code>gettable_event</code> function.\nThis function is not defined or callable in Lua.\nSimilarly, the <code>_env</code> variable is not defined in Lua.\nWe use them here only for explanatory purposes.)\n\n\n\n\n\n<h2>2.4 - <a name=\"2.4\">Statements</a></h2>\n\n<p>\nLua supports an almost conventional set of statements,\nsimilar to those in Pascal or C.\nThis set includes\nassignments, control structures, function calls,\nand variable declarations.\n\n\n\n<h3>2.4.1 - <a name=\"2.4.1\">Chunks</a></h3>\n\n<p>\nThe unit of execution of Lua is called a <em>chunk</em>.\nA chunk is simply a sequence of statements,\nwhich are executed sequentially.\nEach statement can be optionally followed by a semicolon:\n\n<pre>\n\tchunk ::= {stat [`<b>;</b>&acute;]}\n</pre><p>\nThere are no empty statements and thus '<code>;;</code>' is not legal.\n\n\n<p>\nLua handles a chunk as the body of an anonymous function \nwith a variable number of arguments\n(see <a href=\"#2.5.9\">&sect;2.5.9</a>).\nAs such, chunks can define local variables,\nreceive arguments, and return values.\n\n\n<p>\nA chunk can be stored in a file or in a string inside the host program.\nTo execute a chunk,\nLua first pre-compiles the chunk into instructions for a virtual machine,\nand then it executes the compiled code\nwith an interpreter for the virtual machine.\n\n\n<p>\nChunks can also be pre-compiled into binary form;\nsee program <code>luac</code> for details.\nPrograms in source and compiled forms are interchangeable;\nLua automatically detects the file type and acts accordingly.\n\n\n\n\n\n\n<h3>2.4.2 - <a name=\"2.4.2\">Blocks</a></h3><p>\nA block is a list of statements;\nsyntactically, a block is the same as a chunk:\n\n<pre>\n\tblock ::= chunk\n</pre>\n\n<p>\nA block can be explicitly delimited to produce a single statement:\n\n<pre>\n\tstat ::= <b>do</b> block <b>end</b>\n</pre><p>\nExplicit blocks are useful\nto control the scope of variable declarations.\nExplicit blocks are also sometimes used to\nadd a <b>return</b> or <b>break</b> statement in the middle\nof another block (see <a href=\"#2.4.4\">&sect;2.4.4</a>).\n\n\n\n\n\n<h3>2.4.3 - <a name=\"2.4.3\">Assignment</a></h3>\n\n<p>\nLua allows multiple assignments.\nTherefore, the syntax for assignment\ndefines a list of variables on the left side\nand a list of expressions on the right side.\nThe elements in both lists are separated by commas:\n\n<pre>\n\tstat ::= varlist `<b>=</b>&acute; explist\n\tvarlist ::= var {`<b>,</b>&acute; var}\n\texplist ::= exp {`<b>,</b>&acute; exp}\n</pre><p>\nExpressions are discussed in <a href=\"#2.5\">&sect;2.5</a>.\n\n\n<p>\nBefore the assignment,\nthe list of values is <em>adjusted</em> to the length of\nthe list of variables.\nIf there are more values than needed,\nthe excess values are thrown away.\nIf there are fewer values than needed,\nthe list is extended with as many  <b>nil</b>'s as needed.\nIf the list of expressions ends with a function call,\nthen all values returned by that call enter the list of values,\nbefore the adjustment\n(except when the call is enclosed in parentheses; see <a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nThe assignment statement first evaluates all its expressions\nand only then are the assignments performed.\nThus the code\n\n<pre>\n     i = 3\n     i, a[i] = i+1, 20\n</pre><p>\nsets <code>a[3]</code> to 20, without affecting <code>a[4]</code>\nbecause the <code>i</code> in <code>a[i]</code> is evaluated (to 3)\nbefore it is assigned&nbsp;4.\nSimilarly, the line\n\n<pre>\n     x, y = y, x\n</pre><p>\nexchanges the values of <code>x</code> and <code>y</code>,\nand\n\n<pre>\n     x, y, z = y, z, x\n</pre><p>\ncyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.\n\n\n<p>\nThe meaning of assignments to global variables\nand table fields can be changed via metatables.\nAn assignment to an indexed variable <code>t[i] = val</code> is equivalent to\n<code>settable_event(t,i,val)</code>.\n(See <a href=\"#2.8\">&sect;2.8</a> for a complete description of the\n<code>settable_event</code> function.\nThis function is not defined or callable in Lua.\nWe use it here only for explanatory purposes.)\n\n\n<p>\nAn assignment to a global variable <code>x = val</code>\nis equivalent to the assignment\n<code>_env.x = val</code>,\nwhich in turn is equivalent to\n\n<pre>\n     settable_event(_env, \"x\", val)\n</pre><p>\nwhere <code>_env</code> is the environment of the running function.\n(The <code>_env</code> variable is not defined in Lua.\nWe use it here only for explanatory purposes.)\n\n\n\n\n\n<h3>2.4.4 - <a name=\"2.4.4\">Control Structures</a></h3><p>\nThe control structures\n<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and\nfamiliar syntax:\n\n\n\n\n<pre>\n\tstat ::= <b>while</b> exp <b>do</b> block <b>end</b>\n\tstat ::= <b>repeat</b> block <b>until</b> exp\n\tstat ::= <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b>\n</pre><p>\nLua also has a <b>for</b> statement, in two flavors (see <a href=\"#2.4.5\">&sect;2.4.5</a>).\n\n\n<p>\nThe condition expression of a\ncontrol structure can return any value.\nBoth <b>false</b> and <b>nil</b> are considered false.\nAll values different from <b>nil</b> and <b>false</b> are considered true\n(in particular, the number 0 and the empty string are also true).\n\n\n<p>\nIn the <b>repeat</b>&ndash;<b>until</b> loop,\nthe inner block does not end at the <b>until</b> keyword,\nbut only after the condition.\nSo, the condition can refer to local variables\ndeclared inside the loop block.\n\n\n<p>\nThe <b>return</b> statement is used to return values\nfrom a function or a chunk (which is just a function).\n\nFunctions and chunks can return more than one value,\nand so the syntax for the <b>return</b> statement is\n\n<pre>\n\tstat ::= <b>return</b> [explist]\n</pre>\n\n<p>\nThe <b>break</b> statement is used to terminate the execution of a\n<b>while</b>, <b>repeat</b>, or <b>for</b> loop,\nskipping to the next statement after the loop:\n\n\n<pre>\n\tstat ::= <b>break</b>\n</pre><p>\nA <b>break</b> ends the innermost enclosing loop.\n\n\n<p>\nThe <b>return</b> and <b>break</b>\nstatements can only be written as the <em>last</em> statement of a block.\nIf it is really necessary to <b>return</b> or <b>break</b> in the\nmiddle of a block,\nthen an explicit inner block can be used,\nas in the idioms\n<code>do return end</code> and <code>do break end</code>,\nbecause now <b>return</b> and <b>break</b> are the last statements in\ntheir (inner) blocks.\n\n\n\n\n\n<h3>2.4.5 - <a name=\"2.4.5\">For Statement</a></h3>\n\n<p>\n\nThe <b>for</b> statement has two forms:\none numeric and one generic.\n\n\n<p>\nThe numeric <b>for</b> loop repeats a block of code while a\ncontrol variable runs through an arithmetic progression.\nIt has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b>\n</pre><p>\nThe <em>block</em> is repeated for <em>name</em> starting at the value of\nthe first <em>exp</em>, until it passes the second <em>exp</em> by steps of the\nthird <em>exp</em>.\nMore precisely, a <b>for</b> statement like\n\n<pre>\n     for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)\n       if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end\n       while (<em>step</em> &gt; 0 and <em>var</em> &lt;= <em>limit</em>) or (<em>step</em> &lt;= 0 and <em>var</em> &gt;= <em>limit</em>) do\n         local v = <em>var</em>\n         <em>block</em>\n         <em>var</em> = <em>var</em> + <em>step</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\nAll three control expressions are evaluated only once,\nbefore the loop starts.\nThey must all result in numbers.\n</li>\n\n<li>\n<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.\nThe names shown here are for explanatory purposes only.\n</li>\n\n<li>\nIf the third expression (the step) is absent,\nthen a step of&nbsp;1 is used.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variable <code>v</code> is local to the loop;\nyou cannot use its value after the <b>for</b> ends or is broken.\nIf you need this value,\nassign it to another variable before breaking or exiting the loop.\n</li>\n\n</ul>\n\n<p>\nThe generic <b>for</b> statement works over functions,\ncalled <em>iterators</em>.\nOn each iteration, the iterator function is called to produce a new value,\nstopping when this new value is <b>nil</b>.\nThe generic <b>for</b> loop has the following syntax:\n\n<pre>\n\tstat ::= <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b>\n\tnamelist ::= Name {`<b>,</b>&acute; Name}\n</pre><p>\nA <b>for</b> statement like\n\n<pre>\n     for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end\n</pre><p>\nis equivalent to the code:\n\n<pre>\n     do\n       local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>\n       while true do\n         local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)\n         <em>var</em> = <em>var_1</em>\n         if <em>var</em> == nil then break end\n         <em>block</em>\n       end\n     end\n</pre><p>\nNote the following:\n\n<ul>\n\n<li>\n<code><em>explist</em></code> is evaluated only once.\nIts results are an <em>iterator</em> function,\na <em>state</em>,\nand an initial value for the first <em>iterator variable</em>.\n</li>\n\n<li>\n<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.\nThe names are here for explanatory purposes only.\n</li>\n\n<li>\nYou can use <b>break</b> to exit a <b>for</b> loop.\n</li>\n\n<li>\nThe loop variables <code><em>var_i</em></code> are local to the loop;\nyou cannot use their values after the <b>for</b> ends.\nIf you need these values,\nthen assign them to other variables before breaking or exiting the loop.\n</li>\n\n</ul>\n\n\n\n\n<h3>2.4.6 - <a name=\"2.4.6\">Function Calls as Statements</a></h3><p>\nTo allow possible side-effects,\nfunction calls can be executed as statements:\n\n<pre>\n\tstat ::= functioncall\n</pre><p>\nIn this case, all returned values are thrown away.\nFunction calls are explained in <a href=\"#2.5.8\">&sect;2.5.8</a>.\n\n\n\n\n\n<h3>2.4.7 - <a name=\"2.4.7\">Local Declarations</a></h3><p>\nLocal variables can be declared anywhere inside a block.\nThe declaration can include an initial assignment:\n\n<pre>\n\tstat ::= <b>local</b> namelist [`<b>=</b>&acute; explist]\n</pre><p>\nIf present, an initial assignment has the same semantics\nof a multiple assignment (see <a href=\"#2.4.3\">&sect;2.4.3</a>).\nOtherwise, all variables are initialized with <b>nil</b>.\n\n\n<p>\nA chunk is also a block (see <a href=\"#2.4.1\">&sect;2.4.1</a>),\nand so local variables can be declared in a chunk outside any explicit block.\nThe scope of such local variables extends until the end of the chunk.\n\n\n<p>\nThe visibility rules for local variables are explained in <a href=\"#2.6\">&sect;2.6</a>.\n\n\n\n\n\n\n\n<h2>2.5 - <a name=\"2.5\">Expressions</a></h2>\n\n<p>\nThe basic expressions in Lua are the following:\n\n<pre>\n\texp ::= prefixexp\n\texp ::= <b>nil</b> | <b>false</b> | <b>true</b>\n\texp ::= Number\n\texp ::= String\n\texp ::= function\n\texp ::= tableconstructor\n\texp ::= `<b>...</b>&acute;\n\texp ::= exp binop exp\n\texp ::= unop exp\n\tprefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;\n</pre>\n\n<p>\nNumbers and literal strings are explained in <a href=\"#2.1\">&sect;2.1</a>;\nvariables are explained in <a href=\"#2.3\">&sect;2.3</a>;\nfunction definitions are explained in <a href=\"#2.5.9\">&sect;2.5.9</a>;\nfunction calls are explained in <a href=\"#2.5.8\">&sect;2.5.8</a>;\ntable constructors are explained in <a href=\"#2.5.7\">&sect;2.5.7</a>.\nVararg expressions,\ndenoted by three dots ('<code>...</code>'), can only be used when\ndirectly inside a vararg function;\nthey are explained in <a href=\"#2.5.9\">&sect;2.5.9</a>.\n\n\n<p>\nBinary operators comprise arithmetic operators (see <a href=\"#2.5.1\">&sect;2.5.1</a>),\nrelational operators (see <a href=\"#2.5.2\">&sect;2.5.2</a>), logical operators (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\nand the concatenation operator (see <a href=\"#2.5.4\">&sect;2.5.4</a>).\nUnary operators comprise the unary minus (see <a href=\"#2.5.1\">&sect;2.5.1</a>),\nthe unary <b>not</b> (see <a href=\"#2.5.3\">&sect;2.5.3</a>),\nand the unary <em>length operator</em> (see <a href=\"#2.5.5\">&sect;2.5.5</a>).\n\n\n<p>\nBoth function calls and vararg expressions can result in multiple values.\nIf an expression is used as a statement\n(only possible for function calls (see <a href=\"#2.4.6\">&sect;2.4.6</a>)),\nthen its return list is adjusted to zero elements,\nthus discarding all returned values.\nIf an expression is used as the last (or the only) element\nof a list of expressions,\nthen no adjustment is made\n(unless the call is enclosed in parentheses).\nIn all other contexts,\nLua adjusts the result list to one element,\ndiscarding all values except the first one.\n\n\n<p>\nHere are some examples:\n\n<pre>\n     f()                -- adjusted to 0 results\n     g(f(), x)          -- f() is adjusted to 1 result\n     g(x, f())          -- g gets x plus all results from f()\n     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)\n     a,b = ...          -- a gets the first vararg parameter, b gets\n                        -- the second (both a and b can get nil if there\n                        -- is no corresponding vararg parameter)\n     \n     a,b,c = x, f()     -- f() is adjusted to 2 results\n     a,b,c = f()        -- f() is adjusted to 3 results\n     return f()         -- returns all results from f()\n     return ...         -- returns all received vararg parameters\n     return x,y,f()     -- returns x, y, and all results from f()\n     {f()}              -- creates a list with all results from f()\n     {...}              -- creates a list with all vararg parameters\n     {f(), nil}         -- f() is adjusted to 1 result\n</pre>\n\n<p>\nAny expression enclosed in parentheses always results in only one value.\nThus,\n<code>(f(x,y,z))</code> is always a single value,\neven if <code>f</code> returns several values.\n(The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>\nor <b>nil</b> if <code>f</code> does not return any values.)\n\n\n\n<h3>2.5.1 - <a name=\"2.5.1\">Arithmetic Operators</a></h3><p>\nLua supports the usual arithmetic operators:\nthe binary <code>+</code> (addition),\n<code>-</code> (subtraction), <code>*</code> (multiplication),\n<code>/</code> (division), <code>%</code> (modulo), and <code>^</code> (exponentiation);\nand unary <code>-</code> (negation).\nIf the operands are numbers, or strings that can be converted to\nnumbers (see <a href=\"#2.2.1\">&sect;2.2.1</a>),\nthen all operations have the usual meaning.\nExponentiation works for any exponent.\nFor instance, <code>x^(-0.5)</code> computes the inverse of the square root of <code>x</code>.\nModulo is defined as\n\n<pre>\n     a % b == a - math.floor(a/b)*b\n</pre><p>\nThat is, it is the remainder of a division that rounds\nthe quotient towards minus infinity.\n\n\n\n\n\n<h3>2.5.2 - <a name=\"2.5.2\">Relational Operators</a></h3><p>\nThe relational operators in Lua are\n\n<pre>\n     ==    ~=    &lt;     &gt;     &lt;=    &gt;=\n</pre><p>\nThese operators always result in <b>false</b> or <b>true</b>.\n\n\n<p>\nEquality (<code>==</code>) first compares the type of its operands.\nIf the types are different, then the result is <b>false</b>.\nOtherwise, the values of the operands are compared.\nNumbers and strings are compared in the usual way.\nObjects (tables, userdata, threads, and functions)\nare compared by <em>reference</em>:\ntwo objects are considered equal only if they are the <em>same</em> object.\nEvery time you create a new object\n(a table, userdata, thread, or function),\nthis new object is different from any previously existing object.\n\n\n<p>\nYou can change the way that Lua compares tables and userdata \nby using the \"eq\" metamethod (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n<p>\nThe conversion rules of <a href=\"#2.2.1\">&sect;2.2.1</a>\n<em>do not</em> apply to equality comparisons.\nThus, <code>\"0\"==0</code> evaluates to <b>false</b>,\nand <code>t[0]</code> and <code>t[\"0\"]</code> denote different\nentries in a table.\n\n\n<p>\nThe operator <code>~=</code> is exactly the negation of equality (<code>==</code>).\n\n\n<p>\nThe order operators work as follows.\nIf both arguments are numbers, then they are compared as such.\nOtherwise, if both arguments are strings,\nthen their values are compared according to the current locale.\nOtherwise, Lua tries to call the \"lt\" or the \"le\"\nmetamethod (see <a href=\"#2.8\">&sect;2.8</a>).\nA comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>\nand <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.\n\n\n\n\n\n<h3>2.5.3 - <a name=\"2.5.3\">Logical Operators</a></h3><p>\nThe logical operators in Lua are\n<b>and</b>, <b>or</b>, and <b>not</b>.\nLike the control structures (see <a href=\"#2.4.4\">&sect;2.4.4</a>),\nall logical operators consider both <b>false</b> and <b>nil</b> as false\nand anything else as true.\n\n\n<p>\nThe negation operator <b>not</b> always returns <b>false</b> or <b>true</b>.\nThe conjunction operator <b>and</b> returns its first argument\nif this value is <b>false</b> or <b>nil</b>;\notherwise, <b>and</b> returns its second argument.\nThe disjunction operator <b>or</b> returns its first argument\nif this value is different from <b>nil</b> and <b>false</b>;\notherwise, <b>or</b> returns its second argument.\nBoth <b>and</b> and <b>or</b> use short-cut evaluation;\nthat is,\nthe second operand is evaluated only if necessary.\nHere are some examples:\n\n<pre>\n     10 or 20            --&gt; 10\n     10 or error()       --&gt; 10\n     nil or \"a\"          --&gt; \"a\"\n     nil and 10          --&gt; nil\n     false and error()   --&gt; false\n     false and nil       --&gt; false\n     false or nil        --&gt; nil\n     10 and 20           --&gt; 20\n</pre><p>\n(In this manual,\n<code>--&gt;</code> indicates the result of the preceding expression.)\n\n\n\n\n\n<h3>2.5.4 - <a name=\"2.5.4\">Concatenation</a></h3><p>\nThe string concatenation operator in Lua is\ndenoted by two dots ('<code>..</code>').\nIf both operands are strings or numbers, then they are converted to\nstrings according to the rules mentioned in <a href=\"#2.2.1\">&sect;2.2.1</a>.\nOtherwise, the \"concat\" metamethod is called (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<h3>2.5.5 - <a name=\"2.5.5\">The Length Operator</a></h3>\n\n<p>\nThe length operator is denoted by the unary operator <code>#</code>.\nThe length of a string is its number of bytes\n(that is, the usual meaning of string length when each\ncharacter is one byte).\n\n\n<p>\nThe length of a table <code>t</code> is defined to be any\ninteger index <code>n</code>\nsuch that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>;\nmoreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> can be zero.\nFor a regular array, with non-nil values from 1 to a given <code>n</code>,\nits length is exactly that <code>n</code>,\nthe index of its last value.\nIf the array has \"holes\"\n(that is, <b>nil</b> values between other non-nil values),\nthen <code>#t</code> can be any of the indices that\ndirectly precedes a <b>nil</b> value\n(that is, it may consider any such <b>nil</b> value as the end of\nthe array). \n\n\n\n\n\n<h3>2.5.6 - <a name=\"2.5.6\">Precedence</a></h3><p>\nOperator precedence in Lua follows the table below,\nfrom lower to higher priority:\n\n<pre>\n     or\n     and\n     &lt;     &gt;     &lt;=    &gt;=    ~=    ==\n     ..\n     +     -\n     *     /     %\n     not   #     - (unary)\n     ^\n</pre><p>\nAs usual,\nyou can use parentheses to change the precedences of an expression.\nThe concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')\noperators are right associative.\nAll other binary operators are left associative.\n\n\n\n\n\n<h3>2.5.7 - <a name=\"2.5.7\">Table Constructors</a></h3><p>\nTable constructors are expressions that create tables.\nEvery time a constructor is evaluated, a new table is created.\nA constructor can be used to create an empty table\nor to create a table and initialize some of its fields.\nThe general syntax for constructors is\n\n<pre>\n\ttableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\tfield ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp\n\tfieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;\n</pre>\n\n<p>\nEach field of the form <code>[exp1] = exp2</code> adds to the new table an entry\nwith key <code>exp1</code> and value <code>exp2</code>.\nA field of the form <code>name = exp</code> is equivalent to\n<code>[\"name\"] = exp</code>.\nFinally, fields of the form <code>exp</code> are equivalent to\n<code>[i] = exp</code>, where <code>i</code> are consecutive numerical integers,\nstarting with 1.\nFields in the other formats do not affect this counting.\nFor example,\n\n<pre>\n     a = { [f(1)] = g; \"x\", \"y\"; x = 1, f(x), [30] = 23; 45 }\n</pre><p>\nis equivalent to\n\n<pre>\n     do\n       local t = {}\n       t[f(1)] = g\n       t[1] = \"x\"         -- 1st exp\n       t[2] = \"y\"         -- 2nd exp\n       t.x = 1            -- t[\"x\"] = 1\n       t[3] = f(x)        -- 3rd exp\n       t[30] = 23\n       t[4] = 45          -- 4th exp\n       a = t\n     end\n</pre>\n\n<p>\nIf the last field in the list has the form <code>exp</code>\nand the expression is a function call or a vararg expression,\nthen all values returned by this expression enter the list consecutively\n(see <a href=\"#2.5.8\">&sect;2.5.8</a>).\nTo avoid this,\nenclose the function call or the vararg expression\nin parentheses (see <a href=\"#2.5\">&sect;2.5</a>).\n\n\n<p>\nThe field list can have an optional trailing separator,\nas a convenience for machine-generated code.\n\n\n\n\n\n<h3>2.5.8 - <a name=\"2.5.8\">Function Calls</a></h3><p>\nA function call in Lua has the following syntax:\n\n<pre>\n\tfunctioncall ::= prefixexp args\n</pre><p>\nIn a function call,\nfirst prefixexp and args are evaluated.\nIf the value of prefixexp has type <em>function</em>,\nthen this function is called\nwith the given arguments.\nOtherwise, the prefixexp \"call\" metamethod is called,\nhaving as first parameter the value of prefixexp,\nfollowed by the original call arguments\n(see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n<p>\nThe form\n\n<pre>\n\tfunctioncall ::= prefixexp `<b>:</b>&acute; Name args\n</pre><p>\ncan be used to call \"methods\".\nA call <code>v:name(<em>args</em>)</code>\nis syntactic sugar for <code>v.name(v,<em>args</em>)</code>,\nexcept that <code>v</code> is evaluated only once.\n\n\n<p>\nArguments have the following syntax:\n\n<pre>\n\targs ::= `<b>(</b>&acute; [explist] `<b>)</b>&acute;\n\targs ::= tableconstructor\n\targs ::= String\n</pre><p>\nAll argument expressions are evaluated before the call.\nA call of the form <code>f{<em>fields</em>}</code> is\nsyntactic sugar for <code>f({<em>fields</em>})</code>;\nthat is, the argument list is a single new table.\nA call of the form <code>f'<em>string</em>'</code>\n(or <code>f\"<em>string</em>\"</code> or <code>f[[<em>string</em>]]</code>)\nis syntactic sugar for <code>f('<em>string</em>')</code>;\nthat is, the argument list is a single literal string.\n\n\n<p>\nAs an exception to the free-format syntax of Lua,\nyou cannot put a line break before the '<code>(</code>' in a function call.\nThis restriction avoids some ambiguities in the language.\nIf you write\n\n<pre>\n     a = f\n     (g).x(a)\n</pre><p>\nLua would see that as a single statement, <code>a = f(g).x(a)</code>.\nSo, if you want two statements, you must add a semi-colon between them.\nIf you actually want to call <code>f</code>,\nyou must remove the line break before <code>(g)</code>.\n\n\n<p>\nA call of the form <code>return</code> <em>functioncall</em> is called\na <em>tail call</em>.\nLua implements <em>proper tail calls</em>\n(or <em>proper tail recursion</em>):\nin a tail call,\nthe called function reuses the stack entry of the calling function.\nTherefore, there is no limit on the number of nested tail calls that\na program can execute.\nHowever, a tail call erases any debug information about the\ncalling function.\nNote that a tail call only happens with a particular syntax,\nwhere the <b>return</b> has one single function call as argument;\nthis syntax makes the calling function return exactly\nthe returns of the called function.\nSo, none of the following examples are tail calls:\n\n<pre>\n     return (f(x))        -- results adjusted to 1\n     return 2 * f(x)\n     return x, f(x)       -- additional results\n     f(x); return         -- results discarded\n     return x or f(x)     -- results adjusted to 1\n</pre>\n\n\n\n\n<h3>2.5.9 - <a name=\"2.5.9\">Function Definitions</a></h3>\n\n<p>\nThe syntax for function definition is\n\n<pre>\n\tfunction ::= <b>function</b> funcbody\n\tfuncbody ::= `<b>(</b>&acute; [parlist] `<b>)</b>&acute; block <b>end</b>\n</pre>\n\n<p>\nThe following syntactic sugar simplifies function definitions:\n\n<pre>\n\tstat ::= <b>function</b> funcname funcbody\n\tstat ::= <b>local</b> <b>function</b> Name funcbody\n\tfuncname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]\n</pre><p>\nThe statement\n\n<pre>\n     function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     function t.a.b.c.f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     t.a.b.c.f = function () <em>body</em> end\n</pre><p>\nThe statement\n\n<pre>\n     local function f () <em>body</em> end\n</pre><p>\ntranslates to\n\n<pre>\n     local f; f = function () <em>body</em> end\n</pre><p>\n<em>not</em> to\n\n<pre>\n     local f = function () <em>body</em> end\n</pre><p>\n(This only makes a difference when the body of the function\ncontains references to <code>f</code>.)\n\n\n<p>\nA function definition is an executable expression,\nwhose value has type <em>function</em>.\nWhen Lua pre-compiles a chunk,\nall its function bodies are pre-compiled too.\nThen, whenever Lua executes the function definition,\nthe function is <em>instantiated</em> (or <em>closed</em>).\nThis function instance (or <em>closure</em>)\nis the final value of the expression.\nDifferent instances of the same function\ncan refer to different  external local variables\nand can have different environment tables.\n\n\n<p>\nParameters act as local variables that are\ninitialized with the argument values:\n\n<pre>\n\tparlist ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;\n</pre><p>\nWhen a function is called,\nthe list of arguments is adjusted to\nthe length of the list of parameters,\nunless the function is a variadic or <em>vararg function</em>,\nwhich is\nindicated by three dots ('<code>...</code>') at the end of its parameter list.\nA vararg function does not adjust its argument list;\ninstead, it collects all extra arguments and supplies them\nto the function through a <em>vararg expression</em>,\nwhich is also written as three dots.\nThe value of this expression is a list of all actual extra arguments,\nsimilar to a function with multiple results.\nIf a vararg expression is used inside another expression\nor in the middle of a list of expressions,\nthen its return list is adjusted to one element.\nIf the expression is used as the last element of a list of expressions,\nthen no adjustment is made\n(unless that last expression is enclosed in parentheses).\n\n\n<p>\nAs an example, consider the following definitions:\n\n<pre>\n     function f(a, b) end\n     function g(a, b, ...) end\n     function r() return 1,2,3 end\n</pre><p>\nThen, we have the following mapping from arguments to parameters and\nto the vararg expression:\n\n<pre>\n     CALL            PARAMETERS\n     \n     f(3)             a=3, b=nil\n     f(3, 4)          a=3, b=4\n     f(3, 4, 5)       a=3, b=4\n     f(r(), 10)       a=1, b=10\n     f(r())           a=1, b=2\n     \n     g(3)             a=3, b=nil, ... --&gt;  (nothing)\n     g(3, 4)          a=3, b=4,   ... --&gt;  (nothing)\n     g(3, 4, 5, 8)    a=3, b=4,   ... --&gt;  5  8\n     g(5, r())        a=5, b=1,   ... --&gt;  2  3\n</pre>\n\n<p>\nResults are returned using the <b>return</b> statement (see <a href=\"#2.4.4\">&sect;2.4.4</a>).\nIf control reaches the end of a function\nwithout encountering a <b>return</b> statement,\nthen the function returns with no results.\n\n\n<p>\nThe <em>colon</em> syntax\nis used for defining <em>methods</em>,\nthat is, functions that have an implicit extra parameter <code>self</code>.\nThus, the statement\n\n<pre>\n     function t.a.b.c:f (<em>params</em>) <em>body</em> end\n</pre><p>\nis syntactic sugar for\n\n<pre>\n     t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end\n</pre>\n\n\n\n\n\n\n<h2>2.6 - <a name=\"2.6\">Visibility Rules</a></h2>\n\n<p>\n\nLua is a lexically scoped language.\nThe scope of variables begins at the first statement <em>after</em>\ntheir declaration and lasts until the end of the innermost block that\nincludes the declaration.\nConsider the following example:\n\n<pre>\n     x = 10                -- global variable\n     do                    -- new block\n       local x = x         -- new 'x', with value 10\n       print(x)            --&gt; 10\n       x = x+1\n       do                  -- another block\n         local x = x+1     -- another 'x'\n         print(x)          --&gt; 12\n       end\n       print(x)            --&gt; 11\n     end\n     print(x)              --&gt; 10  (the global one)\n</pre>\n\n<p>\nNotice that, in a declaration like <code>local x = x</code>,\nthe new <code>x</code> being declared is not in scope yet,\nand so the second <code>x</code> refers to the outside variable.\n\n\n<p>\nBecause of the lexical scoping rules,\nlocal variables can be freely accessed by functions\ndefined inside their scope.\nA local variable used by an inner function is called\nan <em>upvalue</em>, or <em>external local variable</em>,\ninside the inner function.\n\n\n<p>\nNotice that each execution of a <b>local</b> statement\ndefines new local variables.\nConsider the following example:\n\n<pre>\n     a = {}\n     local x = 20\n     for i=1,10 do\n       local y = 0\n       a[i] = function () y=y+1; return x+y end\n     end\n</pre><p>\nThe loop creates ten closures\n(that is, ten instances of the anonymous function).\nEach of these closures uses a different <code>y</code> variable,\nwhile all of them share the same <code>x</code>.\n\n\n\n\n\n<h2>2.7 - <a name=\"2.7\">Error Handling</a></h2>\n\n<p>\nBecause Lua is an embedded extension language,\nall Lua actions start from C&nbsp;code in the host program\ncalling a function from the Lua library (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\nWhenever an error occurs during Lua compilation or execution,\ncontrol returns to C,\nwhich can take appropriate measures\n(such as printing an error message).\n\n\n<p>\nLua code can explicitly generate an error by calling the\n<a href=\"#pdf-error\"><code>error</code></a> function.\nIf you need to catch errors in Lua,\nyou can use the <a href=\"#pdf-pcall\"><code>pcall</code></a> function.\n\n\n\n\n\n<h2>2.8 - <a name=\"2.8\">Metatables</a></h2>\n\n<p>\nEvery value in Lua can have a <em>metatable</em>.\nThis <em>metatable</em> is an ordinary Lua table\nthat defines the behavior of the original value\nunder certain special operations.\nYou can change several aspects of the behavior\nof operations over a value by setting specific fields in its metatable.\nFor instance, when a non-numeric value is the operand of an addition,\nLua checks for a function in the field <code>\"__add\"</code> in its metatable.\nIf it finds one,\nLua calls this function to perform the addition.\n\n\n<p>\nWe call the keys in a metatable <em>events</em>\nand the values <em>metamethods</em>.\nIn the previous example, the event is <code>\"add\"</code> \nand the metamethod is the function that performs the addition.\n\n\n<p>\nYou can query the metatable of any value\nthrough the <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a> function.\n\n\n<p>\nYou can replace the metatable of tables\nthrough the <a href=\"#pdf-setmetatable\"><code>setmetatable</code></a>\nfunction.\nYou cannot change the metatable of other types from Lua\n(except by using the debug library);\nyou must use the C&nbsp;API for that.\n\n\n<p>\nTables and full userdata have individual metatables\n(although multiple tables and userdata can share their metatables).\nValues of all other types share one single metatable per type;\nthat is, there is one single metatable for all numbers,\none for all strings, etc.\n\n\n<p>\nA metatable controls how an object behaves in arithmetic operations,\norder comparisons, concatenation, length operation, and indexing.\nA metatable also can define a function to be called when a userdata\nis garbage collected.\nFor each of these operations Lua associates a specific key\ncalled an <em>event</em>.\nWhen Lua performs one of these operations over a value,\nit checks whether this value has a metatable with the corresponding event.\nIf so, the value associated with that key (the metamethod)\ncontrols how Lua will perform the operation.\n\n\n<p>\nMetatables control the operations listed next.\nEach operation is identified by its corresponding name.\nThe key for each operation is a string with its name prefixed by\ntwo underscores, '<code>__</code>';\nfor instance, the key for operation \"add\" is the\nstring <code>\"__add\"</code>.\nThe semantics of these operations is better explained by a Lua function\ndescribing how the interpreter executes the operation.\n\n\n<p>\nThe code shown here in Lua is only illustrative;\nthe real behavior is hard coded in the interpreter\nand it is much more efficient than this simulation.\nAll functions used in these descriptions\n(<a href=\"#pdf-rawget\"><code>rawget</code></a>, <a href=\"#pdf-tonumber\"><code>tonumber</code></a>, etc.)\nare described in <a href=\"#5.1\">&sect;5.1</a>.\nIn particular, to retrieve the metamethod of a given object,\nwe use the expression\n\n<pre>\n     metatable(obj)[event]\n</pre><p>\nThis should be read as\n\n<pre>\n     rawget(getmetatable(obj) or {}, event)\n</pre><p>\n\nThat is, the access to a metamethod does not invoke other metamethods,\nand the access to objects with no metatables does not fail\n(it simply results in <b>nil</b>).\n\n\n\n<ul>\n\n<li><b>\"add\":</b>\nthe <code>+</code> operation.\n\n\n\n<p>\nThe function <code>getbinhandler</code> below defines how Lua chooses a handler\nfor a binary operation.\nFirst, Lua tries the first operand.\nIf its type does not define a handler for the operation,\nthen Lua tries the second operand.\n\n<pre>\n     function getbinhandler (op1, op2, event)\n       return metatable(op1)[event] or metatable(op2)[event]\n     end\n</pre><p>\nBy using this function,\nthe behavior of the <code>op1 + op2</code> is\n\n<pre>\n     function add_event (op1, op2)\n       local o1, o2 = tonumber(op1), tonumber(op2)\n       if o1 and o2 then  -- both operands are numeric?\n         return o1 + o2   -- '+' here is the primitive 'add'\n       else  -- at least one of the operands is not numeric\n         local h = getbinhandler(op1, op2, \"__add\")\n         if h then\n           -- call the handler with both operands\n           return (h(op1, op2))\n         else  -- no handler available: default behavior\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"sub\":</b>\nthe <code>-</code> operation.\n\nBehavior similar to the \"add\" operation.\n</li>\n\n<li><b>\"mul\":</b>\nthe <code>*</code> operation.\n\nBehavior similar to the \"add\" operation.\n</li>\n\n<li><b>\"div\":</b>\nthe <code>/</code> operation.\n\nBehavior similar to the \"add\" operation.\n</li>\n\n<li><b>\"mod\":</b>\nthe <code>%</code> operation.\n\nBehavior similar to the \"add\" operation,\nwith the operation\n<code>o1 - floor(o1/o2)*o2</code> as the primitive operation.\n</li>\n\n<li><b>\"pow\":</b>\nthe <code>^</code> (exponentiation) operation.\n\nBehavior similar to the \"add\" operation,\nwith the function <code>pow</code> (from the C&nbsp;math library)\nas the primitive operation.\n</li>\n\n<li><b>\"unm\":</b>\nthe unary <code>-</code> operation.\n\n\n<pre>\n     function unm_event (op)\n       local o = tonumber(op)\n       if o then  -- operand is numeric?\n         return -o  -- '-' here is the primitive 'unm'\n       else  -- the operand is not numeric.\n         -- Try to get a handler from the operand\n         local h = metatable(op).__unm\n         if h then\n           -- call the handler with the operand\n           return (h(op))\n         else  -- no handler available: default behavior\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"concat\":</b>\nthe <code>..</code> (concatenation) operation.\n\n\n<pre>\n     function concat_event (op1, op2)\n       if (type(op1) == \"string\" or type(op1) == \"number\") and\n          (type(op2) == \"string\" or type(op2) == \"number\") then\n         return op1 .. op2  -- primitive string concatenation\n       else\n         local h = getbinhandler(op1, op2, \"__concat\")\n         if h then\n           return (h(op1, op2))\n         else\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"len\":</b>\nthe <code>#</code> operation.\n\n\n<pre>\n     function len_event (op)\n       if type(op) == \"string\" then\n         return strlen(op)         -- primitive string length\n       elseif type(op) == \"table\" then\n         return #op                -- primitive table length\n       else\n         local h = metatable(op).__len\n         if h then\n           -- call the handler with the operand\n           return (h(op))\n         else  -- no handler available: default behavior\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\nSee <a href=\"#2.5.5\">&sect;2.5.5</a> for a description of the length of a table.\n</li>\n\n<li><b>\"eq\":</b>\nthe <code>==</code> operation.\n\nThe function <code>getcomphandler</code> defines how Lua chooses a metamethod\nfor comparison operators.\nA metamethod only is selected when both objects\nbeing compared have the same type\nand the same metamethod for the selected operation.\n\n<pre>\n     function getcomphandler (op1, op2, event)\n       if type(op1) ~= type(op2) then return nil end\n       local mm1 = metatable(op1)[event]\n       local mm2 = metatable(op2)[event]\n       if mm1 == mm2 then return mm1 else return nil end\n     end\n</pre><p>\nThe \"eq\" event is defined as follows:\n\n<pre>\n     function eq_event (op1, op2)\n       if type(op1) ~= type(op2) then  -- different types?\n         return false   -- different objects\n       end\n       if op1 == op2 then   -- primitive equal?\n         return true   -- objects are equal\n       end\n       -- try metamethod\n       local h = getcomphandler(op1, op2, \"__eq\")\n       if h then\n         return (h(op1, op2))\n       else\n         return false\n       end\n     end\n</pre><p>\n<code>a ~= b</code> is equivalent to <code>not (a == b)</code>.\n</li>\n\n<li><b>\"lt\":</b>\nthe <code>&lt;</code> operation.\n\n\n<pre>\n     function lt_event (op1, op2)\n       if type(op1) == \"number\" and type(op2) == \"number\" then\n         return op1 &lt; op2   -- numeric comparison\n       elseif type(op1) == \"string\" and type(op2) == \"string\" then\n         return op1 &lt; op2   -- lexicographic comparison\n       else\n         local h = getcomphandler(op1, op2, \"__lt\")\n         if h then\n           return (h(op1, op2))\n         else\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n<code>a &gt; b</code> is equivalent to <code>b &lt; a</code>.\n</li>\n\n<li><b>\"le\":</b>\nthe <code>&lt;=</code> operation.\n\n\n<pre>\n     function le_event (op1, op2)\n       if type(op1) == \"number\" and type(op2) == \"number\" then\n         return op1 &lt;= op2   -- numeric comparison\n       elseif type(op1) == \"string\" and type(op2) == \"string\" then\n         return op1 &lt;= op2   -- lexicographic comparison\n       else\n         local h = getcomphandler(op1, op2, \"__le\")\n         if h then\n           return (h(op1, op2))\n         else\n           h = getcomphandler(op1, op2, \"__lt\")\n           if h then\n             return not h(op2, op1)\n           else\n             error(&middot;&middot;&middot;)\n           end\n         end\n       end\n     end\n</pre><p>\n<code>a &gt;= b</code> is equivalent to <code>b &lt;= a</code>.\nNote that, in the absence of a \"le\" metamethod,\nLua tries the \"lt\", assuming that <code>a &lt;= b</code> is\nequivalent to <code>not (b &lt; a)</code>.\n</li>\n\n<li><b>\"index\":</b>\nThe indexing access <code>table[key]</code>.\n\n\n<pre>\n     function gettable_event (table, key)\n       local h\n       if type(table) == \"table\" then\n         local v = rawget(table, key)\n         if v ~= nil then return v end\n         h = metatable(table).__index\n         if h == nil then return nil end\n       else\n         h = metatable(table).__index\n         if h == nil then\n           error(&middot;&middot;&middot;)\n         end\n       end\n       if type(h) == \"function\" then\n         return (h(table, key))     -- call the handler\n       else return h[key]           -- or repeat operation on it\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"newindex\":</b>\nThe indexing assignment <code>table[key] = value</code>.\n\n\n<pre>\n     function settable_event (table, key, value)\n       local h\n       if type(table) == \"table\" then\n         local v = rawget(table, key)\n         if v ~= nil then rawset(table, key, value); return end\n         h = metatable(table).__newindex\n         if h == nil then rawset(table, key, value); return end\n       else\n         h = metatable(table).__newindex\n         if h == nil then\n           error(&middot;&middot;&middot;)\n         end\n       end\n       if type(h) == \"function\" then\n         h(table, key,value)           -- call the handler\n       else h[key] = value             -- or repeat operation on it\n       end\n     end\n</pre><p>\n</li>\n\n<li><b>\"call\":</b>\ncalled when Lua calls a value.\n\n\n<pre>\n     function function_event (func, ...)\n       if type(func) == \"function\" then\n         return func(...)   -- primitive call\n       else\n         local h = metatable(func).__call\n         if h then\n           return h(func, ...)\n         else\n           error(&middot;&middot;&middot;)\n         end\n       end\n     end\n</pre><p>\n</li>\n\n</ul>\n\n\n\n\n<h2>2.9 - <a name=\"2.9\">Environments</a></h2>\n\n<p>\nBesides metatables,\nobjects of types thread, function, and userdata\nhave another table associated with them,\ncalled their <em>environment</em>.\nLike metatables, environments are regular tables and\nmultiple objects can share the same environment.\n\n\n<p>\nThreads are created sharing the environment of the creating thread.\nUserdata and C&nbsp;functions are created sharing the environment\nof the creating C&nbsp;function.\nNon-nested Lua functions\n(created by <a href=\"#pdf-loadfile\"><code>loadfile</code></a>, <a href=\"#pdf-loadstring\"><code>loadstring</code></a> or <a href=\"#pdf-load\"><code>load</code></a>)\nare created sharing the environment of the creating thread.\nNested Lua functions are created sharing the environment of\nthe creating Lua function.\n\n\n<p>\nEnvironments associated with userdata have no meaning for Lua.\nIt is only a convenience feature for programmers to associate a table to\na userdata.\n\n\n<p>\nEnvironments associated with threads are called\n<em>global environments</em>.\nThey are used as the default environment for threads and\nnon-nested Lua functions created by the thread\nand can be directly accessed by C&nbsp;code (see <a href=\"#3.3\">&sect;3.3</a>).\n\n\n<p>\nThe environment associated with a C&nbsp;function can be directly\naccessed by C&nbsp;code (see <a href=\"#3.3\">&sect;3.3</a>).\nIt is used as the default environment for other C&nbsp;functions\nand userdata created by the function.\n\n\n<p>\nEnvironments associated with Lua functions are used to resolve\nall accesses to global variables within the function (see <a href=\"#2.3\">&sect;2.3</a>).\nThey are used as the default environment for nested Lua functions\ncreated by the function.\n\n\n<p>\nYou can change the environment of a Lua function or the\nrunning thread by calling <a href=\"#pdf-setfenv\"><code>setfenv</code></a>.\nYou can get the environment of a Lua function or the running thread\nby calling <a href=\"#pdf-getfenv\"><code>getfenv</code></a>.\nTo manipulate the environment of other objects\n(userdata, C&nbsp;functions, other threads) you must\nuse the C&nbsp;API.\n\n\n\n\n\n<h2>2.10 - <a name=\"2.10\">Garbage Collection</a></h2>\n\n<p>\nLua performs automatic memory management.\nThis means that\nyou have to worry neither about allocating memory for new objects\nnor about freeing it when the objects are no longer needed.\nLua manages memory automatically by running\na <em>garbage collector</em> from time to time\nto collect all <em>dead objects</em>\n(that is, objects that are no longer accessible from Lua).\nAll memory used by Lua is subject to automatic management:\ntables, userdata, functions, threads, strings, etc.\n\n\n<p>\nLua implements an incremental mark-and-sweep collector.\nIt uses two numbers to control its garbage-collection cycles:\nthe <em>garbage-collector pause</em> and\nthe <em>garbage-collector step multiplier</em>.\nBoth use percentage points as units\n(so that a value of 100 means an internal value of 1).\n\n\n<p>\nThe garbage-collector pause\ncontrols how long the collector waits before starting a new cycle.\nLarger values make the collector less aggressive.\nValues smaller than 100 mean the collector will not wait to\nstart a new cycle.\nA value of 200 means that the collector waits for the total memory in use\nto double before starting a new cycle.\n\n\n<p>\nThe step multiplier\ncontrols the relative speed of the collector relative to\nmemory allocation.\nLarger values make the collector more aggressive but also increase\nthe size of each incremental step.\nValues smaller than 100 make the collector too slow and\ncan result in the collector never finishing a cycle.\nThe default, 200, means that the collector runs at \"twice\"\nthe speed of memory allocation.\n\n\n<p>\nYou can change these numbers by calling <a href=\"#lua_gc\"><code>lua_gc</code></a> in C\nor <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> in Lua.\nWith these functions you can also control \nthe collector directly (e.g., stop and restart it).\n\n\n\n<h3>2.10.1 - <a name=\"2.10.1\">Garbage-Collection Metamethods</a></h3>\n\n<p>\nUsing the C&nbsp;API,\nyou can set garbage-collector metamethods for userdata (see <a href=\"#2.8\">&sect;2.8</a>).\nThese metamethods are also called <em>finalizers</em>.\nFinalizers allow you to coordinate Lua's garbage collection\nwith external resource management\n(such as closing files, network or database connections,\nor freeing your own memory).\n\n\n<p>\nGarbage userdata with a field <code>__gc</code> in their metatables are not\ncollected immediately by the garbage collector.\nInstead, Lua puts them in a list.\nAfter the collection,\nLua does the equivalent of the following function\nfor each userdata in that list:\n\n<pre>\n     function gc_event (udata)\n       local h = metatable(udata).__gc\n       if h then\n         h(udata)\n       end\n     end\n</pre>\n\n<p>\nAt the end of each garbage-collection cycle,\nthe finalizers for userdata are called in <em>reverse</em>\norder of their creation,\namong those collected in that cycle.\nThat is, the first finalizer to be called is the one associated\nwith the userdata created last in the program.\nThe userdata itself is freed only in the next garbage-collection cycle.\n\n\n\n\n\n<h3>2.10.2 - <a name=\"2.10.2\">Weak Tables</a></h3>\n\n<p>\nA <em>weak table</em> is a table whose elements are\n<em>weak references</em>.\nA weak reference is ignored by the garbage collector.\nIn other words,\nif the only references to an object are weak references,\nthen the garbage collector will collect this object.\n\n\n<p>\nA weak table can have weak keys, weak values, or both.\nA table with weak keys allows the collection of its keys,\nbut prevents the collection of its values.\nA table with both weak keys and weak values allows the collection of\nboth keys and values.\nIn any case, if either the key or the value is collected,\nthe whole pair is removed from the table.\nThe weakness of a table is controlled by the\n<code>__mode</code> field of its metatable.\nIf the <code>__mode</code> field is a string containing the character&nbsp;'<code>k</code>',\nthe keys in the table are weak.\nIf <code>__mode</code> contains '<code>v</code>',\nthe values in the table are weak.\n\n\n<p>\nAfter you use a table as a metatable,\nyou should not change the value of its <code>__mode</code> field.\nOtherwise, the weak behavior of the tables controlled by this\nmetatable is undefined.\n\n\n\n\n\n\n\n<h2>2.11 - <a name=\"2.11\">Coroutines</a></h2>\n\n<p>\nLua supports coroutines,\nalso called <em>collaborative multithreading</em>.\nA coroutine in Lua represents an independent thread of execution.\nUnlike threads in multithread systems, however,\na coroutine only suspends its execution by explicitly calling\na yield function.\n\n\n<p>\nYou create a coroutine with a call to <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>.\nIts sole argument is a function\nthat is the main function of the coroutine.\nThe <code>create</code> function only creates a new coroutine and\nreturns a handle to it (an object of type <em>thread</em>);\nit does not start the coroutine execution.\n\n\n<p>\nWhen you first call <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\npassing as its first argument\na thread returned by <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe coroutine starts its execution,\nat the first line of its main function.\nExtra arguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> are passed on\nto the coroutine main function.\nAfter the coroutine starts running,\nit runs until it terminates or <em>yields</em>.\n\n\n<p>\nA coroutine can terminate its execution in two ways:\nnormally, when its main function returns\n(explicitly or implicitly, after the last instruction);\nand abnormally, if there is an unprotected error.\nIn the first case, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>true</b>,\nplus any values returned by the coroutine main function.\nIn case of errors, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns <b>false</b>\nplus an error message.\n\n\n<p>\nA coroutine yields by calling <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nWhen a coroutine yields,\nthe corresponding <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> returns immediately,\neven if the yield happens inside nested function calls\n(that is, not in the main function,\nbut in a function directly or indirectly called by the main function).\nIn the case of a yield, <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a> also returns <b>true</b>,\nplus any values passed to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a>.\nThe next time you resume the same coroutine,\nit continues its execution from the point where it yielded,\nwith the call to <a href=\"#pdf-coroutine.yield\"><code>coroutine.yield</code></a> returning any extra\narguments passed to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n\n\n<p>\nLike <a href=\"#pdf-coroutine.create\"><code>coroutine.create</code></a>,\nthe <a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> function also creates a coroutine,\nbut instead of returning the coroutine itself,\nit returns a function that, when called, resumes the coroutine.\nAny arguments passed to this function\ngo as extra arguments to <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>.\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> returns all the values returned by <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\nexcept the first one (the boolean error code).\nUnlike <a href=\"#pdf-coroutine.resume\"><code>coroutine.resume</code></a>,\n<a href=\"#pdf-coroutine.wrap\"><code>coroutine.wrap</code></a> does not catch errors;\nany error is propagated to the caller.\n\n\n<p>\nAs an example,\nconsider the following code:\n\n<pre>\n     function foo (a)\n       print(\"foo\", a)\n       return coroutine.yield(2*a)\n     end\n     \n     co = coroutine.create(function (a,b)\n           print(\"co-body\", a, b)\n           local r = foo(a+1)\n           print(\"co-body\", r)\n           local r, s = coroutine.yield(a+b, a-b)\n           print(\"co-body\", r, s)\n           return b, \"end\"\n     end)\n            \n     print(\"main\", coroutine.resume(co, 1, 10))\n     print(\"main\", coroutine.resume(co, \"r\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n     print(\"main\", coroutine.resume(co, \"x\", \"y\"))\n</pre><p>\nWhen you run it, it produces the following output:\n\n<pre>\n     co-body 1       10\n     foo     2\n     \n     main    true    4\n     co-body r\n     main    true    11      -9\n     co-body x       y\n     main    true    10      end\n     main    false   cannot resume dead coroutine\n</pre>\n\n\n\n\n<h1>3 - <a name=\"3\">The Application Program Interface</a></h1>\n\n<p>\n\nThis section describes the C&nbsp;API for Lua, that is,\nthe set of C&nbsp;functions available to the host program to communicate\nwith Lua.\nAll API functions and related types and constants\nare declared in the header file <a name=\"pdf-lua.h\"><code>lua.h</code></a>.\n\n\n<p>\nEven when we use the term \"function\",\nany facility in the API may be provided as a macro instead.\nAll such macros use each of their arguments exactly once\n(except for the first argument, which is always a Lua state),\nand so do not generate any hidden side-effects.\n\n\n<p>\nAs in most C&nbsp;libraries,\nthe Lua API functions do not check their arguments for validity or consistency.\nHowever, you can change this behavior by compiling Lua\nwith a proper definition for the macro <a name=\"pdf-luai_apicheck\"><code>luai_apicheck</code></a>,\nin file <code>luaconf.h</code>.\n\n\n\n<h2>3.1 - <a name=\"3.1\">The Stack</a></h2>\n\n<p>\nLua uses a <em>virtual stack</em> to pass values to and from C.\nEach element in this stack represents a Lua value\n(<b>nil</b>, number, string, etc.).\n\n\n<p>\nWhenever Lua calls C, the called function gets a new stack,\nwhich is independent of previous stacks and of stacks of\nC&nbsp;functions that are still active.\nThis stack initially contains any arguments to the C&nbsp;function\nand it is where the C&nbsp;function pushes its results\nto be returned to the caller (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\nFor convenience,\nmost query operations in the API do not follow a strict stack discipline.\nInstead, they can refer to any element in the stack\nby using an <em>index</em>:\nA positive index represents an <em>absolute</em> stack position\n(starting at&nbsp;1);\na negative index represents an <em>offset</em> relative to the top of the stack.\nMore specifically, if the stack has <em>n</em> elements,\nthen index&nbsp;1 represents the first element\n(that is, the element that was pushed onto the stack first)\nand\nindex&nbsp;<em>n</em> represents the last element;\nindex&nbsp;-1 also represents the last element\n(that is, the element at the&nbsp;top)\nand index <em>-n</em> represents the first element.\nWe say that an index is <em>valid</em>\nif it lies between&nbsp;1 and the stack top\n(that is, if <code>1 &le; abs(index) &le; top</code>).\n \n\n\n\n\n\n<h2>3.2 - <a name=\"3.2\">Stack Size</a></h2>\n\n<p>\nWhen you interact with Lua API,\nyou are responsible for ensuring consistency.\nIn particular,\n<em>you are responsible for controlling stack overflow</em>.\nYou can use the function <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>\nto grow the stack size.\n\n\n<p>\nWhenever Lua calls C,\nit ensures that at least <a name=\"pdf-LUA_MINSTACK\"><code>LUA_MINSTACK</code></a> stack positions are available.\n<code>LUA_MINSTACK</code> is defined as 20,\nso that usually you do not have to worry about stack space\nunless your code has loops pushing elements onto the stack.\n\n\n<p>\nMost query functions accept as indices any value inside the\navailable stack space, that is, indices up to the maximum stack size\nyou have set through <a href=\"#lua_checkstack\"><code>lua_checkstack</code></a>.\nSuch indices are called <em>acceptable indices</em>.\nMore formally, we define an <em>acceptable index</em>\nas follows:\n\n<pre>\n     (index &lt; 0 &amp;&amp; abs(index) &lt;= top) ||\n     (index &gt; 0 &amp;&amp; index &lt;= stackspace)\n</pre><p>\nNote that 0 is never an acceptable index.\n\n\n\n\n\n<h2>3.3 - <a name=\"3.3\">Pseudo-Indices</a></h2>\n\n<p>\nUnless otherwise noted,\nany function that accepts valid indices can also be called with\n<em>pseudo-indices</em>,\nwhich represent some Lua values that are accessible to C&nbsp;code\nbut which are not in the stack.\nPseudo-indices are used to access the thread environment,\nthe function environment,\nthe registry,\nand the upvalues of a C&nbsp;function (see <a href=\"#3.4\">&sect;3.4</a>).\n\n\n<p>\nThe thread environment (where global variables live) is\nalways at pseudo-index <a name=\"pdf-LUA_GLOBALSINDEX\"><code>LUA_GLOBALSINDEX</code></a>.\nThe environment of the running C&nbsp;function is always\nat pseudo-index <a name=\"pdf-LUA_ENVIRONINDEX\"><code>LUA_ENVIRONINDEX</code></a>.\n\n\n<p>\nTo access and change the value of global variables,\nyou can use regular table operations over an environment table.\nFor instance, to access the value of a global variable, do\n\n<pre>\n     lua_getfield(L, LUA_GLOBALSINDEX, varname);\n</pre>\n\n\n\n\n<h2>3.4 - <a name=\"3.4\">C Closures</a></h2>\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a <em>C&nbsp;closure</em>;\nthese values are called <em>upvalues</em> and are\naccessible to the function whenever it is called\n(see <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>).\n\n\n<p>\nWhenever a C&nbsp;function is called,\nits upvalues are located at specific pseudo-indices.\nThese pseudo-indices are produced by the macro\n<a name=\"lua_upvalueindex\"><code>lua_upvalueindex</code></a>.\nThe first value associated with a function is at position\n<code>lua_upvalueindex(1)</code>, and so on.\nAny access to <code>lua_upvalueindex(<em>n</em>)</code>,\nwhere <em>n</em> is greater than the number of upvalues of the\ncurrent function (but not greater than 256),\nproduces an acceptable (but invalid) index.\n\n\n\n\n\n<h2>3.5 - <a name=\"3.5\">Registry</a></h2>\n\n<p>\nLua provides a <em>registry</em>,\na pre-defined table that can be used by any C&nbsp;code to\nstore whatever Lua value it needs to store.\nThis table is always located at pseudo-index\n<a name=\"pdf-LUA_REGISTRYINDEX\"><code>LUA_REGISTRYINDEX</code></a>.\nAny C&nbsp;library can store data into this table,\nbut it should take care to choose keys different from those used\nby other libraries, to avoid collisions.\nTypically, you should use as key a string containing your library name\nor a light userdata with the address of a C&nbsp;object in your code.\n\n\n<p>\nThe integer keys in the registry are used by the reference mechanism,\nimplemented by the auxiliary library,\nand therefore should not be used for other purposes.\n\n\n\n\n\n<h2>3.6 - <a name=\"3.6\">Error Handling in C</a></h2>\n\n<p>\nInternally, Lua uses the C <code>longjmp</code> facility to handle errors.\n(You can also choose to use exceptions if you use C++;\nsee file <code>luaconf.h</code>.)\nWhen Lua faces any error\n(such as memory allocation errors, type errors, syntax errors,\nand runtime errors)\nit <em>raises</em> an error;\nthat is, it does a long jump.\nA <em>protected environment</em> uses <code>setjmp</code>\nto set a recover point;\nany error jumps to the most recent active recover point.\n\n\n<p>\nMost functions in the API can throw an error,\nfor instance due to a memory allocation error.\nThe documentation for each function indicates whether\nit can throw errors.\n\n\n<p>\nInside a C&nbsp;function you can throw an error by calling <a href=\"#lua_error\"><code>lua_error</code></a>.\n\n\n\n\n\n<h2>3.7 - <a name=\"3.7\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the C&nbsp;API in\nalphabetical order.\nEach function has an indicator like this:\n<span class=\"apii\">[-o, +p, <em>x</em>]</span>\n\n\n<p>\nThe first field, <code>o</code>,\nis how many elements the function pops from the stack.\nThe second field, <code>p</code>,\nis how many elements the function pushes onto the stack.\n(Any function always pushes its results after popping its arguments.)\nA field in the form <code>x|y</code> means the function can push (or pop)\n<code>x</code> or <code>y</code> elements,\ndepending on the situation;\nan interrogation mark '<code>?</code>' means that\nwe cannot know how many elements the function pops/pushes\nby looking only at its arguments\n(e.g., they may depend on what is on the stack).\nThe third field, <code>x</code>,\ntells whether the function may throw errors:\n'<code>-</code>' means the function never throws any error;\n'<code>m</code>' means the function may throw an error\nonly due to not enough memory;\n'<code>e</code>' means the function may throw other kinds of errors;\n'<code>v</code>' means the function may throw an error on purpose.\n\n\n\n<hr><h3><a name=\"lua_Alloc\"><code>lua_Alloc</code></a></h3>\n<pre>typedef void * (*lua_Alloc) (void *ud,\n                             void *ptr,\n                             size_t osize,\n                             size_t nsize);</pre>\n\n<p>\nThe type of the memory-allocation function used by Lua states.\nThe allocator function must provide a\nfunctionality similar to <code>realloc</code>,\nbut not exactly the same.\nIts arguments are\n<code>ud</code>, an opaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>;\n<code>ptr</code>, a pointer to the block being allocated/reallocated/freed;\n<code>osize</code>, the original size of the block;\n<code>nsize</code>, the new size of the block.\n<code>ptr</code> is <code>NULL</code> if and only if <code>osize</code> is zero.\nWhen <code>nsize</code> is zero, the allocator must return <code>NULL</code>;\nif <code>osize</code> is not zero,\nit should free the block pointed to by <code>ptr</code>.\nWhen <code>nsize</code> is not zero, the allocator returns <code>NULL</code>\nif and only if it cannot fill the request.\nWhen <code>nsize</code> is not zero and <code>osize</code> is zero,\nthe allocator should behave like <code>malloc</code>.\nWhen <code>nsize</code> and <code>osize</code> are not zero,\nthe allocator behaves like <code>realloc</code>.\nLua assumes that the allocator never fails when\n<code>osize &gt;= nsize</code>.\n\n\n<p>\nHere is a simple implementation for the allocator function.\nIt is used in the auxiliary library by <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a>.\n\n<pre>\n     static void *l_alloc (void *ud, void *ptr, size_t osize,\n                                                size_t nsize) {\n       (void)ud;  (void)osize;  /* not used */\n       if (nsize == 0) {\n         free(ptr);\n         return NULL;\n       }\n       else\n         return realloc(ptr, nsize);\n     }\n</pre><p>\nThis code assumes\nthat <code>free(NULL)</code> has no effect and that\n<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.\nANSI&nbsp;C ensures both behaviors.\n\n\n\n\n\n<hr><h3><a name=\"lua_atpanic\"><code>lua_atpanic</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre>\n\n<p>\nSets a new panic function and returns the old one.\n\n\n<p>\nIf an error happens outside any protected environment,\nLua calls a <em>panic function</em>\nand then calls <code>exit(EXIT_FAILURE)</code>,\nthus exiting the host application.\nYour panic function can avoid this exit by\nnever returning (e.g., doing a long jump).\n\n\n<p>\nThe panic function can access the error message at the top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_call\"><code>lua_call</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +nresults, <em>e</em>]</span>\n<pre>void lua_call (lua_State *L, int nargs, int nresults);</pre>\n\n<p>\nCalls a function.\n\n\n<p>\nTo call a function you must use the following protocol:\nfirst, the function to be called is pushed onto the stack;\nthen, the arguments to the function are pushed\nin direct order;\nthat is, the first argument is pushed first.\nFinally you call <a href=\"#lua_call\"><code>lua_call</code></a>;\n<code>nargs</code> is the number of arguments that you pushed onto the stack.\nAll arguments and the function value are popped from the stack\nwhen the function is called.\nThe function results are pushed onto the stack when the function returns.\nThe number of results is adjusted to <code>nresults</code>,\nunless <code>nresults</code> is <a name=\"pdf-LUA_MULTRET\"><code>LUA_MULTRET</code></a>.\nIn this case, <em>all</em> results from the function are pushed.\nLua takes care that the returned values fit into the stack space.\nThe function results are pushed onto the stack in direct order\n(the first result is pushed first),\nso that after the call the last result is on the top of the stack.\n\n\n<p>\nAny error inside the called function is propagated upwards\n(with a <code>longjmp</code>).\n\n\n<p>\nThe following example shows how the host program can do the\nequivalent to this Lua code:\n\n<pre>\n     a = f(\"how\", t.x, 14)\n</pre><p>\nHere it is in&nbsp;C:\n\n<pre>\n     lua_getfield(L, LUA_GLOBALSINDEX, \"f\"); /* function to be called */\n     lua_pushstring(L, \"how\");                        /* 1st argument */\n     lua_getfield(L, LUA_GLOBALSINDEX, \"t\");   /* table to be indexed */\n     lua_getfield(L, -1, \"x\");        /* push result of t.x (2nd arg) */\n     lua_remove(L, -2);                  /* remove 't' from the stack */\n     lua_pushinteger(L, 14);                          /* 3rd argument */\n     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */\n     lua_setfield(L, LUA_GLOBALSINDEX, \"a\");        /* set global 'a' */\n</pre><p>\nNote that the code above is \"balanced\":\nat its end, the stack is back to its original configuration.\nThis is considered good programming practice.\n\n\n\n\n\n<hr><h3><a name=\"lua_CFunction\"><code>lua_CFunction</code></a></h3>\n<pre>typedef int (*lua_CFunction) (lua_State *L);</pre>\n\n<p>\nType for C&nbsp;functions.\n\n\n<p>\nIn order to communicate properly with Lua,\na C&nbsp;function must use the following protocol,\nwhich defines the way parameters and results are passed:\na C&nbsp;function receives its arguments from Lua in its stack\nin direct order (the first argument is pushed first).\nSo, when the function starts,\n<code>lua_gettop(L)</code> returns the number of arguments received by the function.\nThe first argument (if any) is at index 1\nand its last argument is at index <code>lua_gettop(L)</code>.\nTo return values to Lua, a C&nbsp;function just pushes them onto the stack,\nin direct order (the first result is pushed first),\nand returns the number of results.\nAny other value in the stack below the results will be properly\ndiscarded by Lua.\nLike a Lua function, a C&nbsp;function called by Lua can also return\nmany results.\n\n\n<p>\nAs an example, the following function receives a variable number\nof numerical arguments and returns their average and sum:\n\n<pre>\n     static int foo (lua_State *L) {\n       int n = lua_gettop(L);    /* number of arguments */\n       lua_Number sum = 0;\n       int i;\n       for (i = 1; i &lt;= n; i++) {\n         if (!lua_isnumber(L, i)) {\n           lua_pushstring(L, \"incorrect argument\");\n           lua_error(L);\n         }\n         sum += lua_tonumber(L, i);\n       }\n       lua_pushnumber(L, sum/n);        /* first result */\n       lua_pushnumber(L, sum);         /* second result */\n       return 2;                   /* number of results */\n     }\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_checkstack\"><code>lua_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_checkstack (lua_State *L, int extra);</pre>\n\n<p>\nEnsures that there are at least <code>extra</code> free stack slots in the stack.\nIt returns false if it cannot grow the stack to that size.\nThis function never shrinks the stack;\nif the stack is already larger than the new size,\nit is left unchanged.\n\n\n\n\n\n<hr><h3><a name=\"lua_close\"><code>lua_close</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void lua_close (lua_State *L);</pre>\n\n<p>\nDestroys all objects in the given Lua state\n(calling the corresponding garbage-collection metamethods, if any)\nand frees all dynamic memory used by this state.\nOn several platforms, you may not need to call this function,\nbecause all resources are naturally released when the host program ends.\nOn the other hand, long-running programs,\nsuch as a daemon or a web server,\nmight need to release states as soon as they are not needed,\nto avoid growing too large.\n\n\n\n\n\n<hr><h3><a name=\"lua_concat\"><code>lua_concat</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>e</em>]</span>\n<pre>void lua_concat (lua_State *L, int n);</pre>\n\n<p>\nConcatenates the <code>n</code> values at the top of the stack,\npops them, and leaves the result at the top.\nIf <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack\n(that is, the function does nothing);\nif <code>n</code> is 0, the result is the empty string.\nConcatenation is performed following the usual semantics of Lua\n(see <a href=\"#2.5.4\">&sect;2.5.4</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_cpcall\"><code>lua_cpcall</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);</pre>\n\n<p>\nCalls the C&nbsp;function <code>func</code> in protected mode.\n<code>func</code> starts with only one element in its stack,\na light userdata containing <code>ud</code>.\nIn case of errors,\n<a href=\"#lua_cpcall\"><code>lua_cpcall</code></a> returns the same error codes as <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nplus the error object on the top of the stack;\notherwise, it returns zero, and does not change the stack.\nAll values returned by <code>func</code> are discarded.\n\n\n\n\n\n<hr><h3><a name=\"lua_createtable\"><code>lua_createtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_createtable (lua_State *L, int narr, int nrec);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nThe new table has space pre-allocated\nfor <code>narr</code> array elements and <code>nrec</code> non-array elements.\nThis pre-allocation is useful when you know exactly how many elements\nthe table will have.\nOtherwise you can use the function <a href=\"#lua_newtable\"><code>lua_newtable</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_dump\"><code>lua_dump</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>int lua_dump (lua_State *L, lua_Writer writer, void *data);</pre>\n\n<p>\nDumps a function as a binary chunk.\nReceives a Lua function on the top of the stack\nand produces a binary chunk that,\nif loaded again,\nresults in a function equivalent to the one dumped.\nAs it produces parts of the chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href=\"#lua_Writer\"><code>lua_Writer</code></a>)\nwith the given <code>data</code>\nto write them.\n\n\n<p>\nThe value returned is the error code returned by the last\ncall to the writer;\n0&nbsp;means no errors.\n\n\n<p>\nThis function does not pop the Lua function from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_equal\"><code>lua_equal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_equal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in acceptable indices <code>index1</code> and\n<code>index2</code> are equal,\nfollowing the semantics of the Lua <code>==</code> operator\n(that is, may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is non valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_error\"><code>lua_error</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>v</em>]</span>\n<pre>int lua_error (lua_State *L);</pre>\n\n<p>\nGenerates a Lua error.\nThe error message (which can actually be a Lua value of any type)\nmust be on the stack top.\nThis function does a long jump,\nand therefore never returns.\n(see <a href=\"#luaL_error\"><code>luaL_error</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gc\"><code>lua_gc</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_gc (lua_State *L, int what, int data);</pre>\n\n<p>\nControls the garbage collector.\n\n\n<p>\nThis function performs several tasks,\naccording to the value of the parameter <code>what</code>:\n\n<ul>\n\n<li><b><code>LUA_GCSTOP</code>:</b>\nstops the garbage collector.\n</li>\n\n<li><b><code>LUA_GCRESTART</code>:</b>\nrestarts the garbage collector.\n</li>\n\n<li><b><code>LUA_GCCOLLECT</code>:</b>\nperforms a full garbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCCOUNT</code>:</b>\nreturns the current amount of memory (in Kbytes) in use by Lua.\n</li>\n\n<li><b><code>LUA_GCCOUNTB</code>:</b>\nreturns the remainder of dividing the current amount of bytes of\nmemory in use by Lua by 1024.\n</li>\n\n<li><b><code>LUA_GCSTEP</code>:</b>\nperforms an incremental step of garbage collection.\nThe step \"size\" is controlled by <code>data</code>\n(larger values mean more steps) in a non-specified way.\nIf you want to control the step size\nyou must experimentally tune the value of <code>data</code>.\nThe function returns 1 if the step finished a\ngarbage-collection cycle.\n</li>\n\n<li><b><code>LUA_GCSETPAUSE</code>:</b>\nsets <code>data</code> as the new value\nfor the <em>pause</em> of the collector (see <a href=\"#2.10\">&sect;2.10</a>).\nThe function returns the previous value of the pause.\n</li>\n\n<li><b><code>LUA_GCSETSTEPMUL</code>:</b>\nsets <code>data</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.10\">&sect;2.10</a>).\nThe function returns the previous value of the step multiplier.\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_getallocf\"><code>lua_getallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre>\n\n<p>\nReturns the memory-allocation function of a given state.\nIf <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the\nopaque pointer passed to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfenv\"><code>lua_getfenv</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_getfenv (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the environment table of\nthe value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"lua_getfield\"><code>lua_getfield</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_getfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given valid index.\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getglobal\"><code>lua_getglobal</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>e</em>]</span>\n<pre>void lua_getglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPushes onto the stack the value of the global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_getglobal(L,s)  lua_getfield(L, LUA_GLOBALSINDEX, s)\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_getmetatable\"><code>lua_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>int lua_getmetatable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the metatable of the value at the given\nacceptable index.\nIf the index is not valid,\nor if the value does not have a metatable,\nthe function returns&nbsp;0 and pushes nothing on the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_gettable\"><code>lua_gettable</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>e</em>]</span>\n<pre>void lua_gettable (lua_State *L, int index);</pre>\n\n<p>\nPushes onto the stack the value <code>t[k]</code>,\nwhere <code>t</code> is the value at the given valid index\nand <code>k</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the key from the stack\n(putting the resulting value in its place).\nAs in Lua, this function may trigger a metamethod\nfor the \"index\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_gettop\"><code>lua_gettop</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_gettop (lua_State *L);</pre>\n\n<p>\nReturns the index of the top element in the stack.\nBecause indices start at&nbsp;1,\nthis result is equal to the number of elements in the stack\n(and so 0&nbsp;means an empty stack).\n\n\n\n\n\n<hr><h3><a name=\"lua_insert\"><code>lua_insert</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>-</em>]</span>\n<pre>void lua_insert (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given valid index,\nshifting up the elements above this index to open space.\nCannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_Integer\"><code>lua_Integer</code></a></h3>\n<pre>typedef ptrdiff_t lua_Integer;</pre>\n\n<p>\nThe type used by the Lua API to represent integral values.\n\n\n<p>\nBy default it is a <code>ptrdiff_t</code>,\nwhich is usually the largest signed integral type the machine handles\n\"comfortably\".\n\n\n\n\n\n<hr><h3><a name=\"lua_isboolean\"><code>lua_isboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isboolean (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index has type boolean,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_iscfunction\"><code>lua_iscfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_iscfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a C&nbsp;function,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isfunction\"><code>lua_isfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isfunction (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a function\n(either C or Lua), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_islightuserdata\"><code>lua_islightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_islightuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a light userdata,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnil\"><code>lua_isnil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnone\"><code>lua_isnone</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnone (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given acceptable index is not valid\n(that is, it refers to an element outside the current stack),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnoneornil\"><code>lua_isnoneornil</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnoneornil (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the given acceptable index is not valid\n(that is, it refers to an element outside the current stack)\nor if the value at this index is <b>nil</b>,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isnumber\"><code>lua_isnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isnumber (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a number\nor a string convertible to a number,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isstring\"><code>lua_isstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isstring (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a string\nor a number (which is always convertible to a string),\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_istable\"><code>lua_istable</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_istable (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a table,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isthread\"><code>lua_isthread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isthread (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a thread,\nand 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_isuserdata\"><code>lua_isuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_isuserdata (lua_State *L, int index);</pre>\n\n<p>\nReturns 1 if the value at the given acceptable index is a userdata\n(either full or light), and 0&nbsp;otherwise.\n\n\n\n\n\n<hr><h3><a name=\"lua_lessthan\"><code>lua_lessthan</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>int lua_lessthan (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the value at acceptable index <code>index1</code> is smaller\nthan the value at acceptable index <code>index2</code>,\nfollowing the semantics of the Lua <code>&lt;</code> operator\n(that is, may call metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices is non valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_load\"><code>lua_load</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>int lua_load (lua_State *L,\n              lua_Reader reader,\n              void *data,\n              const char *chunkname);</pre>\n\n<p>\nLoads a Lua chunk.\nIf there are no errors,\n<a href=\"#lua_load\"><code>lua_load</code></a> pushes the compiled chunk as a Lua\nfunction on top of the stack.\nOtherwise, it pushes an error message.\nThe return values of <a href=\"#lua_load\"><code>lua_load</code></a> are:\n\n<ul>\n\n<li><b>0:</b> no errors;</li>\n\n<li><b><a name=\"pdf-LUA_ERRSYNTAX\"><code>LUA_ERRSYNTAX</code></a>:</b>\nsyntax error during pre-compilation;</li>\n\n<li><b><a href=\"#pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>:</b>\nmemory allocation error.</li>\n\n</ul>\n\n<p>\nThis function only loads a chunk;\nit does not run it.\n\n\n<p>\n<a href=\"#lua_load\"><code>lua_load</code></a> automatically detects whether the chunk is text or binary,\nand loads it accordingly (see program <code>luac</code>).\n\n\n<p>\nThe <a href=\"#lua_load\"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function\nto read the chunk (see <a href=\"#lua_Reader\"><code>lua_Reader</code></a>).\nThe <code>data</code> argument is an opaque value passed to the reader function.\n\n\n<p>\nThe <code>chunkname</code> argument gives a name to the chunk,\nwhich is used for error messages and in debug information (see <a href=\"#3.8\">&sect;3.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_newstate\"><code>lua_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre>\n\n<p>\nCreates a new, independent state.\nReturns <code>NULL</code> if cannot create the state\n(due to lack of memory).\nThe argument <code>f</code> is the allocator function;\nLua does all memory allocation for this state through this function.\nThe second argument, <code>ud</code>, is an opaque pointer that Lua\nsimply passes to the allocator in every call.\n\n\n\n\n\n<hr><h3><a name=\"lua_newtable\"><code>lua_newtable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_newtable (lua_State *L);</pre>\n\n<p>\nCreates a new empty table and pushes it onto the stack.\nIt is equivalent to <code>lua_createtable(L, 0, 0)</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_newthread\"><code>lua_newthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>lua_State *lua_newthread (lua_State *L);</pre>\n\n<p>\nCreates a new thread, pushes it on the stack,\nand returns a pointer to a <a href=\"#lua_State\"><code>lua_State</code></a> that represents this new thread.\nThe new state returned by this function shares with the original state\nall global objects (such as tables),\nbut has an independent execution stack.\n\n\n<p>\nThere is no explicit function to close or to destroy a thread.\nThreads are subject to garbage collection,\nlike any Lua object.\n\n\n\n\n\n<hr><h3><a name=\"lua_newuserdata\"><code>lua_newuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void *lua_newuserdata (lua_State *L, size_t size);</pre>\n\n<p>\nThis function allocates a new block of memory with the given size,\npushes onto the stack a new full userdata with the block address,\nand returns this address.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>full userdata</em> represents a block of memory.\nIt is an object (like a table):\nyou must create it, it can have its own metatable,\nand you can detect when it is being collected.\nA full userdata is only equal to itself (under raw equality).\n\n\n<p>\nWhen Lua collects a full userdata with a <code>gc</code> metamethod,\nLua calls the metamethod and marks the userdata as finalized.\nWhen this userdata is collected again then\nLua frees its corresponding memory.\n\n\n\n\n\n<hr><h3><a name=\"lua_next\"><code>lua_next</code></a></h3><p>\n<span class=\"apii\">[-1, +(2|0), <em>e</em>]</span>\n<pre>int lua_next (lua_State *L, int index);</pre>\n\n<p>\nPops a key from the stack,\nand pushes a key-value pair from the table at the given index\n(the \"next\" pair after the given key).\nIf there are no more elements in the table,\nthen <a href=\"#lua_next\"><code>lua_next</code></a> returns 0 (and pushes nothing).\n\n\n<p>\nA typical traversal looks like this:\n\n<pre>\n     /* table is in the stack at index 't' */\n     lua_pushnil(L);  /* first key */\n     while (lua_next(L, t) != 0) {\n       /* uses 'key' (at index -2) and 'value' (at index -1) */\n       printf(\"%s - %s\\n\",\n              lua_typename(L, lua_type(L, -2)),\n              lua_typename(L, lua_type(L, -1)));\n       /* removes 'value'; keeps 'key' for next iteration */\n       lua_pop(L, 1);\n     }\n</pre>\n\n<p>\nWhile traversing a table,\ndo not call <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> directly on a key,\nunless you know that the key is actually a string.\nRecall that <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> <em>changes</em>\nthe value at the given index;\nthis confuses the next call to <a href=\"#lua_next\"><code>lua_next</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Number\"><code>lua_Number</code></a></h3>\n<pre>typedef double lua_Number;</pre>\n\n<p>\nThe type of numbers in Lua.\nBy default, it is double, but that can be changed in <code>luaconf.h</code>.\n\n\n<p>\nThrough the configuration file you can change\nLua to operate with another type for numbers (e.g., float or long).\n\n\n\n\n\n<hr><h3><a name=\"lua_objlen\"><code>lua_objlen</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>size_t lua_objlen (lua_State *L, int index);</pre>\n\n<p>\nReturns the \"length\" of the value at the given acceptable index:\nfor strings, this is the string length;\nfor tables, this is the result of the length operator ('<code>#</code>');\nfor userdata, this is the size of the block of memory allocated\nfor the userdata;\nfor other values, it is&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_pcall\"><code>lua_pcall</code></a></h3><p>\n<span class=\"apii\">[-(nargs + 1), +(nresults|1), <em>-</em>]</span>\n<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre>\n\n<p>\nCalls a function in protected mode.\n\n\n<p>\nBoth <code>nargs</code> and <code>nresults</code> have the same meaning as\nin <a href=\"#lua_call\"><code>lua_call</code></a>.\nIf there are no errors during the call,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> behaves exactly like <a href=\"#lua_call\"><code>lua_call</code></a>.\nHowever, if there is any error,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> catches it,\npushes a single value on the stack (the error message),\nand returns an error code.\nLike <a href=\"#lua_call\"><code>lua_call</code></a>,\n<a href=\"#lua_pcall\"><code>lua_pcall</code></a> always removes the function\nand its arguments from the stack.\n\n\n<p>\nIf <code>errfunc</code> is 0,\nthen the error message returned on the stack\nis exactly the original error message.\nOtherwise, <code>errfunc</code> is the stack index of an\n<em>error handler function</em>.\n(In the current implementation, this index cannot be a pseudo-index.)\nIn case of runtime errors,\nthis function will be called with the error message\nand its return value will be the message returned on the stack by <a href=\"#lua_pcall\"><code>lua_pcall</code></a>.\n\n\n<p>\nTypically, the error handler function is used to add more debug\ninformation to the error message, such as a stack traceback.\nSuch information cannot be gathered after the return of <a href=\"#lua_pcall\"><code>lua_pcall</code></a>,\nsince by then the stack has unwound.\n\n\n<p>\nThe <a href=\"#lua_pcall\"><code>lua_pcall</code></a> function returns 0 in case of success\nor one of the following error codes\n(defined in <code>lua.h</code>):\n\n<ul>\n\n<li><b><a name=\"pdf-LUA_ERRRUN\"><code>LUA_ERRRUN</code></a>:</b>\na runtime error.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRMEM\"><code>LUA_ERRMEM</code></a>:</b>\nmemory allocation error.\nFor such errors, Lua does not call the error handler function.\n</li>\n\n<li><b><a name=\"pdf-LUA_ERRERR\"><code>LUA_ERRERR</code></a>:</b>\nerror while running the error handler function.\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pop\"><code>lua_pop</code></a></h3><p>\n<span class=\"apii\">[-n, +0, <em>-</em>]</span>\n<pre>void lua_pop (lua_State *L, int n);</pre>\n\n<p>\nPops <code>n</code> elements from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushboolean\"><code>lua_pushboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushboolean (lua_State *L, int b);</pre>\n\n<p>\nPushes a boolean value with value <code>b</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcclosure\"><code>lua_pushcclosure</code></a></h3><p>\n<span class=\"apii\">[-n, +1, <em>m</em>]</span>\n<pre>void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);</pre>\n\n<p>\nPushes a new C&nbsp;closure onto the stack.\n\n\n<p>\nWhen a C&nbsp;function is created,\nit is possible to associate some values with it,\nthus creating a C&nbsp;closure (see <a href=\"#3.4\">&sect;3.4</a>);\nthese values are then accessible to the function whenever it is called.\nTo associate values with a C&nbsp;function,\nfirst these values should be pushed onto the stack\n(when there are multiple values, the first value is pushed first).\nThen <a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a>\nis called to create and push the C&nbsp;function onto the stack,\nwith the argument <code>n</code> telling how many values should be\nassociated with the function.\n<a href=\"#lua_pushcclosure\"><code>lua_pushcclosure</code></a> also pops these values from the stack.\n\n\n<p>\nThe maximum value for <code>n</code> is 255.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushcfunction\"><code>lua_pushcfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre>\n\n<p>\nPushes a C&nbsp;function onto the stack.\nThis function receives a pointer to a C function\nand pushes onto the stack a Lua value of type <code>function</code> that,\nwhen called, invokes the corresponding C&nbsp;function.\n\n\n<p>\nAny function to be registered in Lua must\nfollow the correct protocol to receive its parameters\nand return its results (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>).\n\n\n<p>\n<code>lua_pushcfunction</code> is defined as a macro:\n\n<pre>\n     #define lua_pushcfunction(L,f)  lua_pushcclosure(L,f,0)\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_pushfstring\"><code>lua_pushfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushfstring (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nPushes onto the stack a formatted string\nand returns a pointer to this string.\nIt is similar to the C&nbsp;function <code>sprintf</code>,\nbut has some important differences:\n\n<ul>\n\n<li>\nYou do not have to allocate space for the result:\nthe result is a Lua string and Lua takes care of memory allocation\n(and deallocation, through garbage collection).\n</li>\n\n<li>\nThe conversion specifiers are quite restricted.\nThere are no flags, widths, or precisions.\nThe conversion specifiers can only be\n'<code>%%</code>' (inserts a '<code>%</code>' in the string),\n'<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),\n'<code>%f</code>' (inserts a <a href=\"#lua_Number\"><code>lua_Number</code></a>),\n'<code>%p</code>' (inserts a pointer as a hexadecimal numeral),\n'<code>%d</code>' (inserts an <code>int</code>), and\n'<code>%c</code>' (inserts an <code>int</code> as a character).\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_pushinteger\"><code>lua_pushinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre>\n\n<p>\nPushes a number with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlightuserdata\"><code>lua_pushlightuserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre>\n\n<p>\nPushes a light userdata onto the stack.\n\n\n<p>\nUserdata represent C&nbsp;values in Lua.\nA <em>light userdata</em> represents a pointer.\nIt is a value (like a number):\nyou do not create it, it has no individual metatable,\nand it is not collected (as it was never created).\nA light userdata is equal to \"any\"\nlight userdata with the same C&nbsp;address.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushliteral\"><code>lua_pushliteral</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushliteral (lua_State *L, const char *s);</pre>\n\n<p>\nThis macro is equivalent to <a href=\"#lua_pushlstring\"><code>lua_pushlstring</code></a>,\nbut can be used only when <code>s</code> is a literal string.\nIn these cases, it automatically provides the string length.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushlstring\"><code>lua_pushlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushlstring (lua_State *L, const char *s, size_t len);</pre>\n\n<p>\nPushes the string pointed to by <code>s</code> with size <code>len</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string can contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnil\"><code>lua_pushnil</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushnil (lua_State *L);</pre>\n\n<p>\nPushes a nil value onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushnumber\"><code>lua_pushnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre>\n\n<p>\nPushes a number with value <code>n</code> onto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushstring\"><code>lua_pushstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void lua_pushstring (lua_State *L, const char *s);</pre>\n\n<p>\nPushes the zero-terminated string pointed to by <code>s</code>\nonto the stack.\nLua makes (or reuses) an internal copy of the given string,\nso the memory at <code>s</code> can be freed or reused immediately after\nthe function returns.\nThe string cannot contain embedded zeros;\nit is assumed to end at the first zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushthread\"><code>lua_pushthread</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>int lua_pushthread (lua_State *L);</pre>\n\n<p>\nPushes the thread represented by <code>L</code> onto the stack.\nReturns 1 if this thread is the main thread of its state.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvalue\"><code>lua_pushvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_pushvalue (lua_State *L, int index);</pre>\n\n<p>\nPushes a copy of the element at the given valid index\nonto the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_pushvfstring\"><code>lua_pushvfstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *lua_pushvfstring (lua_State *L,\n                              const char *fmt,\n                              va_list argp);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>, except that it receives a <code>va_list</code>\ninstead of a variable number of arguments.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawequal\"><code>lua_rawequal</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre>\n\n<p>\nReturns 1 if the two values in acceptable indices <code>index1</code> and\n<code>index2</code> are primitively equal\n(that is, without calling metamethods).\nOtherwise returns&nbsp;0.\nAlso returns&nbsp;0 if any of the indices are non valid.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawget\"><code>lua_rawget</code></a></h3><p>\n<span class=\"apii\">[-1, +1, <em>-</em>]</span>\n<pre>void lua_rawget (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_gettable\"><code>lua_gettable</code></a>, but does a raw access\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawgeti\"><code>lua_rawgeti</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void lua_rawgeti (lua_State *L, int index, int n);</pre>\n\n<p>\nPushes onto the stack the value <code>t[n]</code>,\nwhere <code>t</code> is the value at the given valid index.\nThe access is raw;\nthat is, it does not invoke metamethods.\n\n\n\n\n\n<hr><h3><a name=\"lua_rawset\"><code>lua_rawset</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>m</em>]</span>\n<pre>void lua_rawset (lua_State *L, int index);</pre>\n\n<p>\nSimilar to <a href=\"#lua_settable\"><code>lua_settable</code></a>, but does a raw assignment\n(i.e., without metamethods).\n\n\n\n\n\n<hr><h3><a name=\"lua_rawseti\"><code>lua_rawseti</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void lua_rawseti (lua_State *L, int index, int n);</pre>\n\n<p>\nDoes the equivalent of <code>t[n] = v</code>,\nwhere <code>t</code> is the value at the given valid index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nThe assignment is raw;\nthat is, it does not invoke metamethods.\n\n\n\n\n\n<hr><h3><a name=\"lua_Reader\"><code>lua_Reader</code></a></h3>\n<pre>typedef const char * (*lua_Reader) (lua_State *L,\n                                    void *data,\n                                    size_t *size);</pre>\n\n<p>\nThe reader function used by <a href=\"#lua_load\"><code>lua_load</code></a>.\nEvery time it needs another piece of the chunk,\n<a href=\"#lua_load\"><code>lua_load</code></a> calls the reader,\npassing along its <code>data</code> parameter.\nThe reader must return a pointer to a block of memory\nwith a new piece of the chunk\nand set <code>size</code> to the block size.\nThe block must exist until the reader function is called again.\nTo signal the end of the chunk,\nthe reader must return <code>NULL</code> or set <code>size</code> to zero.\nThe reader function may return pieces of any size greater than zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_register\"><code>lua_register</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>e</em>]</span>\n<pre>void lua_register (lua_State *L,\n                   const char *name,\n                   lua_CFunction f);</pre>\n\n<p>\nSets the C function <code>f</code> as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_register(L,n,f) \\\n            (lua_pushcfunction(L, f), lua_setglobal(L, n))\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_remove\"><code>lua_remove</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>void lua_remove (lua_State *L, int index);</pre>\n\n<p>\nRemoves the element at the given valid index,\nshifting down the elements above this index to fill the gap.\nCannot be called with a pseudo-index,\nbecause a pseudo-index is not an actual stack position.\n\n\n\n\n\n<hr><h3><a name=\"lua_replace\"><code>lua_replace</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>void lua_replace (lua_State *L, int index);</pre>\n\n<p>\nMoves the top element into the given position (and pops it),\nwithout shifting any element\n(therefore replacing the value at the given position).\n\n\n\n\n\n<hr><h3><a name=\"lua_resume\"><code>lua_resume</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>int lua_resume (lua_State *L, int narg);</pre>\n\n<p>\nStarts and resumes a coroutine in a given thread.\n\n\n<p>\nTo start a coroutine, you first create a new thread\n(see <a href=\"#lua_newthread\"><code>lua_newthread</code></a>);\nthen you push onto its stack the main function plus any arguments;\nthen you call <a href=\"#lua_resume\"><code>lua_resume</code></a>,\nwith <code>narg</code> being the number of arguments.\nThis call returns when the coroutine suspends or finishes its execution.\nWhen it returns, the stack contains all values passed to <a href=\"#lua_yield\"><code>lua_yield</code></a>,\nor all values returned by the body function.\n<a href=\"#lua_resume\"><code>lua_resume</code></a> returns\n<a href=\"#pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the coroutine yields,\n0 if the coroutine finishes its execution\nwithout errors,\nor an error code in case of errors (see <a href=\"#lua_pcall\"><code>lua_pcall</code></a>).\nIn case of errors,\nthe stack is not unwound,\nso you can use the debug API over it.\nThe error message is on the top of the stack.\nTo restart a coroutine, you put on its stack only the values to\nbe passed as results from <code>yield</code>,\nand then call <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setallocf\"><code>lua_setallocf</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre>\n\n<p>\nChanges the allocator function of a given state to <code>f</code>\nwith user data <code>ud</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfenv\"><code>lua_setfenv</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>int lua_setfenv (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and sets it as\nthe new environment for the value at the given index.\nIf the value at the given index is\nneither a function nor a thread nor a userdata,\n<a href=\"#lua_setfenv\"><code>lua_setfenv</code></a> returns 0.\nOtherwise it returns 1.\n\n\n\n\n\n<hr><h3><a name=\"lua_setfield\"><code>lua_setfield</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setfield (lua_State *L, int index, const char *k);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given valid index\nand <code>v</code> is the value at the top of the stack.\n\n\n<p>\nThis function pops the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_setglobal\"><code>lua_setglobal</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>e</em>]</span>\n<pre>void lua_setglobal (lua_State *L, const char *name);</pre>\n\n<p>\nPops a value from the stack and\nsets it as the new value of global <code>name</code>.\nIt is defined as a macro:\n\n<pre>\n     #define lua_setglobal(L,s)   lua_setfield(L, LUA_GLOBALSINDEX, s)\n</pre>\n\n\n\n\n<hr><h3><a name=\"lua_setmetatable\"><code>lua_setmetatable</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>-</em>]</span>\n<pre>int lua_setmetatable (lua_State *L, int index);</pre>\n\n<p>\nPops a table from the stack and\nsets it as the new metatable for the value at the given\nacceptable index.\n\n\n\n\n\n<hr><h3><a name=\"lua_settable\"><code>lua_settable</code></a></h3><p>\n<span class=\"apii\">[-2, +0, <em>e</em>]</span>\n<pre>void lua_settable (lua_State *L, int index);</pre>\n\n<p>\nDoes the equivalent to <code>t[k] = v</code>,\nwhere <code>t</code> is the value at the given valid index,\n<code>v</code> is the value at the top of the stack,\nand <code>k</code> is the value just below the top.\n\n\n<p>\nThis function pops both the key and the value from the stack.\nAs in Lua, this function may trigger a metamethod\nfor the \"newindex\" event (see <a href=\"#2.8\">&sect;2.8</a>).\n\n\n\n\n\n<hr><h3><a name=\"lua_settop\"><code>lua_settop</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>void lua_settop (lua_State *L, int index);</pre>\n\n<p>\nAccepts any acceptable index, or&nbsp;0,\nand sets the stack top to this index.\nIf the new top is larger than the old one,\nthen the new elements are filled with <b>nil</b>.\nIf <code>index</code> is&nbsp;0, then all stack elements are removed.\n\n\n\n\n\n<hr><h3><a name=\"lua_State\"><code>lua_State</code></a></h3>\n<pre>typedef struct lua_State lua_State;</pre>\n\n<p>\nOpaque structure that keeps the whole state of a Lua interpreter.\nThe Lua library is fully reentrant:\nit has no global variables.\nAll information about a state is kept in this structure.\n\n\n<p>\nA pointer to this state must be passed as the first argument to\nevery function in the library, except to <a href=\"#lua_newstate\"><code>lua_newstate</code></a>,\nwhich creates a Lua state from scratch.\n\n\n\n\n\n<hr><h3><a name=\"lua_status\"><code>lua_status</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_status (lua_State *L);</pre>\n\n<p>\nReturns the status of the thread <code>L</code>.\n\n\n<p>\nThe status can be 0 for a normal thread,\nan error code if the thread finished its execution with an error,\nor <a name=\"pdf-LUA_YIELD\"><code>LUA_YIELD</code></a> if the thread is suspended.\n\n\n\n\n\n<hr><h3><a name=\"lua_toboolean\"><code>lua_toboolean</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_toboolean (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index to a C&nbsp;boolean\nvalue (0&nbsp;or&nbsp;1).\nLike all tests in Lua,\n<a href=\"#lua_toboolean\"><code>lua_toboolean</code></a> returns 1 for any Lua value\ndifferent from <b>false</b> and <b>nil</b>;\notherwise it returns 0.\nIt also returns 0 when called with a non-valid index.\n(If you want to accept only actual boolean values,\nuse <a href=\"#lua_isboolean\"><code>lua_isboolean</code></a> to test the value's type.)\n\n\n\n\n\n<hr><h3><a name=\"lua_tocfunction\"><code>lua_tocfunction</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre>\n\n<p>\nConverts a value at the given acceptable index to a C&nbsp;function.\nThat value must be a C&nbsp;function;\notherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tointeger\"><code>lua_tointeger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index\nto the signed integral type <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#2.2.1\">&sect;2.2.1</a>);\notherwise, <a href=\"#lua_tointeger\"><code>lua_tointeger</code></a> returns&nbsp;0.\n\n\n<p>\nIf the number is not an integer,\nit is truncated in some non-specified way.\n\n\n\n\n\n<hr><h3><a name=\"lua_tolstring\"><code>lua_tolstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index to a C&nbsp;string.\nIf <code>len</code> is not <code>NULL</code>,\nit also sets <code>*len</code> with the string length.\nThe Lua value must be a string or a number;\notherwise, the function returns <code>NULL</code>.\nIf the value is a number,\nthen <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> also\n<em>changes the actual value in the stack to a string</em>.\n(This change confuses <a href=\"#lua_next\"><code>lua_next</code></a>\nwhen <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> is applied to keys during a table traversal.)\n\n\n<p>\n<a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> returns a fully aligned pointer\nto a string inside the Lua state.\nThis string always has a zero ('<code>\\0</code>')\nafter its last character (as in&nbsp;C),\nbut can contain other zeros in its body.\nBecause Lua has garbage collection,\nthere is no guarantee that the pointer returned by <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a>\nwill be valid after the corresponding value is removed from the stack.\n\n\n\n\n\n<hr><h3><a name=\"lua_tonumber\"><code>lua_tonumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Number lua_tonumber (lua_State *L, int index);</pre>\n\n<p>\nConverts the Lua value at the given acceptable index\nto the C&nbsp;type <a href=\"#lua_Number\"><code>lua_Number</code></a> (see <a href=\"#lua_Number\"><code>lua_Number</code></a>).\nThe Lua value must be a number or a string convertible to a number\n(see <a href=\"#2.2.1\">&sect;2.2.1</a>);\notherwise, <a href=\"#lua_tonumber\"><code>lua_tonumber</code></a> returns&nbsp;0.\n\n\n\n\n\n<hr><h3><a name=\"lua_topointer\"><code>lua_topointer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>const void *lua_topointer (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given acceptable index to a generic\nC&nbsp;pointer (<code>void*</code>).\nThe value can be a userdata, a table, a thread, or a function;\notherwise, <a href=\"#lua_topointer\"><code>lua_topointer</code></a> returns <code>NULL</code>.\nDifferent objects will give different pointers.\nThere is no way to convert the pointer back to its original value.\n\n\n<p>\nTypically this function is used only for debug information.\n\n\n\n\n\n<hr><h3><a name=\"lua_tostring\"><code>lua_tostring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>const char *lua_tostring (lua_State *L, int index);</pre>\n\n<p>\nEquivalent to <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_tothread\"><code>lua_tothread</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_State *lua_tothread (lua_State *L, int index);</pre>\n\n<p>\nConverts the value at the given acceptable index to a Lua thread\n(represented as <code>lua_State*</code>).\nThis value must be a thread;\notherwise, the function returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_touserdata\"><code>lua_touserdata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void *lua_touserdata (lua_State *L, int index);</pre>\n\n<p>\nIf the value at the given acceptable index is a full userdata,\nreturns its block address.\nIf the value is a light userdata,\nreturns its pointer.\nOtherwise, returns <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_type\"><code>lua_type</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_type (lua_State *L, int index);</pre>\n\n<p>\nReturns the type of the value in the given acceptable index,\nor <code>LUA_TNONE</code> for a non-valid index\n(that is, an index to an \"empty\" stack position).\nThe types returned by <a href=\"#lua_type\"><code>lua_type</code></a> are coded by the following constants\ndefined in <code>lua.h</code>:\n<code>LUA_TNIL</code>,\n<code>LUA_TNUMBER</code>,\n<code>LUA_TBOOLEAN</code>,\n<code>LUA_TSTRING</code>,\n<code>LUA_TTABLE</code>,\n<code>LUA_TFUNCTION</code>,\n<code>LUA_TUSERDATA</code>,\n<code>LUA_TTHREAD</code>,\nand\n<code>LUA_TLIGHTUSERDATA</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_typename\"><code>lua_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>const char *lua_typename  (lua_State *L, int tp);</pre>\n\n<p>\nReturns the name of the type encoded by the value <code>tp</code>,\nwhich must be one the values returned by <a href=\"#lua_type\"><code>lua_type</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"lua_Writer\"><code>lua_Writer</code></a></h3>\n<pre>typedef int (*lua_Writer) (lua_State *L,\n                           const void* p,\n                           size_t sz,\n                           void* ud);</pre>\n\n<p>\nThe type of the writer function used by <a href=\"#lua_dump\"><code>lua_dump</code></a>.\nEvery time it produces another piece of chunk,\n<a href=\"#lua_dump\"><code>lua_dump</code></a> calls the writer,\npassing along the buffer to be written (<code>p</code>),\nits size (<code>sz</code>),\nand the <code>data</code> parameter supplied to <a href=\"#lua_dump\"><code>lua_dump</code></a>.\n\n\n<p>\nThe writer returns an error code:\n0&nbsp;means no errors;\nany other value means an error and stops <a href=\"#lua_dump\"><code>lua_dump</code></a> from\ncalling the writer again.\n\n\n\n\n\n<hr><h3><a name=\"lua_xmove\"><code>lua_xmove</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre>\n\n<p>\nExchange values between different threads of the <em>same</em> global state.\n\n\n<p>\nThis function pops <code>n</code> values from the stack <code>from</code>,\nand pushes them onto the stack <code>to</code>.\n\n\n\n\n\n<hr><h3><a name=\"lua_yield\"><code>lua_yield</code></a></h3><p>\n<span class=\"apii\">[-?, +?, <em>-</em>]</span>\n<pre>int lua_yield  (lua_State *L, int nresults);</pre>\n\n<p>\nYields a coroutine.\n\n\n<p>\nThis function should only be called as the\nreturn expression of a C&nbsp;function, as follows:\n\n<pre>\n     return lua_yield (L, nresults);\n</pre><p>\nWhen a C&nbsp;function calls <a href=\"#lua_yield\"><code>lua_yield</code></a> in that way,\nthe running coroutine suspends its execution,\nand the call to <a href=\"#lua_resume\"><code>lua_resume</code></a> that started this coroutine returns.\nThe parameter <code>nresults</code> is the number of values from the stack\nthat are passed as results to <a href=\"#lua_resume\"><code>lua_resume</code></a>.\n\n\n\n\n\n\n\n<h2>3.8 - <a name=\"3.8\">The Debug Interface</a></h2>\n\n<p>\nLua has no built-in debugging facilities.\nInstead, it offers a special interface\nby means of functions and <em>hooks</em>.\nThis interface allows the construction of different\nkinds of debuggers, profilers, and other tools\nthat need \"inside information\" from the interpreter.\n\n\n\n<hr><h3><a name=\"lua_Debug\"><code>lua_Debug</code></a></h3>\n<pre>typedef struct lua_Debug {\n  int event;\n  const char *name;           /* (n) */\n  const char *namewhat;       /* (n) */\n  const char *what;           /* (S) */\n  const char *source;         /* (S) */\n  int currentline;            /* (l) */\n  int nups;                   /* (u) number of upvalues */\n  int linedefined;            /* (S) */\n  int lastlinedefined;        /* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  <em>other fields</em>\n} lua_Debug;</pre>\n\n<p>\nA structure used to carry different pieces of\ninformation about an active function.\n<a href=\"#lua_getstack\"><code>lua_getstack</code></a> fills only the private part\nof this structure, for later use.\nTo fill the other fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> with useful information,\ncall <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nThe fields of <a href=\"#lua_Debug\"><code>lua_Debug</code></a> have the following meaning:\n\n<ul>\n\n<li><b><code>source</code>:</b>\nIf the function was defined in a string,\nthen <code>source</code> is that string.\nIf the function was defined in a file,\nthen <code>source</code> starts with a '<code>@</code>' followed by the file name.\n</li>\n\n<li><b><code>short_src</code>:</b>\na \"printable\" version of <code>source</code>, to be used in error messages.\n</li>\n\n<li><b><code>linedefined</code>:</b>\nthe line number where the definition of the function starts.\n</li>\n\n<li><b><code>lastlinedefined</code>:</b>\nthe line number where the definition of the function ends.\n</li>\n\n<li><b><code>what</code>:</b>\nthe string <code>\"Lua\"</code> if the function is a Lua function,\n<code>\"C\"</code> if it is a C&nbsp;function,\n<code>\"main\"</code> if it is the main part of a chunk,\nand <code>\"tail\"</code> if it was a function that did a tail call.\nIn the latter case,\nLua has no other information about the function.\n</li>\n\n<li><b><code>currentline</code>:</b>\nthe current line where the given function is executing.\nWhen no line information is available,\n<code>currentline</code> is set to -1.\n</li>\n\n<li><b><code>name</code>:</b>\na reasonable name for the given function.\nBecause functions in Lua are first-class values,\nthey do not have a fixed name:\nsome functions can be the value of multiple global variables,\nwhile others can be stored only in a table field.\nThe <code>lua_getinfo</code> function checks how the function was\ncalled to find a suitable name.\nIf it cannot find a name,\nthen <code>name</code> is set to <code>NULL</code>.\n</li>\n\n<li><b><code>namewhat</code>:</b>\nexplains the <code>name</code> field.\nThe value of <code>namewhat</code> can be\n<code>\"global\"</code>, <code>\"local\"</code>, <code>\"method\"</code>,\n<code>\"field\"</code>, <code>\"upvalue\"</code>, or <code>\"\"</code> (the empty string),\naccording to how the function was called.\n(Lua uses the empty string when no other option seems to apply.)\n</li>\n\n<li><b><code>nups</code>:</b>\nthe number of upvalues of the function.\n</li>\n\n</ul>\n\n\n\n\n<hr><h3><a name=\"lua_gethook\"><code>lua_gethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_Hook lua_gethook (lua_State *L);</pre>\n\n<p>\nReturns the current hook function.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookcount\"><code>lua_gethookcount</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_gethookcount (lua_State *L);</pre>\n\n<p>\nReturns the current hook count.\n\n\n\n\n\n<hr><h3><a name=\"lua_gethookmask\"><code>lua_gethookmask</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_gethookmask (lua_State *L);</pre>\n\n<p>\nReturns the current hook mask.\n\n\n\n\n\n<hr><h3><a name=\"lua_getinfo\"><code>lua_getinfo</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +(0|1|2), <em>m</em>]</span>\n<pre>int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);</pre>\n\n<p>\nReturns information about a specific function or function invocation.\n\n\n<p>\nTo get information about a function invocation,\nthe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\n\n\n<p>\nTo get information about a function you push it onto the stack\nand start the <code>what</code> string with the character '<code>&gt;</code>'.\n(In that case,\n<code>lua_getinfo</code> pops the function in the top of the stack.)\nFor instance, to know in which line a function <code>f</code> was defined,\nyou can write the following code:\n\n<pre>\n     lua_Debug ar;\n     lua_getfield(L, LUA_GLOBALSINDEX, \"f\");  /* get global 'f' */\n     lua_getinfo(L, \"&gt;S\", &amp;ar);\n     printf(\"%d\\n\", ar.linedefined);\n</pre>\n\n<p>\nEach character in the string <code>what</code>\nselects some fields of the structure <code>ar</code> to be filled or\na value to be pushed on the stack:\n\n<ul>\n\n<li><b>'<code>n</code>':</b> fills in the field <code>name</code> and <code>namewhat</code>;\n</li>\n\n<li><b>'<code>S</code>':</b>\nfills in the fields <code>source</code>, <code>short_src</code>,\n<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;\n</li>\n\n<li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>;\n</li>\n\n<li><b>'<code>u</code>':</b> fills in the field <code>nups</code>;\n</li>\n\n<li><b>'<code>f</code>':</b>\npushes onto the stack the function that is\nrunning at the given level;\n</li>\n\n<li><b>'<code>L</code>':</b>\npushes onto the stack a table whose indices are the\nnumbers of the lines that are valid on the function.\n(A <em>valid line</em> is a line with some associated code,\nthat is, a line where you can put a break point.\nNon-valid lines include empty lines and comments.)\n</li>\n\n</ul>\n\n<p>\nThis function returns 0 on error\n(for instance, an invalid option in <code>what</code>).\n\n\n\n\n\n<hr><h3><a name=\"lua_getlocal\"><code>lua_getlocal</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre>\n\n<p>\nGets information about a local variable of a given activation record.\nThe parameter <code>ar</code> must be a valid activation record that was\nfilled by a previous call to <a href=\"#lua_getstack\"><code>lua_getstack</code></a> or\ngiven as argument to a hook (see <a href=\"#lua_Hook\"><code>lua_Hook</code></a>).\nThe index <code>n</code> selects which local variable to inspect\n(1 is the first parameter or active local variable, and so on,\nuntil the last active local variable).\n<a href=\"#lua_getlocal\"><code>lua_getlocal</code></a> pushes the variable's value onto the stack\nand returns its name.\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parentheses)\nrepresent internal variables\n(loop control variables, temporaries, and C&nbsp;function locals).\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_getstack\"><code>lua_getstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre>\n\n<p>\nGet information about the interpreter runtime stack.\n\n\n<p>\nThis function fills parts of a <a href=\"#lua_Debug\"><code>lua_Debug</code></a> structure with\nan identification of the <em>activation record</em>\nof the function executing at a given level.\nLevel&nbsp;0 is the current running function,\nwhereas level <em>n+1</em> is the function that has called level <em>n</em>.\nWhen there are no errors, <a href=\"#lua_getstack\"><code>lua_getstack</code></a> returns 1;\nwhen called with a level greater than the stack depth,\nit returns 0.\n\n\n\n\n\n<hr><h3><a name=\"lua_getupvalue\"><code>lua_getupvalue</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>-</em>]</span>\n<pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nGets information about a closure's upvalue.\n(For Lua functions,\nupvalues are the external local variables that the function uses,\nand that are consequently included in its closure.)\n<a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a> gets the index <code>n</code> of an upvalue,\npushes the upvalue's value onto the stack,\nand returns its name.\n<code>funcindex</code> points to the closure in the stack.\n(Upvalues have no particular order,\nas they are active through the whole function.\nSo, they are numbered in an arbitrary order.)\n\n\n<p>\nReturns <code>NULL</code> (and pushes nothing)\nwhen the index is greater than the number of upvalues.\nFor C&nbsp;functions, this function uses the empty string <code>\"\"</code>\nas a name for all upvalues.\n\n\n\n\n\n<hr><h3><a name=\"lua_Hook\"><code>lua_Hook</code></a></h3>\n<pre>typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);</pre>\n\n<p>\nType for debugging hook functions.\n\n\n<p>\nWhenever a hook is called, its <code>ar</code> argument has its field\n<code>event</code> set to the specific event that triggered the hook.\nLua identifies these events with the following constants:\n<a name=\"pdf-LUA_HOOKCALL\"><code>LUA_HOOKCALL</code></a>, <a name=\"pdf-LUA_HOOKRET\"><code>LUA_HOOKRET</code></a>,\n<a name=\"pdf-LUA_HOOKTAILRET\"><code>LUA_HOOKTAILRET</code></a>, <a name=\"pdf-LUA_HOOKLINE\"><code>LUA_HOOKLINE</code></a>,\nand <a name=\"pdf-LUA_HOOKCOUNT\"><code>LUA_HOOKCOUNT</code></a>.\nMoreover, for line events, the field <code>currentline</code> is also set.\nTo get the value of any other field in <code>ar</code>,\nthe hook must call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\nFor return events, <code>event</code> can be <code>LUA_HOOKRET</code>,\nthe normal value, or <code>LUA_HOOKTAILRET</code>.\nIn the latter case, Lua is simulating a return from\na function that did a tail call;\nin this case, it is useless to call <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>.\n\n\n<p>\nWhile Lua is running a hook, it disables other calls to hooks.\nTherefore, if a hook calls back Lua to execute a function or a chunk,\nthis execution occurs without any calls to hooks.\n\n\n\n\n\n<hr><h3><a name=\"lua_sethook\"><code>lua_sethook</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre>\n\n<p>\nSets the debugging hook function.\n\n\n<p>\nArgument <code>f</code> is the hook function.\n<code>mask</code> specifies on which events the hook will be called:\nit is formed by a bitwise or of the constants\n<a name=\"pdf-LUA_MASKCALL\"><code>LUA_MASKCALL</code></a>,\n<a name=\"pdf-LUA_MASKRET\"><code>LUA_MASKRET</code></a>,\n<a name=\"pdf-LUA_MASKLINE\"><code>LUA_MASKLINE</code></a>,\nand <a name=\"pdf-LUA_MASKCOUNT\"><code>LUA_MASKCOUNT</code></a>.\nThe <code>count</code> argument is only meaningful when the mask\nincludes <code>LUA_MASKCOUNT</code>.\nFor each event, the hook is called as explained below:\n\n<ul>\n\n<li><b>The call hook:</b> is called when the interpreter calls a function.\nThe hook is called just after Lua enters the new function,\nbefore the function gets its arguments.\n</li>\n\n<li><b>The return hook:</b> is called when the interpreter returns from a function.\nThe hook is called just before Lua leaves the function.\nYou have no access to the values to be returned by the function.\n</li>\n\n<li><b>The line hook:</b> is called when the interpreter is about to\nstart the execution of a new line of code,\nor when it jumps back in the code (even to the same line).\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n<li><b>The count hook:</b> is called after the interpreter executes every\n<code>count</code> instructions.\n(This event only happens while Lua is executing a Lua function.)\n</li>\n\n</ul>\n\n<p>\nA hook is disabled by setting <code>mask</code> to zero.\n\n\n\n\n\n<hr><h3><a name=\"lua_setlocal\"><code>lua_setlocal</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, <em>-</em>]</span>\n<pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre>\n\n<p>\nSets the value of a local variable of a given activation record.\nParameters <code>ar</code> and <code>n</code> are as in <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>\n(see <a href=\"#lua_getlocal\"><code>lua_getlocal</code></a>).\n<a href=\"#lua_setlocal\"><code>lua_setlocal</code></a> assigns the value at the top of the stack\nto the variable and returns its name.\nIt also pops the value from the stack.\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than\nthe number of active local variables.\n\n\n\n\n\n<hr><h3><a name=\"lua_setupvalue\"><code>lua_setupvalue</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +0, <em>-</em>]</span>\n<pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre>\n\n<p>\nSets the value of a closure's upvalue.\nIt assigns the value at the top of the stack\nto the upvalue and returns its name.\nIt also pops the value from the stack.\nParameters <code>funcindex</code> and <code>n</code> are as in the <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>\n(see <a href=\"#lua_getupvalue\"><code>lua_getupvalue</code></a>).\n\n\n<p>\nReturns <code>NULL</code> (and pops nothing)\nwhen the index is greater than the number of upvalues.\n\n\n\n\n\n\n\n<h1>4 - <a name=\"4\">The Auxiliary Library</a></h1>\n\n<p>\n\nThe <em>auxiliary library</em> provides several convenient functions\nto interface C with Lua.\nWhile the basic API provides the primitive functions for all \ninteractions between C and Lua,\nthe auxiliary library provides higher-level functions for some\ncommon tasks.\n\n\n<p>\nAll functions from the auxiliary library\nare defined in header file <code>lauxlib.h</code> and\nhave a prefix <code>luaL_</code>.\n\n\n<p>\nAll functions in the auxiliary library are built on\ntop of the basic API,\nand so they provide nothing that cannot be done with this API.\n\n\n<p>\nSeveral functions in the auxiliary library are used to\ncheck C&nbsp;function arguments.\nTheir names are always <code>luaL_check*</code> or <code>luaL_opt*</code>.\nAll of these functions throw an error if the check is not satisfied.\nBecause the error message is formatted for arguments\n(e.g., \"<code>bad argument #1</code>\"),\nyou should not use these functions for other stack values.\n\n\n\n<h2>4.1 - <a name=\"4.1\">Functions and Types</a></h2>\n\n<p>\nHere we list all functions and types from the auxiliary library\nin alphabetical order.\n\n\n\n<hr><h3><a name=\"luaL_addchar\"><code>luaL_addchar</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addchar (luaL_Buffer *B, char c);</pre>\n\n<p>\nAdds the character <code>c</code> to the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addlstring\"><code>luaL_addlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);</pre>\n\n<p>\nAdds the string pointed to by <code>s</code> with length <code>l</code> to\nthe buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string may contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addsize\"><code>luaL_addsize</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre>\n\n<p>\nAdds to the buffer <code>B</code> (see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>)\na string of length <code>n</code> previously copied to the\nbuffer area (see <a href=\"#luaL_prepbuffer\"><code>luaL_prepbuffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_addstring\"><code>luaL_addstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_addstring (luaL_Buffer *B, const char *s);</pre>\n\n<p>\nAdds the zero-terminated string pointed to by <code>s</code>\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nThe string may not contain embedded zeros.\n\n\n\n\n\n<hr><h3><a name=\"luaL_addvalue\"><code>luaL_addvalue</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>void luaL_addvalue (luaL_Buffer *B);</pre>\n\n<p>\nAdds the value at the top of the stack\nto the buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nPops the value.\n\n\n<p>\nThis is the only function on string buffers that can (and must)\nbe called with an extra element on the stack,\nwhich is the value to be added to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_argcheck\"><code>luaL_argcheck</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_argcheck (lua_State *L,\n                    int cond,\n                    int narg,\n                    const char *extramsg);</pre>\n\n<p>\nChecks whether <code>cond</code> is true.\nIf not, raises an error with the following message,\nwhere <code>func</code> is retrieved from the call stack:\n\n<pre>\n     bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)\n</pre>\n\n\n\n\n<hr><h3><a name=\"luaL_argerror\"><code>luaL_argerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre>\n\n<p>\nRaises an error with the following message,\nwhere <code>func</code> is retrieved from the call stack:\n\n<pre>\n     bad argument #&lt;narg&gt; to &lt;func&gt; (&lt;extramsg&gt;)\n</pre>\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_argerror(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Buffer\"><code>luaL_Buffer</code></a></h3>\n<pre>typedef struct luaL_Buffer luaL_Buffer;</pre>\n\n<p>\nType for a <em>string buffer</em>.\n\n\n<p>\nA string buffer allows C&nbsp;code to build Lua strings piecemeal.\nIts pattern of use is as follows:\n\n<ul>\n\n<li>First you declare a variable <code>b</code> of type <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>.</li>\n\n<li>Then you initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>\n\n<li>\nThen you add string pieces to the buffer calling any of\nthe <code>luaL_add*</code> functions.\n</li>\n\n<li>\nYou finish by calling <code>luaL_pushresult(&amp;b)</code>.\nThis call leaves the final string on the top of the stack.\n</li>\n\n</ul>\n\n<p>\nDuring its normal operation,\na string buffer uses a variable number of stack slots.\nSo, while using a buffer, you cannot assume that you know where\nthe top of the stack is.\nYou can use the stack between successive calls to buffer operations\nas long as that use is balanced;\nthat is,\nwhen you call a buffer operation,\nthe stack is at the same level\nit was immediately after the previous buffer operation.\n(The only exception to this rule is <a href=\"#luaL_addvalue\"><code>luaL_addvalue</code></a>.)\nAfter calling <a href=\"#luaL_pushresult\"><code>luaL_pushresult</code></a> the stack is back to its\nlevel when the buffer was initialized,\nplus the final string on its top.\n\n\n\n\n\n<hr><h3><a name=\"luaL_buffinit\"><code>luaL_buffinit</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre>\n\n<p>\nInitializes a buffer <code>B</code>.\nThis function does not allocate any space;\nthe buffer must be declared as a variable\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_callmeta\"><code>luaL_callmeta</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>e</em>]</span>\n<pre>int luaL_callmeta (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nCalls a metamethod.\n\n\n<p>\nIf the object at index <code>obj</code> has a metatable and this\nmetatable has a field <code>e</code>,\nthis function calls this field and passes the object as its only argument.\nIn this case this function returns 1 and pushes onto the\nstack the value returned by the call.\nIf there is no metatable or no metamethod,\nthis function returns 0 (without pushing any value on the stack).\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkany\"><code>luaL_checkany</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkany (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function has an argument\nof any type (including <b>nil</b>) at position <code>narg</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkint\"><code>luaL_checkint</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkint (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number cast to an <code>int</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkinteger\"><code>luaL_checkinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_checkinteger (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklong\"><code>luaL_checklong</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>long luaL_checklong (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number cast to a <code>long</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checklstring\"><code>luaL_checklstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checklstring (lua_State *L, int narg, size_t *l);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a string\nand returns this string;\nif <code>l</code> is not <code>NULL</code> fills <code>*l</code>\nwith the string's length.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checknumber\"><code>luaL_checknumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_checknumber (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a number\nand returns this number.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkoption\"><code>luaL_checkoption</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_checkoption (lua_State *L,\n                      int narg,\n                      const char *def,\n                      const char *const lst[]);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a string and\nsearches for this string in the array <code>lst</code>\n(which must be NULL-terminated).\nReturns the index in the array where the string was found.\nRaises an error if the argument is not a string or\nif the string cannot be found.\n\n\n<p>\nIf <code>def</code> is not <code>NULL</code>,\nthe function uses <code>def</code> as a default value when\nthere is no argument <code>narg</code> or if this argument is <b>nil</b>.\n\n\n<p>\nThis is a useful function for mapping strings to C&nbsp;enums.\n(The usual convention in Lua libraries is\nto use strings instead of numbers to select options.)\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstack\"><code>luaL_checkstack</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checkstack (lua_State *L, int sz, const char *msg);</pre>\n\n<p>\nGrows the stack size to <code>top + sz</code> elements,\nraising an error if the stack cannot grow to that size.\n<code>msg</code> is an additional text to go into the error message.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkstring\"><code>luaL_checkstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_checkstring (lua_State *L, int narg);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a string\nand returns this string.\n\n\n<p>\nThis function uses <a href=\"#lua_tolstring\"><code>lua_tolstring</code></a> to get its result,\nso all conversions and caveats of that function apply here.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checktype\"><code>luaL_checktype</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void luaL_checktype (lua_State *L, int narg, int t);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> has type <code>t</code>.\nSee <a href=\"#lua_type\"><code>lua_type</code></a> for the encoding of types for <code>t</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_checkudata\"><code>luaL_checkudata</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>void *luaL_checkudata (lua_State *L, int narg, const char *tname);</pre>\n\n<p>\nChecks whether the function argument <code>narg</code> is a userdata\nof the type <code>tname</code> (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_dofile\"><code>luaL_dofile</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>m</em>]</span>\n<pre>int luaL_dofile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads and runs the given file.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns 0 if there are no errors\nor 1 in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_dostring\"><code>luaL_dostring</code></a></h3><p>\n<span class=\"apii\">[-0, +?, <em>m</em>]</span>\n<pre>int luaL_dostring (lua_State *L, const char *str);</pre>\n\n<p>\nLoads and runs the given string.\nIt is defined as the following macro:\n\n<pre>\n     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))\n</pre><p>\nIt returns 0 if there are no errors\nor 1 in case of errors.\n\n\n\n\n\n<hr><h3><a name=\"luaL_error\"><code>luaL_error</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_error (lua_State *L, const char *fmt, ...);</pre>\n\n<p>\nRaises an error.\nThe error message format is given by <code>fmt</code>\nplus any extra arguments,\nfollowing the same rules of <a href=\"#lua_pushfstring\"><code>lua_pushfstring</code></a>.\nIt also adds at the beginning of the message the file name and\nthe line number where the error occurred,\nif this information is available.\n\n\n<p>\nThis function never returns,\nbut it is an idiom to use it in C&nbsp;functions\nas <code>return luaL_error(<em>args</em>)</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetafield\"><code>luaL_getmetafield</code></a></h3><p>\n<span class=\"apii\">[-0, +(0|1), <em>m</em>]</span>\n<pre>int luaL_getmetafield (lua_State *L, int obj, const char *e);</pre>\n\n<p>\nPushes onto the stack the field <code>e</code> from the metatable\nof the object at index <code>obj</code>.\nIf the object does not have a metatable,\nor if the metatable does not have this field,\nreturns 0 and pushes nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_getmetatable\"><code>luaL_getmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>-</em>]</span>\n<pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nPushes onto the stack the metatable associated with name <code>tname</code>\nin the registry (see <a href=\"#luaL_newmetatable\"><code>luaL_newmetatable</code></a>).\n\n\n\n\n\n<hr><h3><a name=\"luaL_gsub\"><code>luaL_gsub</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>const char *luaL_gsub (lua_State *L,\n                       const char *s,\n                       const char *p,\n                       const char *r);</pre>\n\n<p>\nCreates a copy of string <code>s</code> by replacing\nany occurrence of the string <code>p</code>\nwith the string <code>r</code>.\nPushes the resulting string on the stack and returns it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadbuffer\"><code>luaL_loadbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadbuffer (lua_State *L,\n                     const char *buff,\n                     size_t sz,\n                     const char *name);</pre>\n\n<p>\nLoads a buffer as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the\nbuffer pointed to by <code>buff</code> with size <code>sz</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n<code>name</code> is the chunk name,\nused for debug information and error messages.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadfile\"><code>luaL_loadfile</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre>\n\n<p>\nLoads a file as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in the file\nnamed <code>filename</code>.\nIf <code>filename</code> is <code>NULL</code>,\nthen it loads from the standard input.\nThe first line in the file is ignored if it starts with a <code>#</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>,\nbut it has an extra error code <a name=\"pdf-LUA_ERRFILE\"><code>LUA_ERRFILE</code></a>\nif it cannot open/read the file.\n\n\n<p>\nAs <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_loadstring\"><code>luaL_loadstring</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_loadstring (lua_State *L, const char *s);</pre>\n\n<p>\nLoads a string as a Lua chunk.\nThis function uses <a href=\"#lua_load\"><code>lua_load</code></a> to load the chunk in\nthe zero-terminated string <code>s</code>.\n\n\n<p>\nThis function returns the same results as <a href=\"#lua_load\"><code>lua_load</code></a>.\n\n\n<p>\nAlso as <a href=\"#lua_load\"><code>lua_load</code></a>, this function only loads the chunk;\nit does not run it.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newmetatable\"><code>luaL_newmetatable</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>int luaL_newmetatable (lua_State *L, const char *tname);</pre>\n\n<p>\nIf the registry already has the key <code>tname</code>,\nreturns 0.\nOtherwise,\ncreates a new table to be used as a metatable for userdata,\nadds it to the registry with key <code>tname</code>,\nand returns 1.\n\n\n<p>\nIn both cases pushes onto the stack the final value associated\nwith <code>tname</code> in the registry.\n\n\n\n\n\n<hr><h3><a name=\"luaL_newstate\"><code>luaL_newstate</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>lua_State *luaL_newstate (void);</pre>\n\n<p>\nCreates a new Lua state.\nIt calls <a href=\"#lua_newstate\"><code>lua_newstate</code></a> with an\nallocator based on the standard&nbsp;C <code>realloc</code> function\nand then sets a panic function (see <a href=\"#lua_atpanic\"><code>lua_atpanic</code></a>) that prints\nan error message to the standard error output in case of fatal\nerrors.\n\n\n<p>\nReturns the new state,\nor <code>NULL</code> if there is a memory allocation error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_openlibs\"><code>luaL_openlibs</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>m</em>]</span>\n<pre>void luaL_openlibs (lua_State *L);</pre>\n\n<p>\nOpens all standard Lua libraries into the given state.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optint\"><code>luaL_optint</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_optint (lua_State *L, int narg, int d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number cast to an <code>int</code>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optinteger\"><code>luaL_optinteger</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Integer luaL_optinteger (lua_State *L,\n                             int narg,\n                             lua_Integer d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number cast to a <a href=\"#lua_Integer\"><code>lua_Integer</code></a>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlong\"><code>luaL_optlong</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>long luaL_optlong (lua_State *L, int narg, long d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number cast to a <code>long</code>.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optlstring\"><code>luaL_optlstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optlstring (lua_State *L,\n                             int narg,\n                             const char *d,\n                             size_t *l);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n<p>\nIf <code>l</code> is not <code>NULL</code>,\nfills the position <code>*l</code> with the results's length.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optnumber\"><code>luaL_optnumber</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a number,\nreturns this number.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_optstring\"><code>luaL_optstring</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>const char *luaL_optstring (lua_State *L,\n                            int narg,\n                            const char *d);</pre>\n\n<p>\nIf the function argument <code>narg</code> is a string,\nreturns this string.\nIf this argument is absent or is <b>nil</b>,\nreturns <code>d</code>.\nOtherwise, raises an error.\n\n\n\n\n\n<hr><h3><a name=\"luaL_prepbuffer\"><code>luaL_prepbuffer</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>\n\n<p>\nReturns an address to a space of size <a name=\"pdf-LUAL_BUFFERSIZE\"><code>LUAL_BUFFERSIZE</code></a>\nwhere you can copy a string to be added to buffer <code>B</code>\n(see <a href=\"#luaL_Buffer\"><code>luaL_Buffer</code></a>).\nAfter copying the string into this space you must call\n<a href=\"#luaL_addsize\"><code>luaL_addsize</code></a> with the size of the string to actually add \nit to the buffer.\n\n\n\n\n\n<hr><h3><a name=\"luaL_pushresult\"><code>luaL_pushresult</code></a></h3><p>\n<span class=\"apii\">[-?, +1, <em>m</em>]</span>\n<pre>void luaL_pushresult (luaL_Buffer *B);</pre>\n\n<p>\nFinishes the use of buffer <code>B</code> leaving the final string on\nthe top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_ref\"><code>luaL_ref</code></a></h3><p>\n<span class=\"apii\">[-1, +0, <em>m</em>]</span>\n<pre>int luaL_ref (lua_State *L, int t);</pre>\n\n<p>\nCreates and returns a <em>reference</em>,\nin the table at index <code>t</code>,\nfor the object at the top of the stack (and pops the object).\n\n\n<p>\nA reference is a unique integer key.\nAs long as you do not manually add integer keys into table <code>t</code>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.\nYou can retrieve an object referred by reference <code>r</code>\nby calling <code>lua_rawgeti(L, t, r)</code>.\nFunction <a href=\"#luaL_unref\"><code>luaL_unref</code></a> frees a reference and its associated object.\n\n\n<p>\nIf the object at the top of the stack is <b>nil</b>,\n<a href=\"#luaL_ref\"><code>luaL_ref</code></a> returns the constant <a name=\"pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>.\nThe constant <a name=\"pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> is guaranteed to be different\nfrom any reference returned by <a href=\"#luaL_ref\"><code>luaL_ref</code></a>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_Reg\"><code>luaL_Reg</code></a></h3>\n<pre>typedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;</pre>\n\n<p>\nType for arrays of functions to be registered by\n<a href=\"#luaL_register\"><code>luaL_register</code></a>.\n<code>name</code> is the function name and <code>func</code> is a pointer to\nthe function.\nAny array of <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a> must end with an sentinel entry\nin which both <code>name</code> and <code>func</code> are <code>NULL</code>.\n\n\n\n\n\n<hr><h3><a name=\"luaL_register\"><code>luaL_register</code></a></h3><p>\n<span class=\"apii\">[-(0|1), +1, <em>m</em>]</span>\n<pre>void luaL_register (lua_State *L,\n                    const char *libname,\n                    const luaL_Reg *l);</pre>\n\n<p>\nOpens a library.\n\n\n<p>\nWhen called with <code>libname</code> equal to <code>NULL</code>,\nit simply registers all functions in the list <code>l</code>\n(see <a href=\"#luaL_Reg\"><code>luaL_Reg</code></a>) into the table on the top of the stack.\n\n\n<p>\nWhen called with a non-null <code>libname</code>,\n<code>luaL_register</code> creates a new table <code>t</code>,\nsets it as the value of the global variable <code>libname</code>,\nsets it as the value of <code>package.loaded[libname]</code>,\nand registers on it all functions in the list <code>l</code>.\nIf there is a table in <code>package.loaded[libname]</code> or in\nvariable <code>libname</code>,\nreuses this table instead of creating a new one.\n\n\n<p>\nIn any case the function leaves the table\non the top of the stack.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typename\"><code>luaL_typename</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>const char *luaL_typename (lua_State *L, int index);</pre>\n\n<p>\nReturns the name of the type of the value at the given index.\n\n\n\n\n\n<hr><h3><a name=\"luaL_typerror\"><code>luaL_typerror</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>v</em>]</span>\n<pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre>\n\n<p>\nGenerates an error with a message like the following:\n\n<pre>\n     <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>)\n</pre><p>\nwhere <code><em>location</em></code> is produced by <a href=\"#luaL_where\"><code>luaL_where</code></a>,\n<code><em>func</em></code> is the name of the current function,\nand <code><em>rt</em></code> is the type name of the actual argument.\n\n\n\n\n\n<hr><h3><a name=\"luaL_unref\"><code>luaL_unref</code></a></h3><p>\n<span class=\"apii\">[-0, +0, <em>-</em>]</span>\n<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>\n\n<p>\nReleases reference <code>ref</code> from the table at index <code>t</code>\n(see <a href=\"#luaL_ref\"><code>luaL_ref</code></a>).\nThe entry is removed from the table,\nso that the referred object can be collected.\nThe reference <code>ref</code> is also freed to be used again.\n\n\n<p>\nIf <code>ref</code> is <a href=\"#pdf-LUA_NOREF\"><code>LUA_NOREF</code></a> or <a href=\"#pdf-LUA_REFNIL\"><code>LUA_REFNIL</code></a>,\n<a href=\"#luaL_unref\"><code>luaL_unref</code></a> does nothing.\n\n\n\n\n\n<hr><h3><a name=\"luaL_where\"><code>luaL_where</code></a></h3><p>\n<span class=\"apii\">[-0, +1, <em>m</em>]</span>\n<pre>void luaL_where (lua_State *L, int lvl);</pre>\n\n<p>\nPushes onto the stack a string identifying the current position\nof the control at level <code>lvl</code> in the call stack.\nTypically this string has the following format:\n\n<pre>\n     <em>chunkname</em>:<em>currentline</em>:\n</pre><p>\nLevel&nbsp;0 is the running function,\nlevel&nbsp;1 is the function that called the running function,\netc.\n\n\n<p>\nThis function is used to build a prefix for error messages.\n\n\n\n\n\n\n\n<h1>5 - <a name=\"5\">Standard Libraries</a></h1>\n\n<p>\nThe standard Lua libraries provide useful functions\nthat are implemented directly through the C&nbsp;API.\nSome of these functions provide essential services to the language\n(e.g., <a href=\"#pdf-type\"><code>type</code></a> and <a href=\"#pdf-getmetatable\"><code>getmetatable</code></a>);\nothers provide access to \"outside\" services (e.g., I/O);\nand others could be implemented in Lua itself,\nbut are quite useful or have critical performance requirements that\ndeserve an implementation in C (e.g., <a href=\"#pdf-table.sort\"><code>table.sort</code></a>).\n\n\n<p>\nAll libraries are implemented through the official C&nbsp;API\nand are provided as separate C&nbsp;modules.\nCurrently, Lua has the following standard libraries:\n\n<ul>\n\n<li>basic library,</li> which includes the coroutine sub-library;\n\n<li>package library;</li>\n\n<li>string manipulation;</li>\n\n<li>table manipulation;</li>\n\n<li>mathematical functions (sin, log, etc.);</li>\n\n<li>input and output;</li>\n\n<li>operating system facilities;</li>\n\n<li>debug facilities.</li>\n\n</ul><p>\nExcept for the basic and package libraries,\neach library provides all its functions as fields of a global table\nor as methods of its objects.\n\n\n<p>\nTo have access to these libraries,\nthe C&nbsp;host program should call the <a href=\"#luaL_openlibs\"><code>luaL_openlibs</code></a> function,\nwhich opens all standard libraries.\nAlternatively,\nit can open them individually by calling\n<a name=\"pdf-luaopen_base\"><code>luaopen_base</code></a> (for the basic library),\n<a name=\"pdf-luaopen_package\"><code>luaopen_package</code></a> (for the package library),\n<a name=\"pdf-luaopen_string\"><code>luaopen_string</code></a> (for the string library),\n<a name=\"pdf-luaopen_table\"><code>luaopen_table</code></a> (for the table library),\n<a name=\"pdf-luaopen_math\"><code>luaopen_math</code></a> (for the mathematical library),\n<a name=\"pdf-luaopen_io\"><code>luaopen_io</code></a> (for the I/O library),\n<a name=\"pdf-luaopen_os\"><code>luaopen_os</code></a> (for the Operating System library),\nand <a name=\"pdf-luaopen_debug\"><code>luaopen_debug</code></a> (for the debug library).\nThese functions are declared in <a name=\"pdf-lualib.h\"><code>lualib.h</code></a>\nand should not be called directly:\nyou must call them like any other Lua C&nbsp;function,\ne.g., by using <a href=\"#lua_call\"><code>lua_call</code></a>.\n\n\n\n<h2>5.1 - <a name=\"5.1\">Basic Functions</a></h2>\n\n<p>\nThe basic library provides some core functions to Lua.\nIf you do not include this library in your application,\nyou should check carefully whether you need to provide \nimplementations for some of its facilities.\n\n\n<p>\n<hr><h3><a name=\"pdf-assert\"><code>assert (v [, message])</code></a></h3>\nIssues an  error when\nthe value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);\notherwise, returns all its arguments.\n<code>message</code> is an error message;\nwhen absent, it defaults to \"assertion failed!\"\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-collectgarbage\"><code>collectgarbage (opt [, arg])</code></a></h3>\n\n\n<p>\nThis function is a generic interface to the garbage collector.\nIt performs different functions according to its first argument, <code>opt</code>:\n\n<ul>\n\n<li><b>\"stop\":</b>\nstops the garbage collector.\n</li>\n\n<li><b>\"restart\":</b>\nrestarts the garbage collector.\n</li>\n\n<li><b>\"collect\":</b>\nperforms a full garbage-collection cycle.\n</li>\n\n<li><b>\"count\":</b>\nreturns the total memory in use by Lua (in Kbytes).\n</li>\n\n<li><b>\"step\":</b>\nperforms a garbage-collection step.\nThe step \"size\" is controlled by <code>arg</code>\n(larger values mean more steps) in a non-specified way.\nIf you want to control the step size\nyou must experimentally tune the value of <code>arg</code>.\nReturns <b>true</b> if the step finished a collection cycle.\n</li>\n\n<li><b>\"setpause\":</b>\nsets <code>arg</code> as the new value for the <em>pause</em> of\nthe collector (see <a href=\"#2.10\">&sect;2.10</a>).\nReturns the previous value for <em>pause</em>.\n</li>\n\n<li><b>\"setstepmul\":</b>\nsets <code>arg</code> as the new value for the <em>step multiplier</em> of\nthe collector (see <a href=\"#2.10\">&sect;2.10</a>).\nReturns the previous value for <em>step</em>.\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-dofile\"><code>dofile (filename)</code></a></h3>\nOpens the named file and executes its contents as a Lua chunk.\nWhen called without arguments,\n<code>dofile</code> executes the contents of the standard input (<code>stdin</code>).\nReturns all values returned by the chunk.\nIn case of errors, <code>dofile</code> propagates the error\nto its caller (that is, <code>dofile</code> does not run in protected mode).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-error\"><code>error (message [, level])</code></a></h3>\nTerminates the last protected function called\nand returns <code>message</code> as the error message.\nFunction <code>error</code> never returns.\n\n\n<p>\nUsually, <code>error</code> adds some information about the error position\nat the beginning of the message.\nThe <code>level</code> argument specifies how to get the error position.\nWith level&nbsp;1 (the default), the error position is where the\n<code>error</code> function was called.\nLevel&nbsp;2 points the error to where the function\nthat called <code>error</code> was called; and so on.\nPassing a level&nbsp;0 avoids the addition of error position information\nto the message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_G\"><code>_G</code></a></h3>\nA global variable (not a function) that\nholds the global environment (that is, <code>_G._G = _G</code>).\nLua itself does not use this variable;\nchanging its value does not affect any environment,\nnor vice-versa.\n(Use <a href=\"#pdf-setfenv\"><code>setfenv</code></a> to change environments.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getfenv\"><code>getfenv ([f])</code></a></h3>\nReturns the current environment in use by the function.\n<code>f</code> can be a Lua function or a number\nthat specifies the function at that stack level:\nLevel&nbsp;1 is the function calling <code>getfenv</code>.\nIf the given function is not a Lua function,\nor if <code>f</code> is 0,\n<code>getfenv</code> returns the global environment.\nThe default for <code>f</code> is 1.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-getmetatable\"><code>getmetatable (object)</code></a></h3>\n\n\n<p>\nIf <code>object</code> does not have a metatable, returns <b>nil</b>.\nOtherwise,\nif the object's metatable has a <code>\"__metatable\"</code> field,\nreturns the associated value.\nOtherwise, returns the metatable of the given object.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-ipairs\"><code>ipairs (t)</code></a></h3>\n\n\n<p>\nReturns three values: an iterator function, the table <code>t</code>, and 0,\nso that the construction\n\n<pre>\n     for i,v in ipairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middot;&middot;&middot;,\nup to the first integer key absent from the table.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-load\"><code>load (func [, chunkname])</code></a></h3>\n\n\n<p>\nLoads a chunk using function <code>func</code> to get its pieces.\nEach call to <code>func</code> must return a string that concatenates\nwith previous results.\nA return of an empty string, <b>nil</b>, or no value signals the end of the chunk.\n\n\n<p>\nIf there are no errors, \nreturns the compiled chunk as a function;\notherwise, returns <b>nil</b> plus the error message.\nThe environment of the returned function is the global environment.\n\n\n<p>\n<code>chunkname</code> is used as the chunk name for error messages\nand debug information.\nWhen absent,\nit defaults to \"<code>=(load)</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadfile\"><code>loadfile ([filename])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from file <code>filename</code>\nor from the standard input,\nif no file name is given.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-loadstring\"><code>loadstring (string [, chunkname])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-load\"><code>load</code></a>,\nbut gets the chunk from the given string.\n\n\n<p>\nTo load and run a given string, use the idiom\n\n<pre>\n     assert(loadstring(s))()\n</pre>\n\n<p>\nWhen absent,\n<code>chunkname</code> defaults to the given string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-next\"><code>next (table [, index])</code></a></h3>\n\n\n<p>\nAllows a program to traverse all fields of a table.\nIts first argument is a table and its second argument\nis an index in this table.\n<code>next</code> returns the next index of the table\nand its associated value.\nWhen called with <b>nil</b> as its second argument,\n<code>next</code> returns an initial index\nand its associated value.\nWhen called with the last index,\nor with <b>nil</b> in an empty table,\n<code>next</code> returns <b>nil</b>.\nIf the second argument is absent, then it is interpreted as <b>nil</b>.\nIn particular,\nyou can use <code>next(t)</code> to check whether a table is empty.\n\n\n<p>\nThe order in which the indices are enumerated is not specified,\n<em>even for numeric indices</em>.\n(To traverse a table in numeric order,\nuse a numerical <b>for</b> or the <a href=\"#pdf-ipairs\"><code>ipairs</code></a> function.)\n\n\n<p>\nThe behavior of <code>next</code> is <em>undefined</em> if,\nduring the traversal,\nyou assign any value to a non-existent field in the table.\nYou may however modify existing fields.\nIn particular, you may clear existing fields.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pairs\"><code>pairs (t)</code></a></h3>\n\n\n<p>\nReturns three values: the <a href=\"#pdf-next\"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,\nso that the construction\n\n<pre>\n     for k,v in pairs(t) do <em>body</em> end\n</pre><p>\nwill iterate over all key&ndash;value pairs of table <code>t</code>.\n\n\n<p>\nSee function <a href=\"#pdf-next\"><code>next</code></a> for the caveats of modifying\nthe table during its traversal.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-pcall\"><code>pcall (f, arg1, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nCalls function <code>f</code> with\nthe given arguments in <em>protected mode</em>.\nThis means that any error inside&nbsp;<code>f</code> is not propagated;\ninstead, <code>pcall</code> catches the error\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn such case, <code>pcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error, <code>pcall</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-print\"><code>print (&middot;&middot;&middot;)</code></a></h3>\nReceives any number of arguments,\nand prints their values to <code>stdout</code>,\nusing the <a href=\"#pdf-tostring\"><code>tostring</code></a> function to convert them to strings.\n<code>print</code> is not intended for formatted output,\nbut only as a quick way to show a value,\ntypically for debugging.\nFor formatted output, use <a href=\"#pdf-string.format\"><code>string.format</code></a>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawequal\"><code>rawequal (v1, v2)</code></a></h3>\nChecks whether <code>v1</code> is equal to <code>v2</code>,\nwithout invoking any metamethod.\nReturns a boolean.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawget\"><code>rawget (table, index)</code></a></h3>\nGets the real value of <code>table[index]</code>,\nwithout invoking any metamethod.\n<code>table</code> must be a table;\n<code>index</code> may be any value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-rawset\"><code>rawset (table, index, value)</code></a></h3>\nSets the real value of <code>table[index]</code> to <code>value</code>,\nwithout invoking any metamethod.\n<code>table</code> must be a table,\n<code>index</code> any value different from <b>nil</b>,\nand <code>value</code> any Lua value.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-select\"><code>select (index, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nIf <code>index</code> is a number,\nreturns all arguments after argument number <code>index</code>.\nOtherwise, <code>index</code> must be the string <code>\"#\"</code>,\nand <code>select</code> returns the total number of extra arguments it received.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setfenv\"><code>setfenv (f, table)</code></a></h3>\n\n\n<p>\nSets the environment to be used by the given function.\n<code>f</code> can be a Lua function or a number\nthat specifies the function at that stack level:\nLevel&nbsp;1 is the function calling <code>setfenv</code>.\n<code>setfenv</code> returns the given function.\n\n\n<p>\nAs a special case, when <code>f</code> is 0 <code>setfenv</code> changes\nthe environment of the running thread.\nIn this case, <code>setfenv</code> returns no values.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-setmetatable\"><code>setmetatable (table, metatable)</code></a></h3>\n\n\n<p>\nSets the metatable for the given table.\n(You cannot change the metatable of other types from Lua, only from&nbsp;C.)\nIf <code>metatable</code> is <b>nil</b>,\nremoves the metatable of the given table.\nIf the original metatable has a <code>\"__metatable\"</code> field,\nraises an error.\n\n\n<p>\nThis function returns <code>table</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tonumber\"><code>tonumber (e [, base])</code></a></h3>\nTries to convert its argument to a number.\nIf the argument is already a number or a string convertible\nto a number, then <code>tonumber</code> returns this number;\notherwise, it returns <b>nil</b>.\n\n\n<p>\nAn optional argument specifies the base to interpret the numeral.\nThe base may be any integer between 2 and 36, inclusive.\nIn bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)\nrepresents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,\nwith '<code>Z</code>' representing 35.\nIn base 10 (the default), the number can have a decimal part,\nas well as an optional exponent part (see <a href=\"#2.1\">&sect;2.1</a>).\nIn other bases, only unsigned integers are accepted.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-tostring\"><code>tostring (e)</code></a></h3>\nReceives an argument of any type and\nconverts it to a string in a reasonable format.\nFor complete control of how numbers are converted,\nuse <a href=\"#pdf-string.format\"><code>string.format</code></a>.\n\n\n<p>\nIf the metatable of <code>e</code> has a <code>\"__tostring\"</code> field,\nthen <code>tostring</code> calls the corresponding value\nwith <code>e</code> as argument,\nand uses the result of the call as its result.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-type\"><code>type (v)</code></a></h3>\nReturns the type of its only argument, coded as a string.\nThe possible results of this function are\n\"<code>nil</code>\" (a string, not the value <b>nil</b>),\n\"<code>number</code>\",\n\"<code>string</code>\",\n\"<code>boolean</code>\",\n\"<code>table</code>\",\n\"<code>function</code>\",\n\"<code>thread</code>\",\nand \"<code>userdata</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-unpack\"><code>unpack (list [, i [, j]])</code></a></h3>\nReturns the elements from the given table.\nThis function is equivalent to\n\n<pre>\n     return list[i], list[i+1], &middot;&middot;&middot;, list[j]\n</pre><p>\nexcept that the above code can be written only for a fixed number\nof elements.\nBy default, <code>i</code> is&nbsp;1 and <code>j</code> is the length of the list,\nas defined by the length operator (see <a href=\"#2.5.5\">&sect;2.5.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-_VERSION\"><code>_VERSION</code></a></h3>\nA global variable (not a function) that\nholds a string containing the current interpreter version.\nThe current contents of this variable is \"<code>Lua 5.1</code>\".\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-xpcall\"><code>xpcall (f, err)</code></a></h3>\n\n\n<p>\nThis function is similar to <a href=\"#pdf-pcall\"><code>pcall</code></a>,\nexcept that you can set a new error handler.\n\n\n<p>\n<code>xpcall</code> calls function <code>f</code> in protected mode,\nusing <code>err</code> as the error handler.\nAny error inside <code>f</code> is not propagated;\ninstead, <code>xpcall</code> catches the error,\ncalls the <code>err</code> function with the original error object,\nand returns a status code.\nIts first result is the status code (a boolean),\nwhich is true if the call succeeds without errors.\nIn this case, <code>xpcall</code> also returns all results from the call,\nafter this first result.\nIn case of any error,\n<code>xpcall</code> returns <b>false</b> plus the result from <code>err</code>.\n\n\n\n\n\n\n\n<h2>5.2 - <a name=\"5.2\">Coroutine Manipulation</a></h2>\n\n<p>\nThe operations related to coroutines comprise a sub-library of\nthe basic library and come inside the table <a name=\"pdf-coroutine\"><code>coroutine</code></a>.\nSee <a href=\"#2.11\">&sect;2.11</a> for a general description of coroutines.\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.create\"><code>coroutine.create (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a Lua function.\nReturns this new coroutine,\nan object with type <code>\"thread\"</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.resume\"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nStarts or continues the execution of coroutine <code>co</code>.\nThe first time you resume a coroutine,\nit starts running its body.\nThe values <code>val1</code>, &middot;&middot;&middot; are passed\nas the arguments to the body function.\nIf the coroutine has yielded,\n<code>resume</code> restarts it;\nthe values <code>val1</code>, &middot;&middot;&middot; are passed\nas the results from the yield.\n\n\n<p>\nIf the coroutine runs without any errors,\n<code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>\n(if the coroutine yields) or any values returned by the body function\n(if the coroutine terminates).\nIf there is any error,\n<code>resume</code> returns <b>false</b> plus the error message.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.running\"><code>coroutine.running ()</code></a></h3>\n\n\n<p>\nReturns the running coroutine,\nor <b>nil</b> when called by the main thread.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.status\"><code>coroutine.status (co)</code></a></h3>\n\n\n<p>\nReturns the status of coroutine <code>co</code>, as a string:\n<code>\"running\"</code>,\nif the coroutine is running (that is, it called <code>status</code>);\n<code>\"suspended\"</code>, if the coroutine is suspended in a call to <code>yield</code>,\nor if it has not started running yet;\n<code>\"normal\"</code> if the coroutine is active but not running\n(that is, it has resumed another coroutine);\nand <code>\"dead\"</code> if the coroutine has finished its body function,\nor if it has stopped with an error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.wrap\"><code>coroutine.wrap (f)</code></a></h3>\n\n\n<p>\nCreates a new coroutine, with body <code>f</code>.\n<code>f</code> must be a Lua function.\nReturns a function that resumes the coroutine each time it is called.\nAny arguments passed to the function behave as the\nextra arguments to <code>resume</code>.\nReturns the same values returned by <code>resume</code>,\nexcept the first boolean.\nIn case of error, propagates the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-coroutine.yield\"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nSuspends the execution of the calling coroutine.\nThe coroutine cannot be running a C&nbsp;function,\na metamethod, or an iterator.\nAny arguments to <code>yield</code> are passed as extra results to <code>resume</code>.\n\n\n\n\n\n\n\n<h2>5.3 - <a name=\"5.3\">Modules</a></h2>\n\n<p>\nThe package library provides basic\nfacilities for loading and building modules in Lua.\nIt exports two of its functions directly in the global environment:\n<a href=\"#pdf-require\"><code>require</code></a> and <a href=\"#pdf-module\"><code>module</code></a>.\nEverything else is exported in a table <a name=\"pdf-package\"><code>package</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-module\"><code>module (name [, &middot;&middot;&middot;])</code></a></h3>\n\n\n<p>\nCreates a module.\nIf there is a table in <code>package.loaded[name]</code>,\nthis table is the module.\nOtherwise, if there is a global table <code>t</code> with the given name,\nthis table is the module.\nOtherwise creates a new table <code>t</code> and\nsets it as the value of the global <code>name</code> and\nthe value of <code>package.loaded[name]</code>.\nThis function also initializes <code>t._NAME</code> with the given name,\n<code>t._M</code> with the module (<code>t</code> itself),\nand <code>t._PACKAGE</code> with the package name\n(the full module name minus last component; see below).\nFinally, <code>module</code> sets <code>t</code> as the new environment\nof the current function and the new value of <code>package.loaded[name]</code>,\nso that <a href=\"#pdf-require\"><code>require</code></a> returns <code>t</code>.\n\n\n<p>\nIf <code>name</code> is a compound name\n(that is, one with components separated by dots),\n<code>module</code> creates (or reuses, if they already exist)\ntables for each component.\nFor instance, if <code>name</code> is <code>a.b.c</code>,\nthen <code>module</code> stores the module table in field <code>c</code> of\nfield <code>b</code> of global <code>a</code>.\n\n\n<p>\nThis function can receive optional <em>options</em> after\nthe module name,\nwhere each option is a function to be applied over the module.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-require\"><code>require (modname)</code></a></h3>\n\n\n<p>\nLoads the given module.\nThe function starts by looking into the <a href=\"#pdf-package.loaded\"><code>package.loaded</code></a> table\nto determine whether <code>modname</code> is already loaded.\nIf it is, then <code>require</code> returns the value stored\nat <code>package.loaded[modname]</code>.\nOtherwise, it tries to find a <em>loader</em> for the module.\n\n\n<p>\nTo find a loader,\n<code>require</code> is guided by the <a href=\"#pdf-package.loaders\"><code>package.loaders</code></a> array.\nBy changing this array,\nwe can change how <code>require</code> looks for a module.\nThe following explanation is based on the default configuration\nfor <a href=\"#pdf-package.loaders\"><code>package.loaders</code></a>.\n\n\n<p>\nFirst <code>require</code> queries <code>package.preload[modname]</code>.\nIf it has a value,\nthis value (which should be a function) is the loader.\nOtherwise <code>require</code> searches for a Lua loader using the\npath stored in <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nIf that also fails, it searches for a C&nbsp;loader using the\npath stored in <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nIf that also fails,\nit tries an <em>all-in-one</em> loader (see <a href=\"#pdf-package.loaders\"><code>package.loaders</code></a>).\n\n\n<p>\nOnce a loader is found,\n<code>require</code> calls the loader with a single argument, <code>modname</code>.\nIf the loader returns any value,\n<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.\nIf the loader returns no value and\nhas not assigned any value to <code>package.loaded[modname]</code>,\nthen <code>require</code> assigns <b>true</b> to this entry.\nIn any case, <code>require</code> returns the\nfinal value of <code>package.loaded[modname]</code>.\n\n\n<p>\nIf there is any error loading or running the module,\nor if it cannot find any loader for the module,\nthen <code>require</code> signals an error. \n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.cpath\"><code>package.cpath</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a C&nbsp;loader.\n\n\n<p>\nLua initializes the C&nbsp;path <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a> in the same way\nit initializes the Lua path <a href=\"#pdf-package.path\"><code>package.path</code></a>,\nusing the environment variable <a name=\"pdf-LUA_CPATH\"><code>LUA_CPATH</code></a>\nor a default path defined in <code>luaconf.h</code>.\n\n\n\n\n<p>\n\n<hr><h3><a name=\"pdf-package.loaded\"><code>package.loaded</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control which\nmodules are already loaded.\nWhen you require a module <code>modname</code> and\n<code>package.loaded[modname]</code> is not false,\n<a href=\"#pdf-require\"><code>require</code></a> simply returns the value stored there.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loaders\"><code>package.loaders</code></a></h3>\n\n\n<p>\nA table used by <a href=\"#pdf-require\"><code>require</code></a> to control how to load modules.\n\n\n<p>\nEach entry in this table is a <em>searcher function</em>.\nWhen looking for a module,\n<a href=\"#pdf-require\"><code>require</code></a> calls each of these searchers in ascending order,\nwith the module name (the argument given to <a href=\"#pdf-require\"><code>require</code></a>) as its\nsole parameter.\nThe function can return another function (the module <em>loader</em>)\nor a string explaining why it did not find that module\n(or <b>nil</b> if it has nothing to say).\nLua initializes this table with four functions.\n\n\n<p>\nThe first searcher simply looks for a loader in the\n<a href=\"#pdf-package.preload\"><code>package.preload</code></a> table.\n\n\n<p>\nThe second searcher looks for a loader as a Lua library,\nusing the path stored at <a href=\"#pdf-package.path\"><code>package.path</code></a>.\nA path is a sequence of <em>templates</em> separated by semicolons.\nFor each template,\nthe searcher will change each interrogation\nmark in the template by <code>filename</code>,\nwhich is the module name with each dot replaced by a\n\"directory separator\" (such as \"<code>/</code>\" in Unix);\nthen it will try to open the resulting file name.\nSo, for instance, if the Lua path is the string\n\n<pre>\n     \"./?.lua;./?.lc;/usr/local/?/init.lua\"\n</pre><p>\nthe search for a Lua file for module <code>foo</code>\nwill try to open the files\n<code>./foo.lua</code>, <code>./foo.lc</code>, and\n<code>/usr/local/foo/init.lua</code>, in that order.\n\n\n<p>\nThe third searcher looks for a loader as a C&nbsp;library,\nusing the path given by the variable <a href=\"#pdf-package.cpath\"><code>package.cpath</code></a>.\nFor instance,\nif the C&nbsp;path is the string\n\n<pre>\n     \"./?.so;./?.dll;/usr/local/?/init.so\"\n</pre><p>\nthe searcher for module <code>foo</code>\nwill try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,\nand <code>/usr/local/foo/init.so</code>, in that order.\nOnce it finds a C&nbsp;library,\nthis searcher first uses a dynamic link facility to link the\napplication with the library.\nThen it tries to find a C&nbsp;function inside the library to\nbe used as the loader.\nThe name of this C&nbsp;function is the string \"<code>luaopen_</code>\"\nconcatenated with a copy of the module name where each dot\nis replaced by an underscore.\nMoreover, if the module name has a hyphen,\nits prefix up to (and including) the first hyphen is removed.\nFor instance, if the module name is <code>a.v1-b.c</code>,\nthe function name will be <code>luaopen_b_c</code>.\n\n\n<p>\nThe fourth searcher tries an <em>all-in-one loader</em>.\nIt searches the C&nbsp;path for a library for\nthe root name of the given module.\nFor instance, when requiring <code>a.b.c</code>,\nit will search for a C&nbsp;library for <code>a</code>.\nIf found, it looks into it for an open function for\nthe submodule;\nin our example, that would be <code>luaopen_a_b_c</code>.\nWith this facility, a package can pack several C&nbsp;submodules\ninto one single library,\nwith each submodule keeping its original open function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.loadlib\"><code>package.loadlib (libname, funcname)</code></a></h3>\n\n\n<p>\nDynamically links the host program with the C&nbsp;library <code>libname</code>.\nInside this library, looks for a function <code>funcname</code>\nand returns this function as a C&nbsp;function.\n(So, <code>funcname</code> must follow the protocol (see <a href=\"#lua_CFunction\"><code>lua_CFunction</code></a>)).\n\n\n<p>\nThis is a low-level function.\nIt completely bypasses the package and module system.\nUnlike <a href=\"#pdf-require\"><code>require</code></a>,\nit does not perform any path searching and\ndoes not automatically adds extensions.\n<code>libname</code> must be the complete file name of the C&nbsp;library,\nincluding if necessary a path and extension.\n<code>funcname</code> must be the exact name exported by the C&nbsp;library\n(which may depend on the C&nbsp;compiler and linker used).\n\n\n<p>\nThis function is not supported by ANSI C.\nAs such, it is only available on some platforms\n(Windows, Linux, Mac OS X, Solaris, BSD,\nplus other Unix systems that support the <code>dlfcn</code> standard).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.path\"><code>package.path</code></a></h3>\n\n\n<p>\nThe path used by <a href=\"#pdf-require\"><code>require</code></a> to search for a Lua loader.\n\n\n<p>\nAt start-up, Lua initializes this variable with\nthe value of the environment variable <a name=\"pdf-LUA_PATH\"><code>LUA_PATH</code></a> or\nwith a default path defined in <code>luaconf.h</code>,\nif the environment variable is not defined.\nAny \"<code>;;</code>\" in the value of the environment variable\nis replaced by the default path.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.preload\"><code>package.preload</code></a></h3>\n\n\n<p>\nA table to store loaders for specific modules\n(see <a href=\"#pdf-require\"><code>require</code></a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-package.seeall\"><code>package.seeall (module)</code></a></h3>\n\n\n<p>\nSets a metatable for <code>module</code> with\nits <code>__index</code> field referring to the global environment,\nso that this module inherits values\nfrom the global environment.\nTo be used as an option to function <a href=\"#pdf-module\"><code>module</code></a>.\n\n\n\n\n\n\n\n<h2>5.4 - <a name=\"5.4\">String Manipulation</a></h2>\n\n<p>\nThis library provides generic functions for string manipulation,\nsuch as finding and extracting substrings, and pattern matching.\nWhen indexing a string in Lua, the first character is at position&nbsp;1\n(not at&nbsp;0, as in C).\nIndices are allowed to be negative and are interpreted as indexing backwards,\nfrom the end of the string.\nThus, the last character is at position -1, and so on.\n\n\n<p>\nThe string library provides all its functions inside the table\n<a name=\"pdf-string\"><code>string</code></a>.\nIt also sets a metatable for strings\nwhere the <code>__index</code> field points to the <code>string</code> table.\nTherefore, you can use the string functions in object-oriented style.\nFor instance, <code>string.byte(s, i)</code>\ncan be written as <code>s:byte(i)</code>.\n\n\n<p>\nThe string library assumes one-byte character encodings.\n\n\n<p>\n<hr><h3><a name=\"pdf-string.byte\"><code>string.byte (s [, i [, j]])</code></a></h3>\nReturns the internal numerical codes of the characters <code>s[i]</code>,\n<code>s[i+1]</code>, &middot;&middot;&middot;, <code>s[j]</code>.\nThe default value for <code>i</code> is&nbsp;1;\nthe default value for <code>j</code> is&nbsp;<code>i</code>.\n\n\n<p>\nNote that numerical codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.char\"><code>string.char (&middot;&middot;&middot;)</code></a></h3>\nReceives zero or more integers.\nReturns a string with length equal to the number of arguments,\nin which each character has the internal numerical code equal\nto its corresponding argument.\n\n\n<p>\nNote that numerical codes are not necessarily portable across platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.dump\"><code>string.dump (function)</code></a></h3>\n\n\n<p>\nReturns a string containing a binary representation of the given function,\nso that a later <a href=\"#pdf-loadstring\"><code>loadstring</code></a> on this string returns\na copy of the function.\n<code>function</code> must be a Lua function without upvalues.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.find\"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>\nLooks for the first match of\n<code>pattern</code> in the string <code>s</code>.\nIf it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>\nwhere this occurrence starts and ends;\notherwise, it returns <b>nil</b>.\nA third, optional numerical argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\nA value of <b>true</b> as a fourth, optional argument <code>plain</code>\nturns off the pattern matching facilities,\nso the function does a plain \"find substring\" operation,\nwith no characters in <code>pattern</code> being considered \"magic\".\nNote that if <code>plain</code> is given, then <code>init</code> must be given as well.\n\n\n<p>\nIf the pattern has captures,\nthen in a successful match\nthe captured values are also returned,\nafter the two indices.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.format\"><code>string.format (formatstring, &middot;&middot;&middot;)</code></a></h3>\nReturns a formatted version of its variable number of arguments\nfollowing the description given in its first argument (which must be a string).\nThe format string follows the same rules as the <code>printf</code> family of\nstandard C&nbsp;functions.\nThe only differences are that the options/modifiers\n<code>*</code>, <code>l</code>, <code>L</code>, <code>n</code>, <code>p</code>,\nand <code>h</code> are not supported\nand that there is an extra option, <code>q</code>.\nThe <code>q</code> option formats a string in a form suitable to be safely read\nback by the Lua interpreter:\nthe string is written between double quotes,\nand all double quotes, newlines, embedded zeros,\nand backslashes in the string\nare correctly escaped when written.\nFor instance, the call\n\n<pre>\n     string.format('%q', 'a string with \"quotes\" and \\n new line')\n</pre><p>\nwill produce the string:\n\n<pre>\n     \"a string with \\\"quotes\\\" and \\\n      new line\"\n</pre>\n\n<p>\nThe options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>,\n<code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all\nexpect a number as argument,\nwhereas <code>q</code> and <code>s</code> expect a string.\n\n\n<p>\nThis function does not accept string values\ncontaining embedded zeros,\nexcept as arguments to the <code>q</code> option.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gmatch\"><code>string.gmatch (s, pattern)</code></a></h3>\nReturns an iterator function that,\neach time it is called,\nreturns the next captures from <code>pattern</code> over string <code>s</code>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is produced in each call.\n\n\n<p>\nAs an example, the following loop\n\n<pre>\n     s = \"hello world from Lua\"\n     for w in string.gmatch(s, \"%a+\") do\n       print(w)\n     end\n</pre><p>\nwill iterate over all the words from string <code>s</code>,\nprinting one per line.\nThe next example collects all pairs <code>key=value</code> from the\ngiven string into a table:\n\n<pre>\n     t = {}\n     s = \"from=world, to=Lua\"\n     for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n       t[k] = v\n     end\n</pre>\n\n<p>\nFor this function, a '<code>^</code>' at the start of a pattern does not\nwork as an anchor, as this would prevent the iteration.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.gsub\"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>\nReturns a copy of <code>s</code>\nin which all (or the first <code>n</code>, if given)\noccurrences of the <code>pattern</code> have been\nreplaced by a replacement string specified by <code>repl</code>,\nwhich can be a string, a table, or a function.\n<code>gsub</code> also returns, as its second value,\nthe total number of matches that occurred.\n\n\n<p>\nIf <code>repl</code> is a string, then its value is used for replacement.\nThe character&nbsp;<code>%</code> works as an escape character:\nany sequence in <code>repl</code> of the form <code>%<em>n</em></code>,\nwith <em>n</em> between 1 and 9,\nstands for the value of the <em>n</em>-th captured substring (see below).\nThe sequence <code>%0</code> stands for the whole match.\nThe sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.\n\n\n<p>\nIf <code>repl</code> is a table, then the table is queried for every match,\nusing the first capture as the key;\nif the pattern specifies no captures,\nthen the whole match is used as the key.\n\n\n<p>\nIf <code>repl</code> is a function, then this function is called every time a\nmatch occurs, with all captured substrings passed as arguments,\nin order;\nif the pattern specifies no captures,\nthen the whole match is passed as a sole argument.\n\n\n<p>\nIf the value returned by the table query or by the function call\nis a string or a number,\nthen it is used as the replacement string;\notherwise, if it is <b>false</b> or <b>nil</b>,\nthen there is no replacement\n(that is, the original match is kept in the string).\n\n\n<p>\nHere are some examples:\n\n<pre>\n     x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n     --&gt; x=\"hello hello world world\"\n     \n     x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n     --&gt; x=\"hello hello world\"\n     \n     x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n     --&gt; x=\"world hello Lua from\"\n     \n     x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n     --&gt; x=\"home = /home/roberto, user = roberto\"\n     \n     x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n           return loadstring(s)()\n         end)\n     --&gt; x=\"4+5 = 9\"\n     \n     local t = {name=\"lua\", version=\"5.1\"}\n     x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n     --&gt; x=\"lua-5.1.tar.gz\"\n</pre>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.len\"><code>string.len (s)</code></a></h3>\nReceives a string and returns its length.\nThe empty string <code>\"\"</code> has length 0.\nEmbedded zeros are counted,\nso <code>\"a\\000bc\\000\"</code> has length 5.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.lower\"><code>string.lower (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nuppercase letters changed to lowercase.\nAll other characters are left unchanged.\nThe definition of what an uppercase letter is depends on the current locale.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.match\"><code>string.match (s, pattern [, init])</code></a></h3>\nLooks for the first <em>match</em> of\n<code>pattern</code> in the string <code>s</code>.\nIf it finds one, then <code>match</code> returns\nthe captures from the pattern;\notherwise it returns <b>nil</b>.\nIf <code>pattern</code> specifies no captures,\nthen the whole match is returned.\nA third, optional numerical argument <code>init</code> specifies\nwhere to start the search;\nits default value is&nbsp;1 and can be negative.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.rep\"><code>string.rep (s, n)</code></a></h3>\nReturns a string that is the concatenation of <code>n</code> copies of\nthe string <code>s</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.reverse\"><code>string.reverse (s)</code></a></h3>\nReturns a string that is the string <code>s</code> reversed.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.sub\"><code>string.sub (s, i [, j])</code></a></h3>\nReturns the substring of <code>s</code> that\nstarts at <code>i</code>  and continues until <code>j</code>;\n<code>i</code> and <code>j</code> can be negative.\nIf <code>j</code> is absent, then it is assumed to be equal to -1\n(which is the same as the string length).\nIn particular,\nthe call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>\nwith length <code>j</code>,\nand <code>string.sub(s, -i)</code> returns a suffix of <code>s</code>\nwith length <code>i</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-string.upper\"><code>string.upper (s)</code></a></h3>\nReceives a string and returns a copy of this string with all\nlowercase letters changed to uppercase.\nAll other characters are left unchanged.\nThe definition of what a lowercase letter is depends on the current locale.\n\n\n\n<h3>5.4.1 - <a name=\"5.4.1\">Patterns</a></h3>\n\n\n<h4>Character Class:</h4><p>\nA <em>character class</em> is used to represent a set of characters.\nThe following combinations are allowed in describing a character class:\n\n<ul>\n\n<li><b><em>x</em>:</b>\n(where <em>x</em> is not one of the <em>magic characters</em>\n<code>^$()%.[]*+-?</code>)\nrepresents the character <em>x</em> itself.\n</li>\n\n<li><b><code>.</code>:</b> (a dot) represents all characters.</li>\n\n<li><b><code>%a</code>:</b> represents all letters.</li>\n\n<li><b><code>%c</code>:</b> represents all control characters.</li>\n\n<li><b><code>%d</code>:</b> represents all digits.</li>\n\n<li><b><code>%l</code>:</b> represents all lowercase letters.</li>\n\n<li><b><code>%p</code>:</b> represents all punctuation characters.</li>\n\n<li><b><code>%s</code>:</b> represents all space characters.</li>\n\n<li><b><code>%u</code>:</b> represents all uppercase letters.</li>\n\n<li><b><code>%w</code>:</b> represents all alphanumeric characters.</li>\n\n<li><b><code>%x</code>:</b> represents all hexadecimal digits.</li>\n\n<li><b><code>%z</code>:</b> represents the character with representation 0.</li>\n\n<li><b><code>%<em>x</em></code>:</b> (where <em>x</em> is any non-alphanumeric character)\nrepresents the character <em>x</em>.\nThis is the standard way to escape the magic characters.\nAny punctuation character (even the non magic)\ncan be preceded by a '<code>%</code>'\nwhen used to represent itself in a pattern.\n</li>\n\n<li><b><code>[<em>set</em>]</code>:</b>\nrepresents the class which is the union of all\ncharacters in <em>set</em>.\nA range of characters can be specified by\nseparating the end characters of the range with a '<code>-</code>'.\nAll classes <code>%</code><em>x</em> described above can also be used as\ncomponents in <em>set</em>.\nAll other characters in <em>set</em> represent themselves.\nFor example, <code>[%w_]</code> (or <code>[_%w]</code>)\nrepresents all alphanumeric characters plus the underscore,\n<code>[0-7]</code> represents the octal digits,\nand <code>[0-7%l%-]</code> represents the octal digits plus\nthe lowercase letters plus the '<code>-</code>' character.\n\n\n<p>\nThe interaction between ranges and classes is not defined.\nTherefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>\nhave no meaning.\n</li>\n\n<li><b><code>[^<em>set</em>]</code>:</b>\nrepresents the complement of <em>set</em>,\nwhere <em>set</em> is interpreted as above.\n</li>\n\n</ul><p>\nFor all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),\nthe corresponding uppercase letter represents the complement of the class.\nFor instance, <code>%S</code> represents all non-space characters.\n\n\n<p>\nThe definitions of letter, space, and other character groups\ndepend on the current locale.\nIn particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.\n\n\n\n\n\n<h4>Pattern Item:</h4><p>\nA <em>pattern item</em> can be\n\n<ul>\n\n<li>\na single character class,\nwhich matches any single character in the class;\n</li>\n\n<li>\na single character class followed by '<code>*</code>',\nwhich matches 0 or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>+</code>',\nwhich matches 1 or more repetitions of characters in the class.\nThese repetition items will always match the longest possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>-</code>',\nwhich also matches 0 or more repetitions of characters in the class.\nUnlike '<code>*</code>',\nthese repetition items will always match the <em>shortest</em> possible sequence;\n</li>\n\n<li>\na single character class followed by '<code>?</code>',\nwhich matches 0 or 1 occurrence of a character in the class;\n</li>\n\n<li>\n<code>%<em>n</em></code>, for <em>n</em> between 1 and 9;\nsuch item matches a substring equal to the <em>n</em>-th captured string\n(see below);\n</li>\n\n<li>\n<code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;\nsuch item matches strings that start with&nbsp;<em>x</em>, end with&nbsp;<em>y</em>,\nand where the <em>x</em> and <em>y</em> are <em>balanced</em>.\nThis means that, if one reads the string from left to right,\ncounting <em>+1</em> for an <em>x</em> and <em>-1</em> for a <em>y</em>,\nthe ending <em>y</em> is the first <em>y</em> where the count reaches 0.\nFor instance, the item <code>%b()</code> matches expressions with\nbalanced parentheses.\n</li>\n\n</ul>\n\n\n\n\n<h4>Pattern:</h4><p>\nA <em>pattern</em> is a sequence of pattern items.\nA '<code>^</code>' at the beginning of a pattern anchors the match at the\nbeginning of the subject string.\nA '<code>$</code>' at the end of a pattern anchors the match at the\nend of the subject string.\nAt other positions,\n'<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.\n\n\n\n\n\n<h4>Captures:</h4><p>\nA pattern can contain sub-patterns enclosed in parentheses;\nthey describe <em>captures</em>.\nWhen a match succeeds, the substrings of the subject string\nthat match captures are stored (<em>captured</em>) for future use.\nCaptures are numbered according to their left parentheses.\nFor instance, in the pattern <code>\"(a*(.)%w(%s*))\"</code>,\nthe part of the string matching <code>\"a*(.)%w(%s*)\"</code> is\nstored as the first capture (and therefore has number&nbsp;1);\nthe character matching \"<code>.</code>\" is captured with number&nbsp;2,\nand the part matching \"<code>%s*</code>\" has number&nbsp;3.\n\n\n<p>\nAs a special case, the empty capture <code>()</code> captures\nthe current string position (a number).\nFor instance, if we apply the pattern <code>\"()aa()\"</code> on the\nstring <code>\"flaaap\"</code>, there will be two captures: 3&nbsp;and&nbsp;5.\n\n\n<p>\nA pattern cannot contain embedded zeros.  Use <code>%z</code> instead.\n\n\n\n\n\n\n\n\n\n\n\n<h2>5.5 - <a name=\"5.5\">Table Manipulation</a></h2><p>\nThis library provides generic functions for table manipulation.\nIt provides all its functions inside the table <a name=\"pdf-table\"><code>table</code></a>.\n\n\n<p>\nMost functions in the table library assume that the table\nrepresents an array or a list.\nFor these functions, when we talk about the \"length\" of a table\nwe mean the result of the length operator.\n\n\n<p>\n<hr><h3><a name=\"pdf-table.concat\"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3>\nGiven an array where all elements are strings or numbers,\nreturns <code>table[i]..sep..table[i+1] &middot;&middot;&middot; sep..table[j]</code>.\nThe default value for <code>sep</code> is the empty string,\nthe default for <code>i</code> is 1,\nand the default for <code>j</code> is the length of the table.\nIf <code>i</code> is greater than <code>j</code>, returns the empty string.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.insert\"><code>table.insert (table, [pos,] value)</code></a></h3>\n\n\n<p>\nInserts element <code>value</code> at position <code>pos</code> in <code>table</code>,\nshifting up other elements to open space, if necessary.\nThe default value for <code>pos</code> is <code>n+1</code>,\nwhere <code>n</code> is the length of the table (see <a href=\"#2.5.5\">&sect;2.5.5</a>),\nso that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end\nof table <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.maxn\"><code>table.maxn (table)</code></a></h3>\n\n\n<p>\nReturns the largest positive numerical index of the given table,\nor zero if the table has no positive numerical indices.\n(To do its job this function does a linear traversal of\nthe whole table.) \n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.remove\"><code>table.remove (table [, pos])</code></a></h3>\n\n\n<p>\nRemoves from <code>table</code> the element at position <code>pos</code>,\nshifting down other elements to close the space, if necessary.\nReturns the value of the removed element.\nThe default value for <code>pos</code> is <code>n</code>,\nwhere <code>n</code> is the length of the table,\nso that a call <code>table.remove(t)</code> removes the last element\nof table <code>t</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-table.sort\"><code>table.sort (table [, comp])</code></a></h3>\nSorts table elements in a given order, <em>in-place</em>,\nfrom <code>table[1]</code> to <code>table[n]</code>,\nwhere <code>n</code> is the length of the table.\nIf <code>comp</code> is given,\nthen it must be a function that receives two table elements,\nand returns true\nwhen the first is less than the second\n(so that <code>not comp(a[i+1],a[i])</code> will be true after the sort).\nIf <code>comp</code> is not given,\nthen the standard Lua operator <code>&lt;</code> is used instead.\n\n\n<p>\nThe sort algorithm is not stable;\nthat is, elements considered equal by the given order\nmay have their relative positions changed by the sort.\n\n\n\n\n\n\n\n<h2>5.6 - <a name=\"5.6\">Mathematical Functions</a></h2>\n\n<p>\nThis library is an interface to the standard C&nbsp;math library.\nIt provides all its functions inside the table <a name=\"pdf-math\"><code>math</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-math.abs\"><code>math.abs (x)</code></a></h3>\n\n\n<p>\nReturns the absolute value of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.acos\"><code>math.acos (x)</code></a></h3>\n\n\n<p>\nReturns the arc cosine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.asin\"><code>math.asin (x)</code></a></h3>\n\n\n<p>\nReturns the arc sine of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan\"><code>math.atan (x)</code></a></h3>\n\n\n<p>\nReturns the arc tangent of <code>x</code> (in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.atan2\"><code>math.atan2 (y, x)</code></a></h3>\n\n\n<p>\nReturns the arc tangent of <code>y/x</code> (in radians),\nbut uses the signs of both parameters to find the\nquadrant of the result.\n(It also handles correctly the case of <code>x</code> being zero.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ceil\"><code>math.ceil (x)</code></a></h3>\n\n\n<p>\nReturns the smallest integer larger than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cos\"><code>math.cos (x)</code></a></h3>\n\n\n<p>\nReturns the cosine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.cosh\"><code>math.cosh (x)</code></a></h3>\n\n\n<p>\nReturns the hyperbolic cosine of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.deg\"><code>math.deg (x)</code></a></h3>\n\n\n<p>\nReturns the angle <code>x</code> (given in radians) in degrees.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.exp\"><code>math.exp (x)</code></a></h3>\n\n\n<p>\nReturns the value <em>e<sup>x</sup></em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.floor\"><code>math.floor (x)</code></a></h3>\n\n\n<p>\nReturns the largest integer smaller than or equal to <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.fmod\"><code>math.fmod (x, y)</code></a></h3>\n\n\n<p>\nReturns the remainder of the division of <code>x</code> by <code>y</code>\nthat rounds the quotient towards zero.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.frexp\"><code>math.frexp (x)</code></a></h3>\n\n\n<p>\nReturns <code>m</code> and <code>e</code> such that <em>x = m2<sup>e</sup></em>,\n<code>e</code> is an integer and the absolute value of <code>m</code> is\nin the range <em>[0.5, 1)</em>\n(or zero when <code>x</code> is zero).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.huge\"><code>math.huge</code></a></h3>\n\n\n<p>\nThe value <code>HUGE_VAL</code>,\na value larger than or equal to any other numerical value.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.ldexp\"><code>math.ldexp (m, e)</code></a></h3>\n\n\n<p>\nReturns <em>m2<sup>e</sup></em> (<code>e</code> should be an integer).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log\"><code>math.log (x)</code></a></h3>\n\n\n<p>\nReturns the natural logarithm of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.log10\"><code>math.log10 (x)</code></a></h3>\n\n\n<p>\nReturns the base-10 logarithm of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.max\"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the maximum value among its arguments.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.min\"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReturns the minimum value among its arguments.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.modf\"><code>math.modf (x)</code></a></h3>\n\n\n<p>\nReturns two numbers,\nthe integral part of <code>x</code> and the fractional part of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pi\"><code>math.pi</code></a></h3>\n\n\n<p>\nThe value of <em>pi</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.pow\"><code>math.pow (x, y)</code></a></h3>\n\n\n<p>\nReturns <em>x<sup>y</sup></em>.\n(You can also use the expression <code>x^y</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.rad\"><code>math.rad (x)</code></a></h3>\n\n\n<p>\nReturns the angle <code>x</code> (given in degrees) in radians.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.random\"><code>math.random ([m [, n]])</code></a></h3>\n\n\n<p>\nThis function is an interface to the simple\npseudo-random generator function <code>rand</code> provided by ANSI&nbsp;C.\n(No guarantees can be given for its statistical properties.)\n\n\n<p>\nWhen called without arguments,\nreturns a uniform pseudo-random real number\nin the range <em>[0,1)</em>.  \nWhen called with an integer number <code>m</code>,\n<code>math.random</code> returns\na uniform pseudo-random integer in the range <em>[1, m]</em>.\nWhen called with two integer numbers <code>m</code> and <code>n</code>,\n<code>math.random</code> returns a uniform pseudo-random\ninteger in the range <em>[m, n]</em>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.randomseed\"><code>math.randomseed (x)</code></a></h3>\n\n\n<p>\nSets <code>x</code> as the \"seed\"\nfor the pseudo-random generator:\nequal seeds produce equal sequences of numbers.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sin\"><code>math.sin (x)</code></a></h3>\n\n\n<p>\nReturns the sine of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sinh\"><code>math.sinh (x)</code></a></h3>\n\n\n<p>\nReturns the hyperbolic sine of <code>x</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.sqrt\"><code>math.sqrt (x)</code></a></h3>\n\n\n<p>\nReturns the square root of <code>x</code>.\n(You can also use the expression <code>x^0.5</code> to compute this value.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tan\"><code>math.tan (x)</code></a></h3>\n\n\n<p>\nReturns the tangent of <code>x</code> (assumed to be in radians).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-math.tanh\"><code>math.tanh (x)</code></a></h3>\n\n\n<p>\nReturns the hyperbolic tangent of <code>x</code>.\n\n\n\n\n\n\n\n<h2>5.7 - <a name=\"5.7\">Input and Output Facilities</a></h2>\n\n<p>\nThe I/O library provides two different styles for file manipulation.\nThe first one uses implicit file descriptors;\nthat is, there are operations to set a default input file and a\ndefault output file,\nand all input/output operations are over these default files.\nThe second style uses explicit file descriptors.\n\n\n<p>\nWhen using implicit file descriptors,\nall operations are supplied by table <a name=\"pdf-io\"><code>io</code></a>.\nWhen using explicit file descriptors,\nthe operation <a href=\"#pdf-io.open\"><code>io.open</code></a> returns a file descriptor\nand then all operations are supplied as methods of the file descriptor.\n\n\n<p>\nThe table <code>io</code> also provides\nthree predefined file descriptors with their usual meanings from C:\n<a name=\"pdf-io.stdin\"><code>io.stdin</code></a>, <a name=\"pdf-io.stdout\"><code>io.stdout</code></a>, and <a name=\"pdf-io.stderr\"><code>io.stderr</code></a>.\nThe I/O library never closes these files.\n\n\n<p>\nUnless otherwise stated,\nall I/O functions return <b>nil</b> on failure\n(plus an error message as a second result and\na system-dependent error code as a third result)\nand some value different from <b>nil</b> on success.\n\n\n<p>\n<hr><h3><a name=\"pdf-io.close\"><code>io.close ([file])</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:close()</code>.\nWithout a <code>file</code>, closes the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.flush\"><code>io.flush ()</code></a></h3>\n\n\n<p>\nEquivalent to <code>file:flush</code> over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.input\"><code>io.input ([file])</code></a></h3>\n\n\n<p>\nWhen called with a file name, it opens the named file (in text mode),\nand sets its handle as the default input file.\nWhen called with a file handle,\nit simply sets this file handle as the default input file.\nWhen called without parameters,\nit returns the current default input file.\n\n\n<p>\nIn case of errors this function raises the error,\ninstead of returning an error code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.lines\"><code>io.lines ([filename])</code></a></h3>\n\n\n<p>\nOpens the given file name in read mode\nand returns an iterator function that,\neach time it is called,\nreturns a new line from the file.\nTherefore, the construction\n\n<pre>\n     for line in io.lines(filename) do <em>body</em> end\n</pre><p>\nwill iterate over all lines of the file.\nWhen the iterator function detects the end of file,\nit returns <b>nil</b> (to finish the loop) and automatically closes the file.\n\n\n<p>\nThe call <code>io.lines()</code> (with no file name) is equivalent\nto <code>io.input():lines()</code>;\nthat is, it iterates over the lines of the default input file.\nIn this case it does not close the file when the loop ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.open\"><code>io.open (filename [, mode])</code></a></h3>\n\n\n<p>\nThis function opens a file,\nin the mode specified in the string <code>mode</code>.\nIt returns a new file handle,\nor, in case of errors, <b>nil</b> plus an error message.\n\n\n<p>\nThe <code>mode</code> string can be any of the following:\n\n<ul>\n<li><b>\"r\":</b> read mode (the default);</li>\n<li><b>\"w\":</b> write mode;</li>\n<li><b>\"a\":</b> append mode;</li>\n<li><b>\"r+\":</b> update mode, all previous data is preserved;</li>\n<li><b>\"w+\":</b> update mode, all previous data is erased;</li>\n<li><b>\"a+\":</b> append update mode, previous data is preserved,\n  writing is only allowed at the end of file.</li>\n</ul><p>\nThe <code>mode</code> string can also have a '<code>b</code>' at the end,\nwhich is needed in some systems to open the file in binary mode.\nThis string is exactly what is used in the\nstandard&nbsp;C function <code>fopen</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.output\"><code>io.output ([file])</code></a></h3>\n\n\n<p>\nSimilar to <a href=\"#pdf-io.input\"><code>io.input</code></a>, but operates over the default output file.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.popen\"><code>io.popen (prog [, mode])</code></a></h3>\n\n\n<p>\nStarts program <code>prog</code> in a separated process and returns\na file handle that you can use to read data from this program\n(if <code>mode</code> is <code>\"r\"</code>, the default)\nor to write data to this program\n(if <code>mode</code> is <code>\"w\"</code>).\n\n\n<p>\nThis function is system dependent and is not available\non all platforms.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.read\"><code>io.read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.input():read</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.tmpfile\"><code>io.tmpfile ()</code></a></h3>\n\n\n<p>\nReturns a handle for a temporary file.\nThis file is opened in update mode\nand it is automatically removed when the program ends.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.type\"><code>io.type (obj)</code></a></h3>\n\n\n<p>\nChecks whether <code>obj</code> is a valid file handle.\nReturns the string <code>\"file\"</code> if <code>obj</code> is an open file handle,\n<code>\"closed file\"</code> if <code>obj</code> is a closed file handle,\nor <b>nil</b> if <code>obj</code> is not a file handle.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-io.write\"><code>io.write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nEquivalent to <code>io.output():write</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:close\"><code>file:close ()</code></a></h3>\n\n\n<p>\nCloses <code>file</code>.\nNote that files are automatically closed when\ntheir handles are garbage collected,\nbut that takes an unpredictable amount of time to happen.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:flush\"><code>file:flush ()</code></a></h3>\n\n\n<p>\nSaves any written data to <code>file</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:lines\"><code>file:lines ()</code></a></h3>\n\n\n<p>\nReturns an iterator function that,\neach time it is called,\nreturns a new line from the file.\nTherefore, the construction\n\n<pre>\n     for line in file:lines() do <em>body</em> end\n</pre><p>\nwill iterate over all lines of the file.\n(Unlike <a href=\"#pdf-io.lines\"><code>io.lines</code></a>, this function does not close the file\nwhen the loop ends.)\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:read\"><code>file:read (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nReads the file <code>file</code>,\naccording to the given formats, which specify what to read.\nFor each format,\nthe function returns a string (or a number) with the characters read,\nor <b>nil</b> if it cannot read data with the specified format.\nWhen called without formats,\nit uses a default format that reads the entire next line\n(see below).\n\n\n<p>\nThe available formats are\n\n<ul>\n\n<li><b>\"*n\":</b>\nreads a number;\nthis is the only format that returns a number instead of a string.\n</li>\n\n<li><b>\"*a\":</b>\nreads the whole file, starting at the current position.\nOn end of file, it returns the empty string.\n</li>\n\n<li><b>\"*l\":</b>\nreads the next line (skipping the end of line),\nreturning <b>nil</b> on end of file.\nThis is the default format.\n</li>\n\n<li><b><em>number</em>:</b>\nreads a string with up to this number of characters,\nreturning <b>nil</b> on end of file.\nIf number is zero,\nit reads nothing and returns an empty string,\nor <b>nil</b> on end of file.\n</li>\n\n</ul>\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:seek\"><code>file:seek ([whence] [, offset])</code></a></h3>\n\n\n<p>\nSets and gets the file position,\nmeasured from the beginning of the file,\nto the position given by <code>offset</code> plus a base\nspecified by the string <code>whence</code>, as follows:\n\n<ul>\n<li><b>\"set\":</b> base is position 0 (beginning of the file);</li>\n<li><b>\"cur\":</b> base is current position;</li>\n<li><b>\"end\":</b> base is end of file;</li>\n</ul><p>\nIn case of success, function <code>seek</code> returns the final file position,\nmeasured in bytes from the beginning of the file.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n<p>\nThe default value for <code>whence</code> is <code>\"cur\"</code>,\nand for <code>offset</code> is 0.\nTherefore, the call <code>file:seek()</code> returns the current\nfile position, without changing it;\nthe call <code>file:seek(\"set\")</code> sets the position to the\nbeginning of the file (and returns 0);\nand the call <code>file:seek(\"end\")</code> sets the position to the\nend of the file, and returns its size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:setvbuf\"><code>file:setvbuf (mode [, size])</code></a></h3>\n\n\n<p>\nSets the buffering mode for an output file.\nThere are three available modes:\n\n<ul>\n\n<li><b>\"no\":</b>\nno buffering; the result of any output operation appears immediately.\n</li>\n\n<li><b>\"full\":</b>\nfull buffering; output operation is performed only\nwhen the buffer is full (or when you explicitly <code>flush</code> the file\n(see <a href=\"#pdf-io.flush\"><code>io.flush</code></a>)).\n</li>\n\n<li><b>\"line\":</b>\nline buffering; output is buffered until a newline is output\nor there is any input from some special files\n(such as a terminal device).\n</li>\n\n</ul><p>\nFor the last two cases, <code>size</code>\nspecifies the size of the buffer, in bytes.\nThe default is an appropriate size.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-file:write\"><code>file:write (&middot;&middot;&middot;)</code></a></h3>\n\n\n<p>\nWrites the value of each of its arguments to\nthe <code>file</code>.\nThe arguments must be strings or numbers.\nTo write other values,\nuse <a href=\"#pdf-tostring\"><code>tostring</code></a> or <a href=\"#pdf-string.format\"><code>string.format</code></a> before <code>write</code>.\n\n\n\n\n\n\n\n<h2>5.8 - <a name=\"5.8\">Operating System Facilities</a></h2>\n\n<p>\nThis library is implemented through table <a name=\"pdf-os\"><code>os</code></a>.\n\n\n<p>\n<hr><h3><a name=\"pdf-os.clock\"><code>os.clock ()</code></a></h3>\n\n\n<p>\nReturns an approximation of the amount in seconds of CPU time\nused by the program.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.date\"><code>os.date ([format [, time]])</code></a></h3>\n\n\n<p>\nReturns a string or a table containing date and time,\nformatted according to the given string <code>format</code>.\n\n\n<p>\nIf the <code>time</code> argument is present,\nthis is the time to be formatted\n(see the <a href=\"#pdf-os.time\"><code>os.time</code></a> function for a description of this value).\nOtherwise, <code>date</code> formats the current time.\n\n\n<p>\nIf <code>format</code> starts with '<code>!</code>',\nthen the date is formatted in Coordinated Universal Time.\nAfter this optional character,\nif <code>format</code> is the string \"<code>*t</code>\",\nthen <code>date</code> returns a table with the following fields:\n<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31),\n<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61),\n<code>wday</code> (weekday, Sunday is&nbsp;1),\n<code>yday</code> (day of the year),\nand <code>isdst</code> (daylight saving flag, a boolean).\n\n\n<p>\nIf <code>format</code> is not \"<code>*t</code>\",\nthen <code>date</code> returns the date as a string,\nformatted according to the same rules as the C&nbsp;function <code>strftime</code>.\n\n\n<p>\nWhen called without arguments,\n<code>date</code> returns a reasonable date and time representation that depends on\nthe host system and on the current locale\n(that is, <code>os.date()</code> is equivalent to <code>os.date(\"%c\")</code>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.difftime\"><code>os.difftime (t2, t1)</code></a></h3>\n\n\n<p>\nReturns the number of seconds from time <code>t1</code> to time <code>t2</code>.\nIn POSIX, Windows, and some other systems,\nthis value is exactly <code>t2</code><em>-</em><code>t1</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.execute\"><code>os.execute ([command])</code></a></h3>\n\n\n<p>\nThis function is equivalent to the C&nbsp;function <code>system</code>.\nIt passes <code>command</code> to be executed by an operating system shell.\nIt returns a status code, which is system-dependent.\nIf <code>command</code> is absent, then it returns nonzero if a shell is available\nand zero otherwise.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.exit\"><code>os.exit ([code])</code></a></h3>\n\n\n<p>\nCalls the C&nbsp;function <code>exit</code>,\nwith an optional <code>code</code>,\nto terminate the host program.\nThe default value for <code>code</code> is the success code.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.getenv\"><code>os.getenv (varname)</code></a></h3>\n\n\n<p>\nReturns the value of the process environment variable <code>varname</code>,\nor <b>nil</b> if the variable is not defined.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.remove\"><code>os.remove (filename)</code></a></h3>\n\n\n<p>\nDeletes the file or directory with the given name.\nDirectories must be empty to be removed.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.rename\"><code>os.rename (oldname, newname)</code></a></h3>\n\n\n<p>\nRenames file or directory named <code>oldname</code> to <code>newname</code>.\nIf this function fails, it returns <b>nil</b>,\nplus a string describing the error.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.setlocale\"><code>os.setlocale (locale [, category])</code></a></h3>\n\n\n<p>\nSets the current locale of the program.\n<code>locale</code> is a string specifying a locale;\n<code>category</code> is an optional string describing which category to change:\n<code>\"all\"</code>, <code>\"collate\"</code>, <code>\"ctype\"</code>,\n<code>\"monetary\"</code>, <code>\"numeric\"</code>, or <code>\"time\"</code>;\nthe default category is <code>\"all\"</code>.\nThe function returns the name of the new locale,\nor <b>nil</b> if the request cannot be honored.\n\n\n<p>\nIf <code>locale</code> is the empty string,\nthe current locale is set to an implementation-defined native locale.\nIf <code>locale</code> is the string \"<code>C</code>\",\nthe current locale is set to the standard C locale.\n\n\n<p>\nWhen called with <b>nil</b> as the first argument,\nthis function only returns the name of the current locale\nfor the given category.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.time\"><code>os.time ([table])</code></a></h3>\n\n\n<p>\nReturns the current time when called without arguments,\nor a time representing the date and time specified by the given table.\nThis table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,\nand may have fields <code>hour</code>, <code>min</code>, <code>sec</code>, and <code>isdst</code>\n(for a description of these fields, see the <a href=\"#pdf-os.date\"><code>os.date</code></a> function).\n\n\n<p>\nThe returned value is a number, whose meaning depends on your system.\nIn POSIX, Windows, and some other systems, this number counts the number\nof seconds since some given start time (the \"epoch\").\nIn other systems, the meaning is not specified,\nand the number returned by <code>time</code> can be used only as an argument to\n<code>date</code> and <code>difftime</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-os.tmpname\"><code>os.tmpname ()</code></a></h3>\n\n\n<p>\nReturns a string with a file name that can\nbe used for a temporary file.\nThe file must be explicitly opened before its use\nand explicitly removed when no longer needed.\n\n\n<p>\nOn some systems (POSIX),\nthis function also creates a file with that name,\nto avoid security risks.\n(Someone else might create the file with wrong permissions\nin the time between getting the name and creating the file.)\nYou still have to open the file to use it\nand to remove it (even if you do not use it).\n\n\n<p>\nWhen possible,\nyou may prefer to use <a href=\"#pdf-io.tmpfile\"><code>io.tmpfile</code></a>,\nwhich automatically removes the file when the program ends.\n\n\n\n\n\n\n\n<h2>5.9 - <a name=\"5.9\">The Debug Library</a></h2>\n\n<p>\nThis library provides\nthe functionality of the debug interface to Lua programs.\nYou should exert care when using this library.\nThe functions provided here should be used exclusively for debugging\nand similar tasks, such as profiling.\nPlease resist the temptation to use them as a\nusual programming tool:\nthey can be very slow.\nMoreover, several of these functions\nviolate some assumptions about Lua code\n(e.g., that variables local to a function\ncannot be accessed from outside or\nthat userdata metatables cannot be changed by Lua code)\nand therefore can compromise otherwise secure code.\n\n\n<p>\nAll functions in this library are provided\ninside the <a name=\"pdf-debug\"><code>debug</code></a> table.\nAll functions that operate over a thread\nhave an optional first argument which is the\nthread to operate over.\nThe default is always the current thread.\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.debug\"><code>debug.debug ()</code></a></h3>\n\n\n<p>\nEnters an interactive mode with the user,\nrunning each string that the user enters.\nUsing simple commands and other debug facilities,\nthe user can inspect global and local variables,\nchange their values, evaluate expressions, and so on.\nA line containing only the word <code>cont</code> finishes this function,\nso that the caller continues its execution.\n\n\n<p>\nNote that commands for <code>debug.debug</code> are not lexically nested\nwithin any function, and so have no direct access to local variables.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getfenv\"><code>debug.getfenv (o)</code></a></h3>\nReturns the environment of object <code>o</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.gethook\"><code>debug.gethook ([thread])</code></a></h3>\n\n\n<p>\nReturns the current hook settings of the thread, as three values:\nthe current hook function, the current hook mask,\nand the current hook count\n(as set by the <a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> function).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getinfo\"><code>debug.getinfo ([thread,] function [, what])</code></a></h3>\n\n\n<p>\nReturns a table with information about a function.\nYou can give the function directly,\nor you can give a number as the value of <code>function</code>,\nwhich means the function running at level <code>function</code> of the call stack\nof the given thread:\nlevel&nbsp;0 is the current function (<code>getinfo</code> itself);\nlevel&nbsp;1 is the function that called <code>getinfo</code>;\nand so on.\nIf <code>function</code> is a number larger than the number of active functions,\nthen <code>getinfo</code> returns <b>nil</b>.\n\n\n<p>\nThe returned table can contain all the fields returned by <a href=\"#lua_getinfo\"><code>lua_getinfo</code></a>,\nwith the string <code>what</code> describing which fields to fill in.\nThe default for <code>what</code> is to get all information available,\nexcept the table of valid lines.\nIf present,\nthe option '<code>f</code>'\nadds a field named <code>func</code> with the function itself.\nIf present,\nthe option '<code>L</code>'\nadds a field named <code>activelines</code> with the table of\nvalid lines.\n\n\n<p>\nFor instance, the expression <code>debug.getinfo(1,\"n\").name</code> returns\na table with a name for the current function,\nif a reasonable name can be found,\nand the expression <code>debug.getinfo(print)</code>\nreturns a table with all available information\nabout the <a href=\"#pdf-print\"><code>print</code></a> function.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getlocal\"><code>debug.getlocal ([thread,] level, local)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\n(The first parameter or local variable has index&nbsp;1, and so on,\nuntil the last active local variable.)\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <a href=\"#pdf-debug.getinfo\"><code>debug.getinfo</code></a> to check whether the level is valid.)\n\n\n<p>\nVariable names starting with '<code>(</code>' (open parentheses)\nrepresent internal variables\n(loop control variables, temporaries, and C&nbsp;function locals).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getmetatable\"><code>debug.getmetatable (object)</code></a></h3>\n\n\n<p>\nReturns the metatable of the given <code>object</code>\nor <b>nil</b> if it does not have a metatable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getregistry\"><code>debug.getregistry ()</code></a></h3>\n\n\n<p>\nReturns the registry table (see <a href=\"#3.5\">&sect;3.5</a>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.getupvalue\"><code>debug.getupvalue (func, up)</code></a></h3>\n\n\n<p>\nThis function returns the name and the value of the upvalue\nwith index <code>up</code> of the function <code>func</code>.\nThe function returns <b>nil</b> if there is no upvalue with the given index.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setfenv\"><code>debug.setfenv (object, table)</code></a></h3>\n\n\n<p>\nSets the environment of the given <code>object</code> to the given <code>table</code>.\nReturns <code>object</code>.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.sethook\"><code>debug.sethook ([thread,] hook, mask [, count])</code></a></h3>\n\n\n<p>\nSets the given function as a hook.\nThe string <code>mask</code> and the number <code>count</code> describe\nwhen the hook will be called.\nThe string mask may have the following characters,\nwith the given meaning:\n\n<ul>\n<li><b><code>\"c\"</code>:</b> the hook is called every time Lua calls a function;</li>\n<li><b><code>\"r\"</code>:</b> the hook is called every time Lua returns from a function;</li>\n<li><b><code>\"l\"</code>:</b> the hook is called every time Lua enters a new line of code.</li>\n</ul><p>\nWith a <code>count</code> different from zero,\nthe hook is called after every <code>count</code> instructions.\n\n\n<p>\nWhen called without arguments,\n<a href=\"#pdf-debug.sethook\"><code>debug.sethook</code></a> turns off the hook.\n\n\n<p>\nWhen the hook is called, its first parameter is a string\ndescribing the event that has triggered its call:\n<code>\"call\"</code>, <code>\"return\"</code> (or <code>\"tail return\"</code>,\nwhen simulating a return from a tail call),\n<code>\"line\"</code>, and <code>\"count\"</code>.\nFor line events,\nthe hook also gets the new line number as its second parameter.\nInside a hook,\nyou can call <code>getinfo</code> with level&nbsp;2 to get more information about\nthe running function\n(level&nbsp;0 is the <code>getinfo</code> function,\nand level&nbsp;1 is the hook function),\nunless the event is <code>\"tail return\"</code>.\nIn this case, Lua is only simulating the return,\nand a call to <code>getinfo</code> will return invalid data.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setlocal\"><code>debug.setlocal ([thread,] level, local, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the local variable\nwith index <code>local</code> of the function at level <code>level</code> of the stack.\nThe function returns <b>nil</b> if there is no local\nvariable with the given index,\nand raises an error when called with a <code>level</code> out of range.\n(You can call <code>getinfo</code> to check whether the level is valid.)\nOtherwise, it returns the name of the local variable.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setmetatable\"><code>debug.setmetatable (object, table)</code></a></h3>\n\n\n<p>\nSets the metatable for the given <code>object</code> to the given <code>table</code>\n(which can be <b>nil</b>).\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.setupvalue\"><code>debug.setupvalue (func, up, value)</code></a></h3>\n\n\n<p>\nThis function assigns the value <code>value</code> to the upvalue\nwith index <code>up</code> of the function <code>func</code>.\nThe function returns <b>nil</b> if there is no upvalue\nwith the given index.\nOtherwise, it returns the name of the upvalue.\n\n\n\n\n<p>\n<hr><h3><a name=\"pdf-debug.traceback\"><code>debug.traceback ([thread,] [message] [, level])</code></a></h3>\n\n\n<p>\nReturns a string with a traceback of the call stack.\nAn optional <code>message</code> string is appended\nat the beginning of the traceback.\nAn optional <code>level</code> number tells at which level\nto start the traceback\n(default is 1, the function calling <code>traceback</code>).\n\n\n\n\n\n\n\n<h1>6 - <a name=\"6\">Lua Stand-alone</a></h1>\n\n<p>\nAlthough Lua has been designed as an extension language,\nto be embedded in a host C&nbsp;program,\nit is also frequently used as a stand-alone language.\nAn interpreter for Lua as a stand-alone language,\ncalled simply <code>lua</code>,\nis provided with the standard distribution.\nThe stand-alone interpreter includes\nall standard libraries, including the debug library.\nIts usage is:\n\n<pre>\n     lua [options] [script [args]]\n</pre><p>\nThe options are:\n\n<ul>\n<li><b><code>-e <em>stat</em></code>:</b> executes string <em>stat</em>;</li>\n<li><b><code>-l <em>mod</em></code>:</b> \"requires\" <em>mod</em>;</li>\n<li><b><code>-i</code>:</b> enters interactive mode after running <em>script</em>;</li>\n<li><b><code>-v</code>:</b> prints version information;</li>\n<li><b><code>--</code>:</b> stops handling options;</li>\n<li><b><code>-</code>:</b> executes <code>stdin</code> as a file and stops handling options.</li>\n</ul><p>\nAfter handling its options, <code>lua</code> runs the given <em>script</em>,\npassing to it the given <em>args</em> as string arguments.\nWhen called without arguments,\n<code>lua</code> behaves as <code>lua -v -i</code>\nwhen the standard input (<code>stdin</code>) is a terminal,\nand as <code>lua -</code> otherwise.\n\n\n<p>\nBefore running any argument,\nthe interpreter checks for an environment variable <a name=\"pdf-LUA_INIT\"><code>LUA_INIT</code></a>.\nIf its format is <code>@<em>filename</em></code>,\nthen <code>lua</code> executes the file.\nOtherwise, <code>lua</code> executes the string itself.\n\n\n<p>\nAll options are handled in order, except <code>-i</code>.\nFor instance, an invocation like\n\n<pre>\n     $ lua -e'a=1' -e 'print(a)' script.lua\n</pre><p>\nwill first set <code>a</code> to 1, then print the value of <code>a</code> (which is '<code>1</code>'),\nand finally run the file <code>script.lua</code> with no arguments.\n(Here <code>$</code> is the shell prompt. Your prompt may be different.)\n\n\n<p>\nBefore starting to run the script,\n<code>lua</code> collects all arguments in the command line\nin a global table called <code>arg</code>.\nThe script name is stored at index 0,\nthe first argument after the script name goes to index 1,\nand so on.\nAny arguments before the script name\n(that is, the interpreter name plus the options)\ngo to negative indices.\nFor instance, in the call\n\n<pre>\n     $ lua -la b.lua t1 t2\n</pre><p>\nthe interpreter first runs the file <code>a.lua</code>,\nthen creates a table\n\n<pre>\n     arg = { [-2] = \"lua\", [-1] = \"-la\",\n             [0] = \"b.lua\",\n             [1] = \"t1\", [2] = \"t2\" }\n</pre><p>\nand finally runs the file <code>b.lua</code>.\nThe script is called with <code>arg[1]</code>, <code>arg[2]</code>, &middot;&middot;&middot;\nas arguments;\nit can also access these arguments with the vararg expression '<code>...</code>'.\n\n\n<p>\nIn interactive mode,\nif you write an incomplete statement,\nthe interpreter waits for its completion\nby issuing a different prompt.\n\n\n<p>\nIf the global variable <a name=\"pdf-_PROMPT\"><code>_PROMPT</code></a> contains a string,\nthen its value is used as the prompt.\nSimilarly, if the global variable <a name=\"pdf-_PROMPT2\"><code>_PROMPT2</code></a> contains a string,\nits value is used as the secondary prompt\n(issued during incomplete statements).\nTherefore, both prompts can be changed directly on the command line\nor in any Lua programs by assigning to <code>_PROMPT</code>.\nSee the next example:\n\n<pre>\n     $ lua -e\"_PROMPT='myprompt&gt; '\" -i\n</pre><p>\n(The outer pair of quotes is for the shell,\nthe inner pair is for Lua.)\nNote the use of <code>-i</code> to enter interactive mode;\notherwise,\nthe program would just end silently\nright after the assignment to <code>_PROMPT</code>.\n\n\n<p>\nTo allow the use of Lua as a\nscript interpreter in Unix systems,\nthe stand-alone interpreter skips\nthe first line of a chunk if it starts with <code>#</code>.\nTherefore, Lua scripts can be made into executable programs\nby using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,\nas in\n\n<pre>\n     #!/usr/local/bin/lua\n</pre><p>\n(Of course,\nthe location of the Lua interpreter may be different in your machine.\nIf <code>lua</code> is in your <code>PATH</code>,\nthen \n\n<pre>\n     #!/usr/bin/env lua\n</pre><p>\nis a more portable solution.) \n\n\n\n<h1>7 - <a name=\"7\">Incompatibilities with the Previous Version</a></h1>\n\n<p>\nHere we list the incompatibilities that you may find when moving a program\nfrom Lua&nbsp;5.0 to Lua&nbsp;5.1.\nYou can avoid most of the incompatibilities compiling Lua with\nappropriate options (see file <code>luaconf.h</code>).\nHowever,\nall these compatibility options will be removed in the next version of Lua.\n\n\n\n<h2>7.1 - <a name=\"7.1\">Changes in the Language</a></h2>\n<ul>\n\n<li>\nThe vararg system changed from the pseudo-argument <code>arg</code> with a\ntable with the extra arguments to the vararg expression.\n(See compile-time option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nThere was a subtle change in the scope of the implicit\nvariables of the <b>for</b> statement and for the <b>repeat</b> statement.\n</li>\n\n<li>\nThe long string/long comment syntax (<code>[[<em>string</em>]]</code>)\ndoes not allow nesting.\nYou can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases.\n(See compile-time option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.)\n</li>\n\n</ul>\n\n\n\n\n<h2>7.2 - <a name=\"7.2\">Changes in the Libraries</a></h2>\n<ul>\n\n<li>\nFunction <code>string.gfind</code> was renamed <a href=\"#pdf-string.gmatch\"><code>string.gmatch</code></a>.\n(See compile-time option <code>LUA_COMPAT_GFIND</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nWhen <a href=\"#pdf-string.gsub\"><code>string.gsub</code></a> is called with a function as its\nthird argument,\nwhenever this function returns <b>nil</b> or <b>false</b> the\nreplacement string is the whole match,\ninstead of the empty string.\n</li>\n\n<li>\nFunction <code>table.setn</code> was deprecated.\nFunction <code>table.getn</code> corresponds\nto the new length operator (<code>#</code>);\nuse the operator instead of the function.\n(See compile-time option <code>LUA_COMPAT_GETN</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nFunction <code>loadlib</code> was renamed <a href=\"#pdf-package.loadlib\"><code>package.loadlib</code></a>.\n(See compile-time option <code>LUA_COMPAT_LOADLIB</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nFunction <code>math.mod</code> was renamed <a href=\"#pdf-math.fmod\"><code>math.fmod</code></a>.\n(See compile-time option <code>LUA_COMPAT_MOD</code> in <code>luaconf.h</code>.)\n</li>\n\n<li>\nFunctions <code>table.foreach</code> and <code>table.foreachi</code> are deprecated.\nYou can use a for loop with <code>pairs</code> or <code>ipairs</code> instead.\n</li>\n\n<li>\nThere were substantial changes in function <a href=\"#pdf-require\"><code>require</code></a> due to\nthe new module system.\nHowever, the new behavior is mostly compatible with the old,\nbut <code>require</code> gets the path from <a href=\"#pdf-package.path\"><code>package.path</code></a> instead\nof from <code>LUA_PATH</code>.\n</li>\n\n<li>\nFunction <a href=\"#pdf-collectgarbage\"><code>collectgarbage</code></a> has different arguments.\nFunction <code>gcinfo</code> is deprecated;\nuse <code>collectgarbage(\"count\")</code> instead.\n</li>\n\n</ul>\n\n\n\n\n<h2>7.3 - <a name=\"7.3\">Changes in the API</a></h2>\n<ul>\n\n<li>\nThe <code>luaopen_*</code> functions (to open libraries)\ncannot be called directly,\nlike a regular C function.\nThey must be called through Lua,\nlike a Lua function.\n</li>\n\n<li>\nFunction <code>lua_open</code> was replaced by <a href=\"#lua_newstate\"><code>lua_newstate</code></a> to\nallow the user to set a memory-allocation function.\nYou can use <a href=\"#luaL_newstate\"><code>luaL_newstate</code></a> from the standard library to\ncreate a state with a standard allocation function\n(based on <code>realloc</code>).\n</li>\n\n<li>\nFunctions <code>luaL_getn</code> and <code>luaL_setn</code>\n(from the auxiliary library) are deprecated.\nUse <a href=\"#lua_objlen\"><code>lua_objlen</code></a> instead of <code>luaL_getn</code>\nand nothing instead of <code>luaL_setn</code>.\n</li>\n\n<li>\nFunction <code>luaL_openlib</code> was replaced by <a href=\"#luaL_register\"><code>luaL_register</code></a>.\n</li>\n\n<li>\nFunction <code>luaL_checkudata</code> now throws an error when the given value\nis not a userdata of the expected type.\n(In Lua&nbsp;5.0 it returned <code>NULL</code>.)\n</li>\n\n</ul>\n\n\n\n\n<h1>8 - <a name=\"8\">The Complete Syntax of Lua</a></h1>\n\n<p>\nHere is the complete syntax of Lua in extended BNF.\n(It does not describe operator precedences.)\n\n\n\n\n<pre>\n\n\tchunk ::= {stat [`<b>;</b>&acute;]} [laststat [`<b>;</b>&acute;]]\n\n\tblock ::= chunk\n\n\tstat ::=  varlist `<b>=</b>&acute; explist | \n\t\t functioncall | \n\t\t <b>do</b> block <b>end</b> | \n\t\t <b>while</b> exp <b>do</b> block <b>end</b> | \n\t\t <b>repeat</b> block <b>until</b> exp | \n\t\t <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | \n\t\t <b>for</b> Name `<b>=</b>&acute; exp `<b>,</b>&acute; exp [`<b>,</b>&acute; exp] <b>do</b> block <b>end</b> | \n\t\t <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | \n\t\t <b>function</b> funcname funcbody | \n\t\t <b>local</b> <b>function</b> Name funcbody | \n\t\t <b>local</b> namelist [`<b>=</b>&acute; explist] \n\n\tlaststat ::= <b>return</b> [explist] | <b>break</b>\n\n\tfuncname ::= Name {`<b>.</b>&acute; Name} [`<b>:</b>&acute; Name]\n\n\tvarlist ::= var {`<b>,</b>&acute; var}\n\n\tvar ::=  Name | prefixexp `<b>[</b>&acute; exp `<b>]</b>&acute; | prefixexp `<b>.</b>&acute; Name \n\n\tnamelist ::= Name {`<b>,</b>&acute; Name}\n\n\texplist ::= {exp `<b>,</b>&acute;} exp\n\n\texp ::=  <b>nil</b> | <b>false</b> | <b>true</b> | Number | String | `<b>...</b>&acute; | function | \n\t\t prefixexp | tableconstructor | exp binop exp | unop exp \n\n\tprefixexp ::= var | functioncall | `<b>(</b>&acute; exp `<b>)</b>&acute;\n\n\tfunctioncall ::=  prefixexp args | prefixexp `<b>:</b>&acute; Name args \n\n\targs ::=  `<b>(</b>&acute; [explist] `<b>)</b>&acute; | tableconstructor | String \n\n\tfunction ::= <b>function</b> funcbody\n\n\tfuncbody ::= `<b>(</b>&acute; [parlist] `<b>)</b>&acute; block <b>end</b>\n\n\tparlist ::= namelist [`<b>,</b>&acute; `<b>...</b>&acute;] | `<b>...</b>&acute;\n\n\ttableconstructor ::= `<b>{</b>&acute; [fieldlist] `<b>}</b>&acute;\n\n\tfieldlist ::= field {fieldsep field} [fieldsep]\n\n\tfield ::= `<b>[</b>&acute; exp `<b>]</b>&acute; `<b>=</b>&acute; exp | Name `<b>=</b>&acute; exp | exp\n\n\tfieldsep ::= `<b>,</b>&acute; | `<b>;</b>&acute;\n\n\tbinop ::= `<b>+</b>&acute; | `<b>-</b>&acute; | `<b>*</b>&acute; | `<b>/</b>&acute; | `<b>^</b>&acute; | `<b>%</b>&acute; | `<b>..</b>&acute; | \n\t\t `<b>&lt;</b>&acute; | `<b>&lt;=</b>&acute; | `<b>&gt;</b>&acute; | `<b>&gt;=</b>&acute; | `<b>==</b>&acute; | `<b>~=</b>&acute; | \n\t\t <b>and</b> | <b>or</b>\n\n\tunop ::= `<b>-</b>&acute; | <b>not</b> | `<b>#</b>&acute;\n\n</pre>\n\n<p>\n\n\n\n\n\n\n\n<HR>\n<SMALL>\nLast update:\nMon Aug 18 13:25:46 BRT 2008\n</SMALL>\n<!--\nLast change: revised for Lua 5.1.4\n-->\n\n</body></html>\n\n"
  },
  {
    "path": "doc/readme.html",
    "content": "<HTML>\n<HEAD>\n<TITLE>Lua documentation</TITLE>\n<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"lua.css\">\n</HEAD>\n\n<BODY>\n\n<HR>\n<H1>\n<A HREF=\"http://www.lua.org/\"><IMG SRC=\"logo.gif\" ALT=\"Lua\" BORDER=0></A>\nDocumentation\n</H1>\n\nThis is the documentation included in the source distribution of Lua 5.1.4.\n\n<UL>\n<LI><A HREF=\"contents.html\">Reference manual</A>\n<LI><A HREF=\"lua.html\">lua man page</A>\n<LI><A HREF=\"luac.html\">luac man page</A>\n<LI><A HREF=\"../README\">lua/README</A>\n<LI><A HREF=\"../etc/README\">lua/etc/README</A>\n<LI><A HREF=\"../test/README\">lua/test/README</A>\n</UL>\n\nLua's\n<A HREF=\"http://www.lua.org/\">official web site</A>\ncontains updated documentation,\nespecially the\n<A HREF=\"http://www.lua.org/manual/5.1/\">reference manual</A>.\n<P>\n\n<HR>\n<SMALL>\nLast update:\nTue Aug 12 14:46:07 BRT 2008\n</SMALL>\n\n</BODY>\n</HTML>\n"
  },
  {
    "path": "etc/README",
    "content": "This directory contains some useful files and code.\nUnlike the code in ../src, everything here is in the public domain.\n\nIf any of the makes fail, you're probably not using the same libraries\nused to build Lua. Set MYLIBS in Makefile accordingly.\n\nall.c\n\tFull Lua interpreter in a single file.\n\tDo \"make one\" for a demo.\n\nlua.hpp\n\tLua header files for C++ using 'extern \"C\"'.\n\nlua.ico\n\tA Lua icon for Windows (and web sites: save as favicon.ico).\n\tDrawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.\n\nlua.pc\n\tpkg-config data for Lua\n\nluavs.bat\n\tScript to build Lua under \"Visual Studio .NET Command Prompt\".\n\tRun it from the toplevel as etc\\luavs.bat.\n\nmin.c\n\tA minimal Lua interpreter.\n\tGood for learning and for starting your own.\n\tDo \"make min\" for a demo.\n\nnoparser.c\n\tLinking with noparser.o avoids loading the parsing modules in lualib.a.\n\tDo \"make noparser\" for a demo.\n\nstrict.lua\n\tTraps uses of undeclared global variables.\n\tDo \"make strict\" for a demo.\n\n"
  },
  {
    "path": "etc/all.c",
    "content": "/*\n* all.c -- Lua core, libraries and interpreter in a single file\n*/\n\n#define luaall_c\n\n#include \"lapi.c\"\n#include \"lcode.c\"\n#include \"ldebug.c\"\n#include \"ldo.c\"\n#include \"ldump.c\"\n#include \"lfunc.c\"\n#include \"lgc.c\"\n#include \"llex.c\"\n#include \"lmem.c\"\n#include \"lobject.c\"\n#include \"lopcodes.c\"\n#include \"lparser.c\"\n#include \"lstate.c\"\n#include \"lstring.c\"\n#include \"ltable.c\"\n#include \"ltm.c\"\n#include \"lundump.c\"\n#include \"lvm.c\"\n#include \"lzio.c\"\n\n#include \"lauxlib.c\"\n#include \"lbaselib.c\"\n#include \"ldblib.c\"\n#include \"liolib.c\"\n#include \"linit.c\"\n#include \"lmathlib.c\"\n#include \"loadlib.c\"\n#include \"loslib.c\"\n#include \"lstrlib.c\"\n#include \"ltablib.c\"\n\n#include \"lua.c\"\n"
  },
  {
    "path": "etc/embed_jit.c",
    "content": "/*\n* min.c -- a minimal Lua interpreter\n* loads stdin only with minimal error handling.\n* no interaction, and no standard library, only a \"print\" function.\n*/\n\n#include <stdio.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\nstatic int print(lua_State *L)\n{\n int n=lua_gettop(L);\n int i;\n for (i=1; i<=n; i++)\n {\n  if (i>1) printf(\"\\t\");\n  if (lua_isstring(L,i))\n   printf(\"%s\",lua_tostring(L,i));\n  else if (lua_isnil(L,i))\n   printf(\"%s\",\"nil\");\n  else if (lua_isboolean(L,i))\n   printf(\"%s\",lua_toboolean(L,i) ? \"true\" : \"false\");\n  else\n   printf(\"%s:%p\",luaL_typename(L,i),lua_topointer(L,i));\n }\n printf(\"\\n\");\n return 0;\n}\n\nint main(int argc, char **argv)\n{\n lua_State *L=lua_open();\n char *file=NULL;\n lua_register(L,\"print\",print);\n if (argc > 1) {\n \tfile = argv[1];\n }\n if (luaL_dofile(L,file)!=0) fprintf(stderr,\"%s\\n\",lua_tostring(L,-1));\n lua_close(L);\n return 0;\n}\n"
  },
  {
    "path": "etc/embed_jit.cpp",
    "content": "/*\n* min.c -- a minimal Lua interpreter\n* loads stdin only with minimal error handling.\n* no interaction, and no standard library, only a \"print\" function.\n*/\n\n#include <stdio.h>\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lauxlib.h\"\n}\n\nstatic int print(lua_State *L)\n{\n int n=lua_gettop(L);\n int i;\n for (i=1; i<=n; i++)\n {\n  if (i>1) printf(\"\\t\");\n  if (lua_isstring(L,i))\n   printf(\"%s\",lua_tostring(L,i));\n  else if (lua_isnil(L,i))\n   printf(\"%s\",\"nil\");\n  else if (lua_isboolean(L,i))\n   printf(\"%s\",lua_toboolean(L,i) ? \"true\" : \"false\");\n  else\n   printf(\"%s:%p\",luaL_typename(L,i),lua_topointer(L,i));\n }\n printf(\"\\n\");\n return 0;\n}\n\nint main(int argc, char **argv)\n{\n lua_State *L=lua_open();\n char *file=NULL;\n lua_register(L,\"print\",print);\n if (argc > 1) {\n \tfile = argv[1];\n }\n if (luaL_dofile(L,file)!=0) fprintf(stderr,\"%s\\n\",lua_tostring(L,-1));\n lua_close(L);\n return 0;\n}\n"
  },
  {
    "path": "etc/lua.hpp",
    "content": "// lua.hpp\n// Lua header files for C++\n// <<extern \"C\">> not supplied automatically because Lua also compiles as C++\n\nextern \"C\" {\n#include \"lua.h\"\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n}\n"
  },
  {
    "path": "etc/lua.pc",
    "content": "# lua.pc -- pkg-config data for Lua\n\n# vars from install Makefile\n\n# grep '^V=' ../Makefile\nV= 5.1\n# grep '^R=' ../Makefile\nR= 5.1.4\n\n# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'\nprefix= /usr\nINSTALL_BIN= ${prefix}/bin\nINSTALL_INC= ${prefix}/include\nINSTALL_LIB= ${prefix}/lib\nINSTALL_MAN= ${prefix}/man/man1\nINSTALL_LMOD= ${prefix}/share/lua/${V}\nINSTALL_CMOD= ${prefix}/lib/lua/${V}\n\n# canonical vars\nexec_prefix=${prefix}\nlibdir=${exec_prefix}/lib\nincludedir=${prefix}/include\n\nName: LLVM-Lua\nDescription: An Extensible Extension Language with JIT support from LLVM\nVersion: ${R}\nRequires: \nLibs: -L${libdir} -llua -lm `llvm-config --ldflags --libs core jit native bitreader bitwriter ipo`\nCflags: -I${includedir}\n\n# (end of lua.pc)\n"
  },
  {
    "path": "etc/luavs.bat",
    "content": "@rem Script to build Lua under \"Visual Studio .NET Command Prompt\".\r\n@rem Do not run from this directory; run it from the toplevel: etc\\luavs.bat .\r\n@rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.\r\n@rem (contributed by David Manura and Mike Pall)\r\n\r\n@setlocal\r\n@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE\r\n@set MYLINK=link /nologo\r\n@set MYMT=mt /nologo\r\n\r\ncd src\r\n%MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c\r\ndel lua.obj luac.obj\r\n%MYLINK% /DLL /out:lua51.dll l*.obj\r\nif exist lua51.dll.manifest^\r\n  %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2\r\n%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c\r\n%MYLINK% /out:lua.exe lua.obj lua51.lib\r\nif exist lua.exe.manifest^\r\n  %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe\r\n%MYCOMPILE% l*.c print.c\r\ndel lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^\r\n    loslib.obj ltablib.obj lstrlib.obj loadlib.obj\r\n%MYLINK% /out:luac.exe *.obj\r\nif exist luac.exe.manifest^\r\n  %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe\r\ndel *.obj *.manifest\r\ncd ..\r\n"
  },
  {
    "path": "etc/min.c",
    "content": "/*\n* min.c -- a minimal Lua interpreter\n* loads stdin only with minimal error handling.\n* no interaction, and no standard library, only a \"print\" function.\n*/\n\n#include <stdio.h>\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\nstatic int print(lua_State *L)\n{\n int n=lua_gettop(L);\n int i;\n for (i=1; i<=n; i++)\n {\n  if (i>1) printf(\"\\t\");\n  if (lua_isstring(L,i))\n   printf(\"%s\",lua_tostring(L,i));\n  else if (lua_isnil(L,i))\n   printf(\"%s\",\"nil\");\n  else if (lua_isboolean(L,i))\n   printf(\"%s\",lua_toboolean(L,i) ? \"true\" : \"false\");\n  else\n   printf(\"%s:%p\",luaL_typename(L,i),lua_topointer(L,i));\n }\n printf(\"\\n\");\n return 0;\n}\n\nint main(void)\n{\n lua_State *L=lua_open();\n lua_register(L,\"print\",print);\n if (luaL_dofile(L,NULL)!=0) fprintf(stderr,\"%s\\n\",lua_tostring(L,-1));\n lua_close(L);\n return 0;\n}\n"
  },
  {
    "path": "etc/noparser.c",
    "content": "/*\n* The code below can be used to make a Lua core that does not contain the\n* parsing modules (lcode, llex, lparser), which represent 35% of the total core.\n* You'll only be able to load binary files and strings, precompiled with luac.\n* (Of course, you'll have to build luac with the original parsing modules!)\n*\n* To use this module, simply compile it (\"make noparser\" does that) and list\n* its object file before the Lua libraries. The linker should then not load\n* the parsing modules. To try it, do \"make luab\".\n*\n* If you also want to avoid the dump module (ldump.o), define NODUMP.\n* #define NODUMP\n*/\n\n#define LUA_CORE\n\n#include \"llex.h\"\n#include \"lparser.h\"\n#include \"lzio.h\"\n\nLUAI_FUNC void luaX_init (lua_State *L) {\n  UNUSED(L);\n}\n\nLUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {\n  UNUSED(z);\n  UNUSED(buff);\n  UNUSED(name);\n  lua_pushliteral(L,\"parser not loaded\");\n  lua_error(L);\n  return NULL;\n}\n\n#ifdef NODUMP\n#include \"lundump.h\"\n\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) {\n  UNUSED(f);\n  UNUSED(w);\n  UNUSED(data);\n  UNUSED(strip);\n#if 1\n  UNUSED(L);\n  return 0;\n#else\n  lua_pushliteral(L,\"dumper not loaded\");\n  lua_error(L);\n#endif\n}\n#endif\n"
  },
  {
    "path": "etc/strict.lua",
    "content": "--\n-- strict.lua\n-- checks uses of undeclared global variables\n-- All global variables must be 'declared' through a regular assignment\n-- (even assigning nil will do) in a main chunk before being used\n-- anywhere or assigned to inside a function.\n--\n\nlocal getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget\n\nlocal mt = getmetatable(_G)\nif mt == nil then\n  mt = {}\n  setmetatable(_G, mt)\nend\n\nmt.__declared = {}\n\nlocal function what ()\n  local d = getinfo(3, \"S\")\n  return d and d.what or \"C\"\nend\n\nmt.__newindex = function (t, n, v)\n  if not mt.__declared[n] then\n    local w = what()\n    if w ~= \"main\" and w ~= \"C\" then\n      error(\"assign to undeclared variable '\"..n..\"'\", 2)\n    end\n    mt.__declared[n] = true\n  end\n  rawset(t, n, v)\nend\n  \nmt.__index = function (t, n)\n  if not mt.__declared[n] and what() ~= \"C\" then\n    error(\"variable '\"..n..\"' is not declared\", 2)\n  end\n  return rawget(t, n)\nend\n\n"
  },
  {
    "path": "gen_changelog.sh",
    "content": "#!/bin/sh\n#\n\nsvn2cl --authors=AUTHORS --break-before-msg --group-by-day -o ChangeLog\n\n"
  },
  {
    "path": "llvm-lua/CMakeLists.txt",
    "content": "\n#\n# llvm-lua source\n#\nset(NON_LLVM_SRC\n\tlua_core.c\n\tlua_vm_ops_static.c\n\tload_jit_proto.c\n)\nset(LLVM_COMMON_SRC\n\tLLVMCompiler.cpp\n\tllvm_compiler.cpp\n\tload_embedded_bc.cpp\n\tload_vm_ops.cpp\n\tlua_vm_ops_bc.h\n\t${NON_LLVM_SRC}\n)\nset(NO_JIT_SRC\n\tno_jit.c\n\t${NON_LLVM_SRC}\n)\nset(EMB_BCS\n\tlua_vm_ops_bc.h\n\tliblua_main_bc.h\n)\nset(LLVM_LUA_SRC\n\tllvm-lua.cpp\n\tlua_interpreter.c\n)\nset(LLVM_LUAC_SRC\n\tllvm-luac.cpp\n\tlua_compiler.c\n\tLLVMDumper.cpp\n\tllvm_dumper.cpp\n\tload_liblua_main.cpp\n\tliblua_main_bc.h\n)\nset(LLVM_LUA_LIB_SRC\n\tlua_interpreter.c\n\t${LLVM_COMMON_SRC}\n)\nset(LLVM_LUA_BINS)\nset(LUA_COMPILER)\n\ninclude_directories(${CMAKE_CURRENT_SOURCE_DIR}\n\t\t\t\t${PROJECT_SOURCE_DIR}/src\n\t\t\t\t${CMAKE_CURRENT_BINARY_DIR})\n\nconfigure_file(\n\t\"${CMAKE_CURRENT_SOURCE_DIR}/llvm_lua_config.h.in\"\n\t\"${CMAKE_CURRENT_BINARY_DIR}/llvm_lua_config.h\"\n\t@ONLY\n)\n\nadd_executable(bin2c bin2c.c)\n\n# cflags for LLVM bitcode files.\nif(CMAKE_BUILD_TYPE STREQUAL \"Release\")\n\tset(BC_CFLAGS \"${COMMON_CFLAGS} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}\")\nelse()\n\tset(BC_CFLAGS \"${COMMON_CFLAGS} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}\")\nendif()\nstring(REGEX REPLACE \"[ \\t\\n]+\" \";\" BC_CFLAGS ${BC_CFLAGS})\n# setup cross-compiler flags.\nif(CROSS_COMPILE)\n\tif(NOT CROSS_ISYSTEM STREQUAL \"\")\n\t\tset(BC_CFLAGS ${BC_CFLAGS} -nostdinc)\n\t\tstring(REGEX REPLACE \":([^:]+)\" \";-isystem;\\\\1\" ISYSTEM_FLAGS \"${CROSS_ISYSTEM}\")\n\t\tset(BC_CFLAGS ${BC_CFLAGS} -Wno-gnu-designator -isystem ${ISYSTEM_FLAGS})\n\tendif()\n\tset(BC_CFLAGS ${BC_CFLAGS} -ccc-host-triple ${CROSS_TRIPLE})\n\tif(NOT CROSS_CPU STREQUAL \"\")\n\t\tset(BC_CFLAGS ${BC_CFLAGS} -mcpu=${CROSS_CPU})\n\tendif()\n\t# don't need shared library support for cross-compiler\n\tset(WANT_SHARED_LIBRARY FALSE)\nendif(CROSS_COMPILE)\n# ignore unused parameters in lua_vm_ops* files.\nset(BC_CFLAGS ${BC_CFLAGS} -Wno-unused-parameter)\nset(BC_CFLAGS ${BC_CFLAGS} -c -emit-llvm -I../src)\n\n#\n# Embedded LLVM bitcode files\n#\nadd_llvm_bc_library(lua_vm_ops lua_vm_ops.c)\nadd_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua_vm_ops_bc.h\n\tCOMMAND bin2c -z -c ${CMAKE_CURRENT_BINARY_DIR}/lua_vm_ops.bc ${CMAKE_CURRENT_BINARY_DIR}/lua_vm_ops_bc.h\n\tWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}\n\tDEPENDS bin2c ${CMAKE_CURRENT_BINARY_DIR}/lua_vm_ops.bc\n)\nadd_llvm_bc_library(liblua_main lua_main.c ${NO_JIT_SRC})\nadd_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liblua_main_bc.h\n\tCOMMAND bin2c -z -c ${CMAKE_CURRENT_BINARY_DIR}/liblua_main.bc ${CMAKE_CURRENT_BINARY_DIR}/liblua_main_bc.h\n\tWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}\n\tDEPENDS bin2c ${CMAKE_CURRENT_BINARY_DIR}/liblua_main.bc\n)\n\n#\n# Lua library.\n#\nset(LLVM_LUA_LIBS)\n\nif(WANT_STATIC_LIBRARY)\n\t# llvm-lua static library.\n\tadd_library(llvm-lua_static STATIC ${LLVM_LUA_LIB_SRC})\n\tadd_target_properties(llvm-lua_static COMPILE_FLAGS \"${COMMON_CFLAGS} ${LLVM_CFLAGS}\")\n\tadd_target_properties(llvm-lua_static LINK_FLAGS \"${LD_FLAGS} ${COMMON_LDFLAGS} ${LLVM_LFLAGS}\")\n\ttarget_link_libraries(llvm-lua_static ${LIBS} ${LLVM_ALL_LIBS})\n\n\t# link lua interpreter with static library\n\tset(LLVM_LUA_MAIN_LIB llvm-lua_static)\n\tset(LLVM_LUA_LIBS ${LLVM_LUA_LIBS} llvm-lua_static)\n\n\tif (WANT_NOJIT_LIBRARIES)\n\t\t# lua static library without LLVM JIT support.\n\t\tadd_library(llvm-lua_nojit_static STATIC ${NO_JIT_SRC})\n\t\tadd_target_properties(llvm-lua_nojit_static COMPILE_FLAGS \"${COMMON_CFLAGS}\")\n\t\tadd_target_properties(llvm-lua_nojit_static LINK_FLAGS \"${LD_FLAGS} ${COMMON_LDFLAGS}\")\n\t\ttarget_link_libraries(llvm-lua_nojit_static ${LIBS})\n\n\t\tset(LLVM_LUA_LIBS ${LLVM_LUA_LIBS} llvm-lua_nojit_static)\n\tendif (WANT_NOJIT_LIBRARIES)\nendif(WANT_STATIC_LIBRARY)\n\nif(WANT_SHARED_LIBRARY)\n\t# llvm-lua dynamic library\n\tadd_library(llvm-lua_dynamic SHARED ${LLVM_LUA_LIB_SRC})\n\tadd_target_properties(llvm-lua_dynamic COMPILE_FLAGS \"${COMMON_CFLAGS} ${LLVM_CFLAGS}\")\n\tadd_target_properties(llvm-lua_dynamic LINK_FLAGS \"${LD_FLAGS} ${COMMON_LDFLAGS} ${LLVM_LFLAGS}\")\n\ttarget_link_libraries(llvm-lua_dynamic ${LIBS} ${LLVM_ALL_LIBS})\n\tset_target_properties(llvm-lua_dynamic PROPERTIES OUTPUT_NAME llvm-lua)\n\n\t# link lua interpreter with dynamic library\n\tset(LLVM_LUA_MAIN_LIB llvm-lua_dynamic)\n\tset(LLVM_LUA_LIBS ${LLVM_LUA_LIBS} llvm-lua_dynamic)\n\n\tif (WANT_NOJIT_LIBRARIES)\n\t\t# lua dynamic library without LLVM JIT support.\n\t\tadd_library(llvm-lua_nojit_dynamic SHARED ${NO_JIT_SRC})\n\t\tadd_target_properties(llvm-lua_nojit_dynamic COMPILE_FLAGS \"${COMMON_CFLAGS}\")\n\t\tadd_target_properties(llvm-lua_nojit_dynamic LINK_FLAGS \"${LD_FLAGS} ${COMMON_LDFLAGS}\")\n\t\ttarget_link_libraries(llvm-lua_nojit_dynamic ${LIBS})\n\t\tset_target_properties(llvm-lua_nojit_dynamic PROPERTIES OUTPUT_NAME llvm-lua_nojit)\n\n\t\tset(LLVM_LUA_LIBS ${LLVM_LUA_LIBS} llvm-lua_nojit_dynamic)\n\tendif (WANT_NOJIT_LIBRARIES)\nendif(WANT_SHARED_LIBRARY)\n\n#\n# static library liblua_main.a\n#\nif(NOT CROSS_COMPILE)\n\tadd_library(llvm-lua_main STATIC lua_main.c ${NO_JIT_SRC})\n\tadd_target_properties(llvm-lua_main COMPILE_FLAGS \"${COMMON_CFLAGS}\")\n\tadd_target_properties(llvm-lua_main LINK_FLAGS \"${LD_FLAGS} ${COMMON_LDFLAGS}\")\n\n\tset(LLVM_LUA_LIBS ${LLVM_LUA_LIBS} llvm-lua_main)\nendif(NOT CROSS_COMPILE)\n\n# set library version & soversion\nif(LLVM_LUA_LIBS)\n\tset_target_properties(${LLVM_LUA_LIBS} PROPERTIES\n\t\tVERSION ${LLVM_LUA_VERSION}\n\t\tSOVERSION ${LLVM_LUA_SOVERSION}\n\t\tCLEAN_DIRECT_OUTPUT 1\n\t)\nendif(LLVM_LUA_LIBS)\n\n# set rpath & handle framework\nif(APPLE)\n\tset(INSTALL_NAME_DIR)\n\t# Set Dynamic Library and Framework properties\n\tif(WANT_FRAMEWORK)\n\t\tset_target_properties(llvm-lua_dynamic PROPERTIES\n\t\t\tFRAMEWORK TRUE\n\t\t\tFRAMEWORK_VERSION \"${LUA_FRAMEWORK_VERSION_NUMBER}\"\n\t\t\tPUBLIC_HEADER \"${LUA_LIB_HEADERS}\"\n\t\t\tRESOURCE \"${RESOURCE_FILES}\"\n\t\t)\n\t\tset(INSTALL_NAME_DIR ${CMAKE_FRAMEWORK_INSTALL_NAME_DIR})\n\n\t\t# Short Version is the \"marketing version\". It is the version\n\t\t# the user sees in an information panel.\n\t\tset(MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n\t\t\t\t\t\t\"${LLVM_LUA_VERSION_MAJOR}.${LLVM_LUA_VERSION_MINOR}.${LLVM_LUA_VERSION_PATCH}\")\n\t\t# Bundle version is the version the OS looks at.\n\t\tset(MACOSX_FRAMEWORK_BUNDLE_VERSION\n\t\t\t\t\t\t\"${LLVM_LUA_VERSION_MAJOR}.${LLVM_LUA_VERSION_MINOR}.${LLVM_LUA_VERSION_PATCH}\")\n\t\tset(MACOSX_FRAMEWORK_IDENTIFIER \"org.lua.llvm-lua\")\n\telseif(WANT_SHARED_LIBRARY)\n\t\tset_target_properties(llvm-lua_dynamic PROPERTIES\n\t\t\tFRAMEWORK FALSE\n\t\t)\n\t\tset(INSTALL_NAME_DIR ${CMAKE_DYLIB_INSTALL_NAME_DIR})\n\tendif(WANT_FRAMEWORK)\n\n\tif(INSTALL_NAME_DIR)\n\t\tset_target_properties(llvm-lua_dynamic PROPERTIES\n\t\t\tINSTALL_NAME_DIR ${INSTALL_NAME_DIR}\n\t\t\tBUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH}\n\t\t)\n\telse(INSTALL_NAME_DIR)\n\t\t# no install_name folder force BUILD_WITH_INSTALL_RPATH to OFF\n\t\tset_property(TARGET llvm-lua_dynamic PROPERTY BUILD_WITH_INSTALL_RPATH OFF)\n\tendif(INSTALL_NAME_DIR)\n\n\tset(CMAKE_OSX_ARCHITECTURES ${OSX_ARCHITECTURES})\nelseif(WANT_SHARED_LIBRARY)\n\tset_target_properties(llvm-lua_dynamic PROPERTIES\n\t\tINSTALL_RPATH ${CMAKE_INSTALL_RPATH}\n\t\tBUILD_WITH_INSTALL_RPATH ${CMAKE_BUILD_WITH_INSTALL_RPATH}\n\t)\nendif(APPLE)\n\n#\n# Lua compiler\n#\nadd_executable(llvm-luac ${LLVM_LUAC_SRC})\nadd_target_properties(llvm-luac COMPILE_FLAGS \"${COMMON_CFLAGS} ${LLVM_CFLAGS}\")\nadd_target_properties(llvm-luac LINK_FLAGS\n\t\"${LD_FLAGS} ${COMMON_LDFLAGS} ${LLVM_LFLAGS}\")\ntarget_link_libraries(llvm-luac ${LLVM_LUA_MAIN_LIB} ${LLVM_ALL_LIBS})\nset(LLVM_LUA_BINS llvm-luac)\n\n#\n# build as a cross-compiler\n#\nif(CROSS_COMPILE)\n\tset(LUA_COMPILER \"${CMAKE_CURRENT_BINARY_DIR}/lua-cross-compiler\")\n\tset_target_properties(llvm-luac PROPERTIES OUTPUT_NAME ${CROSS_TRIPLE}-llvm-luac)\n\tconfigure_file(\"${CMAKE_CURRENT_SOURCE_DIR}/lua-cross-compiler.in\" \"${LUA_COMPILER}\" @ONLY)\nelse(CROSS_COMPILE)\n\tset(LUA_COMPILER \"${CMAKE_CURRENT_BINARY_DIR}/lua-compiler\")\n\tconfigure_file(\"${CMAKE_CURRENT_SOURCE_DIR}/lua-compiler.in\" \"${LUA_COMPILER}\" @ONLY)\nendif(CROSS_COMPILE)\n\n#\n# Lua stand-alone interpreter\n#\nif(NOT CROSS_COMPILE)\n\tadd_executable(llvm-lua_binary ${LLVM_LUA_SRC})\n\tadd_target_properties(llvm-lua_binary COMPILE_FLAGS \"${COMMON_CFLAGS} ${LLVM_CFLAGS}\")\n\tadd_target_properties(llvm-lua_binary LINK_FLAGS\n\t\t\"${LD_FLAGS} ${COMMON_LDFLAGS} ${LLVM_LFLAGS}\")\n\ttarget_link_libraries(llvm-lua_binary ${LLVM_LUA_MAIN_LIB} ${LLVM_JIT_LIBS})\n\t# rename llvm-lua.bin to llvm-lua\n\tset_target_properties(llvm-lua_binary PROPERTIES OUTPUT_NAME llvm-lua)\n\tset(LLVM_LUA_BINS ${LLVM_LUA_BINS} llvm-lua_binary)\nendif(NOT CROSS_COMPILE)\n\n#\n# install llvm-lua/llvm-luac & library.\n#\nif(APPLE AND WANT_SHARED_LIBRARY AND WANT_FRAMEWORK)\n\t# Make directory: llvm-lua.framework/Versions/5.1/MacOS\n\tadd_custom_command(\n\t\tTARGET llvm-lua_dynamic\n\t\tPOST_BUILD\n\t\tCOMMAND ${CMAKE_COMMAND}\n\t\tARGS -E make_directory \"${llvm_lua_BINARY_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_VERSIONED_EXECUTABLE_DIR}\"\n\t\tCOMMENT \"Command line tools\")\n\n\t# Make directory: llvm-lua.framework/Versions/5.1/lib\n\tadd_custom_command(\n\t\tTARGET llvm-lua_dynamic\n\t\tPOST_BUILD\n\t\tCOMMAND ${CMAKE_COMMAND}\n\t\tARGS -E make_directory \"${llvm_lua_BINARY_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_VERSIONED_LIB_DIR}\"\n\t\tCOMMENT \"Static lib\")\n\n\t# Copy llvm-lua to: llvm-lua.framework/Versions/5.1/MacOS/llvm-lua\n\tadd_custom_command(\n\t\tTARGET llvm-lua_dynamic llvm-lua_binary\n\t\tPOST_BUILD\n\t\tCOMMAND ${CMAKE_COMMAND}\n\t\tARGS -E copy \"${llvm_lua_BINARY_DIR}/llvm-lua\" \"${llvm_lua_BINARY_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_VERSIONED_EXECUTABLE_DIR}/llvm-lua\"\n\t\tCOMMENT \"Command line tools\")\n\n\t# Copy llvm-luac to: llvm-lua.framework/Versions/5.1/MacOS/llvm-luac\n\tadd_custom_command(\n\t\tTARGET llvm-lua_dynamic llvm-luac\n\t\tPOST_BUILD\n\t\tCOMMAND ${CMAKE_COMMAND}\n\t\tARGS -E copy ${llvm_lua_BINARY_DIR}/llvm-luac ${llvm_lua_BINARY_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_VERSIONED_EXECUTABLE_DIR}/llvm-luac\n\t\tCOMMENT \"Command line tools\")\n\n\t# Copy liblua.a to: llvm-lua.framework/Versions/5.1/lib/liblua.a\n\tadd_custom_command(\n\t\tTARGET llvm-lua_dynamic llvm-lua_static\n\t\tPOST_BUILD\n\t\tCOMMAND ${CMAKE_COMMAND}\n\t\tARGS -E copy \"${llvm_lua_BINARY_DIR}/liblua.a\" \"${llvm_lua_BINARY_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_VERSIONED_LIB_DIR}/liblua.a\"\n\t\tCOMMENT \"Static lib\")\n\n\t# Will install framework to /Library/Frameworks directory or user specified\n\tinstall(TARGETS llvm-lua_dynamic\n\t\tFRAMEWORK DESTINATION ${CMAKE_FRAMEWORK_INSTALL_DIR}\n\t)\n\n\tif(LUA_FRAMEWORK_SYMLINKS)\n\t\tinstall(CODE \"EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E make_directory \\\"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin\\\")\")\n\n\t\t# create a symbolic link for llvm-lua\n\t\t# and add it to the install manifest\n\t\tinstall(CODE \"EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E create_symlink \\\"${CMAKE_FRAMEWORK_INSTALL_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_CURRENT_EXECUTABLE_DIR}/llvm-lua\\\" \\\"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/lua\\\")\n\t\tlist(APPEND CMAKE_INSTALL_MANIFEST_FILES \\\"${CMAKE_INSTALL_PREFIX}/bin/llvm-lua\\\")\n\t\t\")\n\n\t\t# create a symbolic link for llvm-luac\n\t\t# and add it to the install manifest\n\t\tinstall(CODE \"EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E create_symlink \\\"${CMAKE_FRAMEWORK_INSTALL_DIR}/${LUA_FRAMEWORK_NAME}/${LUA_FRAMEWORK_CURRENT_EXECUTABLE_DIR}/llvm-luac\\\" \\\"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/luac\\\")\n\t\tlist(APPEND CMAKE_INSTALL_MANIFEST_FILES \\\"${CMAKE_INSTALL_PREFIX}/bin/llvm-luac\\\")\n\t\t\")\n\tendif(LUA_FRAMEWORK_SYMLINKS)\n\nelse(APPLE AND WANT_SHARED_LIBRARY AND WANT_FRAMEWORK)\n\tinstall(TARGETS ${LLVM_LUA_BINS}\n\t\tRUNTIME DESTINATION bin\n\t)\n\tinstall(FILES ${LUA_COMPILER}\n\t\tDESTINATION bin\n\t\tPERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE\n\t\tWORLD_READ WORLD_EXECUTE\n\t)\n\n\tif(LLVM_LUA_LIBS)\n\t\tinstall(TARGETS ${LLVM_LUA_LIBS}\n\t\t\tLIBRARY DESTINATION lib\n\t\t\tARCHIVE DESTINATION lib\n\t\t)\n\tendif(LLVM_LUA_LIBS)\n\nendif(APPLE AND WANT_SHARED_LIBRARY AND WANT_FRAMEWORK)\n\n"
  },
  {
    "path": "llvm-lua/COPYRIGHT.llvm-lua",
    "content": "Copyright (c) 2008 Robert G. Jakabosky\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\nMIT License: http://www.opensource.org/licenses/mit-license.php\n\n"
  },
  {
    "path": "llvm-lua/LLVMCompiler.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include \"llvm/LLVMContext.h\"\n#include \"llvm/DerivedTypes.h\"\n#include \"llvm/ExecutionEngine/ExecutionEngine.h\"\n#include \"llvm/Module.h\"\n#include \"llvm/PassManager.h\"\n#include \"llvm/Analysis/Verifier.h\"\n#include \"llvm/Target/TargetData.h\"\n#include \"llvm/Target/TargetMachine.h\"\n#include \"llvm/Target/TargetOptions.h\" \n#include \"llvm/Transforms/Scalar.h\"\n#include \"llvm/Transforms/IPO.h\"\n#include \"llvm/Transforms/Utils/Cloning.h\"\n#include \"llvm/Support/IRBuilder.h\"\n#include \"llvm/Support/Timer.h\"\n#include \"llvm/Support/CommandLine.h\"\n#include <cstdio>\n#include <string>\n#include <vector>\n#include <math.h>\n\n#include \"LLVMCompiler.h\"\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n#include \"lopcodes.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lcoco.h\"\n#ifdef __cplusplus\n}\n#endif\n#include \"load_vm_ops.h\"\n\n/*\n * Using lazing compilation requires large 512K c-stacks for each coroutine.\n */\nstatic bool NoLazyCompilation = true;\nstatic unsigned int OptLevel = 3;\n\nstatic llvm::cl::opt<bool> Fast(\"fast\",\n                   llvm::cl::desc(\"Generate code quickly, \"\n                            \"potentially sacrificing code quality\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> OpCodeStats(\"opcode-stats\",\n                   llvm::cl::desc(\"Generate stats on compiled Lua opcodes.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> RunOpCodeStats(\"runtime-opcode-stats\",\n                   llvm::cl::desc(\"Generate stats on executed Lua opcodes.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> PrintRunOpCodes(\"print-runtime-opcodes\",\n                   llvm::cl::desc(\"Print each opcode before executing it.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> CompileLargeFunctions(\"compile-large-functions\",\n                   llvm::cl::desc(\"Compile all Lua functions even really large functions.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<int> MaxFunctionSize(\"max-func-size\",\n                   llvm::cl::desc(\"Functions larger then this will not be compiled.\"),\n                   llvm::cl::value_desc(\"int\"),\n                   llvm::cl::init(200));\n\nstatic llvm::cl::opt<bool> DontInlineOpcodes(\"do-not-inline-opcodes\",\n                   llvm::cl::desc(\"Turn off inlining of opcode functions.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> VerifyFunctions(\"verify-functions\",\n                   llvm::cl::desc(\"Verify each compiled function.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> DumpFunctions(\"dump-functions\",\n                   llvm::cl::desc(\"Dump LLVM IR for each function.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> DebugOpCodes(\"g\",\n                   llvm::cl::desc(\"Allow debugging of Lua code.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> DisableOpt(\"O0\",\n                   llvm::cl::desc(\"Disable optimizations.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> OptLevelO1(\"O1\",\n                   llvm::cl::desc(\"Optimization level 1.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> OptLevelO2(\"O2\",\n                   llvm::cl::desc(\"Optimization level 2.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> OptLevelO3(\"O3\",\n                   llvm::cl::desc(\"Optimization level 3.\"),\n                   llvm::cl::init(false));\n\n#define BRANCH_COND -1\n#define BRANCH_NONE -2\n\n//===----------------------------------------------------------------------===//\n// Lua bytecode to LLVM IR compiler\n//===----------------------------------------------------------------------===//\n\nllvm::Type *LLVMCompiler::get_var_type(val_t type, hint_t hints) {\n\tswitch(type) {\n\tcase VAR_T_VOID:\n\t\treturn llvm::Type::getVoidTy(getCtx());\n\tcase VAR_T_INT:\n\tcase VAR_T_ARG_A:\n\tcase VAR_T_ARG_B:\n\tcase VAR_T_ARG_BK:\n\tcase VAR_T_ARG_Bx:\n\tcase VAR_T_ARG_Bx_NUM_CONSTANT:\n\tcase VAR_T_ARG_B_FB2INT:\n\tcase VAR_T_ARG_sBx:\n\tcase VAR_T_ARG_C:\n\tcase VAR_T_ARG_CK:\n\tcase VAR_T_ARG_C_NUM_CONSTANT:\n\tcase VAR_T_ARG_C_NEXT_INSTRUCTION:\n\tcase VAR_T_ARG_C_FB2INT:\n\tcase VAR_T_PC_OFFSET:\n\tcase VAR_T_INSTRUCTION:\n\tcase VAR_T_NEXT_INSTRUCTION:\n\t\treturn llvm::Type::getInt32Ty(getCtx());\n\tcase VAR_T_LUA_STATE_PTR:\n\t\treturn Ty_lua_State_ptr;\n\tcase VAR_T_K:\n\t\treturn Ty_TValue_ptr;\n\tcase VAR_T_CL:\n\t\treturn Ty_LClosure_ptr;\n\tcase VAR_T_OP_VALUE_0:\n\tcase VAR_T_OP_VALUE_1:\n\tcase VAR_T_OP_VALUE_2:\n\t\tif(hints & HINT_USE_LONG) {\n\t\t\treturn llvm::Type::getInt64Ty(getCtx());\n\t\t}\n\t\treturn llvm::Type::getDoubleTy(getCtx());\n\tdefault:\n\t\tfprintf(stderr, \"Error: missing var_type=%d\\n\", type);\n\t\texit(1);\n\t\tbreak;\n\t}\n\treturn NULL;\n}\n\nllvm::Value *LLVMCompiler::get_proto_constant(TValue *constant) {\n\tllvm::Value *val = NULL;\n\tswitch(ttype(constant)) {\n\tcase LUA_TBOOLEAN:\n\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(sizeof(LUA_NUMBER), !l_isfalse(constant)));\n\t\tbreak;\n\tcase LUA_TNUMBER:\n\t\tval = llvm::ConstantFP::get(getCtx(), llvm::APFloat(nvalue(constant)));\n\t\tbreak;\n\tcase LUA_TSTRING:\n\t\tbreak;\n\tcase LUA_TNIL:\n\tdefault:\n\t\tbreak;\n\t}\n\treturn val;\n}\n\nLLVMCompiler::LLVMCompiler(int useJIT) {\n\tstd::string error;\n\tllvm::Timer load_ops(\"load_ops\");\n\tllvm::Timer load_jit(\"load_jit\");\n\tllvm::FunctionType *func_type;\n\tllvm::Function *func;\n\tstd::vector<llvm::Type*> func_args;\n\tconst vm_func_info *func_info;\n\tint opcode;\n\n\t// set OptLevel\n\tif(OptLevelO1) OptLevel = 1;\n\tif(OptLevelO2) OptLevel = 2;\n\tif(OptLevelO3) OptLevel = 3;\n\tif(DisableOpt) OptLevel = 0;\n\t// create timers.\n\tlua_to_llvm = new llvm::Timer(\"lua_to_llvm\");\n\tcodegen = new llvm::Timer(\"codegen\");\n\tstrip_code = false;\n\n\t// initialize opcode data arrays.\n\topcode_data_len = 0;\n\top_hints = NULL;\n\top_values = NULL;\n\top_blocks = NULL;\n\tneed_op_block = NULL;\n\tresize_opcode_data(MaxFunctionSize);\n\n\tif(llvm::TimePassesIsEnabled) load_ops.startTimer();\n\n\tif(OpCodeStats) {\n\t\topcode_stats = new int[NUM_OPCODES];\n\t\tfor(int i = 0; i < NUM_OPCODES; i++) {\n\t\t\topcode_stats[i] = 0;\n\t\t}\n\t}\n\n\tif(!useJIT) {\n\t\t// running as static compiler, so don't use Lazy loading.\n\t\tNoLazyCompilation = true;\n\t}\n\t// load vm op functions\n\tM = load_vm_ops(getCtx(), NoLazyCompilation);\n\n\t// get important struct types.\n\tTy_TValue = M->getTypeByName(\"struct.lua_TValue\");\n\tif(Ty_TValue == NULL) {\n\t\tTy_TValue = M->getTypeByName(\"struct.TValue\");\n\t}\n\tTy_TValue_ptr = llvm::PointerType::getUnqual(Ty_TValue);\n\tTy_LClosure = M->getTypeByName(\"struct.LClosure\");\n\tTy_LClosure_ptr = llvm::PointerType::getUnqual(Ty_LClosure);\n\tTy_lua_State = M->getTypeByName(\"struct.lua_State\");\n\tTy_lua_State_ptr = llvm::PointerType::getUnqual(Ty_lua_State);\n\t// setup argument lists.\n\tfunc_args.clear();\n\tfunc_args.push_back(Ty_lua_State_ptr);\n\tlua_func_type = llvm::FunctionType::get(llvm::Type::getInt32Ty(getCtx()), func_args, false);\n\t// define extern vm_next_OP\n\tvm_next_OP = M->getFunction(\"vm_next_OP\");\n\tif(vm_next_OP == NULL) {\n\t\tfunc_args.clear();\n\t\tfunc_args.push_back(Ty_lua_State_ptr);\n\t\tfunc_args.push_back(Ty_LClosure_ptr);\n\t\tfunc_args.push_back(llvm::Type::getInt32Ty(getCtx()));\n\t\tfunc_type = llvm::FunctionType::get(llvm::Type::getVoidTy(getCtx()), func_args, false);\n\t\tvm_next_OP = llvm::Function::Create(func_type,\n\t\t\tllvm::Function::ExternalLinkage, \"vm_next_OP\", M);\n\t}\n\t// define extern vm_print_OP\n\tvm_print_OP = M->getFunction(\"vm_print_OP\");\n\tif(vm_print_OP == NULL) {\n\t\tfunc_args.clear();\n\t\tfunc_args.push_back(Ty_lua_State_ptr);\n\t\tfunc_args.push_back(Ty_LClosure_ptr);\n\t\tfunc_args.push_back(llvm::Type::getInt32Ty(getCtx()));\n\t\tfunc_args.push_back(llvm::Type::getInt32Ty(getCtx()));\n\t\tfunc_type = llvm::FunctionType::get(llvm::Type::getVoidTy(getCtx()), func_args, false);\n\t\tvm_print_OP = llvm::Function::Create(func_type,\n\t\t\tllvm::Function::ExternalLinkage, \"vm_print_OP\", M);\n\t}\n\t// function for counting each executed op.\n\tif(RunOpCodeStats) {\n\t\tvm_count_OP = M->getFunction(\"vm_count_OP\");\n\t\tif(vm_count_OP == NULL) {\n\t\t\tfunc_args.clear();\n\t\t\tfunc_args.push_back(llvm::Type::getInt32Ty(getCtx()));\n\t\t\tfunc_type = llvm::FunctionType::get(llvm::Type::getVoidTy(getCtx()), func_args, false);\n\t\t\tvm_count_OP = llvm::Function::Create(func_type,\n\t\t\t\tllvm::Function::ExternalLinkage, \"vm_count_OP\", M);\n\t\t}\n\t\tfor(int i = 0; i < NUM_OPCODES; i++) {\n\t\t\tvm_op_run_count[i] = 0;\n\t\t}\n\t}\n\t// define extern vm_mini_vm\n\tvm_mini_vm = M->getFunction(\"vm_mini_vm\");\n\tif(vm_mini_vm == NULL) {\n\t\tfunc_args.clear();\n\t\tfunc_args.push_back(Ty_lua_State_ptr);\n\t\tfunc_args.push_back(Ty_LClosure_ptr);\n\t\tfunc_args.push_back(llvm::Type::getInt32Ty(getCtx()));\n\t\tfunc_args.push_back(llvm::Type::getInt32Ty(getCtx()));\n\t\tfunc_type = llvm::FunctionType::get(llvm::Type::getVoidTy(getCtx()), func_args, false);\n\t\tvm_mini_vm = llvm::Function::Create(func_type,\n\t\t\tllvm::Function::ExternalLinkage, \"vm_mini_vm\", M);\n\t}\n\t// define extern vm_get_current_closure\n\tvm_get_current_closure = M->getFunction(\"vm_get_current_closure\");\n\t// define extern vm_get_current_constants\n\tvm_get_current_constants = M->getFunction(\"vm_get_current_constants\");\n\t// define extern vm_get_number\n\tvm_get_number = M->getFunction(\"vm_get_number\");\n\t// define extern vm_get_long\n\tvm_get_long = M->getFunction(\"vm_get_long\");\n\t// define extern vm_set_number\n\tvm_set_number = M->getFunction(\"vm_set_number\");\n\t// define extern vm_set_long\n\tvm_set_long = M->getFunction(\"vm_set_long\");\n\n\n\t// create prototype for vm_* functions.\n\tvm_op_funcs = new OPFunc *[NUM_OPCODES];\n\tfor(int i = 0; i < NUM_OPCODES; i++) vm_op_funcs[i] = NULL; // clear list.\n\tfor(int i = 0; true; i++) {\n\t\tfunc_info = &vm_op_functions[i];\n\t\topcode = func_info->opcode;\n\t\tif(opcode < 0) break;\n\t\tvm_op_funcs[opcode] = new OPFunc(func_info, vm_op_funcs[opcode]);\n\t\tfunc = M->getFunction(func_info->name);\n\t\tif(func != NULL) {\n\t\t\tvm_op_funcs[opcode]->func = func;\n\t\t\tvm_op_funcs[opcode]->compiled = !useJIT; // lazy compile ops when JIT is enabled.\n\t\t\tcontinue;\n\t\t}\n\t\tfunc_args.clear();\n\t\tfor(int x = 0; func_info->params[x] != VAR_T_VOID; x++) {\n\t\t\tfunc_args.push_back(get_var_type(func_info->params[x], func_info->hint));\n\t\t}\n\t\tfunc_type = llvm::FunctionType::get(\n\t\t\tget_var_type(func_info->ret_type, func_info->hint), func_args, false);\n\t\tfunc = llvm::Function::Create(func_type, llvm::Function::ExternalLinkage,\n\t\t\t\t\t\t\tfunc_info->name, M);\n\t\tvm_op_funcs[opcode]->func = func;\n\t\tvm_op_funcs[opcode]->compiled = true; // built-in op function.\n\t}\n\n\tif(llvm::TimePassesIsEnabled) load_ops.stopTimer();\n\n\tif(llvm::TimePassesIsEnabled) load_jit.startTimer();\n\t// Create the JIT.\n\tif(useJIT) {\n\t\tllvm::EngineBuilder engine(M);\n\n\t\tllvm::TargetOptions options;\n\t\toptions.GuaranteedTailCallOpt = true;\n\t\toptions.JITEmitDebugInfo = false;\n\t\toptions.JITExceptionHandling = false;\n\t\tengine.setTargetOptions(options);\n\n\t\tllvm::CodeGenOpt::Level optLevel = llvm::CodeGenOpt::Aggressive;\n\t\tif(Fast) {\n\t\t\toptLevel = llvm::CodeGenOpt::Default;\n\t\t}\n#ifdef LUA_CPP_SUPPORT\n\t\tllvm::ExceptionHandling = true; \n#endif\n\t\tengine.setErrorStr(&error);\n\t\tengine.setOptLevel(optLevel);\n\t\tTheExecutionEngine = engine.create();\n\t\tif(!TheExecutionEngine) {\n\t\t\tprintf(\"Error creating JIT engine: %s\\n\", error.c_str());\n\t\t}\n\t\tif (NoLazyCompilation)\n\t\t\tTheExecutionEngine->DisableLazyCompilation();\n\n\t\tTheExecutionEngine->runStaticConstructorsDestructors(false);\n\n\t\tif (NoLazyCompilation) {\n\t\t\tTheExecutionEngine->getPointerToFunction(vm_get_current_closure);\n\t\t\tTheExecutionEngine->getPointerToFunction(vm_get_current_constants);\n\t\t\tTheExecutionEngine->getPointerToFunction(vm_get_number);\n\t\t\tTheExecutionEngine->getPointerToFunction(vm_get_long);\n\t\t\tTheExecutionEngine->getPointerToFunction(vm_set_number);\n\t\t\tTheExecutionEngine->getPointerToFunction(vm_set_long);\n\t\t}\n\t} else {\n\t\tTheExecutionEngine = NULL;\n\t}\n\n\tif(OptLevel > 1) {\n\t\tTheFPM = new llvm::FunctionPassManager(M);\n\t\t\n\t\t/*\n\t\t * Function Pass Manager.\n\t\t */\n\t\t// Set up the optimizer pipeline.  Start with registering info about how the\n\t\t// target lays out data structures.\n\t\tif(useJIT) {\n\t\t\tTheFPM->add(new llvm::TargetData(*TheExecutionEngine->getTargetData()));\n\t\t} else {\n\t\t\tTheFPM->add(new llvm::TargetData(M));\n\t\t}\n\t\t// mem2reg\n\t\tTheFPM->add(llvm::createPromoteMemoryToRegisterPass());\n\t\t// Do simple \"peephole\" optimizations and bit-twiddling optzns.\n\t\tTheFPM->add(llvm::createInstructionCombiningPass());\n\t\t// Dead code Elimination\n\t\tTheFPM->add(llvm::createDeadCodeEliminationPass());\n\t\tif(OptLevel > 2) {\n\t\t\t// BlockPlacement\n\t\t\tTheFPM->add(llvm::createBlockPlacementPass());\n\t\t\t// Reassociate expressions.\n\t\t\tTheFPM->add(llvm::createReassociatePass());\n\t\t\t// Simplify the control flow graph (deleting unreachable blocks, etc).\n\t\t\tTheFPM->add(llvm::createCFGSimplificationPass());\n\t\t}\n\t} else {\n\t\tTheFPM = NULL;\n\t}\n\t\n\tif(llvm::TimePassesIsEnabled) load_jit.stopTimer();\n}\n\nvoid print_opcode_stats(int *stats, const char *stats_name) {\n\tint order[NUM_OPCODES];\n\tint max=0;\n\tint width=1;\n\tfor(int opcode = 0; opcode < NUM_OPCODES; opcode++) {\n\t\torder[opcode] = opcode;\n\t\tif(max < stats[opcode]) max = stats[opcode];\n\t\tfor(int n = 0; n < opcode; n++) {\n\t\t\tif(stats[opcode] >= stats[order[n]]) {\n\t\t\t\t// insert here.\n\t\t\t\tmemmove(&order[n + 1], &order[n], (opcode - n) * sizeof(int));\n\t\t\t\torder[n] = opcode;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// calc width.\n\twhile(max >= 10) { width++; max /= 10; }\n\t// sort by count.\n\tfprintf(stderr, \"===================== %s =======================\\n\", stats_name);\n\tint opcode;\n\tfor(int i = 0; i < NUM_OPCODES; i++) {\n\t\topcode = order[i];\n\t\tif(stats[opcode] == 0) continue;\n\t\tfprintf(stderr, \"%*d: %s(%d)\\n\", width, stats[opcode], luaP_opnames[opcode], opcode);\n\t}\n}\n\nLLVMCompiler::~LLVMCompiler() {\n\tstd::string error;\n\t// print opcode stats.\n\tif(OpCodeStats) {\n\t\tprint_opcode_stats(opcode_stats, \"Compiled OpCode counts\");\n\t\tdelete opcode_stats;\n\t}\n\tif(RunOpCodeStats) {\n\t\tprint_opcode_stats(vm_op_run_count, \"Compiled OpCode counts\");\n\t}\n\n\tresize_opcode_data(0);\n\n\tdelete lua_to_llvm;\n\tdelete codegen;\n\tif(TheFPM) delete TheFPM;\n\tTheFPM = NULL;\n\n\tfor(int i = 0; i < NUM_OPCODES; i++) {\n\t\tif(vm_op_funcs[i]) delete vm_op_funcs[i];\n\t}\n\tdelete[] vm_op_funcs;\n\n\t// Print out all of the generated code.\n\t//M->dump();\n\n\tif(TheExecutionEngine) {\n\t\tTheExecutionEngine->freeMachineCodeForFunction(vm_get_current_closure);\n\t\tTheExecutionEngine->freeMachineCodeForFunction(vm_get_current_constants);\n\t\tTheExecutionEngine->freeMachineCodeForFunction(vm_get_number);\n\t\tTheExecutionEngine->freeMachineCodeForFunction(vm_get_long);\n\t\tTheExecutionEngine->freeMachineCodeForFunction(vm_set_number);\n\t\tTheExecutionEngine->freeMachineCodeForFunction(vm_set_long);\n\t\tTheExecutionEngine->runStaticConstructorsDestructors(true);\n\t\tif(!TheExecutionEngine->removeModule(M)) {\n\t\t\tprintf(\"Failed find Module in execution engine.\\n\");\n\t\t\texit(1);\n\t\t}\n\t\tdelete TheExecutionEngine;\n\t}\n\tif(M) {\n\t\tdelete M;\n\t\tM = NULL;\n\t}\n}\n\nvoid LLVMCompiler::resize_opcode_data(int code_len) {\n\t// free old arrays.\n\tif(opcode_data_len > 0) {\n\t\t// free old data.\n\t\tclear_opcode_data(opcode_data_len);\n\t\tif(op_hints) delete[] op_hints;\n\t\tif(op_values) delete[] op_values;\n\t\tif(op_blocks) delete[] op_blocks;\n\t\tif(need_op_block) delete[] need_op_block;\n\t}\n\t// allocate new arrays\n\topcode_data_len = code_len;\n\tif(code_len == 0) return;\n\top_hints = new hint_t[code_len];\n\top_values = new OPValues *[code_len];\n\top_blocks = new llvm::BasicBlock *[code_len];\n\tneed_op_block = new bool[code_len];\n\tfor(int i = 0; i < code_len; i++) {\n\t\top_hints[i] = HINT_NONE;\n\t\top_values[i] = NULL;\n\t\top_blocks[i] = NULL;\n\t\tneed_op_block[i] = false;\n\t}\n}\n\nvoid LLVMCompiler::clear_opcode_data(int code_len) {\n\tif(code_len > opcode_data_len) {\n\t\tresize_opcode_data(code_len);\n\t\treturn;\n\t}\n\tfor(int i = 0; i < code_len; i++) {\n\t\top_hints[i] = HINT_NONE;\n\t\tif(op_values[i]) {\n\t\t\tdelete op_values[i];\n\t\t\top_values[i] = NULL;\n\t\t}\n\t\top_blocks[i] = NULL;\n\t\tneed_op_block[i] = false;\n\t}\n}\n\n/*\n * Pre-Compile all loaded functions.\n */\nvoid LLVMCompiler::compileAll(lua_State *L, Proto *parent) {\n\tint i;\n\t/* pre-compile parent */\n\tcompile(L, parent);\n\t/* pre-compile all children */\n\tfor(i = 0; i < parent->sizep; i++) {\n\t\tcompileAll(L, parent->p[i]);\n\t}\n}\n\nvoid LLVMCompiler::compile(lua_State *L, Proto *p)\n{\n\tInstruction *code=p->code;\n\tTValue *k=p->k;\n\tint code_len=p->sizecode;\n\tOPFunc *opfunc;\n\tllvm::Function *func;\n\tllvm::BasicBlock *true_block=NULL;\n\tllvm::BasicBlock *false_block=NULL;\n\tllvm::BasicBlock *current_block=NULL;\n\tllvm::BasicBlock *entry_block=NULL;\n\tllvm::Value *brcond=NULL;\n\tllvm::Value *func_L;\n\tllvm::Value *func_cl;\n\tllvm::Value *func_k;\n\tconst vm_func_info *func_info;\n\tstd::vector<llvm::Value*> args;\n\tllvm::CallInst *call=NULL;\n\tstd::vector<llvm::CallInst *> inlineList;\n\tstd::string name;\n\tchar name_buf[128];\n\t//char locals[LUAI_MAXVARS];\n\tbool inline_call=false;\n\tint strip_ops=0;\n\tint branch;\n\tInstruction op_intr;\n\tint opcode;\n\tint mini_op_repeat=0;\n\tint i;\n\tllvm::IRBuilder<> Builder(getCtx());\n\n#ifndef COCO_DISABLE\n\t// Don't run the JIT from a coroutine.\n\tif(!luaCOCO_mainthread(L)) {\n\t\treturn;\n\t}\n#endif\n\tif(code_len >= MaxFunctionSize) {\n\t\tif(TheExecutionEngine != NULL && !CompileLargeFunctions) {\n\t\t\t// don't JIT large functions.\n\t\t\treturn;\n\t\t} else {\n\t\t\t// make sure there is room to compile large functions.\n\t\t\tif(code_len > opcode_data_len) {\n\t\t\t\tresize_opcode_data(code_len);\n\t\t\t}\n\t\t}\n\t}\n\n\tif(llvm::TimePassesIsEnabled) lua_to_llvm->startTimer();\n\t// create function.\n\tname = getstr(p->source);\n\tif(name.size() > 32) {\n\t\tname = name.substr(0,32);\n\t}\n\t// replace non-alphanum characters with '_'\n\tfor(size_t n = 0; n < name.size(); n++) {\n\t\tchar c = name[n];\n\t\tif((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {\n\t\t\tcontinue;\n\t\t}\n\t\tif(c == '\\n' || c == '\\r') {\n\t\t\tname = name.substr(0,n);\n\t\t\tbreak;\n\t\t}\n\t\tname[n] = '_';\n\t}\n\tsnprintf(name_buf,128,\"_%d_%d\",p->linedefined, p->lastlinedefined);\n\tname += name_buf;\n\tfunc = llvm::Function::Create(lua_func_type, llvm::Function::ExternalLinkage, name, M);\n\t// name arg1 = \"L\"\n\tfunc_L = func->arg_begin();\n\tfunc_L->setName(\"L\");\n\t// entry block\n\tentry_block = llvm::BasicBlock::Create(getCtx(),\"entry\", func);\n\tBuilder.SetInsertPoint(entry_block);\n\t// get LClosure & constants.\n\tcall=Builder.CreateCall(vm_get_current_closure, func_L);\n\tinlineList.push_back(call);\n\tfunc_cl=call;\n\tcall=Builder.CreateCall(vm_get_current_constants, func_cl);\n\tinlineList.push_back(call);\n\tfunc_k=call;\n\n\t// find all jump/branch destinations and create a new basic block at that opcode.\n\t// also build hints for some opcodes.\n\tfor(i = 0; i < code_len; i++) {\n\t\top_intr=code[i];\n\t\topcode = GET_OPCODE(op_intr);\n\t\t// combind simple ops into one function call.\n\t\tif(is_mini_vm_op(opcode)) {\n\t\t\tmini_op_repeat++;\n\t\t} else {\n\t\t\tif(mini_op_repeat >= 3 && OptLevel > 1) {\n\t\t\t\top_hints[i - mini_op_repeat] |= HINT_MINI_VM;\n\t\t\t}\n\t\t\tmini_op_repeat = 0;\n\t\t}\n\t\tswitch (opcode) {\n\t\t\tcase OP_LOADBOOL:\n\t\t\t\tbranch = i+1;\n\t\t\t\t// check C operand if C!=0 then skip over the next op_block.\n\t\t\t\tif(GETARG_C(op_intr) != 0)\n\t\t\t\t\t++branch;\n\t\t\t\tneed_op_block[branch] = true;\n\t\t\t\tbreak;\n\t\t\tcase OP_LOADK: {\n\t\t\t\t// check if arg Bx is a number constant.\n\t\t\t\tTValue *rb = k + INDEXK(GETARG_Bx(op_intr));\n\t\t\t\tif(ttisnumber(rb)) op_hints[i] |= HINT_Bx_NUM_CONSTANT;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase OP_JMP:\n\t\t\t\t// always branch to the offset stored in operand sBx\n\t\t\t\tbranch = i + 1 + GETARG_sBx(op_intr);\n\t\t\t\tneed_op_block[branch] = true;\n\t\t\t\tbreak;\n\t\t\tcase OP_TAILCALL:\n\t\t\t\tbranch = i+1;\n\t\t\t\tneed_op_block[0] = true; /* branch to start of function if this is a recursive tail-call. */\n\t\t\t\tneed_op_block[branch] = true; /* branch to return instruction if not recursive. */\n\t\t\t\tbreak;\n\t\t\tcase OP_EQ:\n\t\t\tcase OP_LT:\n\t\t\tcase OP_LE:\n\t\t\t\t// check if arg C is a number constant.\n\t\t\t\tif(ISK(GETARG_C(op_intr))) {\n\t\t\t\t\tTValue *rc = k + INDEXK(GETARG_C(op_intr));\n\t\t\t\t\tif(ttisnumber(rc)) op_hints[i] |= HINT_C_NUM_CONSTANT;\n\t\t\t\t}\n\t\t\t\tif(GETARG_A(op_intr) == 1) {\n\t\t\t\t\top_hints[i] |= HINT_NOT;\n\t\t\t\t}\n\t\t\t\t// fall-through\n\t\t\tcase OP_TEST:\n\t\t\tcase OP_TESTSET:\n\t\t\tcase OP_TFORLOOP:\n\t\t\t\tbranch = ++i + 1;\n\t\t\t\top_intr=code[i];\n\t\t\t\tneed_op_block[branch + GETARG_sBx(op_intr)] = true; /* inline JMP op. */\n\t\t\t\tneed_op_block[branch] = true;\n\t\t\t\tbreak;\n\t\t\tcase OP_FORLOOP:\n\t\t\t\tbranch = i+1;\n\t\t\t\tneed_op_block[branch] = true;\n\t\t\t\tbranch += GETARG_sBx(op_intr);\n\t\t\t\tneed_op_block[branch] = true;\n\t\t\t\tbreak;\n\t\t\tcase OP_FORPREP:\n\t\t\t\tbranch = i + 1 + GETARG_sBx(op_intr);\n\t\t\t\tneed_op_block[branch] = true;\n\t\t\t\tneed_op_block[branch + 1] = true;\n\t\t\t\t// test if init/plimit/pstep are number constants.\n\t\t\t\tif(OptLevel > 1 && i >= 3) {\n\t\t\t\t\tlua_Number nums[3];\n\t\t\t\t\tbool found_val[3] = { false, false , false };\n\t\t\t\t\tbool is_const_num[3] = { false, false, false };\n\t\t\t\t\tbool all_longs=true;\n\t\t\t\t\tint found=0;\n\t\t\t\t\tOPValues *vals = new OPValues(4);\n\t\t\t\t\tint forprep_ra = GETARG_A(op_intr);\n\t\t\t\t\tbool no_jmp_end_point = true; // don't process ops after finding a jmp end point.\n\t\t\t\t\t// find & load constants for init/plimit/pstep\n\t\t\t\t\tfor(int x = 1; x < 6 && found < 3 && no_jmp_end_point; ++x) {\n\t\t\t\t\t\tconst TValue *tmp;\n\t\t\t\t\t\tInstruction op_intr2;\n\t\t\t\t\t\tint ra;\n\n\t\t\t\t\t\tif((i - x) < 0) break;\n\t\t\t\t\t\top_intr2 = code[i - x];\n\t\t\t\t\t\t// get 'a' register.\n\t\t\t\t\t\tra = GETARG_A(op_intr2);\n\t\t\t\t\t\tra -= forprep_ra;\n\t\t\t\t\t\t// check for jmp end-point.\n\t\t\t\t\t\tno_jmp_end_point = !(need_op_block[i - x]);\n\t\t\t\t\t\t// check that the 'a' register is for one of the value we are interested in.\n\t\t\t\t\t\tif(ra < 0 || ra > 2) continue;\n\t\t\t\t\t\t// only process this opcode if we haven't seen this value before.\n\t\t\t\t\t\tif(found_val[ra]) continue;\n\t\t\t\t\t\tfound_val[ra] = true;\n\t\t\t\t\t\tfound++;\n\t\t\t\t\t\tif(GET_OPCODE(op_intr2) == OP_LOADK) {\n\t\t\t\t\t\t\ttmp = k + GETARG_Bx(op_intr2);\n\t\t\t\t\t\t\tif(ttisnumber(tmp)) {\n\t\t\t\t\t\t\t\tlua_Number num=nvalue(tmp);\n\t\t\t\t\t\t\t\tnums[ra] = num;\n\t\t\t\t\t\t\t\t// test if number is a whole number\n\t\t\t\t\t\t\t\tall_longs &= (floor(num) == num);\n\t\t\t\t\t\t\t\tvals->set(ra,llvm::ConstantFP::get(getCtx(), llvm::APFloat(num)));\n\t\t\t\t\t\t\t\tis_const_num[ra] = true;\n\t\t\t\t\t\t\t\top_hints[i - x] |= HINT_SKIP_OP;\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tall_longs = false;\n\t\t\t\t\t}\n\t\t\t\t\tall_longs &= (found == 3);\n\t\t\t\t\t// create for_idx OP_FORPREP will inialize it.\n\t\t\t\t\top_hints[branch] = HINT_FOR_N_N_N;\n\t\t\t\t\tif(all_longs) {\n\t\t\t\t\t\tvals->set(3, Builder.CreateAlloca(llvm::Type::getInt64Ty(getCtx()), 0, \"for_idx\"));\n\t\t\t\t\t\top_hints[branch] |= HINT_USE_LONG;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvals->set(3, Builder.CreateAlloca(llvm::Type::getDoubleTy(getCtx()), 0, \"for_idx\"));\n\t\t\t\t\t}\n\t\t\t\t\top_values[branch] = vals;\n\t\t\t\t\t// check if step, init, limit are constants\n\t\t\t\t\tif(is_const_num[2]) {\n\t\t\t\t\t\t// step is a constant\n\t\t\t\t\t\tif(is_const_num[0]) {\n\t\t\t\t\t\t\t// init & step are constants.\n\t\t\t\t\t\t\tif(is_const_num[1]) {\n\t\t\t\t\t\t\t\t// all are constants.\n\t\t\t\t\t\t\t\top_hints[i] = HINT_FOR_N_N_N;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// limit is variable.\n\t\t\t\t\t\t\t\top_hints[i] = HINT_FOR_N_M_N;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\top_values[i] = new OPValues(3);\n\t\t\t\t\t\t\top_values[i]->set(0, vals->get(0));\n\t\t\t\t\t\t\top_values[i]->set(2, vals->get(2));\n\t\t\t\t\t\t} else if(is_const_num[1]) {\n\t\t\t\t\t\t\t// init is variable, limit & step are constants.\n\t\t\t\t\t\t\top_hints[i] = HINT_FOR_M_N_N;\n\t\t\t\t\t\t\top_values[i] = new OPValues(3);\n\t\t\t\t\t\t\top_values[i]->set(1, vals->get(1));\n\t\t\t\t\t\t\top_values[i]->set(2, vals->get(2));\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// check the direct of step.\n\t\t\t\t\t\tif(nums[2] > 0) {\n\t\t\t\t\t\t\top_hints[branch] |= HINT_UP;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\top_hints[branch] |= HINT_DOWN;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif(op_hints[i] == HINT_NONE) {\n\t\t\t\t\t\t// don't skip LOADK ops, since we are not inlining them.\n\t\t\t\t\t\tfor(int x=i-3; x < i; x++) {\n\t\t\t\t\t\t\tif(op_hints[x] & HINT_SKIP_OP) op_hints[x] &= ~(HINT_SKIP_OP);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif(all_longs) {\n\t\t\t\t\t\tfor(int x = 0; x < 3; ++x) {\n\t\t\t\t\t\t\tvals->set(x,llvm::ConstantInt::get(getCtx(), llvm::APInt(64,(lua_Long)nums[x])));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// make sure OP_FORPREP doesn't subtract 'step' from 'init'\n\t\t\t\t\top_hints[i] |= HINT_NO_SUB;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase OP_SETLIST:\n\t\t\t\t// if C == 0, then next code value is count value.\n\t\t\t\tif(GETARG_C(op_intr) == 0) {\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase OP_ADD:\n\t\t\tcase OP_SUB:\n\t\t\tcase OP_MUL:\n\t\t\tcase OP_DIV:\n\t\t\tcase OP_MOD:\n\t\t\tcase OP_POW:\n\t\t\t\t// check if arg C is a number constant.\n\t\t\t\tif(ISK(GETARG_C(op_intr))) {\n\t\t\t\t\tTValue *rc = k + INDEXK(GETARG_C(op_intr));\n\t\t\t\t\tif(ttisnumber(rc)) op_hints[i] |= HINT_C_NUM_CONSTANT;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t\t// update local variable type hints.\n\t\t//vm_op_hint_locals(locals, p->maxstacksize, k, op_intr);\n\t}\n\t// pre-create basic blocks.\n\tfor(i = 0; i < code_len; i++) {\n\t\tif(need_op_block[i]) {\n\t\t\top_intr=code[i];\n\t\t\topcode = GET_OPCODE(op_intr);\n\t\t\tsnprintf(name_buf,128,\"op_block_%s_%d\",luaP_opnames[opcode],i);\n\t\t\top_blocks[i] = llvm::BasicBlock::Create(getCtx(),name_buf, func);\n\t\t} else {\n\t\t\top_blocks[i] = NULL;\n\t\t}\n\t}\n\t// branch \"entry\" to first block.\n\tif(need_op_block[0]) {\n\t\tBuilder.CreateBr(op_blocks[0]);\n\t} else {\n\t\tcurrent_block = entry_block;\n\t}\n\t// gen op calls.\n\tfor(i = 0; i < code_len; i++) {\n\t\tif(op_blocks[i] != NULL) {\n\t\t\tif(current_block) {\n\t\t\t\t// add branch to new block.\n\t\t\t\tBuilder.CreateBr(op_blocks[i]);\n\t\t\t}\n\t\t\tBuilder.SetInsertPoint(op_blocks[i]);\n\t\t\tcurrent_block = op_blocks[i];\n\t\t}\n\t\t// skip dead unreachable code.\n\t\tif(current_block == NULL) {\n\t\t\tif(strip_code) strip_ops++;\n\t\t\tcontinue;\n\t\t}\n\t\tbranch = i+1;\n\t\top_intr=code[i];\n\t\topcode = GET_OPCODE(op_intr);\n\t\topfunc = vm_op_funcs[opcode];\n\t\t// combind multiple simple ops into one call.\n\t\tif(op_hints[i] & HINT_MINI_VM) {\n\t\t\tint op_count = 1;\n\t\t\t// count mini ops and check for any branch end-points.\n\t\t\twhile(is_mini_vm_op(GET_OPCODE(code[i + op_count])) &&\n\t\t\t\t\t(op_hints[i + op_count] & HINT_SKIP_OP) == 0) {\n\t\t\t\t// branch end-point in middle of mini ops block.\n\t\t\t\tif(need_op_block[i + op_count]) {\n\t\t\t\t\top_hints[i + op_count] |= HINT_MINI_VM; // mark start of new mini vm ops.\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\top_count++;\n\t\t\t}\n\t\t\tif(op_count >= 3) {\n\t\t\t\t// large block of mini ops add function call to vm_mini_vm()\n\t\t\t\tBuilder.CreateCall4(vm_mini_vm, func_L, func_cl,\n\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,op_count)),\n\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,i - strip_ops)));\n\t\t\t\tif(strip_code && strip_ops > 0) {\n\t\t\t\t\twhile(op_count > 0) {\n\t\t\t\t\t\tcode[i - strip_ops] = code[i];\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\top_count--;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ti += op_count;\n\t\t\t\t}\n\t\t\t\ti--;\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\t// mini ops block too small.\n\t\t\t\top_hints[i] &= ~(HINT_MINI_VM);\n\t\t\t}\n\t\t}\n\t\t// find op function with matching hint.\n\t\twhile(opfunc->next != NULL && (opfunc->info->hint & op_hints[i]) != opfunc->info->hint) {\n\t\t\topfunc = opfunc->next;\n\t\t}\n\t\tif(OpCodeStats) {\n\t\t\topcode_stats[opcode]++;\n\t\t}\n\t\t//fprintf(stderr, \"%d: '%s' (%d) = 0x%08X, hint=0x%X\\n\", i, luaP_opnames[opcode], opcode, op_intr, op_hints[i]);\n\t\t//fprintf(stderr, \"%d: func: '%s', func hints=0x%X\\n\", i, opfunc->info->name,opfunc->info->hint);\n\t\tif(PrintRunOpCodes) {\n\t\t\tBuilder.CreateCall4(vm_print_OP, func_L, func_cl,\n\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,op_intr)),\n\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,i)));\n\t\t}\n\t\tif(RunOpCodeStats) {\n\t\t\tBuilder.CreateCall(vm_count_OP, llvm::ConstantInt::get(getCtx(), llvm::APInt(32,op_intr)));\n\t\t}\n\t\tif(DebugOpCodes) {\n\t\t\t/* vm_next_OP function is used to call count/line debug hooks. */\n\t\t\tBuilder.CreateCall3(vm_next_OP, func_L, func_cl, llvm::ConstantInt::get(getCtx(), llvm::APInt(32,i)));\n\t\t}\n\t\tif(op_hints[i] & HINT_SKIP_OP) {\n\t\t\tif(strip_code) strip_ops++;\n\t\t\tcontinue;\n\t\t}\n\t\tif(strip_code) {\n\t\t\t// strip all opcodes.\n\t\t\tstrip_ops++;\n\t\t\tif(strip_ops > 0 && strip_ops < (i+1)) {\n\t\t\t\t// move opcodes we want to keep to new position.\n\t\t\t\tcode[(i+1) - strip_ops] = op_intr;\n\t\t\t}\n\t\t}\n\t\t// setup arguments for opcode function.\n\t\tfunc_info = opfunc->info;\n\t\tif(func_info == NULL) {\n\t\t\tfprintf(stderr, \"Error missing vm_OP_* function for opcode: %d\\n\", opcode);\n\t\t\treturn;\n\t\t}\n\t\t// special handling of OP_FORLOOP\n\t\tif(opcode == OP_FORLOOP) {\n\t\t\tllvm::BasicBlock *loop_test;\n\t\t\tllvm::BasicBlock *prep_block;\n\t\t\tllvm::BasicBlock *incr_block;\n\t\t\tllvm::Value *init,*step,*idx_var,*cur_idx,*next_idx;\n\t\t\tllvm::PHINode *PN;\n\t\t\tOPValues *vals;\n\n\t\t\tvals=op_values[i];\n\t\t\tif(vals != NULL) {\n\t\t\t\t// get init value from forprep block\n\t\t\t\tinit = vals->get(0);\n\t\t\t\t// get for loop 'idx' variable.\n\t\t\t\tstep = vals->get(2);\n\t\t\t\tidx_var = vals->get(3);\n\t\t\t\tassert(idx_var != NULL);\n\t\t\t\tincr_block = current_block;\n\t\t\t\tcur_idx = Builder.CreateLoad(idx_var);\n\t\t\t\tif(op_hints[i] & HINT_USE_LONG) {\n\t\t\t\t\tnext_idx = Builder.CreateAdd(cur_idx, step, \"next_idx\");\n\t\t\t\t} else {\n\t\t\t\t\tnext_idx = Builder.CreateFAdd(cur_idx, step, \"next_idx\");\n\t\t\t\t}\n\t\t\t\tBuilder.CreateStore(next_idx, idx_var); // store 'for_init' value.\n\t\t\t\t// create extra BasicBlock for vm_OP_FORLOOP_*\n\t\t\t\tsnprintf(name_buf,128,\"op_block_%s_%d_loop_test\",luaP_opnames[opcode],i);\n\t\t\t\tloop_test = llvm::BasicBlock::Create(getCtx(),name_buf, func);\n\t\t\t\t// create unconditional jmp from current block to loop test block\n\t\t\t\tBuilder.CreateBr(loop_test);\n\t\t\t\t// create unconditional jmp from forprep block to loop test block\n\t\t\t\tprep_block = op_blocks[branch + GETARG_sBx(op_intr) - 1];\n\t\t\t\tBuilder.SetInsertPoint(prep_block);\n\t\t\t\tBuilder.CreateBr(loop_test);\n\t\t\t\t// set current_block to loop_test block\n\t\t\t\tcurrent_block = loop_test;\n\t\t\t\tBuilder.SetInsertPoint(current_block);\n\t\t\t\t// Emit merge block\n\t\t\t\tif(op_hints[i] & HINT_USE_LONG) {\n\t\t\t\t\tPN = Builder.CreatePHI(llvm::Type::getInt64Ty(getCtx()), 2, \"idx\");\n\t\t\t\t} else {\n\t\t\t\t\tPN = Builder.CreatePHI(llvm::Type::getDoubleTy(getCtx()), 2, \"idx\");\n\t\t\t\t}\n\t\t\t\tPN->addIncoming(init, prep_block);\n\t\t\t\tPN->addIncoming(next_idx, incr_block);\n\t\t\t\tvals->set(0, PN);\n\t\t\t}\n\t\t}\n\t\targs.clear();\n\t\tfor(int x = 0; func_info->params[x] != VAR_T_VOID ; x++) {\n\t\t\tllvm::Value *val=NULL;\n\t\t\tswitch(func_info->params[x]) {\n\t\t\tcase VAR_T_ARG_A:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,GETARG_A(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_C:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,GETARG_C(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_C_FB2INT:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,luaO_fb2int(GETARG_C(op_intr))));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_Bx_NUM_CONSTANT:\n\t\t\t\tval = get_proto_constant(k + INDEXK(GETARG_Bx(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_C_NUM_CONSTANT:\n\t\t\t\tval = get_proto_constant(k + INDEXK(GETARG_C(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_C_NEXT_INSTRUCTION: {\n\t\t\t\tint c = GETARG_C(op_intr);\n\t\t\t\t// if C == 0, then next code value is used as ARG_C.\n\t\t\t\tif(c == 0) {\n\t\t\t\t\tif((i+1) < code_len) {\n\t\t\t\t\t\tc = code[i+1];\n\t\t\t\t\t\tif(strip_code) strip_ops++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,c));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase VAR_T_ARG_B:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,GETARG_B(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_B_FB2INT:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,luaO_fb2int(GETARG_B(op_intr))));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_Bx:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,GETARG_Bx(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_ARG_sBx:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,GETARG_sBx(op_intr)));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_PC_OFFSET:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,i + 1 - strip_ops));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_INSTRUCTION:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,op_intr));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_NEXT_INSTRUCTION:\n\t\t\t\tval = llvm::ConstantInt::get(getCtx(), llvm::APInt(32,code[i+1]));\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_LUA_STATE_PTR:\n\t\t\t\tval = func_L;\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_K:\n\t\t\t\tval = func_k;\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_CL:\n\t\t\t\tval = func_cl;\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_OP_VALUE_0:\n\t\t\t\tif(op_values[i] != NULL) val = op_values[i]->get(0);\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_OP_VALUE_1:\n\t\t\t\tif(op_values[i] != NULL) val = op_values[i]->get(1);\n\t\t\t\tbreak;\n\t\t\tcase VAR_T_OP_VALUE_2:\n\t\t\t\tif(op_values[i] != NULL) val = op_values[i]->get(2);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tfprintf(stderr, \"Error: not implemented!\\n\");\n\t\t\t\treturn;\n\t\t\tcase VAR_T_VOID:\n\t\t\t\tfprintf(stderr, \"Error: invalid value type!\\n\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(val == NULL) {\n\t\t\t\tfprintf(stderr, \"Error: Missing parameter '%d' for this opcode(%d) function=%s!\\n\", x,\n\t\t\t\t\topcode, func_info->name);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\targs.push_back(val);\n\t\t}\n\t\t// create call to opcode function.\n\t\tif(func_info->ret_type != VAR_T_VOID) {\n\t\t\tcall=Builder.CreateCall(opfunc->func, args, \"retval\");\n\t\t} else {\n\t\t\tcall=Builder.CreateCall(opfunc->func, args);\n\t\t}\n\t\tinline_call = false;\n\t\t// handle retval from opcode function.\n\t\tswitch (opcode) {\n\t\t\tcase OP_LOADBOOL:\n\t\t\t\t// check C operand if C!=0 then skip over the next op_block.\n\t\t\t\tif(GETARG_C(op_intr) != 0) branch += 1;\n\t\t\t\telse branch = BRANCH_NONE;\n\t\t\t\tinline_call = true;\n\t\t\t\tbreak;\n\t\t\tcase OP_LOADK:\n\t\t\tcase OP_LOADNIL:\n\t\t\tcase OP_GETGLOBAL:\n\t\t\tcase OP_GETTABLE:\n\t\t\tcase OP_SETGLOBAL:\n\t\t\tcase OP_SETTABLE:\n\t\t\tcase OP_NEWTABLE:\n\t\t\tcase OP_SELF:\n\t\t\tcase OP_ADD:\n\t\t\tcase OP_SUB:\n\t\t\tcase OP_MUL:\n\t\t\tcase OP_DIV:\n\t\t\tcase OP_MOD:\n\t\t\tcase OP_POW:\n\t\t\tcase OP_UNM:\n\t\t\tcase OP_NOT:\n\t\t\tcase OP_LEN:\n\t\t\tcase OP_CONCAT:\n\t\t\tcase OP_GETUPVAL:\n\t\t\tcase OP_MOVE:\n\t\t\t\tinline_call = true;\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\tcase OP_CLOSE:\n\t\t\tcase OP_SETUPVAL:\n\t\t\t\tinline_call = false;\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\tcase OP_VARARG:\n\t\t\tcase OP_CALL:\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\tcase OP_TAILCALL:\n\t\t\t\t//call->setTailCall(true);\n\t\t\t\tbrcond=call;\n\t\t\t\tbrcond=Builder.CreateICmpNE(brcond,\n\t\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32, PCRTAILRECUR)), \"brcond\");\n\t\t\t\ti++; // skip return opcode.\n\t\t\t\tfalse_block = op_blocks[0]; // branch to start of function if this is a recursive tail-call.\n\t\t\t\ttrue_block = op_blocks[i]; // branch to return instruction if not recursive.\n\t\t\t\tBuilder.CreateCondBr(brcond, true_block, false_block);\n\t\t\t\tBuilder.SetInsertPoint(op_blocks[i]);\n\t\t\t\tBuilder.CreateRet(call);\n\t\t\t\tcurrent_block = NULL; // have terminator\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\tcase OP_JMP:\n\t\t\t\t// always branch to the offset stored in operand sBx\n\t\t\t\tbranch += GETARG_sBx(op_intr);\n\t\t\t\t// call vm_OP_JMP just in case luai_threadyield is defined.\n\t\t\t\tinline_call = true;\n\t\t\t\tbreak;\n\t\t\tcase OP_EQ:\n\t\t\tcase OP_LT:\n\t\t\tcase OP_LE:\n\t\t\tcase OP_TEST:\n\t\t\tcase OP_TESTSET:\n\t\t\t\tinline_call = true;\n\t\t\tcase OP_TFORLOOP:\n\t\t\t\tbrcond=call;\n\t\t\t\tbrcond=Builder.CreateICmpNE(brcond, llvm::ConstantInt::get(getCtx(), llvm::APInt(32,0)), \"brcond\");\n\t\t\t\tfalse_block=op_blocks[branch+1];\n\t\t\t\t/* inlined JMP op. */\n\t\t\t\tbranch = ++i + 1;\n\t\t\t\tif(strip_code) {\n\t\t\t\t\tstrip_ops++;\n\t\t\t\t\tif(strip_ops > 0 && strip_ops < (i+1)) {\n\t\t\t\t\t\t// move opcodes we want to keep to new position.\n\t\t\t\t\t\tcode[(i+1) - strip_ops] = code[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\top_intr=code[i];\n\t\t\t\tbranch += GETARG_sBx(op_intr);\n\t\t\t\ttrue_block=op_blocks[branch];\n\t\t\t\tbranch = BRANCH_COND; // do conditional branch\n\t\t\t\tbreak;\n\t\t\tcase OP_FORLOOP: {\n\t\t\t\tllvm::Function *set_func=vm_set_number;\n\t\t\t\tllvm::CallInst *call2;\n\t\t\t\tOPValues *vals;\n\n\t\t\t\tinline_call = true;\n\t\t\t\tbrcond=call;\n\t\t\t\tbrcond=Builder.CreateICmpNE(brcond, llvm::ConstantInt::get(getCtx(), llvm::APInt(32,0)), \"brcond\");\n\t\t\t\ttrue_block=op_blocks[branch + GETARG_sBx(op_intr)];\n\t\t\t\tfalse_block=op_blocks[branch];\n\t\t\t\tbranch = BRANCH_COND; // do conditional branch\n\n\t\t\t\t// update external index if needed.\n\t\t\t\tvals=op_values[i];\n\t\t\t\tif(vals != NULL) {\n\t\t\t\t\tllvm::BasicBlock *idx_block;\n\t\t\t\t\tif(op_hints[i] & HINT_USE_LONG) {\n\t\t\t\t\t\tset_func = vm_set_long;\n\t\t\t\t\t}\n\t\t\t\t\t// create extra BasicBlock\n\t\t\t\t\tsnprintf(name_buf,128,\"op_block_%s_%d_set_for_idx\",luaP_opnames[opcode],i);\n\t\t\t\t\tidx_block = llvm::BasicBlock::Create(getCtx(),name_buf, func);\n\t\t\t\t\tBuilder.SetInsertPoint(idx_block);\n\t\t\t\t\t// copy idx value to Lua-stack.\n\t\t\t\t\tcall2=Builder.CreateCall3(set_func,func_L,\n\t\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,(GETARG_A(op_intr) + 3))), vals->get(0));\n\t\t\t\t\tinlineList.push_back(call2);\n\t\t\t\t\t// create jmp to true_block\n\t\t\t\t\tBuilder.CreateBr(true_block);\n\t\t\t\t\ttrue_block = idx_block;\n\t\t\t\t\tBuilder.SetInsertPoint(current_block);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase OP_FORPREP: {\n\t\t\t\tllvm::Function *get_func=vm_get_number;\n\t\t\t\tllvm::Value *idx_var,*init;\n\t\t\t\tllvm::CallInst *call2;\n\t\t\t\tOPValues *vals;\n\n\t\t\t\t//inline_call = true;\n\t\t\t\top_blocks[i] = current_block;\n\t\t\t\tbranch += GETARG_sBx(op_intr);\n\t\t\t\tvals=op_values[branch];\n\t\t\t\t// if no saved value, then use slow method.\n\t\t\t\tif(vals == NULL) break;\n\t\t\t\tif(op_hints[branch] & HINT_USE_LONG) {\n\t\t\t\t\tget_func = vm_get_long;\n\t\t\t\t}\n\t\t\t\t// get non-constant init from Lua stack.\n\t\t\t\tif(vals->get(0) == NULL) {\n\t\t\t\t\tcall2=Builder.CreateCall2(get_func,func_L,\n\t\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,(GETARG_A(op_intr) + 0))), \"for_init\");\n\t\t\t\t\tinlineList.push_back(call2);\n\t\t\t\t\tvals->set(0, call2);\n\t\t\t\t}\n\t\t\t\tinit = vals->get(0);\n\t\t\t\t// get non-constant limit from Lua stack.\n\t\t\t\tif(vals->get(1) == NULL) {\n\t\t\t\t\tcall2=Builder.CreateCall2(get_func,func_L,\n\t\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,(GETARG_A(op_intr) + 1))), \"for_limit\");\n\t\t\t\t\tinlineList.push_back(call2);\n\t\t\t\t\tvals->set(1, call2);\n\t\t\t\t}\n\t\t\t\t// get non-constant step from Lua stack.\n\t\t\t\tif(vals->get(2) == NULL) {\n\t\t\t\t\tcall2=Builder.CreateCall2(get_func,func_L,\n\t\t\t\t\t\tllvm::ConstantInt::get(getCtx(), llvm::APInt(32,(GETARG_A(op_intr) + 2))), \"for_step\");\n\t\t\t\t\tinlineList.push_back(call2);\n\t\t\t\t\tvals->set(2, call2);\n\t\t\t\t}\n\t\t\t\t// get for loop 'idx' variable.\n\t\t\t\tassert(vals->get(3) != NULL);\n\t\t\t\tidx_var = vals->get(3);\n\t\t\t\tBuilder.CreateStore(init, idx_var); // store 'for_init' value.\n\t\t\t\tvals->set(0, init);\n\t\t\t\tcurrent_block = NULL; // have terminator\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase OP_SETLIST:\n\t\t\t\t// if C == 0, then next code value is used as ARG_C.\n\t\t\t\tif(GETARG_C(op_intr) == 0) {\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\tcase OP_CLOSURE: {\n\t\t\t\tProto *p2 = p->p[GETARG_Bx(op_intr)];\n\t\t\t\tint nups = p2->nups;\n\t\t\t\tif(strip_code && strip_ops > 0) {\n\t\t\t\t\twhile(nups > 0) {\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tcode[i - strip_ops] = code[i];\n\t\t\t\t\t\tnups--;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ti += nups;\n\t\t\t\t}\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase OP_RETURN: {\n\t\t\t\tcall->setTailCall(true);\n\t\t\t\tBuilder.CreateRet(call);\n\t\t\t\tbranch = BRANCH_NONE;\n\t\t\t\tcurrent_block = NULL; // have terminator\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tfprintf(stderr, \"Bad opcode: opcode=%d\\n\", opcode);\n\t\t\t\tbreak;\n\t\t}\n\t\tif(OptLevel > 0 && inline_call && !DontInlineOpcodes) {\n\t\t\tinlineList.push_back(call);\n\t\t} else if(!opfunc->compiled) {\n\t\t\t// only compile opcode functions that are not inlined.\n\t\t\topfunc->compiled = true;\n\t\t\tTheExecutionEngine->getPointerToFunction(opfunc->func);\n\t\t}\n\t\t// branch to next block.\n\t\tif(branch >= 0 && branch < code_len) {\n\t\t\tBuilder.CreateBr(op_blocks[branch]);\n\t\t\tcurrent_block = NULL; // have terminator\n\t\t} else if(branch == BRANCH_COND) {\n\t\t\tBuilder.CreateCondBr(brcond, true_block, false_block);\n\t\t\tcurrent_block = NULL; // have terminator\n\t\t}\n\t}\n\t// free opcode values and clear hints.\n\tclear_opcode_data(code_len);\n\t// strip Lua bytecode and debug info.\n\tif(strip_code && strip_ops > 0) {\n\t\tcode_len -= strip_ops;\n\t\tluaM_reallocvector(L, p->code, p->sizecode, code_len, Instruction);\n\t\tp->sizecode = code_len;\n\t\tluaM_reallocvector(L, p->lineinfo, p->sizelineinfo, 0, int);\n\t\tp->sizelineinfo = 0;\n\t\tluaM_reallocvector(L, p->locvars, p->sizelocvars, 0, LocVar);\n\t\tp->sizelocvars = 0;\n\t\tluaM_reallocvector(L, p->upvalues, p->sizeupvalues, 0, TString *);\n\t\tp->sizeupvalues = 0;\n\t}\n\tif(DumpFunctions) func->dump();\n\t// only run function inliner & optimization passes on same functions.\n\tif(OptLevel > 0 && !DontInlineOpcodes) {\n\t\tllvm::InlineFunctionInfo IFI;\n\t\tfor(std::vector<llvm::CallInst *>::iterator I=inlineList.begin(); I != inlineList.end() ; I++) {\n\t\t\tInlineFunction(*I, IFI);\n\t\t}\n\t\t// Validate the generated code, checking for consistency.\n\t\tif(VerifyFunctions) verifyFunction(*func);\n\t\t// Optimize the function.\n\t\tif(TheFPM) TheFPM->run(*func);\n\t}\n\tif(llvm::TimePassesIsEnabled) lua_to_llvm->stopTimer();\n\n\tif(llvm::TimePassesIsEnabled) codegen->startTimer();\n\t// finished.\n\tif(TheExecutionEngine != NULL) {\n\t\tunion {\n\t\t\tvoid *ptr;\n\t\t\tlua_CFunction func;\n\t\t} jit_func;\n\t\tjit_func.ptr = TheExecutionEngine->getPointerToFunction(func);\n\t\tp->jit_func = jit_func.func;\n\t} else {\n\t\tp->jit_func = NULL;\n\t}\n\tp->func_ref = func;\n\tif(llvm::TimePassesIsEnabled) codegen->stopTimer();\n}\n\nvoid LLVMCompiler::free(lua_State *L, Proto *p)\n{\n\tllvm::Function *func;\n\tunion {\n\t\tvoid *ptr;\n\t\tlua_CFunction func;\n\t} jit_func;\n\t(void)L;\n\n\tif(TheExecutionEngine == NULL) return;\n\n\tjit_func.func = p->jit_func;\n\tfunc=(llvm::Function *)TheExecutionEngine->getGlobalValueAtAddress(jit_func.ptr);\n\tif(func != NULL) {\n\t\tTheExecutionEngine->freeMachineCodeForFunction(func);\n\t\tfunc->removeFromParent();\n\t\tdelete func;\n\t}\n}\n\n"
  },
  {
    "path": "llvm-lua/LLVMCompiler.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef LLVMCOMPILER_h\n#define LLVMCOMPILER_h\n\n#include \"llvm/Support/IRBuilder.h\"\n#include \"llvm/Module.h\"\n#include \"llvm/LLVMContext.h\"\n\n#include \"lua_core.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lobject.h\"\n\n#include \"lua_vm_ops.h\"\n\n#ifdef __cplusplus\n}\n#endif\n\nnamespace llvm {\nclass FunctionPassManager;\nclass ExecutionEngine;\nclass Timer;\n}\n\nclass LLVMCompiler {\nprivate:\n\tclass OPFunc {\n\tpublic:\n\t\tconst vm_func_info *info;\n\t\tbool compiled;\n\t\tllvm::Function *func;\n\t\tOPFunc *next;\n\n\t\tOPFunc(const vm_func_info *info_, OPFunc *next_) :\n\t\t\t\tinfo(info_), compiled(false), func(NULL), next(next_) {}\n\t\t~OPFunc() {\n\t\t\tif(next) delete next;\n\t\t}\n\t};\n\tclass OPValues {\n\tprivate:\n\t\tint len;\n\t\tllvm::Value **values;\n\t\n\tpublic:\n\t\tOPValues(int len_) : len(len_), values(new llvm::Value *[len_]) {\n\t\t\tfor(int i = 0; i < len; ++i) {\n\t\t\t\tvalues[i] = NULL;\n\t\t\t}\n\t\t}\n\t\n\t\t~OPValues() {\n\t\t\tdelete[] values;\n\t\t}\n\t\tvoid set(int idx, llvm::Value *val) {\n\t\t\tassert(idx >= 0 && idx < len);\n\t\t\tvalues[idx] = val;\n\t\t}\n\t\tllvm::Value *get(int idx) {\n\t\t\tassert(idx >= 0 && idx < len);\n\t\t\treturn values[idx];\n\t\t}\n\t};\n\nprivate:\n\tllvm::LLVMContext Context;\n\tllvm::Module *M;\n\tllvm::FunctionPassManager *TheFPM;\n\tllvm::ExecutionEngine *TheExecutionEngine;\n\tbool strip_code;\n\n\t// struct types.\n\tllvm::Type *Ty_TValue;\n\tllvm::Type *Ty_TValue_ptr;\n\tllvm::Type *Ty_LClosure;\n\tllvm::Type *Ty_LClosure_ptr;\n\tllvm::Type *Ty_lua_State;\n\tllvm::Type *Ty_lua_State_ptr;\n\t// common function types.\n\tllvm::FunctionType *lua_func_type;\n\t// functions to get LClosure & constants pointer.\n\tllvm::Function *vm_get_current_closure;\n\tllvm::Function *vm_get_current_constants;\n\tllvm::Function *vm_get_number;\n\tllvm::Function *vm_get_long;\n\tllvm::Function *vm_set_number;\n\tllvm::Function *vm_set_long;\n\t// function for counting each executed op.\n\tllvm::Function *vm_count_OP;\n\t// function for print each executed op.\n\tllvm::Function *vm_print_OP;\n\t// function for handling count/line debug hooks.\n\tllvm::Function *vm_next_OP;\n\t// function for handling a block of simple opcodes.\n\tllvm::Function *vm_mini_vm;\n\t// available op function for each opcode.\n\tOPFunc **vm_op_funcs;\n\t// count compiled opcodes.\n\tint *opcode_stats;\n\n\t// timers\n\tllvm::Timer *lua_to_llvm;\n\tllvm::Timer *codegen;\n\n\t// opcode hints/values/blocks/need_block arrays used in compile() method.\n\tint opcode_data_len; // length of opcode arrays.\n\thint_t *op_hints;\n\tOPValues **op_values;\n\tllvm::BasicBlock **op_blocks;\n\tbool *need_op_block;\n\t// resize the opcode hint data arrays.\n\tvoid resize_opcode_data(int code_len);\n\t// reset/clear the opcode hint data arrays.\n\tvoid clear_opcode_data(int code_len);\n\npublic:\n\tLLVMCompiler(int useJIT);\n\t~LLVMCompiler();\n\n\t/*\n\t * set code stripping mode.\n\t */\n\tvoid setStripCode(bool strip) {\n\t\tstrip_code = strip;\n\t}\n\n\t/*\n\t * return the module.\n\t */\n\tllvm::Module *getModule() {\n\t\treturn M;\n\t}\n\n\tllvm::LLVMContext& getCtx() {\n\t\treturn Context;\n\t}\n\n\tllvm::FunctionType *get_lua_func_type() {\n\t\treturn lua_func_type;\n\t}\n\n\tllvm::Type *get_var_type(val_t type, hint_t hints);\n\n\tllvm::Value *get_proto_constant(TValue *constant);\n\t\n\t/*\n\t * Pre-Compile all loaded functions.\n\t */\n\tvoid compileAll(lua_State *L, Proto *parent);\n\n\tvoid compile(lua_State *L, Proto *p);\n\n\tvoid free(lua_State *L, Proto *p);\n};\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/LLVMDumper.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include \"llvm/DerivedTypes.h\"\n#include \"llvm/Module.h\"\n#include \"llvm/Target/TargetData.h\"\n#include \"llvm/Linker.h\"\n#include \"llvm/Analysis/Verifier.h\"\n#include \"llvm/Bitcode/ReaderWriter.h\"\n#include \"llvm/Support/CommandLine.h\"\n#include \"llvm/Support/raw_ostream.h\"\n#include <string>\n#include <vector>\n#include <fstream>\n#include <stdint.h>\n\n#include \"LLVMCompiler.h\"\n#include \"LLVMDumper.h\"\n#include \"lstate.h\"\n#include \"load_jit_proto.h\"\n#include \"load_liblua_main.h\"\n\nstatic llvm::cl::opt<bool> LuaModule(\"lua-module\",\n                   llvm::cl::desc(\"Generate a Lua Module instead of a standalone exe.\"),\n                   llvm::cl::init(false));\n\nstatic llvm::cl::opt<bool> NoMain(\"no-main\",\n                   llvm::cl::desc(\"Don't link in liblua_main.bc.\"),\n                   llvm::cl::init(false));\n\n//===----------------------------------------------------------------------===//\n// Dump a compilable bitcode module.\n//===----------------------------------------------------------------------===//\n\nLLVMDumper::LLVMDumper(LLVMCompiler *compiler_) : compiler(compiler_) {\n\tstd::vector<llvm::Type *> fields;\n\tllvm::TargetData *type_info;\n\tllvm::Type *value_type;\n\tllvm::ArrayType *pad_type;\n\tint num_size;\n\tint ptr_size;\n\tint max_size=0;\n\tint pad_size=0;\n\n\tM = compiler->getModule();\n\t// get target size of pointer & double\n\ttype_info = new llvm::TargetData(M);\n\tnum_size = type_info->getTypeStoreSize(llvm::Type::getDoubleTy(getCtx()));\n\tmax_size = num_size;\n\tptr_size = type_info->getPointerSize();\n\tif(ptr_size > max_size) max_size = ptr_size;\n\tdelete type_info;\n\n\tlua_func_type = compiler->get_lua_func_type();\n\tlua_func_type_ptr = llvm::PointerType::get(lua_func_type, 0);\n\tTy_str_ptr=llvm::PointerType::get(llvm::IntegerType::get(getCtx(), 8), 0);\n\t//\n\t// create constant_type structure type.\n\t//\n\n\t// union.constant_value\n\t\t// TODO: handle LUA_NUMBER types other then 'double'.\n\tfields.push_back(llvm::Type::getDoubleTy(getCtx()));\n\tTy_constant_value = llvm::StructType::create(getCtx(), fields, \"union.constant_value\", false);\n\n\t// struct.constant_type\n\tfields.clear();\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // type\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // length\n\tfields.push_back(Ty_constant_value);                    // val\n\tTy_constant_type = llvm::StructType::create(getCtx(), fields, \"struct.constant_type\", false);\n\tTy_constant_type_ptr = llvm::PointerType::get(Ty_constant_type, 0);\n\n\t// struct.constant_num_type\n\tfields.clear();\n\tfields.push_back(llvm::Type::getDoubleTy(getCtx()));    // double\n\tvalue_type = llvm::StructType::get(getCtx(), fields, false);\n\tfields.clear();\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // type\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // length\n\tfields.push_back(value_type);                           // val (double)\n\tTy_constant_num_type = llvm::StructType::create(getCtx(), fields, \"struct.constant_num_type\", false);\n\tnum_padding = NULL;\n\n\t// struct.constant_bool_type\n\tfields.clear();\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // boolean\n\tpad_size = max_size - 4;\n\tif(pad_size > 0) {\n\t\tpad_type = llvm::ArrayType::get(llvm::IntegerType::get(getCtx(), 8), pad_size);\n\t\tbool_padding = llvm::Constant::getNullValue(pad_type);\n\t\tfields.push_back(pad_type);                           // padding\n\t} else {\n\t\tbool_padding = NULL;\n\t}\n\tvalue_type = llvm::StructType::get(getCtx(), fields, false);\n\tfields.clear();\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // type\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // length\n\tfields.push_back(value_type);                           // val (boolean)\n\tTy_constant_bool_type = llvm::StructType::create(getCtx(), fields, \"struct.constant_bool_type\", false);\n\n\t// struct.constant_str_type\n\tfields.clear();\n\tfields.push_back(Ty_str_ptr);                           // char *\n\tpad_size = max_size - ptr_size;\n\tif(pad_size > 0) {\n\t\tpad_type = llvm::ArrayType::get(llvm::IntegerType::get(getCtx(), 8), pad_size);\n\t\tstr_padding = llvm::Constant::getNullValue(pad_type);\n\t\tfields.push_back(pad_type);                           // padding\n\t} else {\n\t\tstr_padding = NULL;\n\t}\n\tvalue_type = llvm::StructType::get(getCtx(), fields, false);\n\tfields.clear();\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // type\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // length\n\tfields.push_back(value_type);                           // val (char *)\n\tTy_constant_str_type = llvm::StructType::create(getCtx(), fields, \"struct.constant_str_type\", false);\n\n\t//\n\t// create jit_LocVar structure type.\n\t//\n\tfields.clear();\n\tfields.push_back(Ty_str_ptr); // varname\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // startpc\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // endpc\n\tTy_jit_LocVar = llvm::StructType::create(getCtx(), fields, \"struct.jit_LocVar\", false);\n\tTy_jit_LocVar_ptr = llvm::PointerType::get(Ty_jit_LocVar, 0);\n\n\t//\n\t// create jit_proto structure type.\n\t//\n\tfields.clear();\n\n\tTy_jit_proto = llvm::StructType::create(getCtx(), \"struct.jit_proto\");\n\tfields.push_back(Ty_str_ptr); // name\n\tfields.push_back(lua_func_type_ptr); // jit_func\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // linedefined\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // lastlinedefined\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 8)); // nups\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 8)); // numparams\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 8)); // is_vararg\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 8)); // maxstacksize\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 16)); // sizek\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 16)); // sizelocvars\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // sizeupvalues\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // sizep\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // sizecode\n\tfields.push_back(llvm::IntegerType::get(getCtx(), 32)); // sizelineinfo\n\tfields.push_back(Ty_constant_type_ptr); // k\n\tfields.push_back(Ty_jit_LocVar_ptr); // locvars\n\tfields.push_back(llvm::PointerType::get(Ty_str_ptr, 0)); // upvalues\n\tfields.push_back(llvm::PointerType::get(Ty_jit_proto, 0)); // p\n\tfields.push_back(llvm::PointerType::get(llvm::IntegerType::get(getCtx(), 32), 0)); // code\n\tfields.push_back(llvm::PointerType::get(llvm::IntegerType::get(getCtx(), 32), 0)); // lineinfo\n\tTy_jit_proto->setBody(fields, false);\n\tTy_jit_proto_ptr = llvm::PointerType::get(Ty_jit_proto, 0);\n}\n\nvoid LLVMDumper::dump(const char *output, lua_State *L, Proto *p, int stripping) {\n\tllvm::raw_fd_ostream *out;\n\tstd::string error;\n\tllvm::Module *liblua_main = NULL;\n\n\tout = new llvm::raw_fd_ostream(output, error, llvm::raw_fd_ostream::F_Binary);\n\tif(error.empty()) {\n\t\tcompiler->setStripCode(stripping);\n\t\t// Internalize all opcode functions.\n\t\tfor (llvm::Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {\n\t\t\tllvm::Function *Fn = &*I;\n\t\t\tif (!Fn->isDeclaration())\n\t\t\t\tFn->setLinkage(llvm::GlobalValue::getLinkOnceLinkage(true));\n\t\t}\n\t\t// Compile all Lua prototypes to LLVM IR\n\t\tcompiler->compileAll(L, p);\n\t\tif(LuaModule) {\n\t\t\t// Dump proto info to static variable and create 'luaopen_<mod_name>' function.\n\t\t\tdump_lua_module(p, output);\n\t\t} else {\n\t\t\t// Dump proto info to global for standalone exe.\n\t\t\tdump_standalone(p);\n\t\t\t// link with liblua_main.bc\n\t\t\tif(!NoMain) {\n\t\t\t\tliblua_main = load_liblua_main(getCtx(), true);\n\t\t\t\tif(llvm::Linker::LinkModules(M, liblua_main, llvm::Linker::DestroySource, &error)) {\n\t\t\t\t\tfprintf(stderr, \"Failed to link compiled Lua script with embedded 'liblua_main.bc': %s\",\n\t\t\t\t\t\terror.c_str());\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tllvm::verifyModule(*M);\n\t\tllvm::WriteBitcodeToFile(M, *out);\n\t\tdelete out;\n\t} else {\n\t\tdelete out;\n\t\tfprintf(stderr, \"Failed to open output file: %s\",\n\t\t\terror.c_str());\n\t\texit(1);\n\t}\n}\n\nllvm::Constant *LLVMDumper::get_ptr(llvm::Constant *val) {\n\tstd::vector<llvm::Constant *> idxList;\n\tidxList.push_back(llvm::Constant::getNullValue(llvm::IntegerType::get(getCtx(), 32)));\n\tidxList.push_back(llvm::Constant::getNullValue(llvm::IntegerType::get(getCtx(), 32)));\n\treturn llvm::ConstantExpr::getGetElementPtr(val, idxList);\n}\n\nllvm::Constant *LLVMDumper::get_global_str(const char *str) {\n\tllvm::Constant *str_const = llvm::ConstantDataArray::getString(getCtx(), str, true);\n\tllvm::GlobalVariable *var_str = new llvm::GlobalVariable(*M, str_const->getType(), true,\n\t\tllvm::GlobalValue::InternalLinkage, str_const, \".str\");\n\treturn get_ptr(var_str);\n}\n\nllvm::GlobalVariable *LLVMDumper::dump_constants(Proto *p) {\n\tllvm::GlobalVariable *constant;\n\tllvm::Constant *array_struct;\n\tstd::vector<llvm::Constant *> array_struct_fields;\n\n\tfor(int i = 0; i < p->sizek; i++) {\n\t\tint const_type = 0;\n\t\tint const_length = 0;\n\t\tllvm::StructType *type;\n\t\tstd::vector<llvm::Constant *> tmp_struct;\n\t\tllvm::Constant *value;\n\t\tTValue *tval = &(p->k[i]);\n\t\tconst_length = 0;\n\t\tswitch(ttype(tval)) {\n\t\t\tcase LUA_TSTRING:\n\t\t\t\tconst_type = TYPE_STRING;\n\t\t\t\tconst_length = tsvalue(tval)->len;\n\t\t\t\ttype = Ty_constant_str_type;\n\t\t\t\ttmp_struct.push_back(get_global_str(svalue(tval)));\n\t\t\t\tif(str_padding != NULL) {\n\t\t\t\t\ttmp_struct.push_back(str_padding);\n\t\t\t\t}\n\t\t\t\tvalue = llvm::ConstantStruct::getAnon(getCtx(), tmp_struct, false);\n\t\t\t\tbreak;\n\t\t\tcase LUA_TBOOLEAN:\n\t\t\t\tconst_type = TYPE_BOOLEAN;\n\t\t\t\ttype = Ty_constant_bool_type;\n\t\t\t\ttmp_struct.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32, !l_isfalse(tval))));\n\t\t\t\tif(bool_padding != NULL) {\n\t\t\t\t\ttmp_struct.push_back(bool_padding);\n\t\t\t\t}\n\t\t\t\tvalue = llvm::ConstantStruct::getAnon(getCtx(), tmp_struct, false);\n\t\t\t\tbreak;\n\t\t\tcase LUA_TNUMBER:\n\t\t\t\tconst_type = TYPE_NUMBER;\n\t\t\t\ttype = Ty_constant_num_type;\n\t\t\t\ttmp_struct.push_back(llvm::ConstantFP::get(getCtx(), llvm::APFloat(nvalue(tval))));\n\t\t\t\tif(num_padding != NULL) {\n\t\t\t\t\ttmp_struct.push_back(num_padding);\n\t\t\t\t}\n\t\t\t\tvalue = llvm::ConstantStruct::getAnon(getCtx(), tmp_struct, false);\n\t\t\t\tbreak;\n\t\t\tcase LUA_TNIL:\n\t\t\tdefault:\n\t\t\t\tconst_type = TYPE_NIL;\n\t\t\t\ttype = Ty_constant_bool_type;\n\t\t\t\ttmp_struct.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32, 0)));\n\t\t\t\tif(bool_padding != NULL) {\n\t\t\t\t\ttmp_struct.push_back(bool_padding);\n\t\t\t\t}\n\t\t\t\tvalue = llvm::ConstantStruct::getAnon(getCtx(), tmp_struct, false);\n\t\t\t\tbreak;\n\t\t}\n\t\ttmp_struct.clear();\n\t\ttmp_struct.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32, const_type)));\n\t\ttmp_struct.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32, const_length)));\n\t\ttmp_struct.push_back(value);\n\t\tarray_struct_fields.push_back(llvm::ConstantStruct::get(type, tmp_struct));\n\t}\n\n\tarray_struct = llvm::ConstantStruct::getAnon(getCtx(), array_struct_fields, false);\n\tconstant = new llvm::GlobalVariable(*M, array_struct->getType(), true,\n\t\tllvm::GlobalValue::InternalLinkage, array_struct, \".constants\");\n\t//constant->setAlignment(32);\n\treturn constant;\n}\n\nllvm::GlobalVariable *LLVMDumper::dump_locvars(Proto *p) {\n\tllvm::GlobalVariable *constant;\n\tllvm::Constant *array_struct;\n\tstd::vector<llvm::Constant *> array_struct_fields;\n\tstd::vector<llvm::Constant *> tmp_struct;\n\n\tfor(int i = 0; i < p->sizelocvars; i++) {\n\t\tLocVar *locvar = &(p->locvars[i]);\n\t\ttmp_struct.clear();\n\t\ttmp_struct.push_back(get_global_str(getstr(locvar->varname)));\n\t\ttmp_struct.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32, locvar->startpc)));\n\t\ttmp_struct.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32, locvar->endpc)));\n\t\tarray_struct_fields.push_back(llvm::ConstantStruct::get(Ty_jit_LocVar, tmp_struct));\n\t}\n\n\tarray_struct = llvm::ConstantStruct::getAnon(getCtx(), array_struct_fields, false);\n\tconstant = new llvm::GlobalVariable(*M, array_struct->getType(), true,\n\t\tllvm::GlobalValue::InternalLinkage, array_struct, \".locvars\");\n\t//constant->setAlignment(32);\n\treturn constant;\n}\n\nllvm::GlobalVariable *LLVMDumper::dump_upvalues(Proto *p) {\n\tllvm::GlobalVariable *constant;\n\tllvm::Constant *array_struct;\n\tstd::vector<llvm::Constant *> array_struct_fields;\n\n\tfor(int i = 0; i < p->sizeupvalues; i++) {\n\t\tarray_struct_fields.push_back(get_global_str(getstr(p->upvalues[i])));\n\t}\n\n\tarray_struct = llvm::ConstantStruct::getAnon(getCtx(), array_struct_fields, false);\n\tconstant = new llvm::GlobalVariable(*M, array_struct->getType(), true,\n\t\tllvm::GlobalValue::InternalLinkage, array_struct, \".upvalues\");\n\t//constant->setAlignment(32);\n\treturn constant;\n}\n\nllvm::Constant *LLVMDumper::dump_proto(Proto *p) {\n\tstd::vector<llvm::Constant *> jit_proto_fields;\n\tstd::vector<llvm::Constant *> tmp_array;\n\tllvm::Function *func = (llvm::Function *)p->func_ref;\n\tllvm::GlobalVariable *tmp_global;\n\tllvm::Constant *tmp_constant;\n\n\t// name\n\tjit_proto_fields.push_back(get_global_str(getstr(p->source)));\n\t// jit_func\n\tif(func) {\n\t\tjit_proto_fields.push_back(func);\n\t} else {\n\t\tjit_proto_fields.push_back(llvm::Constant::getNullValue(lua_func_type_ptr));\n\t}\n\t// linedefined\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->linedefined)));\n\t// lastlinedefined\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->lastlinedefined)));\n\t// nups\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(8,p->nups)));\n\t// numparams\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(8,p->numparams)));\n\t// is_vararg\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(8,p->is_vararg)));\n\t// maxstacksize\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(8,p->maxstacksize)));\n\t// sizek\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(16,p->sizek)));\n\t// sizelocvars\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(16,p->sizelocvars)));\n\t// sizeupvalues\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->sizeupvalues)));\n\t// sizep\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->sizep)));\n\t// sizecode\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->sizecode)));\n\t// sizelineinfo\n\tjit_proto_fields.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->sizelineinfo)));\n\t// k\n\tjit_proto_fields.push_back(\n\t\tllvm::ConstantExpr::getCast(llvm::Instruction::BitCast,\n\t\t\tdump_constants(p), Ty_constant_type_ptr));\n\t// locvars\n\tjit_proto_fields.push_back(\n\t\tllvm::ConstantExpr::getCast(llvm::Instruction::BitCast,\n\t\t\tdump_locvars(p), Ty_jit_LocVar_ptr));\n\t// upvalues\n\tjit_proto_fields.push_back(\n\t\tllvm::ConstantExpr::getCast(llvm::Instruction::BitCast,\n\t\t\tdump_upvalues(p), llvm::PointerType::get(Ty_str_ptr, 0)));\n\t// p\n\tif(p->sizep > 0) {\n\t\ttmp_array.clear();\n\t\tfor(int i = 0; i < p->sizep; i++) {\n\t\t\ttmp_array.push_back(dump_proto(p->p[i]));\n\t\t}\n\t\ttmp_constant = llvm::ConstantArray::get(llvm::ArrayType::get(Ty_jit_proto,p->sizep),tmp_array);\n\t\ttmp_global = new llvm::GlobalVariable(*M, tmp_constant->getType(), false,\n\t\t\tllvm::GlobalValue::InternalLinkage, tmp_constant, \".sub_protos\");\n\t\tjit_proto_fields.push_back(get_ptr(tmp_global));\n\t} else {\n\t\tjit_proto_fields.push_back(llvm::Constant::getNullValue(Ty_jit_proto_ptr));\n\t}\n\t// code\n\tif(p->sizecode > 0) {\n\t\ttmp_array.clear();\n\t\tfor(int i = 0; i < p->sizecode; i++) {\n\t\t\ttmp_array.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->code[i])));\n\t\t}\n\t\ttmp_constant = llvm::ConstantArray::get(llvm::ArrayType::get(llvm::IntegerType::get(getCtx(), 32),p->sizecode),tmp_array);\n\t\ttmp_global = new llvm::GlobalVariable(*M, tmp_constant->getType(), false,\n\t\t\tllvm::GlobalValue::InternalLinkage, tmp_constant, \".proto_code\");\n\t\tjit_proto_fields.push_back(get_ptr(tmp_global));\n\t} else {\n\t\tjit_proto_fields.push_back(llvm::Constant::getNullValue(llvm::PointerType::get(llvm::IntegerType::get(getCtx(), 32), 0)));\n\t}\n\t// lineinfo\n\tif(p->sizelineinfo > 0) {\n\t\ttmp_array.clear();\n\t\tfor(int i = 0; i < p->sizelineinfo; i++) {\n\t\t\ttmp_array.push_back(llvm::ConstantInt::get(getCtx(), llvm::APInt(32,p->lineinfo[i])));\n\t\t}\n\t\ttmp_constant = llvm::ConstantArray::get(llvm::ArrayType::get(llvm::IntegerType::get(getCtx(), 32),p->sizelineinfo),tmp_array);\n\t\ttmp_global = new llvm::GlobalVariable(*M, tmp_constant->getType(), false,\n\t\t\tllvm::GlobalValue::InternalLinkage, tmp_constant, \".proto_lineinfo\");\n\t\tjit_proto_fields.push_back(get_ptr(tmp_global));\n\t} else {\n\t\tjit_proto_fields.push_back(llvm::Constant::getNullValue(llvm::PointerType::get(llvm::IntegerType::get(getCtx(), 32), 0)));\n\t}\n\n\treturn llvm::ConstantStruct::get(Ty_jit_proto, jit_proto_fields);\n}\n\nvoid LLVMDumper::dump_standalone(Proto *p) {\n\t//\n\t// dump protos to a global variable for re-loading.\n\t//\n\tllvm::Constant *jit_proto = dump_proto(p);\n\t//llvm::GlobalVariable *gjit_proto_init = \n\tnew llvm::GlobalVariable(*M, Ty_jit_proto, false,\n\t\tllvm::GlobalValue::ExternalLinkage, jit_proto, \"jit_proto_init\");\n\t//gjit_proto_init->setAlignment(32);\n}\n\nvoid LLVMDumper::dump_lua_module(Proto *p, std::string mod_name) {\n\tllvm::IRBuilder<> Builder(getCtx());\n\tllvm::Function *func;\n\tllvm::Function *load_compiled_module_func;\n\tllvm::BasicBlock *block=NULL;\n\tllvm::Value *func_L;\n\tllvm::CallInst *call=NULL;\n\tstd::vector<llvm::Type*> func_args;\n\tllvm::FunctionType *func_type;\n\tstd::string name = \"luaopen_\";\n\tstd::string tmp;\n\tsize_t n;\n\n\t//\n\t// normalize mod_name.\n\t//\n\n\t// remove '.bc' from end of mod_name.\n\tn = mod_name.size()-3;\n\tif(n > 0) {\n\t\ttmp = mod_name.substr(n, 3);\n\t\tif(tmp[0] == '.') {\n\t\t\tif(tmp[1] == 'b' || tmp[1] == 'B') {\n\t\t\t\tif(tmp[2] == 'c' || tmp[2] == 'C') {\n\t\t\t\t\tmod_name = mod_name.substr(0, n);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t// convert non-alphanum chars to '_'\n\tfor(n = 0; n < mod_name.size(); n++) {\n\t\tchar c = mod_name[n];\n\t\tif((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) continue;\n\t\tif(c == '\\n' || c == '\\r') {\n\t\t\tmod_name = mod_name.substr(0,n);\n\t\t\tbreak;\n\t\t}\n\t\tmod_name[n] = '_';\n\t}\n\n\t//\n\t// dump protos to a static variable for re-loading.\n\t//\n\tllvm::Constant *jit_proto = dump_proto(p);\n\tllvm::GlobalVariable *gjit_proto_init = new llvm::GlobalVariable(*M, Ty_jit_proto, false,\n\t\tllvm::GlobalValue::InternalLinkage, jit_proto, \"jit_proto_init\");\n\t//gjit_proto_init->setAlignment(32);\n\n\t//\n\t// dump 'luaopen_<mod_name>' for loading the module.\n\t//\n\tname.append(mod_name);\n\tfunc = llvm::Function::Create(lua_func_type, llvm::Function::ExternalLinkage, name, M);\n\t// name arg1 = \"L\"\n\tfunc_L = func->arg_begin();\n\tfunc_L->setName(\"L\");\n\t// entry block\n\tblock = llvm::BasicBlock::Create(getCtx(), \"entry\", func);\n\tBuilder.SetInsertPoint(block);\n\t// call 'load_compiled_module'\n\tload_compiled_module_func = M->getFunction(\"load_compiled_module\");\n\tif(load_compiled_module_func == NULL) {\n\t\tfunc_args.clear();\n\t\tfunc_args.push_back(func_L->getType());\n\t\tfunc_args.push_back(Ty_jit_proto_ptr);\n\t\tfunc_type = llvm::FunctionType::get(llvm::IntegerType::get(getCtx(), 32), func_args, false);\n\t\tload_compiled_module_func = llvm::Function::Create(func_type,\n\t\t\tllvm::Function::ExternalLinkage, \"load_compiled_module\", M);\n\t}\n\tcall=Builder.CreateCall2(load_compiled_module_func, func_L, gjit_proto_init);\n\tcall->setTailCall(true);\n\tBuilder.CreateRet(call);\n\n\t//func->dump();\n}\n\n"
  },
  {
    "path": "llvm-lua/LLVMDumper.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef LLVMDUMPER_h\n#define LLVMDUMPER_h\n\n#include \"llvm/Module.h\"\n#include \"lua_core.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lobject.h\"\n\n#ifdef __cplusplus\n}\n#endif\n\nnamespace llvm {\nclass Module;\nclass Type;\nclass StructType;\nclass FunctionType;\nclass Constant;\nclass GlobalVariable;\n}\n\nclass LLVMCompiler;\n\nclass LLVMDumper {\nprivate:\n\tLLVMCompiler *compiler;\n\tllvm::Module *M;\n\n\t// types.\n\tllvm::Type *Ty_str_ptr;\n\tllvm::StructType *Ty_constant_value;\n\tllvm::StructType *Ty_constant_type;\n\tllvm::Type *Ty_constant_type_ptr;\n\tllvm::StructType *Ty_constant_num_type;\n\tllvm::Constant *num_padding;\n\tllvm::StructType *Ty_constant_bool_type;\n\tllvm::Constant *bool_padding;\n\tllvm::StructType *Ty_constant_str_type;\n\tllvm::Constant *str_padding;\n\tllvm::StructType *Ty_jit_LocVar;\n\tllvm::Type *Ty_jit_LocVar_ptr;\n\tllvm::StructType *Ty_jit_proto;\n\tllvm::Type *Ty_jit_proto_ptr;\n\tllvm::FunctionType *lua_func_type;\n\tllvm::Type *lua_func_type_ptr;\n\npublic:\n\tLLVMDumper(LLVMCompiler *compiler);\n\n\tvoid dump(const char *output, lua_State *L, Proto *p, int stripping);\n\n\tllvm::LLVMContext& getCtx() const {\n\t\treturn compiler->getCtx();\n\t}\n\nprivate:\n\tllvm::Constant *get_ptr(llvm::Constant *val);\n\n\tllvm::Constant *get_global_str(const char *str);\n\n\tllvm::GlobalVariable *dump_constants(Proto *p);\n\n\tllvm::GlobalVariable *dump_locvars(Proto *p);\n\n\tllvm::GlobalVariable *dump_upvalues(Proto *p);\n\n\tllvm::Constant *dump_proto(Proto *p);\n\n\tvoid dump_standalone(Proto *p);\n\n\tvoid dump_lua_module(Proto *p, std::string mod_name);\n\n};\n#endif\n\n"
  },
  {
    "path": "llvm-lua/TODO",
    "content": "\noptimizations:\n* When the internal index/limit/step variable of a OP_FORLOOP get moved to the C-Stack the space on the Lua-stack is unused.  We should be able to decrease the maxstacksize by re-using those stack slots.\n* Try to inline some table/global lookups if they have a constant key.\n\n"
  },
  {
    "path": "llvm-lua/bin2c.c",
    "content": "/*\n * bin2c.c\n *\n * convert a binary file into a C source vector\n *\n * THE \"BEER-WARE LICENSE\" (Revision 3.1415):\n * sandro AT sigala DOT it wrote this file. As long as you retain this notice you can do\n * whatever you want with this stuff.  If we meet some day, and you think this stuff is\n * worth it, you can buy me a beer in return.  Sandro Sigala\n *\n * syntax:  bin2c [-c] [-z] <input_file> <output_file>\n *\n *          -c    add the \"const\" keyword to definition\n *          -z    terminate the array with a zero (useful for embedded C strings)\n *\n * examples:\n *     bin2c -c myimage.png myimage_png.cpp\n *     bin2c -z sometext.txt sometext_txt.cpp\n */\n \n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n \n#ifndef PATH_MAX\n#define PATH_MAX 1024\n#endif\n \nint useconst = 0;\nint zeroterminated = 0;\n \nint myfgetc(FILE *f)\n{\n\tint c = fgetc(f);\n\tif (c == EOF && zeroterminated)\n\t{\n\t\tzeroterminated = 0;\n\t\treturn 0;\n\t}\n\treturn c;\n}\n \nvoid process(const char *ifname, const char *ofname)\n{\n\tFILE *ifile, *ofile;\n\tifile = fopen(ifname, \"rb\");\n\tif (ifile == NULL)\n\t{\n\t\tfprintf(stderr, \"cannot open %s for reading\\n\", ifname);\n\t\texit(1);\n\t}\n\tofile = fopen(ofname, \"wb\");\n\tif (ofile == NULL)\n\t{\n\t\tfprintf(stderr, \"cannot open %s for writing\\n\", ofname);\n\t\texit(1);\n\t}\n\tchar buf[PATH_MAX], *p;\n\tconst char *cp;\n\tif ((cp = strrchr(ifname, '/')) != NULL)\n\t{\n\t\t++cp;\n\t} else {\n\t\tif ((cp = strrchr(ifname, '\\\\')) != NULL)\n\t\t\t++cp;\n\t\telse\n\t\t\tcp = ifname;\n\t}\n\tstrcpy(buf, cp);\n\tfor (p = buf; *p != '\\0'; ++p)\n\t{\n\t\tif (!isalnum(*p))\n\t\t\t*p = '_';\n\t}\n\tfprintf(ofile, \"static %sunsigned char %s[] = {\\n\", useconst ? \"const \" : \"\", buf);\n\tint c, col = 1;\n\twhile ((c = myfgetc(ifile)) != EOF)\n\t{\n\t\tif (col >= 78 - 6)\n\t\t{\n\t\t\tfputc('\\n', ofile);\n\t\t\tcol = 1;\n\t\t}\n\t\tfprintf(ofile, \"0x%.2x,\", c);\n\t\tcol += 6;\n\t}\n\tfprintf(ofile, \"\\n};\\n\");\n \n\tfclose(ifile);\n\tfclose(ofile);\n}\n \nvoid usage(void)\n{\n\tfprintf(stderr, \"usage: bin2c [-cz] <input_file> <output_file>\\n\");\n\texit(1);\n}\n \nint main(int argc, char **argv)\n{\n\twhile (argc > 3)\n\t{\n\t\tif (!strcmp(argv[1], \"-c\"))\n\t\t{\n\t\t\tuseconst = 1;\n\t\t\t--argc;\n\t\t\t++argv;\n\t\t} else if (!strcmp(argv[1], \"-z\"))\n\t\t{\n\t\t\tzeroterminated = 1;\n\t\t\t--argc;\n\t\t\t++argv;\n\t\t} else {\n\t\t\tusage();\n\t\t}\n\t}\n\tif (argc != 3)\n\t{\n\t\tusage();\n\t}\n\tprocess(argv[1], argv[2]);\n\treturn 0;\n}\n\n"
  },
  {
    "path": "llvm-lua/compile_all.sh",
    "content": "#!/usr/bin/env bash\n#\n\nOPTS=\"\"\nFILES=\"\"\n# parse command line parameters.\nfor arg in \"$@\" ; do\n\tcase \"$arg\" in\n\t-*) OPTS=\"$OPTS $arg\" ;;\n\t*) FILES=\"$FILES $arg\" ;;\n\tesac\ndone\n\nfor script in $FILES; do\n\techo \"Compiling script: $script\"\n\tlua-compiler $OPTS $script\n\t#./lua-compiler $OPTS $script\ndone\n\n"
  },
  {
    "path": "llvm-lua/hook_parser.c",
    "content": "/*\n** See Copyright Notice in lua.h\n*/\n\n/*\n* hook_parser.c - Add a hook to the parser in ldo.c\n*\n* Most of this code is from ldo.c\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#if !ENABLE_PARSER_HOOK\n\n#include \"ldo.c\"\n\nint llvm_precall_lua (lua_State *L, StkId func, int nresults) {\n  return luaD_precall_lua(L, func, nresults);\n}\n\n#else\n\n#include \"llvm_compiler.h\"\n\n#define luaD_protectedparser luaD_protectedparser_old\n#include \"ldo.c\"\n#undef luaD_protectedparser\n\nstatic void llvm_f_parser (lua_State *L, void *ud) {\n  int i;\n  Proto *tf;\n  Closure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = luaZ_lookahead(p->z);\n  luaC_checkGC(L);\n  set_block_gc(L);  /* stop collector during parsing */\n  tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,\n                                                             &p->buff, p->name);\n  llvm_compiler_compile_all(L, tf);\n  cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));\n  cl->l.p = tf;\n  for (i = 0; i < tf->nups; i++)  /* initialize eventual upvalues */\n    cl->l.upvals[i] = luaF_newupval(L);\n  setclvalue(L, L->top, cl);\n  incr_top(L);\n  unset_block_gc(L);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {\n  struct SParser p;\n  int status;\n  p.z = z; p.name = name;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, llvm_f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  return status;\n}\n\nint llvm_precall_jit (lua_State *L, StkId func, int nresults) {\n  Closure *cl;\n  ptrdiff_t funcr;\n  CallInfo *ci;\n  StkId st, base;\n  Proto *p;\n\n  funcr = savestack(L, func);\n  cl = clvalue(func);\n  p = cl->l.p;\n  luaD_checkstack(L, p->maxstacksize);\n  func = restorestack(L, funcr);\n  base = func + 1;\n  if (L->top > base + p->numparams)\n    L->top = base + p->numparams;\n  ci = L->ci;  /* now `enter' new function */\n  ci->func = func;\n  L->base = ci->base = base;\n  ci->top = L->base + p->maxstacksize;\n  lua_assert(ci->top <= L->stack_last);\n  L->savedpc = p->code;  /* starting point */\n  ci->nresults = nresults;\n  for (st = L->top; st < ci->top; st++)\n    setnilvalue(st);\n  L->top = ci->top;\n  if (L->hookmask & LUA_MASKCALL) {\n    L->savedpc++;  /* hooks assume 'pc' is already incremented */\n    luaD_callhook(L, LUA_HOOKCALL, -1);\n    L->savedpc--;  /* correct 'pc' */\n  }\n  return (p->jit_func)(L); /* do the actual call */\n}\n\nint llvm_precall_jit_vararg (lua_State *L, StkId func, int nresults) {\n  Closure *cl;\n  ptrdiff_t funcr;\n  CallInfo *ci;\n  StkId st, base;\n  Proto *p;\n  int nargs;\n\n  funcr = savestack(L, func);\n  cl = clvalue(func);\n  p = cl->l.p;\n  luaD_checkstack(L, p->maxstacksize);\n  func = restorestack(L, funcr);\n  nargs = cast_int(L->top - func) - 1;\n  base = adjust_varargs(L, p, nargs);\n  func = restorestack(L, funcr);  /* previous call may change the stack */\n  ci = L->ci;  /* now `enter' new function */\n  ci->func = func;\n  L->base = ci->base = base;\n  ci->top = L->base + p->maxstacksize;\n  lua_assert(ci->top <= L->stack_last);\n  L->savedpc = p->code;  /* starting point */\n  ci->nresults = nresults;\n  for (st = L->top; st < ci->top; st++)\n    setnilvalue(st);\n  L->top = ci->top;\n  if (L->hookmask & LUA_MASKCALL) {\n    L->savedpc++;  /* hooks assume 'pc' is already incremented */\n    luaD_callhook(L, LUA_HOOKCALL, -1);\n    L->savedpc--;  /* correct 'pc' */\n  }\n  return (p->jit_func)(L); /* do the actual call */\n}\n\nint llvm_precall_lua (lua_State *L, StkId func, int nresults) {\n  Closure *cl;\n  Proto *p;\n\n  cl = clvalue(func);\n  p = cl->l.p;\n  /* check if Function needs to be compiled. */\n  if(p->jit_func == NULL) {\n    llvm_compiler_compile(L, p);\n  }\n  if(p->jit_func != NULL) {\n    if (!p->is_vararg) {  /* no varargs? */\n      cl->l.precall = llvm_precall_jit;\n      return llvm_precall_jit(L, func, nresults);\n    } else {\n      cl->l.precall = llvm_precall_jit_vararg;\n      return llvm_precall_jit_vararg(L, func, nresults);\n    }\n  }\n  /* function didn't compile, fall-back to lua interpreter */\n  cl->l.precall = luaD_precall_lua;\n  return luaD_precall_lua(L, func, nresults);\n}\n\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/llvm-lua.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include <stdio.h>\n\n#include \"llvm_compiler.h\"\n#include \"lua_interpreter.h\"\n\n#include \"llvm/Support/CommandLine.h\"\n#include \"llvm/Support/ManagedStatic.h\"\n\nnamespace {\n  llvm::cl::opt<std::string>\n  InputFile(llvm::cl::Positional, llvm::cl::desc(\"<script>\"));\n\n  llvm::cl::list<std::string>\n  InputArgv(llvm::cl::ConsumeAfter, llvm::cl::desc(\"<script arguments>...\"));\n\n  llvm::cl::list<std::string>\n  Executes(\"e\",\n            llvm::cl::desc(\"execuate string 'stat'\"),\n              llvm::cl::value_desc(\"stat\"),\n              llvm::cl::ZeroOrMore,\n              llvm::cl::Prefix);\n\n  llvm::cl::list<std::string>\n  Libraries(\"l\",\n            llvm::cl::desc(\"require library 'name'\"),\n              llvm::cl::value_desc(\"name\"),\n              llvm::cl::ZeroOrMore,\n              llvm::cl::Prefix);\n\n  llvm::cl::opt<std::string>\n  MemLimit(\"m\",\n            llvm::cl::desc(\"set memory limit. (units ar in Kbytes)\"),\n              llvm::cl::value_desc(\"limit\"));\n\n  llvm::cl::opt<bool>\n  Interactive(\"i\",\n            llvm::cl::desc(\"enter interactive mode after executing 'script'\"));\n\n  llvm::cl::opt<bool>\n  ShowVersion(\"v\",\n            llvm::cl::desc(\"show version information\"));\n\n}\n\nvoid print_version() {\n\tprintf(LLVM_LUA_VERSION \" \" LLVM_LUA_COPYRIGHT \"\\n\");\n\tprintf(LUA_RELEASE \"  \" LUA_COPYRIGHT \"\\n\");\n\tllvm::cl::PrintVersionMessage();\n}\n\n/*\n *\n */\nint main(int argc, char ** argv) {\n\tstd::vector<std::string> arg_list;\n\tllvm::llvm_shutdown_obj Y;   // Call llvm_shutdown() on exit.\n\tstd::string tmp;\n\tchar **lua_argv;\n\tint lua_argc=0;\n\tint new_argc=0;\n\tint pos;\n\tint ret;\n\n\t// check for '--' and '-' options to cut-off parsing at that point.\n\tfor(new_argc=0; new_argc < argc; new_argc++) {\n\t\tif(argv[new_argc][0] == '-') {\n\t\t\tif(argv[new_argc][1] == '\\0') {\n\t\t\t\tbreak;\n\t\t\t} else if(argv[new_argc][1] == '-' && argv[new_argc][2] == '\\0') {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tllvm::cl::SetVersionPrinter(print_version);\n\tllvm::cl::ParseCommandLineOptions(new_argc, argv, 0, true);\n\t// Show version?\n\tif(ShowVersion) {\n\t\tprint_version();\n\t\treturn 0;\n\t}\n\t// recreate arg list.\n\targ_list.push_back(argv[0]);\n\tfor(std::vector<std::string>::iterator I=Executes.begin(); I != Executes.end(); I++) {\n\t\tpos = Executes.getPosition(I - Executes.begin());\n\t\t// keep same format -e'statement' or -e 'statement'\n\t\tif(argv[pos][0] == '-' && argv[pos][1] == 'e') {\n\t\t\ttmp = \"-e\";\n\t\t\ttmp.append(*I);\n\t\t\targ_list.push_back(tmp);\n\t\t} else {\n\t\t\targ_list.push_back(\"-e\");\n\t\t\targ_list.push_back(*I);\n\t\t}\n\t}\n\tfor(std::vector<std::string>::iterator I=Libraries.begin(); I != Libraries.end(); I++) {\n\t\tpos = Libraries.getPosition(I - Libraries.begin());\n\t\t// keep same format -llibrary or -l library\n\t\tif(argv[pos][0] == '-' && argv[pos][1] == 'l') {\n\t\t\ttmp = \"-l\";\n\t\t\ttmp.append(*I);\n\t\t\targ_list.push_back(tmp);\n\t\t} else {\n\t\t\targ_list.push_back(\"-l\");\n\t\t\targ_list.push_back(*I);\n\t\t}\n\t}\n\tif(!MemLimit.empty()) {\n\t\targ_list.push_back(\"-m\");\n\t\targ_list.push_back(MemLimit);\n\t}\n\tif(Interactive) {\n\t\targ_list.push_back(\"-i\");\n\t}\n\tif(!InputFile.empty()) {\n\t\targ_list.push_back(InputFile);\n\t}\n\t// append options from cut-off point.\n\tfor(;new_argc < argc; new_argc++) {\n\t\targ_list.push_back(argv[new_argc]);\n\t}\n\targ_list.insert(arg_list.end(),InputArgv.begin(), InputArgv.end());\n\t/* construct lua_argc, lua_argv. */\n\tnew_argc = arg_list.size() + 1;\n\tlua_argv = (char **)calloc(new_argc, sizeof(char *));\n\tfor(std::vector<std::string>::iterator I=arg_list.begin(); I != arg_list.end(); I++) {\n\t\tif(lua_argc == new_argc) break;\n\t\tlua_argv[lua_argc] = (char *)(*I).c_str();\n\t\tlua_argc++;\n\t}\n\tlua_argv[lua_argc] = NULL;\n\n\t// initialize the Lua to LLVM compiler.\n\tret = llvm_compiler_main(1);\n\t// Run the main \"interpreter loop\" now.\n\tret = lua_main(lua_argc, lua_argv);\n\treturn ret;\n}\n\n"
  },
  {
    "path": "llvm-lua/llvm-luac.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include <stdio.h>\n\n#include \"llvm/LLVMContext.h\"\n#include \"llvm/Module.h\"\n#include \"llvm/PassManager.h\"\n#include \"llvm/Pass.h\"\n#include \"llvm/ADT/Triple.h\"\n#include \"llvm/Analysis/Verifier.h\"\n#include \"llvm/Bitcode/ReaderWriter.h\"\n#include \"llvm/CodeGen/LinkAllAsmWriterComponents.h\"\n#include \"llvm/CodeGen/LinkAllCodegenComponents.h\"\n#include \"llvm/Config/config.h\"\n#include \"llvm/LinkAllVMCore.h\"\n#include \"llvm/Support/CommandLine.h\"\n#include \"llvm/Support/FileUtilities.h\"\n#include \"llvm/Support/FormattedStream.h\"\n#include \"llvm/Support/ManagedStatic.h\"\n#include \"llvm/Support/MemoryBuffer.h\"\n#include \"llvm/Support/PluginLoader.h\"\n#include \"llvm/Support/PrettyStackTrace.h\"\n#include \"llvm/Support/Signals.h\"\n#include \"llvm/Support/TargetSelect.h\"\n#include \"llvm/Support/TargetRegistry.h\"\n#include \"llvm/Target/TargetData.h\"\n#include \"llvm/Target/TargetMachine.h\"\n\n#include \"llvm_compiler.h\"\n#include \"lua_compiler.h\"\n\nnamespace {\n  llvm::cl::list<std::string>\n  InputFiles(llvm::cl::Positional, llvm::cl::OneOrMore, llvm::cl::desc(\"[filenames]\"));\n\n  llvm::cl::opt<bool>\n  Bitcode(\"bc\",\n            llvm::cl::desc(\"output LLVM bitcode\"));\n\n  llvm::cl::list<std::string>\n  Libraries(\"L\",\n            llvm::cl::desc(\"preload Lua library 'name'\"),\n              llvm::cl::value_desc(\"name\"),\n              llvm::cl::ZeroOrMore,\n              llvm::cl::Prefix);\n\n  llvm::cl::list<bool>\n  ListOpcodes(\"l\",\n            llvm::cl::desc(\"list opcodes\"),\n              llvm::cl::ZeroOrMore);\n\n  llvm::cl::opt<std::string>\n  Output(\"o\",\n            llvm::cl::desc(\"output to file 'name' (default is \\\"luac.out\\\")\"),\n              llvm::cl::value_desc(\"name\"));\n\n  llvm::cl::opt<bool>\n  ParseOnly(\"p\",\n            llvm::cl::desc(\"parse only\"));\n\n  llvm::cl::opt<bool>\n  StripDebug(\"s\",\n            llvm::cl::desc(\"strip debug information\"));\n\n  llvm::cl::opt<bool>\n  ShowVersion(\"v\",\n            llvm::cl::desc(\"show version information\"));\n\n}\n\nvoid print_version() {\n\tprintf(LLVM_LUA_VERSION \" \" LLVM_LUA_COPYRIGHT \"\\n\");\n\tprintf(LUA_RELEASE \"  \" LUA_COPYRIGHT \"\\n\");\n\tllvm::cl::PrintVersionMessage();\n\tprintf(\"\\n\");\n\tllvm::TargetRegistry::printRegisteredTargetsForVersion();\n}\n\n/*\n *\n */\nint main(int argc, char ** argv) {\n  llvm::sys::PrintStackTraceOnErrorSignal();\n  llvm::PrettyStackTraceProgram X(argc, argv);\n\tstd::vector<std::string> arg_list;\n\tllvm::llvm_shutdown_obj Y;   // Call llvm_shutdown() on exit.\n\tstd::string tmp;\n\tchar **luac_argv;\n\tint luac_argc=0;\n\tint new_argc=0;\n\tint pos;\n\tint ret;\n\n  // Initialize targets first.\n  llvm::InitializeAllTargets();\n  llvm::InitializeAllTargetMCs();\n  llvm::InitializeAllAsmPrinters();\n  llvm::InitializeAllAsmParsers();\n\n\tllvm::cl::SetVersionPrinter(print_version);\n\n\tllvm::cl::ParseCommandLineOptions(argc, argv, \"LLVM-Lua native compiler\\n\");\n\t// Show version?\n\tif(ShowVersion) {\n\t\tprint_version();\n\t\treturn 0;\n\t}\n\t// recreate arg list.\n\targ_list.push_back(argv[0]);\n\tfor(std::vector<std::string>::iterator I=Libraries.begin(); I != Libraries.end(); I++) {\n\t\tpos = Libraries.getPosition(I - Libraries.begin());\n\t\t// keep same format -llibrary or -l library\n\t\tif(argv[pos][0] == '-' && argv[pos][1] == 'L') {\n\t\t\ttmp = \"-L\";\n\t\t\ttmp.append(*I);\n\t\t\targ_list.push_back(tmp);\n\t\t} else {\n\t\t\targ_list.push_back(\"-L\");\n\t\t\targ_list.push_back(*I);\n\t\t}\n\t}\n\tif(Bitcode) {\n\t\targ_list.push_back(\"-bc\");\n\t}\n\tfor(std::vector<bool>::iterator I=ListOpcodes.begin(); I != ListOpcodes.end(); I++) {\n\t\targ_list.push_back(\"-l\");\n\t}\n\tif(!Output.empty()) {\n\t\targ_list.push_back(\"-o\");\n\t\targ_list.push_back(Output);\n\t}\n\tif(ParseOnly) {\n\t\targ_list.push_back(\"-p\");\n\t}\n\tif(StripDebug) {\n\t\targ_list.push_back(\"-s\");\n\t}\n\targ_list.insert(arg_list.end(),InputFiles.begin(), InputFiles.end());\n\t/* construct luac_argc, luac_argv. */\n\tnew_argc = arg_list.size() + 1;\n\tluac_argv = (char **)calloc(new_argc, sizeof(char *));\n\tfor(std::vector<std::string>::iterator I=arg_list.begin(); I != arg_list.end(); I++) {\n\t\tif(luac_argc == new_argc) break;\n\t\tluac_argv[luac_argc] = (char *)(*I).c_str();\n\t\tluac_argc++;\n\t}\n\tluac_argv[luac_argc] = NULL;\n\n\t// initialize the Lua to LLVM compiler.\n\tret = llvm_compiler_main(0);\n\t// Run the main Lua compiler\n\tret = luac_main(luac_argc, luac_argv);\n\treturn ret;\n}\n\n"
  },
  {
    "path": "llvm-lua/llvm_compiler.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include \"LLVMCompiler.h\"\n#include \"llvm-c/ExecutionEngine.h\"\n#include \"llvm-c/Target.h\"\n#include \"llvm_compiler.h\"\n#include \"llvm_compiler_private.h\"\n\nextern \"C\" {\n\n#include \"lstate.h\"\n\n/* only used to turn off JIT for static compiler llvm-luac. */\nstatic int g_useJIT = 1;\nstatic int g_need_init = 1;\n\nint llvm_compiler_main(int useJIT) {\n\tg_useJIT = useJIT;\n\treturn 0;\n}\n\nLLVMCompiler *llvm_get_compiler(lua_State *L) {\n\tglobal_State *g = G(L);\n\treturn (LLVMCompiler *)g->llvm_compiler;\n}\n\nvoid llvm_new_compiler(lua_State *L) {\n\tglobal_State *g = G(L);\n\tif(g_need_init) {\n\t\tLLVMLinkInJIT();\n\t\tLLVMInitializeNativeTarget();\n\t\tg_need_init = 0;\n\t}\n\tg->llvm_compiler = new LLVMCompiler(g_useJIT);\n}\n\nvoid llvm_free_compiler(lua_State *L) {\n\tglobal_State *g = G(L);\n\tLLVMCompiler *compiler = ((LLVMCompiler *)g->llvm_compiler);\n\tg->llvm_compiler = NULL;\n\tdelete compiler;\n}\n\nvoid llvm_compiler_compile(lua_State *L, Proto *p) {\n\tLLVMCompiler *compiler = llvm_get_compiler(L);\n\tif(compiler == NULL) {\n\t\tllvm_compiler_main(1);\n\t}\n\tcompiler->compile(L, p);\n}\n\nvoid llvm_compiler_compile_all(lua_State *L, Proto *p) {\n\tLLVMCompiler *compiler = llvm_get_compiler(L);\n\tif(compiler == NULL) {\n\t\tllvm_compiler_main(1);\n\t}\n\tcompiler->compileAll(L, p);\n}\n\nvoid llvm_compiler_free(lua_State *L, Proto *p) {\n\tLLVMCompiler *compiler = llvm_get_compiler(L);\n\tif(compiler != NULL) {\n\t\tcompiler->free(L, p);\n\t}\n}\n\n}// end: extern \"C\"\n\n"
  },
  {
    "path": "llvm-lua/llvm_compiler.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef llvm_compiler_h\n#define llvm_compiler_h\n\n#include \"lua_core.h\"\n#include \"llvm_lua_config.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lobject.h\"\n\nint llvm_compiler_main(int useJIT);\nvoid llvm_new_compiler(lua_State *L);\nvoid llvm_free_compiler(lua_State *L);\nvoid llvm_compiler_compile(lua_State *L, Proto *p);\nvoid llvm_compiler_compile_all(lua_State *L, Proto *p);\nvoid llvm_compiler_free(lua_State *L, Proto *p);\n\nextern int llvm_precall_jit (lua_State *L, StkId func, int nresults);\nextern int llvm_precall_lua (lua_State *L, StkId func, int nresults);\n\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/llvm_compiler_private.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef llvm_compiler_private_h\n#define llvm_compiler_private_h\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nLLVMCompiler *llvm_get_compiler(lua_State *L);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/llvm_dumper.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include \"LLVMCompiler.h\"\n#include \"LLVMDumper.h\"\n#include \"llvm_compiler.h\"\n#include \"llvm_compiler_private.h\"\n#include \"llvm_dumper.h\"\n\nextern \"C\" {\n\nvoid llvm_dumper_dump(const char *output, lua_State *L, Proto *p, int stripping) {\n\tLLVMCompiler *compiler = llvm_get_compiler(L);\n\tLLVMDumper *dumper = new LLVMDumper(compiler);\n\tdumper->dump(output, L, p, stripping);\n\tdelete dumper;\n}\n\n}// end: extern \"C\"\n\n"
  },
  {
    "path": "llvm-lua/llvm_dumper.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef llvm_dumper_h\n#define llvm_dumper_h\n\n#include \"lua_core.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lobject.h\"\n\nvoid llvm_dumper_dump(const char *output, lua_State *L, Proto *p, int stripping);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/llvm_lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <stdlib.h>\n#include <math.h>\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI (3.14159265358979323846)\n#define RADIANS_PER_DEGREE (PI/180.0)\n\n\n#define llvm_arg_tonumber(L, arg, narg) \\\n  if(!ttisnumber(arg)) { \\\n    goto fallback; \\\n  }\n\n#define MATH_FASTCALL1(name, fname) \\\nstatic int math_ ## name ## _precall (lua_State *L, StkId func, int nresults) { \\\n  StkId arg1 = func + 1; \\\n  llvm_arg_tonumber(L, arg1, 1); \\\n  setnvalue(func, fname(nvalue(arg1))); \\\n  L->ci--; \\\n  L->top = func + 1; \\\n  L->base = L->ci->base; \\\n  return PCRC; \\\nfallback: \\\n  return luaD_precall_c(L, func, nresults); \\\n}\n\n#define MATH_FASTCALL2(name, fname) \\\nstatic int math_ ## name ## _precall (lua_State *L, StkId func, int nresults) { \\\n  StkId arg1 = func + 1; \\\n  StkId arg2 = func + 2; \\\n  llvm_arg_tonumber(L, arg1, 1); \\\n  llvm_arg_tonumber(L, arg2, 2); \\\n  setnvalue(func, fname(nvalue(arg1), nvalue(arg2))); \\\n  L->ci--; \\\n  L->top = func + 1; \\\n  L->base = L->ci->base; \\\n  return PCRC; \\\nfallback: \\\n  return luaD_precall_c(L, func, nresults); \\\n}\n\n\n\nstatic int math_abs (lua_State *L) {\n  lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(abs, fabs)\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, sin(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(sin, sin)\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(sinh, sinh)\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, cos(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(cos, cos)\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(cosh, cosh)\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, tan(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(tan, tan)\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(tanh, tanh)\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, asin(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(asin, asin)\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, acos(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(acos, acos)\n\nstatic int math_atan (lua_State *L) {\n  lua_pushnumber(L, atan(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(atan, atan)\n\nstatic int math_atan2 (lua_State *L) {\n  lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nMATH_FASTCALL2(atan2, atan2)\n\nstatic int math_ceil (lua_State *L) {\n  lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(ceil, ceil)\n\nstatic int math_floor (lua_State *L) {\n  lua_pushnumber(L, floor(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(floor, floor)\n\nstatic int math_fmod (lua_State *L) {\n  lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nMATH_FASTCALL2(fmod, fmod)\n\nstatic int math_modf (lua_State *L) {\n  double ip;\n  double fp = modf(luaL_checknumber(L, 1), &ip);\n  lua_pushnumber(L, ip);\n  lua_pushnumber(L, fp);\n  return 2;\n}\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(sqrt, sqrt)\n\nstatic int math_pow (lua_State *L) {\n  lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nMATH_FASTCALL2(pow, pow)\n\nstatic int math_log (lua_State *L) {\n  lua_pushnumber(L, log(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(log, log)\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, log10(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(log10, log10)\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, exp(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nMATH_FASTCALL1(exp, exp)\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);\n  return 1;\n}\n\n#define radians_to_degree(num) ((num) / RADIANS_PER_DEGREE)\nMATH_FASTCALL1(deg, radians_to_degree)\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);\n  return 1;\n}\n\n#define degree_to_radians(num) ((num) * RADIANS_PER_DEGREE)\nMATH_FASTCALL1(rad, degree_to_radians)\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));\n  return 1;\n}\n\nMATH_FASTCALL2(ldexp, ldexp)\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  lua_Number dmin = luaL_checknumber(L, 1);\n  int i;\n  for (i=2; i<=n; i++) {\n    lua_Number d = luaL_checknumber(L, i);\n    if (d < dmin)\n      dmin = d;\n  }\n  lua_pushnumber(L, dmin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  lua_Number dmax = luaL_checknumber(L, 1);\n  int i;\n  for (i=2; i<=n; i++) {\n    lua_Number d = luaL_checknumber(L, i);\n    if (d > dmax)\n      dmax = d;\n  }\n  lua_pushnumber(L, dmax);\n  return 1;\n}\n\n\nstatic int math_random (lua_State *L) {\n  /* the `%' avoids the (rare) case of r==1, and is needed also because on\n     some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */\n  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, r);  /* Number between 0 and 1 */\n      break;\n    }\n    case 1: {  /* only upper limit */\n      int u = luaL_checkint(L, 1);\n      luaL_argcheck(L, 1<=u, 1, \"interval is empty\");\n      lua_pushnumber(L, floor(r*u)+1);  /* int between 1 and `u' */\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      int l = luaL_checkint(L, 1);\n      int u = luaL_checkint(L, 2);\n      luaL_argcheck(L, l<=u, 2, \"interval is empty\");\n      lua_pushnumber(L, floor(r*(u-l+1))+l);  /* int between `l' and `u' */\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  srand(luaL_checkint(L, 1));\n  return 0;\n}\n\n\nstatic const luaL_Reg3 mathlib[] = {\n  {\"abs\",   math_abs, math_abs_precall},\n  {\"acos\",  math_acos, math_acos_precall},\n  {\"asin\",  math_asin, math_asin_precall},\n  {\"atan2\", math_atan2, math_atan2_precall},\n  {\"atan\",  math_atan, math_atan_precall},\n  {\"ceil\",  math_ceil, math_ceil_precall},\n  {\"cosh\",   math_cosh, math_cosh_precall},\n  {\"cos\",   math_cos, math_cos_precall},\n  {\"deg\",   math_deg, math_deg_precall},\n  {\"exp\",   math_exp, math_exp_precall},\n  {\"floor\", math_floor, math_floor_precall},\n  {\"fmod\",   math_fmod, math_fmod_precall},\n  {\"frexp\", math_frexp, NULL},\n  {\"ldexp\", math_ldexp, math_ldexp_precall},\n  {\"log10\", math_log10, math_log10_precall},\n  {\"log\",   math_log, math_log_precall},\n  {\"max\",   math_max, NULL},\n  {\"min\",   math_min, NULL},\n  {\"modf\",   math_modf, NULL},\n  {\"pow\",   math_pow, math_pow_precall},\n  {\"rad\",   math_rad, math_rad_precall},\n  {\"random\",     math_random, NULL},\n  {\"randomseed\", math_randomseed, NULL},\n  {\"sinh\",   math_sinh, math_sinh_precall},\n  {\"sin\",   math_sin, math_sin_precall},\n  {\"sqrt\",  math_sqrt, math_sqrt_precall},\n  {\"tanh\",   math_tanh, math_tanh_precall},\n  {\"tan\",   math_tan, math_tan_precall},\n  {NULL, NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUALIB_API int luaopen_math (lua_State *L) {\n  luaL_register3(L, LUA_MATHLIBNAME, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n#if defined(LUA_COMPAT_MOD)\n  lua_getfield(L, -1, \"fmod\");\n  lua_setfield(L, -2, \"mod\");\n#endif\n  return 1;\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/llvm_lua_config.h.in",
    "content": "#ifndef llvm_config_h\n#define llvm_config_h\n\n#define LLVM_LUA_VERSION \"@LLVM_LUA_NAME@ @LLVM_LUA_VERSION@\"\n#define LLVM_LUA_COPYRIGHT \"@LLVM_LUA_COPYRIGHT@\"\n\n#endif\n"
  },
  {
    "path": "llvm-lua/load_embedded_bc.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include <stdlib.h>\n#include <stdio.h>\n\n#include \"llvm/Module.h\"\n#include \"llvm/LLVMContext.h\"\n\n#include \"llvm/Support/MemoryBuffer.h\"\n#include \"llvm/Bitcode/ReaderWriter.h\"\n\n#include <string>\n\n#include \"load_embedded_bc.h\"\n\nllvm::Module *load_embedded_bc(llvm::LLVMContext &context,\n\tconst char *name, const unsigned char *start, size_t len, bool NoLazyCompilation)\n{\n\tllvm::Module *module = NULL;\n\tllvm::StringRef mem_ref((const char *)start, len - 1);\n\tstd::string error;\n\n\t// Load in the bitcode file containing the functions for each\n\t// bytecode operation.\n\n\tllvm::MemoryBuffer* buffer;\n\tbuffer= llvm::MemoryBuffer::getMemBuffer(mem_ref, name);\n\tif(buffer != NULL) {\n\t\tmodule = llvm::getLazyBitcodeModule(buffer, context, &error);\n\t\tif(!module) {\n\t\t\tdelete buffer;\n\t\t}\n\t}\n\tif(!module) {\n\t\tprintf(\"Failed to parse embedded '%s' file: %s\\n\", name, error.c_str());\n\t\texit(1);\n\t}\n\t// Materialize module\n\tif(NoLazyCompilation) {\n\t\tif(module->MaterializeAll(&error)) {\n\t\t\tprintf(\"Failed to materialize embedded '%s' file: %s\\n\", name, error.c_str());\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treturn module;\n}\n\n"
  },
  {
    "path": "llvm-lua/load_jit_proto.c",
    "content": "/*\n\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <string.h>\n#include \"lua_core.h\"\n#include \"lobject.h\"\n#include \"lfunc.h\"\n#include \"ldo.h\"\n#include \"lstring.h\"\n#include \"lmem.h\"\n#include \"load_jit_proto.h\"\n#include \"lundump.h\"\n\n#define DUMP_PROTOS 0\n#if DUMP_PROTOS\n#include <stdio.h>\n\n#define luaU_print luaU_dump_proto\n#include \"print.c\"\n#endif\n\nProto *load_jit_proto(lua_State *L, jit_proto *p) {\n\tProto *f = luaF_newproto(L);\n\tunsigned int i;\n\n\t/* proto source */\n\tf->source = luaS_new(L, p->name);\n\t/* jit_func */\n\tf->jit_func = p->jit_func;\n\t/* linedefined */\n\tf->linedefined = p->linedefined;\n\t/* lastlinedefined */\n\tf->lastlinedefined = p->lastlinedefined;\n\t/* nups */\n\tf->nups = p->nups;\n\t/* numparams */\n\tf->numparams = p->numparams;\n\t/* is_vararg */\n\tf->is_vararg = p->is_vararg;\n\t/* maxstacksize */\n\tf->maxstacksize = p->maxstacksize;\n\t/* sizek */\n\tf->sizek = p->sizek;\n\t/* k */\n\tf->k=luaM_newvector(L,p->sizek,TValue);\n\tfor(i = 0; i < p->sizek; i++) {\n\t\tTValue *o=&f->k[i];\n\t\tswitch(p->k[i].type) {\n\t\t\tcase TYPE_STRING:\n\t\t\t\tsetsvalue2n(L,o, luaS_newlstr(L, p->k[i].val.str, p->k[i].length));\n\t\t\t\tbreak;\n\t\t\tcase TYPE_BOOLEAN:\n\t\t\t\tsetbvalue(o, p->k[i].val.b != 0);\n\t\t\t\tbreak;\n\t\t\tcase TYPE_NUMBER:\n\t\t\t\tsetnvalue(o, p->k[i].val.num);\n\t\t\t\tbreak;\n\t\t\tcase TYPE_NIL:\n\t\t\tdefault:\n\t\t\t\tsetnilvalue(o);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t/* sizep */\n\tf->sizep = p->sizep;\n\t/* p */\n\tf->p=luaM_newvector(L,(size_t)p->sizep,Proto*);\n\tfor(i = 0; i < p->sizep; i++) {\n\t\tf->p[i] = load_jit_proto(L, &(p->p[i]));\n\t}\n\t/* sizecode */\n\tf->sizecode = p->sizecode;\n\t/* code */\n\tf->code=luaM_newvector(L,(size_t)p->sizecode,Instruction);\n\tfor(i = 0; i < p->sizecode; i++) {\n\t\tf->code[i] = p->code[i];\n\t}\n\t/* sizelineinfo */\n\tf->sizelineinfo = p->sizelineinfo;\n\t/* lineinfo */\n\tf->lineinfo=luaM_newvector(L,(size_t)p->sizelineinfo,int);\n\tfor(i = 0; i < p->sizelineinfo; i++) {\n\t\tf->lineinfo[i] = p->lineinfo[i];\n\t}\n\t/* sizelocvars */\n\tf->sizelocvars = p->sizelocvars;\n\t/* locvars */\n\tf->locvars=luaM_newvector(L,p->sizelocvars,LocVar);\n\tfor(i = 0; i < p->sizelocvars; i++) {\n\t\tjit_LocVar *locvar = &(p->locvars[i]);\n\t\tf->locvars[i].varname = luaS_new(L, locvar->varname);\n\t\tf->locvars[i].startpc = locvar->startpc;\n\t\tf->locvars[i].endpc = locvar->endpc;\n\t}\n\t/* sizeupvalues */\n\tf->sizeupvalues = p->sizeupvalues;\n\t/* upvalues */\n\tf->upvalues=luaM_newvector(L,(size_t)p->sizeupvalues,TString*);\n\tfor(i = 0; i < p->sizeupvalues; i++) {\n\t\tf->upvalues[i] = luaS_new(L, p->upvalues[i]);\n\t}\n\treturn f;\n}\n\nLUALIB_API int load_compiled_protos(lua_State *L, jit_proto *p) {\n  Closure *cl;\n  Proto *tf;\n  int i;\n\n\t// load compiled lua code.\n  luaC_checkGC(L);\n  set_block_gc(L);  /* stop collector during jit function loading. */\n  tf = load_jit_proto(L, p);\n#if DUMP_PROTOS\n\tluaU_dump_proto(tf,2);\n#endif\n  cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));\n  cl->l.p = tf;\n  for (i = 0; i < tf->nups; i++)  /* initialize eventual upvalues */\n    cl->l.upvals[i] = luaF_newupval(L);\n  setclvalue(L, L->top, cl);\n  incr_top(L);\n  unset_block_gc(L);\n\n\treturn 0;\n}\n\n\nLUALIB_API int load_compiled_module(lua_State *L, jit_proto *p) {\n\t// load compiled lua code.\n\tload_compiled_protos(L, p);\n\t// run compiled lua code.\n\tlua_insert(L, -2); // pass our first parameter to the lua module.\n\tlua_call(L, 1, 1);\n\n\treturn 1;\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/load_jit_proto.h",
    "content": "/*\n  load_jit_proto.h -- load jit proto\n\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef load_jit_proto_h\n#define load_jit_proto_h\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lobject.h\"\n#include <stdint.h>\n\n#define TYPE_NIL\t\t\t0\n#define TYPE_NUMBER\t\t1\n#define TYPE_BOOLEAN\t2\n#define TYPE_STRING\t\t3\n\ntypedef union constant_value {\n\t/* nil doesn't need a value. */\n\tuint32_t b; /* Lua boolean */\n\tLUA_NUMBER num; /* Lua numbers */\n\tchar *str; /* Lua string. */\n} constant_value;\n\ntypedef struct constant_type {\n\tuint32_t type;   /* constant type. */\n\tuint32_t length; /* string length */\n\tconstant_value val; /* value of Lua nil/boolean/number/string. */\n} constant_type;\n\n/* simplified version of LocVar struct. */\ntypedef struct jit_LocVar {\n\tchar *varname;\n\tuint32_t startpc;\n\tuint32_t endpc;\n} jit_LocVar;\n\n/* simplified version of Proto struct. */\ntypedef struct jit_proto jit_proto;\nstruct jit_proto {\n\tchar          *name;\n\tlua_CFunction jit_func;\n\tuint32_t      linedefined;\n\tuint32_t      lastlinedefined;\n\tuint8_t       nups;\n\tuint8_t       numparams;\n\tuint8_t       is_vararg;\n\tuint8_t       maxstacksize;\n\tuint16_t      sizek;\n\tuint16_t      sizelocvars;\n\tuint32_t      sizeupvalues;\n\tuint32_t      sizep;\n\tuint32_t      sizecode;\n\tuint32_t      sizelineinfo;\n\tconstant_type *k;\n\tjit_LocVar    *locvars;\n\tchar          **upvalues;\n\tjit_proto     *p;\n\tuint32_t      *code;\n\tuint32_t      *lineinfo;\n};\n\nProto *load_jit_proto(lua_State *L, jit_proto *p);\n\nLUALIB_API int load_compiled_protos(lua_State *L, jit_proto *p);\nLUALIB_API int load_compiled_module(lua_State *L, jit_proto *p);\n\nextern jit_proto jit_proto_init;\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/load_liblua_main.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include <stdlib.h>\n\n#include \"llvm/Module.h\"\n#include \"llvm/LLVMContext.h\"\n\n#include \"load_liblua_main.h\"\n#include \"load_embedded_bc.h\"\n\n#include \"liblua_main_bc.h\"\n\nllvm::Module *load_liblua_main(llvm::LLVMContext &context, bool NoLazyCompilation) {\n\treturn load_embedded_bc(context, \"liblua_main_bc\", liblua_main_bc,\n\t\tsizeof(liblua_main_bc), NoLazyCompilation);\n}\n\n"
  },
  {
    "path": "llvm-lua/load_liblua_main.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef load_liblua_main_h\n#define load_liblua_main_h\n\nextern llvm::Module *load_liblua_main(llvm::LLVMContext &context, bool NoLazyCompilation);\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/load_vm_ops.cpp",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#include <stdlib.h>\n\n#include \"llvm/LLVMContext.h\"\n#include \"llvm/Module.h\"\n\n#include \"load_vm_ops.h\"\n#include \"load_embedded_bc.h\"\n\n#include \"lua_vm_ops_bc.h\"\n\nllvm::Module *load_vm_ops(llvm::LLVMContext &context, bool NoLazyCompilation) {\n\treturn load_embedded_bc(context, \"lua_vm_ops_bc\", lua_vm_ops_bc,\n\t\tsizeof(lua_vm_ops_bc), NoLazyCompilation);\n}\n\n"
  },
  {
    "path": "llvm-lua/load_vm_ops.h",
    "content": "/*\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifndef load_vm_ops_h\n#define load_vm_ops_h\n\nextern llvm::Module *load_vm_ops(llvm::LLVMContext &context, bool NoLazyCompilation);\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua-compiler.in",
    "content": "#!/usr/bin/env bash\n#\n\n# path to lua-compiler\nDIR=`realpath $0`\nDIR=`dirname $DIR`\n\nCC=clang\nLIBTOOL=\"libtool --tag=CC --silent\"\nRPATH=`pwd`\nLLVM_LUAC=\"./llvm-luac\"\nPREFIX=\"@CMAKE_INSTALL_PREFIX@\"\n\n# find llvm-luac\nif [[ ! -x \"$LLVM_LUAC\" ]]; then\n\tLLVM_LUAC=\"$DIR/llvm-luac\"\nfi\nif [[ ! -x \"$LLVM_LUAC\" ]]; then\n\tLLVM_LUAC=`which llvm-luac`\nfi\n\nARCH=\nCPU=i686\n#CPU=pentium4\n#CPU=athlon64\nFORCE_CPU=\"0\"\nFILE=\nFILES=\"\"\nOUTPUT_FILE=\"\"\nDEBUG=\"0\"\nKEEP_TMPS=\"0\"\nSTATIC=\"0\"\nMODE=\"standalone\"\nEXPORT_SYMBOLS=\" -Wl,-E \"\nEXTRA_ARGS=\nLIBS=\n\nfunction echo_cmd() {\n\tCMD=\"$1\"\n\tshift 1\n\techo \"$CMD\" \"$@\"\n\t$CMD \"$@\"\n}\n\nfunction version() {\n\t$LLVM_LUAC -version\n\texit 0;\n}\n\nfunction usage() {\n\techo \"USAGE: $0 [options] <script>\n\nOPTIONS:\n  -c++             - Compile as C++ code instead of C code.  Requires that the core was\n\t                     also compiled as C++ code.\n  -lua-module      - Compile Lua script into a loadable module instead of a standalone\n                       executable.\n  -debug           - Turns off all optimizations and turns on debug info.  Both Lua debug\n                       info and gcc debug symbols are enabled.\n  -keep-tmps       - Don't delete temp. files generated by intermediate stages.  Use only\n                       for debuging generated code or if you are really curious!\n  -march=<march>   - <march> is passed to llc as '-march=<march>', see llc --version for targets\n  -mcpu=<arch>     - <cpu> is passed to gcc as '-march=<cpu>'\n  -******          - All other options passed to 'llvm-luac'.  See below for a list of\n                       options supported by 'llvm-luac'.\n\nllvm-luac '-help' output:\n\"\n\t$LLVM_LUAC -help\n\texit 0;\n}\n\n# parse command line parameters.\nCONSUME=\"\"\nfor arg in \"$@\" ; do\n\tcase \"$CONSUME\" in\n\t-o)  OUTPUT_FILE=` echo \"$arg\" | sed -e 's/-o=//'` ;;\n\t-L)  EXTRA_ARGS=\"$EXTRA_ARGS -L $arg\" ;;\n\tesac\n\tif [[ ! -z \"$CONSUME\" ]]; then\n\t\tCONSUME=\"\"\n\t\tcontinue\n\tfi\n\tcase \"$arg\" in\n\t-lua-mod*)  MODE=\"lua_mod\"; EXTRA_ARGS=\"$EXTRA_ARGS $arg\" ;;\n\t-static)  STATIC=\"1\" ;;\n\t-c++)  CC=clang++ ;;\n\t-debug)  DEBUG=\"1\" ;;\n\t-keep-tmps)  KEEP_TMPS=\"1\" ;;\n\t-mode=*)  MODE=` echo \"$arg\" | sed -e 's/-mode=//'` ;;\n\t-march=*)  ARCH=` echo \"$arg\" | sed -e 's/-march=//'` ;;\n\t-mcpu=*)  FORCE_CPU=\"1\"; CPU=` echo \"$arg\" | sed -e 's/-mcpu=//'` ;;\n\t-help|--help|-h)  usage ;;\n\t-version|--version|-v)  version ;;\n\t-o|-L)  CONSUME=\"$arg\" ;;\n\t-L*)  EXTRA_ARGS=\"$EXTRA_ARGS $arg\" ;;\n\t-*)  EXTRA_ARGS=\"$EXTRA_ARGS $arg\" ;;\n\t*) FILE=${arg/.lua/}; FILES=\"$FILES $arg\" ;;\n\tesac\ndone\n\n# find the mode's output file extension.\nOUTPUT_EXT=\"\"\ncase \"$MODE\" in\n\tll) OUTPUT_EXT=\".ll\" ;;\n\tlua_mod) OUTPUT_EXT=\".so\" ;;\nesac\nif [[ -z \"$OUTPUT_FILE\" ]]; then\n\tOUTPUT_FILE=\"${FILE}${OUTPUT_EXT}\"\nelse\n\tFILE=${OUTPUT_FILE}\nfi\n\n# get source file's path & filename.\nFPATH=`dirname ${FILE}`\nFNAME=`basename ${FILE}`\n\n# select debug/optimize parameters.\nif [[ $DEBUG == \"1\" ]]; then\n\tCFLAGS=\" -O0 -ggdb \"\n\tLUA_FLAGS=\" -O0 -g \"\n\t#LUA_FLAGS=\" -O3 -do-not-inline-opcodes \"\n\t#CFLAGS=\" -ggdb -O3 -fomit-frame-pointer -pipe -Wall \"\nelse\n\tLUA_FLAGS=\" -O3 -s \"\n\t#LUA_FLAGS=\" -O3 -g \"\n\t#CFLAGS=\" -ggdb -O3 -fomit-frame-pointer -pipe -Wall \"\n\tCFLAGS=\" -O3 -fomit-frame-pointer -pipe \"\nfi\nif [[ ! -z $CPU && $FORCE_CPU == \"1\" ]]; then\n\tCFLAGS=\" -mcpu=$CPU $LLC_FLAGS \"\nfi\n\nif [[ ! -z $ARCH && $FORCE_ARCH == \"1\" ]]; then\n\tCFLAGS=\" -march=$ARCH $LLC_FLAGS \"\nfi\n\n#\n# run llvm-luac to compile Lua source/bytecode to LLVM bitcode.\n#\necho_cmd $LLVM_LUAC $EXTRA_ARGS $LUA_FLAGS -bc -o ${FILE}.bc ${FILES} || {\n\techo \"llvm-luac: failed to compile Lua code into LLVM bitcode.\"\n\texit 1;\n}\nTMPS=\"${FILE}.bc\"\n\n# use one of the compile modes.\ncase \"$MODE\" in\n\tstandalone)\n\t\tTMPS=\"$TMPS ${FILE}_run.s\"\n\t\techo_cmd $CC $EXPORT_SYMBOLS $CFLAGS -o ${OUTPUT_FILE} ${FILE}.bc -lm -ldl\n\t\t;;\n\tlua_mod)\n\t\tTMPS=\"$TMPS ${FILE}_mod.s ${FPATH}/${FNAME}.lo ${FPATH}/lib${FNAME}.la\"\n\t\t# compile assembly code to object file.\n\t\t$LIBTOOL --mode=compile $CC $CFLAGS -c -o ${FILE}.lo ${FILE}.bc\n\t\t# compile to dynamic module\n\t\tif [[ $STATIC == \"0\" ]]; then\n\t\t\t$LIBTOOL --mode=link $CC -rpath ${RPATH} -o ${FPATH}/lib${FNAME}.la ${FILE}.lo && \\\n\t\t\tcp -p ${FPATH}/.libs/lib${FNAME}.so ${RPATH}/${OUTPUT_FILE}\n\t\t\tif [[ $KEEP_TMPS == \"0\" ]]; then\n\t\t\t\t$LIBTOOL --mode=clean rm -f $TMPS\n\t\t\tfi\n\t\tfi\n\t\t;;\n\t*)\n\t\techo \"Invalid compile mode: $MODE\"\n\t\t;;\nesac\n\nif [[ $KEEP_TMPS == \"0\" ]]; then\n\trm -f $TMPS\nfi\n\n"
  },
  {
    "path": "llvm-lua/lua-cross-compiler.in",
    "content": "#!/usr/bin/env bash\n#\n\n# path to lua-cross-compiler\nDIR=`realpath $0`\nDIR=`dirname $DIR`\n\nCC=@CROSS_TRIPLE@-gcc\nLLVM_LUAC=\"./@CROSS_TRIPLE@-llvm-luac\"\n\n# find llvm-luac cross-compiler\nif [[ ! -x \"$LLVM_LUAC\" ]]; then\n\tLLVM_LUAC=\"$DIR/@CROSS_TRIPLE@-llvm-luac\"\nfi\nif [[ ! -x \"$LLVM_LUAC\" ]]; then\n\tLLVM_LUAC=`which @CROSS_TRIPLE@-llvm-luac`\nfi\n\nARCH=@CROSS_ARCH@\nCPU=@CROSS_CPU@\nFORCE_CPU=\"0\"\nMODULE=\"0\"\nNO_ASSEMBLE=\"0\"\nFILE=lua-native-out\nFILES=\"\"\nDEBUG=\"0\"\nKEEP_TMPS=\"0\"\nEXTRA_ARGS=\n\nfunction echo_cmd() {\n\tCMD=\"$1\"\n\tshift 1\n\techo \"$CMD\" \"$@\"\n\t$CMD \"$@\"\n}\n\nfunction version() {\n\t$LLVM_LUAC -version\n\texit 0;\n}\n\nfunction usage() {\n\techo \"USAGE: $0 [options] <script>\n\nOPTIONS:\n  -lua-module      - Compile Lua script into a loadable module instead of a standalone\n                       executable.\n  -no-assemble     - Only compile to native Assembly code or C-code, don't compile to machine code.\n  -debug           - Turns off all optimizations and turns on debug info.  Both Lua debug\n                       info and gcc debug symbols are enabled.\n  -keep-tmps       - Don't delete temp. files generated by intermediate stages.  Use only\n                       for debuging generated code or if you are really curious!\n  -march=<march>   - <march> is passed to llc as '-march=<march>', see llc --version for targets\n  -mcpu=<arch>     - <cpu> is passed to gcc as '-march=<cpu>'\n  -******          - All other options passed to 'llvm-luac'.  See below for a list of\n                       options supported by 'llvm-luac'.\n\nllvm-luac '-help' output:\n\"\n\t$LLVM_LUAC -help\n\texit 0;\n}\n\n# parse command line parameters.\nCONSUME=\"\"\nfor arg in \"$@\" ; do\n\tcase \"$CONSUME\" in\n\t-o)  OUTPUT_FILE=` echo \"$arg\" | sed -e 's/-o=//'` ;;\n\t-L)  EXTRA_ARGS=\"$EXTRA_ARGS -L $arg\" ;;\n\tesac\n\tif [[ ! -z \"$CONSUME\" ]]; then\n\t\tCONSUME=\"\"\n\t\tcontinue\n\tfi\n\tcase \"$arg\" in\n\t-lua-mod*)  MODULE=\"1\"; EXTRA_ARGS=\"$EXTRA_ARGS $arg\" ;;\n\t-debug)  DEBUG=\"1\" ;;\n\t-no-assemble)  NO_ASSEMBLE=\"1\" ;;\n\t-keep-tmps)  KEEP_TMPS=\"1\" ;;\n\t-march=*)  ARCH=` echo \"$arg\" | sed -e 's/-march=//'` ;;\n\t-mcpu=*)  FORCE_CPU=\"1\"; CPU=` echo \"$arg\" | sed -e 's/-mcpu=//'` ;;\n\t-help|--help|-h)  usage ;;\n\t-version|--version|-v)  version ;;\n\t-o|-L)  CONSUME=\"$arg\" ;;\n\t-L*)  EXTRA_ARGS=\"$EXTRA_ARGS $arg\" ;;\n\t-*)  EXTRA_ARGS=\"$EXTRA_ARGS $arg\" ;;\n\t*) FILE=${arg/.lua/}; FILES=\"$FILES $arg\" ;;\n\tesac\ndone\n\n# find the mode's output file extension.\nOUTPUT_EXT=\"\"\nMODE_OUT=\"\"\nOUTPUT_EXT=\".s\"\nif [[ -z \"$OUTPUT_FILE\" ]]; then\n\tif [[ $MODULE == \"0\" && $NO_ASSEMBLE == \"0\" ]]; then\n\t\tOUTPUT_FILE=\"${FILE}\"\n\telse\n\t\tOUTPUT_FILE=\"${FILE}${OUTPUT_EXT}\"\n\tfi\nelse\n\tFILE=${OUTPUT_FILE}\nfi\nMODE_OUT=\"${FILE}${OUTPUT_EXT}\"\n\n# select debug/optimize parameters.\nif [[ $DEBUG == \"1\" ]]; then\n\tLUA_FLAGS=\" -O0 -g \"\n\tLLC_FLAGS=\" -O0 \"\nelse\n\tLUA_FLAGS=\" -O3 -s \"\n\tLLC_FLAGS=\" -O3 -tailcallopt \"\nfi\nif [[ ! -z \"$CPU\" ]]; then\n\tLLC_FLAGS=\" -mcpu=$CPU $LLC_FLAGS \"\nfi\nif [[ ! -z $ARCH ]]; then\n\tLLC_FLAGS=\" -march=$ARCH $LLC_FLAGS \"\nfi\n\n#\n# run llvm-luac to compile Lua source/bytecode to LLVM bitcode.\n#\necho_cmd $LLVM_LUAC $EXTRA_ARGS $LUA_FLAGS -bc -o ${FILE}.bc ${FILES} || {\n\techo \"llvm-luac: failed to compile Lua code into LLVM bitcode.\"\n\texit 1;\n}\nTMPS=\"${FILE}.bc\"\necho_cmd llc $LLC_FLAGS -filetype=asm -o ${MODE_OUT} ${FILE}.bc\n\n# compile to stand-alone\nif [[ $MODULE == \"0\" && $NO_ASSEMBLE == \"0\" ]]; then\n\techo_cmd ${CC} -o ${OUTPUT_FILE} ${MODE_OUT} -lm -ldl && \\\n\tTMPS=\"$TMPS ${MODE_OUT}\"\nfi\n\n# keep assembly/c-code output.\nif [[ $NO_ASSEMBLE == \"1\" && $MODE_OUT != $OUTPUT_FILE ]]; then\n\techo_cmd mv $MODE_OUT $OUTPUT_FILE\nfi\n\nif [[ $KEEP_TMPS == \"0\" ]]; then\n\trm -f $TMPS\nfi\n\n"
  },
  {
    "path": "llvm-lua/lua_compiler.c",
    "content": "/*\n** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $\n** Lua compiler (saves bytecodes to files; also list bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lua_core.h\"\n#include \"lua_interpreter.h\"\n#include \"llvm_compiler.h\"\n#include \"llvm_dumper.h\"\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n\n#define ENABLE_PARSER_HOOK 0\n#include \"hook_parser.c\"\n#include \"print.c\"\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define\tOUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int parse_only=0;\t/* only parse the Lua scripts? */\nstatic int llvm_bitcode=0;/* output llvm bitcode? */\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\n#define MAX_PRELOADS (MAXINDEXRK - 2)\nstatic char* preload_libs[MAX_PRELOADS];\nstatic int preloads=0;\n\nstatic void fatal(const char* message) {\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n  exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what) {\n  fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n  exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message) {\n  if (*message=='-')\n    fprintf(stderr,\"%s: unrecognized option \" LUA_QS \"\\n\",progname,message);\n  else\n    fprintf(stderr,\"%s: %s\\n\",progname,message);\n  fprintf(stderr,\n  \"usage: %s [options] [filenames].\\n\"\n  \"Available options are:\\n\"\n  \"  -        process stdin\\n\"\n  \"  -bc      output LLVM bitcode\\n\"\n  \"  -l       list\\n\"\n  \"  -L name  preload lua library \" LUA_QL(\"name\") \"\\n\"\n  \"  -o name  output to file \" LUA_QL(\"name\") \" (default is \\\"%s\\\")\\n\"\n  \"  -p       parse only\\n\"\n  \"  -s       strip debug information\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\",\n  progname,Output);\n  exit(EXIT_FAILURE);\n}\n\n#define\tIS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[]) {\n  int i;\n  int version=0;\n  if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n  for (i=1; i<argc; i++) {\n    if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n      break;\n    else if (IS(\"--\")) {\t\t/* end of options; skip it */\n      ++i;\n      if (version) ++version;\n      break;\n    } else if (IS(\"-\")) \t\t/* end of options; use stdin */\n      break;\n    else if (IS(\"-bc\")) {\t\t/* output LLVM bitcode */\n      llvm_bitcode=1;\n      dumping=0;\n    } else if (IS(\"-L\")) {\t/* preload library */\n      if (preloads >= MAX_PRELOADS) usage(LUA_QL(\"-L\") \" too many preloads\");\n      preload_libs[preloads]=argv[++i];\n      preloads++;\n    } else if (IS(\"-l\"))\t\t/* list */\n      ++listing;\n    else if (IS(\"-o\")) {\t\t/* output file */\n      output=argv[++i];\n      if (output==NULL || *output==0) usage(LUA_QL(\"-o\") \" needs argument\");\n      if (IS(\"-\")) output=NULL;\n    } else if (IS(\"-p\"))\t\t/* parse only */\n      parse_only=1;\n    else if (IS(\"-s\"))\t\t\t/* strip debug information */\n      stripping=1;\n    else if (IS(\"-v\"))\t\t\t/* show version */\n      ++version;\n    else\t\t\t\t\t/* unknown option */\n      usage(argv[i]);\n  }\n  if (i==argc && (listing || !dumping)) {\n    dumping=0;\n    argv[--i]=Output;\n  }\n  if (version) {\n    printf(\"%s  %s\\n\",LUA_RELEASE,LUA_COPYRIGHT);\n    if (version==argc-1) exit(EXIT_SUCCESS);\n  }\n  return i;\n}\n\n#define toproto(L,i) (clvalue(L->top+(i))->l.p)\n\nstatic Proto* combine(lua_State* L, int scripts) {\n  if (scripts==1 && preloads==0)\n    return toproto(L,-1);\n  else {\n    TString *s;\n    TValue *k;\n    int i,pc,n;\n    Proto* f=luaF_newproto(L);\n    setptvalue2s(L,L->top,f); incr_top(L);\n    f->source=luaS_newliteral(L,\"=(\" PROGNAME \")\");\n    f->maxstacksize=1;\n    pc=(2*scripts) + 1;\n    if(preloads > 0) {\n      pc+=(2*preloads) + 2;\n    }\n    f->code=luaM_newvector(L,pc,Instruction);\n    f->sizecode=pc;\n    n=(scripts + preloads);\n    f->p=luaM_newvector(L,n,Proto*);\n    f->sizep=n;\n    pc=0;\n    n=0;\n    /* preload libraries. */\n    if (preloads > 0) {\n      /* create constants array. */\n      f->k=luaM_newvector(L, (preloads + 2),TValue);\n      f->sizek=(preloads + 2);\n      /* make room for \"local t\" variable. */\n      f->maxstacksize=2;\n      /* add \"package\" & \"preload\" constants. */\n      k=&(f->k[0]);\n      s=luaS_newliteral(L, \"package\");\n      setsvalue2n(L,k,s);\n      k=&(f->k[1]);\n      s=luaS_newliteral(L, \"preload\");\n      setsvalue2n(L,k,s);\n      /* code: local t = package.preload */\n      f->code[pc++]=CREATE_ABx(OP_GETGLOBAL,0,0);\n      f->code[pc++]=CREATE_ABC(OP_GETTABLE,0,0,RKASK(1));\n    }\n    /* add preload libraries to \"package.preload\" */\n    for (i=0; i < preloads; i++) {\n      /* create constant for library name. */\n      k=&(f->k[i+2]);\n      s=luaS_new(L, preload_libs[i]);\n      setsvalue2n(L,k,s);\n      /* code: t['name'] = function() --[[ lib code ]] end */\n      f->code[pc++]=CREATE_ABx(OP_CLOSURE,1,n);\n      f->code[pc++]=CREATE_ABC(OP_SETTABLE,0,RKASK(i+2),1);\n      f->p[n++]=toproto(L,i-preloads-1);\n    }\n    /* call scripts. */\n    for (i=0; i < scripts; i++) {\n      /* code: (function() --[[ script code ]] end)() */\n      f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,n);\n      f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);\n      f->p[n++]=toproto(L,i-scripts-1-preloads);\n    }\n    f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);\n    return f;\n  }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u) {\n  UNUSED(L);\n  return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstruct Smain {\n  int argc;\n  char** argv;\n};\n\nstatic int pmain(lua_State* L) {\n  struct Smain* s = (struct Smain*)lua_touserdata(L, 1);\n  int argc=s->argc;\n  char** argv=s->argv;\n  Proto* f;\n  int scripts=0;\n  int i;\n  if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */\n  luaL_openlibs(L);  /* open libraries */\n  lua_gc(L, LUA_GCRESTART, 0);\n  /* compile each script from command line into a Lua function. */\n  for (i=0; i<argc; i++) {\n    const char* filename=IS(\"-\") ? NULL : argv[i];\n    if(IS(\"-L\")) break;\n    if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));\n    scripts++;\n  }\n  /* compile each preload library from the command line into a Lua function. */\n  for (i=0; i<preloads; i++) {\n    char* filename=preload_libs[i];\n    char* p;\n    /* try loading library as if it is a normal file. */\n    if (luaL_loadfile(L,filename)!=0) {\n      /* try pre-loading library with 'require' module loading system. */\n      lua_getglobal(L, \"require\");\n      lua_pushstring(L, filename);\n      lua_pushboolean(L, 1);\n      lua_call(L, 2, 1);\n      if (lua_iscfunction(L, -1)) { /* make sure it is not a C-Function. */\n        lua_pop(L, 1);\n        lua_pushfstring(L, \"\\nCan't preload C module: '%s'\\n\", filename);\n        lua_concat(L, 2);  /* accumulate with error from luaL_findfile */\n        fatal(lua_tostring(L,-1));\n      }\n      if (!lua_isfunction(L, -1)) { /* did we get an error? */\n        lua_pushliteral(L, \"\\n\");\n        lua_concat(L, 3);  /* accumulate with error from luaL_findfile */\n        fatal(lua_tostring(L,-1));\n      } else {\n        lua_remove(L, -2); /* remove error from luaL_findfile. */\n      }\n    } else {\n      /* convert filename into package name. */\n      p= filename + strlen(filename);\n      for(;p >= filename; p--) {\n        if(p[0] == '.') { /* Remove file extension. */\n          p[0] = '\\0';\n          continue;\n        }\n        if(p[0] == '/') { /* Remove file path. */\n          preload_libs[i] = p+1;\n          break;\n        }\n      }\n    }\n  }\n  /* generate a new Lua function to combine all of the compiled scripts. */\n  f=combine(L, scripts);\n  if (listing) luaU_print(f,listing>1);\n  if (llvm_bitcode && !parse_only) {\n    lua_lock(L);\n    llvm_dumper_dump(output, L, f, stripping);\n    lua_unlock(L);\n  }\n  if (dumping && !parse_only) {\n    FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n    if (D==NULL) cannot(\"open\");\n    lua_lock(L);\n    luaU_dump(L,f,writer,D,stripping);\n    lua_unlock(L);\n    if (ferror(D)) cannot(\"write\");\n    if (fclose(D)) cannot(\"close\");\n  }\n  return 0;\n}\n\nint luac_main(int argc, char* argv[]) {\n  lua_State* L;\n  struct Smain s;\n  int i=doargs(argc,argv);\n  argc-=i; argv+=i;\n  if (argc<=0) usage(\"no input files given\");\n  L=lua_open();\n  if (L==NULL) fatal(\"not enough memory for state\");\n  s.argc=argc;\n  s.argv=argv;\n  if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));\n  lua_close(L);\n  return EXIT_SUCCESS;\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_compiler.h",
    "content": "\n#ifndef lua_compiler_h\n#define lua_compiler_h\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lua_core.h\"\n\nextern int luac_main(int argc, char **argv);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_core.c",
    "content": "/*\n  lua_core.c -- Lua core, libraries and JIT hooks compiled into a single file\n\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lua_core.h\"\n#include \"lobject.h\"\n#include \"llvm_compiler.h\"\n\nvoid llvm_newproto (lua_State *L, Proto *f);\nvoid llvm_freeproto (lua_State *L, Proto *f);\n\n/* functions */\n#define JIT_NEW_STATE(L) llvm_new_compiler(L)\n#define JIT_CLOSE_STATE(L) llvm_free_compiler(L)\n#define JIT_NEWPROTO(L,f) llvm_newproto(L,f)\n#define JIT_FREEPROTO(L,f) llvm_freeproto(L,f)\n#define JIT_PRECALL llvm_precall_lua\n\n#include \"lapi.c\"\n#include \"lcode.c\"\n#include \"ldebug.c\"\n#include \"ldump.c\"\n#include \"lfunc.c\"\n#include \"lgc.c\"\n#include \"llex.c\"\n#include \"lmem.c\"\n#include \"lobject.c\"\n#include \"lopcodes.c\"\n#include \"lparser.c\"\n#include \"lstate.c\"\n#include \"lstring.c\"\n#include \"ltable.c\"\n#include \"ltm.c\"\n#include \"lundump.c\"\n#include \"lvm.c\"\n#include \"lzio.c\"\n\n#include \"lbaselib.c\"\n#include \"lcoco.c\"\n#include \"ldblib.c\"\n#include \"liolib.c\"\n#include \"linit.c\"\n#include \"llvm_lmathlib.c\"\n#include \"loadlib.c\"\n#include \"loslib.c\"\n#include \"lstrlib.c\"\n#include \"ltablib.c\"\n\n#include \"lauxlib.c\"\n\nvoid llvm_newproto (lua_State *L, Proto *f) {\n\t(void)L;\n\tf->jit_func = NULL;\n\tf->func_ref = NULL;\n}\n\nvoid llvm_freeproto (lua_State *L, Proto *f) {\n\tllvm_compiler_free(L, f);\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_core.h",
    "content": "\n#ifndef lua_core_h\n#define lua_core_h\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define lua_c\n#define loslib_c\n#define LUA_CORE\n\n/* Lua interpreter with LLVM JIT support. */\n#define JIT_SUPPORT\n\n/* extra variables for global_State */\n#define JIT_COMPILER_STATE \\\n\tvoid *llvm_compiler;\n\n/* state */\n#define JIT_PROTO_STATE \\\n\tlua_CFunction jit_func; /* jit compiled function */ \\\n\tvoid *func_ref; /* Reference to Function class */\n\n#include <lua.h>\n/* extern all lua core functions. */\n#undef LUAI_FUNC\n#define LUAI_FUNC extern\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_interpreter.c",
    "content": "/*\n * lua_interpreter.c -- Lua interpreter\n */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lua_core.h\"\n#include \"lua_interpreter.h\"\n\n#define ENABLE_PARSER_HOOK 1\n#include \"hook_parser.c\"\n\n#define main lua_main\n#include \"lua.c\"\n#undef main\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_interpreter.h",
    "content": "\n#ifndef lua_interpreter_h\n#define lua_interpreter_h\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nextern int lua_main(int argc, char **argv);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_main.c",
    "content": "/*\n** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n/*\n * Most of this file is from lua.c\n */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"lua_core.h\"\n#include \"lua_interpreter.h\"\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#include \"load_jit_proto.h\"\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);\n  luaL_error(L, \"interrupted!\");\n}\n\n\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens before lstop,\n                              terminate process (default action) */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) fprintf(stderr, \"%s: \", pname);\n  fprintf(stderr, \"%s\\n\", msg);\n  fflush(stderr);\n}\n\n\nstatic int report (lua_State *L, int status) {\n  if (status && !lua_isnil(L, -1)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg == NULL) msg = \"(error object is not a string)\";\n    l_message(progname, msg);\n    lua_pop(L, 1);\n  }\n  return status;\n}\n\n\nstatic int traceback (lua_State *L) {\n  if (!lua_isstring(L, 1))  /* 'message' not a string? */\n    return 1;  /* keep it intact */\n  lua_getfield(L, LUA_GLOBALSINDEX, \"debug\");\n  if (!lua_istable(L, -1)) {\n    lua_pop(L, 1);\n    return 1;\n  }\n  lua_getfield(L, -1, \"traceback\");\n  if (!lua_isfunction(L, -1)) {\n    lua_pop(L, 2);\n    return 1;\n  }\n  lua_pushvalue(L, 1);  /* pass error message */\n  lua_pushinteger(L, 2);  /* skip this function and traceback */\n  lua_call(L, 2, 1);  /* call debug.traceback */\n  return 1;\n}\n\n\nstatic int docall (lua_State *L, int narg, int clear) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, traceback);  /* push traceback function */\n  lua_insert(L, base);  /* put it under chunk and args */\n  signal(SIGINT, laction);\n  status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);\n  signal(SIGINT, SIG_DFL);\n  lua_remove(L, base);  /* remove traceback function */\n  /* force a complete garbage collection in case of errors */\n  if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);\n  return status;\n}\n\n\nstatic int getargs (lua_State *L, int argc, char **argv) {\n  int i;\n  luaL_checkstack(L, argc + 3, \"too many arguments to script\");\n  for (i=0; i < argc; i++)\n    lua_pushstring(L, argv[i]);\n  lua_createtable(L, argc, 0);\n  for (i=0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i);\n  }\n  return argc;\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  int status = luaL_loadfile(L, name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\nstatic int handle_script (lua_State *L, int argc, char **argv) {\n  int status;\n  int narg = getargs(L, argc, argv);  /* collect arguments */\n  lua_setglobal(L, \"arg\");\n  status = load_compiled_protos(L, &jit_proto_init);\n  lua_insert(L, -(narg+1));\n  if (status == 0)\n    status = docall(L, narg, 0);\n  else\n    lua_pop(L, narg);      \n  return report(L, status);\n}\n\n\n/* check that argument has no extra characters at the end */\n#define notail(x)\t{if ((x)[2] != '\\0') return -1;}\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *init = getenv(LUA_INIT);\n  if (init == NULL) return 0;  /* status OK */\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, \"=\" LUA_INIT);\n}\n\n\nstruct Smain {\n  int argc;\n  char **argv;\n  int status;\n};\n\n\nstatic int pmain (lua_State *L) {\n  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);\n  char **argv = s->argv;\n  globalL = L;\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */\n  luaL_openlibs(L);  /* open libraries */\n  lua_gc(L, LUA_GCRESTART, 0);\n  s->status = handle_luainit(L);\n  if (s->status != 0) return 0;\n  s->status = handle_script(L, s->argc, argv);\n  if (s->status != 0) return 0;\n  return 0;\n}\n\n\nint main (int argc, char **argv) {\n  int status;\n  struct Smain s;\n  lua_State *L = lua_open();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  s.argc = argc;\n  s.argv = argv;\n  status = lua_cpcall(L, &pmain, &s);\n  report(L, status);\n  lua_close(L);\n  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_normal.c",
    "content": "/*\n** See Copyright Notice in lua.h\n*/\n\n/*\n * lua_normal.c -- Lua core, libraries and interpreter in a single file\n */\n\n#define lua_normal_c\n\n#define luaall_c\n#define LUA_CORE\n#include \"lapi.c\"\n#include \"lcode.c\"\n#include \"ldebug.c\"\n#include \"ldump.c\"\n#include \"lfunc.c\"\n#include \"lgc.c\"\n#include \"llex.c\"\n#include \"lmem.c\"\n#include \"lobject.c\"\n#include \"lopcodes.c\"\n#include \"lparser.c\"\n#include \"lstate.c\"\n#include \"lstring.c\"\n#include \"ltable.c\"\n#include \"ltm.c\"\n#include \"lundump.c\"\n#include \"lvm.c\"\n#include \"lzio.c\"\n\n#include \"lbaselib.c\"\n#include \"lcoco.c\"\n#include \"ldblib.c\"\n#include \"liolib.c\"\n#include \"linit.c\"\n#include \"lmathlib.c\"\n#include \"loadlib.c\"\n#include \"loslib.c\"\n#include \"lstrlib.c\"\n#include \"ltablib.c\"\n\n#include \"lauxlib.c\"\n\n#include \"ldo.c\"\n#include \"lua.c\"\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_vm_ops.c",
    "content": "/*\n** See Copyright Notice in lua.h\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*\n * lua_vm_ops.c -- Lua ops functions for use by LLVM IR gen.\n *\n * Most of this file was copied from Lua's lvm.c\n */\n\n#include \"lua_vm_ops.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n#include <stdio.h>\n#include <assert.h>\n\nvoid vm_OP_MOVE(lua_State *L, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  setobjs2s(L, ra, base + b);\n}\n\nvoid vm_OP_LOADK(lua_State *L, TValue *k, int a, int bx) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  setobj2s(L, ra, k + bx);\n}\n\nvoid vm_OP_LOADK_N(lua_State *L, int a, lua_Number nb) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  setnvalue(ra, nb);\n}\n\nvoid vm_OP_LOADBOOL(lua_State *L, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  setbvalue(ra, b);\n}\n\nvoid vm_OP_LOADNIL(lua_State *L, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  TValue *rb = base + b;\n  do {\n    setnilvalue(rb--);\n  } while (rb >= ra);\n}\n\nvoid vm_OP_GETUPVAL(lua_State *L, LClosure *cl, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  setobj2s(L, ra, cl->upvals[b]->v);\n}\n\nvoid vm_OP_GETGLOBAL(lua_State *L, TValue *k, LClosure *cl, int a, int bx) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  TValue *rb = k + bx;\n  TValue g;\n  sethvalue(L, &g, cl->env);\n  lua_assert(ttisstring(rb));\n  luaV_gettable(L, &g, rb, ra);\n}\n\nvoid vm_OP_GETTABLE(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  luaV_gettable(L, base + b, RK(c), ra);\n}\n\nvoid vm_OP_SETGLOBAL(lua_State *L, TValue *k, LClosure *cl, int a, int bx) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  TValue g;\n  sethvalue(L, &g, cl->env);\n  lua_assert(ttisstring(k + bx));\n  luaV_settable(L, &g, k + bx, ra);\n}\n\nvoid vm_OP_SETUPVAL(lua_State *L, LClosure *cl, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  UpVal *uv = cl->upvals[b];\n  setobj(L, uv->v, ra);\n  luaC_barrier(L, uv, ra);\n}\n\nvoid vm_OP_SETTABLE(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  luaV_settable(L, ra, RK(b), RK(c));\n}\n\nvoid vm_OP_NEWTABLE(lua_State *L, int a, int b_fb2int, int c_fb2int) {\n  Table *h;\n  h = luaH_new(L, b_fb2int, c_fb2int);\n  sethvalue(L, L->base + a, h);\n  luaC_checkGC(L);\n}\n\nvoid vm_OP_SELF(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  StkId rb = base + b;\n  setobjs2s(L, ra+1, rb);\n  luaV_gettable(L, rb, RK(c), ra);\n}\n\nvoid vm_OP_ADD(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  arith_op(luai_numadd, TM_ADD);\n}\n\nvoid vm_OP_ADD_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c) {\n  TValue *base = L->base;\n  arith_op_nc(luai_numadd, TM_ADD);\n}\n\nvoid vm_OP_SUB(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  arith_op(luai_numsub, TM_SUB);\n}\n\nvoid vm_OP_SUB_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c) {\n  TValue *base = L->base;\n  arith_op_nc(luai_numsub, TM_SUB);\n}\n\nvoid vm_OP_MUL(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  arith_op(luai_nummul, TM_MUL);\n}\n\nvoid vm_OP_MUL_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c) {\n  TValue *base = L->base;\n  arith_op_nc(luai_nummul, TM_MUL);\n}\n\nvoid vm_OP_DIV(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  arith_op(luai_numdiv, TM_DIV);\n}\n\nvoid vm_OP_DIV_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c) {\n  TValue *base = L->base;\n  arith_op_nc(luai_numdiv, TM_DIV);\n}\n\nvoid vm_OP_MOD(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  arith_op(luai_nummod, TM_MOD);\n}\n\nvoid vm_OP_MOD_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c) {\n  TValue *base = L->base;\n  arith_op_nc(luai_nummod, TM_MOD);\n}\n\nvoid vm_OP_POW(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  arith_op(luai_numpow, TM_POW);\n}\n\nvoid vm_OP_POW_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c) {\n  TValue *base = L->base;\n  arith_op_nc(luai_numpow, TM_POW);\n}\n\nvoid vm_OP_UNM(lua_State *L, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  TValue *rb = base + b;\n  if (ttisnumber(rb)) {\n    lua_Number nb = nvalue(rb);\n    setnvalue(ra, luai_numunm(nb));\n  }\n  else {\n    luaV_arith(L, ra, rb, rb, TM_UNM);\n  }\n}\n\nvoid vm_OP_NOT(lua_State *L, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  int res = l_isfalse(base + b);  /* next assignment may change this value */\n  setbvalue(ra, res);\n}\n\nvoid vm_OP_LEN(lua_State *L, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  const TValue *rb = base + b;\n  switch (ttype(rb)) {\n    case LUA_TTABLE: {\n      setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));\n      break;\n    }\n    case LUA_TSTRING: {\n      setnvalue(ra, cast_num(tsvalue(rb)->len));\n      break;\n    }\n    default: {  /* try metamethod */\n      ptrdiff_t br = savestack(L, rb);\n      if (!luaV_call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))\n        luaG_typeerror(L, restorestack(L, br), \"get length of\");\n    }\n  }\n}\n\nvoid vm_OP_CONCAT(lua_State *L, int a, int b, int c) {\n  TValue *base;\n  luaV_concat(L, c-b+1, c); luaC_checkGC(L);\n  base = L->base;\n  setobjs2s(L, base + a, base + b);\n}\n\nvoid vm_OP_JMP(lua_State *L, int sbx) {\n  dojump(sbx);\n}\n\nint vm_OP_EQ(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  int ret;\n  TValue *rb = RK(b);\n  TValue *rc = RK(c);\n  ret = (equalobj(L, rb, rc) == a);\n  if(ret)\n    dojump(GETARG_sBx(*L->savedpc));\n  return ret;\n}\n\nint vm_OP_EQ_NC(lua_State *L, TValue *k, int b, lua_Number nc) {\n  TValue *base = L->base;\n  int ret;\n  TValue *rb = RK(b);\n  if (ttisnumber(rb)) {\n    ret = !luai_numeq(nvalue(rb), nc);\n    if(ret)\n      dojump(GETARG_sBx(*L->savedpc));\n    return ret;\n  }\n  return 1;\n}\n\nint vm_OP_NOT_EQ_NC(lua_State *L, TValue *k, int b, lua_Number nc) {\n  TValue *base = L->base;\n  int ret;\n  TValue *rb = RK(b);\n  if (ttisnumber(rb)) {\n    ret = luai_numeq(nvalue(rb), nc);\n    if(ret)\n      dojump(GETARG_sBx(*L->savedpc));\n    return ret;\n  }\n  return 0;\n}\n\nint vm_OP_LT(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  int ret;\n  ret = (luaV_lessthan(L, RK(b), RK(c)) == a);\n  if(ret)\n    dojump(GETARG_sBx(*L->savedpc));\n  return ret;\n}\n\nint vm_OP_LE(lua_State *L, TValue *k, int a, int b, int c) {\n  TValue *base = L->base;\n  int ret;\n  ret = (luaV_lessequal(L, RK(b), RK(c)) == a);\n  if(ret)\n    dojump(GETARG_sBx(*L->savedpc));\n  return ret;\n}\n\nint vm_OP_TEST(lua_State *L, int a, int c) {\n  TValue *ra = L->base + a;\n  if (l_isfalse(ra) != c) {\n    dojump(GETARG_sBx(*L->savedpc));\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_TESTSET(lua_State *L, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  TValue *rb = base + b;\n  if (l_isfalse(rb) != c) {\n    setobjs2s(L, ra, rb);\n    dojump(GETARG_sBx(*L->savedpc));\n    return 1;\n  }\n  return 0;\n}\n\n/*\n * Generic number FORPREP\n *\n * Test if init/plimit/pstep are numbers, fallback to slower FORPREP\n * if one ore more of then are not numbers.\n *\n */\nvoid vm_OP_FORPREP(lua_State *L, int a, int sbx) {\n  TValue *ra = L->base + a;\n  const TValue *init = ra;\n  const TValue *plimit = ra+1;\n  const TValue *pstep = ra+2;\n  int valid=1;\n  valid &= ttisnumber(init);\n  valid &= ttisnumber(plimit);\n  valid &= ttisnumber(pstep);\n  if(!valid) {\n    vm_OP_FORPREP_slow(L,a,sbx);\n  }\n  // subtract pstep from init.\n  setnvalue(ra, luai_numsub(nvalue(init), nvalue(pstep)));\n  dojump(sbx);\n}\n\nvoid vm_OP_FORPREP_no_sub(lua_State *L, int a, int sbx) {\n  TValue *ra = L->base + a;\n  const TValue *init = ra;\n  const TValue *plimit = ra+1;\n  const TValue *pstep = ra+2;\n  int valid=1;\n  valid &= ttisnumber(init);\n  valid &= ttisnumber(plimit);\n  valid &= ttisnumber(pstep);\n  if(!valid) {\n    vm_OP_FORPREP_slow(L,a,sbx);\n  }\n  dojump(sbx);\n}\n\n/*\n * limit & step are number constants.  Only test if init is a number.\n */\nvoid vm_OP_FORPREP_M_N_N(lua_State *L, int a, int sbx, lua_Number limit, lua_Number step) {\n  TValue *ra = L->base + a;\n  const TValue *init = ra;\n  if(!ttisnumber(init)) {\n    setnvalue(ra+1, limit);\n    setnvalue(ra+2, step);\n    vm_OP_FORPREP_slow(L,a,sbx);\n  }\n  dojump(sbx);\n}\n\n/*\n * init & pstep are number constants.  Only test if plimit is a number.\n */\nvoid vm_OP_FORPREP_N_M_N(lua_State *L, int a, int sbx, lua_Number init, lua_Number step) {\n  TValue *ra = L->base + a;\n  const TValue *plimit = ra+1;\n  if(!ttisnumber(plimit)) {\n    setnvalue(ra, init);\n    setnvalue(ra+2, step);\n    vm_OP_FORPREP_slow(L,a,sbx);\n  }\n  dojump(sbx);\n}\n\n/*\n * init, plimit & pstep are number constants.\n */\nvoid vm_OP_FORPREP_N_N_N(lua_State *L, int a, int sbx, lua_Number init, lua_Number step) {\n  dojump(sbx);\n}\n\nint vm_OP_FORLOOP(lua_State *L, int a, int sbx) {\n  TValue *ra = L->base + a;\n  lua_Number step = nvalue(ra+2);\n  lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */\n  lua_Number limit = nvalue(ra+1);\n  if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                          : luai_numle(limit, idx)) {\n    dojump(sbx);  /* jump back */\n    setnvalue(ra, idx);  /* update internal index... */\n    setnvalue(ra+3, idx);  /* ...and external index */\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_FORLOOP_N_N(lua_State *L, int a, int sbx, lua_Number limit, lua_Number step) {\n  TValue *ra = L->base + a;\n  lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */\n  if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                          : luai_numle(limit, idx)) {\n    dojump(sbx);  /* jump back */\n    setnvalue(ra, idx);  /* update internal index... */\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_FORLOOP_N_N_N(lua_State *L, int a, int sbx, lua_Number idx, lua_Number limit, lua_Number step) {\n  if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                          : luai_numle(limit, idx)) {\n    dojump(sbx);  /* jump back */\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_FORLOOP_up(lua_State *L, int a, int sbx, lua_Number idx, lua_Number limit) {\n  if (luai_numle(idx, limit)) {\n    dojump(sbx);  /* jump back */\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_FORLOOP_down(lua_State *L, int a, int sbx, lua_Number idx, lua_Number limit) {\n  if (luai_numle(limit, idx)) {\n    dojump(sbx);  /* jump back */\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_FORLOOP_long_up(lua_State *L, int a, int sbx, lua_Long idx, lua_Long limit) {\n  if (luai_numle(idx, limit)) {\n    dojump(sbx);  /* jump back */\n    return 1;\n  }\n  return 0;\n}\n\nint vm_OP_FORLOOP_long_down(lua_State *L, int a, int sbx, lua_Long idx, lua_Long limit) {\n  if (luai_numle(limit, idx)) {\n    dojump(sbx);  /* jump back */\n    return 1;\n  }\n  return 0;\n}\n\nvoid vm_OP_CLOSE(lua_State *L, int a) {\n  luaF_close(L, L->base + a);\n}\n\nLClosure *vm_get_current_closure(lua_State *L) {\n  return &clvalue(L->ci->func)->l;\n}\n\nTValue *vm_get_current_constants(LClosure *cl) {\n  return cl->p->k;\n}\n\nlua_Number vm_get_number(lua_State *L, int idx) {\n  return nvalue(L->base + idx);\n}\n\nvoid vm_set_number(lua_State *L, int idx, lua_Number num) {\n  setnvalue(L->base + idx, num);  /* write number to Lua-stack */\n}\n\nlua_Long vm_get_long(lua_State *L, int idx) {\n  return (lua_Long)nvalue(L->base + idx);\n}\n\nvoid vm_set_long(lua_State *L, int idx, lua_Long num) {\n  setnvalue(L->base + idx, (lua_Number)num);  /* write number to Lua-stack */\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_vm_ops.h",
    "content": "\n#ifndef lua_vm_ops_h\n#define lua_vm_ops_h\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lua_core.h\"\n#include \"lobject.h\"\n\ntypedef struct {\n  TValue *k;\n  LClosure *cl;\n} func_state;\n\n#if defined(__x86_64__)\ntypedef long lua_Long;\n#else\ntypedef long long lua_Long;\n#endif\n\ntypedef unsigned int hint_t;\n#define HINT_NONE\t\t\t\t\t\t\t0\n#define HINT_C_NUM_CONSTANT\t\t(1<<0)\n#define HINT_Bx_NUM_CONSTANT\t(1<<1)\n#define HINT_NOT\t\t\t\t\t\t\t(1<<2)\n#define HINT_FOR_M_N_N\t\t\t\t(1<<3)\n#define HINT_FOR_N_M_N\t\t\t\t(1<<4)\n#define HINT_FOR_N_N_N\t\t\t\t(1<<5)\n#define HINT_FOR_N_N\t\t\t\t\t(1<<6)\n#define HINT_SKIP_OP\t\t\t\t\t(1<<7)\n#define HINT_MINI_VM\t\t\t\t\t(1<<8)\n#define HINT_USE_LONG\t\t\t\t\t(1<<9)\n#define HINT_UP\t\t\t\t\t\t\t\t(1<<10)\n#define HINT_DOWN\t\t\t\t\t\t\t(1<<11)\n#define HINT_NO_SUB\t\t\t\t\t\t(1<<12)\n\ntypedef enum {\n\tVAR_T_VOID = 0,\n\tVAR_T_INT,\n\tVAR_T_ARG_A,\n\tVAR_T_ARG_B,\n\tVAR_T_ARG_BK,\n\tVAR_T_ARG_Bx_NUM_CONSTANT,\n\tVAR_T_ARG_B_FB2INT,\n\tVAR_T_ARG_Bx,\n\tVAR_T_ARG_sBx,\n\tVAR_T_ARG_C,\n\tVAR_T_ARG_CK,\n\tVAR_T_ARG_C_NUM_CONSTANT,\n\tVAR_T_ARG_C_NEXT_INSTRUCTION,\n\tVAR_T_ARG_C_FB2INT,\n\tVAR_T_PC_OFFSET,\n\tVAR_T_INSTRUCTION,\n\tVAR_T_NEXT_INSTRUCTION,\n\tVAR_T_LUA_STATE_PTR,\n\tVAR_T_K,\n\tVAR_T_CL,\n\tVAR_T_OP_VALUE_0,\n\tVAR_T_OP_VALUE_1,\n\tVAR_T_OP_VALUE_2\n} val_t;\n\ntypedef struct {\n\tint opcode; /* Lua opcode */\n\thint_t hint; /* Specialized version. [0=generic] */\n\tval_t ret_type; /* return type */\n\tconst char *name; /* function name */\n\tval_t params[10]; /* an 'VOID' type ends the parameter list */\n} vm_func_info;\n\nextern const vm_func_info vm_op_functions[];\n\nextern int vm_op_run_count[];\n\nextern void vm_count_OP(const Instruction i);\n\nextern void vm_print_OP(lua_State *L, LClosure *cl, const Instruction i, int pc_offset);\n\nextern void vm_next_OP(lua_State *L, LClosure *cl, int pc_offset);\n\nextern void vm_OP_MOVE(lua_State *L, int a, int b);\n\nextern void vm_OP_LOADK(lua_State *L, TValue *k, int a, int bx);\n\nextern void vm_OP_LOADK_N(lua_State *L, int a, lua_Number nb);\n\nextern void vm_OP_LOADBOOL(lua_State *L, int a, int b, int c);\n\nextern void vm_OP_LOADNIL(lua_State *L, int a, int b);\n\nextern void vm_OP_GETUPVAL(lua_State *L, LClosure *cl, int a, int b);\n\nextern void vm_OP_GETGLOBAL(lua_State *L, TValue *k, LClosure *cl, int a, int bx);\n\nextern void vm_OP_GETTABLE(lua_State *L, TValue *k, int a, int b, int c);\n\nextern void vm_OP_SETGLOBAL(lua_State *L, TValue *k, LClosure *cl, int a, int bx);\n\nextern void vm_OP_SETUPVAL(lua_State *L, LClosure *cl, int a, int b);\n\nextern void vm_OP_SETTABLE(lua_State *L, TValue *k, int a, int b, int c);\n\nextern void vm_OP_NEWTABLE(lua_State *L, int a, int b, int c);\n\nextern void vm_OP_SELF(lua_State *L, TValue *k, int a, int b, int c);\n\nextern void vm_OP_ADD(lua_State *L, TValue *k, int a, int b, int c);\nextern void vm_OP_ADD_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c);\n\nextern void vm_OP_SUB(lua_State *L, TValue *k, int a, int b, int c);\nextern void vm_OP_SUB_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c);\n\nextern void vm_OP_MUL(lua_State *L, TValue *k, int a, int b, int c);\nextern void vm_OP_MUL_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c);\n\nextern void vm_OP_DIV(lua_State *L, TValue *k, int a, int b, int c);\nextern void vm_OP_DIV_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c);\n\nextern void vm_OP_MOD(lua_State *L, TValue *k, int a, int b, int c);\nextern void vm_OP_MOD_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c);\n\nextern void vm_OP_POW(lua_State *L, TValue *k, int a, int b, int c);\nextern void vm_OP_POW_NC(lua_State *L, TValue *k, int a, int b, lua_Number nc, int c);\n\nextern void vm_OP_UNM(lua_State *L, int a, int b);\n\nextern void vm_OP_NOT(lua_State *L, int a, int b);\n\nextern void vm_OP_LEN(lua_State *L, int a, int b);\n\nextern void vm_OP_CONCAT(lua_State *L, int a, int b, int c);\n\nextern void vm_OP_JMP(lua_State *L, int sbx);\n\nextern int vm_OP_EQ(lua_State *L, TValue *k, int a, int b, int c);\nextern int vm_OP_EQ_NC(lua_State *L, TValue *k, int b, lua_Number nc);\nextern int vm_OP_NOT_EQ_NC(lua_State *L, TValue *k, int b, lua_Number nc);\n\nextern int vm_OP_LT(lua_State *L, TValue *k, int a, int b, int c);\n\nextern int vm_OP_LE(lua_State *L, TValue *k, int a, int b, int c);\n\nextern int vm_OP_TEST(lua_State *L, int a, int c);\n\nextern int vm_OP_TESTSET(lua_State *L, int a, int b, int c);\n\nextern int vm_OP_CALL(lua_State *L, int a, int b, int c);\n\nextern int vm_OP_RETURN(lua_State *L, int a, int b);\n\nextern int vm_OP_TAILCALL(lua_State *L, int a, int b);\n\nextern int vm_OP_FORLOOP(lua_State *L, int a, int sbx);\nextern int vm_OP_FORLOOP_N_N(lua_State *L, int a, int sbx, lua_Number limit, lua_Number step);\nextern int vm_OP_FORLOOP_N_N_N(lua_State *L, int a, int sbx, lua_Number idx, lua_Number limit, lua_Number step);\nextern int vm_OP_FORLOOP_up(lua_State *L, int a, int sbx, lua_Number idx, lua_Number limit);\nextern int vm_OP_FORLOOP_down(lua_State *L, int a, int sbx, lua_Number idx, lua_Number limit);\nextern int vm_OP_FORLOOP_long_up(lua_State *L, int a, int sbx, lua_Long idx, lua_Long limit);\nextern int vm_OP_FORLOOP_long_down(lua_State *L, int a, int sbx, lua_Long idx, lua_Long limit);\n\nextern void vm_OP_FORPREP_slow(lua_State *L, int a, int sbx);\nextern void vm_OP_FORPREP(lua_State *L, int a, int sbx);\nextern void vm_OP_FORPREP_no_sub(lua_State *L, int a, int sbx);\nextern void vm_OP_FORPREP_M_N_N(lua_State *L, int a, int sbx, lua_Number limit, lua_Number step);\nextern void vm_OP_FORPREP_N_M_N(lua_State *L, int a, int sbx, lua_Number init, lua_Number step);\nextern void vm_OP_FORPREP_N_N_N(lua_State *L, int a, int sbx, lua_Number init, lua_Number step);\n\nextern int vm_OP_TFORLOOP(lua_State *L, int a, int c);\n\nextern void vm_OP_SETLIST(lua_State *L, int a, int b, int c);\n\nextern void vm_OP_CLOSE(lua_State *L, int a);\n\nextern void vm_OP_CLOSURE(lua_State *L, LClosure *cl, int a, int bx, int pseudo_ops_offset);\n\nextern void vm_OP_VARARG(lua_State *L, LClosure *cl, int a, int b);\n\nextern int is_mini_vm_op(int opcode);\nextern void vm_mini_vm(lua_State *L, LClosure *cl, int count, int pseudo_ops_offset);\n\nextern void vm_op_hint_locals(char *locals, int stacksize, TValue *k, const Instruction i);\n\nextern LClosure *vm_get_current_closure(lua_State *L);\n\nextern TValue *vm_get_current_constants(LClosure *cl);\n\nextern lua_Number vm_get_number(lua_State *L, int idx);\nextern void vm_set_number(lua_State *L, int idx, lua_Number num);\n\nextern lua_Long vm_get_long(lua_State *L, int idx);\nextern void vm_set_long(lua_State *L, int idx, lua_Long num);\n\n/*\n** some macros for common tasks in `vm_OP_*' functions.\n*/\n\n#define runtime_check(L, c) { if (!(c)) return; }\n\n#define RA(i) (base+GETARG_A(i))\n/* to be used after possible stack reallocation */\n#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)  check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n  ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)  check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n  ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n#define KBx(i)  check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))\n\n#define RK(arg)  (ISK(arg) ? k+INDEXK(arg) : base+arg)\n\n#define dojump(i)  {luai_threadyield(L);}\n#define skip_op()\n\n\n#define Protect(x)  { {x;}; base = L->base; }\n\n#define arith_op(op,tm) { \\\n        TValue *ra = base + a; \\\n        TValue *rb = RK(b); \\\n        TValue *rc = RK(c); \\\n        if (ttisnumber(rb) && ttisnumber(rc)) { \\\n          lua_Number nb = nvalue(rb), nc = nvalue(rc); \\\n          setnvalue(ra, op(nb, nc)); \\\n        } \\\n        else \\\n          luaV_arith(L, ra, rb, rc, tm); \\\n      }\n\n#define arith_op_nc(op,tm) { \\\n        TValue *ra = base + a; \\\n        TValue *rb = RK(b); \\\n        if (ttisnumber(rb)) { \\\n          lua_Number nb = nvalue(rb); \\\n          setnvalue(ra, op(nb, nc)); \\\n        } \\\n        else \\\n          luaV_arith(L, ra, rb, RK(c), tm); \\\n      }\n\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "llvm-lua/lua_vm_ops_static.c",
    "content": "/*\n** See Copyright Notice in lua.h\n*/\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*\n * lua_vm_ops.c -- Lua ops functions for use by LLVM IR gen.\n *\n * Most of this file was copied from Lua's lvm.c\n */\n\n#include \"lua_vm_ops.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n#include <stdio.h>\n#include <string.h>\n#include <assert.h>\n\n#include \"llvm_compiler.h\"\n\nconst vm_func_info vm_op_functions[] = {\n  { OP_MOVE, HINT_NONE, VAR_T_VOID, \"vm_OP_MOVE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_LOADK, HINT_NONE, VAR_T_VOID, \"vm_OP_LOADK\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_Bx, VAR_T_VOID},\n  },\n  { OP_LOADK, HINT_Bx_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_LOADK_N\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_Bx_NUM_CONSTANT, VAR_T_VOID},\n  },\n  { OP_LOADBOOL, HINT_NONE, VAR_T_VOID, \"vm_OP_LOADBOOL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_LOADNIL, HINT_NONE, VAR_T_VOID, \"vm_OP_LOADNIL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_GETUPVAL, HINT_NONE, VAR_T_VOID, \"vm_OP_GETUPVAL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_CL, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_GETGLOBAL, HINT_NONE, VAR_T_VOID, \"vm_OP_GETGLOBAL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_CL, VAR_T_ARG_A, VAR_T_ARG_Bx, VAR_T_VOID},\n  },\n  { OP_GETTABLE, HINT_NONE, VAR_T_VOID, \"vm_OP_GETTABLE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_SETGLOBAL, HINT_NONE, VAR_T_VOID, \"vm_OP_SETGLOBAL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_CL, VAR_T_ARG_A, VAR_T_ARG_Bx, VAR_T_VOID},\n  },\n  { OP_SETUPVAL, HINT_NONE, VAR_T_VOID, \"vm_OP_SETUPVAL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_CL, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_SETTABLE, HINT_NONE, VAR_T_VOID, \"vm_OP_SETTABLE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_NEWTABLE, HINT_NONE, VAR_T_VOID, \"vm_OP_NEWTABLE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B_FB2INT, VAR_T_ARG_C_FB2INT, VAR_T_VOID},\n  },\n  { OP_SELF, HINT_NONE, VAR_T_VOID, \"vm_OP_SELF\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_ADD, HINT_NONE, VAR_T_VOID, \"vm_OP_ADD\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_ADD, HINT_C_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_ADD_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_SUB, HINT_NONE, VAR_T_VOID, \"vm_OP_SUB\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_SUB, HINT_C_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_SUB_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_MUL, HINT_NONE, VAR_T_VOID, \"vm_OP_MUL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_MUL, HINT_C_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_MUL_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_DIV, HINT_NONE, VAR_T_VOID, \"vm_OP_DIV\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_DIV, HINT_C_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_DIV_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_MOD, HINT_NONE, VAR_T_VOID, \"vm_OP_MOD\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_MOD, HINT_C_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_MOD_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_POW, HINT_NONE, VAR_T_VOID, \"vm_OP_POW\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_POW, HINT_C_NUM_CONSTANT, VAR_T_VOID, \"vm_OP_POW_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_UNM, HINT_NONE, VAR_T_VOID, \"vm_OP_UNM\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_NOT, HINT_NONE, VAR_T_VOID, \"vm_OP_NOT\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_LEN, HINT_NONE, VAR_T_VOID, \"vm_OP_LEN\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_CONCAT, HINT_NONE, VAR_T_VOID, \"vm_OP_CONCAT\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_JMP, HINT_NONE, VAR_T_VOID, \"vm_OP_JMP\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_sBx, VAR_T_VOID},\n  },\n  { OP_EQ, HINT_NONE, VAR_T_INT, \"vm_OP_EQ\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_EQ, HINT_C_NUM_CONSTANT, VAR_T_INT, \"vm_OP_EQ_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_VOID},\n  },\n  { OP_EQ, HINT_C_NUM_CONSTANT|HINT_NOT, VAR_T_INT, \"vm_OP_NOT_EQ_NC\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_B, VAR_T_ARG_C_NUM_CONSTANT, VAR_T_VOID},\n  },\n  { OP_LT, HINT_NONE, VAR_T_INT, \"vm_OP_LT\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_LE, HINT_NONE, VAR_T_INT, \"vm_OP_LE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_K, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_TEST, HINT_NONE, VAR_T_INT, \"vm_OP_TEST\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_TESTSET, HINT_NONE, VAR_T_INT, \"vm_OP_TESTSET\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_CALL, HINT_NONE, VAR_T_INT, \"vm_OP_CALL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_TAILCALL, HINT_NONE, VAR_T_INT, \"vm_OP_TAILCALL\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_RETURN, HINT_NONE, VAR_T_INT, \"vm_OP_RETURN\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_NONE, VAR_T_INT, \"vm_OP_FORLOOP\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_FOR_N_N, VAR_T_INT, \"vm_OP_FORLOOP_N_N\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_1, VAR_T_OP_VALUE_2, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_FOR_N_N_N, VAR_T_INT, \"vm_OP_FORLOOP_N_N_N\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_1, VAR_T_OP_VALUE_2, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_FOR_N_N_N | HINT_UP, VAR_T_INT, \"vm_OP_FORLOOP_up\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_1, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_FOR_N_N_N | HINT_DOWN, VAR_T_INT, \"vm_OP_FORLOOP_down\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_1, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_FOR_N_N_N | HINT_USE_LONG | HINT_UP, VAR_T_INT, \"vm_OP_FORLOOP_long_up\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_1, VAR_T_VOID},\n  },\n  { OP_FORLOOP, HINT_FOR_N_N_N | HINT_USE_LONG | HINT_DOWN, VAR_T_INT, \"vm_OP_FORLOOP_long_down\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_1, VAR_T_VOID},\n  },\n  { OP_FORPREP, HINT_NONE, VAR_T_VOID, \"vm_OP_FORPREP\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_VOID},\n  },\n  { OP_FORPREP, HINT_NO_SUB, VAR_T_VOID, \"vm_OP_FORPREP_no_sub\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_VOID},\n  },\n  { OP_FORPREP, HINT_FOR_M_N_N, VAR_T_VOID, \"vm_OP_FORPREP_M_N_N\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_1, VAR_T_OP_VALUE_2, VAR_T_VOID},\n  },\n  { OP_FORPREP, HINT_FOR_N_M_N, VAR_T_VOID, \"vm_OP_FORPREP_N_M_N\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_2, VAR_T_VOID},\n  },\n  { OP_FORPREP, HINT_FOR_N_N_N, VAR_T_VOID, \"vm_OP_FORPREP_N_N_N\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_sBx, VAR_T_OP_VALUE_0, VAR_T_OP_VALUE_2, VAR_T_VOID},\n  },\n  { OP_TFORLOOP, HINT_NONE, VAR_T_INT, \"vm_OP_TFORLOOP\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_C, VAR_T_VOID},\n  },\n  { OP_SETLIST, HINT_NONE, VAR_T_VOID, \"vm_OP_SETLIST\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_ARG_C_NEXT_INSTRUCTION, VAR_T_VOID},\n  },\n  { OP_CLOSE, HINT_NONE, VAR_T_VOID, \"vm_OP_CLOSE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_ARG_A, VAR_T_VOID},\n  },\n  { OP_CLOSURE, HINT_NONE, VAR_T_VOID, \"vm_OP_CLOSURE\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_CL, VAR_T_ARG_A, VAR_T_ARG_Bx, VAR_T_PC_OFFSET, VAR_T_VOID},\n  },\n  { OP_VARARG, HINT_NONE, VAR_T_VOID, \"vm_OP_VARARG\",\n    {VAR_T_LUA_STATE_PTR, VAR_T_CL, VAR_T_ARG_A, VAR_T_ARG_B, VAR_T_VOID},\n  },\n  { -1, HINT_NONE, VAR_T_VOID, NULL, {VAR_T_VOID} }\n};\n\nint vm_op_run_count[NUM_OPCODES];\n\nvoid vm_count_OP(const Instruction i) {\n  vm_op_run_count[GET_OPCODE(i)]++;\n}\n\nvoid vm_print_OP(lua_State *L, LClosure *cl, const Instruction i, int pc_offset) {\n  const Instruction *pc;\n  int op = GET_OPCODE(i);\n  int line = -1;\n  (void)L;\n  if(cl->p->sizelineinfo > pc_offset) {\n    line = cl->p->lineinfo[pc_offset];\n  }\n  if(pc_offset <= cl->p->sizecode) {\n    pc = cl->p->code + pc_offset;\n  } else {\n    pc = cl->p->code + cl->p->sizecode;\n  }\n  fprintf(stderr, \"%d: '%s' (%d) = 0x%08X, pc=%p, line=%d\\n\", pc_offset,\n    luaP_opnames[op], op, i, pc, line);\n  lua_assert(pc_offset == (pc - cl->p->code));\n  lua_assert(pc[0] == i);\n}\n\nvoid vm_next_OP(lua_State *L, LClosure *cl, int pc_offset) {\n  const Instruction *pc = cl->p->code;\n  /* calculate current pc. */\n  if(pc_offset <= cl->p->sizecode) {\n    pc += pc_offset;\n  }\n  pc++;\n  //vm_print_OP(L, cl, pc[0], pc_offset);\n  lua_assert(pc >= cl->p->code && (pc < &(cl->p->code[cl->p->sizecode])));\n  if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&\n      (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {\n    luaV_traceexec(L, pc);\n#if 0\n    if (L->status == LUA_YIELD) {  /* did hook yield? */\n      // TODO: fix hook yield\n      L->savedpc = pc - 1;\n      return;\n    }\n#endif\n  }\n  L->savedpc = pc;\n}\n\nint vm_OP_CALL(lua_State *L, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra=base + a;\n  int nresults = c - 1;\n  int ret;\n  if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n  ret = luaD_precall(L, ra, nresults);\n  switch (ret) {\n    case PCRLUA: {\n      luaV_execute(L, 1);\n      if (nresults >= 0) L->top = L->ci->top;\n      break;\n    }\n    case PCRC: {\n      /* it was a C function (`precall' called it); adjust results */\n      if (nresults >= 0) L->top = L->ci->top;\n      break;\n    }\n    default: {\n      /* TODO: fix yielding from C funtions, right now we can't resume a JIT with using COCO. */\n      return PCRYIELD;\n    }\n  }\n  return 0;\n}\n\nint vm_OP_RETURN(lua_State *L, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  if (b != 0) L->top = ra+b-1;\n  if (L->openupval) luaF_close(L, base);\n  b = luaD_poscall(L, ra);\n  return PCRC;\n}\n\nint vm_OP_TAILCALL(lua_State *L, int a, int b) {\n  TValue *func = L->base + a;\n  Closure *cl;\n  CallInfo *ci;\n  StkId st, cur_func;\n  Proto *p;\n  int aux;\n  int tail_recur;\n\n  if (b != 0) L->top = func+b;  /* else previous instruction set top */\n\n  /* current function index */\n  ci = L->ci;\n  cur_func = ci->func;\n  /* check for tail recursive call */\n  if(gcvalue(func) == gcvalue(cur_func)) {\n    cl = clvalue(func);\n    p = cl->l.p;\n    /* if is not a vararg function. */\n    tail_recur = !p->is_vararg;\n    L->savedpc = p->code;\n  } else {\n    tail_recur=0;\n    ci->savedpc = L->savedpc;\n    if (!ttisfunction(func)) /* `func' is not a function? */\n      func = luaD_tryfuncTM(L, func);  /* check the `function' tag method */\n    cl = clvalue(func);\n#ifndef NDEBUG\n    if(cl->l.isC) { /* can't tailcall into C functions.  Causes problems with getfenv() */\n      luaD_precall(L, func, LUA_MULTRET);\n      vm_OP_RETURN(L, a, 0);\n      return PCRC;\n    }\n#endif\n  }\n\n  /* clean up current frame to prepare to tailcall into next function. */\n  if (L->openupval) luaF_close(L, ci->base);\n  for (aux = 0; func+aux < L->top; aux++)  /* move frame down */\n    setobjs2s(L, cur_func+aux, func+aux);\n  L->top = cur_func+aux;\n  /* JIT function calling it's self. */\n  if(tail_recur) {\n    for (st = L->top; st < ci->top; st++)\n      setnilvalue(st);\n    return PCRTAILRECUR;\n  }\n  L->base = cur_func; /* point base at new function to call.  This is needed by luaD_precall. */\n  /* unwind stack back to luaD_precall */\n  return PCRTAILCALL;\n}\n\n/*\n * Notes: split function into two copies, one with number checks + (init - step) + jmp,\n * and the other with the same number checks + slow error throwing code.\n */\nvoid vm_OP_FORPREP_slow(lua_State *L, int a, int sbx) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  const TValue *init = ra;\n  const TValue *plimit = ra+1;\n  const TValue *pstep = ra+2;\n  (void)sbx;\n  if (!tonumber(init, ra))\n    luaG_runerror(L, LUA_QL(\"for\") \" initial value must be a number\");\n  else if (!tonumber(plimit, ra+1))\n    luaG_runerror(L, LUA_QL(\"for\") \" limit must be a number\");\n  else if (!tonumber(pstep, ra+2))\n    luaG_runerror(L, LUA_QL(\"for\") \" step must be a number\");\n}\n\nint vm_OP_TFORLOOP(lua_State *L, int a, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  StkId cb = ra + 3;  /* call base */\n  setobjs2s(L, cb+2, ra+2);\n  setobjs2s(L, cb+1, ra+1);\n  setobjs2s(L, cb, ra);\n  L->top = cb+3;  /* func. + 2 args (state and index) */\n  Protect(luaD_call(L, cb, c));\n  L->top = L->ci->top;\n  cb = base + a + 3;  /* previous call may change the stack */\n  if (!ttisnil(cb)) {  /* continue loop? */\n    setobjs2s(L, cb-1, cb);  /* save control variable */\n    dojump(GETARG_sBx(*L->savedpc));\n    return 1;\n  }\n  return 0;\n}\n\nvoid vm_OP_SETLIST(lua_State *L, int a, int b, int c) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  int last;\n  Table *h;\n  fixedstack(L);\n  if (b == 0) {\n    b = cast_int(L->top - ra) - 1;\n    L->top = L->ci->top;\n  }\n  runtime_check(L, ttistable(ra));\n  h = hvalue(ra);\n  last = ((c-1)*LFIELDS_PER_FLUSH) + b;\n  if (last > h->sizearray)  /* needs more space? */\n    luaH_resizearray(L, h, last);  /* pre-alloc it at once */\n  for (; b > 0; b--) {\n    TValue *val = ra+b;\n    setobj2t(L, luaH_setnum(L, h, last--), val);\n    luaC_barriert(L, h, val);\n  }\n  unfixedstack(L);\n}\n\nvoid vm_OP_CLOSURE(lua_State *L, LClosure *cl, int a, int bx, int pseudo_ops_offset) {\n  TValue *base = L->base;\n  const Instruction *pc;\n  TValue *ra = base + a;\n  Proto *p;\n  Closure *ncl;\n  int nup, j;\n\n  p = cl->p->p[bx];\n  pc=cl->p->code + pseudo_ops_offset;\n  nup = p->nups;\n  fixedstack(L);\n  ncl = luaF_newLclosure(L, nup, cl->env);\n  setclvalue(L, ra, ncl);\n  ncl->l.p = p;\n  for (j=0; j<nup; j++, pc++) {\n    if (GET_OPCODE(*pc) == OP_GETUPVAL)\n      ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];\n    else {\n      lua_assert(GET_OPCODE(*pc) == OP_MOVE);\n      ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));\n    }\n  }\n  unfixedstack(L);\n  luaC_checkGC(L);\n}\n\nvoid vm_OP_VARARG(lua_State *L, LClosure *cl, int a, int b) {\n  TValue *base = L->base;\n  TValue *ra = base + a;\n  int j;\n  CallInfo *ci = L->ci;\n  int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;\n  b -= 1;\n  if (b == LUA_MULTRET) {\n    Protect(luaD_checkstack(L, n));\n    ra = base + a;  /* previous call may change the stack */\n    b = n;\n    L->top = ra + n;\n  }\n  for (j = 0; j < b; j++) {\n    if (j < n) {\n      setobjs2s(L, ra + j, ci->base - n + j);\n    }\n    else {\n      setnilvalue(ra + j);\n    }\n  }\n}\n\nint is_mini_vm_op(int opcode) {\n  switch (opcode) {\n    case OP_MOVE:\n    case OP_LOADK:\n    case OP_GETUPVAL:\n    case OP_SETUPVAL:\n    case OP_SETTABLE:\n      return 1;\n    default:\n      return 0;\n  }\n  return 0;\n}\n\n/*\n * This function is used to update the local variable type hints.\n *\n */\nvoid vm_op_hint_locals(char *locals, int stacksize, TValue *k, const Instruction i) {\n  int ra,rb,rc;\n  char ra_type = LUA_TNONE;\n\n#define reset_local() memset(locals, LUA_TNONE, stacksize * sizeof(char))\n#define RK_TYPE(rk) (ISK(rk) ? ttype(k+INDEXK(rk)) : locals[rk])\n  // make sure ra is a valid local register.\n  switch (GET_OPCODE(i)) {\n    case OP_MOVE:\n      rb = GETARG_B(i);\n      ra_type = locals[rb];\n      break;\n    case OP_LOADK:\n      rb = GETARG_Bx(i);\n      ra_type = ttype(k + rb);\n      break;\n    case OP_LOADBOOL:\n      if (GETARG_C(i)) {\n        reset_local(); // jmp, reset types.\n      } else {\n        ra_type = LUA_TBOOLEAN;\n      }\n      break;\n    case OP_LOADNIL:\n      ra = GETARG_A(i);\n      rb = GETARG_B(i);\n      do {\n        locals[rb--] = LUA_TNIL;\n      } while (rb >= ra);\n      return;\n    case OP_GETUPVAL:\n    case OP_GETGLOBAL:\n    case OP_GETTABLE:\n      // reset 'ra' type don't know type at compile-time.\n      break;\n    case OP_SETUPVAL:\n    case OP_SETGLOBAL:\n    case OP_SETTABLE:\n      // no changes to locals.\n      return;\n    case OP_NEWTABLE:\n      ra_type = LUA_TTABLE;\n      break;\n    case OP_SELF:\n      // 'ra + 1' will be a table.\n      ra = GETARG_A(i);\n      locals[ra + 1] = LUA_TTABLE;\n      // reset 'ra' type don't know type at compile-time.\n      break;\n    case OP_ADD:\n    case OP_SUB:\n    case OP_MUL:\n    case OP_DIV:\n    case OP_MOD:\n    case OP_POW:\n      // if 'b' & 'c' are numbers, then 'ra' will be a number\n      rb = GETARG_B(i);\n      rc = GETARG_C(i);\n      if(RK_TYPE(rb) == LUA_TNUMBER && RK_TYPE(rc) == LUA_TNUMBER) {\n        ra_type = LUA_TNUMBER;\n      }\n      break;\n    case OP_UNM:\n       // if 'b' is a number, then 'ra' will be a number\n      rb = GETARG_B(i);\n      if(RK_TYPE(rb) == LUA_TNUMBER) {\n        ra_type = LUA_TNUMBER;\n      }\n      break;\n    case OP_NOT:\n      ra_type = LUA_TBOOLEAN;\n      break;\n    case OP_LEN:\n      rb = GETARG_B(i);\n      switch (locals[rb]) {\n        case LUA_TTABLE:\n        case LUA_TSTRING:\n          ra_type = LUA_TNUMBER;\n          break;\n        default:\n          // 'ra' type unknown.\n          break;\n      }\n      break;\n    case OP_CONCAT:\n      rb = GETARG_B(i);\n      rc = GETARG_C(i);\n      // if all values 'rb' -> 'rc' are strings/numbers then 'ra' will be a string.\n      ra_type = LUA_TSTRING;\n      while(rb <= rc) {\n        if(locals[rb] != LUA_TNUMBER && locals[rb] != LUA_TSTRING) {\n          // we don't know what type 'ra' will be.\n          ra_type = LUA_TNONE;\n          break;\n        }\n        rb++;\n      }\n      break;\n    case OP_JMP:\n    case OP_EQ:\n    case OP_LT:\n    case OP_LE:\n    case OP_TEST:\n    case OP_TESTSET:\n      reset_local(); // jmp, reset types.\n      break;\n    case OP_CALL:\n      ra = GETARG_A(i);\n      // just reset 'ra' -> top of the stack.\n      while(ra < stacksize) {\n        locals[ra++] = LUA_TNONE;\n      }\n      return;\n    case OP_TAILCALL:\n    case OP_RETURN:\n    case OP_FORLOOP:\n    case OP_FORPREP:\n    case OP_TFORLOOP:\n      reset_local();\n      return;\n    case OP_SETLIST:\n    case OP_CLOSE:\n      return;\n    case OP_CLOSURE:\n      ra_type = LUA_TFUNCTION;\n      break;\n    case OP_VARARG:\n      ra = GETARG_A(i);\n      rb = ra + GETARG_B(i) - 1;\n      // reset type for 'ra' -> 'ra + rb - 1'\n      while(ra <= rb) {\n        locals[ra++] = LUA_TNONE;\n      }\n      return;\n    default:\n      return;\n  }\n  ra = GETARG_A(i);\n}\n\nvoid vm_mini_vm(lua_State *L, LClosure *cl, int count, int pseudo_ops_offset) {\n  const Instruction *pc;\n  StkId base;\n  TValue *k;\n\n  k = cl->p->k;\n  pc = cl->p->code + pseudo_ops_offset;\n  base = L->base;\n  /* process next 'count' ops */\n  for (; count > 0; count--) {\n    const Instruction i = *pc++;\n    StkId ra = RA(i);\n    lua_assert(base == L->base && L->base == L->ci->base);\n    lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);\n    lua_assert(L->top == L->ci->top || luaG_checkopenop(i));\n    switch (GET_OPCODE(i)) {\n      case OP_MOVE: {\n        setobjs2s(L, ra, RB(i));\n        continue;\n      }\n      case OP_LOADK: {\n        setobj2s(L, ra, KBx(i));\n        continue;\n      }\n      case OP_GETUPVAL: {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        continue;\n      }\n      case OP_SETUPVAL: {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_barrier(L, uv, ra);\n        continue;\n      }\n      case OP_SETTABLE: {\n        Protect(luaV_settable(L, ra, RKB(i), RKC(i)));\n        continue;\n      }\n      default: {\n        luaG_runerror(L, \"Bad opcode: opcode=%d\", GET_OPCODE(i));\n        continue;\n      }\n    }\n  }\n}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/no_jit.c",
    "content": "/*\n\n  Copyright (c) 2009 Robert G. Jakabosky\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the \"Software\"), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n  \n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n  \n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n\n  MIT License: http://www.opensource.org/licenses/mit-license.php\n*/\n\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"lua_core.h\"\n\n#include \"lua.h\"\n#include \"lobject.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n#define ENABLE_PARSER_HOOK 1\n#include \"hook_parser.c\"\n\n#ifndef UNUSED\n#define UNUSED(x) ((void)x)\n#endif\n\n/*\n * link against this file to use the Lua VM core without LLVM.\n * This will disable JIT support, but still allow loading static compiled Lua scripts.\n */\nvoid llvm_new_compiler(lua_State *L) {UNUSED(L);}\nvoid llvm_free_compiler(lua_State *L) {UNUSED(L);}\nvoid llvm_compiler_compile(lua_State *L, Proto *p) {UNUSED(L);UNUSED(p);}\nvoid llvm_compiler_compile_all(lua_State *L, Proto *p) {UNUSED(L);UNUSED(p);}\nvoid llvm_compiler_free(lua_State *L, Proto *p) {UNUSED(L);UNUSED(p);}\n\nvoid llvm_dumper_dump(const char *output, lua_State *L, Proto *p, int stripping) {UNUSED(L);UNUSED(p);UNUSED(output);UNUSED(stripping);}\n\n#ifdef __cplusplus\n}\n#endif\n\n"
  },
  {
    "path": "llvm-lua/run_tests.sh",
    "content": "#!/bin/sh\n#\n\nfor script in `ls tests/*.lua`; do\n\techo \"run test: $script\"\n\tllvm-lua -g -O0 $script >/dev/null || {\n\t\techo \"Failed to run: $script\"\n\t}\n\t#llvm-lua -g -O0 $script\n\t#lua $script\n\t#llvm-lua -O3 $script >/dev/null\ndone\n\n"
  },
  {
    "path": "llvm-lua/tests/NOTES",
    "content": "Some of these scripts are pieces from other scripts that have exposed bugs\nin past versions of llvm-lua.\n\nThese scripts are only used for regression testing.\n\n"
  },
  {
    "path": "llvm-lua/tests/add.lua",
    "content": "local a = \"1\" + 2\nlocal b = 1\nlocal c = 2\nlocal d = b + 2\nlocal e = 1 + c\nlocal f = b + c\nprint(a,b,c,d,e,f)\n"
  },
  {
    "path": "llvm-lua/tests/arg_test.lua",
    "content": "print(unpack(arg))\nlocal n = tonumber((arg and arg[1]) or 1)\nio.write(n,\"\\n\")\n"
  },
  {
    "path": "llvm-lua/tests/big_table.lua",
    "content": "local q = {\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3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coroutine tests\n\nlocal f\n\nassert(coroutine.running() == nil)\n\n\n-- tests for global environment\n\nlocal function foo (a)\n  setfenv(0, a)\n\tprint('yield')\n  coroutine.yield(getfenv())\n\tprint('getfenv(0)')\n  assert(getfenv(0) == a)\n\tprint('getfenv(1)')\n  assert(getfenv(1) == _G)\n\tprint('getfenv(loadstring)')\n\t----------------------------------------------------------\n\t-- NOTE: The call to 'loadstring' from a coroutine caused\n\t-- a stack overflow when the LLVM JIT tried to codegen\n\t-- the Lua code (in this case an empty function).\n\t-- \n\t-- For now we will disable the JIT compiler from running\n\t-- on a coroutine.\n\t-- TODO: Switch to a separate large cstack when needed.\n\t----------------------------------------------------------\n  assert(getfenv(loadstring\"\") == a)\n\tprint('getfenv()')\n  return getfenv()\nend\n\nf = coroutine.wrap(foo)\nlocal a = {print = print, tostring=tostring}\nassert(f(a) == _G)\nlocal a,b = pcall(f)\nprint(a,b)\nassert(a and b == _G)\n\n"
  },
  {
    "path": "llvm-lua/tests/dump.lua",
    "content": "local function test()\n\tlocal v=\"test\"\n\tlocal function test2()\n\t\tprint(v)\n\tend\n\ttest2()\n\treturn\nend\n\nlocal d=string.dump(test)\nio.write(d)\ntest()\n"
  },
  {
    "path": "llvm-lua/tests/for.lua",
    "content": "local n = tonumber((arg and arg[1]) or 1)\nlocal hash1={}\nfor i=0,10000 do\n    hash1[\"foo_\"..i] = i\n    hash1[i] = i\nend\nfor i=0,10000 do\nprint(i,hash1[i])\nend\nprint(hash1[\"foo_1\"], hash1[\"foo_9999\"])\n"
  },
  {
    "path": "llvm-lua/tests/hash2.lua",
    "content": "local n = tonumber((arg and arg[1]) or 1)\n\nlocal hash1={}\nfor i=0,10000 do\n    hash1[\"foo_\"..i] = i\nend\nlocal hash2={}\nfor i=1,n do\n    for k,v in pairs(hash1) do\n\thash2[k] = v + (hash2[k] or 0)\n    end\nend\n\nprint(hash1[\"foo_1\"], hash1[\"foo_9999\"],\n\t     hash2[\"foo_1\"], hash2[\"foo_9999\"])\n--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9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n}\n\treturn q\nend\n\nlocal N = tonumber(arg and arg[1]) or 1\n\nfor i=0,N do\n\ttest_loadk()\nend\n\nlocal t=test_loadk()\nprint(\"table size=\",#t)\n"
  },
  {
    "path": "llvm-lua/tests/local_nil.lua",
    "content": "--[[\nlocal function min_stack()\nend\nlocal function min_stack_params(a,b,c,d,e)\nend\nlocal function tail_recursive_nil(depth)\n\tlocal a,b,c,d,e\n\tprint(\"should be 5 nil values:\",a,b,c,d,e)\n\ta,b,c,d,e = 1,2,3,4,5\n\tif(depth == 0) then return a,b,c,d,e end\n\treturn tail_recursive_nil(depth - 1)\nend\nprint(tail_recursive_nil(2))\n]]\nlocal function test_nil()\n\tlocal a,b,c,d,e\n\treturn a,b,c,d,e\nend\nprint(test_nil())\n"
  },
  {
    "path": "llvm-lua/tests/loops.lua",
    "content": "\nlocal x = 0\nfor a=1,25 do\n\tx = x + 1\nend\nfor b=1,25 do\n\tx = x + 1\nend\nfor c=1,25 do\n\tx = x + 1\nend\nfor d=1,25 do\n\tx = x + 1\nend\nfor e=1,25 do\n\tx = x + 1\nend\nfor f=1,25 do\n\tx = x + 1\nend\n--print(a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f,\",\",x,\"\\n\")\nio.write(x,\"\\n\")\n"
  },
  {
    "path": "llvm-lua/tests/lua_tail.lua",
    "content": "local function lua_tail()\nlocal q = {\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,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2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,\n}\n\treturn q\nend\nlocal function jit_tailcaller()\n\treturn lua_tail()\nend\nlocal a = jit_tailcaller()\nprint(\"table size=\",#a)\n"
  },
  {
    "path": "llvm-lua/tests/nestedloop.lua",
    "content": "local x = 0\nlocal x2 = 0\nfor a=1,25 do\n\tfor b=1,25 do\n\t\tfor c=1,25 do\n\t\t\tfor d=1,25 do\n\t\t\t\tfor e=1,25 do\n\t\t\t\t\tfor f=1,25 do\n--io.write(a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f,\",\",x,\"\\n\")\n\t\t\t\t\t\tx = x + 1\n\t\t\t\t\t\tx2 = x2 + a + b + c + d + e + f\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n--print(a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f,\",\",x,\"\\n\")\nio.write(x,\"\\n\")\nio.write(x2,\"\\n\")\n"
  },
  {
    "path": "llvm-lua/tests/nestedloop2.lua",
    "content": "local x = 0\nfor a=25,1,-1 do\n\tfor b=25,1,-1 do\n\t\tfor c=25,1,-1 do\n\t\t\tfor d=25,1,-1 do\n\t\t\t\tfor e=25,1,-1 do\n\t\t\t\t\tfor f=25,1,-1 do\n--io.write(a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f,\",\",x,\"\\n\")\n\t\t\t\t\t\tx = x + 1\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\nprint(a,\",\",b,\",\",c,\",\",d,\",\",e,\",\",f,\",\",x,\"\\n\")\nio.write(x,\"\\n\")\n"
  },
  {
    "path": "llvm-lua/tests/nums.lua",
    "content": "local a=5\nlocal b=6\nlocal c=7\nlocal d=8\na = a + 9\nb = b - 10\nc = c * 11\nd = d / 12\nprint(a,b,c,d)\n"
  },
  {
    "path": "llvm-lua/tests/scimark_loop.lua",
    "content": "\nlocal n = 100\nlocal test = function()\n\t\tfor i=1,n*2 do\nprint(i)\n\t\tend\nend\n\ntest(100)\n\n"
  },
  {
    "path": "llvm-lua/tests/scimark_rand.lua",
    "content": "--\n-- This script dies at the assert if compiled using the following commands:\n-- 1. llvm-luac -O0 -no-main -bc -o scimark_rand.bc scimark_rand.lua\n-- 2. opt -O2 -f -o scimark_rand_opt.bc scimark_rand.bc\n-- 3. llc --march=c -f -o scimark_rand.c scimark_rand_opt.bc\n-- 4. gcc -O3 -o scimark_rand scimark_rand.c ../liblua_main.a -lm -ld\n--\n-- Compiled on x86_64 Gentoo linux host.\n--\n-- If the optimization levels for 'opt' or 'gcc' are lowered then this script will run correctly.\n-- Seems to expose a bug in LLVM or GCC or both.\n--\n\nlocal Rj = 17\nlocal function rand()\n  local j = 17\n  if 17 < 17 then\n\t\tRj = j + 1\n\telse\n\t\tRj = 1\nprint(\"Rj\", Rj)\nassert(Rj == 1)\n\tend\nend\n\nrand()\n\n"
  },
  {
    "path": "llvm-lua/tests/stress_for.lua",
    "content": "local width = 100\nlocal xb = 50\nlocal a = 0\n\nfor x=0, xb < width and 10 or 20 do\n\ta = a + 1\nend\n\nfor x=xb < width and 10 or 20,0,-1 do\n\ta = a + 1\nend\n\nprint(\"a=\", a)\n\n"
  },
  {
    "path": "llvm-lua/tests/test.lua",
    "content": "\nlocal i\nlocal count=0\n\nfor i=1,100000000 do\n\tcount = count + 1\nend\n\nprint(count)\n"
  },
  {
    "path": "llvm-lua/tests/test2.lua",
    "content": "function f(x,y,z)\n        print(\"hook\",x,y,z)\nend\n\nfunction g()\n        print\"0\"\n        debug.sethook(f,\"l\")\n        print\"1\"\n        print\"2\"\n        print\"3\"\n        print\"4\"\nend\n\nprint(\"pcall\",pcall(g))\n\n"
  },
  {
    "path": "llvm-lua/tests/test3.lua",
    "content": "debug.sethook(function(e,l,x) print(e,l,x) end, \"l\")\n\n-- very inefficient fibonacci function\nfunction fib(n)\n\tN=N+1\n\tif n<2 then\n\t\treturn n\n\telse\n\t\treturn fib(n-1)+fib(n-2)\n\tend\nend\n\n-- run and time it\nfunction test(s,f)\n\tN=0\n\tlocal c=os.clock()\n\tlocal v=f(n)\n\tlocal t=os.clock()-c\n\tprint(s,n,v,t,N)\nend\n\nn=arg[1] or 24\t\t-- for other values, do lua fib.lua XX\nn=tonumber(n)\nprint(\"\",\"n\",\"value\",\"time\",\"evals\")\ntest(\"plain\",fib)\n\n"
  },
  {
    "path": "llvm-lua/tests/test4.lua",
    "content": "local a = 1\nlocal b = 2\nlocal c\nif a > b then\n\tc = a\nelse\n\tc = b\nend\nprint(c)\n"
  },
  {
    "path": "llvm-lua/tests/test_lineerror.lua",
    "content": "-- testing line error\n\nfunction lineerror (s)\n  local err,msg = pcall(loadstring(s))\n  local line = string.match(msg, \":(%d+):\")\n  print(err,msg,line,X)\n  return line and line+0\nend\n\nassert(lineerror\"local a\\n for i=1,'a' do \\n print(i) \\n end\" == 2)\nassert(lineerror\"\\n local a \\n for k,v in 3 \\n do \\n print(k) \\n end\" == 3)\nassert(lineerror\"\\n\\n for k,v in \\n 3 \\n do \\n print(k) \\n end\" == 4)\nassert(lineerror\"function a.x.y ()\\na=a+1\\nend\" == 1)\n\nlocal p = [[\nfunction g() f() end\nfunction f(x) error('a', X) end\ng()\n]]\nX=3;assert(lineerror(p) == 3)\nX=0;assert(lineerror(p) == nil)\nX=1;assert(lineerror(p) == 2)\nX=2;assert(lineerror(p) == 1)\n\n"
  },
  {
    "path": "llvm-lua/tests/test_math.lua",
    "content": "\nlocal sqrt=math.sqrt\nlocal a\n\nfor n=1,1000000 do\n--for n=1,10000 do\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\n\ta=sqrt(9)\nend\n\nprint(\"a=\",a)\nprint(\"pow(3,3)=\", math.pow(3,2))\nprint(\"abs(-3.6)=\", math.abs(-3.6))\n\n-- test tailcall of math.* function\nlocal function floor(num)\n\treturn math.floor(num)\nend\n\nprint(\"floor(1.2345)=\", floor(1.2345))\n\n"
  },
  {
    "path": "llvm-lua/tests/test_tail.lua",
    "content": "local function tail(depth)\n\tif(depth > 0) then\n\t\treturn tail(depth - 1)\n\tend\n\treturn 0\nend\n\nlocal N = tonumber(arg and arg[1]) or 1\nprint(tail(N))\n\nlocal function tail_math()\n  -- tail call\n\treturn math.sin(\"a\")\nend\n\ntail_math()\n\n"
  },
  {
    "path": "llvm-lua/tests/test_tail_nil_multret.lua",
    "content": "do\n\tlocal f = function(n)\n\t\tlocal x = {}\n\t\tfor i=1,n do\n\t\t\tx[i] = i\n\t\tend\n\t\treturn unpack(x)\n\tend\n\n\tlocal a,b,c\n\ta,b,c = 0,5,f(0)\n\tprint(\"a,b,c\", a, b, c)\n\tassert(a==0 and b==5 and c==nil)\n\ta={f(0)}\n\tprint(\"#a = \", #a)\n\tprint(\"a = \", unpack(a))\nend\n"
  },
  {
    "path": "llvm-lua/tests/test_varg_tail2.lua",
    "content": "function tail_cfunc(...)\n\tlocal s = string.format(...)\n\treturn print(s)\nend\n\nprint(tail_cfunc(\"this is a test: %s %s %s %s\",\"1\",\"2\",\"3\",\"4\"))\n\n"
  },
  {
    "path": "src/lapi.c",
    "content": "/*\n** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $\n** Lua API\n** See Copyright Notice in lua.h\n*/\n\n\n#include <assert.h>\n#include <math.h>\n#include <stdarg.h>\n#include <string.h>\n\n#define lapi_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n\n\n\nconst char lua_ident[] =\n  \"$Lua: \" LUA_RELEASE \" \" LUA_COPYRIGHT \" $\\n\"\n  \"$Authors: \" LUA_AUTHORS \" $\\n\"\n  \"$URL: www.lua.org $\\n\";\n\n\n\n#define api_checknelems(L, n)\tapi_check(L, (n) <= (L->top - L->base))\n\n#define api_checkvalidindex(L, i)\tapi_check(L, (i) != luaO_nilobject)\n\n#define api_incr_top(L)   {api_check(L, L->top < L->ci->top); L->top++;}\n\n\n\nstatic TValue *index2adr (lua_State *L, int idx) {\n  if (idx > 0) {\n    TValue *o = L->base + (idx - 1);\n    api_check(L, idx <= L->ci->top - L->base);\n    if (o >= L->top) return cast(TValue *, luaO_nilobject);\n    else return o;\n  }\n  else if (idx > LUA_REGISTRYINDEX) {\n    api_check(L, idx != 0 && -idx <= L->top - L->base);\n    return L->top + idx;\n  }\n  else switch (idx) {  /* pseudo-indices */\n    case LUA_REGISTRYINDEX: return registry(L);\n    case LUA_ENVIRONINDEX: {\n      Closure *func = curr_func(L);\n      sethvalue(L, &L->env, func->c.env);\n      return &L->env;\n    }\n    case LUA_GLOBALSINDEX: return gt(L);\n    default: {\n      Closure *func = curr_func(L);\n      idx = LUA_GLOBALSINDEX - idx;\n      return (idx <= func->c.nupvalues)\n                ? &func->c.upvalue[idx-1]\n                : cast(TValue *, luaO_nilobject);\n    }\n  }\n}\n\n\nstatic Table *getcurrenv (lua_State *L) {\n  if (L->ci == L->base_ci)  /* no enclosing function? */\n    return hvalue(gt(L));  /* use global table as environment */\n  else {\n    Closure *func = curr_func(L);\n    return func->c.env;\n  }\n}\n\n\nvoid luaA_pushobject (lua_State *L, const TValue *o) {\n  setobj2s(L, L->top, o);\n  api_incr_top(L);\n}\n\n\nLUA_API int lua_checkstack (lua_State *L, int size) {\n  int res = 1;\n  lua_lock(L);\n  if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)\n    res = 0;  /* stack overflow */\n  else if (size > 0) {\n    luaD_checkstack(L, size);\n    if (L->ci->top < L->top + size)\n      L->ci->top = L->top + size;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {\n  StkId f, t;\n  if (from == to) return;\n  lua_lock(to);\n  api_checknelems(from, n);\n  api_check(from, G(from) == G(to));\n  api_check(from, to->ci->top - to->top >= n);\n  f = from->top;\n  t = to->top = to->top + n;\n  while (--n >= 0) setobj2s(to, --t, --f);\n  from->top = f;\n  lua_unlock(to);\n}\n\n\nLUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {\n  lua_CFunction old;\n  lua_lock(L);\n  old = G(L)->panic;\n  G(L)->panic = panicf;\n  lua_unlock(L);\n  return old;\n}\n\n\nLUA_API lua_State *lua_newthread (lua_State *L) {\n  lua_State *L1;\n  lua_lock(L);\n  luaC_checkGC(L);\n  L1 = luaE_newthread(L);\n  setthvalue(L, L->top, L1);\n  api_incr_top(L);\n  lua_unlock(L);\n  luai_userstatethread(L, L1);\n  return L1;\n}\n\n\n\n/*\n** basic stack manipulation\n*/\n\n\nLUA_API int lua_gettop (lua_State *L) {\n  return cast_int(L->top - L->base);\n}\n\n\nLUA_API void lua_settop (lua_State *L, int idx) {\n  lua_lock(L);\n  if (idx >= 0) {\n    api_check(L, idx <= L->stack_last - L->base);\n    while (L->top < L->base + idx)\n      setnilvalue(L->top++);\n    L->top = L->base + idx;\n  }\n  else {\n    api_check(L, -(idx+1) <= (L->top - L->base));\n    L->top += idx+1;  /* `subtract' index (index is negative) */\n  }\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_remove (lua_State *L, int idx) {\n  StkId p;\n  lua_lock(L);\n  p = index2adr(L, idx);\n  api_checkvalidindex(L, p);\n  while (++p < L->top) setobjs2s(L, p-1, p);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_insert (lua_State *L, int idx) {\n  StkId p;\n  StkId q;\n  lua_lock(L);\n  p = index2adr(L, idx);\n  api_checkvalidindex(L, p);\n  for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);\n  setobjs2s(L, p, L->top);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_replace (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  /* explicit test for incompatible code */\n  if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci)\n    luaG_runerror(L, \"no calling environment\");\n  api_checknelems(L, 1);\n  o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  if (idx == LUA_ENVIRONINDEX) {\n    Closure *func = curr_func(L);\n    api_check(L, ttistable(L->top - 1)); \n    func->c.env = hvalue(L->top - 1);\n    luaC_barrier(L, func, L->top - 1);\n  }\n  else {\n    setobj(L, o, L->top - 1);\n    if (idx < LUA_GLOBALSINDEX)  /* function upvalue? */\n      luaC_barrier(L, curr_func(L), L->top - 1);\n  }\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushvalue (lua_State *L, int idx) {\n  lua_lock(L);\n  setobj2s(L, L->top, index2adr(L, idx));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n\n/*\n** access functions (stack -> C)\n*/\n\n\nLUA_API int lua_type (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);\n}\n\n\nLUA_API const char *lua_typename (lua_State *L, int t) {\n  UNUSED(L);\n  return (t == LUA_TNONE) ? \"no value\" : luaT_typenames[t];\n}\n\n\nLUA_API int lua_iscfunction (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return iscfunction(o);\n}\n\n\nLUA_API int lua_isnumber (lua_State *L, int idx) {\n  TValue n;\n  const TValue *o = index2adr(L, idx);\n  return tonumber(o, &n);\n}\n\n\nLUA_API int lua_isstring (lua_State *L, int idx) {\n  int t = lua_type(L, idx);\n  return (t == LUA_TSTRING || t == LUA_TNUMBER);\n}\n\n\nLUA_API int lua_isuserdata (lua_State *L, int idx) {\n  const TValue *o = index2adr(L, idx);\n  return (ttisuserdata(o) || ttislightuserdata(o));\n}\n\n\nLUA_API int lua_rawequal (lua_State *L, int index1, int index2) {\n  StkId o1 = index2adr(L, index1);\n  StkId o2 = index2adr(L, index2);\n  return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0\n         : luaO_rawequalObj(o1, o2);\n}\n\n\nLUA_API int lua_equal (lua_State *L, int index1, int index2) {\n  StkId o1, o2;\n  int i;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2adr(L, index1);\n  o2 = index2adr(L, index2);\n  i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2);\n  lua_unlock(L);\n  return i;\n}\n\n\nLUA_API int lua_lessthan (lua_State *L, int index1, int index2) {\n  StkId o1, o2;\n  int i;\n  lua_lock(L);  /* may call tag method */\n  o1 = index2adr(L, index1);\n  o2 = index2adr(L, index2);\n  i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0\n       : luaV_lessthan(L, o1, o2);\n  lua_unlock(L);\n  return i;\n}\n\n\n\nLUA_API lua_Number lua_tonumber (lua_State *L, int idx) {\n  TValue n;\n  const TValue *o = index2adr(L, idx);\n  if (tonumber(o, &n))\n    return nvalue(o);\n  else\n    return 0;\n}\n\n\nLUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {\n  TValue n;\n  const TValue *o = index2adr(L, idx);\n  if (tonumber(o, &n)) {\n    lua_Integer res;\n    lua_Number num = nvalue(o);\n    lua_number2integer(res, num);\n    return res;\n  }\n  else\n    return 0;\n}\n\n\nLUA_API int lua_toboolean (lua_State *L, int idx) {\n  const TValue *o = index2adr(L, idx);\n  return !l_isfalse(o);\n}\n\n\nLUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {\n  StkId o = index2adr(L, idx);\n  if (!ttisstring(o)) {\n    lua_lock(L);  /* `luaV_tostring' may create a new string */\n    if (!luaV_tostring(L, o)) {  /* conversion failed? */\n      if (len != NULL) *len = 0;\n      lua_unlock(L);\n      return NULL;\n    }\n    luaC_checkGC(L);\n    o = index2adr(L, idx);  /* previous call may reallocate the stack */\n    lua_unlock(L);\n  }\n  if (len != NULL) *len = tsvalue(o)->len;\n  return svalue(o);\n}\n\n\nLUA_API size_t lua_objlen (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TSTRING: return tsvalue(o)->len;\n    case LUA_TUSERDATA: return uvalue(o)->len;\n    case LUA_TTABLE: return luaH_getn(hvalue(o));\n    case LUA_TNUMBER: {\n      size_t l;\n      lua_lock(L);  /* `luaV_tostring' may create a new string */\n      l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);\n      lua_unlock(L);\n      return l;\n    }\n    default: return 0;\n  }\n}\n\n\nLUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return (!iscfunction(o)) ? NULL : clvalue(o)->c.f;\n}\n\n\nLUA_API void *lua_touserdata (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TUSERDATA: return (rawuvalue(o) + 1);\n    case LUA_TLIGHTUSERDATA: return pvalue(o);\n    default: return NULL;\n  }\n}\n\n\nLUA_API lua_State *lua_tothread (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  return (!ttisthread(o)) ? NULL : thvalue(o);\n}\n\n\nLUA_API const void *lua_topointer (lua_State *L, int idx) {\n  StkId o = index2adr(L, idx);\n  switch (ttype(o)) {\n    case LUA_TTABLE: return hvalue(o);\n    case LUA_TFUNCTION: return clvalue(o);\n    case LUA_TTHREAD: return thvalue(o);\n    case LUA_TUSERDATA:\n    case LUA_TLIGHTUSERDATA:\n      return lua_touserdata(L, idx);\n    default: return NULL;\n  }\n}\n\n\n\n/*\n** push functions (C -> stack)\n*/\n\n\nLUA_API void lua_pushnil (lua_State *L) {\n  lua_lock(L);\n  setnilvalue(L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushnumber (lua_State *L, lua_Number n) {\n  lua_lock(L);\n  setnvalue(L->top, n);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {\n  lua_lock(L);\n  setnvalue(L->top, cast_num(n));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {\n  lua_lock(L);\n  luaC_checkGC(L);\n  setsvalue2s(L, L->top, luaS_newlstr(L, s, len));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushstring (lua_State *L, const char *s) {\n  if (s == NULL)\n    lua_pushnil(L);\n  else\n    lua_pushlstring(L, s, strlen(s));\n}\n\n\nLUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,\n                                      va_list argp) {\n  const char *ret;\n  lua_lock(L);\n  luaC_checkGC(L);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *ret;\n  va_list argp;\n  lua_lock(L);\n  luaC_checkGC(L);\n  va_start(argp, fmt);\n  ret = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_unlock(L);\n  return ret;\n}\n\n\nLUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {\n  Closure *cl;\n  lua_lock(L);\n  luaC_checkGC(L);\n  api_checknelems(L, n);\n  cl = luaF_newCclosure(L, n, getcurrenv(L));\n  cl->c.f = fn;\n  L->top -= n;\n  while (n--)\n    setobj2n(L, &cl->c.upvalue[n], L->top+n);\n  setclvalue(L, L->top, cl);\n  lua_assert(iswhite(obj2gco(cl)));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushboolean (lua_State *L, int b) {\n  lua_lock(L);\n  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_pushlightuserdata (lua_State *L, const void *p) {\n\tunion {const void *c_p; void *p;} ptr;\n\tptr.c_p = p; /* cast \"const void *\" to \"void *\" without compiler warning. */\n  lua_lock(L);\n  setpvalue(L->top, ptr.p);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_pushthread (lua_State *L) {\n  lua_lock(L);\n  setthvalue(L, L->top, L);\n  api_incr_top(L);\n  lua_unlock(L);\n  return (G(L)->mainthread == L);\n}\n\n\n\n/*\n** get functions (Lua -> stack)\n*/\n\n\nLUA_API void lua_gettable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  luaV_gettable(L, t, L->top - 1, L->top - 1);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_getfield (lua_State *L, int idx, const char *k) {\n  StkId t;\n  TValue key;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  fixedstack(L);\n  setsvalue(L, &key, luaS_new(L, k));\n  unfixedstack(L);\n  luaV_gettable(L, t, &key, L->top);\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawget (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_check(L, ttistable(t));\n  setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawgeti (lua_State *L, int idx, int n) {\n  StkId o;\n  lua_lock(L);\n  o = index2adr(L, idx);\n  api_check(L, ttistable(o));\n  setobj2s(L, L->top, luaH_getnum(hvalue(o), n));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_createtable (lua_State *L, int narray, int nrec) {\n  lua_lock(L);\n  luaC_checkGC(L);\n  sethvalue(L, L->top, luaH_new(L, narray, nrec));\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_getmetatable (lua_State *L, int objindex) {\n  const TValue *obj;\n  Table *mt = NULL;\n  int res;\n  lua_lock(L);\n  obj = index2adr(L, objindex);\n  switch (ttype(obj)) {\n    case LUA_TTABLE:\n      mt = hvalue(obj)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(obj)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttype(obj)];\n      break;\n  }\n  if (mt == NULL)\n    res = 0;\n  else {\n    sethvalue(L, L->top, mt);\n    api_incr_top(L);\n    res = 1;\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\nLUA_API void lua_getfenv (lua_State *L, int idx) {\n  StkId o;\n  lua_lock(L);\n  o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  switch (ttype(o)) {\n    case LUA_TFUNCTION:\n      sethvalue(L, L->top, clvalue(o)->c.env);\n      break;\n    case LUA_TUSERDATA:\n      sethvalue(L, L->top, uvalue(o)->env);\n      break;\n    case LUA_TTHREAD:\n      setobj2s(L, L->top,  gt(thvalue(o)));\n      break;\n    default:\n      setnilvalue(L->top);\n      break;\n  }\n  api_incr_top(L);\n  lua_unlock(L);\n}\n\n\n/*\n** set functions (stack -> Lua)\n*/\n\n\nLUA_API void lua_settable (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  luaV_settable(L, t, L->top - 2, L->top - 1);\n  L->top -= 2;  /* pop index and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_setfield (lua_State *L, int idx, const char *k) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  t = index2adr(L, idx);\n  api_checkvalidindex(L, t);\n  setsvalue2s(L, L->top, luaS_new(L, k));\n  api_incr_top(L);\n  luaV_settable(L, t, L->top - 1, L->top - 2);\n  L->top -= 2;  /* pop key and value */\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawset (lua_State *L, int idx) {\n  StkId t;\n  lua_lock(L);\n  api_checknelems(L, 2);\n  t = index2adr(L, idx);\n  api_check(L, ttistable(t));\n  fixedstack(L);\n  setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);\n  unfixedstack(L);\n  luaC_barriert(L, hvalue(t), L->top-1);\n  L->top -= 2;\n  lua_unlock(L);\n}\n\n\nLUA_API void lua_rawseti (lua_State *L, int idx, int n) {\n  StkId o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2adr(L, idx);\n  api_check(L, ttistable(o));\n  fixedstack(L);\n  setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);\n  unfixedstack(L);\n  luaC_barriert(L, hvalue(o), L->top-1);\n  L->top--;\n  lua_unlock(L);\n}\n\n\nLUA_API int lua_setmetatable (lua_State *L, int objindex) {\n  TValue *obj;\n  Table *mt;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  obj = index2adr(L, objindex);\n  api_checkvalidindex(L, obj);\n  if (ttisnil(L->top - 1))\n    mt = NULL;\n  else {\n    api_check(L, ttistable(L->top - 1));\n    mt = hvalue(L->top - 1);\n  }\n  switch (ttype(obj)) {\n    case LUA_TTABLE: {\n      hvalue(obj)->metatable = mt;\n      if (mt)\n        luaC_objbarriert(L, hvalue(obj), mt);\n      break;\n    }\n    case LUA_TUSERDATA: {\n      uvalue(obj)->metatable = mt;\n      if (mt)\n        luaC_objbarrier(L, rawuvalue(obj), mt);\n      break;\n    }\n    default: {\n      G(L)->mt[ttype(obj)] = mt;\n      break;\n    }\n  }\n  L->top--;\n  lua_unlock(L);\n  return 1;\n}\n\n\nLUA_API int lua_setfenv (lua_State *L, int idx) {\n  StkId o;\n  int res = 1;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = index2adr(L, idx);\n  api_checkvalidindex(L, o);\n  api_check(L, ttistable(L->top - 1));\n  switch (ttype(o)) {\n    case LUA_TFUNCTION:\n      clvalue(o)->c.env = hvalue(L->top - 1);\n      break;\n    case LUA_TUSERDATA:\n      uvalue(o)->env = hvalue(L->top - 1);\n      break;\n    case LUA_TTHREAD:\n      sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1));\n      break;\n    default:\n      res = 0;\n      break;\n  }\n  if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));\n  L->top--;\n  lua_unlock(L);\n  return res;\n}\n\n\n/*\n** `load' and `call' functions (run Lua code)\n*/\n\n\n#define adjustresults(L,nres) \\\n    { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }\n\n\n#define checkresults(L,na,nr) \\\n     api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)))\n\t\n\nLUA_API void lua_call (lua_State *L, int nargs, int nresults) {\n  StkId func;\n  lua_lock(L);\n  api_checknelems(L, nargs+1);\n  checkresults(L, nargs, nresults);\n  func = L->top - (nargs+1);\n  luaD_call(L, func, nresults);\n  adjustresults(L, nresults);\n  lua_unlock(L);\n}\n\n\n\n/*\n** Execute a protected call.\n*/\nstruct CallS {  /* data to `f_call' */\n  StkId func;\n  int nresults;\n};\n\n\nstatic void f_call (lua_State *L, void *ud) {\n  struct CallS *c = cast(struct CallS *, ud);\n  luaD_call(L, c->func, c->nresults);\n}\n\n\n\nLUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {\n  struct CallS c;\n  int status;\n  ptrdiff_t func;\n  lua_lock(L);\n  api_checknelems(L, nargs+1);\n  checkresults(L, nargs, nresults);\n  if (errfunc == 0)\n    func = 0;\n  else {\n    StkId o = index2adr(L, errfunc);\n    api_checkvalidindex(L, o);\n    func = savestack(L, o);\n  }\n  c.func = L->top - (nargs+1);  /* function to be called */\n  c.nresults = nresults;\n  status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);\n  adjustresults(L, nresults);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** Execute a protected C call.\n*/\nstruct CCallS {  /* data to `f_Ccall' */\n  lua_CFunction func;\n  void *ud;\n};\n\n\nstatic void f_Ccall (lua_State *L, void *ud) {\n  struct CCallS *c = cast(struct CCallS *, ud);\n  Closure *cl;\n  cl = luaF_newCclosure(L, 0, getcurrenv(L));\n  cl->c.f = c->func;\n  setclvalue(L, L->top, cl);  /* push function */\n  api_incr_top(L);\n  setpvalue(L->top, c->ud);  /* push only argument */\n  api_incr_top(L);\n  luaD_call(L, L->top - 2, 0);\n}\n\n\nLUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {\n  struct CCallS c;\n  int status;\n  lua_lock(L);\n  c.func = func;\n  c.ud = ud;\n  status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,\n                      const char *chunkname) {\n  ZIO z;\n  int status;\n  lua_lock(L);\n  if (!chunkname) chunkname = \"?\";\n  luaZ_init(L, &z, reader, data);\n  status = luaD_protectedparser(L, &z, chunkname);\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) {\n  int status;\n  TValue *o;\n  lua_lock(L);\n  api_checknelems(L, 1);\n  o = L->top - 1;\n  if (isLfunction(o))\n    status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);\n  else\n    status = 1;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int  lua_status (lua_State *L) {\n  return L->status;\n}\n\n\n/*\n** Garbage-collection function\n*/\n\nLUA_API int lua_gc (lua_State *L, int what, int data) {\n  int res = 0;\n  global_State *g;\n  lua_lock(L);\n  g = G(L);\n  switch (what) {\n    case LUA_GCSTOP: {\n      set_block_gc(L);\n      break;\n    }\n    case LUA_GCRESTART: {\n      unset_block_gc(L);\n      break;\n    }\n    case LUA_GCCOLLECT: {\n      luaC_fullgc(L);\n      break;\n    }\n    case LUA_GCCOUNT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      res = cast_int(g->totalbytes >> 10);\n      break;\n    }\n    case LUA_GCCOUNTB: {\n      res = cast_int(g->totalbytes & 0x3ff);\n      break;\n    }\n    case LUA_GCSTEP: {\n      if(is_block_gc(L)) {\n        res = 1; /* gc is block so we need to pretend that the collection cycle finished. */\n        break;\n      }\n      lu_mem a = (cast(lu_mem, data) << 10);\n      if (a <= g->totalbytes)\n        g->GCthreshold = g->totalbytes - a;\n      else\n        g->GCthreshold = 0;\n      while (g->GCthreshold <= g->totalbytes) {\n        luaC_step(L);\n        if (g->gcstate == GCSpause) {  /* end of cycle? */\n          res = 1;  /* signal it */\n          break;\n        }\n      }\n      break;\n    }\n    case LUA_GCSETPAUSE: {\n      res = g->gcpause;\n      g->gcpause = data;\n      break;\n    }\n    case LUA_GCSETSTEPMUL: {\n      res = g->gcstepmul;\n      g->gcstepmul = data;\n      break;\n    }\n    case LUA_GCSETMEMLIMIT: {\n      /* GC values are expressed in Kbytes: #bytes/2^10 */\n      lu_mem new_memlimit = (cast(lu_mem, data) << 10);\n      if(new_memlimit > 0 && new_memlimit < g->totalbytes) {\n        /* run a full GC to make totalbytes < the new limit. */\n        luaC_fullgc(L);\n        if(new_memlimit < g->totalbytes)\n          new_memlimit = (g->totalbytes + 1024) & ~(1024-1); /* round up to next multiple of 1024 */\n      }\n      g->memlimit = new_memlimit;\n      /* new memlimit might be > then requested memlimit. */\n      res = cast_int(new_memlimit >> 10);\n      break;\n    }\n    case LUA_GCGETMEMLIMIT: {\n      res = cast_int(g->memlimit >> 10);\n      break;\n    }\n    default: res = -1;  /* invalid option */\n  }\n  lua_unlock(L);\n  return res;\n}\n\n\n\n/*\n** miscellaneous functions\n*/\n\n\nLUA_API int lua_error (lua_State *L) {\n  lua_lock(L);\n  api_checknelems(L, 1);\n  luaG_errormsg(L);\n  lua_unlock(L);\n  return 0;  /* to avoid warnings */\n}\n\n\nLUA_API int lua_next (lua_State *L, int idx) {\n  StkId t;\n  int more;\n  lua_lock(L);\n  t = index2adr(L, idx);\n  api_check(L, ttistable(t));\n  more = luaH_next(L, hvalue(t), L->top - 1);\n  if (more) {\n    api_incr_top(L);\n  }\n  else  /* no more elements */\n    L->top -= 1;  /* remove key */\n  lua_unlock(L);\n  return more;\n}\n\n\nLUA_API void lua_concat (lua_State *L, int n) {\n  lua_lock(L);\n  api_checknelems(L, n);\n  if (n >= 2) {\n    luaC_checkGC(L);\n    luaV_concat(L, n, cast_int(L->top - L->base) - 1);\n    L->top -= (n-1);\n  }\n  else if (n == 0) {  /* push empty string */\n    setsvalue2s(L, L->top, luaS_newlstr(L, \"\", 0));\n    api_incr_top(L);\n  }\n  /* else n == 1; nothing to do */\n  lua_unlock(L);\n}\n\n\nLUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {\n  lua_Alloc f;\n  lua_lock(L);\n  if (ud) *ud = G(L)->ud;\n  f = G(L)->frealloc;\n  lua_unlock(L);\n  return f;\n}\n\n\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {\n  lua_lock(L);\n  G(L)->ud = ud;\n  G(L)->frealloc = f;\n  lua_unlock(L);\n}\n\n\nLUA_API void *lua_newuserdata (lua_State *L, size_t size) {\n  Udata *u;\n  lua_lock(L);\n  luaC_checkGC(L);\n  u = luaS_newudata(L, size, getcurrenv(L));\n  setuvalue(L, L->top, u);\n  api_incr_top(L);\n  lua_unlock(L);\n  return u + 1;\n}\n\n\n\n\nstatic const char *aux_upvalue (StkId fi, int n, TValue **val) {\n  Closure *f;\n  if (!ttisfunction(fi)) return NULL;\n  f = clvalue(fi);\n  if (cl_isC(f)) {\n    if (!(1 <= n && n <= f->c.nupvalues)) return NULL;\n    *val = &f->c.upvalue[n-1];\n    return \"\";\n  }\n  else {\n    Proto *p = f->l.p;\n    if (!(1 <= n && n <= p->sizeupvalues)) return NULL;\n    *val = f->l.upvals[n-1]->v;\n    return getstr(p->upvalues[n-1]);\n  }\n}\n\n\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val;\n  lua_lock(L);\n  name = aux_upvalue(index2adr(L, funcindex), n, &val);\n  if (name) {\n    setobj2s(L, L->top, val);\n    api_incr_top(L);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {\n  const char *name;\n  TValue *val;\n  StkId fi;\n  lua_lock(L);\n  fi = index2adr(L, funcindex);\n  api_checknelems(L, 1);\n  name = aux_upvalue(fi, n, &val);\n  if (name) {\n    L->top--;\n    setobj(L, val, L->top);\n    luaC_barrier(L, clvalue(fi), L->top);\n  }\n  lua_unlock(L);\n  return name;\n}\n\n"
  },
  {
    "path": "src/lapi.h",
    "content": "/*\n** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions from Lua API\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lapi_h\n#define lapi_h\n\n\n#include \"lobject.h\"\n\n\nLUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);\n\n#endif\n"
  },
  {
    "path": "src/lauxlib.c",
    "content": "/*\n** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#include <ctype.h>\n#include <errno.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n\n/* This file uses only the official API of Lua.\n** Any function declared here could be written as an application function.\n*/\n\n#define lauxlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lgc.h\"\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define FREELIST_REF\t0\t/* free list of references */\n\n\n/* convert a stack index to positive */\n#define abs_index(L, i)\t\t((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \\\n\t\t\t\t\tlua_gettop(L) + (i) + 1)\n\n\n/*\n** {======================================================\n** Error-report functions\n** =======================================================\n*/\n\n\nLUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {\n  lua_Debug ar;\n  if (!lua_getstack(L, 0, &ar))  /* no stack frame? */\n    return luaL_error(L, \"bad argument #%d (%s)\", narg, extramsg);\n  lua_getinfo(L, \"n\", &ar);\n  if (strcmp(ar.namewhat, \"method\") == 0) {\n    narg--;  /* do not count `self' */\n    if (narg == 0)  /* error is in the self argument itself? */\n      return luaL_error(L, \"calling \" LUA_QS \" on bad self (%s)\",\n                           ar.name, extramsg);\n  }\n  if (ar.name == NULL)\n    ar.name = \"?\";\n  return luaL_error(L, \"bad argument #%d to \" LUA_QS \" (%s)\",\n                        narg, ar.name, extramsg);\n}\n\n\nLUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {\n  const char *msg = lua_pushfstring(L, \"%s expected, got %s\",\n                                    tname, luaL_typename(L, narg));\n  return luaL_argerror(L, narg, msg);\n}\n\n\nstatic void tag_error (lua_State *L, int narg, int tag) {\n  luaL_typerror(L, narg, lua_typename(L, tag));\n}\n\n\nLUALIB_API void luaL_where (lua_State *L, int level) {\n  lua_Debug ar;\n  if (lua_getstack(L, level, &ar)) {  /* check function at level */\n    lua_getinfo(L, \"Sl\", &ar);  /* get info about it */\n    if (ar.currentline > 0) {  /* is there info? */\n      lua_pushfstring(L, \"%s:%d: \", ar.short_src, ar.currentline);\n      return;\n    }\n  }\n  lua_pushliteral(L, \"\");  /* else, no information available... */\n}\n\n\nLUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  luaL_where(L, 1);\n  lua_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  lua_concat(L, 2);\n  return lua_error(L);\n}\n\n/* }====================================================== */\n\n\nLUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def,\n                                 const char *const lst[]) {\n  const char *name = (def) ? luaL_optstring(L, narg, def) :\n                             luaL_checkstring(L, narg);\n  int i;\n  for (i=0; lst[i]; i++)\n    if (strcmp(lst[i], name) == 0)\n      return i;\n  return luaL_argerror(L, narg,\n                       lua_pushfstring(L, \"invalid option \" LUA_QS, name));\n}\n\n\nLUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {\n  lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get registry.name */\n  if (!lua_isnil(L, -1))  /* name already in use? */\n    return 0;  /* leave previous value on top, but return 0 */\n  lua_pop(L, 1);\n  lua_newtable(L);  /* create metatable */\n  lua_pushvalue(L, -1);\n  lua_setfield(L, LUA_REGISTRYINDEX, tname);  /* registry.name = metatable */\n  return 1;\n}\n\n\nLUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {\n  void *p = lua_touserdata(L, ud);\n  if (p != NULL) {  /* value is a userdata? */\n    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */\n      lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */\n      if (lua_rawequal(L, -1, -2)) {  /* does it have the correct mt? */\n        lua_pop(L, 2);  /* remove both metatables */\n        return p;\n      }\n    }\n  }\n  luaL_typerror(L, ud, tname);  /* else error */\n  return NULL;  /* to avoid warnings */\n}\n\n\nLUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {\n  if (!lua_checkstack(L, space))\n    luaL_error(L, \"stack overflow (%s)\", mes);\n}\n\n\nLUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {\n  if (lua_type(L, narg) != t)\n    tag_error(L, narg, t);\n}\n\n\nLUALIB_API void luaL_checkany (lua_State *L, int narg) {\n  if (lua_type(L, narg) == LUA_TNONE)\n    luaL_argerror(L, narg, \"value expected\");\n}\n\n\nLUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {\n  const char *s = lua_tolstring(L, narg, len);\n  if (!s) tag_error(L, narg, LUA_TSTRING);\n  return s;\n}\n\n\nLUALIB_API const char *luaL_optlstring (lua_State *L, int narg,\n                                        const char *def, size_t *len) {\n  if (lua_isnoneornil(L, narg)) {\n    if (len)\n      *len = (def ? strlen(def) : 0);\n    return def;\n  }\n  else return luaL_checklstring(L, narg, len);\n}\n\n\nLUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {\n  lua_Number d = lua_tonumber(L, narg);\n  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */\n    tag_error(L, narg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {\n  return luaL_opt(L, luaL_checknumber, narg, def);\n}\n\n\nLUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {\n  lua_Integer d = lua_tointeger(L, narg);\n  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */\n    tag_error(L, narg, LUA_TNUMBER);\n  return d;\n}\n\n\nLUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,\n                                                      lua_Integer def) {\n  return luaL_opt(L, luaL_checkinteger, narg, def);\n}\n\n\nLUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {\n  if (!lua_getmetatable(L, obj))  /* no metatable? */\n    return 0;\n  lua_pushstring(L, event);\n  lua_rawget(L, -2);\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 2);  /* remove metatable and metafield */\n    return 0;\n  }\n  else {\n    lua_remove(L, -2);  /* remove only metatable */\n    return 1;\n  }\n}\n\n\nLUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {\n  obj = abs_index(L, obj);\n  if (!luaL_getmetafield(L, obj, event))  /* no metafield? */\n    return 0;\n  lua_pushvalue(L, obj);\n  lua_call(L, 1, 1);\n  return 1;\n}\n\n\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l) {\n  luaI_openlib(L, libname, l, 0);\n}\n\n\nstatic int libsize (const luaL_Reg *l) {\n  int size = 0;\n  for (; l->name; l++) size++;\n  return size;\n}\n\n\nLUALIB_API void luaI_openlib (lua_State *L, const char *libname,\n                              const luaL_Reg *l, int nup) {\n  if (libname) {\n    int size = libsize(l);\n    /* check whether lib already exists */\n    luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 1);\n    lua_getfield(L, -1, libname);  /* get _LOADED[libname] */\n    if (!lua_istable(L, -1)) {  /* not found? */\n      lua_pop(L, 1);  /* remove previous result */\n      /* try global variable (and create one if it does not exist) */\n      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)\n        luaL_error(L, \"name conflict for module \" LUA_QS, libname);\n      lua_pushvalue(L, -1);\n      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */\n    }\n    lua_remove(L, -2);  /* remove _LOADED table */\n    lua_insert(L, -(nup+1));  /* move library table to below upvalues */\n  }\n  for (; l->name; l++) {\n    int i;\n    for (i=0; i<nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);\n    lua_setfield(L, -(nup+2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\nLUALIB_API void (luaL_register3) (lua_State *L, const char *libname,\n                                const luaL_Reg3 *l) {\n  luaI_openlib3(L, libname, l, 0);\n}\n\n\nstatic int libsize3 (const luaL_Reg3 *l) {\n  int size = 0;\n  for (; l->name; l++) size++;\n  return size;\n}\n\n\nLUALIB_API void (luaI_openlib3) (lua_State *L, const char *libname,\n                                const luaL_Reg3 *l, int nup) {\n  if (libname) {\n    int size = libsize3(l);\n    /* check whether lib already exists */\n    luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 1);\n    lua_getfield(L, -1, libname);  /* get _LOADED[libname] */\n    if (!lua_istable(L, -1)) {  /* not found? */\n      lua_pop(L, 1);  /* remove previous result */\n      /* try global variable (and create one if it does not exist) */\n      if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)\n        luaL_error(L, \"name conflict for module \" LUA_QS, libname);\n      lua_pushvalue(L, -1);\n      lua_setfield(L, -3, libname);  /* _LOADED[libname] = new table */\n    }\n    lua_remove(L, -2);  /* remove _LOADED table */\n    lua_insert(L, -(nup+1));  /* move library table to below upvalues */\n  }\n  for (; l->name; l++) {\n    int i;\n    for (i=0; i<nup; i++)  /* copy upvalues to the top */\n      lua_pushvalue(L, -nup);\n    lua_pushcclosure(L, l->func, nup);\n    if (l->precall) {\n      Closure *cl;\n      cl = clvalue(L->top - 1);\n      cl->c.precall = l->precall;\n    }\n    lua_setfield(L, -(nup+2), l->name);\n  }\n  lua_pop(L, nup);  /* remove upvalues */\n}\n\n\n/*\n** {======================================================\n** getn-setn: size for arrays\n** =======================================================\n*/\n\n#if defined(LUA_COMPAT_GETN)\n\nstatic int checkint (lua_State *L, int topop) {\n  int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1;\n  lua_pop(L, topop);\n  return n;\n}\n\n\nstatic void getsizes (lua_State *L) {\n  lua_getfield(L, LUA_REGISTRYINDEX, \"LUA_SIZES\");\n  if (lua_isnil(L, -1)) {  /* no `size' table? */\n    lua_pop(L, 1);  /* remove nil */\n    lua_newtable(L);  /* create it */\n    lua_pushvalue(L, -1);  /* `size' will be its own metatable */\n    lua_setmetatable(L, -2);\n    lua_pushliteral(L, \"kv\");\n    lua_setfield(L, -2, \"__mode\");  /* metatable(N).__mode = \"kv\" */\n    lua_pushvalue(L, -1);\n    lua_setfield(L, LUA_REGISTRYINDEX, \"LUA_SIZES\");  /* store in register */\n  }\n}\n\n\nLUALIB_API void luaL_setn (lua_State *L, int t, int n) {\n  t = abs_index(L, t);\n  lua_pushliteral(L, \"n\");\n  lua_rawget(L, t);\n  if (checkint(L, 1) >= 0) {  /* is there a numeric field `n'? */\n    lua_pushliteral(L, \"n\");  /* use it */\n    lua_pushinteger(L, n);\n    lua_rawset(L, t);\n  }\n  else {  /* use `sizes' */\n    getsizes(L);\n    lua_pushvalue(L, t);\n    lua_pushinteger(L, n);\n    lua_rawset(L, -3);  /* sizes[t] = n */\n    lua_pop(L, 1);  /* remove `sizes' */\n  }\n}\n\n\nLUALIB_API int luaL_getn (lua_State *L, int t) {\n  int n;\n  t = abs_index(L, t);\n  lua_pushliteral(L, \"n\");  /* try t.n */\n  lua_rawget(L, t);\n  if ((n = checkint(L, 1)) >= 0) return n;\n  getsizes(L);  /* else try sizes[t] */\n  lua_pushvalue(L, t);\n  lua_rawget(L, -2);\n  if ((n = checkint(L, 2)) >= 0) return n;\n  return (int)lua_objlen(L, t);\n}\n\n#endif\n\n/* }====================================================== */\n\n\n\nLUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,\n                                                               const char *r) {\n  const char *wild;\n  size_t l = strlen(p);\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while ((wild = strstr(s, p)) != NULL) {\n    luaL_addlstring(&b, s, wild - s);  /* push prefix */\n    luaL_addstring(&b, r);  /* push replacement in place of pattern */\n    s = wild + l;  /* continue after `p' */\n  }\n  luaL_addstring(&b, s);  /* push last suffix */\n  luaL_pushresult(&b);\n  return lua_tostring(L, -1);\n}\n\n\nLUALIB_API const char *luaL_findtable (lua_State *L, int idx,\n                                       const char *fname, int szhint) {\n  const char *e;\n  lua_pushvalue(L, idx);\n  do {\n    e = strchr(fname, '.');\n    if (e == NULL) e = fname + strlen(fname);\n    lua_pushlstring(L, fname, e - fname);\n    lua_rawget(L, -2);\n    if (lua_isnil(L, -1)) {  /* no such field? */\n      lua_pop(L, 1);  /* remove this nil */\n      lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */\n      lua_pushlstring(L, fname, e - fname);\n      lua_pushvalue(L, -2);\n      lua_settable(L, -4);  /* set new table into field */\n    }\n    else if (!lua_istable(L, -1)) {  /* field has a non-table value? */\n      lua_pop(L, 2);  /* remove table and value */\n      return fname;  /* return problematic part of the name */\n    }\n    lua_remove(L, -2);  /* remove previous table */\n    fname = e + 1;\n  } while (*e == '.');\n  return NULL;\n}\n\n\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n#define bufflen(B)\t((B)->p - (B)->buffer)\n#define bufffree(B)\t((size_t)(LUAL_BUFFERSIZE - bufflen(B)))\n\n#define LIMIT\t(LUA_MINSTACK/2)\n\n\nstatic int emptybuffer (luaL_Buffer *B) {\n  size_t l = bufflen(B);\n  if (l == 0) return 0;  /* put nothing on stack */\n  else {\n    lua_pushlstring(B->L, B->buffer, l);\n    B->p = B->buffer;\n    B->lvl++;\n    return 1;\n  }\n}\n\n\nstatic void adjuststack (luaL_Buffer *B) {\n  if (B->lvl > 1) {\n    lua_State *L = B->L;\n    int toget = 1;  /* number of levels to concat */\n    size_t toplen = lua_strlen(L, -1);\n    do {\n      size_t l = lua_strlen(L, -(toget+1));\n      if (B->lvl - toget + 1 >= LIMIT || toplen > l) {\n        toplen += l;\n        toget++;\n      }\n      else break;\n    } while (toget < B->lvl);\n    lua_concat(L, toget);\n    B->lvl = B->lvl - toget + 1;\n  }\n}\n\n\nLUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {\n  if (emptybuffer(B))\n    adjuststack(B);\n  return B->buffer;\n}\n\n\nLUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {\n  while (l--)\n    luaL_addchar(B, *s++);\n}\n\n\nLUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {\n  luaL_addlstring(B, s, strlen(s));\n}\n\n\nLUALIB_API void luaL_pushresult (luaL_Buffer *B) {\n  emptybuffer(B);\n  lua_concat(B->L, B->lvl);\n  B->lvl = 1;\n}\n\n\nLUALIB_API void luaL_addvalue (luaL_Buffer *B) {\n  lua_State *L = B->L;\n  size_t vl;\n  const char *s = lua_tolstring(L, -1, &vl);\n  if (vl <= bufffree(B)) {  /* fit into buffer? */\n    memcpy(B->p, s, vl);  /* put it there */\n    B->p += vl;\n    lua_pop(L, 1);  /* remove from stack */\n  }\n  else {\n    if (emptybuffer(B))\n      lua_insert(L, -2);  /* put buffer before new value */\n    B->lvl++;  /* add new value into B stack */\n    adjuststack(B);\n  }\n}\n\n\nLUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {\n  B->L = L;\n  B->p = B->buffer;\n  B->lvl = 0;\n}\n\n/* }====================================================== */\n\n\nLUALIB_API int luaL_ref (lua_State *L, int t) {\n  int ref;\n  t = abs_index(L, t);\n  if (lua_isnil(L, -1)) {\n    lua_pop(L, 1);  /* remove from stack */\n    return LUA_REFNIL;  /* `nil' has a unique fixed reference */\n  }\n  lua_rawgeti(L, t, FREELIST_REF);  /* get first free element */\n  ref = (int)lua_tointeger(L, -1);  /* ref = t[FREELIST_REF] */\n  lua_pop(L, 1);  /* remove it from stack */\n  if (ref != 0) {  /* any free element? */\n    lua_rawgeti(L, t, ref);  /* remove it from list */\n    lua_rawseti(L, t, FREELIST_REF);  /* (t[FREELIST_REF] = t[ref]) */\n  }\n  else {  /* no free elements */\n    ref = (int)lua_objlen(L, t);\n    ref++;  /* create new reference */\n  }\n  lua_rawseti(L, t, ref);\n  return ref;\n}\n\n\nLUALIB_API void luaL_unref (lua_State *L, int t, int ref) {\n  if (ref >= 0) {\n    t = abs_index(L, t);\n    lua_rawgeti(L, t, FREELIST_REF);\n    lua_rawseti(L, t, ref);  /* t[ref] = t[FREELIST_REF] */\n    lua_pushinteger(L, ref);\n    lua_rawseti(L, t, FREELIST_REF);  /* t[FREELIST_REF] = ref */\n  }\n}\n\n\n\n/*\n** {======================================================\n** Load functions\n** =======================================================\n*/\n\ntypedef struct LoadF {\n  int extraline;\n  FILE *f;\n  char buff[LUAL_BUFFERSIZE];\n} LoadF;\n\n\nstatic const char *getF (lua_State *L, void *ud, size_t *size) {\n  LoadF *lf = (LoadF *)ud;\n  (void)L;\n  if (lf->extraline) {\n    lf->extraline = 0;\n    *size = 1;\n    return \"\\n\";\n  }\n  if (feof(lf->f)) return NULL;\n  *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);\n  return (*size > 0) ? lf->buff : NULL;\n}\n\n\nstatic int errfile (lua_State *L, const char *what, int fnameindex) {\n  const char *serr = strerror(errno);\n  const char *filename = lua_tostring(L, fnameindex) + 1;\n  lua_pushfstring(L, \"cannot %s %s: %s\", what, filename, serr);\n  lua_remove(L, fnameindex);\n  return LUA_ERRFILE;\n}\n\n\nLUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {\n  LoadF lf;\n  int status, readstatus;\n  int c;\n  int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */\n  lf.extraline = 0;\n  if (filename == NULL) {\n    lua_pushliteral(L, \"=stdin\");\n    lf.f = stdin;\n  }\n  else {\n    lua_pushfstring(L, \"@%s\", filename);\n    lf.f = fopen(filename, \"r\");\n    if (lf.f == NULL) return errfile(L, \"open\", fnameindex);\n  }\n  c = getc(lf.f);\n  if (c == '#') {  /* Unix exec. file? */\n    lf.extraline = 1;\n    while ((c = getc(lf.f)) != EOF && c != '\\n') ;  /* skip first line */\n    if (c == '\\n') c = getc(lf.f);\n  }\n  if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */\n    lf.f = freopen(filename, \"rb\", lf.f);  /* reopen in binary mode */\n    if (lf.f == NULL) return errfile(L, \"reopen\", fnameindex);\n    /* skip eventual `#!...' */\n   while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {}\n    lf.extraline = 0;\n  }\n  ungetc(c, lf.f);\n  status = lua_load(L, getF, &lf, lua_tostring(L, -1));\n  readstatus = ferror(lf.f);\n  if (filename) fclose(lf.f);  /* close file (even in case of errors) */\n  if (readstatus) {\n    lua_settop(L, fnameindex);  /* ignore results from `lua_load' */\n    return errfile(L, \"read\", fnameindex);\n  }\n  lua_remove(L, fnameindex);\n  return status;\n}\n\n\ntypedef struct LoadS {\n  const char *s;\n  size_t size;\n} LoadS;\n\n\nstatic const char *getS (lua_State *L, void *ud, size_t *size) {\n  LoadS *ls = (LoadS *)ud;\n  (void)L;\n  if (ls->size == 0) return NULL;\n  *size = ls->size;\n  ls->size = 0;\n  return ls->s;\n}\n\n\nLUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size,\n                                const char *name) {\n  LoadS ls;\n  ls.s = buff;\n  ls.size = size;\n  return lua_load(L, getS, &ls, name);\n}\n\n\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {\n  return luaL_loadbuffer(L, s, strlen(s), s);\n}\n\n\n\n/* }====================================================== */\n\n\nstatic int l_check_memlimit(lua_State *L, size_t needbytes) {\n  global_State *g = G(L);\n  int cycle_count = 0;\n  lu_mem limit = g->memlimit - needbytes;\n  /* don't allow allocation if it requires more memory then the total limit. */\n  if (needbytes > g->memlimit) return 1;\n  /* make sure the GC is not disabled. */\n  if (!is_block_gc(L)) {\n    while (g->totalbytes >= limit) {\n      /* only allow the GC to finished atleast 1 full cycle. */\n      if (g->gcstate == GCSpause && ++cycle_count > 1) break;\n      luaC_step(L);\n    }\n  }\n  return (g->totalbytes >= limit) ? 1 : 0;\n}\n\n\nstatic void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {\n  lua_State *L = (lua_State *)ud;\n  void *nptr;\n  if (nsize == 0) {\n    free(ptr);\n    return NULL;\n  }\n  if(nsize > osize && L != NULL) {\n    if(G(L)->memlimit > 0 && l_check_memlimit(L, nsize - osize))\n      return NULL;\n  }\n  nptr = realloc(ptr, nsize);\n  if (nptr == NULL && L != NULL) {\n    luaC_fullgc(L); /* emergency full collection. */\n    nptr = realloc(ptr, nsize); /* try allocation again */\n  }\n  return nptr;\n}\n\n\nstatic int panic (lua_State *L) {\n  (void)L;  /* to avoid warnings */\n  fprintf(stderr, \"PANIC: unprotected error in call to Lua API (%s)\\n\",\n                   lua_tostring(L, -1));\n  return 0;\n}\n\n\nLUALIB_API lua_State *luaL_newstate (void) {\n  lua_State *L = lua_newstate(l_alloc, NULL);\n  lua_setallocf(L, l_alloc, L); /* allocator need lua_State. */\n  if (L) lua_atpanic(L, &panic);\n  return L;\n}\n\n"
  },
  {
    "path": "src/lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n#if defined(LUA_COMPAT_GETN)\nLUALIB_API int (luaL_getn) (lua_State *L, int t);\nLUALIB_API void (luaL_setn) (lua_State *L, int t, int n);\n#else\n#define luaL_getn(L,i)          ((int)lua_objlen(L, i))\n#define luaL_setn(L,i,j)        ((void)0)  /* no op! */\n#endif\n\n#if defined(LUA_COMPAT_OPENLIB)\n#define luaI_openlib\tluaL_openlib\n#endif\n\n\n/* extra error code for `luaL_load' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\ntypedef struct luaL_Reg3 {\n  const char *name;\n  lua_CFunction func;\n  lua_precall precall;\n} luaL_Reg3;\n\n\nLUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l);\nLUALIB_API void (luaI_openlib3) (lua_State *L, const char *libname,\n                                const luaL_Reg3 *l, int nup);\nLUALIB_API void (luaL_register3) (lua_State *L, const char *libname,\n                                const luaL_Reg3 *l);\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);\nLUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int narg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);\nLUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,\n                                  const char *name);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,\n                                         const char *fname, int szhint);\n\n\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define luaL_argcheck(L, cond,numarg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n\ntypedef struct luaL_Buffer {\n  char *p;\t\t\t/* current position in buffer */\n  int lvl;  /* number of strings in the stack (level) */\n  lua_State *L;\n  char buffer[LUAL_BUFFERSIZE];\n} luaL_Buffer;\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \\\n   (*(B)->p++ = (char)(c)))\n\n/* compatibility only */\n#define luaL_putchar(B,c)\tluaL_addchar(B,c)\n\n#define luaL_addsize(B,n)\t((B)->p += (n))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\n\n\n/* }====================================================== */\n\n\n/* compatibility with ref system */\n\n/* pre-defined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\n#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \\\n      (lua_pushstring(L, \"unlocked references are obsolete\"), lua_error(L), 0))\n\n#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))\n\n#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))\n\n\n#define luaL_reg\tluaL_Reg\n\n#endif\n\n\n"
  },
  {
    "path": "src/lbaselib.c",
    "content": "/*\n** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $\n** Basic library\n** See Copyright Notice in lua.h\n*/\n\n\n\n#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lbaselib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n#ifndef COCO_DISABLE\n#include \"lcoco.h\"\n#endif\n\n\n\n\n/*\n** If your system does not support `stdout', you can just remove this function.\n** If you need, you can define your own `print' function, following this\n** model but changing `fputs' to put the strings at a proper place\n** (a console window or a log file, for instance).\n*/\nstatic int luaB_print (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  lua_getglobal(L, \"tostring\");\n  for (i=1; i<=n; i++) {\n    const char *s;\n    lua_pushvalue(L, -1);  /* function to be called */\n    lua_pushvalue(L, i);   /* value to print */\n    lua_call(L, 1, 1);\n    s = lua_tostring(L, -1);  /* get result */\n    if (s == NULL)\n      return luaL_error(L, LUA_QL(\"tostring\") \" must return a string to \"\n                           LUA_QL(\"print\"));\n    if (i>1) fputs(\"\\t\", stdout);\n    fputs(s, stdout);\n    lua_pop(L, 1);  /* pop result */\n  }\n  fputs(\"\\n\", stdout);\n  return 0;\n}\n\n\nstatic int luaB_tonumber (lua_State *L) {\n  int base = luaL_optint(L, 2, 10);\n  if (base == 10) {  /* standard conversion */\n    luaL_checkany(L, 1);\n    if (lua_isnumber(L, 1)) {\n      lua_pushnumber(L, lua_tonumber(L, 1));\n      return 1;\n    }\n  }\n  else {\n    const char *s1 = luaL_checkstring(L, 1);\n    char *s2;\n    unsigned long n;\n    luaL_argcheck(L, 2 <= base && base <= 36, 2, \"base out of range\");\n    n = strtoul(s1, &s2, base);\n    if (s1 != s2) {  /* at least one valid digit? */\n      while (isspace((unsigned char)(*s2))) s2++;  /* skip trailing spaces */\n      if (*s2 == '\\0') {  /* no invalid trailing characters? */\n        lua_pushnumber(L, (lua_Number)n);\n        return 1;\n      }\n    }\n  }\n  lua_pushnil(L);  /* else not a number */\n  return 1;\n}\n\n\nstatic int luaB_error (lua_State *L) {\n  int level = luaL_optint(L, 2, 1);\n  lua_settop(L, 1);\n  if (lua_isstring(L, 1) && level > 0) {  /* add extra information? */\n    luaL_where(L, level);\n    lua_pushvalue(L, 1);\n    lua_concat(L, 2);\n  }\n  return lua_error(L);\n}\n\n\nstatic int luaB_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);\n    return 1;  /* no metatable */\n  }\n  luaL_getmetafield(L, 1, \"__metatable\");\n  return 1;  /* returns either __metatable field (if present) or metatable */\n}\n\n\nstatic int luaB_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  if (luaL_getmetafield(L, 1, \"__metatable\"))\n    luaL_error(L, \"cannot change a protected metatable\");\n  lua_settop(L, 2);\n  lua_setmetatable(L, 1);\n  return 1;\n}\n\n\nstatic void getfunc (lua_State *L, int opt) {\n  if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);\n  else {\n    lua_Debug ar;\n    int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);\n    luaL_argcheck(L, level >= 0, 1, \"level must be non-negative\");\n    if (lua_getstack(L, level, &ar) == 0)\n      luaL_argerror(L, 1, \"invalid level\");\n    lua_getinfo(L, \"f\", &ar);\n    if (lua_isnil(L, -1))\n      luaL_error(L, \"no function environment for tail call at level %d\",\n                    level);\n  }\n}\n\n\nstatic int luaB_getfenv (lua_State *L) {\n  getfunc(L, 1);\n  if (lua_iscfunction(L, -1))  /* is a C function? */\n    lua_pushvalue(L, LUA_GLOBALSINDEX);  /* return the thread's global env. */\n  else\n    lua_getfenv(L, -1);\n  return 1;\n}\n\n\nstatic int luaB_setfenv (lua_State *L) {\n  luaL_checktype(L, 2, LUA_TTABLE);\n  getfunc(L, 0);\n  lua_pushvalue(L, 2);\n  if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {\n    /* change environment of current thread */\n    lua_pushthread(L);\n    lua_insert(L, -2);\n    lua_setfenv(L, -2);\n    return 0;\n  }\n  else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)\n    luaL_error(L,\n          LUA_QL(\"setfenv\") \" cannot change environment of given object\");\n  return 1;\n}\n\n\nstatic int luaB_rawequal (lua_State *L) {\n  luaL_checkany(L, 1);\n  luaL_checkany(L, 2);\n  lua_pushboolean(L, lua_rawequal(L, 1, 2));\n  return 1;\n}\n\n\nstatic int luaB_rawget (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_rawget(L, 1);\n  return 1;\n}\n\nstatic int luaB_rawset (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checkany(L, 2);\n  luaL_checkany(L, 3);\n  lua_settop(L, 3);\n  lua_rawset(L, 1);\n  return 1;\n}\n\n\nstatic int luaB_gcinfo (lua_State *L) {\n  lua_pushinteger(L, lua_getgccount(L));\n  return 1;\n}\n\n\nstatic int luaB_collectgarbage (lua_State *L) {\n  static const char *const opts[] = {\"stop\", \"restart\", \"collect\",\n    \"count\", \"step\", \"setpause\", \"setstepmul\",\"setmemlimit\",\"getmemlimit\", NULL};\n  static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,\n    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,\n\t\tLUA_GCSETMEMLIMIT,LUA_GCGETMEMLIMIT};\n  int o = luaL_checkoption(L, 1, \"collect\", opts);\n  int ex = luaL_optint(L, 2, 0);\n  int res = lua_gc(L, optsnum[o], ex);\n  switch (optsnum[o]) {\n    case LUA_GCCOUNT: {\n      int b = lua_gc(L, LUA_GCCOUNTB, 0);\n      lua_pushnumber(L, res + ((lua_Number)b/1024));\n      return 1;\n    }\n    case LUA_GCSTEP: {\n      lua_pushboolean(L, res);\n      return 1;\n    }\n    default: {\n      lua_pushnumber(L, res);\n      return 1;\n    }\n  }\n}\n\n\nstatic int luaB_type (lua_State *L) {\n  luaL_checkany(L, 1);\n  lua_pushstring(L, luaL_typename(L, 1));\n  return 1;\n}\n\n\nstatic int luaB_next (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */\n  if (lua_next(L, 1))\n    return 2;\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int luaB_pairs (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushvalue(L, lua_upvalueindex(1));  /* return generator, */\n  lua_pushvalue(L, 1);  /* state, */\n  lua_pushnil(L);  /* and initial value */\n  return 3;\n}\n\n\nstatic int ipairsaux (lua_State *L) {\n  int i = luaL_checkint(L, 2);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  i++;  /* next value */\n  lua_pushinteger(L, i);\n  lua_rawgeti(L, 1, i);\n  return (lua_isnil(L, -1)) ? 0 : 2;\n}\n\n\nstatic int luaB_ipairs (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushvalue(L, lua_upvalueindex(1));  /* return generator, */\n  lua_pushvalue(L, 1);  /* state, */\n  lua_pushinteger(L, 0);  /* and initial value */\n  return 3;\n}\n\n\nstatic int load_aux (lua_State *L, int status) {\n  if (status == 0)  /* OK? */\n    return 1;\n  else {\n    lua_pushnil(L);\n    lua_insert(L, -2);  /* put before error message */\n    return 2;  /* return nil plus error message */\n  }\n}\n\n\nstatic int luaB_loadstring (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  const char *chunkname = luaL_optstring(L, 2, s);\n  return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));\n}\n\n\nstatic int luaB_loadfile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  return load_aux(L, luaL_loadfile(L, fname));\n}\n\n\n/*\n** Reader for generic `load' function: `lua_load' uses the\n** stack for internal stuff, so the reader cannot change the\n** stack top. Instead, it keeps its resulting string in a\n** reserved slot inside the stack.\n*/\nstatic const char *generic_reader (lua_State *L, void *ud, size_t *size) {\n  (void)ud;  /* to avoid warnings */\n  luaL_checkstack(L, 2, \"too many nested functions\");\n  lua_pushvalue(L, 1);  /* get function */\n  lua_call(L, 0, 1);  /* call it */\n  if (lua_isnil(L, -1)) {\n    *size = 0;\n    return NULL;\n  }\n  else if (lua_isstring(L, -1)) {\n    lua_replace(L, 3);  /* save string in a reserved stack slot */\n    return lua_tolstring(L, 3, size);\n  }\n  else luaL_error(L, \"reader function must return a string\");\n  return NULL;  /* to avoid warnings */\n}\n\n\nstatic int luaB_load (lua_State *L) {\n  int status;\n  const char *cname = luaL_optstring(L, 2, \"=(load)\");\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 3);  /* function, eventual name, plus one reserved slot */\n  status = lua_load(L, generic_reader, NULL, cname);\n  return load_aux(L, status);\n}\n\n\nstatic int luaB_dofile (lua_State *L) {\n  const char *fname = luaL_optstring(L, 1, NULL);\n  int n = lua_gettop(L);\n  if (luaL_loadfile(L, fname) != 0) lua_error(L);\n  lua_call(L, 0, LUA_MULTRET);\n  return lua_gettop(L) - n;\n}\n\n\nstatic int luaB_assert (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_toboolean(L, 1))\n    return luaL_error(L, \"%s\", luaL_optstring(L, 2, \"assertion failed!\"));\n  return lua_gettop(L);\n}\n\n\nstatic int luaB_unpack (lua_State *L) {\n  int i, e, n;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  i = luaL_optint(L, 2, 1);\n  e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));\n  if (i > e) return 0;  /* empty range */\n  n = e - i + 1;  /* number of elements */\n  if (n <= 0 || !lua_checkstack(L, n))  /* n <= 0 means arith. overflow */\n    return luaL_error(L, \"too many results to unpack\");\n  lua_rawgeti(L, 1, i);  /* push arg[i] (avoiding overflow problems) */\n  while (i++ < e)  /* push arg[i + 1...e] */\n    lua_rawgeti(L, 1, i);\n  return n;\n}\n\n\nstatic int luaB_select (lua_State *L) {\n  int n = lua_gettop(L);\n  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {\n    lua_pushinteger(L, n-1);\n    return 1;\n  }\n  else {\n    int i = luaL_checkint(L, 1);\n    if (i < 0) i = n + i;\n    else if (i > n) i = n;\n    luaL_argcheck(L, 1 <= i, 1, \"index out of range\");\n    return n - i;\n  }\n}\n\n\nstatic int luaB_pcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 1);\n  status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);\n  lua_pushboolean(L, (status == 0));\n  lua_insert(L, 1);\n  return lua_gettop(L);  /* return status + all results */\n}\n\n\nstatic int luaB_xpcall (lua_State *L) {\n  int status;\n  luaL_checkany(L, 2);\n  lua_settop(L, 2);\n  lua_insert(L, 1);  /* put error function under function to be called */\n  status = lua_pcall(L, 0, LUA_MULTRET, 1);\n  lua_pushboolean(L, (status == 0));\n  lua_replace(L, 1);\n  return lua_gettop(L);  /* return status + all results */\n}\n\n\nstatic int luaB_tostring (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (luaL_callmeta(L, 1, \"__tostring\"))  /* is there a metafield? */\n    return 1;  /* use its value */\n  switch (lua_type(L, 1)) {\n    case LUA_TNUMBER:\n      lua_pushstring(L, lua_tostring(L, 1));\n      break;\n    case LUA_TSTRING:\n      lua_pushvalue(L, 1);\n      break;\n    case LUA_TBOOLEAN:\n      lua_pushstring(L, (lua_toboolean(L, 1) ? \"true\" : \"false\"));\n      break;\n    case LUA_TNIL:\n      lua_pushliteral(L, \"nil\");\n      break;\n    default:\n      lua_pushfstring(L, \"%s: %p\", luaL_typename(L, 1), lua_topointer(L, 1));\n      break;\n  }\n  return 1;\n}\n\n\nstatic int luaB_newproxy (lua_State *L) {\n  lua_settop(L, 1);\n  lua_newuserdata(L, 0);  /* create proxy */\n  if (lua_toboolean(L, 1) == 0)\n    return 1;  /* no metatable */\n  else if (lua_isboolean(L, 1)) {\n    lua_newtable(L);  /* create a new metatable `m' ... */\n    lua_pushvalue(L, -1);  /* ... and mark `m' as a valid metatable */\n    lua_pushboolean(L, 1);\n    lua_rawset(L, lua_upvalueindex(1));  /* weaktable[m] = true */\n  }\n  else {\n    int validproxy = 0;  /* to check if weaktable[metatable(u)] == true */\n    if (lua_getmetatable(L, 1)) {\n      lua_rawget(L, lua_upvalueindex(1));\n      validproxy = lua_toboolean(L, -1);\n      lua_pop(L, 1);  /* remove value */\n    }\n    luaL_argcheck(L, validproxy, 1, \"boolean or proxy expected\");\n    lua_getmetatable(L, 1);  /* metatable is valid; get it */\n  }\n  lua_setmetatable(L, 2);\n  return 1;\n}\n\n\nstatic const luaL_Reg base_funcs[] = {\n  {\"assert\", luaB_assert},\n  {\"collectgarbage\", luaB_collectgarbage},\n  {\"dofile\", luaB_dofile},\n  {\"error\", luaB_error},\n  {\"gcinfo\", luaB_gcinfo},\n  {\"getfenv\", luaB_getfenv},\n  {\"getmetatable\", luaB_getmetatable},\n  {\"loadfile\", luaB_loadfile},\n  {\"load\", luaB_load},\n  {\"loadstring\", luaB_loadstring},\n  {\"next\", luaB_next},\n  {\"pcall\", luaB_pcall},\n  {\"print\", luaB_print},\n  {\"rawequal\", luaB_rawequal},\n  {\"rawget\", luaB_rawget},\n  {\"rawset\", luaB_rawset},\n  {\"select\", luaB_select},\n  {\"setfenv\", luaB_setfenv},\n  {\"setmetatable\", luaB_setmetatable},\n  {\"tonumber\", luaB_tonumber},\n  {\"tostring\", luaB_tostring},\n  {\"type\", luaB_type},\n  {\"unpack\", luaB_unpack},\n  {\"xpcall\", luaB_xpcall},\n  {NULL, NULL}\n};\n\n\n/*\n** {======================================================\n** Coroutine library\n** =======================================================\n*/\n\n#define CO_RUN\t0\t/* running */\n#define CO_SUS\t1\t/* suspended */\n#define CO_NOR\t2\t/* 'normal' (it resumed another coroutine) */\n#define CO_DEAD\t3\n\nstatic const char *const statnames[] =\n    {\"running\", \"suspended\", \"normal\", \"dead\"};\n\nstatic int costatus (lua_State *L, lua_State *co) {\n  if (L == co) return CO_RUN;\n  switch (lua_status(co)) {\n    case LUA_YIELD:\n      return CO_SUS;\n    case 0: {\n      lua_Debug ar;\n      if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */\n        return CO_NOR;  /* it is running */\n      else if (lua_gettop(co) == 0)\n          return CO_DEAD;\n      else\n        return CO_SUS;  /* initial state */\n    }\n    default:  /* some error occured */\n      return CO_DEAD;\n  }\n}\n\n\nstatic int luaB_costatus (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  luaL_argcheck(L, co, 1, \"coroutine expected\");\n  lua_pushstring(L, statnames[costatus(L, co)]);\n  return 1;\n}\n\n\nstatic int auxresume (lua_State *L, lua_State *co, int narg) {\n  int status = costatus(L, co);\n  if (!lua_checkstack(co, narg))\n    luaL_error(L, \"too many arguments to resume\");\n  if (status != CO_SUS) {\n    lua_pushfstring(L, \"cannot resume %s coroutine\", statnames[status]);\n    return -1;  /* error flag */\n  }\n  lua_xmove(L, co, narg);\n  status = lua_resume(co, narg);\n  if (status == 0 || status == LUA_YIELD) {\n    int nres = lua_gettop(co);\n    if (!lua_checkstack(L, nres + 1))\n      luaL_error(L, \"too many results to resume\");\n    lua_xmove(co, L, nres);  /* move yielded values */\n    return nres;\n  }\n  else {\n    lua_xmove(co, L, 1);  /* move error message */\n    return -1;  /* error flag */\n  }\n}\n\n\nstatic int luaB_coresume (lua_State *L) {\n  lua_State *co = lua_tothread(L, 1);\n  int r;\n  luaL_argcheck(L, co, 1, \"coroutine expected\");\n  r = auxresume(L, co, lua_gettop(L) - 1);\n  if (r < 0) {\n    lua_pushboolean(L, 0);\n    lua_insert(L, -2);\n    return 2;  /* return false + error message */\n  }\n  else {\n    lua_pushboolean(L, 1);\n    lua_insert(L, -(r + 1));\n    return r + 1;  /* return true + `resume' returns */\n  }\n}\n\n\nstatic int luaB_auxwrap (lua_State *L) {\n  lua_State *co = lua_tothread(L, lua_upvalueindex(1));\n  int r = auxresume(L, co, lua_gettop(L));\n  if (r < 0) {\n    if (lua_isstring(L, -1)) {  /* error object is a string? */\n      luaL_where(L, 1);  /* add extra info */\n      lua_insert(L, -2);\n      lua_concat(L, 2);\n    }\n    lua_error(L);  /* propagate error */\n  }\n  return r;\n}\n\n\n#ifndef COCO_DISABLE\nstatic int luaB_cstacksize (lua_State *L)\n{\n  lua_pushinteger(L, luaCOCO_cstacksize(luaL_optint(L, 1, -1)));\n  return 1;\n}\n#endif\n\n\nstatic int luaB_cocreate (lua_State *L) {\n#ifdef COCO_DISABLE\n  lua_State *NL = lua_newthread(L);\n  luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,\n    \"Lua function expected\");\n#else\n  int cstacksize = luaL_optint(L, 2, 0);\n  lua_State *NL = lua_newcthread(L, cstacksize);\n  luaL_argcheck(L, lua_isfunction(L, 1) &&\n                   (cstacksize >= 0 ? 1 : !lua_iscfunction(L, 1)),\n                1, \"Lua function expected\");\n#endif\n  lua_pushvalue(L, 1);  /* move function to top */\n  lua_xmove(L, NL, 1);  /* move function from L to NL */\n  return 1;\n}\n\n\nstatic int luaB_cowrap (lua_State *L) {\n  luaB_cocreate(L);\n  lua_pushcclosure(L, luaB_auxwrap, 1);\n  return 1;\n}\n\n\nstatic int luaB_yield (lua_State *L) {\n  return lua_yield(L, lua_gettop(L));\n}\n\n\nstatic int luaB_corunning (lua_State *L) {\n  if (lua_pushthread(L))\n    lua_pushnil(L);  /* main thread is not a coroutine */\n  return 1;\n}\n\n\nstatic const luaL_Reg co_funcs[] = {\n  {\"create\", luaB_cocreate},\n  {\"resume\", luaB_coresume},\n  {\"running\", luaB_corunning},\n  {\"status\", luaB_costatus},\n  {\"wrap\", luaB_cowrap},\n  {\"yield\", luaB_yield},\n#ifndef COCO_DISABLE\n  {\"cstacksize\", luaB_cstacksize},\n#endif\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\nstatic void auxopen (lua_State *L, const char *name,\n                     lua_CFunction f, lua_CFunction u) {\n  lua_pushcfunction(L, u);\n  lua_pushcclosure(L, f, 1);\n  lua_setfield(L, -2, name);\n}\n\n\nstatic void base_open (lua_State *L) {\n  /* set global _G */\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  lua_setglobal(L, \"_G\");\n  /* open lib into global table */\n  luaL_register(L, \"_G\", base_funcs);\n  lua_pushliteral(L, LUA_VERSION);\n  lua_setglobal(L, \"_VERSION\");  /* set global _VERSION */\n  /* `ipairs' and `pairs' need auxliliary functions as upvalues */\n  auxopen(L, \"ipairs\", luaB_ipairs, ipairsaux);\n  auxopen(L, \"pairs\", luaB_pairs, luaB_next);\n  /* `newproxy' needs a weaktable as upvalue */\n  lua_createtable(L, 0, 1);  /* new table `w' */\n  lua_pushvalue(L, -1);  /* `w' will be its own metatable */\n  lua_setmetatable(L, -2);\n  lua_pushliteral(L, \"kv\");\n  lua_setfield(L, -2, \"__mode\");  /* metatable(w).__mode = \"kv\" */\n  lua_pushcclosure(L, luaB_newproxy, 1);\n  lua_setglobal(L, \"newproxy\");  /* set global `newproxy' */\n}\n\n\nLUALIB_API int luaopen_base (lua_State *L) {\n  base_open(L);\n  luaL_register(L, LUA_COLIBNAME, co_funcs);\n#ifndef COCO_DISABLE\n  lua_pushboolean(L, 1); \n  lua_setfield(L, -2, \"coco\");\n#endif\n  return 2;\n}\n\n"
  },
  {
    "path": "src/lcoco.c",
    "content": "/*\n** Copyright (C) 2004-2012 Mike Pall. All rights reserved.\n**\n** Permission is hereby granted, free of charge, to any person obtaining\n** a copy of this software and associated documentation files (the\n** \"Software\"), to deal in the Software without restriction, including\n** without limitation the rights to use, copy, modify, merge, publish,\n** distribute, sublicense, and/or sell copies of the Software, and to\n** permit persons to whom the Software is furnished to do so, subject to\n** the following conditions:\n**\n** The above copyright notice and this permission notice shall be\n** included in all copies or substantial portions of the Software.\n**\n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n**\n** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]\n*/\n\n/* Coco -- True C coroutines for Lua. http://luajit.org/coco.html */\n#ifndef COCO_DISABLE\n\n#define lcoco_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"ldo.h\"\n#include \"lvm.h\"\n#include \"lgc.h\"\n\n\n/*\n** Define this if you want to run Coco with valgrind. You will get random\n** errors about accessing memory from newly allocated C stacks if you don't.\n** You need at least valgrind 3.0 for this to work.\n**\n** This macro evaluates to a no-op if not run with valgrind. I.e. you can\n** use the same binary for regular runs, too (without a performance loss).\n*/\n#ifdef USE_VALGRIND\n#include <valgrind/valgrind.h>\n#define STACK_REG(coco, p, sz)\t(coco)->vgid = VALGRIND_STACK_REGISTER(p, p+sz);\n#define STACK_DEREG(coco)\tVALGRIND_STACK_DEREGISTER((coco)->vgid);\n#define STACK_VGID\t\tunsigned int vgid;\n#else\n#define STACK_REG(coco, p, sz)\n#define STACK_DEREG(id)\n#define STACK_VGID\n#endif\n\n/* ------------------------------------------------------------------------ */\n\n/* Use Windows Fibers. */\n#if defined(COCO_USE_FIBERS)\n\n#define _WIN32_WINNT 0x0400\n#include <windows.h>\n\n#define COCO_MAIN_DECL\t\tCALLBACK\n\ntypedef LPFIBER_START_ROUTINE coco_MainFunc;\n\n#define COCO_NEW(OL, NL, cstacksize, mainfunc) \\\n  if ((L2COCO(NL)->fib = CreateFiber(cstacksize, mainfunc, NL)) == NULL) \\\n    luaD_throw(OL, LUA_ERRMEM);\n\n#define COCO_FREE(L) \\\n  DeleteFiber(L2COCO(L)->fib); \\\n  L2COCO(L)->fib = NULL;\n\n/* See: http://blogs.msdn.com/oldnewthing/archive/2004/12/31/344799.aspx */\n#define COCO_JUMPIN(coco) \\\n  { void *cur = GetCurrentFiber(); \\\n    coco->back = (cur == NULL || cur == (void *)0x1e00) ? \\\n      ConvertThreadToFiber(NULL) : cur; } \\\n  SwitchToFiber(coco->fib);\n\n#define COCO_JUMPOUT(coco) \\\n  SwitchToFiber(coco->back);\n\n/* CreateFiber() defaults to STACKSIZE from the Windows module .def file. */\n#define COCO_DEFAULT_CSTACKSIZE\t\t0\n\n/* ------------------------------------------------------------------------ */\n\n#else /* !COCO_USE_FIBERS */\n\n#ifndef COCO_USE_UCONTEXT\n\n/* Try inline asm first. */\n#if __GNUC__ >= 3 && !defined(COCO_USE_SETJMP)\n\n#if defined(__i386) || defined(__i386__)\n\n#ifdef __PIC__\ntypedef void *coco_ctx[4];  /* eip, esp, ebp, ebx */\nstatic inline void coco_switch(coco_ctx from, coco_ctx to)\n{\n  __asm__ __volatile__ (\n    \"call 1f\\n\" \"1:\\tpopl %%eax\\n\\t\" \"addl $(2f-1b),%%eax\\n\\t\"\n    \"movl %%eax, (%0)\\n\\t\" \"movl %%esp, 4(%0)\\n\\t\"\n    \"movl %%ebp, 8(%0)\\n\\t\" \"movl %%ebx, 12(%0)\\n\\t\"\n    \"movl 12(%1), %%ebx\\n\\t\" \"movl 8(%1), %%ebp\\n\\t\"\n    \"movl 4(%1), %%esp\\n\\t\" \"jmp *(%1)\\n\" \"2:\\n\"\n    : \"+S\" (from), \"+D\" (to) : : \"eax\", \"ecx\", \"edx\", \"memory\", \"cc\");\n}\n#else\ntypedef void *coco_ctx[3];  /* eip, esp, ebp */\nstatic inline void coco_switch(coco_ctx from, coco_ctx to)\n{\n  __asm__ __volatile__ (\n    \"movl $1f, (%0)\\n\\t\" \"movl %%esp, 4(%0)\\n\\t\" \"movl %%ebp, 8(%0)\\n\\t\"\n    \"movl 8(%1), %%ebp\\n\\t\" \"movl 4(%1), %%esp\\n\\t\" \"jmp *(%1)\\n\" \"1:\\n\"\n    : \"+S\" (from), \"+D\" (to) : : \"eax\", \"ebx\", \"ecx\", \"edx\", \"memory\", \"cc\");\n}\n#endif\n\n#define COCO_CTX\t\tcoco_ctx\n#define COCO_SWITCH(from, to)\tcoco_switch(from, to);\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  buf[0] = (void *)(func); \\\n  buf[1] = (void *)(stack); \\\n  buf[2] = (void *)0; \\\n  stack[0] = 0xdeadc0c0;  /* Dummy return address. */ \\\n  coco->arg0 = (size_t)(a0);\n#define COCO_STATE_HEAD\t\tsize_t arg0;\n\n#elif defined(__x86_64__)\n\nstatic void coco_wrap_main(void)\n{\n  __asm__ __volatile__ (\"\\tmovq %r13, %rdi\\n\\tjmpq *%r12\\n\");\n}\n\ntypedef void *coco_ctx[8];  /* rip, rsp, rbp, rbx, r12, r13, r14, r15 */\nstatic inline void coco_switch(coco_ctx from, coco_ctx to)\n{\n  __asm__ __volatile__ (\n    \"leaq 1f(%%rip), %%rax\\n\\t\"\n    \"movq %%rax, (%0)\\n\\t\" \"movq %%rsp, 8(%0)\\n\\t\" \"movq %%rbp, 16(%0)\\n\\t\"\n    \"movq %%rbx, 24(%0)\\n\\t\" \"movq %%r12, 32(%0)\\n\\t\" \"movq %%r13, 40(%0)\\n\\t\"\n    \"movq %%r14, 48(%0)\\n\\t\" \"movq %%r15, 56(%0)\\n\\t\"\n    \"movq 56(%1), %%r15\\n\\t\" \"movq 48(%1), %%r14\\n\\t\" \"movq 40(%1), %%r13\\n\\t\"\n    \"movq 32(%1), %%r12\\n\\t\" \"movq 24(%1), %%rbx\\n\\t\" \"movq 16(%1), %%rbp\\n\\t\"\n    \"movq 8(%1), %%rsp\\n\\t\" \"jmpq *(%1)\\n\" \"1:\\n\"\n    : \"+S\" (from), \"+D\" (to) :\n    : \"rax\", \"rcx\", \"rdx\", \"r8\", \"r9\", \"r10\", \"r11\", \"memory\", \"cc\");\n}\n\n#define COCO_CTX\t\tcoco_ctx\n#define COCO_SWITCH(from, to)\tcoco_switch(from, to);\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  buf[0] = (void *)(coco_wrap_main); \\\n  buf[1] = (void *)(stack); \\\n  buf[2] = (void *)0; \\\n  buf[3] = (void *)0; \\\n  buf[4] = (void *)(func); \\\n  buf[5] = (void *)(a0); \\\n  buf[6] = (void *)0; \\\n  buf[7] = (void *)0; \\\n  stack[0] = 0xdeadc0c0deadc0c0;  /* Dummy return address. */ \\\n\n#elif defined(__arm__)\n\ntypedef void *coco_ctx[1];  /* sp */\nstatic inline void coco_switch(coco_ctx from, coco_ctx to)\n{\n  __asm__ __volatile__ (\n\t\t\"adr lr, 1f\\n\\t\"\n    \"push {r0, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}\\n\\t\"\n\t\t\"str sp, [%0]\\n\\t\"\n\t\t\"ldr sp, [%1]\\n\\t\"\n    \"pop {r0, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}\\n\\t\"\n\t\t\"mov pc, lr\\n\\t\"\n\t\t\"1:\\n\\t\"\n    : : \"r\" (from), \"r\" (to)\n    : \"r1\", \"r2\", \"r3\", \"lr\", \"memory\", \"cc\");\n}\n\n#define COCO_STACKADJUST\t12\n#define COCO_CTX\t\tcoco_ctx\n#define COCO_SWITCH(from, to)\tcoco_switch(from, to);\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  buf[0] = (void *)(stack); \\\n  stack[0] = (size_t)(a0); \\\n  stack[1] = 0; \\\n  stack[2] = 0; \\\n  stack[3] = 0; \\\n  stack[4] = 0; \\\n  stack[5] = 0; \\\n  stack[6] = 0; \\\n  stack[7] = 0; \\\n  stack[8] = 0; \\\n  stack[9] = 0; \\\n  stack[10]= (size_t)(func); \\\n  stack[11]= 0xdeadc0c0;  /* Dummy return address. */\n\n#elif __mips && !defined(__mips_eabi) && \\\n      ((defined(_ABIO32) && _MIPS_SIM == _ABIO32) || \\\n       (defined(_MIPS_SIM_ABI32) && _MIPS_SIM == _MIPS_SIM_ABI32))\n\n/* No way to avoid the function prologue with inline assembler. So use this: */\nstatic const unsigned int coco_switch[] = {\n#ifdef __mips_soft_float\n#define COCO_STACKSAVE\t\t-10\n  0x27bdffd8,  /* addiu sp, sp, -(10*4) */\n#else\n#define COCO_STACKSAVE\t\t-22\n  0x27bdffa8,  /* addiu sp, sp, -(10*4+6*8) */\n  /* sdc1 {$f20-$f30}, offset(sp) */\n  0xf7be0050, 0xf7bc0048, 0xf7ba0040, 0xf7b80038, 0xf7b60030, 0xf7b40028,\n#endif\n  /* sw {gp,s0-s8}, offset(sp) */\n  0xafbe0024, 0xafb70020, 0xafb6001c, 0xafb50018, 0xafb40014, 0xafb30010,\n  0xafb2000c, 0xafb10008, 0xafb00004, 0xafbc0000,\n  /* sw sp, 4(a0); sw ra, 0(a0); lw ra, 0(a1); lw sp, 4(a1); move t9, ra */\n  0xac9d0004, 0xac9f0000, 0x8cbf0000, 0x8cbd0004, 0x03e0c821,\n  /* lw caller-saved-reg, offset(sp) */\n  0x8fbe0024, 0x8fb70020, 0x8fb6001c, 0x8fb50018, 0x8fb40014, 0x8fb30010,\n  0x8fb2000c, 0x8fb10008, 0x8fb00004, 0x8fbc0000,\n#ifdef __mips_soft_float\n  0x03e00008, 0x27bd0028  /* jr ra; addiu sp, sp, 10*4 */\n#else\n  /* ldc1 {$f20-$f30}, offset(sp) */\n  0xd7be0050, 0xd7bc0048, 0xd7ba0040, 0xd7b80038, 0xd7b60030, 0xd7b40028,\n  0x03e00008, 0x27bd0058  /* jr ra; addiu sp, sp, 10*4+6*8 */\n#endif\n};\n\ntypedef void *coco_ctx[2];  /* ra, sp */\n#define COCO_CTX\t\tcoco_ctx\n#define COCO_SWITCH(from, to) \\\n  ((void (*)(coco_ctx, coco_ctx))coco_switch)(from, to);\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  buf[0] = (void *)(func); \\\n  buf[1] = (void *)&stack[COCO_STACKSAVE]; \\\n  stack[4] = (size_t)(a0);  /* Assumes o32 ABI. */\n#define COCO_STACKADJUST\t8\n#define COCO_MAIN_PARAM\t\tint _a, int _b, int _c, int _d, lua_State *L\n\n#elif defined(__sparc__)\n\ntypedef void *coco_ctx[4];\n#define COCO_CTX\t\tcoco_ctx\n#define COCO_SWITCH(from, to)\tcoco_switch(from, to);\n#define COCO_STACKADJUST\t24\n\n#if defined(__LP64__)\n#define COCO_STACKBIAS\t\t(2047UL)\n#define COCO_PTR2SP(stack)\t(((unsigned long)stack)-COCO_STACKBIAS)\nstatic inline void coco_switch(coco_ctx from, coco_ctx to)\n{\n  void *__stack[16] __attribute__((aligned (16)));\n  unsigned long __tmp_sp = COCO_PTR2SP(__stack);\n  __asm__ __volatile__\n    (/* Flush register window(s) to stack and save the previous stack\n\tpointer to capture the current registers, %l0-%l7 and %i0-%i7. */\n     \"ta 3\\n\\t\"\n     \"stx %%sp,[%0+8]\\n\\t\"\n     /* Move to a temporary stack. If the register window is flushed\n\tfor some reason (e.g. context switch), not the next stack\n\tbut the temporary stack should be used so as not to break\n\tneither the previous nor next stack */\n     \"mov %2,%%sp\\n\\t\"\n     \"sethi %%hh(1f),%%g1\\n\\t\"\t\t/* i.e. setx 1f,%%g1 */\n     \"or %%g1,%%hm(1f),%%g1\\n\\t\"\n     \"sethi %%lm(1f),%%g2\\n\\t\"\n     \"or %%g2,%%lo(1f),%%g2\\n\\t\"\n     \"sllx %%g1,32,%%g1\\n\\t\"\n     \"or %%g1,%%g2,%%g1\\n\\t\"\n     \"stx %%g1,[%0]\\n\\t\"\n     /* Restore registers from stack. DO NOT load the next stack\n\tpointer directly to %sp. The register window can be possibly\n\tflushed and restored asynchronous (e.g. context switch). */\n     \"mov %1,%%o1\\n\\t\"\n     \"ldx [%%o1+8],%%o2\\n\\t\"\n     \"ldx [%%o2+%3],%%l0\\n\\t\"\n     \"ldx [%%o2+%3+8],%%l1\\n\\t\"\n     \"ldx [%%o2+%3+0x10],%%l2\\n\\t\"\n     \"ldx [%%o2+%3+0x18],%%l3\\n\\t\"\n     \"ldx [%%o2+%3+0x20],%%l4\\n\\t\"\n     \"ldx [%%o2+%3+0x28],%%l5\\n\\t\"\n     \"ldx [%%o2+%3+0x30],%%l6\\n\\t\"\n     \"ldx [%%o2+%3+0x38],%%l7\\n\\t\"\n     \"ldx [%%o2+%3+0x40],%%i0\\n\\t\"\n     \"ldx [%%o2+%3+0x48],%%i1\\n\\t\"\n     \"ldx [%%o2+%3+0x50],%%i2\\n\\t\"\n     \"ldx [%%o2+%3+0x58],%%i3\\n\\t\"\n     \"ldx [%%o2+%3+0x60],%%i4\\n\\t\"\n     \"ldx [%%o2+%3+0x68],%%i5\\n\\t\"\n     \"ldx [%%o2+%3+0x70],%%i6\\n\\t\"\n     \"ldx [%%o2+%3+0x78],%%i7\\n\\t\"\n     /* Move to the next stack with the consistent registers atomically */\n     \"mov %%o2,%%sp\\n\\t\"\n     \"ldx [%%o1],%%o2\\n\\t\"\n     /* Since %o0-%o7 are marked as clobbered, values are safely overwritten\n\tacross the inline assembly.  %o0-%o7 will have meaningless values\n\tafter leaving the inline assembly. The only exception is %o0, which\n\tserves as an argument to coco_main */\n     \"ldx [%%o1+16],%%o0\\n\\t\"\n     \"jmpl %%o2,%%g0\\n\\t\"\n     \"nop\\n\\t\"\n     \"1:\\n\"\n     /* An assumption is made here; no input operand is assigned to %g1\n\tnor %g2. It's the case for the currently avilable gcc's */\n     : : \"r\"(from),\"r\"(to),\"r\"(__tmp_sp),\"i\"(COCO_STACKBIAS)\n     : \"g1\",\"g2\",\"o0\",\"o1\",\"o2\",\"o3\",\"o4\",\"o5\",\"o7\",\"memory\",\"cc\");\n}\n\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  buf[0] = (void *)(func); \\\n  buf[1] = (void *)COCO_PTR2SP(&(stack)[0]); \\\n  buf[2] = (void *)(a0); \\\n  stack[0] = 0; \\\n  stack[1] = 0; \\\n  stack[2] = 0; \\\n  stack[3] = 0; \\\n  stack[4] = 0; \\\n  stack[5] = 0; \\\n  stack[6] = 0; \\\n  stack[7] = 0; \\\n  stack[8] = 0; \\\n  stack[9] = 0; \\\n  stack[10] = 0; \\\n  stack[11] = 0; \\\n  stack[12] = 0; \\\n  stack[13] = 0; \\\n  stack[14] = COCO_PTR2SP(&(stack)[COCO_STACKADJUST]); \\\n  stack[15] = 0xdeadc0c0deadc0c0; /* Dummy return address. */ \\\n\n#else\nstatic inline void coco_switch(coco_ctx from, coco_ctx to)\n{\n  void *__tmp_stack[16] __attribute__((aligned (16)));\n  __asm__ __volatile__ \n    (\"ta 3\\n\\t\"\n     \"st %%sp,[%0+4]\\n\\t\"\n     \"mov %2,%%sp\\n\\t\"\n     \"set 1f,%%g1\\n\\t\"\n     \"st %%g1,[%0]\\n\\t\"\n     \"mov %1,%%o1\\n\\t\"\n     \"ld [%%o1+4],%%o2\\n\\t\"\n     \"ldd [%%o2],%%l0\\n\\t\"\n     \"ldd [%%o2+8],%%l2\\n\\t\"\n     \"ldd [%%o2+0x10],%%l4\\n\\t\"\n     \"ldd [%%o2+0x18],%%l6\\n\\t\"\n     \"ldd [%%o2+0x20],%%i0\\n\\t\"\n     \"ldd [%%o2+0x28],%%i2\\n\\t\"\n     \"ldd [%%o2+0x30],%%i4\\n\\t\"\n     \"ldd [%%o2+0x38],%%i6\\n\\t\"\n     \"mov %%o2,%%sp\\n\\t\"\n     \"ld [%%o1],%%o2\\n\\t\"\n     \"ld [%%o1+8],%%o0\\n\\t\"\n     \"jmpl %%o2,%%g0\\n\\t\"\n     \"nop\\n\\t\"\n     \"1:\\n\"\n     : : \"r\"(from),\"r\"(to),\"r\"(__tmp_stack)\n     : \"g1\",\"o0\",\"o1\",\"o2\",\"o3\",\"o4\",\"o5\",\"o7\",\"memory\",\"cc\");\n}\n\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  buf[0] = (void *)(func); \\\n  buf[1] = (void *)(stack); \\\n  buf[2] = (void *)(a0); \\\n  stack[0] = 0; \\\n  stack[1] = 0; \\\n  stack[2] = 0; \\\n  stack[3] = 0; \\\n  stack[4] = 0; \\\n  stack[5] = 0; \\\n  stack[6] = 0; \\\n  stack[7] = 0; \\\n  stack[8] = 0; \\\n  stack[9] = 0; \\\n  stack[10] = 0; \\\n  stack[11] = 0; \\\n  stack[12] = 0; \\\n  stack[13] = 0; \\\n  stack[14] = (size_t)&stack[COCO_STACKADJUST]; \\\n  stack[15] = 0xdeadc0c0; /* Dummy return address. */ \\\n\n#endif /* !define(__LP64__) */\n\n#endif /* arch check */\n\n#endif /* !(__GNUC__ >= 3 && !defined(COCO_USE_SETJMP)) */\n\n/* Try _setjmp/_longjmp with a patched jump buffer. */\n#ifndef COCO_MAKECTX\n#include <setjmp.h>\n\n/* Check for supported CPU+OS combinations. */\n#if defined(__i386) || defined(__i386__)\n\n#define COCO_STATE_HEAD\t\tsize_t arg0;\n#define COCO_SETJMP_X86(coco, stack, a0) \\\n  stack[COCO_STACKADJUST-1] = 0xdeadc0c0;  /* Dummy return address. */ \\\n  coco->arg0 = (size_t)(a0);\n\n#if __GLIBC__ == 2 && defined(JB_SP)\t\t/* x86-linux-glibc2 */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf->__jmpbuf[JB_PC] = (int)(func); \\\n  buf->__jmpbuf[JB_SP] = (int)(stack); \\\n  buf->__jmpbuf[JB_BP] = 0; \\\n  COCO_SETJMP_X86(coco, stack, a0)\n#elif defined(__linux__) && defined(_I386_JMP_BUF_H)\t/* x86-linux-libc5 */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf->__pc = (func); \\\n  buf->__sp = (stack); \\\n  buf->__bp = NULL; \\\n  COCO_SETJMP_X86(coco, stack, a0)\n#elif defined(__FreeBSD__)\t\t\t/* x86-FreeBSD */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf->_jb[0] = (long)(func); \\\n  buf->_jb[2] = (long)(stack); \\\n  buf->_jb[3] = 0; /* ebp */ \\\n  COCO_SETJMP_X86(coco, stack, a0)\n#define COCO_STACKADJUST\t2\n#elif defined(__NetBSD__) || defined(__OpenBSD__) /* x86-NetBSD, x86-OpenBSD */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf[0] = (long)(func); \\\n  buf[2] = (long)(stack); \\\n  buf[3] = 0; /* ebp */ \\\n  COCO_SETJMP_X86(coco, stack, a0)\n#define COCO_STACKADJUST\t2\n#elif defined(__solaris__) && _JBLEN == 10\t/* x86-solaris */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf[5] = (int)(func); \\\n  buf[4] = (int)(stack); \\\n  buf[3] = 0; \\\n  COCO_SETJMP_X86(coco, stack, a0)\n#elif defined(__MACH__) && defined(_BSD_I386_SETJMP_H)\t/* x86-macosx */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf[12] = (int)(func); \\\n  buf[9] = (int)(stack); \\\n  buf[8] = 0; /* ebp */ \\\n  COCO_SETJMP_X86(coco, stack, a0)\n#endif\n\n#elif defined(__x86_64__) || defined(__x86_64)\n\n#define COCO_STATE_HEAD\t\tsize_t arg0;\n\n#define COCO_MAIN_PARAM \\\n  int _a, int _b, int _c, int _d, int _e, int _f, lua_State *L\n\n#if defined(__solaris__) && _JBLEN == 8\t\t\t/* x64-solaris */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf[7] = (long)(func); \\\n  buf[6] = (long)(stack); \\\n  buf[5] = 0; \\\n  stack[0] = 0xdeadc0c0;  /* Dummy return address. */ \\\n  coco->arg0 = (size_t)(a0);\n#endif\n\n#elif defined(PPC) || defined(__ppc__) || defined(__PPC__) || \\\n      defined(__powerpc__) || defined(__POWERPC__) || defined(_ARCH_PPC)\n\n#define COCO_STACKADJUST\t16\n#define COCO_MAIN_PARAM \\\n  int _a, int _b, int _c, int _d, int _e, int _f, int _g, int _h, lua_State *L\n\n#if defined(__MACH__) && defined(_BSD_PPC_SETJMP_H_)\t/* ppc32-macosx */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf[21] = (int)(func); \\\n  buf[0] = (int)(stack); \\\n  stack[6+8] = (size_t)(a0);\n#endif\n\n#elif (defined(MIPS) || defined(MIPSEL) || defined(__mips)) && \\\n  _MIPS_SIM == _MIPS_SIM_ABI32 && !defined(__mips_eabi)\n\n/* Stack layout for o32 ABI. */\n#define COCO_STACKADJUST\t8\n#define COCO_MAIN_PARAM\t\tint _a, int _b, int _c, int _d, lua_State *L\n\n#if __GLIBC__ == 2 || defined(__UCLIBC__)\t/* mips32-linux-glibc2 */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf->__jmpbuf->__pc = (func); /* = t9 in _longjmp. Reqd. for -mabicalls. */ \\\n  buf->__jmpbuf->__sp = (stack); \\\n  buf->__jmpbuf->__fp = (void *)0; \\\n  stack[4] = (size_t)(a0);\n#endif\n\n#elif defined(__arm__) || defined(__ARM__)\n\n#if __GLIBC__ == 2 || defined(__UCLIBC__)\t/* arm-linux-glibc2 */\n#if defined(__ARM_EABI__)\n#define __JMP_BUF_SP\t8\n#endif\n#ifndef __JMP_BUF_SP\n#define __JMP_BUF_SP\t((sizeof(__jmp_buf)/sizeof(int))-2)\n#endif\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf->__jmpbuf[__JMP_BUF_SP+1] = (int)(func); /* pc */ \\\n  buf->__jmpbuf[__JMP_BUF_SP] = (int)(stack); /* sp */ \\\n  buf->__jmpbuf[__JMP_BUF_SP-1] = 0; /* fp */ \\\n  stack[0] = (size_t)(a0);\n#define COCO_STACKADJUST\t2\n#define COCO_MAIN_PARAM\t\tint _a, int _b, int _c, int _d, lua_State *L\n#elif defined(__APPLE__)\t/* arm-ios */\n#define __JMP_BUF_SP  7   /* r4 r5 r6 r7 r8 r10 fp sp lr sig ... */\n#define COCO_PATCHCTX(coco, buf, func, stack, a0) \\\n  buf[__JMP_BUF_SP+1] = (int)(func); /* lr */ \\\n  buf[__JMP_BUF_SP] = (int)(stack); /* sp */ \\\n  buf[__JMP_BUF_SP-1] = 0; /* fp */ \\\n  stack[0] = (size_t)(a0);\n#define COCO_STACKADJUST 2\n#define COCO_MAIN_PARAM int _a, int _b, int _c, int _d, lua_State *L\n#endif\n\n#endif /* arch check */\n\n#ifdef COCO_PATCHCTX\n#define COCO_CTX\t\tjmp_buf\n#define COCO_MAKECTX(coco, buf, func, stack, a0) \\\n  _setjmp(buf); COCO_PATCHCTX(coco, buf, func, stack, a0)\n#define COCO_SWITCH(from, to)\tif (!_setjmp(from)) _longjmp(to, 1);\n#endif\n\n#endif /* !defined(COCO_MAKECTX) */\n\n#endif /* !defined(COCO_USE_UCONTEXT) */\n\n/* ------------------------------------------------------------------------ */\n\n/* Use inline asm or _setjmp/_longjmp if available. */\n#ifdef COCO_MAKECTX\n\n#ifndef COCO_STACKADJUST\n#define COCO_STACKADJUST\t1\n#endif\n\n#define COCO_FILL(coco, NL, mainfunc) \\\n{ /* Include the return address to get proper stack alignment. */ \\\n  size_t *stackptr = &((size_t *)coco)[-COCO_STACKADJUST]; \\\n  COCO_MAKECTX(coco, coco->ctx, mainfunc, stackptr, NL) \\\n}\n\n/* ------------------------------------------------------------------------ */\n\n/* Else fallback to ucontext. Slower, because it saves/restores signals. */\n#else /* !defined(COCO_MAKECTX) */\n\n#include <ucontext.h>\n\n#define COCO_CTX\t\tucontext_t\n\n/* Ugly workaround for makecontext() deficiencies on 64 bit CPUs. */\n/* Note that WIN64 (which is LLP64) never comes here. See above. */\n#if defined(__LP64__) || defined(_LP64) || INT_MAX != LONG_MAX\n/* 64 bit CPU: split the pointer into two 32 bit ints. */\n#undef COCO_MAIN_PARAM\n#define COCO_MAIN_PARAM\t\tunsigned int lo, unsigned int hi\n#define COCO_MAIN_GETL \\\n  lua_State *L = (lua_State *)((((unsigned long)hi)<<32)+(unsigned long)lo);\n#define COCO_MAKECTX(coco, NL, mainfunc) \\\n  makecontext(&coco->ctx, mainfunc, 2, \\\n    (int)(ptrdiff_t)NL, (int)((ptrdiff_t)NL>>32));\n#else\n/* 32 bit CPU: a pointer fits into an int. */\n#define COCO_MAKECTX(coco, NL, mainfunc) \\\n  makecontext(&coco->ctx, mainfunc, 1, (int)NL);\n#endif\n\n#define COCO_FILL(coco, NL, mainfunc) \\\n  if(getcontext(&coco->ctx) < 0) { \\\n    luaL_error(OL, \"getcontext() failed!  ucontext is broken on this system.\"); \\\n    return NULL; \\\n  } \\\n  coco->ctx.uc_link = NULL;  /* We never exit from coco_main. */ \\\n  coco->ctx.uc_stack.ss_sp = coco->allocptr; \\\n  coco->ctx.uc_stack.ss_size = (char *)coco - (char *)(coco->allocptr); \\\n  COCO_MAKECTX(coco, NL, mainfunc)\n\n#define COCO_SWITCH(from, to)\tswapcontext(&(from), &(to));\n\n#endif /* !defined(COCO_MAKECTX) */\n\n\n/* Common code for inline asm/setjmp/ucontext to allocate/free the stack. */\n\nstruct coco_State {\n#ifdef COCO_STATE_HEAD\n  COCO_STATE_HEAD\n#endif\n  COCO_CTX ctx;\t\t\t/* Own context. */\n  COCO_CTX back;\t\t/* Context to switch back to. */\n  void *allocptr;\t\t/* Pointer to allocated memory. */\n  int allocsize;\t\t/* Size of allocated memory. */\n  int nargs;\t\t\t/* Number of arguments to pass. */\n  STACK_VGID\t\t\t/* Optional valgrind stack id. See above. */\n};\n\ntypedef void (*coco_MainFunc)(void);\n\n/* Put the Coco state at the end and align it downwards. */\n#define ALIGNED_END(p, s, t) \\\n  ((t *)(((char *)0) + ((((char *)(p)-(char *)0)+(s)-sizeof(t)) & -16)))\n\n/* TODO: use mmap. */\n#define COCO_NEW(OL, NL, cstacksize, mainfunc) \\\n{ \\\n  void *ptr = luaM_malloc(OL, cstacksize); \\\n  coco_State *coco = ALIGNED_END(ptr, cstacksize, coco_State); \\\n  STACK_REG(coco, ptr, cstacksize) \\\n  coco->allocptr = ptr; \\\n  coco->allocsize = cstacksize; \\\n  COCO_FILL(coco, NL, mainfunc) \\\n  L2COCO(NL) = coco; \\\n}\n\n#define COCO_FREE(L) \\\n  STACK_DEREG(L2COCO(L)) \\\n  luaM_freemem(L, L2COCO(L)->allocptr, L2COCO(L)->allocsize); \\\n  L2COCO(L) = NULL;\n\n#define COCO_JUMPIN(coco)\tCOCO_SWITCH(coco->back, coco->ctx)\n#define COCO_JUMPOUT(coco)\tCOCO_SWITCH(coco->ctx, coco->back)\n\n#endif /* !COCO_USE_FIBERS */\n\n/* ------------------------------------------------------------------------ */\n\n#ifndef COCO_MIN_CSTACKSIZE\n#define COCO_MIN_CSTACKSIZE\t\t(32768+4096)\n#endif\n\n/* Don't use multiples of 64K to avoid D-cache aliasing conflicts. */\n#ifndef COCO_DEFAULT_CSTACKSIZE\n#define COCO_DEFAULT_CSTACKSIZE\t\t(65536-4096)\n#endif\n\nstatic int defaultcstacksize = COCO_DEFAULT_CSTACKSIZE;\n\n/* Start the Lua or C function. */\nstatic void coco_start(lua_State *L, void *ud)\n{\n  if (luaD_precall(L, (StkId)ud, LUA_MULTRET) == PCRLUA)\n    luaV_execute(L, L->ci - L->base_ci);\n}\n\n#ifndef COCO_MAIN_PARAM\n#define COCO_MAIN_PARAM\t\tlua_State *L\n#endif\n\n#ifndef COCO_MAIN_DECL\n#define COCO_MAIN_DECL\n#endif\n\n/* Toplevel function for the new coroutine stack. Never exits. */\nstatic void COCO_MAIN_DECL coco_main(COCO_MAIN_PARAM)\n{\n#ifdef COCO_MAIN_GETL\n  COCO_MAIN_GETL\n#endif\n  coco_State *coco = L2COCO(L);\n  for (;;) {\n    L->status = luaD_rawrunprotected(L, coco_start, L->top - (coco->nargs+1));\n    if (L->status != 0) luaD_seterrorobj(L, L->status, L->top);\n    COCO_JUMPOUT(coco)\n  }\n}\n\n/* Add a C stack to a coroutine. */\nlua_State *lua_newcthread(lua_State *OL, int cstacksize)\n{\n  lua_State *NL = lua_newthread(OL);\n\n  if (cstacksize < 0)\n    return NL;\n  if (cstacksize == 0)\n    cstacksize = defaultcstacksize;\n  else if (cstacksize < COCO_MIN_CSTACKSIZE)\n    cstacksize = COCO_MIN_CSTACKSIZE;\n  cstacksize &= -16;\n\n  COCO_NEW(OL, NL, cstacksize, ((coco_MainFunc)(coco_main)))\n\n  return NL;\n}\n\n/* Free the C stack of a coroutine. Called from lstate.c. */\nvoid luaCOCO_free(lua_State *L)\n{\n  COCO_FREE(L)\n}\n\n/* Resume a coroutine with a C stack. Called from ldo.c. */\nint luaCOCO_resume(lua_State *L, int nargs)\n{\n  coco_State *coco = L2COCO(L);\n  coco->nargs = nargs;\n  COCO_JUMPIN(coco)\n#ifndef COCO_DISABLE_EARLY_FREE\n  if (L->status != LUA_YIELD) {\n    COCO_FREE(L)\n  }\n#endif\n  return L->status;\n}\n\n/* Yield from a coroutine with a C stack. Called from ldo.c. */\nint luaCOCO_yield(lua_State *L)\n{\n  coco_State *coco = L2COCO(L);\n  L->status = LUA_YIELD;\n  COCO_JUMPOUT(coco)\n  L->status = 0;\n  {\n    StkId base = L->top - coco->nargs;\n    StkId rbase = L->base;\n    if (rbase < base) {  /* Need to move args down? */\n      while (base < L->top)\n\tsetobjs2s(L, rbase++, base++);\n      L->top = rbase;\n    }\n  }\n  L->base = L->ci->base;  /* Restore invariant. */\n  return coco->nargs;\n}\n\n/* Get/set the default C stack size. */\nint luaCOCO_cstacksize(int cstacksize)\n{\n  int oldsz = defaultcstacksize;\n  if (cstacksize >= 0) {\n    if (cstacksize == 0)\n      cstacksize = COCO_DEFAULT_CSTACKSIZE;\n    else if (cstacksize < COCO_MIN_CSTACKSIZE)\n      cstacksize = COCO_MIN_CSTACKSIZE;\n    defaultcstacksize = cstacksize;\n  }\n  return oldsz;\n}\n\nint luaCOCO_mainthread(lua_State *L) {\n  return (G(L)->mainthread == L);\n}\n\n#endif\n"
  },
  {
    "path": "src/lcoco.h",
    "content": "/*\n** Lua/Coco glue.\n** Copyright (C) 2004-2012 Mike Pall. See copyright notice in lcoco.c\n*/\n\n#ifndef lcoco_h\n#define lcoco_h\n\n#define LUACOCO_VERSION\t\t\"Coco 1.1.7\"\n#define LUACOCO_VERSION_NUM\t10107\n\n/* Exported C API to add a C stack to a coroutine. */\nLUA_API lua_State *lua_newcthread(lua_State *L, int cstacksize);\n\n/* Internal support routines. */\nLUAI_FUNC void luaCOCO_free(lua_State *L);\nLUAI_FUNC int luaCOCO_resume(lua_State *L, int nargs);\nLUAI_FUNC int luaCOCO_yield(lua_State *L);\nLUAI_FUNC int luaCOCO_cstacksize(int cstacksize);\nLUAI_FUNC int luaCOCO_mainthread(lua_State *L);\n\n/* Forward declaration. */\ntypedef struct coco_State coco_State;\n\n/* These are redefined below. */\n#undef LUAI_EXTRASPACE\n#undef luai_userstateopen\n/* luai_userstateclose unused */\n#undef luai_userstatethread\n#undef luai_userstatefree\n#undef luai_userstateresume\n#undef luai_userstateyield\n\n/* Use Windows Fibers (Win98+). */\n#if defined(_WIN32)\n\n/* Fibers allocate their own stack. The whole Coco state is in front of L. */\nstruct coco_State {\n  void *fib;\t\t\t/* Own fiber (if any). */\n  void *back;\t\t\t/* Fiber to switch back to. */\n  int nargs;\t\t\t/* Number of arguments to pass. */\n  int dummy_align;\n};\n\n#define L2COCO(L)\t\t(&((coco_State *)(L))[-1])\n#define LHASCOCO(L)\t\t(L2COCO(L)->fib)\n#define LUAI_EXTRASPACE\t\tsizeof(coco_State)\n#define luai_userstateopen(L)\tL2COCO(L)->fib = NULL\n#define luai_userstatethread(L,L1)\tL2COCO(L1)->fib = NULL\n#define COCO_USE_FIBERS\n\n#else /* !defined(_WIN32) */\n\n#include \"llimits.h\"\n\n/* The Coco state depends on the context switch method used. See lcoco.c. */\n/* It's stored at the end of the stack. Only need a pointer in front of L. */\n#define L2COCO(L)\t\t(((coco_State **)(L))[-1])\n#define LHASCOCO(L)\t\t(L2COCO(L))\n/* This wastes some space on 32 bit systems, but gets better alignment. */\n#define LUAI_EXTRASPACE\t\tsizeof(L_Umaxalign)\n#define luai_userstateopen(L)\tL2COCO(L) = NULL\n#define luai_userstatethread(L,L1)\tL2COCO(L1) = NULL\n\n#endif /* !defined(_WIN32) */\n\n#define luai_userstatefree(L)\tif (LHASCOCO(L)) luaCOCO_free(L)\n#define luai_userstateresume(L, nargs) \\\n  if (LHASCOCO(L)) return luaCOCO_resume(L, nargs)\n#define luai_userstateyield(L, nresults) \\\n  do { if (LHASCOCO(L)) { \\\n    L->base = L->top - (nresults);  /* Protect stack slots below. */ \\\n    return luaCOCO_yield(L); } } while (0)\n\n#endif\n"
  },
  {
    "path": "src/lcode.c",
    "content": "/*\n** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdlib.h>\n\n#define lcode_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"ltable.h\"\n\n\n#define hasjumps(e)\t((e)->t != (e)->f)\n\n\nstatic int isnumeral(expdesc *e) {\n  return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);\n}\n\n\nvoid luaK_nil (FuncState *fs, int from, int n) {\n  Instruction *previous;\n  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */\n    if (fs->pc == 0) {  /* function start? */\n      if (from >= fs->nactvar)\n        return;  /* positions are already clean */\n    }\n    else {\n      previous = &fs->f->code[fs->pc-1];\n      if (GET_OPCODE(*previous) == OP_LOADNIL) {\n        int pfrom = GETARG_A(*previous);\n        int pto = GETARG_B(*previous);\n        if (pfrom <= from && from <= pto+1) {  /* can connect both? */\n          if (from+n-1 > pto)\n            SETARG_B(*previous, from+n-1);\n          return;\n        }\n      }\n    }\n  }\n  luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0);  /* else no optimization */\n}\n\n\nint luaK_jump (FuncState *fs) {\n  int jpc = fs->jpc;  /* save list of jumps to here */\n  int j;\n  fs->jpc = NO_JUMP;\n  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);\n  luaK_concat(fs, &j, jpc);  /* keep them on hold */\n  return j;\n}\n\n\nvoid luaK_ret (FuncState *fs, int first, int nret) {\n  luaK_codeABC(fs, OP_RETURN, first, nret+1, 0);\n}\n\n\nstatic int condjump (FuncState *fs, OpCode op, int A, int B, int C) {\n  luaK_codeABC(fs, op, A, B, C);\n  return luaK_jump(fs);\n}\n\n\nstatic void fixjump (FuncState *fs, int pc, int dest) {\n  Instruction *jmp = &fs->f->code[pc];\n  int offset = dest-(pc+1);\n  lua_assert(dest != NO_JUMP);\n  if (abs(offset) > MAXARG_sBx)\n    luaX_syntaxerror(fs->ls, \"control structure too long\");\n  SETARG_sBx(*jmp, offset);\n}\n\n\n/*\n** returns current `pc' and marks it as a jump target (to avoid wrong\n** optimizations with consecutive instructions not in the same basic block).\n*/\nint luaK_getlabel (FuncState *fs) {\n  fs->lasttarget = fs->pc;\n  return fs->pc;\n}\n\n\nstatic int getjump (FuncState *fs, int pc) {\n  int offset = GETARG_sBx(fs->f->code[pc]);\n  if (offset == NO_JUMP)  /* point to itself represents end of list */\n    return NO_JUMP;  /* end of list */\n  else\n    return (pc+1)+offset;  /* turn offset into absolute position */\n}\n\n\nstatic Instruction *getjumpcontrol (FuncState *fs, int pc) {\n  Instruction *pi = &fs->f->code[pc];\n  if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1))))\n    return pi-1;\n  else\n    return pi;\n}\n\n\n/*\n** check whether list has any jump that do not produce a value\n** (or produce an inverted value)\n*/\nstatic int need_value (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list)) {\n    Instruction i = *getjumpcontrol(fs, list);\n    if (GET_OPCODE(i) != OP_TESTSET) return 1;\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int patchtestreg (FuncState *fs, int node, int reg) {\n  Instruction *i = getjumpcontrol(fs, node);\n  if (GET_OPCODE(*i) != OP_TESTSET)\n    return 0;  /* cannot patch other instructions */\n  if (reg != NO_REG && reg != GETARG_B(*i))\n    SETARG_A(*i, reg);\n  else  /* no register to put value or register already has the value */\n    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));\n\n  return 1;\n}\n\n\nstatic void removevalues (FuncState *fs, int list) {\n  for (; list != NO_JUMP; list = getjump(fs, list))\n      patchtestreg(fs, list, NO_REG);\n}\n\n\nstatic void patchlistaux (FuncState *fs, int list, int vtarget, int reg,\n                          int dtarget) {\n  while (list != NO_JUMP) {\n    int next = getjump(fs, list);\n    if (patchtestreg(fs, list, reg))\n      fixjump(fs, list, vtarget);\n    else\n      fixjump(fs, list, dtarget);  /* jump to default target */\n    list = next;\n  }\n}\n\n\nstatic void dischargejpc (FuncState *fs) {\n  patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);\n  fs->jpc = NO_JUMP;\n}\n\n\nvoid luaK_patchlist (FuncState *fs, int list, int target) {\n  if (target == fs->pc)\n    luaK_patchtohere(fs, list);\n  else {\n    lua_assert(target < fs->pc);\n    patchlistaux(fs, list, target, NO_REG, target);\n  }\n}\n\n\nvoid luaK_patchtohere (FuncState *fs, int list) {\n  luaK_getlabel(fs);\n  luaK_concat(fs, &fs->jpc, list);\n}\n\n\nvoid luaK_concat (FuncState *fs, int *l1, int l2) {\n  if (l2 == NO_JUMP) return;\n  else if (*l1 == NO_JUMP)\n    *l1 = l2;\n  else {\n    int list = *l1;\n    int next;\n    while ((next = getjump(fs, list)) != NO_JUMP)  /* find last element */\n      list = next;\n    fixjump(fs, list, l2);\n  }\n}\n\n\nvoid luaK_checkstack (FuncState *fs, int n) {\n  int newstack = fs->freereg + n;\n  if (newstack > fs->f->maxstacksize) {\n    if (newstack >= MAXSTACK)\n      luaX_syntaxerror(fs->ls, \"function or expression too complex\");\n    fs->f->maxstacksize = cast_byte(newstack);\n  }\n}\n\n\nvoid luaK_reserveregs (FuncState *fs, int n) {\n  luaK_checkstack(fs, n);\n  fs->freereg += n;\n}\n\n\nstatic void freereg (FuncState *fs, int reg) {\n  if (!ISK(reg) && reg >= fs->nactvar) {\n    fs->freereg--;\n    lua_assert(reg == fs->freereg);\n  }\n}\n\n\nstatic void freeexp (FuncState *fs, expdesc *e) {\n  if (e->k == VNONRELOC)\n    freereg(fs, e->u.s.info);\n}\n\n\nstatic int addk (FuncState *fs, TValue *k, TValue *v) {\n  lua_State *L = fs->L;\n  TValue *idx = luaH_set(L, fs->h, k);\n  Proto *f = fs->f;\n  int oldsize = f->sizek;\n  if (ttisnumber(idx)) {\n    lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));\n    return cast_int(nvalue(idx));\n  }\n  else {  /* constant not found; create a new entry */\n    setnvalue(idx, cast_num(fs->nk));\n    luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,\n                    MAXARG_Bx, \"constant table overflow\");\n    while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);\n    setobj(L, &f->k[fs->nk], v);\n    luaC_barrier(L, f, v);\n    return fs->nk++;\n  }\n}\n\n\nint luaK_stringK (FuncState *fs, TString *s) {\n  TValue o;\n  setsvalue(fs->L, &o, s);\n  return addk(fs, &o, &o);\n}\n\n\nint luaK_numberK (FuncState *fs, lua_Number r) {\n  TValue o;\n  setnvalue(&o, r);\n  return addk(fs, &o, &o);\n}\n\n\nstatic int boolK (FuncState *fs, int b) {\n  TValue o;\n  setbvalue(&o, b);\n  return addk(fs, &o, &o);\n}\n\n\nstatic int nilK (FuncState *fs) {\n  TValue k, v;\n  setnilvalue(&v);\n  /* cannot use nil as key; instead use table itself to represent nil */\n  sethvalue(fs->L, &k, fs->h);\n  return addk(fs, &k, &v);\n}\n\n\nvoid luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    SETARG_C(getcode(fs, e), nresults+1);\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getcode(fs, e), nresults+1);\n    SETARG_A(getcode(fs, e), fs->freereg);\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nvoid luaK_setoneret (FuncState *fs, expdesc *e) {\n  if (e->k == VCALL) {  /* expression is an open function call? */\n    e->k = VNONRELOC;\n    e->u.s.info = GETARG_A(getcode(fs, e));\n  }\n  else if (e->k == VVARARG) {\n    SETARG_B(getcode(fs, e), 2);\n    e->k = VRELOCABLE;  /* can relocate its simple result */\n  }\n}\n\n\nvoid luaK_dischargevars (FuncState *fs, expdesc *e) {\n  switch (e->k) {\n    case VLOCAL: {\n      e->k = VNONRELOC;\n      break;\n    }\n    case VUPVAL: {\n      e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VGLOBAL: {\n      e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VINDEXED: {\n      freereg(fs, e->u.s.aux);\n      freereg(fs, e->u.s.info);\n      e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux);\n      e->k = VRELOCABLE;\n      break;\n    }\n    case VVARARG:\n    case VCALL: {\n      luaK_setoneret(fs, e);\n      break;\n    }\n    default: break;  /* there is one value available (somewhere) */\n  }\n}\n\n\nstatic int code_label (FuncState *fs, int A, int b, int jump) {\n  luaK_getlabel(fs);  /* those instructions may be jump targets */\n  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);\n}\n\n\nstatic void discharge2reg (FuncState *fs, expdesc *e, int reg) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: {\n      luaK_nil(fs, reg, 1);\n      break;\n    }\n    case VFALSE:  case VTRUE: {\n      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);\n      break;\n    }\n    case VK: {\n      luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info);\n      break;\n    }\n    case VKNUM: {\n      luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval));\n      break;\n    }\n    case VRELOCABLE: {\n      Instruction *pc = &getcode(fs, e);\n      SETARG_A(*pc, reg);\n      break;\n    }\n    case VNONRELOC: {\n      if (reg != e->u.s.info)\n        luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0);\n      break;\n    }\n    default: {\n      lua_assert(e->k == VVOID || e->k == VJMP);\n      return;  /* nothing to do... */\n    }\n  }\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n\nstatic void discharge2anyreg (FuncState *fs, expdesc *e) {\n  if (e->k != VNONRELOC) {\n    luaK_reserveregs(fs, 1);\n    discharge2reg(fs, e, fs->freereg-1);\n  }\n}\n\n\nstatic void exp2reg (FuncState *fs, expdesc *e, int reg) {\n  discharge2reg(fs, e, reg);\n  if (e->k == VJMP)\n    luaK_concat(fs, &e->t, e->u.s.info);  /* put this jump in `t' list */\n  if (hasjumps(e)) {\n    int final;  /* position after whole expression */\n    int p_f = NO_JUMP;  /* position of an eventual LOAD false */\n    int p_t = NO_JUMP;  /* position of an eventual LOAD true */\n    if (need_value(fs, e->t) || need_value(fs, e->f)) {\n      int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);\n      p_f = code_label(fs, reg, 0, 1);\n      p_t = code_label(fs, reg, 1, 0);\n      luaK_patchtohere(fs, fj);\n    }\n    final = luaK_getlabel(fs);\n    patchlistaux(fs, e->f, final, reg, p_f);\n    patchlistaux(fs, e->t, final, reg, p_t);\n  }\n  e->f = e->t = NO_JUMP;\n  e->u.s.info = reg;\n  e->k = VNONRELOC;\n}\n\n\nvoid luaK_exp2nextreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  freeexp(fs, e);\n  luaK_reserveregs(fs, 1);\n  exp2reg(fs, e, fs->freereg - 1);\n}\n\n\nint luaK_exp2anyreg (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  if (e->k == VNONRELOC) {\n    if (!hasjumps(e)) return e->u.s.info;  /* exp is already in a register */\n    if (e->u.s.info >= fs->nactvar) {  /* reg. is not a local? */\n      exp2reg(fs, e, e->u.s.info);  /* put value on it */\n      return e->u.s.info;\n    }\n  }\n  luaK_exp2nextreg(fs, e);  /* default */\n  return e->u.s.info;\n}\n\n\nvoid luaK_exp2val (FuncState *fs, expdesc *e) {\n  if (hasjumps(e))\n    luaK_exp2anyreg(fs, e);\n  else\n    luaK_dischargevars(fs, e);\n}\n\n\nint luaK_exp2RK (FuncState *fs, expdesc *e) {\n  luaK_exp2val(fs, e);\n  switch (e->k) {\n    case VKNUM:\n    case VTRUE:\n    case VFALSE:\n    case VNIL: {\n      if (fs->nk <= MAXINDEXRK) {  /* constant fit in RK operand? */\n        e->u.s.info = (e->k == VNIL)  ? nilK(fs) :\n                      (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :\n                                        boolK(fs, (e->k == VTRUE));\n        e->k = VK;\n        return RKASK(e->u.s.info);\n      }\n      else break;\n    }\n    case VK: {\n      if (e->u.s.info <= MAXINDEXRK)  /* constant fit in argC? */\n        return RKASK(e->u.s.info);\n      else break;\n    }\n    default: break;\n  }\n  /* not a constant in the right range: put it in a register */\n  return luaK_exp2anyreg(fs, e);\n}\n\n\nvoid luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {\n  switch (var->k) {\n    case VLOCAL: {\n      freeexp(fs, ex);\n      exp2reg(fs, ex, var->u.s.info);\n      return;\n    }\n    case VUPVAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0);\n      break;\n    }\n    case VGLOBAL: {\n      int e = luaK_exp2anyreg(fs, ex);\n      luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info);\n      break;\n    }\n    case VINDEXED: {\n      int e = luaK_exp2RK(fs, ex);\n      luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e);\n      break;\n    }\n    default: {\n      lua_assert(0);  /* invalid var kind to store */\n      break;\n    }\n  }\n  freeexp(fs, ex);\n}\n\n\nvoid luaK_self (FuncState *fs, expdesc *e, expdesc *key) {\n  int func;\n  luaK_exp2anyreg(fs, e);\n  freeexp(fs, e);\n  func = fs->freereg;\n  luaK_reserveregs(fs, 2);\n  luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));\n  freeexp(fs, key);\n  e->u.s.info = func;\n  e->k = VNONRELOC;\n}\n\n\nstatic void invertjump (FuncState *fs, expdesc *e) {\n  Instruction *pc = getjumpcontrol(fs, e->u.s.info);\n  lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&\n                                           GET_OPCODE(*pc) != OP_TEST);\n  SETARG_A(*pc, !(GETARG_A(*pc)));\n}\n\n\nstatic int jumponcond (FuncState *fs, expdesc *e, int cond) {\n  if (e->k == VRELOCABLE) {\n    Instruction ie = getcode(fs, e);\n    if (GET_OPCODE(ie) == OP_NOT) {\n      fs->pc--;  /* remove previous OP_NOT */\n      return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);\n    }\n    /* else go through */\n  }\n  discharge2anyreg(fs, e);\n  freeexp(fs, e);\n  return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond);\n}\n\n\nvoid luaK_goiftrue (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of last jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VK: case VKNUM: case VTRUE: {\n      pc = NO_JUMP;  /* always true; do nothing */\n      break;\n    }\n    case VJMP: {\n      invertjump(fs, e);\n      pc = e->u.s.info;\n      break;\n    }\n    case VFALSE: {\n      if (!hasjumps(e)) {\n        pc = luaK_jump(fs);  /* always jump */\n        break;\n      }\n      /* else go through */\n    }\n    default: {\n      pc = jumponcond(fs, e, 0);\n      break;\n    }\n  }\n  luaK_concat(fs, &e->f, pc);  /* insert last jump in `f' list */\n  luaK_patchtohere(fs, e->t);\n  e->t = NO_JUMP;\n}\n\n\nstatic void luaK_goiffalse (FuncState *fs, expdesc *e) {\n  int pc;  /* pc of last jump */\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      pc = NO_JUMP;  /* always false; do nothing */\n      break;\n    }\n    case VJMP: {\n      pc = e->u.s.info;\n      break;\n    }\n    case VTRUE: {\n      if (!hasjumps(e)) {\n        pc = luaK_jump(fs);  /* always jump */\n        break;\n      }\n      /* else go through */\n    }\n    default: {\n      pc = jumponcond(fs, e, 1);\n      break;\n    }\n  }\n  luaK_concat(fs, &e->t, pc);  /* insert last jump in `t' list */\n  luaK_patchtohere(fs, e->f);\n  e->f = NO_JUMP;\n}\n\n\nstatic void codenot (FuncState *fs, expdesc *e) {\n  luaK_dischargevars(fs, e);\n  switch (e->k) {\n    case VNIL: case VFALSE: {\n      e->k = VTRUE;\n      break;\n    }\n    case VK: case VKNUM: case VTRUE: {\n      e->k = VFALSE;\n      break;\n    }\n    case VJMP: {\n      invertjump(fs, e);\n      break;\n    }\n    case VRELOCABLE:\n    case VNONRELOC: {\n      discharge2anyreg(fs, e);\n      freeexp(fs, e);\n      e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0);\n      e->k = VRELOCABLE;\n      break;\n    }\n    default: {\n      lua_assert(0);  /* cannot happen */\n      break;\n    }\n  }\n  /* interchange true and false lists */\n  { int temp = e->f; e->f = e->t; e->t = temp; }\n  removevalues(fs, e->f);\n  removevalues(fs, e->t);\n}\n\n\nvoid luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {\n  t->u.s.aux = luaK_exp2RK(fs, k);\n  t->k = VINDEXED;\n}\n\n\nstatic int constfolding (OpCode op, expdesc *e1, expdesc *e2) {\n  lua_Number v1, v2, r;\n  if (!isnumeral(e1) || !isnumeral(e2)) return 0;\n  v1 = e1->u.nval;\n  v2 = e2->u.nval;\n  switch (op) {\n    case OP_ADD: r = luai_numadd(v1, v2); break;\n    case OP_SUB: r = luai_numsub(v1, v2); break;\n    case OP_MUL: r = luai_nummul(v1, v2); break;\n    case OP_DIV:\n      if (v2 == 0) return 0;  /* do not attempt to divide by 0 */\n      r = luai_numdiv(v1, v2); break;\n    case OP_MOD:\n      if (v2 == 0) return 0;  /* do not attempt to divide by 0 */\n      r = luai_nummod(v1, v2); break;\n    case OP_POW: r = luai_numpow(v1, v2); break;\n    case OP_UNM: r = luai_numunm(v1); break;\n    case OP_LEN: return 0;  /* no constant folding for 'len' */\n    default: lua_assert(0); r = 0; break;\n  }\n  if (luai_numisnan(r)) return 0;  /* do not attempt to produce NaN */\n  e1->u.nval = r;\n  return 1;\n}\n\n\nstatic void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {\n  if (constfolding(op, e1, e2))\n    return;\n  else {\n    int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;\n    int o1 = luaK_exp2RK(fs, e1);\n    if (o1 > o2) {\n      freeexp(fs, e1);\n      freeexp(fs, e2);\n    }\n    else {\n      freeexp(fs, e2);\n      freeexp(fs, e1);\n    }\n    e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);\n    e1->k = VRELOCABLE;\n  }\n}\n\n\nstatic void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1,\n                                                          expdesc *e2) {\n  int o1 = luaK_exp2RK(fs, e1);\n  int o2 = luaK_exp2RK(fs, e2);\n  freeexp(fs, e2);\n  freeexp(fs, e1);\n  if (cond == 0 && op != OP_EQ) {\n    int temp;  /* exchange args to replace by `<' or `<=' */\n    temp = o1; o1 = o2; o2 = temp;  /* o1 <==> o2 */\n    cond = 1;\n  }\n  e1->u.s.info = condjump(fs, op, cond, o1, o2);\n  e1->k = VJMP;\n}\n\n\nvoid luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {\n  expdesc e2;\n  e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;\n  switch (op) {\n    case OPR_MINUS: {\n      if (!isnumeral(e))\n        luaK_exp2anyreg(fs, e);  /* cannot operate on non-numeric constants */\n      codearith(fs, OP_UNM, e, &e2);\n      break;\n    }\n    case OPR_NOT: codenot(fs, e); break;\n    case OPR_LEN: {\n      luaK_exp2anyreg(fs, e);  /* cannot operate on constants */\n      codearith(fs, OP_LEN, e, &e2);\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\nvoid luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {\n  switch (op) {\n    case OPR_AND: {\n      luaK_goiftrue(fs, v);\n      break;\n    }\n    case OPR_OR: {\n      luaK_goiffalse(fs, v);\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */\n      break;\n    }\n    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:\n    case OPR_MOD: case OPR_POW: {\n      if (!isnumeral(v)) luaK_exp2RK(fs, v);\n      break;\n    }\n    default: {\n      luaK_exp2RK(fs, v);\n      break;\n    }\n  }\n}\n\n\nvoid luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {\n  switch (op) {\n    case OPR_AND: {\n      lua_assert(e1->t == NO_JUMP);  /* list must be closed */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->f, e1->f);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_OR: {\n      lua_assert(e1->f == NO_JUMP);  /* list must be closed */\n      luaK_dischargevars(fs, e2);\n      luaK_concat(fs, &e2->t, e1->t);\n      *e1 = *e2;\n      break;\n    }\n    case OPR_CONCAT: {\n      luaK_exp2val(fs, e2);\n      if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {\n        lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1);\n        freeexp(fs, e1);\n        SETARG_B(getcode(fs, e2), e1->u.s.info);\n        e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info;\n      }\n      else {\n        luaK_exp2nextreg(fs, e2);  /* operand must be on the 'stack' */\n        codearith(fs, OP_CONCAT, e1, e2);\n      }\n      break;\n    }\n    case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;\n    case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;\n    case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;\n    case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;\n    case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;\n    case OPR_POW: codearith(fs, OP_POW, e1, e2); break;\n    case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;\n    case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;\n    case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;\n    case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;\n    case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;\n    case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;\n    default: lua_assert(0);\n  }\n}\n\n\nvoid luaK_fixline (FuncState *fs, int line) {\n  fs->f->lineinfo[fs->pc - 1] = line;\n}\n\n\nstatic int luaK_code (FuncState *fs, Instruction i, int line) {\n  Proto *f = fs->f;\n  dischargejpc(fs);  /* `pc' will change */\n  /* put new instruction in code array */\n  luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,\n                  MAX_INT, \"code size overflow\");\n  f->code[fs->pc] = i;\n  /* save corresponding line information */\n  luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,\n                  MAX_INT, \"code size overflow\");\n  f->lineinfo[fs->pc] = line;\n  return fs->pc++;\n}\n\n\nint luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {\n  lua_assert(getOpMode(o) == iABC);\n  lua_assert(getBMode(o) != OpArgN || b == 0);\n  lua_assert(getCMode(o) != OpArgN || c == 0);\n  return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);\n}\n\n\nint luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {\n  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);\n  lua_assert(getCMode(o) == OpArgN);\n  return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);\n}\n\n\nvoid luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {\n  int c =  (nelems - 1)/LFIELDS_PER_FLUSH + 1;\n  int b = (tostore == LUA_MULTRET) ? 0 : tostore;\n  lua_assert(tostore != 0);\n  if (c <= MAXARG_C)\n    luaK_codeABC(fs, OP_SETLIST, base, b, c);\n  else {\n    luaK_codeABC(fs, OP_SETLIST, base, b, 0);\n    luaK_code(fs, cast(Instruction, c), fs->ls->lastline);\n  }\n  fs->freereg = base + 1;  /* free registers with list values */\n}\n\n"
  },
  {
    "path": "src/lcode.h",
    "content": "/*\n** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $\n** Code generator for Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lcode_h\n#define lcode_h\n\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n\n\n/*\n** Marks the end of a patch list. It is an invalid value both as an absolute\n** address, and as a list link (would link an element to itself).\n*/\n#define NO_JUMP (-1)\n\n\n/*\n** grep \"ORDER OPR\" if you change these enums\n*/\ntypedef enum BinOpr {\n  OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,\n  OPR_CONCAT,\n  OPR_NE, OPR_EQ,\n  OPR_LT, OPR_LE, OPR_GT, OPR_GE,\n  OPR_AND, OPR_OR,\n  OPR_NOBINOPR\n} BinOpr;\n\n\ntypedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;\n\n\n#define getcode(fs,e)\t((fs)->f->code[(e)->u.s.info])\n\n#define luaK_codeAsBx(fs,o,A,sBx)\tluaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)\n\n#define luaK_setmultret(fs,e)\tluaK_setreturns(fs, e, LUA_MULTRET)\n\nLUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);\nLUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);\nLUAI_FUNC void luaK_fixline (FuncState *fs, int line);\nLUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);\nLUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);\nLUAI_FUNC void luaK_checkstack (FuncState *fs, int n);\nLUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);\nLUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);\nLUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);\nLUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);\nLUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);\nLUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);\nLUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);\nLUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);\nLUAI_FUNC int luaK_jump (FuncState *fs);\nLUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);\nLUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);\nLUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);\nLUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);\nLUAI_FUNC int luaK_getlabel (FuncState *fs);\nLUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);\nLUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);\nLUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);\nLUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);\n\n\n#endif\n"
  },
  {
    "path": "src/ldblib.c",
    "content": "/*\n** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $\n** Interface from Lua to its debug API\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define ldblib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\nstatic int db_getregistry (lua_State *L) {\n  lua_pushvalue(L, LUA_REGISTRYINDEX);\n  return 1;\n}\n\n\nstatic int db_getmetatable (lua_State *L) {\n  luaL_checkany(L, 1);\n  if (!lua_getmetatable(L, 1)) {\n    lua_pushnil(L);  /* no metatable */\n  }\n  return 1;\n}\n\n\nstatic int db_setmetatable (lua_State *L) {\n  int t = lua_type(L, 2);\n  luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,\n                    \"nil or table expected\");\n  lua_settop(L, 2);\n  lua_pushboolean(L, lua_setmetatable(L, 1));\n  return 1;\n}\n\n\nstatic int db_getfenv (lua_State *L) {\n  luaL_checkany(L, 1);\n  lua_getfenv(L, 1);\n  return 1;\n}\n\n\nstatic int db_setfenv (lua_State *L) {\n  luaL_checktype(L, 2, LUA_TTABLE);\n  lua_settop(L, 2);\n  if (lua_setfenv(L, 1) == 0)\n    luaL_error(L, LUA_QL(\"setfenv\")\n                  \" cannot change environment of given object\");\n  return 1;\n}\n\n\nstatic void settabss (lua_State *L, const char *i, const char *v) {\n  lua_pushstring(L, v);\n  lua_setfield(L, -2, i);\n}\n\n\nstatic void settabsi (lua_State *L, const char *i, int v) {\n  lua_pushinteger(L, v);\n  lua_setfield(L, -2, i);\n}\n\n\nstatic lua_State *getthread (lua_State *L, int *arg) {\n  if (lua_isthread(L, 1)) {\n    *arg = 1;\n    return lua_tothread(L, 1);\n  }\n  else {\n    *arg = 0;\n    return L;\n  }\n}\n\n\nstatic void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {\n  if (L == L1) {\n    lua_pushvalue(L, -2);\n    lua_remove(L, -3);\n  }\n  else\n    lua_xmove(L1, L, 1);\n  lua_setfield(L, -2, fname);\n}\n\n\nstatic int db_getinfo (lua_State *L) {\n  lua_Debug ar;\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  const char *options = luaL_optstring(L, arg+2, \"flnSu\");\n  if (lua_isnumber(L, arg+1)) {\n    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {\n      lua_pushnil(L);  /* level out of range */\n      return 1;\n    }\n  }\n  else if (lua_isfunction(L, arg+1)) {\n    lua_pushfstring(L, \">%s\", options);\n    options = lua_tostring(L, -1);\n    lua_pushvalue(L, arg+1);\n    lua_xmove(L, L1, 1);\n  }\n  else\n    return luaL_argerror(L, arg+1, \"function or level expected\");\n  if (!lua_getinfo(L1, options, &ar))\n    return luaL_argerror(L, arg+2, \"invalid option\");\n  lua_createtable(L, 0, 2);\n  if (strchr(options, 'S')) {\n    settabss(L, \"source\", ar.source);\n    settabss(L, \"short_src\", ar.short_src);\n    settabsi(L, \"linedefined\", ar.linedefined);\n    settabsi(L, \"lastlinedefined\", ar.lastlinedefined);\n    settabss(L, \"what\", ar.what);\n  }\n  if (strchr(options, 'l'))\n    settabsi(L, \"currentline\", ar.currentline);\n  if (strchr(options, 'u'))\n    settabsi(L, \"nups\", ar.nups);\n  if (strchr(options, 'n')) {\n    settabss(L, \"name\", ar.name);\n    settabss(L, \"namewhat\", ar.namewhat);\n  }\n  if (strchr(options, 'L'))\n    treatstackoption(L, L1, \"activelines\");\n  if (strchr(options, 'f'))\n    treatstackoption(L, L1, \"func\");\n  return 1;  /* return table */\n}\n    \n\nstatic int db_getlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  const char *name;\n  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2));\n  if (name) {\n    lua_xmove(L1, L, 1);\n    lua_pushstring(L, name);\n    lua_pushvalue(L, -2);\n    return 2;\n  }\n  else {\n    lua_pushnil(L);\n    return 1;\n  }\n}\n\n\nstatic int db_setlocal (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))  /* out of range? */\n    return luaL_argerror(L, arg+1, \"level out of range\");\n  luaL_checkany(L, arg+3);\n  lua_settop(L, arg+3);\n  lua_xmove(L, L1, 1);\n  lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));\n  return 1;\n}\n\n\nstatic int auxupvalue (lua_State *L, int get) {\n  const char *name;\n  int n = luaL_checkint(L, 2);\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  if (lua_iscfunction(L, 1)) return 0;  /* cannot touch C upvalues from Lua */\n  name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);\n  if (name == NULL) return 0;\n  lua_pushstring(L, name);\n  lua_insert(L, -(get+1));\n  return get + 1;\n}\n\n\nstatic int db_getupvalue (lua_State *L) {\n  return auxupvalue(L, 1);\n}\n\n\nstatic int db_setupvalue (lua_State *L) {\n  luaL_checkany(L, 3);\n  return auxupvalue(L, 0);\n}\n\n\n\nstatic const char KEY_HOOK = 'h';\n\n\nstatic void hookf (lua_State *L, lua_Debug *ar) {\n  static const char *const hooknames[] =\n    {\"call\", \"return\", \"line\", \"count\", \"tail return\"};\n  lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n  lua_rawget(L, LUA_REGISTRYINDEX);\n  lua_pushlightuserdata(L, L);\n  lua_rawget(L, -2);\n  if (lua_isfunction(L, -1)) {\n    lua_pushstring(L, hooknames[(int)ar->event]);\n    if (ar->currentline >= 0)\n      lua_pushinteger(L, ar->currentline);\n    else lua_pushnil(L);\n    lua_assert(lua_getinfo(L, \"lS\", ar));\n    lua_call(L, 2, 0);\n  }\n}\n\n\nstatic int makemask (const char *smask, int count) {\n  int mask = 0;\n  if (strchr(smask, 'c')) mask |= LUA_MASKCALL;\n  if (strchr(smask, 'r')) mask |= LUA_MASKRET;\n  if (strchr(smask, 'l')) mask |= LUA_MASKLINE;\n  if (count > 0) mask |= LUA_MASKCOUNT;\n  return mask;\n}\n\n\nstatic char *unmakemask (int mask, char *smask) {\n  int i = 0;\n  if (mask & LUA_MASKCALL) smask[i++] = 'c';\n  if (mask & LUA_MASKRET) smask[i++] = 'r';\n  if (mask & LUA_MASKLINE) smask[i++] = 'l';\n  smask[i] = '\\0';\n  return smask;\n}\n\n\nstatic void gethooktable (lua_State *L) {\n  lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n  lua_rawget(L, LUA_REGISTRYINDEX);\n  if (!lua_istable(L, -1)) {\n    lua_pop(L, 1);\n    lua_createtable(L, 0, 1);\n    lua_pushlightuserdata(L, (void *)&KEY_HOOK);\n    lua_pushvalue(L, -2);\n    lua_rawset(L, LUA_REGISTRYINDEX);\n  }\n}\n\n\nstatic int db_sethook (lua_State *L) {\n  int arg, mask, count;\n  lua_Hook func;\n  lua_State *L1 = getthread(L, &arg);\n  if (lua_isnoneornil(L, arg+1)) {\n    lua_settop(L, arg+1);\n    func = NULL; mask = 0; count = 0;  /* turn off hooks */\n  }\n  else {\n    const char *smask = luaL_checkstring(L, arg+2);\n    luaL_checktype(L, arg+1, LUA_TFUNCTION);\n    count = luaL_optint(L, arg+3, 0);\n    func = hookf; mask = makemask(smask, count);\n  }\n  gethooktable(L);\n  lua_pushlightuserdata(L, L1);\n  lua_pushvalue(L, arg+1);\n  lua_rawset(L, -3);  /* set new hook */\n  lua_pop(L, 1);  /* remove hook table */\n  lua_sethook(L1, func, mask, count);  /* set hooks */\n  return 0;\n}\n\n\nstatic int db_gethook (lua_State *L) {\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  char buff[5];\n  int mask = lua_gethookmask(L1);\n  lua_Hook hook = lua_gethook(L1);\n  if (hook != NULL && hook != hookf)  /* external hook? */\n    lua_pushliteral(L, \"external hook\");\n  else {\n    gethooktable(L);\n    lua_pushlightuserdata(L, L1);\n    lua_rawget(L, -2);   /* get hook */\n    lua_remove(L, -2);  /* remove hook table */\n  }\n  lua_pushstring(L, unmakemask(mask, buff));\n  lua_pushinteger(L, lua_gethookcount(L1));\n  return 3;\n}\n\n\nstatic int db_debug (lua_State *L) {\n  for (;;) {\n    char buffer[250];\n    fputs(\"lua_debug> \", stderr);\n    if (fgets(buffer, sizeof(buffer), stdin) == 0 ||\n        strcmp(buffer, \"cont\\n\") == 0)\n      return 0;\n    if (luaL_loadbuffer(L, buffer, strlen(buffer), \"=(debug command)\") ||\n        lua_pcall(L, 0, 0, 0)) {\n      fputs(lua_tostring(L, -1), stderr);\n      fputs(\"\\n\", stderr);\n    }\n    lua_settop(L, 0);  /* remove eventual returns */\n  }\n}\n\n\n#define LEVELS1\t12\t/* size of the first part of the stack */\n#define LEVELS2\t10\t/* size of the second part of the stack */\n\nstatic int db_errorfb (lua_State *L) {\n  int level;\n  int firstpart = 1;  /* still before eventual `...' */\n  int arg;\n  lua_State *L1 = getthread(L, &arg);\n  lua_Debug ar;\n  if (lua_isnumber(L, arg+2)) {\n    level = (int)lua_tointeger(L, arg+2);\n    lua_pop(L, 1);\n  }\n  else\n    level = (L == L1) ? 1 : 0;  /* level 0 may be this own function */\n  if (lua_gettop(L) == arg)\n    lua_pushliteral(L, \"\");\n  else if (!lua_isstring(L, arg+1)) return 1;  /* message is not a string */\n  else lua_pushliteral(L, \"\\n\");\n  lua_pushliteral(L, \"stack traceback:\");\n  while (lua_getstack(L1, level++, &ar)) {\n    if (level > LEVELS1 && firstpart) {\n      /* no more than `LEVELS2' more levels? */\n      if (!lua_getstack(L1, level+LEVELS2, &ar))\n        level--;  /* keep going */\n      else {\n        lua_pushliteral(L, \"\\n\\t...\");  /* too many levels */\n        while (lua_getstack(L1, level+LEVELS2, &ar))  /* find last levels */\n          level++;\n      }\n      firstpart = 0;\n      continue;\n    }\n    lua_pushliteral(L, \"\\n\\t\");\n    lua_getinfo(L1, \"Snl\", &ar);\n    lua_pushfstring(L, \"%s:\", ar.short_src);\n    if (ar.currentline > 0)\n      lua_pushfstring(L, \"%d:\", ar.currentline);\n    if (*ar.namewhat != '\\0')  /* is there a name? */\n        lua_pushfstring(L, \" in function \" LUA_QS, ar.name);\n    else {\n      if (*ar.what == 'm')  /* main? */\n        lua_pushfstring(L, \" in main chunk\");\n      else if (*ar.what == 'C' || *ar.what == 't')\n        lua_pushliteral(L, \" ?\");  /* C function or tail call */\n      else\n        lua_pushfstring(L, \" in function <%s:%d>\",\n                           ar.short_src, ar.linedefined);\n    }\n    lua_concat(L, lua_gettop(L) - arg);\n  }\n  lua_concat(L, lua_gettop(L) - arg);\n  return 1;\n}\n\n\nstatic const luaL_Reg dblib[] = {\n  {\"debug\", db_debug},\n  {\"getfenv\", db_getfenv},\n  {\"gethook\", db_gethook},\n  {\"getinfo\", db_getinfo},\n  {\"getlocal\", db_getlocal},\n  {\"getregistry\", db_getregistry},\n  {\"getmetatable\", db_getmetatable},\n  {\"getupvalue\", db_getupvalue},\n  {\"setfenv\", db_setfenv},\n  {\"sethook\", db_sethook},\n  {\"setlocal\", db_setlocal},\n  {\"setmetatable\", db_setmetatable},\n  {\"setupvalue\", db_setupvalue},\n  {\"traceback\", db_errorfb},\n  {NULL, NULL}\n};\n\n\nLUALIB_API int luaopen_debug (lua_State *L) {\n  luaL_register(L, LUA_DBLIBNAME, dblib);\n  return 1;\n}\n\n"
  },
  {
    "path": "src/ldebug.c",
    "content": "/*\n** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $\n** Debug Interface\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdarg.h>\n#include <stddef.h>\n#include <string.h>\n\n\n#define ldebug_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lapi.h\"\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);\n\n\nstatic int currentpc (lua_State *L, CallInfo *ci) {\n  if (!isLua(ci)) return -1;  /* function is not a Lua function? */\n  if (ci == L->ci)\n    ci->savedpc = L->savedpc;\n  return pcRel(ci->savedpc, ci_func(ci)->l.p);\n}\n\n\nstatic int currentline (lua_State *L, CallInfo *ci) {\n  int pc = currentpc(L, ci);\n  if (pc < 0)\n    return -1;  /* only active lua functions have current-line information */\n  else\n    return getlinenum(ci_func(ci)->l.p, pc);\n}\n\n\n/*\n** this function can be called asynchronous (e.g. during a signal)\n*/\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {\n  if (func == NULL || mask == 0) {  /* turn off hooks? */\n    mask = 0;\n    func = NULL;\n  }\n  L->hook = func;\n  L->basehookcount = count;\n  resethookcount(L);\n  L->hookmask = cast_byte(mask);\n  return 1;\n}\n\n\nLUA_API lua_Hook lua_gethook (lua_State *L) {\n  return L->hook;\n}\n\n\nLUA_API int lua_gethookmask (lua_State *L) {\n  return L->hookmask;\n}\n\n\nLUA_API int lua_gethookcount (lua_State *L) {\n  return L->basehookcount;\n}\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {\n  int status;\n  CallInfo *ci;\n  lua_lock(L);\n  for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {\n    level--;\n    if (f_isLua(ci))  /* Lua function? */\n      level -= ci->tailcalls;  /* skip lost tail calls */\n  }\n  if (level == 0 && ci > L->base_ci) {  /* level found? */\n    status = 1;\n    ar->i_ci = cast_int(ci - L->base_ci);\n  }\n  else if (level < 0) {  /* level is of a lost tail call? */\n    status = 1;\n    ar->i_ci = 0;\n  }\n  else status = 0;  /* no such level */\n  lua_unlock(L);\n  return status;\n}\n\n\nstatic Proto *getluaproto (CallInfo *ci) {\n  return (isLua(ci) ? ci_func(ci)->l.p : NULL);\n}\n\n\nstatic const char *findlocal (lua_State *L, CallInfo *ci, int n) {\n  const char *name;\n  Proto *fp = getluaproto(ci);\n  if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)\n    return name;  /* is a local variable in a Lua function */\n  else {\n    StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;\n    if (limit - ci->base >= n && n > 0)  /* is 'n' inside 'ci' stack? */\n      return \"(*temporary)\";\n    else\n      return NULL;\n  }\n}\n\n\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {\n  CallInfo *ci = L->base_ci + ar->i_ci;\n  const char *name = findlocal(L, ci, n);\n  lua_lock(L);\n  if (name)\n      luaA_pushobject(L, ci->base + (n - 1));\n  lua_unlock(L);\n  return name;\n}\n\n\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {\n  CallInfo *ci = L->base_ci + ar->i_ci;\n  const char *name = findlocal(L, ci, n);\n  lua_lock(L);\n  if (name)\n      setobjs2s(L, ci->base + (n - 1), L->top - 1);\n  L->top--;  /* pop value */\n  lua_unlock(L);\n  return name;\n}\n\n\nstatic void funcinfo (lua_Debug *ar, Closure *cl) {\n  if (cl_isC(cl)) {\n    ar->source = \"=[C]\";\n    ar->linedefined = -1;\n    ar->lastlinedefined = -1;\n    ar->what = \"C\";\n  }\n  else {\n    ar->source = getstr(cl->l.p->source);\n    ar->linedefined = cl->l.p->linedefined;\n    ar->lastlinedefined = cl->l.p->lastlinedefined;\n    ar->what = (ar->linedefined == 0) ? \"main\" : \"Lua\";\n  }\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n}\n\n\nstatic void info_tailcall (lua_Debug *ar) {\n  ar->name = ar->namewhat = \"\";\n  ar->what = \"tail\";\n  ar->lastlinedefined = ar->linedefined = ar->currentline = -1;\n  ar->source = \"=(tail call)\";\n  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);\n  ar->nups = 0;\n}\n\n\nstatic void collectvalidlines (lua_State *L, Closure *f) {\n  if (f == NULL || cl_isC(f)) {\n    setnilvalue(L->top);\n  }\n  else {\n    Table *t = luaH_new(L, 0, 0);\n    int *lineinfo = f->l.p->lineinfo;\n    int i;\n    for (i=0; i<f->l.p->sizelineinfo; i++)\n      setbvalue(luaH_setnum(L, t, lineinfo[i]), 1);\n    sethvalue(L, L->top, t); \n  }\n  incr_top(L);\n}\n\n\nstatic int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,\n                    Closure *f, CallInfo *ci) {\n  int status = 1;\n  if (f == NULL) {\n    info_tailcall(ar);\n    return status;\n  }\n  for (; *what; what++) {\n    switch (*what) {\n      case 'S': {\n        funcinfo(ar, f);\n        break;\n      }\n      case 'l': {\n        ar->currentline = (ci) ? currentline(L, ci) : -1;\n        break;\n      }\n      case 'u': {\n        ar->nups = f->c.nupvalues;\n        break;\n      }\n      case 'n': {\n        ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL;\n        if (ar->namewhat == NULL) {\n          ar->namewhat = \"\";  /* not found */\n          ar->name = NULL;\n        }\n        break;\n      }\n      case 'L':\n      case 'f':  /* handled by lua_getinfo */\n        break;\n      default: status = 0;  /* invalid option */\n    }\n  }\n  return status;\n}\n\n\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {\n  int status;\n  Closure *f = NULL;\n  CallInfo *ci = NULL;\n  lua_lock(L);\n  if (*what == '>') {\n    StkId func = L->top - 1;\n    luai_apicheck(L, ttisfunction(func));\n    what++;  /* skip the '>' */\n    f = clvalue(func);\n    L->top--;  /* pop function */\n  }\n  else if (ar->i_ci != 0) {  /* no tail call? */\n    ci = L->base_ci + ar->i_ci;\n    lua_assert(ttisfunction(ci->func));\n    f = clvalue(ci->func);\n  }\n  status = auxgetinfo(L, what, ar, f, ci);\n  if (strchr(what, 'f')) {\n    if (f == NULL) setnilvalue(L->top);\n    else setclvalue(L, L->top, f);\n    incr_top(L);\n  }\n  if (strchr(what, 'L'))\n    collectvalidlines(L, f);\n  lua_unlock(L);\n  return status;\n}\n\n\n/*\n** {======================================================\n** Symbolic Execution and code checker\n** =======================================================\n*/\n\n#define check(x)\t\tif (!(x)) return 0;\n\n#define checkjump(pt,pc)\tcheck(0 <= pc && pc < pt->sizecode)\n\n#define checkreg(pt,reg)\tcheck((reg) < (pt)->maxstacksize)\n\n\n\nstatic int precheck (const Proto *pt) {\n  check(pt->maxstacksize <= MAXSTACK);\n  check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);\n  check(!(pt->is_vararg & VARARG_NEEDSARG) ||\n              (pt->is_vararg & VARARG_HASARG));\n  check(pt->sizeupvalues <= pt->nups);\n  check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);\n  check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);\n  return 1;\n}\n\n\n#define checkopenop(pt,pc)\tluaG_checkopenop((pt)->code[(pc)+1])\n\nint luaG_checkopenop (Instruction i) {\n  switch (GET_OPCODE(i)) {\n    case OP_CALL:\n    case OP_TAILCALL:\n    case OP_RETURN:\n    case OP_SETLIST: {\n      check(GETARG_B(i) == 0);\n      return 1;\n    }\n    default: return 0;  /* invalid instruction after an open call */\n  }\n}\n\n\nstatic int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) {\n  switch (mode) {\n    case OpArgN: check(r == 0); break;\n    case OpArgU: break;\n    case OpArgR: checkreg(pt, r); break;\n    case OpArgK:\n      check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize);\n      break;\n  }\n  return 1;\n}\n\n\nstatic Instruction symbexec (const Proto *pt, int lastpc, int reg) {\n  int pc;\n  int last;  /* stores position of last instruction that changed `reg' */\n  last = pt->sizecode-1;  /* points to final return (a `neutral' instruction) */\n  check(precheck(pt));\n  for (pc = 0; pc < lastpc; pc++) {\n    Instruction i = pt->code[pc];\n    OpCode op = GET_OPCODE(i);\n    int a = GETARG_A(i);\n    int b = 0;\n    int c = 0;\n    check(op < NUM_OPCODES);\n    checkreg(pt, a);\n    switch (getOpMode(op)) {\n      case iABC: {\n        b = GETARG_B(i);\n        c = GETARG_C(i);\n        check(checkArgMode(pt, b, getBMode(op)));\n        check(checkArgMode(pt, c, getCMode(op)));\n        break;\n      }\n      case iABx: {\n        b = GETARG_Bx(i);\n        if (getBMode(op) == OpArgK) check(b < pt->sizek);\n        break;\n      }\n      case iAsBx: {\n        b = GETARG_sBx(i);\n        if (getBMode(op) == OpArgR) {\n          int dest = pc+1+b;\n          check(0 <= dest && dest < pt->sizecode);\n          if (dest > 0) {\n            int j;\n            /* check that it does not jump to a setlist count; this\n               is tricky, because the count from a previous setlist may\n               have the same value of an invalid setlist; so, we must\n               go all the way back to the first of them (if any) */\n            for (j = 0; j < dest; j++) {\n              Instruction d = pt->code[dest-1-j];\n              if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;\n            }\n            /* if 'j' is even, previous value is not a setlist (even if\n               it looks like one) */\n            check((j&1) == 0);\n          }\n        }\n        break;\n      }\n    }\n    if (testAMode(op)) {\n      if (a == reg) last = pc;  /* change register `a' */\n    }\n    if (testTMode(op)) {\n      check(pc+2 < pt->sizecode);  /* check skip */\n      check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);\n    }\n    switch (op) {\n      case OP_LOADBOOL: {\n        if (c == 1) {  /* does it jump? */\n          check(pc+2 < pt->sizecode);  /* check its jump */\n          check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||\n                GETARG_C(pt->code[pc+1]) != 0);\n        }\n        break;\n      }\n      case OP_LOADNIL: {\n        if (a <= reg && reg <= b)\n          last = pc;  /* set registers from `a' to `b' */\n        break;\n      }\n      case OP_GETUPVAL:\n      case OP_SETUPVAL: {\n        check(b < pt->nups);\n        break;\n      }\n      case OP_GETGLOBAL:\n      case OP_SETGLOBAL: {\n        check(ttisstring(&pt->k[b]));\n        break;\n      }\n      case OP_SELF: {\n        checkreg(pt, a+1);\n        if (reg == a+1) last = pc;\n        break;\n      }\n      case OP_CONCAT: {\n        check(b < c);  /* at least two operands */\n        break;\n      }\n      case OP_TFORLOOP: {\n        check(c >= 1);  /* at least one result (control variable) */\n        checkreg(pt, a+2+c);  /* space for results */\n        if (reg >= a+2) last = pc;  /* affect all regs above its base */\n        break;\n      }\n      case OP_FORLOOP:\n      case OP_FORPREP:\n        checkreg(pt, a+3);\n        /* go through */\n      case OP_JMP: {\n        int dest = pc+1+b;\n        /* not full check and jump is forward and do not skip `lastpc'? */\n        if (reg != NO_REG && pc < dest && dest <= lastpc)\n          pc += b;  /* do the jump */\n        break;\n      }\n      case OP_CALL:\n      case OP_TAILCALL: {\n        if (b != 0) {\n          checkreg(pt, a+b-1);\n        }\n        c--;  /* c = num. returns */\n        if (c == LUA_MULTRET) {\n          check(checkopenop(pt, pc));\n        }\n        else if (c != 0)\n          checkreg(pt, a+c-1);\n        if (reg >= a) last = pc;  /* affect all registers above base */\n        break;\n      }\n      case OP_RETURN: {\n        b--;  /* b = num. returns */\n        if (b > 0) checkreg(pt, a+b-1);\n        break;\n      }\n      case OP_SETLIST: {\n        if (b > 0) checkreg(pt, a + b);\n        if (c == 0) {\n          pc++;\n          check(pc < pt->sizecode - 1);\n        }\n        break;\n      }\n      case OP_CLOSURE: {\n        int nup, j;\n        check(b < pt->sizep);\n        nup = pt->p[b]->nups;\n        check(pc + nup < pt->sizecode);\n        for (j = 1; j <= nup; j++) {\n          OpCode op1 = GET_OPCODE(pt->code[pc + j]);\n          check(op1 == OP_GETUPVAL || op1 == OP_MOVE);\n        }\n        if (reg != NO_REG)  /* tracing? */\n          pc += nup;  /* do not 'execute' these pseudo-instructions */\n        break;\n      }\n      case OP_VARARG: {\n        check((pt->is_vararg & VARARG_ISVARARG) &&\n             !(pt->is_vararg & VARARG_NEEDSARG));\n        b--;\n        if (b == LUA_MULTRET) check(checkopenop(pt, pc));\n        checkreg(pt, a+b-1);\n        break;\n      }\n      default: break;\n    }\n  }\n  return pt->code[last];\n}\n\n#undef check\n#undef checkjump\n#undef checkreg\n\n/* }====================================================== */\n\n\nint luaG_checkcode (const Proto *pt) {\n  if(pt->sizecode == 0) return 1; /* no bytecode, stripped jit compiled Lua function */\n  return (symbexec(pt, pt->sizecode, NO_REG) != 0);\n}\n\n\nstatic const char *kname (Proto *p, int c) {\n  if (ISK(c) && ttisstring(&p->k[INDEXK(c)]))\n    return svalue(&p->k[INDEXK(c)]);\n  else\n    return \"?\";\n}\n\n\nstatic const char *getobjname (lua_State *L, CallInfo *ci, int stackpos,\n                               const char **name) {\n  if (isLua(ci)) {  /* a Lua function? */\n    Proto *p = ci_func(ci)->l.p;\n    int pc = currentpc(L, ci);\n    Instruction i;\n    if (pc < 0 || p->sizecode == 0)  /* no bytecode, stripped jit compiled Lua function */\n      return NULL;\n    *name = luaF_getlocalname(p, stackpos+1, pc);\n    if (*name)  /* is a local? */\n      return \"local\";\n    i = symbexec(p, pc, stackpos);  /* try symbolic execution */\n    lua_assert(pc != -1);\n    switch (GET_OPCODE(i)) {\n      case OP_GETGLOBAL: {\n        int g = GETARG_Bx(i);  /* global index */\n        lua_assert(ttisstring(&p->k[g]));\n        *name = svalue(&p->k[g]);\n        return \"global\";\n      }\n      case OP_MOVE: {\n        int a = GETARG_A(i);\n        int b = GETARG_B(i);  /* move from `b' to `a' */\n        if (b < a)\n          return getobjname(L, ci, b, name);  /* get name for `b' */\n        break;\n      }\n      case OP_GETTABLE: {\n        int k = GETARG_C(i);  /* key index */\n        *name = kname(p, k);\n        return \"field\";\n      }\n      case OP_GETUPVAL: {\n        int u = GETARG_B(i);  /* upvalue index */\n        *name = p->upvalues ? getstr(p->upvalues[u]) : \"?\";\n        return \"upvalue\";\n      }\n      case OP_SELF: {\n        int k = GETARG_C(i);  /* key index */\n        *name = kname(p, k);\n        return \"method\";\n      }\n      default: break;\n    }\n  }\n  return NULL;  /* no useful name found */\n}\n\n\nstatic const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {\n  Instruction i, *code;\n\tint pc;\n  if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1))\n    return NULL;  /* calling function is not Lua (or is unknown) */\n  ci--;  /* calling function */\n\tcode = ci_func(ci)->l.p->code;\n\tpc = currentpc(L, ci);\n\tif(pc < 0 || code == NULL) return NULL; /* no bytecode, stripped jit compiled Lua function */\n  i = code[currentpc(L, ci)];\n  if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||\n      GET_OPCODE(i) == OP_TFORLOOP)\n    return getobjname(L, ci, GETARG_A(i), name);\n  else\n    return NULL;  /* no useful name can be found */\n}\n\n\n/* only ANSI way to check whether a pointer points to an array */\nstatic int isinstack (CallInfo *ci, const TValue *o) {\n  StkId p;\n  for (p = ci->base; p < ci->top; p++)\n    if (o == p) return 1;\n  return 0;\n}\n\n\nvoid luaG_typeerror (lua_State *L, const TValue *o, const char *op) {\n  const char *name = NULL;\n  const char *t = luaT_typenames[ttype(o)];\n  const char *kind = (isinstack(L->ci, o)) ?\n                         getobjname(L, L->ci, cast_int(o - L->base), &name) :\n                         NULL;\n  if (kind)\n    luaG_runerror(L, \"attempt to %s %s \" LUA_QS \" (a %s value)\",\n                op, kind, name, t);\n  else\n    luaG_runerror(L, \"attempt to %s a %s value\", op, t);\n}\n\n\nvoid luaG_concaterror (lua_State *L, StkId p1, StkId p2) {\n  if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;\n  lua_assert(!ttisstring(p1) && !ttisnumber(p1));\n  luaG_typeerror(L, p1, \"concatenate\");\n}\n\n\nvoid luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {\n  TValue temp;\n  if (luaV_tonumber(p1, &temp) == NULL)\n    p2 = p1;  /* first operand is wrong */\n  luaG_typeerror(L, p2, \"perform arithmetic on\");\n}\n\n\nint luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {\n  const char *t1 = luaT_typenames[ttype(p1)];\n  const char *t2 = luaT_typenames[ttype(p2)];\n  if (t1[2] == t2[2])\n    luaG_runerror(L, \"attempt to compare two %s values\", t1);\n  else\n    luaG_runerror(L, \"attempt to compare %s with %s\", t1, t2);\n  return 0;\n}\n\n\nstatic void addinfo (lua_State *L, const char *msg) {\n  CallInfo *ci = L->ci;\n  if (isLua(ci)) {  /* is Lua code? */\n    char buff[LUA_IDSIZE];  /* add file:line information */\n    int line = currentline(L, ci);\n    luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);\n    luaO_pushfstring(L, \"%s:%d: %s\", buff, line, msg);\n  }\n}\n\n\nvoid luaG_errormsg (lua_State *L) {\n  if (L->errfunc != 0) {  /* is there an error handling function? */\n    StkId errfunc = restorestack(L, L->errfunc);\n    if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);\n    setobjs2s(L, L->top, L->top - 1);  /* move argument */\n    setobjs2s(L, L->top - 1, errfunc);  /* push function */\n    incr_top(L);\n    luaD_call(L, L->top - 2, 1);  /* call it */\n  }\n  luaD_throw(L, LUA_ERRRUN);\n}\n\n\nvoid luaG_runerror (lua_State *L, const char *fmt, ...) {\n  va_list argp;\n  va_start(argp, fmt);\n  addinfo(L, luaO_pushvfstring(L, fmt, argp));\n  va_end(argp);\n  luaG_errormsg(L);\n}\n\n"
  },
  {
    "path": "src/ldebug.h",
    "content": "/*\n** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions from Debug Interface module\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldebug_h\n#define ldebug_h\n\n\n#include \"lstate.h\"\n\n\n#define pcRel(pc, p)\t(cast(int, (pc) - (p)->code) - 1)\n\n#define getlinenum(f,pc)\t(((f)->lineinfo) ? (f)->lineinfo[pc] : 0)\n\n#define resethookcount(L)\t(L->hookcount = L->basehookcount)\n\n\nLUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,\n                                             const char *opname);\nLUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);\nLUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,\n                                              const TValue *p2);\nLUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,\n                                             const TValue *p2);\nLUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaG_errormsg (lua_State *L);\nLUAI_FUNC int luaG_checkcode (const Proto *pt);\nLUAI_FUNC int luaG_checkopenop (Instruction i);\n\n#endif\n"
  },
  {
    "path": "src/ldo.c",
    "content": "/*\n** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#include <setjmp.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define ldo_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lundump.h\"\n#include \"lvm.h\"\n#include \"lzio.h\"\n\n\n\n\n/*\n** {======================================================\n** Error-recovery functions\n** =======================================================\n*/\n\n\n/* chain list of long jump buffers */\nstruct lua_longjmp {\n  struct lua_longjmp *previous;\n  luai_jmpbuf b;\n  volatile int status;  /* error code */\n};\n\n\nvoid luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {\n  switch (errcode) {\n    case LUA_ERRMEM: {\n      ptrdiff_t oldtopr = savestack(L, oldtop);\n      setsvalue2s(L, restorestack(L, oldtopr), luaS_newliteral(L, MEMERRMSG));\n      break;\n    }\n    case LUA_ERRERR: {\n      ptrdiff_t oldtopr = savestack(L, oldtop);\n      setsvalue2s(L, restorestack(L, oldtopr), luaS_newliteral(L, \"error in error handling\"));\n      break;\n    }\n    case LUA_ERRSYNTAX:\n    case LUA_ERRRUN: {\n      setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */\n      break;\n    }\n  }\n  L->top = oldtop + 1;\n}\n\n\nstatic void restore_stack_limit (lua_State *L) {\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);\n  if (L->size_ci > LUAI_MAXCALLS) {  /* there was an overflow? */\n    int inuse = cast_int(L->ci - L->base_ci);\n    if (inuse + 1 < LUAI_MAXCALLS)  /* can `undo' overflow? */\n      luaD_reallocCI(L, LUAI_MAXCALLS);\n  }\n}\n\n\nstatic void resetstack (lua_State *L, int status) {\n  L->ci = L->base_ci;\n  L->base = L->ci->base;\n  luaF_close(L, L->base);  /* close eventual pending closures */\n  luaD_seterrorobj(L, status, L->base);\n  L->nCcalls = 0;\n  L->allowhook = 1;\n  restore_stack_limit(L);\n  L->errfunc = 0;\n  L->errorJmp = NULL;\n}\n\n\nvoid luaD_throw (lua_State *L, int errcode) {\n  unfixedstack(L); /* make sure the fixedstack & block_gc flags get reset. */\n  unset_block_gc(L);\n  if (L->errorJmp) {\n    L->errorJmp->status = errcode;\n    LUAI_THROW(L, L->errorJmp);\n  }\n  else {\n    L->status = cast_byte(errcode);\n    if (G(L)->panic) {\n      resetstack(L, errcode);\n      lua_unlock(L);\n      G(L)->panic(L);\n    }\n    exit(EXIT_FAILURE);\n  }\n}\n\n\nint luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {\n  struct lua_longjmp lj;\n  lj.status = 0;\n  lj.previous = L->errorJmp;  /* chain new error handler */\n  L->errorJmp = &lj;\n  LUAI_TRY(L, &lj,\n    (*f)(L, ud);\n  );\n  L->errorJmp = lj.previous;  /* restore old error handler */\n  return lj.status;\n}\n\n/* }====================================================== */\n\n\nstatic void correctstack (lua_State *L, TValue *oldstack) {\n  CallInfo *ci;\n  GCObject *up;\n  L->top = (L->top - oldstack) + L->stack;\n  for (up = L->openupval; up != NULL; up = up->gch.next)\n    gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;\n  for (ci = L->base_ci; ci <= L->ci; ci++) {\n    ci->top = (ci->top - oldstack) + L->stack;\n    ci->base = (ci->base - oldstack) + L->stack;\n    ci->func = (ci->func - oldstack) + L->stack;\n  }\n  L->base = (L->base - oldstack) + L->stack;\n}\n\n\nvoid luaD_reallocstack (lua_State *L, int newsize) {\n  TValue *oldstack = L->stack;\n  int realsize = newsize + 1 + EXTRA_STACK;\n  lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);\n  luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue);\n  L->stacksize = realsize;\n  L->stack_last = L->stack+newsize;\n  correctstack(L, oldstack);\n}\n\n\nvoid luaD_reallocCI (lua_State *L, int newsize) {\n  CallInfo *oldci = L->base_ci;\n  luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);\n  L->size_ci = newsize;\n  L->ci = (L->ci - oldci) + L->base_ci;\n  L->end_ci = L->base_ci + L->size_ci - 1;\n}\n\n\nvoid luaD_growstack (lua_State *L, int n) {\n  if (n <= L->stacksize)  /* double size is enough? */\n    luaD_reallocstack(L, 2*L->stacksize);\n  else\n    luaD_reallocstack(L, L->stacksize + n);\n}\n\n\nstatic CallInfo *growCI (lua_State *L) {\n  if (L->size_ci > LUAI_MAXCALLS)  /* overflow while handling overflow? */\n    luaD_throw(L, LUA_ERRERR);\n  else {\n    luaD_reallocCI(L, 2*L->size_ci);\n    if (L->size_ci > LUAI_MAXCALLS)\n      luaG_runerror(L, \"stack overflow\");\n  }\n  return ++L->ci;\n}\n\n\nvoid luaD_callhook (lua_State *L, int event, int line) {\n  lua_Hook hook = L->hook;\n  if (hook && L->allowhook) {\n    ptrdiff_t top = savestack(L, L->top);\n    ptrdiff_t ci_top = savestack(L, L->ci->top);\n    lua_Debug ar;\n    ar.event = event;\n    ar.currentline = line;\n    if (event == LUA_HOOKTAILRET)\n      ar.i_ci = 0;  /* tail call; no debug information about it */\n    else\n      ar.i_ci = cast_int(L->ci - L->base_ci);\n    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n    L->ci->top = L->top + LUA_MINSTACK;\n    lua_assert(L->ci->top <= L->stack_last);\n    L->allowhook = 0;  /* cannot call hooks inside a hook */\n    lua_unlock(L);\n    (*hook)(L, &ar);\n    lua_lock(L);\n    lua_assert(!L->allowhook);\n    L->allowhook = 1;\n    L->ci->top = restorestack(L, ci_top);\n    L->top = restorestack(L, top);\n  }\n}\n\n\nstatic StkId adjust_varargs (lua_State *L, Proto *p, int actual) {\n  int i;\n  int nfixargs = p->numparams;\n#if defined(LUA_COMPAT_VARARG)\n  Table *htab = NULL;\n#endif\n  StkId base, fixed;\n  for (; actual < nfixargs; ++actual)\n    setnilvalue(L->top++);\n#if defined(LUA_COMPAT_VARARG)\n  if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */\n    int nvar = actual - nfixargs;  /* number of extra arguments */\n    lua_assert(p->is_vararg & VARARG_HASARG);\n    luaC_checkGC(L);\n    htab = luaH_new(L, nvar, 1);  /* create `arg' table */\n    sethvalue2s(L, L->top, htab); /* put table on stack */\n    incr_top(L);\n    fixedstack(L);\n    for (i=0; i<nvar; i++)  /* put extra arguments into `arg' table */\n      setobj2n(L, luaH_setnum(L, htab, i+1), L->top - 1 - nvar + i);\n    unfixedstack(L);\n    /* store counter in field `n' */\n    setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, \"n\")), cast_num(nvar));\n    L->top--; /* remove table from stack */\n  }\n#endif\n  /* move fixed parameters to final position */\n  fixed = L->top - actual;  /* first fixed argument */\n  base = L->top;  /* final position of first argument */\n  for (i=0; i<nfixargs; i++) {\n    setobjs2s(L, L->top++, fixed+i);\n    setnilvalue(fixed+i);\n  }\n#if defined(LUA_COMPAT_VARARG)\n  /* add `arg' parameter */\n  if (htab) {\n    sethvalue(L, L->top++, htab);\n    lua_assert(iswhite(obj2gco(htab)));\n  }\n#endif\n  return base;\n}\n\n\nStkId luaD_tryfuncTM (lua_State *L, StkId func) {\n  const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);\n  StkId p;\n  ptrdiff_t funcr = savestack(L, func);\n  if (!ttisfunction(tm))\n    luaG_typeerror(L, func, \"call\");\n  /* Open a hole inside the stack at `func' */\n  for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);\n  incr_top(L);\n  func = restorestack(L, funcr);  /* previous call may change stack */\n  setobj2s(L, func, tm);  /* tag method is the new function to be called */\n  return func;\n}\n\n\n\n#define inc_ci(L) \\\n  ((L->ci == L->end_ci) ? growCI(L) : \\\n   (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))\n\n\nint luaD_precall_lua (lua_State *L, StkId func, int nresults) {\n  Closure *cl;\n  ptrdiff_t funcr;\n  CallInfo *ci;\n  StkId st, base;\n  Proto *p;\n\n  funcr = savestack(L, func);\n  cl = clvalue(func);\n  p = cl->l.p;\n  luaD_checkstack(L, p->maxstacksize);\n  func = restorestack(L, funcr);\n  if (!p->is_vararg) {  /* no varargs? */\n    base = func + 1;\n    if (L->top > base + p->numparams)\n      L->top = base + p->numparams;\n  }\n  else {  /* vararg function */\n    int nargs = cast_int(L->top - func) - 1;\n    base = adjust_varargs(L, p, nargs);\n    func = restorestack(L, funcr);  /* previous call may change the stack */\n  }\n  ci = L->ci;  /* now `enter' new function */\n  ci->func = func;\n  L->base = ci->base = base;\n  ci->top = L->base + p->maxstacksize;\n  lua_assert(ci->top <= L->stack_last);\n  L->savedpc = p->code;  /* starting point */\n  ci->nresults = nresults;\n  for (st = L->top; st < ci->top; st++)\n    setnilvalue(st);\n  L->top = ci->top;\n  if (L->hookmask & LUA_MASKCALL) {\n    L->savedpc++;  /* hooks assume 'pc' is already incremented */\n    luaD_callhook(L, LUA_HOOKCALL, -1);\n    L->savedpc--;  /* correct 'pc' */\n  }\n  return PCRLUA;\n}\n\nint luaD_precall_c (lua_State *L, StkId func, int nresults) {\n  ptrdiff_t funcr;\n  CallInfo *ci;\n  int n;\n\n  funcr = savestack(L, func);\n  luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */\n  ci = L->ci;  /* now `enter' new function */\n  ci->func = restorestack(L, funcr);\n  L->base = ci->base = ci->func + 1;\n  ci->top = L->top + LUA_MINSTACK;\n  lua_assert(ci->top <= L->stack_last);\n  ci->nresults = nresults;\n  if (L->hookmask & LUA_MASKCALL)\n    luaD_callhook(L, LUA_HOOKCALL, -1);\n  lua_unlock(L);\n  n = (*curr_func(L)->c.f)(L);  /* do the actual call */\n  lua_lock(L);\n  if (n < 0)  /* yielding? */\n    return PCRYIELD;\n  else {\n    luaD_poscall(L, L->top - n);\n    return PCRC;\n  }\n}\n\nint luaD_precall (lua_State *L, StkId func, int nresults) {\n  Closure *cl;\n  CallInfo *ci;\n  int ret;\n  if (!ttisfunction(func)) /* `func' is not a function? */\n    func = luaD_tryfuncTM(L, func);  /* check the `function' tag method */\n  L->ci->savedpc = L->savedpc;\n  /* allocate callinfo. */\n  ci = inc_ci(L);\n  ci->tailcalls = 0;\ntailcall:\n  cl = clvalue(func);\n  ret = cl->l.precall(L,func,nresults);\n  if(ret == PCRTAILCALL) {\n    L->ci->tailcalls++;\n    func = L->base;\n    goto tailcall;\n  }\n  return ret;\n}\n\n\nstatic StkId callrethooks (lua_State *L, StkId firstResult) {\n  ptrdiff_t fr = savestack(L, firstResult);  /* next call may change stack */\n  luaD_callhook(L, LUA_HOOKRET, -1);\n  while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls-- > 0) /* tail calls */\n    luaD_callhook(L, LUA_HOOKTAILRET, -1);\n  return restorestack(L, fr);\n}\n\n\nint luaD_poscall (lua_State *L, StkId firstResult) {\n  StkId res;\n  int wanted, i;\n  CallInfo *ci;\n  if (L->hookmask & LUA_MASKRET)\n    firstResult = callrethooks(L, firstResult);\n  ci = L->ci--;\n  ci->tailcalls = 0;\n  res = ci->func;  /* res == final position of 1st result */\n  wanted = ci->nresults;\n  L->base = (ci - 1)->base;  /* restore base */\n  L->savedpc = (ci - 1)->savedpc;  /* restore savedpc */\n  /* move results to correct place */\n  for (i = wanted; i != 0 && firstResult < L->top; i--)\n    setobjs2s(L, res++, firstResult++);\n  while (i-- > 0)\n    setnilvalue(res++);\n  L->top = res;\n  return (wanted - LUA_MULTRET);  /* 0 iff wanted == LUA_MULTRET */\n}\n\n\n/*\n** Call a function (C or Lua). The function to be called is at *func.\n** The arguments are on the stack, right after the function.\n** When returns, all the results are on the stack, starting at the original\n** function position.\n*/ \nvoid luaD_call (lua_State *L, StkId func, int nResults) {\n  if (++L->nCcalls >= LUAI_MAXCCALLS) {\n    if (L->nCcalls == LUAI_MAXCCALLS)\n      luaG_runerror(L, \"C stack overflow\");\n    else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))\n      luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */\n  }\n  if (luaD_precall(L, func, nResults) == PCRLUA)  /* is a Lua function? */\n    luaV_execute(L, 1);  /* call it */\n  L->nCcalls--;\n  luaC_checkGC(L);\n}\n\n\nstatic void resume (lua_State *L, void *ud) {\n  StkId firstArg = cast(StkId, ud);\n  CallInfo *ci = L->ci;\n  if (L->status == 0) {  /* start coroutine? */\n    lua_assert(ci == L->base_ci && firstArg > L->base);\n    if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)\n      return;\n  }\n  else {  /* resuming from previous yield */\n    lua_assert(L->status == LUA_YIELD);\n    L->status = 0;\n    if (!f_isLua(ci)) {  /* `common' yield? */\n      /* finish interrupted execution of `OP_CALL' */\n      lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||\n                 GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL);\n      if (luaD_poscall(L, firstArg))  /* complete it... */\n        L->top = L->ci->top;  /* and correct top if not multiple results */\n    }\n    else  /* yielded inside a hook: just continue its execution */\n      L->base = L->ci->base;\n  }\n  luaV_execute(L, cast_int(L->ci - L->base_ci));\n}\n\n\nstatic int resume_error (lua_State *L, const char *msg) {\n  L->top = L->ci->base;\n  setsvalue2s(L, L->top, luaS_new(L, msg));\n  incr_top(L);\n  lua_unlock(L);\n  return LUA_ERRRUN;\n}\n\n\nLUA_API int lua_resume (lua_State *L, int nargs) {\n  int status;\n  lua_lock(L);\n  if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))\n      return resume_error(L, \"cannot resume non-suspended coroutine\");\n  luai_userstateresume(L, nargs);\n  lua_assert(L->errfunc == 0 && L->nCcalls == 0);\n  status = luaD_rawrunprotected(L, resume, L->top - nargs);\n  if (status != 0) {  /* error? */\n    L->status = cast_byte(status);  /* mark thread as `dead' */\n    luaD_seterrorobj(L, status, L->top);\n    L->ci->top = L->top;\n  }\n  else\n    status = L->status;\n  lua_unlock(L);\n  return status;\n}\n\n\nLUA_API int lua_yield (lua_State *L, int nresults) {\n  luai_userstateyield(L, nresults);\n  lua_lock(L);\n  if (L->nCcalls > 0)\n    luaG_runerror(L, \"attempt to yield across metamethod/C-call boundary\");\n  L->base = L->top - nresults;  /* protect stack slots below */\n  L->status = LUA_YIELD;\n  lua_unlock(L);\n  return -1;\n}\n\n\nint luaD_pcall (lua_State *L, Pfunc func, void *u,\n                ptrdiff_t old_top, ptrdiff_t ef) {\n  int status;\n  unsigned short oldnCcalls = L->nCcalls;\n  ptrdiff_t old_ci = saveci(L, L->ci);\n  lu_byte old_allowhooks = L->allowhook;\n  ptrdiff_t old_errfunc = L->errfunc;\n  L->errfunc = ef;\n  status = luaD_rawrunprotected(L, func, u);\n  if (status != 0) {  /* an error occurred? */\n    StkId oldtop = restorestack(L, old_top);\n    luaF_close(L, oldtop);  /* close eventual pending closures */\n    luaD_seterrorobj(L, status, oldtop);\n    L->nCcalls = oldnCcalls;\n    L->ci = restoreci(L, old_ci);\n    L->base = L->ci->base;\n    L->savedpc = L->ci->savedpc;\n    L->allowhook = old_allowhooks;\n    restore_stack_limit(L);\n  }\n  L->errfunc = old_errfunc;\n  return status;\n}\n\n\n\n/*\n** Execute a protected parser.\n*/\nstruct SParser {  /* data to `f_parser' */\n  ZIO *z;\n  Mbuffer buff;  /* buffer to be used by the scanner */\n  const char *name;\n};\n\nstatic void f_parser (lua_State *L, void *ud) {\n  int i;\n  Proto *tf;\n  Closure *cl;\n  struct SParser *p = cast(struct SParser *, ud);\n  int c = luaZ_lookahead(p->z);\n  luaC_checkGC(L);\n  set_block_gc(L);  /* stop collector during parsing */\n  tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z,\n                                                             &p->buff, p->name);\n  cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));\n  cl->l.p = tf;\n  for (i = 0; i < tf->nups; i++)  /* initialize eventual upvalues */\n    cl->l.upvals[i] = luaF_newupval(L);\n  setclvalue(L, L->top, cl);\n  incr_top(L);\n  unset_block_gc(L);\n}\n\n\nint luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {\n  struct SParser p;\n  int status;\n  p.z = z; p.name = name;\n  luaZ_initbuffer(L, &p.buff);\n  status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);\n  luaZ_freebuffer(L, &p.buff);\n  return status;\n}\n\n\n"
  },
  {
    "path": "src/ldo.h",
    "content": "/*\n** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $\n** Stack and Call structure of Lua\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ldo_h\n#define ldo_h\n\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\n#define luaD_checkstack(L,n)\t\\\n  if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \\\n    luaD_growstack(L, n); \\\n  else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));\n\n\n#define incr_top(L) {luaD_checkstack(L,1); L->top++;}\n\n#define savestack(L,p)\t\t((char *)(p) - (char *)L->stack)\n#define restorestack(L,n)\t((TValue *)((char *)L->stack + (n)))\n\n#define saveci(L,p)\t\t((char *)(p) - (char *)L->base_ci)\n#define restoreci(L,n)\t\t((CallInfo *)((char *)L->base_ci + (n)))\n\n\n/* results from luaD_precall */\n#define PCRLUA\t\t0\t/* initiated a call to a Lua function */\n#define PCRC\t\t1\t/* did a call to a C function */\n#define PCRYIELD\t2\t/* C funtion yielded */\n#define PCRTAILCALL\t3\t/* JIT function tail-calling into another function. */\n#define PCRTAILRECUR\t4\t/* JIT function tail-recursive call */\n\n\n/* type of protected functions, to be ran by `runprotected' */\ntypedef void (*Pfunc) (lua_State *L, void *ud);\n\nLUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);\nLUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);\nLUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func);\nLUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);\nLUAI_FUNC int luaD_precall_lua (lua_State *L, StkId func, int nresults);\nLUAI_FUNC int luaD_precall_c (lua_State *L, StkId func, int nresults);\nLUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);\nLUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,\n                                        ptrdiff_t oldtop, ptrdiff_t ef);\nLUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);\nLUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);\nLUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);\nLUAI_FUNC void luaD_growstack (lua_State *L, int n);\n\nLUAI_FUNC void luaD_throw (lua_State *L, int errcode);\nLUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);\n\nLUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);\n\n#endif\n\n"
  },
  {
    "path": "src/ldump.c",
    "content": "/*\n** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $\n** save precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#include <stddef.h>\n\n#define ldump_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lundump.h\"\n\ntypedef struct {\n lua_State* L;\n lua_Writer writer;\n void* data;\n int strip;\n int status;\n} DumpState;\n\n#define DumpMem(b,n,size,D)\tDumpBlock(b,(n)*(size),D)\n#define DumpVar(x,D)\t \tDumpMem(&x,1,sizeof(x),D)\n\nstatic void DumpBlock(const void* b, size_t size, DumpState* D)\n{\n if (D->status==0)\n {\n  lua_unlock(D->L);\n  D->status=(*D->writer)(D->L,b,size,D->data);\n  lua_lock(D->L);\n }\n}\n\nstatic void DumpChar(int y, DumpState* D)\n{\n char x=(char)y;\n DumpVar(x,D);\n}\n\nstatic void DumpInt(int x, DumpState* D)\n{\n DumpVar(x,D);\n}\n\nstatic void DumpNumber(lua_Number x, DumpState* D)\n{\n DumpVar(x,D);\n}\n\nstatic void DumpVector(const void* b, int n, size_t size, DumpState* D)\n{\n DumpInt(n,D);\n DumpMem(b,n,size,D);\n}\n\nstatic void DumpString(const TString* s, DumpState* D)\n{\n if (s==NULL || getstr(s)==NULL)\n {\n  size_t size=0;\n  DumpVar(size,D);\n }\n else\n {\n  size_t size=s->tsv.len+1;\t\t/* include trailing '\\0' */\n  DumpVar(size,D);\n  DumpBlock(getstr(s),size,D);\n }\n}\n\n#define DumpCode(f,D)\t DumpVector(f->code,f->sizecode,sizeof(Instruction),D)\n\nstatic void DumpFunction(const Proto* f, const TString* p, DumpState* D);\n\nstatic void DumpConstants(const Proto* f, DumpState* D)\n{\n int i,n=f->sizek;\n DumpInt(n,D);\n for (i=0; i<n; i++)\n {\n  const TValue* o=&f->k[i];\n  DumpChar(ttype(o),D);\n  switch (ttype(o))\n  {\n   case LUA_TNIL:\n\tbreak;\n   case LUA_TBOOLEAN:\n\tDumpChar(bvalue(o),D);\n\tbreak;\n   case LUA_TNUMBER:\n\tDumpNumber(nvalue(o),D);\n\tbreak;\n   case LUA_TSTRING:\n\tDumpString(rawtsvalue(o),D);\n\tbreak;\n   default:\n\tlua_assert(0);\t\t\t/* cannot happen */\n\tbreak;\n  }\n }\n n=f->sizep;\n DumpInt(n,D);\n for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);\n}\n\nstatic void DumpDebug(const Proto* f, DumpState* D)\n{\n int i,n;\n n= (D->strip) ? 0 : f->sizelineinfo;\n DumpVector(f->lineinfo,n,sizeof(int),D);\n n= (D->strip) ? 0 : f->sizelocvars;\n DumpInt(n,D);\n for (i=0; i<n; i++)\n {\n  DumpString(f->locvars[i].varname,D);\n  DumpInt(f->locvars[i].startpc,D);\n  DumpInt(f->locvars[i].endpc,D);\n }\n n= (D->strip) ? 0 : f->sizeupvalues;\n DumpInt(n,D);\n for (i=0; i<n; i++) DumpString(f->upvalues[i],D);\n}\n\nstatic void DumpFunction(const Proto* f, const TString* p, DumpState* D)\n{\n DumpString((f->source==p || D->strip) ? NULL : f->source,D);\n DumpInt(f->linedefined,D);\n DumpInt(f->lastlinedefined,D);\n DumpChar(f->nups,D);\n DumpChar(f->numparams,D);\n DumpChar(f->is_vararg,D);\n DumpChar(f->maxstacksize,D);\n DumpCode(f,D);\n DumpConstants(f,D);\n DumpDebug(f,D);\n}\n\nstatic void DumpHeader(DumpState* D)\n{\n char h[LUAC_HEADERSIZE];\n luaU_header(h);\n DumpBlock(h,LUAC_HEADERSIZE,D);\n}\n\n/*\n** dump Lua function as precompiled chunk\n*/\nint luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)\n{\n DumpState D;\n D.L=L;\n D.writer=w;\n D.data=data;\n D.strip=strip;\n D.status=0;\n DumpHeader(&D);\n DumpFunction(f,NULL,&D);\n return D.status;\n}\n"
  },
  {
    "path": "src/lfunc.c",
    "content": "/*\n** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define lfunc_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"ldo.h\"\n\n\n\nClosure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {\n  Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));\n  luaC_link(L, obj2gco(c), LUA_TFUNCTION);\n  c->c.precall = luaD_precall_c;\n  c->c.isC = 1;\n  c->c.env = e;\n  c->c.nupvalues = cast_byte(nelems);\n  return c;\n}\n\n\nClosure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {\n  Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));\n  luaC_link(L, obj2gco(c), LUA_TFUNCTION);\n  c->l.precall = JIT_PRECALL;\n  c->l.isC = 0;\n  c->l.env = e;\n  c->l.nupvalues = cast_byte(nelems);\n  while (nelems--) c->l.upvals[nelems] = NULL;\n  return c;\n}\n\n\nUpVal *luaF_newupval (lua_State *L) {\n  UpVal *uv = luaM_new(L, UpVal);\n  luaC_link(L, obj2gco(uv), LUA_TUPVAL);\n  uv->v = &uv->u.value;\n  setnilvalue(uv->v);\n  return uv;\n}\n\n\nUpVal *luaF_findupval (lua_State *L, StkId level) {\n  global_State *g = G(L);\n  GCObject **pp = &L->openupval;\n  UpVal *p;\n  UpVal *uv;\n  while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {\n    lua_assert(p->v != &p->u.value);\n    if (p->v == level) {  /* found a corresponding upvalue? */\n      if (isdead(g, obj2gco(p)))  /* is it dead? */\n        changewhite(obj2gco(p));  /* ressurect it */\n      return p;\n    }\n    pp = &p->next;\n  }\n  uv = luaM_new(L, UpVal);  /* not found: create a new one */\n  uv->tt = LUA_TUPVAL;\n  uv->v = level;  /* current value lives in the stack */\n  uv->next = *pp;  /* chain it in the proper position */\n  *pp = obj2gco(uv);\n  uv->u.l.prev = &g->uvhead;  /* double link it in `uvhead' list */\n  uv->u.l.next = g->uvhead.u.l.next;\n  uv->u.l.next->u.l.prev = uv;\n  g->uvhead.u.l.next = uv;\n  luaC_marknew(L, obj2gco(uv));\n  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);\n  return uv;\n}\n\n\nstatic void unlinkupval (UpVal *uv) {\n  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);\n  uv->u.l.next->u.l.prev = uv->u.l.prev;  /* remove from `uvhead' list */\n  uv->u.l.prev->u.l.next = uv->u.l.next;\n}\n\n\nvoid luaF_freeupval (lua_State *L, UpVal *uv) {\n  if (uv->v != &uv->u.value)  /* is it open? */\n    unlinkupval(uv);  /* remove from open list */\n  luaM_free(L, uv);  /* free upvalue */\n}\n\n\nvoid luaF_close (lua_State *L, StkId level) {\n  UpVal *uv;\n  global_State *g = G(L);\n  while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {\n    GCObject *o = obj2gco(uv);\n    lua_assert(!isblack(o) && uv->v != &uv->u.value);\n    L->openupval = uv->next;  /* remove from `open' list */\n    if (isdead(g, o))\n      luaF_freeupval(L, uv);  /* free upvalue */\n    else {\n      unlinkupval(uv);\n      setobj(L, &uv->u.value, uv->v);\n      uv->v = &uv->u.value;  /* now current value lives here */\n      luaC_linkupval(L, uv);  /* link upvalue into `gcroot' list */\n    }\n  }\n}\n\n\nProto *luaF_newproto (lua_State *L) {\n  Proto *f = luaM_new(L, Proto);\n  luaC_link(L, obj2gco(f), LUA_TPROTO);\n  f->k = NULL;\n  f->sizek = 0;\n  f->p = NULL;\n  f->sizep = 0;\n  f->code = NULL;\n  f->sizecode = 0;\n  f->sizelineinfo = 0;\n  f->sizeupvalues = 0;\n  f->nups = 0;\n  f->upvalues = NULL;\n  f->numparams = 0;\n  f->is_vararg = 0;\n  f->maxstacksize = 0;\n  f->lineinfo = NULL;\n  f->sizelocvars = 0;\n  f->locvars = NULL;\n  f->linedefined = 0;\n  f->lastlinedefined = 0;\n  f->source = NULL;\n  JIT_NEWPROTO(L, f);\n  return f;\n}\n\n\nvoid luaF_freeproto (lua_State *L, Proto *f) {\n  JIT_FREEPROTO(L, f);\n  luaM_freearray(L, f->code, f->sizecode, Instruction);\n  luaM_freearray(L, f->p, f->sizep, Proto *);\n  luaM_freearray(L, f->k, f->sizek, TValue);\n  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);\n  luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);\n  luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);\n  luaM_free(L, f);\n}\n\n\nvoid luaF_freeclosure (lua_State *L, Closure *c) {\n  int size = (cl_isC(c)) ? sizeCclosure(c->c.nupvalues) :\n                          sizeLclosure(c->l.nupvalues);\n  luaM_freemem(L, c, size);\n}\n\n\n/*\n** Look for n-th local variable at line `line' in function `func'.\n** Returns NULL if not found.\n*/\nconst char *luaF_getlocalname (const Proto *f, int local_number, int pc) {\n  int i;\n  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {\n    if (pc < f->locvars[i].endpc) {  /* is variable active? */\n      local_number--;\n      if (local_number == 0)\n        return getstr(f->locvars[i].varname);\n    }\n  }\n  return NULL;  /* not found */\n}\n\n"
  },
  {
    "path": "src/lfunc.h",
    "content": "/*\n** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions to manipulate prototypes and closures\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lfunc_h\n#define lfunc_h\n\n\n#include \"lobject.h\"\n\n\n#define sizeCclosure(n)\t(cast(int, sizeof(CClosure)) + \\\n                         cast(int, sizeof(TValue)*((n)-1)))\n\n#define sizeLclosure(n)\t(cast(int, sizeof(LClosure)) + \\\n                         cast(int, sizeof(TValue *)*((n)-1)))\n\n\nLUAI_FUNC Proto *luaF_newproto (lua_State *L);\nLUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);\nLUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);\nLUAI_FUNC UpVal *luaF_newupval (lua_State *L);\nLUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);\nLUAI_FUNC void luaF_close (lua_State *L, StkId level);\nLUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);\nLUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);\nLUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);\nLUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,\n                                         int pc);\n\n\n#endif\n"
  },
  {
    "path": "src/lgc.c",
    "content": "/*\n** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#include <string.h>\n\n#define lgc_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#define GCSTEPSIZE\t1024u\n#define GCSWEEPMAX\t40\n#define GCSWEEPCOST\t10\n#define GCFINALIZECOST\t100\n\n\n#define maskmarks\tcast_byte(~(bitmask(BLACKBIT)|WHITEBITS))\n\n#define makewhite(g,x)\t\\\n   ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))\n\n#define white2gray(x)\treset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)\n#define black2gray(x)\tresetbit((x)->gch.marked, BLACKBIT)\n\n#define stringmark(s)\treset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)\n\n\n#define isfinalized(u)\t\ttestbit((u)->marked, FINALIZEDBIT)\n#define markfinalized(u)\tl_setbit((u)->marked, FINALIZEDBIT)\n\n\n#define KEYWEAK         bitmask(KEYWEAKBIT)\n#define VALUEWEAK       bitmask(VALUEWEAKBIT)\n\n\n\n#define markvalue(g,o) { checkconsistency(o); \\\n  if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); }\n\n#define markobject(g,t) { if (iswhite(obj2gco(t))) \\\n\t\treallymarkobject(g, obj2gco(t)); }\n\n\n#define setthreshold(g)  (g->GCthreshold = (g->estimate/100) * g->gcpause)\n\n\nstatic void removeentry (Node *n) {\n  lua_assert(ttisnil(gval(n)));\n  if (iscollectable(gkey(n)))\n    setttype(gkey(n), LUA_TDEADKEY);  /* dead key; remove it */\n}\n\n\nstatic void reallymarkobject (global_State *g, GCObject *o) {\n  lua_assert(iswhite(o) && !isdead(g, o));\n  white2gray(o);\n  switch (o->gch.tt) {\n    case LUA_TSTRING: {\n      return;\n    }\n    case LUA_TUSERDATA: {\n      Table *mt = gco2u(o)->metatable;\n      gray2black(o);  /* udata are never gray */\n      if (mt) markobject(g, mt);\n      markobject(g, gco2u(o)->env);\n      return;\n    }\n    case LUA_TUPVAL: {\n      UpVal *uv = gco2uv(o);\n      markvalue(g, uv->v);\n      if (uv->v == &uv->u.value)  /* closed? */\n        gray2black(o);  /* open upvalues are never black */\n      return;\n    }\n    case LUA_TFUNCTION: {\n      gco2cl(o)->c.gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    case LUA_TTABLE: {\n      gco2h(o)->gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    case LUA_TTHREAD: {\n      gco2th(o)->gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    case LUA_TPROTO: {\n      gco2p(o)->gclist = g->gray;\n      g->gray = o;\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\nstatic void marktmu (global_State *g) {\n  GCObject *u = g->tmudata;\n  if (u) {\n    do {\n      u = u->gch.next;\n      makewhite(g, u);  /* may be marked, if left from previous GC */\n      reallymarkobject(g, u);\n    } while (u != g->tmudata);\n  }\n}\n\n\n/* move `dead' udata that need finalization to list `tmudata' */\nsize_t luaC_separateudata (lua_State *L, int all) {\n  global_State *g = G(L);\n  size_t deadmem = 0;\n  GCObject **p = &g->mainthread->next;\n  GCObject *curr;\n  while ((curr = *p) != NULL) {\n    if (!(iswhite(curr) || all) || isfinalized(gco2u(curr)))\n      p = &curr->gch.next;  /* don't bother with them */\n    else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {\n      markfinalized(gco2u(curr));  /* don't need finalization */\n      p = &curr->gch.next;\n    }\n    else {  /* must call its gc method */\n      deadmem += sizeudata(gco2u(curr));\n      markfinalized(gco2u(curr));\n      *p = curr->gch.next;\n      /* link `curr' at the end of `tmudata' list */\n      if (g->tmudata == NULL)  /* list is empty? */\n        g->tmudata = curr->gch.next = curr;  /* creates a circular list */\n      else {\n        curr->gch.next = g->tmudata->gch.next;\n        g->tmudata->gch.next = curr;\n        g->tmudata = curr;\n      }\n    }\n  }\n  return deadmem;\n}\n\n\nstatic int traversetable (global_State *g, Table *h) {\n  int i;\n  int weakkey = 0;\n  int weakvalue = 0;\n  const TValue *mode;\n  if (h->metatable)\n    markobject(g, h->metatable);\n  mode = gfasttm(g, h->metatable, TM_MODE);\n  if (mode && ttisstring(mode)) {  /* is there a weak mode? */\n    weakkey = (strchr(svalue(mode), 'k') != NULL);\n    weakvalue = (strchr(svalue(mode), 'v') != NULL);\n    if (weakkey || weakvalue) {  /* is really weak? */\n      h->marked &= ~(KEYWEAK | VALUEWEAK);  /* clear bits */\n      h->marked |= cast_byte((weakkey << KEYWEAKBIT) |\n                             (weakvalue << VALUEWEAKBIT));\n      h->gclist = g->weak;  /* must be cleared after GC, ... */\n      g->weak = obj2gco(h);  /* ... so put in the appropriate list */\n    }\n  }\n  if (weakkey && weakvalue) return 1;\n  if (!weakvalue) {\n    i = h->sizearray;\n    while (i--)\n      markvalue(g, &h->array[i]);\n  }\n  i = sizenode(h);\n  while (i--) {\n    Node *n = gnode(h, i);\n    lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n)));\n    if (ttisnil(gval(n)))\n      removeentry(n);  /* remove empty entries */\n    else {\n      lua_assert(!ttisnil(gkey(n)));\n      if (!weakkey) markvalue(g, gkey(n));\n      if (!weakvalue) markvalue(g, gval(n));\n    }\n  }\n  return weakkey || weakvalue;\n}\n\n\n/*\n** All marks are conditional because a GC may happen while the\n** prototype is still being created\n*/\nstatic void traverseproto (global_State *g, Proto *f) {\n  int i;\n  if (f->source) stringmark(f->source);\n  for (i=0; i<f->sizek; i++)  /* mark literals */\n    markvalue(g, &f->k[i]);\n  for (i=0; i<f->sizeupvalues; i++) {  /* mark upvalue names */\n    if (f->upvalues[i])\n      stringmark(f->upvalues[i]);\n  }\n  for (i=0; i<f->sizep; i++) {  /* mark nested protos */\n    if (f->p[i])\n      markobject(g, f->p[i]);\n  }\n  for (i=0; i<f->sizelocvars; i++) {  /* mark local-variable names */\n    if (f->locvars[i].varname)\n      stringmark(f->locvars[i].varname);\n  }\n}\n\n\n\nstatic void traverseclosure (global_State *g, Closure *cl) {\n  markobject(g, cl->c.env);\n  if (cl_isC(cl)) {\n    int i;\n    for (i=0; i<cl->c.nupvalues; i++)  /* mark its upvalues */\n      markvalue(g, &cl->c.upvalue[i]);\n  }\n  else {\n    int i;\n    lua_assert(cl->l.nupvalues == cl->l.p->nups);\n    markobject(g, cl->l.p);\n    for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */\n      if(cl->l.upvals[i])\n        markobject(g, cl->l.upvals[i]);\n    }\n  }\n}\n\n\nstatic void checkstacksizes (lua_State *L, StkId max) {\n  int ci_used = cast_int(L->ci - L->base_ci);  /* number of `ci' in use */\n  int s_used = cast_int(max - L->stack);  /* part of stack in use */\n  if (L->size_ci > LUAI_MAXCALLS)  /* handling overflow? */\n    return;  /* do not touch the stacks */\n  if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)\n    luaD_reallocCI(L, L->size_ci/2);  /* still big enough... */\n  condhardstacktests(luaD_reallocCI(L, ci_used + 1));\n  if (4*s_used < L->stacksize &&\n      2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)\n    luaD_reallocstack(L, L->stacksize/2);  /* still big enough... */\n  condhardstacktests(luaD_reallocstack(L, s_used));\n}\n\n\nstatic void traversestack (global_State *g, lua_State *l) {\n  StkId o, lim;\n  CallInfo *ci;\n  markvalue(g, gt(l));\n  lim = l->top;\n  if(l->stack == NULL) return; /* no stack to traverse */\n  for (ci = l->base_ci; ci <= l->ci; ci++) {\n    lua_assert(ci->top <= l->stack_last);\n    if (lim < ci->top) lim = ci->top;\n  }\n  for (o = l->stack; o < l->top; o++)\n    markvalue(g, o);\n  for (; o <= lim; o++)\n    setnilvalue(o);\n  if (!isfixedstack(l)) /* if stack size is fixed, can't resize it. */\n    checkstacksizes(l, lim);\n}\n\n\n/*\n** traverse one gray object, turning it to black.\n** Returns `quantity' traversed.\n*/\nstatic l_mem propagatemark (global_State *g) {\n  GCObject *o = g->gray;\n  lua_assert(isgray(o));\n  gray2black(o);\n  switch (o->gch.tt) {\n    case LUA_TTABLE: {\n      Table *h = gco2h(o);\n      g->gray = h->gclist;\n      if (traversetable(g, h))  /* table is weak? */\n        black2gray(o);  /* keep it gray */\n      return sizeof(Table) + sizeof(TValue) * h->sizearray +\n                             sizeof(Node) * sizenode(h);\n    }\n    case LUA_TFUNCTION: {\n      Closure *cl = gco2cl(o);\n      g->gray = cl->c.gclist;\n      traverseclosure(g, cl);\n      return (cl_isC(cl)) ? sizeCclosure(cl->c.nupvalues) :\n                           sizeLclosure(cl->l.nupvalues);\n    }\n    case LUA_TTHREAD: {\n      lua_State *th = gco2th(o);\n      g->gray = th->gclist;\n      th->gclist = g->grayagain;\n      g->grayagain = o;\n      black2gray(o);\n      traversestack(g, th);\n      return sizeof(lua_State) + sizeof(TValue) * th->stacksize +\n                                 sizeof(CallInfo) * th->size_ci;\n    }\n    case LUA_TPROTO: {\n      Proto *p = gco2p(o);\n      g->gray = p->gclist;\n      traverseproto(g, p);\n      return sizeof(Proto) + sizeof(Instruction) * p->sizecode +\n                             sizeof(Proto *) * p->sizep +\n                             sizeof(TValue) * p->sizek + \n                             sizeof(int) * p->sizelineinfo +\n                             sizeof(LocVar) * p->sizelocvars +\n                             sizeof(TString *) * p->sizeupvalues;\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nstatic size_t propagateall (global_State *g) {\n  size_t m = 0;\n  while (g->gray) m += propagatemark(g);\n  return m;\n}\n\n\n/*\n** The next function tells whether a key or value can be cleared from\n** a weak table. Non-collectable objects are never removed from weak\n** tables. Strings behave as `values', so are never removed too. for\n** other objects: if really collected, cannot keep them; for userdata\n** being finalized, keep them in keys, but not in values\n*/\nstatic int iscleared (const TValue *o, int iskey) {\n  if (!iscollectable(o)) return 0;\n  if (ttisstring(o)) {\n    stringmark(rawtsvalue(o));  /* strings are `values', so are never weak */\n    return 0;\n  }\n  return iswhite(gcvalue(o)) ||\n    (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));\n}\n\n\n/*\n** clear collected entries from weaktables\n*/\nstatic void cleartable (GCObject *l) {\n  while (l) {\n    Table *h = gco2h(l);\n    int i = h->sizearray;\n    lua_assert(testbit(h->marked, VALUEWEAKBIT) ||\n               testbit(h->marked, KEYWEAKBIT));\n    if (testbit(h->marked, VALUEWEAKBIT)) {\n      while (i--) {\n        TValue *o = &h->array[i];\n        if (iscleared(o, 0))  /* value was collected? */\n          setnilvalue(o);  /* remove value */\n      }\n    }\n    i = sizenode(h);\n    while (i--) {\n      Node *n = gnode(h, i);\n      if (!ttisnil(gval(n)) &&  /* non-empty entry? */\n          (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) {\n        setnilvalue(gval(n));  /* remove value ... */\n        removeentry(n);  /* remove entry from table */\n      }\n    }\n    l = h->gclist;\n  }\n}\n\n\nstatic void freeobj (lua_State *L, GCObject *o) {\n  switch (o->gch.tt) {\n    case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;\n    case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;\n    case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;\n    case LUA_TTABLE: luaH_free(L, gco2h(o)); break;\n    case LUA_TTHREAD: {\n      lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);\n      luaE_freethread(L, gco2th(o));\n      break;\n    }\n    case LUA_TSTRING: {\n      G(L)->strt.nuse--;\n      luaM_freemem(L, o, sizestring(gco2ts(o)));\n      break;\n    }\n    case LUA_TUSERDATA: {\n      luaM_freemem(L, o, sizeudata(gco2u(o)));\n      break;\n    }\n    default: lua_assert(0);\n  }\n}\n\n\n\n#define sweepwholelist(L,p)\tsweeplist(L,p,MAX_LUMEM)\n\n\nstatic GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {\n  GCObject *curr;\n  global_State *g = G(L);\n  int deadmask = otherwhite(g);\n  while ((curr = *p) != NULL && count-- > 0) {\n    if (curr->gch.tt == LUA_TTHREAD)  /* sweep open upvalues of each thread */\n      sweepwholelist(L, &gco2th(curr)->openupval);\n    if ((curr->gch.marked ^ WHITEBITS) & deadmask) {  /* not dead? */\n      lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT));\n      makewhite(g, curr);  /* make it white (for next cycle) */\n      p = &curr->gch.next;\n    }\n    else {  /* must erase `curr' */\n      lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT));\n      *p = curr->gch.next;\n      freeobj(L, curr);\n    }\n  }\n  return p;\n}\n\n\nstatic void checkSizes (lua_State *L) {\n  global_State *g = G(L);\n  /* check size of string hash */\n  if (g->strt.nuse < cast(lu_int32, g->strt.size/4) &&\n      g->strt.size > MINSTRTABSIZE*2)\n    luaS_resize(L, g->strt.size/2);  /* table is too big */\n  /* it is not safe to re-size the buffer if it is in use. */\n  if (luaZ_bufflen(&g->buff) > 0) return;\n  /* check size of buffer */\n  if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) {  /* buffer too big? */\n    size_t newsize = luaZ_sizebuffer(&g->buff) / 2;\n    luaZ_resizebuffer(L, &g->buff, newsize);\n  }\n}\n\n\nstatic void GCTM (lua_State *L) {\n  global_State *g = G(L);\n  GCObject *o = g->tmudata->gch.next;  /* get first element */\n  Udata *udata = rawgco2u(o);\n  const TValue *tm;\n  /* remove udata from `tmudata' */\n  if (o == g->tmudata)  /* last element? */\n    g->tmudata = NULL;\n  else\n    g->tmudata->gch.next = udata->uv.next;\n  udata->uv.next = g->mainthread->next;  /* return it to `root' list */\n  g->mainthread->next = o;\n  makewhite(g, o);\n  tm = fasttm(L, udata->uv.metatable, TM_GC);\n  if (tm != NULL) {\n    lu_byte oldah = L->allowhook;\n    lu_mem oldt = g->GCthreshold;\n    L->allowhook = 0;  /* stop debug hooks during GC tag method */\n    g->GCthreshold = 2*g->totalbytes;  /* avoid GC steps */\n    setobj2s(L, L->top, tm);\n    setuvalue(L, L->top+1, udata);\n    L->top += 2;\n    luaD_call(L, L->top - 2, 0);\n    L->allowhook = oldah;  /* restore hooks */\n    g->GCthreshold = oldt;  /* restore threshold */\n  }\n}\n\n\n/*\n** Call all GC tag methods\n*/\nvoid luaC_callGCTM (lua_State *L) {\n  while (G(L)->tmudata)\n    GCTM(L);\n}\n\n\nvoid luaC_freeall (lua_State *L) {\n  global_State *g = G(L);\n  int i;\n  g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT);  /* mask to collect all elements */\n  sweepwholelist(L, &g->rootgc);\n  for (i = 0; i < g->strt.size; i++)  /* free all string lists */\n    sweepwholelist(L, &g->strt.hash[i]);\n}\n\n\nstatic void markmt (global_State *g) {\n  int i;\n  for (i=0; i<NUM_TAGS; i++)\n    if (g->mt[i]) markobject(g, g->mt[i]);\n}\n\n\n/* mark root set */\nstatic void markroot (lua_State *L) {\n  global_State *g = G(L);\n  g->gray = NULL;\n  g->grayagain = NULL;\n  g->weak = NULL;\n  markobject(g, g->mainthread);\n  /* make global table be traversed before main stack */\n  markvalue(g, gt(g->mainthread));\n  markvalue(g, registry(L));\n  markmt(g);\n  g->gcstate = GCSpropagate;\n}\n\n\nstatic void remarkupvals (global_State *g) {\n  UpVal *uv;\n  for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {\n    lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);\n    if (isgray(obj2gco(uv)))\n      markvalue(g, uv->v);\n  }\n}\n\n\nstatic void atomic (lua_State *L) {\n  global_State *g = G(L);\n  size_t udsize;  /* total size of userdata to be finalized */\n  /* remark occasional upvalues of (maybe) dead threads */\n  remarkupvals(g);\n  /* traverse objects cautch by write barrier and by 'remarkupvals' */\n  propagateall(g);\n  /* remark weak tables */\n  g->gray = g->weak;\n  g->weak = NULL;\n  lua_assert(!iswhite(obj2gco(g->mainthread)));\n  markobject(g, L);  /* mark running thread */\n  markmt(g);  /* mark basic metatables (again) */\n  propagateall(g);\n  /* remark gray again */\n  g->gray = g->grayagain;\n  g->grayagain = NULL;\n  propagateall(g);\n  udsize = luaC_separateudata(L, 0);  /* separate userdata to be finalized */\n  marktmu(g);  /* mark `preserved' userdata */\n  udsize += propagateall(g);  /* remark, to propagate `preserveness' */\n  cleartable(g->weak);  /* remove collected objects from weak tables */\n  /* flip current white */\n  g->currentwhite = cast_byte(otherwhite(g));\n  g->sweepstrgc = 0;\n  g->sweepgc = &g->rootgc;\n  g->gcstate = GCSsweepstring;\n  g->estimate = g->totalbytes - udsize;  /* first estimate */\n}\n\n\nstatic l_mem singlestep (lua_State *L) {\n  global_State *g = G(L);\n  /*lua_checkmemory(L);*/\n  switch (g->gcstate) {\n    case GCSpause: {\n      markroot(L);  /* start a new collection */\n      return 0;\n    }\n    case GCSpropagate: {\n      if (g->gray)\n        return propagatemark(g);\n      else {  /* no more `gray' objects */\n        atomic(L);  /* finish mark phase */\n        return 0;\n      }\n    }\n    case GCSsweepstring: {\n      lu_mem old = g->totalbytes;\n      sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);\n      if (g->sweepstrgc >= g->strt.size)  /* nothing more to sweep? */\n        g->gcstate = GCSsweep;  /* end sweep-string phase */\n      lua_assert(old >= g->totalbytes);\n      g->estimate -= old - g->totalbytes;\n      return GCSWEEPCOST;\n    }\n    case GCSsweep: {\n      lu_mem old = g->totalbytes;\n      g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);\n      if (*g->sweepgc == NULL) {  /* nothing more to sweep? */\n        checkSizes(L);\n        g->gcstate = GCSfinalize;  /* end sweep phase */\n      }\n      lua_assert(old >= g->totalbytes);\n      g->estimate -= old - g->totalbytes;\n      return GCSWEEPMAX*GCSWEEPCOST;\n    }\n    case GCSfinalize: {\n      if (g->tmudata) {\n        GCTM(L);\n        if (g->estimate > GCFINALIZECOST)\n          g->estimate -= GCFINALIZECOST;\n        return GCFINALIZECOST;\n      }\n      else {\n        g->gcstate = GCSpause;  /* end collection */\n        g->gcdept = 0;\n        return 0;\n      }\n    }\n    default: lua_assert(0); return 0;\n  }\n}\n\n\nvoid luaC_step (lua_State *L) {\n  global_State *g = G(L);\n  if(is_block_gc(L)) return;\n  set_block_gc(L);\n  l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;\n  if (lim == 0)\n    lim = (MAX_LUMEM-1)/2;  /* no limit */\n  g->gcdept += g->totalbytes - g->GCthreshold;\n  if (g->estimate > g->totalbytes)\n    g->estimate = g->totalbytes;\n  do {\n    lim -= singlestep(L);\n    if (g->gcstate == GCSpause)\n      break;\n  } while (lim > 0);\n  if (g->gcstate != GCSpause) {\n    if (g->gcdept < GCSTEPSIZE)\n      g->GCthreshold = g->totalbytes + GCSTEPSIZE;  /* - lim/g->gcstepmul;*/\n    else {\n      g->gcdept -= GCSTEPSIZE;\n      g->GCthreshold = g->totalbytes;\n    }\n  }\n  else {\n    lua_assert(g->totalbytes >= g->estimate);\n    setthreshold(g);\n  }\n  unset_block_gc(L);\n}\n\n\nvoid luaC_fullgc (lua_State *L) {\n  global_State *g = G(L);\n  if(is_block_gc(L)) return;\n  set_block_gc(L);\n  if (g->gcstate <= GCSpropagate) {\n    /* reset sweep marks to sweep all elements (returning them to white) */\n    g->sweepstrgc = 0;\n    g->sweepgc = &g->rootgc;\n    /* reset other collector lists */\n    g->gray = NULL;\n    g->grayagain = NULL;\n    g->weak = NULL;\n    g->gcstate = GCSsweepstring;\n  }\n  lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate);\n  /* finish any pending sweep phase */\n  while (g->gcstate != GCSfinalize) {\n    lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep);\n    singlestep(L);\n  }\n  markroot(L);\n  while (g->gcstate != GCSpause) {\n    singlestep(L);\n  }\n  setthreshold(g);\n  unset_block_gc(L);\n}\n\n\nvoid luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {\n  global_State *g = G(L);\n  lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));\n  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);\n  lua_assert(ttype(&o->gch) != LUA_TTABLE);\n  /* must keep invariant? */\n  if (g->gcstate == GCSpropagate)\n    reallymarkobject(g, v);  /* restore invariant */\n  else  /* don't mind */\n    makewhite(g, o);  /* mark as white just to avoid other barriers */\n}\n\n\nvoid luaC_barrierback (lua_State *L, Table *t) {\n  global_State *g = G(L);\n  GCObject *o = obj2gco(t);\n  lua_assert(isblack(o) && !isdead(g, o));\n  lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);\n  black2gray(o);  /* make table gray (again) */\n  t->gclist = g->grayagain;\n  g->grayagain = o;\n}\n\n\nvoid luaC_marknew (lua_State *L, GCObject *o) {\n  global_State *g = G(L);\n  o->gch.marked = luaC_white(g);\n  if (g->gcstate == GCSpropagate)\n    reallymarkobject(g, o);  /* mark new objects as gray during propagate state. */\n}\n\n\nvoid luaC_link (lua_State *L, GCObject *o, lu_byte tt) {\n  global_State *g = G(L);\n  o->gch.next = g->rootgc;\n  g->rootgc = o;\n  o->gch.marked = luaC_white(g);\n  o->gch.tt = tt;\n}\n\n\nvoid luaC_linkupval (lua_State *L, UpVal *uv) {\n  global_State *g = G(L);\n  GCObject *o = obj2gco(uv);\n  o->gch.next = g->rootgc;  /* link upvalue into `rootgc' list */\n  g->rootgc = o;\n  if (isgray(o)) { \n    if (g->gcstate == GCSpropagate) {\n      gray2black(o);  /* closed upvalues need barrier */\n      luaC_barrier(L, uv, uv->v);\n    }\n    else {  /* sweep phase: sweep it (turning it into white) */\n      makewhite(g, o);\n      lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/lgc.h",
    "content": "/*\n** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $\n** Garbage Collector\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lgc_h\n#define lgc_h\n\n\n#include \"lobject.h\"\n\n\n/*\n** Possible states of the Garbage Collector\n*/\n#define GCSpause\t0\n#define GCSpropagate\t1\n#define GCSsweepstring\t2\n#define GCSsweep\t3\n#define GCSfinalize\t4\n\n\n/*\n** some userful bit tricks\n*/\n#define resetbits(x,m)\t((x) &= cast(lu_byte, ~(m)))\n#define setbits(x,m)\t((x) |= (m))\n#define testbits(x,m)\t((x) & (m))\n#define bitmask(b)\t(1<<(b))\n#define bit2mask(b1,b2)\t(bitmask(b1) | bitmask(b2))\n#define l_setbit(x,b)\tsetbits(x, bitmask(b))\n#define resetbit(x,b)\tresetbits(x, bitmask(b))\n#define testbit(x,b)\ttestbits(x, bitmask(b))\n#define set2bits(x,b1,b2)\tsetbits(x, (bit2mask(b1, b2)))\n#define reset2bits(x,b1,b2)\tresetbits(x, (bit2mask(b1, b2)))\n#define test2bits(x,b1,b2)\ttestbits(x, (bit2mask(b1, b2)))\n\n\n/*\n** Possible Garbage Collector flags.\n** Layout for bit use in 'gsflags' field in global_State structure.\n** bit 0 - Protect GC from recursive calls.\n** bit 1 - Don't try to shrink string table if EGC was called during a string table resize.\n*/\n#define GCFlagsNone\t\t0\n#define GCBlockGCBit\t0\n\n\n#define is_block_gc(L) testbit(G(L)->gcflags, GCBlockGCBit)\n#define set_block_gc(L) l_setbit(G(L)->gcflags, GCBlockGCBit)\n#define unset_block_gc(L) resetbit(G(L)->gcflags, GCBlockGCBit)\n\n/*\n** Layout for bit use in `marked' field:\n** bit 0 - object is white (type 0)\n** bit 1 - object is white (type 1)\n** bit 2 - object is black\n** bit 3 - for thread: Don't resize thread's stack\n** bit 3 - for userdata: has been finalized\n** bit 3 - for tables: has weak keys\n** bit 4 - for tables: has weak values\n** bit 5 - object is fixed (should not be collected)\n** bit 6 - object is \"super\" fixed (only the main thread)\n*/\n\n\n#define WHITE0BIT\t0\n#define WHITE1BIT\t1\n#define BLACKBIT\t2\n#define FIXEDSTACKBIT\t3\n#define FINALIZEDBIT\t3\n#define KEYWEAKBIT\t3\n#define VALUEWEAKBIT\t4\n#define FIXEDBIT\t5\n#define SFIXEDBIT\t6\n#define WHITEBITS\tbit2mask(WHITE0BIT, WHITE1BIT)\n\n\n#define iswhite(x)      test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)\n#define isblack(x)      testbit((x)->gch.marked, BLACKBIT)\n#define isgray(x)\t(!isblack(x) && !iswhite(x))\n\n#define otherwhite(g)\t(g->currentwhite ^ WHITEBITS)\n#define isdead(g,v)\t((v)->gch.marked & otherwhite(g) & WHITEBITS)\n\n#define changewhite(x)\t((x)->gch.marked ^= WHITEBITS)\n#define gray2black(x)\tl_setbit((x)->gch.marked, BLACKBIT)\n\n#define valiswhite(x)\t(iscollectable(x) && iswhite(gcvalue(x)))\n\n#define luaC_white(g)\tcast(lu_byte, (g)->currentwhite & WHITEBITS)\n\n#define isfixedstack(x)\ttestbit((x)->marked, FIXEDSTACKBIT)\n#define fixedstack(x)\tl_setbit((x)->marked, FIXEDSTACKBIT)\n#define unfixedstack(x)\tresetbit((x)->marked, FIXEDSTACKBIT)\n\n#define luaC_checkGC(L) { \\\n  condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \\\n  if (G(L)->totalbytes >= G(L)->GCthreshold) \\\n\tluaC_step(L); }\n\n\n#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p)))  \\\n\tluaC_barrierf(L,obj2gco(p),gcvalue(v)); }\n\n#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t)))  \\\n\tluaC_barrierback(L,t); }\n\n#define luaC_objbarrier(L,p,o)  \\\n\t{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \\\n\t\tluaC_barrierf(L,obj2gco(p),obj2gco(o)); }\n\n#define luaC_objbarriert(L,t,o)  \\\n   { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }\n\nLUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);\nLUAI_FUNC void luaC_callGCTM (lua_State *L);\nLUAI_FUNC void luaC_freeall (lua_State *L);\nLUAI_FUNC void luaC_step (lua_State *L);\nLUAI_FUNC void luaC_fullgc (lua_State *L);\nLUAI_FUNC void luaC_marknew (lua_State *L, GCObject *o);\nLUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);\nLUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);\nLUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);\nLUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);\n\n\n#endif\n"
  },
  {
    "path": "src/linit.c",
    "content": "/*\n** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $\n** Initialization of libraries for lua.c\n** See Copyright Notice in lua.h\n*/\n\n\n#define linit_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lualib.h\"\n#include \"lauxlib.h\"\n\n\nstatic const luaL_Reg lualibs[] = {\n  {\"\", luaopen_base},\n  {LUA_LOADLIBNAME, luaopen_package},\n  {LUA_TABLIBNAME, luaopen_table},\n  {LUA_IOLIBNAME, luaopen_io},\n  {LUA_OSLIBNAME, luaopen_os},\n  {LUA_STRLIBNAME, luaopen_string},\n  {LUA_MATHLIBNAME, luaopen_math},\n  {LUA_DBLIBNAME, luaopen_debug},\n  {NULL, NULL}\n};\n\n\nLUALIB_API void luaL_openlibs (lua_State *L) {\n  const luaL_Reg *lib = lualibs;\n  for (; lib->func; lib++) {\n    lua_pushcfunction(L, lib->func);\n    lua_pushstring(L, lib->name);\n    lua_call(L, 1, 0);\n  }\n}\n\n"
  },
  {
    "path": "src/liolib.c",
    "content": "/*\n** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $\n** Standard I/O (and system) library\n** See Copyright Notice in lua.h\n*/\n\n\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define liolib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\n#define IO_INPUT\t1\n#define IO_OUTPUT\t2\n\n\nstatic const char *const fnames[] = {\"input\", \"output\"};\n\n\nstatic int pushresult (lua_State *L, int i, const char *filename) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (i) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    if (filename)\n      lua_pushfstring(L, \"%s: %s\", filename, strerror(en));\n    else\n      lua_pushfstring(L, \"%s\", strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\nstatic void fileerror (lua_State *L, int arg, const char *filename) {\n  lua_pushfstring(L, \"%s: %s\", filename, strerror(errno));\n  luaL_argerror(L, arg, lua_tostring(L, -1));\n}\n\n\n#define tofilep(L)\t((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE))\n\n\nstatic int io_type (lua_State *L) {\n  void *ud;\n  luaL_checkany(L, 1);\n  ud = lua_touserdata(L, 1);\n  lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);\n  if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1))\n    lua_pushnil(L);  /* not a file */\n  else if (*((FILE **)ud) == NULL)\n    lua_pushliteral(L, \"closed file\");\n  else\n    lua_pushliteral(L, \"file\");\n  return 1;\n}\n\n\nstatic FILE *tofile (lua_State *L) {\n  FILE **f = tofilep(L);\n  if (*f == NULL)\n    luaL_error(L, \"attempt to use a closed file\");\n  return *f;\n}\n\n\n\n/*\n** When creating file handles, always creates a `closed' file handle\n** before opening the actual file; so, if there is a memory error, the\n** file is not left opened.\n*/\nstatic FILE **newfile (lua_State *L) {\n  FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));\n  *pf = NULL;  /* file handle is currently `closed' */\n  luaL_getmetatable(L, LUA_FILEHANDLE);\n  lua_setmetatable(L, -2);\n  return pf;\n}\n\n\n/*\n** function to (not) close the standard files stdin, stdout, and stderr\n*/\nstatic int io_noclose (lua_State *L) {\n  lua_pushnil(L);\n  lua_pushliteral(L, \"cannot close standard file\");\n  return 2;\n}\n\n\n/*\n** function to close 'popen' files\n*/\nstatic int io_pclose (lua_State *L) {\n  FILE **p = tofilep(L);\n  int ok = lua_pclose(L, *p);\n  *p = NULL;\n  return pushresult(L, ok, NULL);\n}\n\n\n/*\n** function to close regular files\n*/\nstatic int io_fclose (lua_State *L) {\n  FILE **p = tofilep(L);\n  int ok = (fclose(*p) == 0);\n  *p = NULL;\n  return pushresult(L, ok, NULL);\n}\n\n\nstatic int aux_close (lua_State *L) {\n  lua_getfenv(L, 1);\n  lua_getfield(L, -1, \"__close\");\n  return (lua_tocfunction(L, -1))(L);\n}\n\n\nstatic int io_close (lua_State *L) {\n  if (lua_isnone(L, 1))\n    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);\n  tofile(L);  /* make sure argument is a file */\n  return aux_close(L);\n}\n\n\nstatic int io_gc (lua_State *L) {\n  FILE *f = *tofilep(L);\n  /* ignore closed files */\n  if (f != NULL)\n    aux_close(L);\n  return 0;\n}\n\n\nstatic int io_tostring (lua_State *L) {\n  FILE *f = *tofilep(L);\n  if (f == NULL)\n    lua_pushliteral(L, \"file (closed)\");\n  else\n    lua_pushfstring(L, \"file (%p)\", f);\n  return 1;\n}\n\n\nstatic int io_open (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  FILE **pf = newfile(L);\n  *pf = fopen(filename, mode);\n  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;\n}\n\n\n/*\n** this function has a separated environment, which defines the\n** correct __close for 'popen' files\n*/\nstatic int io_popen (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  const char *mode = luaL_optstring(L, 2, \"r\");\n  FILE **pf = newfile(L);\n  *pf = lua_popen(L, filename, mode);\n  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;\n}\n\n\nstatic int io_tmpfile (lua_State *L) {\n  FILE **pf = newfile(L);\n  *pf = tmpfile();\n  return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;\n}\n\n\nstatic FILE *getiofile (lua_State *L, int findex) {\n  FILE *f;\n  lua_rawgeti(L, LUA_ENVIRONINDEX, findex);\n  f = *(FILE **)lua_touserdata(L, -1);\n  if (f == NULL)\n    luaL_error(L, \"standard %s file is closed\", fnames[findex - 1]);\n  return f;\n}\n\n\nstatic int g_iofile (lua_State *L, int f, const char *mode) {\n  if (!lua_isnoneornil(L, 1)) {\n    const char *filename = lua_tostring(L, 1);\n    if (filename) {\n      FILE **pf = newfile(L);\n      *pf = fopen(filename, mode);\n      if (*pf == NULL)\n        fileerror(L, 1, filename);\n    }\n    else {\n      tofile(L);  /* check that it's a valid file handle */\n      lua_pushvalue(L, 1);\n    }\n    lua_rawseti(L, LUA_ENVIRONINDEX, f);\n  }\n  /* return current value */\n  lua_rawgeti(L, LUA_ENVIRONINDEX, f);\n  return 1;\n}\n\n\nstatic int io_input (lua_State *L) {\n  return g_iofile(L, IO_INPUT, \"r\");\n}\n\n\nstatic int io_output (lua_State *L) {\n  return g_iofile(L, IO_OUTPUT, \"w\");\n}\n\n\nstatic int io_readline (lua_State *L);\n\n\nstatic void aux_lines (lua_State *L, int idx, int toclose) {\n  lua_pushvalue(L, idx);\n  lua_pushboolean(L, toclose);  /* close/not close file when finished */\n  lua_pushcclosure(L, io_readline, 2);\n}\n\n\nstatic int f_lines (lua_State *L) {\n  tofile(L);  /* check that it's a valid file handle */\n  aux_lines(L, 1, 0);\n  return 1;\n}\n\n\nstatic int io_lines (lua_State *L) {\n  if (lua_isnoneornil(L, 1)) {  /* no arguments? */\n    /* will iterate over default input */\n    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT);\n    return f_lines(L);\n  }\n  else {\n    const char *filename = luaL_checkstring(L, 1);\n    FILE **pf = newfile(L);\n    *pf = fopen(filename, \"r\");\n    if (*pf == NULL)\n      fileerror(L, 1, filename);\n    aux_lines(L, lua_gettop(L), 1);\n    return 1;\n  }\n}\n\n\n/*\n** {======================================================\n** READ\n** =======================================================\n*/\n\n\nstatic int read_number (lua_State *L, FILE *f) {\n  lua_Number d;\n  if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {\n    lua_pushnumber(L, d);\n    return 1;\n  }\n  else return 0;  /* read fails */\n}\n\n\nstatic int test_eof (lua_State *L, FILE *f) {\n  int c = getc(f);\n  ungetc(c, f);\n  lua_pushlstring(L, NULL, 0);\n  return (c != EOF);\n}\n\n\nstatic int read_line (lua_State *L, FILE *f) {\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  for (;;) {\n    size_t l;\n    char *p = luaL_prepbuffer(&b);\n    if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) {  /* eof? */\n      luaL_pushresult(&b);  /* close buffer */\n      return (lua_objlen(L, -1) > 0);  /* check whether read something */\n    }\n    l = strlen(p);\n    if (l == 0 || p[l-1] != '\\n')\n      luaL_addsize(&b, l);\n    else {\n      luaL_addsize(&b, l - 1);  /* do not include `eol' */\n      luaL_pushresult(&b);  /* close buffer */\n      return 1;  /* read at least an `eol' */\n    }\n  }\n}\n\n\nstatic int read_chars (lua_State *L, FILE *f, size_t n) {\n  size_t rlen;  /* how much to read */\n  size_t nr;  /* number of chars actually read */\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  rlen = LUAL_BUFFERSIZE;  /* try to read that much each time */\n  do {\n    char *p = luaL_prepbuffer(&b);\n    if (rlen > n) rlen = n;  /* cannot read more than asked */\n    nr = fread(p, sizeof(char), rlen, f);\n    luaL_addsize(&b, nr);\n    n -= nr;  /* still have to read `n' chars */\n  } while (n > 0 && nr == rlen);  /* until end of count or eof */\n  luaL_pushresult(&b);  /* close buffer */\n  return (n == 0 || lua_objlen(L, -1) > 0);\n}\n\n\nstatic int g_read (lua_State *L, FILE *f, int first) {\n  int nargs = lua_gettop(L) - 1;\n  int success;\n  int n;\n  clearerr(f);\n  if (nargs == 0) {  /* no arguments? */\n    success = read_line(L, f);\n    n = first+1;  /* to return 1 result */\n  }\n  else {  /* ensure stack space for all results and for auxlib's buffer */\n    luaL_checkstack(L, nargs+LUA_MINSTACK, \"too many arguments\");\n    success = 1;\n    for (n = first; nargs-- && success; n++) {\n      if (lua_type(L, n) == LUA_TNUMBER) {\n        size_t l = (size_t)lua_tointeger(L, n);\n        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);\n      }\n      else {\n        const char *p = lua_tostring(L, n);\n        luaL_argcheck(L, p && p[0] == '*', n, \"invalid option\");\n        switch (p[1]) {\n          case 'n':  /* number */\n            success = read_number(L, f);\n            break;\n          case 'l':  /* line */\n            success = read_line(L, f);\n            break;\n          case 'a':  /* file */\n            read_chars(L, f, ~((size_t)0));  /* read MAX_SIZE_T chars */\n            success = 1; /* always success */\n            break;\n          default:\n            return luaL_argerror(L, n, \"invalid format\");\n        }\n      }\n    }\n  }\n  if (ferror(f))\n    return pushresult(L, 0, NULL);\n  if (!success) {\n    lua_pop(L, 1);  /* remove last result */\n    lua_pushnil(L);  /* push nil instead */\n  }\n  return n - first;\n}\n\n\nstatic int io_read (lua_State *L) {\n  return g_read(L, getiofile(L, IO_INPUT), 1);\n}\n\n\nstatic int f_read (lua_State *L) {\n  return g_read(L, tofile(L), 2);\n}\n\n\nstatic int io_readline (lua_State *L) {\n  FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));\n  int sucess;\n  if (f == NULL)  /* file is already closed? */\n    luaL_error(L, \"file is already closed\");\n  sucess = read_line(L, f);\n  if (ferror(f))\n    return luaL_error(L, \"%s\", strerror(errno));\n  if (sucess) return 1;\n  else {  /* EOF */\n    if (lua_toboolean(L, lua_upvalueindex(2))) {  /* generator created file? */\n      lua_settop(L, 0);\n      lua_pushvalue(L, lua_upvalueindex(1));\n      aux_close(L);  /* close it */\n    }\n    return 0;\n  }\n}\n\n/* }====================================================== */\n\n\nstatic int g_write (lua_State *L, FILE *f, int arg) {\n  int nargs = lua_gettop(L) - 1;\n  int status = 1;\n  for (; nargs--; arg++) {\n    if (lua_type(L, arg) == LUA_TNUMBER) {\n      /* optimization: could be done exactly as for strings */\n      status = status &&\n          fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0;\n    }\n    else {\n      size_t l;\n      const char *s = luaL_checklstring(L, arg, &l);\n      status = status && (fwrite(s, sizeof(char), l, f) == l);\n    }\n  }\n  return pushresult(L, status, NULL);\n}\n\n\nstatic int io_write (lua_State *L) {\n  return g_write(L, getiofile(L, IO_OUTPUT), 1);\n}\n\n\nstatic int f_write (lua_State *L) {\n  return g_write(L, tofile(L), 2);\n}\n\n\nstatic int f_seek (lua_State *L) {\n  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};\n  static const char *const modenames[] = {\"set\", \"cur\", \"end\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, \"cur\", modenames);\n  long offset = luaL_optlong(L, 3, 0);\n  op = fseek(f, offset, mode[op]);\n  if (op)\n    return pushresult(L, 0, NULL);  /* error */\n  else {\n    lua_pushinteger(L, ftell(f));\n    return 1;\n  }\n}\n\n\nstatic int f_setvbuf (lua_State *L) {\n  static const int mode[] = {_IONBF, _IOFBF, _IOLBF};\n  static const char *const modenames[] = {\"no\", \"full\", \"line\", NULL};\n  FILE *f = tofile(L);\n  int op = luaL_checkoption(L, 2, NULL, modenames);\n  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);\n  int res = setvbuf(f, NULL, mode[op], sz);\n  return pushresult(L, res == 0, NULL);\n}\n\n\n\nstatic int io_flush (lua_State *L) {\n  return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);\n}\n\n\nstatic int f_flush (lua_State *L) {\n  return pushresult(L, fflush(tofile(L)) == 0, NULL);\n}\n\n\nstatic const luaL_Reg iolib[] = {\n  {\"close\", io_close},\n  {\"flush\", io_flush},\n  {\"input\", io_input},\n  {\"lines\", io_lines},\n  {\"open\", io_open},\n  {\"output\", io_output},\n  {\"popen\", io_popen},\n  {\"read\", io_read},\n  {\"tmpfile\", io_tmpfile},\n  {\"type\", io_type},\n  {\"write\", io_write},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg flib[] = {\n  {\"close\", io_close},\n  {\"flush\", f_flush},\n  {\"lines\", f_lines},\n  {\"read\", f_read},\n  {\"seek\", f_seek},\n  {\"setvbuf\", f_setvbuf},\n  {\"write\", f_write},\n  {\"__gc\", io_gc},\n  {\"__tostring\", io_tostring},\n  {NULL, NULL}\n};\n\n\nstatic void createmeta (lua_State *L) {\n  luaL_newmetatable(L, LUA_FILEHANDLE);  /* create metatable for file handles */\n  lua_pushvalue(L, -1);  /* push metatable */\n  lua_setfield(L, -2, \"__index\");  /* metatable.__index = metatable */\n  luaL_register(L, NULL, flib);  /* file methods */\n}\n\n\nstatic void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {\n  *newfile(L) = f;\n  if (k > 0) {\n    lua_pushvalue(L, -1);\n    lua_rawseti(L, LUA_ENVIRONINDEX, k);\n  }\n  lua_pushvalue(L, -2);  /* copy environment */\n  lua_setfenv(L, -2);  /* set it */\n  lua_setfield(L, -3, fname);\n}\n\n\nstatic void newfenv (lua_State *L, lua_CFunction cls) {\n  lua_createtable(L, 0, 1);\n  lua_pushcfunction(L, cls);\n  lua_setfield(L, -2, \"__close\");\n}\n\n\nLUALIB_API int luaopen_io (lua_State *L) {\n  createmeta(L);\n  /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */\n  newfenv(L, io_fclose);\n  lua_replace(L, LUA_ENVIRONINDEX);\n  /* open library */\n  luaL_register(L, LUA_IOLIBNAME, iolib);\n  /* create (and set) default files */\n  newfenv(L, io_noclose);  /* close function for default files */\n  createstdfile(L, stdin, IO_INPUT, \"stdin\");\n  createstdfile(L, stdout, IO_OUTPUT, \"stdout\");\n  createstdfile(L, stderr, 0, \"stderr\");\n  lua_pop(L, 1);  /* pop environment for default files */\n  lua_getfield(L, -1, \"popen\");\n  newfenv(L, io_pclose);  /* create environment for 'popen' */\n  lua_setfenv(L, -2);  /* set fenv for 'popen' */\n  lua_pop(L, 1);  /* pop 'popen' */\n  return 1;\n}\n\n"
  },
  {
    "path": "src/llex.c",
    "content": "/*\n** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n\n#include <ctype.h>\n#include <locale.h>\n#include <string.h>\n\n#define llex_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldo.h\"\n#include \"llex.h\"\n#include \"lobject.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"lzio.h\"\n\n\n\n#define next(ls) (ls->current = zgetc(ls->z))\n\n\n\n\n#define currIsNewline(ls)\t(ls->current == '\\n' || ls->current == '\\r')\n\n\n/* ORDER RESERVED */\nconst char *const luaX_tokens [] = {\n    \"and\", \"break\", \"do\", \"else\", \"elseif\",\n    \"end\", \"false\", \"for\", \"function\", \"if\",\n    \"in\", \"local\", \"nil\", \"not\", \"or\", \"repeat\",\n    \"return\", \"then\", \"true\", \"until\", \"while\",\n    \"..\", \"...\", \"==\", \">=\", \"<=\", \"~=\",\n    \"<number>\", \"<name>\", \"<string>\", \"<eof>\",\n    NULL\n};\n\n\n#define save_and_next(ls) (save(ls, ls->current), next(ls))\n\n\nstatic void save (LexState *ls, int c) {\n  Mbuffer *b = ls->buff;\n  if (b->n + 1 > b->buffsize) {\n    size_t newsize;\n    if (b->buffsize >= MAX_SIZET/2)\n      luaX_lexerror(ls, \"lexical element too long\", 0);\n    newsize = b->buffsize * 2;\n    luaZ_resizebuffer(ls->L, b, newsize);\n  }\n  b->buffer[b->n++] = cast(char, c);\n}\n\n\nvoid luaX_init (lua_State *L) {\n  int i;\n  for (i=0; i<NUM_RESERVED; i++) {\n    TString *ts = luaS_new(L, luaX_tokens[i]);\n    luaS_fix(ts);  /* reserved words are never collected */\n    lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);\n    ts->tsv.reserved = cast_byte(i+1);  /* reserved word */\n  }\n}\n\n\n#define MAXSRC          80\n\n\nconst char *luaX_token2str (LexState *ls, int token) {\n  if (token < FIRST_RESERVED) {\n    lua_assert(token == cast(unsigned char, token));\n    return (iscntrl(token)) ? luaO_pushfstring(ls->L, \"char(%d)\", token) :\n                              luaO_pushfstring(ls->L, \"%c\", token);\n  }\n  else\n    return luaX_tokens[token-FIRST_RESERVED];\n}\n\n\nstatic const char *txtToken (LexState *ls, int token) {\n  switch (token) {\n    case TK_NAME:\n    case TK_STRING:\n    case TK_NUMBER:\n      save(ls, '\\0');\n      return luaZ_buffer(ls->buff);\n    default:\n      return luaX_token2str(ls, token);\n  }\n}\n\n\nvoid luaX_lexerror (LexState *ls, const char *msg, int token) {\n  char buff[MAXSRC];\n  luaO_chunkid(buff, getstr(ls->source), MAXSRC);\n  msg = luaO_pushfstring(ls->L, \"%s:%d: %s\", buff, ls->linenumber, msg);\n  if (token)\n    luaO_pushfstring(ls->L, \"%s near \" LUA_QS, msg, txtToken(ls, token));\n  luaD_throw(ls->L, LUA_ERRSYNTAX);\n}\n\n\nvoid luaX_syntaxerror (LexState *ls, const char *msg) {\n  luaX_lexerror(ls, msg, ls->t.token);\n}\n\n\nTString *luaX_newstring (LexState *ls, const char *str, size_t l) {\n  lua_State *L = ls->L;\n  TString *ts = luaS_newlstr(L, str, l);\n  TValue *o = luaH_setstr(L, ls->fs->h, ts);  /* entry for `str' */\n  if (ttisnil(o))\n    setbvalue(o, 1);  /* make sure `str' will not be collected */\n  return ts;\n}\n\n\nstatic void inclinenumber (LexState *ls) {\n  int old = ls->current;\n  lua_assert(currIsNewline(ls));\n  next(ls);  /* skip `\\n' or `\\r' */\n  if (currIsNewline(ls) && ls->current != old)\n    next(ls);  /* skip `\\n\\r' or `\\r\\n' */\n  if (++ls->linenumber >= MAX_INT)\n    luaX_syntaxerror(ls, \"chunk has too many lines\");\n}\n\n\nvoid luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {\n  ls->decpoint = '.';\n  ls->L = L;\n  ls->lookahead.token = TK_EOS;  /* no look-ahead token */\n  ls->z = z;\n  ls->fs = NULL;\n  ls->linenumber = 1;\n  ls->lastline = 1;\n  ls->source = source;\n  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */\n  next(ls);  /* read first char */\n}\n\n\n\n/*\n** =======================================================\n** LEXICAL ANALYZER\n** =======================================================\n*/\n\n\n\nstatic int check_next (LexState *ls, const char *set) {\n  if (!strchr(set, ls->current))\n    return 0;\n  save_and_next(ls);\n  return 1;\n}\n\n\nstatic void buffreplace (LexState *ls, char from, char to) {\n  size_t n = luaZ_bufflen(ls->buff);\n  char *p = luaZ_buffer(ls->buff);\n  while (n--)\n    if (p[n] == from) p[n] = to;\n}\n\n\nstatic void trydecpoint (LexState *ls, SemInfo *seminfo) {\n  /* format error: try to update decimal point separator */\n  struct lconv *cv = localeconv();\n  char old = ls->decpoint;\n  ls->decpoint = (cv ? cv->decimal_point[0] : '.');\n  buffreplace(ls, old, ls->decpoint);  /* try updated decimal separator */\n  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {\n    /* format error with correct decimal point: no more options */\n    buffreplace(ls, ls->decpoint, '.');  /* undo change (for error message) */\n    luaX_lexerror(ls, \"malformed number\", TK_NUMBER);\n  }\n}\n\n\n/* LUA_NUMBER */\nstatic void read_numeral (LexState *ls, SemInfo *seminfo) {\n  lua_assert(isdigit(ls->current));\n  do {\n    save_and_next(ls);\n  } while (isdigit(ls->current) || ls->current == '.');\n  if (check_next(ls, \"Ee\"))  /* `E'? */\n    check_next(ls, \"+-\");  /* optional exponent sign */\n  while (isalnum(ls->current) || ls->current == '_')\n    save_and_next(ls);\n  save(ls, '\\0');\n  buffreplace(ls, '.', ls->decpoint);  /* follow locale for decimal point */\n  if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r))  /* format error? */\n    trydecpoint(ls, seminfo); /* try to update decimal point separator */\n}\n\n\nstatic int skip_sep (LexState *ls) {\n  int count = 0;\n  int s = ls->current;\n  lua_assert(s == '[' || s == ']');\n  save_and_next(ls);\n  while (ls->current == '=') {\n    save_and_next(ls);\n    count++;\n  }\n  return (ls->current == s) ? count : (-count) - 1;\n}\n\n\nstatic void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {\n  int cont = 0;\n  (void)(cont);  /* avoid warnings when `cont' is not used */\n  save_and_next(ls);  /* skip 2nd `[' */\n  if (currIsNewline(ls))  /* string starts with a newline? */\n    inclinenumber(ls);  /* skip it */\n  for (;;) {\n    switch (ls->current) {\n      case EOZ:\n        luaX_lexerror(ls, (seminfo) ? \"unfinished long string\" :\n                                   \"unfinished long comment\", TK_EOS);\n        break;  /* to avoid warnings */\n#if defined(LUA_COMPAT_LSTR)\n      case '[': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd `[' */\n          cont++;\n#if LUA_COMPAT_LSTR == 1\n          if (sep == 0)\n            luaX_lexerror(ls, \"nesting of [[...]] is deprecated\", '[');\n#endif\n        }\n        break;\n      }\n#endif\n      case ']': {\n        if (skip_sep(ls) == sep) {\n          save_and_next(ls);  /* skip 2nd `]' */\n#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2\n          cont--;\n          if (sep == 0 && cont >= 0) break;\n#endif\n          goto endloop;\n        }\n        break;\n      }\n      case '\\n':\n      case '\\r': {\n        save(ls, '\\n');\n        inclinenumber(ls);\n        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */\n        break;\n      }\n      default: {\n        if (seminfo) save_and_next(ls);\n        else next(ls);\n      }\n    }\n  } endloop:\n  if (seminfo)\n    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),\n                                     luaZ_bufflen(ls->buff) - 2*(2 + sep));\n}\n\n\nstatic void read_string (LexState *ls, int del, SemInfo *seminfo) {\n  save_and_next(ls);\n  while (ls->current != del) {\n    switch (ls->current) {\n      case EOZ:\n        luaX_lexerror(ls, \"unfinished string\", TK_EOS);\n        continue;  /* to avoid warnings */\n      case '\\n':\n      case '\\r':\n        luaX_lexerror(ls, \"unfinished string\", TK_STRING);\n        continue;  /* to avoid warnings */\n      case '\\\\': {\n        int c;\n        next(ls);  /* do not save the `\\' */\n        switch (ls->current) {\n          case 'a': c = '\\a'; break;\n          case 'b': c = '\\b'; break;\n          case 'f': c = '\\f'; break;\n          case 'n': c = '\\n'; break;\n          case 'r': c = '\\r'; break;\n          case 't': c = '\\t'; break;\n          case 'v': c = '\\v'; break;\n          case '\\n':  /* go through */\n          case '\\r': save(ls, '\\n'); inclinenumber(ls); continue;\n          case EOZ: continue;  /* will raise an error next loop */\n          default: {\n            if (!isdigit(ls->current))\n              save_and_next(ls);  /* handles \\\\, \\\", \\', and \\? */\n            else {  /* \\xxx */\n              int i = 0;\n              c = 0;\n              do {\n                c = 10*c + (ls->current-'0');\n                next(ls);\n              } while (++i<3 && isdigit(ls->current));\n              if (c > UCHAR_MAX)\n                luaX_lexerror(ls, \"escape sequence too large\", TK_STRING);\n              save(ls, c);\n            }\n            continue;\n          }\n        }\n        save(ls, c);\n        next(ls);\n        continue;\n      }\n      default:\n        save_and_next(ls);\n    }\n  }\n  save_and_next(ls);  /* skip delimiter */\n  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,\n                                   luaZ_bufflen(ls->buff) - 2);\n}\n\n\nstatic int llex (LexState *ls, SemInfo *seminfo) {\n  luaZ_resetbuffer(ls->buff);\n  for (;;) {\n    switch (ls->current) {\n      case '\\n':\n      case '\\r': {\n        inclinenumber(ls);\n        continue;\n      }\n      case '-': {\n        next(ls);\n        if (ls->current != '-') return '-';\n        /* else is a comment */\n        next(ls);\n        if (ls->current == '[') {\n          int sep = skip_sep(ls);\n          luaZ_resetbuffer(ls->buff);  /* `skip_sep' may dirty the buffer */\n          if (sep >= 0) {\n            read_long_string(ls, NULL, sep);  /* long comment */\n            luaZ_resetbuffer(ls->buff);\n            continue;\n          }\n        }\n        /* else short comment */\n        while (!currIsNewline(ls) && ls->current != EOZ)\n          next(ls);\n        continue;\n      }\n      case '[': {\n        int sep = skip_sep(ls);\n        if (sep >= 0) {\n          read_long_string(ls, seminfo, sep);\n          return TK_STRING;\n        }\n        else if (sep == -1) return '[';\n        else luaX_lexerror(ls, \"invalid long string delimiter\", TK_STRING);\n      }\n      case '=': {\n        next(ls);\n        if (ls->current != '=') return '=';\n        else { next(ls); return TK_EQ; }\n      }\n      case '<': {\n        next(ls);\n        if (ls->current != '=') return '<';\n        else { next(ls); return TK_LE; }\n      }\n      case '>': {\n        next(ls);\n        if (ls->current != '=') return '>';\n        else { next(ls); return TK_GE; }\n      }\n      case '~': {\n        next(ls);\n        if (ls->current != '=') return '~';\n        else { next(ls); return TK_NE; }\n      }\n      case '\"':\n      case '\\'': {\n        read_string(ls, ls->current, seminfo);\n        return TK_STRING;\n      }\n      case '.': {\n        save_and_next(ls);\n        if (check_next(ls, \".\")) {\n          if (check_next(ls, \".\"))\n            return TK_DOTS;   /* ... */\n          else return TK_CONCAT;   /* .. */\n        }\n        else if (!isdigit(ls->current)) return '.';\n        else {\n          read_numeral(ls, seminfo);\n          return TK_NUMBER;\n        }\n      }\n      case EOZ: {\n        return TK_EOS;\n      }\n      default: {\n        if (isspace(ls->current)) {\n          lua_assert(!currIsNewline(ls));\n          next(ls);\n          continue;\n        }\n        else if (isdigit(ls->current)) {\n          read_numeral(ls, seminfo);\n          return TK_NUMBER;\n        }\n        else if (isalpha(ls->current) || ls->current == '_') {\n          /* identifier or reserved word */\n          TString *ts;\n          do {\n            save_and_next(ls);\n          } while (isalnum(ls->current) || ls->current == '_');\n          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),\n                                  luaZ_bufflen(ls->buff));\n          if (ts->tsv.reserved > 0)  /* reserved word? */\n            return ts->tsv.reserved - 1 + FIRST_RESERVED;\n          else {\n            seminfo->ts = ts;\n            return TK_NAME;\n          }\n        }\n        else {\n          int c = ls->current;\n          next(ls);\n          return c;  /* single-char tokens (+ - / ...) */\n        }\n      }\n    }\n  }\n}\n\n\nvoid luaX_next (LexState *ls) {\n  ls->lastline = ls->linenumber;\n  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */\n    ls->t = ls->lookahead;  /* use this one */\n    ls->lookahead.token = TK_EOS;  /* and discharge it */\n  }\n  else\n    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */\n}\n\n\nvoid luaX_lookahead (LexState *ls) {\n  lua_assert(ls->lookahead.token == TK_EOS);\n  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);\n}\n\n"
  },
  {
    "path": "src/llex.h",
    "content": "/*\n** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lexical Analyzer\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llex_h\n#define llex_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n#define FIRST_RESERVED\t257\n\n/* maximum length of a reserved word */\n#define TOKEN_LEN\t(sizeof(\"function\")/sizeof(char))\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER RESERVED\"\n*/\nenum RESERVED {\n  /* terminal symbols denoted by reserved words */\n  TK_AND = FIRST_RESERVED, TK_BREAK,\n  TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,\n  TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,\n  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,\n  /* other terminal symbols */\n  TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,\n  TK_NAME, TK_STRING, TK_EOS\n};\n\n/* number of reserved words */\n#define NUM_RESERVED\t(cast(int, TK_WHILE-FIRST_RESERVED+1))\n\n\n/* array with token `names' */\nLUAI_DATA const char *const luaX_tokens [];\n\n\ntypedef union {\n  lua_Number r;\n  TString *ts;\n} SemInfo;  /* semantics information */\n\n\ntypedef struct Token {\n  int token;\n  SemInfo seminfo;\n} Token;\n\n\ntypedef struct LexState {\n  int current;  /* current character (charint) */\n  int linenumber;  /* input line counter */\n  int lastline;  /* line of last token `consumed' */\n  Token t;  /* current token */\n  Token lookahead;  /* look ahead token */\n  struct FuncState *fs;  /* `FuncState' is private to the parser */\n  struct lua_State *L;\n  ZIO *z;  /* input stream */\n  Mbuffer *buff;  /* buffer for tokens */\n  TString *source;  /* current source name */\n  char decpoint;  /* locale decimal point */\n} LexState;\n\n\nLUAI_FUNC void luaX_init (lua_State *L);\nLUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,\n                              TString *source);\nLUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);\nLUAI_FUNC void luaX_next (LexState *ls);\nLUAI_FUNC void luaX_lookahead (LexState *ls);\nLUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);\nLUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);\nLUAI_FUNC const char *luaX_token2str (LexState *ls, int token);\n\n\n#endif\n"
  },
  {
    "path": "src/llimits.h",
    "content": "/*\n** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $\n** Limits, basic types, and some other `installation-dependent' definitions\n** See Copyright Notice in lua.h\n*/\n\n#ifndef llimits_h\n#define llimits_h\n\n\n#include <limits.h>\n#include <stddef.h>\n\n\n#include \"lua.h\"\n\n\ntypedef LUAI_UINT32 lu_int32;\n\ntypedef LUAI_UMEM lu_mem;\n\ntypedef LUAI_MEM l_mem;\n\n\n\n/* chars used as small naturals (so that `char' is reserved for characters) */\ntypedef unsigned char lu_byte;\n\n\n#define MAX_SIZET\t((size_t)(~(size_t)0)-2)\n\n#define MAX_LUMEM\t((lu_mem)(~(lu_mem)0)-2)\n\n\n#define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */\n\n/*\n** conversion of pointer to integer\n** this is for hashing only; there is no problem if the integer\n** cannot hold the whole pointer value\n*/\n#define IntPoint(p)  ((unsigned int)(lu_mem)(p))\n\n\n\n/* type to ensure maximum alignment */\ntypedef LUAI_USER_ALIGNMENT_T L_Umaxalign;\n\n\n/* result of a `usual argument conversion' over lua_Number */\ntypedef LUAI_UACNUMBER l_uacNumber;\n\n\n/* internal assertions for in-house debugging */\n#ifdef lua_assert\n\n#define check_exp(c,e)\t\t(lua_assert(c), (e))\n#define api_check(l,e)\t\tlua_assert(e)\n\n#else\n\n#define lua_assert(c)\t\t((void)0)\n#define check_exp(c,e)\t\t(e)\n#define api_check\t\tluai_apicheck\n\n#endif\n\n\n#ifndef UNUSED\n#define UNUSED(x)\t((void)(x))\t/* to avoid warnings */\n#endif\n\n\n#ifndef cast\n#define cast(t, exp)\t((t)(exp))\n#endif\n\n#define cast_byte(i)\tcast(lu_byte, (i))\n#define cast_num(i)\tcast(lua_Number, (i))\n#define cast_int(i)\tcast(int, (i))\n\n\n\n/*\n** type for virtual-machine instructions\n** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)\n*/\ntypedef lu_int32 Instruction;\n\n\n\n/* maximum stack for a Lua function */\n#define MAXSTACK\t250\n\n\n\n/* minimum size for the string table (must be power of 2) */\n#ifndef MINSTRTABSIZE\n#define MINSTRTABSIZE\t32\n#endif\n\n\n/* minimum size for string buffer */\n#ifndef LUA_MINBUFFER\n#define LUA_MINBUFFER\t32\n#endif\n\n\n#ifndef lua_lock\n#define lua_lock(L)     ((void) 0) \n#define lua_unlock(L)   ((void) 0)\n#endif\n\n#ifndef luai_threadyield\n#define luai_threadyield(L)     {lua_unlock(L); lua_lock(L);}\n#endif\n\n\n/*\n** macro to control inclusion of some hard tests on stack reallocation\n*/ \n#ifndef HARDSTACKTESTS\n#define condhardstacktests(x)\t((void)0)\n#else\n#define condhardstacktests(x)\tx\n#endif\n\n#endif\n"
  },
  {
    "path": "src/lmathlib.c",
    "content": "/*\n** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $\n** Standard mathematical library\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdlib.h>\n#include <math.h>\n\n#define lmathlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#undef PI\n#define PI (3.14159265358979323846)\n#define RADIANS_PER_DEGREE (PI/180.0)\n\n\n\nstatic int math_abs (lua_State *L) {\n  lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sin (lua_State *L) {\n  lua_pushnumber(L, sin(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_sinh (lua_State *L) {\n  lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cos (lua_State *L) {\n  lua_pushnumber(L, cos(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_cosh (lua_State *L) {\n  lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tan (lua_State *L) {\n  lua_pushnumber(L, tan(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_tanh (lua_State *L) {\n  lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_asin (lua_State *L) {\n  lua_pushnumber(L, asin(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_acos (lua_State *L) {\n  lua_pushnumber(L, acos(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan (lua_State *L) {\n  lua_pushnumber(L, atan(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_atan2 (lua_State *L) {\n  lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nstatic int math_ceil (lua_State *L) {\n  lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_floor (lua_State *L) {\n  lua_pushnumber(L, floor(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_fmod (lua_State *L) {\n  lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nstatic int math_modf (lua_State *L) {\n  double ip;\n  double fp = modf(luaL_checknumber(L, 1), &ip);\n  lua_pushnumber(L, ip);\n  lua_pushnumber(L, fp);\n  return 2;\n}\n\nstatic int math_sqrt (lua_State *L) {\n  lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_pow (lua_State *L) {\n  lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));\n  return 1;\n}\n\nstatic int math_log (lua_State *L) {\n  lua_pushnumber(L, log(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_log10 (lua_State *L) {\n  lua_pushnumber(L, log10(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_exp (lua_State *L) {\n  lua_pushnumber(L, exp(luaL_checknumber(L, 1)));\n  return 1;\n}\n\nstatic int math_deg (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);\n  return 1;\n}\n\nstatic int math_rad (lua_State *L) {\n  lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);\n  return 1;\n}\n\nstatic int math_frexp (lua_State *L) {\n  int e;\n  lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));\n  lua_pushinteger(L, e);\n  return 2;\n}\n\nstatic int math_ldexp (lua_State *L) {\n  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));\n  return 1;\n}\n\n\n\nstatic int math_min (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  lua_Number dmin = luaL_checknumber(L, 1);\n  int i;\n  for (i=2; i<=n; i++) {\n    lua_Number d = luaL_checknumber(L, i);\n    if (d < dmin)\n      dmin = d;\n  }\n  lua_pushnumber(L, dmin);\n  return 1;\n}\n\n\nstatic int math_max (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  lua_Number dmax = luaL_checknumber(L, 1);\n  int i;\n  for (i=2; i<=n; i++) {\n    lua_Number d = luaL_checknumber(L, i);\n    if (d > dmax)\n      dmax = d;\n  }\n  lua_pushnumber(L, dmax);\n  return 1;\n}\n\n\nstatic int math_random (lua_State *L) {\n  /* the `%' avoids the (rare) case of r==1, and is needed also because on\n     some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */\n  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;\n  switch (lua_gettop(L)) {  /* check number of arguments */\n    case 0: {  /* no arguments */\n      lua_pushnumber(L, r);  /* Number between 0 and 1 */\n      break;\n    }\n    case 1: {  /* only upper limit */\n      int u = luaL_checkint(L, 1);\n      luaL_argcheck(L, 1<=u, 1, \"interval is empty\");\n      lua_pushnumber(L, floor(r*u)+1);  /* int between 1 and `u' */\n      break;\n    }\n    case 2: {  /* lower and upper limits */\n      int l = luaL_checkint(L, 1);\n      int u = luaL_checkint(L, 2);\n      luaL_argcheck(L, l<=u, 2, \"interval is empty\");\n      lua_pushnumber(L, floor(r*(u-l+1))+l);  /* int between `l' and `u' */\n      break;\n    }\n    default: return luaL_error(L, \"wrong number of arguments\");\n  }\n  return 1;\n}\n\n\nstatic int math_randomseed (lua_State *L) {\n  srand(luaL_checkint(L, 1));\n  return 0;\n}\n\n\nstatic const luaL_Reg mathlib[] = {\n  {\"abs\",   math_abs},\n  {\"acos\",  math_acos},\n  {\"asin\",  math_asin},\n  {\"atan2\", math_atan2},\n  {\"atan\",  math_atan},\n  {\"ceil\",  math_ceil},\n  {\"cosh\",   math_cosh},\n  {\"cos\",   math_cos},\n  {\"deg\",   math_deg},\n  {\"exp\",   math_exp},\n  {\"floor\", math_floor},\n  {\"fmod\",   math_fmod},\n  {\"frexp\", math_frexp},\n  {\"ldexp\", math_ldexp},\n  {\"log10\", math_log10},\n  {\"log\",   math_log},\n  {\"max\",   math_max},\n  {\"min\",   math_min},\n  {\"modf\",   math_modf},\n  {\"pow\",   math_pow},\n  {\"rad\",   math_rad},\n  {\"random\",     math_random},\n  {\"randomseed\", math_randomseed},\n  {\"sinh\",   math_sinh},\n  {\"sin\",   math_sin},\n  {\"sqrt\",  math_sqrt},\n  {\"tanh\",   math_tanh},\n  {\"tan\",   math_tan},\n  {NULL, NULL}\n};\n\n\n/*\n** Open math library\n*/\nLUALIB_API int luaopen_math (lua_State *L) {\n  luaL_register(L, LUA_MATHLIBNAME, mathlib);\n  lua_pushnumber(L, PI);\n  lua_setfield(L, -2, \"pi\");\n  lua_pushnumber(L, HUGE_VAL);\n  lua_setfield(L, -2, \"huge\");\n#if defined(LUA_COMPAT_MOD)\n  lua_getfield(L, -1, \"fmod\");\n  lua_setfield(L, -2, \"mod\");\n#endif\n  return 1;\n}\n\n"
  },
  {
    "path": "src/lmem.c",
    "content": "/*\n** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define lmem_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n\n/*\n** About the realloc function:\n** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);\n** (`osize' is the old size, `nsize' is the new size)\n**\n** Lua ensures that (ptr == NULL) iff (osize == 0).\n**\n** * frealloc(ud, NULL, 0, x) creates a new block of size `x'\n**\n** * frealloc(ud, p, x, 0) frees the block `p'\n** (in this specific case, frealloc must return NULL).\n** particularly, frealloc(ud, NULL, 0, 0) does nothing\n** (which is equivalent to free(NULL) in ANSI C)\n**\n** frealloc returns NULL if it cannot create or reallocate the area\n** (any reallocation to an equal or smaller size cannot fail!)\n*/\n\n\n\n#define MINSIZEARRAY\t4\n\n\nvoid *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,\n                     int limit, const char *errormsg) {\n  void *newblock;\n  int newsize;\n  if (*size >= limit/2) {  /* cannot double it? */\n    if (*size >= limit)  /* cannot grow even a little? */\n      luaG_runerror(L, errormsg);\n    newsize = limit;  /* still have at least one free place */\n  }\n  else {\n    newsize = (*size)*2;\n    if (newsize < MINSIZEARRAY)\n      newsize = MINSIZEARRAY;  /* minimum size */\n  }\n  newblock = luaM_reallocv(L, block, *size, newsize, size_elems);\n  *size = newsize;  /* update only when everything else is OK */\n  return newblock;\n}\n\n\nvoid *luaM_toobig (lua_State *L) {\n  luaG_runerror(L, \"memory allocation error: block too big\");\n  return NULL;  /* to avoid warnings */\n}\n\n\n\n/*\n** generic allocation routine.\n*/\nvoid *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {\n  global_State *g = G(L);\n  lua_assert((osize == 0) == (block == NULL));\n  block = (*g->frealloc)(g->ud, block, osize, nsize);\n  if (block == NULL && nsize > 0)\n    luaD_throw(L, LUA_ERRMEM);\n  lua_assert((nsize == 0) == (block == NULL));\n  g->totalbytes = (g->totalbytes - osize) + nsize;\n  return block;\n}\n\n"
  },
  {
    "path": "src/lmem.h",
    "content": "/*\n** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $\n** Interface to Memory Manager\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lmem_h\n#define lmem_h\n\n\n#include <stddef.h>\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n#define MEMERRMSG\t\"not enough memory\"\n\n\n#define luaM_reallocv(L,b,on,n,e) \\\n\t((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \\\n\t\tluaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \\\n\t\tluaM_toobig(L))\n\n#define luaM_freemem(L, b, s)\tluaM_realloc_(L, (b), (s), 0)\n#define luaM_free(L, b)\t\tluaM_realloc_(L, (b), sizeof(*(b)), 0)\n#define luaM_freearray(L, b, n, t)   luaM_reallocv(L, (b), n, 0, sizeof(t))\n\n#define luaM_malloc(L,t)\tluaM_realloc_(L, NULL, 0, (t))\n#define luaM_new(L,t)\t\tcast(t *, luaM_malloc(L, sizeof(t)))\n#define luaM_newvector(L,n,t) \\\n\t\tcast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))\n\n#define luaM_growvector(L,v,nelems,size,t,limit,e) \\\n          if ((nelems)+1 > (size)) \\\n            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))\n\n#define luaM_reallocvector(L, v,oldn,n,t) \\\n   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))\n\n\nLUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,\n                                                          size_t size);\nLUAI_FUNC void *luaM_toobig (lua_State *L);\nLUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,\n                               size_t size_elem, int limit,\n                               const char *errormsg);\n\n#endif\n\n"
  },
  {
    "path": "src/loadlib.c",
    "content": "/*\n** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $\n** Dynamic library loader for Lua\n** See Copyright Notice in lua.h\n**\n** This module contains an implementation of loadlib for Unix systems\n** that have dlfcn, an implementation for Darwin (Mac OS X), an\n** implementation for Windows, and a stub for other systems.\n*/\n\n\n#include <stdlib.h>\n#include <string.h>\n\n\n#define loadlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/* prefix for open functions in C libraries */\n#define LUA_POF\t\t\"luaopen_\"\n\n/* separator for open functions in C libraries */\n#define LUA_OFSEP\t\"_\"\n\n\n#define LIBPREFIX\t\"LOADLIB: \"\n\n#define POF\t\tLUA_POF\n#define LIB_FAIL\t\"open\"\n\n\n/* error codes for ll_loadfunc */\n#define ERRLIB\t\t1\n#define ERRFUNC\t\t2\n\n#define setprogdir(L)\t\t((void)0)\n\n\nstatic void ll_unloadlib (void *lib);\nstatic void *ll_load (lua_State *L, const char *path);\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);\n\n\n\n#if defined(LUA_DL_DLOPEN)\n/*\n** {========================================================================\n** This is an implementation of loadlib based on the dlfcn interface.\n** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,\n** NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least\n** as an emulation layer on top of native functions.\n** =========================================================================\n*/\n\n#include <dlfcn.h>\n\nstatic void ll_unloadlib (void *lib) {\n  dlclose(lib);\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  void *lib = dlopen(path, RTLD_NOW);\n  if (lib == NULL) lua_pushstring(L, dlerror());\n  return lib;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)dlsym(lib, sym);\n  if (f == NULL) lua_pushstring(L, dlerror());\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DLL)\n/*\n** {======================================================================\n** This is an implementation of loadlib for Windows using native functions.\n** =======================================================================\n*/\n\n#include <windows.h>\n\n\n#undef setprogdir\n\nstatic void setprogdir (lua_State *L) {\n  char buff[MAX_PATH + 1];\n  char *lb;\n  DWORD nsize = sizeof(buff)/sizeof(char);\n  DWORD n = GetModuleFileNameA(NULL, buff, nsize);\n  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\\\')) == NULL)\n    luaL_error(L, \"unable to get ModuleFileName\");\n  else {\n    *lb = '\\0';\n    luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);\n    lua_remove(L, -2);  /* remove original string */\n  }\n}\n\n\nstatic void pusherror (lua_State *L) {\n  int error = GetLastError();\n  char buffer[128];\n  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,\n      NULL, error, 0, buffer, sizeof(buffer), NULL))\n    lua_pushstring(L, buffer);\n  else\n    lua_pushfstring(L, \"system error %d\\n\", error);\n}\n\nstatic void ll_unloadlib (void *lib) {\n  FreeLibrary((HINSTANCE)lib);\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  HINSTANCE lib = LoadLibraryA(path);\n  if (lib == NULL) pusherror(L);\n  return lib;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);\n  if (f == NULL) pusherror(L);\n  return f;\n}\n\n/* }====================================================== */\n\n\n\n#elif defined(LUA_DL_DYLD)\n/*\n** {======================================================================\n** Native Mac OS X / Darwin Implementation\n** =======================================================================\n*/\n\n#include <mach-o/dyld.h>\n\n\n/* Mac appends a `_' before C function names */\n#undef POF\n#define POF\t\"_\" LUA_POF\n\n\nstatic void pusherror (lua_State *L) {\n  const char *err_str;\n  const char *err_file;\n  NSLinkEditErrors err;\n  int err_num;\n  NSLinkEditError(&err, &err_num, &err_file, &err_str);\n  lua_pushstring(L, err_str);\n}\n\n\nstatic const char *errorfromcode (NSObjectFileImageReturnCode ret) {\n  switch (ret) {\n    case NSObjectFileImageInappropriateFile:\n      return \"file is not a bundle\";\n    case NSObjectFileImageArch:\n      return \"library is for wrong CPU type\";\n    case NSObjectFileImageFormat:\n      return \"bad format\";\n    case NSObjectFileImageAccess:\n      return \"cannot access file\";\n    case NSObjectFileImageFailure:\n    default:\n      return \"unable to load library\";\n  }\n}\n\n\nstatic void ll_unloadlib (void *lib) {\n  NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  NSObjectFileImage img;\n  NSObjectFileImageReturnCode ret;\n  /* this would be a rare case, but prevents crashing if it happens */\n  if(!_dyld_present()) {\n    lua_pushliteral(L, \"dyld not present\");\n    return NULL;\n  }\n  ret = NSCreateObjectFileImageFromFile(path, &img);\n  if (ret == NSObjectFileImageSuccess) {\n    NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE |\n                       NSLINKMODULE_OPTION_RETURN_ON_ERROR);\n    NSDestroyObjectFileImage(img);\n    if (mod == NULL) pusherror(L);\n    return mod;\n  }\n  lua_pushstring(L, errorfromcode(ret));\n  return NULL;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);\n  if (nss == NULL) {\n    lua_pushfstring(L, \"symbol \" LUA_QS \" not found\", sym);\n    return NULL;\n  }\n  return (lua_CFunction)NSAddressOfSymbol(nss);\n}\n\n/* }====================================================== */\n\n\n\n#else\n/*\n** {======================================================\n** Fallback for other systems\n** =======================================================\n*/\n\n#undef LIB_FAIL\n#define LIB_FAIL\t\"absent\"\n\n\n#define DLMSG\t\"dynamic libraries not enabled; check your Lua installation\"\n\n\nstatic void ll_unloadlib (void *lib) {\n  (void)lib;  /* to avoid warnings */\n}\n\n\nstatic void *ll_load (lua_State *L, const char *path) {\n  (void)path;  /* to avoid warnings */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n\nstatic lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {\n  (void)lib; (void)sym;  /* to avoid warnings */\n  lua_pushliteral(L, DLMSG);\n  return NULL;\n}\n\n/* }====================================================== */\n#endif\n\n\n\nstatic void **ll_register (lua_State *L, const char *path) {\n  void **plib;\n  lua_pushfstring(L, \"%s%s\", LIBPREFIX, path);\n  lua_gettable(L, LUA_REGISTRYINDEX);  /* check library in registry? */\n  if (!lua_isnil(L, -1))  /* is there an entry? */\n    plib = (void **)lua_touserdata(L, -1);\n  else {  /* no entry yet; create one */\n    lua_pop(L, 1);\n    plib = (void **)lua_newuserdata(L, sizeof(const void *));\n    *plib = NULL;\n    luaL_getmetatable(L, \"_LOADLIB\");\n    lua_setmetatable(L, -2);\n    lua_pushfstring(L, \"%s%s\", LIBPREFIX, path);\n    lua_pushvalue(L, -2);\n    lua_settable(L, LUA_REGISTRYINDEX);\n  }\n  return plib;\n}\n\n\n/*\n** __gc tag method: calls library's `ll_unloadlib' function with the lib\n** handle\n*/\nstatic int gctm (lua_State *L) {\n  void **lib = (void **)luaL_checkudata(L, 1, \"_LOADLIB\");\n  if (*lib) ll_unloadlib(*lib);\n  *lib = NULL;  /* mark library as closed */\n  return 0;\n}\n\n\nstatic int ll_loadfunc (lua_State *L, const char *path, const char *sym) {\n  void **reg = ll_register(L, path);\n  if (*reg == NULL) *reg = ll_load(L, path);\n  if (*reg == NULL)\n    return ERRLIB;  /* unable to load library */\n  else {\n    lua_CFunction f = ll_sym(L, *reg, sym);\n    if (f == NULL)\n      return ERRFUNC;  /* unable to find function */\n    lua_pushcfunction(L, f);\n    return 0;  /* return function */\n  }\n}\n\n\nstatic int ll_loadlib (lua_State *L) {\n  const char *path = luaL_checkstring(L, 1);\n  const char *init = luaL_checkstring(L, 2);\n  int stat = ll_loadfunc(L, path, init);\n  if (stat == 0)  /* no errors? */\n    return 1;  /* return the loaded function */\n  else {  /* error; error message is on stack top */\n    lua_pushnil(L);\n    lua_insert(L, -2);\n    lua_pushstring(L, (stat == ERRLIB) ?  LIB_FAIL : \"init\");\n    return 3;  /* return nil, error message, and where */\n  }\n}\n\n\n\n/*\n** {======================================================\n** 'require' function\n** =======================================================\n*/\n\n\nstatic int readable (const char *filename) {\n  FILE *f = fopen(filename, \"r\");  /* try to open file */\n  if (f == NULL) return 0;  /* open failed */\n  fclose(f);\n  return 1;\n}\n\n\nstatic const char *pushnexttemplate (lua_State *L, const char *path) {\n  const char *l;\n  while (*path == *LUA_PATHSEP) path++;  /* skip separators */\n  if (*path == '\\0') return NULL;  /* no more templates */\n  l = strchr(path, *LUA_PATHSEP);  /* find next separator */\n  if (l == NULL) l = path + strlen(path);\n  lua_pushlstring(L, path, l - path);  /* template */\n  return l;\n}\n\n\nstatic const char *findfile (lua_State *L, const char *name,\n                                           const char *pname) {\n  const char *path;\n  name = luaL_gsub(L, name, \".\", LUA_DIRSEP);\n  lua_getfield(L, LUA_ENVIRONINDEX, pname);\n  path = lua_tostring(L, -1);\n  if (path == NULL)\n    luaL_error(L, LUA_QL(\"package.%s\") \" must be a string\", pname);\n  lua_pushliteral(L, \"\");  /* error accumulator */\n  while ((path = pushnexttemplate(L, path)) != NULL) {\n    const char *filename;\n    filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);\n    lua_remove(L, -2);  /* remove path template */\n    if (readable(filename))  /* does file exist and is readable? */\n      return filename;  /* return that file name */\n    lua_pushfstring(L, \"\\n\\tno file \" LUA_QS, filename);\n    lua_remove(L, -2);  /* remove file name */\n    lua_concat(L, 2);  /* add entry to possible error message */\n  }\n  return NULL;  /* not found */\n}\n\n\nstatic void loaderror (lua_State *L, const char *filename) {\n  luaL_error(L, \"error loading module \" LUA_QS \" from file \" LUA_QS \":\\n\\t%s\",\n                lua_tostring(L, 1), filename, lua_tostring(L, -1));\n}\n\n\nstatic int loader_Lua (lua_State *L) {\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  filename = findfile(L, name, \"path\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  if (luaL_loadfile(L, filename) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\n\nstatic const char *mkfuncname (lua_State *L, const char *modname) {\n  const char *fname;\n  const char *mark = strchr(modname, *LUA_IGMARK);\n  if (mark) modname = mark + 1;\n  fname = luaL_gsub(L, modname, \".\", LUA_OFSEP);\n  fname = lua_pushfstring(L, POF\"%s\", fname);\n  lua_remove(L, -2);  /* remove 'gsub' result */\n  return fname;\n}\n\n\nstatic int loader_C (lua_State *L) {\n  const char *fname;\n  const char *name = luaL_checkstring(L, 1);\n  const char *filename = findfile(L, name, \"cpath\");\n  if (filename == NULL) return 1;  /* library not found in this path */\n  fname = mkfuncname(L, name);\n  if (ll_loadfunc(L, filename, fname) != 0)\n    loaderror(L, filename);\n  return 1;  /* library loaded successfully */\n}\n\n\nstatic int loader_Croot (lua_State *L) {\n  const char *fname;\n  const char *filename;\n  const char *name = luaL_checkstring(L, 1);\n  const char *p = strchr(name, '.');\n  int stat;\n  if (p == NULL) return 0;  /* is root */\n  lua_pushlstring(L, name, p - name);\n  filename = findfile(L, lua_tostring(L, -1), \"cpath\");\n  if (filename == NULL) return 1;  /* root not found */\n  fname = mkfuncname(L, name);\n  if ((stat = ll_loadfunc(L, filename, fname)) != 0) {\n    if (stat != ERRFUNC) loaderror(L, filename);  /* real error */\n    lua_pushfstring(L, \"\\n\\tno module \" LUA_QS \" in file \" LUA_QS,\n                       name, filename);\n    return 1;  /* function not found */\n  }\n  return 1;\n}\n\n\nstatic int loader_preload (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  lua_getfield(L, LUA_ENVIRONINDEX, \"preload\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.preload\") \" must be a table\");\n  lua_getfield(L, -1, name);\n  if (lua_isnil(L, -1))  /* not found? */\n    lua_pushfstring(L, \"\\n\\tno field package.preload['%s']\", name);\n  return 1;\n}\n\n\nstatic const int sentinel_ = 0;\n#define sentinel\t((void *)&sentinel_)\n\n\nstatic int ll_require (lua_State *L) {\n  const char *name = luaL_checkstring(L, 1);\n  int preload = lua_toboolean(L, 2);\n  int i;\n  lua_settop(L, 1);  /* _PRELOAD/_LOADED table will be at index 2 */\n  lua_getfield(L, LUA_REGISTRYINDEX, (preload)?\"_PRELOAD\":\"_LOADED\");\n  lua_getfield(L, 2, name);\n  if (lua_toboolean(L, -1)) {  /* is it there? */\n    if (lua_touserdata(L, -1) == sentinel)  /* check loops */\n      luaL_error(L, \"loop or previous error loading module \" LUA_QS, name);\n    return 1;  /* package is already loaded */\n  }\n  /* else must load it; iterate over available loaders */\n  lua_getfield(L, LUA_ENVIRONINDEX, \"loaders\");\n  if (!lua_istable(L, -1))\n    luaL_error(L, LUA_QL(\"package.loaders\") \" must be a table\");\n  lua_pushliteral(L, \"\");  /* error message accumulator */\n  for (i=1; ; i++) {\n    lua_rawgeti(L, -2, i);  /* get a loader */\n    if (lua_isnil(L, -1))\n      luaL_error(L, \"module \" LUA_QS \" not found:%s\",\n                    name, lua_tostring(L, -2));\n    lua_pushstring(L, name);\n    lua_call(L, 1, 1);  /* call it */\n    if (lua_isfunction(L, -1))  /* did it find module? */\n      break;  /* module loaded successfully */\n    else if (lua_isstring(L, -1))  /* loader returned error message? */\n      lua_concat(L, 2);  /* accumulate it */\n    else\n      lua_pop(L, 1);\n  }\n  if (preload) { /* add library to preload list, don't run it yet. */\n    lua_pushvalue(L, -1);  /* dup module function */\n    lua_setfield(L, 2, name);  /* _PRELOAD[name] = library load function. */\n    return 1;\n  }\n  lua_pushlightuserdata(L, sentinel);\n  lua_setfield(L, 2, name);  /* _LOADED[name] = sentinel */\n  lua_pushstring(L, name);  /* pass name as argument to module */\n  lua_call(L, 1, 1);  /* run loaded module */\n  if (!lua_isnil(L, -1))  /* non-nil return? */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = returned value */\n  lua_getfield(L, 2, name);\n  if (lua_touserdata(L, -1) == sentinel) {   /* module did not set a value? */\n    lua_pushboolean(L, 1);  /* use true as result */\n    lua_pushvalue(L, -1);  /* extra copy to be returned */\n    lua_setfield(L, 2, name);  /* _LOADED[name] = true */\n  }\n  return 1;\n}\n\n/* }====================================================== */\n\n\n\n/*\n** {======================================================\n** 'module' function\n** =======================================================\n*/\n  \n\nstatic void setfenv (lua_State *L) {\n  lua_Debug ar;\n  if (lua_getstack(L, 1, &ar) == 0 ||\n      lua_getinfo(L, \"f\", &ar) == 0 ||  /* get calling function */\n      lua_iscfunction(L, -1))\n    luaL_error(L, LUA_QL(\"module\") \" not called from a Lua function\");\n  lua_pushvalue(L, -2);\n  lua_setfenv(L, -2);\n  lua_pop(L, 1);\n}\n\n\nstatic void dooptions (lua_State *L, int n) {\n  int i;\n  for (i = 2; i <= n; i++) {\n    lua_pushvalue(L, i);  /* get option (a function) */\n    lua_pushvalue(L, -2);  /* module */\n    lua_call(L, 1, 0);\n  }\n}\n\n\nstatic void modinit (lua_State *L, const char *modname) {\n  const char *dot;\n  lua_pushvalue(L, -1);\n  lua_setfield(L, -2, \"_M\");  /* module._M = module */\n  lua_pushstring(L, modname);\n  lua_setfield(L, -2, \"_NAME\");\n  dot = strrchr(modname, '.');  /* look for last dot in module name */\n  if (dot == NULL) dot = modname;\n  else dot++;\n  /* set _PACKAGE as package name (full module name minus last part) */\n  lua_pushlstring(L, modname, dot - modname);\n  lua_setfield(L, -2, \"_PACKAGE\");\n}\n\n\nstatic int ll_module (lua_State *L) {\n  const char *modname = luaL_checkstring(L, 1);\n  int loaded = lua_gettop(L) + 1;  /* index of _LOADED table */\n  lua_getfield(L, LUA_REGISTRYINDEX, \"_LOADED\");\n  lua_getfield(L, loaded, modname);  /* get _LOADED[modname] */\n  if (!lua_istable(L, -1)) {  /* not found? */\n    lua_pop(L, 1);  /* remove previous result */\n    /* try global variable (and create one if it does not exist) */\n    if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)\n      return luaL_error(L, \"name conflict for module \" LUA_QS, modname);\n    lua_pushvalue(L, -1);\n    lua_setfield(L, loaded, modname);  /* _LOADED[modname] = new table */\n  }\n  /* check whether table already has a _NAME field */\n  lua_getfield(L, -1, \"_NAME\");\n  if (!lua_isnil(L, -1))  /* is table an initialized module? */\n    lua_pop(L, 1);\n  else {  /* no; initialize it */\n    lua_pop(L, 1);\n    modinit(L, modname);\n  }\n  lua_pushvalue(L, -1);\n  setfenv(L);\n  dooptions(L, loaded - 1);\n  return 0;\n}\n\n\nstatic int ll_seeall (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  if (!lua_getmetatable(L, 1)) {\n    lua_createtable(L, 0, 1); /* create new metatable */\n    lua_pushvalue(L, -1);\n    lua_setmetatable(L, 1);\n  }\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  lua_setfield(L, -2, \"__index\");  /* mt.__index = _G */\n  return 0;\n}\n\n\n/* }====================================================== */\n\n\n\n/* auxiliary mark (for internal use) */\n#define AUXMARK\t\t\"\\1\"\n\nstatic void setpath (lua_State *L, const char *fieldname, const char *envname,\n                                   const char *def) {\n  const char *path = getenv(envname);\n  if (path == NULL)  /* no environment variable? */\n    lua_pushstring(L, def);  /* use default */\n  else {\n    /* replace \";;\" by \";AUXMARK;\" and then AUXMARK by default path */\n    path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,\n                              LUA_PATHSEP AUXMARK LUA_PATHSEP);\n    luaL_gsub(L, path, AUXMARK, def);\n    lua_remove(L, -2);\n  }\n  setprogdir(L);\n  lua_setfield(L, -2, fieldname);\n}\n\n\nstatic const luaL_Reg pk_funcs[] = {\n  {\"loadlib\", ll_loadlib},\n  {\"seeall\", ll_seeall},\n  {NULL, NULL}\n};\n\n\nstatic const luaL_Reg ll_funcs[] = {\n  {\"module\", ll_module},\n  {\"require\", ll_require},\n  {NULL, NULL}\n};\n\n\nstatic const lua_CFunction loaders[] =\n  {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};\n\n\nLUALIB_API int luaopen_package (lua_State *L) {\n  int i;\n  /* create new type _LOADLIB */\n  luaL_newmetatable(L, \"_LOADLIB\");\n  lua_pushcfunction(L, gctm);\n  lua_setfield(L, -2, \"__gc\");\n  /* create `package' table */\n  luaL_register(L, LUA_LOADLIBNAME, pk_funcs);\n#if defined(LUA_COMPAT_LOADLIB) \n  lua_getfield(L, -1, \"loadlib\");\n  lua_setfield(L, LUA_GLOBALSINDEX, \"loadlib\");\n#endif\n  lua_pushvalue(L, -1);\n  lua_replace(L, LUA_ENVIRONINDEX);\n  /* create `loaders' table */\n  lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);\n  /* fill it with pre-defined loaders */\n  for (i=0; loaders[i] != NULL; i++) {\n    lua_pushcfunction(L, loaders[i]);\n    lua_rawseti(L, -2, i+1);\n  }\n  lua_setfield(L, -2, \"loaders\");  /* put it in field `loaders' */\n  setpath(L, \"path\", LUA_PATH, LUA_PATH_DEFAULT);  /* set field `path' */\n  setpath(L, \"cpath\", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */\n  /* store config information */\n  lua_pushliteral(L, LUA_DIRSEP \"\\n\" LUA_PATHSEP \"\\n\" LUA_PATH_MARK \"\\n\"\n                     LUA_EXECDIR \"\\n\" LUA_IGMARK);\n  lua_setfield(L, -2, \"config\");\n  /* set field `loaded' */\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_LOADED\", 2);\n  lua_setfield(L, -2, \"loaded\");\n  /* set field `preload' */\n  luaL_findtable(L, LUA_REGISTRYINDEX, \"_PRELOAD\", 0);\n  lua_setfield(L, -2, \"preload\");\n  lua_pushvalue(L, LUA_GLOBALSINDEX);\n  luaL_register(L, NULL, ll_funcs);  /* open lib into global table */\n  lua_pop(L, 1);\n  return 1;  /* return 'package' table */\n}\n\n"
  },
  {
    "path": "src/lobject.c",
    "content": "/*\n** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $\n** Some generic functions over Lua objects\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lobject_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldo.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"lvm.h\"\n\n\n\nconst TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};\n\n\n/*\n** converts an integer to a \"floating point byte\", represented as\n** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if\n** eeeee != 0 and (xxx) otherwise.\n*/\nint luaO_int2fb (unsigned int x) {\n  int e = 0;  /* expoent */\n  while (x >= 16) {\n    x = (x+1) >> 1;\n    e++;\n  }\n  if (x < 8) return x;\n  else return ((e+1) << 3) | (cast_int(x) - 8);\n}\n\n\n/* converts back */\nint luaO_fb2int (int x) {\n  int e = (x >> 3) & 31;\n  if (e == 0) return x;\n  else return ((x & 7)+8) << (e - 1);\n}\n\n\nint luaO_log2 (unsigned int x) {\n  static const lu_byte log_2[256] = {\n    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8\n  };\n  int l = -1;\n  while (x >= 256) { l += 8; x >>= 8; }\n  return l + log_2[x];\n\n}\n\n\nint luaO_rawequalObj (const TValue *t1, const TValue *t2) {\n  if (ttype(t1) != ttype(t2)) return 0;\n  else switch (ttype(t1)) {\n    case LUA_TNIL:\n      return 1;\n    case LUA_TNUMBER:\n      return luai_numeq(nvalue(t1), nvalue(t2));\n    case LUA_TBOOLEAN:\n      return bvalue(t1) == bvalue(t2);  /* boolean true must be 1 !! */\n    case LUA_TLIGHTUSERDATA:\n      return pvalue(t1) == pvalue(t2);\n    default:\n      lua_assert(iscollectable(t1));\n      return gcvalue(t1) == gcvalue(t2);\n  }\n}\n\n\nint luaO_str2d (const char *s, lua_Number *result) {\n  char *endptr;\n  *result = lua_str2number(s, &endptr);\n  if (endptr == s) return 0;  /* conversion failed */\n  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */\n    *result = cast_num(strtoul(s, &endptr, 16));\n  if (*endptr == '\\0') return 1;  /* most common case */\n  while (isspace(cast(unsigned char, *endptr))) endptr++;\n  if (*endptr != '\\0') return 0;  /* invalid trailing characters? */\n  return 1;\n}\n\n\n\nstatic void pushstr (lua_State *L, const char *str) {\n  setsvalue2s(L, L->top, luaS_new(L, str));\n  incr_top(L);\n}\n\n\n/* this function handles only `%d', `%c', %f, %p, and `%s' formats */\nconst char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {\n  int n = 1;\n  pushstr(L, \"\");\n  for (;;) {\n    const char *e = strchr(fmt, '%');\n    if (e == NULL) break;\n    setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));\n    incr_top(L);\n    switch (*(e+1)) {\n      case 's': {\n        const char *s = va_arg(argp, char *);\n        if (s == NULL) s = \"(null)\";\n        pushstr(L, s);\n        break;\n      }\n      case 'c': {\n        char buff[2];\n        buff[0] = cast(char, va_arg(argp, int));\n        buff[1] = '\\0';\n        pushstr(L, buff);\n        break;\n      }\n      case 'd': {\n        setnvalue(L->top, cast_num(va_arg(argp, int)));\n        incr_top(L);\n        break;\n      }\n      case 'f': {\n        setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));\n        incr_top(L);\n        break;\n      }\n      case 'p': {\n        char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */\n        sprintf(buff, \"%p\", va_arg(argp, void *));\n        pushstr(L, buff);\n        break;\n      }\n      case '%': {\n        pushstr(L, \"%\");\n        break;\n      }\n      default: {\n        char buff[3];\n        buff[0] = '%';\n        buff[1] = *(e+1);\n        buff[2] = '\\0';\n        pushstr(L, buff);\n        break;\n      }\n    }\n    n += 2;\n    fmt = e+2;\n  }\n  pushstr(L, fmt);\n  luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);\n  L->top -= n;\n  return svalue(L->top - 1);\n}\n\n\nconst char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {\n  const char *msg;\n  va_list argp;\n  va_start(argp, fmt);\n  msg = luaO_pushvfstring(L, fmt, argp);\n  va_end(argp);\n  return msg;\n}\n\n\nvoid luaO_chunkid (char *out, const char *source, size_t bufflen) {\n  if (*source == '=') {\n    strncpy(out, source+1, bufflen);  /* remove first char */\n    out[bufflen-1] = '\\0';  /* ensures null termination */\n  }\n  else {  /* out = \"source\", or \"...source\" */\n    if (*source == '@') {\n      size_t l;\n      source++;  /* skip the `@' */\n      bufflen -= sizeof(\" '...' \");\n      l = strlen(source);\n      strcpy(out, \"\");\n      if (l > bufflen) {\n        source += (l-bufflen);  /* get last part of file name */\n        strcat(out, \"...\");\n      }\n      strcat(out, source);\n    }\n    else {  /* out = [string \"string\"] */\n      size_t len = strcspn(source, \"\\n\\r\");  /* stop at first newline */\n      bufflen -= sizeof(\" [string \\\"...\\\"] \");\n      if (len > bufflen) len = bufflen;\n      strcpy(out, \"[string \\\"\");\n      if (source[len] != '\\0') {  /* must truncate? */\n        strncat(out, source, len);\n        strcat(out, \"...\");\n      }\n      else\n        strcat(out, source);\n      strcat(out, \"\\\"]\");\n    }\n  }\n}\n"
  },
  {
    "path": "src/lobject.h",
    "content": "/*\n** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $\n** Type definitions for Lua objects\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lobject_h\n#define lobject_h\n\n\n#include <stdarg.h>\n\n\n#include \"llimits.h\"\n#include \"lua.h\"\n\n\n/* tags for values visible from Lua */\n#define LAST_TAG\tLUA_TTHREAD\n\n#define NUM_TAGS\t(LAST_TAG+1)\n\n\n/*\n** Extra tags for non-values\n*/\n#define LUA_TPROTO\t(LAST_TAG+1)\n#define LUA_TUPVAL\t(LAST_TAG+2)\n#define LUA_TDEADKEY\t(LAST_TAG+3)\n\n\n/*\n** Union of all collectable objects\n*/\ntypedef union GCObject GCObject;\n\n\n/*\n** Common Header for all collectable objects (in macro form, to be\n** included in other objects)\n*/\n#define CommonHeader\tGCObject *next; lu_byte tt; lu_byte marked\n\n\n/*\n** Common header in struct form\n*/\ntypedef struct GCheader {\n  CommonHeader;\n} GCheader;\n\n\n\n\n/*\n** Union of all Lua values\n*/\ntypedef union {\n  GCObject *gc;\n  void *p;\n  lua_Number n;\n  int b;\n} Value;\n\n\n/*\n** Tagged Values\n*/\n\n#define TValuefields\tValue value; int tt\n\nstruct lua_TValue {\n  TValuefields;\n};\n\n\n/* Macros to test type */\n#define ttisnil(o)\t(ttype(o) == LUA_TNIL)\n#define ttisnumber(o)\t(ttype(o) == LUA_TNUMBER)\n#define ttisstring(o)\t(ttype(o) == LUA_TSTRING)\n#define ttistable(o)\t(ttype(o) == LUA_TTABLE)\n#define ttisfunction(o)\t(ttype(o) == LUA_TFUNCTION)\n#define ttisboolean(o)\t(ttype(o) == LUA_TBOOLEAN)\n#define ttisuserdata(o)\t(ttype(o) == LUA_TUSERDATA)\n#define ttisthread(o)\t(ttype(o) == LUA_TTHREAD)\n#define ttislightuserdata(o)\t(ttype(o) == LUA_TLIGHTUSERDATA)\n\n/* Macros to access values */\n#define ttype(o)\t((o)->tt)\n#define gcvalue(o)\tcheck_exp(iscollectable(o), (o)->value.gc)\n#define pvalue(o)\tcheck_exp(ttislightuserdata(o), (o)->value.p)\n#define nvalue(o)\tcheck_exp(ttisnumber(o), (o)->value.n)\n#define rawtsvalue(o)\tcheck_exp(ttisstring(o), &(o)->value.gc->ts)\n#define tsvalue(o)\t(&rawtsvalue(o)->tsv)\n#define rawuvalue(o)\tcheck_exp(ttisuserdata(o), &(o)->value.gc->u)\n#define uvalue(o)\t(&rawuvalue(o)->uv)\n#define clvalue(o)\tcheck_exp(ttisfunction(o), &(o)->value.gc->cl)\n#define hvalue(o)\tcheck_exp(ttistable(o), &(o)->value.gc->h)\n#define bvalue(o)\tcheck_exp(ttisboolean(o), (o)->value.b)\n#define thvalue(o)\tcheck_exp(ttisthread(o), &(o)->value.gc->th)\n\n#define l_isfalse(o)\t(ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))\n\n/*\n** for internal debug only\n*/\n#define checkconsistency(obj) \\\n  lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))\n\n#define checkliveness(g,obj) \\\n  lua_assert(!iscollectable(obj) || \\\n  ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))\n\n\n/* Macros to set values */\n#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)\n\n#define setnvalue(obj,x) \\\n  { lua_Number i_x = (x); TValue *i_o=(obj); i_o->value.n=i_x; i_o->tt=LUA_TNUMBER; }\n\n#define setpvalue(obj,x) \\\n  { void *i_x = (x); TValue *i_o=(obj); i_o->value.p=i_x; i_o->tt=LUA_TLIGHTUSERDATA; }\n\n#define setbvalue(obj,x) \\\n  { int i_x = (x); TValue *i_o=(obj); i_o->value.b=i_x; i_o->tt=LUA_TBOOLEAN; }\n\n#define setsvalue(L,obj,x) \\\n  { GCObject *i_x = cast(GCObject *, (x)); \\\n    TValue *i_o=(obj); \\\n    i_o->value.gc=i_x; i_o->tt=LUA_TSTRING; \\\n    checkliveness(G(L),i_o); }\n\n#define setuvalue(L,obj,x) \\\n  { GCObject *i_x = cast(GCObject *, (x)); \\\n    TValue *i_o=(obj); \\\n    i_o->value.gc=i_x; i_o->tt=LUA_TUSERDATA; \\\n    checkliveness(G(L),i_o); }\n\n#define setthvalue(L,obj,x) \\\n  { GCObject *i_x = cast(GCObject *, (x)); \\\n    TValue *i_o=(obj); \\\n    i_o->value.gc=i_x; i_o->tt=LUA_TTHREAD; \\\n    checkliveness(G(L),i_o); }\n\n#define setclvalue(L,obj,x) \\\n  { GCObject *i_x = cast(GCObject *, (x)); \\\n    TValue *i_o=(obj); \\\n    i_o->value.gc=i_x; i_o->tt=LUA_TFUNCTION; \\\n    checkliveness(G(L),i_o); }\n\n#define sethvalue(L,obj,x) \\\n  { GCObject *i_x = cast(GCObject *, (x)); \\\n    TValue *i_o=(obj); \\\n    i_o->value.gc=i_x; i_o->tt=LUA_TTABLE; \\\n    checkliveness(G(L),i_o); }\n\n#define setptvalue(L,obj,x) \\\n  { GCObject *i_x = cast(GCObject *, (x)); \\\n    TValue *i_o=(obj); \\\n    i_o->value.gc=i_x; i_o->tt=LUA_TPROTO; \\\n    checkliveness(G(L),i_o); }\n\n\n\n\n#define setobj(L,obj1,obj2) \\\n  { const TValue *o2=(obj2); TValue *o1=(obj1); \\\n    o1->value = o2->value; o1->tt=o2->tt; \\\n    checkliveness(G(L),o1); }\n\n\n/*\n** different types of sets, according to destination\n*/\n\n/* from stack to (same) stack */\n#define setobjs2s\tsetobj\n/* to stack (not from same stack) */\n#define setobj2s\tsetobj\n#define setsvalue2s\tsetsvalue\n#define sethvalue2s\tsethvalue\n#define setptvalue2s\tsetptvalue\n/* from table to same table */\n#define setobjt2t\tsetobj\n/* to table */\n#define setobj2t\tsetobj\n/* to new object */\n#define setobj2n\tsetobj\n#define setsvalue2n\tsetsvalue\n\n#define setttype(obj, tt) (ttype(obj) = (tt))\n\n\n#define iscollectable(o)\t(ttype(o) >= LUA_TSTRING)\n\n\n\n/*\n** String headers for string table\n*/\ntypedef union TString {\n  L_Umaxalign dummy;  /* ensures maximum alignment for strings */\n  struct {\n    CommonHeader;\n    lu_byte reserved;\n    unsigned int hash;\n    size_t len;\n  } tsv;\n} TString;\n\n\n#define getstr(ts)\tcast(const char *, (ts) + 1)\n#define svalue(o)       getstr(rawtsvalue(o))\n\n\n\ntypedef union Udata {\n  L_Umaxalign dummy;  /* ensures maximum alignment for `local' udata */\n  struct {\n    CommonHeader;\n    struct Table *metatable;\n    struct Table *env;\n    size_t len;\n  } uv;\n} Udata;\n\n\n\n\n/*\n** Function Prototypes\n*/\ntypedef struct Proto {\n  CommonHeader;\n  TValue *k;  /* constants used by the function */\n  Instruction *code;\n  struct Proto **p;  /* functions defined inside the function */\n  int *lineinfo;  /* map from opcodes to source lines */\n  struct LocVar *locvars;  /* information about local variables */\n  TString **upvalues;  /* upvalue names */\n  TString  *source;\n  int sizeupvalues;\n  int sizek;  /* size of `k' */\n  int sizecode;\n  int sizelineinfo;\n  int sizep;  /* size of `p' */\n  int sizelocvars;\n  int linedefined;\n  int lastlinedefined;\n  GCObject *gclist;\n  lu_byte nups;  /* number of upvalues */\n  lu_byte numparams;\n  lu_byte is_vararg;\n  lu_byte maxstacksize;\n  JIT_PROTO_STATE\n} Proto;\n\n\n/* masks for new-style vararg */\n#define VARARG_HASARG\t\t1\n#define VARARG_ISVARARG\t\t2\n#define VARARG_NEEDSARG\t\t4\n\n\ntypedef struct LocVar {\n  TString *varname;\n  int startpc;  /* first point where variable is active */\n  int endpc;    /* first point where variable is dead */\n} LocVar;\n\n\n\n/*\n** Upvalues\n*/\n\ntypedef struct UpVal {\n  CommonHeader;\n  TValue *v;  /* points to stack or to its own value */\n  union {\n    TValue value;  /* the value (when closed) */\n    struct {  /* double linked list (when open) */\n      struct UpVal *prev;\n      struct UpVal *next;\n    } l;\n  } u;\n} UpVal;\n\n\n/*\n** Closures\n*/\n\n#define ClosureHeader \\\n\tCommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \\\n\tstruct Table *env; lua_precall precall\n\ntypedef struct CClosure {\n  ClosureHeader;\n  lua_CFunction f;\n  TValue upvalue[1];\n} CClosure;\n\n\ntypedef struct LClosure {\n  ClosureHeader;\n  struct Proto *p;\n  UpVal *upvals[1];\n} LClosure;\n\n\ntypedef union Closure {\n  CClosure c;\n  LClosure l;\n} Closure;\n\n\n#define iscfunction(o)\t(ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)\n#define isLfunction(o)\t(ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)\n\n\n/*\n** Tables\n*/\n\ntypedef union TKey {\n  struct {\n    TValuefields;\n    struct Node *next;  /* for chaining */\n  } nk;\n  TValue tvk;\n} TKey;\n\n\ntypedef struct Node {\n  TValue i_val;\n  TKey i_key;\n} Node;\n\n\ntypedef struct Table {\n  CommonHeader;\n  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */ \n  lu_byte lsizenode;  /* log2 of size of `node' array */\n  struct Table *metatable;\n  TValue *array;  /* array part */\n  Node *node;\n  Node *lastfree;  /* any free position is before this position */\n  GCObject *gclist;\n  int sizearray;  /* size of `array' array */\n} Table;\n\n\n\n/*\n** `module' operation for hashing (size is always a power of 2)\n*/\n#define lmod(s,size) \\\n\t(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))\n\n\n#define twoto(x)\t(1<<(x))\n#define sizenode(t)\t(twoto((t)->lsizenode))\n\n\n#define luaO_nilobject\t\t(&luaO_nilobject_)\n\nLUAI_DATA const TValue luaO_nilobject_;\n\n#define ceillog2(x)\t(luaO_log2((x)-1) + 1)\n\nLUAI_FUNC int luaO_log2 (unsigned int x);\nLUAI_FUNC int luaO_int2fb (unsigned int x);\nLUAI_FUNC int luaO_fb2int (int x);\nLUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);\nLUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);\nLUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,\n                                                       va_list argp);\nLUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);\nLUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);\n\n\n#endif\n\n"
  },
  {
    "path": "src/lopcodes.c",
    "content": "/*\n** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $\n** See Copyright Notice in lua.h\n*/\n\n\n#define lopcodes_c\n#define LUA_CORE\n\n\n#include \"lopcodes.h\"\n\n\n/* ORDER OP */\n\nconst char *const luaP_opnames[NUM_OPCODES+1] = {\n  \"MOVE\",\n  \"LOADK\",\n  \"LOADBOOL\",\n  \"LOADNIL\",\n  \"GETUPVAL\",\n  \"GETGLOBAL\",\n  \"GETTABLE\",\n  \"SETGLOBAL\",\n  \"SETUPVAL\",\n  \"SETTABLE\",\n  \"NEWTABLE\",\n  \"SELF\",\n  \"ADD\",\n  \"SUB\",\n  \"MUL\",\n  \"DIV\",\n  \"MOD\",\n  \"POW\",\n  \"UNM\",\n  \"NOT\",\n  \"LEN\",\n  \"CONCAT\",\n  \"JMP\",\n  \"EQ\",\n  \"LT\",\n  \"LE\",\n  \"TEST\",\n  \"TESTSET\",\n  \"CALL\",\n  \"TAILCALL\",\n  \"RETURN\",\n  \"FORLOOP\",\n  \"FORPREP\",\n  \"TFORLOOP\",\n  \"SETLIST\",\n  \"CLOSE\",\n  \"CLOSURE\",\n  \"VARARG\",\n  NULL\n};\n\n\n#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))\n\nconst lu_byte luaP_opmodes[NUM_OPCODES] = {\n/*       T  A    B       C     mode\t\t   opcode\t*/\n  opmode(0, 1, OpArgR, OpArgN, iABC) \t\t/* OP_MOVE */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_LOADK */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_LOADBOOL */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LOADNIL */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_GETUPVAL */\n ,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t/* OP_GETGLOBAL */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_GETTABLE */\n ,opmode(0, 0, OpArgK, OpArgN, iABx)\t\t/* OP_SETGLOBAL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_SETUPVAL */\n ,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t/* OP_SETTABLE */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_NEWTABLE */\n ,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t/* OP_SELF */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_ADD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_SUB */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MUL */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_DIV */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_MOD */\n ,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t/* OP_POW */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_UNM */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_NOT */\n ,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t/* OP_LEN */\n ,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t/* OP_CONCAT */\n ,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t/* OP_JMP */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_EQ */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LT */\n ,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t/* OP_LE */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TEST */\n ,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t/* OP_TESTSET */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_CALL */\n ,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t/* OP_TAILCALL */\n ,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t/* OP_RETURN */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORLOOP */\n ,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t/* OP_FORPREP */\n ,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t/* OP_TFORLOOP */\n ,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t/* OP_SETLIST */\n ,opmode(0, 0, OpArgN, OpArgN, iABC)\t\t/* OP_CLOSE */\n ,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t/* OP_CLOSURE */\n ,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t/* OP_VARARG */\n};\n\n"
  },
  {
    "path": "src/lopcodes.h",
    "content": "/*\n** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $\n** Opcodes for Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lopcodes_h\n#define lopcodes_h\n\n#include \"llimits.h\"\n\n\n/*===========================================================================\n  We assume that instructions are unsigned numbers.\n  All instructions have an opcode in the first 6 bits.\n  Instructions can have the following fields:\n\t`A' : 8 bits\n\t`B' : 9 bits\n\t`C' : 9 bits\n\t`Bx' : 18 bits (`B' and `C' together)\n\t`sBx' : signed Bx\n\n  A signed argument is represented in excess K; that is, the number\n  value is the unsigned value minus K. K is exactly the maximum value\n  for that argument (so that -max is represented by 0, and +max is\n  represented by 2*max), which is half the maximum for the corresponding\n  unsigned argument.\n===========================================================================*/\n\n\nenum OpMode {iABC, iABx, iAsBx};  /* basic instruction format */\n\n\n/*\n** size and position of opcode arguments.\n*/\n#define SIZE_C\t\t9\n#define SIZE_B\t\t9\n#define SIZE_Bx\t\t(SIZE_C + SIZE_B)\n#define SIZE_A\t\t8\n\n#define SIZE_OP\t\t6\n\n#define POS_OP\t\t0\n#define POS_A\t\t(POS_OP + SIZE_OP)\n#define POS_C\t\t(POS_A + SIZE_A)\n#define POS_B\t\t(POS_C + SIZE_C)\n#define POS_Bx\t\tPOS_C\n\n\n/*\n** limits for opcode arguments.\n** we use (signed) int to manipulate most arguments,\n** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)\n*/\n#if SIZE_Bx < LUAI_BITSINT-1\n#define MAXARG_Bx        ((1<<SIZE_Bx)-1)\n#define MAXARG_sBx        (MAXARG_Bx>>1)         /* `sBx' is signed */\n#else\n#define MAXARG_Bx        MAX_INT\n#define MAXARG_sBx        MAX_INT\n#endif\n\n\n#define MAXARG_A        ((1<<SIZE_A)-1)\n#define MAXARG_B        ((1<<SIZE_B)-1)\n#define MAXARG_C        ((1<<SIZE_C)-1)\n\n\n/* creates a mask with `n' 1 bits at position `p' */\n#define MASK1(n,p)\t((~((~(Instruction)0)<<n))<<p)\n\n/* creates a mask with `n' 0 bits at position `p' */\n#define MASK0(n,p)\t(~MASK1(n,p))\n\n/*\n** the following macros help to manipulate instructions\n*/\n\n#define GET_OPCODE(i)\t(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))\n#define SET_OPCODE(i,o)\t((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \\\n\t\t((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))\n\n#define GETARG_A(i)\t(cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))\n#define SETARG_A(i,u)\t((i) = (((i)&MASK0(SIZE_A,POS_A)) | \\\n\t\t((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))\n\n#define GETARG_B(i)\t(cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))\n#define SETARG_B(i,b)\t((i) = (((i)&MASK0(SIZE_B,POS_B)) | \\\n\t\t((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))\n\n#define GETARG_C(i)\t(cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))\n#define SETARG_C(i,b)\t((i) = (((i)&MASK0(SIZE_C,POS_C)) | \\\n\t\t((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))\n\n#define GETARG_Bx(i)\t(cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))\n#define SETARG_Bx(i,b)\t((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \\\n\t\t((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))\n\n#define GETARG_sBx(i)\t(GETARG_Bx(i)-MAXARG_sBx)\n#define SETARG_sBx(i,b)\tSETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))\n\n\n#define CREATE_ABC(o,a,b,c)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, b)<<POS_B) \\\n\t\t\t| (cast(Instruction, c)<<POS_C))\n\n#define CREATE_ABx(o,a,bc)\t((cast(Instruction, o)<<POS_OP) \\\n\t\t\t| (cast(Instruction, a)<<POS_A) \\\n\t\t\t| (cast(Instruction, bc)<<POS_Bx))\n\n\n/*\n** Macros to operate RK indices\n*/\n\n/* this bit 1 means constant (0 means register) */\n#define BITRK\t\t(1 << (SIZE_B - 1))\n\n/* test whether value is a constant */\n#define ISK(x)\t\t((x) & BITRK)\n\n/* gets the index of the constant */\n#define INDEXK(r)\t((int)(r) & ~BITRK)\n\n#define MAXINDEXRK\t(BITRK - 1)\n\n/* code a constant index as a RK value */\n#define RKASK(x)\t((x) | BITRK)\n\n\n/*\n** invalid register that fits in 8 bits\n*/\n#define NO_REG\t\tMAXARG_A\n\n\n/*\n** R(x) - register\n** Kst(x) - constant (in constant table)\n** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)\n*/\n\n\n/*\n** grep \"ORDER OP\" if you change these enums\n*/\n\ntypedef enum {\n/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*/\nOP_MOVE,/*\tA B\tR(A) := R(B)\t\t\t\t\t*/\nOP_LOADK,/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*/\nOP_LOADBOOL,/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*/\nOP_LOADNIL,/*\tA B\tR(A) := ... := R(B) := nil\t\t\t*/\nOP_GETUPVAL,/*\tA B\tR(A) := UpValue[B]\t\t\t\t*/\n\nOP_GETGLOBAL,/*\tA Bx\tR(A) := Gbl[Kst(Bx)]\t\t\t\t*/\nOP_GETTABLE,/*\tA B C\tR(A) := R(B)[RK(C)]\t\t\t\t*/\n\nOP_SETGLOBAL,/*\tA Bx\tGbl[Kst(Bx)] := R(A)\t\t\t\t*/\nOP_SETUPVAL,/*\tA B\tUpValue[B] := R(A)\t\t\t\t*/\nOP_SETTABLE,/*\tA B C\tR(A)[RK(B)] := RK(C)\t\t\t\t*/\n\nOP_NEWTABLE,/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*/\n\nOP_SELF,/*\tA B C\tR(A+1) := R(B); R(A) := R(B)[RK(C)]\t\t*/\n\nOP_ADD,/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*/\nOP_SUB,/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*/\nOP_MUL,/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*/\nOP_DIV,/*\tA B C\tR(A) := RK(B) / RK(C)\t\t\t\t*/\nOP_MOD,/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*/\nOP_POW,/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*/\nOP_UNM,/*\tA B\tR(A) := -R(B)\t\t\t\t\t*/\nOP_NOT,/*\tA B\tR(A) := not R(B)\t\t\t\t*/\nOP_LEN,/*\tA B\tR(A) := length of R(B)\t\t\t\t*/\n\nOP_CONCAT,/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*/\n\nOP_JMP,/*\tsBx\tpc+=sBx\t\t\t\t\t*/\n\nOP_EQ,/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*/\nOP_LT,/*\tA B C\tif ((RK(B) <  RK(C)) ~= A) then pc++  \t\t*/\nOP_LE,/*\tA B C\tif ((RK(B) <= RK(C)) ~= A) then pc++  \t\t*/\n\nOP_TEST,/*\tA C\tif not (R(A) <=> C) then pc++\t\t\t*/ \nOP_TESTSET,/*\tA B C\tif (R(B) <=> C) then R(A) := R(B) else pc++\t*/ \n\nOP_CALL,/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */\nOP_TAILCALL,/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*/\nOP_RETURN,/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*/\n\nOP_FORLOOP,/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/\nOP_FORPREP,/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*/\n\nOP_TFORLOOP,/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); \n                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++\t*/ \nOP_SETLIST,/*\tA B C\tR(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B\t*/\n\nOP_CLOSE,/*\tA \tclose all variables in the stack up to (>=) R(A)*/\nOP_CLOSURE,/*\tA Bx\tR(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))\t*/\n\nOP_VARARG/*\tA B\tR(A), R(A+1), ..., R(A+B-1) = vararg\t\t*/\n} OpCode;\n\n\n#define NUM_OPCODES\t(cast(int, OP_VARARG) + 1)\n\n\n\n/*===========================================================================\n  Notes:\n  (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,\n      and can be 0: OP_CALL then sets `top' to last_result+1, so\n      next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.\n\n  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and\n      set top (like in OP_CALL with C == 0).\n\n  (*) In OP_RETURN, if (B == 0) then return up to `top'\n\n  (*) In OP_SETLIST, if (B == 0) then B = `top';\n      if (C == 0) then next `instruction' is real C\n\n  (*) For comparisons, A specifies what condition the test should accept\n      (true or false).\n\n  (*) All `skips' (pc++) assume that next instruction is a jump\n===========================================================================*/\n\n\n/*\n** masks for instruction properties. The format is:\n** bits 0-1: op mode\n** bits 2-3: C arg mode\n** bits 4-5: B arg mode\n** bit 6: instruction set register A\n** bit 7: operator is a test\n*/  \n\nenum OpArgMask {\n  OpArgN,  /* argument is not used */\n  OpArgU,  /* argument is used */\n  OpArgR,  /* argument is a register or a jump offset */\n  OpArgK   /* argument is a constant or register/constant */\n};\n\nLUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];\n\n#define getOpMode(m)\t(cast(enum OpMode, luaP_opmodes[m] & 3))\n#define getBMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))\n#define getCMode(m)\t(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))\n#define testAMode(m)\t(luaP_opmodes[m] & (1 << 6))\n#define testTMode(m)\t(luaP_opmodes[m] & (1 << 7))\n\n\nLUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */\n\n\n/* number of list items to accumulate before a SETLIST instruction */\n#define LFIELDS_PER_FLUSH\t50\n\n\n#endif\n"
  },
  {
    "path": "src/loslib.c",
    "content": "/*\n** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $\n** Standard Operating System library\n** See Copyright Notice in lua.h\n*/\n\n\n#include <errno.h>\n#include <locale.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n\n#define loslib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\nstatic int os_pushresult (lua_State *L, int i, const char *filename) {\n  int en = errno;  /* calls to Lua API may change this value */\n  if (i) {\n    lua_pushboolean(L, 1);\n    return 1;\n  }\n  else {\n    lua_pushnil(L);\n    lua_pushfstring(L, \"%s: %s\", filename, strerror(en));\n    lua_pushinteger(L, en);\n    return 3;\n  }\n}\n\n\nstatic int os_execute (lua_State *L) {\n  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));\n  return 1;\n}\n\n\nstatic int os_remove (lua_State *L) {\n  const char *filename = luaL_checkstring(L, 1);\n  return os_pushresult(L, remove(filename) == 0, filename);\n}\n\n\nstatic int os_rename (lua_State *L) {\n  const char *fromname = luaL_checkstring(L, 1);\n  const char *toname = luaL_checkstring(L, 2);\n  return os_pushresult(L, rename(fromname, toname) == 0, fromname);\n}\n\n\nstatic int os_tmpname (lua_State *L) {\n  char buff[LUA_TMPNAMBUFSIZE];\n  int err;\n  lua_tmpnam(buff, err);\n  if (err)\n    return luaL_error(L, \"unable to generate a unique filename\");\n  lua_pushstring(L, buff);\n  return 1;\n}\n\n\nstatic int os_getenv (lua_State *L) {\n  lua_pushstring(L, getenv(luaL_checkstring(L, 1)));  /* if NULL push nil */\n  return 1;\n}\n\n\nstatic int os_clock (lua_State *L) {\n  lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);\n  return 1;\n}\n\n\n/*\n** {======================================================\n** Time/Date operations\n** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,\n**   wday=%w+1, yday=%j, isdst=? }\n** =======================================================\n*/\n\nstatic void setfield (lua_State *L, const char *key, int value) {\n  lua_pushinteger(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic void setboolfield (lua_State *L, const char *key, int value) {\n  if (value < 0)  /* undefined? */\n    return;  /* does not set field */\n  lua_pushboolean(L, value);\n  lua_setfield(L, -2, key);\n}\n\nstatic int getboolfield (lua_State *L, const char *key) {\n  int res;\n  lua_getfield(L, -1, key);\n  res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);\n  lua_pop(L, 1);\n  return res;\n}\n\n\nstatic int getfield (lua_State *L, const char *key, int d) {\n  int res;\n  lua_getfield(L, -1, key);\n  if (lua_isnumber(L, -1))\n    res = (int)lua_tointeger(L, -1);\n  else {\n    if (d < 0)\n      return luaL_error(L, \"field \" LUA_QS \" missing in date table\", key);\n    res = d;\n  }\n  lua_pop(L, 1);\n  return res;\n}\n\n\nstatic int os_date (lua_State *L) {\n  const char *s = luaL_optstring(L, 1, \"%c\");\n  time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));\n  struct tm *stm;\n  if (*s == '!') {  /* UTC? */\n    stm = gmtime(&t);\n    s++;  /* skip `!' */\n  }\n  else\n    stm = localtime(&t);\n  if (stm == NULL)  /* invalid date? */\n    lua_pushnil(L);\n  else if (strcmp(s, \"*t\") == 0) {\n    lua_createtable(L, 0, 9);  /* 9 = number of fields */\n    setfield(L, \"sec\", stm->tm_sec);\n    setfield(L, \"min\", stm->tm_min);\n    setfield(L, \"hour\", stm->tm_hour);\n    setfield(L, \"day\", stm->tm_mday);\n    setfield(L, \"month\", stm->tm_mon+1);\n    setfield(L, \"year\", stm->tm_year+1900);\n    setfield(L, \"wday\", stm->tm_wday+1);\n    setfield(L, \"yday\", stm->tm_yday+1);\n    setboolfield(L, \"isdst\", stm->tm_isdst);\n  }\n  else {\n    char cc[3];\n    luaL_Buffer b;\n    cc[0] = '%'; cc[2] = '\\0';\n    luaL_buffinit(L, &b);\n    for (; *s; s++) {\n      if (*s != '%' || *(s + 1) == '\\0')  /* no conversion specifier? */\n        luaL_addchar(&b, *s);\n      else {\n        size_t reslen;\n        char buff[200];  /* should be big enough for any conversion result */\n        cc[1] = *(++s);\n        reslen = strftime(buff, sizeof(buff), cc, stm);\n        luaL_addlstring(&b, buff, reslen);\n      }\n    }\n    luaL_pushresult(&b);\n  }\n  return 1;\n}\n\n\nstatic int os_time (lua_State *L) {\n  time_t t;\n  if (lua_isnoneornil(L, 1))  /* called without args? */\n    t = time(NULL);  /* get current time */\n  else {\n    struct tm ts;\n    luaL_checktype(L, 1, LUA_TTABLE);\n    lua_settop(L, 1);  /* make sure table is at the top */\n    ts.tm_sec = getfield(L, \"sec\", 0);\n    ts.tm_min = getfield(L, \"min\", 0);\n    ts.tm_hour = getfield(L, \"hour\", 12);\n    ts.tm_mday = getfield(L, \"day\", -1);\n    ts.tm_mon = getfield(L, \"month\", -1) - 1;\n    ts.tm_year = getfield(L, \"year\", -1) - 1900;\n    ts.tm_isdst = getboolfield(L, \"isdst\");\n    t = mktime(&ts);\n  }\n  if (t == (time_t)(-1))\n    lua_pushnil(L);\n  else\n    lua_pushnumber(L, (lua_Number)t);\n  return 1;\n}\n\n\nstatic int os_difftime (lua_State *L) {\n  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),\n                             (time_t)(luaL_optnumber(L, 2, 0))));\n  return 1;\n}\n\n/* }====================================================== */\n\n\nstatic int os_setlocale (lua_State *L) {\n  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,\n                      LC_NUMERIC, LC_TIME};\n  static const char *const catnames[] = {\"all\", \"collate\", \"ctype\", \"monetary\",\n     \"numeric\", \"time\", NULL};\n  const char *l = luaL_optstring(L, 1, NULL);\n  int op = luaL_checkoption(L, 2, \"all\", catnames);\n  lua_pushstring(L, setlocale(cat[op], l));\n  return 1;\n}\n\n\nstatic int os_exit (lua_State *L) {\n  exit(luaL_optint(L, 1, EXIT_SUCCESS));\n}\n\nstatic const luaL_Reg syslib[] = {\n  {\"clock\",     os_clock},\n  {\"date\",      os_date},\n  {\"difftime\",  os_difftime},\n  {\"execute\",   os_execute},\n  {\"exit\",      os_exit},\n  {\"getenv\",    os_getenv},\n  {\"remove\",    os_remove},\n  {\"rename\",    os_rename},\n  {\"setlocale\", os_setlocale},\n  {\"time\",      os_time},\n  {\"tmpname\",   os_tmpname},\n  {NULL, NULL}\n};\n\n/* }====================================================== */\n\n\n\nLUALIB_API int luaopen_os (lua_State *L) {\n  luaL_register(L, LUA_OSLIBNAME, syslib);\n  return 1;\n}\n\n"
  },
  {
    "path": "src/lparser.c",
    "content": "/*\n** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define lparser_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lcode.h\"\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lparser.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n\n\n\n#define hasmultret(k)\t\t((k) == VCALL || (k) == VVARARG)\n\n#define getlocvar(fs, i)\t((fs)->f->locvars[(fs)->actvar[i]])\n\n#define luaY_checklimit(fs,v,l,m)\tif ((v)>(l)) errorlimit(fs,l,m)\n\n\n/*\n** nodes for block list (list of active blocks)\n*/\ntypedef struct BlockCnt {\n  struct BlockCnt *previous;  /* chain */\n  int breaklist;  /* list of jumps out of this loop */\n  lu_byte nactvar;  /* # active locals outside the breakable structure */\n  lu_byte upval;  /* true if some variable in the block is an upvalue */\n  lu_byte isbreakable;  /* true if `block' is a loop */\n} BlockCnt;\n\n\n\n/*\n** prototypes for recursive non-terminal functions\n*/\nstatic void chunk (LexState *ls);\nstatic void expr (LexState *ls, expdesc *v);\n\n\nstatic void anchor_token (LexState *ls) {\n  if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {\n    TString *ts = ls->t.seminfo.ts;\n    luaX_newstring(ls, getstr(ts), ts->tsv.len);\n  }\n}\n\n\nstatic void error_expected (LexState *ls, int token) {\n  luaX_syntaxerror(ls,\n      luaO_pushfstring(ls->L, LUA_QS \" expected\", luaX_token2str(ls, token)));\n}\n\n\nstatic void errorlimit (FuncState *fs, int limit, const char *what) {\n  const char *msg = (fs->f->linedefined == 0) ?\n    luaO_pushfstring(fs->L, \"main function has more than %d %s\", limit, what) :\n    luaO_pushfstring(fs->L, \"function at line %d has more than %d %s\",\n                            fs->f->linedefined, limit, what);\n  luaX_lexerror(fs->ls, msg, 0);\n}\n\n\nstatic int testnext (LexState *ls, int c) {\n  if (ls->t.token == c) {\n    luaX_next(ls);\n    return 1;\n  }\n  else return 0;\n}\n\n\nstatic void check (LexState *ls, int c) {\n  if (ls->t.token != c)\n    error_expected(ls, c);\n}\n\nstatic void checknext (LexState *ls, int c) {\n  check(ls, c);\n  luaX_next(ls);\n}\n\n\n#define check_condition(ls,c,msg)\t{ if (!(c)) luaX_syntaxerror(ls, msg); }\n\n\n\nstatic void check_match (LexState *ls, int what, int who, int where) {\n  if (!testnext(ls, what)) {\n    if (where == ls->linenumber)\n      error_expected(ls, what);\n    else {\n      luaX_syntaxerror(ls, luaO_pushfstring(ls->L,\n             LUA_QS \" expected (to close \" LUA_QS \" at line %d)\",\n              luaX_token2str(ls, what), luaX_token2str(ls, who), where));\n    }\n  }\n}\n\n\nstatic TString *str_checkname (LexState *ls) {\n  TString *ts;\n  check(ls, TK_NAME);\n  ts = ls->t.seminfo.ts;\n  luaX_next(ls);\n  return ts;\n}\n\n\nstatic void init_exp (expdesc *e, expkind k, int i) {\n  e->f = e->t = NO_JUMP;\n  e->k = k;\n  e->u.s.info = i;\n}\n\n\nstatic void codestring (LexState *ls, expdesc *e, TString *s) {\n  init_exp(e, VK, luaK_stringK(ls->fs, s));\n}\n\n\nstatic void checkname(LexState *ls, expdesc *e) {\n  codestring(ls, e, str_checkname(ls));\n}\n\n\nstatic int registerlocalvar (LexState *ls, TString *varname) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizelocvars;\n  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,\n                  LocVar, SHRT_MAX, \"too many local variables\");\n  while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;\n  f->locvars[fs->nlocvars].varname = varname;\n  luaC_objbarrier(ls->L, f, varname);\n  return fs->nlocvars++;\n}\n\n\n#define new_localvarliteral(ls,v,n) \\\n  new_localvar(ls, luaX_newstring(ls, \"\" v, (sizeof(v)/sizeof(char))-1), n)\n\n\nstatic void new_localvar (LexState *ls, TString *name, int n) {\n  FuncState *fs = ls->fs;\n  luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, \"local variables\");\n  fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));\n}\n\n\nstatic void adjustlocalvars (LexState *ls, int nvars) {\n  FuncState *fs = ls->fs;\n  fs->nactvar = cast_byte(fs->nactvar + nvars);\n  for (; nvars; nvars--) {\n    getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc;\n  }\n}\n\n\nstatic void removevars (LexState *ls, int tolevel) {\n  FuncState *fs = ls->fs;\n  while (fs->nactvar > tolevel)\n    getlocvar(fs, --fs->nactvar).endpc = fs->pc;\n}\n\n\nstatic int indexupvalue (FuncState *fs, TString *name, expdesc *v) {\n  int i;\n  Proto *f = fs->f;\n  int oldsize = f->sizeupvalues;\n  for (i=0; i<f->nups; i++) {\n    if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {\n      lua_assert(f->upvalues[i] == name);\n      return i;\n    }\n  }\n  /* new one */\n  luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, \"upvalues\");\n  luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues,\n                  TString *, MAX_INT, \"\");\n  while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;\n  f->upvalues[f->nups] = name;\n  luaC_objbarrier(fs->L, f, name);\n  lua_assert(v->k == VLOCAL || v->k == VUPVAL);\n  fs->upvalues[f->nups].k = cast_byte(v->k);\n  fs->upvalues[f->nups].info = cast_byte(v->u.s.info);\n  return f->nups++;\n}\n\n\nstatic int searchvar (FuncState *fs, TString *n) {\n  int i;\n  for (i=fs->nactvar-1; i >= 0; i--) {\n    if (n == getlocvar(fs, i).varname)\n      return i;\n  }\n  return -1;  /* not found */\n}\n\n\nstatic void markupval (FuncState *fs, int level) {\n  BlockCnt *bl = fs->bl;\n  while (bl && bl->nactvar > level) bl = bl->previous;\n  if (bl) bl->upval = 1;\n}\n\n\nstatic int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {\n  if (fs == NULL) {  /* no more levels? */\n    init_exp(var, VGLOBAL, NO_REG);  /* default is global variable */\n    return VGLOBAL;\n  }\n  else {\n    int v = searchvar(fs, n);  /* look up at current level */\n    if (v >= 0) {\n      init_exp(var, VLOCAL, v);\n      if (!base)\n        markupval(fs, v);  /* local will be used as an upval */\n      return VLOCAL;\n    }\n    else {  /* not found at current level; try upper one */\n      if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL)\n        return VGLOBAL;\n      var->u.s.info = indexupvalue(fs, n, var);  /* else was LOCAL or UPVAL */\n      var->k = VUPVAL;  /* upvalue in this level */\n      return VUPVAL;\n    }\n  }\n}\n\n\nstatic void singlevar (LexState *ls, expdesc *var) {\n  TString *varname = str_checkname(ls);\n  FuncState *fs = ls->fs;\n  if (singlevaraux(fs, varname, var, 1) == VGLOBAL)\n    var->u.s.info = luaK_stringK(fs, varname);  /* info points to global name */\n}\n\n\nstatic void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {\n  FuncState *fs = ls->fs;\n  int extra = nvars - nexps;\n  if (hasmultret(e->k)) {\n    extra++;  /* includes call itself */\n    if (extra < 0) extra = 0;\n    luaK_setreturns(fs, e, extra);  /* last exp. provides the difference */\n    if (extra > 1) luaK_reserveregs(fs, extra-1);\n  }\n  else {\n    if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */\n    if (extra > 0) {\n      int reg = fs->freereg;\n      luaK_reserveregs(fs, extra);\n      luaK_nil(fs, reg, extra);\n    }\n  }\n}\n\n\nstatic void enterlevel (LexState *ls) {\n  if (++ls->L->nCcalls > LUAI_MAXCCALLS)\n\tluaX_lexerror(ls, \"chunk has too many syntax levels\", 0);\n}\n\n\n#define leavelevel(ls)\t((ls)->L->nCcalls--)\n\n\nstatic void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) {\n  bl->breaklist = NO_JUMP;\n  bl->isbreakable = isbreakable;\n  bl->nactvar = fs->nactvar;\n  bl->upval = 0;\n  bl->previous = fs->bl;\n  fs->bl = bl;\n  lua_assert(fs->freereg == fs->nactvar);\n}\n\n\nstatic void leaveblock (FuncState *fs) {\n  BlockCnt *bl = fs->bl;\n  fs->bl = bl->previous;\n  removevars(fs->ls, bl->nactvar);\n  if (bl->upval)\n    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);\n  /* a block either controls scope or breaks (never both) */\n  lua_assert(!bl->isbreakable || !bl->upval);\n  lua_assert(bl->nactvar == fs->nactvar);\n  fs->freereg = fs->nactvar;  /* free registers */\n  luaK_patchtohere(fs, bl->breaklist);\n}\n\n\nstatic void pushclosure (LexState *ls, FuncState *func, expdesc *v) {\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int oldsize = f->sizep;\n  int i;\n  luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,\n                  MAXARG_Bx, \"constant table overflow\");\n  while (oldsize < f->sizep) f->p[oldsize++] = NULL;\n  f->p[fs->np++] = func->f;\n  luaC_objbarrier(ls->L, f, func->f);\n  init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));\n  for (i=0; i<func->f->nups; i++) {\n    OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;\n    luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0);\n  }\n}\n\n\nstatic void open_func (LexState *ls, FuncState *fs) {\n  lua_State *L = ls->L;\n  Proto *f = luaF_newproto(L);\n  fs->f = f;\n  fs->prev = ls->fs;  /* linked list of funcstates */\n  fs->ls = ls;\n  fs->L = L;\n  ls->fs = fs;\n  fs->pc = 0;\n  fs->lasttarget = -1;\n  fs->jpc = NO_JUMP;\n  fs->freereg = 0;\n  fs->nk = 0;\n  fs->np = 0;\n  fs->nlocvars = 0;\n  fs->nactvar = 0;\n  fs->bl = NULL;\n  f->source = ls->source;\n  f->maxstacksize = 2;  /* registers 0/1 are always valid */\n  fs->h = luaH_new(L, 0, 0);\n  /* anchor table of constants and prototype (to avoid being collected) */\n  sethvalue2s(L, L->top, fs->h);\n  incr_top(L);\n  setptvalue2s(L, L->top, f);\n  incr_top(L);\n}\n\n\nstatic void close_func (LexState *ls) {\n  lua_State *L = ls->L;\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  removevars(ls, 0);\n  luaK_ret(fs, 0, 0);  /* final return */\n  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);\n  f->sizecode = fs->pc;\n  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);\n  f->sizelineinfo = fs->pc;\n  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);\n  f->sizek = fs->nk;\n  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);\n  f->sizep = fs->np;\n  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);\n  f->sizelocvars = fs->nlocvars;\n  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);\n  f->sizeupvalues = f->nups;\n  lua_assert(luaG_checkcode(f));\n  lua_assert(fs->bl == NULL);\n  ls->fs = fs->prev;\n  L->top -= 2;  /* remove table and prototype from the stack */\n  /* last token read was anchored in defunct function; must reanchor it */\n  if (fs) anchor_token(ls);\n}\n\n\nProto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {\n  struct LexState lexstate;\n  struct FuncState funcstate;\n  lexstate.buff = buff;\n  luaX_setinput(L, &lexstate, z, luaS_new(L, name));\n  open_func(&lexstate, &funcstate);\n  funcstate.f->is_vararg = VARARG_ISVARARG;  /* main func. is always vararg */\n  luaX_next(&lexstate);  /* read first token */\n  chunk(&lexstate);\n  check(&lexstate, TK_EOS);\n  close_func(&lexstate);\n  lua_assert(funcstate.prev == NULL);\n  lua_assert(funcstate.f->nups == 0);\n  lua_assert(lexstate.fs == NULL);\n  return funcstate.f;\n}\n\n\n\n/*============================================================*/\n/* GRAMMAR RULES */\n/*============================================================*/\n\n\nstatic void field (LexState *ls, expdesc *v) {\n  /* field -> ['.' | ':'] NAME */\n  FuncState *fs = ls->fs;\n  expdesc key;\n  luaK_exp2anyreg(fs, v);\n  luaX_next(ls);  /* skip the dot or colon */\n  checkname(ls, &key);\n  luaK_indexed(fs, v, &key);\n}\n\n\nstatic void yindex (LexState *ls, expdesc *v) {\n  /* index -> '[' expr ']' */\n  luaX_next(ls);  /* skip the '[' */\n  expr(ls, v);\n  luaK_exp2val(ls->fs, v);\n  checknext(ls, ']');\n}\n\n\n/*\n** {======================================================================\n** Rules for Constructors\n** =======================================================================\n*/\n\n\nstruct ConsControl {\n  expdesc v;  /* last list item read */\n  expdesc *t;  /* table descriptor */\n  int nh;  /* total number of `record' elements */\n  int na;  /* total number of array elements */\n  int tostore;  /* number of array elements pending to be stored */\n};\n\n\nstatic void recfield (LexState *ls, struct ConsControl *cc) {\n  /* recfield -> (NAME | `['exp1`]') = exp1 */\n  FuncState *fs = ls->fs;\n  int reg = ls->fs->freereg;\n  expdesc key, val;\n  int rkkey;\n  if (ls->t.token == TK_NAME) {\n    luaY_checklimit(fs, cc->nh, MAX_INT, \"items in a constructor\");\n    checkname(ls, &key);\n  }\n  else  /* ls->t.token == '[' */\n    yindex(ls, &key);\n  cc->nh++;\n  checknext(ls, '=');\n  rkkey = luaK_exp2RK(fs, &key);\n  expr(ls, &val);\n  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val));\n  fs->freereg = reg;  /* free registers */\n}\n\n\nstatic void closelistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->v.k == VVOID) return;  /* there is no list item */\n  luaK_exp2nextreg(fs, &cc->v);\n  cc->v.k = VVOID;\n  if (cc->tostore == LFIELDS_PER_FLUSH) {\n    luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);  /* flush */\n    cc->tostore = 0;  /* no more items pending */\n  }\n}\n\n\nstatic void lastlistfield (FuncState *fs, struct ConsControl *cc) {\n  if (cc->tostore == 0) return;\n  if (hasmultret(cc->v.k)) {\n    luaK_setmultret(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET);\n    cc->na--;  /* do not count last expression (unknown number of elements) */\n  }\n  else {\n    if (cc->v.k != VVOID)\n      luaK_exp2nextreg(fs, &cc->v);\n    luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore);\n  }\n}\n\n\nstatic void listfield (LexState *ls, struct ConsControl *cc) {\n  expr(ls, &cc->v);\n  luaY_checklimit(ls->fs, cc->na, MAX_INT, \"items in a constructor\");\n  cc->na++;\n  cc->tostore++;\n}\n\n\nstatic void constructor (LexState *ls, expdesc *t) {\n  /* constructor -> ?? */\n  FuncState *fs = ls->fs;\n  int line = ls->linenumber;\n  int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);\n  struct ConsControl cc;\n  cc.na = cc.nh = cc.tostore = 0;\n  cc.t = t;\n  init_exp(t, VRELOCABLE, pc);\n  init_exp(&cc.v, VVOID, 0);  /* no value (yet) */\n  luaK_exp2nextreg(ls->fs, t);  /* fix it at stack top (for gc) */\n  checknext(ls, '{');\n  do {\n    lua_assert(cc.v.k == VVOID || cc.tostore > 0);\n    if (ls->t.token == '}') break;\n    closelistfield(fs, &cc);\n    switch(ls->t.token) {\n      case TK_NAME: {  /* may be listfields or recfields */\n        luaX_lookahead(ls);\n        if (ls->lookahead.token != '=')  /* expression? */\n          listfield(ls, &cc);\n        else\n          recfield(ls, &cc);\n        break;\n      }\n      case '[': {  /* constructor_item -> recfield */\n        recfield(ls, &cc);\n        break;\n      }\n      default: {  /* constructor_part -> listfield */\n        listfield(ls, &cc);\n        break;\n      }\n    }\n  } while (testnext(ls, ',') || testnext(ls, ';'));\n  check_match(ls, '}', '{', line);\n  lastlistfield(fs, &cc);\n  SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */\n  SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh));  /* set initial table size */\n}\n\n/* }====================================================================== */\n\n\n\nstatic void parlist (LexState *ls) {\n  /* parlist -> [ param { `,' param } ] */\n  FuncState *fs = ls->fs;\n  Proto *f = fs->f;\n  int nparams = 0;\n  f->is_vararg = 0;\n  if (ls->t.token != ')') {  /* is `parlist' not empty? */\n    do {\n      switch (ls->t.token) {\n        case TK_NAME: {  /* param -> NAME */\n          new_localvar(ls, str_checkname(ls), nparams++);\n          break;\n        }\n        case TK_DOTS: {  /* param -> `...' */\n          luaX_next(ls);\n#if defined(LUA_COMPAT_VARARG)\n          /* use `arg' as default name */\n          new_localvarliteral(ls, \"arg\", nparams++);\n          f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG;\n#endif\n          f->is_vararg |= VARARG_ISVARARG;\n          break;\n        }\n        default: luaX_syntaxerror(ls, \"<name> or \" LUA_QL(\"...\") \" expected\");\n      }\n    } while (!f->is_vararg && testnext(ls, ','));\n  }\n  adjustlocalvars(ls, nparams);\n  f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));\n  luaK_reserveregs(fs, fs->nactvar);  /* reserve register for parameters */\n}\n\n\nstatic void body (LexState *ls, expdesc *e, int needself, int line) {\n  /* body ->  `(' parlist `)' chunk END */\n  FuncState new_fs;\n  open_func(ls, &new_fs);\n  new_fs.f->linedefined = line;\n  checknext(ls, '(');\n  if (needself) {\n    new_localvarliteral(ls, \"self\", 0);\n    adjustlocalvars(ls, 1);\n  }\n  parlist(ls);\n  checknext(ls, ')');\n  chunk(ls);\n  new_fs.f->lastlinedefined = ls->linenumber;\n  check_match(ls, TK_END, TK_FUNCTION, line);\n  close_func(ls);\n  pushclosure(ls, &new_fs, e);\n}\n\n\nstatic int explist1 (LexState *ls, expdesc *v) {\n  /* explist1 -> expr { `,' expr } */\n  int n = 1;  /* at least one expression */\n  expr(ls, v);\n  while (testnext(ls, ',')) {\n    luaK_exp2nextreg(ls->fs, v);\n    expr(ls, v);\n    n++;\n  }\n  return n;\n}\n\n\nstatic void funcargs (LexState *ls, expdesc *f) {\n  FuncState *fs = ls->fs;\n  expdesc args;\n  int base, nparams;\n  int line = ls->linenumber;\n  switch (ls->t.token) {\n    case '(': {  /* funcargs -> `(' [ explist1 ] `)' */\n      if (line != ls->lastline)\n        luaX_syntaxerror(ls,\"ambiguous syntax (function call x new statement)\");\n      luaX_next(ls);\n      if (ls->t.token == ')')  /* arg list is empty? */\n        args.k = VVOID;\n      else {\n        explist1(ls, &args);\n        luaK_setmultret(fs, &args);\n      }\n      check_match(ls, ')', '(', line);\n      break;\n    }\n    case '{': {  /* funcargs -> constructor */\n      constructor(ls, &args);\n      break;\n    }\n    case TK_STRING: {  /* funcargs -> STRING */\n      codestring(ls, &args, ls->t.seminfo.ts);\n      luaX_next(ls);  /* must use `seminfo' before `next' */\n      break;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"function arguments expected\");\n      return;\n    }\n  }\n  lua_assert(f->k == VNONRELOC);\n  base = f->u.s.info;  /* base register for call */\n  if (hasmultret(args.k))\n    nparams = LUA_MULTRET;  /* open call */\n  else {\n    if (args.k != VVOID)\n      luaK_exp2nextreg(fs, &args);  /* close last argument */\n    nparams = fs->freereg - (base+1);\n  }\n  init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));\n  luaK_fixline(fs, line);\n  fs->freereg = base+1;  /* call remove function and arguments and leaves\n                            (unless changed) one result */\n}\n\n\n\n\n/*\n** {======================================================================\n** Expression parsing\n** =======================================================================\n*/\n\n\nstatic void prefixexp (LexState *ls, expdesc *v) {\n  /* prefixexp -> NAME | '(' expr ')' */\n  switch (ls->t.token) {\n    case '(': {\n      int line = ls->linenumber;\n      luaX_next(ls);\n      expr(ls, v);\n      check_match(ls, ')', '(', line);\n      luaK_dischargevars(ls->fs, v);\n      return;\n    }\n    case TK_NAME: {\n      singlevar(ls, v);\n      return;\n    }\n    default: {\n      luaX_syntaxerror(ls, \"unexpected symbol\");\n      return;\n    }\n  }\n}\n\n\nstatic void primaryexp (LexState *ls, expdesc *v) {\n  /* primaryexp ->\n        prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */\n  FuncState *fs = ls->fs;\n  prefixexp(ls, v);\n  for (;;) {\n    switch (ls->t.token) {\n      case '.': {  /* field */\n        field(ls, v);\n        break;\n      }\n      case '[': {  /* `[' exp1 `]' */\n        expdesc key;\n        luaK_exp2anyreg(fs, v);\n        yindex(ls, &key);\n        luaK_indexed(fs, v, &key);\n        break;\n      }\n      case ':': {  /* `:' NAME funcargs */\n        expdesc key;\n        luaX_next(ls);\n        checkname(ls, &key);\n        luaK_self(fs, v, &key);\n        funcargs(ls, v);\n        break;\n      }\n      case '(': case TK_STRING: case '{': {  /* funcargs */\n        luaK_exp2nextreg(fs, v);\n        funcargs(ls, v);\n        break;\n      }\n      default: return;\n    }\n  }\n}\n\n\nstatic void simpleexp (LexState *ls, expdesc *v) {\n  /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |\n                  constructor | FUNCTION body | primaryexp */\n  switch (ls->t.token) {\n    case TK_NUMBER: {\n      init_exp(v, VKNUM, 0);\n      v->u.nval = ls->t.seminfo.r;\n      break;\n    }\n    case TK_STRING: {\n      codestring(ls, v, ls->t.seminfo.ts);\n      break;\n    }\n    case TK_NIL: {\n      init_exp(v, VNIL, 0);\n      break;\n    }\n    case TK_TRUE: {\n      init_exp(v, VTRUE, 0);\n      break;\n    }\n    case TK_FALSE: {\n      init_exp(v, VFALSE, 0);\n      break;\n    }\n    case TK_DOTS: {  /* vararg */\n      FuncState *fs = ls->fs;\n      check_condition(ls, fs->f->is_vararg,\n                      \"cannot use \" LUA_QL(\"...\") \" outside a vararg function\");\n      fs->f->is_vararg &= ~VARARG_NEEDSARG;  /* don't need 'arg' */\n      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));\n      break;\n    }\n    case '{': {  /* constructor */\n      constructor(ls, v);\n      return;\n    }\n    case TK_FUNCTION: {\n      luaX_next(ls);\n      body(ls, v, 0, ls->linenumber);\n      return;\n    }\n    default: {\n      primaryexp(ls, v);\n      return;\n    }\n  }\n  luaX_next(ls);\n}\n\n\nstatic UnOpr getunopr (int op) {\n  switch (op) {\n    case TK_NOT: return OPR_NOT;\n    case '-': return OPR_MINUS;\n    case '#': return OPR_LEN;\n    default: return OPR_NOUNOPR;\n  }\n}\n\n\nstatic BinOpr getbinopr (int op) {\n  switch (op) {\n    case '+': return OPR_ADD;\n    case '-': return OPR_SUB;\n    case '*': return OPR_MUL;\n    case '/': return OPR_DIV;\n    case '%': return OPR_MOD;\n    case '^': return OPR_POW;\n    case TK_CONCAT: return OPR_CONCAT;\n    case TK_NE: return OPR_NE;\n    case TK_EQ: return OPR_EQ;\n    case '<': return OPR_LT;\n    case TK_LE: return OPR_LE;\n    case '>': return OPR_GT;\n    case TK_GE: return OPR_GE;\n    case TK_AND: return OPR_AND;\n    case TK_OR: return OPR_OR;\n    default: return OPR_NOBINOPR;\n  }\n}\n\n\nstatic const struct {\n  lu_byte left;  /* left priority for each binary operator */\n  lu_byte right; /* right priority */\n} priority[] = {  /* ORDER OPR */\n   {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},  /* `+' `-' `/' `%' */\n   {10, 9}, {5, 4},                 /* power and concat (right associative) */\n   {3, 3}, {3, 3},                  /* equality and inequality */\n   {3, 3}, {3, 3}, {3, 3}, {3, 3},  /* order */\n   {2, 2}, {1, 1}                   /* logical (and/or) */\n};\n\n#define UNARY_PRIORITY\t8  /* priority for unary operators */\n\n\n/*\n** subexpr -> (simpleexp | unop subexpr) { binop subexpr }\n** where `binop' is any binary operator with a priority higher than `limit'\n*/\nstatic BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {\n  BinOpr op;\n  UnOpr uop;\n  enterlevel(ls);\n  uop = getunopr(ls->t.token);\n  if (uop != OPR_NOUNOPR) {\n    luaX_next(ls);\n    subexpr(ls, v, UNARY_PRIORITY);\n    luaK_prefix(ls->fs, uop, v);\n  }\n  else simpleexp(ls, v);\n  /* expand while operators have priorities higher than `limit' */\n  op = getbinopr(ls->t.token);\n  while (op != OPR_NOBINOPR && priority[op].left > limit) {\n    expdesc v2;\n    BinOpr nextop;\n    luaX_next(ls);\n    luaK_infix(ls->fs, op, v);\n    /* read sub-expression with higher priority */\n    nextop = subexpr(ls, &v2, priority[op].right);\n    luaK_posfix(ls->fs, op, v, &v2);\n    op = nextop;\n  }\n  leavelevel(ls);\n  return op;  /* return first untreated operator */\n}\n\n\nstatic void expr (LexState *ls, expdesc *v) {\n  subexpr(ls, v, 0);\n}\n\n/* }==================================================================== */\n\n\n\n/*\n** {======================================================================\n** Rules for Statements\n** =======================================================================\n*/\n\n\nstatic int block_follow (int token) {\n  switch (token) {\n    case TK_ELSE: case TK_ELSEIF: case TK_END:\n    case TK_UNTIL: case TK_EOS:\n      return 1;\n    default: return 0;\n  }\n}\n\n\nstatic void block (LexState *ls) {\n  /* block -> chunk */\n  FuncState *fs = ls->fs;\n  BlockCnt bl;\n  enterblock(fs, &bl, 0);\n  chunk(ls);\n  lua_assert(bl.breaklist == NO_JUMP);\n  leaveblock(fs);\n}\n\n\n/*\n** structure to chain all variables in the left-hand side of an\n** assignment\n*/\nstruct LHS_assign {\n  struct LHS_assign *prev;\n  expdesc v;  /* variable (global, local, upvalue, or indexed) */\n};\n\n\n/*\n** check whether, in an assignment to a local variable, the local variable\n** is needed in a previous assignment (to a table). If so, save original\n** local value in a safe place and use this safe copy in the previous\n** assignment.\n*/\nstatic void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {\n  FuncState *fs = ls->fs;\n  int extra = fs->freereg;  /* eventual position to save local variable */\n  int conflict = 0;\n  for (; lh; lh = lh->prev) {\n    if (lh->v.k == VINDEXED) {\n      if (lh->v.u.s.info == v->u.s.info) {  /* conflict? */\n        conflict = 1;\n        lh->v.u.s.info = extra;  /* previous assignment will use safe copy */\n      }\n      if (lh->v.u.s.aux == v->u.s.info) {  /* conflict? */\n        conflict = 1;\n        lh->v.u.s.aux = extra;  /* previous assignment will use safe copy */\n      }\n    }\n  }\n  if (conflict) {\n    luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0);  /* make copy */\n    luaK_reserveregs(fs, 1);\n  }\n}\n\n\nstatic void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {\n  expdesc e;\n  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,\n                      \"syntax error\");\n  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */\n    struct LHS_assign nv;\n    nv.prev = lh;\n    primaryexp(ls, &nv.v);\n    if (nv.v.k == VLOCAL)\n      check_conflict(ls, lh, &nv.v);\n    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,\n                    \"variables in assignment\");\n    assignment(ls, &nv, nvars+1);\n  }\n  else {  /* assignment -> `=' explist1 */\n    int nexps;\n    checknext(ls, '=');\n    nexps = explist1(ls, &e);\n    if (nexps != nvars) {\n      adjust_assign(ls, nvars, nexps, &e);\n      if (nexps > nvars)\n        ls->fs->freereg -= nexps - nvars;  /* remove extra values */\n    }\n    else {\n      luaK_setoneret(ls->fs, &e);  /* close last expression */\n      luaK_storevar(ls->fs, &lh->v, &e);\n      return;  /* avoid default */\n    }\n  }\n  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */\n  luaK_storevar(ls->fs, &lh->v, &e);\n}\n\n\nstatic int cond (LexState *ls) {\n  /* cond -> exp */\n  expdesc v;\n  expr(ls, &v);  /* read condition */\n  if (v.k == VNIL) v.k = VFALSE;  /* `falses' are all equal here */\n  luaK_goiftrue(ls->fs, &v);\n  return v.f;\n}\n\n\nstatic void breakstat (LexState *ls) {\n  FuncState *fs = ls->fs;\n  BlockCnt *bl = fs->bl;\n  int upval = 0;\n  while (bl && !bl->isbreakable) {\n    upval |= bl->upval;\n    bl = bl->previous;\n  }\n  if (!bl)\n    luaX_syntaxerror(ls, \"no loop to break\");\n  if (upval)\n    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);\n  luaK_concat(fs, &bl->breaklist, luaK_jump(fs));\n}\n\n\nstatic void whilestat (LexState *ls, int line) {\n  /* whilestat -> WHILE cond DO block END */\n  FuncState *fs = ls->fs;\n  int whileinit;\n  int condexit;\n  BlockCnt bl;\n  luaX_next(ls);  /* skip WHILE */\n  whileinit = luaK_getlabel(fs);\n  condexit = cond(ls);\n  enterblock(fs, &bl, 1);\n  checknext(ls, TK_DO);\n  block(ls);\n  luaK_patchlist(fs, luaK_jump(fs), whileinit);\n  check_match(ls, TK_END, TK_WHILE, line);\n  leaveblock(fs);\n  luaK_patchtohere(fs, condexit);  /* false conditions finish the loop */\n}\n\n\nstatic void repeatstat (LexState *ls, int line) {\n  /* repeatstat -> REPEAT block UNTIL cond */\n  int condexit;\n  FuncState *fs = ls->fs;\n  int repeat_init = luaK_getlabel(fs);\n  BlockCnt bl1, bl2;\n  enterblock(fs, &bl1, 1);  /* loop block */\n  enterblock(fs, &bl2, 0);  /* scope block */\n  luaX_next(ls);  /* skip REPEAT */\n  chunk(ls);\n  check_match(ls, TK_UNTIL, TK_REPEAT, line);\n  condexit = cond(ls);  /* read condition (inside scope block) */\n  if (!bl2.upval) {  /* no upvalues? */\n    leaveblock(fs);  /* finish scope */\n    luaK_patchlist(ls->fs, condexit, repeat_init);  /* close the loop */\n  }\n  else {  /* complete semantics when there are upvalues */\n    breakstat(ls);  /* if condition then break */\n    luaK_patchtohere(ls->fs, condexit);  /* else... */\n    leaveblock(fs);  /* finish scope... */\n    luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init);  /* and repeat */\n  }\n  leaveblock(fs);  /* finish loop */\n}\n\n\nstatic int exp1 (LexState *ls) {\n  expdesc e;\n  int k;\n  expr(ls, &e);\n  k = e.k;\n  luaK_exp2nextreg(ls->fs, &e);\n  return k;\n}\n\n\nstatic void forbody (LexState *ls, int base, int line, int nvars, int isnum) {\n  /* forbody -> DO block */\n  BlockCnt bl;\n  FuncState *fs = ls->fs;\n  int prep, endfor;\n  adjustlocalvars(ls, 3);  /* control variables */\n  checknext(ls, TK_DO);\n  prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);\n  enterblock(fs, &bl, 0);  /* scope for declared variables */\n  adjustlocalvars(ls, nvars);\n  luaK_reserveregs(fs, nvars);\n  block(ls);\n  leaveblock(fs);  /* end of scope for declared variables */\n  luaK_patchtohere(fs, prep);\n  endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) :\n                     luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);\n  luaK_fixline(fs, line);  /* pretend that `OP_FOR' starts the loop */\n  luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1);\n}\n\n\nstatic void fornum (LexState *ls, TString *varname, int line) {\n  /* fornum -> NAME = exp1,exp1[,exp1] forbody */\n  FuncState *fs = ls->fs;\n  int base = fs->freereg;\n  new_localvarliteral(ls, \"(for index)\", 0);\n  new_localvarliteral(ls, \"(for limit)\", 1);\n  new_localvarliteral(ls, \"(for step)\", 2);\n  new_localvar(ls, varname, 3);\n  checknext(ls, '=');\n  exp1(ls);  /* initial value */\n  checknext(ls, ',');\n  exp1(ls);  /* limit */\n  if (testnext(ls, ','))\n    exp1(ls);  /* optional step */\n  else {  /* default step = 1 */\n    luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1));\n    luaK_reserveregs(fs, 1);\n  }\n  forbody(ls, base, line, 1, 1);\n}\n\n\nstatic void forlist (LexState *ls, TString *indexname) {\n  /* forlist -> NAME {,NAME} IN explist1 forbody */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int nvars = 0;\n  int line;\n  int base = fs->freereg;\n  /* create control variables */\n  new_localvarliteral(ls, \"(for generator)\", nvars++);\n  new_localvarliteral(ls, \"(for state)\", nvars++);\n  new_localvarliteral(ls, \"(for control)\", nvars++);\n  /* create declared variables */\n  new_localvar(ls, indexname, nvars++);\n  while (testnext(ls, ','))\n    new_localvar(ls, str_checkname(ls), nvars++);\n  checknext(ls, TK_IN);\n  line = ls->linenumber;\n  adjust_assign(ls, 3, explist1(ls, &e), &e);\n  luaK_checkstack(fs, 3);  /* extra space to call generator */\n  forbody(ls, base, line, nvars - 3, 0);\n}\n\n\nstatic void forstat (LexState *ls, int line) {\n  /* forstat -> FOR (fornum | forlist) END */\n  FuncState *fs = ls->fs;\n  TString *varname;\n  BlockCnt bl;\n  enterblock(fs, &bl, 1);  /* scope for loop and control variables */\n  luaX_next(ls);  /* skip `for' */\n  varname = str_checkname(ls);  /* first variable name */\n  switch (ls->t.token) {\n    case '=': fornum(ls, varname, line); break;\n    case ',': case TK_IN: forlist(ls, varname); break;\n    default: luaX_syntaxerror(ls, LUA_QL(\"=\") \" or \" LUA_QL(\"in\") \" expected\");\n  }\n  check_match(ls, TK_END, TK_FOR, line);\n  leaveblock(fs);  /* loop scope (`break' jumps to this point) */\n}\n\n\nstatic int test_then_block (LexState *ls) {\n  /* test_then_block -> [IF | ELSEIF] cond THEN block */\n  int condexit;\n  luaX_next(ls);  /* skip IF or ELSEIF */\n  condexit = cond(ls);\n  checknext(ls, TK_THEN);\n  block(ls);  /* `then' part */\n  return condexit;\n}\n\n\nstatic void ifstat (LexState *ls, int line) {\n  /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */\n  FuncState *fs = ls->fs;\n  int flist;\n  int escapelist = NO_JUMP;\n  flist = test_then_block(ls);  /* IF cond THEN block */\n  while (ls->t.token == TK_ELSEIF) {\n    luaK_concat(fs, &escapelist, luaK_jump(fs));\n    luaK_patchtohere(fs, flist);\n    flist = test_then_block(ls);  /* ELSEIF cond THEN block */\n  }\n  if (ls->t.token == TK_ELSE) {\n    luaK_concat(fs, &escapelist, luaK_jump(fs));\n    luaK_patchtohere(fs, flist);\n    luaX_next(ls);  /* skip ELSE (after patch, for correct line info) */\n    block(ls);  /* `else' part */\n  }\n  else\n    luaK_concat(fs, &escapelist, flist);\n  luaK_patchtohere(fs, escapelist);\n  check_match(ls, TK_END, TK_IF, line);\n}\n\n\nstatic void localfunc (LexState *ls) {\n  expdesc v, b;\n  FuncState *fs = ls->fs;\n  new_localvar(ls, str_checkname(ls), 0);\n  init_exp(&v, VLOCAL, fs->freereg);\n  luaK_reserveregs(fs, 1);\n  adjustlocalvars(ls, 1);\n  body(ls, &b, 0, ls->linenumber);\n  luaK_storevar(fs, &v, &b);\n  /* debug information will only see the variable after this point! */\n  getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;\n}\n\n\nstatic void localstat (LexState *ls) {\n  /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */\n  int nvars = 0;\n  int nexps;\n  expdesc e;\n  do {\n    new_localvar(ls, str_checkname(ls), nvars++);\n  } while (testnext(ls, ','));\n  if (testnext(ls, '='))\n    nexps = explist1(ls, &e);\n  else {\n    e.k = VVOID;\n    nexps = 0;\n  }\n  adjust_assign(ls, nvars, nexps, &e);\n  adjustlocalvars(ls, nvars);\n}\n\n\nstatic int funcname (LexState *ls, expdesc *v) {\n  /* funcname -> NAME {field} [`:' NAME] */\n  int needself = 0;\n  singlevar(ls, v);\n  while (ls->t.token == '.')\n    field(ls, v);\n  if (ls->t.token == ':') {\n    needself = 1;\n    field(ls, v);\n  }\n  return needself;\n}\n\n\nstatic void funcstat (LexState *ls, int line) {\n  /* funcstat -> FUNCTION funcname body */\n  int needself;\n  expdesc v, b;\n  luaX_next(ls);  /* skip FUNCTION */\n  needself = funcname(ls, &v);\n  body(ls, &b, needself, line);\n  luaK_storevar(ls->fs, &v, &b);\n  luaK_fixline(ls->fs, line);  /* definition `happens' in the first line */\n}\n\n\nstatic void exprstat (LexState *ls) {\n  /* stat -> func | assignment */\n  FuncState *fs = ls->fs;\n  struct LHS_assign v;\n  primaryexp(ls, &v.v);\n  if (v.v.k == VCALL)  /* stat -> func */\n    SETARG_C(getcode(fs, &v.v), 1);  /* call statement uses no results */\n  else {  /* stat -> assignment */\n    v.prev = NULL;\n    assignment(ls, &v, 1);\n  }\n}\n\n\nstatic void retstat (LexState *ls) {\n  /* stat -> RETURN explist */\n  FuncState *fs = ls->fs;\n  expdesc e;\n  int first, nret;  /* registers with returned values */\n  luaX_next(ls);  /* skip RETURN */\n  if (block_follow(ls->t.token) || ls->t.token == ';')\n    first = nret = 0;  /* return no values */\n  else {\n    nret = explist1(ls, &e);  /* optional return values */\n    if (hasmultret(e.k)) {\n      luaK_setmultret(fs, &e);\n      if (e.k == VCALL && nret == 1) {  /* tail call? */\n        SET_OPCODE(getcode(fs,&e), OP_TAILCALL);\n        lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);\n      }\n      first = fs->nactvar;\n      nret = LUA_MULTRET;  /* return all values */\n    }\n    else {\n      if (nret == 1)  /* only one single value? */\n        first = luaK_exp2anyreg(fs, &e);\n      else {\n        luaK_exp2nextreg(fs, &e);  /* values must go to the `stack' */\n        first = fs->nactvar;  /* return all `active' values */\n        lua_assert(nret == fs->freereg - first);\n      }\n    }\n  }\n  luaK_ret(fs, first, nret);\n}\n\n\nstatic int statement (LexState *ls) {\n  int line = ls->linenumber;  /* may be needed for error messages */\n  switch (ls->t.token) {\n    case TK_IF: {  /* stat -> ifstat */\n      ifstat(ls, line);\n      return 0;\n    }\n    case TK_WHILE: {  /* stat -> whilestat */\n      whilestat(ls, line);\n      return 0;\n    }\n    case TK_DO: {  /* stat -> DO block END */\n      luaX_next(ls);  /* skip DO */\n      block(ls);\n      check_match(ls, TK_END, TK_DO, line);\n      return 0;\n    }\n    case TK_FOR: {  /* stat -> forstat */\n      forstat(ls, line);\n      return 0;\n    }\n    case TK_REPEAT: {  /* stat -> repeatstat */\n      repeatstat(ls, line);\n      return 0;\n    }\n    case TK_FUNCTION: {\n      funcstat(ls, line);  /* stat -> funcstat */\n      return 0;\n    }\n    case TK_LOCAL: {  /* stat -> localstat */\n      luaX_next(ls);  /* skip LOCAL */\n      if (testnext(ls, TK_FUNCTION))  /* local function? */\n        localfunc(ls);\n      else\n        localstat(ls);\n      return 0;\n    }\n    case TK_RETURN: {  /* stat -> retstat */\n      retstat(ls);\n      return 1;  /* must be last statement */\n    }\n    case TK_BREAK: {  /* stat -> breakstat */\n      luaX_next(ls);  /* skip BREAK */\n      breakstat(ls);\n      return 1;  /* must be last statement */\n    }\n    default: {\n      exprstat(ls);\n      return 0;  /* to avoid warnings */\n    }\n  }\n}\n\n\nstatic void chunk (LexState *ls) {\n  /* chunk -> { stat [`;'] } */\n  int islast = 0;\n  enterlevel(ls);\n  while (!islast && !block_follow(ls->t.token)) {\n    islast = statement(ls);\n    testnext(ls, ';');\n    lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&\n               ls->fs->freereg >= ls->fs->nactvar);\n    ls->fs->freereg = ls->fs->nactvar;  /* free registers */\n  }\n  leavelevel(ls);\n}\n\n/* }====================================================================== */\n"
  },
  {
    "path": "src/lparser.h",
    "content": "/*\n** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua Parser\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lparser_h\n#define lparser_h\n\n#include \"llimits.h\"\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n\n/*\n** Expression descriptor\n*/\n\ntypedef enum {\n  VVOID,\t/* no value */\n  VNIL,\n  VTRUE,\n  VFALSE,\n  VK,\t\t/* info = index of constant in `k' */\n  VKNUM,\t/* nval = numerical value */\n  VLOCAL,\t/* info = local register */\n  VUPVAL,       /* info = index of upvalue in `upvalues' */\n  VGLOBAL,\t/* info = index of table; aux = index of global name in `k' */\n  VINDEXED,\t/* info = table register; aux = index register (or `k') */\n  VJMP,\t\t/* info = instruction pc */\n  VRELOCABLE,\t/* info = instruction pc */\n  VNONRELOC,\t/* info = result register */\n  VCALL,\t/* info = instruction pc */\n  VVARARG\t/* info = instruction pc */\n} expkind;\n\ntypedef struct expdesc {\n  expkind k;\n  union {\n    struct { int info, aux; } s;\n    lua_Number nval;\n  } u;\n  int t;  /* patch list of `exit when true' */\n  int f;  /* patch list of `exit when false' */\n} expdesc;\n\n\ntypedef struct upvaldesc {\n  lu_byte k;\n  lu_byte info;\n} upvaldesc;\n\n\nstruct BlockCnt;  /* defined in lparser.c */\n\n\n/* state needed to generate code for a given function */\ntypedef struct FuncState {\n  Proto *f;  /* current function header */\n  Table *h;  /* table to find (and reuse) elements in `k' */\n  struct FuncState *prev;  /* enclosing function */\n  struct LexState *ls;  /* lexical state */\n  struct lua_State *L;  /* copy of the Lua state */\n  struct BlockCnt *bl;  /* chain of current blocks */\n  int pc;  /* next position to code (equivalent to `ncode') */\n  int lasttarget;   /* `pc' of last `jump target' */\n  int jpc;  /* list of pending jumps to `pc' */\n  int freereg;  /* first free register */\n  int nk;  /* number of elements in `k' */\n  int np;  /* number of elements in `p' */\n  short nlocvars;  /* number of elements in `locvars' */\n  lu_byte nactvar;  /* number of active local variables */\n  upvaldesc upvalues[LUAI_MAXUPVALUES];  /* upvalues */\n  unsigned short actvar[LUAI_MAXVARS];  /* declared-variable stack */\n} FuncState;\n\n\nLUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,\n                                            const char *name);\n\n\n#endif\n"
  },
  {
    "path": "src/lstate.c",
    "content": "/*\n** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define lstate_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"llex.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n#define state_size(x)\t(sizeof(x) + LUAI_EXTRASPACE)\n#define fromstate(l)\t(cast(lu_byte *, (l)) - LUAI_EXTRASPACE)\n#define tostate(l)   (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))\n\n\n/*\n** Main thread combines a thread state and the global state\n*/\ntypedef struct LG {\n  lua_State l;\n  global_State g;\n} LG;\n  \n\n\nstatic void stack_init (lua_State *L1, lua_State *L) {\n  /* initialize CallInfo array */\n  L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);\n  L1->ci = L1->base_ci;\n  L1->size_ci = BASIC_CI_SIZE;\n  L1->end_ci = L1->base_ci + L1->size_ci - 1;\n  /* initialize stack array */\n  L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);\n  L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;\n  L1->top = L1->stack;\n  L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;\n  /* initialize first ci */\n  L1->ci->func = L1->top;\n  setnilvalue(L1->top++);  /* `function' entry for this `ci' */\n  L1->base = L1->ci->base = L1->top;\n  L1->ci->top = L1->top + LUA_MINSTACK;\n}\n\n\nstatic void freestack (lua_State *L, lua_State *L1) {\n  luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);\n  luaM_freearray(L, L1->stack, L1->stacksize, TValue);\n}\n\n\n/*\n** open parts that may cause memory-allocation errors\n*/\nstatic void f_luaopen (lua_State *L, void *ud) {\n  global_State *g = G(L);\n  UNUSED(ud);\n  stack_init(L, L);  /* init stack */\n  sethvalue(L, gt(L), luaH_new(L, 0, 2));  /* table of globals */\n  sethvalue(L, registry(L), luaH_new(L, 0, 2));  /* registry */\n  luaS_resize(L, MINSTRTABSIZE);  /* initial size of string table */\n  luaT_init(L);\n  luaX_init(L);\n  luaS_fix(luaS_newliteral(L, MEMERRMSG));\n  g->GCthreshold = 4*g->totalbytes;\n}\n\n\nstatic void preinit_state (lua_State *L, global_State *g) {\n  G(L) = g;\n  L->stack = NULL;\n  L->stacksize = 0;\n  L->errorJmp = NULL;\n  L->hook = NULL;\n  L->hookmask = 0;\n  L->basehookcount = 0;\n  L->allowhook = 1;\n  resethookcount(L);\n  L->openupval = NULL;\n  L->size_ci = 0;\n  L->nCcalls = 0;\n  L->status = 0;\n  L->base_ci = L->ci = NULL;\n  L->savedpc = NULL;\n  L->errfunc = 0;\n  setnilvalue(gt(L));\n}\n\n\nstatic void close_state (lua_State *L) {\n  global_State *g = G(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_freeall(L);  /* collect all objects */\n  lua_assert(g->rootgc == obj2gco(L));\n  lua_assert(g->strt.nuse == 0);\n  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);\n  luaZ_freebuffer(L, &g->buff);\n  freestack(L, L);\n  lua_assert(g->totalbytes == sizeof(LG));\n  (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);\n}\n\n\nlua_State *luaE_newthread (lua_State *L) {\n  lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));\n  luaC_link(L, obj2gco(L1), LUA_TTHREAD);\n  setthvalue(L, L->top, L1); /* put thread on stack */\n  incr_top(L);\n  preinit_state(L1, G(L));\n  stack_init(L1, L);  /* init stack */\n  setobj2n(L, gt(L1), gt(L));  /* share table of globals */\n  L1->hookmask = L->hookmask;\n  L1->basehookcount = L->basehookcount;\n  L1->hook = L->hook;\n  resethookcount(L1);\n  lua_assert(!isdead(G(L), obj2gco(L1)));\n  L->top--; /* remove thread from stack */\n  return L1;\n}\n\n\nvoid luaE_freethread (lua_State *L, lua_State *L1) {\n  luaF_close(L1, L1->stack);  /* close all upvalues for this thread */\n  lua_assert(L1->openupval == NULL);\n  luai_userstatefree(L1);\n  freestack(L, L1);\n  luaM_freemem(L, fromstate(L1), state_size(lua_State));\n}\n\n\nLUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {\n  int i;\n  lua_State *L;\n  global_State *g;\n  void *l = (*f)(ud, NULL, 0, state_size(LG));\n  if (l == NULL) return NULL;\n  L = tostate(l);\n  g = &((LG *)L)->g;\n  L->next = NULL;\n  L->tt = LUA_TTHREAD;\n  g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);\n  L->marked = luaC_white(g);\n  set2bits(L->marked, FIXEDBIT, SFIXEDBIT);\n  preinit_state(L, g);\n  g->frealloc = f;\n  g->ud = ud;\n  g->mainthread = L;\n  g->uvhead.u.l.prev = &g->uvhead;\n  g->uvhead.u.l.next = &g->uvhead;\n  g->GCthreshold = 0;  /* mark it as unfinished state */\n  g->estimate = 0;\n  g->strt.size = 0;\n  g->strt.nuse = 0;\n  g->strt.hash = NULL;\n  setnilvalue(registry(L));\n  luaZ_initbuffer(L, &g->buff);\n  g->panic = NULL;\n  g->gcstate = GCSpause;\n  g->gcflags = GCFlagsNone;\n  g->rootgc = obj2gco(L);\n  g->sweepstrgc = 0;\n  g->sweepgc = &g->rootgc;\n  g->gray = NULL;\n  g->grayagain = NULL;\n  g->weak = NULL;\n  g->tmudata = NULL;\n  g->totalbytes = sizeof(LG);\n  g->memlimit = 0;\n  g->gcpause = LUAI_GCPAUSE;\n  g->gcstepmul = LUAI_GCMUL;\n  g->gcdept = 0;\n  JIT_NEW_STATE(L);\n  for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;\n  if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {\n    /* memory allocation error: free partial state */\n    close_state(L);\n    L = NULL;\n  }\n  else\n    luai_userstateopen(L);\n  return L;\n}\n\n\nstatic void callallgcTM (lua_State *L, void *ud) {\n  UNUSED(ud);\n  luaC_callGCTM(L);  /* call GC metamethods for all udata */\n}\n\n\nLUA_API void lua_close (lua_State *L) {\n  L = G(L)->mainthread;  /* only the main thread can be closed */\n  lua_lock(L);\n  luaF_close(L, L->stack);  /* close all upvalues for this thread */\n  luaC_separateudata(L, 1);  /* separate udata that have GC metamethods */\n  L->errfunc = 0;  /* no error function during GC metamethods */\n  do {  /* repeat until no more errors */\n    L->ci = L->base_ci;\n    L->base = L->top = L->ci->base;\n    L->nCcalls = 0;\n  } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);\n  lua_assert(G(L)->tmudata == NULL);\n  luai_userstateclose(L);\n  JIT_CLOSE_STATE(L);\n  close_state(L);\n}\n\n"
  },
  {
    "path": "src/lstate.h",
    "content": "/*\n** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $\n** Global State\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstate_h\n#define lstate_h\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"ltm.h\"\n#include \"lzio.h\"\n#ifndef COCO_DISABLE\n#include \"lcoco.h\"\n#endif\n\n\n\nstruct lua_longjmp;  /* defined in ldo.c */\n\n\n/* table of globals */\n#define gt(L)\t(&L->l_gt)\n\n/* registry */\n#define registry(L)\t(&G(L)->l_registry)\n\n\n/* extra stack space to handle TM calls and some other extras */\n#define EXTRA_STACK   5\n\n\n#define BASIC_CI_SIZE           8\n\n#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)\n\n\n\ntypedef struct stringtable {\n  GCObject **hash;\n  lu_int32 nuse;  /* number of elements */\n  int size;\n} stringtable;\n\n\n/*\n** informations about a call\n*/\ntypedef struct CallInfo {\n  StkId base;  /* base for this function */\n  StkId func;  /* function index in the stack */\n  StkId\ttop;  /* top for this function */\n  const Instruction *savedpc;\n  int nresults;  /* expected number of results from this function */\n  int tailcalls;  /* number of tail calls lost under this entry */\n} CallInfo;\n\n\n\n#define curr_func(L)\t(clvalue(L->ci->func))\n#define ci_func(ci)\t(clvalue((ci)->func))\n#define f_isLua(ci)\t(!ci_func(ci)->c.isC)\n#define cl_isC(cl)\t(cl->c.isC)\n#define cl_isLua(cl)\t(!cl_isC(cl))\n#define isLua(ci)\t(ttisfunction((ci)->func) && f_isLua(ci))\n\n\n/*\n** `global state', shared by all threads of this state\n*/\ntypedef struct global_State {\n  stringtable strt;  /* hash table for strings */\n  lua_Alloc frealloc;  /* function to reallocate memory */\n  void *ud;         /* auxiliary data to `frealloc' */\n  lu_byte currentwhite;\n  lu_byte gcstate;  /* state of garbage collector */\n  lu_byte gcflags;  /* flags for the garbage collector */\n  int sweepstrgc;  /* position of sweep in `strt' */\n  GCObject *rootgc;  /* list of all collectable objects */\n  GCObject **sweepgc;  /* position of sweep in `rootgc' */\n  GCObject *gray;  /* list of gray objects */\n  GCObject *grayagain;  /* list of objects to be traversed atomically */\n  GCObject *weak;  /* list of weak tables (to be cleared) */\n  GCObject *tmudata;  /* last element of list of userdata to be GC */\n  Mbuffer buff;  /* temporary buffer for string concatentation */\n  lu_mem GCthreshold;\n  lu_mem totalbytes;  /* number of bytes currently allocated */\n  lu_mem memlimit;  /* maximum number of bytes that can be allocated, 0 = no limit. */\n  lu_mem estimate;  /* an estimate of number of bytes actually in use */\n  lu_mem gcdept;  /* how much GC is `behind schedule' */\n  int gcpause;  /* size of pause between successive GCs */\n  int gcstepmul;  /* GC `granularity' */\n  lua_CFunction panic;  /* to be called in unprotected errors */\n  TValue l_registry;\n  struct lua_State *mainthread;\n  UpVal uvhead;  /* head of double-linked list of all open upvalues */\n  struct Table *mt[NUM_TAGS];  /* metatables for basic types */\n  TString *tmname[TM_N];  /* array with tag-method names */\n  JIT_COMPILER_STATE\n} global_State;\n\n\n/*\n** `per thread' state\n*/\nstruct lua_State {\n  CommonHeader;\n  lu_byte status;\n  StkId top;  /* first free slot in the stack */\n  StkId base;  /* base of current function */\n  global_State *l_G;\n  CallInfo *ci;  /* call info for current function */\n  const Instruction *savedpc;  /* `savedpc' of current function */\n  StkId stack_last;  /* last free slot in the stack */\n  StkId stack;  /* stack base */\n  CallInfo *end_ci;  /* points after end of ci array*/\n  CallInfo *base_ci;  /* array of CallInfo's */\n  int stacksize;\n  int size_ci;  /* size of array `base_ci' */\n  unsigned short nCcalls;  /* number of nested C calls */\n  lu_byte hookmask;\n  lu_byte allowhook;\n  int basehookcount;\n  int hookcount;\n  lua_Hook hook;\n  TValue l_gt;  /* table of globals */\n  TValue env;  /* temporary place for environments */\n  GCObject *openupval;  /* list of open upvalues in this stack */\n  GCObject *gclist;\n  struct lua_longjmp *errorJmp;  /* current error recover point */\n  ptrdiff_t errfunc;  /* current error handling function (stack index) */\n};\n\n\n#define G(L)\t(L->l_G)\n\n\n/*\n** Union of all collectable objects\n*/\nunion GCObject {\n  GCheader gch;\n  union TString ts;\n  union Udata u;\n  union Closure cl;\n  struct Table h;\n  struct Proto p;\n  struct UpVal uv;\n  struct lua_State th;  /* thread */\n};\n\n\n/* macros to convert a GCObject into a specific value */\n#define rawgco2ts(o)\tcheck_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))\n#define gco2ts(o)\t(&rawgco2ts(o)->tsv)\n#define rawgco2u(o)\tcheck_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))\n#define gco2u(o)\t(&rawgco2u(o)->uv)\n#define gco2cl(o)\tcheck_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))\n#define gco2h(o)\tcheck_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))\n#define gco2p(o)\tcheck_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))\n#define gco2uv(o)\tcheck_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))\n#define ngcotouv(o) \\\n\tcheck_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))\n#define gco2th(o)\tcheck_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))\n\n/* macro to convert any Lua object into a GCObject */\n#define obj2gco(v)\t(cast(GCObject *, (v)))\n\n\nLUAI_FUNC lua_State *luaE_newthread (lua_State *L);\nLUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);\n\n#endif\n\n"
  },
  {
    "path": "src/lstring.c",
    "content": "/*\n** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $\n** String table (keeps all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define lstring_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n\n\n\nvoid luaS_resize (lua_State *L, int newsize) {\n  stringtable *tb;\n  int i;\n  tb = &G(L)->strt;\n  if (G(L)->gcstate == GCSsweepstring || newsize == tb->size)\n    return;  /* cannot resize during GC traverse or doesn't need to be resized */\n  if (newsize > tb->size) {\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);\n    for (i=tb->size; i<newsize; i++) tb->hash[i] = NULL;\n  }\n  /* rehash */\n  for (i=0; i<tb->size; i++) {\n    GCObject *p = tb->hash[i];\n    tb->hash[i] = NULL;\n    while (p) {  /* for each node in the list */\n      GCObject *next = p->gch.next;  /* save next */\n      unsigned int h = gco2ts(p)->hash;\n      int h1 = lmod(h, newsize);  /* new position */\n      lua_assert(cast_int(h%newsize) == lmod(h, newsize));\n      p->gch.next = tb->hash[h1];  /* chain it */\n      tb->hash[h1] = p;\n      p = next;\n    }\n  }\n  if (newsize < tb->size)\n    luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);\n  tb->size = newsize;\n}\n\n\nstatic TString *newlstr (lua_State *L, const char *str, size_t l,\n                                       unsigned int h) {\n  TString *ts;\n  stringtable *tb;\n  if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))\n    luaM_toobig(L);\n  tb = &G(L)->strt;\n  if ((tb->nuse + 1) > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)\n    luaS_resize(L, tb->size*2);  /* too crowded */\n  ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));\n  ts->tsv.len = l;\n  ts->tsv.hash = h;\n  ts->tsv.marked = luaC_white(G(L));\n  ts->tsv.tt = LUA_TSTRING;\n  ts->tsv.reserved = 0;\n  memcpy(ts+1, str, l*sizeof(char));\n  ((char *)(ts+1))[l] = '\\0';  /* ending 0 */\n  h = lmod(h, tb->size);\n  ts->tsv.next = tb->hash[h];  /* chain new entry */\n  tb->hash[h] = obj2gco(ts);\n  tb->nuse++;\n  return ts;\n}\n\n\nTString *luaS_newlstr (lua_State *L, const char *str, size_t l) {\n  GCObject *o;\n  unsigned int h = cast(unsigned int, l);  /* seed */\n  size_t step = (l>>5)+1;  /* if string is too long, don't hash all its chars */\n  size_t l1;\n  for (l1=l; l1>=step; l1-=step)  /* compute hash */\n    h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));\n  for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];\n       o != NULL;\n       o = o->gch.next) {\n    TString *ts = rawgco2ts(o);\n    if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {\n      /* string may be dead */\n      if (isdead(G(L), o)) changewhite(o);\n      return ts;\n    }\n  }\n  return newlstr(L, str, l, h);  /* not found */\n}\n\n\nUdata *luaS_newudata (lua_State *L, size_t s, Table *e) {\n  Udata *u;\n  if (s > MAX_SIZET - sizeof(Udata))\n    luaM_toobig(L);\n  u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));\n  u->uv.marked = luaC_white(G(L));  /* is not finalized */\n  u->uv.tt = LUA_TUSERDATA;\n  u->uv.len = s;\n  u->uv.metatable = NULL;\n  u->uv.env = e;\n  /* chain it on udata list (after main thread) */\n  u->uv.next = G(L)->mainthread->next;\n  G(L)->mainthread->next = obj2gco(u);\n  return u;\n}\n\n"
  },
  {
    "path": "src/lstring.h",
    "content": "/*\n** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $\n** String table (keep all strings handled by Lua)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lstring_h\n#define lstring_h\n\n\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n\n\n#define sizestring(s)\t(sizeof(union TString)+((s)->len+1)*sizeof(char))\n\n#define sizeudata(u)\t(sizeof(union Udata)+(u)->len)\n\n#define luaS_new(L, s)\t(luaS_newlstr(L, s, strlen(s)))\n#define luaS_newliteral(L, s)\t(luaS_newlstr(L, \"\" s, \\\n                                 (sizeof(s)/sizeof(char))-1))\n\n#define luaS_fix(s)\tl_setbit((s)->tsv.marked, FIXEDBIT)\n\nLUAI_FUNC void luaS_resize (lua_State *L, int newsize);\nLUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);\nLUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);\n\n\n#endif\n"
  },
  {
    "path": "src/lstrlib.c",
    "content": "/*\n** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $\n** Standard library for string operations and pattern-matching\n** See Copyright Notice in lua.h\n*/\n\n\n#include <ctype.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lstrlib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n/* macro to `unsign' a character */\n#define uchar(c)        ((unsigned char)(c))\n\n\n\nstatic int str_len (lua_State *L) {\n  size_t l;\n  luaL_checklstring(L, 1, &l);\n  lua_pushinteger(L, l);\n  return 1;\n}\n\n\nstatic ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {\n  /* relative string position: negative means back from end */\n  if (pos < 0) pos += (ptrdiff_t)len + 1;\n  return (pos >= 0) ? pos : 0;\n}\n\n\nstatic int str_sub (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l);\n  ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l);\n  if (start < 1) start = 1;\n  if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;\n  if (start <= end)\n    lua_pushlstring(L, s+start-1, end-start+1);\n  else lua_pushliteral(L, \"\");\n  return 1;\n}\n\n\nstatic int str_reverse (lua_State *L) {\n  size_t l;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  luaL_buffinit(L, &b);\n  while (l--) luaL_addchar(&b, s[l]);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_lower (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  luaL_buffinit(L, &b);\n  for (i=0; i<l; i++)\n    luaL_addchar(&b, tolower(uchar(s[i])));\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_upper (lua_State *L) {\n  size_t l;\n  size_t i;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  luaL_buffinit(L, &b);\n  for (i=0; i<l; i++)\n    luaL_addchar(&b, toupper(uchar(s[i])));\n  luaL_pushresult(&b);\n  return 1;\n}\n\nstatic int str_rep (lua_State *L) {\n  size_t l;\n  luaL_Buffer b;\n  const char *s = luaL_checklstring(L, 1, &l);\n  int n = luaL_checkint(L, 2);\n  luaL_buffinit(L, &b);\n  while (n-- > 0)\n    luaL_addlstring(&b, s, l);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int str_byte (lua_State *L) {\n  size_t l;\n  const char *s = luaL_checklstring(L, 1, &l);\n  ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);\n  ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);\n  int n, i;\n  if (posi <= 0) posi = 1;\n  if ((size_t)pose > l) pose = l;\n  if (posi > pose) return 0;  /* empty interval; return no values */\n  n = (int)(pose -  posi + 1);\n  if (posi + n <= pose)  /* overflow? */\n    luaL_error(L, \"string slice too long\");\n  luaL_checkstack(L, n, \"string slice too long\");\n  for (i=0; i<n; i++)\n    lua_pushinteger(L, uchar(s[posi+i-1]));\n  return n;\n}\n\n\nstatic int str_char (lua_State *L) {\n  int n = lua_gettop(L);  /* number of arguments */\n  int i;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  for (i=1; i<=n; i++) {\n    int c = luaL_checkint(L, i);\n    luaL_argcheck(L, uchar(c) == c, i, \"invalid value\");\n    luaL_addchar(&b, uchar(c));\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic int writer (lua_State *L, const void* b, size_t size, void* B) {\n  (void)L;\n  luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);\n  return 0;\n}\n\n\nstatic int str_dump (lua_State *L) {\n  luaL_Buffer b;\n  luaL_checktype(L, 1, LUA_TFUNCTION);\n  lua_settop(L, 1);\n  luaL_buffinit(L,&b);\n  if (lua_dump(L, writer, &b) != 0)\n    luaL_error(L, \"unable to dump given function\");\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** PATTERN MATCHING\n** =======================================================\n*/\n\n\n#define CAP_UNFINISHED\t(-1)\n#define CAP_POSITION\t(-2)\n\ntypedef struct MatchState {\n  const char *src_init;  /* init of source string */\n  const char *src_end;  /* end (`\\0') of source string */\n  lua_State *L;\n  int level;  /* total number of captures (finished or unfinished) */\n  struct {\n    const char *init;\n    ptrdiff_t len;\n  } capture[LUA_MAXCAPTURES];\n} MatchState;\n\n\n#define L_ESC\t\t'%'\n#define SPECIALS\t\"^$*+?.([%-\"\n\n\nstatic int check_capture (MatchState *ms, int l) {\n  l -= '1';\n  if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)\n    return luaL_error(ms->L, \"invalid capture index\");\n  return l;\n}\n\n\nstatic int capture_to_close (MatchState *ms) {\n  int level = ms->level;\n  for (level--; level>=0; level--)\n    if (ms->capture[level].len == CAP_UNFINISHED) return level;\n  return luaL_error(ms->L, \"invalid pattern capture\");\n}\n\n\nstatic const char *classend (MatchState *ms, const char *p) {\n  switch (*p++) {\n    case L_ESC: {\n      if (*p == '\\0')\n        luaL_error(ms->L, \"malformed pattern (ends with \" LUA_QL(\"%%\") \")\");\n      return p+1;\n    }\n    case '[': {\n      if (*p == '^') p++;\n      do {  /* look for a `]' */\n        if (*p == '\\0')\n          luaL_error(ms->L, \"malformed pattern (missing \" LUA_QL(\"]\") \")\");\n        if (*(p++) == L_ESC && *p != '\\0')\n          p++;  /* skip escapes (e.g. `%]') */\n      } while (*p != ']');\n      return p+1;\n    }\n    default: {\n      return p;\n    }\n  }\n}\n\n\nstatic int match_class (int c, int cl) {\n  int res;\n  switch (tolower(cl)) {\n    case 'a' : res = isalpha(c); break;\n    case 'c' : res = iscntrl(c); break;\n    case 'd' : res = isdigit(c); break;\n    case 'l' : res = islower(c); break;\n    case 'p' : res = ispunct(c); break;\n    case 's' : res = isspace(c); break;\n    case 'u' : res = isupper(c); break;\n    case 'w' : res = isalnum(c); break;\n    case 'x' : res = isxdigit(c); break;\n    case 'z' : res = (c == 0); break;\n    default: return (cl == c);\n  }\n  return (islower(cl) ? res : !res);\n}\n\n\nstatic int matchbracketclass (int c, const char *p, const char *ec) {\n  int sig = 1;\n  if (*(p+1) == '^') {\n    sig = 0;\n    p++;  /* skip the `^' */\n  }\n  while (++p < ec) {\n    if (*p == L_ESC) {\n      p++;\n      if (match_class(c, uchar(*p)))\n        return sig;\n    }\n    else if ((*(p+1) == '-') && (p+2 < ec)) {\n      p+=2;\n      if (uchar(*(p-2)) <= c && c <= uchar(*p))\n        return sig;\n    }\n    else if (uchar(*p) == c) return sig;\n  }\n  return !sig;\n}\n\n\nstatic int singlematch (int c, const char *p, const char *ep) {\n  switch (*p) {\n    case '.': return 1;  /* matches any char */\n    case L_ESC: return match_class(c, uchar(*(p+1)));\n    case '[': return matchbracketclass(c, p, ep-1);\n    default:  return (uchar(*p) == c);\n  }\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p);\n\n\nstatic const char *matchbalance (MatchState *ms, const char *s,\n                                   const char *p) {\n  if (*p == 0 || *(p+1) == 0)\n    luaL_error(ms->L, \"unbalanced pattern\");\n  if (*s != *p) return NULL;\n  else {\n    int b = *p;\n    int e = *(p+1);\n    int cont = 1;\n    while (++s < ms->src_end) {\n      if (*s == e) {\n        if (--cont == 0) return s+1;\n      }\n      else if (*s == b) cont++;\n    }\n  }\n  return NULL;  /* string ends out of balance */\n}\n\n\nstatic const char *max_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  ptrdiff_t i = 0;  /* counts maximum expand for item */\n  while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))\n    i++;\n  /* keeps trying to match with the maximum repetitions */\n  while (i>=0) {\n    const char *res = match(ms, (s+i), ep+1);\n    if (res) return res;\n    i--;  /* else didn't match; reduce 1 repetition to try again */\n  }\n  return NULL;\n}\n\n\nstatic const char *min_expand (MatchState *ms, const char *s,\n                                 const char *p, const char *ep) {\n  for (;;) {\n    const char *res = match(ms, s, ep+1);\n    if (res != NULL)\n      return res;\n    else if (s<ms->src_end && singlematch(uchar(*s), p, ep))\n      s++;  /* try with one more repetition */\n    else return NULL;\n  }\n}\n\n\nstatic const char *start_capture (MatchState *ms, const char *s,\n                                    const char *p, int what) {\n  const char *res;\n  int level = ms->level;\n  if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, \"too many captures\");\n  ms->capture[level].init = s;\n  ms->capture[level].len = what;\n  ms->level = level+1;\n  if ((res=match(ms, s, p)) == NULL)  /* match failed? */\n    ms->level--;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *end_capture (MatchState *ms, const char *s,\n                                  const char *p) {\n  int l = capture_to_close(ms);\n  const char *res;\n  ms->capture[l].len = s - ms->capture[l].init;  /* close capture */\n  if ((res = match(ms, s, p)) == NULL)  /* match failed? */\n    ms->capture[l].len = CAP_UNFINISHED;  /* undo capture */\n  return res;\n}\n\n\nstatic const char *match_capture (MatchState *ms, const char *s, int l) {\n  size_t len;\n  l = check_capture(ms, l);\n  len = ms->capture[l].len;\n  if ((size_t)(ms->src_end-s) >= len &&\n      memcmp(ms->capture[l].init, s, len) == 0)\n    return s+len;\n  else return NULL;\n}\n\n\nstatic const char *match (MatchState *ms, const char *s, const char *p) {\n  init: /* using goto's to optimize tail recursion */\n  switch (*p) {\n    case '(': {  /* start capture */\n      if (*(p+1) == ')')  /* position capture? */\n        return start_capture(ms, s, p+2, CAP_POSITION);\n      else\n        return start_capture(ms, s, p+1, CAP_UNFINISHED);\n    }\n    case ')': {  /* end capture */\n      return end_capture(ms, s, p+1);\n    }\n    case L_ESC: {\n      switch (*(p+1)) {\n        case 'b': {  /* balanced string? */\n          s = matchbalance(ms, s, p+2);\n          if (s == NULL) return NULL;\n          p+=4; goto init;  /* else return match(ms, s, p+4); */\n        }\n        case 'f': {  /* frontier? */\n          const char *ep; char previous;\n          p += 2;\n          if (*p != '[')\n            luaL_error(ms->L, \"missing \" LUA_QL(\"[\") \" after \"\n                               LUA_QL(\"%%f\") \" in pattern\");\n          ep = classend(ms, p);  /* points to what is next */\n          previous = (s == ms->src_init) ? '\\0' : *(s-1);\n          if (matchbracketclass(uchar(previous), p, ep-1) ||\n             !matchbracketclass(uchar(*s), p, ep-1)) return NULL;\n          p=ep; goto init;  /* else return match(ms, s, ep); */\n        }\n        default: {\n          if (isdigit(uchar(*(p+1)))) {  /* capture results (%0-%9)? */\n            s = match_capture(ms, s, uchar(*(p+1)));\n            if (s == NULL) return NULL;\n            p+=2; goto init;  /* else return match(ms, s, p+2) */\n          }\n          goto dflt;  /* case default */\n        }\n      }\n    }\n    case '\\0': {  /* end of pattern */\n      return s;  /* match succeeded */\n    }\n    case '$': {\n      if (*(p+1) == '\\0')  /* is the `$' the last char in pattern? */\n        return (s == ms->src_end) ? s : NULL;  /* check end of string */\n      else goto dflt;\n    }\n    default: dflt: {  /* it is a pattern item */\n      const char *ep = classend(ms, p);  /* points to what is next */\n      int m = s<ms->src_end && singlematch(uchar(*s), p, ep);\n      switch (*ep) {\n        case '?': {  /* optional */\n          const char *res;\n          if (m && ((res=match(ms, s+1, ep+1)) != NULL))\n            return res;\n          p=ep+1; goto init;  /* else return match(ms, s, ep+1); */\n        }\n        case '*': {  /* 0 or more repetitions */\n          return max_expand(ms, s, p, ep);\n        }\n        case '+': {  /* 1 or more repetitions */\n          return (m ? max_expand(ms, s+1, p, ep) : NULL);\n        }\n        case '-': {  /* 0 or more repetitions (minimum) */\n          return min_expand(ms, s, p, ep);\n        }\n        default: {\n          if (!m) return NULL;\n          s++; p=ep; goto init;  /* else return match(ms, s+1, ep); */\n        }\n      }\n    }\n  }\n}\n\n\n\nstatic const char *lmemfind (const char *s1, size_t l1,\n                               const char *s2, size_t l2) {\n  if (l2 == 0) return s1;  /* empty strings are everywhere */\n  else if (l2 > l1) return NULL;  /* avoids a negative `l1' */\n  else {\n    const char *init;  /* to search for a `*s2' inside `s1' */\n    l2--;  /* 1st char will be checked by `memchr' */\n    l1 = l1-l2;  /* `s2' cannot be found after that */\n    while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {\n      init++;   /* 1st char is already checked */\n      if (memcmp(init, s2+1, l2) == 0)\n        return init-1;\n      else {  /* correct `l1' and `s1' to try again */\n        l1 -= init-s1;\n        s1 = init;\n      }\n    }\n    return NULL;  /* not found */\n  }\n}\n\n\nstatic void push_onecapture (MatchState *ms, int i, const char *s,\n                                                    const char *e) {\n  if (i >= ms->level) {\n    if (i == 0)  /* ms->level == 0, too */\n      lua_pushlstring(ms->L, s, e - s);  /* add whole match */\n    else\n      luaL_error(ms->L, \"invalid capture index\");\n  }\n  else {\n    ptrdiff_t l = ms->capture[i].len;\n    if (l == CAP_UNFINISHED) luaL_error(ms->L, \"unfinished capture\");\n    if (l == CAP_POSITION)\n      lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);\n    else\n      lua_pushlstring(ms->L, ms->capture[i].init, l);\n  }\n}\n\n\nstatic int push_captures (MatchState *ms, const char *s, const char *e) {\n  int i;\n  int nlevels = (ms->level == 0 && s) ? 1 : ms->level;\n  luaL_checkstack(ms->L, nlevels, \"too many captures\");\n  for (i = 0; i < nlevels; i++)\n    push_onecapture(ms, i, s, e);\n  return nlevels;  /* number of strings pushed */\n}\n\n\nstatic int str_find_aux (lua_State *L, int find) {\n  size_t l1, l2;\n  const char *s = luaL_checklstring(L, 1, &l1);\n  const char *p = luaL_checklstring(L, 2, &l2);\n  ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;\n  if (init < 0) init = 0;\n  else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;\n  if (find && (lua_toboolean(L, 4) ||  /* explicit request? */\n      strpbrk(p, SPECIALS) == NULL)) {  /* or no special characters? */\n    /* do a plain search */\n    const char *s2 = lmemfind(s+init, l1-init, p, l2);\n    if (s2) {\n      lua_pushinteger(L, s2-s+1);\n      lua_pushinteger(L, s2-s+l2);\n      return 2;\n    }\n  }\n  else {\n    MatchState ms;\n    int anchor = (*p == '^') ? (p++, 1) : 0;\n    const char *s1=s+init;\n    ms.L = L;\n    ms.src_init = s;\n    ms.src_end = s+l1;\n    do {\n      const char *res;\n      ms.level = 0;\n      if ((res=match(&ms, s1, p)) != NULL) {\n        if (find) {\n          lua_pushinteger(L, s1-s+1);  /* start */\n          lua_pushinteger(L, res-s);   /* end */\n          return push_captures(&ms, NULL, 0) + 2;\n        }\n        else\n          return push_captures(&ms, s1, res);\n      }\n    } while (s1++ < ms.src_end && !anchor);\n  }\n  lua_pushnil(L);  /* not found */\n  return 1;\n}\n\n\nstatic int str_find (lua_State *L) {\n  return str_find_aux(L, 1);\n}\n\n\nstatic int str_match (lua_State *L) {\n  return str_find_aux(L, 0);\n}\n\n\nstatic int gmatch_aux (lua_State *L) {\n  MatchState ms;\n  size_t ls;\n  const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);\n  const char *p = lua_tostring(L, lua_upvalueindex(2));\n  const char *src;\n  ms.L = L;\n  ms.src_init = s;\n  ms.src_end = s+ls;\n  for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));\n       src <= ms.src_end;\n       src++) {\n    const char *e;\n    ms.level = 0;\n    if ((e = match(&ms, src, p)) != NULL) {\n      lua_Integer newstart = e-s;\n      if (e == src) newstart++;  /* empty match? go at least one position */\n      lua_pushinteger(L, newstart);\n      lua_replace(L, lua_upvalueindex(3));\n      return push_captures(&ms, src, e);\n    }\n  }\n  return 0;  /* not found */\n}\n\n\nstatic int gmatch (lua_State *L) {\n  luaL_checkstring(L, 1);\n  luaL_checkstring(L, 2);\n  lua_settop(L, 2);\n  lua_pushinteger(L, 0);\n  lua_pushcclosure(L, gmatch_aux, 3);\n  return 1;\n}\n\n\nstatic int gfind_nodef (lua_State *L) {\n  return luaL_error(L, LUA_QL(\"string.gfind\") \" was renamed to \"\n                       LUA_QL(\"string.gmatch\"));\n}\n\n\nstatic void add_s (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                   const char *e) {\n  size_t l, i;\n  const char *news = lua_tolstring(ms->L, 3, &l);\n  for (i = 0; i < l; i++) {\n    if (news[i] != L_ESC)\n      luaL_addchar(b, news[i]);\n    else {\n      i++;  /* skip ESC */\n      if (!isdigit(uchar(news[i])))\n        luaL_addchar(b, news[i]);\n      else if (news[i] == '0')\n          luaL_addlstring(b, s, e - s);\n      else {\n        push_onecapture(ms, news[i] - '1', s, e);\n        luaL_addvalue(b);  /* add capture to accumulated result */\n      }\n    }\n  }\n}\n\n\nstatic void add_value (MatchState *ms, luaL_Buffer *b, const char *s,\n                                                       const char *e) {\n  lua_State *L = ms->L;\n  switch (lua_type(L, 3)) {\n    case LUA_TNUMBER:\n    case LUA_TSTRING: {\n      add_s(ms, b, s, e);\n      return;\n    }\n    case LUA_TFUNCTION: {\n      int n;\n      lua_pushvalue(L, 3);\n      n = push_captures(ms, s, e);\n      lua_call(L, n, 1);\n      break;\n    }\n    case LUA_TTABLE: {\n      push_onecapture(ms, 0, s, e);\n      lua_gettable(L, 3);\n      break;\n    }\n  }\n  if (!lua_toboolean(L, -1)) {  /* nil or false? */\n    lua_pop(L, 1);\n    lua_pushlstring(L, s, e - s);  /* keep original text */\n  }\n  else if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid replacement value (a %s)\", luaL_typename(L, -1)); \n  luaL_addvalue(b);  /* add result to accumulator */\n}\n\n\nstatic int str_gsub (lua_State *L) {\n  size_t srcl;\n  const char *src = luaL_checklstring(L, 1, &srcl);\n  const char *p = luaL_checkstring(L, 2);\n  int  tr = lua_type(L, 3);\n  int max_s = luaL_optint(L, 4, srcl+1);\n  int anchor = (*p == '^') ? (p++, 1) : 0;\n  int n = 0;\n  MatchState ms;\n  luaL_Buffer b;\n  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||\n                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,\n                      \"string/function/table expected\");\n  luaL_buffinit(L, &b);\n  ms.L = L;\n  ms.src_init = src;\n  ms.src_end = src+srcl;\n  while (n < max_s) {\n    const char *e;\n    ms.level = 0;\n    e = match(&ms, src, p);\n    if (e) {\n      n++;\n      add_value(&ms, &b, src, e);\n    }\n    if (e && e>src) /* non empty match? */\n      src = e;  /* skip it */\n    else if (src < ms.src_end)\n      luaL_addchar(&b, *src++);\n    else break;\n    if (anchor) break;\n  }\n  luaL_addlstring(&b, src, ms.src_end-src);\n  luaL_pushresult(&b);\n  lua_pushinteger(L, n);  /* number of substitutions */\n  return 2;\n}\n\n/* }====================================================== */\n\n\n/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */\n#define MAX_ITEM\t512\n/* valid flags in a format specification */\n#define FLAGS\t\"-+ #0\"\n/*\n** maximum size of each format specification (such as '%-099.99d')\n** (+10 accounts for %99.99x plus margin of error)\n*/\n#define MAX_FORMAT\t(sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)\n\n\nstatic void addquoted (lua_State *L, luaL_Buffer *b, int arg) {\n  size_t l;\n  const char *s = luaL_checklstring(L, arg, &l);\n  luaL_addchar(b, '\"');\n  while (l--) {\n    switch (*s) {\n      case '\"': case '\\\\': case '\\n': {\n        luaL_addchar(b, '\\\\');\n        luaL_addchar(b, *s);\n        break;\n      }\n      case '\\r': {\n        luaL_addlstring(b, \"\\\\r\", 2);\n        break;\n      }\n      case '\\0': {\n        luaL_addlstring(b, \"\\\\000\", 4);\n        break;\n      }\n      default: {\n        luaL_addchar(b, *s);\n        break;\n      }\n    }\n    s++;\n  }\n  luaL_addchar(b, '\"');\n}\n\nstatic const char *scanformat (lua_State *L, const char *strfrmt, char *form) {\n  const char *p = strfrmt;\n  while (*p != '\\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */\n  if ((size_t)(p - strfrmt) >= sizeof(FLAGS))\n    luaL_error(L, \"invalid format (repeated flags)\");\n  if (isdigit(uchar(*p))) p++;  /* skip width */\n  if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  if (*p == '.') {\n    p++;\n    if (isdigit(uchar(*p))) p++;  /* skip precision */\n    if (isdigit(uchar(*p))) p++;  /* (2 digits at most) */\n  }\n  if (isdigit(uchar(*p)))\n    luaL_error(L, \"invalid format (width or precision too long)\");\n  *(form++) = '%';\n  strncpy(form, strfrmt, p - strfrmt + 1);\n  form += p - strfrmt + 1;\n  *form = '\\0';\n  return p;\n}\n\n\nstatic void addintlen (char *form) {\n  size_t l = strlen(form);\n  char spec = form[l - 1];\n  strcpy(form + l - 1, LUA_INTFRMLEN);\n  form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;\n  form[l + sizeof(LUA_INTFRMLEN) - 1] = '\\0';\n}\n\n\nstatic int str_format (lua_State *L) {\n  int arg = 1;\n  size_t sfl;\n  const char *strfrmt = luaL_checklstring(L, arg, &sfl);\n  const char *strfrmt_end = strfrmt+sfl;\n  luaL_Buffer b;\n  luaL_buffinit(L, &b);\n  while (strfrmt < strfrmt_end) {\n    if (*strfrmt != L_ESC)\n      luaL_addchar(&b, *strfrmt++);\n    else if (*++strfrmt == L_ESC)\n      luaL_addchar(&b, *strfrmt++);  /* %% */\n    else { /* format item */\n      char form[MAX_FORMAT];  /* to store the format (`%...') */\n      char buff[MAX_ITEM];  /* to store the formatted item */\n      arg++;\n      strfrmt = scanformat(L, strfrmt, form);\n      switch (*strfrmt++) {\n        case 'c': {\n          sprintf(buff, form, (int)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'd':  case 'i': {\n          addintlen(form);\n          sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'o':  case 'u':  case 'x':  case 'X': {\n          addintlen(form);\n          sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'e':  case 'E': case 'f':\n        case 'g': case 'G': {\n          sprintf(buff, form, (double)luaL_checknumber(L, arg));\n          break;\n        }\n        case 'q': {\n          addquoted(L, &b, arg);\n          continue;  /* skip the 'addsize' at the end */\n        }\n        case 's': {\n          size_t l;\n          const char *s = luaL_checklstring(L, arg, &l);\n          if (!strchr(form, '.') && l >= 100) {\n            /* no precision and string is too long to be formatted;\n               keep original string */\n            lua_pushvalue(L, arg);\n            luaL_addvalue(&b);\n            continue;  /* skip the `addsize' at the end */\n          }\n          else {\n            sprintf(buff, form, s);\n            break;\n          }\n        }\n        default: {  /* also treat cases `pnLlh' */\n          return luaL_error(L, \"invalid option \" LUA_QL(\"%%%c\") \" to \"\n                               LUA_QL(\"format\"), *(strfrmt - 1));\n        }\n      }\n      luaL_addlstring(&b, buff, strlen(buff));\n    }\n  }\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\nstatic const luaL_Reg strlib[] = {\n  {\"byte\", str_byte},\n  {\"char\", str_char},\n  {\"dump\", str_dump},\n  {\"find\", str_find},\n  {\"format\", str_format},\n  {\"gfind\", gfind_nodef},\n  {\"gmatch\", gmatch},\n  {\"gsub\", str_gsub},\n  {\"len\", str_len},\n  {\"lower\", str_lower},\n  {\"match\", str_match},\n  {\"rep\", str_rep},\n  {\"reverse\", str_reverse},\n  {\"sub\", str_sub},\n  {\"upper\", str_upper},\n  {NULL, NULL}\n};\n\n\nstatic void createmetatable (lua_State *L) {\n  lua_createtable(L, 0, 1);  /* create metatable for strings */\n  lua_pushliteral(L, \"\");  /* dummy string */\n  lua_pushvalue(L, -2);\n  lua_setmetatable(L, -2);  /* set string metatable */\n  lua_pop(L, 1);  /* pop dummy string */\n  lua_pushvalue(L, -2);  /* string library... */\n  lua_setfield(L, -2, \"__index\");  /* ...is the __index metamethod */\n  lua_pop(L, 1);  /* pop metatable */\n}\n\n\n/*\n** Open string library\n*/\nLUALIB_API int luaopen_string (lua_State *L) {\n  luaL_register(L, LUA_STRLIBNAME, strlib);\n#if defined(LUA_COMPAT_GFIND)\n  lua_getfield(L, -1, \"gmatch\");\n  lua_setfield(L, -2, \"gfind\");\n#endif\n  createmetatable(L);\n  return 1;\n}\n\n"
  },
  {
    "path": "src/ltable.c",
    "content": "/*\n** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n\n/*\n** Implementation of tables (aka arrays, objects, or hash tables).\n** Tables keep its elements in two parts: an array part and a hash part.\n** Non-negative integer keys are all candidates to be kept in the array\n** part. The actual size of the array is the largest `n' such that at\n** least half the slots between 0 and n are in use.\n** Hash uses a mix of chained scatter table with Brent's variation.\n** A main invariant of these tables is that, if an element is not\n** in its main position (i.e. the `original' position that its hash gives\n** to it), then the colliding element is in its own main position.\n** Hence even when the load factor reaches 100%, performance remains good.\n*/\n\n#include <math.h>\n#include <string.h>\n\n#define ltable_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lgc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"ltable.h\"\n\n\n/*\n** max size of array part is 2^MAXBITS\n*/\n#if LUAI_BITSINT > 26\n#define MAXBITS\t\t26\n#else\n#define MAXBITS\t\t(LUAI_BITSINT-2)\n#endif\n\n#define MAXASIZE\t(1 << MAXBITS)\n\n\n#define hashpow2(t,n)      (gnode(t, lmod((n), sizenode(t))))\n  \n#define hashstr(t,str)  hashpow2(t, (str)->tsv.hash)\n#define hashboolean(t,p)        hashpow2(t, p)\n\n\n/*\n** for some types, it is better to avoid modulus by power of 2, as\n** they tend to have many 2 factors.\n*/\n#define hashmod(t,n)\t(gnode(t, ((n) % ((sizenode(t)-1)|1))))\n\n\n#define hashpointer(t,p)\thashmod(t, IntPoint(p))\n\n\n/*\n** number of ints inside a lua_Number\n*/\n#define numints\t\tcast_int(sizeof(lua_Number)/sizeof(int))\n\n\n\n#define dummynode\t\t(&dummynode_)\n\nstatic const Node dummynode_ = {\n  {{NULL}, LUA_TNIL},  /* value */\n  {{{NULL}, LUA_TNIL, NULL}}  /* key */\n};\n\n\n/*\n** hash for lua_Numbers\n*/\nstatic Node *hashnum (const Table *t, lua_Number n) {\n  unsigned int a[numints];\n  int i;\n  if (luai_numeq(n, 0))  /* avoid problems with -0 */\n    return gnode(t, 0);\n  memcpy(a, &n, sizeof(a));\n  for (i = 1; i < numints; i++) a[0] += a[i];\n  return hashmod(t, a[0]);\n}\n\n\n\n/*\n** returns the `main' position of an element in a table (that is, the index\n** of its hash value)\n*/\nstatic Node *mainposition (const Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNUMBER:\n      return hashnum(t, nvalue(key));\n    case LUA_TSTRING:\n      return hashstr(t, rawtsvalue(key));\n    case LUA_TBOOLEAN:\n      return hashboolean(t, bvalue(key));\n    case LUA_TLIGHTUSERDATA:\n      return hashpointer(t, pvalue(key));\n    default:\n      return hashpointer(t, gcvalue(key));\n  }\n}\n\n\n/*\n** returns the index for `key' if `key' is an appropriate key to live in\n** the array part of the table, -1 otherwise.\n*/\nstatic int arrayindex (const TValue *key) {\n  if (ttisnumber(key)) {\n    lua_Number n = nvalue(key);\n    int k;\n    lua_number2int(k, n);\n    if (luai_numeq(cast_num(k), n))\n      return k;\n  }\n  return -1;  /* `key' did not match some condition */\n}\n\n\n/*\n** returns the index of a `key' for table traversals. First goes all\n** elements in the array part, then elements in the hash part. The\n** beginning of a traversal is signalled by -1.\n*/\nstatic int findindex (lua_State *L, Table *t, StkId key) {\n  int i;\n  if (ttisnil(key)) return -1;  /* first iteration */\n  i = arrayindex(key);\n  if (0 < i && i <= t->sizearray)  /* is `key' inside array part? */\n    return i-1;  /* yes; that's the index (corrected to C) */\n  else {\n    Node *n = mainposition(t, key);\n    do {  /* check whether `key' is somewhere in the chain */\n      /* key may be dead already, but it is ok to use it in `next' */\n      if (luaO_rawequalObj(key2tval(n), key) ||\n            (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&\n             gcvalue(gkey(n)) == gcvalue(key))) {\n        i = cast_int(n - gnode(t, 0));  /* key index in hash table */\n        /* hash elements are numbered after array ones */\n        return i + t->sizearray;\n      }\n      else n = gnext(n);\n    } while (n);\n    luaG_runerror(L, \"invalid key to \" LUA_QL(\"next\"));  /* key not found */\n    return 0;  /* to avoid warnings */\n  }\n}\n\n\nint luaH_next (lua_State *L, Table *t, StkId key) {\n  int i = findindex(L, t, key);  /* find original element */\n  for (i++; i < t->sizearray; i++) {  /* try first array part */\n    if (!ttisnil(&t->array[i])) {  /* a non-nil value? */\n      setnvalue(key, cast_num(i+1));\n      setobj2s(L, key+1, &t->array[i]);\n      return 1;\n    }\n  }\n  for (i -= t->sizearray; i < sizenode(t); i++) {  /* then hash part */\n    if (!ttisnil(gval(gnode(t, i)))) {  /* a non-nil value? */\n      setobj2s(L, key, key2tval(gnode(t, i)));\n      setobj2s(L, key+1, gval(gnode(t, i)));\n      return 1;\n    }\n  }\n  return 0;  /* no more elements */\n}\n\n\n/*\n** {=============================================================\n** Rehash\n** ==============================================================\n*/\n\n\nstatic int computesizes (int nums[], int *narray) {\n  int i;\n  int twotoi;  /* 2^i */\n  int a = 0;  /* number of elements smaller than 2^i */\n  int na = 0;  /* number of elements to go to array part */\n  int n = 0;  /* optimal size for array part */\n  for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {\n    if (nums[i] > 0) {\n      a += nums[i];\n      if (a > twotoi/2) {  /* more than half elements present? */\n        n = twotoi;  /* optimal size (till now) */\n        na = a;  /* all elements smaller than n will go to array part */\n      }\n    }\n    if (a == *narray) break;  /* all elements already counted */\n  }\n  *narray = n;\n  lua_assert(*narray/2 <= na && na <= *narray);\n  return na;\n}\n\n\nstatic int countint (const TValue *key, int *nums) {\n  int k = arrayindex(key);\n  if (0 < k && k <= MAXASIZE) {  /* is `key' an appropriate array index? */\n    nums[ceillog2(k)]++;  /* count as such */\n    return 1;\n  }\n  else\n    return 0;\n}\n\n\nstatic int numusearray (const Table *t, int *nums) {\n  int lg;\n  int ttlg;  /* 2^lg */\n  int ause = 0;  /* summation of `nums' */\n  int i = 1;  /* count to traverse all array keys */\n  for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) {  /* for each slice */\n    int lc = 0;  /* counter */\n    int lim = ttlg;\n    if (lim > t->sizearray) {\n      lim = t->sizearray;  /* adjust upper limit */\n      if (i > lim)\n        break;  /* no more elements to count */\n    }\n    /* count elements in range (2^(lg-1), 2^lg] */\n    for (; i <= lim; i++) {\n      if (!ttisnil(&t->array[i-1]))\n        lc++;\n    }\n    nums[lg] += lc;\n    ause += lc;\n  }\n  return ause;\n}\n\n\nstatic int numusehash (const Table *t, int *nums, int *pnasize) {\n  int totaluse = 0;  /* total number of elements */\n  int ause = 0;  /* summation of `nums' */\n  int i = sizenode(t);\n  while (i--) {\n    Node *n = &t->node[i];\n    if (!ttisnil(gval(n))) {\n      ause += countint(key2tval(n), nums);\n      totaluse++;\n    }\n  }\n  *pnasize += ause;\n  return totaluse;\n}\n\n\nstatic void setarrayvector (lua_State *L, Table *t, int size) {\n  int i;\n  luaM_reallocvector(L, t->array, t->sizearray, size, TValue);\n  for (i=t->sizearray; i<size; i++)\n     setnilvalue(&t->array[i]);\n  t->sizearray = size;\n}\n\n\nstatic Node *getfreepos (Table *t) {\n  while (t->lastfree-- > t->node) {\n    if (ttisnil(gkey(t->lastfree)))\n      return t->lastfree;\n  }\n  return NULL;  /* could not find a free place */\n}\n\n\nstatic void resizenodevector (lua_State *L, Table *t, int oldsize, int newsize) {\n  int lsize;\n  if (newsize == 0) {  /* no elements to hash part? */\n    t->node = cast(Node *, dummynode);  /* use common `dummynode' */\n    lsize = 0;\n  }\n  else {\n    Node *node = t->node;\n    int i;\n    lsize = ceillog2(newsize);\n    if (lsize > MAXBITS)\n      luaG_runerror(L, \"table overflow\");\n    newsize = twoto(lsize);\n    if (node == dummynode) {\n      oldsize = 0;\n      node = NULL; /* don't try to realloc `dummynode' pointer. */\n    }\n    luaM_reallocvector(L, node, oldsize, newsize, Node);\n    t->node = node;\n    for (i=oldsize; i<newsize; i++) {\n      Node *n = gnode(t, i);\n      gnext(n) = NULL;\n      setnilvalue(gkey(n));\n      setnilvalue(gval(n));\n    }\n  }\n  t->lsizenode = cast_byte(lsize);\n  t->lastfree = gnode(t, newsize);  /* reset lastfree to end of table. */\n}\n\n\nstatic Node *find_prev_node(Node *mp, Node *next) {\n  Node *prev = mp;\n  while (prev != NULL && gnext(prev) != next) prev = gnext(prev);\n  return prev;\n}\n\n\n/*\n** move a node from it's old position to it's new position during a rehash;\n** first, check whether the moving node's main position is free. If not, check whether\n** colliding node is in its main position or not: if it is not, move colliding\n** node to an empty place and put moving node in its main position; otherwise\n** (colliding node is in its main position), moving node goes to an empty position. \n*/\nstatic int move_node (lua_State *L, Table *t, Node *node) {\n  (void)L;\n  Node *mp = mainposition(t, key2tval(node));\n  /* if node is in it's main position, don't need to move node. */\n  if (mp == node) return 1;\n  /* if node is in it's main position's chain, don't need to move node. */\n  if (find_prev_node(mp, node) != NULL) return 1;\n  /* is main position is free? */\n  if (!ttisnil(gval(mp)) || mp == dummynode) {\n    /* no; move main position node if it is out of its main position */\n    Node *othermp;\n    othermp = mainposition(t, key2tval(mp));\n    if (othermp != mp) {  /* is colliding node out of its main position? */\n      /* yes; swap colliding node with the node that is being moved. */\n      Node *prev;\n      Node tmp;\n      tmp = *node;\n      prev = find_prev_node(othermp, mp);  /* find previous */\n      if (prev != NULL) gnext(prev) = node;  /* redo the chain with `n' in place of `mp' */\n      *node = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      *mp = tmp;\n      return (prev != NULL) ? 1 : 0; /* is colliding node part of its main position chain? */\n    }\n    else {  /* colliding node is in its own main position */\n      /* add node to main position's chain. */\n      gnext(node) = gnext(mp);  /* chain new position */\n      gnext(mp) = node;\n    }\n  }\n  else { /* main position is free, move node */\n    *mp = *node;\n    gnext(node) = NULL;\n    setnilvalue(gkey(node));\n    setnilvalue(gval(node));\n  }\n  return 1;\n}\n\n\nstatic int move_number (lua_State *L, Table *t, Node *node) {\n  int key;\n  lua_Number n = nvalue(key2tval(node));\n  lua_number2int(key, n);\n  (void)L;\n  if (luai_numeq(cast_num(key), nvalue(key2tval(node)))) {/* index is int? */\n    /* (1 <= key && key <= t->sizearray) */\n    if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) {\n      setobjt2t(L, &t->array[key-1], gval(node));\n      setnilvalue(gkey(node));\n      setnilvalue(gval(node));\n      return 1;\n    }\n  }\n  return 0;\n}\n\n\nstatic void resize_hashpart (lua_State *L, Table *t, int nhsize) {\n  int i;\n  int lsize=0;\n  int oldhsize = (t->node != dummynode) ? twoto(t->lsizenode) : 0;\n  if (nhsize > 0) { /* round new hashpart size up to next power of two. */\n    lsize=ceillog2(nhsize);\n    if (lsize > MAXBITS)\n      luaG_runerror(L, \"table overflow\");\n  }\n  nhsize = twoto(lsize);\n  /* grow hash part to new size. */\n  if (oldhsize < nhsize)\n    resizenodevector(L, t, oldhsize, nhsize);\n  else { /* hash part might be shrinking */\n    if (nhsize > 0) {\n      t->lsizenode = cast_byte(lsize);\n      t->lastfree = gnode(t, nhsize);  /* reset lastfree back to end of table. */\n    }\n    else { /* new hashpart size is zero. */\n      resizenodevector(L, t, oldhsize, nhsize);\n      return;\n    }\n  }\n  /* break old chains, try moving int keys to array part and compact keys into new hashpart */\n  for (i = 0; i < oldhsize; i++) {\n    Node *old = gnode(t, i);\n    gnext(old) = NULL;\n    if (ttisnil(gval(old))) { /* clear nodes with nil values. */\n      setnilvalue(gkey(old));\n      continue;\n    }\n    if (ttisnumber(key2tval(old))) { /* try moving the int keys into array part. */\n      if(move_number(L, t, old))\n        continue;\n    }\n    if (i >= nhsize) { /* move all valid keys to indices < nhsize. */\n      Node *n = getfreepos(t);  /* get a free place */\n      lua_assert(n != dummynode && n != NULL);\n      *n = *old;\n    }\n  }\n  /* shrink hash part */\n  if (oldhsize > nhsize)\n    resizenodevector(L, t, oldhsize, nhsize);\n  /* move nodes to their new mainposition and re-create node chains */\n  for (i = 0; i < nhsize; i++) {\n    Node *curr = gnode(t, i);\n    if (!ttisnil(gval(curr)))\n      while (move_node(L, t, curr) == 0);\n  }\n}\n\n\nstatic void resize (lua_State *L, Table *t, int nasize, int nhsize) {\n  int i;\n  int oldasize = t->sizearray;\n  if (nasize > oldasize)  /* array part must grow? */\n    setarrayvector(L, t, nasize);\n  resize_hashpart(L, t, nhsize);\n  if (nasize < oldasize) {  /* array part must shrink? */\n    t->sizearray = nasize;\n    /* re-insert elements from vanishing slice */\n    for (i=nasize; i<oldasize; i++) {\n      if (!ttisnil(&t->array[i]))\n        setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);\n    }\n    /* shrink array */\n    luaM_reallocvector(L, t->array, oldasize, nasize, TValue);\n  }\n}\n\n\nvoid luaH_resizearray (lua_State *L, Table *t, int nasize) {\n  int nsize = (t->node == dummynode) ? 0 : sizenode(t);\n  resize(L, t, nasize, nsize);\n}\n\n\nstatic void rehash (lua_State *L, Table *t, const TValue *ek) {\n  int nasize, na;\n  int nums[MAXBITS+1];  /* nums[i] = number of keys between 2^(i-1) and 2^i */\n  int i;\n  int totaluse;\n  for (i=0; i<=MAXBITS; i++) nums[i] = 0;  /* reset counts */\n  nasize = numusearray(t, nums);  /* count keys in array part */\n  totaluse = nasize;  /* all those keys are integer keys */\n  totaluse += numusehash(t, nums, &nasize);  /* count keys in hash part */\n  /* count extra key */\n  nasize += countint(ek, nums);\n  totaluse++;\n  /* compute new size for array part */\n  na = computesizes(nums, &nasize);\n  /* resize the table to new computed sizes */\n  resize(L, t, nasize, totaluse - na);\n}\n\n\n\n/*\n** }=============================================================\n*/\n\n\nTable *luaH_new (lua_State *L, int narray, int nhash) {\n  Table *t = luaM_new(L, Table);\n  luaC_link(L, obj2gco(t), LUA_TTABLE);\n  sethvalue2s(L, L->top, t); /* put table on stack */\n  incr_top(L);\n  t->metatable = NULL;\n  t->flags = cast_byte(~0);\n  /* temporary values (kept only if some malloc fails) */\n  t->array = NULL;\n  t->sizearray = 0;\n  t->lsizenode = 0;\n  t->node = cast(Node *, dummynode);\n  setarrayvector(L, t, narray);\n  resizenodevector(L, t, 0, nhash);\n  L->top--; /* remove table from stack */\n  return t;\n}\n\n\nvoid luaH_free (lua_State *L, Table *t) {\n  if (t->node != dummynode)\n    luaM_freearray(L, t->node, sizenode(t), Node);\n  luaM_freearray(L, t->array, t->sizearray, TValue);\n  luaM_free(L, t);\n}\n\n\n\n/*\n** inserts a new key into a hash table; first, check whether key's main \n** position is free. If not, check whether colliding node is in its main \n** position or not: if it is not, move colliding node to an empty place and \n** put new key in its main position; otherwise (colliding node is in its main \n** position), new key goes to an empty position. \n*/\nstatic TValue *newkey (lua_State *L, Table *t, const TValue *key) {\n  Node *mp = mainposition(t, key);\n  if (!ttisnil(gval(mp)) || mp == dummynode) {\n    Node *othern;\n    Node *n = getfreepos(t);  /* get a free place */\n    if (n == NULL) {  /* cannot find a free place? */\n      rehash(L, t, key);  /* grow table */\n      return luaH_set(L, t, key);  /* re-insert key into grown table */\n    }\n    lua_assert(n != dummynode);\n    othern = mainposition(t, key2tval(mp));\n    if (othern != mp) {  /* is colliding node out of its main position? */\n      /* yes; move colliding node into free position */\n      while (gnext(othern) != mp) othern = gnext(othern);  /* find previous */\n      gnext(othern) = n;  /* redo the chain with `n' in place of `mp' */\n      *n = *mp;  /* copy colliding node into free pos. (mp->next also goes) */\n      gnext(mp) = NULL;  /* now `mp' is free */\n      setnilvalue(gval(mp));\n    }\n    else {  /* colliding node is in its own main position */\n      /* new node will go into free position */\n      gnext(n) = gnext(mp);  /* chain new position */\n      gnext(mp) = n;\n      mp = n;\n    }\n  }\n  gkey(mp)->value = key->value; gkey(mp)->tt = key->tt;\n  luaC_barriert(L, t, key);\n  lua_assert(ttisnil(gval(mp)));\n  return gval(mp);\n}\n\n\n/*\n** search function for integers\n*/\nconst TValue *luaH_getnum (Table *t, int key) {\n  /* (1 <= key && key <= t->sizearray) */\n  if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))\n    return &t->array[key-1];\n  else {\n    lua_Number nk = cast_num(key);\n    Node *n = hashnum(t, nk);\n    do {  /* check whether `key' is somewhere in the chain */\n      if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))\n        return gval(n);  /* that's it */\n      else n = gnext(n);\n    } while (n);\n    return luaO_nilobject;\n  }\n}\n\n\n/*\n** search function for strings\n*/\nconst TValue *luaH_getstr (Table *t, TString *key) {\n  Node *n = hashstr(t, key);\n  do {  /* check whether `key' is somewhere in the chain */\n    if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)\n      return gval(n);  /* that's it */\n    else n = gnext(n);\n  } while (n);\n  return luaO_nilobject;\n}\n\n\n/*\n** main search function\n*/\nconst TValue *luaH_get (Table *t, const TValue *key) {\n  switch (ttype(key)) {\n    case LUA_TNIL: return luaO_nilobject;\n    case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));\n    case LUA_TNUMBER: {\n      int k;\n      lua_Number n = nvalue(key);\n      lua_number2int(k, n);\n      if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */\n        return luaH_getnum(t, k);  /* use specialized version */\n      /* else go through */\n    }\n    default: {\n      Node *n = mainposition(t, key);\n      do {  /* check whether `key' is somewhere in the chain */\n        if (luaO_rawequalObj(key2tval(n), key))\n          return gval(n);  /* that's it */\n        else n = gnext(n);\n      } while (n);\n      return luaO_nilobject;\n    }\n  }\n}\n\n\nTValue *luaH_set (lua_State *L, Table *t, const TValue *key) {\n  const TValue *p = luaH_get(t, key);\n  t->flags = 0;\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else {\n    if (ttisnil(key)) luaG_runerror(L, \"table index is nil\");\n    else if (ttisnumber(key) && luai_numisnan(nvalue(key)))\n      luaG_runerror(L, \"table index is NaN\");\n    return newkey(L, t, key);\n  }\n}\n\n\nTValue *luaH_setnum (lua_State *L, Table *t, int key) {\n  const TValue *p = luaH_getnum(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else {\n    TValue k;\n    setnvalue(&k, cast_num(key));\n    return newkey(L, t, &k);\n  }\n}\n\n\nTValue *luaH_setstr (lua_State *L, Table *t, TString *key) {\n  const TValue *p = luaH_getstr(t, key);\n  if (p != luaO_nilobject)\n    return cast(TValue *, p);\n  else {\n    TValue k;\n    setsvalue(L, &k, key);\n    return newkey(L, t, &k);\n  }\n}\n\n\nstatic int unbound_search (Table *t, unsigned int j) {\n  unsigned int i = j;  /* i is zero or a present index */\n  j++;\n  /* find `i' and `j' such that i is present and j is not */\n  while (!ttisnil(luaH_getnum(t, j))) {\n    i = j;\n    j *= 2;\n    if (j > cast(unsigned int, MAX_INT)) {  /* overflow? */\n      /* table was built with bad purposes: resort to linear search */\n      i = 1;\n      while (!ttisnil(luaH_getnum(t, i))) i++;\n      return i - 1;\n    }\n  }\n  /* now do a binary search between them */\n  while (j - i > 1) {\n    unsigned int m = (i+j)/2;\n    if (ttisnil(luaH_getnum(t, m))) j = m;\n    else i = m;\n  }\n  return i;\n}\n\n\n/*\n** Try to find a boundary in table `t'. A `boundary' is an integer index\n** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).\n*/\nint luaH_getn (Table *t) {\n  unsigned int j = t->sizearray;\n  if (j > 0 && ttisnil(&t->array[j - 1])) {\n    /* there is a boundary in the array part: (binary) search for it */\n    unsigned int i = 0;\n    while (j - i > 1) {\n      unsigned int m = (i+j)/2;\n      if (ttisnil(&t->array[m - 1])) j = m;\n      else i = m;\n    }\n    return i;\n  }\n  /* else must find a boundary in hash part */\n  else if (t->node == dummynode)  /* hash part is empty? */\n    return j;  /* that is easy... */\n  else return unbound_search(t, j);\n}\n\n\n\n#if defined(LUA_DEBUG)\n\nNode *luaH_mainposition (const Table *t, const TValue *key) {\n  return mainposition(t, key);\n}\n\nint luaH_isdummy (Node *n) { return n == dummynode; }\n\n#endif\n"
  },
  {
    "path": "src/ltable.h",
    "content": "/*\n** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua tables (hash)\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltable_h\n#define ltable_h\n\n#include \"lobject.h\"\n\n\n#define gnode(t,i)\t(&(t)->node[i])\n#define gkey(n)\t\t(&(n)->i_key.nk)\n#define gval(n)\t\t(&(n)->i_val)\n#define gnext(n)\t((n)->i_key.nk.next)\n\n#define key2tval(n)\t(&(n)->i_key.tvk)\n\n\nLUAI_FUNC const TValue *luaH_getnum (Table *t, int key);\nLUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);\nLUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);\nLUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);\nLUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);\nLUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);\nLUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash);\nLUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);\nLUAI_FUNC void luaH_free (lua_State *L, Table *t);\nLUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);\nLUAI_FUNC int luaH_getn (Table *t);\n\n\n#if defined(LUA_DEBUG)\nLUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);\nLUAI_FUNC int luaH_isdummy (Node *n);\n#endif\n\n\n#endif\n"
  },
  {
    "path": "src/ltablib.c",
    "content": "/*\n** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $\n** Library for Table Manipulation\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stddef.h>\n\n#define ltablib_c\n#define LUA_LIB\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n#define aux_getn(L,n)\t(luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))\n\n\nstatic int foreachi (lua_State *L) {\n  int i;\n  int n = aux_getn(L, 1);\n  luaL_checktype(L, 2, LUA_TFUNCTION);\n  for (i=1; i <= n; i++) {\n    lua_pushvalue(L, 2);  /* function */\n    lua_pushinteger(L, i);  /* 1st argument */\n    lua_rawgeti(L, 1, i);  /* 2nd argument */\n    lua_call(L, 2, 1);\n    if (!lua_isnil(L, -1))\n      return 1;\n    lua_pop(L, 1);  /* remove nil result */\n  }\n  return 0;\n}\n\n\nstatic int foreach (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n  luaL_checktype(L, 2, LUA_TFUNCTION);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pushvalue(L, 2);  /* function */\n    lua_pushvalue(L, -3);  /* key */\n    lua_pushvalue(L, -3);  /* value */\n    lua_call(L, 2, 1);\n    if (!lua_isnil(L, -1))\n      return 1;\n    lua_pop(L, 2);  /* remove value and result */\n  }\n  return 0;\n}\n\n\nstatic int maxn (lua_State *L) {\n  lua_Number max = 0;\n  luaL_checktype(L, 1, LUA_TTABLE);\n  lua_pushnil(L);  /* first key */\n  while (lua_next(L, 1)) {\n    lua_pop(L, 1);  /* remove value */\n    if (lua_type(L, -1) == LUA_TNUMBER) {\n      lua_Number v = lua_tonumber(L, -1);\n      if (v > max) max = v;\n    }\n  }\n  lua_pushnumber(L, max);\n  return 1;\n}\n\n\nstatic int getn (lua_State *L) {\n  lua_pushinteger(L, aux_getn(L, 1));\n  return 1;\n}\n\n\nstatic int setn (lua_State *L) {\n  luaL_checktype(L, 1, LUA_TTABLE);\n#ifndef luaL_setn\n  luaL_setn(L, 1, luaL_checkint(L, 2));\n#else\n  luaL_error(L, LUA_QL(\"setn\") \" is obsolete\");\n#endif\n  lua_pushvalue(L, 1);\n  return 1;\n}\n\n\nstatic int tinsert (lua_State *L) {\n  int e = aux_getn(L, 1) + 1;  /* first empty element */\n  int pos;  /* where to insert new element */\n  switch (lua_gettop(L)) {\n    case 2: {  /* called with only 2 arguments */\n      pos = e;  /* insert new element at the end */\n      break;\n    }\n    case 3: {\n      int i;\n      pos = luaL_checkint(L, 2);  /* 2nd argument is the position */\n      if (pos > e) e = pos;  /* `grow' array if necessary */\n      for (i = e; i > pos; i--) {  /* move up elements */\n        lua_rawgeti(L, 1, i-1);\n        lua_rawseti(L, 1, i);  /* t[i] = t[i-1] */\n      }\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to \" LUA_QL(\"insert\"));\n    }\n  }\n  luaL_setn(L, 1, e);  /* new size */\n  lua_rawseti(L, 1, pos);  /* t[pos] = v */\n  return 0;\n}\n\n\nstatic int tremove (lua_State *L) {\n  int e = aux_getn(L, 1);\n  int pos = luaL_optint(L, 2, e);\n  if (!(1 <= pos && pos <= e))  /* position is outside bounds? */\n   return 0;  /* nothing to remove */\n  luaL_setn(L, 1, e - 1);  /* t.n = n-1 */\n  lua_rawgeti(L, 1, pos);  /* result = t[pos] */\n  for ( ;pos<e; pos++) {\n    lua_rawgeti(L, 1, pos+1);\n    lua_rawseti(L, 1, pos);  /* t[pos] = t[pos+1] */\n  }\n  lua_pushnil(L);\n  lua_rawseti(L, 1, e);  /* t[e] = nil */\n  return 1;\n}\n\n\nstatic void addfield (lua_State *L, luaL_Buffer *b, int i) {\n  lua_rawgeti(L, 1, i);\n  if (!lua_isstring(L, -1))\n    luaL_error(L, \"invalid value (%s) at index %d in table for \"\n                  LUA_QL(\"concat\"), luaL_typename(L, -1), i);\n    luaL_addvalue(b);\n}\n\n\nstatic int tconcat (lua_State *L) {\n  luaL_Buffer b;\n  size_t lsep;\n  int i, last;\n  const char *sep = luaL_optlstring(L, 2, \"\", &lsep);\n  luaL_checktype(L, 1, LUA_TTABLE);\n  i = luaL_optint(L, 3, 1);\n  last = luaL_opt(L, luaL_checkint, 4, luaL_getn(L, 1));\n  luaL_buffinit(L, &b);\n  for (; i < last; i++) {\n    addfield(L, &b, i);\n    luaL_addlstring(&b, sep, lsep);\n  }\n  if (i == last)  /* add last value (if interval was not empty) */\n    addfield(L, &b, i);\n  luaL_pushresult(&b);\n  return 1;\n}\n\n\n\n/*\n** {======================================================\n** Quicksort\n** (based on `Algorithms in MODULA-3', Robert Sedgewick;\n**  Addison-Wesley, 1993.)\n*/\n\n\nstatic void set2 (lua_State *L, int i, int j) {\n  lua_rawseti(L, 1, i);\n  lua_rawseti(L, 1, j);\n}\n\nstatic int sort_comp (lua_State *L, int a, int b) {\n  if (!lua_isnil(L, 2)) {  /* function? */\n    int res;\n    lua_pushvalue(L, 2);\n    lua_pushvalue(L, a-1);  /* -1 to compensate function */\n    lua_pushvalue(L, b-2);  /* -2 to compensate function and `a' */\n    lua_call(L, 2, 1);\n    res = lua_toboolean(L, -1);\n    lua_pop(L, 1);\n    return res;\n  }\n  else  /* a < b? */\n    return lua_lessthan(L, a, b);\n}\n\nstatic void auxsort (lua_State *L, int l, int u) {\n  while (l < u) {  /* for tail recursion */\n    int i, j;\n    /* sort elements a[l], a[(l+u)/2] and a[u] */\n    lua_rawgeti(L, 1, l);\n    lua_rawgeti(L, 1, u);\n    if (sort_comp(L, -1, -2))  /* a[u] < a[l]? */\n      set2(L, l, u);  /* swap a[l] - a[u] */\n    else\n      lua_pop(L, 2);\n    if (u-l == 1) break;  /* only 2 elements */\n    i = (l+u)/2;\n    lua_rawgeti(L, 1, i);\n    lua_rawgeti(L, 1, l);\n    if (sort_comp(L, -2, -1))  /* a[i]<a[l]? */\n      set2(L, i, l);\n    else {\n      lua_pop(L, 1);  /* remove a[l] */\n      lua_rawgeti(L, 1, u);\n      if (sort_comp(L, -1, -2))  /* a[u]<a[i]? */\n        set2(L, i, u);\n      else\n        lua_pop(L, 2);\n    }\n    if (u-l == 2) break;  /* only 3 elements */\n    lua_rawgeti(L, 1, i);  /* Pivot */\n    lua_pushvalue(L, -1);\n    lua_rawgeti(L, 1, u-1);\n    set2(L, i, u-1);\n    /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */\n    i = l; j = u-1;\n    for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */\n      /* repeat ++i until a[i] >= P */\n      while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {\n        if (i>u) luaL_error(L, \"invalid order function for sorting\");\n        lua_pop(L, 1);  /* remove a[i] */\n      }\n      /* repeat --j until a[j] <= P */\n      while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {\n        if (j<l) luaL_error(L, \"invalid order function for sorting\");\n        lua_pop(L, 1);  /* remove a[j] */\n      }\n      if (j<i) {\n        lua_pop(L, 3);  /* pop pivot, a[i], a[j] */\n        break;\n      }\n      set2(L, i, j);\n    }\n    lua_rawgeti(L, 1, u-1);\n    lua_rawgeti(L, 1, i);\n    set2(L, u-1, i);  /* swap pivot (a[u-1]) with a[i] */\n    /* a[l..i-1] <= a[i] == P <= a[i+1..u] */\n    /* adjust so that smaller half is in [j..i] and larger one in [l..u] */\n    if (i-l < u-i) {\n      j=l; i=i-1; l=i+2;\n    }\n    else {\n      j=i+1; i=u; u=j-2;\n    }\n    auxsort(L, j, i);  /* call recursively the smaller one */\n  }  /* repeat the routine for the larger one */\n}\n\nstatic int sort (lua_State *L) {\n  int n = aux_getn(L, 1);\n  luaL_checkstack(L, 40, \"\");  /* assume array is smaller than 2^40 */\n  if (!lua_isnoneornil(L, 2))  /* is there a 2nd argument? */\n    luaL_checktype(L, 2, LUA_TFUNCTION);\n  lua_settop(L, 2);  /* make sure there is two arguments */\n  auxsort(L, 1, n);\n  return 0;\n}\n\n/* }====================================================== */\n\n\nstatic const luaL_Reg tab_funcs[] = {\n  {\"concat\", tconcat},\n  {\"foreach\", foreach},\n  {\"foreachi\", foreachi},\n  {\"getn\", getn},\n  {\"maxn\", maxn},\n  {\"insert\", tinsert},\n  {\"remove\", tremove},\n  {\"setn\", setn},\n  {\"sort\", sort},\n  {NULL, NULL}\n};\n\n\nLUALIB_API int luaopen_table (lua_State *L) {\n  luaL_register(L, LUA_TABLIBNAME, tab_funcs);\n  return 1;\n}\n\n"
  },
  {
    "path": "src/ltm.c",
    "content": "/*\n** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define ltm_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"lobject.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n\n\n\nconst char *const luaT_typenames[] = {\n  \"nil\", \"boolean\", \"userdata\", \"number\",\n  \"string\", \"table\", \"function\", \"userdata\", \"thread\",\n  \"proto\", \"upval\"\n};\n\n\nvoid luaT_init (lua_State *L) {\n  static const char *const luaT_eventname[] = {  /* ORDER TM */\n    \"__index\", \"__newindex\",\n    \"__gc\", \"__mode\", \"__eq\",\n    \"__add\", \"__sub\", \"__mul\", \"__div\", \"__mod\",\n    \"__pow\", \"__unm\", \"__len\", \"__lt\", \"__le\",\n    \"__concat\", \"__call\"\n  };\n  int i;\n  for (i=0; i<TM_N; i++) {\n    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);\n    luaS_fix(G(L)->tmname[i]);  /* never collect these names */\n  }\n}\n\n\n/*\n** function to be used with macro \"fasttm\": optimized for absence of\n** tag methods\n*/\nconst TValue *luaT_gettm (Table *events, TMS event, TString *ename) {\n  const TValue *tm = luaH_getstr(events, ename);\n  lua_assert(event <= TM_EQ);\n  if (ttisnil(tm)) {  /* no tag method? */\n    events->flags |= cast_byte(1u<<event);  /* cache this fact */\n    return NULL;\n  }\n  else return tm;\n}\n\n\nconst TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {\n  Table *mt;\n  switch (ttype(o)) {\n    case LUA_TTABLE:\n      mt = hvalue(o)->metatable;\n      break;\n    case LUA_TUSERDATA:\n      mt = uvalue(o)->metatable;\n      break;\n    default:\n      mt = G(L)->mt[ttype(o)];\n  }\n  return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);\n}\n\n"
  },
  {
    "path": "src/ltm.h",
    "content": "/*\n** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $\n** Tag methods\n** See Copyright Notice in lua.h\n*/\n\n#ifndef ltm_h\n#define ltm_h\n\n\n#include \"lobject.h\"\n\n\n/*\n* WARNING: if you change the order of this enumeration,\n* grep \"ORDER TM\"\n*/\ntypedef enum {\n  TM_INDEX,\n  TM_NEWINDEX,\n  TM_GC,\n  TM_MODE,\n  TM_EQ,  /* last tag method with `fast' access */\n  TM_ADD,\n  TM_SUB,\n  TM_MUL,\n  TM_DIV,\n  TM_MOD,\n  TM_POW,\n  TM_UNM,\n  TM_LEN,\n  TM_LT,\n  TM_LE,\n  TM_CONCAT,\n  TM_CALL,\n  TM_N\t\t/* number of elements in the enum */\n} TMS;\n\n\n\n#define gfasttm(g,et,e) ((et) == NULL ? NULL : \\\n  ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))\n\n#define fasttm(l,et,e)\tgfasttm(G(l), et, e)\n\nLUAI_DATA const char *const luaT_typenames[];\n\n\nLUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);\nLUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,\n                                                       TMS event);\nLUAI_FUNC void luaT_init (lua_State *L);\n\n#endif\n"
  },
  {
    "path": "src/lua.c",
    "content": "/*\n** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $\n** Lua stand-alone interpreter\n** See Copyright Notice in lua.h\n*/\n\n\n#include <signal.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lua_c\n\n#include \"lua.h\"\n\n#include \"lauxlib.h\"\n#include \"lualib.h\"\n\n\n\nstatic lua_State *globalL = NULL;\n\nstatic const char *progname = LUA_PROGNAME;\n\n\n\nstatic void lstop (lua_State *L, lua_Debug *ar) {\n  (void)ar;  /* unused arg. */\n  lua_sethook(L, NULL, 0, 0);\n  luaL_error(L, \"interrupted!\");\n}\n\n\nstatic void laction (int i) {\n  signal(i, SIG_DFL); /* if another SIGINT happens before lstop,\n                              terminate process (default action) */\n  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);\n}\n\n\nstatic void print_usage (void) {\n  fprintf(stderr,\n  \"usage: %s [options] [script [args]].\\n\"\n  \"Available options are:\\n\"\n  \"  -e stat  execute string \" LUA_QL(\"stat\") \"\\n\"\n  \"  -l name  require library \" LUA_QL(\"name\") \"\\n\"\n  \"  -m limit set memory limit. (units are in Kbytes)\\n\"\n  \"  -i       enter interactive mode after executing \" LUA_QL(\"script\") \"\\n\"\n  \"  -v       show version information\\n\"\n  \"  --       stop handling options\\n\"\n  \"  -        execute stdin and stop handling options\\n\"\n  ,\n  progname);\n  fflush(stderr);\n}\n\n\nstatic void l_message (const char *pname, const char *msg) {\n  if (pname) fprintf(stderr, \"%s: \", pname);\n  fprintf(stderr, \"%s\\n\", msg);\n  fflush(stderr);\n}\n\n\nstatic int report (lua_State *L, int status) {\n  if (status && !lua_isnil(L, -1)) {\n    const char *msg = lua_tostring(L, -1);\n    if (msg == NULL) msg = \"(error object is not a string)\";\n    l_message(progname, msg);\n    lua_pop(L, 1);\n  }\n  return status;\n}\n\n\nstatic int traceback (lua_State *L) {\n  if (!lua_isstring(L, 1))  /* 'message' not a string? */\n    return 1;  /* keep it intact */\n  lua_getfield(L, LUA_GLOBALSINDEX, \"debug\");\n  if (!lua_istable(L, -1)) {\n    lua_pop(L, 1);\n    return 1;\n  }\n  lua_getfield(L, -1, \"traceback\");\n  if (!lua_isfunction(L, -1)) {\n    lua_pop(L, 2);\n    return 1;\n  }\n  lua_pushvalue(L, 1);  /* pass error message */\n  lua_pushinteger(L, 2);  /* skip this function and traceback */\n  lua_call(L, 2, 1);  /* call debug.traceback */\n  return 1;\n}\n\n\nstatic int docall (lua_State *L, int narg, int clear) {\n  int status;\n  int base = lua_gettop(L) - narg;  /* function index */\n  lua_pushcfunction(L, traceback);  /* push traceback function */\n  lua_insert(L, base);  /* put it under chunk and args */\n  signal(SIGINT, laction);\n  status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);\n  signal(SIGINT, SIG_DFL);\n  lua_remove(L, base);  /* remove traceback function */\n  /* force a complete garbage collection in case of errors */\n  if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);\n  return status;\n}\n\n\nstatic void print_version (void) {\n  l_message(NULL, LUA_RELEASE \"  \" LUA_COPYRIGHT);\n}\n\n\nstatic int getargs (lua_State *L, char **argv, int n) {\n  int narg;\n  int i;\n  int argc = 0;\n  while (argv[argc]) argc++;  /* count total number of arguments */\n  narg = argc - (n + 1);  /* number of arguments to the script */\n  luaL_checkstack(L, narg + 3, \"too many arguments to script\");\n  for (i=n+1; i < argc; i++)\n    lua_pushstring(L, argv[i]);\n  lua_createtable(L, narg, n + 1);\n  for (i=0; i < argc; i++) {\n    lua_pushstring(L, argv[i]);\n    lua_rawseti(L, -2, i - n);\n  }\n  return narg;\n}\n\n\nstatic int dofile (lua_State *L, const char *name) {\n  int status = luaL_loadfile(L, name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\n\nstatic int dostring (lua_State *L, const char *s, const char *name) {\n  int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);\n  return report(L, status);\n}\n\n\nstatic int dolibrary (lua_State *L, const char *name) {\n  lua_getglobal(L, \"require\");\n  lua_pushstring(L, name);\n  return report(L, docall(L, 1, 1));\n}\n\n\nstatic const char *get_prompt (lua_State *L, int firstline) {\n  const char *p;\n  lua_getfield(L, LUA_GLOBALSINDEX, firstline ? \"_PROMPT\" : \"_PROMPT2\");\n  p = lua_tostring(L, -1);\n  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);\n  lua_pop(L, 1);  /* remove global */\n  return p;\n}\n\n\nstatic int incomplete (lua_State *L, int status) {\n  if (status == LUA_ERRSYNTAX) {\n    size_t lmsg;\n    const char *msg = lua_tolstring(L, -1, &lmsg);\n    const char *tp = msg + lmsg - (sizeof(LUA_QL(\"<eof>\")) - 1);\n    if (strstr(msg, LUA_QL(\"<eof>\")) == tp) {\n      lua_pop(L, 1);\n      return 1;\n    }\n  }\n  return 0;  /* else... */\n}\n\n\nstatic int pushline (lua_State *L, int firstline) {\n  char buffer[LUA_MAXINPUT];\n  char *b = buffer;\n  size_t l;\n  const char *prmt = get_prompt(L, firstline);\n  if (lua_readline(L, b, prmt) == 0)\n    return 0;  /* no input */\n  l = strlen(b);\n  if (l > 0 && b[l-1] == '\\n')  /* line ends with newline? */\n    b[l-1] = '\\0';  /* remove it */\n  if (firstline && b[0] == '=')  /* first line starts with `=' ? */\n    lua_pushfstring(L, \"return %s\", b+1);  /* change it to `return' */\n  else\n    lua_pushstring(L, b);\n  lua_freeline(L, b);\n  return 1;\n}\n\n\nstatic int loadline (lua_State *L) {\n  int status;\n  lua_settop(L, 0);\n  if (!pushline(L, 1))\n    return -1;  /* no input */\n  for (;;) {  /* repeat until gets a complete line */\n    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), \"=stdin\");\n    if (!incomplete(L, status)) break;  /* cannot try to add lines? */\n    if (!pushline(L, 0))  /* no more input? */\n      return -1;\n    lua_pushliteral(L, \"\\n\");  /* add a new line... */\n    lua_insert(L, -2);  /* ...between the two lines */\n    lua_concat(L, 3);  /* join them */\n  }\n  lua_saveline(L, 1);\n  lua_remove(L, 1);  /* remove line */\n  return status;\n}\n\n\nstatic void dotty (lua_State *L) {\n  int status;\n  const char *oldprogname = progname;\n  progname = NULL;\n  while ((status = loadline(L)) != -1) {\n    if (status == 0) status = docall(L, 0, 0);\n    report(L, status);\n    if (status == 0 && lua_gettop(L) > 0) {  /* any result to print? */\n      lua_getglobal(L, \"print\");\n      lua_insert(L, 1);\n      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)\n        l_message(progname, lua_pushfstring(L,\n                               \"error calling \" LUA_QL(\"print\") \" (%s)\",\n                               lua_tostring(L, -1)));\n    }\n  }\n  lua_settop(L, 0);  /* clear stack */\n  fputs(\"\\n\", stdout);\n  fflush(stdout);\n  progname = oldprogname;\n}\n\n\nstatic int handle_script (lua_State *L, char **argv, int n) {\n  int status;\n  const char *fname;\n  int narg = getargs(L, argv, n);  /* collect arguments */\n  lua_setglobal(L, \"arg\");\n  fname = argv[n];\n  if (strcmp(fname, \"-\") == 0 && strcmp(argv[n-1], \"--\") != 0) \n    fname = NULL;  /* stdin */\n  status = luaL_loadfile(L, fname);\n  lua_insert(L, -(narg+1));\n  if (status == 0)\n    status = docall(L, narg, 0);\n  else\n    lua_pop(L, narg);      \n  return report(L, status);\n}\n\n\n/* check that argument has no extra characters at the end */\n#define notail(x)\t{if ((x)[2] != '\\0') return -1;}\n\n\nstatic int collectargs (char **argv, int *pi, int *pv, int *pe) {\n  int i;\n  for (i = 1; argv[i] != NULL; i++) {\n    if (argv[i][0] != '-')  /* not an option? */\n        return i;\n    switch (argv[i][1]) {  /* option */\n      case '-':\n        notail(argv[i]);\n        return (argv[i+1] != NULL ? i+1 : 0);\n      case '\\0':\n        return i;\n      case 'i':\n        notail(argv[i]);\n        *pi = 1;  /* go through */\n      case 'v':\n        notail(argv[i]);\n        *pv = 1;\n        break;\n      case 'e':\n        *pe = 1;  /* go through */\n      case 'm':   /* go through */\n      case 'l':\n        if (argv[i][2] == '\\0') {\n          i++;\n          if (argv[i] == NULL) return -1;\n        }\n        break;\n      default: return -1;  /* invalid option */\n    }\n  }\n  return 0;\n}\n\n\nstatic int runargs (lua_State *L, char **argv, int n) {\n  int i;\n  for (i = 1; i < n; i++) {\n    if (argv[i] == NULL) continue;\n    lua_assert(argv[i][0] == '-');\n    switch (argv[i][1]) {  /* option */\n      case 'e': {\n        const char *chunk = argv[i] + 2;\n        if (*chunk == '\\0') chunk = argv[++i];\n        lua_assert(chunk != NULL);\n        if (dostring(L, chunk, \"=(command line)\") != 0)\n          return 1;\n        break;\n      }\n      case 'm': {\n        const char *limit = argv[i] + 2;\n        int memlimit=0;\n        if (*limit == '\\0') limit = argv[++i];\n        lua_assert(limit != NULL);\n        memlimit = atoi(limit);\n        lua_gc(L, LUA_GCSETMEMLIMIT, memlimit);\n        break;\n      }\n      case 'l': {\n        const char *filename = argv[i] + 2;\n        if (*filename == '\\0') filename = argv[++i];\n        lua_assert(filename != NULL);\n        if (dolibrary(L, filename))\n          return 1;  /* stop if file fails */\n        break;\n      }\n      default: break;\n    }\n  }\n  return 0;\n}\n\n\nstatic int handle_luainit (lua_State *L) {\n  const char *init = getenv(LUA_INIT);\n  if (init == NULL) return 0;  /* status OK */\n  else if (init[0] == '@')\n    return dofile(L, init+1);\n  else\n    return dostring(L, init, \"=\" LUA_INIT);\n}\n\n\nstruct Smain {\n  int argc;\n  char **argv;\n  int status;\n};\n\n\nstatic int pmain (lua_State *L) {\n  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);\n  char **argv = s->argv;\n  int script;\n  int has_i = 0, has_v = 0, has_e = 0;\n  globalL = L;\n  if (argv[0] && argv[0][0]) progname = argv[0];\n  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */\n  luaL_openlibs(L);  /* open libraries */\n  lua_gc(L, LUA_GCRESTART, 0);\n  s->status = handle_luainit(L);\n  if (s->status != 0) return 0;\n  script = collectargs(argv, &has_i, &has_v, &has_e);\n  if (script < 0) {  /* invalid args? */\n    print_usage();\n    s->status = 1;\n    return 0;\n  }\n  if (has_v) print_version();\n  s->status = runargs(L, argv, (script > 0) ? script : s->argc);\n  if (s->status != 0) return 0;\n  if (script)\n    s->status = handle_script(L, argv, script);\n  if (s->status != 0) return 0;\n  if (has_i)\n    dotty(L);\n  else if (script == 0 && !has_e && !has_v) {\n    if (lua_stdin_is_tty()) {\n      print_version();\n      dotty(L);\n    }\n    else dofile(L, NULL);  /* executes stdin as a file */\n  }\n  return 0;\n}\n\n\nint main (int argc, char **argv) {\n  int status;\n  struct Smain s;\n  lua_State *L = lua_open();  /* create state */\n  if (L == NULL) {\n    l_message(argv[0], \"cannot create state: not enough memory\");\n    return EXIT_FAILURE;\n  }\n  s.argc = argc;\n  s.argv = argv;\n  status = lua_cpcall(L, &pmain, &s);\n  report(L, status);\n  lua_close(L);\n  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;\n}\n\n"
  },
  {
    "path": "src/lua.h",
    "content": "/*\n** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $\n** Lua - An Extensible Extension Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION\t\"Lua 5.1\"\n#define LUA_RELEASE\t\"Lua 5.1.4\"\n#define LUA_VERSION_NUM\t501\n#define LUA_COPYRIGHT\t\"Copyright (C) 1994-2008 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS \t\"R. Ierusalimschy, L. H. de Figueiredo & W. Celes\"\n\n\n/* mark for precompiled code (`<esc>Lua') */\n#define\tLUA_SIGNATURE\t\"\\033Lua\"\n\n/* option for multiple returns in `lua_pcall' and `lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** pseudo-indices\n*/\n#define LUA_REGISTRYINDEX\t(-10000)\n#define LUA_ENVIRONINDEX\t(-10001)\n#define LUA_GLOBALSINDEX\t(-10002)\n#define lua_upvalueindex(i)\t(LUA_GLOBALSINDEX-(i))\n\n\n/* thread status; 0 is OK */\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRERR\t5\n\n\ntypedef struct lua_State lua_State;\ntypedef struct lua_TValue TValue;\ntypedef TValue *StkId;  /* index to stack elements */\n\ntypedef int (*lua_CFunction) (lua_State *L);\ntypedef int (*lua_precall) (lua_State *L, StkId func, int nresults);\n\n\n/*\n** functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);\n\n\n/*\n** prototype for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_remove) (lua_State *L, int idx);\nLUA_API void  (lua_insert) (lua_State *L, int idx);\nLUA_API void  (lua_replace) (lua_State *L, int idx);\nLUA_API int   (lua_checkstack) (lua_State *L, int sz);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);\n\nLUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);\nLUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_objlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void  (lua_pushnil) (lua_State *L);\nLUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);\nLUA_API void  (lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, const void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API void  (lua_gettable) (lua_State *L, int idx);\nLUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawget) (lua_State *L, int idx);\nLUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_getfenv) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API int   (lua_setfenv) (lua_State *L, int idx);\n\n\n/*\n** `load' and `call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);\nLUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);\nLUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                                        const char *chunkname);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yield) (lua_State *L, int nresults);\nLUA_API int  (lua_resume) (lua_State *L, int narg);\nLUA_API int  (lua_status) (lua_State *L);\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n#define LUA_GCSETMEMLIMIT\t8\n#define LUA_GCGETMEMLIMIT\t9\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/* \n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_strlen(L,i)\t\tlua_objlen(L, (i))\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\t\\\n\tlua_pushlstring(L, \"\" s, (sizeof(s)/sizeof(char))-1)\n\n#define lua_setglobal(L,s)\tlua_setfield(L, LUA_GLOBALSINDEX, (s))\n#define lua_getglobal(L,s)\tlua_getfield(L, LUA_GLOBALSINDEX, (s))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n\n/*\n** compatibility macros and functions\n*/\n\n#define lua_open()\tluaL_newstate()\n\n#define lua_getregistry(L)\tlua_pushvalue(L, LUA_REGISTRYINDEX)\n\n#define lua_getgccount(L)\tlua_gc(L, LUA_GCCOUNT, 0)\n\n#define lua_Chunkreader\t\tlua_Reader\n#define lua_Chunkwriter\t\tlua_Writer\n\n\n/* hack */\nLUA_API void lua_setlevel\t(lua_State *from, lua_State *to);\n\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILRET 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debuger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);\n\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook lua_gethook (lua_State *L);\nLUA_API int lua_gethookmask (lua_State *L);\nLUA_API int lua_gethookcount (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) `global', `local', `field', `method' */\n  const char *what;\t/* (S) `Lua', `C', `main', `tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int nups;\t\t/* (u) number of upvalues */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  int i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "src/luac.c",
    "content": "/*\n** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $\n** Lua compiler (saves bytecodes to files; also list bytecodes)\n** See Copyright Notice in lua.h\n*/\n\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"lua.h\"\n#include \"lauxlib.h\"\n\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n\n#define PROGNAME\t\"luac\"\t\t/* default program name */\n#define\tOUTPUT\t\tPROGNAME \".out\"\t/* default output file */\n\nstatic int listing=0;\t\t\t/* list bytecodes? */\nstatic int dumping=1;\t\t\t/* dump bytecodes? */\nstatic int stripping=0;\t\t\t/* strip debug information? */\nstatic char Output[]={ OUTPUT };\t/* default output file name */\nstatic const char* output=Output;\t/* actual output file name */\nstatic const char* progname=PROGNAME;\t/* actual program name */\n\nstatic void fatal(const char* message)\n{\n fprintf(stderr,\"%s: %s\\n\",progname,message);\n exit(EXIT_FAILURE);\n}\n\nstatic void cannot(const char* what)\n{\n fprintf(stderr,\"%s: cannot %s %s: %s\\n\",progname,what,output,strerror(errno));\n exit(EXIT_FAILURE);\n}\n\nstatic void usage(const char* message)\n{\n if (*message=='-')\n  fprintf(stderr,\"%s: unrecognized option \" LUA_QS \"\\n\",progname,message);\n else\n  fprintf(stderr,\"%s: %s\\n\",progname,message);\n fprintf(stderr,\n \"usage: %s [options] [filenames].\\n\"\n \"Available options are:\\n\"\n \"  -        process stdin\\n\"\n \"  -l       list\\n\"\n \"  -o name  output to file \" LUA_QL(\"name\") \" (default is \\\"%s\\\")\\n\"\n \"  -p       parse only\\n\"\n \"  -s       strip debug information\\n\"\n \"  -v       show version information\\n\"\n \"  --       stop handling options\\n\",\n progname,Output);\n exit(EXIT_FAILURE);\n}\n\n#define\tIS(s)\t(strcmp(argv[i],s)==0)\n\nstatic int doargs(int argc, char* argv[])\n{\n int i;\n int version=0;\n if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];\n for (i=1; i<argc; i++)\n {\n  if (*argv[i]!='-')\t\t\t/* end of options; keep it */\n   break;\n  else if (IS(\"--\"))\t\t\t/* end of options; skip it */\n  {\n   ++i;\n   if (version) ++version;\n   break;\n  }\n  else if (IS(\"-\"))\t\t\t/* end of options; use stdin */\n   break;\n  else if (IS(\"-l\"))\t\t\t/* list */\n   ++listing;\n  else if (IS(\"-o\"))\t\t\t/* output file */\n  {\n   output=argv[++i];\n   if (output==NULL || *output==0) usage(LUA_QL(\"-o\") \" needs argument\");\n   if (IS(\"-\")) output=NULL;\n  }\n  else if (IS(\"-p\"))\t\t\t/* parse only */\n   dumping=0;\n  else if (IS(\"-s\"))\t\t\t/* strip debug information */\n   stripping=1;\n  else if (IS(\"-v\"))\t\t\t/* show version */\n   ++version;\n  else\t\t\t\t\t/* unknown option */\n   usage(argv[i]);\n }\n if (i==argc && (listing || !dumping))\n {\n  dumping=0;\n  argv[--i]=Output;\n }\n if (version)\n {\n  printf(\"%s  %s\\n\",LUA_RELEASE,LUA_COPYRIGHT);\n  if (version==argc-1) exit(EXIT_SUCCESS);\n }\n return i;\n}\n\n#define toproto(L,i) (clvalue(L->top+(i))->l.p)\n\nstatic const Proto* combine(lua_State* L, int n)\n{\n if (n==1)\n  return toproto(L,-1);\n else\n {\n  int i,pc;\n  Proto* f=luaF_newproto(L);\n  setptvalue2s(L,L->top,f); incr_top(L);\n  f->source=luaS_newliteral(L,\"=(\" PROGNAME \")\");\n  f->maxstacksize=1;\n  pc=2*n+1;\n  f->code=luaM_newvector(L,pc,Instruction);\n  f->sizecode=pc;\n  f->p=luaM_newvector(L,n,Proto*);\n  f->sizep=n;\n  pc=0;\n  for (i=0; i<n; i++)\n  {\n   f->p[i]=toproto(L,i-n-1);\n   f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i);\n   f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);\n  }\n  f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);\n  return f;\n }\n}\n\nstatic int writer(lua_State* L, const void* p, size_t size, void* u)\n{\n UNUSED(L);\n return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);\n}\n\nstruct Smain {\n int argc;\n char** argv;\n};\n\nstatic int pmain(lua_State* L)\n{\n struct Smain* s = (struct Smain*)lua_touserdata(L, 1);\n int argc=s->argc;\n char** argv=s->argv;\n const Proto* f;\n int i;\n if (!lua_checkstack(L,argc)) fatal(\"too many input files\");\n for (i=0; i<argc; i++)\n {\n  const char* filename=IS(\"-\") ? NULL : argv[i];\n  if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));\n }\n f=combine(L,argc);\n if (listing) luaU_print(f,listing>1);\n if (dumping)\n {\n  FILE* D= (output==NULL) ? stdout : fopen(output,\"wb\");\n  if (D==NULL) cannot(\"open\");\n  lua_lock(L);\n  luaU_dump(L,f,writer,D,stripping);\n  lua_unlock(L);\n  if (ferror(D)) cannot(\"write\");\n  if (fclose(D)) cannot(\"close\");\n }\n return 0;\n}\n\nint main(int argc, char* argv[])\n{\n lua_State* L;\n struct Smain s;\n int i=doargs(argc,argv);\n argc-=i; argv+=i;\n if (argc<=0) usage(\"no input files given\");\n L=lua_open();\n if (L==NULL) fatal(\"not enough memory for state\");\n s.argc=argc;\n s.argv=argv;\n if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));\n lua_close(L);\n return EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/luaconf.h",
    "content": "/*\n** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lconfig_h\n#define lconfig_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ==================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n@@ LUA_ANSI controls the use of non-ansi features.\n** CHANGE it (define it) if you want Lua to avoid the use of any\n** non-ansi feature or library.\n*/\n#if defined(__STRICT_ANSI__)\n#define LUA_ANSI\n#endif\n\n\n#if !defined(LUA_ANSI) && defined(_WIN32)\n#define LUA_WIN\n#endif\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_DL_DYLD\t\t/* does not need extra library */\n#endif\n\n\n\n/*\n@@ LUA_USE_POSIX includes all functionallity listed as X/Open System\n@* Interfaces Extension (XSI).\n** CHANGE it (define it) if your system is XSI compatible.\n*/\n#if defined(LUA_USE_POSIX)\n#define LUA_USE_MKSTEMP\n#define LUA_USE_ISATTY\n#define LUA_USE_POPEN\n#define LUA_USE_ULONGJMP\n#endif\n\n\n/*\n@@ LUA_PATH and LUA_CPATH are the names of the environment variables that\n@* Lua check to set its paths.\n@@ LUA_INIT is the name of the environment variable that Lua\n@* checks for initialization code.\n** CHANGE them if you want different names.\n*/\n#define LUA_PATH        \"LUA_PATH\"\n#define LUA_CPATH       \"LUA_CPATH\"\n#define LUA_INIT\t\"LUA_INIT\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n@* Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n@* C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#if defined(_WIN32)\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\t\".\\\\?.lua;\"  LUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\t             LUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\".\\\\?.dll;\"  LUA_CDIR\"?.dll;\" LUA_CDIR\"loadall.dll\"\n\n#else\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/5.1/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/5.1/\"\n#define LUA_PATH_DEFAULT  \\\n\t\t\"./?.lua;\"  LUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\t            LUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\"./?.so;\"  LUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so\"\n#endif\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n\n/*\n@@ LUA_PATHSEP is the character that separates templates in a path.\n@@ LUA_PATH_MARK is the string that marks the substitution points in a\n@* template.\n@@ LUA_EXECDIR in a Windows path is replaced by the executable's\n@* directory.\n@@ LUA_IGMARK is a mark to ignore all before it when bulding the\n@* luaopen_ function name.\n** CHANGE them if for some reason your system cannot use those\n** characters. (E.g., if one of those characters is a common character\n** in file/directory names.) Probably you do not need to change them.\n*/\n#define LUA_PATHSEP\t\";\"\n#define LUA_PATH_MARK\t\"?\"\n#define LUA_EXECDIR\t\"!\"\n#define LUA_IGMARK\t\"-\"\n\n\n/*\n@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.\n** CHANGE that if ptrdiff_t is not adequate on your machine. (On most\n** machines, ptrdiff_t gives a good choice between int or long.)\n*/\n#define LUA_INTEGER\tptrdiff_t\n\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all standard library functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\n#define LUA_API __declspec(dllexport)\n#else\n#define LUA_API __declspec(dllimport)\n#endif\n\n#else\n\n#define LUA_API\t\textern\n\n#endif\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n@* exported to outside modules.\n@@ LUAI_DATA is a mark for all extern (const) variables that are not to\n@* be exported to outside modules.\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library.\n*/\n#if defined(luaall_c)\n#define LUAI_FUNC\tstatic\n#define LUAI_DATA\t/* empty */\n\n#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n      defined(__ELF__)\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#define LUAI_DATA\tLUAI_FUNC\n\n#else\n#define LUAI_FUNC\textern\n#define LUAI_DATA\textern\n#endif\n\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** CHANGE it if you want a different appearance.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@* of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#define LUA_IDSIZE\t60\n\n\n/*\n** {==================================================================\n** Stand-alone configuration\n** ===================================================================\n*/\n\n#if defined(lua_c) || defined(luaall_c)\n\n/*\n@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n@* is, whether we're running lua interactively).\n** CHANGE it if you have a better definition for non-POSIX/non-Windows\n** systems.\n*/\n#if defined(LUA_USE_ISATTY)\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n#elif defined(LUA_WIN)\n#include <io.h>\n#include <stdio.h>\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n#else\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n#endif\n\n\n/*\n@@ LUA_PROMPT is the default prompt used by stand-alone Lua.\n@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.\n** CHANGE them if you want different prompts. (You can also change the\n** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)\n*/\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n\n\n/*\n@@ LUA_PROGNAME is the default name for the stand-alone Lua program.\n** CHANGE it if your stand-alone interpreter has a different name and\n** your system is not able to detect that name automatically.\n*/\n#define LUA_PROGNAME\t\t\"lua\"\n\n\n/*\n@@ LUA_MAXINPUT is the maximum length for an input line in the\n@* stand-alone interpreter.\n** CHANGE it if you need longer lines.\n*/\n#define LUA_MAXINPUT\t512\n\n\n/*\n@@ lua_readline defines how to show a prompt and then read a line from\n@* the standard input.\n@@ lua_saveline defines how to \"save\" a read line in a \"history\".\n@@ lua_freeline defines how to free a line read by lua_readline.\n** CHANGE them if you want to improve this functionality (e.g., by using\n** GNU readline and history facilities).\n*/\n#if defined(LUA_USE_READLINE)\n#include <stdio.h>\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,idx) \\\n\tif (lua_strlen(L,idx) > 0)  /* non-empty line? */ \\\n\t  add_history(lua_tostring(L, idx));  /* add it to history */\n#define lua_freeline(L,b)\t((void)L, free(b))\n#else\n#define lua_readline(L,b,p)\t\\\n\t((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n\tfgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,idx)\t{ (void)L; (void)idx; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n#endif\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles\n@* as a percentage.\n** CHANGE it if you want the GC to run faster or slower (higher values\n** mean larger pauses which mean slower collection.) You can also change\n** this value dynamically.\n*/\n#define LUAI_GCPAUSE\t200  /* 200% (wait memory to double before next GC) */\n\n\n/*\n@@ LUAI_GCMUL defines the default speed of garbage collection relative to\n@* memory allocation as a percentage.\n** CHANGE it if you want to change the granularity of the garbage\n** collection. (Higher values mean coarser collections. 0 represents\n** infinity, where each step performs a full collection.) You can also\n** change this value dynamically.\n*/\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n\n\n\n/*\n@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.\n** CHANGE it (define it) if you want exact compatibility with the\n** behavior of setn/getn in Lua 5.0.\n*/\n#undef LUA_COMPAT_GETN\n\n/*\n@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.\n** CHANGE it to undefined as soon as you do not need a global 'loadlib'\n** function (the function is still available as 'package.loadlib').\n*/\n#undef LUA_COMPAT_LOADLIB\n\n/*\n@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.\n** CHANGE it to undefined as soon as your programs use only '...' to\n** access vararg parameters (instead of the old 'arg' table).\n*/\n#undef LUA_COMPAT_VARARG\n\n/*\n@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.\n** CHANGE it to undefined as soon as your programs use 'math.fmod' or\n** the new '%' operator instead of 'math.mod'.\n*/\n#define LUA_COMPAT_MOD\n\n/*\n@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting\n@* facility.\n** CHANGE it to 2 if you want the old behaviour, or undefine it to turn\n** off the advisory error when nesting [[...]].\n*/\n#undef LUA_COMPAT_LSTR\n\n/*\n@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.\n** CHANGE it to undefined as soon as you rename 'string.gfind' to\n** 'string.gmatch'.\n*/\n#define LUA_COMPAT_GFIND\n\n/*\n@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'\n@* behavior.\n** CHANGE it to undefined as soon as you replace to 'luaL_register'\n** your uses of 'luaL_openlib'\n*/\n#define LUA_COMPAT_OPENLIB\n\n\n\n/*\n@@ luai_apicheck is the assert macro used by the Lua-C API.\n** CHANGE luai_apicheck if you want Lua to perform some checks in the\n** parameters it gets from API calls. This may slow down the interpreter\n** a bit, but may be quite useful when debugging C code that interfaces\n** with Lua. A useful redefinition is to use assert.h.\n*/\n#if 0\n#define LUA_USE_APICHECK\n#define lua_assert(c) assert(c)\n#endif\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(L,o)\t{ (void)L; assert(o); }\n#else\n#define luai_apicheck(L,o)\t{ (void)L; }\n#endif\n\n\n/*\n@@ LUAI_BITSINT defines the number of bits in an int.\n** CHANGE here if Lua cannot automatically detect the number of bits of\n** your machine. Probably you do not need to change this.\n*/\n/* avoid overflows in comparison */\n#if INT_MAX-20 < 32760\n#define LUAI_BITSINT\t16\n#elif INT_MAX > 2147483640L\n/* int has at least 32 bits */\n#define LUAI_BITSINT\t32\n#else\n#error \"you must define LUA_BITSINT with number of bits in an integer\"\n#endif\n\n\n/*\n@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.\n@@ LUAI_INT32 is an signed integer with at least 32 bits.\n@@ LUAI_UMEM is an unsigned integer big enough to count the total\n@* memory used by Lua.\n@@ LUAI_MEM is a signed integer big enough to count the total memory\n@* used by Lua.\n** CHANGE here if for some weird reason the default definitions are not\n** good enough for your machine. (The definitions in the 'else'\n** part always works, but may waste space on machines with 64-bit\n** longs.) Probably you do not need to change this.\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_UINT32\tunsigned int\n#define LUAI_INT32\tint\n#define LUAI_MAXINT32\tINT_MAX\n#define LUAI_UMEM\tsize_t\n#define LUAI_MEM\tptrdiff_t\n#else\n/* 16-bit ints */\n#define LUAI_UINT32\tunsigned long\n#define LUAI_INT32\tlong\n#define LUAI_MAXINT32\tLONG_MAX\n#define LUAI_UMEM\tunsigned long\n#define LUAI_MEM\tlong\n#endif\n\n\n/*\n@@ LUAI_MAXCALLS limits the number of nested calls.\n** CHANGE it if you need really deep recursive calls. This limit is\n** arbitrary; its only purpose is to stop infinite recursion before\n** exhausting memory.\n*/\n#define LUAI_MAXCALLS\t20000\n\n\n/*\n@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function\n@* can use.\n** CHANGE it if you need lots of (Lua) stack space for your C\n** functions. This limit is arbitrary; its only purpose is to stop C\n** functions to consume unlimited stack space. (must be smaller than\n** -LUA_REGISTRYINDEX)\n*/\n#define LUAI_MAXCSTACK\t8000\n\n\n\n/*\n** {==================================================================\n** CHANGE (to smaller values) the following definitions if your system\n** has a small C stack. (Or you may want to change them to larger\n** values if your system has a large C stack and these limits are\n** too rigid for you.) Some of these constants control the size of\n** stack-allocated arrays used by the compiler or the interpreter, while\n** others limit the maximum number of recursive calls that the compiler\n** or the interpreter can perform. Values too large may cause a C stack\n** overflow for some forms of deep constructs.\n** ===================================================================\n*/\n\n\n/*\n@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and\n@* syntactical nested non-terminals in a program.\n*/\n#define LUAI_MAXCCALLS\t\t200\n\n\n/*\n@@ LUAI_MAXVARS is the maximum number of local variables per function\n@* (must be smaller than 250).\n*/\n#define LUAI_MAXVARS\t\t200\n\n\n/*\n@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function\n@* (must be smaller than 250).\n*/\n#define LUAI_MAXUPVALUES\t60\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n*/\n#define LUAL_BUFFERSIZE\t\tBUFSIZ\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n@@ LUA_NUMBER is the type of numbers in Lua.\n** CHANGE the following definitions only if you want to build Lua\n** with a number type different from double. You may also need to\n** change lua_number2int & lua_number2integer.\n** ===================================================================\n*/\n\n#define LUA_NUMBER_DOUBLE\n#define LUA_NUMBER\tdouble\n\n/*\n@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'\n@* over a number.\n*/\n#define LUAI_UACNUMBER\tdouble\n\n\n/*\n@@ LUA_NUMBER_SCAN is the format for reading numbers.\n@@ LUA_NUMBER_FMT is the format for writing numbers.\n@@ lua_number2str converts a number to a string.\n@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.\n@@ lua_str2number converts a string to a number.\n*/\n#define LUA_NUMBER_SCAN\t\t\"%lf\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n#define lua_number2str(s,n)\tsprintf((s), LUA_NUMBER_FMT, (n))\n#define LUAI_MAXNUMBER2STR\t32 /* 16 digits, sign, point, and \\0 */\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n\n/*\n@@ The luai_num* macros define the primitive operations over numbers.\n*/\n#if defined(LUA_CORE)\n#include <math.h>\n#define luai_numadd(a,b)\t((a)+(b))\n#define luai_numsub(a,b)\t((a)-(b))\n#define luai_nummul(a,b)\t((a)*(b))\n#define luai_numdiv(a,b)\t((a)/(b))\n#define luai_nummod(a,b)\t((a) - floor((a)/(b))*(b))\n#define luai_numpow(a,b)\t(pow(a,b))\n#define luai_numunm(a)\t\t(-(a))\n#define luai_numeq(a,b)\t\t((a)==(b))\n#define luai_numlt(a,b)\t\t((a)<(b))\n#define luai_numle(a,b)\t\t((a)<=(b))\n#define luai_numisnan(a)\t(!luai_numeq((a), (a)))\n#endif\n\n\n/*\n@@ lua_number2int is a macro to convert lua_Number to int.\n@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.\n** CHANGE them if you know a faster way to convert a lua_Number to\n** int (with any rounding method and without throwing errors) in your\n** system. In Pentium machines, a naive typecast from double to int\n** in C is extremely slow, so any alternative is worth trying.\n*/\n\n/* On a Pentium, resort to a trick */\n#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \\\n    (defined(__i386) || defined (_M_IX86) || defined(__i386__))\n\n/* On a Microsoft compiler, use assembler */\n#if defined(_MSC_VER)\n\n#define lua_number2int(i,d)   __asm fld d   __asm fistp i\n#define lua_number2integer(i,n)\t\tlua_number2int(i, n)\n\n/* the next trick should work on any Pentium, but sometimes clashes\n   with a DirectX idiosyncrasy */\n#else\n\nunion luai_Cast { double l_d; long l_l; };\n#define lua_number2int(i,d) \\\n  { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }\n#define lua_number2integer(i,n)\t\tlua_number2int(i, n)\n\n#endif\n\n\n/* this option always works, but may be slow */\n#else\n#define lua_number2int(i,d)\t((i)=(int)(d))\n#define lua_number2integer(i,d)\t((i)=(lua_Integer)(d))\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.\n** CHANGE it if your system requires alignments larger than double. (For\n** instance, if your system supports long doubles and they must be\n** aligned in 16-byte boundaries, then you should add long double in the\n** union.) Probably you do not need to change this.\n*/\n#define LUAI_USER_ALIGNMENT_T\tunion { double u; void *s; long l; }\n\n\n/*\n@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.\n** CHANGE them if you prefer to use longjmp/setjmp even with C++\n** or if want/don't to use _longjmp/_setjmp instead of regular\n** longjmp/setjmp. By default, Lua handles errors with exceptions when\n** compiling as C++ code, with _longjmp/_setjmp when asked to use them,\n** and with longjmp/setjmp otherwise.\n*/\n#if defined(__cplusplus)\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\tthrow(c)\n#define LUAI_TRY(L,c,a)\ttry { a } catch(...) \\\n\t{ if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\tint  /* dummy variable */\n\n#elif defined(LUA_USE_ULONGJMP)\n/* in Unix, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\tjmp_buf\n\n#else\n/* default handling with long jumps */\n#define LUAI_THROW(L,c)\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\tjmp_buf\n\n#endif\n\n\n/*\n@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern\n@* can do during pattern-matching.\n** CHANGE it if you need more captures. This limit is arbitrary.\n*/\n#define LUA_MAXCAPTURES\t\t32\n\n\n/*\n@@ lua_tmpnam is the function that the OS library uses to create a\n@* temporary name.\n@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.\n** CHANGE them if you have an alternative to tmpnam (which is considered\n** insecure) or if you want the original tmpnam anyway.  By default, Lua\n** uses tmpnam except when POSIX is available, where it uses mkstemp.\n*/\n#if defined(loslib_c) || defined(luaall_c)\n\n#if defined(LUA_USE_MKSTEMP)\n#include <unistd.h>\n#define LUA_TMPNAMBUFSIZE\t32\n#define lua_tmpnam(b,e)\t{ \\\n\tstrcpy(b, \"/tmp/lua_XXXXXX\"); \\\n\te = mkstemp(b); \\\n\tif (e != -1) close(e); \\\n\te = (e == -1); }\n\n#else\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n#endif\n\n#endif\n\n\n/*\n@@ lua_popen spawns a new process connected to the current one through\n@* the file streams.\n** CHANGE it if you have a way to implement it in your system.\n*/\n#if defined(LUA_USE_POPEN)\n\n#define lua_popen(L,c,m)\t((void)L, fflush(NULL), popen(c,m))\n#define lua_pclose(L,file)\t((void)L, (pclose(file) != -1))\n\n#elif defined(LUA_WIN)\n\n#define lua_popen(L,c,m)\t((void)L, _popen(c,m))\n#define lua_pclose(L,file)\t((void)L, (_pclose(file) != -1))\n\n#else\n\n#define lua_popen(L,c,m)\t((void)((void)c, m),  \\\n\t\tluaL_error(L, LUA_QL(\"popen\") \" not supported\"), (FILE*)0)\n#define lua_pclose(L,file)\t\t((void)((void)L, file), 0)\n\n#endif\n\n/*\n@@ LUA_DL_* define which dynamic-library system Lua should use.\n** CHANGE here if Lua has problems choosing the appropriate\n** dynamic-library system for your platform (either Windows' DLL, Mac's\n** dyld, or Unix's dlopen). If your system is some kind of Unix, there\n** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for\n** it.  To use dlopen you also need to adapt the src/Makefile (probably\n** adding -ldl to the linker options), so Lua does not select it\n** automatically.  (When you change the makefile to add -ldl, you must\n** also add -DLUA_USE_DLOPEN.)\n** If you do not want any kind of dynamic library, undefine all these\n** options.\n** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.\n*/\n#if defined(LUA_USE_DLOPEN)\n#define LUA_DL_DLOPEN\n#endif\n\n#if defined(LUA_WIN)\n#define LUA_DL_DLL\n#endif\n\n\n/*\n@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State\n@* (the data goes just *before* the lua_State pointer).\n** CHANGE (define) this if you really need that. This value must be\n** a multiple of the maximum alignment required for your machine.\n*/\n#define LUAI_EXTRASPACE\t\t0\n\n\n/*\n@@ luai_userstate* allow user-specific actions on threads.\n** CHANGE them if you defined LUAI_EXTRASPACE and need to do something\n** extra when a thread is created/deleted/resumed/yielded.\n*/\n#define luai_userstateopen(L)\t\t((void)L)\n#define luai_userstateclose(L)\t\t((void)L)\n#define luai_userstatethread(L,L1)\t((void)L)\n#define luai_userstatefree(L)\t\t((void)L)\n#define luai_userstateresume(L,n)\t((void)L)\n#define luai_userstateyield(L,n)\t((void)L)\n\n\n/*\n@@ LUA_INTFRMLEN is the length modifier for integer conversions\n@* in 'string.format'.\n@@ LUA_INTFRM_T is the integer type correspoding to the previous length\n@* modifier.\n** CHANGE them if your system supports long long or does not support long.\n*/\n\n#if defined(LUA_USELONGLONG)\n\n#define LUA_INTFRMLEN\t\t\"ll\"\n#define LUA_INTFRM_T\t\tlong long\n\n#else\n\n#define LUA_INTFRMLEN\t\t\"l\"\n#define LUA_INTFRM_T\t\tlong\n\n#endif\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n#if !defined(JIT_SUPPORT)\n\n/* extra variables for global_State */\n#define JIT_COMPILER_STATE\n\n/* jit function state */\n#define JIT_PROTO_STATE\n\n/* functions */\n#define JIT_NEW_STATE(L)\n#define JIT_CLOSE_STATE(L)\n#define JIT_NEWPROTO(L,p)\n#define JIT_FREEPROTO(L,p)\n#define JIT_PRECALL luaD_precall_lua\n\n#endif\n\n#endif\n\n"
  },
  {
    "path": "src/lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* Key to file-handle type */\n#define LUA_FILEHANDLE\t\t\"FILE*\"\n\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUALIB_API int (luaopen_base) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUALIB_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUALIB_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUALIB_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUALIB_API int (luaopen_string) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUALIB_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUALIB_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUALIB_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L); \n\n\n\n#ifndef lua_assert\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "src/lundump.c",
    "content": "/*\n** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#include <string.h>\n\n#define lundump_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lmem.h\"\n#include \"lobject.h\"\n#include \"lstring.h\"\n#include \"lundump.h\"\n#include \"lzio.h\"\n\ntypedef struct {\n lua_State* L;\n ZIO* Z;\n Mbuffer* b;\n const char* name;\n} LoadState;\n\n#ifdef LUAC_TRUST_BINARIES\n#define IF(c,s)\n#define error(S,s)\n#else\n#define IF(c,s)\t\tif (c) error(S,s)\n\nstatic void error(LoadState* S, const char* why)\n{\n luaO_pushfstring(S->L,\"%s: %s in precompiled chunk\",S->name,why);\n luaD_throw(S->L,LUA_ERRSYNTAX);\n}\n#endif\n\n#define LoadMem(S,b,n,size)\tLoadBlock(S,b,(n)*(size))\n#define\tLoadByte(S)\t\t(lu_byte)LoadChar(S)\n#define LoadVar(S,x)\t\tLoadMem(S,&x,1,sizeof(x))\n#define LoadVector(S,b,n,size)\tLoadMem(S,b,n,size)\n\nstatic void LoadBlock(LoadState* S, void* b, size_t size)\n{\n size_t r=luaZ_read(S->Z,b,size);\n IF (r!=0, \"unexpected end\");\n}\n\nstatic int LoadChar(LoadState* S)\n{\n char x;\n LoadVar(S,x);\n return x;\n}\n\nstatic int LoadInt(LoadState* S)\n{\n int x;\n LoadVar(S,x);\n IF (x<0, \"bad integer\");\n return x;\n}\n\nstatic lua_Number LoadNumber(LoadState* S)\n{\n lua_Number x;\n LoadVar(S,x);\n return x;\n}\n\nstatic TString* LoadString(LoadState* S)\n{\n size_t size;\n LoadVar(S,size);\n if (size==0)\n  return NULL;\n else\n {\n  char* s=luaZ_openspace(S->L,S->b,size);\n  LoadBlock(S,s,size);\n  return luaS_newlstr(S->L,s,size-1);\t\t/* remove trailing '\\0' */\n }\n}\n\nstatic void LoadCode(LoadState* S, Proto* f)\n{\n int n=LoadInt(S);\n f->code=luaM_newvector(S->L,n,Instruction);\n f->sizecode=n;\n LoadVector(S,f->code,n,sizeof(Instruction));\n}\n\nstatic Proto* LoadFunction(LoadState* S, TString* p);\n\nstatic void LoadConstants(LoadState* S, Proto* f)\n{\n int i,n;\n n=LoadInt(S);\n f->k=luaM_newvector(S->L,n,TValue);\n f->sizek=n;\n for (i=0; i<n; i++) setnilvalue(&f->k[i]);\n for (i=0; i<n; i++)\n {\n  TValue* o=&f->k[i];\n  int t=LoadChar(S);\n  switch (t)\n  {\n   case LUA_TNIL:\n   \tsetnilvalue(o);\n\tbreak;\n   case LUA_TBOOLEAN:\n   \tsetbvalue(o,LoadChar(S)!=0);\n\tbreak;\n   case LUA_TNUMBER:\n\tsetnvalue(o,LoadNumber(S));\n\tbreak;\n   case LUA_TSTRING:\n\tsetsvalue2n(S->L,o,LoadString(S));\n\tbreak;\n   default:\n\terror(S,\"bad constant\");\n\tbreak;\n  }\n }\n n=LoadInt(S);\n f->p=luaM_newvector(S->L,n,Proto*);\n f->sizep=n;\n for (i=0; i<n; i++) f->p[i]=NULL;\n for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);\n}\n\nstatic void LoadDebug(LoadState* S, Proto* f)\n{\n int i,n;\n n=LoadInt(S);\n f->lineinfo=luaM_newvector(S->L,n,int);\n f->sizelineinfo=n;\n LoadVector(S,f->lineinfo,n,sizeof(int));\n n=LoadInt(S);\n f->locvars=luaM_newvector(S->L,n,LocVar);\n f->sizelocvars=n;\n for (i=0; i<n; i++) f->locvars[i].varname=NULL;\n for (i=0; i<n; i++)\n {\n  f->locvars[i].varname=LoadString(S);\n  f->locvars[i].startpc=LoadInt(S);\n  f->locvars[i].endpc=LoadInt(S);\n }\n n=LoadInt(S);\n f->upvalues=luaM_newvector(S->L,n,TString*);\n f->sizeupvalues=n;\n for (i=0; i<n; i++) f->upvalues[i]=NULL;\n for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);\n}\n\nstatic Proto* LoadFunction(LoadState* S, TString* p)\n{\n Proto* f;\n if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,\"code too deep\");\n f=luaF_newproto(S->L);\n setptvalue2s(S->L,S->L->top,f); incr_top(S->L);\n f->source=LoadString(S); if (f->source==NULL) f->source=p;\n f->linedefined=LoadInt(S);\n f->lastlinedefined=LoadInt(S);\n f->nups=LoadByte(S);\n f->numparams=LoadByte(S);\n f->is_vararg=LoadByte(S);\n f->maxstacksize=LoadByte(S);\n LoadCode(S,f);\n LoadConstants(S,f);\n LoadDebug(S,f);\n IF (!luaG_checkcode(f), \"bad code\");\n S->L->top--;\n S->L->nCcalls--;\n return f;\n}\n\nstatic void LoadHeader(LoadState* S)\n{\n char h[LUAC_HEADERSIZE];\n char s[LUAC_HEADERSIZE];\n luaU_header(h);\n LoadBlock(S,s,LUAC_HEADERSIZE);\n IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, \"bad header\");\n}\n\n/*\n** load precompiled chunk\n*/\nProto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)\n{\n LoadState S;\n if (*name=='@' || *name=='=')\n  S.name=name+1;\n else if (*name==LUA_SIGNATURE[0])\n  S.name=\"binary string\";\n else\n  S.name=name;\n S.L=L;\n S.Z=Z;\n S.b=buff;\n LoadHeader(&S);\n return LoadFunction(&S,luaS_newliteral(L,\"=?\"));\n}\n\n/*\n* make header\n*/\nvoid luaU_header (char* h)\n{\n int x=1;\n memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);\n h+=sizeof(LUA_SIGNATURE)-1;\n *h++=(char)LUAC_VERSION;\n *h++=(char)LUAC_FORMAT;\n *h++=(char)*(char*)&x;\t\t\t\t/* endianness */\n *h++=(char)sizeof(int);\n *h++=(char)sizeof(size_t);\n *h++=(char)sizeof(Instruction);\n *h++=(char)sizeof(lua_Number);\n *h++=(char)(((lua_Number)0.5)==0);\t\t/* is lua_Number integral? */\n}\n"
  },
  {
    "path": "src/lundump.h",
    "content": "/*\n** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $\n** load precompiled Lua chunks\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lundump_h\n#define lundump_h\n\n#include \"lobject.h\"\n#include \"lzio.h\"\n\n/* load one chunk; from lundump.c */\nLUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);\n\n/* make header; from lundump.c */\nLUAI_FUNC void luaU_header (char* h);\n\n/* dump one chunk; from ldump.c */\nLUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);\n\n#ifdef luac_c\n/* print one chunk; from print.c */\nLUAI_FUNC void luaU_print (const Proto* f, int full);\n#endif\n\n/* for header of binary files -- this is Lua 5.1 */\n#define LUAC_VERSION\t\t0x51\n\n/* for header of binary files -- this is the official format */\n#define LUAC_FORMAT\t\t0\n\n/* size of header of binary files */\n#define LUAC_HEADERSIZE\t\t12\n\n#endif\n"
  },
  {
    "path": "src/lvm.c",
    "content": "/*\n** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define lvm_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"ldebug.h\"\n#include \"ldo.h\"\n#include \"lfunc.h\"\n#include \"lgc.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lstate.h\"\n#include \"lstring.h\"\n#include \"ltable.h\"\n#include \"ltm.h\"\n#include \"lvm.h\"\n\n\n\n/* limit for table tag-method chains (to avoid loops) */\n#define MAXTAGLOOP\t100\n\n\nconst TValue *luaV_tonumber (const TValue *obj, TValue *n) {\n  lua_Number num;\n  if (ttisnumber(obj)) return obj;\n  if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {\n    setnvalue(n, num);\n    return n;\n  }\n  else\n    return NULL;\n}\n\n\nint luaV_tostring (lua_State *L, StkId obj) {\n  if (!ttisnumber(obj))\n    return 0;\n  else {\n    char s[LUAI_MAXNUMBER2STR];\n    ptrdiff_t objr = savestack(L, obj);\n    lua_Number n = nvalue(obj);\n    lua_number2str(s, n);\n    setsvalue2s(L, restorestack(L, objr), luaS_new(L, s));\n    return 1;\n  }\n}\n\n\nvoid luaV_traceexec (lua_State *L, const Instruction *pc) {\n  lu_byte mask = L->hookmask;\n  const Instruction *oldpc = L->savedpc;\n  L->savedpc = pc;\n  if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {\n    resethookcount(L);\n    luaD_callhook(L, LUA_HOOKCOUNT, -1);\n  }\n  if (mask & LUA_MASKLINE) {\n    Proto *p = ci_func(L->ci)->l.p;\n    int npc = pcRel(pc, p);\n    int newline = getlinenum(p, npc);\n    /* call linehook when enter a new function, when jump back (loop),\n       or when enter a new line */\n    if (npc == 0 || pc <= oldpc || newline != getlinenum(p, pcRel(oldpc, p)))\n      luaD_callhook(L, LUA_HOOKLINE, newline);\n  }\n}\n\n\nstatic void callTMres (lua_State *L, StkId res, const TValue *f,\n                        const TValue *p1, const TValue *p2) {\n  ptrdiff_t result = savestack(L, res);\n  setobj2s(L, L->top, f);  /* push function */\n  setobj2s(L, L->top+1, p1);  /* 1st argument */\n  setobj2s(L, L->top+2, p2);  /* 2nd argument */\n  luaD_checkstack(L, 3);\n  L->top += 3;\n  luaD_call(L, L->top - 3, 1);\n  res = restorestack(L, result);\n  L->top--;\n  setobjs2s(L, res, L->top);\n}\n\n\n\nstatic void callTM (lua_State *L, const TValue *f, const TValue *p1,\n                    const TValue *p2, const TValue *p3) {\n  setobj2s(L, L->top, f);  /* push function */\n  setobj2s(L, L->top+1, p1);  /* 1st argument */\n  setobj2s(L, L->top+2, p2);  /* 2nd argument */\n  setobj2s(L, L->top+3, p3);  /* 3th argument */\n  luaD_checkstack(L, 4);\n  L->top += 4;\n  luaD_call(L, L->top - 4, 0);\n}\n\n\nvoid luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {\n  int loop;\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;\n    if (ttistable(t)) {  /* `t' is a table? */\n      Table *h = hvalue(t);\n      const TValue *res = luaH_get(h, key); /* do a primitive get */\n      if (!ttisnil(res) ||  /* result is no nil? */\n          (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */\n        setobj2s(L, val, res);\n        return;\n      }\n      /* else will try the tag method */\n    }\n    else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))\n      luaG_typeerror(L, t, \"index\");\n    if (ttisfunction(tm)) {\n      callTMres(L, val, tm, t, key);\n      return;\n    }\n    t = tm;  /* else repeat with `tm' */ \n  }\n  luaG_runerror(L, \"loop in gettable\");\n}\n\n\nvoid luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {\n  int loop;\n  TValue temp;\n  setnilvalue(L->top);\n  L->top++;\n  fixedstack(L);\n  for (loop = 0; loop < MAXTAGLOOP; loop++) {\n    const TValue *tm;\n    if (ttistable(t)) {  /* `t' is a table? */\n      Table *h = hvalue(t);\n      TValue *oldval = luaH_set(L, h, key); /* do a primitive set */\n      if (!ttisnil(oldval) ||  /* result is no nil? */\n          (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */\n        L->top--;\n        unfixedstack(L);\n        setobj2t(L, oldval, val);\n        luaC_barriert(L, h, val);\n        return;\n      }\n      /* else will try the tag method */\n    }\n    else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))\n      luaG_typeerror(L, t, \"index\");\n    if (ttisfunction(tm)) {\n      L->top--;\n      unfixedstack(L);\n      callTM(L, tm, t, key, val);\n      return;\n    }\n    /* else repeat with `tm' */\n    setobj(L, &temp, tm);  /* avoid pointing inside table (may rehash) */\n    t = &temp;\n    setobj2s(L, L->top-1, t);  /* need to protect value from EGC. */\n  }\n  luaG_runerror(L, \"loop in settable\");\n}\n\n\nint luaV_call_binTM (lua_State *L, const TValue *p1, const TValue *p2,\n                       StkId res, TMS event) {\n  const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */\n  if (ttisnil(tm))\n    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */\n  if (ttisnil(tm)) return 0;\n  callTMres(L, res, tm, p1, p2);\n  return 1;\n}\n\n\nstatic const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,\n                                  TMS event) {\n  const TValue *tm1 = fasttm(L, mt1, event);\n  const TValue *tm2;\n  if (tm1 == NULL) return NULL;  /* no metamethod */\n  if (mt1 == mt2) return tm1;  /* same metatables => same metamethods */\n  tm2 = fasttm(L, mt2, event);\n  if (tm2 == NULL) return NULL;  /* no metamethod */\n  if (luaO_rawequalObj(tm1, tm2))  /* same metamethods? */\n    return tm1;\n  return NULL;\n}\n\n\nstatic int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,\n                         TMS event) {\n  const TValue *tm1 = luaT_gettmbyobj(L, p1, event);\n  const TValue *tm2;\n  if (ttisnil(tm1)) return -1;  /* no metamethod? */\n  tm2 = luaT_gettmbyobj(L, p2, event);\n  if (!luaO_rawequalObj(tm1, tm2))  /* different metamethods? */\n    return -1;\n  callTMres(L, L->top, tm1, p1, p2);\n  return !l_isfalse(L->top);\n}\n\n\nstatic int l_strcmp (const TString *ls, const TString *rs) {\n  const char *l = getstr(ls);\n  size_t ll = ls->tsv.len;\n  const char *r = getstr(rs);\n  size_t lr = rs->tsv.len;\n  for (;;) {\n    int temp = strcoll(l, r);\n    if (temp != 0) return temp;\n    else {  /* strings are equal up to a `\\0' */\n      size_t len = strlen(l);  /* index of first `\\0' in both strings */\n      if (len == lr)  /* r is finished? */\n        return (len == ll) ? 0 : 1;\n      else if (len == ll)  /* l is finished? */\n        return -1;  /* l is smaller than r (because r is not finished) */\n      /* both strings longer than `len'; go on comparing (after the `\\0') */\n      len++;\n      l += len; ll -= len; r += len; lr -= len;\n    }\n  }\n}\n\n\nint luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttype(l) != ttype(r))\n    return luaG_ordererror(L, l, r);\n  else if (ttisnumber(l))\n    return luai_numlt(nvalue(l), nvalue(r));\n  else if (ttisstring(l))\n    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;\n  else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)\n    return res;\n  return luaG_ordererror(L, l, r);\n}\n\n\nint luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {\n  int res;\n  if (ttype(l) != ttype(r))\n    return luaG_ordererror(L, l, r);\n  else if (ttisnumber(l))\n    return luai_numle(nvalue(l), nvalue(r));\n  else if (ttisstring(l))\n    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;\n  else if ((res = call_orderTM(L, l, r, TM_LE)) != -1)  /* first try `le' */\n    return res;\n  else if ((res = call_orderTM(L, r, l, TM_LT)) != -1)  /* else try `lt' */\n    return !res;\n  return luaG_ordererror(L, l, r);\n}\n\n\nint luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) {\n  const TValue *tm;\n  lua_assert(ttype(t1) == ttype(t2));\n  switch (ttype(t1)) {\n    case LUA_TNIL: return 1;\n    case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));\n    case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2);  /* true must be 1 !! */\n    case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);\n    case LUA_TUSERDATA: {\n      if (uvalue(t1) == uvalue(t2)) return 1;\n      tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,\n                         TM_EQ);\n      break;  /* will try TM */\n    }\n    case LUA_TTABLE: {\n      if (hvalue(t1) == hvalue(t2)) return 1;\n      tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);\n      break;  /* will try TM */\n    }\n    default: return gcvalue(t1) == gcvalue(t2);\n  }\n  if (tm == NULL) return 0;  /* no TM? */\n  callTMres(L, L->top, tm, t1, t2);  /* call TM */\n  return !l_isfalse(L->top);\n}\n\n\nvoid luaV_concat (lua_State *L, int total, int last) {\n  lu_mem max_sizet = MAX_SIZET;\n  if (G(L)->memlimit < max_sizet) max_sizet = G(L)->memlimit;\n  do {\n    StkId top = L->base + last + 1;\n    int n = 2;  /* number of elements handled in this pass (at least 2) */\n    if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {\n      if (!luaV_call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) {\n        /* restore 'top' pointer, since stack might have been reallocted */\n        top = L->base + last + 1;\n        luaG_concaterror(L, top-2, top-1);\n      }\n    } else if (tsvalue(top-1)->len == 0)  /* second op is empty? */\n      (void)tostring(L, top - 2);  /* result is first op (as string) */\n    else {\n      /* at least two string values; get as many as possible */\n      size_t tl = tsvalue(top-1)->len;\n      char *buffer;\n      int i;\n      fixedstack(L);\n      /* collect total length */\n      for (n = 1; n < total && tostring(L, top-n-1); n++) {\n        size_t l = tsvalue(top-n-1)->len;\n        if (l >= max_sizet - tl) luaG_runerror(L, \"string length overflow\");\n        tl += l;\n      }\n      G(L)->buff.n = tl;\n      buffer = luaZ_openspace(L, &G(L)->buff, tl);\n      tl = 0;\n      for (i=n; i>0; i--) {  /* concat all strings */\n        size_t l = tsvalue(top-i)->len;\n        memcpy(buffer+tl, svalue(top-i), l);\n        tl += l;\n      }\n      setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));\n      luaZ_resetbuffer(&G(L)->buff);\n      unfixedstack(L);\n    }\n    total -= n-1;  /* got `n' strings to create 1 new */\n    last -= n-1;\n  } while (total > 1);  /* repeat until only 1 result left */\n}\n\n\nvoid luaV_arith (lua_State *L, StkId ra, const TValue *rb,\n                   const TValue *rc, TMS op) {\n  TValue tempb, tempc;\n  const TValue *b, *c;\n  if ((b = luaV_tonumber(rb, &tempb)) != NULL &&\n      (c = luaV_tonumber(rc, &tempc)) != NULL) {\n    lua_Number nb = nvalue(b), nc = nvalue(c);\n    switch (op) {\n      case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;\n      case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;\n      case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;\n      case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;\n      case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;\n      case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;\n      case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;\n      default: lua_assert(0); break;\n    }\n  }\n  else {\n    ptrdiff_t br = savestack(L, rb);\n    ptrdiff_t cr = savestack(L, rc);\n    if (!luaV_call_binTM(L, rb, rc, ra, op)) {\n      luaG_aritherror(L, restorestack(L, br), restorestack(L, cr));\n    }\n  }\n}\n\n\n\n/*\n** some macros for common tasks in `luaV_execute'\n*/\n\n#define runtime_check(L, c)\t{ if (!(c)) break; }\n\n#define RA(i)\t(base+GETARG_A(i))\n/* to be used after possible stack reallocation */\n#define RB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))\n#define RC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))\n#define RKB(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))\n#define RKC(i)\tcheck_exp(getCMode(GET_OPCODE(i)) == OpArgK, \\\n\tISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))\n#define KBx(i)\tcheck_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))\n\n\n#define dojump(L,pc,i)\t{(pc) += (i); luai_threadyield(L);}\n\n\n#define Protect(x)\t{ L->savedpc = pc; {x;}; base = L->base; }\n\n\n#define arith_op(op,tm) { \\\n        TValue *rb = RKB(i); \\\n        TValue *rc = RKC(i); \\\n        if (ttisnumber(rb) && ttisnumber(rc)) { \\\n          lua_Number nb = nvalue(rb), nc = nvalue(rc); \\\n          setnvalue(ra, op(nb, nc)); \\\n        } \\\n        else \\\n          Protect(luaV_arith(L, ra, rb, rc, tm)); \\\n      }\n\n\n\nvoid luaV_execute (lua_State *L, int nexeccalls) {\n  LClosure *cl;\n  StkId base;\n  TValue *k;\n  const Instruction *pc;\n reentry:  /* entry point */\n  lua_assert(isLua(L->ci));\n  pc = L->savedpc;\n  cl = &clvalue(L->ci->func)->l;\n  base = L->base;\n  k = cl->p->k;\n  /* main loop of interpreter */\n  for (;;) {\n    const Instruction i = *pc++;\n    StkId ra;\n    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&\n        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {\n      luaV_traceexec(L, pc);\n      if (L->status == LUA_YIELD) {  /* did hook yield? */\n        L->savedpc = pc - 1;\n        return;\n      }\n      base = L->base;\n    }\n    /* warning!! several calls may realloc the stack and invalidate `ra' */\n    ra = RA(i);\n    lua_assert(base == L->base && L->base == L->ci->base);\n    lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);\n    lua_assert(L->top == L->ci->top || luaG_checkopenop(i));\n    switch (GET_OPCODE(i)) {\n      case OP_MOVE: {\n        setobjs2s(L, ra, RB(i));\n        continue;\n      }\n      case OP_LOADK: {\n        setobj2s(L, ra, KBx(i));\n        continue;\n      }\n      case OP_LOADBOOL: {\n        setbvalue(ra, GETARG_B(i));\n        if (GETARG_C(i)) pc++;  /* skip next instruction (if C) */\n        continue;\n      }\n      case OP_LOADNIL: {\n        TValue *rb = RB(i);\n        do {\n          setnilvalue(rb--);\n        } while (rb >= ra);\n        continue;\n      }\n      case OP_GETUPVAL: {\n        int b = GETARG_B(i);\n        setobj2s(L, ra, cl->upvals[b]->v);\n        continue;\n      }\n      case OP_GETGLOBAL: {\n        TValue g;\n        TValue *rb = KBx(i);\n        sethvalue(L, &g, cl->env);\n        lua_assert(ttisstring(rb));\n        Protect(luaV_gettable(L, &g, rb, ra));\n        continue;\n      }\n      case OP_GETTABLE: {\n        Protect(luaV_gettable(L, RB(i), RKC(i), ra));\n        continue;\n      }\n      case OP_SETGLOBAL: {\n        TValue g;\n        sethvalue(L, &g, cl->env);\n        lua_assert(ttisstring(KBx(i)));\n        Protect(luaV_settable(L, &g, KBx(i), ra));\n        continue;\n      }\n      case OP_SETUPVAL: {\n        UpVal *uv = cl->upvals[GETARG_B(i)];\n        setobj(L, uv->v, ra);\n        luaC_barrier(L, uv, ra);\n        continue;\n      }\n      case OP_SETTABLE: {\n        Protect(luaV_settable(L, ra, RKB(i), RKC(i)));\n        continue;\n      }\n      case OP_NEWTABLE: {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Table *h;\n        Protect(h = luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));\n        sethvalue(L, RA(i), h);\n        Protect(luaC_checkGC(L));\n        continue;\n      }\n      case OP_SELF: {\n        StkId rb = RB(i);\n        setobjs2s(L, ra+1, rb);\n        Protect(luaV_gettable(L, rb, RKC(i), ra));\n        continue;\n      }\n      case OP_ADD: {\n        arith_op(luai_numadd, TM_ADD);\n        continue;\n      }\n      case OP_SUB: {\n        arith_op(luai_numsub, TM_SUB);\n        continue;\n      }\n      case OP_MUL: {\n        arith_op(luai_nummul, TM_MUL);\n        continue;\n      }\n      case OP_DIV: {\n        arith_op(luai_numdiv, TM_DIV);\n        continue;\n      }\n      case OP_MOD: {\n        arith_op(luai_nummod, TM_MOD);\n        continue;\n      }\n      case OP_POW: {\n        arith_op(luai_numpow, TM_POW);\n        continue;\n      }\n      case OP_UNM: {\n        TValue *rb = RB(i);\n        if (ttisnumber(rb)) {\n          lua_Number nb = nvalue(rb);\n          setnvalue(ra, luai_numunm(nb));\n        }\n        else {\n          Protect(luaV_arith(L, ra, rb, rb, TM_UNM));\n        }\n        continue;\n      }\n      case OP_NOT: {\n        int res = l_isfalse(RB(i));  /* next assignment may change this value */\n        setbvalue(ra, res);\n        continue;\n      }\n      case OP_LEN: {\n        const TValue *rb = RB(i);\n        switch (ttype(rb)) {\n          case LUA_TTABLE: {\n            setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));\n            break;\n          }\n          case LUA_TSTRING: {\n            setnvalue(ra, cast_num(tsvalue(rb)->len));\n            break;\n          }\n          default: {  /* try metamethod */\n            ptrdiff_t br = savestack(L, rb);\n            Protect(\n              if (!luaV_call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))\n                luaG_typeerror(L, restorestack(L, br), \"get length of\");\n            )\n          }\n        }\n        continue;\n      }\n      case OP_CONCAT: {\n        int b = GETARG_B(i);\n        int c = GETARG_C(i);\n        Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));\n        setobjs2s(L, RA(i), base+b);\n        continue;\n      }\n      case OP_JMP: {\n        dojump(L, pc, GETARG_sBx(i));\n        continue;\n      }\n      case OP_EQ: {\n        TValue *rb = RKB(i);\n        TValue *rc = RKC(i);\n        Protect(\n          if (equalobj(L, rb, rc) == GETARG_A(i))\n            dojump(L, pc, GETARG_sBx(*pc));\n        )\n        pc++;\n        continue;\n      }\n      case OP_LT: {\n        Protect(\n          if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))\n            dojump(L, pc, GETARG_sBx(*pc));\n        )\n        pc++;\n        continue;\n      }\n      case OP_LE: {\n        Protect(\n          if (luaV_lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))\n            dojump(L, pc, GETARG_sBx(*pc));\n        )\n        pc++;\n        continue;\n      }\n      case OP_TEST: {\n        if (l_isfalse(ra) != GETARG_C(i))\n          dojump(L, pc, GETARG_sBx(*pc));\n        pc++;\n        continue;\n      }\n      case OP_TESTSET: {\n        TValue *rb = RB(i);\n        if (l_isfalse(rb) != GETARG_C(i)) {\n          setobjs2s(L, ra, rb);\n          dojump(L, pc, GETARG_sBx(*pc));\n        }\n        pc++;\n        continue;\n      }\n      case OP_CALL: {\n        int b = GETARG_B(i);\n        int nresults = GETARG_C(i) - 1;\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        L->savedpc = pc;\n        switch (luaD_precall(L, ra, nresults)) {\n          case PCRLUA: {\n            nexeccalls++;\n            goto reentry;  /* restart luaV_execute over new Lua function */\n          }\n          case PCRC: {\n            /* it was a C function (`precall' called it); adjust results */\n            if (nresults >= 0) L->top = L->ci->top;\n            base = L->base;\n            continue;\n          }\n          default: {\n            return;  /* yield */\n          }\n        }\n      }\n      case OP_TAILCALL: {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b;  /* else previous instruction set top */\n        L->savedpc = pc;\n        lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);\n        switch (luaD_precall(L, ra, LUA_MULTRET)) {\n          case PCRLUA: {\n            /* tail call: put new frame in place of previous one */\n            CallInfo *ci = L->ci - 1;  /* previous frame */\n            int aux;\n            StkId func = ci->func;\n            StkId pfunc = (ci+1)->func;  /* previous function index */\n            if (L->openupval) luaF_close(L, ci->base);\n            L->base = ci->base = ci->func + ((ci+1)->base - pfunc);\n            for (aux = 0; pfunc+aux < L->top; aux++)  /* move frame down */\n              setobjs2s(L, func+aux, pfunc+aux);\n            ci->top = L->top = func+aux;  /* correct top */\n            lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);\n            ci->savedpc = L->savedpc;\n            ci->tailcalls++;  /* one more call lost */\n            L->ci--;  /* remove new frame */\n            goto reentry;\n          }\n          case PCRC: {  /* it was a C function (`precall' called it) */\n            base = L->base;\n            continue;\n          }\n          default: {\n            return;  /* yield */\n          }\n        }\n      }\n      case OP_RETURN: {\n        int b = GETARG_B(i);\n        if (b != 0) L->top = ra+b-1;\n        if (L->openupval) luaF_close(L, base);\n        L->savedpc = pc;\n        b = luaD_poscall(L, ra);\n        if (--nexeccalls == 0)  /* was previous function running `here'? */\n          return;  /* no: return */\n        else {  /* yes: continue its execution */\n          if (b) L->top = L->ci->top;\n          lua_assert(isLua(L->ci));\n          lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);\n          goto reentry;\n        }\n      }\n      case OP_FORLOOP: {\n        lua_Number step = nvalue(ra+2);\n        lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */\n        lua_Number limit = nvalue(ra+1);\n        if (luai_numlt(0, step) ? luai_numle(idx, limit)\n                                : luai_numle(limit, idx)) {\n          dojump(L, pc, GETARG_sBx(i));  /* jump back */\n          setnvalue(ra, idx);  /* update internal index... */\n          setnvalue(ra+3, idx);  /* ...and external index */\n        }\n        continue;\n      }\n      case OP_FORPREP: {\n        const TValue *init = ra;\n        const TValue *plimit = ra+1;\n        const TValue *pstep = ra+2;\n        L->savedpc = pc;  /* next steps may throw errors */\n        if (!tonumber(init, ra))\n          luaG_runerror(L, LUA_QL(\"for\") \" initial value must be a number\");\n        else if (!tonumber(plimit, ra+1))\n          luaG_runerror(L, LUA_QL(\"for\") \" limit must be a number\");\n        else if (!tonumber(pstep, ra+2))\n          luaG_runerror(L, LUA_QL(\"for\") \" step must be a number\");\n        setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));\n        dojump(L, pc, GETARG_sBx(i));\n        continue;\n      }\n      case OP_TFORLOOP: {\n        StkId cb = ra + 3;  /* call base */\n        setobjs2s(L, cb+2, ra+2);\n        setobjs2s(L, cb+1, ra+1);\n        setobjs2s(L, cb, ra);\n        L->top = cb+3;  /* func. + 2 args (state and index) */\n        Protect(luaD_call(L, cb, GETARG_C(i)));\n        L->top = L->ci->top;\n        cb = RA(i) + 3;  /* previous call may change the stack */\n        if (!ttisnil(cb)) {  /* continue loop? */\n          setobjs2s(L, cb-1, cb);  /* save control variable */\n          dojump(L, pc, GETARG_sBx(*pc));  /* jump back */\n        }\n        pc++;\n        continue;\n      }\n      case OP_SETLIST: {\n        int n = GETARG_B(i);\n        int c = GETARG_C(i);\n        int last;\n        Table *h;\n        fixedstack(L);\n        if (n == 0) {\n          n = cast_int(L->top - ra) - 1;\n          L->top = L->ci->top;\n        }\n        if (c == 0) c = cast_int(*pc++);\n        runtime_check(L, ttistable(ra));\n        h = hvalue(ra);\n        last = ((c-1)*LFIELDS_PER_FLUSH) + n;\n        if (last > h->sizearray)  /* needs more space? */\n          luaH_resizearray(L, h, last);  /* pre-alloc it at once */\n        for (; n > 0; n--) {\n          TValue *val = ra+n;\n          setobj2t(L, luaH_setnum(L, h, last--), val);\n          luaC_barriert(L, h, val);\n        }\n        unfixedstack(L);\n        continue;\n      }\n      case OP_CLOSE: {\n        luaF_close(L, ra);\n        continue;\n      }\n      case OP_CLOSURE: {\n        Proto *p;\n        Closure *ncl;\n        int nup, j;\n        p = cl->p->p[GETARG_Bx(i)];\n        nup = p->nups;\n        fixedstack(L);\n        ncl = luaF_newLclosure(L, nup, cl->env);\n        setclvalue(L, ra, ncl);\n        ncl->l.p = p;\n        for (j=0; j<nup; j++, pc++) {\n          if (GET_OPCODE(*pc) == OP_GETUPVAL)\n            ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];\n          else {\n            lua_assert(GET_OPCODE(*pc) == OP_MOVE);\n            ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));\n          }\n        }\n        unfixedstack(L);\n        Protect(luaC_checkGC(L));\n        continue;\n      }\n      case OP_VARARG: {\n        int b = GETARG_B(i) - 1;\n        int j;\n        CallInfo *ci = L->ci;\n        int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;\n        if (b == LUA_MULTRET) {\n          Protect(luaD_checkstack(L, n));\n          ra = RA(i);  /* previous call may change the stack */\n          b = n;\n          L->top = ra + n;\n        }\n        for (j = 0; j < b; j++) {\n          if (j < n) {\n            setobjs2s(L, ra + j, ci->base - n + j);\n          }\n          else {\n            setnilvalue(ra + j);\n          }\n        }\n        continue;\n      }\n      default: {\n        luaG_runerror(L, \"Bad opcode: opcode=%d\", GET_OPCODE(i));\n        continue;\n      }\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/lvm.h",
    "content": "/*\n** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua virtual machine\n** See Copyright Notice in lua.h\n*/\n\n#ifndef lvm_h\n#define lvm_h\n\n\n#include \"ldo.h\"\n#include \"lobject.h\"\n#include \"ltm.h\"\n\n\n#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))\n\n#define tonumber(o,n)\t(ttype(o) == LUA_TNUMBER || \\\n                         (((o) = luaV_tonumber(o,n)) != NULL))\n\n#define equalobj(L,o1,o2) \\\n\t(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))\n\n\nLUAI_FUNC void luaV_traceexec (lua_State *L, const Instruction *pc);\nLUAI_FUNC int luaV_call_binTM (lua_State *L, const TValue *p1, const TValue *p2,\n                                             StkId res, TMS event);\nLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);\nLUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);\nLUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);\nLUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);\nLUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,\n                                            StkId val);\nLUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,\n                                            StkId val);\nLUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb,\n                                         const TValue *rc, TMS op);\nLUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);\nLUAI_FUNC void luaV_concat (lua_State *L, int total, int last);\n\n#endif\n"
  },
  {
    "path": "src/lzio.c",
    "content": "/*\n** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $\n** a generic input stream interface\n** See Copyright Notice in lua.h\n*/\n\n\n#include <string.h>\n\n#define lzio_c\n#define LUA_CORE\n\n#include \"lua.h\"\n\n#include \"llimits.h\"\n#include \"lmem.h\"\n#include \"lstate.h\"\n#include \"lzio.h\"\n\n\nint luaZ_fill (ZIO *z) {\n  size_t size;\n  lua_State *L = z->L;\n  const char *buff;\n  lua_unlock(L);\n  buff = z->reader(L, z->data, &size);\n  lua_lock(L);\n  if (buff == NULL || size == 0) return EOZ;\n  z->n = size - 1;\n  z->p = buff;\n  return char2int(*(z->p++));\n}\n\n\nint luaZ_lookahead (ZIO *z) {\n  if (z->n == 0) {\n    if (luaZ_fill(z) == EOZ)\n      return EOZ;\n    else {\n      z->n++;  /* luaZ_fill removed first byte; put back it */\n      z->p--;\n    }\n  }\n  return char2int(*z->p);\n}\n\n\nvoid luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {\n  z->L = L;\n  z->reader = reader;\n  z->data = data;\n  z->n = 0;\n  z->p = NULL;\n}\n\n\n/* --------------------------------------------------------------- read --- */\nsize_t luaZ_read (ZIO *z, void *b, size_t n) {\n  while (n) {\n    size_t m;\n    if (luaZ_lookahead(z) == EOZ)\n      return n;  /* return number of missing bytes */\n    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */\n    memcpy(b, z->p, m);\n    z->n -= m;\n    z->p += m;\n    b = (char *)b + m;\n    n -= m;\n  }\n  return 0;\n}\n\n/* ------------------------------------------------------------------------ */\nchar *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {\n  if (n > buff->buffsize) {\n    if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;\n    luaZ_resizebuffer(L, buff, n);\n  }\n  return buff->buffer;\n}\n\n\n"
  },
  {
    "path": "src/lzio.h",
    "content": "/*\n** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $\n** Buffered streams\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lzio_h\n#define lzio_h\n\n#include \"lua.h\"\n\n#include \"lmem.h\"\n\n\n#define EOZ\t(-1)\t\t\t/* end of stream */\n\ntypedef struct Zio ZIO;\n\n#define char2int(c)\tcast(int, cast(unsigned char, (c)))\n\n#define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))\n\ntypedef struct Mbuffer {\n  char *buffer;\n  size_t n;\n  size_t buffsize;\n} Mbuffer;\n\n#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->n = 0, (buff)->buffsize = 0)\n\n#define luaZ_buffer(buff)\t((buff)->buffer)\n#define luaZ_sizebuffer(buff)\t((buff)->buffsize)\n#define luaZ_bufflen(buff)\t((buff)->n)\n\n#define luaZ_resetbuffer(buff) ((buff)->n = 0)\n\n\n#define luaZ_resizebuffer(L, buff, size) \\\n\t(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \\\n\t(buff)->buffsize = size)\n\n#define luaZ_freebuffer(L, buff)\tluaZ_resizebuffer(L, buff, 0)\n\n\nLUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);\nLUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,\n                                        void *data);\nLUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);\t/* read next n bytes */\nLUAI_FUNC int luaZ_lookahead (ZIO *z);\n\n\n\n/* --------- Private Part ------------------ */\n\nstruct Zio {\n  size_t n;\t\t\t/* bytes still unread */\n  const char *p;\t\t/* current position in buffer */\n  lua_Reader reader;\n  void* data;\t\t\t/* additional data */\n  lua_State *L;\t\t\t/* Lua state (for reader) */\n};\n\n\nLUAI_FUNC int luaZ_fill (ZIO *z);\n\n#endif\n"
  },
  {
    "path": "src/print.c",
    "content": "/*\n** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $\n** print bytecodes\n** See Copyright Notice in lua.h\n*/\n\n#include <ctype.h>\n#include <stdio.h>\n\n#define luac_c\n#define LUA_CORE\n\n#include \"ldebug.h\"\n#include \"lobject.h\"\n#include \"lopcodes.h\"\n#include \"lundump.h\"\n\n#define PrintFunction\tluaU_print\n\n#define Sizeof(x)\t((int)sizeof(x))\n#define VOID(p)\t\t((const void*)(p))\n\nstatic void PrintString(const TString* ts)\n{\n const char* s=getstr(ts);\n size_t i,n=ts->tsv.len;\n putchar('\"');\n for (i=0; i<n; i++)\n {\n  int c=s[i];\n  switch (c)\n  {\n   case '\"': printf(\"\\\\\\\"\"); break;\n   case '\\\\': printf(\"\\\\\\\\\"); break;\n   case '\\a': printf(\"\\\\a\"); break;\n   case '\\b': printf(\"\\\\b\"); break;\n   case '\\f': printf(\"\\\\f\"); break;\n   case '\\n': printf(\"\\\\n\"); break;\n   case '\\r': printf(\"\\\\r\"); break;\n   case '\\t': printf(\"\\\\t\"); break;\n   case '\\v': printf(\"\\\\v\"); break;\n   default:\tif (isprint((unsigned char)c))\n   \t\t\tputchar(c);\n\t\telse\n\t\t\tprintf(\"\\\\%03u\",(unsigned char)c);\n  }\n }\n putchar('\"');\n}\n\nstatic void PrintConstant(const Proto* f, int i)\n{\n const TValue* o=&f->k[i];\n switch (ttype(o))\n {\n  case LUA_TNIL:\n\tprintf(\"nil\");\n\tbreak;\n  case LUA_TBOOLEAN:\n\tprintf(bvalue(o) ? \"true\" : \"false\");\n\tbreak;\n  case LUA_TNUMBER:\n\tprintf(LUA_NUMBER_FMT,nvalue(o));\n\tbreak;\n  case LUA_TSTRING:\n\tPrintString(rawtsvalue(o));\n\tbreak;\n  default:\t\t\t\t/* cannot happen */\n\tprintf(\"? type=%d\",ttype(o));\n\tbreak;\n }\n}\n\nstatic void PrintCode(const Proto* f)\n{\n const Instruction* code=f->code;\n int pc,n=f->sizecode;\n for (pc=0; pc<n; pc++)\n {\n  Instruction i=code[pc];\n  OpCode o=GET_OPCODE(i);\n  int a=GETARG_A(i);\n  int b=GETARG_B(i);\n  int c=GETARG_C(i);\n  int bx=GETARG_Bx(i);\n  int sbx=GETARG_sBx(i);\n  int line=getlinenum(f,pc);\n  printf(\"\\t%d\\t\",pc+1);\n  if (line>0) printf(\"[%d]\\t\",line); else printf(\"[-]\\t\");\n  printf(\"%-9s\\t\",luaP_opnames[o]);\n  switch (getOpMode(o))\n  {\n   case iABC:\n    printf(\"%d\",a);\n    if (getBMode(o)!=OpArgN) printf(\" %d\",ISK(b) ? (-1-INDEXK(b)) : b);\n    if (getCMode(o)!=OpArgN) printf(\" %d\",ISK(c) ? (-1-INDEXK(c)) : c);\n    break;\n   case iABx:\n    if (getBMode(o)==OpArgK) printf(\"%d %d\",a,-1-bx); else printf(\"%d %d\",a,bx);\n    break;\n   case iAsBx:\n    if (o==OP_JMP) printf(\"%d\",sbx); else printf(\"%d %d\",a,sbx);\n    break;\n  }\n  switch (o)\n  {\n   case OP_LOADK:\n    printf(\"\\t; \"); PrintConstant(f,bx);\n    break;\n   case OP_GETUPVAL:\n   case OP_SETUPVAL:\n    printf(\"\\t; %s\", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : \"-\");\n    break;\n   case OP_GETGLOBAL:\n   case OP_SETGLOBAL:\n    printf(\"\\t; %s\",svalue(&f->k[bx]));\n    break;\n   case OP_GETTABLE:\n   case OP_SELF:\n    if (ISK(c)) { printf(\"\\t; \"); PrintConstant(f,INDEXK(c)); }\n    break;\n   case OP_SETTABLE:\n   case OP_ADD:\n   case OP_SUB:\n   case OP_MUL:\n   case OP_DIV:\n   case OP_POW:\n   case OP_EQ:\n   case OP_LT:\n   case OP_LE:\n    if (ISK(b) || ISK(c))\n    {\n     printf(\"\\t; \");\n     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(\"-\");\n     printf(\" \");\n     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(\"-\");\n    }\n    break;\n   case OP_JMP:\n   case OP_FORLOOP:\n   case OP_FORPREP:\n    printf(\"\\t; to %d\",sbx+pc+2);\n    break;\n   case OP_CLOSURE:\n    printf(\"\\t; %p\",VOID(f->p[bx]));\n    break;\n   case OP_SETLIST:\n    if (c==0) printf(\"\\t; %d\",(int)code[++pc]);\n    else printf(\"\\t; %d\",c);\n    break;\n   default:\n    break;\n  }\n  printf(\"\\n\");\n }\n}\n\n#define SS(x)\t(x==1)?\"\":\"s\"\n#define S(x)\tx,SS(x)\n\nstatic void PrintHeader(const Proto* f)\n{\n const char* s=getstr(f->source);\n if (*s=='@' || *s=='=')\n  s++;\n else if (*s==LUA_SIGNATURE[0])\n  s=\"(bstring)\";\n else\n  s=\"(string)\";\n printf(\"\\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\\n\",\n \t(f->linedefined==0)?\"main\":\"function\",s,\n\tf->linedefined,f->lastlinedefined,\n\tS(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));\n printf(\"%d%s param%s, %d slot%s, %d upvalue%s, \",\n\tf->numparams,f->is_vararg?\"+\":\"\",SS(f->numparams),\n\tS(f->maxstacksize),S(f->nups));\n printf(\"%d local%s, %d constant%s, %d function%s\\n\",\n\tS(f->sizelocvars),S(f->sizek),S(f->sizep));\n}\n\nstatic void PrintConstants(const Proto* f)\n{\n int i,n=f->sizek;\n printf(\"constants (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t\",i+1);\n  PrintConstant(f,i);\n  printf(\"\\n\");\n }\n}\n\nstatic void PrintLocals(const Proto* f)\n{\n int i,n=f->sizelocvars;\n printf(\"locals (%d) for %p:\\n\",n,VOID(f));\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\t%d\\t%d\\n\",\n  i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);\n }\n}\n\nstatic void PrintUpvalues(const Proto* f)\n{\n int i,n=f->sizeupvalues;\n printf(\"upvalues (%d) for %p:\\n\",n,VOID(f));\n if (f->upvalues==NULL) return;\n for (i=0; i<n; i++)\n {\n  printf(\"\\t%d\\t%s\\n\",i,getstr(f->upvalues[i]));\n }\n}\n\nvoid PrintFunction(const Proto* f, int full)\n{\n int i,n=f->sizep;\n PrintHeader(f);\n PrintCode(f);\n if (full)\n {\n  PrintConstants(f);\n  PrintLocals(f);\n  PrintUpvalues(f);\n }\n for (i=0; i<n; i++) PrintFunction(f->p[i],full);\n}\n"
  },
  {
    "path": "test/README",
    "content": "These are simple tests for Lua.  Some of them contain useful code.\nThey are meant to be run to make sure Lua is built correctly and also\nto be read, to see how Lua programs look.\n\nHere is a one-line summary of each program:\n\n   bisect.lua\t\tbisection method for solving non-linear equations\n   cf.lua\t\ttemperature conversion table (celsius to farenheit)\n   echo.lua             echo command line arguments\n   env.lua              environment variables as automatic global variables\n   factorial.lua\tfactorial without recursion\n   fib.lua\t\tfibonacci function with cache\n   fibfor.lua\t\tfibonacci numbers with coroutines and generators\n   globals.lua\t\treport global variable usage\n   hello.lua\t\tthe first program in every language\n   life.lua\t\tConway's Game of Life\n   luac.lua\t \tbare-bones luac\n   printf.lua\t\tan implementation of printf\n   readonly.lua\t\tmake global variables readonly\n   sieve.lua\t\tthe sieve of of Eratosthenes programmed with coroutines\n   sort.lua\t\ttwo implementations of a sort function\n   table.lua\t\tmake table, grouping all data for the same item\n   trace-calls.lua\ttrace calls\n   trace-globals.lua\ttrace assigments to global variables\n   xd.lua\t\thex dump\n\n"
  },
  {
    "path": "test/bisect.lua",
    "content": "-- bisection method for solving non-linear equations\n\ndelta=1e-6\t-- tolerance\n\nfunction bisect(f,a,b,fa,fb)\n local c=(a+b)/2\n io.write(n,\" c=\",c,\" a=\",a,\" b=\",b,\"\\n\")\n if c==a or c==b or math.abs(a-b)<delta then return c,b-a end\n n=n+1\n local fc=f(c)\n if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end\nend\n\n-- find root of f in the inverval [a,b]. needs f(a)*f(b)<0\nfunction solve(f,a,b)\n n=0\n local z,e=bisect(f,a,b,f(a),f(b))\n io.write(string.format(\"after %d steps, root is %.17g with error %.1e, f=%.1e\\n\",n,z,e,f(z)))\nend\n\n-- our function\nfunction f(x)\n return x*x*x-x-1\nend\n\n-- find zero in [1,2]\nsolve(f,1,2)\n"
  },
  {
    "path": "test/cf.lua",
    "content": "-- temperature conversion table (celsius to farenheit)\n\nfor c0=-20,50-1,10 do\n\tio.write(\"C \")\n\tfor c=c0,c0+10-1 do\n\t\tio.write(string.format(\"%3.0f \",c))\n\tend\n\tio.write(\"\\n\")\n\t\n\tio.write(\"F \")\n\tfor c=c0,c0+10-1 do\n\t\tf=(9/5)*c+32\n\t\tio.write(string.format(\"%3.0f \",f))\n\tend\n\tio.write(\"\\n\\n\")\nend\n"
  },
  {
    "path": "test/echo.lua",
    "content": "-- echo command line arguments\n\nfor i=0,#arg do\n print(i,arg[i])\nend\n"
  },
  {
    "path": "test/env.lua",
    "content": "-- read environment variables as if they were global variables\n\nlocal f=function (t,i) return os.getenv(i) end\nsetmetatable(getfenv(),{__index=f})\n\n-- an example\nprint(a,USER,PATH)\n"
  },
  {
    "path": "test/factorial.lua",
    "content": "-- function closures are powerful\n\n-- traditional fixed-point operator from functional programming\nY = function (g)\n      local a = function (f) return f(f) end\n      return a(function (f)\n                 return g(function (x)\n                             local c=f(f)\n                             return c(x)\n                           end)\n               end)\nend\n\n\n-- factorial without recursion\nF = function (f)\n      return function (n)\n               if n == 0 then return 1\n               else return n*f(n-1) end\n             end\n    end\n\nfactorial = Y(F)   -- factorial is the fixed point of F\n\n-- now test it\nfunction test(x)\n\tio.write(x,\"! = \",factorial(x),\"\\n\")\nend\n\nfor n=0,16 do\n\ttest(n)\nend\n"
  },
  {
    "path": "test/fib.lua",
    "content": "-- fibonacci function with cache\n\n-- very inefficient fibonacci function\nfunction fib(n)\n\tN=N+1\n\tif n<2 then\n\t\treturn n\n\telse\n\t\treturn fib(n-1)+fib(n-2)\n\tend\nend\n\n-- a general-purpose value cache\nfunction cache(f)\n\tlocal c={}\n\treturn function (x)\n\t\tlocal y=c[x]\n\t\tif not y then\n\t\t\ty=f(x)\n\t\t\tc[x]=y\n\t\tend\n\t\treturn y\n\tend\nend\n\n-- run and time it\nfunction test(s,f)\n\tN=0\n\tlocal c=os.clock()\n\tlocal v=f(n)\n\tlocal t=os.clock()-c\n\tprint(s,n,v,t,N)\nend\n\nn=arg[1] or 24\t\t-- for other values, do lua fib.lua XX\nn=tonumber(n)\nprint(\"\",\"n\",\"value\",\"time\",\"evals\")\ntest(\"plain\",fib)\nfib=cache(fib)\ntest(\"cached\",fib)\n"
  },
  {
    "path": "test/fibfor.lua",
    "content": "-- example of for with generator functions\n\nfunction generatefib (n)\n  return coroutine.wrap(function ()\n    local a,b = 1, 1\n    while a <= n do\n      coroutine.yield(a)\n      a, b = b, a+b\n    end\n  end)\nend\n\nfor i in generatefib(1000) do print(i) end\n"
  },
  {
    "path": "test/globals.lua",
    "content": "-- reads luac listings and reports global variable usage\n-- lines where a global is written to are marked with \"*\"\n-- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua\n\nwhile 1 do\n local s=io.read()\n if s==nil then break end\n local ok,_,l,op,g=string.find(s,\"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$\")\n if ok then\n  if op==\"S\" then op=\"*\" else op=\"\" end\n  io.write(g,\"\\t\",l,op,\"\\n\")\n end\nend\n"
  },
  {
    "path": "test/hello.lua",
    "content": "-- the first program in every language\n\nio.write(\"Hello world, from \",_VERSION,\"!\\n\")\n"
  },
  {
    "path": "test/life.lua",
    "content": "-- life.lua\n-- original by Dave Bollinger <DBollinger@compuserve.com> posted to lua-l\n-- modified to use ANSI terminal escape sequences\n-- modified to use for instead of while\n\nlocal write=io.write\n\nALIVE=\"\"\tDEAD=\"\"\nALIVE=\"O\"\tDEAD=\"-\"\n\nfunction delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary\n  for i=1,10000 do end\n  -- local i=os.clock()+1 while(os.clock()<i) do end\nend\n\nfunction ARRAY2D(w,h)\n  local t = {w=w,h=h}\n  for y=1,h do\n    t[y] = {}\n    for x=1,w do\n      t[y][x]=0\n    end\n  end\n  return t\nend\n\n_CELLS = {}\n\n-- give birth to a \"shape\" within the cell array\nfunction _CELLS:spawn(shape,left,top)\n  for y=0,shape.h-1 do\n    for x=0,shape.w-1 do\n      self[top+y][left+x] = shape[y*shape.w+x+1]\n    end\n  end\nend\n\n-- run the CA and produce the next generation\nfunction _CELLS:evolve(next)\n  local ym1,y,yp1,yi=self.h-1,self.h,1,self.h\n  while yi > 0 do\n    local xm1,x,xp1,xi=self.w-1,self.w,1,self.w\n    while xi > 0 do\n      local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] +\n                  self[y][xm1] + self[y][xp1] +\n                  self[yp1][xm1] + self[yp1][x] + self[yp1][xp1]\n      next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0\n      xm1,x,xp1,xi = x,xp1,xp1+1,xi-1\n    end\n    ym1,y,yp1,yi = y,yp1,yp1+1,yi-1\n  end\nend\n\n-- output the array to screen\nfunction _CELLS:draw()\n  local out=\"\" -- accumulate to reduce flicker\n  for y=1,self.h do\n   for x=1,self.w do\n      out=out..(((self[y][x]>0) and ALIVE) or DEAD)\n    end\n    out=out..\"\\n\"\n  end\n  write(out)\nend\n\n-- constructor\nfunction CELLS(w,h)\n  local c = ARRAY2D(w,h)\n  c.spawn = _CELLS.spawn\n  c.evolve = _CELLS.evolve\n  c.draw = _CELLS.draw\n  return c\nend\n\n--\n-- shapes suitable for use with spawn() above\n--\nHEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 }\nGLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 }\nEXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 }\nFISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 }\nBUTTERFLY = { 1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1; w=5,h=5 }\n\n-- the main routine\nfunction LIFE(w,h)\n  -- create two arrays\n  local thisgen = CELLS(w,h)\n  local nextgen = CELLS(w,h)\n\n  -- create some life\n  -- about 1000 generations of fun, then a glider steady-state\n  thisgen:spawn(GLIDER,5,4)\n  thisgen:spawn(EXPLODE,25,10)\n  thisgen:spawn(FISH,4,12)\n\n  -- run until break\n  local gen=1\n  write(\"\\027[2J\")\t-- ANSI clear screen\n  while 1 do\n    thisgen:evolve(nextgen)\n    thisgen,nextgen = nextgen,thisgen\n    write(\"\\027[H\")\t-- ANSI home cursor\n    thisgen:draw()\n    write(\"Life - generation \",gen,\"\\n\")\n    gen=gen+1\n    if gen>2000 then break end\n    --delay()\t\t-- no delay\n  end\nend\n\nLIFE(40,20)\n"
  },
  {
    "path": "test/luac.lua",
    "content": "-- bare-bones luac in Lua\n-- usage: lua luac.lua file.lua\n\nassert(arg[1]~=nil and arg[2]==nil,\"usage: lua luac.lua file.lua\")\nf=assert(io.open(\"luac.out\",\"wb\"))\nassert(f:write(string.dump(assert(loadfile(arg[1])))))\nassert(f:close())\n"
  },
  {
    "path": "test/printf.lua",
    "content": "-- an implementation of printf\n\nfunction printf(...)\n io.write(string.format(...))\nend\n\nprintf(\"Hello %s from %s on %s\\n\",os.getenv\"USER\" or \"there\",_VERSION,os.date())\n"
  },
  {
    "path": "test/readonly.lua",
    "content": "-- make global variables readonly\n\nlocal f=function (t,i) error(\"cannot redefine global variable `\"..i..\"'\",2) end\nlocal g={}\nlocal G=getfenv()\nsetmetatable(g,{__index=G,__newindex=f})\nsetfenv(1,g)\n\n-- an example\nrawset(g,\"x\",3)\nx=2\ny=1\t-- cannot redefine `y'\n"
  },
  {
    "path": "test/sieve.lua",
    "content": "-- the sieve of of Eratosthenes programmed with coroutines\n-- typical usage: lua -e N=1000 sieve.lua | column\n\n-- generate all the numbers from 2 to n\nfunction gen (n)\n  return coroutine.wrap(function ()\n    for i=2,n do coroutine.yield(i) end\n  end)\nend\n\n-- filter the numbers generated by `g', removing multiples of `p'\nfunction filter (p, g)\n  return coroutine.wrap(function ()\n    while 1 do\n      local n = g()\n      if n == nil then return end\n      if math.fmod(n, p) ~= 0 then coroutine.yield(n) end\n    end\n  end)\nend\n\nN=N or 1000\t\t-- from command line\nx = gen(N)\t\t-- generate primes up to N\nwhile 1 do\n  local n = x()\t\t-- pick a number until done\n  if n == nil then break end\n  print(n)\t\t-- must be a prime number\n  x = filter(n, x)\t-- now remove its multiples\nend\n"
  },
  {
    "path": "test/sort.lua",
    "content": "-- two implementations of a sort function\n-- this is an example only. Lua has now a built-in function \"sort\"\n\n-- extracted from Programming Pearls, page 110\nfunction qsort(x,l,u,f)\n if l<u then\n  local m=math.random(u-(l-1))+l-1\t-- choose a random pivot in range l..u\n  x[l],x[m]=x[m],x[l]\t\t\t-- swap pivot to first position\n  local t=x[l]\t\t\t\t-- pivot value\n  m=l\n  local i=l+1\n  while i<=u do\n    -- invariant: x[l+1..m] < t <= x[m+1..i-1]\n    if f(x[i],t) then\n      m=m+1\n      x[m],x[i]=x[i],x[m]\t\t-- swap x[i] and x[m]\n    end\n    i=i+1\n  end\n  x[l],x[m]=x[m],x[l]\t\t\t-- swap pivot to a valid place\n  -- x[l+1..m-1] < x[m] <= x[m+1..u]\n  qsort(x,l,m-1,f)\n  qsort(x,m+1,u,f)\n end\nend\n\nfunction selectionsort(x,n,f)\n local i=1\n while i<=n do\n  local m,j=i,i+1\n  while j<=n do\n   if f(x[j],x[m]) then m=j end\n   j=j+1\n  end\n x[i],x[m]=x[m],x[i]\t\t\t-- swap x[i] and x[m]\n i=i+1\n end\nend\n\nfunction show(m,x)\n io.write(m,\"\\n\\t\")\n local i=1\n while x[i] do\n  io.write(x[i])\n  i=i+1\n  if x[i] then io.write(\",\") end\n end\n io.write(\"\\n\")\nend\n\nfunction testsorts(x)\n local n=1\n while x[n] do n=n+1 end; n=n-1\t\t-- count elements\n show(\"original\",x)\n qsort(x,1,n,function (x,y) return x<y end)\n show(\"after quicksort\",x)\n selectionsort(x,n,function (x,y) return x>y end)\n show(\"after reverse selection sort\",x)\n qsort(x,1,n,function (x,y) return x<y end)\n show(\"after quicksort again\",x)\nend\n\n-- array to be sorted\nx={\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\"}\n\ntestsorts(x)\n"
  },
  {
    "path": "test/table.lua",
    "content": "-- make table, grouping all data for the same item\n-- input is 2 columns (item, data)\n\nlocal A\nwhile 1 do\n local l=io.read()\n if l==nil then break end\n local _,_,a,b=string.find(l,'\"?([_%w]+)\"?%s*(.*)$')\n if a~=A then A=a io.write(\"\\n\",a,\":\") end\n io.write(\" \",b)\nend\nio.write(\"\\n\")\n"
  },
  {
    "path": "test/trace-calls.lua",
    "content": "-- trace calls\n-- example: lua -ltrace-calls bisect.lua\n\nlocal level=0\n\nlocal function hook(event)\n local t=debug.getinfo(3)\n io.write(level,\" >>> \",string.rep(\" \",level))\n if t~=nil and t.currentline>=0 then io.write(t.short_src,\":\",t.currentline,\" \") end\n t=debug.getinfo(2)\n if event==\"call\" then\n  level=level+1\n else\n  level=level-1 if level<0 then level=0 end\n end\n if t.what==\"main\" then\n  if event==\"call\" then\n   io.write(\"begin \",t.short_src)\n  else\n   io.write(\"end \",t.short_src)\n  end\n elseif t.what==\"Lua\" then\n-- table.foreach(t,print)\n  io.write(event,\" \",t.name or \"(Lua)\",\" <\",t.linedefined,\":\",t.short_src,\">\")\n else\n io.write(event,\" \",t.name or \"(C)\",\" [\",t.what,\"] \")\n end\n io.write(\"\\n\")\nend\n\ndebug.sethook(hook,\"cr\")\nlevel=0\n"
  },
  {
    "path": "test/trace-globals.lua",
    "content": "-- trace assigments to global variables\n\ndo\n -- a tostring that quotes strings. note the use of the original tostring.\n local _tostring=tostring\n local tostring=function(a)\n  if type(a)==\"string\" then\n   return string.format(\"%q\",a)\n  else\n   return _tostring(a)\n  end\n end\n\n local log=function (name,old,new)\n  local t=debug.getinfo(3,\"Sl\")\n  local line=t.currentline\n  io.write(t.short_src)\n  if line>=0 then io.write(\":\",line) end\n  io.write(\": \",name,\" is now \",tostring(new),\" (was \",tostring(old),\")\",\"\\n\")\n end\n\n local g={}\n local set=function (t,name,value)\n  log(name,g[name],value)\n  g[name]=value\n end\n setmetatable(getfenv(),{__index=g,__newindex=set})\nend\n\n-- an example\n\na=1\nb=2\na=10\nb=20\nb=nil\nb=200\nprint(a,b,c)\n"
  },
  {
    "path": "test/xd.lua",
    "content": "-- hex dump\n-- usage: lua xd.lua < file\n\nlocal offset=0\nwhile true do\n local s=io.read(16)\n if s==nil then return end\n io.write(string.format(\"%08X  \",offset))\n string.gsub(s,\"(.)\",\n\tfunction (c) io.write(string.format(\"%02X \",string.byte(c))) end)\n io.write(string.rep(\" \",3*(16-string.len(s))))\n io.write(\" \",string.gsub(s,\"%c\",\".\"),\"\\n\") \n offset=offset+16\nend\n"
  },
  {
    "path": "tools/hg_import_split.lua",
    "content": "\nlocal patch = arg[1]\nif not patch then\n\tprint(\"run:\", arg[0] .. \"<hg_patch_set>\")\n\treturn\nend\n\nlocal prefix, ext = patch:match(\"^(.*)%.(.*)$\")\n\nprint(\"split HG patch set:\", prefix .. '.' .. ext)\n\nlocal input = io.open(patch, \"rb\")\n\nlocal part = 0\nlocal output\n\nlocal function append_line(line)\n\tif output then\n\t\toutput:write(line, '\\n')\n\tend\nend\n\nlocal function open_next_output()\n\tif output then\n\t\t-- close previous patch.\n\t\toutput:close()\n\t\toutput = nil\n\tend\n\tpart = part + 1\n\tlocal name = string.format(\"%s_%d.%s\", prefix, part, ext)\n\tprint(\"Start patch file:\", name)\n\toutput = io.open(name, \"w+b\")\nend\n\nfor line in input:lines() do\n\tif line == \"# HG changeset patch\" then\n\t\topen_next_output()\n\tend\n\tappend_line(line)\nend\n\nif output then\n\toutput:close()\nend\n\n"
  }
]