Index: ps/trunk/LICENSE.txt =================================================================== --- ps/trunk/LICENSE.txt +++ ps/trunk/LICENSE.txt @@ -36,7 +36,6 @@ /build Various (unspecified) - /build/premake/premake4 /build/premake/premake5 BSD Index: ps/trunk/build/premake/extern_libs4.lua =================================================================== --- ps/trunk/build/premake/extern_libs4.lua +++ ps/trunk/build/premake/extern_libs4.lua @@ -1,782 +0,0 @@ --- this file provides project_add_extern_libs, which takes care of the --- dirty details of adding the libraries' include and lib paths. --- --- TYPICAL TASK: add new library. Instructions: --- 1) add a new extern_lib_defs entry --- 2) add library name to extern_libs tables in premake.lua for all 'projects' that want to use it - - --- directory in which OS-specific library subdirectories reside. -if os.is("macosx") then - libraries_dir = rootdir.."/libraries/osx/" -elseif os.is("windows") then - libraries_dir = rootdir.."/libraries/win32/" -else - -- No Unix-specific libs yet (use source directory instead!) -end --- directory for shared, bundled libraries -libraries_source_dir = rootdir.."/libraries/source/" -third_party_source_dir = rootdir.."/source/third_party/" - -local function add_default_lib_paths(extern_lib) - libdirs { libraries_dir .. extern_lib .. "/lib" } -end - -local function add_source_lib_paths(extern_lib) - libdirs { libraries_source_dir .. extern_lib .. "/lib" } -end - -local function add_default_include_paths(extern_lib) - includedirs { libraries_dir .. extern_lib .. "/include" } -end - -local function add_source_include_paths(extern_lib) - includedirs { libraries_source_dir .. extern_lib .. "/include" } -end - -local function add_third_party_include_paths(extern_lib) - includedirs { third_party_source_dir .. extern_lib .. "/include" } -end - - --- For unixes: add buildflags and linkflags using pkg-config or another similar command. --- By default, pkg-config is used. Other commands can be passed as "alternative_cmd". --- Running such commands at build/linktime does not work on all environments. --- For those environments where it does not work, we already run it now. --- Any better ideas? -local function pkgconfig_cflags(lib, alternative_cmd) - local cmd_cflags = "" - local result_cflags - if not alternative_cmd then - cmd_cflags = "pkg-config "..lib.." --cflags" - else - cmd_cflags = alternative_cmd - end - - if _ACTION == "xcode3" or _ACTION == "xcode4" then - result_cflags = string.gsub(os.capture(cmd_cflags), "\n", "") - buildoptions { result_cflags } - else - buildoptions { "`"..cmd_cflags.."`" } - end -end - -local function pkgconfig_libs(lib, alternative_cmd) - local cmd_libs = "" - local result_libs - if not alternative_cmd then - cmd_libs = "pkg-config "..lib.." --libs" - else - cmd_libs = alternative_cmd - end - - if _ACTION == "xcode3" or _ACTION == "xcode4" then - -- The syntax of -Wl with the comma separated list doesn't work and -Wl apparently isn't needed in xcode. - -- This is a hack, but it works... - result_libs = string.gsub(os.capture(cmd_libs), "-Wl", "") - result_libs = string.gsub(result_libs, ",", " ") - result_libs = string.gsub(result_libs, "\n", "") - linkoptions { result_libs } - elseif _ACTION == "gmake" then - gnuexternals { "`"..cmd_libs.."`" } - else - linkoptions { "`"..cmd_libs.."`" } - end -end - -function os.capture(cmd) - local f = io.popen(cmd, 'r') - local s = f:read('*a') - return s -end - -local function add_delayload(name, suffix, def) - - if def["no_delayload"] then - return - end - - -- currently only supported by VC; nothing to do on other platforms. - if not os.is("windows") then - return - end - - -- no extra debug version; use same library in all configs - if suffix == "" then - linkoptions { "/DELAYLOAD:"..name..".dll" } - -- extra debug version available; use in debug config - else - local dbg_cmd = "/DELAYLOAD:" .. name .. suffix .. ".dll" - local cmd = "/DELAYLOAD:" .. name .. ".dll" - - configuration "Debug" - linkoptions { dbg_cmd } - configuration "Release" - linkoptions { cmd } - configuration { } - end - -end - -local function add_default_links(def) - - -- careful: make sure to only use *_names when on the correct platform. - local names = {} - if os.is("windows") then - if def.win_names then - names = def.win_names - end - elseif _OPTIONS["android"] and def.android_names then - names = def.android_names - elseif os.is("linux") and def.linux_names then - names = def.linux_names - elseif os.is("macosx") and def.osx_names then - names = def.osx_names - elseif os.is("bsd") and def.bsd_names then - names = def.bsd_names - elseif def.unix_names then - names = def.unix_names - end - - local suffix = "d" - -- library is overriding default suffix (typically "" to indicate there is none) - if def["dbg_suffix"] then - suffix = def["dbg_suffix"] - end - -- non-Windows doesn't have the distinction of debug vs. release libraries - -- (to be more specific, they do, but the two are binary compatible; - -- usually only one type - debug or release - is installed at a time). - if not os.is("windows") then - suffix = "" - end - - -- OS X "Frameworks" need to be added in a special way to the link - -- i.e. by linkoptions += "-framework ..." - if os.is("macosx") and def.osx_frameworks then - for i,name in pairs(def.osx_frameworks) do - linkoptions { "-framework " .. name } - end - else - for i,name in pairs(names) do - configuration "Debug" - links { name .. suffix } - configuration "Release" - links { name } - configuration { } - - add_delayload(name, suffix, def) - end - end -end - --- Library definitions --- In a perfect world, libraries would have a common installation template, --- i.e. location of include directory, naming convention for .lib, etc. --- this table provides a means of working around each library's differences. --- --- The basic approach is defining two functions per library: --- --- 1. compile_settings --- This function should set all settings requred during the compile-phase like --- includedirs, defines etc... --- --- 2. link_settings --- This function should set all settings required during the link-phase like --- libdirs, linkflag etc... --- --- The main reason for separating those settings is different linking behaviour --- on osx and xcode. For more details, read the comment in project_add_extern_libs. --- --- There are some helper functions for the most common tasks. You should use them --- if they can be used in your situation to make the definitions more consistent and --- use their default beviours as a guideline. --- --- --- add_default_lib_paths(extern_lib) --- Description: Add '//lib'to the libpaths --- Parameters: --- * extern_lib: to be used in the libpath. --- --- add_default_include_paths(extern_lib) --- Description: Add '//include' to the includepaths --- Parameters: --- * extern_lib: to be used in the libpath. --- --- add_default_links --- Description: Adds links to libraries and configures delayloading. --- If the *_names parameter for a plattform is missing, no linking will be done --- on that plattform. --- The default assumptions are: --- * debug import library and DLL are distinguished with a "d" suffix --- * the library should be marked for delay-loading. --- Parameters: --- * win_names: table of import library / DLL names (no extension) when --- running on Windows. --- * unix_names: as above; shared object names when running on non-Windows. --- * osx_names: as above; for OS X specifically (overrides unix_names if both are --- specified) --- * bsd_names: as above; for BSD specifically (overrides unix_names if both are --- specified) --- * linux_names: ditto for Linux (overrides unix_names if both given) --- * dbg_suffix: changes the debug suffix from the above default. --- can be "" to indicate the library doesn't have a debug build; --- in that case, the same library (without suffix) is used in --- all build configurations. --- * no_delayload: indicate the library is not to be delay-loaded. --- this is necessary for some libraries that do not support it, --- e.g. Xerces (which is so stupid as to export variables). - -extern_lib_defs = { - boost = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("boost") - elseif os.is("macosx") then - -- Suppress all the Boost warnings on OS X by including it as a system directory - buildoptions { "-isystem../" .. libraries_dir .. "boost/include" } - end - -- TODO: This actually applies to most libraries we use on BSDs, make this a global setting. - if os.is("bsd") then - includedirs { "/usr/local/include" } - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("boost") - end - add_default_links({ - -- The following are not strictly link dependencies on all systems, but - -- are included for compatibility with different versions of Boost - android_names = { "boost_filesystem-gcc-mt", "boost_system-gcc-mt" }, - unix_names = { os.findlib("boost_filesystem-mt") and "boost_filesystem-mt" or "boost_filesystem", os.findlib("boost_system-mt") and "boost_system-mt" or "boost_system" }, - osx_names = { "boost_filesystem-mt", "boost_system-mt" }, - }) - end, - }, - comsuppw = { - link_settings = function() - add_default_links({ - win_names = { "comsuppw" }, - dbg_suffix = "d", - no_delayload = 1, - }) - end, - }, - cxxtest = { - compile_settings = function() - includedirs { libraries_source_dir .. "cxxtest-4.4" } - end, - }, - enet = { - compile_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_include_paths("enet") - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("enet") - end - add_default_links({ - win_names = { "enet" }, - unix_names = { "enet" }, - }) - end, - }, - fcollada = { - compile_settings = function() - add_source_include_paths("fcollada") - end, - link_settings = function() - add_source_lib_paths("fcollada") - if os.is("windows") then - configuration "Debug" - links { "FColladaD" } - configuration "Release" - links { "FCollada" } - configuration { } - else - configuration "Debug" - links { "FColladaSD" } - configuration "Release" - links { "FColladaSR" } - configuration { } - end - end, - }, - gloox = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("gloox") - elseif os.is("macosx") then - -- Support GLOOX_CONFIG for overriding the default PATH-based gloox-config - gloox_config_path = os.getenv("GLOOX_CONFIG") - if not gloox_config_path then - gloox_config_path = "gloox-config" - end - pkgconfig_cflags(nil, gloox_config_path.." --cflags") - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("gloox") - end - if os.is("macosx") then - gloox_config_path = os.getenv("GLOOX_CONFIG") - if not gloox_config_path then - gloox_config_path = "gloox-config" - end - pkgconfig_libs(nil, gloox_config_path.." --libs") - else - -- TODO: consider using pkg-config on non-Windows (for compile_settings too) - add_default_links({ - win_names = { "gloox-1.0" }, - unix_names = { "gloox" }, - no_delayload = 1, - }) - end - end, - }, - iconv = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("iconv") - defines { "HAVE_ICONV_CONST" } - defines { "ICONV_CONST=const" } - defines { "LIBICONV_STATIC" } - elseif os.is("macosx") then - add_default_include_paths("iconv") - defines { "LIBICONV_STATIC" } - elseif os.getversion().description == "FreeBSD" then - defines { "HAVE_ICONV_CONST" } - defines { "ICONV_CONST=const" } - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("iconv") - end - add_default_links({ - win_names = { "libiconv" }, - osx_names = { "iconv" }, - dbg_suffix = "", - no_delayload = 1, - }) - -- glibc (used on Linux and GNU/kFreeBSD) has iconv - -- FreeBSD 10+ has iconv as a part of libc - if os.is("bsd") - and not (os.getversion().description == "FreeBSD" and os.getversion().majorversion >= 10 - or os.getversion().description == "GNU/kFreeBSD") then - add_default_links({ - bsd_names = { "iconv" }, - }) - end - end, - }, - icu = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("icu") - elseif os.is("macosx") then - -- Support ICU_CONFIG for overriding the default PATH-based icu-config - icu_config_path = os.getenv("ICU_CONFIG") - if not icu_config_path then - icu_config_path = "icu-config" - end - pkgconfig_cflags(nil, icu_config_path.." --cppflags") - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("icu") - end - if os.is("macosx") then - icu_config_path = os.getenv("ICU_CONFIG") - if not icu_config_path then - icu_config_path = "gloox-config" - end - pkgconfig_libs(nil, icu_config_path.." --ldflags-searchpath --ldflags-libsonly --ldflags-system") - else - add_default_links({ - win_names = { "icuuc", "icuin" }, - unix_names = { "icui18n", "icuuc" }, - dbg_suffix = "", - no_delayload = 1, - }) - end - end, - }, - libcurl = { - compile_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_include_paths("libcurl") - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("libcurl") - end - add_default_links({ - win_names = { "libcurl" }, - unix_names = { "curl" }, - }) - end, - }, - libpng = { - compile_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_include_paths("libpng") - end - if os.getversion().description == "OpenBSD" then - includedirs { "/usr/local/include/libpng" } - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("libpng") - end - add_default_links({ - win_names = { "libpng16" }, - unix_names = { "png" }, - -- Otherwise ld will sometimes pull in ancient 1.2 from the SDK, which breaks the build :/ - -- TODO: Figure out why that happens - osx_names = { "png16" }, - }) - end, - }, - libsodium = { - compile_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_include_paths("libsodium") - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("libsodium") - end - add_default_links({ - win_names = { "libsodium" }, - unix_names = { "sodium" }, - }) - end, - }, - libxml2 = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("libxml2") - elseif os.is("macosx") then - -- Support XML2_CONFIG for overriding for the default PATH-based xml2-config - xml2_config_path = os.getenv("XML2_CONFIG") - if not xml2_config_path then - xml2_config_path = "xml2-config" - end - - -- use xml2-config instead of pkg-config on OS X - pkgconfig_cflags(nil, xml2_config_path.." --cflags") - -- libxml2 needs _REENTRANT or __MT__ for thread support; - -- OS X doesn't get either set by default, so do it manually - defines { "_REENTRANT" } - else - pkgconfig_cflags("libxml-2.0") - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("libxml2") - configuration "Debug" - links { "libxml2" } - configuration "Release" - links { "libxml2" } - configuration { } - elseif os.is("macosx") then - xml2_config_path = os.getenv("XML2_CONFIG") - if not xml2_config_path then - xml2_config_path = "xml2-config" - end - pkgconfig_libs(nil, xml2_config_path.." --libs") - else - pkgconfig_libs("libxml-2.0") - end - end, - }, - miniupnpc = { - compile_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_include_paths("miniupnpc") - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("miniupnpc") - end - add_default_links({ - win_names = { "miniupnpc" }, - unix_names = { "miniupnpc" }, - }) - end, - }, - nvtt = { - compile_settings = function() - if not _OPTIONS["with-system-nvtt"] then - add_source_include_paths("nvtt") - end - defines { "NVTT_SHARED=1" } - end, - link_settings = function() - if not _OPTIONS["with-system-nvtt"] then - add_source_lib_paths("nvtt") - end - add_default_links({ - win_names = { "nvtt" }, - unix_names = { "nvcore", "nvmath", "nvimage", "nvtt" }, - osx_names = { "nvcore", "nvmath", "nvimage", "nvtt", "squish" }, - dbg_suffix = "", -- for performance we always use the release-mode version - }) - end, - }, - openal = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("openal") - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("openal") - end - add_default_links({ - win_names = { "openal32" }, - unix_names = { "openal" }, - osx_frameworks = { "OpenAL" }, - dbg_suffix = "", - no_delayload = 1, -- delayload seems to cause errors on startup - }) - end, - }, - opengl = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("opengl") - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("opengl") - end - if _OPTIONS["gles"] then - add_default_links({ - unix_names = { "GLESv2" }, - dbg_suffix = "", - }) - else - add_default_links({ - win_names = { "opengl32", "gdi32" }, - unix_names = { "GL" }, - osx_frameworks = { "OpenGL" }, - dbg_suffix = "", - no_delayload = 1, -- delayload seems to cause errors on startup - }) - end - end, - }, - sdl = { - compile_settings = function() - if os.is("windows") then - includedirs { libraries_dir .. "sdl2/include/SDL" } - elseif not _OPTIONS["android"] then - -- Support SDL2_CONFIG for overriding the default (pkg-config sdl2) - -- i.e. on OSX where it gets set in update-workspaces.sh - sdl_config_path = os.getenv("SDL2_CONFIG") - if sdl_config_path then - pkgconfig_cflags(nil, sdl_config_path.." --cflags") - else - pkgconfig_cflags("sdl2") - end - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("sdl2") - elseif not _OPTIONS["android"] then - sdl_config_path = os.getenv("SDL2_CONFIG") - if sdl_config_path then - pkgconfig_libs(nil, sdl_config_path.." --libs") - else - pkgconfig_libs("sdl2") - end - end - end, - }, - spidermonkey = { - compile_settings = function() - if _OPTIONS["with-system-mozjs38"] then - if not _OPTIONS["android"] then - pkgconfig_cflags("mozjs-38") - end - else - if os.is("windows") then - include_dir = "include-win32" - buildoptions { "/FI\"js/RequiredDefines.h\"" } - else - include_dir = "include-unix" - end - configuration "Debug" - includedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-debug" } - defines { "DEBUG" } - configuration "Release" - includedirs { libraries_source_dir.."spidermonkey/"..include_dir.."-release" } - configuration { } - end - end, - link_settings = function() - if _OPTIONS["with-system-mozjs38"] then - if _OPTIONS["android"] then - links { "mozjs-38" } - else - pkgconfig_libs("nspr") - pkgconfig_libs("mozjs-38") - end - else - if os.is("macosx") then - add_default_lib_paths("nspr") - links { "nspr4", "plc4", "plds4" } - end - configuration "Debug" - links { "mozjs38-ps-debug" } - configuration "Release" - links { "mozjs38-ps-release" } - configuration { } - add_source_lib_paths("spidermonkey") - end - end, - }, - tinygettext = { - compile_settings = function() - add_third_party_include_paths("tinygettext") - end, - }, - valgrind = { - compile_settings = function() - add_source_include_paths("valgrind") - end, - }, - vorbis = { - compile_settings = function() - if os.is("windows") then - add_default_include_paths("vorbis") - elseif os.is("macosx") then - add_default_include_paths("libogg") - add_default_include_paths("vorbis") - end - end, - link_settings = function() - if os.is("windows") then - add_default_lib_paths("vorbis") - elseif os.is("macosx") then - add_default_lib_paths("libogg") - add_default_lib_paths("vorbis") - end - -- TODO: We need to force linking with these as currently - -- they need to be loaded explicitly on execution - if os.getversion().description == "OpenBSD" then - add_default_links({ - unix_names = { "ogg", - "vorbis" }, - }) - end - add_default_links({ - win_names = { "vorbisfile" }, - unix_names = { "vorbisfile" }, - osx_names = { "vorbis", "vorbisenc", "vorbisfile", "ogg" }, - dbg_suffix = "_d", - }) - end, - }, - wxwidgets = { - compile_settings = function() - if os.is("windows") then - includedirs { libraries_dir.."wxwidgets/include/msvc" } - add_default_include_paths("wxwidgets") - else - - -- Support WX_CONFIG for overriding for the default PATH-based wx-config - wx_config_path = os.getenv("WX_CONFIG") - if not wx_config_path then - wx_config_path = "wx-config" - end - - pkgconfig_cflags(nil, wx_config_path.." --unicode=yes --cxxflags") - end - end, - link_settings = function() - if os.is("windows") then - libdirs { libraries_dir.."wxwidgets/lib/vc_lib" } - else - wx_config_path = os.getenv("WX_CONFIG") - if not wx_config_path then - wx_config_path = "wx-config" - end - pkgconfig_libs(nil, wx_config_path.." --unicode=yes --libs std,gl") - end - end, - }, - x11 = { - link_settings = function() - add_default_links({ - win_names = { }, - unix_names = { "X11" }, - }) - end, - }, - xcursor = { - link_settings = function() - add_default_links({ - unix_names = { "Xcursor" }, - }) - end, - }, - zlib = { - compile_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_include_paths("zlib") - end - end, - link_settings = function() - if os.is("windows") or os.is("macosx") then - add_default_lib_paths("zlib") - end - add_default_links({ - win_names = { "zlib1" }, - unix_names = { "z" }, - no_delayload = 1, - }) - end, - }, -} - - --- add a set of external libraries to the project; takes care of --- include / lib path and linking against the import library. --- extern_libs: table of library names [string] --- target_type: String defining the projects kind [string] -function project_add_extern_libs(extern_libs, target_type) - - for i,extern_lib in pairs(extern_libs) do - local def = extern_lib_defs[extern_lib] - assert(def, "external library " .. extern_lib .. " not defined") - - if def.compile_settings then - def.compile_settings() - end - - -- Linking to external libraries will only be done in the main executable and not in the - -- static libraries. Premake would silently skip linking into static libraries for some - -- actions anyway (e.g. vs2010). - -- On osx using xcode, if this linking would be defined in the static libraries, it would fail to - -- link if only dylibs are available. If both *.a and *.dylib are available, it would link statically. - -- I couldn't find any problems with that approach. - if target_type ~= "StaticLib" and def.link_settings then - def.link_settings() - end - end -end Index: ps/trunk/build/premake/premake4.lua =================================================================== --- ps/trunk/build/premake/premake4.lua +++ ps/trunk/build/premake/premake4.lua @@ -1,1493 +0,0 @@ -newoption { trigger = "android", description = "Use non-working Android cross-compiling mode" } -newoption { trigger = "atlas", description = "Include Atlas scenario editor projects" } -newoption { trigger = "collada", description = "Include COLLADA projects (requires FCollada library)" } -newoption { trigger = "coverage", description = "Enable code coverage data collection (GCC only)" } -newoption { trigger = "gles", description = "Use non-working OpenGL ES 2.0 mode" } -newoption { trigger = "icc", description = "Use Intel C++ Compiler (Linux only; should use either \"--cc icc\" or --without-pch too, and then set CXX=icpc before calling make)" } -newoption { trigger = "jenkins-tests", description = "Configure CxxTest to use the XmlPrinter runner which produces Jenkins-compatible output" } -newoption { trigger = "minimal-flags", description = "Only set compiler/linker flags that are really needed. Has no effect on Windows builds" } -newoption { trigger = "outpath", description = "Location for generated project files" } -newoption { trigger = "with-system-mozjs38", description = "Search standard paths for libmozjs38, instead of using bundled copy" } -newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" } -newoption { trigger = "without-audio", description = "Disable use of OpenAL/Ogg/Vorbis APIs" } -newoption { trigger = "without-lobby", description = "Disable the use of gloox and the multiplayer lobby" } -newoption { trigger = "without-miniupnpc", description = "Disable use of miniupnpc for port forwarding" } -newoption { trigger = "without-nvtt", description = "Disable use of NVTT" } -newoption { trigger = "without-pch", description = "Disable generation and usage of precompiled headers" } -newoption { trigger = "without-tests", description = "Disable generation of test projects" } - --- OS X specific options -newoption { trigger = "macosx-bundle", description = "Enable OSX bundle, the argument is the bundle identifier string (e.g. com.wildfiregames.0ad)" } -newoption { trigger = "macosx-version-min", description = "Set minimum required version of the OS X API, the build will possibly fail if an older SDK is used, while newer API functions will be weakly linked (i.e. resolved at runtime)" } -newoption { trigger = "sysroot", description = "Set compiler system root path, used for building against a non-system SDK. For example /usr/local becomes SYSROOT/user/local" } - --- Windows specific options -newoption { trigger = "build-shared-glooxwrapper", description = "Rebuild glooxwrapper DLL for Windows. Requires the same compiler version that gloox was built with" } -newoption { trigger = "use-shared-glooxwrapper", description = "Use prebuilt glooxwrapper DLL for Windows" } -newoption { trigger = "large-address-aware", description = "Make the executable large address aware. Do not use for development, in order to spot memory issues easily" } - --- Install options -newoption { trigger = "bindir", description = "Directory for executables (typically '/usr/games'); default is to be relocatable" } -newoption { trigger = "datadir", description = "Directory for data files (typically '/usr/share/games/0ad'); default is ../data/ relative to executable" } -newoption { trigger = "libdir", description = "Directory for libraries (typically '/usr/lib/games/0ad'); default is ./ relative to executable" } - --- Root directory of project checkout relative to this .lua file -rootdir = "../.." - -dofile("extern_libs4.lua") - --- detect compiler for non-Windows -if os.is("macosx") then - cc = "clang" -elseif os.is("linux") and _OPTIONS["icc"] then - cc = "icc" -elseif not os.is("windows") then - cc = os.getenv("CC") - if cc == nil or cc == "" then - local hasgcc = os.execute("which gcc > .gccpath") - local f = io.open(".gccpath", "r") - local gccpath = f:read("*line") - f:close() - os.execute("rm .gccpath") - if gccpath == nil then - cc = "clang" - else - cc = "gcc" - end - end -end - --- TODO: proper clang support -if cc == "clang" then - premake.gcc.cc = "clang" - premake.gcc.cxx = "clang++" -end - --- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM) -arch = "x86" -if _OPTIONS["android"] then - arch = "arm" -elseif os.is("windows") then - if os.getenv("PROCESSOR_ARCHITECTURE") == "amd64" or os.getenv("PROCESSOR_ARCHITEW6432") == "amd64" then - arch = "amd64" - end -else - arch = os.getenv("HOSTTYPE") - if arch == "x86_64" or arch == "amd64" then - arch = "amd64" - else - os.execute(cc .. " -dumpmachine > .gccmachine.tmp") - local f = io.open(".gccmachine.tmp", "r") - local machine = f:read("*line") - f:close() - if string.find(machine, "x86_64") == 1 or string.find(machine, "amd64") == 1 then - arch = "amd64" - elseif string.find(machine, "i.86") == 1 then - arch = "x86" - elseif string.find(machine, "arm") == 1 then - arch = "arm" - elseif string.find(machine, "aarch64") == 1 then - arch = "aarch64" - else - print("WARNING: Cannot determine architecture from GCC, assuming x86") - end - end -end - --- Set up the Solution -solution "pyrogenesis" -targetdir(rootdir.."/binaries/system") -libdirs(rootdir.."/binaries/system") -if not _OPTIONS["outpath"] then - error("You must specify the 'outpath' parameter") -end -location(_OPTIONS["outpath"]) -configurations { "Release", "Debug" } - --- Get some environement specific information used later. -if os.is("windows") then - lcxxtestpath = rootdir.."/build/bin/cxxtestgen.exe" -else - lcxxtestpath = rootdir.."/libraries/source/cxxtest-4.4/bin/cxxtestgen" -end - -source_root = rootdir.."/source/" -- default for most projects - overridden by local in others - --- Rationale: projects should not have any additional include paths except for --- those required by external libraries. Instead, we should always write the --- full relative path, e.g. #include "maths/Vector3d.h". This avoids confusion --- ("which file is meant?") and avoids enormous include path lists. - - --- projects: engine static libs, main exe, atlas, atlas frontends, test. - --------------------------------------------------------------------------------- --- project helper functions --------------------------------------------------------------------------------- - -function project_set_target(project_name) - - -- Note: On Windows, ".exe" is added on the end, on unices the name is used directly - - local obj_dir_prefix = _OPTIONS["outpath"].."/obj/"..project_name.."_" - - configuration "Debug" - objdir(obj_dir_prefix.."Debug") - targetsuffix("_dbg") - - configuration "Release" - objdir(obj_dir_prefix.."Release") - - configuration { } - -end - - -function project_set_build_flags() - - flags { "NoEditAndContinue" } - - if not _OPTIONS["minimal-flags"] then - flags { "Symbols" } - end - - if cc ~= "icc" and (os.is("windows") or not _OPTIONS["minimal-flags"]) then - -- adds the -Wall compiler flag - flags { "ExtraWarnings" } -- this causes far too many warnings/remarks on ICC - end - - -- disable Windows debug heap, since it makes malloc/free hugely slower when - -- running inside a debugger - if os.is("windows") then - flags { "NoDebugHeap" } - end - - configuration "Debug" - defines { "DEBUG" } - - configuration "Release" - if os.is("windows") or not _OPTIONS["minimal-flags"] then - flags { "OptimizeSpeed" } - end - defines { "NDEBUG", "CONFIG_FINAL=1" } - - configuration { } - - if _OPTIONS["gles"] then - defines { "CONFIG2_GLES=1" } - end - - if _OPTIONS["without-audio"] then - defines { "CONFIG2_AUDIO=0" } - end - - if _OPTIONS["without-nvtt"] then - defines { "CONFIG2_NVTT=0" } - end - - if _OPTIONS["without-lobby"] then - defines { "CONFIG2_LOBBY=0" } - end - - if _OPTIONS["without-miniupnpc"] then - defines { "CONFIG2_MINIUPNPC=0" } - end - - -- required for the lowlevel library. must be set from all projects that use it, otherwise it assumes it is - -- being used as a DLL (which is currently not the case in 0ad) - defines { "LIB_STATIC_LINK" } - - -- various platform-specific build flags - if os.is("windows") then - - -- use native wchar_t type (not typedef to unsigned short) - flags { "NativeWChar" } - - else -- *nix - - -- TODO, FIXME: This check is incorrect because it means that some additional flags will be added inside the "else" branch if the - -- compiler is ICC and minimal-flags is specified (ticket: #2994) - if cc == "icc" and not _OPTIONS["minimal-flags"] then - buildoptions { - "-w1", - -- "-Wabi", - -- "-Wp64", -- complains about OBJECT_TO_JSVAL which is annoying - "-Wpointer-arith", - "-Wreturn-type", - -- "-Wshadow", - "-Wuninitialized", - "-Wunknown-pragmas", - "-Wunused-function", - "-wd1292" -- avoid lots of 'attribute "__nonnull__" ignored' - } - configuration "Debug" - buildoptions { "-O0" } -- ICC defaults to -O2 - configuration { } - if os.is("macosx") then - linkoptions { "-multiply_defined","suppress" } - end - else - -- exclude most non-essential build options for minimal-flags - if not _OPTIONS["minimal-flags"] then - buildoptions { - -- enable most of the standard warnings - "-Wno-switch", -- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise) - "-Wno-reorder", -- order of initialization list in constructors (lots of noise) - "-Wno-invalid-offsetof", -- offsetof on non-POD types (see comment in renderer/PatchRData.cpp) - - "-Wextra", - "-Wno-missing-field-initializers", -- (this is common in external headers we can't fix) - - -- add some other useful warnings that need to be enabled explicitly - "-Wunused-parameter", - "-Wredundant-decls", -- (useful for finding some multiply-included header files) - -- "-Wformat=2", -- (useful sometimes, but a bit noisy, so skip it by default) - -- "-Wcast-qual", -- (useful for checking const-correctness, but a bit noisy, so skip it by default) - "-Wnon-virtual-dtor", -- (sometimes noisy but finds real bugs) - "-Wundef", -- (useful for finding macro name typos) - - -- enable security features (stack checking etc) that shouldn't have - -- a significant effect on performance and can catch bugs - "-fstack-protector-all", - "-U_FORTIFY_SOURCE", -- (avoid redefinition warning if already defined) - "-D_FORTIFY_SOURCE=2", - - -- always enable strict aliasing (useful in debug builds because of the warnings) - "-fstrict-aliasing", - - -- don't omit frame pointers (for now), because performance will be impacted - -- negatively by the way this breaks profilers more than it will be impacted - -- positively by the optimisation - "-fno-omit-frame-pointer" - } - - if not _OPTIONS["without-pch"] then - buildoptions { - -- do something (?) so that ccache can handle compilation with PCH enabled - -- (ccache 3.1+ also requires CCACHE_SLOPPINESS=time_macros for this to work) - "-fpch-preprocess" - } - end - - if os.is("linux") or os.is("bsd") then - buildoptions { "-fPIC" } - linkoptions { "-Wl,--no-undefined", "-Wl,--as-needed", "-Wl,-z,relro" } - end - - if arch == "x86" then - buildoptions { - -- To support intrinsics like __sync_bool_compare_and_swap on x86 - -- we need to set -march to something that supports them (i686). - -- We use pentium3 to also enable other features like mmx and sse, - -- while tuning for generic to have good performance on every - -- supported CPU. - -- Note that all these features are already supported on amd64. - "-march=pentium3 -mtune=generic" - } - end - end - - buildoptions { - -- Enable C++11 standard. - "-std=c++0x" - } - - if arch == "arm" then - -- disable warnings about va_list ABI change and use - -- compile-time flags for futher configuration. - buildoptions { "-Wno-psabi" } - if _OPTIONS["android"] then - -- Android uses softfp, so we should too. - buildoptions { "-mfloat-abi=softfp" } - end - end - - if _OPTIONS["coverage"] then - buildoptions { "-fprofile-arcs", "-ftest-coverage" } - links { "gcov" } - end - - -- We don't want to require SSE2 everywhere yet, but OS X headers do - -- require it (and Intel Macs always have it) so enable it here - if os.is("macosx") then - buildoptions { "-msse2" } - end - - -- Check if SDK path should be used - if _OPTIONS["sysroot"] then - buildoptions { "-isysroot " .. _OPTIONS["sysroot"] } - linkoptions { "-Wl,-syslibroot," .. _OPTIONS["sysroot"] } - end - - -- On OS X, sometimes we need to specify the minimum API version to use - if _OPTIONS["macosx-version-min"] then - buildoptions { "-mmacosx-version-min=" .. _OPTIONS["macosx-version-min"] } - -- clang and llvm-gcc look at mmacosx-version-min to determine link target - -- and CRT version, and use it to set the macosx_version_min linker flag - linkoptions { "-mmacosx-version-min=" .. _OPTIONS["macosx-version-min"] } - end - - -- Check if we're building a bundle - if _OPTIONS["macosx-bundle"] then - defines { "BUNDLE_IDENTIFIER=" .. _OPTIONS["macosx-bundle"] } - end - - -- On OS X, force using libc++ since it has better C++11 support, - -- now required by the game - if os.is("macosx") then - buildoptions { "-stdlib=libc++" } - linkoptions { "-stdlib=libc++" } - end - end - - buildoptions { - -- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with - -- Windows - they should be exported explicitly with __attribute__ ((visibility ("default"))) - "-fvisibility=hidden" - } - - if _OPTIONS["bindir"] then - defines { "INSTALLED_BINDIR=" .. _OPTIONS["bindir"] } - end - if _OPTIONS["datadir"] then - defines { "INSTALLED_DATADIR=" .. _OPTIONS["datadir"] } - end - if _OPTIONS["libdir"] then - defines { "INSTALLED_LIBDIR=" .. _OPTIONS["libdir"] } - end - - if os.is("linux") or os.is("bsd") then - -- To use our local shared libraries, they need to be found in the - -- runtime dynamic linker path. Add their path to -rpath. - if _OPTIONS["libdir"] then - linkoptions {"-Wl,-rpath," .. _OPTIONS["libdir"] } - else - -- On FreeBSD we need to allow use of $ORIGIN - if os.is("bsd") then - linkoptions { "-Wl,-z,origin" } - end - - -- Adding the executable path and taking care of correct escaping - if _ACTION == "gmake" then - linkoptions { "-Wl,-rpath,'$$ORIGIN'" } - elseif _ACTION == "codeblocks" then - linkoptions { "-Wl,-R\\\\$$$ORIGIN" } - end - end - end - - end -end - --- add X11 includes paths after all the others so they don't conflict with --- bundled libs -function project_add_x11_dirs() - if not os.is("windows") and not os.is("macosx") then - -- X11 includes may be installed in one of a gadzillion of five places - -- Famous last words: "You can't include too much! ;-)" - includedirs { - "/usr/X11R6/include/X11", - "/usr/X11R6/include", - "/usr/local/include/X11", - "/usr/local/include", - "/usr/include/X11" - } - libdirs { "/usr/X11R6/lib" } - end -end - --- create a project and set the attributes that are common to all projects. -function project_create(project_name, target_type) - - project(project_name) - language "C++" - kind(target_type) - - project_set_target(project_name) - project_set_build_flags() -end - - --- OSX creates a .app bundle if the project type of the main application is set to "WindowedApp". --- We don't want this because this bundle would be broken (it lacks all the resources and external dependencies, Info.plist etc...) --- Windows opens a console in the background if it's set to ConsoleApp, which is not what we want. --- I didn't check if this setting matters for linux, but WindowedApp works there. -function get_main_project_target_type() - if _OPTIONS["android"] then - return "SharedLib" - elseif os.is("macosx") then - return "ConsoleApp" - else - return "WindowedApp" - end -end - - --- source_root: rel_source_dirs and rel_include_dirs are relative to this directory --- rel_source_dirs: A table of subdirectories. All source files in these directories are added. --- rel_include_dirs: A table of subdirectories to be included. --- extra_params: table including zero or more of the following: --- * no_pch: If specified, no precompiled headers are used for this project. --- * pch_dir: If specified, this directory will be used for precompiled headers instead of the default --- /pch//. --- * extra_files: table of filenames (relative to source_root) to add to project --- * extra_links: table of library names to add to link step -function project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params) - - for i,v in pairs(rel_source_dirs) do - local prefix = source_root..v.."/" - files { prefix.."*.cpp", prefix.."*.h", prefix.."*.inl", prefix.."*.js", prefix.."*.asm", prefix.."*.mm" } - end - - -- Put the project-specific PCH directory at the start of the - -- include path, so '#include "precompiled.h"' will look in - -- there first - local pch_dir - if not extra_params["pch_dir"] then - pch_dir = source_root .. "pch/" .. project().name .. "/" - else - pch_dir = extra_params["pch_dir"] - end - includedirs { pch_dir } - - -- Precompiled Headers - -- rationale: we need one PCH per static lib, since one global header would - -- increase dependencies. To that end, we can either include them as - -- "projectdir/precompiled.h", or add "source/PCH/projectdir" to the - -- include path and put the PCH there. The latter is better because - -- many projects contain several dirs and it's unclear where there the - -- PCH should be stored. This way is also a bit easier to use in that - -- source files always include "precompiled.h". - -- Notes: - -- * Visual Assist manages to use the project include path and can - -- correctly open these files from the IDE. - -- * precompiled.cpp (needed to "Create" the PCH) also goes in - -- the abovementioned dir. - if (not _OPTIONS["without-pch"] and not extra_params["no_pch"]) then - pchheader(pch_dir.."precompiled.h") - pchsource(pch_dir.."precompiled.cpp") - defines { "USING_PCH" } - files { pch_dir.."precompiled.h", pch_dir.."precompiled.cpp" } - else - flags { "NoPCH" } - end - - -- next is source root dir, for absolute (nonrelative) includes - -- (e.g. "lib/precompiled.h") - includedirs { source_root } - - for i,v in pairs(rel_include_dirs) do - includedirs { source_root .. v } - end - - if extra_params["extra_files"] then - for i,v in pairs(extra_params["extra_files"]) do - -- .rc files are only needed on Windows - if path.getextension(v) ~= ".rc" or os.is("windows") then - files { source_root .. v } - end - end - end - - if extra_params["extra_links"] then - links { extra_params["extra_links"] } - end -end - - --- Add command-line options to set up the manifest dependencies for Windows --- (See lib/sysdep/os/win/manifest.cpp) -function project_add_manifest() - linkoptions { "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"" } -end - --------------------------------------------------------------------------------- --- engine static libraries --------------------------------------------------------------------------------- - --- the engine is split up into several static libraries. this eases separate --- distribution of those components, reduces dependencies a bit, and can --- also speed up builds. --- more to the point, it is necessary to efficiently support a separate --- test executable that also includes much of the game code. - --- names of all static libs created. automatically added to the --- main app project later (see explanation at end of this file) -static_lib_names = {} -static_lib_names_debug = {} -static_lib_names_release = {} - --- set up one of the static libraries into which the main engine code is split. --- extra_params: --- no_default_link: If specified, linking won't be done by default. --- For the rest of extra_params, see project_add_contents(). --- note: rel_source_dirs and rel_include_dirs are relative to global source_root. -function setup_static_lib_project (project_name, rel_source_dirs, extern_libs, extra_params) - - local target_type = "StaticLib" - project_create(project_name, target_type) - project_add_contents(source_root, rel_source_dirs, {}, extra_params) - project_add_extern_libs(extern_libs, target_type) - project_add_x11_dirs() - - if not extra_params["no_default_link"] then - table.insert(static_lib_names, project_name) - end - - if os.is("windows") then - flags { "NoRTTI" } - end -end - -function setup_third_party_static_lib_project (project_name, rel_source_dirs, extern_libs, extra_params) - - setup_static_lib_project(project_name, rel_source_dirs, extern_libs, extra_params) - includedirs { source_root .. "third_party/" .. project_name .. "/include/" } -end - -function setup_shared_lib_project (project_name, rel_source_dirs, extern_libs, extra_params) - - local target_type = "SharedLib" - project_create(project_name, target_type) - project_add_contents(source_root, rel_source_dirs, {}, extra_params) - project_add_extern_libs(extern_libs, target_type) - project_add_x11_dirs() - - if not extra_params["no_default_link"] then - table.insert(static_lib_names, project_name) - end - - if os.is("windows") then - flags { "NoRTTI" } - links { "delayimp" } - end -end - - --- this is where the source tree is chopped up into static libs. --- can be changed very easily; just copy+paste a new setup_static_lib_project, --- or remove existing ones. static libs are automagically added to --- main_exe link step. -function setup_all_libs () - - -- relative to global source_root. - local source_dirs = {} - -- names of external libraries used (see libraries_dir comment) - local extern_libs = {} - - - source_dirs = { - "network", - } - extern_libs = { - "spidermonkey", - "enet", - "boost", -- dragged in via server->simulation.h->random - } - if not _OPTIONS["without-miniupnpc"] then - table.insert(extern_libs, "miniupnpc") - end - setup_static_lib_project("network", source_dirs, extern_libs, {}) - - source_dirs = { - "third_party/tinygettext/src", - } - extern_libs = { - "iconv", - "boost", - } - setup_third_party_static_lib_project("tinygettext", source_dirs, extern_libs, { } ) - - -- it's an external library and we don't want to modify its source to fix warnings, so we just disable them to avoid noise in the compile output - if _ACTION == "vs2013" then - buildoptions { - "/wd4127", - "/wd4309", - "/wd4800", - "/wd4100", - "/wd4996", - "/wd4099", - "/wd4503" - } - end - - - if not _OPTIONS["without-lobby"] then - source_dirs = { - "lobby", - "lobby/scripting", - "i18n", - "third_party/encryption" - } - - extern_libs = { - "spidermonkey", - "boost", - "enet", - "gloox", - "icu", - "iconv", - "libsodium", - "tinygettext" - } - setup_static_lib_project("lobby", source_dirs, extern_libs, {}) - - if _OPTIONS["use-shared-glooxwrapper"] and not _OPTIONS["build-shared-glooxwrapper"] then - table.insert(static_lib_names_debug, "glooxwrapper_dbg") - table.insert(static_lib_names_release, "glooxwrapper") - else - source_dirs = { - "lobby/glooxwrapper", - } - extern_libs = { - "boost", - "gloox", - } - if _OPTIONS["build-shared-glooxwrapper"] then - setup_shared_lib_project("glooxwrapper", source_dirs, extern_libs, {}) - else - setup_static_lib_project("glooxwrapper", source_dirs, extern_libs, {}) - end - end - else - source_dirs = { - "lobby/scripting", - "third_party/encryption" - } - extern_libs = { - "spidermonkey", - "boost", - "libsodium" - } - setup_static_lib_project("lobby", source_dirs, extern_libs, {}) - files { source_root.."lobby/Globals.cpp" } - end - - - source_dirs = { - "simulation2", - "simulation2/components", - "simulation2/helpers", - "simulation2/scripting", - "simulation2/serialization", - "simulation2/system", - "simulation2/testcomponents", - } - extern_libs = { - "boost", - "opengl", - "spidermonkey", - } - setup_static_lib_project("simulation2", source_dirs, extern_libs, {}) - - - source_dirs = { - "scriptinterface", - "scriptinterface/third_party" - } - extern_libs = { - "boost", - "spidermonkey", - "valgrind", - "sdl", - } - setup_static_lib_project("scriptinterface", source_dirs, extern_libs, {}) - - - source_dirs = { - "ps", - "ps/scripting", - "network/scripting", - "ps/GameSetup", - "ps/XML", - "soundmanager", - "soundmanager/data", - "soundmanager/items", - "soundmanager/scripting", - "maths", - "maths/scripting", - "i18n", - "i18n/scripting", - "third_party/cppformat", - } - extern_libs = { - "spidermonkey", - "sdl", -- key definitions - "libxml2", - "opengl", - "zlib", - "boost", - "enet", - "libcurl", - "tinygettext", - "icu", - "iconv", - "libsodium", - } - - if not _OPTIONS["without-audio"] then - table.insert(extern_libs, "openal") - table.insert(extern_libs, "vorbis") - end - - setup_static_lib_project("engine", source_dirs, extern_libs, {}) - - - source_dirs = { - "graphics", - "graphics/scripting", - "renderer", - "renderer/scripting", - "third_party/mikktspace" - } - extern_libs = { - "opengl", - "sdl", -- key definitions - "spidermonkey", -- for graphics/scripting - "boost" - } - if not _OPTIONS["without-nvtt"] then - table.insert(extern_libs, "nvtt") - end - setup_static_lib_project("graphics", source_dirs, extern_libs, {}) - - - source_dirs = { - "tools/atlas/GameInterface", - "tools/atlas/GameInterface/Handlers" - } - extern_libs = { - "boost", - "sdl", -- key definitions - "opengl", - "spidermonkey" - } - setup_static_lib_project("atlas", source_dirs, extern_libs, {}) - - - source_dirs = { - "gui", - "gui/scripting", - "i18n" - } - extern_libs = { - "spidermonkey", - "sdl", -- key definitions - "opengl", - "boost", - "enet", - "tinygettext", - "icu", - "iconv", - } - if not _OPTIONS["without-audio"] then - table.insert(extern_libs, "openal") - end - setup_static_lib_project("gui", source_dirs, extern_libs, {}) - - - source_dirs = { - "lib", - "lib/adts", - "lib/allocators", - "lib/external_libraries", - "lib/file", - "lib/file/archive", - "lib/file/common", - "lib/file/io", - "lib/file/vfs", - "lib/pch", - "lib/posix", - "lib/res", - "lib/res/graphics", - "lib/sysdep", - "lib/tex" - } - extern_libs = { - "boost", - "sdl", - "openal", - "opengl", - "libpng", - "zlib", - "valgrind", - "cxxtest", - } - - -- CPU architecture-specific - if arch == "amd64" then - table.insert(source_dirs, "lib/sysdep/arch/amd64"); - table.insert(source_dirs, "lib/sysdep/arch/x86_x64"); - elseif arch == "x86" then - table.insert(source_dirs, "lib/sysdep/arch/ia32"); - table.insert(source_dirs, "lib/sysdep/arch/x86_x64"); - elseif arch == "arm" then - table.insert(source_dirs, "lib/sysdep/arch/arm"); - elseif arch == "aarch64" then - table.insert(source_dirs, "lib/sysdep/arch/aarch64"); - end - - -- OS-specific - sysdep_dirs = { - linux = { "lib/sysdep/os/linux", "lib/sysdep/os/unix" }, - -- note: RC file must be added to main_exe project. - -- note: don't add "lib/sysdep/os/win/aken.cpp" because that must be compiled with the DDK. - windows = { "lib/sysdep/os/win", "lib/sysdep/os/win/wposix", "lib/sysdep/os/win/whrt" }, - macosx = { "lib/sysdep/os/osx", "lib/sysdep/os/unix" }, - bsd = { "lib/sysdep/os/bsd", "lib/sysdep/os/unix", "lib/sysdep/os/unix/x" }, - } - for i,v in pairs(sysdep_dirs[os.get()]) do - table.insert(source_dirs, v); - end - - if os.is("linux") then - if _OPTIONS["android"] then - table.insert(source_dirs, "lib/sysdep/os/android") - else - table.insert(source_dirs, "lib/sysdep/os/unix/x") - end - end - - -- runtime-library-specific - if _ACTION == "vs2013" then - table.insert(source_dirs, "lib/sysdep/rtl/msc"); - else - table.insert(source_dirs, "lib/sysdep/rtl/gcc"); - end - - setup_static_lib_project("lowlevel", source_dirs, extern_libs, {}) - - - -- Third-party libraries that are built as part of the main project, - -- not built externally and then linked - source_dirs = { - "third_party/mongoose", - } - extern_libs = { - } - setup_static_lib_project("mongoose", source_dirs, extern_libs, { no_pch = 1 }) - - - -- CxxTest mock function support - extern_libs = { - "boost", - "cxxtest", - } - - -- 'real' implementations, to be linked against the main executable - -- (files are added manually and not with setup_static_lib_project - -- because not all files in the directory are included) - setup_static_lib_project("mocks_real", {}, extern_libs, { no_default_link = 1, no_pch = 1 }) - files { "mocks/*.h", source_root.."mocks/*_real.cpp" } - -- 'test' implementations, to be linked against the test executable - setup_static_lib_project("mocks_test", {}, extern_libs, { no_default_link = 1, no_pch = 1 }) - files { source_root.."mocks/*.h", source_root.."mocks/*_test.cpp" } -end - --------------------------------------------------------------------------------- --- main EXE --------------------------------------------------------------------------------- - --- used for main EXE as well as test -used_extern_libs = { - "opengl", - "sdl", - - "libpng", - "zlib", - - "spidermonkey", - "libxml2", - - "boost", - "cxxtest", - "comsuppw", - "enet", - "libcurl", - "tinygettext", - "icu", - "iconv", - "libsodium", - - "valgrind", -} - -if not os.is("windows") and not _OPTIONS["android"] and not os.is("macosx") then - -- X11 should only be linked on *nix - table.insert(used_extern_libs, "x11") - table.insert(used_extern_libs, "xcursor") -end - -if not _OPTIONS["without-audio"] then - table.insert(used_extern_libs, "openal") - table.insert(used_extern_libs, "vorbis") -end - -if not _OPTIONS["without-nvtt"] then - table.insert(used_extern_libs, "nvtt") -end - -if not _OPTIONS["without-lobby"] then - table.insert(used_extern_libs, "gloox") -end - -if not _OPTIONS["without-miniupnpc"] then - table.insert(used_extern_libs, "miniupnpc") -end - --- Bundles static libs together with main.cpp and builds game executable. -function setup_main_exe () - - local target_type = get_main_project_target_type() - project_create("pyrogenesis", target_type) - - links { "mocks_real" } - - local extra_params = { - extra_files = { "main.cpp" }, - no_pch = 1 - } - project_add_contents(source_root, {}, {}, extra_params) - project_add_extern_libs(used_extern_libs, target_type) - project_add_x11_dirs() - - -- Platform Specifics - if os.is("windows") then - - files { source_root.."lib/sysdep/os/win/icon.rc" } - -- from "lowlevel" static lib; must be added here to be linked in - files { source_root.."lib/sysdep/os/win/error_dialog.rc" } - - flags { "NoRTTI" } - - linkoptions { - -- wraps main thread in a __try block(see wseh.cpp). replace with mainCRTStartup if that's undesired. - "/ENTRY:wseh_EntryPoint", - - -- see wstartup.h - "/INCLUDE:_wstartup_InitAndRegisterShutdown", - - -- allow manual unload of delay-loaded DLLs - "/DELAY:UNLOAD", - } - - -- allow the executable to use more than 2GB of RAM. - -- this should not be enabled during development, so that memory issues are easily spotted. - if _OPTIONS["large-address-aware"] then - linkoptions { "/LARGEADDRESSAWARE" } - end - - -- see manifest.cpp - project_add_manifest() - - elseif os.is("linux") or os.is("bsd") then - - if not _OPTIONS["android"] and not (os.getversion().description == "OpenBSD") then - links { "rt" } - end - - if _OPTIONS["android"] then - -- NDK's STANDALONE-TOOLCHAIN.html says this is required - linkoptions { "-Wl,--fix-cortex-a8" } - - links { "log" } - end - - if os.is("linux") or os.getversion().description == "GNU/kFreeBSD" then - links { - -- Dynamic libraries (needed for linking for gold) - "dl", - } - elseif os.is("bsd") then - links { - -- Needed for backtrace* on BSDs - "execinfo", - } - end - - -- Threading support - buildoptions { "-pthread" } - if not _OPTIONS["android"] then - linkoptions { "-pthread" } - end - - -- For debug_resolve_symbol - configuration "Debug" - linkoptions { "-rdynamic" } - configuration { } - - elseif os.is("macosx") then - - links { "pthread" } - linkoptions { "-framework ApplicationServices", "-framework Cocoa", "-framework CoreFoundation" } - - end -end - - --------------------------------------------------------------------------------- --- atlas --------------------------------------------------------------------------------- - --- setup a typical Atlas component project --- extra_params, rel_source_dirs and rel_include_dirs: as in project_add_contents; -function setup_atlas_project(project_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params) - - local source_root = rootdir.."/source/tools/atlas/" .. project_name .. "/" - project_create(project_name, target_type) - - -- if not specified, the default for atlas pch files is in the project root. - if not extra_params["pch_dir"] then - extra_params["pch_dir"] = source_root - end - - project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params) - project_add_extern_libs(extern_libs, target_type) - project_add_x11_dirs() - - -- Platform Specifics - if os.is("windows") then - defines { "_UNICODE" } - -- Link to required libraries - links { "winmm", "comctl32", "rpcrt4", "delayimp", "ws2_32" } - -- required to use WinMain() on Windows, otherwise will default to main() - flags { "WinMain" } - - elseif os.is("linux") or os.is("bsd") then - buildoptions { "-rdynamic", "-fPIC" } - linkoptions { "-fPIC", "-rdynamic" } - - -- warnings triggered by wxWidgets - buildoptions { "-Wno-unused-local-typedefs" } - - elseif os.is("macosx") then - -- install_name settings aren't really supported yet by premake, but there are plans for the future. - -- we currently use this hack to work around some bugs with wrong install_names. - if target_type == "SharedLib" then - if _OPTIONS["macosx-bundle"] then - -- If we're building a bundle, it will be in ../Frameworks - configuration "Debug" - linkoptions { "-install_name @executable_path/../Frameworks/lib"..project_name.."_dbg.dylib" } - configuration "Release" - linkoptions { "-install_name @executable_path/../Frameworks/lib"..project_name..".dylib" } - configuration { } - else - configuration "Debug" - linkoptions { "-install_name @executable_path/lib"..project_name.."_dbg.dylib" } - configuration "Release" - linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" } - configuration { } - end - end - end - -end - - --- build all Atlas component projects -function setup_atlas_projects() - - setup_atlas_project("AtlasObject", "StaticLib", - { -- src - ".", - "../../../third_party/jsonspirit" - - },{ -- include - "../../../third_party/jsonspirit" - },{ -- extern_libs - "boost", - "iconv", - "libxml2", - "wxwidgets" - },{ -- extra_params - no_pch = 1 - }) - - atlas_src = { - "ActorEditor", - "CustomControls/Buttons", - "CustomControls/Canvas", - "CustomControls/ColorDialog", - "CustomControls/DraggableListCtrl", - "CustomControls/EditableListCtrl", - "CustomControls/FileHistory", - "CustomControls/HighResTimer", - "CustomControls/MapDialog", - "CustomControls/SnapSplitterWindow", - "CustomControls/VirtualDirTreeCtrl", - "CustomControls/Windows", - "General", - "General/VideoRecorder", - "Misc", - "ScenarioEditor", - "ScenarioEditor/Sections/Common", - "ScenarioEditor/Sections/Cinema", - "ScenarioEditor/Sections/Environment", - "ScenarioEditor/Sections/Map", - "ScenarioEditor/Sections/Object", - "ScenarioEditor/Sections/Player", - "ScenarioEditor/Sections/Terrain", - "ScenarioEditor/Tools", - "ScenarioEditor/Tools/Common", - } - atlas_extra_links = { - "AtlasObject" - } - - atlas_extern_libs = { - "boost", - "comsuppw", - "iconv", - "libxml2", - "sdl", -- key definitions - "wxwidgets", - "zlib", - } - if not os.is("windows") and not os.is("macosx") then - -- X11 should only be linked on *nix - table.insert(atlas_extern_libs, "x11") - end - - setup_atlas_project("AtlasUI", "SharedLib", atlas_src, - { -- include - "..", - "CustomControls", - "Misc" - }, - atlas_extern_libs, - { -- extra_params - pch_dir = rootdir.."/source/tools/atlas/AtlasUI/Misc/", - no_pch = false, - extra_links = atlas_extra_links, - extra_files = { "Misc/atlas.rc" } - }) -end - - --- Atlas 'frontend' tool-launching projects -function setup_atlas_frontend_project (project_name) - - local target_type = get_main_project_target_type() - project_create(project_name, target_type) - project_add_x11_dirs() - - local source_root = rootdir.."/source/tools/atlas/AtlasFrontends/" - files { source_root..project_name..".cpp" } - - if os.is("windows") then - files { source_root..project_name..".rc" } - end - - includedirs { source_root .. ".." } - - -- Platform Specifics - if os.is("windows") then - defines { "_UNICODE" } - - -- required to use WinMain() on Windows, otherwise will default to main() - flags { "WinMain" } - - -- see manifest.cpp - project_add_manifest() - - else -- Non-Windows, = Unix - links { "AtlasObject" } - end - - links { "AtlasUI" } - -end - -function setup_atlas_frontends() - setup_atlas_frontend_project("ActorEditor") -end - - --------------------------------------------------------------------------------- --- collada --------------------------------------------------------------------------------- - -function setup_collada_project(project_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params) - - project_create(project_name, target_type) - local source_root = source_root.."collada/" - extra_params["pch_dir"] = source_root - project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params) - project_add_extern_libs(extern_libs, target_type) - project_add_x11_dirs() - - -- Platform Specifics - if os.is("windows") then - -- required to use WinMain() on Windows, otherwise will default to main() - flags { "WinMain" } - - elseif os.is("linux") then - defines { "LINUX" } - - links { - "dl", - } - - -- FCollada is not aliasing-safe, so disallow dangerous optimisations - -- (TODO: It'd be nice to fix FCollada, but that looks hard) - buildoptions { "-fno-strict-aliasing" } - - buildoptions { "-rdynamic" } - linkoptions { "-rdynamic" } - - elseif os.is("bsd") then - if os.getversion().description == "OpenBSD" then - links { "c", } - end - - if os.getversion().description == "GNU/kFreeBSD" then - links { - "dl", - } - end - - buildoptions { "-fno-strict-aliasing" } - - buildoptions { "-rdynamic" } - linkoptions { "-rdynamic" } - - elseif os.is("macosx") then - -- define MACOS-something? - - -- install_name settings aren't really supported yet by premake, but there are plans for the future. - -- we currently use this hack to work around some bugs with wrong install_names. - if target_type == "SharedLib" then - if _OPTIONS["macosx-bundle"] then - -- If we're building a bundle, it will be in ../Frameworks - linkoptions { "-install_name @executable_path/../Frameworks/lib"..project_name..".dylib" } - else - linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" } - end - end - - buildoptions { "-fno-strict-aliasing" } - -- On OSX, fcollada uses a few utility functions from coreservices - linkoptions { "-framework CoreServices" } - end - -end - --- build all Collada component projects -function setup_collada_projects() - - setup_collada_project("Collada", "SharedLib", - { -- src - "." - },{ -- include - },{ -- extern_libs - "fcollada", - "iconv", - "libxml2" - },{ -- extra_params - }) - -end - - --------------------------------------------------------------------------------- --- tests --------------------------------------------------------------------------------- - --- Cxxtestgen needs to create .cpp files from the .h files before they can be compiled. --- By default we are using prebuildcommands, but we are also using customizations of premake --- for makefiles. The reason is that premake currently has a bug with makefiles and parallel --- builds (e.g. -j5). It's not guaranteed that prebuildcommands always run before building. --- All the *.cpp and *.h files need to be added to files no matter if prebuildcommands --- or customizations are used. --- If no customizations are implemented for a specific action (e.g. vs2013), passing the --- parameters won't have any effects. -function configure_cxxtestgen() - - local lcxxtestrootfile = source_root.."test_root.cpp" - files { lcxxtestrootfile } - - -- Define the options used for cxxtestgen - local lcxxtestoptions = "--have-std" - local lcxxtestrootoptions = "--have-std" - - if _OPTIONS["jenkins-tests"] then - lcxxtestrootoptions = lcxxtestrootoptions .. " --runner=XmlPrinter" - else - lcxxtestrootoptions = lcxxtestrootoptions .. " --runner=ErrorPrinter" - end - - -- Precompiled headers - the header is added to all generated .cpp files - -- note that the header isn't actually precompiled here, only #included - -- so that the build stage can use it as a precompiled header. - local include = " --include=precompiled.h" - -- This is required to build against SDL 2.0.4 on Windows - include = include .. " --include=lib/external_libraries/libsdl.h" - lcxxtestrootoptions = lcxxtestrootoptions .. include - lcxxtestoptions = lcxxtestoptions .. include - - -- Set all the parameters used in our cxxtestgen customization in premake. - cxxtestrootfile(lcxxtestrootfile) - cxxtestpath(lcxxtestpath) - cxxtestrootoptions(lcxxtestrootoptions) - cxxtestoptions(lcxxtestoptions) - - -- The file paths needs to be made relative to the project directory for the prebuildcommands. - -- premake's paths are relative to premake4.lua by default. - lcxxtestrootfile = path.rebase(lcxxtestrootfile, path.getabsolute("."), _OPTIONS["outpath"]) - lcxxtestpath = path.rebase(lcxxtestpath, path.getabsolute("."), _OPTIONS["outpath"]) - - -- On windows we have to use backlashes in our paths. We don't have to take care - -- of that for the parameters passed to our cxxtestgen customizations. - if os.is("windows") then - lcxxtestrootfile = path.translate(lcxxtestrootfile, "\\") - lcxxtestpath = path.translate(lcxxtestpath, "\\") - end - - if _ACTION ~= "gmake" and _ACTION ~= "vs2013" then - prebuildcommands { lcxxtestpath.." --root "..lcxxtestrootoptions.." -o "..lcxxtestrootfile } - end - - -- Find header files in 'test' subdirectories - local all_files = os.matchfiles(source_root .. "**/tests/*.h") - for i,v in pairs(all_files) do - -- Don't include sysdep tests on the wrong sys - -- Don't include Atlas tests unless Atlas is being built - if not (string.find(v, "/sysdep/os/win/") and not os.is("windows")) and - not (string.find(v, "/tools/atlas/") and not _OPTIONS["atlas"]) and - not (string.find(v, "/sysdep/arch/x86_x64/") and ((arch ~= "amd64") or (arch ~= "x86"))) - then - local src_file = string.sub(v, 1, -3) .. ".cpp" - cxxtestsrcfiles { src_file } - files { src_file } - cxxtesthdrfiles { v } - - if _ACTION ~= "gmake" and _ACTION ~= "vs2013" then - -- see detailed comment above. - src_file = path.rebase(src_file, path.getabsolute("."), _OPTIONS["outpath"]) - v = path.rebase(v, path.getabsolute("."), _OPTIONS["outpath"]) - - if os.is("windows") then - src_file = path.translate(src_file, "\\") - v = path.translate(v, "\\") - end - prebuildcommands { lcxxtestpath.." --part "..lcxxtestoptions.." -o "..src_file.." "..v } - end - end - - - end -end - - -function setup_tests() - - local target_type = get_main_project_target_type() - project_create("test", target_type) - - configure_cxxtestgen() - - links { static_lib_names } - configuration "Debug" - links { static_lib_names_debug } - configuration "Release" - links { static_lib_names_release } - configuration { } - - links { "mocks_test" } - if _OPTIONS["atlas"] then - links { "AtlasObject" } - project_add_extern_libs({"wxwidgets"}, target_type) - end - extra_params = { - extra_files = { "test_setup.cpp" }, - } - - project_add_contents(source_root, {}, {}, extra_params) - project_add_extern_libs(used_extern_libs, target_type) - project_add_x11_dirs() - - -- TODO: should fix the duplication between this OS-specific linking - -- code, and the similar version in setup_main_exe - - if os.is("windows") then - -- from "lowlevel" static lib; must be added here to be linked in - files { source_root.."lib/sysdep/os/win/error_dialog.rc" } - - flags { "NoRTTI" } - - -- see wstartup.h - linkoptions { "/INCLUDE:_wstartup_InitAndRegisterShutdown" } - -- Enables console for the TEST project on Windows - linkoptions { "/SUBSYSTEM:CONSOLE" } - - project_add_manifest() - - elseif os.is("linux") or os.is("bsd") then - - if not _OPTIONS["android"] and not (os.getversion().description == "OpenBSD") then - links { "rt" } - end - - if _OPTIONS["android"] then - -- NDK's STANDALONE-TOOLCHAIN.html says this is required - linkoptions { "-Wl,--fix-cortex-a8" } - end - - if os.is("linux") or os.getversion().description == "GNU/kFreeBSD" then - links { - -- Dynamic libraries (needed for linking for gold) - "dl", - } - elseif os.is("bsd") then - links { - -- Needed for backtrace* on BSDs - "execinfo", - } - end - - -- Threading support - buildoptions { "-pthread" } - if not _OPTIONS["android"] then - linkoptions { "-pthread" } - end - - -- For debug_resolve_symbol - configuration "Debug" - linkoptions { "-rdynamic" } - configuration { } - - includedirs { source_root .. "pch/test/" } - end -end - --- must come first, so that VC sets it as the default project and therefore --- allows running via F5 without the "where is the EXE" dialog. -setup_main_exe() - -setup_all_libs() - --- add the static libs to the main EXE project. only now (after --- setup_all_libs has run) are the lib names known. cannot move --- setup_main_exe to run after setup_all_libs (see comment above). --- we also don't want to hardcode the names - that would require more --- work when changing the static lib breakdown. -project("pyrogenesis") -- Set the main project active - links { static_lib_names } - configuration "Debug" - links { static_lib_names_debug } - configuration "Release" - links { static_lib_names_release } - configuration { } - -if _OPTIONS["atlas"] then - setup_atlas_projects() - setup_atlas_frontends() -end - -if _OPTIONS["collada"] then - setup_collada_projects() -end - -if not _OPTIONS["without-tests"] then - setup_tests() -end Index: ps/trunk/build/premake/premake4/BUILD.txt =================================================================== --- ps/trunk/build/premake/premake4/BUILD.txt +++ ps/trunk/build/premake/premake4/BUILD.txt @@ -1,123 +0,0 @@ -PREMAKE BUILD INSTRUCTIONS - - Premake is written in a mix of C and Lua. This mix enables many new - features, but also makes building Premake a bit more complicated than - your typical application. - - If you downloaded a source code package from SourceForge (as opposed - to pulling the sources from the repository), you will find project - files for all of the currently supported toolsets in the build/ folder. - Build the release configuration (the default for the makefiles) and you - will find the executable in bin/release ready to go. - - If you want to use a debug build instead, or if you pulled the sources - from BitBucket instead of a SourceForge release, or if you plan on - making changes to Premake, read the next section to learn how to - prepare the project files. - - If you find all of this very confusing and need some help, see the end - of this document for contact information. I'll be glad to help. And if - you have any suggestions for improving this process, we'd be glad to - hear them too. - - -GENERATING THE PROJECT FILES - - If you downloaded a source code package from SourceForge, the project - files are already included (in build/) and you can skip ahead to the - next section. - - If you pulled the sources from BitBucket, you'll need to generate your - own project files before you can build. - - We use Premake to generate the project files for Premake (bootstrapping, - or eating our own dog food). So in order to generate the project files, - you need to have a working version of Premake 4.x installed on your - system. You can get it as source code (with pre-generated project files - ready to build) or a prebuilt binary from the SourceForge download page. - - Once you have a working Premake 4.x installed, the first thing you need - to do is to embed the Lua scripts into the application by running this - command in the top-level Premake directory: - - premake4 embed - - This creates a C file (at src/host/scripts.c) which contains all of the - Lua scripts as static string buffers. These then get compiled into the - executable, which is how we get away with shipping a single file instead - of one executable and whole bunch of scripts. See EMBEDDING THE SCRIPTS, - below, for more information. - - Now you can generate project files for your toolset of choice by running - a command like: - - premake4 gmake -- for GNU makefiles using GCC - premake4 vs2008 -- for a Visual Studio 2008 solution - - Use the "--help" option to see all of the available targets. - - This will create a solution/makefile/workspace in the top-level folder, - which you can now go ahead and build. - - -RELEASE vs. DEBUG BUILDS - - Premake can be built in either "release" or "debug" modes. Makefile users - can choose which configuration to build with the "config" argument: - - make config=debug -- build in debug mode - make config=release -- build in release mode - - IDEs like Visual Studio provide their own mechanism for switching build - configurations. - - In release mode you can build and run Premake like any other C application - (once you've embedded the scripts, see the next section). - - In debug mode, Premake ignores the embedded Lua scripts and instead reads the - latest versions from the disk at runtime. This allows you to change a script, - and then immediately test it without having to embed or compile first. Speedy! - But Premake needs some help to find the scripts. - - You can specify the location of the scripts in one of two ways: using - the /scripts command line argument, like so: - - premake4 /scripts=~/Code/premake4/src gmake - - Or by setting a PREMAKE_PATH environment variable. - - PREMAKE_PATH=~/Code/premake4/src - - As you can see, you need to specify the location of the Premake "src" - directory, the one containing "_premake_main.lua". - - -EMBEDDING THE SCRIPTS - - One of the nice things about Premake is that it comes as a single file, - easy to install or move around. To manage this, we need to embed all of - the Lua scripts into the executable, so we can deliver just the one file, - rather than an executable and a whole bunch of scripts. - - Scripts are embedded by running the command - - premake4 embed - - This copies all of the scripts listed in _manifest.lua into the file - src/host/scripts.c, where they are represented as a set of static C - string buffers. This file is then compiled as part of Premake's release - builds. - - So: very important to embed the scripts before each release build! - - -CONFUSED? - - I'll be glad to help you out. Stop by the main project website where - you can leave a note in the forums (the preferred approach), join the - mailing list, or contact me directly. - - http://industriousone.com/premake - - Enjoy! - \ No newline at end of file Index: ps/trunk/build/premake/premake4/CHANGES.txt =================================================================== --- ps/trunk/build/premake/premake4/CHANGES.txt +++ ps/trunk/build/premake/premake4/CHANGES.txt @@ -1,547 +0,0 @@ -------- - 4.3.1 (in progress) -------- - -* Bug 3119793: Fixed ClCompile blocks with vs10 and PCH (Dan Dunham) -* Bug 2920784: Symbol visibility in Xcode3 libraries (burnson2) -* Bug 3133743: Sets ONLY_ACTIVE_ARCH = YES in Xcode debug builds (James Wynn) -* Properly pass return codes back to shell in release builds -* Bug 3135734: Remove WholeProgramOptimization setting in vs10 (doug) -* Bug 3138377: Link dependencies ignored within "SharedLib" configuration - - -------- - 4.3 -------- - -* CHANGED LICENSE FROM GPLv2 TO BSD -* Added Visual Studio 2010 C/C++ support (Liam Devine) -* Added Solaris support (Dean Ross-Smith) -* Added deployment and image options for Xbox360 (dvoid) -* Patch 2963313: Enable setting .NET framework version (Justen Hyde) -* Patch 2965229: Fix handling of '+' symbol in file patterns (Rachel Blum) -* Patch 2997449: Print configuration with target (ergosys) -* Patch 2997452: Suppress gmake's "nothing to be done" message (ergosys) -* Patch 3011940: Add support for MFC (JTAnderson) -* Patch 3053959: kind() crashes when called with no arguments (rjmyst3) -* Bug 2997728: Project dependencies should be case-sensitive -* Bug 3056381: Xcode project breaks on special chars -* Bug 3007101: Generating PDB in Release builds is not supported -* Bug 2971841: Gmake escaping of shell variable $(...) is broken -* Fixed handling of icons in Xcode (bitshifter) -* Added imagepath to set Xbox360 image file name (Jarod) -* Patch 3063804: Set CompileAs flag for VS200x C projects (rjmyst3) -* Implemented StaticRuntime flag for Xcode (William Burnson) -* Improved portability of Mac OS X binaries (William Burnson) -* Bug 3035545: The pattern { "./folder/*.c" } matches no files -* Bug 3034222: StaticLib projects ignore linkoptions -* Bug 3020382: GCC PCH not working -* Bug 3016050: {"../Dir/file1.c","../../Dir/file2.c"} breaks Xcode (Stephane) -* Bug 3015312: Makefiles are not quoted correctly -* Bug 3097868: Removes relative paths from vs2010 filters (Robert Konrad) -* Bug 3095274: Pre-compiled header support missing for VS2010 target -* Bug 3100062: vs2010 Runtime library selection - - -------- - 4.2.1 -------- - -* Feature 2944697: Add flag to disable Minimal Rebuild in Visual Studio -* Patch 2928029: Add EnableSSE, EnableSSE2 flags -* Patch 2936443: Expose configuration terms to scripts (Laurent Humbertclaude) -* Bug 2928775: Error loading external Lua module with require() -* Bug 2942438: Wrong runtime library linked -* Bug 2931722: pchheader handling not consistent between tools -* Bug 2958829: Files pattern matching including too many files -* Bug 2953594: includedirs / libdirs converting absolute paths to relative -* Bug 2936188: Improve handling for invalid values in lists - - ------ - 4.2 ------ - -- Feature 1526976: Add support for Apple Xcode 3 -- Feature 2900623: Add targetsuffix and implibsuffix properties -- Added project kind to list of configuration filters -- Feature 2839002: Add gcc switch to improve header dependency generation (Johannes Spohr) -- Feature 2832906: Global variable (_SCRIPT) for current script path -- Feature 2905303: Enable better folder matching in file lists -- Feature 2919629: Add help target for makefiles -- Feature 2820644: Add Xbox360 deployment and image options -- Bug 2909463: Fix Xcode handling of Obj-C++ .mm files -- Bug 2903430: Using relative instead of absolute paths with $() macro -- Bug 2910691: Duplicate build options -- Bug 2910639: Nil reference on dylib project dependency -- Bug 2872066: Two test failures in 4.1.2 -- Bug 2912756: dylibs missing lib prefix -- Bug 2910202: Code::Blocks building C files as C++ -- Bug 2926917: Use target name for Visual Studio PDB file -- Bug 2927604: Unable to build Premake with Visual Studio -- Clean action now removes MonoDevelop .pidb files correctly -- Added os.executef() - - -------- - 4.1.2 -------- - -- Fixed ManagedExtension setting for Visual Studio -- Fixed os.match() bug for large result sets (David Raulo) -- Patch 2840052: Order problem of static link -- Patch 2802722: Floating Point Model Flags (Suigintou) -- Patch 2865333: Support for ObjC and ObjC++ sources (Johannes Spohr) -- Patch 2832852: Fix descriptions in cmd help (Sebastian Schuberth) -- Patch 2832848: Show default script name in help (Sebastian Schuberth) - - -------- - 4.1.1 -------- - -- Use libtool instead of ar for Mac OS X Universal static libraries -- Fixed Xbox 360 linker settings in Visual Studio -- Remove platform-specific intermediate objects on clean -- Bug 2819232: Buildoptions not used when creating Makefile for C# -- Bug 2813297: OS X universal config should be "univ" (William Burnson) -- Bug 2814179: Xbox 360 precompiled headers not working - - ------ - 4.1 ------ - -- Added support for cross-compiling target platforms -- Added Xbox 360 support to Visual Studio 2005/2008 -- Added Mac OS X universal binary support -- Added Playstation 3 support -- Added precompiled header support for GCC -- Support links and libdirs for Visual Studio static libraries -- Fail gracefully when list is assigned to string field -- Changed GCC flags to -fno-exceptions and -fno-rtti -- Improved performance of configuration building step -- Fixed crash when configuration is missing a kind -- Patch 2031626: Support for additional manifest files (Colin Graf) -- Patch 2558089: workaround for --as-needed/correct link order (idl0r) -- Patch 2609028: verbose linking in makefile (kaidokert) -- Bug 2564404: FatalWarnings has no effect with gmake target -- Bug 2550759: pchheader option has wrong type -- Bug 1900333: Parentheses in build path -- Bug 2790865: SharedLib on OSX fixes (Ash Berlin) -- Bug 2790882: Trailing slash in path.getabsolute (Ash Berlin) - - -RC2 -> RC3 - -- Bug 2805763: GCC PCH breaks on path -- Bug 2709641: Location field does not propagate to projects -- Bug 2675518: Dependencies wrong on config links -- Bug 2152526: Code::Blocks doesn't build PCH correctly on GCC - -RC1 -> RC2 - -- Removed additional MonoDevelop files in clean action -- Fixed naming of system libraries in Visual Studio link step -- Set OS to Windows when generating for Visual Studio -- Bug 2801257: Linker error LNK1112 when cross-compiling for x64 - - ------ - 4.0 ------ - -This version is a complete rewrite of Premake. - -- A new, more readable and extensible syntax for projects -- More robust syntax validation -- A new command-line format, with better argument validation -- Improved path handling across all project settings -- Upgraded to Lua 5.1.4 -- Many, many bug fixes - -RC4 -> Final - -- Set Mac OS X linker flags for Code::Blocks -- Bug 2533504: Files above project root not added to project - -RC3 -> RC4 - -- Embed scripts instead of bytecodes to avoid portability issues -- solution() and project() now only set the active object when - called with a name; remains unchanged otherwise - -RC2 -> RC3 - -- Bug: GCC Windows release builds of Premake4 crash on script errors -- Patched Lua to load precompiled bytecodes on PPC architectures. -- Display paths of generated files - -RC1 -> RC2 - -- Enabled use of absolute Windows paths to different drive letter -- Bug: Post-build commands run before build on Code::Blocks -- Removed FatalWarnings build flag -- Fixed GCC 4.2 warnings (Ryan Pusztai) -- Enable Windows linking to shared libraries even with NoImportLib - flag set (just in case) -- Fixed handling of paths in links -- Added "ToolsVersion" attribute to VS2005 and VS2008 C# projects -- Fixed separator between library dependencies in C++ makefiles -- Added missing os.copyfile() function -- Bug: Sometimes takes a long time to complete on Linux -- Enabled Lua popen support on Linux and Mac OS X - - ------ - 3.7 ------ - -- Updated Lua to 5.1.3 -- Added new CodeLite support target (Ryan Pusztai) -- Added new cb-ow (Code::Blocks Open Watcom) target (Tim Channon) -- Place OSX winexe's into Content/MacOS folder (William Burnson) -- Sibling executables may now be listed in package.links -- Bug 1520012: Improper Makefiles when filenames have spaces - (Diaa Sami) -- Bug 2045506: "no-exceptions" flag ignored for VS200x (Benoit Miller) -- Bug 2034470: Error in cmd line error handler -- Bug 2114152: package or config table isn't generated automatically - - ------ - 3.6 ------ - -- Patch 1946122: Add support for VS2008 (Ryan Pusztai) -- Patch 1913448: Win32 crash when using '--clean --usetargetpath' - (David Walters) -- Patch 1771168: luaL_getn speed optimization (Richard O'Grady) -- Bug 1939089: Premake segfault on Linux/PPC (Fabio Till) -- Fixed "bad argument #2 to 'chdir'" error -- Disable -MMD on multiple -arch flags (poor man's Universal binary - support) - - ------ - 3.5 ------ - -- Prevent creation of import libraries on OS X -- Improved handling of dylibs on OS X -- Patch 1771977: Ability to compile C source as C++ in Code::Blocks - (Ryan Pusztai) -- Bug 1804810: out-implib not present in linux gnu compler toolchain -- Bug 1806949: .Net reference paths are broken when bindir is specified -- Bug 1806960: Make clean does not remove .mdb files -- Bug 1831389: Makefiles stored in subdirs contain no targets on - first run - - ------ - 3.4 ------ - -- Added `no-pch` flag to suppress precompiled headers -- Added App.config support to GNU makefiles -- Add os.mkdir() to script environment -- Makefile now creates target directory before copying .NET references -- Feature 1520182: Enhanced file-handling functions -- Bug 531878: Problems with relative paths -- Bug 1723867: Config-specific post-build on GNU target (Benoit Miller) -- Bug 1596826: XML targets doesn't escape xml entities -- Bug 1600155: Core dump due to newpackage() and matchfiles() -- Bug 1608895: resgen command shown -- Bug 1639730: Output filename is not set -- Bug 1729227: non-portable executable with relative library path -- Bug 1559951: default clean rule removes package dir -- Patch 1733674: PCH support for Code::Block targets (Ryan Pusztai) -- Patch 1746563: Ability to specify GUID for VS targets (Ryan Pusztai) -- Patch 1754867: Creating import lib of different name (Ryan Pusztai) - - ------ - 3.3 ------ - -- Added support for prebuild, prelink, and postbuild commands -- Added `target` global variable to script environment -- Added build flag `no-edit-and-continue` -- Added build flags `native-wchar` and `no-native-wchar` -- Added build flag `no-manifest` -- Added build flag `seh-exceptions` (VS2005 only) -- Added `resdefines`, `respaths`, and `resoptions` -- Added `prebuildcommands`, `prelinkcommands`, and `postbuildcommands` -- Added `pchheader` and `pchsource` (Visual Studio only) -- Feature 1337547: Package-level bindir and libdir -- Bug 1565755: Generated makefiles do not work with MSYS -- Bug 1587955: Target path ignored for libs -- Bug 1574725: Static library extension for "gnu" target -- Bug 1522861: Fixed by using "ar -rcs" instead of "ar -cr && ranlib" -- Bug 1656816: Mkdir set wrong directory rights -- Bug 1655595: Compile/build problem on FreeBSD -- Bug: "gnu" clean rule doesn't work in cmd.exe -- Improved behavior of Linux findlib() -- Updated Code::Blocks support to latest project version - (major="1" minor="6") -- Patch 1681666: GNU targets always show the console if kind = 'winexe' - - ------ - 3.2 ------ - -- Added support for Code::Blocks -- Updated MonoDevelop support -- Upgraded Lua to 5.0.3 -- Added new matchdirs() to Lua script environment -- Expose list of packages as _PACKAGES global in Lua -- Turn off edit-and-continue in release builds with symbols -- Bug 1559873: libpaths inserts extra space after -L - - ------ - 3.1 ------ - -- Added support for Visual Studio 2005 -- Added support for Windows resources to GNU make target -- Added path handling functions to Lua environment -- Added matchrecursive() for recursive file searches -- Added os.fileexists() function to Lua environment -- Added os.appendfile() function to Lua environment -- Changed `monoresgen` to `resgen` to keep up with Mono project -- Added `mono2` .NET compiler set for Mono .NET 2.0 support -- Feature 1096677: exclude files from matchfiles (package.excludes) -- Bug 1439463: VS2003 RTTI problem -- Bug 1439446: GNU Makefile problem under Mingw32 -- Bug 1422068: package.path="." causes bad makefiles -- Bug 1431530: makefile target fails when project path specified - - ------ - 3.0 ------ - -- Upgraded Lua interpreter to version 5.0.1 -- The options table now stores simple values, rather than tables -- Completed MonoDevelop support -- Improved .NET resource handling for GNU generator -- Added unit test suite -- Merged Scott Graham unicode build flag patch -- Removed package.warninglevel in favor of extra-warnings flag -- Added package.targetprefix -- Overhauled structure of generated GNU makefiles -- Added --os command line option -- Fixed bug 1268588: Use gcc to link C packages -- Fixed bug 1363306: GNU C# should copy referenced DLLs - - ------ - 2.4 ------ - -- Added chdir() to Lua script environment -- Merged Thomas Harning's patch for .NET resources on GNU -- Fixed bug 1194702: Can't put multiple packages in same directory -- Fixed bug in GNU shared library builds (doh!) -- Added target 'vs2002' to replace 'vs7' - - ------ - 2.3 ------ - -- Added 'project.config[]' with 'bindir' and 'libdir' -- Merged Scott Graham's "warninglevel" patch. -- Fixed bug 1153484: Import lib in wrong directory. -- Fixed bug 1013352: Stack overflow with large projects. -- Fixed bug 945406: package.files, bad value = crash - - ------ - 2.2 ------ - -- Worked around VS.NET bug for .NET assemblies > 64K. -- Added --very-verbose flag to GNU generator. -- GNU generator now supports assembly sources. - - ------ - 2.1 ------ - -- File extension of generated binaries can now be set - with config.targetextension. -- Windows targets now handle .def files for DLLs. - - ------ - 2.0 ------ - -- Can now specify build actions per file -- Include paths are now passed to VC7 resource compiler -- Removed _WIN32 define from Cygwin makefiles -- Added package.objdir to set intermediates directory -- Added rmdir() to Lua script environment -- A big bag of bug fixes - - ------ - 1.9 ------ - -- Made verbose mode even more verbose. -- posix.c now builds properly as C. -- Fixed package dependency generation for GNU and VS2003. -- Display Lua version number in usage text. -- Fixed VS link between *.aspx and *.aspx.cs files. -- Fixed VS link between *.resx and *.cs files. -- Fixed *.d file generation for gcc 2.9x. -- Unified various help options under '--help'. -- Bin and Lib paths can now be arbitrarily long. -- linkoptions are now applied in VC6 and VC7 projects. - - ------ - 1.8 ------ - -- Added support for ASP.NET projects. -- Fixed a bug in VC6 support for static libraries. -- matchfiles() now uses package path instead of script path. -- Added --verbose option. -- No longer apply no-rtti and no-exceptions to *.c files. - - ------ - 1.7 ------ - -- Location of generated project files can now be specified with - the project.path variable. -- Inter-package dependencies are fixed for GNU makefiles. -- No longer need to execute in same directory as project script. -- Added "c" language specifier. -- Added support for .resx and .config files to C# projects. -- Added support for full assembly names in .NET references. -- Fixed handling of paths in package.target variable. -- Improved support for SharpDevelop. -- Started support for OS X. -- Added support for Digital Mars compiler. - - -------- - 1.6.1 -------- - -- VS7 generator crashed if a package was built before one of its - dependencies. Now immediately assigns UUID before processing. - - ------ - 1.6 ------ - -- Added support for Visual Studio 2003 and SharpDevelop. -- Added binaries directory as a reference path for VS7. - - ------ - 1.5 ------ - -- Added initial support for building static libraries. -- Added "no-main" flag, prevents overriding WinMain() on - Windows builds. -- Added "--no-rtti" and "no-exceptions" build flags to - disable those C++ features. -- Display error message when project has no packages. -- Moved VC7 *.pdb files into intermediates directory. - - ------ - 1.4 ------ - -- Bug fixes to the path manipulation routines. -- GNU makefiles are regenerated when premake scripts change. - - ------ - 1.3 ------ - -- Added support for the Cygwin environment. -- Added "static-runtime" build flag to statically link against C/C++ - standard runtime libraries. -- Bug fixes to Visual Studio 6 and 7 generators and path reversing - algorithm. - - ------ - 1.2 ------ - -- Standardized format of command-line options. -- Can now handle custom command-line options in script. -- Added new function findlib(). -- Added new C++ build flag "managed" for writing C++ .NET code. -- Can now use open-source C# compilers in VS6 generator. -- Several bug fixes to the VS7 generator. - - ------ - 1.1 ------ - -- Added support for custom build configurations. Added "optimize", - "optimize-size", "optimize-speed", and "no-symbols" flags to control - build settings. -- Added matchfiles() to select files using wildcards. -- Added "unsafe" flag for C# projects. -- Added newpackage() function for creating new package objects inline, - instead of creating separate scripts. -- Changed include() to dopackage() and option() to addoption(). The old - versions have been kept for compatibility, but will be deprecated - eventually. -- Major cleanup of the source code. - - ------ - 1.0 ------ - -- Fixed a bug related to the reference paths in VS7 C# projects. -- Display a warning message if a reference path can't be found. -- Automatically create bin and lib directories if they do not exist. -- GNU C# projects will now properly use the configured library paths. - - -------- - 0.9.2 -------- - -- Added --with-mono and --with-pnet options. -- VS7 C# projects will now properly use the configured library paths. - - -------- - 0.9.1 -------- - -- Switched to Lua (http://www.lua.org/) for project script parsing. -- Add support for custom project options. -- Changed 'type' to 'kind' to avoid conflict with Lua function of the - same name. -- Changed 'conexe' to 'exe' because I liked it better. -- Changed 'library' to 'dll' for C# projects to keep things consistent. - - -------- - 0.9.0 -------- - -- Initial public release. Index: ps/trunk/build/premake/premake4/LICENSE.txt =================================================================== --- ps/trunk/build/premake/premake4/LICENSE.txt +++ ps/trunk/build/premake/premake4/LICENSE.txt @@ -1,27 +0,0 @@ -Copyright (c) 2003-2011 Jason Perkins and individual contributors. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. Neither the name of the Premake nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Index: ps/trunk/build/premake/premake4/README.txt =================================================================== --- ps/trunk/build/premake/premake4/README.txt +++ ps/trunk/build/premake/premake4/README.txt @@ -1,15 +0,0 @@ -PREMAKE -A build configuration tool - - Copyright (C) 2002-2011 by Jason Perkins - Distributed under the terms of the BSD License, see LICENSE.txt - - The Lua language and runtime library is (C) TeCGraf, PUC-Rio. - See their website at http://www.lua.org/ - - - See the file BUILD.txt for instructions on building Premake. - - - For questions, comments, or more information, visit the project - website at http://industriousone.com/premake Index: ps/trunk/build/premake/premake4/build/gmake.bsd/Makefile =================================================================== --- ps/trunk/build/premake/premake4/build/gmake.bsd/Makefile +++ ps/trunk/build/premake/premake4/build/gmake.bsd/Makefile @@ -1,34 +0,0 @@ -# GNU Make solution makefile autogenerated by Premake -# Type "make help" for usage help - -ifndef config - config=release -endif -export config - -PROJECTS := Premake4 - -.PHONY: all clean help $(PROJECTS) - -all: $(PROJECTS) - -Premake4: - @echo "==== Building Premake4 ($(config)) ====" - @${MAKE} --no-print-directory -C . -f Premake4.make - -clean: - @${MAKE} --no-print-directory -C . -f Premake4.make clean - -help: - @echo "Usage: make [config=name] [target]" - @echo "" - @echo "CONFIGURATIONS:" - @echo " release" - @echo " debug" - @echo "" - @echo "TARGETS:" - @echo " all (default)" - @echo " clean" - @echo " Premake4" - @echo "" - @echo "For more information, see http://industriousone.com/premake/quick-start" Index: ps/trunk/build/premake/premake4/build/gmake.bsd/Premake4.make =================================================================== --- ps/trunk/build/premake/premake4/build/gmake.bsd/Premake4.make +++ ps/trunk/build/premake/premake4/build/gmake.bsd/Premake4.make @@ -1,305 +0,0 @@ -# GNU Make project makefile autogenerated by Premake -ifndef config - config=release -endif - -ifndef verbose - SILENT = @ -endif - -ifndef CC - CC = gcc -endif - -ifndef CXX - CXX = g++ -endif - -ifndef AR - AR = ar -endif - -ifeq ($(config),release) - OBJDIR = obj/Release - TARGETDIR = ../../bin/release - TARGET = $(TARGETDIR)/premake4 - DEFINES += -DNDEBUG -DLUA_USE_POSIX -DLUA_USE_DLOPEN - INCLUDES += -I../../src/host/lua-5.1.4/src - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) -Wall -Os - CXXFLAGS += $(CPPFLAGS) -Wall -Os - LDFLAGS += -s -rdynamic - LIBS += -lm - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - -ifeq ($(config),debug) - OBJDIR = obj/Debug - TARGETDIR = ../../bin/debug - TARGET = $(TARGETDIR)/premake4 - DEFINES += -D_DEBUG -DLUA_USE_POSIX -DLUA_USE_DLOPEN - INCLUDES += -I../../src/host/lua-5.1.4/src - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) -Wall -g - CXXFLAGS += $(CPPFLAGS) -Wall -g - LDFLAGS += -rdynamic - LIBS += -lm - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - -OBJECTS := \ - $(OBJDIR)/path_isabsolute.o \ - $(OBJDIR)/os_getversion.o \ - $(OBJDIR)/os_isfile.o \ - $(OBJDIR)/os_uuid.o \ - $(OBJDIR)/os_chdir.o \ - $(OBJDIR)/os_pathsearch.o \ - $(OBJDIR)/os_rmdir.o \ - $(OBJDIR)/os_match.o \ - $(OBJDIR)/scripts.o \ - $(OBJDIR)/os_copyfile.o \ - $(OBJDIR)/os_isdir.o \ - $(OBJDIR)/os_mkdir.o \ - $(OBJDIR)/os_getcwd.o \ - $(OBJDIR)/premake.o \ - $(OBJDIR)/string_endswith.o \ - $(OBJDIR)/loadlib.o \ - $(OBJDIR)/ldebug.o \ - $(OBJDIR)/lstring.o \ - $(OBJDIR)/lparser.o \ - $(OBJDIR)/lfunc.o \ - $(OBJDIR)/ldump.o \ - $(OBJDIR)/liolib.o \ - $(OBJDIR)/lgc.o \ - $(OBJDIR)/lundump.o \ - $(OBJDIR)/lopcodes.o \ - $(OBJDIR)/lmem.o \ - $(OBJDIR)/lstate.o \ - $(OBJDIR)/ltm.o \ - $(OBJDIR)/ldo.o \ - $(OBJDIR)/lzio.o \ - $(OBJDIR)/lstrlib.o \ - $(OBJDIR)/lapi.o \ - $(OBJDIR)/lbaselib.o \ - $(OBJDIR)/ltablib.o \ - $(OBJDIR)/llex.o \ - $(OBJDIR)/loslib.o \ - $(OBJDIR)/ltable.o \ - $(OBJDIR)/linit.o \ - $(OBJDIR)/ldblib.o \ - $(OBJDIR)/lmathlib.o \ - $(OBJDIR)/lobject.o \ - $(OBJDIR)/lvm.o \ - $(OBJDIR)/lcode.o \ - $(OBJDIR)/lauxlib.o \ - -RESOURCES := \ - -SHELLTYPE := msdos -ifeq (,$(ComSpec)$(COMSPEC)) - SHELLTYPE := posix -endif -ifeq (/bin,$(findstring /bin,$(SHELL))) - SHELLTYPE := posix -endif - -.PHONY: clean prebuild prelink - -all: $(TARGET) - @: - -$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink - @echo Linking Premake4 - $(SILENT) $(LINKCMD) - $(POSTBUILDCMDS) - -$(TARGETDIR): - @echo Creating $(TARGETDIR) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(TARGETDIR) -else - $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) -endif - -$(OBJDIR): - @echo Creating $(OBJDIR) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif - -clean: - @echo Cleaning Premake4 -ifeq (posix,$(SHELLTYPE)) - $(SILENT) rm -f $(TARGET) - $(SILENT) rm -rf $(OBJDIR) -else - $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) - $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) -endif - -prebuild: $(TARGETDIR) $(OBJDIR) - $(PREBUILDCMDS) - -prelink: - $(PRELINKCMDS) - -ifneq (,$(PCH)) -$(GCH): $(PCH) | $(OBJDIR) - @echo $(notdir $<) - -$(SILENT) cp $< $(OBJDIR) - $(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<" -endif - -$(OBJDIR)/path_isabsolute.o: ../../src/host/path_isabsolute.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/path_isabsolute.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_getversion.o: ../../src/host/os_getversion.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getversion.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_isfile.o: ../../src/host/os_isfile.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isfile.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_uuid.o: ../../src/host/os_uuid.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_uuid.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_chdir.o: ../../src/host/os_chdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_chdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_pathsearch.o: ../../src/host/os_pathsearch.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_pathsearch.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_rmdir.o: ../../src/host/os_rmdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_rmdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_match.o: ../../src/host/os_match.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_match.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/scripts.o: ../../src/host/scripts.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/scripts.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_copyfile.o: ../../src/host/os_copyfile.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_copyfile.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_isdir.o: ../../src/host/os_isdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_mkdir.o: ../../src/host/os_mkdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_mkdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_getcwd.o: ../../src/host/os_getcwd.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getcwd.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/premake.o: ../../src/host/premake.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/premake.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/string_endswith.o: ../../src/host/string_endswith.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/string_endswith.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/loadlib.o: ../../src/host/lua-5.1.4/src/loadlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loadlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldebug.o: ../../src/host/lua-5.1.4/src/ldebug.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldebug.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstring.o: ../../src/host/lua-5.1.4/src/lstring.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstring.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lparser.o: ../../src/host/lua-5.1.4/src/lparser.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lparser.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lfunc.o: ../../src/host/lua-5.1.4/src/lfunc.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lfunc.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldump.o: ../../src/host/lua-5.1.4/src/ldump.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldump.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/liolib.o: ../../src/host/lua-5.1.4/src/liolib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/liolib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lgc.o: ../../src/host/lua-5.1.4/src/lgc.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lgc.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lundump.o: ../../src/host/lua-5.1.4/src/lundump.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lundump.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lopcodes.o: ../../src/host/lua-5.1.4/src/lopcodes.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lopcodes.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lmem.o: ../../src/host/lua-5.1.4/src/lmem.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmem.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstate.o: ../../src/host/lua-5.1.4/src/lstate.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstate.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltm.o: ../../src/host/lua-5.1.4/src/ltm.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltm.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldo.o: ../../src/host/lua-5.1.4/src/ldo.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldo.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lzio.o: ../../src/host/lua-5.1.4/src/lzio.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lzio.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstrlib.o: ../../src/host/lua-5.1.4/src/lstrlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstrlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lapi.o: ../../src/host/lua-5.1.4/src/lapi.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lapi.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lbaselib.o: ../../src/host/lua-5.1.4/src/lbaselib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lbaselib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltablib.o: ../../src/host/lua-5.1.4/src/ltablib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltablib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/llex.o: ../../src/host/lua-5.1.4/src/llex.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/llex.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/loslib.o: ../../src/host/lua-5.1.4/src/loslib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loslib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltable.o: ../../src/host/lua-5.1.4/src/ltable.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltable.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/linit.o: ../../src/host/lua-5.1.4/src/linit.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/linit.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldblib.o: ../../src/host/lua-5.1.4/src/ldblib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldblib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lmathlib.o: ../../src/host/lua-5.1.4/src/lmathlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmathlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lobject.o: ../../src/host/lua-5.1.4/src/lobject.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lobject.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lvm.o: ../../src/host/lua-5.1.4/src/lvm.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lvm.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lcode.o: ../../src/host/lua-5.1.4/src/lcode.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lcode.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lauxlib.o: ../../src/host/lua-5.1.4/src/lauxlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lauxlib.d -MT "$@" -o "$@" -c "$<" - --include $(OBJECTS:%.o=%.d) --include $(GCH:%.h.gch=%.h.d) \ No newline at end of file Index: ps/trunk/build/premake/premake4/build/gmake.macosx/Makefile =================================================================== --- ps/trunk/build/premake/premake4/build/gmake.macosx/Makefile +++ ps/trunk/build/premake/premake4/build/gmake.macosx/Makefile @@ -1,34 +0,0 @@ -# GNU Make solution makefile autogenerated by Premake -# Type "make help" for usage help - -ifndef config - config=release -endif -export config - -PROJECTS := Premake4 - -.PHONY: all clean help $(PROJECTS) - -all: $(PROJECTS) - -Premake4: - @echo "==== Building Premake4 ($(config)) ====" - @${MAKE} --no-print-directory -C . -f Premake4.make - -clean: - @${MAKE} --no-print-directory -C . -f Premake4.make clean - -help: - @echo "Usage: make [config=name] [target]" - @echo "" - @echo "CONFIGURATIONS:" - @echo " release" - @echo " debug" - @echo "" - @echo "TARGETS:" - @echo " all (default)" - @echo " clean" - @echo " Premake4" - @echo "" - @echo "For more information, see http://industriousone.com/premake/quick-start" Index: ps/trunk/build/premake/premake4/build/gmake.macosx/Premake4.make =================================================================== --- ps/trunk/build/premake/premake4/build/gmake.macosx/Premake4.make +++ ps/trunk/build/premake/premake4/build/gmake.macosx/Premake4.make @@ -1,305 +0,0 @@ -# GNU Make project makefile autogenerated by Premake -ifndef config - config=release -endif - -ifndef verbose - SILENT = @ -endif - -ifndef CC - CC = gcc -endif - -ifndef CXX - CXX = g++ -endif - -ifndef AR - AR = ar -endif - -ifeq ($(config),release) - OBJDIR = obj/Release - TARGETDIR = ../../bin/release - TARGET = $(TARGETDIR)/premake4 - DEFINES += -DNDEBUG -DLUA_USE_MACOSX - INCLUDES += -I../../src/host/lua-5.1.4/src - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) -Wall -Os -mmacosx-version-min=10.4 - CXXFLAGS += $(CPPFLAGS) -Wall -Os -mmacosx-version-min=10.4 - LDFLAGS += -Wl,-x -mmacosx-version-min=10.4 - LIBS += -framework CoreServices - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - -ifeq ($(config),debug) - OBJDIR = obj/Debug - TARGETDIR = ../../bin/debug - TARGET = $(TARGETDIR)/premake4 - DEFINES += -D_DEBUG -DLUA_USE_MACOSX - INCLUDES += -I../../src/host/lua-5.1.4/src - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) -Wall -g -mmacosx-version-min=10.4 - CXXFLAGS += $(CPPFLAGS) -Wall -g -mmacosx-version-min=10.4 - LDFLAGS += -mmacosx-version-min=10.4 - LIBS += -framework CoreServices - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - -OBJECTS := \ - $(OBJDIR)/os_chdir.o \ - $(OBJDIR)/os_copyfile.o \ - $(OBJDIR)/os_getcwd.o \ - $(OBJDIR)/os_getversion.o \ - $(OBJDIR)/os_isdir.o \ - $(OBJDIR)/os_isfile.o \ - $(OBJDIR)/os_match.o \ - $(OBJDIR)/os_mkdir.o \ - $(OBJDIR)/os_pathsearch.o \ - $(OBJDIR)/os_rmdir.o \ - $(OBJDIR)/os_uuid.o \ - $(OBJDIR)/path_isabsolute.o \ - $(OBJDIR)/premake.o \ - $(OBJDIR)/scripts.o \ - $(OBJDIR)/string_endswith.o \ - $(OBJDIR)/lapi.o \ - $(OBJDIR)/lauxlib.o \ - $(OBJDIR)/lbaselib.o \ - $(OBJDIR)/lcode.o \ - $(OBJDIR)/ldblib.o \ - $(OBJDIR)/ldebug.o \ - $(OBJDIR)/ldo.o \ - $(OBJDIR)/ldump.o \ - $(OBJDIR)/lfunc.o \ - $(OBJDIR)/lgc.o \ - $(OBJDIR)/linit.o \ - $(OBJDIR)/liolib.o \ - $(OBJDIR)/llex.o \ - $(OBJDIR)/lmathlib.o \ - $(OBJDIR)/lmem.o \ - $(OBJDIR)/loadlib.o \ - $(OBJDIR)/lobject.o \ - $(OBJDIR)/lopcodes.o \ - $(OBJDIR)/loslib.o \ - $(OBJDIR)/lparser.o \ - $(OBJDIR)/lstate.o \ - $(OBJDIR)/lstring.o \ - $(OBJDIR)/lstrlib.o \ - $(OBJDIR)/ltable.o \ - $(OBJDIR)/ltablib.o \ - $(OBJDIR)/ltm.o \ - $(OBJDIR)/lundump.o \ - $(OBJDIR)/lvm.o \ - $(OBJDIR)/lzio.o \ - -RESOURCES := \ - -SHELLTYPE := msdos -ifeq (,$(ComSpec)$(COMSPEC)) - SHELLTYPE := posix -endif -ifeq (/bin,$(findstring /bin,$(SHELL))) - SHELLTYPE := posix -endif - -.PHONY: clean prebuild prelink - -all: $(TARGET) - @: - -$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink - @echo Linking Premake4 - $(SILENT) $(LINKCMD) - $(POSTBUILDCMDS) - -$(TARGETDIR): - @echo Creating $(TARGETDIR) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(TARGETDIR) -else - $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) -endif - -$(OBJDIR): - @echo Creating $(OBJDIR) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif - -clean: - @echo Cleaning Premake4 -ifeq (posix,$(SHELLTYPE)) - $(SILENT) rm -f $(TARGET) - $(SILENT) rm -rf $(OBJDIR) -else - $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) - $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) -endif - -prebuild: $(TARGETDIR) $(OBJDIR) - $(PREBUILDCMDS) - -prelink: - $(PRELINKCMDS) - -ifneq (,$(PCH)) -$(GCH): $(PCH) | $(OBJDIR) - @echo $(notdir $<) - -$(SILENT) cp $< $(OBJDIR) - $(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<" -endif - -$(OBJDIR)/os_chdir.o: ../../src/host/os_chdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_chdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_copyfile.o: ../../src/host/os_copyfile.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_copyfile.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_getcwd.o: ../../src/host/os_getcwd.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getcwd.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_getversion.o: ../../src/host/os_getversion.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getversion.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_isdir.o: ../../src/host/os_isdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_isfile.o: ../../src/host/os_isfile.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isfile.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_match.o: ../../src/host/os_match.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_match.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_mkdir.o: ../../src/host/os_mkdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_mkdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_pathsearch.o: ../../src/host/os_pathsearch.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_pathsearch.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_rmdir.o: ../../src/host/os_rmdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_rmdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_uuid.o: ../../src/host/os_uuid.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_uuid.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/path_isabsolute.o: ../../src/host/path_isabsolute.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/path_isabsolute.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/premake.o: ../../src/host/premake.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/premake.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/scripts.o: ../../src/host/scripts.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/scripts.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/string_endswith.o: ../../src/host/string_endswith.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/string_endswith.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lapi.o: ../../src/host/lua-5.1.4/src/lapi.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lapi.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lauxlib.o: ../../src/host/lua-5.1.4/src/lauxlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lauxlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lbaselib.o: ../../src/host/lua-5.1.4/src/lbaselib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lbaselib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lcode.o: ../../src/host/lua-5.1.4/src/lcode.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lcode.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldblib.o: ../../src/host/lua-5.1.4/src/ldblib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldblib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldebug.o: ../../src/host/lua-5.1.4/src/ldebug.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldebug.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldo.o: ../../src/host/lua-5.1.4/src/ldo.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldo.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldump.o: ../../src/host/lua-5.1.4/src/ldump.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldump.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lfunc.o: ../../src/host/lua-5.1.4/src/lfunc.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lfunc.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lgc.o: ../../src/host/lua-5.1.4/src/lgc.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lgc.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/linit.o: ../../src/host/lua-5.1.4/src/linit.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/linit.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/liolib.o: ../../src/host/lua-5.1.4/src/liolib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/liolib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/llex.o: ../../src/host/lua-5.1.4/src/llex.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/llex.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lmathlib.o: ../../src/host/lua-5.1.4/src/lmathlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmathlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lmem.o: ../../src/host/lua-5.1.4/src/lmem.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmem.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/loadlib.o: ../../src/host/lua-5.1.4/src/loadlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loadlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lobject.o: ../../src/host/lua-5.1.4/src/lobject.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lobject.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lopcodes.o: ../../src/host/lua-5.1.4/src/lopcodes.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lopcodes.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/loslib.o: ../../src/host/lua-5.1.4/src/loslib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loslib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lparser.o: ../../src/host/lua-5.1.4/src/lparser.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lparser.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstate.o: ../../src/host/lua-5.1.4/src/lstate.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstate.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstring.o: ../../src/host/lua-5.1.4/src/lstring.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstring.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstrlib.o: ../../src/host/lua-5.1.4/src/lstrlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstrlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltable.o: ../../src/host/lua-5.1.4/src/ltable.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltable.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltablib.o: ../../src/host/lua-5.1.4/src/ltablib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltablib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltm.o: ../../src/host/lua-5.1.4/src/ltm.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltm.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lundump.o: ../../src/host/lua-5.1.4/src/lundump.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lundump.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lvm.o: ../../src/host/lua-5.1.4/src/lvm.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lvm.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lzio.o: ../../src/host/lua-5.1.4/src/lzio.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lzio.d -MT "$@" -o "$@" -c "$<" - --include $(OBJECTS:%.o=%.d) --include $(GCH:%.h.gch=%.h.d) Index: ps/trunk/build/premake/premake4/build/gmake.unix/Makefile =================================================================== --- ps/trunk/build/premake/premake4/build/gmake.unix/Makefile +++ ps/trunk/build/premake/premake4/build/gmake.unix/Makefile @@ -1,34 +0,0 @@ -# GNU Make solution makefile autogenerated by Premake -# Type "make help" for usage help - -ifndef config - config=release -endif -export config - -PROJECTS := Premake4 - -.PHONY: all clean help $(PROJECTS) - -all: $(PROJECTS) - -Premake4: - @echo "==== Building Premake4 ($(config)) ====" - @${MAKE} --no-print-directory -C . -f Premake4.make - -clean: - @${MAKE} --no-print-directory -C . -f Premake4.make clean - -help: - @echo "Usage: make [config=name] [target]" - @echo "" - @echo "CONFIGURATIONS:" - @echo " release" - @echo " debug" - @echo "" - @echo "TARGETS:" - @echo " all (default)" - @echo " clean" - @echo " Premake4" - @echo "" - @echo "For more information, see http://industriousone.com/premake/quick-start" Index: ps/trunk/build/premake/premake4/build/gmake.unix/Premake4.make =================================================================== --- ps/trunk/build/premake/premake4/build/gmake.unix/Premake4.make +++ ps/trunk/build/premake/premake4/build/gmake.unix/Premake4.make @@ -1,305 +0,0 @@ -# GNU Make project makefile autogenerated by Premake -ifndef config - config=release -endif - -ifndef verbose - SILENT = @ -endif - -ifndef CC - CC = gcc -endif - -ifndef CXX - CXX = g++ -endif - -ifndef AR - AR = ar -endif - -ifeq ($(config),release) - OBJDIR = obj/Release - TARGETDIR = ../../bin/release - TARGET = $(TARGETDIR)/premake4 - DEFINES += -DNDEBUG -DLUA_USE_POSIX -DLUA_USE_DLOPEN - INCLUDES += -I../../src/host/lua-5.1.4/src - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) -Wall -Os - CXXFLAGS += $(CPPFLAGS) -Wall -Os - LDFLAGS += -s -rdynamic - LIBS += -lm -ldl - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - -ifeq ($(config),debug) - OBJDIR = obj/Debug - TARGETDIR = ../../bin/debug - TARGET = $(TARGETDIR)/premake4 - DEFINES += -D_DEBUG -DLUA_USE_POSIX -DLUA_USE_DLOPEN - INCLUDES += -I../../src/host/lua-5.1.4/src - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) -Wall -g - CXXFLAGS += $(CPPFLAGS) -Wall -g - LDFLAGS += -rdynamic - LIBS += -lm -ldl - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(LDDEPS) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - -OBJECTS := \ - $(OBJDIR)/path_isabsolute.o \ - $(OBJDIR)/os_getversion.o \ - $(OBJDIR)/os_isfile.o \ - $(OBJDIR)/os_uuid.o \ - $(OBJDIR)/os_chdir.o \ - $(OBJDIR)/os_pathsearch.o \ - $(OBJDIR)/os_rmdir.o \ - $(OBJDIR)/os_match.o \ - $(OBJDIR)/scripts.o \ - $(OBJDIR)/os_copyfile.o \ - $(OBJDIR)/os_isdir.o \ - $(OBJDIR)/os_mkdir.o \ - $(OBJDIR)/os_getcwd.o \ - $(OBJDIR)/premake.o \ - $(OBJDIR)/string_endswith.o \ - $(OBJDIR)/loadlib.o \ - $(OBJDIR)/ldebug.o \ - $(OBJDIR)/lstring.o \ - $(OBJDIR)/lparser.o \ - $(OBJDIR)/lfunc.o \ - $(OBJDIR)/ldump.o \ - $(OBJDIR)/liolib.o \ - $(OBJDIR)/lgc.o \ - $(OBJDIR)/lundump.o \ - $(OBJDIR)/lopcodes.o \ - $(OBJDIR)/lmem.o \ - $(OBJDIR)/lstate.o \ - $(OBJDIR)/ltm.o \ - $(OBJDIR)/ldo.o \ - $(OBJDIR)/lzio.o \ - $(OBJDIR)/lstrlib.o \ - $(OBJDIR)/lapi.o \ - $(OBJDIR)/lbaselib.o \ - $(OBJDIR)/ltablib.o \ - $(OBJDIR)/llex.o \ - $(OBJDIR)/loslib.o \ - $(OBJDIR)/ltable.o \ - $(OBJDIR)/linit.o \ - $(OBJDIR)/ldblib.o \ - $(OBJDIR)/lmathlib.o \ - $(OBJDIR)/lobject.o \ - $(OBJDIR)/lvm.o \ - $(OBJDIR)/lcode.o \ - $(OBJDIR)/lauxlib.o \ - -RESOURCES := \ - -SHELLTYPE := msdos -ifeq (,$(ComSpec)$(COMSPEC)) - SHELLTYPE := posix -endif -ifeq (/bin,$(findstring /bin,$(SHELL))) - SHELLTYPE := posix -endif - -.PHONY: clean prebuild prelink - -all: $(TARGET) - @: - -$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink - @echo Linking Premake4 - $(SILENT) $(LINKCMD) - $(POSTBUILDCMDS) - -$(TARGETDIR): - @echo Creating $(TARGETDIR) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(TARGETDIR) -else - $(SILENT) mkdir $(subst /,\\,$(TARGETDIR)) -endif - -$(OBJDIR): - @echo Creating $(OBJDIR) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif - -clean: - @echo Cleaning Premake4 -ifeq (posix,$(SHELLTYPE)) - $(SILENT) rm -f $(TARGET) - $(SILENT) rm -rf $(OBJDIR) -else - $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET)) - $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR)) -endif - -prebuild: $(TARGETDIR) $(OBJDIR) - $(PREBUILDCMDS) - -prelink: - $(PRELINKCMDS) - -ifneq (,$(PCH)) -$(GCH): $(PCH) | $(OBJDIR) - @echo $(notdir $<) - -$(SILENT) cp $< $(OBJDIR) - $(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<" -endif - -$(OBJDIR)/path_isabsolute.o: ../../src/host/path_isabsolute.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/path_isabsolute.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_getversion.o: ../../src/host/os_getversion.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getversion.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_isfile.o: ../../src/host/os_isfile.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isfile.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_uuid.o: ../../src/host/os_uuid.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_uuid.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_chdir.o: ../../src/host/os_chdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_chdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_pathsearch.o: ../../src/host/os_pathsearch.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_pathsearch.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_rmdir.o: ../../src/host/os_rmdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_rmdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_match.o: ../../src/host/os_match.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_match.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/scripts.o: ../../src/host/scripts.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/scripts.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_copyfile.o: ../../src/host/os_copyfile.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_copyfile.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_isdir.o: ../../src/host/os_isdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_isdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_mkdir.o: ../../src/host/os_mkdir.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_mkdir.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/os_getcwd.o: ../../src/host/os_getcwd.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/os_getcwd.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/premake.o: ../../src/host/premake.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/premake.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/string_endswith.o: ../../src/host/string_endswith.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/string_endswith.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/loadlib.o: ../../src/host/lua-5.1.4/src/loadlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loadlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldebug.o: ../../src/host/lua-5.1.4/src/ldebug.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldebug.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstring.o: ../../src/host/lua-5.1.4/src/lstring.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstring.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lparser.o: ../../src/host/lua-5.1.4/src/lparser.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lparser.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lfunc.o: ../../src/host/lua-5.1.4/src/lfunc.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lfunc.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldump.o: ../../src/host/lua-5.1.4/src/ldump.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldump.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/liolib.o: ../../src/host/lua-5.1.4/src/liolib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/liolib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lgc.o: ../../src/host/lua-5.1.4/src/lgc.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lgc.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lundump.o: ../../src/host/lua-5.1.4/src/lundump.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lundump.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lopcodes.o: ../../src/host/lua-5.1.4/src/lopcodes.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lopcodes.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lmem.o: ../../src/host/lua-5.1.4/src/lmem.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmem.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstate.o: ../../src/host/lua-5.1.4/src/lstate.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstate.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltm.o: ../../src/host/lua-5.1.4/src/ltm.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltm.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldo.o: ../../src/host/lua-5.1.4/src/ldo.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldo.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lzio.o: ../../src/host/lua-5.1.4/src/lzio.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lzio.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lstrlib.o: ../../src/host/lua-5.1.4/src/lstrlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lstrlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lapi.o: ../../src/host/lua-5.1.4/src/lapi.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lapi.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lbaselib.o: ../../src/host/lua-5.1.4/src/lbaselib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lbaselib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltablib.o: ../../src/host/lua-5.1.4/src/ltablib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltablib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/llex.o: ../../src/host/lua-5.1.4/src/llex.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/llex.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/loslib.o: ../../src/host/lua-5.1.4/src/loslib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/loslib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ltable.o: ../../src/host/lua-5.1.4/src/ltable.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ltable.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/linit.o: ../../src/host/lua-5.1.4/src/linit.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/linit.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/ldblib.o: ../../src/host/lua-5.1.4/src/ldblib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/ldblib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lmathlib.o: ../../src/host/lua-5.1.4/src/lmathlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lmathlib.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lobject.o: ../../src/host/lua-5.1.4/src/lobject.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lobject.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lvm.o: ../../src/host/lua-5.1.4/src/lvm.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lvm.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lcode.o: ../../src/host/lua-5.1.4/src/lcode.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lcode.d -MT "$@" -o "$@" -c "$<" -$(OBJDIR)/lauxlib.o: ../../src/host/lua-5.1.4/src/lauxlib.c $(GCH) | prebuild - @echo $(notdir $<) - $(SILENT) $(CC) $(PCHINCLUDES) $(CFLAGS) -MF $(OBJDIR)/lauxlib.d -MT "$@" -o "$@" -c "$<" - --include $(OBJECTS:%.o=%.d) --include $(GCH:%.h.gch=%.h.d) \ No newline at end of file Index: ps/trunk/build/premake/premake4/build/vs2013/Premake4.sln =================================================================== --- ps/trunk/build/premake/premake4/build/vs2013/Premake4.sln +++ ps/trunk/build/premake/premake4/build/vs2013/Premake4.sln @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 13.00 -# Visual Studio 2013 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Premake4", "Premake4.vcxproj", "{C01B3660-A453-4F42-B58C-F0B862AF8C1C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Release|Win32 = Release|Win32 - Debug|Win32 = Debug|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C01B3660-A453-4F42-B58C-F0B862AF8C1C}.Release|Win32.ActiveCfg = Release|Win32 - {C01B3660-A453-4F42-B58C-F0B862AF8C1C}.Release|Win32.Build.0 = Release|Win32 - {C01B3660-A453-4F42-B58C-F0B862AF8C1C}.Debug|Win32.ActiveCfg = Debug|Win32 - {C01B3660-A453-4F42-B58C-F0B862AF8C1C}.Debug|Win32.Build.0 = Debug|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal Index: ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj =================================================================== --- ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj +++ ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj @@ -1,332 +0,0 @@ - - - - - Release - Win32 - - - Debug - Win32 - - - - {C01B3660-A453-4F42-B58C-F0B862AF8C1C} - Premake4 - Win32Proj - - - - Application - MultiByte - false - v120_xp - - - Application - MultiByte - true - v120_xp - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\release\ - obj\Release\ - premake4 - false - ..\..\bin\debug\ - obj\Debug\ - premake4 - true - - - - MinSpace - ..\..\src\host\lua-5.1.4\src;%(AdditionalIncludeDirectories) - NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - false - true - MultiThreaded - true - - Level4 - - CompileAsC - - - NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\src\host\lua-5.1.4\src;%(AdditionalIncludeDirectories) - - - $(OutDir)premake4.exe - %(AdditionalLibraryDirectories) - Console - false - true - true - mainCRTStartup - MachineX86 - - - - - Disabled - ..\..\src\host\lua-5.1.4\src;%(AdditionalIncludeDirectories) - _DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - EnableFastChecks - true - MultiThreadedDebug - true - - Level4 - EditAndContinue - CompileAsC - - - _DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ..\..\src\host\lua-5.1.4\src;%(AdditionalIncludeDirectories) - - - $(OutDir)premake4.exe - %(AdditionalLibraryDirectories) - Console - true - $(OutDir)premake4.pdb - mainCRTStartup - MachineX86 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj.filters =================================================================== --- ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj.filters +++ ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj.filters @@ -1,574 +0,0 @@ - - - - - {36BA0540-A6A1-114F-89F3-042F36024844} - - - {FA5D4911-18C5-E44B-97AA-94331270D873} - - - {BC8BA9DE-6170-EF4B-AA76-2273C329A3E4} - - - {5C53251B-4541-0849-9C7B-807CA0D0554C} - - - {537A43E1-A784-DF44-8869-FF09689E64FB} - - - {27AF517C-10D6-5C4F-A114-CCA3E2E417CD} - - - {E36E9579-D1B5-4C4B-8597-C1BC428BE96B} - - - {A766B337-8045-DA44-BF73-E8C2089012DA} - - - {3F536621-36C9-3043-AF39-153814F57430} - - - {4EB65216-E256-C14B-BA94-2635DCED676B} - - - {8EB2000D-3744-2A4D-AF31-24AC9660A207} - - - {6682BEBB-F371-8147-BC19-9517F943B28F} - - - {B39B9E1D-A0D8-6B4A-85FD-1B1D7B280012} - - - {E8945B2E-79D8-7149-B32E-AE3DBB150E49} - - - {390645CE-5B7D-3E42-942D-78343FD35821} - - - {BC4F4D40-597C-F748-A666-2EDFA87150AD} - - - {0719453C-23E3-6345-B3DE-1218B5C12237} - - - {244F8DEA-E911-6948-BF29-2DB61556CA92} - - - {6993107F-6A69-B84A-99D8-6F338A127BCC} - - - {83AA069D-DDDF-974F-B32B-F5398FB5E77A} - - - {86F6ABC5-91A9-9949-9588-A5DA9BB558E5} - - - {38AB070D-9B03-9E46-8DE8-B0E5B34ACD23} - - - - - src\host - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - src\host\lua-5.1.4\src - - - - - - - - - - scripts - - - scripts - - - src - - - src - - - src\actions\clean - - - src\actions\codeblocks - - - src\actions\codeblocks - - - src\actions\codeblocks - - - src\actions\codelite - - - src\actions\codelite - - - src\actions\codelite - - - src\actions\example - - - src\actions\example - - - src\actions\example - - - src\actions\make - - - src\actions\make - - - src\actions\make - - - src\actions\make - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\vstudio - - - src\actions\xcode - - - src\actions\xcode - - - src\actions\xcode - - - src\actions\xcode - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\base - - - src\tools - - - src\tools - - - src\tools - - - src\tools - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests - - - tests\actions - - - tests\actions\make - - - tests\actions\make - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\vstudio - - - tests\actions\xcode - - - tests\actions\xcode - - - tests\actions\xcode - - - tests\base - - - tests\base - - - tests\base - - - tests\base - - - tests\base - - - tests\base - - - tests\base - - - tests\base - - - tests\folder - - - Index: ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj.user =================================================================== --- ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj.user +++ ps/trunk/build/premake/premake4/build/vs2013/Premake4.vcxproj.user @@ -1,3 +0,0 @@ - - - Index: ps/trunk/build/premake/premake4/doxyfile =================================================================== --- ps/trunk/build/premake/premake4/doxyfile +++ ps/trunk/build/premake/premake4/doxyfile @@ -1,258 +0,0 @@ -# Doxyfile 1.5.1-p1 - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = "Premake Internals" -PROJECT_NUMBER = -OUTPUT_DIRECTORY = doc -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the -ALWAYS_DETAILED_SEC = YES -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = "" -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -DETAILS_AT_TOP = NO -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 4 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = YES -OPTIMIZE_OUTPUT_JAVA = NO -BUILTIN_STL_SUPPORT = NO -DISTRIBUTE_GROUP_DOC = NO -SUBGROUPING = YES -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = NO -EXTRACT_PRIVATE = NO -EXTRACT_STATIC = NO -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO -HIDE_UNDOC_MEMBERS = YES -HIDE_UNDOC_CLASSES = YES -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = NO -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = YES -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = NO -FILE_VERSION_FILTER = -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = YES -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = src -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.d \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.idl \ - *.odl \ - *.cs \ - *.php \ - *.php3 \ - *.inc \ - *.m \ - *.mm \ - *.dox \ - *.py -RECURSIVE = YES -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = */UnitTest++/* */lua-5.1.1/* -EXAMPLE_PATH = -EXAMPLE_PATTERNS = * -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = NO -REFERENCES_RELATION = NO -REFERENCES_LINK_SOURCE = YES -USE_HTAGS = NO -VERBATIM_HEADERS = NO -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = NO -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_ALIGN_MEMBERS = YES -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -BINARY_TOC = NO -TOC_EXPAND = NO -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = NO -TREEVIEW_WIDTH = 250 -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = -PDF_HYPERLINKS = NO -USE_PDFLATEX = NO -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = NO -XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = NO -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = NO -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -CALLER_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = -MAX_DOT_GRAPH_DEPTH = 1000 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = NO Index: ps/trunk/build/premake/premake4/premake4.lua =================================================================== --- ps/trunk/build/premake/premake4/premake4.lua +++ ps/trunk/build/premake/premake4/premake4.lua @@ -1,128 +0,0 @@ --- --- Premake 4.x build configuration script --- - --- --- Define the project. Put the release configuration first so it will be the --- default when folks build using the makefile. That way they don't have to --- worry about the /scripts argument and all that. --- - - solution "Premake4" - configurations { "Release", "Debug" } - location ( _OPTIONS["to"] ) - - project "Premake4" - targetname "premake4" - language "C" - kind "ConsoleApp" - flags { "No64BitChecks", "ExtraWarnings", "StaticRuntime" } - includedirs { "src/host/lua-5.1.4/src" } - - files - { - "*.txt", "**.lua", - "src/**.h", "src/**.c", - "src/host/scripts.c" - } - - excludes - { - "src/premake.lua", - "src/host/lua-5.1.4/src/lua.c", - "src/host/lua-5.1.4/src/luac.c", - "src/host/lua-5.1.4/src/print.c", - "src/host/lua-5.1.4/**.lua", - "src/host/lua-5.1.4/etc/*.c" - } - - configuration "Debug" - targetdir "bin/debug" - defines "_DEBUG" - flags { "Symbols" } - - configuration "Release" - targetdir "bin/release" - defines "NDEBUG" - flags { "OptimizeSize" } - - configuration "vs*" - defines { "_CRT_SECURE_NO_WARNINGS" } - - configuration "bsd" - defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" } - links { "m" } - - configuration "linux" - defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" } - links { "m", "dl" } - - configuration "macosx" - defines { "LUA_USE_MACOSX" } - links { "CoreServices.framework" } - - configuration { "macosx", "gmake" } - buildoptions{ "-mmacosx-version-min=10.4" } - linkoptions { "-mmacosx-version-min=10.4" } - - configuration { "not windows", "not solaris", "not macosx" } - linkoptions { "-rdynamic" } - - configuration { "solaris" } - linkoptions { "-Wl,--export-dynamic" } - - - --- --- A more thorough cleanup. --- - - if _ACTION == "clean" then - os.rmdir("bin") - os.rmdir("build") - end - - - --- --- Use the --to=path option to control where the project files get generated. I use --- this to create project files for each supported toolset, each in their own folder, --- in preparation for deployment. --- - - newoption { - trigger = "to", - value = "path", - description = "Set the output location for the generated files" - } - - - --- --- Use the embed action to convert all of the Lua scripts into C strings, which --- can then be built into the executable. Always embed the scripts before creating --- a release build. --- - - dofile("scripts/embed.lua") - - newaction { - trigger = "embed", - description = "Embed scripts in scripts.c; required before release builds", - execute = doembed - } - - --- --- Use the release action to prepare source and binary packages for a new release. --- This action isn't complete yet; a release still requires some manual work. --- - - - dofile("scripts/release.lua") - - newaction { - trigger = "release", - description = "Prepare a new release (incomplete)", - execute = dorelease - } Index: ps/trunk/build/premake/premake4/scripts/RELEASE.txt =================================================================== --- ps/trunk/build/premake/premake4/scripts/RELEASE.txt +++ ps/trunk/build/premake/premake4/scripts/RELEASE.txt @@ -1,57 +0,0 @@ -PREMAKE RELEASE CHECKLIST -------------------------- - -VERSION NUMBERS - - 4.0 - 4.0-beta1 - 4.0-rc1 - 4.0.1 - -PREP - - * Make sure all tests pass on Windows and POSIX - - * Update CHANGELOG.txt as needed - - * Prep release announcement for forums - - * Run `premake4 embed` - - * Commit all changes to premake-stable - - * Tag premake-stable with the version number and push - - * Pull changes to premake-dev - - -BUILD - - * On each platform, run `premake4 release {version} binary` - - * On one platform, run `premake4 release {version} source` - - * If desired, copy binary to local path - - * Upload packages (in release/) to SourceForge - - -RELEASE - - * On SourceForge, set package properties (platform, etc.) - - * Update the download page - http://industriousone.com/premake/download - - * Post release announcement to the forums - - * Update the Latest News on the project home page - - * Post annoucement to @industrious on Twitter - - * Post announcement to email list - - * Post announcement to Industrious Facebook group - - * Add release to Freshmeat - http://freshmeat.net/projects/premake Index: ps/trunk/build/premake/premake4/scripts/embed.lua =================================================================== --- ps/trunk/build/premake/premake4/scripts/embed.lua +++ ps/trunk/build/premake/premake4/scripts/embed.lua @@ -1,96 +0,0 @@ --- --- Embed the Lua scripts into src/host/scripts.c as static data buffers. --- I embed the actual scripts, rather than Lua bytecodes, because the --- bytecodes are not portable to different architectures, which causes --- issues in Mac OS X Universal builds. --- - - local function stripfile(fname) - local f = io.open(fname) - local s = f:read("*a") - f:close() - - -- strip tabs - s = s:gsub("[\t]", "") - - -- strip any CRs - s = s:gsub("[\r]", "") - - -- strip out comments - s = s:gsub("\n%-%-[^\n]*", "") - - -- escape backslashes - s = s:gsub("\\", "\\\\") - - -- strip duplicate line feeds - s = s:gsub("\n+", "\n") - - -- strip out leading comments - s = s:gsub("^%-%-\n", "") - - -- escape line feeds - s = s:gsub("\n", "\\n") - - -- escape double quote marks - s = s:gsub("\"", "\\\"") - - return s - end - - - local function writeline(out, s, continues) - out:write("\t\"") - out:write(s) - out:write(iif(continues, "\"\n", "\",\n")) - end - - - local function writefile(out, fname, contents) - local max = 1024 - - out:write("\t/* " .. fname .. " */\n") - - -- break up large strings to fit in Visual Studio's string length limit - local start = 1 - local len = contents:len() - while start <= len do - local n = len - start - if n > max then n = max end - local finish = start + n - - -- make sure I don't cut an escape sequence - while contents:sub(finish, finish) == "\\" do - finish = finish - 1 - end - - writeline(out, contents:sub(start, finish), finish < len) - start = finish + 1 - end - - out:write("\n") - end - - - function doembed() - -- load the manifest of script files - scripts = dofile("src/_manifest.lua") - - -- main script always goes at the end - table.insert(scripts, "_premake_main.lua") - - -- open scripts.c and write the file header - local out = io.open("src/host/scripts.c", "w+b") - out:write("/* Premake's Lua scripts, as static data buffers for release mode builds */\n") - out:write("/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */\n") - out:write("/* To regenerate this file, run: premake4 embed */ \n\n") - out:write("const char* builtin_scripts[] = {\n") - - for i,fn in ipairs(scripts) do - print(fn) - local s = stripfile("src/" .. fn) - writefile(out, fn, s) - end - - out:write("\t0\n};\n"); - out:close() - end Index: ps/trunk/build/premake/premake4/scripts/release.lua =================================================================== --- ps/trunk/build/premake/premake4/scripts/release.lua +++ ps/trunk/build/premake/premake4/scripts/release.lua @@ -1,216 +0,0 @@ --- --- Prepare a new Premake release. This is still incomplete and some manual --- work is needed to get everything packaged up. See RELEASE.txt in this --- folder for the full checklist. --- --- Info on using Mercurial to manage releases: --- http://hgbook.red-bean.com/read/managing-releases-and-branchy-development.html --- http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/ --- - - -function dorelease() - local z - local hgroot = "https://bitbucket.org/premake/premake-stable" - --- --- Helper function: runs a command (formatted, with optional arguments) and --- suppresses any output. Works on both Windows and POSIX. Might be a good --- candidate for a core function. --- - - local function exec(cmd, ...) - cmd = string.format(cmd, unpack(arg)) - local z = os.execute(cmd .. " > output.log 2> error.log") - os.remove("output.log") - os.remove("error.log") - return z - end - - - --- --- Make sure a version was specified --- - - if #_ARGS ~= 2 then - error("** Usage: release [version] [source | binary]", 0) - end - - local version = _ARGS[1] - local kind = _ARGS[2] - - local pkgname = "premake-" .. version - - --- --- Look for required utilities --- - - local required = { "hg", "zip", "tar", "make", "gcc" } - for _, value in ipairs(required) do - z = exec("%s --version", value) - if z ~= 0 then - error("** '" .. value .. "' not found", 0) - end - end - - --- --- Pre-release checklist --- - - print( "") - print( "BEFORE RUNNING THIS SCRIPT follow the checklist in RELEASE.txt" ) - print( "") - print( "Press [Enter] to begin.") - io .read() - - - - - ---------------------------------------------------------------------------- --- --- Everything below this needs to be reworked for Mercurial --- ---------------------------------------------------------------------------- - --- --- Check out the release tagged sources to releases/ --- - - print("Downloading release tag...") - - os.mkdir("release") - os.chdir("release") - - os.rmdir(pkgname) - z = exec( "hg clone -r %s %s %s", version, hgroot, pkgname) - if z ~= 0 then - error("** Failed to download tagged sources", 0) - end - - os.chdir(pkgname) - - --- --- Update the version number in premake.c --- - - print("Updating version number...") - - io.input("src/host/premake.c") - local text = io.read("*a") - text = text:gsub("HEAD", version) - io.output("src/host/premake.c") - io.write(text) - io.close() - - --- --- Make absolutely sure the embedded scripts have been updated --- - - print("Updating embedded scripts...") - - z = exec("premake4 embed") - if z ~= 0 then - error("** Failed to update the embedded scripts", 0) - end - - --- --- Generate source packaging --- - - if kind == "source" then - - -- - -- Remove extra directories - -- - - print("Cleaning up the source tree...") - - os.rmdir("samples") - os.rmdir("packages") - os.rmdir(".hg") - os.rmdir(".hgignore") - os.rmdir(".hgtags") - - - -- - -- Generate project files to the build directory - -- - - print("Generating project files...") - - exec("premake4 /to=build/vs2005 vs2005") - exec("premake4 /to=build/vs2008 vs2008") - exec("premake4 /to=build/vs2010 vs2010") - exec("premake4 /to=build/vs2012 vs2012") - exec("premake4 /to=build/vs2013 vs2013") - exec("premake4 /to=build/gmake.windows /os=windows gmake") - exec("premake4 /to=build/gmake.unix /os=linux gmake") - exec("premake4 /to=build/gmake.macosx /os=macosx /platform=universal32 gmake") - exec("premake4 /to=build/codeblocks.windows /os=windows codeblocks") - exec("premake4 /to=build/codeblocks.unix /os=linux codeblocks") - exec("premake4 /to=build/codeblocks.macosx /os=macosx /platform=universal32 codeblocks") - exec("premake4 /to=build/codelite.windows /os=windows codelite") - exec("premake4 /to=build/codelite.unix /os=linux codelite") - exec("premake4 /to=build/codelite.macosx /os=macosx /platform=universal32 codelite") - exec("premake4 /to=build/xcode3 /platform=universal32 xcode3") - - - -- - -- Create source package - -- - - print("Creating source code package...") - - os.chdir("..") - exec("zip -r9 %s-src.zip %s/*", pkgname, pkgname) - --- --- Create a binary package for this platform. This step requires a working --- GNU/Make/GCC environment. I use MinGW on Windows. --- - - else - - print("Building platform binary release...") - - exec("premake4 /platform=universal32 gmake") - exec("make config=%s", iif(os.is("macosx"), "releaseuniv32", "release")) - - local fname - os.chdir("bin/release") - if os.is("windows") then - fname = string.format("%s-windows.zip", pkgname) - exec("zip -9 %s premake4.exe", fname) - else - fname = string.format("%s-%s.tar.gz", pkgname, os.get()) - exec("tar czvf %s premake4", fname) - end - - os.copyfile(fname, "../../../" .. fname) - os.chdir("../../..") - end - - --- --- Upload files to SourceForge --- - - - --- --- Clean up --- - - os.rmdir(pkgname) - - print("") - print( "Finished.") - -end Index: ps/trunk/build/premake/premake4/src/_manifest.lua =================================================================== --- ps/trunk/build/premake/premake4/src/_manifest.lua +++ ps/trunk/build/premake/premake4/src/_manifest.lua @@ -1,74 +0,0 @@ --- --- _manifest.lua --- Manage the list of built-in Premake scripts. --- Copyright (c) 2002-2010 Jason Perkins and the Premake project --- - --- The master list of built-in scripts. Order is important! If you want to --- build a new script into Premake, add it to this list. - - return - { - -- core files - "base/os.lua", - "base/path.lua", - "base/string.lua", - "base/table.lua", - "base/io.lua", - "base/globals.lua", - "base/action.lua", - "base/option.lua", - "base/tree.lua", - "base/solution.lua", - "base/project.lua", - "base/configs.lua", - "base/api.lua", - "base/cmdline.lua", - "tools/dotnet.lua", - "tools/gcc.lua", - "tools/msc.lua", - "tools/ow.lua", - "base/validate.lua", - "base/help.lua", - "base/premake.lua", - - -- CodeBlocks action - "actions/codeblocks/_codeblocks.lua", - "actions/codeblocks/codeblocks_workspace.lua", - "actions/codeblocks/codeblocks_cbp.lua", - - -- CodeLite action - "actions/codelite/_codelite.lua", - "actions/codelite/codelite_workspace.lua", - "actions/codelite/codelite_project.lua", - - -- GNU make action - "actions/make/_make.lua", - "actions/make/make_solution.lua", - "actions/make/make_cpp.lua", - "actions/make/make_csharp.lua", - - -- Visual Studio actions - "actions/vstudio/_vstudio.lua", - "actions/vstudio/vs2002_solution.lua", - "actions/vstudio/vs2002_csproj.lua", - "actions/vstudio/vs2002_csproj_user.lua", - "actions/vstudio/vs200x_vcproj.lua", - "actions/vstudio/vs2003_solution.lua", - "actions/vstudio/vs2005_solution.lua", - "actions/vstudio/vs2005_csproj.lua", - "actions/vstudio/vs2005_csproj_user.lua", - "actions/vstudio/vs_generic_solution.lua", - "actions/vstudio/vs2010_vcxproxj.lua", - - -- Xcode action - "actions/xcode/_xcode.lua", - "actions/xcode/xcode_common.lua", - "actions/xcode/xcode_project.lua", - - -- Xcode4 action - "actions/xcode/xcode4_workspace.lua", - - -- Clean action - "actions/clean/_clean.lua", - } Index: ps/trunk/build/premake/premake4/src/_premake_main.lua =================================================================== --- ps/trunk/build/premake/premake4/src/_premake_main.lua +++ ps/trunk/build/premake/premake4/src/_premake_main.lua @@ -1,154 +0,0 @@ --- --- _premake_main.lua --- Script-side entry point for the main program logic. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - - local scriptfile = "premake4.lua" - local shorthelp = "Type 'premake4 --help' for help" - local versionhelp = "premake4 (Premake Build Script Generator) %s" - - - --- --- Inject a new target platform into each solution; called if the --platform --- argument was specified on the command line. --- - - local function injectplatform(platform) - if not platform then return true end - platform = premake.checkvalue(platform, premake.fields.platforms.allowed) - - for sln in premake.solution.each() do - local platforms = sln.platforms or { } - - -- an empty table is equivalent to a native build - if #platforms == 0 then - table.insert(platforms, "Native") - end - - -- the solution must provide a native build in order to support this feature - if not table.contains(platforms, "Native") then - return false, sln.name .. " does not target native platform\nNative platform settings are required for the --platform feature." - end - - -- add it to the end of the list, if it isn't in there already - if not table.contains(platforms, platform) then - table.insert(platforms, platform) - end - - sln.platforms = platforms - end - - return true - end - - --- --- Script-side program entry point. --- - - function _premake_main(scriptpath) - - -- if running off the disk (in debug mode), load everything - -- listed in _manifest.lua; the list divisions make sure - -- everything gets initialized in the proper order. - - if (scriptpath) then - local scripts = dofile(scriptpath .. "/_manifest.lua") - for _,v in ipairs(scripts) do - dofile(scriptpath .. "/" .. v) - end - end - - - -- Set up the environment for the chosen action early, so side-effects - -- can be picked up by the scripts. - - premake.action.set(_ACTION) - - - -- Seed the random number generator so actions don't have to do it themselves - - math.randomseed(os.time()) - - - -- If there is a project script available, run it to get the - -- project information, available options and actions, etc. - - local fname = _OPTIONS["file"] or scriptfile - if (os.isfile(fname)) then - dofile(fname) - end - - - -- Process special options - - if (_OPTIONS["version"]) then - printf(versionhelp, _PREMAKE_VERSION) - return 1 - end - - if (_OPTIONS["help"]) then - premake.showhelp() - return 1 - end - - - -- If no action was specified, show a short help message - - if (not _ACTION) then - print(shorthelp) - return 1 - end - - - -- If there wasn't a project script I've got to bail now - - if (not os.isfile(fname)) then - error("No Premake script ("..scriptfile..") found!", 2) - end - - - -- Validate the command-line arguments. This has to happen after the - -- script has run to allow for project-specific options - - action = premake.action.current() - if (not action) then - error("Error: no such action '" .. _ACTION .. "'", 0) - end - - ok, err = premake.option.validate(_OPTIONS) - if (not ok) then error("Error: " .. err, 0) end - - - -- Sanity check the current project setup - - ok, err = premake.checktools() - if (not ok) then error("Error: " .. err, 0) end - - - -- If a platform was specified on the command line, inject it now - - ok, err = injectplatform(_OPTIONS["platform"]) - if (not ok) then error("Error: " .. err, 0) end - - - -- work-in-progress: build the configurations - print("Building configurations...") - premake.buildconfigs() - - ok, err = premake.checkprojects() - if (not ok) then error("Error: " .. err, 0) end - - - -- Hand over control to the action - printf("Running action '%s'...", action.trigger) - premake.action.call(action.trigger) - - print("Done.") - return 0 - - end - Index: ps/trunk/build/premake/premake4/src/actions/clean/_clean.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/clean/_clean.lua +++ ps/trunk/build/premake/premake4/src/actions/clean/_clean.lua @@ -1,104 +0,0 @@ --- --- _clean.lua --- The "clean" action: removes all generated files. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - premake.clean = { } - - --- --- Clean a solution or project specific directory. Uses information in the --- project object to build the target path. --- --- @param obj --- A solution or project object. --- @param pattern --- A filename pattern to clean; see premake.project.getfilename() for --- a description of the format. --- - - function premake.clean.directory(obj, pattern) - local fname = premake.project.getfilename(obj, pattern) - os.rmdir(fname) - end - - --- --- Clean a solution or project specific file. Uses information in the project --- object to build the target filename. --- --- @param obj --- A solution or project object. --- @param pattern --- A filename pattern to clean; see premake.project.getfilename() for --- a description of the format. --- - - function premake.clean.file(obj, pattern) - local fname = premake.project.getfilename(obj, pattern) - os.remove(fname) - end - - --- --- Register the "clean" action. --- - - newaction { - trigger = "clean", - description = "Remove all binaries and generated files", - - onsolution = function(sln) - for action in premake.action.each() do - if action.oncleansolution then - action.oncleansolution(sln) - end - end - end, - - onproject = function(prj) - for action in premake.action.each() do - if action.oncleanproject then - action.oncleanproject(prj) - end - end - - if (prj.objectsdir) then - premake.clean.directory(prj, prj.objectsdir) - end - - -- build a list of supported target platforms that also includes a generic build - local platforms = prj.solution.platforms or { } - if not table.contains(platforms, "Native") then - platforms = table.join(platforms, { "Native" }) - end - - for _, platform in ipairs(platforms) do - for cfg in premake.eachconfig(prj, platform) do - premake.clean.directory(prj, cfg.objectsdir) - - -- remove all permutations of the target binary - premake.clean.file(prj, premake.gettarget(cfg, "build", "posix", "windows", "windows").fullpath) - premake.clean.file(prj, premake.gettarget(cfg, "build", "posix", "posix", "linux").fullpath) - premake.clean.file(prj, premake.gettarget(cfg, "build", "posix", "posix", "macosx").fullpath) - premake.clean.file(prj, premake.gettarget(cfg, "build", "posix", "PS3", "windows").fullpath) - if cfg.kind == "WindowedApp" then - premake.clean.directory(prj, premake.gettarget(cfg, "build", "posix", "posix", "linux").fullpath .. ".app") - end - - -- if there is an import library, remove that too - premake.clean.file(prj, premake.gettarget(cfg, "link", "windows", "windows", "windows").fullpath) - premake.clean.file(prj, premake.gettarget(cfg, "link", "posix", "posix", "linux").fullpath) - - -- call action.oncleantarget() with the undecorated target name - local target = path.join(premake.project.getfilename(prj, cfg.buildtarget.directory), cfg.buildtarget.basename) - for action in premake.action.each() do - if action.oncleantarget then - action.oncleantarget(target) - end - end - end - end - end - } Index: ps/trunk/build/premake/premake4/src/actions/codeblocks/_codeblocks.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/codeblocks/_codeblocks.lua +++ ps/trunk/build/premake/premake4/src/actions/codeblocks/_codeblocks.lua @@ -1,38 +0,0 @@ --- --- _codeblocks.lua --- Define the Code::Blocks action(s). --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - - newaction { - trigger = "codeblocks", - shortname = "Code::Blocks", - description = "Generate Code::Blocks project files", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++" }, - - valid_tools = { - cc = { "gcc", "ow" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.workspace", premake.codeblocks_workspace) - end, - - onproject = function(prj) - premake.generate(prj, "%%.cbp", premake.codeblocks_cbp) - end, - - oncleansolution = function(sln) - premake.clean.file(sln, "%%.workspace") - end, - - oncleanproject = function(prj) - premake.clean.file(prj, "%%.cbp") - premake.clean.file(prj, "%%.depend") - premake.clean.file(prj, "%%.layout") - end - } Index: ps/trunk/build/premake/premake4/src/actions/codeblocks/codeblocks_cbp.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/codeblocks/codeblocks_cbp.lua +++ ps/trunk/build/premake/premake4/src/actions/codeblocks/codeblocks_cbp.lua @@ -1,144 +0,0 @@ --- --- codeblocks_cbp.lua --- Generate a Code::Blocks C/C++ project. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.codeblocks_cbp(prj) - -- alias the C/C++ compiler interface - local cc = premake.gettool(prj) - - _p('') - _p('') - _p(1,'') - - -- write project block header - _p(1,'') - _p(2,'') - _p('') - _p('') - - end Index: ps/trunk/build/premake/premake4/src/actions/codeblocks/codeblocks_workspace.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/codeblocks/codeblocks_workspace.lua +++ ps/trunk/build/premake/premake4/src/actions/codeblocks/codeblocks_workspace.lua @@ -1,27 +0,0 @@ --- --- codeblocks_workspace.lua --- Generate a Code::Blocks workspace. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.codeblocks_workspace(sln) - _p('') - _p('') - _p(1,'', sln.name) - - for prj in premake.solution.eachproject(sln) do - local fname = path.join(path.getrelative(sln.location, prj.location), prj.name) - local active = iif(prj.project == sln.projects[1], ' active="1"', '') - - _p(2,'', fname, active) - for _,dep in ipairs(premake.getdependencies(prj)) do - _p(3,'', path.join(path.getrelative(sln.location, dep.location), dep.name)) - end - - _p(2,'') - end - - _p(1,'') - _p('') - end - Index: ps/trunk/build/premake/premake4/src/actions/codelite/_codelite.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/codelite/_codelite.lua +++ ps/trunk/build/premake/premake4/src/actions/codelite/_codelite.lua @@ -1,40 +0,0 @@ --- --- _codelite.lua --- Define the CodeLite action(s). --- Copyright (c) 2008-2009 Jason Perkins and the Premake project --- - - newaction { - trigger = "codelite", - shortname = "CodeLite", - description = "Generate CodeLite project files", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++" }, - - valid_tools = { - cc = { "gcc" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.workspace", premake.codelite_workspace) - end, - - onproject = function(prj) - premake.generate(prj, "%%.project", premake.codelite_project) - end, - - oncleansolution = function(sln) - premake.clean.file(sln, "%%.workspace") - premake.clean.file(sln, "%%_wsp.mk") - premake.clean.file(sln, "%%.tags") - end, - - oncleanproject = function(prj) - premake.clean.file(prj, "%%.project") - premake.clean.file(prj, "%%.mk") - premake.clean.file(prj, "%%.list") - premake.clean.file(prj, "%%.out") - end - } Index: ps/trunk/build/premake/premake4/src/actions/codelite/codelite_project.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/codelite/codelite_project.lua +++ ps/trunk/build/premake/premake4/src/actions/codelite/codelite_project.lua @@ -1,146 +0,0 @@ --- --- codelite_project.lua --- Generate a CodeLite C/C++ project file. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.codelite_project(prj) - _p('') - _p('', premake.esc(prj.name)) - - premake.walksources(prj, premake.codelite_files) - - local types = { - ConsoleApp = "Executable", - WindowedApp = "Executable", - StaticLib = "Static Library", - SharedLib = "Dynamic Library", - } - _p(' ', types[prj.kind]) - - -- build a list of supported target platforms; I don't support cross-compiling yet - local platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms, "Native") - for i = #platforms, 1, -1 do - if premake.platforms[platforms[i]].iscrosscompiler then - table.remove(platforms, i) - end - end - - for _, platform in ipairs(platforms) do - for cfg in premake.eachconfig(prj, platform) do - local name = premake.esc(cfg.longname) - local compiler = iif(cfg.language == "C", "gcc", "g++") - _p(' ', name, compiler, types[cfg.kind]) - - local fname = premake.esc(cfg.buildtarget.fullpath) - local objdir = premake.esc(cfg.objectsdir) - local runcmd = cfg.buildtarget.name - local rundir = cfg.buildtarget.directory - local pause = iif(cfg.kind == "WindowedApp", "no", "yes") - _p(' ', fname, objdir, runcmd, rundir, pause) - - -- begin compiler block -- - local flags = premake.esc(table.join(premake.gcc.getcflags(cfg), premake.gcc.getcxxflags(cfg), cfg.buildoptions)) - _p(' ', table.concat(flags, ";")) - for _,v in ipairs(cfg.includedirs) do - _p(' ', premake.esc(v)) - end - for _,v in ipairs(cfg.defines) do - _p(' ', premake.esc(v)) - end - _p(' ') - -- end compiler block -- - - -- begin linker block -- - flags = premake.esc(table.join(premake.gcc.getldflags(cfg), cfg.linkoptions)) - _p(' ', table.concat(flags, ";")) - for _,v in ipairs(premake.getlinks(cfg, "all", "directory")) do - _p(' ', premake.esc(v)) - end - for _,v in ipairs(premake.getlinks(cfg, "all", "basename")) do - _p(' ', premake.esc(v)) - end - _p(' ') - -- end linker block -- - - -- begin resource compiler block -- - if premake.findfile(cfg, ".rc") then - local defines = table.implode(table.join(cfg.defines, cfg.resdefines), "-D", ";", "") - local options = table.concat(cfg.resoptions, ";") - _p(' ', defines, options) - for _,v in ipairs(table.join(cfg.includedirs, cfg.resincludedirs)) do - _p(' ', premake.esc(v)) - end - _p(' ') - else - _p(' ') - end - -- end resource compiler block -- - - -- begin build steps -- - if #cfg.prebuildcommands > 0 then - _p(' ') - for _,v in ipairs(cfg.prebuildcommands) do - _p(' %s', premake.esc(v)) - end - _p(' ') - end - if #cfg.postbuildcommands > 0 then - _p(' ') - for _,v in ipairs(cfg.postbuildcommands) do - _p(' %s', premake.esc(v)) - end - _p(' ') - end - -- end build steps -- - - _p(' ') - _p(' ') - _p(' ') - _p(' ') - _p(' ') - _p(' None') - _p(' ') - _p(' ') - _p(' ') - _p(' ') - _p(' ') - _p(' ') - _p(' ') - end - end - _p(' ') - - for _, platform in ipairs(platforms) do - for cfg in premake.eachconfig(prj, platform) do - _p(' ', cfg.longname) - for _,dep in ipairs(premake.getdependencies(prj)) do - _p(' ', dep.name) - end - _p(' ') - end - end - - _p('') - end - - - --- --- Write out entries for the files element; called from premake.walksources(). --- - - function premake.codelite_files(prj, fname, state, nestlevel) - local indent = string.rep(" ", nestlevel + 1) - - if (state == "GroupStart") then - io.write(indent .. '\n') - elseif (state == "GroupEnd") then - io.write(indent .. '\n') - else - io.write(indent .. '\n') - end - end - - - Index: ps/trunk/build/premake/premake4/src/actions/codelite/codelite_workspace.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/codelite/codelite_workspace.lua +++ ps/trunk/build/premake/premake4/src/actions/codelite/codelite_workspace.lua @@ -1,40 +0,0 @@ --- --- codelite_workspace.lua --- Generate a CodeLite workspace file. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.codelite_workspace(sln) - _p('') - _p('', premake.esc(sln.name), premake.esc(sln.name)) - - for i,prj in ipairs(sln.projects) do - local name = premake.esc(prj.name) - local fname = path.join(path.getrelative(sln.location, prj.location), prj.name) - local active = iif(i==1, "Yes", "No") - _p(' ', name, fname, active) - end - - -- build a list of supported target platforms; I don't support cross-compiling yet - local platforms = premake.filterplatforms(sln, premake[_OPTIONS.cc].platforms, "Native") - for i = #platforms, 1, -1 do - if premake.platforms[platforms[i]].iscrosscompiler then - table.remove(platforms, i) - end - end - - _p(' ') - for _, platform in ipairs(platforms) do - for _, cfgname in ipairs(sln.configurations) do - local name = premake.getconfigname(cfgname, platform) - _p(' ', name) - for _,prj in ipairs(sln.projects) do - _p(' ', prj.name, name) - end - _p(' ') - end - end - _p(' ') - _p('') - end - Index: ps/trunk/build/premake/premake4/src/actions/example/_example.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/example/_example.lua +++ ps/trunk/build/premake/premake4/src/actions/example/_example.lua @@ -1,99 +0,0 @@ --- Define a namespace for my new action. The second line defines an alias that I --- can use in this file, saving myself some typing. It will not be visible outside --- of this file (though I can always define it again). - - premake.example = { } - local example = premake.example - - --- The description of the action. Note that only the first three fields are required; --- you can remove any of the additional fields that are not required by your action. - - newaction - { - -- The trigger is what needs to be typed on the command line to cause - -- this action this run (premake4 example) - trigger = "example", - - -- The short name is used when this toolset name needs to be shown to - -- the user, such as in status or error messages - shortname = "Super Studio 3000", - - -- The description is shown in the help text (premake4 /help) - description = "An example action that prints simple text files", - - -- Some actions imply a particular operating system: Visual Studio only - -- runs on Windows, and Xcode only on Mac OS X. If this is the case, - -- uncomment this line and set it to one of "windows", "linux" or "macosx". - -- Otherwise, this action will target the current operating system. - -- os = "macosx", - - -- Which kinds of targets this action supports; remove those you don't. - valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib" }, - - -- Which programming languages this actions supports; remove those you don't. - valid_languages = { "C", "C++", "C#" }, - - -- Which compiler sets this action supports; remove those you don't. The set - -- is specified with the /cc and /dotnet command-line options. You can find - -- the tool interfaces at src/tools. - valid_tools = { - cc = { "msc", "gcc", "ow" }, - dotnet = { "mono", "msnet", "pnet" }, - }, - - - -- This function is called during state validation. If your action has some - -- special requirements you can check them here and error if necessary. - - - oncheckproject = function(prj) - -- if this_project_is_no_good(prj) then - -- error("Project " .. prj.name .. " is no good", 0) - -- end - end, - - - -- These functions will get called for each solution and project. The function - -- premake.generate() creates a file for you in the correct place, taking into - -- account any location information specified in the script. The sequence "%%" - -- will be replaced by the solution/project name. The last parameter is the - -- function that will actually do the work of generating the file contents. - - onsolution = function(sln) - premake.generate(sln, "%%.sln.txt", premake.example.solution) - end, - - onproject = function(prj) - if premake.isdotnetproject(prj) then - premake.generate(prj, "%%.csprj.txt", premake.example.project) - else - premake.generate(prj, "%%.cprj.txt", premake.example.project) - end - end, - - - -- These functions are called for each solution, project, and target as part - -- of the "clean" action. They should remove any files generated by the tools. - -- premake.clean.file() and premake.clean.directory() are convenience functions - -- that use the same pattern matching as premake.generate() above. - - oncleansolution = function(sln) - premake.clean.file(sln, "%%.sln.txt") - end, - - oncleanproject = function(prj) - if premake.isdotnetproject(prj) then - premake.clean.file(prj, "%%.csprj.txt") - else - premake.clean.file(prj, "%%.cprj.txt") - end - end, - - oncleantarget = function(trg) - -- 'trg' is the path and base name of the target being cleaned, - -- like 'bin/debug/MyApplication'. So you might do something like: - -- os.remove(trg .. ".exe") - end, - } - Index: ps/trunk/build/premake/premake4/src/actions/example/example_project.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/example/example_project.lua +++ ps/trunk/build/premake/premake4/src/actions/example/example_project.lua @@ -1,91 +0,0 @@ --- An example project generator; see _example.lua for action description - --- --- The project generation function, attached to the action in _example.lua. --- By now, premake.generate() has created the project file using the name --- provided in _example.lua, and redirected input to this new file. --- - - function premake.example.project(prj) - -- If necessary, set an explicit line ending sequence - -- io.eol = '\r\n' - - -- Let's start with a header - _p('-- Example project file version 1.0') - _p('Name: %s', prj.name) - _p('Kind: %s', prj.kind) - _p('Language: %s', prj.language) - _p('ID: {%s}', prj.uuid) - _p('') - - - -- List the build configurations, and the settings for each - for cfg in premake.eachconfig(prj) do - _p('Configuration %s:', cfg.name) - _p(1, 'Objects directory: %s', cfg.objectsdir) - - _p(1, 'Build target:') - _p(2, 'Full path: %s', cfg.buildtarget.fullpath) - _p(2, 'Directory: %s', cfg.buildtarget.directory) - _p(2, 'Name: %s', cfg.buildtarget.name) - _p(2, 'Base name: %s', cfg.buildtarget.basename) - _p(2, 'Prefix: %s', cfg.buildtarget.prefix) - _p(2, 'Suffix: %s', cfg.buildtarget.suffix) - _p('') - - _p(1, 'Compiling:') - _p(2, 'Defines: %s', table.concat(cfg.defines, ";")) - _p(2, 'Include paths: %s', table.concat(cfg.includedirs, ";")) - _p(2, 'Flags: %s', table.concat(cfg.flags, ", ")) - if not cfg.flags.NoPCH and cfg.pchheader then - _p(2, 'Precompiled header: %s (%s)', cfg.pchheader, cfg.pchsource) - end - _p(2, 'Options: %s', table.concat(cfg.buildoptions, " ")) - _p('') - - _p(1, 'Linking:') - _p(2, 'Library paths: %s', table.concat(cfg.libdirs, ";")) - _p(2, 'Options: %s', table.concat(cfg.linkoptions, " ")) - _p(2, 'Libraries: %s', table.concat(premake.getlinks(cfg, "all", "fullpath"))) - _p('') - - if #cfg.prebuildcommands > 0 then - _p(1, 'Prebuild commands:') - for _, cmd in ipairs(cfg.prebuildcommands) do - _p(2, cmd) - end - _p('') - end - - if #cfg.prelinkcommands > 0 then - _p(1, 'Prelink commands:') - for _, cmd in ipairs(cfg.prelinkcommands) do - _p(2, cmd) - end - _p('') - end - - if #cfg.postbuildcommands > 0 then - _p(1, 'Postbuild commands:') - for _, cmd in ipairs(cfg.postbuildcommands) do - _p(2, cmd) - end - _p('') - end - end - - - -- List out the folders and files that make up the build - local tr = premake.project.buildsourcetree(prj) - premake.tree.sort(tr) - premake.tree.traverse(tr, { - onbranch = function(node, depth) - _p(depth, path.getname(node.name) .. "/") - end, - - onleaf = function(node, depth) - _p(depth, path.getname(node.name)) - end - }) - - end Index: ps/trunk/build/premake/premake4/src/actions/example/example_solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/example/example_solution.lua +++ ps/trunk/build/premake/premake4/src/actions/example/example_solution.lua @@ -1,46 +0,0 @@ --- An example solution generator; see _example.lua for action description - --- --- The solution generation function, attached to the action in _example.lua. --- By now, premake.generate() has created the solution file using the name --- provided in _example.lua, and redirected input to this new file. --- - - function premake.example.solution(sln) - -- If necessary, set an explicit line ending sequence - -- io.eol = '\r\n' - - -- Let's start with a header - _p('-- Example solution file version 1.0') - _p('Name: %s', sln.name) - _p('') - - - -- List the build configurations - for _, cfgname in ipairs(sln.configurations) do - _p('Config: %s', cfgname) - end - _p('') - - - -- List the projects contained by the solution, with some info on each - for prj in premake.solution.eachproject(sln) do - _p('Project: %s', prj.name) - _p(1, 'Kind: %s', prj.kind) - _p(1, 'Language: %s', prj.language) - _p(1, 'ID: {%s}', prj.uuid) - _p(1, 'Relative path: %s', path.getrelative(sln.location, prj.location)) - - -- List dependencies, if there are any - local deps = premake.getdependencies(prj) - if #deps > 0 then - _p(1, 'Dependencies:') - for _, depprj in ipairs(deps) do - _p(2, '%s {%s}', depprj.name, depprj.uuid) - end - end - - _p('') - end - - end Index: ps/trunk/build/premake/premake4/src/actions/make/_make.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/make/_make.lua +++ ps/trunk/build/premake/premake4/src/actions/make/_make.lua @@ -1,141 +0,0 @@ --- --- _make.lua --- Define the makefile action(s). --- Copyright (c) 2002-2010 Jason Perkins and the Premake project --- - - _MAKE = { } - premake.make = { } - --- --- Escape a string so it can be written to a makefile. --- - - function _MAKE.esc(value) - local result - if (type(value) == "table") then - result = { } - for _,v in ipairs(value) do - table.insert(result, _MAKE.esc(v)) - end - return result - else - -- handle simple replacements - result = value:gsub("\\", "\\\\") - result = result:gsub(" ", "\\ ") - result = result:gsub("%(", "\\%(") - result = result:gsub("%)", "\\%)") - - -- leave $(...) shell replacement sequences alone - result = result:gsub("$\\%((.-)\\%)", "$%(%1%)") - return result - end - end - - - --- --- Rules for file ops based on the shell type. Can't use defines and $@ because --- it screws up the escaping of spaces and parethesis (anyone know a solution?) --- - - function premake.make_copyrule(source, target) - _p('%s: %s', target, source) - _p('\t@echo Copying $(notdir %s)', target) - _p('ifeq (posix,$(SHELLTYPE))') - _p('\t$(SILENT) cp -fR %s %s', source, target) - _p('else') - _p('\t$(SILENT) copy /Y $(subst /,\\\\,%s) $(subst /,\\\\,%s)', source, target) - _p('endif') - end - - function premake.make_mkdirrule(var) - _p('\t@echo Creating %s', var) - _p('ifeq (posix,$(SHELLTYPE))') - _p('\t$(SILENT) mkdir -p %s', var) - _p('else') - _p('\t$(SILENT) mkdir $(subst /,\\\\,%s)', var) - _p('endif') - _p('') - end - - - --- --- Get the makefile file name for a solution or a project. If this object is the --- only one writing to a location then I can use "Makefile". If more than one object --- writes to the same location I use name + ".make" to keep it unique. --- - - function _MAKE.getmakefilename(this, searchprjs) - -- how many projects/solutions use this location? - local count = 0 - for sln in premake.solution.each() do - if (sln.location == this.location) then count = count + 1 end - if (searchprjs) then - for _,prj in ipairs(sln.projects) do - if (prj.location == this.location) then count = count + 1 end - end - end - end - - if (count == 1) then - return "Makefile" - else - return this.name .. ".make" - end - end - - --- --- Returns a list of object names, properly escaped to be included in the makefile. --- - - function _MAKE.getnames(tbl) - local result = table.extract(tbl, "name") - for k,v in pairs(result) do - result[k] = _MAKE.esc(v) - end - return result - end - - --- --- Register the "gmake" action --- - - newaction { - trigger = "gmake", - shortname = "GNU Make", - description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++", "C#" }, - - valid_tools = { - cc = { "gcc" }, - dotnet = { "mono", "msnet", "pnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, _MAKE.getmakefilename(sln, false), premake.make_solution) - end, - - onproject = function(prj) - local makefile = _MAKE.getmakefilename(prj, true) - if premake.isdotnetproject(prj) then - premake.generate(prj, makefile, premake.make_csharp) - else - premake.generate(prj, makefile, premake.make_cpp) - end - end, - - oncleansolution = function(sln) - premake.clean.file(sln, _MAKE.getmakefilename(sln, false)) - end, - - oncleanproject = function(prj) - premake.clean.file(prj, _MAKE.getmakefilename(prj, true)) - end - } Index: ps/trunk/build/premake/premake4/src/actions/make/make_cpp.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/make/make_cpp.lua +++ ps/trunk/build/premake/premake4/src/actions/make/make_cpp.lua @@ -1,338 +0,0 @@ --- --- make_cpp.lua --- Generate a C/C++ project makefile. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - premake.make.cpp = { } - local _ = premake.make.cpp - - - function premake.make_cpp(prj) - -- create a shortcut to the compiler interface - local cc = premake.gettool(prj) - - -- build a list of supported target platforms that also includes a generic build - local platforms = premake.filterplatforms(prj.solution, cc.platforms, "Native") - - premake.gmake_cpp_header(prj, cc, platforms) - - for _, platform in ipairs(platforms) do - for cfg in premake.eachconfig(prj, platform) do - premake.gmake_cpp_config(cfg, cc) - end - end - - -- list intermediate files - _p('OBJECTS := \\') - for _, file in ipairs(prj.files) do - if path.iscppfile(file) or path.getextension(file) == ".asm" then - _p('\t$(OBJDIR)/%s.o \\', _MAKE.esc(path.getbasename(file))) - end - end - _p('') - - _p('RESOURCES := \\') - for _, file in ipairs(prj.files) do - if path.isresourcefile(file) then - _p('\t$(OBJDIR)/%s.res \\', _MAKE.esc(path.getbasename(file))) - end - end - _p('') - - -- identify the shell type - _p('SHELLTYPE := msdos') - _p('ifeq (,$(ComSpec)$(COMSPEC))') - _p(' SHELLTYPE := posix') - _p('endif') - _p('ifeq (/bin,$(findstring /bin,$(SHELL)))') - _p(' SHELLTYPE := posix') - _p('endif') - _p('') - - -- main build rule(s) - _p('.PHONY: clean prebuild prelink') - _p('') - - if os.is("MacOSX") and prj.kind == "WindowedApp" then - _p('all: $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist') - else - _p('all: $(TARGET)') - end - _p('\t@:') - _p('') - - -- target build rule - _p('$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink') - _p('\t@echo Linking %s', prj.name) - _p('\t$(SILENT) $(LINKCMD)') - _p('\t$(POSTBUILDCMDS)') - _p('') - - -- Create destination directories. Can't use $@ for this because it loses the - -- escaping, causing issues with spaces and parenthesis - _p('$(TARGETDIR):') - premake.make_mkdirrule("$(TARGETDIR)") - - _p('$(OBJDIR):') - premake.make_mkdirrule("$(OBJDIR)") - - -- Mac OS X specific targets - if os.is("MacOSX") and prj.kind == "WindowedApp" then - _p('$(dir $(TARGETDIR))PkgInfo:') - _p('$(dir $(TARGETDIR))Info.plist:') - _p('') - end - - -- clean target - _p('clean:') - _p('\t@echo Cleaning %s', prj.name) - _p('ifeq (posix,$(SHELLTYPE))') - _p('\t$(SILENT) rm -f $(TARGET)') - _p('\t$(SILENT) rm -rf $(OBJDIR)') - _p('else') - _p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGET)) del $(subst /,\\\\,$(TARGET))') - _p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))') - _p('endif') - _p('') - - -- custom build step targets - _p('prebuild: $(TARGETDIR) $(OBJDIR)') - _p('\t$(PREBUILDCMDS)') - _p('') - - _p('prelink:') - _p('\t$(PRELINKCMDS)') - _p('') - - -- precompiler header rule - _.pchrules(prj) - - -- per-file rules - for _, file in ipairs(prj.files) do - if path.iscppfile(file) then - -- Don't use PCH for Obj-C/C++ files (we could but we'd have to compile them separately - -- and there's no advantage to that yet) - local gchobj = '$(GCH)' - local pchincludes = '$(PCHINCLUDES)' - if (path.getextension(file) == ".mm" or path.getextension(file) == ".m") then - gchobj = '' - pchincludes = '' - end - - _p('$(OBJDIR)/%s.o: %s %s | prebuild', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file), gchobj) - _p('\t@echo $(notdir $<)') - if (path.iscfile(file)) then - _p('\t$(SILENT) $(CC) %s $(CFLAGS) -MF $(OBJDIR)/%s.d -MT "$@" -o "$@" -c "$<"', pchincludes, _MAKE.esc(path.getbasename(file))) - else - _p('\t$(SILENT) $(CXX) %s $(CXXFLAGS) -MF $(OBJDIR)/%s.d -MT "$@" -o "$@" -c "$<"', pchincludes, _MAKE.esc(path.getbasename(file))) - end - elseif (path.getextension(file) == ".rc") then - _p('$(OBJDIR)/%s.res: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file)) - _p('\t@echo $(notdir $<)') - _p('\t$(SILENT) windres $< -O coff -o "$@" $(RESFLAGS)') - elseif (path.getextension(file) == ".asm") then - _p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file)) - _p('\t@echo $(notdir $<)') - - local opts = '' - if os.is('windows') then - opts = '' - elseif os.is('macosx') then - opts = '-D OS_UNIX=1' - else - opts = '-D DONT_USE_UNDERLINE=1 -D OS_UNIX=1' - end - - if not (prj.solution.nasmpath) then - prj.solution.nasmpath = 'nasm' - end - - _p('\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..' -f '.. - _MAKE.esc(prj.solution.nasmformat)..' -o $@ $<\n\t') - - _p('\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'.. - ' -M -o $@ $< >$(OBJDIR)/$( 0 then - _p('\t@echo Running pre-build commands') - _p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t")) - end - _p(' endef') - - _p(' define PRELINKCMDS') - if #cfg.prelinkcommands > 0 then - _p('\t@echo Running pre-link commands') - _p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t")) - end - _p(' endef') - - _p(' define POSTBUILDCMDS') - if #cfg.postbuildcommands > 0 then - _p('\t@echo Running post-build commands') - _p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t")) - end - _p(' endef') - - _p('endif') - _p('') - end - - --- --- Precompiled header support --- - - function _.pchconfig(cfg) - if not cfg.flags.NoPCH and cfg.pchheader then - _p(' PCH = %s', _MAKE.esc(cfg.pchheader)) - _p(' GCH = $(OBJDIR)/%s.gch', _MAKE.esc(path.getname(cfg.pchheader))) - _p(' PCHINCLUDES = -I$(OBJDIR) -include $(OBJDIR)/%s', _MAKE.esc(path.getname(cfg.pchheader))) - end - end - - function _.pchrules(prj) - _p('ifneq (,$(PCH))') - _p('$(GCH): $(PCH) | $(OBJDIR)') - _p('\t@echo $(notdir $<)') - _p('\t-$(SILENT) cp $< $(OBJDIR)') - if prj.language == "C" then - _p('\t$(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<"') - else - _p('\t$(SILENT) $(CXX) $(CXXFLAGS) -x c++-header -o "$@" -c "$<"') - end - _p('endif') - _p('') - end Index: ps/trunk/build/premake/premake4/src/actions/make/make_csharp.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/make/make_csharp.lua +++ ps/trunk/build/premake/premake4/src/actions/make/make_csharp.lua @@ -1,271 +0,0 @@ --- --- make_csharp.lua --- Generate a C# project makefile. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - --- --- Given a .resx resource file, builds the path to corresponding .resource --- file, matching the behavior and naming of Visual Studio. --- - - local function getresourcefilename(cfg, fname) - if path.getextension(fname) == ".resx" then - local name = cfg.buildtarget.basename .. "." - local dir = path.getdirectory(fname) - if dir ~= "." then - name = name .. path.translate(dir, ".") .. "." - end - return "$(OBJDIR)/" .. _MAKE.esc(name .. path.getbasename(fname)) .. ".resources" - else - return fname - end - end - - - --- --- Main function --- - - function premake.make_csharp(prj) - local csc = premake.dotnet - - -- Do some processing up front: build a list of configuration-dependent libraries. - -- Libraries that are built to a location other than $(TARGETDIR) will need to - -- be copied so they can be found at runtime. - local cfglibs = { } - local cfgpairs = { } - local anycfg - for cfg in premake.eachconfig(prj) do - anycfg = cfg - cfglibs[cfg] = premake.getlinks(cfg, "siblings", "fullpath") - cfgpairs[cfg] = { } - for _, fname in ipairs(cfglibs[cfg]) do - if path.getdirectory(fname) ~= cfg.buildtarget.directory then - cfgpairs[cfg]["$(TARGETDIR)/" .. _MAKE.esc(path.getname(fname))] = _MAKE.esc(fname) - end - end - end - - -- sort the files into categories, based on their build action - local sources = {} - local embedded = { } - local copypairs = { } - - for fcfg in premake.eachfile(prj) do - local action = csc.getbuildaction(fcfg) - if action == "Compile" then - table.insert(sources, fcfg.name) - elseif action == "EmbeddedResource" then - table.insert(embedded, fcfg.name) - elseif action == "Content" then - copypairs["$(TARGETDIR)/" .. _MAKE.esc(path.getname(fcfg.name))] = _MAKE.esc(fcfg.name) - elseif path.getname(fcfg.name):lower() == "app.config" then - copypairs["$(TARGET).config"] = _MAKE.esc(fcfg.name) - end - end - - -- Any assemblies that are on the library search paths should be copied - -- to $(TARGETDIR) so they can be found at runtime - local paths = table.translate(prj.libdirs, function(v) return path.join(prj.basedir, v) end) - paths = table.join({prj.basedir}, paths) - for _, libname in ipairs(premake.getlinks(prj, "system", "fullpath")) do - local libdir = os.pathsearch(libname..".dll", unpack(paths)) - if (libdir) then - local target = "$(TARGETDIR)/" .. _MAKE.esc(path.getname(libname)) - local source = path.getrelative(prj.basedir, path.join(libdir, libname))..".dll" - copypairs[target] = _MAKE.esc(source) - end - end - - -- end of preprocessing -- - - - -- set up the environment - _p('# %s project makefile autogenerated by Premake', premake.action.current().shortname) - _p('') - - _p('ifndef config') - _p(' config=%s', _MAKE.esc(prj.configurations[1]:lower())) - _p('endif') - _p('') - - _p('ifndef verbose') - _p(' SILENT = @') - _p('endif') - _p('') - - _p('ifndef CSC') - _p(' CSC=%s', csc.getcompilervar(prj)) - _p('endif') - _p('') - - _p('ifndef RESGEN') - _p(' RESGEN=resgen') - _p('endif') - _p('') - - -- Platforms aren't support for .NET projects, but I need the ability to match - -- the buildcfg:platform identifiers with a block of settings. So enumerate the - -- pairs the same way I do for C/C++ projects, but always use the generic settings - local platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms) - table.insert(platforms, 1, "") - - -- write the configuration blocks - for cfg in premake.eachconfig(prj) do - premake.gmake_cs_config(cfg, csc, cfglibs) - end - - -- set project level values - _p('# To maintain compatibility with VS.NET, these values must be set at the project level') - _p('TARGET := $(TARGETDIR)/%s', _MAKE.esc(prj.buildtarget.name)) - _p('FLAGS += /t:%s %s', csc.getkind(prj):lower(), table.implode(_MAKE.esc(prj.libdirs), "/lib:", "", " ")) - _p('REFERENCES += %s', table.implode(_MAKE.esc(premake.getlinks(prj, "system", "basename")), "/r:", ".dll", " ")) - _p('') - - -- list source files - _p('SOURCES := \\') - for _, fname in ipairs(sources) do - _p('\t%s \\', _MAKE.esc(path.translate(fname))) - end - _p('') - - _p('EMBEDFILES := \\') - for _, fname in ipairs(embedded) do - _p('\t%s \\', getresourcefilename(prj, fname)) - end - _p('') - - _p('COPYFILES += \\') - for target, source in pairs(cfgpairs[anycfg]) do - _p('\t%s \\', target) - end - for target, source in pairs(copypairs) do - _p('\t%s \\', target) - end - _p('') - - -- identify the shell type - _p('SHELLTYPE := msdos') - _p('ifeq (,$(ComSpec)$(COMSPEC))') - _p(' SHELLTYPE := posix') - _p('endif') - _p('ifeq (/bin,$(findstring /bin,$(SHELL)))') - _p(' SHELLTYPE := posix') - _p('endif') - _p('') - - -- main build rule(s) - _p('.PHONY: clean prebuild prelink') - _p('') - - _p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)') - _p('') - - _p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)') - _p('\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))') - _p('\t$(POSTBUILDCMDS)') - _p('') - - -- Create destination directories. Can't use $@ for this because it loses the - -- escaping, causing issues with spaces and parenthesis - _p('$(TARGETDIR):') - premake.make_mkdirrule("$(TARGETDIR)") - - _p('$(OBJDIR):') - premake.make_mkdirrule("$(OBJDIR)") - - -- clean target - _p('clean:') - _p('\t@echo Cleaning %s', prj.name) - _p('ifeq (posix,$(SHELLTYPE))') - _p('\t$(SILENT) rm -f $(TARGETDIR)/%s.* $(COPYFILES)', prj.buildtarget.basename) - _p('\t$(SILENT) rm -rf $(OBJDIR)') - _p('else') - _p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGETDIR)/%s.*) del $(subst /,\\\\,$(TARGETDIR)/%s.*)', prj.buildtarget.basename, prj.buildtarget.basename) - for target, source in pairs(cfgpairs[anycfg]) do - _p('\t$(SILENT) if exist $(subst /,\\\\,%s) del $(subst /,\\\\,%s)', target, target) - end - for target, source in pairs(copypairs) do - _p('\t$(SILENT) if exist $(subst /,\\\\,%s) del $(subst /,\\\\,%s)', target, target) - end - _p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))') - _p('endif') - _p('') - - -- custom build step targets - _p('prebuild:') - _p('\t$(PREBUILDCMDS)') - _p('') - - _p('prelink:') - _p('\t$(PRELINKCMDS)') - _p('') - - -- per-file rules - _p('# Per-configuration copied file rules') - for cfg in premake.eachconfig(prj) do - _p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower())) - for target, source in pairs(cfgpairs[cfg]) do - premake.make_copyrule(source, target) - end - _p('endif') - _p('') - end - - _p('# Copied file rules') - for target, source in pairs(copypairs) do - premake.make_copyrule(source, target) - end - - _p('# Embedded file rules') - for _, fname in ipairs(embedded) do - if path.getextension(fname) == ".resx" then - _p('%s: %s', getresourcefilename(prj, fname), _MAKE.esc(fname)) - _p('\t$(SILENT) $(RESGEN) $^ $@') - end - _p('') - end - - end - - --- --- Write a block of configuration settings. --- - - function premake.gmake_cs_config(cfg, csc, cfglibs) - - _p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower())) - _p(' TARGETDIR := %s', _MAKE.esc(cfg.buildtarget.directory)) - _p(' OBJDIR := %s', _MAKE.esc(cfg.objectsdir)) - _p(' DEPENDS := %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "dependencies", "fullpath")), " ")) - _p(' REFERENCES := %s', table.implode(_MAKE.esc(cfglibs[cfg]), "/r:", "", " ")) - _p(' FLAGS += %s %s', table.implode(cfg.defines, "/d:", "", " "), table.concat(table.join(csc.getflags(cfg), cfg.buildoptions), " ")) - - _p(' define PREBUILDCMDS') - if #cfg.prebuildcommands > 0 then - _p('\t@echo Running pre-build commands') - _p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t")) - end - _p(' endef') - - _p(' define PRELINKCMDS') - if #cfg.prelinkcommands > 0 then - _p('\t@echo Running pre-link commands') - _p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t")) - end - _p(' endef') - - _p(' define POSTBUILDCMDS') - if #cfg.postbuildcommands > 0 then - _p('\t@echo Running post-build commands') - _p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t")) - end - _p(' endef') - - _p('endif') - _p('') - - end Index: ps/trunk/build/premake/premake4/src/actions/make/make_solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/make/make_solution.lua +++ ps/trunk/build/premake/premake4/src/actions/make/make_solution.lua @@ -1,74 +0,0 @@ --- --- make_solution.lua --- Generate a solution-level makefile. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - function premake.make_solution(sln) - -- create a shortcut to the compiler interface - local cc = premake[_OPTIONS.cc] - - -- build a list of supported target platforms that also includes a generic build - local platforms = premake.filterplatforms(sln, cc.platforms, "Native") - - -- write a header showing the build options - _p('# %s solution makefile autogenerated by Premake', premake.action.current().shortname) - _p('# Type "make help" for usage help') - _p('') - - -- set a default configuration - _p('ifndef config') - _p(' config=%s', _MAKE.esc(premake.getconfigname(sln.configurations[1], platforms[1], true))) - _p('endif') - _p('export config') - _p('') - - -- list the projects included in the solution - _p('PROJECTS := %s', table.concat(_MAKE.esc(table.extract(sln.projects, "name")), " ")) - _p('') - _p('.PHONY: all clean help $(PROJECTS)') - _p('') - _p('all: $(PROJECTS)') - _p('') - - -- write the project build rules - for _, prj in ipairs(sln.projects) do - _p('%s: %s', _MAKE.esc(prj.name), table.concat(_MAKE.esc(table.extract(premake.getdependencies(prj), "name")), " ")) - _p('\t@echo "==== Building %s ($(config)) ===="', prj.name) - _p('\t@${MAKE} --no-print-directory -C %s -f %s', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(_MAKE.getmakefilename(prj, true))) - _p('') - end - - -- clean rules - _p('clean:') - for _ ,prj in ipairs(sln.projects) do - _p('\t@${MAKE} --no-print-directory -C %s -f %s clean', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(_MAKE.getmakefilename(prj, true))) - end - _p('') - - -- help rule - _p('help:') - _p(1,'@echo "Usage: make [config=name] [target]"') - _p(1,'@echo ""') - _p(1,'@echo "CONFIGURATIONS:"') - - local cfgpairs = { } - for _, platform in ipairs(platforms) do - for _, cfgname in ipairs(sln.configurations) do - _p(1,'@echo " %s"', premake.getconfigname(cfgname, platform, true)) - end - end - - _p(1,'@echo ""') - _p(1,'@echo "TARGETS:"') - _p(1,'@echo " all (default)"') - _p(1,'@echo " clean"') - - for _, prj in ipairs(sln.projects) do - _p(1,'@echo " %s"', prj.name) - end - - _p(1,'@echo ""') - _p(1,'@echo "For more information, see http://industriousone.com/premake/quick-start"') - - end Index: ps/trunk/build/premake/premake4/src/actions/vstudio/_vstudio.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/_vstudio.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/_vstudio.lua @@ -1,551 +0,0 @@ --- --- _vstudio.lua --- Define the Visual Studio 200x actions. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - _VS = { } -- deprecated, will remove eventually - - premake.vstudio = { } - local vstudio = premake.vstudio - - --- --- Map Premake platform identifiers to the Visual Studio versions. Adds the Visual --- Studio specific "any" and "mixed" to make solution generation easier. --- - - premake.vstudio_platforms = { - any = "Any CPU", - mixed = "Mixed Platforms", - Native = "Win32", - x32 = "Win32", - x64 = "x64", - PS3 = "PS3", - Xbox360 = "Xbox 360", - } - - - --- --- Returns the architecture identifier for a project. --- - - function _VS.arch(prj) - if (prj.language == "C#") then - if (_ACTION < "vs2005") then - return ".NET" - else - return "Any CPU" - end - else - return "Win32" - end - end - - - --- --- Return the version-specific text for a boolean value. --- (this should probably go in vs200x_vcproj.lua) --- - - function _VS.bool(value) - if (_ACTION < "vs2005") then - return iif(value, "TRUE", "FALSE") - else - return iif(value, "true", "false") - end - end - - --- --- Process the solution's list of configurations and platforms, creates a list --- of build configuration/platform pairs in a Visual Studio compatible format. --- --- @param sln --- The solution containing the configuration and platform lists. --- @param with_pseudo --- If true, Visual Studio's "Any CPU" and "Mixed Platforms" platforms will --- be added for .NET and mixed mode solutions. --- - --- --- Process the solution's list of configurations and platforms, creates a list --- of build configuration/platform pairs in a Visual Studio compatible format. --- --- @param sln --- The solution containing the configuration and platform lists. --- - - function premake.vstudio_buildconfigs(sln) - local cfgs = { } - - local platforms = premake.filterplatforms(sln, premake.vstudio_platforms, "Native") - - -- .NET projects add "Any CPU", mixed mode solutions add "Mixed Platforms" - local hascpp = premake.hascppproject(sln) - local hasdotnet = premake.hasdotnetproject(sln) - if hasdotnet then - table.insert(platforms, 1, "any") - end - if hasdotnet and hascpp then - table.insert(platforms, 2, "mixed") - end - - for _, buildcfg in ipairs(sln.configurations) do - for _, platform in ipairs(platforms) do - local entry = { } - entry.src_buildcfg = buildcfg - entry.src_platform = platform - - -- PS3 is funky and needs special handling; it's more of a build - -- configuration than a platform from Visual Studio's point of view - if platform ~= "PS3" then - entry.buildcfg = buildcfg - entry.platform = premake.vstudio_platforms[platform] - else - entry.buildcfg = platform .. " " .. buildcfg - entry.platform = "Win32" - end - - -- create a name the way VS likes it - entry.name = entry.buildcfg .. "|" .. entry.platform - - -- flag the "fake" platforms added for .NET - entry.isreal = (platform ~= "any" and platform ~= "mixed") - - table.insert(cfgs, entry) - end - end - - return cfgs - end - - - --- --- Return a configuration type index. --- (this should probably go in vs200x_vcproj.lua) --- - - function _VS.cfgtype(cfg) - if (cfg.kind == "SharedLib") then - return 2 - elseif (cfg.kind == "StaticLib") then - return 4 - else - return 1 - end - end - - - --- --- Clean Visual Studio files --- - - function premake.vstudio.cleansolution(sln) - premake.clean.file(sln, "%%.sln") - premake.clean.file(sln, "%%.suo") - premake.clean.file(sln, "%%.ncb") - -- MonoDevelop files - premake.clean.file(sln, "%%.userprefs") - premake.clean.file(sln, "%%.usertasks") - end - - function premake.vstudio.cleanproject(prj) - local fname = premake.project.getfilename(prj, "%%") - - os.remove(fname .. ".vcproj") - os.remove(fname .. ".vcproj.user") - - os.remove(fname .. ".vcxproj") - os.remove(fname .. ".vcxproj.user") - os.remove(fname .. ".vcxproj.filters") - - os.remove(fname .. ".csproj") - os.remove(fname .. ".csproj.user") - - os.remove(fname .. ".pidb") - os.remove(fname .. ".sdf") - end - - function premake.vstudio.cleantarget(name) - os.remove(name .. ".pdb") - os.remove(name .. ".idb") - os.remove(name .. ".ilk") - os.remove(name .. ".vshost.exe") - os.remove(name .. ".exe.manifest") - end - - - --- --- Write out entries for the files element; called from premake.walksources(). --- (this should probably go in vs200x_vcproj.lua) --- - - local function output(indent, value) - -- io.write(indent .. value .. "\r\n") - _p(indent .. value) - end - - local function attrib(indent, name, value) - -- io.write(indent .. "\t" .. name .. '="' .. value .. '"\r\n') - _p(indent .. "\t" .. name .. '="' .. value .. '"') - end - - function _VS.files(prj, fname, state, nestlevel) - local indent = string.rep("\t", nestlevel + 2) - - if (state == "GroupStart") then - output(indent, "") - - elseif (state == "GroupEnd") then - output(indent, "") - - else - output(indent, "") - if (not prj.flags.NoPCH and prj.pchsource == fname) then - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - if cfginfo.isreal then - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - output(indent, "\t") - output(indent, "\t\t") - output(indent, "\t") - end - end - end - - if (path.getextension(fname) == ".asm") then - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - if cfginfo.isreal then - - -- set defaults if required parameters are not set - if not (prj.solution.nasmformat) then - prj.solution.nasmformat = 'win32' - end - if not (prj.solution.nasmpath) then - prj.solution.nasmpath = 'nasm' - end - - local nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath), "\\") - local command = nasmpath.." -i "..path.translate(path.getdirectory(fname), "\\").."\\ -f "..prj.solution.nasmformat.. - " "$(InputPath)" -o "$(IntDir)\\$(InputName).obj"" - - output(indent, "\t") - output(indent, "\t\t") - output(indent, "\t") - end - end - end - - output(indent, "") - end - end - - - --- --- Return the optimization code. --- (this should probably go in vs200x_vcproj.lua) --- - - function _VS.optimization(cfg) - local result = 0 - for _, value in ipairs(cfg.flags) do - if (value == "Optimize") then - result = 3 - elseif (value == "OptimizeSize") then - result = 1 - elseif (value == "OptimizeSpeed") then - result = 2 - end - end - return result - end - - - --- --- Assemble the project file name. --- - - function _VS.projectfile(prj) - local extension - if (prj.language == "C#") then - extension = ".csproj" - elseif (_ACTION == "vs2010" or _ACTION == "vs2012" or _ACTION == "vs2013") then - extension = ".vcxproj" - else - extension = ".vcproj" - end - - local fname = path.join(prj.location, prj.name) - return fname..extension - end - - --- --- Returns the Visual Studio tool ID for a given project type. --- - - function _VS.tool(prj) - if (prj.language == "C#") then - return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" - else - return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" - end - end - - --- --- Register the Visual Studio command line actions --- - - newaction { - trigger = "vs2002", - shortname = "Visual Studio 2002", - description = "Generate Microsoft Visual Studio 2002 project files", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++", "C#" }, - - valid_tools = { - cc = { "msc" }, - dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs2002_solution) - end, - - onproject = function(prj) - if premake.isdotnetproject(prj) then - premake.generate(prj, "%%.csproj", premake.vs2002_csproj) - premake.generate(prj, "%%.csproj.user", premake.vs2002_csproj_user) - else - premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj) - end - end, - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } - - newaction { - trigger = "vs2003", - shortname = "Visual Studio 2003", - description = "Generate Microsoft Visual Studio 2003 project files", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++", "C#" }, - - valid_tools = { - cc = { "msc" }, - dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs2003_solution) - end, - - onproject = function(prj) - if premake.isdotnetproject(prj) then - premake.generate(prj, "%%.csproj", premake.vs2002_csproj) - premake.generate(prj, "%%.csproj.user", premake.vs2002_csproj_user) - else - premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj) - end - end, - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } - - newaction { - trigger = "vs2005", - shortname = "Visual Studio 2005", - description = "Generate Microsoft Visual Studio 2005 project files", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++", "C#" }, - - valid_tools = { - cc = { "msc" }, - dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs2005_solution) - end, - - onproject = function(prj) - if premake.isdotnetproject(prj) then - premake.generate(prj, "%%.csproj", premake.vs2005_csproj) - premake.generate(prj, "%%.csproj.user", premake.vs2005_csproj_user) - else - premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj) - end - end, - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } - - newaction { - trigger = "vs2008", - shortname = "Visual Studio 2008", - description = "Generate Microsoft Visual Studio 2008 project files", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C", "C++", "C#" }, - - valid_tools = { - cc = { "msc" }, - dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs2005_solution) - end, - - onproject = function(prj) - if premake.isdotnetproject(prj) then - premake.generate(prj, "%%.csproj", premake.vs2005_csproj) - premake.generate(prj, "%%.csproj.user", premake.vs2005_csproj_user) - else - premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj) - end - end, - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } - - - newaction - { - trigger = "vs2010", - shortname = "Visual Studio 2010", - description = "Generate Visual Studio 2010 project files (experimental)", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C++","C"}, - - valid_tools = { - cc = { "msc" }, - --dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs_generic_solution) - end, - - onproject = function(prj) - premake.generate(prj, "%%.vcxproj", premake.vs2010_vcxproj) - premake.generate(prj, "%%.vcxproj.user", premake.vs2010_vcxproj_user) - premake.generate(prj, "%%.vcxproj.filters", premake.vs2010_vcxproj_filters) - end, - - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } - - newaction - { - trigger = "vs2012", - shortname = "Visual Studio 2012", - description = "Generate Visual Studio 2012 project files (experimental)", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C++","C"}, - - valid_tools = { - cc = { "msc" }, - --dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs_generic_solution) - end, - - onproject = function(prj) - premake.generate(prj, "%%.vcxproj", premake.vs2010_vcxproj) - premake.generate(prj, "%%.vcxproj.user", premake.vs2010_vcxproj_user) - premake.generate(prj, "%%.vcxproj.filters", premake.vs2010_vcxproj_filters) - end, - - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } - - newaction - { - trigger = "vs2013", - shortname = "Visual Studio 2013", - description = "Generate Visual Studio 2013 project files (experimental)", - os = "windows", - - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, - - valid_languages = { "C++","C"}, - - valid_tools = { - cc = { "msc" }, - --dotnet = { "msnet" }, - }, - - onsolution = function(sln) - premake.generate(sln, "%%.sln", premake.vs_generic_solution) - end, - - onproject = function(prj) - premake.generate(prj, "%%.vcxproj", premake.vs2010_vcxproj) - premake.generate(prj, "%%.vcxproj.user", premake.vs2010_vcxproj_user) - premake.generate(prj, "%%.vcxproj.filters", premake.vs2010_vcxproj_filters) - end, - - - oncleansolution = premake.vstudio.cleansolution, - oncleanproject = premake.vstudio.cleanproject, - oncleantarget = premake.vstudio.cleantarget - } Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_csproj.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_csproj.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_csproj.lua @@ -1,143 +0,0 @@ --- --- vs2002_csproj.lua --- Generate a Visual Studio 2002/2003 C# project. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - -- - -- Figure out what elements a particular file need in its item block, - -- based on its build action and any related files in the project. - -- - local function getelements(prj, action, fname) - - if action == "Compile" and fname:endswith(".cs") then - return "SubTypeCode" - end - - if action == "EmbeddedResource" and fname:endswith(".resx") then - -- is there a matching *.cs file? - local basename = fname:sub(1, -6) - local testname = path.getname(basename .. ".cs") - if premake.findfile(prj, testname) then - return "Dependency", testname - end - end - - return "None" - end - - - - function premake.vs2002_csproj(prj) - io.eol = "\r\n" - _p('') - - _p(1,'') - - _p(2,'') - - -- Write out project-wide settings - _p(3,'') - - -- Write out configuration blocks - for cfg in premake.eachconfig(prj) do - _p(4,'') - end - _p(3,'') - - -- List assembly references - _p(3,'') - for _, ref in ipairs(premake.getlinks(prj, "siblings", "object")) do - _p(4,'') - end - for _, linkname in ipairs(premake.getlinks(prj, "system", "fullpath")) do - _p(4,'') - end - _p(3,'') - - _p(2,'') - - -- List source files - _p(2,'') - _p(3,'') - for fcfg in premake.eachfile(prj) do - local action = premake.dotnet.getbuildaction(fcfg) - local fname = path.translate(premake.esc(fcfg.name), "\\") - local elements, dependency = getelements(prj, action, fcfg.name) - - _p(4,'') - end - _p(3,'') - _p(2,'') - - _p(1,'') - _p('') - - end Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_csproj_user.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_csproj_user.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_csproj_user.lua @@ -1,50 +0,0 @@ --- --- vs2002_csproj_user.lua --- Generate a Visual Studio 2002/2003 C# .user file. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.vs2002_csproj_user(prj) - io.eol = "\r\n" - - _p('') - _p(1,'') - _p(2,'') - - -- Visual Studio wants absolute paths - local refpaths = table.translate(prj.libdirs, function(v) return path.getabsolute(prj.location .. "/" .. v) end) - _p(3,'', path.translate(table.concat(refpaths, ";"), "\\")) - - for cfg in premake.eachconfig(prj) do - _p(4,'') - end - - _p(3,'') - _p(2,'') - _p(2,'') - - _p(1,'') - _p('') - - end Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_solution.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2002_solution.lua @@ -1,47 +0,0 @@ --- --- vs2002_solution.lua --- Generate a Visual Studio 2002 solution. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.vs2002_solution(sln) - io.eol = '\r\n' - - -- Precompute Visual Studio configurations - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - - _p('Microsoft Visual Studio Solution File, Format Version 7.00') - - -- Write out the list of project entries - for prj in premake.solution.eachproject(sln) do - local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj))) - _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) - _p('EndProject') - end - - _p('Global') - _p(1,'GlobalSection(SolutionConfiguration) = preSolution') - for i, cfgname in ipairs(sln.configurations) do - _p(2,'ConfigName.%d = %s', i - 1, cfgname) - end - _p(1,'EndGlobalSection') - - _p(1,'GlobalSection(ProjectDependencies) = postSolution') - _p(1,'EndGlobalSection') - - _p(1,'GlobalSection(ProjectConfiguration) = postSolution') - for prj in premake.solution.eachproject(sln) do - for _, cfgname in ipairs(sln.configurations) do - _p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) - _p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) - end - end - _p(1,'EndGlobalSection') - _p(1,'GlobalSection(ExtensibilityGlobals) = postSolution') - _p(1,'EndGlobalSection') - _p(1,'GlobalSection(ExtensibilityAddIns) = postSolution') - _p(1,'EndGlobalSection') - - _p('EndGlobal') - end - \ No newline at end of file Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2003_solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2003_solution.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2003_solution.lua @@ -1,57 +0,0 @@ --- --- vs2003_solution.lua --- Generate a Visual Studio 2003 solution. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.vs2003_solution(sln) - io.eol = '\r\n' - - -- Precompute Visual Studio configurations - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - - _p('Microsoft Visual Studio Solution File, Format Version 8.00') - - -- Write out the list of project entries - for prj in premake.solution.eachproject(sln) do - local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj))) - _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) - - local deps = premake.getdependencies(prj) - if #deps > 0 then - _p('\tProjectSection(ProjectDependencies) = postProject') - for _, dep in ipairs(deps) do - _p('\t\t{%s} = {%s}', dep.uuid, dep.uuid) - end - _p('\tEndProjectSection') - end - - _p('EndProject') - end - - _p('Global') - _p('\tGlobalSection(SolutionConfiguration) = preSolution') - for _, cfgname in ipairs(sln.configurations) do - _p('\t\t%s = %s', cfgname, cfgname) - end - _p('\tEndGlobalSection') - - _p('\tGlobalSection(ProjectDependencies) = postSolution') - _p('\tEndGlobalSection') - - _p('\tGlobalSection(ProjectConfiguration) = postSolution') - for prj in premake.solution.eachproject(sln) do - for _, cfgname in ipairs(sln.configurations) do - _p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) - _p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) - end - end - _p('\tEndGlobalSection') - - _p('\tGlobalSection(ExtensibilityGlobals) = postSolution') - _p('\tEndGlobalSection') - _p('\tGlobalSection(ExtensibilityAddIns) = postSolution') - _p('\tEndGlobalSection') - - _p('EndGlobal') - end Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_csproj.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_csproj.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_csproj.lua @@ -1,208 +0,0 @@ --- --- vs2005_csproj.lua --- Generate a Visual Studio 2005/2008 C# project. --- Copyright (c) 2009-2010 Jason Perkins and the Premake project --- - --- --- Set up namespaces --- - - premake.vstudio.cs2005 = { } - local vstudio = premake.vstudio - local cs2005 = premake.vstudio.cs2005 - - --- --- Figure out what elements a particular source code file need in its item --- block, based on its build action and any related files in the project. --- - - local function getelements(prj, action, fname) - - if action == "Compile" and fname:endswith(".cs") then - if fname:endswith(".Designer.cs") then - -- is there a matching *.cs file? - local basename = fname:sub(1, -13) - local testname = basename .. ".cs" - if premake.findfile(prj, testname) then - return "Dependency", testname - end - -- is there a matching *.resx file? - testname = basename .. ".resx" - if premake.findfile(prj, testname) then - return "AutoGen", testname - end - else - -- is there a *.Designer.cs file? - local basename = fname:sub(1, -4) - local testname = basename .. ".Designer.cs" - if premake.findfile(prj, testname) then - return "SubTypeForm" - end - end - end - - if action == "EmbeddedResource" and fname:endswith(".resx") then - -- is there a matching *.cs file? - local basename = fname:sub(1, -6) - local testname = path.getname(basename .. ".cs") - if premake.findfile(prj, testname) then - if premake.findfile(prj, basename .. ".Designer.cs") then - return "DesignerType", testname - else - return "Dependency", testname - end - else - -- is there a matching *.Designer.cs? - testname = path.getname(basename .. ".Designer.cs") - if premake.findfile(prj, testname) then - return "AutoGenerated" - end - end - end - - if action == "Content" then - return "CopyNewest" - end - - return "None" - end - - --- --- Write the opening element and project level block. --- - - function cs2005.projectelement(prj) - _p('', iif(_ACTION == 'vs2005', '', ' ToolsVersion="3.5"')) - end - - function cs2005.projectsettings(prj) - _p(' ') - _p(' %s', premake.esc(prj.solution.configurations[1])) - _p(' AnyCPU') - _p(' %s', iif(_ACTION == "vs2005", "8.0.50727", "9.0.21022")) - _p(' 2.0') - _p(' {%s}', prj.uuid) - _p(' %s', premake.dotnet.getkind(prj)) - _p(' Properties') - _p(' %s', prj.buildtarget.basename) - _p(' %s', prj.buildtarget.basename) - if prj.framework then - _p(' v%s', prj.framework) - end - _p(' ') - end - - --- --- The main function: write the project file. --- - - function premake.vs2005_csproj(prj) - io.eol = "\r\n" - - local vsversion, toolversion - if _ACTION == "vs2005" then - vsversion = "8.0.50727" - toolversion = nil - elseif _ACTION == "vs2008" then - vsversion = "9.0.21022" - toolversion = "3.5" - end - - if toolversion then - _p('', toolversion) - else - _p('') - end - - _p(' ') - _p(' %s', premake.esc(prj.solution.configurations[1])) - _p(' AnyCPU') - _p(' %s', vsversion) - _p(' 2.0') - _p(' {%s}', prj.uuid) - _p(' %s', premake.dotnet.getkind(prj)) - _p(' Properties') - _p(' %s', prj.buildtarget.basename) - _p(' %s', prj.buildtarget.basename) - _p(' ') - - for cfg in premake.eachconfig(prj) do - _p(' ', premake.esc(cfg.name)) - if cfg.flags.Symbols then - _p(' true') - _p(' full') - else - _p(' pdbonly') - end - _p(' %s', iif(cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed, "true", "false")) - _p(' %s', cfg.buildtarget.directory) - _p(' %s', table.concat(premake.esc(cfg.defines), ";")) - _p(' prompt') - _p(' 4') - if cfg.flags.Unsafe then - _p(' true') - end - if cfg.flags.FatalWarnings then - _p(' true') - end - _p(' ') - end - - _p(' ') - for _, ref in ipairs(premake.getlinks(prj, "siblings", "object")) do - _p(' ', path.translate(path.getrelative(prj.location, _VS.projectfile(ref)), "\\")) - _p(' {%s}', ref.uuid) - _p(' %s', premake.esc(ref.name)) - _p(' ') - end - for _, linkname in ipairs(premake.getlinks(prj, "system", "basename")) do - _p(' ', premake.esc(linkname)) - end - _p(' ') - - _p(' ') - for fcfg in premake.eachfile(prj) do - local action = premake.dotnet.getbuildaction(fcfg) - local fname = path.translate(premake.esc(fcfg.name), "\\") - local elements, dependency = getelements(prj, action, fcfg.name) - if elements == "None" then - _p(' <%s Include="%s" />', action, fname) - else - _p(' <%s Include="%s">', action, fname) - if elements == "AutoGen" then - _p(' True') - elseif elements == "AutoGenerated" then - _p(' Designer') - _p(' ResXFileCodeGenerator') - _p(' %s.Designer.cs', premake.esc(path.getbasename(fcfg.name))) - elseif elements == "SubTypeDesigner" then - _p(' Designer') - elseif elements == "SubTypeForm" then - _p(' Form') - elseif elements == "PreserveNewest" then - _p(' PreserveNewest') - end - if dependency then - _p(' %s', path.translate(premake.esc(dependency), "\\")) - end - _p(' ', action) - end - end - _p(' ') - - _p(' ') - _p(' ') - _p('') - - end - Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_csproj_user.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_csproj_user.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_csproj_user.lua @@ -1,18 +0,0 @@ --- --- vs2005_csproj_user.lua --- Generate a Visual Studio 2005/2008 C# .user file. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - function premake.vs2005_csproj_user(prj) - io.eol = "\r\n" - - _p('') - _p(' ') - - local refpaths = table.translate(prj.libdirs, function(v) return path.getabsolute(prj.location .. "/" .. v) end) - _p(' %s', path.translate(table.concat(refpaths, ";"), "\\")) - _p(' ') - _p('') - - end Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_solution.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2005_solution.lua @@ -1,105 +0,0 @@ --- --- vs2005_solution.lua --- Generate a Visual Studio 2005 or 2008 solution. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - - function premake.vs2005_solution(sln) - io.eol = '\r\n' - - -- Precompute Visual Studio configurations - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - - -- Mark the file as Unicode - _p('\239\187\191') - - -- Write the solution file version header - _p('Microsoft Visual Studio Solution File, Format Version %s', iif(_ACTION == 'vs2005', '9.00', '10.00')) - _p('# Visual Studio %s', iif(_ACTION == 'vs2005', '2005', '2008')) - - -- Write out the list of project entries - for prj in premake.solution.eachproject(sln) do - -- Build a relative path from the solution file to the project file - local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), "\\") - - _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) - local deps = premake.getdependencies(prj) - if #deps > 0 then - _p('\tProjectSection(ProjectDependencies) = postProject') - for _, dep in ipairs(deps) do - _p('\t\t{%s} = {%s}', dep.uuid, dep.uuid) - end - _p('\tEndProjectSection') - end - _p('EndProject') - end - - _p('Global') - premake.vs2005_solution_platforms(sln) - premake.vs2005_solution_project_platforms(sln) - premake.vs2005_solution_properties(sln) - _p('EndGlobal') - end - - - --- --- Write out the contents of the SolutionConfigurationPlatforms section, which --- lists all of the configuration/platform pairs that exist in the solution. --- - - function premake.vs2005_solution_platforms(sln) - _p('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution') - for _, cfg in ipairs(sln.vstudio_configs) do - _p('\t\t%s = %s', cfg.name, cfg.name) - end - _p('\tEndGlobalSection') - end - - - --- --- Write out the contents of the ProjectConfigurationPlatforms section, which maps --- the configuration/platform pairs into each project of the solution. --- - - function premake.vs2005_solution_project_platforms(sln) - _p('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution') - for prj in premake.solution.eachproject(sln) do - for _, cfg in ipairs(sln.vstudio_configs) do - - -- .NET projects always map to the "Any CPU" platform (for now, at - -- least). For C++, "Any CPU" and "Mixed Platforms" map to the first - -- C++ compatible target platform in the solution list. - local mapped - if premake.isdotnetproject(prj) then - mapped = "Any CPU" - else - if cfg.platform == "Any CPU" or cfg.platform == "Mixed Platforms" then - mapped = sln.vstudio_configs[3].platform - else - mapped = cfg.platform - end - end - - _p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfg.name, cfg.buildcfg, mapped) - if mapped == cfg.platform or cfg.platform == "Mixed Platforms" then - _p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfg.name, cfg.buildcfg, mapped) - end - end - end - _p('\tEndGlobalSection') - end - - - --- --- Write out contents of the SolutionProperties section; currently unused. --- - - function premake.vs2005_solution_properties(sln) - _p('\tGlobalSection(SolutionProperties) = preSolution') - _p('\t\tHideSolutionNode = FALSE') - _p('\tEndGlobalSection') - end Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs200x_vcproj.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs200x_vcproj.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs200x_vcproj.lua @@ -1,654 +0,0 @@ --- --- vs200x_vcproj.lua --- Generate a Visual Studio 2002-2008 C/C++ project. --- Copyright (c) 2009, 2010 Jason Perkins and the Premake project --- - -premake.vstudio.vcproj = { } -local vcproj = premake.vstudio.vcproj - - --- --- Write out the element. --- - - function vcproj.Configuration(name, cfg) - _p(2,'') - end - - --- --- Write out the element; ensures that each target platform --- is listed only once. Skips over .NET's pseudo-platforms (like "Any CPU"). --- - - function premake.vs200x_vcproj_platforms(prj) - local used = { } - _p(1,'') - for _, cfg in ipairs(prj.solution.vstudio_configs) do - if cfg.isreal and not table.contains(used, cfg.platform) then - table.insert(used, cfg.platform) - _p(2,'') - end - end - _p(1,'') - end - - --- --- Return the debugging symbols level for a configuration. --- - - function premake.vs200x_vcproj_symbols(cfg) - if (not cfg.flags.Symbols) then - return 0 - else - -- Edit-and-continue does't work for some configurations - if cfg.flags.NoEditAndContinue or - _VS.optimization(cfg) ~= 0 or - cfg.flags.Managed or - cfg.platform == "x64" then - return 3 - else - return 4 - end - end - end - - --- --- Compiler block for Windows and XBox360 platforms. --- - - function premake.vs200x_vcproj_VCCLCompilerTool(cfg) - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', table.concat(premake.esc(cfg.buildoptions), " ")) - end - - _p(4,'Optimization="%s"', _VS.optimization(cfg)) - - if cfg.flags.NoFramePointer then - _p(4,'OmitFramePointers="%s"', _VS.bool(true)) - end - - if #cfg.includedirs > 0 then - _p(4,'AdditionalIncludeDirectories="%s"', premake.esc(path.translate(table.concat(cfg.includedirs, ";"), '\\'))) - end - - if #cfg.defines > 0 then - _p(4,'PreprocessorDefinitions="%s"', premake.esc(table.concat(cfg.defines, ";"))) - end - - if premake.config.isdebugbuild(cfg) and not cfg.flags.NoMinimalRebuild and not cfg.flags.Managed then - _p(4,'MinimalRebuild="%s"', _VS.bool(true)) - end - - if cfg.flags.NoExceptions then - _p(4,'ExceptionHandling="%s"', iif(_ACTION < "vs2005", "FALSE", 0)) - elseif cfg.flags.SEH and _ACTION > "vs2003" then - _p(4,'ExceptionHandling="2"') - end - - if _VS.optimization(cfg) == 0 and not cfg.flags.Managed then - _p(4,'BasicRuntimeChecks="3"') - end - if _VS.optimization(cfg) ~= 0 then - _p(4,'StringPooling="%s"', _VS.bool(true)) - end - - local runtime - if premake.config.isdebugbuild(cfg) then - runtime = iif(cfg.flags.StaticRuntime, 1, 3) - else - runtime = iif(cfg.flags.StaticRuntime, 0, 2) - end - --- if cfg.flags.StaticRuntime then --- runtime = iif(cfg.flags.Symbols, 1, 0) --- else --- runtime = iif(cfg.flags.Symbols, 3, 2) --- end - _p(4,'RuntimeLibrary="%s"', runtime) - - _p(4,'EnableFunctionLevelLinking="%s"', _VS.bool(true)) - - if _ACTION > "vs2003" and cfg.platform ~= "Xbox360" and cfg.platform ~= "x64" then - if cfg.flags.EnableSSE then - _p(4,'EnableEnhancedInstructionSet="1"') - elseif cfg.flags.EnableSSE2 then - _p(4,'EnableEnhancedInstructionSet="2"') - end - end - - if _ACTION < "vs2005" then - if cfg.flags.FloatFast then - _p(4,'ImproveFloatingPointConsistency="%s"', _VS.bool(false)) - elseif cfg.flags.FloatStrict then - _p(4,'ImproveFloatingPointConsistency="%s"', _VS.bool(true)) - end - else - if cfg.flags.FloatFast then - _p(4,'FloatingPointModel="2"') - elseif cfg.flags.FloatStrict then - _p(4,'FloatingPointModel="1"') - end - end - - if _ACTION < "vs2005" and not cfg.flags.NoRTTI then - _p(4,'RuntimeTypeInfo="%s"', _VS.bool(true)) - elseif _ACTION > "vs2003" and cfg.flags.NoRTTI then - _p(4,'RuntimeTypeInfo="%s"', _VS.bool(false)) - end - - if cfg.flags.NativeWChar then - _p(4,'TreatWChar_tAsBuiltInType="%s"', _VS.bool(true)) - elseif cfg.flags.NoNativeWChar then - _p(4,'TreatWChar_tAsBuiltInType="%s"', _VS.bool(false)) - end - - if not cfg.flags.NoPCH and cfg.pchheader then - _p(4,'UsePrecompiledHeader="%s"', iif(_ACTION < "vs2005", 3, 2)) - _p(4,'PrecompiledHeaderThrough="%s"', path.getname(cfg.pchheader)) - else - _p(4,'UsePrecompiledHeader="%s"', iif(_ACTION > "vs2003" or cfg.flags.NoPCH, 0, 2)) - end - - _p(4,'WarningLevel="%s"', iif(cfg.flags.ExtraWarnings, 4, 3)) - - if cfg.flags.FatalWarnings then - _p(4,'WarnAsError="%s"', _VS.bool(true)) - end - - if _ACTION < "vs2008" and not cfg.flags.Managed then - _p(4,'Detect64BitPortabilityProblems="%s"', _VS.bool(not cfg.flags.No64BitChecks)) - end - - _p(4,'ProgramDataBaseFileName="$(OutDir)\\%s.pdb"', path.getbasename(cfg.buildtarget.name)) - _p(4,'DebugInformationFormat="%s"', premake.vs200x_vcproj_symbols(cfg)) - if cfg.language == "C" then - _p(4, 'CompileAs="1"') - end - _p(3,'/>') - end - - - --- --- Linker block for Windows and Xbox 360 platforms. --- - - function premake.vs200x_vcproj_VCLinkerTool(cfg) - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', table.concat(premake.esc(cfg.linkoptions), " ")) - end - - if #cfg.links > 0 then - _p(4,'AdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " ")) - end - - _p(4,'OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name) - _p(4,'LinkIncremental="%s"', iif(_VS.optimization(cfg) == 0, 2, 1)) - _p(4,'AdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs, '\\')) , ";")) - - local deffile = premake.findfile(cfg, ".def") - if deffile then - _p(4,'ModuleDefinitionFile="%s"', deffile) - end - - if cfg.flags.NoManifest then - _p(4,'GenerateManifest="%s"', _VS.bool(false)) - end - - _p(4,'GenerateDebugInformation="%s"', _VS.bool(premake.vs200x_vcproj_symbols(cfg) ~= 0)) - - if premake.vs200x_vcproj_symbols(cfg) ~= 0 then - _p(4,'ProgramDataBaseFileName="$(OutDir)\\%s.pdb"', path.getbasename(cfg.buildtarget.name)) - end - - _p(4,'SubSystem="%s"', iif(cfg.kind == "ConsoleApp", 1, 2)) - - if _VS.optimization(cfg) ~= 0 then - _p(4,'OptimizeReferences="2"') - _p(4,'EnableCOMDATFolding="2"') - end - - if (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") and not cfg.flags.WinMain then - _p(4,'EntryPointSymbol="mainCRTStartup"') - end - - if cfg.kind == "SharedLib" then - local implibname = cfg.linktarget.fullpath - _p(4,'ImportLibrary="%s"', iif(cfg.flags.NoImportLib, cfg.objectsdir .. "\\" .. path.getname(implibname), implibname)) - end - - _p(4,'TargetMachine="%d"', iif(cfg.platform == "x64", 17, 1)) - - else - _p(4,'Name="VCLibrarianTool"') - - if #cfg.links > 0 then - _p(4,'AdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " ")) - end - - _p(4,'OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name) - - if #cfg.libdirs > 0 then - _p(4,'AdditionalLibraryDirectories="%s"', premake.esc(path.translate(table.concat(cfg.libdirs , ";")))) - end - - if #cfg.linkoptions > 0 then - _p(4,'AdditionalOptions="%s"', table.concat(premake.esc(cfg.linkoptions), " ")) - end - end - - _p(3,'/>') - end - - --- --- Compiler and linker blocks for the PS3 platform, which uses GCC. --- - - function premake.vs200x_vcproj_VCCLCompilerTool_GCC(cfg) - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', premake.esc(table.concat(buildoptions, " "))) - end - - if #cfg.includedirs > 0 then - _p(4,'AdditionalIncludeDirectories="%s"', premake.esc(path.translate(table.concat(cfg.includedirs, ";"), '\\'))) - end - - if #cfg.defines > 0 then - _p(4,'PreprocessorDefinitions="%s"', table.concat(premake.esc(cfg.defines), ";")) - end - - _p(4,'ProgramDataBaseFileName="$(OutDir)\\%s.pdb"', path.getbasename(cfg.buildtarget.name)) - _p(4,'DebugInformationFormat="0"') - _p(4,'CompileAs="0"') - _p(3,'/>') - end - - function premake.vs200x_vcproj_VCLinkerTool_GCC(cfg) - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', premake.esc(table.concat(buildoptions, " "))) - end - - if #cfg.links > 0 then - _p(4,'AdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " ")) - end - - _p(4,'OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name) - _p(4,'LinkIncremental="0"') - _p(4,'AdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs, '\\')) , ";")) - _p(4,'GenerateManifest="%s"', _VS.bool(false)) - _p(4,'ProgramDatabaseFile=""') - _p(4,'RandomizedBaseAddress="1"') - _p(4,'DataExecutionPrevention="0"') - else - _p(4,'Name="VCLibrarianTool"') - - local buildoptions = table.join(premake.gcc.getldflags(cfg), cfg.linkoptions) - if #buildoptions > 0 then - _p(4,'AdditionalOptions="%s"', premake.esc(table.concat(buildoptions, " "))) - end - - if #cfg.links > 0 then - _p(4,'AdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " ")) - end - - _p(4,'OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name) - - if #cfg.libdirs > 0 then - _p(4,'AdditionalLibraryDirectories="%s"', premake.esc(path.translate(table.concat(cfg.libdirs , ";")))) - end - end - - _p(3,'/>') - end - - - --- --- Resource compiler block. --- - - function premake.vs200x_vcproj_VCResourceCompilerTool(cfg) - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', table.concat(premake.esc(cfg.resoptions), " ")) - end - - if #cfg.defines > 0 or #cfg.resdefines > 0 then - _p(4,'PreprocessorDefinitions="%s"', table.concat(premake.esc(table.join(cfg.defines, cfg.resdefines)), ";")) - end - - if #cfg.includedirs > 0 or #cfg.resincludedirs > 0 then - local dirs = table.join(cfg.includedirs, cfg.resincludedirs) - _p(4,'AdditionalIncludeDirectories="%s"', premake.esc(path.translate(table.concat(dirs, ";"), '\\'))) - end - - _p(3,'/>') - end - - - --- --- Manifest block. --- - - function premake.vs200x_vcproj_VCManifestTool(cfg) - -- locate all manifest files - local manifests = { } - for _, fname in ipairs(cfg.files) do - if path.getextension(fname) == ".manifest" then - table.insert(manifests, fname) - end - end - - _p(3,' 0 then - _p(4,'AdditionalManifestFiles="%s"', premake.esc(table.concat(manifests, ";"))) - end - _p(3,'/>') - end - - - --- --- VCMIDLTool block --- - - function premake.vs200x_vcproj_VCMIDLTool(cfg) - _p(3,'') - end - - - --- --- Write out a custom build steps block. --- - - function premake.vs200x_vcproj_buildstepsblock(name, steps) - _p(3,' 0 then - _p(4,'CommandLine="%s"', premake.esc(table.implode(steps, "", "", "\r\n"))) - end - _p(3,'/>') - end - - - --- --- Map project tool blocks to handler functions. Unmapped blocks will output --- an empty element. --- - - local blockmap = - { - VCCLCompilerTool = premake.vs200x_vcproj_VCCLCompilerTool, - VCCLCompilerTool_GCC = premake.vs200x_vcproj_VCCLCompilerTool_GCC, - VCLinkerTool = premake.vs200x_vcproj_VCLinkerTool, - VCLinkerTool_GCC = premake.vs200x_vcproj_VCLinkerTool_GCC, - VCManifestTool = premake.vs200x_vcproj_VCManifestTool, - VCMIDLTool = premake.vs200x_vcproj_VCMIDLTool, - VCResourceCompilerTool = premake.vs200x_vcproj_VCResourceCompilerTool, - } - - --- --- Return a list of sections for a particular Visual Studio version and target platform. --- - - local function getsections(version, platform) - if version == "vs2002" then - return { - "VCCLCompilerTool", - "VCCustomBuildTool", - "VCLinkerTool", - "VCMIDLTool", - "VCPostBuildEventTool", - "VCPreBuildEventTool", - "VCPreLinkEventTool", - "VCResourceCompilerTool", - "VCWebServiceProxyGeneratorTool", - "VCWebDeploymentTool" - } - end - if version == "vs2003" then - return { - "VCCLCompilerTool", - "VCCustomBuildTool", - "VCLinkerTool", - "VCMIDLTool", - "VCPostBuildEventTool", - "VCPreBuildEventTool", - "VCPreLinkEventTool", - "VCResourceCompilerTool", - "VCWebServiceProxyGeneratorTool", - "VCXMLDataGeneratorTool", - "VCWebDeploymentTool", - "VCManagedWrapperGeneratorTool", - "VCAuxiliaryManagedWrapperGeneratorTool" - } - end - if platform == "Xbox360" then - return { - "VCPreBuildEventTool", - "VCCustomBuildTool", - "VCXMLDataGeneratorTool", - "VCWebServiceProxyGeneratorTool", - "VCMIDLTool", - "VCCLCompilerTool", - "VCManagedResourceCompilerTool", - "VCResourceCompilerTool", - "VCPreLinkEventTool", - "VCLinkerTool", - "VCALinkTool", - "VCX360ImageTool", - "VCBscMakeTool", - "VCX360DeploymentTool", - "VCPostBuildEventTool", - "DebuggerTool", - } - end - if platform == "PS3" then - return { - "VCPreBuildEventTool", - "VCCustomBuildTool", - "VCXMLDataGeneratorTool", - "VCWebServiceProxyGeneratorTool", - "VCMIDLTool", - "VCCLCompilerTool_GCC", - "VCManagedResourceCompilerTool", - "VCResourceCompilerTool", - "VCPreLinkEventTool", - "VCLinkerTool_GCC", - "VCALinkTool", - "VCManifestTool", - "VCXDCMakeTool", - "VCBscMakeTool", - "VCFxCopTool", - "VCAppVerifierTool", - "VCWebDeploymentTool", - "VCPostBuildEventTool" - } - else - return { - "VCPreBuildEventTool", - "VCCustomBuildTool", - "VCXMLDataGeneratorTool", - "VCWebServiceProxyGeneratorTool", - "VCMIDLTool", - "VCCLCompilerTool", - "VCManagedResourceCompilerTool", - "VCResourceCompilerTool", - "VCPreLinkEventTool", - "VCLinkerTool", - "VCALinkTool", - "VCManifestTool", - "VCXDCMakeTool", - "VCBscMakeTool", - "VCFxCopTool", - "VCAppVerifierTool", - "VCWebDeploymentTool", - "VCPostBuildEventTool" - } - end - end - - - --- --- The main function: write the project file. --- - - function premake.vs200x_vcproj(prj) - io.eol = "\r\n" - _p('') - - -- Write opening project block - _p(' "vs2003" then - _p(1,'RootNamespace="%s"', prj.name) - end - _p(1,'Keyword="%s"', iif(prj.flags.Managed, "ManagedCProj", "Win32Proj")) - _p(1,'>') - - -- list the target platforms - premake.vs200x_vcproj_platforms(prj) - - if _ACTION > "vs2003" then - _p(1,'') - _p(1,'') - end - - _p(1,'') - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - if cfginfo.isreal then - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - - -- Start a configuration - vcproj.Configuration(cfginfo.name, cfg) - for _, block in ipairs(getsections(_ACTION, cfginfo.src_platform)) do - - if blockmap[block] then - blockmap[block](cfg) - - -- Build event blocks -- - elseif block == "VCPreBuildEventTool" then - premake.vs200x_vcproj_buildstepsblock("VCPreBuildEventTool", cfg.prebuildcommands) - elseif block == "VCPreLinkEventTool" then - premake.vs200x_vcproj_buildstepsblock("VCPreLinkEventTool", cfg.prelinkcommands) - elseif block == "VCPostBuildEventTool" then - premake.vs200x_vcproj_buildstepsblock("VCPostBuildEventTool", cfg.postbuildcommands) - -- End build event blocks -- - - -- Xbox 360 custom sections -- - elseif block == "VCX360DeploymentTool" then - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', table.concat(premake.esc(cfg.deploymentoptions), " ")) - end - _p(3,'/>') - - elseif block == "VCX360ImageTool" then - _p(3,' 0 then - _p(4,'AdditionalOptions="%s"', table.concat(premake.esc(cfg.imageoptions), " ")) - end - if cfg.imagepath ~= nil then - _p(4,'OutputFileName="%s"', premake.esc(path.translate(cfg.imagepath))) - end - _p(3,'/>') - - elseif block == "DebuggerTool" then - _p(3,'') - - -- End Xbox 360 custom sections -- - - else - _p(3,'') - end - - end - - _p(2,'') - end - end - _p(1,'') - - _p(1,'') - _p(1,'') - - _p(1,'') - premake.walksources(prj, _VS.files) - _p(1,'') - - _p(1,'') - _p(1,'') - _p('') - end - - - Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs2010_vcxproxj.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs2010_vcxproxj.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs2010_vcxproxj.lua @@ -1,762 +0,0 @@ - -premake.vstudio.vs10_helpers = { } -local vs10_helpers = premake.vstudio.vs10_helpers - - - function vs10_helpers.remove_relative_path(file) - file = file:gsub("%.%./",'') - file = file:gsub("%./",'') - file = file:gsub("^source/",'') - return file - end - - function vs10_helpers.file_path(file) - file = vs10_helpers.remove_relative_path(file) - local path = string.find(file,'/[%w%.%_%-]+$') - if path then - return string.sub(file,1,path-1) - else - return nil - end - end - - function vs10_helpers.list_of_directories_in_path(path) - local list={} - path = vs10_helpers.remove_relative_path(path) - if path then - for dir in string.gmatch(path,"[%w%-%_%.]+/")do - if #list == 0 then - list[1] = dir:sub(1,#dir-1) - else - list[#list +1] = list[#list] .."/" ..dir:sub(1,#dir-1) - end - end - end - return list - end - - function vs10_helpers.table_of_file_filters(files) - local filters ={} - - for _, valueTable in pairs(files) do - for _, entry in ipairs(valueTable) do - local result = vs10_helpers.list_of_directories_in_path(entry) - for __,dir in ipairs(result) do - if table.contains(filters,dir) ~= true then - filters[#filters +1] = dir - end - end - end - end - - return filters - end - - function vs10_helpers.get_file_extension(file) - local ext_start,ext_end = string.find(file,"%.[%w_%-]+$") - if ext_start then - return string.sub(file,ext_start+1,ext_end) - end - end - - - function vs10_helpers.sort_input_files(files,sorted_container) - local types = - { - h = "ClInclude", - hpp = "ClInclude", - hxx = "ClInclude", - c = "ClCompile", - cpp = "ClCompile", - cxx = "ClCompile", - cc = "ClCompile", - rc = "ResourceCompile", - asm = "ClASM" - } - - for _, current_file in ipairs(files) do - local ext = vs10_helpers.get_file_extension(current_file) - if ext then - local type = types[ext] - if type then - table.insert(sorted_container[type],current_file) - else - table.insert(sorted_container.None,current_file) - end - end - end - end - - - - local function vs2010_config(prj) - _p(1,'') - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - _p(2,'', premake.esc(cfginfo.name)) - _p(3,'%s',cfginfo.buildcfg) - _p(3,'%s',cfginfo.platform) - _p(2,'') - end - _p(1,'') - end - - local function vs2010_globals(prj) - _p(1,'') - _p(2,'{%s}',prj.uuid) - _p(2,'%s',prj.name) - _p(2,'Win32Proj') - - if _ACTION == "vs2012" then - _p(2,[[$(VCTargetsPath11)]]) - end - - _p(1,'') - end - - function vs10_helpers.config_type(config) - local t = - { - SharedLib = "DynamicLibrary", - StaticLib = "StaticLibrary", - ConsoleApp = "Application", - WindowedApp = "Application" - } - return t[config.kind] - end - - local function if_config_and_platform() - return 'Condition="\'$(Configuration)|$(Platform)\'==\'%s\'"' - end - - local function optimisation(cfg) - local result = "Disabled" - for _, value in ipairs(cfg.flags) do - if (value == "Optimize") then - result = "Full" - elseif (value == "OptimizeSize") then - result = "MinSpace" - elseif (value == "OptimizeSpeed") then - result = "MaxSpeed" - end - end - return result - end - - local function config_type_block(prj) - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - _p(1,'' - , premake.esc(cfginfo.name)) - _p(2,'%s',vs10_helpers.config_type(cfg)) - _p(2,'%s',iif(cfg.flags.Unicode,"Unicode","MultiByte")) - _p(2,'%s' - ,iif(optimisation(cfg) == "Disabled","true","false")) - - if _ACTION == "vs2012" then - _p(2, 'v110_xp') - elseif _ACTION == "vs2013" then - _p(2, 'v120_xp') - end - - - if cfg.flags.MFC then - _p(2,'Dynamic') - end - _p(1,'') - end - end - - - local function import_props(prj) - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - _p(1,'' - ,premake.esc(cfginfo.name)) - _p(2,'') - _p(1,'') - end - end - - local function incremental_link(cfg,cfginfo) - if cfg.kind ~= "StaticLib" then - ShoudLinkIncrementally = 'false' - if optimisation(cfg) == "Disabled" then - ShoudLinkIncrementally = 'true' - end - - _p(2,'%s' - ,premake.esc(cfginfo.name),ShoudLinkIncrementally) - end - end - - - local function ignore_import_lib(cfg,cfginfo) - if cfg.kind == "SharedLib" then - local shouldIgnore = "false" - if cfg.flags.NoImportLib then shouldIgnore = "true" end - _p(2,'%s' - ,premake.esc(cfginfo.name),shouldIgnore) - end - end - - - local function intermediate_and_out_dirs(prj) - _p(1,'') - _p(2,'<_ProjectFileVersion>10.0.30319.1') - - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - _p(2,'%s\\' - , premake.esc(cfginfo.name),premake.esc(cfg.buildtarget.directory) ) - _p(2,'%s\\' - , premake.esc(cfginfo.name), premake.esc(cfg.objectsdir)) - _p(2,'%s' - ,premake.esc(cfginfo.name),path.getbasename(cfg.buildtarget.name)) - - ignore_import_lib(cfg,cfginfo) - incremental_link(cfg,cfginfo) - if cfg.flags.NoManifest then - _p(2,'false' - ,premake.esc(cfginfo.name)) - end - end - - _p(1,'') - end - - - - local function runtime(cfg) - local runtime - if premake.config.isdebugbuild(cfg) then - runtime = iif(cfg.flags.StaticRuntime,"MultiThreadedDebug", "MultiThreadedDebugDLL") - else - runtime = iif(cfg.flags.StaticRuntime, "MultiThreaded", "MultiThreadedDLL") - end - return runtime - end - - local function precompiled_header(cfg) - if not cfg.flags.NoPCH and cfg.pchheader then - _p(3,'Use') - _p(3,'%s', path.getname(cfg.pchheader)) - else - _p(3,'') - end - end - - local function preprocessor(indent,cfg) - if #cfg.defines > 0 then - _p(indent,'%s;%%(PreprocessorDefinitions)' - ,premake.esc(table.concat(cfg.defines, ";"))) - else - _p(indent,'') - end - end - - local function include_dirs(indent,cfg) - if #cfg.includedirs > 0 then - _p(indent,'%s;%%(AdditionalIncludeDirectories)' - ,premake.esc(path.translate(table.concat(cfg.includedirs, ";"), '\\'))) - end - end - - local function resource_compile(cfg) - _p(2,'') - preprocessor(3,cfg) - include_dirs(3,cfg) - _p(2,'') - - end - - local function exceptions(cfg) - if cfg.flags.NoExceptions then - _p(2,'false') - elseif cfg.flags.SEH then - _p(2,'Async') - end - end - - local function rtti(cfg) - if cfg.flags.NoRTTI then - _p(3,'false') - end - end - - local function wchar_t_buildin(cfg) - if cfg.flags.NativeWChar then - _p(3,'true') - elseif cfg.flags.NoNativeWChar then - _p(3,'false') - end - end - - local function sse(cfg) - if cfg.flags.EnableSSE then - _p(3,'StreamingSIMDExtensions') - elseif cfg.flags.EnableSSE2 then - _p(3,'StreamingSIMDExtensions2') - end - end - - local function floating_point(cfg) - if cfg.flags.FloatFast then - _p(3,'Fast') - elseif cfg.flags.FloatStrict then - _p(3,'Strict') - end - end - - - local function debug_info(cfg) - -- - -- EditAndContinue /ZI - -- ProgramDatabase /Zi - -- OldStyle C7 Compatable /Z7 - -- - local debug_info = '' - if cfg.flags.Symbols then - if optimisation(cfg) ~= "Disabled" or cfg.flags.NoEditAndContinue then - debug_info = "ProgramDatabase" - elseif cfg.platform ~= "x64" then - debug_info = "EditAndContinue" - else - debug_info = "OldStyle" - end - end - - _p(3,'%s',debug_info) - end - - local function minimal_build(cfg) - if premake.config.isdebugbuild(cfg) and not cfg.flags.NoMinimalRebuild then - _p(3,'true') - else - _p(3,'false') - end - end - - local function compile_language(cfg) - if cfg.language == "C" then - _p(3,'CompileAsC') - end - end - - local function vs10_clcompile(cfg) - _p(2,'') - - if #cfg.buildoptions > 0 then - _p(3,'%s %%(AdditionalOptions)', - table.concat(premake.esc(cfg.buildoptions), " ")) - end - - _p(3,'%s',optimisation(cfg)) - - include_dirs(3,cfg) - preprocessor(3,cfg) - minimal_build(cfg) - - if optimisation(cfg) == "Disabled" then - _p(3,'EnableFastChecks') - if cfg.flags.ExtraWarnings then - _p(3,'true') - end - else - _p(3,'true') - end - - _p(3,'%s', runtime(cfg)) - - _p(3,'true') - - precompiled_header(cfg) - - if cfg.flags.ExtraWarnings then - _p(3,'Level4') - else - _p(3,'Level3') - end - - if cfg.flags.FatalWarnings then - _p(3,'true') - end - - exceptions(cfg) - rtti(cfg) - wchar_t_buildin(cfg) - sse(cfg) - floating_point(cfg) - debug_info(cfg) - - - if cfg.flags.NoFramePointer then - _p(3,'true') - end - - compile_language(cfg) - - _p(2,'') - end - - - local function event_hooks(cfg, prj) - if #cfg.postbuildcommands> 0 then - _p(2,'') - _p(3,'%s',premake.esc(table.implode(cfg.postbuildcommands, "", "", "\r\n"))) - _p(2,'') - end - - if #cfg.prebuildcommands> 0 or prj.cxxtestrootfile then - _p(2,'') - _p(3,'%s',premake.esc(table.implode(cfg.prebuildcommands, "", "", "\r\n"))) - - -- test generation only works if all required parameters are set! - if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then - local cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),"\\") - local cxxtestrootfile = path.translate(prj.cxxtestrootfile,"\\") - _p(3,'%s --root %s > %s', cxxtestpath, prj.cxxtestrootoptions, cxxtestrootfile) - end - _p(2,'') - end - - if #cfg.prelinkcommands> 0 then - _p(2,'') - _p(3,'%s',premake.esc(table.implode(cfg.prelinkcommands, "", "", "\r\n"))) - _p(2,'') - end - end - - local function additional_options(indent,cfg) - if #cfg.linkoptions > 0 then - _p(indent,'%s %%(AdditionalOptions)', - table.concat(premake.esc(cfg.linkoptions), " ")) - end - end - - local function item_def_lib(cfg) - if cfg.kind == 'StaticLib' then - _p(1,'') - _p(2,'$(OutDir)%s',cfg.buildtarget.name) - additional_options(2,cfg) - _p(1,'') - end - end - - local function link_target_machine(cfg) - local target - if cfg.platform == nil or cfg.platform == "x32" then target ="MachineX86" - elseif cfg.platform == "x64" then target ="MachineX64" - end - - _p(3,'%s', target) - end - - local function import_lib(cfg) - --Prevent the generation of an import library for a Windows DLL. - if cfg.kind == "SharedLib" then - local implibname = cfg.linktarget.fullpath - _p(3,'%s',iif(cfg.flags.NoImportLib, cfg.objectsdir .. "\\" .. path.getname(implibname), implibname)) - end - end - - - local function common_link_section(cfg) - _p(3,'%s',iif(cfg.kind == "ConsoleApp","Console", "Windows")) - - if cfg.flags.Symbols then - _p(3,'true') - else - _p(3,'false') - end - - if optimisation(cfg) ~= "Disabled" then - _p(3,'true') - _p(3,'true') - end - - if cfg.flags.Symbols then - _p(3,'$(OutDir)%s.pdb' - , path.getbasename(cfg.buildtarget.name)) - end - end - - local function item_link(cfg) - _p(2,'') - if cfg.kind ~= 'StaticLib' then - - if #cfg.links > 0 then - _p(3,'%s;%%(AdditionalDependencies)', - table.concat(premake.getlinks(cfg, "all", "fullpath"), ";")) - end - _p(3,'$(OutDir)%s', cfg.buildtarget.name) - - _p(3,'%s%s%%(AdditionalLibraryDirectories)', - table.concat(premake.esc(path.translate(cfg.libdirs, '\\')) , ";"), - iif(cfg.libdirs and #cfg.libdirs >0,';','')) - - common_link_section(cfg) - - if vs10_helpers.config_type(cfg) == 'Application' and not cfg.flags.WinMain then - _p(3,'mainCRTStartup') - end - - import_lib(cfg) - - _p(3,'%s', iif(cfg.platform == "x64", "MachineX64", "MachineX86")) - - additional_options(3,cfg) - else - common_link_section(cfg) - end - - _p(2,'') - end - - local function item_definitions(prj) - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - _p(1,'' - ,premake.esc(cfginfo.name)) - vs10_clcompile(cfg) - resource_compile(cfg) - item_def_lib(cfg) - item_link(cfg) - event_hooks(cfg, prj) - _p(1,'') - end - end - - - - -- - -- - -- - -- {8fd826f8-3739-44e6-8cc8-997122e53b8d} - -- - -- - - local function write_cxxtestgen_block(prj) - -- test generation only works if all required parameters are set! - if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then - local cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),"\\") - _p(1,'') - for i, file in ipairs(prj.cxxtesthdrfiles) do - local cxxtesthdrfile = path.translate(file,"\\") - local cxxtestsrcfile = path.translate(prj.cxxtestsrcfiles[i],"\\") - _p(2,'', cxxtesthdrfile) - _p(3,'Generating %s', path.getname(prj.cxxtestsrcfiles[i])) - _p(3,'%s --part %s -o \"%s\" \"%s\"', - cxxtestpath, prj.cxxtestoptions, cxxtestsrcfile, cxxtesthdrfile) - _p(3,'%s;%%(Outputs)', cxxtestsrcfile) - _p(2,'') - end - _p(1,'') - end - end - - local function write_file_type_block(files,group_type) - if #files > 0 then - _p(1,'') - for _, current_file in ipairs(files) do - _p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file,"\\")) - end - _p(1,'') - end - end - - local function write_file_compile_block(files,prj,configs) - if #files > 0 then - local config_mappings = {} - for _, cfginfo in ipairs(configs) do - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - if cfg.pchheader and cfg.pchsource and not cfg.flags.NoPCH then - config_mappings[cfginfo] = cfg.pchsource - end - end - - - _p(1,'') - for _, current_file in ipairs(files) do - _p(2,'', path.translate(current_file, "\\")) - for _, cfginfo in ipairs(configs) do - if config_mappings[cfginfo] and current_file == config_mappings[cfginfo] then - _p(3,'Create' - ,premake.esc(cfginfo.name)) - --only one source file per pch - config_mappings[cfginfo] = nil - end - end - _p(2,'') - end - _p(1,'') - end - end - - local function write_nasm_asm_block(files, prj, configs) - -- set defaults if required parameters are not set - if not (prj.solution.nasmformat) then - prj.solution.nasmformat = 'win32' - end - - if not (prj.solution.nasmpath) then - prj.solution.nasmpath = 'nasm' - end - - if #files > 0 then - _p(1,'') - local nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath),"\\") - for _, current_file in ipairs(files) do - _p(2,'', path.translate(current_file,"\\")) - _p(3,'Assembling %%(FullPath)') - _p(3,'%s -i %s -f %s \"%%(FullPath)\" -o \"$(IntDir)%%(Filename).obj\"', - nasmpath, - path.translate(path.getdirectory(current_file),"\\").."\\", - prj.solution.nasmformat) - _p(3,'$(IntDir)%%(Filename).obj;%%(Outputs)') - _p(2,'') - end - _p(1,'') - end - end - - - local function vcxproj_files(prj) - local sorted = - { - ClCompile ={}, - ClInclude ={}, - ClASM ={}, - None ={}, - ResourceCompile ={} - } - - cfg = premake.getconfig(prj) - vs10_helpers.sort_input_files(cfg.files,sorted) - write_cxxtestgen_block(prj) - write_file_type_block(sorted.ClInclude,"ClInclude") - write_file_compile_block(sorted.ClCompile,prj,prj.solution.vstudio_configs) - write_nasm_asm_block(sorted.ClASM, prj, prj.solution.vstudion_configs) - write_file_type_block(sorted.None,'None') - write_file_type_block(sorted.ResourceCompile,'ResourceCompile') - - end - - local function write_filter_includes(sorted_table) - local directories = vs10_helpers.table_of_file_filters(sorted_table) - --I am going to take a punt here that the ItemGroup is missing if no files!!!! - --there is a test for this see - --vs10_filters.noInputFiles_bufferDoesNotContainTagItemGroup - if #directories >0 then - _p(1,'') - for _, dir in pairs(directories) do - _p(2,'',path.translate(dir,"\\")) - _p(3,'{%s}',os.uuid()) - _p(2,'') - end - _p(1,'') - end - end - - local function write_file_filter_block(files,group_type) - if #files > 0 then - _p(1,'') - for _, current_file in ipairs(files) do - local path_to_file = vs10_helpers.file_path(current_file) - if path_to_file then - _p(2,'<%s Include=\"%s\">', group_type,path.translate(current_file, "\\")) - _p(3,'%s',path.translate(path_to_file,"\\")) - _p(2,'',group_type) - else - _p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file, "\\")) - end - end - _p(1,'') - end - end - - local tool_version_and_xmlns = 'ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"' - local xml_version_and_encoding = '' - - local function vcxproj_filter_files(prj) - local sorted = - { - ClCompile ={}, - ClInclude ={}, - ClASM ={}, - None ={}, - ResourceCompile ={} - } - - cfg = premake.getconfig(prj) - vs10_helpers.sort_input_files(cfg.files,sorted) - - io.eol = "\r\n" - _p(xml_version_and_encoding) - _p('') - write_filter_includes(sorted) - write_file_filter_block(sorted.ClInclude,"ClInclude") - write_file_filter_block(sorted.ClCompile,"ClCompile") - write_file_filter_block(prj.cxxtesthdrfiles,"CustomBuild") - write_file_filter_block(sorted.ClASM,"ClASM") - write_file_filter_block(sorted.None,"None") - write_file_filter_block(sorted.ResourceCompile,"ResourceCompile") - _p('') - end - - function premake.vs2010_vcxproj(prj) - io.eol = "\r\n" - _p(xml_version_and_encoding) - _p('') - vs2010_config(prj) - vs2010_globals(prj) - - _p(1,'') - - config_type_block(prj) - - _p(1,'') - - --check what this section is doing - _p(1,'') - _p(1,'') - - - import_props(prj) - - --what type of macros are these? - _p(1,'') - - intermediate_and_out_dirs(prj) - - item_definitions(prj) - - vcxproj_files(prj) - - _p(1,'') - _p(1,'') - _p(1,'') - - _p('') - end - - function premake.vs2010_vcxproj_user(prj) - _p(xml_version_and_encoding) - _p('') - - for _, cfginfo in ipairs(prj.solution.vstudio_configs) do - local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform) - if cfg.flags.NoDebugHeap then - _p(1,'', premake.esc(cfginfo.name)) - _p(2,'_NO_DEBUG_HEAP=1') - _p(1,'') - end - end - _p('') - end - - function premake.vs2010_vcxproj_filters(prj) - vcxproj_filter_files(prj) - end - - - Index: ps/trunk/build/premake/premake4/src/actions/vstudio/vs_generic_solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/vstudio/vs_generic_solution.lua +++ ps/trunk/build/premake/premake4/src/actions/vstudio/vs_generic_solution.lua @@ -1,70 +0,0 @@ - -local vs_format_version = function() - local t = - { - vs2005 = '9.00', - vs2008 = '10.00', - vs2010 = '11.00', - vs2012 = '12.00', - vs2013 = '13.00' - } - return t[_ACTION] -end - -local vs_version = function() - local t = - { - vs2005 = '2005', - vs2008 = '2008', - vs2010 = '2010', - vs2012 = '2012', - vs2013 = '2013' - } - return t[_ACTION] -end - -local vs_write_version_info = function() - _p('Microsoft Visual Studio Solution File, Format Version %s', vs_format_version()) - _p('# Visual Studio %s', vs_version() ) -end - - -local vs_write_projects = function(sln) - -- Write out the list of project entries - for prj in premake.solution.eachproject(sln) do - -- Build a relative path from the solution file to the project file - local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), "\\") - _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) - - local deps = premake.getdependencies(prj) - if #deps > 0 then - _p('\tProjectSection(ProjectDependencies) = postProject') - for _, dep in ipairs(deps) do - _p('\t\t{%s} = {%s}', dep.uuid, dep.uuid) - end - _p('\tEndProjectSection') - end - _p('EndProject') - end -end - - -local vs_write_pre_version = function(sln) - io.eol = '\r\n' - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - -- Mark the file as Unicode - _p('\239\187\191') -end - -function premake.vs_generic_solution(sln) - vs_write_pre_version(sln) - vs_write_version_info() - vs_write_projects(sln) - - _p('Global') - premake.vs2005_solution_platforms(sln) - premake.vs2005_solution_project_platforms(sln) - premake.vs2005_solution_properties(sln) - _p('EndGlobal') - -end \ No newline at end of file Index: ps/trunk/build/premake/premake4/src/actions/xcode/_xcode.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/xcode/_xcode.lua +++ ps/trunk/build/premake/premake4/src/actions/xcode/_xcode.lua @@ -1,111 +0,0 @@ --- --- _xcode.lua --- Define the Apple XCode action and support functions. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - premake.xcode = { } - - newaction - { - trigger = "xcode3", - shortname = "Xcode 3", - description = "Generate Apple Xcode 3 project files (experimental)", - os = "macosx", - - valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib" }, - - valid_languages = { "C", "C++" }, - - valid_tools = { - cc = { "gcc" }, - }, - - valid_platforms = { - Native = "Native", - x32 = "Native 32-bit", - x64 = "Native 64-bit", - Universal32 = "32-bit Universal", - Universal64 = "64-bit Universal", - Universal = "Universal", - }, - - default_platform = "Universal", - - onsolution = function(sln) - -- Assign IDs needed for inter-project dependencies - premake.xcode.preparesolution(sln) - end, - - onproject = function(prj) - premake.generate(prj, "%%.xcodeproj/project.pbxproj", premake.xcode.project) - end, - - oncleanproject = function(prj) - premake.clean.directory(prj, "%%.xcodeproj") - end, - - oncheckproject = function(prj) - -- Xcode can't mix target kinds within a project - local last - for cfg in premake.eachconfig(prj) do - if last and last ~= cfg.kind then - error("Project '" .. prj.name .. "' uses more than one target kind; not supported by Xcode", 0) - end - last = cfg.kind - end - end, - } - - newaction - { - trigger = "xcode4", - shortname = "Xcode 4", - description = "Generate Apple Xcode 4 project files (experimental)", - os = "macosx", - - valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib" }, - - valid_languages = { "C", "C++" }, - - valid_tools = { - cc = { "gcc" }, - }, - - valid_platforms = { - Native = "Native", - x32 = "Native 32-bit", - x64 = "Native 64-bit", - Universal32 = "32-bit Universal", - Universal64 = "64-bit Universal", - Universal = "Universal", - }, - - default_platform = "Universal", - - onsolution = function(sln) - premake.generate(sln, "%%.xcworkspace/contents.xcworkspacedata", premake.xcode4.workspace_generate) - end, - - onproject = function(prj) - premake.generate(prj, "%%.xcodeproj/project.pbxproj", premake.xcode.project) - end, - - oncleanproject = function(prj) - premake.clean.directory(prj, "%%.xcodeproj") - premake.clean.directory(prj, "%%.xcworkspace") - end, - - oncheckproject = function(prj) - -- Xcode can't mix target kinds within a project - local last - for cfg in premake.eachconfig(prj) do - if last and last ~= cfg.kind then - error("Project '" .. prj.name .. "' uses more than one target kind; not supported by Xcode", 0) - end - last = cfg.kind - end - end, - } - - Index: ps/trunk/build/premake/premake4/src/actions/xcode/xcode4_workspace.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/xcode/xcode4_workspace.lua +++ ps/trunk/build/premake/premake4/src/actions/xcode/xcode4_workspace.lua @@ -1,40 +0,0 @@ -premake.xcode4 = {} - -local xcode4 = premake.xcode4 - -function xcode4.workspace_head() - _p('') - _p('') - -end - -function xcode4.workspace_tail() - _p('') -end - -function xcode4.workspace_file_ref(prj) - - local projpath = path.getrelative(prj.solution.location, prj.location) - if projpath == '.' then projpath = '' - else projpath = projpath ..'/' - end - _p(1,'',projpath .. prj.name .. '.xcodeproj') - _p(1,'') -end - -function xcode4.workspace_generate(sln) - premake.xcode.preparesolution(sln) - - xcode4.workspace_head() - - for prj in premake.solution.eachproject(sln) do - xcode4.workspace_file_ref(prj) - end - - xcode4.workspace_tail() -end - - - Index: ps/trunk/build/premake/premake4/src/actions/xcode/xcode_common.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/xcode/xcode_common.lua +++ ps/trunk/build/premake/premake4/src/actions/xcode/xcode_common.lua @@ -1,885 +0,0 @@ --- --- xcode_common.lua --- Functions to generate the different sections of an Xcode project. --- Copyright (c) 2009-2011 Jason Perkins and the Premake project --- - - local xcode = premake.xcode - local tree = premake.tree - - --- --- Return the Xcode build category for a given file, based on the file extension. --- --- @param node --- The node to identify. --- @returns --- An Xcode build category, one of "Sources", "Resources", "Frameworks", or nil. --- - - function xcode.getbuildcategory(node) - local categories = { - [".a"] = "Frameworks", - [".c"] = "Sources", - [".cc"] = "Sources", - [".cpp"] = "Sources", - [".cxx"] = "Sources", - [".dylib"] = "Frameworks", - [".framework"] = "Frameworks", - [".m"] = "Sources", - [".mm"] = "Sources", - [".strings"] = "Resources", - [".nib"] = "Resources", - [".xib"] = "Resources", - [".icns"] = "Resources", - } - return categories[path.getextension(node.name)] - end - - --- --- Return the displayed name for a build configuration, taking into account the --- configuration and platform, i.e. "Debug 32-bit Universal". --- --- @param cfg --- The configuration being identified. --- @returns --- A build configuration name. --- - - function xcode.getconfigname(cfg) - local name = cfg.name - if #cfg.project.solution.xcode.platforms > 1 then - name = name .. " " .. premake.action.current().valid_platforms[cfg.platform] - end - return name - end - - --- --- Return the Xcode type for a given file, based on the file extension. --- --- @param fname --- The file name to identify. --- @returns --- An Xcode file type, string. --- - - function xcode.getfiletype(node) - local types = { - [".c"] = "sourcecode.c.c", - [".cc"] = "sourcecode.cpp.cpp", - [".cpp"] = "sourcecode.cpp.cpp", - [".css"] = "text.css", - [".cxx"] = "sourcecode.cpp.cpp", - [".framework"] = "wrapper.framework", - [".gif"] = "image.gif", - [".h"] = "sourcecode.c.h", - [".html"] = "text.html", - [".lua"] = "sourcecode.lua", - [".m"] = "sourcecode.c.objc", - [".mm"] = "sourcecode.cpp.objc", - [".nib"] = "wrapper.nib", - [".pch"] = "sourcecode.c.h", - [".plist"] = "text.plist.xml", - [".strings"] = "text.plist.strings", - [".xib"] = "file.xib", - [".icns"] = "image.icns", - } - return types[path.getextension(node.path)] or "text" - end - - --- --- Return the Xcode product type, based target kind. --- --- @param node --- The product node to identify. --- @returns --- An Xcode product type, string. --- - - function xcode.getproducttype(node) - local types = { - ConsoleApp = "com.apple.product-type.tool", - WindowedApp = "com.apple.product-type.application", - StaticLib = "com.apple.product-type.library.static", - SharedLib = "com.apple.product-type.library.dynamic", - } - return types[node.cfg.kind] - end - - --- --- Return the Xcode target type, based on the target file extension. --- --- @param node --- The product node to identify. --- @returns --- An Xcode target type, string. --- - - function xcode.gettargettype(node) - local types = { - ConsoleApp = "\"compiled.mach-o.executable\"", - WindowedApp = "wrapper.application", - StaticLib = "archive.ar", - SharedLib = "\"compiled.mach-o.dylib\"", - } - return types[node.cfg.kind] - end - - --- --- Return a unique file name for a project. Since Xcode uses .xcodeproj's to --- represent both solutions and projects there is a likely change of a name --- collision. Tack on a number to differentiate them. --- --- @param prj --- The project being queried. --- @returns --- A uniqued file name --- - - function xcode.getxcodeprojname(prj) - -- if there is a solution with matching name, then use "projectname1.xcodeproj" - -- just get something working for now - local fname = premake.project.getfilename(prj, "%%.xcodeproj") - return fname - end - - --- --- Returns true if the file name represents a framework. --- --- @param fname --- The name of the file to test. --- - - function xcode.isframework(fname) - return (path.getextension(fname) == ".framework") - end - - --- --- Retrieves a unique 12 byte ID for an object. This function accepts and ignores two --- parameters 'node' and 'usage', which are used by an alternative implementation of --- this function for testing. --- --- @returns --- A 24-character string representing the 12 byte ID. --- - - function xcode.newid() - return string.format("%04X%04X%04X%04X%04X%04X", - math.random(0, 32767), - math.random(0, 32767), - math.random(0, 32767), - math.random(0, 32767), - math.random(0, 32767), - math.random(0, 32767)) - end - - --- --- Create a product tree node and all projects in a solution; assigning IDs --- that are needed for inter-project dependencies. --- --- @param sln --- The solution to prepare. --- - - function xcode.preparesolution(sln) - -- create and cache a list of supported platforms - sln.xcode = { } - sln.xcode.platforms = premake.filterplatforms(sln, premake.action.current().valid_platforms, "Universal") - - for prj in premake.solution.eachproject(sln) do - -- need a configuration to get the target information - local cfg = premake.getconfig(prj, prj.configurations[1], sln.xcode.platforms[1]) - - -- build the product tree node - local node = premake.tree.new(path.getname(cfg.buildtarget.bundlepath)) - node.cfg = cfg - node.id = premake.xcode.newid(node, "product") - node.targetid = premake.xcode.newid(node, "target") - - -- attach it to the project - prj.xcode = {} - prj.xcode.projectnode = node - end - end - - --- --- Print out a list value in the Xcode format. --- --- @param list --- The list of values to be printed. --- @param tag --- The Xcode specific list tag. --- - - function xcode.printlist(list, tag) - if #list > 0 then - _p(4,'%s = (', tag) - for _, item in ipairs(list) do - _p(5, '"%s",', item) - end - _p(4,');') - end - end - - ---------------------------------------------------------------------------- --- Section generator functions, in the same order in which they appear --- in the .pbxproj file ---------------------------------------------------------------------------- - - function xcode.Header() - _p('// !$*UTF8*$!') - _p('{') - _p(1,'archiveVersion = 1;') - _p(1,'classes = {') - _p(1,'};') - _p(1,'objectVersion = 45;') - _p(1,'objects = {') - _p('') - end - - - function xcode.PBXBuildFile(tr) - _p('/* Begin PBXBuildFile section */') - tree.traverse(tr, { - onnode = function(node) - if node.buildid then - _p(2,'%s /* %s in %s */ = {isa = PBXBuildFile; fileRef = %s /* %s */; };', - node.buildid, node.name, xcode.getbuildcategory(node), node.id, node.name) - end - end - }) - _p('/* End PBXBuildFile section */') - _p('') - end - - - function xcode.PBXContainerItemProxy(tr) - if #tr.projects.children > 0 then - _p('/* Begin PBXContainerItemProxy section */') - for _, node in ipairs(tr.projects.children) do - _p(2,'%s /* PBXContainerItemProxy */ = {', node.productproxyid) - _p(3,'isa = PBXContainerItemProxy;') - _p(3,'containerPortal = %s /* %s */;', node.id, path.getname(node.path)) - _p(3,'proxyType = 2;') - _p(3,'remoteGlobalIDString = %s;', node.project.xcode.projectnode.id) - _p(3,'remoteInfo = "%s";', node.project.xcode.projectnode.name) - _p(2,'};') - _p(2,'%s /* PBXContainerItemProxy */ = {', node.targetproxyid) - _p(3,'isa = PBXContainerItemProxy;') - _p(3,'containerPortal = %s /* %s */;', node.id, path.getname(node.path)) - _p(3,'proxyType = 1;') - _p(3,'remoteGlobalIDString = %s;', node.project.xcode.projectnode.targetid) - _p(3,'remoteInfo = "%s";', node.project.xcode.projectnode.name) - _p(2,'};') - end - _p('/* End PBXContainerItemProxy section */') - _p('') - end - end - - - function xcode.PBXFileReference(tr) - _p('/* Begin PBXFileReference section */') - - tree.traverse(tr, { - onleaf = function(node) - -- I'm only listing files here, so ignore anything without a path - if not node.path then - return - end - - -- is this the product node, describing the output target? - if node.kind == "product" then - _p(2,'%s /* %s */ = {isa = PBXFileReference; explicitFileType = %s; includeInIndex = 0; name = "%s"; path = "%s"; sourceTree = BUILT_PRODUCTS_DIR; };', - node.id, node.name, xcode.gettargettype(node), node.name, path.getname(node.cfg.buildtarget.bundlepath)) - - -- is this a project dependency? - elseif node.parent.parent == tr.projects then - local relpath = path.getrelative(tr.project.location, node.parent.project.location) - _p(2,'%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "%s"; path = "%s"; sourceTree = SOURCE_ROOT; };', - node.parent.id, node.parent.name, node.parent.name, path.join(relpath, node.parent.name)) - - -- something else - else - local pth, src - if xcode.isframework(node.path) then - --respect user supplied paths - if string.find(node.path,'/') then - if string.find(node.path,'^%.')then - error('relative paths are not currently supported for frameworks') - end - pth = node.path - else - pth = "/System/Library/Frameworks/" .. node.path - end - src = "absolute" - else - -- something else; probably a source code file - src = "group" - - -- if the parent node is virtual, it won't have a local path - -- of its own; need to use full relative path from project - if node.parent.isvpath then - pth = node.cfg.name - else - pth = tree.getlocalpath(node) - end - end - - _p(2,'%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = %s; name = "%s"; path = "%s"; sourceTree = "<%s>"; };', - node.id, node.name, xcode.getfiletype(node), node.name, pth, src) - end - end - }) - - _p('/* End PBXFileReference section */') - _p('') - end - - - function xcode.PBXFrameworksBuildPhase(tr) - _p('/* Begin PBXFrameworksBuildPhase section */') - _p(2,'%s /* Frameworks */ = {', tr.products.children[1].fxstageid) - _p(3,'isa = PBXFrameworksBuildPhase;') - _p(3,'buildActionMask = 2147483647;') - _p(3,'files = (') - - -- write out library dependencies - tree.traverse(tr.frameworks, { - onleaf = function(node) - _p(4,'%s /* %s in Frameworks */,', node.buildid, node.name) - end - }) - - -- write out project dependencies - tree.traverse(tr.projects, { - onleaf = function(node) - _p(4,'%s /* %s in Frameworks */,', node.buildid, node.name) - end - }) - - _p(3,');') - _p(3,'runOnlyForDeploymentPostprocessing = 0;') - _p(2,'};') - _p('/* End PBXFrameworksBuildPhase section */') - _p('') - end - - - function xcode.PBXGroup(tr) - _p('/* Begin PBXGroup section */') - - tree.traverse(tr, { - onnode = function(node) - -- Skip over anything that isn't a proper group - if (node.path and #node.children == 0) or node.kind == "vgroup" then - return - end - - -- project references get special treatment - if node.parent == tr.projects then - _p(2,'%s /* Products */ = {', node.productgroupid) - else - _p(2,'%s /* %s */ = {', node.id, node.name) - end - - _p(3,'isa = PBXGroup;') - _p(3,'children = (') - for _, childnode in ipairs(node.children) do - _p(4,'%s /* %s */,', childnode.id, childnode.name) - end - _p(3,');') - - if node.parent == tr.projects then - _p(3,'name = Products;') - else - _p(3,'name = "%s";', node.name) - if node.path and not node.isvpath then - local p = node.path - if node.parent.path then - p = path.getrelative(node.parent.path, node.path) - end - _p(3,'path = "%s";', p) - end - end - - _p(3,'sourceTree = "";') - _p(2,'};') - end - }, true) - - _p('/* End PBXGroup section */') - _p('') - end - - - function xcode.PBXNativeTarget(tr) - _p('/* Begin PBXNativeTarget section */') - for _, node in ipairs(tr.products.children) do - local name = tr.project.name - - _p(2,'%s /* %s */ = {', node.targetid, name) - _p(3,'isa = PBXNativeTarget;') - _p(3,'buildConfigurationList = %s /* Build configuration list for PBXNativeTarget "%s" */;', node.cfgsection, name) - _p(3,'buildPhases = (') - if #tr.project.prebuildcommands > 0 then - _p(4,'9607AE1010C857E500CD1376 /* Prebuild */,') - end - _p(4,'%s /* Resources */,', node.resstageid) - _p(4,'%s /* Sources */,', node.sourcesid) - if #tr.project.prelinkcommands > 0 then - _p(4,'9607AE3510C85E7E00CD1376 /* Prelink */,') - end - _p(4,'%s /* Frameworks */,', node.fxstageid) - if #tr.project.postbuildcommands > 0 then - _p(4,'9607AE3710C85E8F00CD1376 /* Postbuild */,') - end - _p(3,');') - _p(3,'buildRules = (') - _p(3,');') - - _p(3,'dependencies = (') - for _, node in ipairs(tr.projects.children) do - _p(4,'%s /* PBXTargetDependency */,', node.targetdependid) - end - _p(3,');') - - _p(3,'name = "%s";', name) - - local p - if node.cfg.kind == "ConsoleApp" then - p = "$(HOME)/bin" - elseif node.cfg.kind == "WindowedApp" then - p = "$(HOME)/Applications" - end - if p then - _p(3,'productInstallPath = "%s";', p) - end - - _p(3,'productName = "%s";', name) - _p(3,'productReference = %s /* %s */;', node.id, node.name) - _p(3,'productType = "%s";', xcode.getproducttype(node)) - _p(2,'};') - end - _p('/* End PBXNativeTarget section */') - _p('') - end - - - function xcode.PBXProject(tr) - _p('/* Begin PBXProject section */') - _p(2,'08FB7793FE84155DC02AAC07 /* Project object */ = {') - _p(3,'isa = PBXProject;') - _p(3,'buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "%s" */;', tr.name) - _p(3,'compatibilityVersion = "Xcode 3.2";') - _p(3,'hasScannedForEncodings = 1;') - _p(3,'mainGroup = %s /* %s */;', tr.id, tr.name) - _p(3,'projectDirPath = "";') - - if #tr.projects.children > 0 then - _p(3,'projectReferences = (') - for _, node in ipairs(tr.projects.children) do - _p(4,'{') - _p(5,'ProductGroup = %s /* Products */;', node.productgroupid) - _p(5,'ProjectRef = %s /* %s */;', node.id, path.getname(node.path)) - _p(4,'},') - end - _p(3,');') - end - - _p(3,'projectRoot = "";') - _p(3,'targets = (') - for _, node in ipairs(tr.products.children) do - _p(4,'%s /* %s */,', node.targetid, node.name) - end - _p(3,');') - _p(2,'};') - _p('/* End PBXProject section */') - _p('') - end - - - function xcode.PBXReferenceProxy(tr) - if #tr.projects.children > 0 then - _p('/* Begin PBXReferenceProxy section */') - tree.traverse(tr.projects, { - onleaf = function(node) - _p(2,'%s /* %s */ = {', node.id, node.name) - _p(3,'isa = PBXReferenceProxy;') - _p(3,'fileType = %s;', xcode.gettargettype(node)) - _p(3,'path = "%s";', node.path) - _p(3,'remoteRef = %s /* PBXContainerItemProxy */;', node.parent.productproxyid) - _p(3,'sourceTree = BUILT_PRODUCTS_DIR;') - _p(2,'};') - end - }) - _p('/* End PBXReferenceProxy section */') - _p('') - end - end - - - function xcode.PBXResourcesBuildPhase(tr) - _p('/* Begin PBXResourcesBuildPhase section */') - for _, target in ipairs(tr.products.children) do - _p(2,'%s /* Resources */ = {', target.resstageid) - _p(3,'isa = PBXResourcesBuildPhase;') - _p(3,'buildActionMask = 2147483647;') - _p(3,'files = (') - tree.traverse(tr, { - onnode = function(node) - if xcode.getbuildcategory(node) == "Resources" then - _p(4,'%s /* %s in Resources */,', node.buildid, node.name) - end - end - }) - _p(3,');') - _p(3,'runOnlyForDeploymentPostprocessing = 0;') - _p(2,'};') - end - _p('/* End PBXResourcesBuildPhase section */') - _p('') - end - - function xcode.PBXShellScriptBuildPhase(tr) - local wrapperWritten = false - - local function doblock(id, name, which) - -- start with the project-level commands (most common) - local prjcmds = tr.project[which] - local commands = table.join(prjcmds, {}) - - -- see if there are any config-specific commands to add - for _, cfg in ipairs(tr.configs) do - local cfgcmds = cfg[which] - if #cfgcmds > #prjcmds then - table.insert(commands, 'if [ "${CONFIGURATION}" = "' .. xcode.getconfigname(cfg) .. '" ]; then') - for i = #prjcmds + 1, #cfgcmds do - table.insert(commands, cfgcmds[i]) - end - table.insert(commands, 'fi') - end - end - - if #commands > 0 then - if not wrapperWritten then - _p('/* Begin PBXShellScriptBuildPhase section */') - wrapperWritten = true - end - _p(2,'%s /* %s */ = {', id, name) - _p(3,'isa = PBXShellScriptBuildPhase;') - _p(3,'buildActionMask = 2147483647;') - _p(3,'files = (') - _p(3,');') - _p(3,'inputPaths = ('); - _p(3,');'); - _p(3,'name = %s;', name); - _p(3,'outputPaths = ('); - _p(3,');'); - _p(3,'runOnlyForDeploymentPostprocessing = 0;'); - _p(3,'shellPath = /bin/sh;'); - _p(3,'shellScript = "%s";', table.concat(commands, "\\n"):gsub('"', '\\"')) - _p(2,'};') - end - end - - doblock("9607AE1010C857E500CD1376", "Prebuild", "prebuildcommands") - doblock("9607AE3510C85E7E00CD1376", "Prelink", "prelinkcommands") - doblock("9607AE3710C85E8F00CD1376", "Postbuild", "postbuildcommands") - - if wrapperWritten then - _p('/* End PBXShellScriptBuildPhase section */') - end - end - - - function xcode.PBXSourcesBuildPhase(tr) - _p('/* Begin PBXSourcesBuildPhase section */') - for _, target in ipairs(tr.products.children) do - _p(2,'%s /* Sources */ = {', target.sourcesid) - _p(3,'isa = PBXSourcesBuildPhase;') - _p(3,'buildActionMask = 2147483647;') - _p(3,'files = (') - tree.traverse(tr, { - onleaf = function(node) - if xcode.getbuildcategory(node) == "Sources" then - _p(4,'%s /* %s in Sources */,', node.buildid, node.name) - end - end - }) - _p(3,');') - _p(3,'runOnlyForDeploymentPostprocessing = 0;') - _p(2,'};') - end - _p('/* End PBXSourcesBuildPhase section */') - _p('') - end - - - function xcode.PBXVariantGroup(tr) - _p('/* Begin PBXVariantGroup section */') - tree.traverse(tr, { - onbranch = function(node) - if node.kind == "vgroup" then - _p(2,'%s /* %s */ = {', node.id, node.name) - _p(3,'isa = PBXVariantGroup;') - _p(3,'children = (') - for _, lang in ipairs(node.children) do - _p(4,'%s /* %s */,', lang.id, lang.name) - end - _p(3,');') - _p(3,'name = %s;', node.name) - _p(3,'sourceTree = "";') - _p(2,'};') - end - end - }) - _p('/* End PBXVariantGroup section */') - _p('') - end - - - function xcode.PBXTargetDependency(tr) - if #tr.projects.children > 0 then - _p('/* Begin PBXTargetDependency section */') - tree.traverse(tr.projects, { - onleaf = function(node) - _p(2,'%s /* PBXTargetDependency */ = {', node.parent.targetdependid) - _p(3,'isa = PBXTargetDependency;') - _p(3,'name = "%s";', node.name) - _p(3,'targetProxy = %s /* PBXContainerItemProxy */;', node.parent.targetproxyid) - _p(2,'};') - end - }) - _p('/* End PBXTargetDependency section */') - _p('') - end - end - - - function xcode.XCBuildConfiguration_Target(tr, target, cfg) - local cfgname = xcode.getconfigname(cfg) - - _p(2,'%s /* %s */ = {', cfg.xcode.targetid, cfgname) - _p(3,'isa = XCBuildConfiguration;') - _p(3,'buildSettings = {') - _p(4,'ALWAYS_SEARCH_USER_PATHS = NO;') - - if not cfg.flags.Symbols then - _p(4,'DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";') - end - - if cfg.kind ~= "StaticLib" and cfg.buildtarget.prefix ~= "" then - _p(4,'EXECUTABLE_PREFIX = %s;', cfg.buildtarget.prefix) - end - - local outdir = path.getdirectory(cfg.buildtarget.bundlepath) - if outdir ~= "." then - _p(4,'CONFIGURATION_BUILD_DIR = %s;', outdir) - end - - _p(4,'GCC_DYNAMIC_NO_PIC = NO;') - _p(4,'GCC_MODEL_TUNING = G5;') - - if tr.infoplist then - _p(4,'INFOPLIST_FILE = "%s";', tr.infoplist.path) - end - - installpaths = { - ConsoleApp = '/usr/local/bin', - WindowedApp = '"$(HOME)/Applications"', - SharedLib = '/usr/local/lib', - StaticLib = '/usr/local/lib', - } - _p(4,'INSTALL_PATH = %s;', installpaths[cfg.kind]) - - _p(4,'PRODUCT_NAME = "%s";', cfg.buildtarget.basename) - _p(3,'};') - _p(3,'name = "%s";', cfgname) - _p(2,'};') - end - - - function xcode.XCBuildConfiguration_Project(tr, cfg) - local cfgname = xcode.getconfigname(cfg) - - _p(2,'%s /* %s */ = {', cfg.xcode.projectid, cfgname) - _p(3,'isa = XCBuildConfiguration;') - _p(3,'buildSettings = {') - - local archs = { - Native = "$(NATIVE_ARCH_ACTUAL)", - x32 = "i386", - x64 = "x86_64", - Universal32 = "$(ARCHS_STANDARD_32_BIT)", - Universal64 = "$(ARCHS_STANDARD_64_BIT)", - Universal = "$(ARCHS_STANDARD_32_64_BIT)", - } - _p(4,'ARCHS = "%s";', archs[cfg.platform]) - - local targetdir = path.getdirectory(cfg.buildtarget.bundlepath) - if targetdir ~= "." then - _p(4,'CONFIGURATION_BUILD_DIR = "$(SYMROOT)";'); - end - - _p(4,'CONFIGURATION_TEMP_DIR = "$(OBJROOT)";') - - if cfg.flags.Symbols then - _p(4,'COPY_PHASE_STRIP = NO;') - end - - _p(4,'GCC_C_LANGUAGE_STANDARD = gnu99;') - - if cfg.flags.NoExceptions then - _p(4,'GCC_ENABLE_CPP_EXCEPTIONS = NO;') - end - - if cfg.flags.NoRTTI then - _p(4,'GCC_ENABLE_CPP_RTTI = NO;') - end - - if _ACTION ~= "xcode4" and cfg.flags.Symbols and not cfg.flags.NoEditAndContinue then - _p(4,'GCC_ENABLE_FIX_AND_CONTINUE = YES;') - end - - if cfg.flags.NoExceptions then - _p(4,'GCC_ENABLE_OBJC_EXCEPTIONS = NO;') - end - - if cfg.flags.Optimize or cfg.flags.OptimizeSize then - _p(4,'GCC_OPTIMIZATION_LEVEL = s;') - elseif cfg.flags.OptimizeSpeed then - _p(4,'GCC_OPTIMIZATION_LEVEL = 3;') - else - _p(4,'GCC_OPTIMIZATION_LEVEL = 0;') - end - - if cfg.pchheader and not cfg.flags.NoPCH then - _p(4,'GCC_PRECOMPILE_PREFIX_HEADER = YES;') - _p(4,'GCC_PREFIX_HEADER = "%s";', cfg.pchheader) - end - - xcode.printlist(cfg.defines, 'GCC_PREPROCESSOR_DEFINITIONS') - - _p(4,'GCC_SYMBOLS_PRIVATE_EXTERN = NO;') - - if cfg.flags.FatalWarnings then - _p(4,'GCC_TREAT_WARNINGS_AS_ERRORS = YES;') - end - - _p(4,'GCC_WARN_ABOUT_RETURN_TYPE = YES;') - _p(4,'GCC_WARN_UNUSED_VARIABLE = YES;') - - xcode.printlist(cfg.includedirs, 'HEADER_SEARCH_PATHS') - xcode.printlist(cfg.libdirs, 'LIBRARY_SEARCH_PATHS') - - _p(4,'OBJROOT = "%s";', cfg.objectsdir) - - _p(4,'ONLY_ACTIVE_ARCH = %s;',iif(premake.config.isdebugbuild(cfg),'YES','NO')) - - -- build list of "other" C/C++ flags - local checks = { - ["-ffast-math"] = cfg.flags.FloatFast, - ["-ffloat-store"] = cfg.flags.FloatStrict, - ["-fomit-frame-pointer"] = cfg.flags.NoFramePointer, - } - - local flags = { } - for flag, check in pairs(checks) do - if check then - table.insert(flags, flag) - end - end - xcode.printlist(table.join(flags, cfg.buildoptions), 'OTHER_CFLAGS') - - -- build list of "other" linked flags. All libraries that aren't frameworks - -- are listed here, so I don't have to try and figure out if they are ".a" - -- or ".dylib", which Xcode requires to list in the Frameworks section - flags = { } - for _, lib in ipairs(premake.getlinks(cfg, "system")) do - if not xcode.isframework(lib) then - table.insert(flags, "-l" .. lib) - end - end - flags = table.join(flags, cfg.linkoptions) - xcode.printlist(flags, 'OTHER_LDFLAGS') - - if cfg.flags.StaticRuntime then - _p(4,'STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = static;') - end - - if targetdir ~= "." then - _p(4,'SYMROOT = "%s";', targetdir) - end - - if cfg.flags.ExtraWarnings then - _p(4,'WARNING_CFLAGS = "-Wall";') - end - - _p(3,'};') - _p(3,'name = "%s";', cfgname) - _p(2,'};') - end - - - function xcode.XCBuildConfiguration(tr) - _p('/* Begin XCBuildConfiguration section */') - for _, target in ipairs(tr.products.children) do - for _, cfg in ipairs(tr.configs) do - xcode.XCBuildConfiguration_Target(tr, target, cfg) - end - end - for _, cfg in ipairs(tr.configs) do - xcode.XCBuildConfiguration_Project(tr, cfg) - end - _p('/* End XCBuildConfiguration section */') - _p('') - end - - - function xcode.XCBuildConfigurationList(tr) - local sln = tr.project.solution - - _p('/* Begin XCConfigurationList section */') - for _, target in ipairs(tr.products.children) do - _p(2,'%s /* Build configuration list for PBXNativeTarget "%s" */ = {', target.cfgsection, target.name) - _p(3,'isa = XCConfigurationList;') - _p(3,'buildConfigurations = (') - for _, cfg in ipairs(tr.configs) do - _p(4,'%s /* %s */,', cfg.xcode.targetid, xcode.getconfigname(cfg)) - end - _p(3,');') - _p(3,'defaultConfigurationIsVisible = 0;') - _p(3,'defaultConfigurationName = "%s";', xcode.getconfigname(tr.configs[1])) - _p(2,'};') - end - _p(2,'1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "%s" */ = {', tr.name) - _p(3,'isa = XCConfigurationList;') - _p(3,'buildConfigurations = (') - for _, cfg in ipairs(tr.configs) do - _p(4,'%s /* %s */,', cfg.xcode.projectid, xcode.getconfigname(cfg)) - end - _p(3,');') - _p(3,'defaultConfigurationIsVisible = 0;') - _p(3,'defaultConfigurationName = "%s";', xcode.getconfigname(tr.configs[1])) - _p(2,'};') - _p('/* End XCConfigurationList section */') - _p('') - end - - - function xcode.Footer() - _p(1,'};') - _p('\trootObject = 08FB7793FE84155DC02AAC07 /* Project object */;') - _p('}') - end Index: ps/trunk/build/premake/premake4/src/actions/xcode/xcode_project.lua =================================================================== --- ps/trunk/build/premake/premake4/src/actions/xcode/xcode_project.lua +++ ps/trunk/build/premake/premake4/src/actions/xcode/xcode_project.lua @@ -1,165 +0,0 @@ --- --- xcode_project.lua --- Generate an Xcode C/C++ project. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - local xcode = premake.xcode - local tree = premake.tree - --- --- Create a tree corresponding to what is shown in the Xcode project browser --- pane, with nodes for files and folders, resources, frameworks, and products. --- --- @param prj --- The project being generated. --- @returns --- A tree, loaded with metadata, which mirrors Xcode's view of the project. --- - - function xcode.buildprjtree(prj) - local tr = premake.project.buildsourcetree(prj) - - -- create a list of build configurations and assign IDs - tr.configs = {} - for _, cfgname in ipairs(prj.solution.configurations) do - for _, platform in ipairs(prj.solution.xcode.platforms) do - local cfg = premake.getconfig(prj, cfgname, platform) - cfg.xcode = {} - cfg.xcode.targetid = xcode.newid(prj.xcode.projectnode, cfgname) - cfg.xcode.projectid = xcode.newid(tr, cfgname) - table.insert(tr.configs, cfg) - end - end - - -- convert localized resources from their filesystem layout (English.lproj/MainMenu.xib) - -- to Xcode's display layout (MainMenu.xib/English). - tree.traverse(tr, { - onbranch = function(node) - if path.getextension(node.name) == ".lproj" then - local lang = path.getbasename(node.name) -- "English", "French", etc. - - -- create a new language group for each file it contains - for _, filenode in ipairs(node.children) do - local grpnode = node.parent.children[filenode.name] - if not grpnode then - grpnode = tree.insert(node.parent, tree.new(filenode.name)) - grpnode.kind = "vgroup" - end - - -- convert the file node to a language node and add to the group - filenode.name = path.getbasename(lang) - tree.insert(grpnode, filenode) - end - - -- remove this directory from the tree - tree.remove(node) - end - end - }) - - -- the special folder "Frameworks" lists all linked frameworks - tr.frameworks = tree.new("Frameworks") - for cfg in premake.eachconfig(prj) do - for _, link in ipairs(premake.getlinks(cfg, "system", "fullpath")) do - local name = path.getname(link) - if xcode.isframework(name) and not tr.frameworks.children[name] then - node = tree.insert(tr.frameworks, tree.new(name)) - node.path = link - end - end - end - - -- only add it to the tree if there are frameworks to link - if #tr.frameworks.children > 0 then - tree.insert(tr, tr.frameworks) - end - - -- the special folder "Products" holds the target produced by the project; this - -- is populated below - tr.products = tree.insert(tr, tree.new("Products")) - - -- the special folder "Projects" lists sibling project dependencies - tr.projects = tree.new("Projects") - for _, dep in ipairs(premake.getdependencies(prj, "sibling", "object")) do - -- create a child node for the dependency's xcodeproj - local xcpath = xcode.getxcodeprojname(dep) - local xcnode = tree.insert(tr.projects, tree.new(path.getname(xcpath))) - xcnode.path = xcpath - xcnode.project = dep - xcnode.productgroupid = xcode.newid(xcnode, "prodgrp") - xcnode.productproxyid = xcode.newid(xcnode, "prodprox") - xcnode.targetproxyid = xcode.newid(xcnode, "targprox") - xcnode.targetdependid = xcode.newid(xcnode, "targdep") - - -- create a grandchild node for the dependency's link target - local cfg = premake.getconfig(dep, prj.configurations[1]) - node = tree.insert(xcnode, tree.new(cfg.linktarget.name)) - node.path = cfg.linktarget.fullpath - node.cfg = cfg - end - - if #tr.projects.children > 0 then - tree.insert(tr, tr.projects) - end - - -- Final setup - tree.traverse(tr, { - onnode = function(node) - -- assign IDs to every node in the tree - node.id = xcode.newid(node) - - -- assign build IDs to buildable files - if xcode.getbuildcategory(node) then - node.buildid = xcode.newid(node, "build") - end - - -- remember key files that are needed elsewhere - if string.endswith(node.name, "Info.plist") then - tr.infoplist = node - end - end - }, true) - - -- Plug in the product node into the Products folder in the tree. The node - -- was built in xcode.preparesolution() in xcode_common.lua; it contains IDs - -- that are necessary for inter-project dependencies - node = tree.insert(tr.products, prj.xcode.projectnode) - node.kind = "product" - node.path = node.cfg.buildtarget.fullpath - node.cfgsection = xcode.newid(node, "cfg") - node.resstageid = xcode.newid(node, "rez") - node.sourcesid = xcode.newid(node, "src") - node.fxstageid = xcode.newid(node, "fxs") - - return tr - end - - --- --- Generate an Xcode .xcodeproj for a Premake project. --- --- @param prj --- The Premake project to generate. --- - - function premake.xcode.project(prj) - local tr = xcode.buildprjtree(prj) - xcode.Header(tr) - xcode.PBXBuildFile(tr) - xcode.PBXContainerItemProxy(tr) - xcode.PBXFileReference(tr) - xcode.PBXFrameworksBuildPhase(tr) - xcode.PBXGroup(tr) - xcode.PBXNativeTarget(tr) - xcode.PBXProject(tr) - xcode.PBXReferenceProxy(tr) - xcode.PBXResourcesBuildPhase(tr) - xcode.PBXShellScriptBuildPhase(tr) - xcode.PBXSourcesBuildPhase(tr) - xcode.PBXVariantGroup(tr) - xcode.PBXTargetDependency(tr) - xcode.XCBuildConfiguration(tr) - xcode.XCBuildConfigurationList(tr) - xcode.Footer(tr) - end Index: ps/trunk/build/premake/premake4/src/base/action.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/action.lua +++ ps/trunk/build/premake/premake4/src/base/action.lua @@ -1,159 +0,0 @@ --- --- action.lua --- Work with the list of registered actions. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - premake.action = { } - - --- --- The list of registered actions. --- - - premake.action.list = { } - - --- --- Register a new action. --- --- @param a --- The new action object. --- - - function premake.action.add(a) - -- validate the action object, at least a little bit - local missing - for _, field in ipairs({"description", "trigger"}) do - if (not a[field]) then - missing = field - end - end - - if (missing) then - error("action needs a " .. missing, 3) - end - - -- add it to the master list - premake.action.list[a.trigger] = a - end - - --- --- Trigger an action. --- --- @param name --- The name of the action to be triggered. --- @returns --- None. --- - - function premake.action.call(name) - local a = premake.action.list[name] - for sln in premake.solution.each() do - if a.onsolution then - a.onsolution(sln) - end - for prj in premake.solution.eachproject(sln) do - if a.onproject then - a.onproject(prj) - end - end - end - - if a.execute then - a.execute() - end - end - - --- --- Retrieve the current action, as determined by _ACTION. --- --- @return --- The current action, or nil if _ACTION is nil or does not match any action. --- - - function premake.action.current() - return premake.action.get(_ACTION) - end - - --- --- Retrieve an action by name. --- --- @param name --- The name of the action to retrieve. --- @returns --- The requested action, or nil if the action does not exist. --- - - function premake.action.get(name) - return premake.action.list[name] - end - - --- --- Iterator for the list of actions. --- - - function premake.action.each() - -- sort the list by trigger - local keys = { } - for _, action in pairs(premake.action.list) do - table.insert(keys, action.trigger) - end - table.sort(keys) - - local i = 0 - return function() - i = i + 1 - return premake.action.list[keys[i]] - end - end - - --- --- Activates a particular action. --- --- @param name --- The name of the action to activate. --- - - function premake.action.set(name) - _ACTION = name - -- Some actions imply a particular operating system - local action = premake.action.get(name) - if action then - _OS = action.os or _OS - end - end - - --- --- Determines if an action supports a particular language or target type. --- --- @param action --- The action to test. --- @param feature --- The feature to check, either a programming language or a target type. --- @returns --- True if the feature is supported, false otherwise. --- - - function premake.action.supports(action, feature) - if not action then - return false - end - if action.valid_languages then - if table.contains(action.valid_languages, feature) then - return true - end - end - if action.valid_kinds then - if table.contains(action.valid_kinds, feature) then - return true - end - end - return false - end Index: ps/trunk/build/premake/premake4/src/base/api.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/api.lua +++ ps/trunk/build/premake/premake4/src/base/api.lua @@ -1,745 +0,0 @@ --- --- api.lua --- Implementation of the solution, project, and configuration APIs. --- Copyright (c) 2002-2008 Jason Perkins and the Premake project --- - - --- --- Here I define all of the getter/setter functions as metadata. The actual --- functions are built programmatically below. --- - - premake.fields = - { - basedir = - { - kind = "path", - scope = "container", - }, - - buildaction = - { - kind = "string", - scope = "config", - allowed = { - "Compile", - "Copy", - "Embed", - "None" - } - }, - - buildoptions = - { - kind = "list", - scope = "config", - }, - - configurations = - { - kind = "list", - scope = "solution", - }, - - cxxtesthdrfiles = - { - kind = "filelist", - scope = "config", - }, - - cxxtestsrcfiles = - { - kind = "filelist", - scope = "config", - }, - - cxxtestoptions = - { - kind = "string", - scope = "config", - }, - - cxxtestpath = - { - kind = "path", - scope = "solution", - }, - - cxxtestrootfile = - { - kind = "path", - scope = "config", - }, - - cxxtestrootoptions = - { - kind = "string", - scope = "config", - }, - - defines = - { - kind = "list", - scope = "config", - }, - - deploymentoptions = - { - kind = "list", - scope = "config", - }, - - excludes = - { - kind = "filelist", - scope = "config", - }, - - files = - { - kind = "filelist", - scope = "config", - }, - - flags = - { - kind = "list", - scope = "config", - isflags = true, - allowed = { - "EnableSSE", - "EnableSSE2", - "ExtraWarnings", - "FatalWarnings", - "FloatFast", - "FloatStrict", - "Managed", - "MFC", - "NativeWChar", - "No64BitChecks", - "NoDebugHeap", - "NoEditAndContinue", - "NoExceptions", - "NoFramePointer", - "NoImportLib", - "NoManifest", - "NoMinimalRebuild", - "NoNativeWChar", - "NoPCH", - "NoRTTI", - "Optimize", - "OptimizeSize", - "OptimizeSpeed", - "SEH", - "StaticRuntime", - "Symbols", - "Unicode", - "Unsafe", - "WinMain" - } - }, - - framework = - { - kind = "string", - scope = "container", - allowed = { - "1.0", - "1.1", - "2.0", - "3.0", - "3.5", - "4.0" - } - }, - - gnuexternals = - { - kind = "list", - scope = "config", - }, - - imagepath = - { - kind = "path", - scope = "config", - }, - - imageoptions = - { - kind = "list", - scope = "config", - }, - - implibdir = - { - kind = "path", - scope = "config", - }, - - implibextension = - { - kind = "string", - scope = "config", - }, - - implibname = - { - kind = "string", - scope = "config", - }, - - implibprefix = - { - kind = "string", - scope = "config", - }, - - implibsuffix = - { - kind = "string", - scope = "config", - }, - - includedirs = - { - kind = "dirlist", - scope = "config", - }, - - kind = - { - kind = "string", - scope = "config", - allowed = { - "ConsoleApp", - "WindowedApp", - "StaticLib", - "SharedLib" - } - }, - - language = - { - kind = "string", - scope = "container", - allowed = { - "C", - "C++", - "C#" - } - }, - - libdirs = - { - kind = "dirlist", - scope = "config", - }, - - linkoptions = - { - kind = "list", - scope = "config", - }, - - links = - { - kind = "list", - scope = "config", - allowed = function(value) - -- if library name contains a '/' then treat it as a path to a local file - if value:find('/', nil, true) then - value = path.getabsolute(value) - end - return value - end - - }, - - location = - { - kind = "path", - scope = "container", - }, - - nasmformat = - { - kind = "string", - scope = "solution", - }, - - nasmpath = - { - kind = "path", - scope = "solution" - }, - - objdir = - { - kind = "path", - scope = "config", - }, - - pchheader = - { - kind = "path", - scope = "config", - }, - - pchsource = - { - kind = "path", - scope = "config", - }, - - platforms = - { - kind = "list", - scope = "solution", - allowed = table.keys(premake.platforms), - }, - - postbuildcommands = - { - kind = "list", - scope = "config", - }, - - prebuildcommands = - { - kind = "list", - scope = "config", - }, - - prelinkcommands = - { - kind = "list", - scope = "config", - }, - - resdefines = - { - kind = "list", - scope = "config", - }, - - resincludedirs = - { - kind = "dirlist", - scope = "config", - }, - - resoptions = - { - kind = "list", - scope = "config", - }, - - targetdir = - { - kind = "path", - scope = "config", - }, - - targetextension = - { - kind = "string", - scope = "config", - }, - - targetname = - { - kind = "string", - scope = "config", - }, - - targetprefix = - { - kind = "string", - scope = "config", - }, - - targetsuffix = - { - kind = "string", - scope = "config", - }, - - trimpaths = - { - kind = "dirlist", - scope = "config", - }, - - uuid = - { - kind = "string", - scope = "container", - allowed = function(value) - local ok = true - if (#value ~= 36) then ok = false end - for i=1,36 do - local ch = value:sub(i,i) - if (not ch:find("[ABCDEFabcdef0123456789-]")) then ok = false end - end - if (value:sub(9,9) ~= "-") then ok = false end - if (value:sub(14,14) ~= "-") then ok = false end - if (value:sub(19,19) ~= "-") then ok = false end - if (value:sub(24,24) ~= "-") then ok = false end - if (not ok) then - return nil, "invalid UUID" - end - return value:upper() - end - }, - } - - --- --- End of metadata --- - - - --- --- Check to see if a value exists in a list of values, using a --- case-insensitive match. If the value does exist, the canonical --- version contained in the list is returned, so future tests can --- use case-sensitive comparisions. --- - - function premake.checkvalue(value, allowed) - if (allowed) then - if (type(allowed) == "function") then - return allowed(value) - else - for _,v in ipairs(allowed) do - if (value:lower() == v:lower()) then - return v - end - end - return nil, "invalid value '" .. value .. "'" - end - else - return value - end - end - - - --- --- Retrieve the current object of a particular type from the session. The --- type may be "solution", "container" (the last activated solution or --- project), or "config" (the last activated configuration). Returns the --- requested container, or nil and an error message. --- - - function premake.getobject(t) - local container - - if (t == "container" or t == "solution") then - container = premake.CurrentContainer - else - container = premake.CurrentConfiguration - end - - if t == "solution" then - if type(container) == "project" then - container = container.solution - end - if type(container) ~= "solution" then - container = nil - end - end - - local msg - if (not container) then - if (t == "container") then - msg = "no active solution or project" - elseif (t == "solution") then - msg = "no active solution" - else - msg = "no active solution, project, or configuration" - end - end - - return container, msg - end - - - --- --- Adds values to an array field of a solution/project/configuration. `ctype` --- specifies the container type (see premake.getobject) for the field. --- - - function premake.setarray(ctype, fieldname, value, allowed) - local container, err = premake.getobject(ctype) - if (not container) then - error(err, 4) - end - - if (not container[fieldname]) then - container[fieldname] = { } - end - - local function doinsert(value, depth) - if (type(value) == "table") then - for _,v in ipairs(value) do - doinsert(v, depth + 1) - end - else - value, err = premake.checkvalue(value, allowed) - if (not value) then - error(err, depth) - end - table.insert(container[fieldname], value) - end - end - - if (value) then - doinsert(value, 5) - end - - return container[fieldname] - end - - - --- --- Adds values to an array-of-directories field of a solution/project/configuration. --- `ctype` specifies the container type (see premake.getobject) for the field. All --- values are converted to absolute paths before being stored. --- - - local function domatchedarray(ctype, fieldname, value, matchfunc) - local result = { } - - function makeabsolute(value, depth) - if (type(value) == "table") then - for _, item in ipairs(value) do - makeabsolute(item, depth + 1) - end - elseif type(value) == "string" then - if value:find("*") then - makeabsolute(matchfunc(value), depth + 1) - else - table.insert(result, path.getabsolute(value)) - end - else - error("Invalid value in list: expected string, got " .. type(value), depth) - end - end - - makeabsolute(value, 3) - return premake.setarray(ctype, fieldname, result) - end - - function premake.setdirarray(ctype, fieldname, value) - return domatchedarray(ctype, fieldname, value, os.matchdirs) - end - - function premake.setfilearray(ctype, fieldname, value) - return domatchedarray(ctype, fieldname, value, os.matchfiles) - end - - - --- --- Set a new value for a string field of a solution/project/configuration. `ctype` --- specifies the container type (see premake.getobject) for the field. --- - - function premake.setstring(ctype, fieldname, value, allowed) - -- find the container for this value - local container, err = premake.getobject(ctype) - if (not container) then - error(err, 4) - end - - -- if a value was provided, set it - if (value) then - value, err = premake.checkvalue(value, allowed) - if (not value) then - error(err, 4) - end - - container[fieldname] = value - end - - return container[fieldname] - end - - - --- --- The getter/setter implemention. --- - - local function accessor(name, value) - local kind = premake.fields[name].kind - local scope = premake.fields[name].scope - local allowed = premake.fields[name].allowed - - if ((kind == "string" or kind == "path") and value) then - if type(value) ~= "string" then - error("string value expected", 3) - end - end - - if (kind == "string") then - return premake.setstring(scope, name, value, allowed) - elseif (kind == "path") then - if value then value = path.getabsolute(value) end - return premake.setstring(scope, name, value) - elseif (kind == "list") then - return premake.setarray(scope, name, value, allowed) - elseif (kind == "dirlist") then - return premake.setdirarray(scope, name, value) - elseif (kind == "filelist") then - return premake.setfilearray(scope, name, value) - end - end - - - --- --- Build all of the getter/setter functions from the metadata above. --- - - for name,_ in pairs(premake.fields) do - _G[name] = function(value) - return accessor(name, value) - end - end - - - --- --- Project object constructors. --- - - function configuration(terms) - if not terms then - return premake.CurrentConfiguration - end - - local container, err = premake.getobject("container") - if (not container) then - error(err, 2) - end - - local cfg = { } - cfg.terms = table.flatten({terms}) - - table.insert(container.blocks, cfg) - premake.CurrentConfiguration = cfg - - -- create a keyword list using just the indexed keyword items. This is a little - -- confusing: "terms" are what the user specifies in the script, "keywords" are - -- the Lua patterns that result. I'll refactor to better names. - cfg.keywords = { } - for _, word in ipairs(cfg.terms) do - table.insert(cfg.keywords, path.wildcards(word):lower()) - end - - -- initialize list-type fields to empty tables - for name, field in pairs(premake.fields) do - if (field.kind ~= "string" and field.kind ~= "path") then - cfg[name] = { } - end - end - - return cfg - end - - - function project(name) - if not name then - return iif(type(premake.CurrentContainer) == "project", premake.CurrentContainer, nil) - end - - -- identify the parent solution - local sln - if (type(premake.CurrentContainer) == "project") then - sln = premake.CurrentContainer.solution - else - sln = premake.CurrentContainer - end - if (type(sln) ~= "solution") then - error("no active solution", 2) - end - - -- if this is a new project, create it - premake.CurrentContainer = sln.projects[name] - if (not premake.CurrentContainer) then - local prj = { } - premake.CurrentContainer = prj - - -- add to master list keyed by both name and index - table.insert(sln.projects, prj) - sln.projects[name] = prj - - -- attach a type - setmetatable(prj, { - __type = "project", - }) - - prj.solution = sln - prj.name = name - prj.basedir = os.getcwd() - prj.uuid = os.uuid() - prj.blocks = { } - end - - -- add an empty, global configuration to the project - configuration { } - - return premake.CurrentContainer - end - - - function solution(name) - if not name then - if type(premake.CurrentContainer) == "project" then - return premake.CurrentContainer.solution - else - return premake.CurrentContainer - end - end - - premake.CurrentContainer = premake.solution.get(name) - if (not premake.CurrentContainer) then - premake.CurrentContainer = premake.solution.new(name) - end - - -- add an empty, global configuration - configuration { } - - return premake.CurrentContainer - end - - --- --- Define a new action. --- --- @param a --- The new action object. --- - - function newaction(a) - premake.action.add(a) - end - - --- --- Define a new option. --- --- @param opt --- The new option object. --- - - function newoption(opt) - premake.option.add(opt) - end Index: ps/trunk/build/premake/premake4/src/base/cmdline.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/cmdline.lua +++ ps/trunk/build/premake/premake4/src/base/cmdline.lua @@ -1,90 +0,0 @@ --- --- cmdline.lua --- Functions to define and handle command line actions and options. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - --- --- Built-in command line options --- - - newoption - { - trigger = "cc", - value = "VALUE", - description = "Choose a C/C++ compiler set", - allowed = { - { "gcc", "GNU GCC (gcc/g++)" }, - { "ow", "OpenWatcom" }, - } - } - - newoption - { - trigger = "dotnet", - value = "VALUE", - description = "Choose a .NET compiler set", - allowed = { - { "msnet", "Microsoft .NET (csc)" }, - { "mono", "Novell Mono (mcs)" }, - { "pnet", "Portable.NET (cscc)" }, - } - } - - newoption - { - trigger = "file", - value = "FILE", - description = "Read FILE as a Premake script; default is 'premake4.lua'" - } - - newoption - { - trigger = "help", - description = "Display this information" - } - - newoption - { - trigger = "os", - value = "VALUE", - description = "Generate files for a different operating system", - allowed = { - { "bsd", "OpenBSD, NetBSD, or FreeBSD" }, - { "linux", "Linux" }, - { "macosx", "Apple Mac OS X" }, - { "solaris", "Solaris" }, - { "windows", "Microsoft Windows" }, - } - } - - newoption - { - trigger = "platform", - value = "VALUE", - description = "Add target architecture (if supported by action)", - allowed = { - { "x32", "32-bit" }, - { "x64", "64-bit" }, - { "universal", "Mac OS X Universal, 32- and 64-bit" }, - { "universal32", "Mac OS X Universal, 32-bit only" }, - { "universal64", "Mac OS X Universal, 64-bit only" }, - { "ps3", "Playstation 3 (experimental)" }, - { "xbox360", "Xbox 360 (experimental)" }, - } - } - - newoption - { - trigger = "scripts", - value = "path", - description = "Search for additional scripts on the given path" - } - - newoption - { - trigger = "version", - description = "Display version information" - } - \ No newline at end of file Index: ps/trunk/build/premake/premake4/src/base/configs.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/configs.lua +++ ps/trunk/build/premake/premake4/src/base/configs.lua @@ -1,502 +0,0 @@ --- --- configs.lua --- --- Functions for working with configuration objects (which can include --- projects and solutions). --- --- This script also contains the configuration "baking" logic (though I --- would like to eventually move this out to a different file): --- Once the project scripts have been run, flatten all of the configuration --- data down into simpler objects, keeping only the settings that apply to --- the current runtime environment. --- --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - premake.config = { } - - --- --- Determine if a configuration represents a "debug" or "release" build. --- This controls the runtime library selected for Visual Studio builds --- (and might also be useful elsewhere). --- --- @param cfg --- The configuration object to test. --- @returns --- True if the configuration represents a debug build; false otherwise. --- - - function premake.config.isdebugbuild(cfg) - -- If any of the optimize flags are set, it's a release a build - if cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed then - return false - end - -- If symbols are not defined, it's a release build - if not cfg.flags.Symbols then - return false - end - return true - end - - -------------------------------------------------------------------------- --- Configuration Baking Logic -------------------------------------------------------------------------- - - -- do not copy these fields into the configurations - local nocopy = - { - blocks = true, - keywords = true, - projects = true, - __configs = true, - } - - -- leave these paths as absolute, rather than converting to project relative - local nofixup = - { - basedir = true, - location = true, - } - - - --- --- Returns a list of all of the active terms from the current environment. --- See the docs for configuration() for more information about the terms. --- - - function premake.getactiveterms() - local terms = { _ACTION:lower(), os.get() } - - -- add option keys or values - for key, value in pairs(_OPTIONS) do - if value ~= "" then - table.insert(terms, value:lower()) - else - table.insert(terms, key:lower()) - end - end - - return terms - end - - --- --- Test a single configuration block keyword against a list of terms. --- The terms are a mix of key/value pairs. The keyword is tested against --- the values; on a match, the corresponding key is returned. This --- enables testing for required values in iskeywordsmatch(), below. --- - - function premake.iskeywordmatch(keyword, terms) - -- is it negated? - if keyword:startswith("not ") then - return not premake.iskeywordmatch(keyword:sub(5), terms) - end - - for _, pattern in ipairs(keyword:explode(" or ")) do --- local pattern = "^" .. word .. "$" - for termkey, term in pairs(terms) do - if term:match(pattern) == term then - return termkey - end - end - end - end - - - --- --- Checks a set of configuration block keywords against a list of terms. --- I've already forgotten the purpose of the required terms (d'oh!) but --- I'll see if I can figure it out on a future refactoring. --- - - function premake.iskeywordsmatch(keywords, terms) - local hasrequired = false - for _, keyword in ipairs(keywords) do - local matched = premake.iskeywordmatch(keyword, terms) - if not matched then - return false - end - if matched == "required" then - hasrequired = true - end - end - - if terms.required and not hasrequired then - return false - else - return true - end - end - - --- --- Converts path fields from absolute to location-relative paths. --- --- @param location --- The base location, paths will be relative to this directory. --- @param obj --- The object containing the fields to be adjusted. --- - - local function adjustpaths(location, obj) - for name, value in pairs(obj) do - local field = premake.fields[name] - if field and value and not nofixup[name] then - if field.kind == "path" then - obj[name] = path.getrelative(location, value) - elseif field.kind == "dirlist" or field.kind == "filelist" then - for i, p in ipairs(value) do - value[i] = path.getrelative(location, p) - end - end - end - end - end - - - --- --- Merge all of the fields from one object into another. String values are overwritten, --- while list values are merged. Fields listed in premake.nocopy are skipped. --- --- @param dest --- The destination object, to contain the merged settings. --- @param src --- The source object, containing the settings to added to the destination. --- - - local function mergeobject(dest, src) - if not src then return end - for field, value in pairs(src) do - if not nocopy[field] then - if type(value) == "table" then - -- merge two lists, removing any duplicates along the way - local tbl = dest[field] or { } - for _, item in ipairs(value) do - if not tbl[item] then - table.insert(tbl, item) - tbl[item] = item - end - end - dest[field] = tbl - else - dest[field] = value - end - end - end - end - - - --- --- Merges the settings from a solution's or project's list of configuration blocks, --- for all blocks that match the provided set of environment terms. --- --- @param dest --- The destination object, to contain the merged settings. --- @param obj --- The solution or project object being collapsed. --- @param basis --- "Root" level settings, from the solution, which act as a starting point for --- all of the collapsed settings built during this call. --- @param terms --- A list of keywords to filter the configuration blocks; only those that --- match will be included in the destination. --- @param cfgname --- The name of the configuration being collapsed. May be nil. --- @param pltname --- The name of the platform being collapsed. May be nil. --- - - local function merge(dest, obj, basis, terms, cfgname, pltname) - -- the configuration key is the merged configuration and platform names - local key = cfgname or "" - pltname = pltname or "Native" - if pltname ~= "Native" then - key = key .. pltname - end - - -- add the configuration and platform to the block filter terms - terms.config = (cfgname or ""):lower() - terms.platform = pltname:lower() - - -- build the configuration base by merging the solution and project level settings - local cfg = {} - mergeobject(cfg, basis[key]) - adjustpaths(obj.location, cfg) - mergeobject(cfg, obj) - - -- add `kind` to the filter terms - if (cfg.kind) then - terms.kind = cfg.kind:lower() - end - - -- now add in any blocks that match the filter terms - for _, blk in ipairs(obj.blocks) do - if (premake.iskeywordsmatch(blk.keywords, terms)) then - mergeobject(cfg, blk) - end - end - - -- package it all up and add it to the result set - cfg.name = cfgname - cfg.platform = pltname - cfg.terms = terms - dest[key] = cfg - end - - - --- --- Collapse a solution or project object down to a canonical set of configuration settings, --- keyed by configuration block/platform pairs, and taking into account the current --- environment settings. --- --- @param obj --- The solution or project to be collapsed. --- @param basis --- "Root" level settings, from the solution, which act as a starting point for --- all of the collapsed settings built during this call. --- @returns --- The collapsed list of settings, keyed by configuration block/platform pair. --- - - local function collapse(obj, basis) - local result = {} - basis = basis or {} - - -- find the solution, which contains the configuration and platform lists - local sln = obj.solution or obj - - -- build a set of configuration filter terms; only those configuration blocks - -- with a matching set of keywords will be included in the merged results - local terms = premake.getactiveterms() - - -- build a project-level configuration. If a target kind is set at this level - -- then include it into the filter terms - merge(result, obj, basis, terms) - -- if result[""].kind then - -- terms.kind = result[""].kind:lower() - -- end - - -- now build configurations for each build config/platform pair - for _, cfgname in ipairs(sln.configurations) do - merge(result, obj, basis, terms, cfgname, "Native") - for _, pltname in ipairs(sln.platforms or {}) do - if pltname ~= "Native" then - merge(result, obj, basis, terms, cfgname, pltname) - end - end - end - - return result - end - - --- --- Post-process a project configuration, applying path fix-ups and other adjustments --- to the "raw" setting data pulled from the project script. --- --- @param prj --- The project object which contains the configuration. --- @param cfg --- The configuration object to be fixed up. --- - - local function postprocess(prj, cfg) - cfg.project = prj - cfg.shortname = premake.getconfigname(cfg.name, cfg.platform, true) - cfg.longname = premake.getconfigname(cfg.name, cfg.platform) - - -- set the project location, if not already set - cfg.location = cfg.location or cfg.basedir - - -- figure out the target system - local platform = premake.platforms[cfg.platform] - if platform.iscrosscompiler then - cfg.system = cfg.platform - else - cfg.system = os.get() - end - - -- adjust the kind as required by the target system - if cfg.kind == "SharedLib" and platform.nosharedlibs then - cfg.kind = "StaticLib" - end - - -- remove excluded files from the file list - local files = { } - for _, fname in ipairs(cfg.files) do - local excluded = false - for _, exclude in ipairs(cfg.excludes) do - excluded = (fname == exclude) - if (excluded) then break end - end - - if (not excluded) then - table.insert(files, fname) - end - end - cfg.files = files - - -- fixup the data - for name, field in pairs(premake.fields) do - -- re-key flag fields for faster lookups - if field.isflags then - local values = cfg[name] - for _, flag in ipairs(values) do values[flag] = true end - end - end - - -- build configuration objects for all files - cfg.__fileconfigs = { } - for _, fname in ipairs(cfg.files) do - cfg.terms.required = fname:lower() - local fcfg = {} - for _, blk in ipairs(cfg.project.blocks) do - if (premake.iskeywordsmatch(blk.keywords, cfg.terms)) then - mergeobject(fcfg, blk) - end - end - - -- add indexed by name and integer - fcfg.name = fname - cfg.__fileconfigs[fname] = fcfg - table.insert(cfg.__fileconfigs, fcfg) - end - end - - - --- --- Computes a unique objects directory for every configuration, using the --- following choices: --- [1] -> the objects directory as set in the project of config --- [2] -> [1] + the platform name --- [3] -> [2] + the configuration name --- [4] -> [3] + the project name --- - - local function builduniquedirs() - local num_variations = 4 - - -- Start by listing out each possible object directory for each configuration. - -- Keep a count of how many times each path gets used across the session. - local cfg_dirs = {} - local hit_counts = {} - - for sln in premake.solution.each() do - for _, prj in ipairs(sln.projects) do - for _, cfg in pairs(prj.__configs) do - - local dirs = { } - dirs[1] = path.getabsolute(path.join(cfg.location, cfg.objdir or cfg.project.objdir or "obj")) - dirs[2] = path.join(dirs[1], iif(cfg.platform == "Native", "", cfg.platform)) - dirs[3] = path.join(dirs[2], cfg.name) - dirs[4] = path.join(dirs[3], cfg.project.name) - cfg_dirs[cfg] = dirs - - -- configurations other than the root should bias toward a more - -- description path, including the platform or config name - local start = iif(cfg.name, 2, 1) - for v = start, num_variations do - local d = dirs[v] - hit_counts[d] = (hit_counts[d] or 0) + 1 - end - - end - end - end - - -- Now assign an object directory to each configuration, skipping those - -- that are in use somewhere else in the session - for sln in premake.solution.each() do - for _, prj in ipairs(sln.projects) do - for _, cfg in pairs(prj.__configs) do - - local dir - local start = iif(cfg.name, 2, 1) - for v = start, num_variations do - dir = cfg_dirs[cfg][v] - if hit_counts[dir] == 1 then break end - end - cfg.objectsdir = path.getrelative(cfg.location, dir) - end - end - end - - end - - - --- --- Pre-computes the build and link targets for a configuration. --- - - local function buildtargets() - for sln in premake.solution.each() do - for _, prj in ipairs(sln.projects) do - for _, cfg in pairs(prj.__configs) do - -- determine which conventions the target should follow for this config - local pathstyle = premake.getpathstyle(cfg) - local namestyle = premake.getnamestyle(cfg) - - -- build the targets - cfg.buildtarget = premake.gettarget(cfg, "build", pathstyle, namestyle, cfg.system) - cfg.linktarget = premake.gettarget(cfg, "link", pathstyle, namestyle, cfg.system) - if pathstyle == "windows" then - cfg.objectsdir = path.translate(cfg.objectsdir, "\\") - end - - end - end - end - end - - - --- --- Takes the configuration information stored in solution->project->block --- hierarchy and flattens it all down into one object per configuration. --- These objects are cached with the project, and can be retrieved by --- calling the getconfig() or the eachconfig() iterator function. --- - - function premake.buildconfigs() - - -- convert project path fields to be relative to project location - for sln in premake.solution.each() do - for _, prj in ipairs(sln.projects) do - prj.location = prj.location or sln.location or prj.basedir - adjustpaths(prj.location, prj) - for _, blk in ipairs(prj.blocks) do - adjustpaths(prj.location, blk) - end - end - sln.location = sln.location or sln.basedir - end - - -- collapse configuration blocks, so that there is only one block per build - -- configuration/platform pair, filtered to the current operating environment - for sln in premake.solution.each() do - local basis = collapse(sln) - for _, prj in ipairs(sln.projects) do - prj.__configs = collapse(prj, basis) - for _, cfg in pairs(prj.__configs) do - postprocess(prj, cfg) - end - end - end - - -- assign unique object directories to each configuration - builduniquedirs() - - -- walk it again and build the targets and unique directories - buildtargets(cfg) - - end Index: ps/trunk/build/premake/premake4/src/base/globals.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/globals.lua +++ ps/trunk/build/premake/premake4/src/base/globals.lua @@ -1,145 +0,0 @@ --- --- globals.lua --- Global tables and variables, replacements and extensions to Lua's global functions. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - --- A top-level namespace for support functions - - premake = { } - - --- The list of supported platforms; also update list in cmdline.lua - - premake.platforms = - { - Native = - { - cfgsuffix = "", - }, - x32 = - { - cfgsuffix = "32", - }, - x64 = - { - cfgsuffix = "64", - }, - Universal = - { - cfgsuffix = "univ", - }, - Universal32 = - { - cfgsuffix = "univ32", - }, - Universal64 = - { - cfgsuffix = "univ64", - }, - PS3 = - { - cfgsuffix = "ps3", - iscrosscompiler = true, - nosharedlibs = true, - namestyle = "PS3", - }, - Xbox360 = - { - cfgsuffix = "xbox360", - iscrosscompiler = true, - namestyle = "windows", - }, - } - - --- --- A replacement for Lua's built-in dofile() function, this one sets the --- current working directory to the script's location, enabling script-relative --- referencing of other files and resources. --- - - local builtin_dofile = dofile - function dofile(fname) - -- remember the current working directory and file; I'll restore it shortly - local oldcwd = os.getcwd() - local oldfile = _SCRIPT - - -- if the file doesn't exist, check the search path - if (not os.isfile(fname)) then - local path = os.pathsearch(fname, _OPTIONS["scripts"], os.getenv("PREMAKE_PATH")) - if (path) then - fname = path.."/"..fname - end - end - - -- use the absolute path to the script file, to avoid any file name - -- ambiguity if an error should arise - _SCRIPT = path.getabsolute(fname) - - -- switch the working directory to the new script location - local newcwd = path.getdirectory(_SCRIPT) - os.chdir(newcwd) - - -- run the chunk. How can I catch variable return values? - local a, b, c, d, e, f = builtin_dofile(_SCRIPT) - - -- restore the previous working directory when done - _SCRIPT = oldfile - os.chdir(oldcwd) - return a, b, c, d, e, f - end - - - --- --- "Immediate If" - returns one of the two values depending on the value of expr. --- - - function iif(expr, trueval, falseval) - if (expr) then - return trueval - else - return falseval - end - end - - - --- --- A shortcut for including another "premake4.lua" file, often used for projects. --- - - function include(fname) - return dofile(fname .. "/premake4.lua") - end - - - --- --- A shortcut for printing formatted output. --- - - function printf(msg, ...) - print(string.format(msg, unpack(arg))) - end - - - --- --- An extension to type() to identify project object types by reading the --- "__type" field from the metatable. --- - - local builtin_type = type - function type(t) - local mt = getmetatable(t) - if (mt) then - if (mt.__type) then - return mt.__type - end - end - return builtin_type(t) - end - \ No newline at end of file Index: ps/trunk/build/premake/premake4/src/base/help.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/help.lua +++ ps/trunk/build/premake/premake4/src/base/help.lua @@ -1,51 +0,0 @@ --- --- help.lua --- User help, displayed on /help option. --- Copyright (c) 2002-2008 Jason Perkins and the Premake project --- - - - function premake.showhelp() - - -- display the basic usage - printf("Premake %s, a build script generator", _PREMAKE_VERSION) - printf(_PREMAKE_COPYRIGHT) - printf("%s %s", _VERSION, _COPYRIGHT) - printf("") - printf("Usage: premake4 [options] action [arguments]") - printf("") - - - -- display all options - printf("OPTIONS") - printf("") - for option in premake.option.each() do - local trigger = option.trigger - local description = option.description - if (option.value) then trigger = trigger .. "=" .. option.value end - if (option.allowed) then description = description .. "; one of:" end - - printf(" --%-15s %s", trigger, description) - if (option.allowed) then - for _, value in ipairs(option.allowed) do - printf(" %-14s %s", value[1], value[2]) - end - end - printf("") - end - - -- display all actions - printf("ACTIONS") - printf("") - for action in premake.action.each() do - printf(" %-17s %s", action.trigger, action.description) - end - printf("") - - - -- see more - printf("For additional information, see http://industriousone.com/premake") - - end - - Index: ps/trunk/build/premake/premake4/src/base/io.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/io.lua +++ ps/trunk/build/premake/premake4/src/base/io.lua @@ -1,81 +0,0 @@ --- --- io.lua --- Additions to the I/O namespace. --- Copyright (c) 2008-2009 Jason Perkins and the Premake project --- - - --- --- Prepare to capture the output from all subsequent calls to io.printf(), --- used for automated testing of the generators. --- - - function io.capture() - io.captured = '' - end - - - --- --- Returns the captured text and stops capturing. --- - - function io.endcapture() - local captured = io.captured - io.captured = nil - return captured - end - - --- --- Open an overload of the io.open() function, which will create any missing --- subdirectories in the filename if "mode" is set to writeable. --- - - local builtin_open = io.open - function io.open(fname, mode) - if (mode) then - if (mode:find("w")) then - local dir = path.getdirectory(fname) - ok, err = os.mkdir(dir) - if (not ok) then - error(err, 0) - end - end - end - return builtin_open(fname, mode) - end - - - --- --- A shortcut for printing formatted output to an output stream. --- - - function io.printf(msg, ...) - if (not io.eol) then - io.eol = "\n" - end - - local s - if type(msg) == "number" then - s = string.rep("\t", msg) .. string.format(unpack(arg)) - else - s = string.format(msg, unpack(arg)) - end - - if io.captured then - io.captured = io.captured .. s .. io.eol - else - io.write(s) - io.write(io.eol) - end - end - - --- --- Because I use io.printf() so often in the generators, create a terse shortcut --- for it. This saves me typing, and also reduces the size of the executable. --- - - _p = io.printf Index: ps/trunk/build/premake/premake4/src/base/option.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/option.lua +++ ps/trunk/build/premake/premake4/src/base/option.lua @@ -1,107 +0,0 @@ --- --- option.lua --- Work with the list of registered options. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - premake.option = { } - - --- --- The list of registered options. --- - - premake.option.list = { } - - --- --- Register a new option. --- --- @param opt --- The new option object. --- - - function premake.option.add(opt) - -- some sanity checking - local missing - for _, field in ipairs({ "description", "trigger" }) do - if (not opt[field]) then - missing = field - end - end - - if (missing) then - error("option needs a " .. missing, 3) - end - - -- add it to the master list - premake.option.list[opt.trigger] = opt - end - - --- --- Retrieve an option by name. --- --- @param name --- The name of the option to retrieve. --- @returns --- The requested option, or nil if the option does not exist. --- - - function premake.option.get(name) - return premake.option.list[name] - end - - --- --- Iterator for the list of options. --- - - function premake.option.each() - -- sort the list by trigger - local keys = { } - for _, option in pairs(premake.option.list) do - table.insert(keys, option.trigger) - end - table.sort(keys) - - local i = 0 - return function() - i = i + 1 - return premake.option.list[keys[i]] - end - end - - --- --- Validate a list of user supplied key/value pairs against the list of registered options. --- --- @param values --- The list of user supplied key/value pairs. --- @returns ---- True if the list of pairs are valid, false and an error message otherwise. --- - - function premake.option.validate(values) - for key, value in pairs(values) do - -- does this option exist - local opt = premake.option.get(key) - if (not opt) then - return false, "invalid option '" .. key .. "'" - end - - -- does it need a value? - if (opt.value and value == "") then - return false, "no value specified for option '" .. key .. "'" - end - - -- is the value allowed? - if (opt.allowed) then - for _, match in ipairs(opt.allowed) do - if (match[1] == value) then return true end - end - return false, "invalid value '" .. value .. "' for option '" .. key .. "'" - end - end - return true - end Index: ps/trunk/build/premake/premake4/src/base/os.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/os.lua +++ ps/trunk/build/premake/premake4/src/base/os.lua @@ -1,290 +0,0 @@ --- --- os.lua --- Additions to the OS namespace. --- Copyright (c) 2002-2011 Jason Perkins and the Premake project --- - - --- --- Same as os.execute(), but accepts string formatting arguments. --- - - function os.executef(cmd, ...) - cmd = string.format(cmd, unpack(arg)) - return os.execute(cmd) - end - - --- --- Scan the well-known system locations for a particular library. --- - - local function parse_ld_so_conf(conf_file) - -- Linux ldconfig file parser to find system library locations - local first, last - local dirs = { } - local file = io.open(conf_file) - -- Handle missing ld.so.conf (BSDs) gracefully - if file == nil then - return dirs - end - for line in file:lines() do - -- ignore comments - first = line:find("#", 1, true) - if first ~= nil then - line = line:sub(1, first - 1) - end - - if line ~= "" then - -- check for include files - first, last = line:find("include%s+") - if first ~= nil then - -- found include glob - local include_glob = line:sub(last + 1) - local includes = os.matchfiles(include_glob) - for _, v in ipairs(includes) do - dirs = table.join(dirs, parse_ld_so_conf(v)) - end - else - -- found an actual ld path entry - table.insert(dirs, line) - end - end - end - return dirs - end - - function os.findlib(libname) - local path, formats - - -- assemble a search path, depending on the platform - if os.is("windows") then - formats = { "%s.dll", "%s" } - path = os.getenv("PATH") - elseif os.is("haiku") then - formats = { "lib%s.so", "%s.so" } - path = os.getenv("LIBRARY_PATH") - else - if os.is("macosx") then - formats = { "lib%s.dylib", "%s.dylib" } - path = os.getenv("DYLD_LIBRARY_PATH") - else - formats = { "lib%s.so", "%s.so" } - path = os.getenv("LD_LIBRARY_PATH") or "" - - for _, v in ipairs(parse_ld_so_conf("/etc/ld.so.conf")) do - path = path .. ":" .. v - end - end - - table.insert(formats, "%s") - path = path or "" - if os.is64bit() then - path = path .. ":/lib64:/usr/lib64/:usr/local/lib64" - end - path = path .. ":/lib:/usr/lib:/usr/local/lib" - end - - for _, fmt in ipairs(formats) do - local name = string.format(fmt, libname) - local result = os.pathsearch(name, path) - if result then return result end - end - end - - - --- --- Retrieve the current operating system ID string. --- - - function os.get() - return _OPTIONS.os or _OS - end - - - --- --- Check the current operating system; may be set with the /os command line flag. --- - - function os.is(id) - return (os.get():lower() == id:lower()) - end - - - --- --- Determine if the current system is running a 64-bit architecture --- - - local _64BitHostTypes = { - "x86_64", - "ia64", - "amd64", - "ppc64", - "powerpc64", - "sparc64" - } - - function os.is64bit() - - -- Identify the system - local arch - if _OS == "windows" then - arch = os.getenv("PROCESSOR_ARCHITECTURE") - elseif _OS == "macosx" then - arch = os.outputof("echo $HOSTTYPE") - else - arch = os.outputof("uname -m") - end - - -- Check our known 64-bit identifiers - arch = arch:lower() - for _, hosttype in ipairs(_64BitHostTypes) do - if arch:find(hosttype) then - return true - end - end - return false - end - - - --- --- The os.matchdirs() and os.matchfiles() functions --- - - local function domatch(result, mask, wantfiles) - -- need to remove extraneous path info from the mask to ensure a match - -- against the paths returned by the OS. Haven't come up with a good - -- way to do it yet, so will handle cases as they come up - if mask:startswith("./") then - mask = mask:sub(3) - end - - -- strip off any leading directory information to find out - -- where the search should take place - local basedir = mask - local starpos = mask:find("%*") - if starpos then - basedir = basedir:sub(1, starpos - 1) - end - basedir = path.getdirectory(basedir) - if (basedir == ".") then basedir = "" end - - -- recurse into subdirectories? - local recurse = mask:find("**", nil, true) - - -- convert mask to a Lua pattern - mask = path.wildcards(mask) - - local function matchwalker(basedir) - local wildcard = path.join(basedir, "*") - - -- retrieve files from OS and test against mask - local m = os.matchstart(wildcard) - while (os.matchnext(m)) do - local isfile = os.matchisfile(m) - if ((wantfiles and isfile) or (not wantfiles and not isfile)) then - local fname = path.join(basedir, os.matchname(m)) - if fname:match(mask) == fname then - table.insert(result, fname) - end - end - end - os.matchdone(m) - - -- check subdirectories - if recurse then - m = os.matchstart(wildcard) - while (os.matchnext(m)) do - if not os.matchisfile(m) then - local dirname = os.matchname(m) - matchwalker(path.join(basedir, dirname)) - end - end - os.matchdone(m) - end - end - - matchwalker(basedir) - end - - function os.matchdirs(...) - local result = { } - for _, mask in ipairs(arg) do - domatch(result, mask, false) - end - return result - end - - function os.matchfiles(...) - local result = { } - for _, mask in ipairs(arg) do - domatch(result, mask, true) - end - return result - end - - - --- --- An overload of the os.mkdir() function, which will create any missing --- subdirectories along the path. --- - - local builtin_mkdir = os.mkdir - function os.mkdir(p) - local dir = iif(p:startswith("/"), "/", "") - for part in p:gmatch("[^/]+") do - dir = dir .. part - - if (part ~= "" and not path.isabsolute(part) and not os.isdir(dir)) then - local ok, err = builtin_mkdir(dir) - if (not ok) then - return nil, err - end - end - - dir = dir .. "/" - end - - return true - end - - --- --- Run a shell command and return the output. --- - - function os.outputof(cmd) - local pipe = io.popen(cmd) - local result = pipe:read('*a') - pipe:close() - return result - end - - --- --- Remove a directory, along with any contained files or subdirectories. --- - - local builtin_rmdir = os.rmdir - function os.rmdir(p) - -- recursively remove subdirectories - local dirs = os.matchdirs(p .. "/*") - for _, dname in ipairs(dirs) do - os.rmdir(dname) - end - - -- remove any files - local files = os.matchfiles(p .. "/*") - for _, fname in ipairs(files) do - os.remove(fname) - end - - -- remove this directory - builtin_rmdir(p) - end - Index: ps/trunk/build/premake/premake4/src/base/path.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/path.lua +++ ps/trunk/build/premake/premake4/src/base/path.lua @@ -1,298 +0,0 @@ --- --- path.lua --- Path manipulation functions. --- Copyright (c) 2002-2010 Jason Perkins and the Premake project --- - - --- --- Get the absolute file path from a relative path. The requested --- file path doesn't actually need to exist. --- - - function path.getabsolute(p) - -- normalize the target path - p = path.translate(p, "/") - if (p == "") then p = "." end - - -- if the directory is already absolute I don't need to do anything - local result = iif (path.isabsolute(p), nil, os.getcwd()) - - -- split up the supplied relative path and tackle it bit by bit - for n, part in ipairs(p:explode("/", true)) do - if (part == "" and n == 1) then - result = "/" - elseif (part == "..") then - result = path.getdirectory(result) - elseif (part ~= ".") then - result = path.join(result, part) - end - end - - -- if I end up with a trailing slash remove it - result = iif(result:endswith("/"), result:sub(1, -2), result) - - return result - end - - --- --- Retrieve the filename portion of a path, without any extension. --- - - function path.getbasename(p) - local name = path.getname(p) - local i = name:findlast(".", true) - if (i) then - return name:sub(1, i - 1) - else - return name - end - end - - --- --- Retrieve the directory portion of a path, or an empty string if --- the path does not include a directory. --- - - function path.getdirectory(p) - local i = p:findlast("/", true) - if (i) then - if i > 1 then i = i - 1 end - return p:sub(1, i) - else - return "." - end - end - - --- --- Retrieve the drive letter, if a Windows path. --- - - function path.getdrive(p) - local ch1 = p:sub(1,1) - local ch2 = p:sub(2,2) - if ch2 == ":" then - return ch1 - end - end - - - --- --- Retrieve the file extension. --- - - function path.getextension(p) - local i = p:findlast(".", true) - if (i) then - return p:sub(i) - else - return "" - end - end - - - --- --- Retrieve the filename portion of a path. --- - - function path.getname(p) - local i = p:findlast("[/\\]") - if (i) then - return p:sub(i + 1) - else - return p - end - end - - --- --- Returns the relative path from src to dest. --- - - function path.getrelative(src, dst) - -- normalize the two paths - src = path.getabsolute(src) - dst = path.getabsolute(dst) - - -- same directory? - if (src == dst) then - return "." - end - - -- dollar macro? Can't tell what the real path is; use absolute - -- This enables paths like $(SDK_ROOT)/include to work correctly. - if dst:startswith("$") then - return dst - end - - src = src .. "/" - dst = dst .. "/" - - -- find the common leading directories - local idx = 0 - while (true) do - local tst = src:find("/", idx + 1, true) - if tst then - if src:sub(1,tst) == dst:sub(1,tst) then - idx = tst - else - break - end - else - break - end - end - - -- if they have nothing in common return absolute path - local first = src:find("/", 0, true) - if idx <= first then - return dst:sub(1, -2) - end - - -- trim off the common directories from the front - src = src:sub(idx + 1) - dst = dst:sub(idx + 1) - - -- back up from dst to get to this common parent - local result = "" - idx = src:find("/") - while (idx) do - result = result .. "../" - idx = src:find("/", idx + 1) - end - - -- tack on the path down to the dst from here - result = result .. dst - - -- remove the trailing slash - return result:sub(1, -2) - end - - --- --- Returns true if the filename represents a C/C++ source code file. This check --- is used to prevent passing non-code files to the compiler in makefiles. It is --- not foolproof, but it has held up well. I'm open to better suggestions. --- - - function path.iscfile(fname) - local extensions = { ".c", ".s", ".m" } - local ext = path.getextension(fname):lower() - return table.contains(extensions, ext) - end - - function path.iscppfile(fname) - local extensions = { ".cc", ".cpp", ".cxx", ".c", ".s", ".m", ".mm" } - local ext = path.getextension(fname):lower() - return table.contains(extensions, ext) - end - - --- --- Returns true if the filename represents a Windows resource file. This check --- is used to prevent passing non-resources to the compiler in makefiles. --- - - function path.isresourcefile(fname) - local extensions = { ".rc" } - local ext = path.getextension(fname):lower() - return table.contains(extensions, ext) - end - - - --- --- Join two pieces of a path together into a single path. --- - - function path.join(leading, trailing) - leading = leading or "" - - if (not trailing) then - return leading - end - - if (path.isabsolute(trailing)) then - return trailing - end - - if (leading == ".") then - leading = "" - end - - if (leading:len() > 0 and not leading:endswith("/")) then - leading = leading .. "/" - end - - return leading .. trailing - end - - --- --- Takes a path which is relative to one location and makes it relative --- to another location instead. --- - - function path.rebase(p, oldbase, newbase) - p = path.getabsolute(path.join(oldbase, p)) - p = path.getrelative(newbase, p) - return p - end - - --- --- Convert the separators in a path from one form to another. If `sep` --- is nil, then a platform-specific separator is used. --- - - function path.translate(p, sep) - if (type(p) == "table") then - local result = { } - for _, value in ipairs(p) do - table.insert(result, path.translate(value)) - end - return result - else - if (not sep) then - if (os.is("windows")) then - sep = "\\" - else - sep = "/" - end - end - local result = p:gsub("[/\\]", sep) - return result - end - end - - --- --- Converts from a simple wildcard syntax, where * is "match any" --- and ** is "match recursive", to the corresponding Lua pattern. --- --- @param pattern --- The wildcard pattern to convert. --- @returns --- The corresponding Lua pattern. --- - - function path.wildcards(pattern) - -- Escape characters that have special meanings in Lua patterns - pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") - - -- Replace wildcard patterns with special placeholders so I don't - -- have competing star replacements to worry about - pattern = pattern:gsub("%*%*", "\001") - pattern = pattern:gsub("%*", "\002") - - -- Replace the placeholders with their Lua patterns - pattern = pattern:gsub("\001", ".*") - pattern = pattern:gsub("\002", "[^/]*") - - return pattern - end Index: ps/trunk/build/premake/premake4/src/base/premake.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/premake.lua +++ ps/trunk/build/premake/premake4/src/base/premake.lua @@ -1,34 +0,0 @@ --- --- premake.lua --- High-level processing functions. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - --- --- Open a file for output, and call a function to actually do the writing. --- Used by the actions to generate solution and project files. --- --- @param obj --- A solution or project object; will be based to the callback function. --- @param filename --- The output filename; see the docs for premake.project.getfilename() --- for the expected format. --- @param callback --- The function responsible for writing the file, should take a solution --- or project as a parameters. --- - - function premake.generate(obj, filename, callback) - filename = premake.project.getfilename(obj, filename) - printf("Generating %s...", filename) - - local f, err = io.open(filename, "wb") - if (not f) then - error(err, 0) - end - - io.output(f) - callback(obj) - f:close() - end Index: ps/trunk/build/premake/premake4/src/base/project.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/project.lua +++ ps/trunk/build/premake/premake4/src/base/project.lua @@ -1,623 +0,0 @@ --- --- project.lua --- Functions for working with the project data. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - premake.project = { } - - --- --- Create a tree from a project's list of files, representing the filesystem hierarchy. --- --- @param prj --- The project containing the files to map. --- @returns --- A new tree object containing a corresponding filesystem hierarchy. The root node --- contains a reference back to the original project: prj = tr.project. --- - - function premake.project.buildsourcetree(prj) - local tr = premake.tree.new(prj.name) - for _, fname in ipairs(prj.files) do - local node = premake.tree.add(tr, fname) - end - premake.tree.sort(tr) - tr.project = prj - return tr - end - - --- --- Returns an iterator for a set of build configuration settings. If a platform is --- specified, settings specific to that platform and build configuration pair are --- returned. --- - - function premake.eachconfig(prj, platform) - -- I probably have the project root config, rather than the actual project - if prj.project then prj = prj.project end - - local cfgs = prj.solution.configurations - local i = 0 - - return function () - i = i + 1 - if i <= #cfgs then - return premake.getconfig(prj, cfgs[i], platform) - end - end - end - - - --- --- Iterator for a project's files; returns a file configuration object. --- - - function premake.eachfile(prj) - -- project root config contains the file config list - if not prj.project then prj = premake.getconfig(prj) end - local i = 0 - local t = prj.files - return function () - i = i + 1 - if (i <= #t) then - return prj.__fileconfigs[t[i]] - end - end - end - - - --- --- Apply XML escaping to a value. --- - - function premake.esc(value) - if (type(value) == "table") then - local result = { } - for _,v in ipairs(value) do - table.insert(result, premake.esc(v)) - end - return result - else - value = value:gsub('&', "&") - value = value:gsub('"', """) - value = value:gsub("'", "'") - value = value:gsub('<', "<") - value = value:gsub('>', ">") - value = value:gsub('\r', " ") - value = value:gsub('\n', " ") - return value - end - end - - - --- --- Given a map of supported platform identifiers, filters the solution's list --- of platforms to match. A map takes the form of a table like: --- --- { x32 = "Win32", x64 = "x64" } --- --- Only platforms that are listed in both the solution and the map will be --- included in the results. An optional default platform may also be specified; --- if the result set would otherwise be empty this platform will be used. --- - - function premake.filterplatforms(sln, map, default) - local result = { } - local keys = { } - if sln.platforms then - for _, p in ipairs(sln.platforms) do - if map[p] and not table.contains(keys, map[p]) then - table.insert(result, p) - table.insert(keys, map[p]) - end - end - end - - if #result == 0 and default then - table.insert(result, default) - end - - return result - end - - - --- --- Locate a project by name; case insensitive. --- - - function premake.findproject(name) - for sln in premake.solution.each() do - for prj in premake.solution.eachproject(sln) do - if (prj.name == name) then - return prj - end - end - end - end - - - --- --- Locate a file in a project with a given extension; used to locate "special" --- items such as Windows .def files. --- - - function premake.findfile(prj, extension) - for _, fname in ipairs(prj.files) do - if fname:endswith(extension) then return fname end - end - end - - - --- --- Retrieve a configuration for a given project/configuration pairing. --- @param prj --- The project to query. --- @param cfgname --- The target build configuration; only settings applicable to this configuration --- will be returned. May be nil to retrieve project-wide settings. --- @param pltname --- The target platform; only settings applicable to this platform will be returned. --- May be nil to retrieve platform-independent settings. --- @returns --- A configuration object containing all the settings for the given platform/build --- configuration pair. --- - - function premake.getconfig(prj, cfgname, pltname) - -- might have the root configuration, rather than the actual project - prj = prj.project or prj - - -- if platform is not included in the solution, use general settings instead - if pltname == "Native" or not table.contains(prj.solution.platforms or {}, pltname) then - pltname = nil - end - - local key = (cfgname or "") - if pltname then key = key .. pltname end - return prj.__configs[key] - end - - - --- --- Build a name from a build configuration/platform pair. The short name --- is good for makefiles or anywhere a user will have to type it in. The --- long name is more readable. --- - - function premake.getconfigname(cfgname, platform, useshortname) - if cfgname then - local name = cfgname - if platform and platform ~= "Native" then - if useshortname then - name = name .. premake.platforms[platform].cfgsuffix - else - name = name .. "|" .. platform - end - end - return iif(useshortname, name:lower(), name) - end - end - - - --- --- Returns a list of sibling projects on which the specified project depends. --- This is used to list dependencies within a solution or workspace. Must --- consider all configurations because Visual Studio does not support per-config --- project dependencies. --- --- @param prj --- The project to query. --- @returns --- A list of dependent projects, as an array of objects. --- - - function premake.getdependencies(prj) - -- make sure I've got the project and not root config - prj = prj.project or prj - - local results = { } - for _, cfg in pairs(prj.__configs) do - for _, link in ipairs(cfg.links) do - local dep = premake.findproject(link) - if dep and not table.contains(results, dep) then - table.insert(results, dep) - end - end - end - - return results - end - - - --- --- Uses information from a project (or solution) to format a filename. --- --- @param prj --- A project or solution object with the file naming information. --- @param pattern --- A naming pattern. The sequence "%%" will be replaced by the --- project name. --- @returns --- A filename matching the specified pattern, with a relative path --- from the current directory to the project location. --- - - function premake.project.getfilename(prj, pattern) - local fname = pattern:gsub("%%%%", prj.name) - fname = path.join(prj.location, fname) - return path.getrelative(os.getcwd(), fname) - end - - - --- --- Returns a list of link targets. Kind may be one of: --- siblings - linkable sibling projects --- system - system (non-sibling) libraries --- dependencies - all sibling dependencies, including non-linkable --- static - siblings that are static libraries --- all - return everything --- --- Part may be one of: --- name - the decorated library name with no directory --- basename - the undecorated library name --- directory - just the directory, no name --- fullpath - full path with decorated name --- object - return the project object of the dependency --- - - function premake.getlinks(cfg, kind, part) - -- if I'm building a list of link directories, include libdirs - local result = iif (part == "directory" and kind == "all", cfg.libdirs, {}) - - -- am I getting links for a configuration or a project? - local cfgname = iif(cfg.name == cfg.project.name, "", cfg.name) - - -- how should files be named? - local pathstyle = premake.getpathstyle(cfg) - local namestyle = premake.getnamestyle(cfg) - - local function canlink(source, target) - if (kind == "static" and target.kind ~= "StaticLib") then - return false - elseif (target.kind ~= "SharedLib" and target.kind ~= "StaticLib") then - return false - end - if premake.iscppproject(source) then - return premake.iscppproject(target) - elseif premake.isdotnetproject(source) then - return premake.isdotnetproject(target) - end - end - - for _, link in ipairs(cfg.links) do - local item - - -- is this a sibling project? - local prj = premake.findproject(link) - if prj and kind ~= "system" then - - local prjcfg = premake.getconfig(prj, cfgname, cfg.platform) - if kind == "dependencies" or canlink(cfg, prjcfg) then - if (part == "directory") then - item = path.rebase(prjcfg.linktarget.directory, prjcfg.location, cfg.location) - elseif (part == "basename") then - item = prjcfg.linktarget.basename - elseif (part == "fullpath") then - item = path.rebase(prjcfg.linktarget.fullpath, prjcfg.location, cfg.location) - elseif (part == "object") then - item = prjcfg - end - end - - elseif not prj and (kind == "system" or kind == "all") then - - if (part == "directory") then - local dir = path.getdirectory(link) - if (dir ~= ".") then - item = dir - end - elseif (part == "fullpath") then - item = link - if namestyle == "windows" then - if premake.iscppproject(cfg) then - item = item .. ".lib" - elseif premake.isdotnetproject(cfg) then - item = item .. ".dll" - end - end - if item:find("/", nil, true) then - item = path.getrelative(cfg.basedir, item) - end - else - item = link - end - - end - - if item then - if pathstyle == "windows" and part ~= "object" then - item = path.translate(item, "\\") - end - if not table.contains(result, item) then - table.insert(result, item) - end - end - end - - return result - end - - - --- --- Gets the name style for a configuration, indicating what kind of prefix, --- extensions, etc. should be used in target file names. --- --- @param cfg --- The configuration to check. --- @returns --- The target naming style, one of "windows", "posix", or "PS3". --- - - function premake.getnamestyle(cfg) - return premake.platforms[cfg.platform].namestyle or premake.gettool(cfg).namestyle or "posix" - end - - - --- --- Gets the path style for a configuration, indicating what kind of path separator --- should be used in target file names. --- --- @param cfg --- The configuration to check. --- @returns --- The target path style, one of "windows" or "posix". --- - - function premake.getpathstyle(cfg) - if premake.action.current().os == "windows" then - return "windows" - else - return "posix" - end - end - - --- --- Assembles a target for a particular tool/system/configuration. --- --- @param cfg --- The configuration to be targeted. --- @param direction --- One of 'build' for the build target, or 'link' for the linking target. --- @param pathstyle --- The path format, one of "windows" or "posix". This comes from the current --- action: Visual Studio uses "windows", GMake uses "posix", etc. --- @param namestyle --- The file naming style, one of "windows" or "posix". This comes from the --- current tool: GCC uses "posix", MSC uses "windows", etc. --- @param system --- The target operating system, which can modify the naming style. For example, --- shared libraries on Mac OS X use a ".dylib" extension. --- @returns --- An object with these fields: --- basename - the target with no directory or file extension --- name - the target name and extension, with no directory --- directory - relative path to the target, with no file name --- prefix - the file name prefix --- suffix - the file name suffix --- fullpath - directory, name, and extension --- bundlepath - the relative path and file name of the bundle --- - - function premake.gettarget(cfg, direction, pathstyle, namestyle, system) - if system == "bsd" or system == "solaris" then - system = "linux" - end - - -- Fix things up based on the current system - local kind = cfg.kind - if premake.iscppproject(cfg) then - -- On Windows, shared libraries link against a static import library - if (namestyle == "windows" or system == "windows") and kind == "SharedLib" and direction == "link" then - kind = "StaticLib" - end - - -- Posix name conventions only apply to static libs on windows (by user request) - if namestyle == "posix" and system == "windows" and kind ~= "StaticLib" then - namestyle = "windows" - end - end - - -- Initialize the target components - local field = iif(direction == "build", "target", "implib") - local name = cfg[field.."name"] or cfg.targetname or cfg.project.name - local dir = cfg[field.."dir"] or cfg.targetdir or path.getrelative(cfg.location, cfg.basedir) - local prefix = "" - local suffix = "" - local ext = "" - local bundlepath, bundlename - - if namestyle == "windows" then - if kind == "ConsoleApp" or kind == "WindowedApp" then - ext = ".exe" - elseif kind == "SharedLib" then - ext = ".dll" - elseif kind == "StaticLib" then - ext = ".lib" - end - elseif namestyle == "posix" then - if kind == "WindowedApp" and system == "macosx" then - bundlename = name .. ".app" - bundlepath = path.join(dir, bundlename) - dir = path.join(bundlepath, "Contents/MacOS") - elseif kind == "SharedLib" then - prefix = "lib" - ext = iif(system == "macosx", ".dylib", ".so") - elseif kind == "StaticLib" then - prefix = "lib" - ext = ".a" - end - elseif namestyle == "PS3" then - if kind == "ConsoleApp" or kind == "WindowedApp" then - ext = ".elf" - elseif kind == "StaticLib" then - prefix = "lib" - ext = ".a" - end - end - - prefix = cfg[field.."prefix"] or cfg.targetprefix or prefix - suffix = cfg[field.."suffix"] or cfg.targetsuffix or suffix - ext = cfg[field.."extension"] or cfg.targetextension or ext - - -- build the results object - local result = { } - result.basename = name .. suffix - result.name = prefix .. name .. suffix .. ext - result.directory = dir - result.prefix = prefix - result.suffix = suffix - result.fullpath = path.join(result.directory, result.name) - result.bundlepath = bundlepath or result.fullpath - - if pathstyle == "windows" then - result.directory = path.translate(result.directory, "\\") - result.fullpath = path.translate(result.fullpath, "\\") - end - - return result - end - - --- --- Return the appropriate tool interface, based on the target language and --- any relevant command-line options. --- - - function premake.gettool(cfg) - if premake.iscppproject(cfg) then - if _OPTIONS.cc then - return premake[_OPTIONS.cc] - end - local action = premake.action.current() - if action.valid_tools then - return premake[action.valid_tools.cc[1]] - end - return premake.gcc - else - return premake.dotnet - end - end - - - --- --- Returns true if the solution contains at least one C/C++ project. --- - - function premake.hascppproject(sln) - for prj in premake.solution.eachproject(sln) do - if premake.iscppproject(prj) then - return true - end - end - end - - - --- --- Returns true if the solution contains at least one .NET project. --- - - function premake.hasdotnetproject(sln) - for prj in premake.solution.eachproject(sln) do - if premake.isdotnetproject(prj) then - return true - end - end - end - - - --- --- Returns true if the project uses a C/C++ language. --- - - function premake.iscppproject(prj) - return (prj.language == "C" or prj.language == "C++") - end - - - --- --- Returns true if the project uses a .NET language. --- - - function premake.isdotnetproject(prj) - return (prj.language == "C#") - end - - - --- --- Walk the list of source code files, breaking them into "groups" based --- on the directory hierarchy. --- - - local function walksources(cfg, fn, group, nestlevel, finished) - local grouplen = group:len() - local gname = iif(group:endswith("/"), group:sub(1, -2), group) - - -- open this new group - if (nestlevel >= 0) then - fn(cfg, gname, "GroupStart", nestlevel) - end - - -- scan the list of files for items which belong in this group - for _,fname in ipairs(cfg.files) do - if (fname:startswith(group)) then - - -- is there a subgroup within this item? - local _,split = fname:find("[^\.]/", grouplen + 1) - if (split) then - local subgroup = fname:sub(1, split) - if (not finished[subgroup]) then - finished[subgroup] = true - walksources(cfg, fn, subgroup, nestlevel + 1, finished) - end - end - - end - end - - -- process all files that belong in this group - for _,fname in ipairs(cfg.files) do - if (fname:startswith(group) and not fname:find("[^\.]/", grouplen + 1)) then - fn(cfg, fname, "GroupItem", nestlevel + 1) - end - end - - -- close the group - if (nestlevel >= 0) then - fn(cfg, gname, "GroupEnd", nestlevel) - end - end - - - function premake.walksources(cfg, fn) - walksources(cfg, fn, "", -1, {}) - end Index: ps/trunk/build/premake/premake4/src/base/solution.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/solution.lua +++ ps/trunk/build/premake/premake4/src/base/solution.lua @@ -1,113 +0,0 @@ --- --- solution.lua --- Work with the list of solutions loaded from the script. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - premake.solution = { } - - --- The list of defined solutions (which contain projects, etc.) - - premake.solution.list = { } - - --- --- Create a new solution and add it to the session. --- --- @param name --- The new solution's name. --- - - function premake.solution.new(name) - local sln = { } - - -- add to master list keyed by both name and index - table.insert(premake.solution.list, sln) - premake.solution.list[name] = sln - - -- attach a type descriptor - setmetatable(sln, { __type="solution" }) - - sln.name = name - sln.basedir = os.getcwd() - sln.projects = { } - sln.blocks = { } - sln.configurations = { } - return sln - end - - --- --- Iterate over the collection of solutions in a session. --- --- @returns --- An iterator function. --- - - function premake.solution.each() - local i = 0 - return function () - i = i + 1 - if i <= #premake.solution.list then - return premake.solution.list[i] - end - end - end - - --- --- Iterate over the projects of a solution. --- --- @param sln --- The solution. --- @returns --- An iterator function. --- - - function premake.solution.eachproject(sln) - local i = 0 - return function () - i = i + 1 - if (i <= #sln.projects) then - return premake.solution.getproject(sln, i) - end - end - end - - --- --- Retrieve a solution by name or index. --- --- @param key --- The solution key, either a string name or integer index. --- @returns --- The solution with the provided key. --- - - function premake.solution.get(key) - return premake.solution.list[key] - end - - --- --- Retrieve the project at a particular index. --- --- @param sln --- The solution. --- @param idx --- An index into the array of projects. --- @returns --- The project at the given index. --- - - function premake.solution.getproject(sln, idx) - -- retrieve the root configuration of the project, with all of - -- the global (not configuration specific) settings collapsed - local prj = sln.projects[idx] - local cfg = premake.getconfig(prj) - - -- root configuration doesn't have a name; use the project's - cfg.name = prj.name - return cfg - end Index: ps/trunk/build/premake/premake4/src/base/string.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/string.lua +++ ps/trunk/build/premake/premake4/src/base/string.lua @@ -1,50 +0,0 @@ --- --- string.lua --- Additions to Lua's built-in string functions. --- Copyright (c) 2002-2008 Jason Perkins and the Premake project --- - - --- --- Returns an array of strings, each of which is a substring of s --- formed by splitting on boundaries formed by `pattern`. --- - - function string.explode(s, pattern, plain) - if (pattern == '') then return false end - local pos = 0 - local arr = { } - for st,sp in function() return s:find(pattern, pos, plain) end do - table.insert(arr, s:sub(pos, st-1)) - pos = sp + 1 - end - table.insert(arr, s:sub(pos)) - return arr - end - - - --- --- Find the last instance of a pattern in a string. --- - - function string.findlast(s, pattern, plain) - local curr = 0 - repeat - local next = s:find(pattern, curr + 1, plain) - if (next) then curr = next end - until (not next) - if (curr > 0) then - return curr - end - end - - - --- --- Returns true if `haystack` starts with the sequence `needle`. --- - - function string.startswith(haystack, needle) - return (haystack:find(needle, 1, true) == 1) - end Index: ps/trunk/build/premake/premake4/src/base/table.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/table.lua +++ ps/trunk/build/premake/premake4/src/base/table.lua @@ -1,139 +0,0 @@ --- --- table.lua --- Additions to Lua's built-in table functions. --- Copyright (c) 2002-2008 Jason Perkins and the Premake project --- - - --- --- Returns true if the table contains the specified value. --- - - function table.contains(t, value) - for _,v in pairs(t) do - if (v == value) then - return true - end - end - return false - end - - --- --- Enumerates an array of objects and returns a new table containing --- only the value of one particular field. --- - - function table.extract(arr, fname) - local result = { } - for _,v in ipairs(arr) do - table.insert(result, v[fname]) - end - return result - end - - - --- --- Flattens a hierarchy of tables into a single array containing all --- of the values. --- - - function table.flatten(arr) - local result = { } - - local function flatten(arr) - for _, v in ipairs(arr) do - if type(v) == "table" then - flatten(v) - else - table.insert(result, v) - end - end - end - - flatten(arr) - return result - end - - --- --- Merges an array of items into a string. --- - - function table.implode(arr, before, after, between) - local result = "" - for _,v in ipairs(arr) do - if (result ~= "" and between) then - result = result .. between - end - result = result .. before .. v .. after - end - return result - end - - --- --- Returns true if the table is empty, and contains no indexed or keyed values. --- - - function table.isempty(t) - return not next(t) - end - - --- --- Adds the values from one array to the end of another and --- returns the result. --- - - function table.join(...) - local result = { } - for _,t in ipairs(arg) do - if type(t) == "table" then - for _,v in ipairs(t) do - table.insert(result, v) - end - else - table.insert(result, t) - end - end - return result - end - - --- --- Return a list of all keys used in a table. --- - - function table.keys(tbl) - local keys = {} - for k, _ in pairs(tbl) do - table.insert(keys, k) - end - return keys - end - - --- --- Translates the values contained in array, using the specified --- translation table, and returns the results in a new array. --- - - function table.translate(arr, translation) - local result = { } - for _, value in ipairs(arr) do - local tvalue - if type(translation) == "function" then - tvalue = translation(value) - else - tvalue = translation[value] - end - if (tvalue) then - table.insert(result, tvalue) - end - end - return result - end - - \ No newline at end of file Index: ps/trunk/build/premake/premake4/src/base/tree.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/tree.lua +++ ps/trunk/build/premake/premake4/src/base/tree.lua @@ -1,195 +0,0 @@ --- --- tree.lua --- Functions for working with the source code tree. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - premake.tree = { } - local tree = premake.tree - - --- --- Create a new tree. --- --- @param n --- The name of the tree, applied to the root node (optional). --- - - function premake.tree.new(n) - local t = { - name = n, - children = { } - } - return t - end - - --- --- Add a new node to the tree, or returns the current node if it already exists. --- --- @param tr --- The tree to contain the new node. --- @param p --- The path of the new node. --- @returns --- The new tree node. --- - - function premake.tree.add(tr, p) - -- Special case "." refers to the current node - if p == "." then - return tr - end - - -- Look for the immediate parent for this new node, creating it if necessary. - -- Recurses to create as much of the tree as necessary. - local parentnode = tree.add(tr, path.getdirectory(p)) - - -- Another special case, ".." refers to the parent node and doesn't create anything - local childname = path.getname(p) - if childname == ".." then - return parentnode - end - - -- Create the child if necessary. If two children with the same name appear - -- at the same level, make sure they have the same path to prevent conflicts - -- i.e. ../Common and ../../Common can both appear at the top of the tree - -- yet they have different paths (Bug #3016050) - local childnode = parentnode.children[childname] - if not childnode or childnode.path ~= p then - childnode = tree.insert(parentnode, tree.new(childname)) - childnode.path = p - end - - return childnode - end - - --- --- Insert one tree into another. --- --- @param parent --- The parent tree, to contain the child. --- @param child --- The child tree, to be inserted. --- - - function premake.tree.insert(parent, child) - table.insert(parent.children, child) - if child.name then - parent.children[child.name] = child - end - child.parent = parent - return child - end - - --- --- Gets the node's relative path from it's parent. If the parent does not have --- a path set (it is the root or other container node) returns the full node path. --- --- @param node --- The node to query. --- - - function premake.tree.getlocalpath(node) - if node.parent.path then - return node.name - else - return node.path - end - end - - --- --- Remove a node from a tree. --- --- @param node --- The node to remove. --- - - function premake.tree.remove(node) - local children = node.parent.children - for i = 1, #children do - if children[i] == node then - table.remove(children, i) - end - end - node.children = {} - end - - --- --- Sort the nodes of a tree in-place. --- --- @param tr --- The tree to sort. --- - - function premake.tree.sort(tr) - tree.traverse(tr, { - onnode = function(node) - table.sort(node.children, function(a,b) - return a.name < b.name - end) - end - }, true) - end - - --- --- Traverse a tree. --- --- @param t --- The tree to traverse. --- @param fn --- A collection of callback functions, which may contain: --- --- onnode(node, depth) - called on each node encountered --- onleaf(node, depth) - called only on leaf nodes --- onbranch(node, depth) - called only on branch nodes --- --- @param includeroot --- True to include the root node in the traversal, otherwise it will be skipped. --- - - function premake.tree.traverse(t, fn, includeroot) - - local donode, dochildren - donode = function(node, fn, depth) - if node.isremoved then - return - end - if fn.onnode then - fn.onnode(node, depth) - end - if #node.children > 0 then - if fn.onbranch then - fn.onbranch(node, depth) - end - dochildren(node, fn, depth + 1) - else - if fn.onleaf then - fn.onleaf(node, depth) - end - end - end - - dochildren = function(parent, fn, depth) - -- this goofy iterator allows nodes to be removed during the traversal - local i = 1 - while i <= #parent.children do - local node = parent.children[i] - donode(node, fn, depth) - if node == parent.children[i] then - i = i + 1 - end - end - end - - if includeroot then - donode(t, fn, 0) - else - dochildren(t, fn, 0) - end - end Index: ps/trunk/build/premake/premake4/src/base/validate.lua =================================================================== --- ps/trunk/build/premake/premake4/src/base/validate.lua +++ ps/trunk/build/premake/premake4/src/base/validate.lua @@ -1,91 +0,0 @@ --- --- validate.lua --- Tests to validate the run-time environment before starting the action. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - --- --- Performs a sanity check of all of the solutions and projects --- in the session to be sure they meet some minimum requirements. --- - - function premake.checkprojects() - local action = premake.action.current() - - for sln in premake.solution.each() do - - -- every solution must have at least one project - if (#sln.projects == 0) then - return nil, "solution '" .. sln.name .. "' needs at least one project" - end - - -- every solution must provide a list of configurations - if (#sln.configurations == 0) then - return nil, "solution '" .. sln.name .. "' needs configurations" - end - - for prj in premake.solution.eachproject(sln) do - - -- every project must have a language - if (not prj.language) then - return nil, "project '" ..prj.name .. "' needs a language" - end - - -- and the action must support it - if (action.valid_languages) then - if (not table.contains(action.valid_languages, prj.language)) then - return nil, "the " .. action.shortname .. " action does not support " .. prj.language .. " projects" - end - end - - for cfg in premake.eachconfig(prj) do - - -- every config must have a kind - if (not cfg.kind) then - return nil, "project '" ..prj.name .. "' needs a kind in configuration '" .. cfg.name .. "'" - end - - -- and the action must support it - if (action.valid_kinds) then - if (not table.contains(action.valid_kinds, cfg.kind)) then - return nil, "the " .. action.shortname .. " action does not support " .. cfg.kind .. " projects" - end - end - - end - - -- some actions have custom validation logic - if action.oncheckproject then - action.oncheckproject(prj) - end - - end - end - return true - end - - --- --- Check the specified tools (/cc, /dotnet, etc.) against the current action --- to make sure they are compatible and supported. --- - - function premake.checktools() - local action = premake.action.current() - if (not action.valid_tools) then - return true - end - - for tool, values in pairs(action.valid_tools) do - if (_OPTIONS[tool]) then - if (not table.contains(values, _OPTIONS[tool])) then - return nil, "the " .. action.shortname .. " action does not support /" .. tool .. "=" .. _OPTIONS[tool] .. " (yet)" - end - else - _OPTIONS[tool] = values[1] - end - end - - return true - end Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/COPYRIGHT =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/COPYRIGHT +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/COPYRIGHT @@ -1,34 +0,0 @@ -Lua License ------------ - -Lua is licensed under the terms of the MIT license reproduced below. -This means that Lua is free software and can be used for both academic -and commercial purposes at absolutely no cost. - -For details and rationale, see http://www.lua.org/license.html . - -=============================================================================== - -Copyright (C) 1994-2008 Lua.org, PUC-Rio. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -=============================================================================== - -(end of COPYRIGHT) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/HISTORY =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/HISTORY +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/HISTORY @@ -1,183 +0,0 @@ -HISTORY for Lua 5.1 - -* Changes from version 5.0 to 5.1 - ------------------------------- - Language: - + new module system. - + new semantics for control variables of fors. - + new semantics for setn/getn. - + new syntax/semantics for varargs. - + new long strings and comments. - + new `mod' operator (`%') - + new length operator #t - + metatables for all types - API: - + new functions: lua_createtable, lua_get(set)field, lua_push(to)integer. - + user supplies memory allocator (lua_open becomes lua_newstate). - + luaopen_* functions must be called through Lua. - Implementation: - + new configuration scheme via luaconf.h. - + incremental garbage collection. - + better handling of end-of-line in the lexer. - + fully reentrant parser (new Lua function `load') - + better support for 64-bit machines. - + native loadlib support for Mac OS X. - + standard distribution in only one library (lualib.a merged into lua.a) - -* Changes from version 4.0 to 5.0 - ------------------------------- - Language: - + lexical scoping. - + Lua coroutines. - + standard libraries now packaged in tables. - + tags replaced by metatables and tag methods replaced by metamethods, - stored in metatables. - + proper tail calls. - + each function can have its own global table, which can be shared. - + new __newindex metamethod, called when we insert a new key into a table. - + new block comments: --[[ ... ]]. - + new generic for. - + new weak tables. - + new boolean type. - + new syntax "local function". - + (f()) returns the first value returned by f. - + {f()} fills a table with all values returned by f. - + \n ignored in [[\n . - + fixed and-or priorities. - + more general syntax for function definition (e.g. function a.x.y:f()...end). - + more general syntax for function calls (e.g. (print or write)(9)). - + new functions (time/date, tmpfile, unpack, require, load*, etc.). - API: - + chunks are loaded by using lua_load; new luaL_loadfile and luaL_loadbuffer. - + introduced lightweight userdata, a simple "void*" without a metatable. - + new error handling protocol: the core no longer prints error messages; - all errors are reported to the caller on the stack. - + new lua_atpanic for host cleanup. - + new, signal-safe, hook scheme. - Implementation: - + new license: MIT. - + new, faster, register-based virtual machine. - + support for external multithreading and coroutines. - + new and consistent error message format. - + the core no longer needs "stdio.h" for anything (except for a single - use of sprintf to convert numbers to strings). - + lua.c now runs the environment variable LUA_INIT, if present. It can - be "@filename", to run a file, or the chunk itself. - + support for user extensions in lua.c. - sample implementation given for command line editing. - + new dynamic loading library, active by default on several platforms. - + safe garbage-collector metamethods. - + precompiled bytecodes checked for integrity (secure binary dostring). - + strings are fully aligned. - + position capture in string.find. - + read('*l') can read lines with embedded zeros. - -* Changes from version 3.2 to 4.0 - ------------------------------- - Language: - + new "break" and "for" statements (both numerical and for tables). - + uniform treatment of globals: globals are now stored in a Lua table. - + improved error messages. - + no more '$debug': full speed *and* full debug information. - + new read form: read(N) for next N bytes. - + general read patterns now deprecated. - (still available with -DCOMPAT_READPATTERNS.) - + all return values are passed as arguments for the last function - (old semantics still available with -DLUA_COMPAT_ARGRET) - + garbage collection tag methods for tables now deprecated. - + there is now only one tag method for order. - API: - + New API: fully re-entrant, simpler, and more efficient. - + New debug API. - Implementation: - + faster than ever: cleaner virtual machine and new hashing algorithm. - + non-recursive garbage-collector algorithm. - + reduced memory usage for programs with many strings. - + improved treatment for memory allocation errors. - + improved support for 16-bit machines (we hope). - + code now compiles unmodified as both ANSI C and C++. - + numbers in bases other than 10 are converted using strtoul. - + new -f option in Lua to support #! scripts. - + luac can now combine text and binaries. - -* Changes from version 3.1 to 3.2 - ------------------------------- - + redirected all output in Lua's core to _ERRORMESSAGE and _ALERT. - + increased limit on the number of constants and globals per function - (from 2^16 to 2^24). - + debugging info (lua_debug and hooks) moved into lua_state and new API - functions provided to get and set this info. - + new debug lib gives full debugging access within Lua. - + new table functions "foreachi", "sort", "tinsert", "tremove", "getn". - + new io functions "flush", "seek". - -* Changes from version 3.0 to 3.1 - ------------------------------- - + NEW FEATURE: anonymous functions with closures (via "upvalues"). - + new syntax: - - local variables in chunks. - - better scope control with DO block END. - - constructors can now be also written: { record-part; list-part }. - - more general syntax for function calls and lvalues, e.g.: - f(x).y=1 - o:f(x,y):g(z) - f"string" is sugar for f("string") - + strings may now contain arbitrary binary data (e.g., embedded zeros). - + major code re-organization and clean-up; reduced module interdependecies. - + no arbitrary limits on the total number of constants and globals. - + support for multiple global contexts. - + better syntax error messages. - + new traversal functions "foreach" and "foreachvar". - + the default for numbers is now double. - changing it to use floats or longs is easy. - + complete debug information stored in pre-compiled chunks. - + sample interpreter now prompts user when run interactively, and also - handles control-C interruptions gracefully. - -* Changes from version 2.5 to 3.0 - ------------------------------- - + NEW CONCEPT: "tag methods". - Tag methods replace fallbacks as the meta-mechanism for extending the - semantics of Lua. Whereas fallbacks had a global nature, tag methods - work on objects having the same tag (e.g., groups of tables). - Existing code that uses fallbacks should work without change. - + new, general syntax for constructors {[exp] = exp, ... }. - + support for handling variable number of arguments in functions (varargs). - + support for conditional compilation ($if ... $else ... $end). - + cleaner semantics in API simplifies host code. - + better support for writing libraries (auxlib.h). - + better type checking and error messages in the standard library. - + luac can now also undump. - -* Changes from version 2.4 to 2.5 - ------------------------------- - + io and string libraries are now based on pattern matching; - the old libraries are still available for compatibility - + dofile and dostring can now return values (via return statement) - + better support for 16- and 64-bit machines - + expanded documentation, with more examples - -* Changes from version 2.2 to 2.4 - ------------------------------- - + external compiler creates portable binary files that can be loaded faster - + interface for debugging and profiling - + new "getglobal" fallback - + new functions for handling references to Lua objects - + new functions in standard lib - + only one copy of each string is stored - + expanded documentation, with more examples - -* Changes from version 2.1 to 2.2 - ------------------------------- - + functions now may be declared with any "lvalue" as a name - + garbage collection of functions - + support for pipes - -* Changes from version 1.1 to 2.1 - ------------------------------- - + object-oriented support - + fallbacks - + simplified syntax for tables - + many internal improvements - -(end of HISTORY) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/INSTALL =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/INSTALL +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/INSTALL @@ -1,99 +0,0 @@ -INSTALL for Lua 5.1 - -* Building Lua - ------------ - Lua is built in the src directory, but the build process can be - controlled from the top-level Makefile. - - Building Lua on Unix systems should be very easy. First do "make" and - see if your platform is listed. If so, just do "make xxx", where xxx - is your platform name. The platforms currently supported are: - aix ansi bsd freebsd generic linux macosx mingw posix solaris - - If your platform is not listed, try the closest one or posix, generic, - ansi, in this order. - - See below for customization instructions and for instructions on how - to build with other Windows compilers. - - If you want to check that Lua has been built correctly, do "make test" - after building Lua. Also, have a look at the example programs in test. - -* Installing Lua - -------------- - Once you have built Lua, you may want to install it in an official - place in your system. In this case, do "make install". The official - place and the way to install files are defined in Makefile. You must - have the right permissions to install files. - - If you want to build and install Lua in one step, do "make xxx install", - where xxx is your platform name. - - If you want to install Lua locally, then do "make local". This will - create directories bin, include, lib, man, and install Lua there as - follows: - - bin: lua luac - include: lua.h luaconf.h lualib.h lauxlib.h lua.hpp - lib: liblua.a - man/man1: lua.1 luac.1 - - These are the only directories you need for development. - - There are man pages for lua and luac, in both nroff and html, and a - reference manual in html in doc, some sample code in test, and some - useful stuff in etc. You don't need these directories for development. - - If you want to install Lua locally, but in some other directory, do - "make install INSTALL_TOP=xxx", where xxx is your chosen directory. - - See below for instructions for Windows and other systems. - -* Customization - ------------- - Three things can be customized by editing a file: - - Where and how to install Lua -- edit Makefile. - - How to build Lua -- edit src/Makefile. - - Lua features -- edit src/luaconf.h. - - You don't actually need to edit the Makefiles because you may set the - relevant variables when invoking make. - - On the other hand, if you need to select some Lua features, you'll need - to edit src/luaconf.h. The edited file will be the one installed, and - it will be used by any Lua clients that you build, to ensure consistency. - - We strongly recommend that you enable dynamic loading. This is done - automatically for all platforms listed above that have this feature - (and also Windows). See src/luaconf.h and also src/Makefile. - -* Building Lua on Windows and other systems - ----------------------------------------- - If you're not using the usual Unix tools, then the instructions for - building Lua depend on the compiler you use. You'll need to create - projects (or whatever your compiler uses) for building the library, - the interpreter, and the compiler, as follows: - - library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c - lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c - ltable.c ltm.c lundump.c lvm.c lzio.c - lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c - ltablib.c lstrlib.c loadlib.c linit.c - - interpreter: library, lua.c - - compiler: library, luac.c print.c - - If you use Visual Studio .NET, you can use etc/luavs.bat in its - "Command Prompt". - - If all you want is to build the Lua interpreter, you may put all .c files - in a single project, except for luac.c and print.c. Or just use etc/all.c. - - To use Lua as a library in your own programs, you'll need to know how to - create and use libraries with your compiler. - - As mentioned above, you may edit luaconf.h to select some features before - building Lua. - -(end of INSTALL) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/Makefile =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/Makefile +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/Makefile @@ -1,128 +0,0 @@ -# makefile for installing Lua -# see INSTALL for installation instructions -# see src/Makefile and src/luaconf.h for further customization - -# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= - -# Your platform. See PLATS for possible values. -PLAT= none - -# Where to install. The installation starts in the src and doc directories, -# so take care if INSTALL_TOP is not an absolute path. -INSTALL_TOP= /usr/local -INSTALL_BIN= $(INSTALL_TOP)/bin -INSTALL_INC= $(INSTALL_TOP)/include -INSTALL_LIB= $(INSTALL_TOP)/lib -INSTALL_MAN= $(INSTALL_TOP)/man/man1 -# -# You probably want to make INSTALL_LMOD and INSTALL_CMOD consistent with -# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc). -INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V -INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V - -# How to install. If your install program does not support "-p", then you -# may have to run ranlib on the installed liblua.a (do "make ranlib"). -INSTALL= install -p -INSTALL_EXEC= $(INSTALL) -m 0755 -INSTALL_DATA= $(INSTALL) -m 0644 -# -# If you don't have install you can use cp instead. -# INSTALL= cp -p -# INSTALL_EXEC= $(INSTALL) -# INSTALL_DATA= $(INSTALL) - -# Utilities. -MKDIR= mkdir -p -RANLIB= ranlib - -# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= - -# Convenience platforms targets. -PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris - -# What to install. -TO_BIN= lua luac -TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp -TO_LIB= liblua.a -TO_MAN= lua.1 luac.1 - -# Lua version and release. -V= 5.1 -R= 5.1.4 - -all: $(PLAT) - -$(PLATS) clean: - cd src && $(MAKE) $@ - -test: dummy - src/lua test/hello.lua - -install: dummy - cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) - cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) - cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) - cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) - cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) - -ranlib: - cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB) - -local: - $(MAKE) install INSTALL_TOP=.. - -none: - @echo "Please do" - @echo " make PLATFORM" - @echo "where PLATFORM is one of these:" - @echo " $(PLATS)" - @echo "See INSTALL for complete instructions." - -# make may get confused with test/ and INSTALL in a case-insensitive OS -dummy: - -# echo config parameters -echo: - @echo "" - @echo "These are the parameters currently set in src/Makefile to build Lua $R:" - @echo "" - @cd src && $(MAKE) -s echo - @echo "" - @echo "These are the parameters currently set in Makefile to install Lua $R:" - @echo "" - @echo "PLAT = $(PLAT)" - @echo "INSTALL_TOP = $(INSTALL_TOP)" - @echo "INSTALL_BIN = $(INSTALL_BIN)" - @echo "INSTALL_INC = $(INSTALL_INC)" - @echo "INSTALL_LIB = $(INSTALL_LIB)" - @echo "INSTALL_MAN = $(INSTALL_MAN)" - @echo "INSTALL_LMOD = $(INSTALL_LMOD)" - @echo "INSTALL_CMOD = $(INSTALL_CMOD)" - @echo "INSTALL_EXEC = $(INSTALL_EXEC)" - @echo "INSTALL_DATA = $(INSTALL_DATA)" - @echo "" - @echo "See also src/luaconf.h ." - @echo "" - -# echo private config parameters -pecho: - @echo "V = $(V)" - @echo "R = $(R)" - @echo "TO_BIN = $(TO_BIN)" - @echo "TO_INC = $(TO_INC)" - @echo "TO_LIB = $(TO_LIB)" - @echo "TO_MAN = $(TO_MAN)" - -# echo config parameters as Lua code -# uncomment the last sed expression if you want nil instead of empty strings -lecho: - @echo "-- installation parameters for Lua $R" - @echo "VERSION = '$V'" - @echo "RELEASE = '$R'" - @$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' - @echo "-- EOF" - -# list targets that do not create files (but not all makes understand .PHONY) -.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho - -# (end of Makefile) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/README =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/README +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/README @@ -1,37 +0,0 @@ -README for Lua 5.1 - -See INSTALL for installation instructions. -See HISTORY for a summary of changes since the last released version. - -* What is Lua? - ------------ - Lua is a powerful, light-weight programming language designed for extending - applications. Lua is also frequently used as a general-purpose, stand-alone - language. Lua is free software. - - For complete information, visit Lua's web site at http://www.lua.org/ . - For an executive summary, see http://www.lua.org/about.html . - - Lua has been used in many different projects around the world. - For a short list, see http://www.lua.org/uses.html . - -* Availability - ------------ - Lua is freely available for both academic and commercial purposes. - See COPYRIGHT and http://www.lua.org/license.html for details. - Lua can be downloaded at http://www.lua.org/download.html . - -* Installation - ------------ - Lua is implemented in pure ANSI C, and compiles unmodified in all known - platforms that have an ANSI C compiler. In most Unix-like platforms, simply - do "make" with a suitable target. See INSTALL for detailed instructions. - -* Origin - ------ - Lua is developed at Lua.org, a laboratory of the Department of Computer - Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro - in Brazil). - For more information about the authors, see http://www.lua.org/authors.html . - -(end of README) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/contents.html =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/contents.html +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/contents.html @@ -1,499 +0,0 @@ - - - -Lua 5.1 Reference Manual - contents - - - - - - - -
-

- -Lua 5.1 Reference Manual -

- -This is an online version of -
- - - -Lua 5.1 Reference Manual -
by R. Ierusalimschy, L. H. de Figueiredo, W. Celes -
Lua.org, August 2006 -
ISBN 85-903798-3-3 -
-[Buy from Amazon] -
-
-

- -Buy a copy of this book and -help to support -the Lua project. -

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

- -start -· -contents -· -index -· -português -· -español -


- -Copyright © 2006-2008 Lua.org, PUC-Rio. -Freely available under the terms of the -Lua license. - -

- -

Contents

- - -

Index

- - - - - - - -
-

Lua functions

-_G
-_VERSION
-assert
-collectgarbage
-dofile
-error
-getfenv
-getmetatable
-ipairs
-load
-loadfile
-loadstring
-module
-next
-pairs
-pcall
-print
-rawequal
-rawget
-rawset
-require
-select
-setfenv
-setmetatable
-tonumber
-tostring
-type
-unpack
-xpcall
-

- -coroutine.create
-coroutine.resume
-coroutine.running
-coroutine.status
-coroutine.wrap
-coroutine.yield
-

- -debug.debug
-debug.getfenv
-debug.gethook
-debug.getinfo
-debug.getlocal
-debug.getmetatable
-debug.getregistry
-debug.getupvalue
-debug.setfenv
-debug.sethook
-debug.setlocal
-debug.setmetatable
-debug.setupvalue
-debug.traceback
- -

-

 

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

- -io.close
-io.flush
-io.input
-io.lines
-io.open
-io.output
-io.popen
-io.read
-io.stderr
-io.stdin
-io.stdout
-io.tmpfile
-io.type
-io.write
-

- -math.abs
-math.acos
-math.asin
-math.atan
-math.atan2
-math.ceil
-math.cos
-math.cosh
-math.deg
-math.exp
-math.floor
-math.fmod
-math.frexp
-math.huge
-math.ldexp
-math.log
-math.log10
-math.max
-math.min
-math.modf
-math.pi
-math.pow
-math.rad
-math.random
-math.randomseed
-math.sin
-math.sinh
-math.sqrt
-math.tan
-math.tanh
-

- -os.clock
-os.date
-os.difftime
-os.execute
-os.exit
-os.getenv
-os.remove
-os.rename
-os.setlocale
-os.time
-os.tmpname
-

- -package.cpath
-package.loaded
-package.loaders
-package.loadlib
-package.path
-package.preload
-package.seeall
-

- -string.byte
-string.char
-string.dump
-string.find
-string.format
-string.gmatch
-string.gsub
-string.len
-string.lower
-string.match
-string.rep
-string.reverse
-string.sub
-string.upper
-

- -table.concat
-table.insert
-table.maxn
-table.remove
-table.sort
- -

-

C API

-lua_Alloc
-lua_CFunction
-lua_Debug
-lua_Hook
-lua_Integer
-lua_Number
-lua_Reader
-lua_State
-lua_Writer
-

- -lua_atpanic
-lua_call
-lua_checkstack
-lua_close
-lua_concat
-lua_cpcall
-lua_createtable
-lua_dump
-lua_equal
-lua_error
-lua_gc
-lua_getallocf
-lua_getfenv
-lua_getfield
-lua_getglobal
-lua_gethook
-lua_gethookcount
-lua_gethookmask
-lua_getinfo
-lua_getlocal
-lua_getmetatable
-lua_getstack
-lua_gettable
-lua_gettop
-lua_getupvalue
-lua_insert
-lua_isboolean
-lua_iscfunction
-lua_isfunction
-lua_islightuserdata
-lua_isnil
-lua_isnone
-lua_isnoneornil
-lua_isnumber
-lua_isstring
-lua_istable
-lua_isthread
-lua_isuserdata
-lua_lessthan
-lua_load
-lua_newstate
-lua_newtable
-lua_newthread
-lua_newuserdata
-lua_next
-lua_objlen
-lua_pcall
-lua_pop
-lua_pushboolean
-lua_pushcclosure
-lua_pushcfunction
-lua_pushfstring
-lua_pushinteger
-lua_pushlightuserdata
-lua_pushliteral
-lua_pushlstring
-lua_pushnil
-lua_pushnumber
-lua_pushstring
-lua_pushthread
-lua_pushvalue
-lua_pushvfstring
-lua_rawequal
-lua_rawget
-lua_rawgeti
-lua_rawset
-lua_rawseti
-lua_register
-lua_remove
-lua_replace
-lua_resume
-lua_setallocf
-lua_setfenv
-lua_setfield
-lua_setglobal
-lua_sethook
-lua_setlocal
-lua_setmetatable
-lua_settable
-lua_settop
-lua_setupvalue
-lua_status
-lua_toboolean
-lua_tocfunction
-lua_tointeger
-lua_tolstring
-lua_tonumber
-lua_topointer
-lua_tostring
-lua_tothread
-lua_touserdata
-lua_type
-lua_typename
-lua_upvalueindex
-lua_xmove
-lua_yield
- -

-

auxiliary library

-luaL_Buffer
-luaL_Reg
-

- -luaL_addchar
-luaL_addlstring
-luaL_addsize
-luaL_addstring
-luaL_addvalue
-luaL_argcheck
-luaL_argerror
-luaL_buffinit
-luaL_callmeta
-luaL_checkany
-luaL_checkint
-luaL_checkinteger
-luaL_checklong
-luaL_checklstring
-luaL_checknumber
-luaL_checkoption
-luaL_checkstack
-luaL_checkstring
-luaL_checktype
-luaL_checkudata
-luaL_dofile
-luaL_dostring
-luaL_error
-luaL_getmetafield
-luaL_getmetatable
-luaL_gsub
-luaL_loadbuffer
-luaL_loadfile
-luaL_loadstring
-luaL_newmetatable
-luaL_newstate
-luaL_openlibs
-luaL_optint
-luaL_optinteger
-luaL_optlong
-luaL_optlstring
-luaL_optnumber
-luaL_optstring
-luaL_prepbuffer
-luaL_pushresult
-luaL_ref
-luaL_register
-luaL_typename
-luaL_typerror
-luaL_unref
-luaL_where
- -

-

- -


- -Last update: -Sat Jan 19 13:24:29 BRST 2008 - - - - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.html =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.html +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.html @@ -1,172 +0,0 @@ - - - -LUA man page - - - - - -

NAME

-lua - Lua interpreter -

SYNOPSIS

-lua -[ -options -] -[ -script -[ -args -] -] -

DESCRIPTION

-lua -is the stand-alone Lua interpreter. -It loads and executes Lua programs, -either in textual source form or -in precompiled binary form. -(Precompiled binaries are output by -luac, -the Lua compiler.) -lua -can be used as a batch interpreter and also interactively. -

-The given -options -(see below) -are executed and then -the Lua program in file -script -is loaded and executed. -The given -args -are available to -script -as strings in a global table named -arg. -If these arguments contain spaces or other characters special to the shell, -then they should be quoted -(but note that the quotes will be removed by the shell). -The arguments in -arg -start at 0, -which contains the string -'script'. -The index of the last argument is stored in -arg.n. -The arguments given in the command line before -script, -including the name of the interpreter, -are available in negative indices in -arg. -

-At the very start, -before even handling the command line, -lua -executes the contents of the environment variable -LUA_INIT, -if it is defined. -If the value of -LUA_INIT -is of the form -'@filename', -then -filename -is executed. -Otherwise, the string is assumed to be a Lua statement and is executed. -

-Options start with -'-' -and are described below. -You can use -'--' -to signal the end of options. -

-If no arguments are given, -then -"-v -i" -is assumed when the standard input is a terminal; -otherwise, -"-" -is assumed. -

-In interactive mode, -lua -prompts the user, -reads lines from the standard input, -and executes them as they are read. -If a line does not contain a complete statement, -then a secondary prompt is displayed and -lines are read until a complete statement is formed or -a syntax error is found. -So, one way to interrupt the reading of an incomplete statement is -to force a syntax error: -adding a -';' -in the middle of a statement is a sure way of forcing a syntax error -(except inside multiline strings and comments; these must be closed explicitly). -If a line starts with -'=', -then -lua -displays the values of all the expressions in the remainder of the -line. The expressions must be separated by commas. -The primary prompt is the value of the global variable -_PROMPT, -if this value is a string; -otherwise, the default prompt is used. -Similarly, the secondary prompt is the value of the global variable -_PROMPT2. -So, -to change the prompts, -set the corresponding variable to a string of your choice. -You can do that after calling the interpreter -or on the command line -(but in this case you have to be careful with quotes -if the prompt string contains a space; otherwise you may confuse the shell.) -The default prompts are "> " and ">> ". -

OPTIONS

-

-- -load and execute the standard input as a file, -that is, -not interactively, -even when the standard input is a terminal. -

--e stat -execute statement -stat. -You need to quote -stat -if it contains spaces, quotes, -or other characters special to the shell. -

--i -enter interactive mode after -script -is executed. -

--l name -call -require('name') -before executing -script. -Typically used to load libraries. -

--v -show version information. -

SEE ALSO

-luac(1) -
-http://www.lua.org/ -

DIAGNOSTICS

-Error messages should be self explanatory. -

AUTHORS

-R. Ierusalimschy, -L. H. de Figueiredo, -and -W. Celes - - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.1 =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.1 +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.1 @@ -1,163 +0,0 @@ -.\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $ -.TH LUA 1 "$Date: 2006/01/06 16:03:34 $" -.SH NAME -lua \- Lua interpreter -.SH SYNOPSIS -.B lua -[ -.I options -] -[ -.I script -[ -.I args -] -] -.SH DESCRIPTION -.B lua -is the stand-alone Lua interpreter. -It loads and executes Lua programs, -either in textual source form or -in precompiled binary form. -(Precompiled binaries are output by -.BR luac , -the Lua compiler.) -.B lua -can be used as a batch interpreter and also interactively. -.LP -The given -.I options -(see below) -are executed and then -the Lua program in file -.I script -is loaded and executed. -The given -.I args -are available to -.I script -as strings in a global table named -.BR arg . -If these arguments contain spaces or other characters special to the shell, -then they should be quoted -(but note that the quotes will be removed by the shell). -The arguments in -.B arg -start at 0, -which contains the string -.RI ' script '. -The index of the last argument is stored in -.BR arg.n . -The arguments given in the command line before -.IR script , -including the name of the interpreter, -are available in negative indices in -.BR arg . -.LP -At the very start, -before even handling the command line, -.B lua -executes the contents of the environment variable -.BR LUA_INIT , -if it is defined. -If the value of -.B LUA_INIT -is of the form -.RI '@ filename ', -then -.I filename -is executed. -Otherwise, the string is assumed to be a Lua statement and is executed. -.LP -Options start with -.B '\-' -and are described below. -You can use -.B "'\--'" -to signal the end of options. -.LP -If no arguments are given, -then -.B "\-v \-i" -is assumed when the standard input is a terminal; -otherwise, -.B "\-" -is assumed. -.LP -In interactive mode, -.B lua -prompts the user, -reads lines from the standard input, -and executes them as they are read. -If a line does not contain a complete statement, -then a secondary prompt is displayed and -lines are read until a complete statement is formed or -a syntax error is found. -So, one way to interrupt the reading of an incomplete statement is -to force a syntax error: -adding a -.B ';' -in the middle of a statement is a sure way of forcing a syntax error -(except inside multiline strings and comments; these must be closed explicitly). -If a line starts with -.BR '=' , -then -.B lua -displays the values of all the expressions in the remainder of the -line. The expressions must be separated by commas. -The primary prompt is the value of the global variable -.BR _PROMPT , -if this value is a string; -otherwise, the default prompt is used. -Similarly, the secondary prompt is the value of the global variable -.BR _PROMPT2 . -So, -to change the prompts, -set the corresponding variable to a string of your choice. -You can do that after calling the interpreter -or on the command line -(but in this case you have to be careful with quotes -if the prompt string contains a space; otherwise you may confuse the shell.) -The default prompts are "> " and ">> ". -.SH OPTIONS -.TP -.B \- -load and execute the standard input as a file, -that is, -not interactively, -even when the standard input is a terminal. -.TP -.BI \-e " stat" -execute statement -.IR stat . -You need to quote -.I stat -if it contains spaces, quotes, -or other characters special to the shell. -.TP -.B \-i -enter interactive mode after -.I script -is executed. -.TP -.BI \-l " name" -call -.BI require(' name ') -before executing -.IR script . -Typically used to load libraries. -.TP -.B \-v -show version information. -.SH "SEE ALSO" -.BR luac (1) -.br -http://www.lua.org/ -.SH DIAGNOSTICS -Error messages should be self explanatory. -.SH AUTHORS -R. Ierusalimschy, -L. H. de Figueiredo, -and -W. Celes -.\" EOF Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.css =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.css +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/lua.css @@ -1,41 +0,0 @@ -body { - color: #000000 ; - background-color: #FFFFFF ; - font-family: sans-serif ; - text-align: justify ; - margin-right: 20px ; - margin-left: 20px ; -} - -h1, h2, h3, h4 { - font-weight: normal ; - font-style: italic ; -} - -a:link { - color: #000080 ; - background-color: inherit ; - text-decoration: none ; -} - -a:visited { - background-color: inherit ; - text-decoration: none ; -} - -a:link:hover, a:visited:hover { - color: #000080 ; - background-color: #E0E0FF ; -} - -a:link:active, a:visited:active { - color: #FF0000 ; -} - -hr { - border: 0 ; - height: 1px ; - color: #a0a0a0 ; - background-color: #a0a0a0 ; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/luac.html =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/luac.html +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/luac.html @@ -1,145 +0,0 @@ - - - -LUAC man page - - - - - -

NAME

-luac - Lua compiler -

SYNOPSIS

-luac -[ -options -] [ -filenames -] -

DESCRIPTION

-luac -is the Lua compiler. -It translates programs written in the Lua programming language -into binary files that can be later loaded and executed. -

-The main advantages of precompiling chunks are: -faster loading, -protecting source code from accidental user changes, -and -off-line syntax checking. -

-Precompiling does not imply faster execution -because in Lua chunks are always compiled into bytecodes before being executed. -luac -simply allows those bytecodes to be saved in a file for later execution. -

-Precompiled chunks are not necessarily smaller than the corresponding source. -The main goal in precompiling is faster loading. -

-The binary files created by -luac -are portable only among architectures with the same word size and byte order. -

-luac -produces a single output file containing the bytecodes -for all source files given. -By default, -the output file is named -luac.out, -but you can change this with the --o -option. -

-In the command line, -you can mix -text files containing Lua source and -binary files containing precompiled chunks. -This is useful because several precompiled chunks, -even from different (but compatible) platforms, -can be combined into a single precompiled chunk. -

-You can use -'-' -to indicate the standard input as a source file -and -'--' -to signal the end of options -(that is, -all remaining arguments will be treated as files even if they start with -'-'). -

-The internal format of the binary files produced by -luac -is likely to change when a new version of Lua is released. -So, -save the source files of all Lua programs that you precompile. -

-

OPTIONS

-Options must be separate. -

--l -produce a listing of the compiled bytecode for Lua's virtual machine. -Listing bytecodes is useful to learn about Lua's virtual machine. -If no files are given, then -luac -loads -luac.out -and lists its contents. -

--o file -output to -file, -instead of the default -luac.out. -(You can use -'-' -for standard output, -but not on platforms that open standard output in text mode.) -The output file may be a source file because -all files are loaded before the output file is written. -Be careful not to overwrite precious files. -

--p -load files but do not generate any output file. -Used mainly for syntax checking and for testing precompiled chunks: -corrupted files will probably generate errors when loaded. -Lua always performs a thorough integrity test on precompiled chunks. -Bytecode that passes this test is completely safe, -in the sense that it will not break the interpreter. -However, -there is no guarantee that such code does anything sensible. -(None can be given, because the halting problem is unsolvable.) -If no files are given, then -luac -loads -luac.out -and tests its contents. -No messages are displayed if the file passes the integrity test. -

--s -strip debug information before writing the output file. -This saves some space in very large chunks, -but if errors occur when running a stripped chunk, -then the error messages may not contain the full information they usually do. -For instance, -line numbers and names of local variables are lost. -

--v -show version information. -

FILES

-

-luac.out -default output file -

SEE ALSO

-lua(1) -
-http://www.lua.org/ -

DIAGNOSTICS

-Error messages should be self explanatory. -

AUTHORS

-L. H. de Figueiredo, -R. Ierusalimschy and -W. Celes - - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/luac.1 =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/luac.1 +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/luac.1 @@ -1,136 +0,0 @@ -.\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $ -.TH LUAC 1 "$Date: 2006/01/06 16:03:34 $" -.SH NAME -luac \- Lua compiler -.SH SYNOPSIS -.B luac -[ -.I options -] [ -.I filenames -] -.SH DESCRIPTION -.B luac -is the Lua compiler. -It translates programs written in the Lua programming language -into binary files that can be later loaded and executed. -.LP -The main advantages of precompiling chunks are: -faster loading, -protecting source code from accidental user changes, -and -off-line syntax checking. -.LP -Pre-compiling does not imply faster execution -because in Lua chunks are always compiled into bytecodes before being executed. -.B luac -simply allows those bytecodes to be saved in a file for later execution. -.LP -Pre-compiled chunks are not necessarily smaller than the corresponding source. -The main goal in pre-compiling is faster loading. -.LP -The binary files created by -.B luac -are portable only among architectures with the same word size and byte order. -.LP -.B luac -produces a single output file containing the bytecodes -for all source files given. -By default, -the output file is named -.BR luac.out , -but you can change this with the -.B \-o -option. -.LP -In the command line, -you can mix -text files containing Lua source and -binary files containing precompiled chunks. -This is useful to combine several precompiled chunks, -even from different (but compatible) platforms, -into a single precompiled chunk. -.LP -You can use -.B "'\-'" -to indicate the standard input as a source file -and -.B "'\--'" -to signal the end of options -(that is, -all remaining arguments will be treated as files even if they start with -.BR "'\-'" ). -.LP -The internal format of the binary files produced by -.B luac -is likely to change when a new version of Lua is released. -So, -save the source files of all Lua programs that you precompile. -.LP -.SH OPTIONS -Options must be separate. -.TP -.B \-l -produce a listing of the compiled bytecode for Lua's virtual machine. -Listing bytecodes is useful to learn about Lua's virtual machine. -If no files are given, then -.B luac -loads -.B luac.out -and lists its contents. -.TP -.BI \-o " file" -output to -.IR file , -instead of the default -.BR luac.out . -(You can use -.B "'\-'" -for standard output, -but not on platforms that open standard output in text mode.) -The output file may be a source file because -all files are loaded before the output file is written. -Be careful not to overwrite precious files. -.TP -.B \-p -load files but do not generate any output file. -Used mainly for syntax checking and for testing precompiled chunks: -corrupted files will probably generate errors when loaded. -Lua always performs a thorough integrity test on precompiled chunks. -Bytecode that passes this test is completely safe, -in the sense that it will not break the interpreter. -However, -there is no guarantee that such code does anything sensible. -(None can be given, because the halting problem is unsolvable.) -If no files are given, then -.B luac -loads -.B luac.out -and tests its contents. -No messages are displayed if the file passes the integrity test. -.TP -.B \-s -strip debug information before writing the output file. -This saves some space in very large chunks, -but if errors occur when running a stripped chunk, -then the error messages may not contain the full information they usually do. -For instance, -line numbers and names of local variables are lost. -.TP -.B \-v -show version information. -.SH FILES -.TP 15 -.B luac.out -default output file -.SH "SEE ALSO" -.BR lua (1) -.br -http://www.lua.org/ -.SH DIAGNOSTICS -Error messages should be self explanatory. -.SH AUTHORS -L. H. de Figueiredo, -R. Ierusalimschy and -W. Celes -.\" EOF Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/manual.html =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/manual.html +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/manual.html @@ -1,8801 +0,0 @@ - - - - -Lua 5.1 Reference Manual - - - - - - - -
-

- -Lua 5.1 Reference Manual -

- -by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes -

- -Copyright © 2006-2008 Lua.org, PUC-Rio. -Freely available under the terms of the -Lua license. - -


-

- -contents -· -index - - -

- - - - - - -

1 - Introduction

- -

-Lua is an extension programming language designed to support -general procedural programming with data description -facilities. -It also offers good support for object-oriented programming, -functional programming, and data-driven programming. -Lua is intended to be used as a powerful, light-weight -scripting language for any program that needs one. -Lua is implemented as a library, written in clean C -(that is, in the common subset of ANSI C and C++). - - -

-Being an extension language, Lua has no notion of a "main" program: -it only works embedded in a host client, -called the embedding program or simply the host. -This host program can invoke functions to execute a piece of Lua code, -can write and read Lua variables, -and can register C functions to be called by Lua code. -Through the use of C functions, Lua can be augmented to cope with -a wide range of different domains, -thus creating customized programming languages sharing a syntactical framework. -The Lua distribution includes a sample host program called lua, -which uses the Lua library to offer a complete, stand-alone Lua interpreter. - - -

-Lua is free software, -and is provided as usual with no guarantees, -as stated in its license. -The implementation described in this manual is available -at Lua's official web site, www.lua.org. - - -

-Like any other reference manual, -this document is dry in places. -For a discussion of the decisions behind the design of Lua, -see the technical papers available at Lua's web site. -For a detailed introduction to programming in Lua, -see Roberto's book, Programming in Lua (Second Edition). - - - -

2 - The Language

- -

-This section describes the lexis, the syntax, and the semantics of Lua. -In other words, -this section describes -which tokens are valid, -how they can be combined, -and what their combinations mean. - - -

-The language constructs will be explained using the usual extended BNF notation, -in which -{a} means 0 or more a's, and -[a] means an optional a. -Non-terminals are shown like non-terminal, -keywords are shown like kword, -and other terminal symbols are shown like `=´. -The complete syntax of Lua can be found in §8 -at the end of this manual. - - - -

2.1 - Lexical Conventions

- -

-Names -(also called identifiers) -in Lua can be any string of letters, -digits, and underscores, -not beginning with a digit. -This coincides with the definition of names in most languages. -(The definition of letter depends on the current locale: -any character considered alphabetic by the current locale -can be used in an identifier.) -Identifiers are used to name variables and table fields. - - -

-The following keywords are reserved -and cannot be used as names: - - -

-     and       break     do        else      elseif
-     end       false     for       function  if
-     in        local     nil       not       or
-     repeat    return    then      true      until     while
-
- -

-Lua is a case-sensitive language: -and is a reserved word, but And and AND -are two different, valid names. -As a convention, names starting with an underscore followed by -uppercase letters (such as _VERSION) -are reserved for internal global variables used by Lua. - - -

-The following strings denote other tokens: - -

-     +     -     *     /     %     ^     #
-     ==    ~=    <=    >=    <     >     =
-     (     )     {     }     [     ]
-     ;     :     ,     .     ..    ...
-
- -

-Literal strings -can be delimited by matching single or double quotes, -and can contain the following C-like escape sequences: -'\a' (bell), -'\b' (backspace), -'\f' (form feed), -'\n' (newline), -'\r' (carriage return), -'\t' (horizontal tab), -'\v' (vertical tab), -'\\' (backslash), -'\"' (quotation mark [double quote]), -and '\'' (apostrophe [single quote]). -Moreover, a backslash followed by a real newline -results in a newline in the string. -A character in a string can also be specified by its numerical value -using the escape sequence \ddd, -where ddd is a sequence of up to three decimal digits. -(Note that if a numerical escape is to be followed by a digit, -it must be expressed using exactly three digits.) -Strings in Lua can contain any 8-bit value, including embedded zeros, -which can be specified as '\0'. - - -

-Literal strings can also be defined using a long format -enclosed by long brackets. -We define an opening long bracket of level n as an opening -square bracket followed by n equal signs followed by another -opening square bracket. -So, an opening long bracket of level 0 is written as [[, -an opening long bracket of level 1 is written as [=[, -and so on. -A closing long bracket is defined similarly; -for instance, a closing long bracket of level 4 is written as ]====]. -A long string starts with an opening long bracket of any level and -ends at the first closing long bracket of the same level. -Literals in this bracketed form can run for several lines, -do not interpret any escape sequences, -and ignore long brackets of any other level. -They can contain anything except a closing bracket of the proper level. - - -

-For convenience, -when the opening long bracket is immediately followed by a newline, -the newline is not included in the string. -As an example, in a system using ASCII -(in which 'a' is coded as 97, -newline is coded as 10, and '1' is coded as 49), -the five literal strings below denote the same string: - -

-     a = 'alo\n123"'
-     a = "alo\n123\""
-     a = '\97lo\10\04923"'
-     a = [[alo
-     123"]]
-     a = [==[
-     alo
-     123"]==]
-
- -

-A numerical constant can be written with an optional decimal part -and an optional decimal exponent. -Lua also accepts integer hexadecimal constants, -by prefixing them with 0x. -Examples of valid numerical constants are - -

-     3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56
-
- -

-A comment starts with a double hyphen (--) -anywhere outside a string. -If the text immediately after -- is not an opening long bracket, -the comment is a short comment, -which runs until the end of the line. -Otherwise, it is a long comment, -which runs until the corresponding closing long bracket. -Long comments are frequently used to disable code temporarily. - - - - - -

2.2 - Values and Types

- -

-Lua is a dynamically typed language. -This means that -variables do not have types; only values do. -There are no type definitions in the language. -All values carry their own type. - - -

-All values in Lua are first-class values. -This means that all values can be stored in variables, -passed as arguments to other functions, and returned as results. - - -

-There are eight basic types in Lua: -nil, boolean, number, -string, function, userdata, -thread, and table. -Nil is the type of the value nil, -whose main property is to be different from any other value; -it usually represents the absence of a useful value. -Boolean is the type of the values false and true. -Both nil and false make a condition false; -any other value makes it true. -Number represents real (double-precision floating-point) numbers. -(It is easy to build Lua interpreters that use other -internal representations for numbers, -such as single-precision float or long integers; -see file luaconf.h.) -String represents arrays of characters. - -Lua is 8-bit clean: -strings can contain any 8-bit character, -including embedded zeros ('\0') (see §2.1). - - -

-Lua can call (and manipulate) functions written in Lua and -functions written in C -(see §2.5.8). - - -

-The type userdata is provided to allow arbitrary C data to -be stored in Lua variables. -This type corresponds to a block of raw memory -and has no pre-defined operations in Lua, -except assignment and identity test. -However, by using metatables, -the programmer can define operations for userdata values -(see §2.8). -Userdata values cannot be created or modified in Lua, -only through the C API. -This guarantees the integrity of data owned by the host program. - - -

-The type thread represents independent threads of execution -and it is used to implement coroutines (see §2.11). -Do not confuse Lua threads with operating-system threads. -Lua supports coroutines on all systems, -even those that do not support threads. - - -

-The type table implements associative arrays, -that is, arrays that can be indexed not only with numbers, -but with any value (except nil). -Tables can be heterogeneous; -that is, they can contain values of all types (except nil). -Tables are the sole data structuring mechanism in Lua; -they can be used to represent ordinary arrays, -symbol tables, sets, records, graphs, trees, etc. -To represent records, Lua uses the field name as an index. -The language supports this representation by -providing a.name as syntactic sugar for a["name"]. -There are several convenient ways to create tables in Lua -(see §2.5.7). - - -

-Like indices, -the value of a table field can be of any type (except nil). -In particular, -because functions are first-class values, -table fields can contain functions. -Thus tables can also carry methods (see §2.5.9). - - -

-Tables, functions, threads, and (full) userdata values are objects: -variables do not actually contain these values, -only references to them. -Assignment, parameter passing, and function returns -always manipulate references to such values; -these operations do not imply any kind of copy. - - -

-The library function type returns a string describing the type -of a given value. - - - -

2.2.1 - Coercion

- -

-Lua provides automatic conversion between -string and number values at run time. -Any arithmetic operation applied to a string tries to convert -this string to a number, following the usual conversion rules. -Conversely, whenever a number is used where a string is expected, -the number is converted to a string, in a reasonable format. -For complete control over how numbers are converted to strings, -use the format function from the string library -(see string.format). - - - - - - - -

2.3 - Variables

- -

-Variables are places that store values. - -There are three kinds of variables in Lua: -global variables, local variables, and table fields. - - -

-A single name can denote a global variable or a local variable -(or a function's formal parameter, -which is a particular kind of local variable): - -

-	var ::= Name
-

-Name denotes identifiers, as defined in §2.1. - - -

-Any variable is assumed to be global unless explicitly declared -as a local (see §2.4.7). -Local variables are lexically scoped: -local variables can be freely accessed by functions -defined inside their scope (see §2.6). - - -

-Before the first assignment to a variable, its value is nil. - - -

-Square brackets are used to index a table: - -

-	var ::= prefixexp `[´ exp `]´
-

-The meaning of accesses to global variables -and table fields can be changed via metatables. -An access to an indexed variable t[i] is equivalent to -a call gettable_event(t,i). -(See §2.8 for a complete description of the -gettable_event function. -This function is not defined or callable in Lua. -We use it here only for explanatory purposes.) - - -

-The syntax var.Name is just syntactic sugar for -var["Name"]: - -

-	var ::= prefixexp `.´ Name
-
- -

-All global variables live as fields in ordinary Lua tables, -called environment tables or simply -environments (see §2.9). -Each function has its own reference to an environment, -so that all global variables in this function -will refer to this environment table. -When a function is created, -it inherits the environment from the function that created it. -To get the environment table of a Lua function, -you call getfenv. -To replace it, -you call setfenv. -(You can only manipulate the environment of C functions -through the debug library; (see §5.9).) - - -

-An access to a global variable x -is equivalent to _env.x, -which in turn is equivalent to - -

-     gettable_event(_env, "x")
-

-where _env is the environment of the running function. -(See §2.8 for a complete description of the -gettable_event function. -This function is not defined or callable in Lua. -Similarly, the _env variable is not defined in Lua. -We use them here only for explanatory purposes.) - - - - - -

2.4 - Statements

- -

-Lua supports an almost conventional set of statements, -similar to those in Pascal or C. -This set includes -assignments, control structures, function calls, -and variable declarations. - - - -

2.4.1 - Chunks

- -

-The unit of execution of Lua is called a chunk. -A chunk is simply a sequence of statements, -which are executed sequentially. -Each statement can be optionally followed by a semicolon: - -

-	chunk ::= {stat [`;´]}
-

-There are no empty statements and thus ';;' is not legal. - - -

-Lua handles a chunk as the body of an anonymous function -with a variable number of arguments -(see §2.5.9). -As such, chunks can define local variables, -receive arguments, and return values. - - -

-A chunk can be stored in a file or in a string inside the host program. -To execute a chunk, -Lua first pre-compiles the chunk into instructions for a virtual machine, -and then it executes the compiled code -with an interpreter for the virtual machine. - - -

-Chunks can also be pre-compiled into binary form; -see program luac for details. -Programs in source and compiled forms are interchangeable; -Lua automatically detects the file type and acts accordingly. - - - - - - -

2.4.2 - Blocks

-A block is a list of statements; -syntactically, a block is the same as a chunk: - -

-	block ::= chunk
-
- -

-A block can be explicitly delimited to produce a single statement: - -

-	stat ::= do block end
-

-Explicit blocks are useful -to control the scope of variable declarations. -Explicit blocks are also sometimes used to -add a return or break statement in the middle -of another block (see §2.4.4). - - - - - -

2.4.3 - Assignment

- -

-Lua allows multiple assignments. -Therefore, the syntax for assignment -defines a list of variables on the left side -and a list of expressions on the right side. -The elements in both lists are separated by commas: - -

-	stat ::= varlist `=´ explist
-	varlist ::= var {`,´ var}
-	explist ::= exp {`,´ exp}
-

-Expressions are discussed in §2.5. - - -

-Before the assignment, -the list of values is adjusted to the length of -the list of variables. -If there are more values than needed, -the excess values are thrown away. -If there are fewer values than needed, -the list is extended with as many nil's as needed. -If the list of expressions ends with a function call, -then all values returned by that call enter the list of values, -before the adjustment -(except when the call is enclosed in parentheses; see §2.5). - - -

-The assignment statement first evaluates all its expressions -and only then are the assignments performed. -Thus the code - -

-     i = 3
-     i, a[i] = i+1, 20
-

-sets a[3] to 20, without affecting a[4] -because the i in a[i] is evaluated (to 3) -before it is assigned 4. -Similarly, the line - -

-     x, y = y, x
-

-exchanges the values of x and y, -and - -

-     x, y, z = y, z, x
-

-cyclically permutes the values of x, y, and z. - - -

-The meaning of assignments to global variables -and table fields can be changed via metatables. -An assignment to an indexed variable t[i] = val is equivalent to -settable_event(t,i,val). -(See §2.8 for a complete description of the -settable_event function. -This function is not defined or callable in Lua. -We use it here only for explanatory purposes.) - - -

-An assignment to a global variable x = val -is equivalent to the assignment -_env.x = val, -which in turn is equivalent to - -

-     settable_event(_env, "x", val)
-

-where _env is the environment of the running function. -(The _env variable is not defined in Lua. -We use it here only for explanatory purposes.) - - - - - -

2.4.4 - Control Structures

-The control structures -if, while, and repeat have the usual meaning and -familiar syntax: - - - - -

-	stat ::= while exp do block end
-	stat ::= repeat block until exp
-	stat ::= if exp then block {elseif exp then block} [else block] end
-

-Lua also has a for statement, in two flavors (see §2.4.5). - - -

-The condition expression of a -control structure can return any value. -Both false and nil are considered false. -All values different from nil and false are considered true -(in particular, the number 0 and the empty string are also true). - - -

-In the repeatuntil loop, -the inner block does not end at the until keyword, -but only after the condition. -So, the condition can refer to local variables -declared inside the loop block. - - -

-The return statement is used to return values -from a function or a chunk (which is just a function). - -Functions and chunks can return more than one value, -and so the syntax for the return statement is - -

-	stat ::= return [explist]
-
- -

-The break statement is used to terminate the execution of a -while, repeat, or for loop, -skipping to the next statement after the loop: - - -

-	stat ::= break
-

-A break ends the innermost enclosing loop. - - -

-The return and break -statements can only be written as the last statement of a block. -If it is really necessary to return or break in the -middle of a block, -then an explicit inner block can be used, -as in the idioms -do return end and do break end, -because now return and break are the last statements in -their (inner) blocks. - - - - - -

2.4.5 - For Statement

- -

- -The for statement has two forms: -one numeric and one generic. - - -

-The numeric for loop repeats a block of code while a -control variable runs through an arithmetic progression. -It has the following syntax: - -

-	stat ::= for Name `=´ exp `,´ exp [`,´ exp] do block end
-

-The block is repeated for name starting at the value of -the first exp, until it passes the second exp by steps of the -third exp. -More precisely, a for statement like - -

-     for v = e1, e2, e3 do block end
-

-is equivalent to the code: - -

-     do
-       local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3)
-       if not (var and limit and step) then error() end
-       while (step > 0 and var <= limit) or (step <= 0 and var >= limit) do
-         local v = var
-         block
-         var = var + step
-       end
-     end
-

-Note the following: - -

    - -
  • -All three control expressions are evaluated only once, -before the loop starts. -They must all result in numbers. -
  • - -
  • -var, limit, and step are invisible variables. -The names shown here are for explanatory purposes only. -
  • - -
  • -If the third expression (the step) is absent, -then a step of 1 is used. -
  • - -
  • -You can use break to exit a for loop. -
  • - -
  • -The loop variable v is local to the loop; -you cannot use its value after the for ends or is broken. -If you need this value, -assign it to another variable before breaking or exiting the loop. -
  • - -
- -

-The generic for statement works over functions, -called iterators. -On each iteration, the iterator function is called to produce a new value, -stopping when this new value is nil. -The generic for loop has the following syntax: - -

-	stat ::= for namelist in explist do block end
-	namelist ::= Name {`,´ Name}
-

-A for statement like - -

-     for var_1, ···, var_n in explist do block end
-

-is equivalent to the code: - -

-     do
-       local f, s, var = explist
-       while true do
-         local var_1, ···, var_n = f(s, var)
-         var = var_1
-         if var == nil then break end
-         block
-       end
-     end
-

-Note the following: - -

    - -
  • -explist is evaluated only once. -Its results are an iterator function, -a state, -and an initial value for the first iterator variable. -
  • - -
  • -f, s, and var are invisible variables. -The names are here for explanatory purposes only. -
  • - -
  • -You can use break to exit a for loop. -
  • - -
  • -The loop variables var_i are local to the loop; -you cannot use their values after the for ends. -If you need these values, -then assign them to other variables before breaking or exiting the loop. -
  • - -
- - - - -

2.4.6 - Function Calls as Statements

-To allow possible side-effects, -function calls can be executed as statements: - -

-	stat ::= functioncall
-

-In this case, all returned values are thrown away. -Function calls are explained in §2.5.8. - - - - - -

2.4.7 - Local Declarations

-Local variables can be declared anywhere inside a block. -The declaration can include an initial assignment: - -

-	stat ::= local namelist [`=´ explist]
-

-If present, an initial assignment has the same semantics -of a multiple assignment (see §2.4.3). -Otherwise, all variables are initialized with nil. - - -

-A chunk is also a block (see §2.4.1), -and so local variables can be declared in a chunk outside any explicit block. -The scope of such local variables extends until the end of the chunk. - - -

-The visibility rules for local variables are explained in §2.6. - - - - - - - -

2.5 - Expressions

- -

-The basic expressions in Lua are the following: - -

-	exp ::= prefixexp
-	exp ::= nil | false | true
-	exp ::= Number
-	exp ::= String
-	exp ::= function
-	exp ::= tableconstructor
-	exp ::= `...´
-	exp ::= exp binop exp
-	exp ::= unop exp
-	prefixexp ::= var | functioncall | `(´ exp `)´
-
- -

-Numbers and literal strings are explained in §2.1; -variables are explained in §2.3; -function definitions are explained in §2.5.9; -function calls are explained in §2.5.8; -table constructors are explained in §2.5.7. -Vararg expressions, -denoted by three dots ('...'), can only be used when -directly inside a vararg function; -they are explained in §2.5.9. - - -

-Binary operators comprise arithmetic operators (see §2.5.1), -relational operators (see §2.5.2), logical operators (see §2.5.3), -and the concatenation operator (see §2.5.4). -Unary operators comprise the unary minus (see §2.5.1), -the unary not (see §2.5.3), -and the unary length operator (see §2.5.5). - - -

-Both function calls and vararg expressions can result in multiple values. -If an expression is used as a statement -(only possible for function calls (see §2.4.6)), -then its return list is adjusted to zero elements, -thus discarding all returned values. -If an expression is used as the last (or the only) element -of a list of expressions, -then no adjustment is made -(unless the call is enclosed in parentheses). -In all other contexts, -Lua adjusts the result list to one element, -discarding all values except the first one. - - -

-Here are some examples: - -

-     f()                -- adjusted to 0 results
-     g(f(), x)          -- f() is adjusted to 1 result
-     g(x, f())          -- g gets x plus all results from f()
-     a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)
-     a,b = ...          -- a gets the first vararg parameter, b gets
-                        -- the second (both a and b can get nil if there
-                        -- is no corresponding vararg parameter)
-     
-     a,b,c = x, f()     -- f() is adjusted to 2 results
-     a,b,c = f()        -- f() is adjusted to 3 results
-     return f()         -- returns all results from f()
-     return ...         -- returns all received vararg parameters
-     return x,y,f()     -- returns x, y, and all results from f()
-     {f()}              -- creates a list with all results from f()
-     {...}              -- creates a list with all vararg parameters
-     {f(), nil}         -- f() is adjusted to 1 result
-
- -

-Any expression enclosed in parentheses always results in only one value. -Thus, -(f(x,y,z)) is always a single value, -even if f returns several values. -(The value of (f(x,y,z)) is the first value returned by f -or nil if f does not return any values.) - - - -

2.5.1 - Arithmetic Operators

-Lua supports the usual arithmetic operators: -the binary + (addition), -- (subtraction), * (multiplication), -/ (division), % (modulo), and ^ (exponentiation); -and unary - (negation). -If the operands are numbers, or strings that can be converted to -numbers (see §2.2.1), -then all operations have the usual meaning. -Exponentiation works for any exponent. -For instance, x^(-0.5) computes the inverse of the square root of x. -Modulo is defined as - -

-     a % b == a - math.floor(a/b)*b
-

-That is, it is the remainder of a division that rounds -the quotient towards minus infinity. - - - - - -

2.5.2 - Relational Operators

-The relational operators in Lua are - -

-     ==    ~=    <     >     <=    >=
-

-These operators always result in false or true. - - -

-Equality (==) first compares the type of its operands. -If the types are different, then the result is false. -Otherwise, the values of the operands are compared. -Numbers and strings are compared in the usual way. -Objects (tables, userdata, threads, and functions) -are compared by reference: -two objects are considered equal only if they are the same object. -Every time you create a new object -(a table, userdata, thread, or function), -this new object is different from any previously existing object. - - -

-You can change the way that Lua compares tables and userdata -by using the "eq" metamethod (see §2.8). - - -

-The conversion rules of §2.2.1 -do not apply to equality comparisons. -Thus, "0"==0 evaluates to false, -and t[0] and t["0"] denote different -entries in a table. - - -

-The operator ~= is exactly the negation of equality (==). - - -

-The order operators work as follows. -If both arguments are numbers, then they are compared as such. -Otherwise, if both arguments are strings, -then their values are compared according to the current locale. -Otherwise, Lua tries to call the "lt" or the "le" -metamethod (see §2.8). -A comparison a > b is translated to b < a -and a >= b is translated to b <= a. - - - - - -

2.5.3 - Logical Operators

-The logical operators in Lua are -and, or, and not. -Like the control structures (see §2.4.4), -all logical operators consider both false and nil as false -and anything else as true. - - -

-The negation operator not always returns false or true. -The conjunction operator and returns its first argument -if this value is false or nil; -otherwise, and returns its second argument. -The disjunction operator or returns its first argument -if this value is different from nil and false; -otherwise, or returns its second argument. -Both and and or use short-cut evaluation; -that is, -the second operand is evaluated only if necessary. -Here are some examples: - -

-     10 or 20            --> 10
-     10 or error()       --> 10
-     nil or "a"          --> "a"
-     nil and 10          --> nil
-     false and error()   --> false
-     false and nil       --> false
-     false or nil        --> nil
-     10 and 20           --> 20
-

-(In this manual, ---> indicates the result of the preceding expression.) - - - - - -

2.5.4 - Concatenation

-The string concatenation operator in Lua is -denoted by two dots ('..'). -If both operands are strings or numbers, then they are converted to -strings according to the rules mentioned in §2.2.1. -Otherwise, the "concat" metamethod is called (see §2.8). - - - - - -

2.5.5 - The Length Operator

- -

-The length operator is denoted by the unary operator #. -The length of a string is its number of bytes -(that is, the usual meaning of string length when each -character is one byte). - - -

-The length of a table t is defined to be any -integer index n -such that t[n] is not nil and t[n+1] is nil; -moreover, if t[1] is nil, n can be zero. -For a regular array, with non-nil values from 1 to a given n, -its length is exactly that n, -the index of its last value. -If the array has "holes" -(that is, nil values between other non-nil values), -then #t can be any of the indices that -directly precedes a nil value -(that is, it may consider any such nil value as the end of -the array). - - - - - -

2.5.6 - Precedence

-Operator precedence in Lua follows the table below, -from lower to higher priority: - -

-     or
-     and
-     <     >     <=    >=    ~=    ==
-     ..
-     +     -
-     *     /     %
-     not   #     - (unary)
-     ^
-

-As usual, -you can use parentheses to change the precedences of an expression. -The concatenation ('..') and exponentiation ('^') -operators are right associative. -All other binary operators are left associative. - - - - - -

2.5.7 - Table Constructors

-Table constructors are expressions that create tables. -Every time a constructor is evaluated, a new table is created. -A constructor can be used to create an empty table -or to create a table and initialize some of its fields. -The general syntax for constructors is - -

-	tableconstructor ::= `{´ [fieldlist] `}´
-	fieldlist ::= field {fieldsep field} [fieldsep]
-	field ::= `[´ exp `]´ `=´ exp | Name `=´ exp | exp
-	fieldsep ::= `,´ | `;´
-
- -

-Each field of the form [exp1] = exp2 adds to the new table an entry -with key exp1 and value exp2. -A field of the form name = exp is equivalent to -["name"] = exp. -Finally, fields of the form exp are equivalent to -[i] = exp, where i are consecutive numerical integers, -starting with 1. -Fields in the other formats do not affect this counting. -For example, - -

-     a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
-

-is equivalent to - -

-     do
-       local t = {}
-       t[f(1)] = g
-       t[1] = "x"         -- 1st exp
-       t[2] = "y"         -- 2nd exp
-       t.x = 1            -- t["x"] = 1
-       t[3] = f(x)        -- 3rd exp
-       t[30] = 23
-       t[4] = 45          -- 4th exp
-       a = t
-     end
-
- -

-If the last field in the list has the form exp -and the expression is a function call or a vararg expression, -then all values returned by this expression enter the list consecutively -(see §2.5.8). -To avoid this, -enclose the function call or the vararg expression -in parentheses (see §2.5). - - -

-The field list can have an optional trailing separator, -as a convenience for machine-generated code. - - - - - -

2.5.8 - Function Calls

-A function call in Lua has the following syntax: - -

-	functioncall ::= prefixexp args
-

-In a function call, -first prefixexp and args are evaluated. -If the value of prefixexp has type function, -then this function is called -with the given arguments. -Otherwise, the prefixexp "call" metamethod is called, -having as first parameter the value of prefixexp, -followed by the original call arguments -(see §2.8). - - -

-The form - -

-	functioncall ::= prefixexp `:´ Name args
-

-can be used to call "methods". -A call v:name(args) -is syntactic sugar for v.name(v,args), -except that v is evaluated only once. - - -

-Arguments have the following syntax: - -

-	args ::= `(´ [explist] `)´
-	args ::= tableconstructor
-	args ::= String
-

-All argument expressions are evaluated before the call. -A call of the form f{fields} is -syntactic sugar for f({fields}); -that is, the argument list is a single new table. -A call of the form f'string' -(or f"string" or f[[string]]) -is syntactic sugar for f('string'); -that is, the argument list is a single literal string. - - -

-As an exception to the free-format syntax of Lua, -you cannot put a line break before the '(' in a function call. -This restriction avoids some ambiguities in the language. -If you write - -

-     a = f
-     (g).x(a)
-

-Lua would see that as a single statement, a = f(g).x(a). -So, if you want two statements, you must add a semi-colon between them. -If you actually want to call f, -you must remove the line break before (g). - - -

-A call of the form return functioncall is called -a tail call. -Lua implements proper tail calls -(or proper tail recursion): -in a tail call, -the called function reuses the stack entry of the calling function. -Therefore, there is no limit on the number of nested tail calls that -a program can execute. -However, a tail call erases any debug information about the -calling function. -Note that a tail call only happens with a particular syntax, -where the return has one single function call as argument; -this syntax makes the calling function return exactly -the returns of the called function. -So, none of the following examples are tail calls: - -

-     return (f(x))        -- results adjusted to 1
-     return 2 * f(x)
-     return x, f(x)       -- additional results
-     f(x); return         -- results discarded
-     return x or f(x)     -- results adjusted to 1
-
- - - - -

2.5.9 - Function Definitions

- -

-The syntax for function definition is - -

-	function ::= function funcbody
-	funcbody ::= `(´ [parlist] `)´ block end
-
- -

-The following syntactic sugar simplifies function definitions: - -

-	stat ::= function funcname funcbody
-	stat ::= local function Name funcbody
-	funcname ::= Name {`.´ Name} [`:´ Name]
-

-The statement - -

-     function f () body end
-

-translates to - -

-     f = function () body end
-

-The statement - -

-     function t.a.b.c.f () body end
-

-translates to - -

-     t.a.b.c.f = function () body end
-

-The statement - -

-     local function f () body end
-

-translates to - -

-     local f; f = function () body end
-

-not to - -

-     local f = function () body end
-

-(This only makes a difference when the body of the function -contains references to f.) - - -

-A function definition is an executable expression, -whose value has type function. -When Lua pre-compiles a chunk, -all its function bodies are pre-compiled too. -Then, whenever Lua executes the function definition, -the function is instantiated (or closed). -This function instance (or closure) -is the final value of the expression. -Different instances of the same function -can refer to different external local variables -and can have different environment tables. - - -

-Parameters act as local variables that are -initialized with the argument values: - -

-	parlist ::= namelist [`,´ `...´] | `...´
-

-When a function is called, -the list of arguments is adjusted to -the length of the list of parameters, -unless the function is a variadic or vararg function, -which is -indicated by three dots ('...') at the end of its parameter list. -A vararg function does not adjust its argument list; -instead, it collects all extra arguments and supplies them -to the function through a vararg expression, -which is also written as three dots. -The value of this expression is a list of all actual extra arguments, -similar to a function with multiple results. -If a vararg expression is used inside another expression -or in the middle of a list of expressions, -then its return list is adjusted to one element. -If the expression is used as the last element of a list of expressions, -then no adjustment is made -(unless that last expression is enclosed in parentheses). - - -

-As an example, consider the following definitions: - -

-     function f(a, b) end
-     function g(a, b, ...) end
-     function r() return 1,2,3 end
-

-Then, we have the following mapping from arguments to parameters and -to the vararg expression: - -

-     CALL            PARAMETERS
-     
-     f(3)             a=3, b=nil
-     f(3, 4)          a=3, b=4
-     f(3, 4, 5)       a=3, b=4
-     f(r(), 10)       a=1, b=10
-     f(r())           a=1, b=2
-     
-     g(3)             a=3, b=nil, ... -->  (nothing)
-     g(3, 4)          a=3, b=4,   ... -->  (nothing)
-     g(3, 4, 5, 8)    a=3, b=4,   ... -->  5  8
-     g(5, r())        a=5, b=1,   ... -->  2  3
-
- -

-Results are returned using the return statement (see §2.4.4). -If control reaches the end of a function -without encountering a return statement, -then the function returns with no results. - - -

-The colon syntax -is used for defining methods, -that is, functions that have an implicit extra parameter self. -Thus, the statement - -

-     function t.a.b.c:f (params) body end
-

-is syntactic sugar for - -

-     t.a.b.c.f = function (self, params) body end
-
- - - - - - -

2.6 - Visibility Rules

- -

- -Lua is a lexically scoped language. -The scope of variables begins at the first statement after -their declaration and lasts until the end of the innermost block that -includes the declaration. -Consider the following example: - -

-     x = 10                -- global variable
-     do                    -- new block
-       local x = x         -- new 'x', with value 10
-       print(x)            --> 10
-       x = x+1
-       do                  -- another block
-         local x = x+1     -- another 'x'
-         print(x)          --> 12
-       end
-       print(x)            --> 11
-     end
-     print(x)              --> 10  (the global one)
-
- -

-Notice that, in a declaration like local x = x, -the new x being declared is not in scope yet, -and so the second x refers to the outside variable. - - -

-Because of the lexical scoping rules, -local variables can be freely accessed by functions -defined inside their scope. -A local variable used by an inner function is called -an upvalue, or external local variable, -inside the inner function. - - -

-Notice that each execution of a local statement -defines new local variables. -Consider the following example: - -

-     a = {}
-     local x = 20
-     for i=1,10 do
-       local y = 0
-       a[i] = function () y=y+1; return x+y end
-     end
-

-The loop creates ten closures -(that is, ten instances of the anonymous function). -Each of these closures uses a different y variable, -while all of them share the same x. - - - - - -

2.7 - Error Handling

- -

-Because Lua is an embedded extension language, -all Lua actions start from C code in the host program -calling a function from the Lua library (see lua_pcall). -Whenever an error occurs during Lua compilation or execution, -control returns to C, -which can take appropriate measures -(such as printing an error message). - - -

-Lua code can explicitly generate an error by calling the -error function. -If you need to catch errors in Lua, -you can use the pcall function. - - - - - -

2.8 - Metatables

- -

-Every value in Lua can have a metatable. -This metatable is an ordinary Lua table -that defines the behavior of the original value -under certain special operations. -You can change several aspects of the behavior -of operations over a value by setting specific fields in its metatable. -For instance, when a non-numeric value is the operand of an addition, -Lua checks for a function in the field "__add" in its metatable. -If it finds one, -Lua calls this function to perform the addition. - - -

-We call the keys in a metatable events -and the values metamethods. -In the previous example, the event is "add" -and the metamethod is the function that performs the addition. - - -

-You can query the metatable of any value -through the getmetatable function. - - -

-You can replace the metatable of tables -through the setmetatable -function. -You cannot change the metatable of other types from Lua -(except by using the debug library); -you must use the C API for that. - - -

-Tables and full userdata have individual metatables -(although multiple tables and userdata can share their metatables). -Values of all other types share one single metatable per type; -that is, there is one single metatable for all numbers, -one for all strings, etc. - - -

-A metatable controls how an object behaves in arithmetic operations, -order comparisons, concatenation, length operation, and indexing. -A metatable also can define a function to be called when a userdata -is garbage collected. -For each of these operations Lua associates a specific key -called an event. -When Lua performs one of these operations over a value, -it checks whether this value has a metatable with the corresponding event. -If so, the value associated with that key (the metamethod) -controls how Lua will perform the operation. - - -

-Metatables control the operations listed next. -Each operation is identified by its corresponding name. -The key for each operation is a string with its name prefixed by -two underscores, '__'; -for instance, the key for operation "add" is the -string "__add". -The semantics of these operations is better explained by a Lua function -describing how the interpreter executes the operation. - - -

-The code shown here in Lua is only illustrative; -the real behavior is hard coded in the interpreter -and it is much more efficient than this simulation. -All functions used in these descriptions -(rawget, tonumber, etc.) -are described in §5.1. -In particular, to retrieve the metamethod of a given object, -we use the expression - -

-     metatable(obj)[event]
-

-This should be read as - -

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

- -That is, the access to a metamethod does not invoke other metamethods, -and the access to objects with no metatables does not fail -(it simply results in nil). - - - -

    - -
  • "add": -the + operation. - - - -

    -The function getbinhandler below defines how Lua chooses a handler -for a binary operation. -First, Lua tries the first operand. -If its type does not define a handler for the operation, -then Lua tries the second operand. - -

    -     function getbinhandler (op1, op2, event)
    -       return metatable(op1)[event] or metatable(op2)[event]
    -     end
    -

    -By using this function, -the behavior of the op1 + op2 is - -

    -     function add_event (op1, op2)
    -       local o1, o2 = tonumber(op1), tonumber(op2)
    -       if o1 and o2 then  -- both operands are numeric?
    -         return o1 + o2   -- '+' here is the primitive 'add'
    -       else  -- at least one of the operands is not numeric
    -         local h = getbinhandler(op1, op2, "__add")
    -         if h then
    -           -- call the handler with both operands
    -           return (h(op1, op2))
    -         else  -- no handler available: default behavior
    -           error(···)
    -         end
    -       end
    -     end
    -

    -

  • - -
  • "sub": -the - operation. - -Behavior similar to the "add" operation. -
  • - -
  • "mul": -the * operation. - -Behavior similar to the "add" operation. -
  • - -
  • "div": -the / operation. - -Behavior similar to the "add" operation. -
  • - -
  • "mod": -the % operation. - -Behavior similar to the "add" operation, -with the operation -o1 - floor(o1/o2)*o2 as the primitive operation. -
  • - -
  • "pow": -the ^ (exponentiation) operation. - -Behavior similar to the "add" operation, -with the function pow (from the C math library) -as the primitive operation. -
  • - -
  • "unm": -the unary - operation. - - -
    -     function unm_event (op)
    -       local o = tonumber(op)
    -       if o then  -- operand is numeric?
    -         return -o  -- '-' here is the primitive 'unm'
    -       else  -- the operand is not numeric.
    -         -- Try to get a handler from the operand
    -         local h = metatable(op).__unm
    -         if h then
    -           -- call the handler with the operand
    -           return (h(op))
    -         else  -- no handler available: default behavior
    -           error(···)
    -         end
    -       end
    -     end
    -

    -

  • - -
  • "concat": -the .. (concatenation) operation. - - -
    -     function concat_event (op1, op2)
    -       if (type(op1) == "string" or type(op1) == "number") and
    -          (type(op2) == "string" or type(op2) == "number") then
    -         return op1 .. op2  -- primitive string concatenation
    -       else
    -         local h = getbinhandler(op1, op2, "__concat")
    -         if h then
    -           return (h(op1, op2))
    -         else
    -           error(···)
    -         end
    -       end
    -     end
    -

    -

  • - -
  • "len": -the # operation. - - -
    -     function len_event (op)
    -       if type(op) == "string" then
    -         return strlen(op)         -- primitive string length
    -       elseif type(op) == "table" then
    -         return #op                -- primitive table length
    -       else
    -         local h = metatable(op).__len
    -         if h then
    -           -- call the handler with the operand
    -           return (h(op))
    -         else  -- no handler available: default behavior
    -           error(···)
    -         end
    -       end
    -     end
    -

    -See §2.5.5 for a description of the length of a table. -

  • - -
  • "eq": -the == operation. - -The function getcomphandler defines how Lua chooses a metamethod -for comparison operators. -A metamethod only is selected when both objects -being compared have the same type -and the same metamethod for the selected operation. - -
    -     function getcomphandler (op1, op2, event)
    -       if type(op1) ~= type(op2) then return nil end
    -       local mm1 = metatable(op1)[event]
    -       local mm2 = metatable(op2)[event]
    -       if mm1 == mm2 then return mm1 else return nil end
    -     end
    -

    -The "eq" event is defined as follows: - -

    -     function eq_event (op1, op2)
    -       if type(op1) ~= type(op2) then  -- different types?
    -         return false   -- different objects
    -       end
    -       if op1 == op2 then   -- primitive equal?
    -         return true   -- objects are equal
    -       end
    -       -- try metamethod
    -       local h = getcomphandler(op1, op2, "__eq")
    -       if h then
    -         return (h(op1, op2))
    -       else
    -         return false
    -       end
    -     end
    -

    -a ~= b is equivalent to not (a == b). -

  • - -
  • "lt": -the < operation. - - -
    -     function lt_event (op1, op2)
    -       if type(op1) == "number" and type(op2) == "number" then
    -         return op1 < op2   -- numeric comparison
    -       elseif type(op1) == "string" and type(op2) == "string" then
    -         return op1 < op2   -- lexicographic comparison
    -       else
    -         local h = getcomphandler(op1, op2, "__lt")
    -         if h then
    -           return (h(op1, op2))
    -         else
    -           error(···)
    -         end
    -       end
    -     end
    -

    -a > b is equivalent to b < a. -

  • - -
  • "le": -the <= operation. - - -
    -     function le_event (op1, op2)
    -       if type(op1) == "number" and type(op2) == "number" then
    -         return op1 <= op2   -- numeric comparison
    -       elseif type(op1) == "string" and type(op2) == "string" then
    -         return op1 <= op2   -- lexicographic comparison
    -       else
    -         local h = getcomphandler(op1, op2, "__le")
    -         if h then
    -           return (h(op1, op2))
    -         else
    -           h = getcomphandler(op1, op2, "__lt")
    -           if h then
    -             return not h(op2, op1)
    -           else
    -             error(···)
    -           end
    -         end
    -       end
    -     end
    -

    -a >= b is equivalent to b <= a. -Note that, in the absence of a "le" metamethod, -Lua tries the "lt", assuming that a <= b is -equivalent to not (b < a). -

  • - -
  • "index": -The indexing access table[key]. - - -
    -     function gettable_event (table, key)
    -       local h
    -       if type(table) == "table" then
    -         local v = rawget(table, key)
    -         if v ~= nil then return v end
    -         h = metatable(table).__index
    -         if h == nil then return nil end
    -       else
    -         h = metatable(table).__index
    -         if h == nil then
    -           error(···)
    -         end
    -       end
    -       if type(h) == "function" then
    -         return (h(table, key))     -- call the handler
    -       else return h[key]           -- or repeat operation on it
    -       end
    -     end
    -

    -

  • - -
  • "newindex": -The indexing assignment table[key] = value. - - -
    -     function settable_event (table, key, value)
    -       local h
    -       if type(table) == "table" then
    -         local v = rawget(table, key)
    -         if v ~= nil then rawset(table, key, value); return end
    -         h = metatable(table).__newindex
    -         if h == nil then rawset(table, key, value); return end
    -       else
    -         h = metatable(table).__newindex
    -         if h == nil then
    -           error(···)
    -         end
    -       end
    -       if type(h) == "function" then
    -         h(table, key,value)           -- call the handler
    -       else h[key] = value             -- or repeat operation on it
    -       end
    -     end
    -

    -

  • - -
  • "call": -called when Lua calls a value. - - -
    -     function function_event (func, ...)
    -       if type(func) == "function" then
    -         return func(...)   -- primitive call
    -       else
    -         local h = metatable(func).__call
    -         if h then
    -           return h(func, ...)
    -         else
    -           error(···)
    -         end
    -       end
    -     end
    -

    -

  • - -
- - - - -

2.9 - Environments

- -

-Besides metatables, -objects of types thread, function, and userdata -have another table associated with them, -called their environment. -Like metatables, environments are regular tables and -multiple objects can share the same environment. - - -

-Threads are created sharing the environment of the creating thread. -Userdata and C functions are created sharing the environment -of the creating C function. -Non-nested Lua functions -(created by loadfile, loadstring or load) -are created sharing the environment of the creating thread. -Nested Lua functions are created sharing the environment of -the creating Lua function. - - -

-Environments associated with userdata have no meaning for Lua. -It is only a convenience feature for programmers to associate a table to -a userdata. - - -

-Environments associated with threads are called -global environments. -They are used as the default environment for threads and -non-nested Lua functions created by the thread -and can be directly accessed by C code (see §3.3). - - -

-The environment associated with a C function can be directly -accessed by C code (see §3.3). -It is used as the default environment for other C functions -and userdata created by the function. - - -

-Environments associated with Lua functions are used to resolve -all accesses to global variables within the function (see §2.3). -They are used as the default environment for nested Lua functions -created by the function. - - -

-You can change the environment of a Lua function or the -running thread by calling setfenv. -You can get the environment of a Lua function or the running thread -by calling getfenv. -To manipulate the environment of other objects -(userdata, C functions, other threads) you must -use the C API. - - - - - -

2.10 - Garbage Collection

- -

-Lua performs automatic memory management. -This means that -you have to worry neither about allocating memory for new objects -nor about freeing it when the objects are no longer needed. -Lua manages memory automatically by running -a garbage collector from time to time -to collect all dead objects -(that is, objects that are no longer accessible from Lua). -All memory used by Lua is subject to automatic management: -tables, userdata, functions, threads, strings, etc. - - -

-Lua implements an incremental mark-and-sweep collector. -It uses two numbers to control its garbage-collection cycles: -the garbage-collector pause and -the garbage-collector step multiplier. -Both use percentage points as units -(so that a value of 100 means an internal value of 1). - - -

-The garbage-collector pause -controls how long the collector waits before starting a new cycle. -Larger values make the collector less aggressive. -Values smaller than 100 mean the collector will not wait to -start a new cycle. -A value of 200 means that the collector waits for the total memory in use -to double before starting a new cycle. - - -

-The step multiplier -controls the relative speed of the collector relative to -memory allocation. -Larger values make the collector more aggressive but also increase -the size of each incremental step. -Values smaller than 100 make the collector too slow and -can result in the collector never finishing a cycle. -The default, 200, means that the collector runs at "twice" -the speed of memory allocation. - - -

-You can change these numbers by calling lua_gc in C -or collectgarbage in Lua. -With these functions you can also control -the collector directly (e.g., stop and restart it). - - - -

2.10.1 - Garbage-Collection Metamethods

- -

-Using the C API, -you can set garbage-collector metamethods for userdata (see §2.8). -These metamethods are also called finalizers. -Finalizers allow you to coordinate Lua's garbage collection -with external resource management -(such as closing files, network or database connections, -or freeing your own memory). - - -

-Garbage userdata with a field __gc in their metatables are not -collected immediately by the garbage collector. -Instead, Lua puts them in a list. -After the collection, -Lua does the equivalent of the following function -for each userdata in that list: - -

-     function gc_event (udata)
-       local h = metatable(udata).__gc
-       if h then
-         h(udata)
-       end
-     end
-
- -

-At the end of each garbage-collection cycle, -the finalizers for userdata are called in reverse -order of their creation, -among those collected in that cycle. -That is, the first finalizer to be called is the one associated -with the userdata created last in the program. -The userdata itself is freed only in the next garbage-collection cycle. - - - - - -

2.10.2 - Weak Tables

- -

-A weak table is a table whose elements are -weak references. -A weak reference is ignored by the garbage collector. -In other words, -if the only references to an object are weak references, -then the garbage collector will collect this object. - - -

-A weak table can have weak keys, weak values, or both. -A table with weak keys allows the collection of its keys, -but prevents the collection of its values. -A table with both weak keys and weak values allows the collection of -both keys and values. -In any case, if either the key or the value is collected, -the whole pair is removed from the table. -The weakness of a table is controlled by the -__mode field of its metatable. -If the __mode field is a string containing the character 'k', -the keys in the table are weak. -If __mode contains 'v', -the values in the table are weak. - - -

-After you use a table as a metatable, -you should not change the value of its __mode field. -Otherwise, the weak behavior of the tables controlled by this -metatable is undefined. - - - - - - - -

2.11 - Coroutines

- -

-Lua supports coroutines, -also called collaborative multithreading. -A coroutine in Lua represents an independent thread of execution. -Unlike threads in multithread systems, however, -a coroutine only suspends its execution by explicitly calling -a yield function. - - -

-You create a coroutine with a call to coroutine.create. -Its sole argument is a function -that is the main function of the coroutine. -The create function only creates a new coroutine and -returns a handle to it (an object of type thread); -it does not start the coroutine execution. - - -

-When you first call coroutine.resume, -passing as its first argument -a thread returned by coroutine.create, -the coroutine starts its execution, -at the first line of its main function. -Extra arguments passed to coroutine.resume are passed on -to the coroutine main function. -After the coroutine starts running, -it runs until it terminates or yields. - - -

-A coroutine can terminate its execution in two ways: -normally, when its main function returns -(explicitly or implicitly, after the last instruction); -and abnormally, if there is an unprotected error. -In the first case, coroutine.resume returns true, -plus any values returned by the coroutine main function. -In case of errors, coroutine.resume returns false -plus an error message. - - -

-A coroutine yields by calling coroutine.yield. -When a coroutine yields, -the corresponding coroutine.resume returns immediately, -even if the yield happens inside nested function calls -(that is, not in the main function, -but in a function directly or indirectly called by the main function). -In the case of a yield, coroutine.resume also returns true, -plus any values passed to coroutine.yield. -The next time you resume the same coroutine, -it continues its execution from the point where it yielded, -with the call to coroutine.yield returning any extra -arguments passed to coroutine.resume. - - -

-Like coroutine.create, -the coroutine.wrap function also creates a coroutine, -but instead of returning the coroutine itself, -it returns a function that, when called, resumes the coroutine. -Any arguments passed to this function -go as extra arguments to coroutine.resume. -coroutine.wrap returns all the values returned by coroutine.resume, -except the first one (the boolean error code). -Unlike coroutine.resume, -coroutine.wrap does not catch errors; -any error is propagated to the caller. - - -

-As an example, -consider the following code: - -

-     function foo (a)
-       print("foo", a)
-       return coroutine.yield(2*a)
-     end
-     
-     co = coroutine.create(function (a,b)
-           print("co-body", a, b)
-           local r = foo(a+1)
-           print("co-body", r)
-           local r, s = coroutine.yield(a+b, a-b)
-           print("co-body", r, s)
-           return b, "end"
-     end)
-            
-     print("main", coroutine.resume(co, 1, 10))
-     print("main", coroutine.resume(co, "r"))
-     print("main", coroutine.resume(co, "x", "y"))
-     print("main", coroutine.resume(co, "x", "y"))
-

-When you run it, it produces the following output: - -

-     co-body 1       10
-     foo     2
-     
-     main    true    4
-     co-body r
-     main    true    11      -9
-     co-body x       y
-     main    true    10      end
-     main    false   cannot resume dead coroutine
-
- - - - -

3 - The Application Program Interface

- -

- -This section describes the C API for Lua, that is, -the set of C functions available to the host program to communicate -with Lua. -All API functions and related types and constants -are declared in the header file lua.h. - - -

-Even when we use the term "function", -any facility in the API may be provided as a macro instead. -All such macros use each of their arguments exactly once -(except for the first argument, which is always a Lua state), -and so do not generate any hidden side-effects. - - -

-As in most C libraries, -the Lua API functions do not check their arguments for validity or consistency. -However, you can change this behavior by compiling Lua -with a proper definition for the macro luai_apicheck, -in file luaconf.h. - - - -

3.1 - The Stack

- -

-Lua uses a virtual stack to pass values to and from C. -Each element in this stack represents a Lua value -(nil, number, string, etc.). - - -

-Whenever Lua calls C, the called function gets a new stack, -which is independent of previous stacks and of stacks of -C functions that are still active. -This stack initially contains any arguments to the C function -and it is where the C function pushes its results -to be returned to the caller (see lua_CFunction). - - -

-For convenience, -most query operations in the API do not follow a strict stack discipline. -Instead, they can refer to any element in the stack -by using an index: -A positive index represents an absolute stack position -(starting at 1); -a negative index represents an offset relative to the top of the stack. -More specifically, if the stack has n elements, -then index 1 represents the first element -(that is, the element that was pushed onto the stack first) -and -index n represents the last element; -index -1 also represents the last element -(that is, the element at the top) -and index -n represents the first element. -We say that an index is valid -if it lies between 1 and the stack top -(that is, if 1 ≤ abs(index) ≤ top). - - - - - - -

3.2 - Stack Size

- -

-When you interact with Lua API, -you are responsible for ensuring consistency. -In particular, -you are responsible for controlling stack overflow. -You can use the function lua_checkstack -to grow the stack size. - - -

-Whenever Lua calls C, -it ensures that at least LUA_MINSTACK stack positions are available. -LUA_MINSTACK is defined as 20, -so that usually you do not have to worry about stack space -unless your code has loops pushing elements onto the stack. - - -

-Most query functions accept as indices any value inside the -available stack space, that is, indices up to the maximum stack size -you have set through lua_checkstack. -Such indices are called acceptable indices. -More formally, we define an acceptable index -as follows: - -

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

-Note that 0 is never an acceptable index. - - - - - -

3.3 - Pseudo-Indices

- -

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

-The thread environment (where global variables live) is -always at pseudo-index LUA_GLOBALSINDEX. -The environment of the running C function is always -at pseudo-index LUA_ENVIRONINDEX. - - -

-To access and change the value of global variables, -you can use regular table operations over an environment table. -For instance, to access the value of a global variable, do - -

-     lua_getfield(L, LUA_GLOBALSINDEX, varname);
-
- - - - -

3.4 - C Closures

- -

-When a C function is created, -it is possible to associate some values with it, -thus creating a C closure; -these values are called upvalues and are -accessible to the function whenever it is called -(see lua_pushcclosure). - - -

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

3.5 - Registry

- -

-Lua provides a registry, -a pre-defined table that can be used by any C code to -store whatever Lua value it needs to store. -This table is always located at pseudo-index -LUA_REGISTRYINDEX. -Any C library can store data into this table, -but it should take care to choose keys different from those used -by other libraries, to avoid collisions. -Typically, you should use as key a string containing your library name -or a light userdata with the address of a C object in your code. - - -

-The integer keys in the registry are used by the reference mechanism, -implemented by the auxiliary library, -and therefore should not be used for other purposes. - - - - - -

3.6 - Error Handling in C

- -

-Internally, Lua uses the C longjmp facility to handle errors. -(You can also choose to use exceptions if you use C++; -see file luaconf.h.) -When Lua faces any error -(such as memory allocation errors, type errors, syntax errors, -and runtime errors) -it raises an error; -that is, it does a long jump. -A protected environment uses setjmp -to set a recover point; -any error jumps to the most recent active recover point. - - -

-Most functions in the API can throw an error, -for instance due to a memory allocation error. -The documentation for each function indicates whether -it can throw errors. - - -

-Inside a C function you can throw an error by calling lua_error. - - - - - -

3.7 - Functions and Types

- -

-Here we list all functions and types from the C API in -alphabetical order. -Each function has an indicator like this: -[-o, +p, x] - - -

-The first field, o, -is how many elements the function pops from the stack. -The second field, p, -is how many elements the function pushes onto the stack. -(Any function always pushes its results after popping its arguments.) -A field in the form x|y means the function can push (or pop) -x or y elements, -depending on the situation; -an interrogation mark '?' means that -we cannot know how many elements the function pops/pushes -by looking only at its arguments -(e.g., they may depend on what is on the stack). -The third field, x, -tells whether the function may throw errors: -'-' means the function never throws any error; -'m' means the function may throw an error -only due to not enough memory; -'e' means the function may throw other kinds of errors; -'v' means the function may throw an error on purpose. - - - -


lua_Alloc

-
typedef void * (*lua_Alloc) (void *ud,
-                             void *ptr,
-                             size_t osize,
-                             size_t nsize);
- -

-The type of the memory-allocation function used by Lua states. -The allocator function must provide a -functionality similar to realloc, -but not exactly the same. -Its arguments are -ud, an opaque pointer passed to lua_newstate; -ptr, a pointer to the block being allocated/reallocated/freed; -osize, the original size of the block; -nsize, the new size of the block. -ptr is NULL if and only if osize is zero. -When nsize is zero, the allocator must return NULL; -if osize is not zero, -it should free the block pointed to by ptr. -When nsize is not zero, the allocator returns NULL -if and only if it cannot fill the request. -When nsize is not zero and osize is zero, -the allocator should behave like malloc. -When nsize and osize are not zero, -the allocator behaves like realloc. -Lua assumes that the allocator never fails when -osize >= nsize. - - -

-Here is a simple implementation for the allocator function. -It is used in the auxiliary library by luaL_newstate. - -

-     static void *l_alloc (void *ud, void *ptr, size_t osize,
-                                                size_t nsize) {
-       (void)ud;  (void)osize;  /* not used */
-       if (nsize == 0) {
-         free(ptr);
-         return NULL;
-       }
-       else
-         return realloc(ptr, nsize);
-     }
-

-This code assumes -that free(NULL) has no effect and that -realloc(NULL, size) is equivalent to malloc(size). -ANSI C ensures both behaviors. - - - - - -


lua_atpanic

-[-0, +0, -] -

lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);
- -

-Sets a new panic function and returns the old one. - - -

-If an error happens outside any protected environment, -Lua calls a panic function -and then calls exit(EXIT_FAILURE), -thus exiting the host application. -Your panic function can avoid this exit by -never returning (e.g., doing a long jump). - - -

-The panic function can access the error message at the top of the stack. - - - - - -


lua_call

-[-(nargs + 1), +nresults, e] -

void lua_call (lua_State *L, int nargs, int nresults);
- -

-Calls a function. - - -

-To call a function you must use the following protocol: -first, the function to be called is pushed onto the stack; -then, the arguments to the function are pushed -in direct order; -that is, the first argument is pushed first. -Finally you call lua_call; -nargs is the number of arguments that you pushed onto the stack. -All arguments and the function value are popped from the stack -when the function is called. -The function results are pushed onto the stack when the function returns. -The number of results is adjusted to nresults, -unless nresults is LUA_MULTRET. -In this case, all results from the function are pushed. -Lua takes care that the returned values fit into the stack space. -The function results are pushed onto the stack in direct order -(the first result is pushed first), -so that after the call the last result is on the top of the stack. - - -

-Any error inside the called function is propagated upwards -(with a longjmp). - - -

-The following example shows how the host program can do the -equivalent to this Lua code: - -

-     a = f("how", t.x, 14)
-

-Here it is in C: - -

-     lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
-     lua_pushstring(L, "how");                        /* 1st argument */
-     lua_getfield(L, LUA_GLOBALSINDEX, "t");   /* table to be indexed */
-     lua_getfield(L, -1, "x");        /* push result of t.x (2nd arg) */
-     lua_remove(L, -2);                  /* remove 't' from the stack */
-     lua_pushinteger(L, 14);                          /* 3rd argument */
-     lua_call(L, 3, 1);     /* call 'f' with 3 arguments and 1 result */
-     lua_setfield(L, LUA_GLOBALSINDEX, "a");        /* set global 'a' */
-

-Note that the code above is "balanced": -at its end, the stack is back to its original configuration. -This is considered good programming practice. - - - - - -


lua_CFunction

-
typedef int (*lua_CFunction) (lua_State *L);
- -

-Type for C functions. - - -

-In order to communicate properly with Lua, -a C function must use the following protocol, -which defines the way parameters and results are passed: -a C function receives its arguments from Lua in its stack -in direct order (the first argument is pushed first). -So, when the function starts, -lua_gettop(L) returns the number of arguments received by the function. -The first argument (if any) is at index 1 -and its last argument is at index lua_gettop(L). -To return values to Lua, a C function just pushes them onto the stack, -in direct order (the first result is pushed first), -and returns the number of results. -Any other value in the stack below the results will be properly -discarded by Lua. -Like a Lua function, a C function called by Lua can also return -many results. - - -

-As an example, the following function receives a variable number -of numerical arguments and returns their average and sum: - -

-     static int foo (lua_State *L) {
-       int n = lua_gettop(L);    /* number of arguments */
-       lua_Number sum = 0;
-       int i;
-       for (i = 1; i <= n; i++) {
-         if (!lua_isnumber(L, i)) {
-           lua_pushstring(L, "incorrect argument");
-           lua_error(L);
-         }
-         sum += lua_tonumber(L, i);
-       }
-       lua_pushnumber(L, sum/n);        /* first result */
-       lua_pushnumber(L, sum);         /* second result */
-       return 2;                   /* number of results */
-     }
-
- - - - -

lua_checkstack

-[-0, +0, m] -

int lua_checkstack (lua_State *L, int extra);
- -

-Ensures that there are at least extra free stack slots in the stack. -It returns false if it cannot grow the stack to that size. -This function never shrinks the stack; -if the stack is already larger than the new size, -it is left unchanged. - - - - - -


lua_close

-[-0, +0, -] -

void lua_close (lua_State *L);
- -

-Destroys all objects in the given Lua state -(calling the corresponding garbage-collection metamethods, if any) -and frees all dynamic memory used by this state. -On several platforms, you may not need to call this function, -because all resources are naturally released when the host program ends. -On the other hand, long-running programs, -such as a daemon or a web server, -might need to release states as soon as they are not needed, -to avoid growing too large. - - - - - -


lua_concat

-[-n, +1, e] -

void lua_concat (lua_State *L, int n);
- -

-Concatenates the n values at the top of the stack, -pops them, and leaves the result at the top. -If n is 1, the result is the single value on the stack -(that is, the function does nothing); -if n is 0, the result is the empty string. -Concatenation is performed following the usual semantics of Lua -(see §2.5.4). - - - - - -


lua_cpcall

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

int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
- -

-Calls the C function func in protected mode. -func starts with only one element in its stack, -a light userdata containing ud. -In case of errors, -lua_cpcall returns the same error codes as lua_pcall, -plus the error object on the top of the stack; -otherwise, it returns zero, and does not change the stack. -All values returned by func are discarded. - - - - - -


lua_createtable

-[-0, +1, m] -

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

-Creates a new empty table and pushes it onto the stack. -The new table has space pre-allocated -for narr array elements and nrec non-array elements. -This pre-allocation is useful when you know exactly how many elements -the table will have. -Otherwise you can use the function lua_newtable. - - - - - -


lua_dump

-[-0, +0, m] -

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

-Dumps a function as a binary chunk. -Receives a Lua function on the top of the stack -and produces a binary chunk that, -if loaded again, -results in a function equivalent to the one dumped. -As it produces parts of the chunk, -lua_dump calls function writer (see lua_Writer) -with the given data -to write them. - - -

-The value returned is the error code returned by the last -call to the writer; -0 means no errors. - - -

-This function does not pop the Lua function from the stack. - - - - - -


lua_equal

-[-0, +0, e] -

int lua_equal (lua_State *L, int index1, int index2);
- -

-Returns 1 if the two values in acceptable indices index1 and -index2 are equal, -following the semantics of the Lua == operator -(that is, may call metamethods). -Otherwise returns 0. -Also returns 0 if any of the indices is non valid. - - - - - -


lua_error

-[-1, +0, v] -

int lua_error (lua_State *L);
- -

-Generates a Lua error. -The error message (which can actually be a Lua value of any type) -must be on the stack top. -This function does a long jump, -and therefore never returns. -(see luaL_error). - - - - - -


lua_gc

-[-0, +0, e] -

int lua_gc (lua_State *L, int what, int data);
- -

-Controls the garbage collector. - - -

-This function performs several tasks, -according to the value of the parameter what: - -

    - -
  • LUA_GCSTOP: -stops the garbage collector. -
  • - -
  • LUA_GCRESTART: -restarts the garbage collector. -
  • - -
  • LUA_GCCOLLECT: -performs a full garbage-collection cycle. -
  • - -
  • LUA_GCCOUNT: -returns the current amount of memory (in Kbytes) in use by Lua. -
  • - -
  • LUA_GCCOUNTB: -returns the remainder of dividing the current amount of bytes of -memory in use by Lua by 1024. -
  • - -
  • LUA_GCSTEP: -performs an incremental step of garbage collection. -The step "size" is controlled by data -(larger values mean more steps) in a non-specified way. -If you want to control the step size -you must experimentally tune the value of data. -The function returns 1 if the step finished a -garbage-collection cycle. -
  • - -
  • LUA_GCSETPAUSE: -sets data as the new value -for the pause of the collector (see §2.10). -The function returns the previous value of the pause. -
  • - -
  • LUA_GCSETSTEPMUL: -sets data as the new value for the step multiplier of -the collector (see §2.10). -The function returns the previous value of the step multiplier. -
  • - -
- - - - -

lua_getallocf

-[-0, +0, -] -

lua_Alloc lua_getallocf (lua_State *L, void **ud);
- -

-Returns the memory-allocation function of a given state. -If ud is not NULL, Lua stores in *ud the -opaque pointer passed to lua_newstate. - - - - - -


lua_getfenv

-[-0, +1, -] -

void lua_getfenv (lua_State *L, int index);
- -

-Pushes onto the stack the environment table of -the value at the given index. - - - - - -


lua_getfield

-[-0, +1, e] -

void lua_getfield (lua_State *L, int index, const char *k);
- -

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


lua_getglobal

-[-0, +1, e] -

void lua_getglobal (lua_State *L, const char *name);
- -

-Pushes onto the stack the value of the global name. -It is defined as a macro: - -

-     #define lua_getglobal(L,s)  lua_getfield(L, LUA_GLOBALSINDEX, s)
-
- - - - -

lua_getmetatable

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

int lua_getmetatable (lua_State *L, int index);
- -

-Pushes onto the stack the metatable of the value at the given -acceptable index. -If the index is not valid, -or if the value does not have a metatable, -the function returns 0 and pushes nothing on the stack. - - - - - -


lua_gettable

-[-1, +1, e] -

void lua_gettable (lua_State *L, int index);
- -

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

-This function pops the key from the stack -(putting the resulting value in its place). -As in Lua, this function may trigger a metamethod -for the "index" event (see §2.8). - - - - - -


lua_gettop

-[-0, +0, -] -

int lua_gettop (lua_State *L);
- -

-Returns the index of the top element in the stack. -Because indices start at 1, -this result is equal to the number of elements in the stack -(and so 0 means an empty stack). - - - - - -


lua_insert

-[-1, +1, -] -

void lua_insert (lua_State *L, int index);
- -

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


lua_Integer

-
typedef ptrdiff_t lua_Integer;
- -

-The type used by the Lua API to represent integral values. - - -

-By default it is a ptrdiff_t, -which is usually the largest signed integral type the machine handles -"comfortably". - - - - - -


lua_isboolean

-[-0, +0, -] -

int lua_isboolean (lua_State *L, int index);
- -

-Returns 1 if the value at the given acceptable index has type boolean, -and 0 otherwise. - - - - - -


lua_iscfunction

-[-0, +0, -] -

int lua_iscfunction (lua_State *L, int index);
- -

-Returns 1 if the value at the given acceptable index is a C function, -and 0 otherwise. - - - - - -


lua_isfunction

-[-0, +0, -] -

int lua_isfunction (lua_State *L, int index);
- -

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


lua_islightuserdata

-[-0, +0, -] -

int lua_islightuserdata (lua_State *L, int index);
- -

-Returns 1 if the value at the given acceptable index is a light userdata, -and 0 otherwise. - - - - - -


lua_isnil

-[-0, +0, -] -

int lua_isnil (lua_State *L, int index);
- -

-Returns 1 if the value at the given acceptable index is nil, -and 0 otherwise. - - - - - -


lua_isnone

-[-0, +0, -] -

int lua_isnone (lua_State *L, int index);
- -

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


lua_isnoneornil

-[-0, +0, -] -

int lua_isnoneornil (lua_State *L, int index);
- -

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


lua_isnumber

-[-0, +0, -] -

int lua_isnumber (lua_State *L, int index);
- -

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


lua_isstring

-[-0, +0, -] -

int lua_isstring (lua_State *L, int index);
- -

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


lua_istable

-[-0, +0, -] -

int lua_istable (lua_State *L, int index);
- -

-Returns 1 if the value at the given acceptable index is a table, -and 0 otherwise. - - - - - -


lua_isthread

-[-0, +0, -] -

int lua_isthread (lua_State *L, int index);
- -

-Returns 1 if the value at the given acceptable index is a thread, -and 0 otherwise. - - - - - -


lua_isuserdata

-[-0, +0, -] -

int lua_isuserdata (lua_State *L, int index);
- -

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


lua_lessthan

-[-0, +0, e] -

int lua_lessthan (lua_State *L, int index1, int index2);
- -

-Returns 1 if the value at acceptable index index1 is smaller -than the value at acceptable index index2, -following the semantics of the Lua < operator -(that is, may call metamethods). -Otherwise returns 0. -Also returns 0 if any of the indices is non valid. - - - - - -


lua_load

-[-0, +1, -] -

int lua_load (lua_State *L,
-              lua_Reader reader,
-              void *data,
-              const char *chunkname);
- -

-Loads a Lua chunk. -If there are no errors, -lua_load pushes the compiled chunk as a Lua -function on top of the stack. -Otherwise, it pushes an error message. -The return values of lua_load are: - -

    - -
  • 0: no errors;
  • - -
  • LUA_ERRSYNTAX: -syntax error during pre-compilation;
  • - -
  • LUA_ERRMEM: -memory allocation error.
  • - -
- -

-This function only loads a chunk; -it does not run it. - - -

-lua_load automatically detects whether the chunk is text or binary, -and loads it accordingly (see program luac). - - -

-The lua_load function uses a user-supplied reader function -to read the chunk (see lua_Reader). -The data argument is an opaque value passed to the reader function. - - -

-The chunkname argument gives a name to the chunk, -which is used for error messages and in debug information (see §3.8). - - - - - -


lua_newstate

-[-0, +0, -] -

lua_State *lua_newstate (lua_Alloc f, void *ud);
- -

-Creates a new, independent state. -Returns NULL if cannot create the state -(due to lack of memory). -The argument f is the allocator function; -Lua does all memory allocation for this state through this function. -The second argument, ud, is an opaque pointer that Lua -simply passes to the allocator in every call. - - - - - -


lua_newtable

-[-0, +1, m] -

void lua_newtable (lua_State *L);
- -

-Creates a new empty table and pushes it onto the stack. -It is equivalent to lua_createtable(L, 0, 0). - - - - - -


lua_newthread

-[-0, +1, m] -

lua_State *lua_newthread (lua_State *L);
- -

-Creates a new thread, pushes it on the stack, -and returns a pointer to a lua_State that represents this new thread. -The new state returned by this function shares with the original state -all global objects (such as tables), -but has an independent execution stack. - - -

-There is no explicit function to close or to destroy a thread. -Threads are subject to garbage collection, -like any Lua object. - - - - - -


lua_newuserdata

-[-0, +1, m] -

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

-This function allocates a new block of memory with the given size, -pushes onto the stack a new full userdata with the block address, -and returns this address. - - -

-Userdata represent C values in Lua. -A full userdata represents a block of memory. -It is an object (like a table): -you must create it, it can have its own metatable, -and you can detect when it is being collected. -A full userdata is only equal to itself (under raw equality). - - -

-When Lua collects a full userdata with a gc metamethod, -Lua calls the metamethod and marks the userdata as finalized. -When this userdata is collected again then -Lua frees its corresponding memory. - - - - - -


lua_next

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

int lua_next (lua_State *L, int index);
- -

-Pops a key from the stack, -and pushes a key-value pair from the table at the given index -(the "next" pair after the given key). -If there are no more elements in the table, -then lua_next returns 0 (and pushes nothing). - - -

-A typical traversal looks like this: - -

-     /* table is in the stack at index 't' */
-     lua_pushnil(L);  /* first key */
-     while (lua_next(L, t) != 0) {
-       /* uses 'key' (at index -2) and 'value' (at index -1) */
-       printf("%s - %s\n",
-              lua_typename(L, lua_type(L, -2)),
-              lua_typename(L, lua_type(L, -1)));
-       /* removes 'value'; keeps 'key' for next iteration */
-       lua_pop(L, 1);
-     }
-
- -

-While traversing a table, -do not call lua_tolstring directly on a key, -unless you know that the key is actually a string. -Recall that lua_tolstring changes -the value at the given index; -this confuses the next call to lua_next. - - - - - -


lua_Number

-
typedef double lua_Number;
- -

-The type of numbers in Lua. -By default, it is double, but that can be changed in luaconf.h. - - -

-Through the configuration file you can change -Lua to operate with another type for numbers (e.g., float or long). - - - - - -


lua_objlen

-[-0, +0, -] -

size_t lua_objlen (lua_State *L, int index);
- -

-Returns the "length" of the value at the given acceptable index: -for strings, this is the string length; -for tables, this is the result of the length operator ('#'); -for userdata, this is the size of the block of memory allocated -for the userdata; -for other values, it is 0. - - - - - -


lua_pcall

-[-(nargs + 1), +(nresults|1), -] -

int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
- -

-Calls a function in protected mode. - - -

-Both nargs and nresults have the same meaning as -in lua_call. -If there are no errors during the call, -lua_pcall behaves exactly like lua_call. -However, if there is any error, -lua_pcall catches it, -pushes a single value on the stack (the error message), -and returns an error code. -Like lua_call, -lua_pcall always removes the function -and its arguments from the stack. - - -

-If errfunc is 0, -then the error message returned on the stack -is exactly the original error message. -Otherwise, errfunc is the stack index of an -error handler function. -(In the current implementation, this index cannot be a pseudo-index.) -In case of runtime errors, -this function will be called with the error message -and its return value will be the message returned on the stack by lua_pcall. - - -

-Typically, the error handler function is used to add more debug -information to the error message, such as a stack traceback. -Such information cannot be gathered after the return of lua_pcall, -since by then the stack has unwound. - - -

-The lua_pcall function returns 0 in case of success -or one of the following error codes -(defined in lua.h): - -

    - -
  • LUA_ERRRUN: -a runtime error. -
  • - -
  • LUA_ERRMEM: -memory allocation error. -For such errors, Lua does not call the error handler function. -
  • - -
  • LUA_ERRERR: -error while running the error handler function. -
  • - -
- - - - -

lua_pop

-[-n, +0, -] -

void lua_pop (lua_State *L, int n);
- -

-Pops n elements from the stack. - - - - - -


lua_pushboolean

-[-0, +1, -] -

void lua_pushboolean (lua_State *L, int b);
- -

-Pushes a boolean value with value b onto the stack. - - - - - -


lua_pushcclosure

-[-n, +1, m] -

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

-Pushes a new C closure onto the stack. - - -

-When a C function is created, -it is possible to associate some values with it, -thus creating a C closure (see §3.4); -these values are then accessible to the function whenever it is called. -To associate values with a C function, -first these values should be pushed onto the stack -(when there are multiple values, the first value is pushed first). -Then lua_pushcclosure -is called to create and push the C function onto the stack, -with the argument n telling how many values should be -associated with the function. -lua_pushcclosure also pops these values from the stack. - - -

-The maximum value for n is 255. - - - - - -


lua_pushcfunction

-[-0, +1, m] -

void lua_pushcfunction (lua_State *L, lua_CFunction f);
- -

-Pushes a C function onto the stack. -This function receives a pointer to a C function -and pushes onto the stack a Lua value of type function that, -when called, invokes the corresponding C function. - - -

-Any function to be registered in Lua must -follow the correct protocol to receive its parameters -and return its results (see lua_CFunction). - - -

-lua_pushcfunction is defined as a macro: - -

-     #define lua_pushcfunction(L,f)  lua_pushcclosure(L,f,0)
-
- - - - -

lua_pushfstring

-[-0, +1, m] -

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

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

    - -
  • -You do not have to allocate space for the result: -the result is a Lua string and Lua takes care of memory allocation -(and deallocation, through garbage collection). -
  • - -
  • -The conversion specifiers are quite restricted. -There are no flags, widths, or precisions. -The conversion specifiers can only be -'%%' (inserts a '%' in the string), -'%s' (inserts a zero-terminated string, with no size restrictions), -'%f' (inserts a lua_Number), -'%p' (inserts a pointer as a hexadecimal numeral), -'%d' (inserts an int), and -'%c' (inserts an int as a character). -
  • - -
- - - - -

lua_pushinteger

-[-0, +1, -] -

void lua_pushinteger (lua_State *L, lua_Integer n);
- -

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


lua_pushlightuserdata

-[-0, +1, -] -

void lua_pushlightuserdata (lua_State *L, void *p);
- -

-Pushes a light userdata onto the stack. - - -

-Userdata represent C values in Lua. -A light userdata represents a pointer. -It is a value (like a number): -you do not create it, it has no individual metatable, -and it is not collected (as it was never created). -A light userdata is equal to "any" -light userdata with the same C address. - - - - - -


lua_pushliteral

-[-0, +1, m] -

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

-This macro is equivalent to lua_pushlstring, -but can be used only when s is a literal string. -In these cases, it automatically provides the string length. - - - - - -


lua_pushlstring

-[-0, +1, m] -

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

-Pushes the string pointed to by s with size len -onto the stack. -Lua makes (or reuses) an internal copy of the given string, -so the memory at s can be freed or reused immediately after -the function returns. -The string can contain embedded zeros. - - - - - -


lua_pushnil

-[-0, +1, -] -

void lua_pushnil (lua_State *L);
- -

-Pushes a nil value onto the stack. - - - - - -


lua_pushnumber

-[-0, +1, -] -

void lua_pushnumber (lua_State *L, lua_Number n);
- -

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


lua_pushstring

-[-0, +1, m] -

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

-Pushes the zero-terminated string pointed to by s -onto the stack. -Lua makes (or reuses) an internal copy of the given string, -so the memory at s can be freed or reused immediately after -the function returns. -The string cannot contain embedded zeros; -it is assumed to end at the first zero. - - - - - -


lua_pushthread

-[-0, +1, -] -

int lua_pushthread (lua_State *L);
- -

-Pushes the thread represented by L onto the stack. -Returns 1 if this thread is the main thread of its state. - - - - - -


lua_pushvalue

-[-0, +1, -] -

void lua_pushvalue (lua_State *L, int index);
- -

-Pushes a copy of the element at the given valid index -onto the stack. - - - - - -


lua_pushvfstring

-[-0, +1, m] -

const char *lua_pushvfstring (lua_State *L,
-                              const char *fmt,
-                              va_list argp);
- -

-Equivalent to lua_pushfstring, except that it receives a va_list -instead of a variable number of arguments. - - - - - -


lua_rawequal

-[-0, +0, -] -

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

-Returns 1 if the two values in acceptable indices index1 and -index2 are primitively equal -(that is, without calling metamethods). -Otherwise returns 0. -Also returns 0 if any of the indices are non valid. - - - - - -


lua_rawget

-[-1, +1, -] -

void lua_rawget (lua_State *L, int index);
- -

-Similar to lua_gettable, but does a raw access -(i.e., without metamethods). - - - - - -


lua_rawgeti

-[-0, +1, -] -

void lua_rawgeti (lua_State *L, int index, int n);
- -

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


lua_rawset

-[-2, +0, m] -

void lua_rawset (lua_State *L, int index);
- -

-Similar to lua_settable, but does a raw assignment -(i.e., without metamethods). - - - - - -


lua_rawseti

-[-1, +0, m] -

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

-Does the equivalent of t[n] = v, -where t is the value at the given valid index -and v is the value at the top of the stack. - - -

-This function pops the value from the stack. -The assignment is raw; -that is, it does not invoke metamethods. - - - - - -


lua_Reader

-
typedef const char * (*lua_Reader) (lua_State *L,
-                                    void *data,
-                                    size_t *size);
- -

-The reader function used by lua_load. -Every time it needs another piece of the chunk, -lua_load calls the reader, -passing along its data parameter. -The reader must return a pointer to a block of memory -with a new piece of the chunk -and set size to the block size. -The block must exist until the reader function is called again. -To signal the end of the chunk, -the reader must return NULL or set size to zero. -The reader function may return pieces of any size greater than zero. - - - - - -


lua_register

-[-0, +0, e] -

void lua_register (lua_State *L,
-                   const char *name,
-                   lua_CFunction f);
- -

-Sets the C function f as the new value of global name. -It is defined as a macro: - -

-     #define lua_register(L,n,f) \
-            (lua_pushcfunction(L, f), lua_setglobal(L, n))
-
- - - - -

lua_remove

-[-1, +0, -] -

void lua_remove (lua_State *L, int index);
- -

-Removes the element at the given valid index, -shifting down the elements above this index to fill the gap. -Cannot be called with a pseudo-index, -because a pseudo-index is not an actual stack position. - - - - - -


lua_replace

-[-1, +0, -] -

void lua_replace (lua_State *L, int index);
- -

-Moves the top element into the given position (and pops it), -without shifting any element -(therefore replacing the value at the given position). - - - - - -


lua_resume

-[-?, +?, -] -

int lua_resume (lua_State *L, int narg);
- -

-Starts and resumes a coroutine in a given thread. - - -

-To start a coroutine, you first create a new thread -(see lua_newthread); -then you push onto its stack the main function plus any arguments; -then you call lua_resume, -with narg being the number of arguments. -This call returns when the coroutine suspends or finishes its execution. -When it returns, the stack contains all values passed to lua_yield, -or all values returned by the body function. -lua_resume returns -LUA_YIELD if the coroutine yields, -0 if the coroutine finishes its execution -without errors, -or an error code in case of errors (see lua_pcall). -In case of errors, -the stack is not unwound, -so you can use the debug API over it. -The error message is on the top of the stack. -To restart a coroutine, you put on its stack only the values to -be passed as results from yield, -and then call lua_resume. - - - - - -


lua_setallocf

-[-0, +0, -] -

void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
- -

-Changes the allocator function of a given state to f -with user data ud. - - - - - -


lua_setfenv

-[-1, +0, -] -

int lua_setfenv (lua_State *L, int index);
- -

-Pops a table from the stack and sets it as -the new environment for the value at the given index. -If the value at the given index is -neither a function nor a thread nor a userdata, -lua_setfenv returns 0. -Otherwise it returns 1. - - - - - -


lua_setfield

-[-1, +0, e] -

void lua_setfield (lua_State *L, int index, const char *k);
- -

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

-This function pops the value from the stack. -As in Lua, this function may trigger a metamethod -for the "newindex" event (see §2.8). - - - - - -


lua_setglobal

-[-1, +0, e] -

void lua_setglobal (lua_State *L, const char *name);
- -

-Pops a value from the stack and -sets it as the new value of global name. -It is defined as a macro: - -

-     #define lua_setglobal(L,s)   lua_setfield(L, LUA_GLOBALSINDEX, s)
-
- - - - -

lua_setmetatable

-[-1, +0, -] -

int lua_setmetatable (lua_State *L, int index);
- -

-Pops a table from the stack and -sets it as the new metatable for the value at the given -acceptable index. - - - - - -


lua_settable

-[-2, +0, e] -

void lua_settable (lua_State *L, int index);
- -

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

-This function pops both the key and the value from the stack. -As in Lua, this function may trigger a metamethod -for the "newindex" event (see §2.8). - - - - - -


lua_settop

-[-?, +?, -] -

void lua_settop (lua_State *L, int index);
- -

-Accepts any acceptable index, or 0, -and sets the stack top to this index. -If the new top is larger than the old one, -then the new elements are filled with nil. -If index is 0, then all stack elements are removed. - - - - - -


lua_State

-
typedef struct lua_State lua_State;
- -

-Opaque structure that keeps the whole state of a Lua interpreter. -The Lua library is fully reentrant: -it has no global variables. -All information about a state is kept in this structure. - - -

-A pointer to this state must be passed as the first argument to -every function in the library, except to lua_newstate, -which creates a Lua state from scratch. - - - - - -


lua_status

-[-0, +0, -] -

int lua_status (lua_State *L);
- -

-Returns the status of the thread L. - - -

-The status can be 0 for a normal thread, -an error code if the thread finished its execution with an error, -or LUA_YIELD if the thread is suspended. - - - - - -


lua_toboolean

-[-0, +0, -] -

int lua_toboolean (lua_State *L, int index);
- -

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


lua_tocfunction

-[-0, +0, -] -

lua_CFunction lua_tocfunction (lua_State *L, int index);
- -

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


lua_tointeger

-[-0, +0, -] -

lua_Integer lua_tointeger (lua_State *L, int index);
- -

-Converts the Lua value at the given acceptable index -to the signed integral type lua_Integer. -The Lua value must be a number or a string convertible to a number -(see §2.2.1); -otherwise, lua_tointeger returns 0. - - -

-If the number is not an integer, -it is truncated in some non-specified way. - - - - - -


lua_tolstring

-[-0, +0, m] -

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

-Converts the Lua value at the given acceptable index to a C string. -If len is not NULL, -it also sets *len with the string length. -The Lua value must be a string or a number; -otherwise, the function returns NULL. -If the value is a number, -then lua_tolstring also -changes the actual value in the stack to a string. -(This change confuses lua_next -when lua_tolstring is applied to keys during a table traversal.) - - -

-lua_tolstring returns a fully aligned pointer -to a string inside the Lua state. -This string always has a zero ('\0') -after its last character (as in C), -but can contain other zeros in its body. -Because Lua has garbage collection, -there is no guarantee that the pointer returned by lua_tolstring -will be valid after the corresponding value is removed from the stack. - - - - - -


lua_tonumber

-[-0, +0, -] -

lua_Number lua_tonumber (lua_State *L, int index);
- -

-Converts the Lua value at the given acceptable index -to the C type lua_Number (see lua_Number). -The Lua value must be a number or a string convertible to a number -(see §2.2.1); -otherwise, lua_tonumber returns 0. - - - - - -


lua_topointer

-[-0, +0, -] -

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

-Converts the value at the given acceptable index to a generic -C pointer (void*). -The value can be a userdata, a table, a thread, or a function; -otherwise, lua_topointer returns NULL. -Different objects will give different pointers. -There is no way to convert the pointer back to its original value. - - -

-Typically this function is used only for debug information. - - - - - -


lua_tostring

-[-0, +0, m] -

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

-Equivalent to lua_tolstring with len equal to NULL. - - - - - -


lua_tothread

-[-0, +0, -] -

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

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


lua_touserdata

-[-0, +0, -] -

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

-If the value at the given acceptable index is a full userdata, -returns its block address. -If the value is a light userdata, -returns its pointer. -Otherwise, returns NULL. - - - - - -


lua_type

-[-0, +0, -] -

int lua_type (lua_State *L, int index);
- -

-Returns the type of the value in the given acceptable index, -or LUA_TNONE for a non-valid index -(that is, an index to an "empty" stack position). -The types returned by lua_type are coded by the following constants -defined in lua.h: -LUA_TNIL, -LUA_TNUMBER, -LUA_TBOOLEAN, -LUA_TSTRING, -LUA_TTABLE, -LUA_TFUNCTION, -LUA_TUSERDATA, -LUA_TTHREAD, -and -LUA_TLIGHTUSERDATA. - - - - - -


lua_typename

-[-0, +0, -] -

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

-Returns the name of the type encoded by the value tp, -which must be one the values returned by lua_type. - - - - - -


lua_Writer

-
typedef int (*lua_Writer) (lua_State *L,
-                           const void* p,
-                           size_t sz,
-                           void* ud);
- -

-The type of the writer function used by lua_dump. -Every time it produces another piece of chunk, -lua_dump calls the writer, -passing along the buffer to be written (p), -its size (sz), -and the data parameter supplied to lua_dump. - - -

-The writer returns an error code: -0 means no errors; -any other value means an error and stops lua_dump from -calling the writer again. - - - - - -


lua_xmove

-[-?, +?, -] -

void lua_xmove (lua_State *from, lua_State *to, int n);
- -

-Exchange values between different threads of the same global state. - - -

-This function pops n values from the stack from, -and pushes them onto the stack to. - - - - - -


lua_yield

-[-?, +?, -] -

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

-Yields a coroutine. - - -

-This function should only be called as the -return expression of a C function, as follows: - -

-     return lua_yield (L, nresults);
-

-When a C function calls lua_yield in that way, -the running coroutine suspends its execution, -and the call to lua_resume that started this coroutine returns. -The parameter nresults is the number of values from the stack -that are passed as results to lua_resume. - - - - - - - -

3.8 - The Debug Interface

- -

-Lua has no built-in debugging facilities. -Instead, it offers a special interface -by means of functions and hooks. -This interface allows the construction of different -kinds of debuggers, profilers, and other tools -that need "inside information" from the interpreter. - - - -


lua_Debug

-
typedef struct lua_Debug {
-  int event;
-  const char *name;           /* (n) */
-  const char *namewhat;       /* (n) */
-  const char *what;           /* (S) */
-  const char *source;         /* (S) */
-  int currentline;            /* (l) */
-  int nups;                   /* (u) number of upvalues */
-  int linedefined;            /* (S) */
-  int lastlinedefined;        /* (S) */
-  char short_src[LUA_IDSIZE]; /* (S) */
-  /* private part */
-  other fields
-} lua_Debug;
- -

-A structure used to carry different pieces of -information about an active function. -lua_getstack fills only the private part -of this structure, for later use. -To fill the other fields of lua_Debug with useful information, -call lua_getinfo. - - -

-The fields of lua_Debug have the following meaning: - -

    - -
  • source: -If the function was defined in a string, -then source is that string. -If the function was defined in a file, -then source starts with a '@' followed by the file name. -
  • - -
  • short_src: -a "printable" version of source, to be used in error messages. -
  • - -
  • linedefined: -the line number where the definition of the function starts. -
  • - -
  • lastlinedefined: -the line number where the definition of the function ends. -
  • - -
  • what: -the string "Lua" if the function is a Lua function, -"C" if it is a C function, -"main" if it is the main part of a chunk, -and "tail" if it was a function that did a tail call. -In the latter case, -Lua has no other information about the function. -
  • - -
  • currentline: -the current line where the given function is executing. -When no line information is available, -currentline is set to -1. -
  • - -
  • name: -a reasonable name for the given function. -Because functions in Lua are first-class values, -they do not have a fixed name: -some functions can be the value of multiple global variables, -while others can be stored only in a table field. -The lua_getinfo function checks how the function was -called to find a suitable name. -If it cannot find a name, -then name is set to NULL. -
  • - -
  • namewhat: -explains the name field. -The value of namewhat can be -"global", "local", "method", -"field", "upvalue", or "" (the empty string), -according to how the function was called. -(Lua uses the empty string when no other option seems to apply.) -
  • - -
  • nups: -the number of upvalues of the function. -
  • - -
- - - - -

lua_gethook

-[-0, +0, -] -

lua_Hook lua_gethook (lua_State *L);
- -

-Returns the current hook function. - - - - - -


lua_gethookcount

-[-0, +0, -] -

int lua_gethookcount (lua_State *L);
- -

-Returns the current hook count. - - - - - -


lua_gethookmask

-[-0, +0, -] -

int lua_gethookmask (lua_State *L);
- -

-Returns the current hook mask. - - - - - -


lua_getinfo

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

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

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

-To get information about a function invocation, -the parameter ar must be a valid activation record that was -filled by a previous call to lua_getstack or -given as argument to a hook (see lua_Hook). - - -

-To get information about a function you push it onto the stack -and start the what string with the character '>'. -(In that case, -lua_getinfo pops the function in the top of the stack.) -For instance, to know in which line a function f was defined, -you can write the following code: - -

-     lua_Debug ar;
-     lua_getfield(L, LUA_GLOBALSINDEX, "f");  /* get global 'f' */
-     lua_getinfo(L, ">S", &ar);
-     printf("%d\n", ar.linedefined);
-
- -

-Each character in the string what -selects some fields of the structure ar to be filled or -a value to be pushed on the stack: - -

    - -
  • 'n': fills in the field name and namewhat; -
  • - -
  • 'S': -fills in the fields source, short_src, -linedefined, lastlinedefined, and what; -
  • - -
  • 'l': fills in the field currentline; -
  • - -
  • 'u': fills in the field nups; -
  • - -
  • 'f': -pushes onto the stack the function that is -running at the given level; -
  • - -
  • 'L': -pushes onto the stack a table whose indices are the -numbers of the lines that are valid on the function. -(A valid line is a line with some associated code, -that is, a line where you can put a break point. -Non-valid lines include empty lines and comments.) -
  • - -
- -

-This function returns 0 on error -(for instance, an invalid option in what). - - - - - -


lua_getlocal

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

const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);
- -

-Gets information about a local variable of a given activation record. -The parameter ar must be a valid activation record that was -filled by a previous call to lua_getstack or -given as argument to a hook (see lua_Hook). -The index n selects which local variable to inspect -(1 is the first parameter or active local variable, and so on, -until the last active local variable). -lua_getlocal pushes the variable's value onto the stack -and returns its name. - - -

-Variable names starting with '(' (open parentheses) -represent internal variables -(loop control variables, temporaries, and C function locals). - - -

-Returns NULL (and pushes nothing) -when the index is greater than -the number of active local variables. - - - - - -


lua_getstack

-[-0, +0, -] -

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

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

-This function fills parts of a lua_Debug structure with -an identification of the activation record -of the function executing at a given level. -Level 0 is the current running function, -whereas level n+1 is the function that has called level n. -When there are no errors, lua_getstack returns 1; -when called with a level greater than the stack depth, -it returns 0. - - - - - -


lua_getupvalue

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

const char *lua_getupvalue (lua_State *L, int funcindex, int n);
- -

-Gets information about a closure's upvalue. -(For Lua functions, -upvalues are the external local variables that the function uses, -and that are consequently included in its closure.) -lua_getupvalue gets the index n of an upvalue, -pushes the upvalue's value onto the stack, -and returns its name. -funcindex points to the closure in the stack. -(Upvalues have no particular order, -as they are active through the whole function. -So, they are numbered in an arbitrary order.) - - -

-Returns NULL (and pushes nothing) -when the index is greater than the number of upvalues. -For C functions, this function uses the empty string "" -as a name for all upvalues. - - - - - -


lua_Hook

-
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
- -

-Type for debugging hook functions. - - -

-Whenever a hook is called, its ar argument has its field -event set to the specific event that triggered the hook. -Lua identifies these events with the following constants: -LUA_HOOKCALL, LUA_HOOKRET, -LUA_HOOKTAILRET, LUA_HOOKLINE, -and LUA_HOOKCOUNT. -Moreover, for line events, the field currentline is also set. -To get the value of any other field in ar, -the hook must call lua_getinfo. -For return events, event can be LUA_HOOKRET, -the normal value, or LUA_HOOKTAILRET. -In the latter case, Lua is simulating a return from -a function that did a tail call; -in this case, it is useless to call lua_getinfo. - - -

-While Lua is running a hook, it disables other calls to hooks. -Therefore, if a hook calls back Lua to execute a function or a chunk, -this execution occurs without any calls to hooks. - - - - - -


lua_sethook

-[-0, +0, -] -

int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);
- -

-Sets the debugging hook function. - - -

-Argument f is the hook function. -mask specifies on which events the hook will be called: -it is formed by a bitwise or of the constants -LUA_MASKCALL, -LUA_MASKRET, -LUA_MASKLINE, -and LUA_MASKCOUNT. -The count argument is only meaningful when the mask -includes LUA_MASKCOUNT. -For each event, the hook is called as explained below: - -

    - -
  • The call hook: is called when the interpreter calls a function. -The hook is called just after Lua enters the new function, -before the function gets its arguments. -
  • - -
  • The return hook: is called when the interpreter returns from a function. -The hook is called just before Lua leaves the function. -You have no access to the values to be returned by the function. -
  • - -
  • The line hook: is called when the interpreter is about to -start the execution of a new line of code, -or when it jumps back in the code (even to the same line). -(This event only happens while Lua is executing a Lua function.) -
  • - -
  • The count hook: is called after the interpreter executes every -count instructions. -(This event only happens while Lua is executing a Lua function.) -
  • - -
- -

-A hook is disabled by setting mask to zero. - - - - - -


lua_setlocal

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

const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);
- -

-Sets the value of a local variable of a given activation record. -Parameters ar and n are as in lua_getlocal -(see lua_getlocal). -lua_setlocal assigns the value at the top of the stack -to the variable and returns its name. -It also pops the value from the stack. - - -

-Returns NULL (and pops nothing) -when the index is greater than -the number of active local variables. - - - - - -


lua_setupvalue

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

const char *lua_setupvalue (lua_State *L, int funcindex, int n);
- -

-Sets the value of a closure's upvalue. -It assigns the value at the top of the stack -to the upvalue and returns its name. -It also pops the value from the stack. -Parameters funcindex and n are as in the lua_getupvalue -(see lua_getupvalue). - - -

-Returns NULL (and pops nothing) -when the index is greater than the number of upvalues. - - - - - - - -

4 - The Auxiliary Library

- -

- -The auxiliary library provides several convenient functions -to interface C with Lua. -While the basic API provides the primitive functions for all -interactions between C and Lua, -the auxiliary library provides higher-level functions for some -common tasks. - - -

-All functions from the auxiliary library -are defined in header file lauxlib.h and -have a prefix luaL_. - - -

-All functions in the auxiliary library are built on -top of the basic API, -and so they provide nothing that cannot be done with this API. - - -

-Several functions in the auxiliary library are used to -check C function arguments. -Their names are always luaL_check* or luaL_opt*. -All of these functions throw an error if the check is not satisfied. -Because the error message is formatted for arguments -(e.g., "bad argument #1"), -you should not use these functions for other stack values. - - - -

4.1 - Functions and Types

- -

-Here we list all functions and types from the auxiliary library -in alphabetical order. - - - -


luaL_addchar

-[-0, +0, m] -

void luaL_addchar (luaL_Buffer *B, char c);
- -

-Adds the character c to the buffer B -(see luaL_Buffer). - - - - - -


luaL_addlstring

-[-0, +0, m] -

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

-Adds the string pointed to by s with length l to -the buffer B -(see luaL_Buffer). -The string may contain embedded zeros. - - - - - -


luaL_addsize

-[-0, +0, m] -

void luaL_addsize (luaL_Buffer *B, size_t n);
- -

-Adds to the buffer B (see luaL_Buffer) -a string of length n previously copied to the -buffer area (see luaL_prepbuffer). - - - - - -


luaL_addstring

-[-0, +0, m] -

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

-Adds the zero-terminated string pointed to by s -to the buffer B -(see luaL_Buffer). -The string may not contain embedded zeros. - - - - - -


luaL_addvalue

-[-1, +0, m] -

void luaL_addvalue (luaL_Buffer *B);
- -

-Adds the value at the top of the stack -to the buffer B -(see luaL_Buffer). -Pops the value. - - -

-This is the only function on string buffers that can (and must) -be called with an extra element on the stack, -which is the value to be added to the buffer. - - - - - -


luaL_argcheck

-[-0, +0, v] -

void luaL_argcheck (lua_State *L,
-                    int cond,
-                    int narg,
-                    const char *extramsg);
- -

-Checks whether cond is true. -If not, raises an error with the following message, -where func is retrieved from the call stack: - -

-     bad argument #<narg> to <func> (<extramsg>)
-
- - - - -

luaL_argerror

-[-0, +0, v] -

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

-Raises an error with the following message, -where func is retrieved from the call stack: - -

-     bad argument #<narg> to <func> (<extramsg>)
-
- -

-This function never returns, -but it is an idiom to use it in C functions -as return luaL_argerror(args). - - - - - -


luaL_Buffer

-
typedef struct luaL_Buffer luaL_Buffer;
- -

-Type for a string buffer. - - -

-A string buffer allows C code to build Lua strings piecemeal. -Its pattern of use is as follows: - -

    - -
  • First you declare a variable b of type luaL_Buffer.
  • - -
  • Then you initialize it with a call luaL_buffinit(L, &b).
  • - -
  • -Then you add string pieces to the buffer calling any of -the luaL_add* functions. -
  • - -
  • -You finish by calling luaL_pushresult(&b). -This call leaves the final string on the top of the stack. -
  • - -
- -

-During its normal operation, -a string buffer uses a variable number of stack slots. -So, while using a buffer, you cannot assume that you know where -the top of the stack is. -You can use the stack between successive calls to buffer operations -as long as that use is balanced; -that is, -when you call a buffer operation, -the stack is at the same level -it was immediately after the previous buffer operation. -(The only exception to this rule is luaL_addvalue.) -After calling luaL_pushresult the stack is back to its -level when the buffer was initialized, -plus the final string on its top. - - - - - -


luaL_buffinit

-[-0, +0, -] -

void luaL_buffinit (lua_State *L, luaL_Buffer *B);
- -

-Initializes a buffer B. -This function does not allocate any space; -the buffer must be declared as a variable -(see luaL_Buffer). - - - - - -


luaL_callmeta

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

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

-Calls a metamethod. - - -

-If the object at index obj has a metatable and this -metatable has a field e, -this function calls this field and passes the object as its only argument. -In this case this function returns 1 and pushes onto the -stack the value returned by the call. -If there is no metatable or no metamethod, -this function returns 0 (without pushing any value on the stack). - - - - - -


luaL_checkany

-[-0, +0, v] -

void luaL_checkany (lua_State *L, int narg);
- -

-Checks whether the function has an argument -of any type (including nil) at position narg. - - - - - -


luaL_checkint

-[-0, +0, v] -

int luaL_checkint (lua_State *L, int narg);
- -

-Checks whether the function argument narg is a number -and returns this number cast to an int. - - - - - -


luaL_checkinteger

-[-0, +0, v] -

lua_Integer luaL_checkinteger (lua_State *L, int narg);
- -

-Checks whether the function argument narg is a number -and returns this number cast to a lua_Integer. - - - - - -


luaL_checklong

-[-0, +0, v] -

long luaL_checklong (lua_State *L, int narg);
- -

-Checks whether the function argument narg is a number -and returns this number cast to a long. - - - - - -


luaL_checklstring

-[-0, +0, v] -

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

-Checks whether the function argument narg is a string -and returns this string; -if l is not NULL fills *l -with the string's length. - - -

-This function uses lua_tolstring to get its result, -so all conversions and caveats of that function apply here. - - - - - -


luaL_checknumber

-[-0, +0, v] -

lua_Number luaL_checknumber (lua_State *L, int narg);
- -

-Checks whether the function argument narg is a number -and returns this number. - - - - - -


luaL_checkoption

-[-0, +0, v] -

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

-Checks whether the function argument narg is a string and -searches for this string in the array lst -(which must be NULL-terminated). -Returns the index in the array where the string was found. -Raises an error if the argument is not a string or -if the string cannot be found. - - -

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

-This is a useful function for mapping strings to C enums. -(The usual convention in Lua libraries is -to use strings instead of numbers to select options.) - - - - - -


luaL_checkstack

-[-0, +0, v] -

void luaL_checkstack (lua_State *L, int sz, const char *msg);
- -

-Grows the stack size to top + sz elements, -raising an error if the stack cannot grow to that size. -msg is an additional text to go into the error message. - - - - - -


luaL_checkstring

-[-0, +0, v] -

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

-Checks whether the function argument narg is a string -and returns this string. - - -

-This function uses lua_tolstring to get its result, -so all conversions and caveats of that function apply here. - - - - - -


luaL_checktype

-[-0, +0, v] -

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

-Checks whether the function argument narg has type t. -See lua_type for the encoding of types for t. - - - - - -


luaL_checkudata

-[-0, +0, v] -

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

-Checks whether the function argument narg is a userdata -of the type tname (see luaL_newmetatable). - - - - - -


luaL_dofile

-[-0, +?, m] -

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

-Loads and runs the given file. -It is defined as the following macro: - -

-     (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0))
-

-It returns 0 if there are no errors -or 1 in case of errors. - - - - - -


luaL_dostring

-[-0, +?, m] -

int luaL_dostring (lua_State *L, const char *str);
- -

-Loads and runs the given string. -It is defined as the following macro: - -

-     (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0))
-

-It returns 0 if there are no errors -or 1 in case of errors. - - - - - -


luaL_error

-[-0, +0, v] -

int luaL_error (lua_State *L, const char *fmt, ...);
- -

-Raises an error. -The error message format is given by fmt -plus any extra arguments, -following the same rules of lua_pushfstring. -It also adds at the beginning of the message the file name and -the line number where the error occurred, -if this information is available. - - -

-This function never returns, -but it is an idiom to use it in C functions -as return luaL_error(args). - - - - - -


luaL_getmetafield

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

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

-Pushes onto the stack the field e from the metatable -of the object at index obj. -If the object does not have a metatable, -or if the metatable does not have this field, -returns 0 and pushes nothing. - - - - - -


luaL_getmetatable

-[-0, +1, -] -

void luaL_getmetatable (lua_State *L, const char *tname);
- -

-Pushes onto the stack the metatable associated with name tname -in the registry (see luaL_newmetatable). - - - - - -


luaL_gsub

-[-0, +1, m] -

const char *luaL_gsub (lua_State *L,
-                       const char *s,
-                       const char *p,
-                       const char *r);
- -

-Creates a copy of string s by replacing -any occurrence of the string p -with the string r. -Pushes the resulting string on the stack and returns it. - - - - - -


luaL_loadbuffer

-[-0, +1, m] -

int luaL_loadbuffer (lua_State *L,
-                     const char *buff,
-                     size_t sz,
-                     const char *name);
- -

-Loads a buffer as a Lua chunk. -This function uses lua_load to load the chunk in the -buffer pointed to by buff with size sz. - - -

-This function returns the same results as lua_load. -name is the chunk name, -used for debug information and error messages. - - - - - -


luaL_loadfile

-[-0, +1, m] -

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

-Loads a file as a Lua chunk. -This function uses lua_load to load the chunk in the file -named filename. -If filename is NULL, -then it loads from the standard input. -The first line in the file is ignored if it starts with a #. - - -

-This function returns the same results as lua_load, -but it has an extra error code LUA_ERRFILE -if it cannot open/read the file. - - -

-As lua_load, this function only loads the chunk; -it does not run it. - - - - - -


luaL_loadstring

-[-0, +1, m] -

int luaL_loadstring (lua_State *L, const char *s);
- -

-Loads a string as a Lua chunk. -This function uses lua_load to load the chunk in -the zero-terminated string s. - - -

-This function returns the same results as lua_load. - - -

-Also as lua_load, this function only loads the chunk; -it does not run it. - - - - - -


luaL_newmetatable

-[-0, +1, m] -

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

-If the registry already has the key tname, -returns 0. -Otherwise, -creates a new table to be used as a metatable for userdata, -adds it to the registry with key tname, -and returns 1. - - -

-In both cases pushes onto the stack the final value associated -with tname in the registry. - - - - - -


luaL_newstate

-[-0, +0, -] -

lua_State *luaL_newstate (void);
- -

-Creates a new Lua state. -It calls lua_newstate with an -allocator based on the standard C realloc function -and then sets a panic function (see lua_atpanic) that prints -an error message to the standard error output in case of fatal -errors. - - -

-Returns the new state, -or NULL if there is a memory allocation error. - - - - - -


luaL_openlibs

-[-0, +0, m] -

void luaL_openlibs (lua_State *L);
- -

-Opens all standard Lua libraries into the given state. - - - - - -


luaL_optint

-[-0, +0, v] -

int luaL_optint (lua_State *L, int narg, int d);
- -

-If the function argument narg is a number, -returns this number cast to an int. -If this argument is absent or is nil, -returns d. -Otherwise, raises an error. - - - - - -


luaL_optinteger

-[-0, +0, v] -

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

-If the function argument narg is a number, -returns this number cast to a lua_Integer. -If this argument is absent or is nil, -returns d. -Otherwise, raises an error. - - - - - -


luaL_optlong

-[-0, +0, v] -

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

-If the function argument narg is a number, -returns this number cast to a long. -If this argument is absent or is nil, -returns d. -Otherwise, raises an error. - - - - - -


luaL_optlstring

-[-0, +0, v] -

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

-If the function argument narg is a string, -returns this string. -If this argument is absent or is nil, -returns d. -Otherwise, raises an error. - - -

-If l is not NULL, -fills the position *l with the results's length. - - - - - -


luaL_optnumber

-[-0, +0, v] -

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

-If the function argument narg is a number, -returns this number. -If this argument is absent or is nil, -returns d. -Otherwise, raises an error. - - - - - -


luaL_optstring

-[-0, +0, v] -

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

-If the function argument narg is a string, -returns this string. -If this argument is absent or is nil, -returns d. -Otherwise, raises an error. - - - - - -


luaL_prepbuffer

-[-0, +0, -] -

char *luaL_prepbuffer (luaL_Buffer *B);
- -

-Returns an address to a space of size LUAL_BUFFERSIZE -where you can copy a string to be added to buffer B -(see luaL_Buffer). -After copying the string into this space you must call -luaL_addsize with the size of the string to actually add -it to the buffer. - - - - - -


luaL_pushresult

-[-?, +1, m] -

void luaL_pushresult (luaL_Buffer *B);
- -

-Finishes the use of buffer B leaving the final string on -the top of the stack. - - - - - -


luaL_ref

-[-1, +0, m] -

int luaL_ref (lua_State *L, int t);
- -

-Creates and returns a reference, -in the table at index t, -for the object at the top of the stack (and pops the object). - - -

-A reference is a unique integer key. -As long as you do not manually add integer keys into table t, -luaL_ref ensures the uniqueness of the key it returns. -You can retrieve an object referred by reference r -by calling lua_rawgeti(L, t, r). -Function luaL_unref frees a reference and its associated object. - - -

-If the object at the top of the stack is nil, -luaL_ref returns the constant LUA_REFNIL. -The constant LUA_NOREF is guaranteed to be different -from any reference returned by luaL_ref. - - - - - -


luaL_Reg

-
typedef struct luaL_Reg {
-  const char *name;
-  lua_CFunction func;
-} luaL_Reg;
- -

-Type for arrays of functions to be registered by -luaL_register. -name is the function name and func is a pointer to -the function. -Any array of luaL_Reg must end with an sentinel entry -in which both name and func are NULL. - - - - - -


luaL_register

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

void luaL_register (lua_State *L,
-                    const char *libname,
-                    const luaL_Reg *l);
- -

-Opens a library. - - -

-When called with libname equal to NULL, -it simply registers all functions in the list l -(see luaL_Reg) into the table on the top of the stack. - - -

-When called with a non-null libname, -luaL_register creates a new table t, -sets it as the value of the global variable libname, -sets it as the value of package.loaded[libname], -and registers on it all functions in the list l. -If there is a table in package.loaded[libname] or in -variable libname, -reuses this table instead of creating a new one. - - -

-In any case the function leaves the table -on the top of the stack. - - - - - -


luaL_typename

-[-0, +0, -] -

const char *luaL_typename (lua_State *L, int index);
- -

-Returns the name of the type of the value at the given index. - - - - - -


luaL_typerror

-[-0, +0, v] -

int luaL_typerror (lua_State *L, int narg, const char *tname);
- -

-Generates an error with a message like the following: - -

-     location: bad argument narg to 'func' (tname expected, got rt)
-

-where location is produced by luaL_where, -func is the name of the current function, -and rt is the type name of the actual argument. - - - - - -


luaL_unref

-[-0, +0, -] -

void luaL_unref (lua_State *L, int t, int ref);
- -

-Releases reference ref from the table at index t -(see luaL_ref). -The entry is removed from the table, -so that the referred object can be collected. -The reference ref is also freed to be used again. - - -

-If ref is LUA_NOREF or LUA_REFNIL, -luaL_unref does nothing. - - - - - -


luaL_where

-[-0, +1, m] -

void luaL_where (lua_State *L, int lvl);
- -

-Pushes onto the stack a string identifying the current position -of the control at level lvl in the call stack. -Typically this string has the following format: - -

-     chunkname:currentline:
-

-Level 0 is the running function, -level 1 is the function that called the running function, -etc. - - -

-This function is used to build a prefix for error messages. - - - - - - - -

5 - Standard Libraries

- -

-The standard Lua libraries provide useful functions -that are implemented directly through the C API. -Some of these functions provide essential services to the language -(e.g., type and getmetatable); -others provide access to "outside" services (e.g., I/O); -and others could be implemented in Lua itself, -but are quite useful or have critical performance requirements that -deserve an implementation in C (e.g., table.sort). - - -

-All libraries are implemented through the official C API -and are provided as separate C modules. -Currently, Lua has the following standard libraries: - -

    - -
  • basic library,
  • which includes the coroutine sub-library; - -
  • package library;
  • - -
  • string manipulation;
  • - -
  • table manipulation;
  • - -
  • mathematical functions (sin, log, etc.);
  • - -
  • input and output;
  • - -
  • operating system facilities;
  • - -
  • debug facilities.
  • - -

-Except for the basic and package libraries, -each library provides all its functions as fields of a global table -or as methods of its objects. - - -

-To have access to these libraries, -the C host program should call the luaL_openlibs function, -which opens all standard libraries. -Alternatively, -it can open them individually by calling -luaopen_base (for the basic library), -luaopen_package (for the package library), -luaopen_string (for the string library), -luaopen_table (for the table library), -luaopen_math (for the mathematical library), -luaopen_io (for the I/O library), -luaopen_os (for the Operating System library), -and luaopen_debug (for the debug library). -These functions are declared in lualib.h -and should not be called directly: -you must call them like any other Lua C function, -e.g., by using lua_call. - - - -

5.1 - Basic Functions

- -

-The basic library provides some core functions to Lua. -If you do not include this library in your application, -you should check carefully whether you need to provide -implementations for some of its facilities. - - -

-


assert (v [, message])

-Issues an error when -the value of its argument v is false (i.e., nil or false); -otherwise, returns all its arguments. -message is an error message; -when absent, it defaults to "assertion failed!" - - - - -

-


collectgarbage (opt [, arg])

- - -

-This function is a generic interface to the garbage collector. -It performs different functions according to its first argument, opt: - -

    - -
  • "stop": -stops the garbage collector. -
  • - -
  • "restart": -restarts the garbage collector. -
  • - -
  • "collect": -performs a full garbage-collection cycle. -
  • - -
  • "count": -returns the total memory in use by Lua (in Kbytes). -
  • - -
  • "step": -performs a garbage-collection step. -The step "size" is controlled by arg -(larger values mean more steps) in a non-specified way. -If you want to control the step size -you must experimentally tune the value of arg. -Returns true if the step finished a collection cycle. -
  • - -
  • "setpause": -sets arg as the new value for the pause of -the collector (see §2.10). -Returns the previous value for pause. -
  • - -
  • "setstepmul": -sets arg as the new value for the step multiplier of -the collector (see §2.10). -Returns the previous value for step. -
  • - -
- - - -

-


dofile (filename)

-Opens the named file and executes its contents as a Lua chunk. -When called without arguments, -dofile executes the contents of the standard input (stdin). -Returns all values returned by the chunk. -In case of errors, dofile propagates the error -to its caller (that is, dofile does not run in protected mode). - - - - -

-


error (message [, level])

-Terminates the last protected function called -and returns message as the error message. -Function error never returns. - - -

-Usually, error adds some information about the error position -at the beginning of the message. -The level argument specifies how to get the error position. -With level 1 (the default), the error position is where the -error function was called. -Level 2 points the error to where the function -that called error was called; and so on. -Passing a level 0 avoids the addition of error position information -to the message. - - - - -

-


_G

-A global variable (not a function) that -holds the global environment (that is, _G._G = _G). -Lua itself does not use this variable; -changing its value does not affect any environment, -nor vice-versa. -(Use setfenv to change environments.) - - - - -

-


getfenv ([f])

-Returns the current environment in use by the function. -f can be a Lua function or a number -that specifies the function at that stack level: -Level 1 is the function calling getfenv. -If the given function is not a Lua function, -or if f is 0, -getfenv returns the global environment. -The default for f is 1. - - - - -

-


getmetatable (object)

- - -

-If object does not have a metatable, returns nil. -Otherwise, -if the object's metatable has a "__metatable" field, -returns the associated value. -Otherwise, returns the metatable of the given object. - - - - -

-


ipairs (t)

- - -

-Returns three values: an iterator function, the table t, and 0, -so that the construction - -

-     for i,v in ipairs(t) do body end
-

-will iterate over the pairs (1,t[1]), (2,t[2]), ···, -up to the first integer key absent from the table. - - - - -

-


load (func [, chunkname])

- - -

-Loads a chunk using function func to get its pieces. -Each call to func must return a string that concatenates -with previous results. -A return of an empty string, nil, or no value signals the end of the chunk. - - -

-If there are no errors, -returns the compiled chunk as a function; -otherwise, returns nil plus the error message. -The environment of the returned function is the global environment. - - -

-chunkname is used as the chunk name for error messages -and debug information. -When absent, -it defaults to "=(load)". - - - - -

-


loadfile ([filename])

- - -

-Similar to load, -but gets the chunk from file filename -or from the standard input, -if no file name is given. - - - - -

-


loadstring (string [, chunkname])

- - -

-Similar to load, -but gets the chunk from the given string. - - -

-To load and run a given string, use the idiom - -

-     assert(loadstring(s))()
-
- -

-When absent, -chunkname defaults to the given string. - - - - -

-


next (table [, index])

- - -

-Allows a program to traverse all fields of a table. -Its first argument is a table and its second argument -is an index in this table. -next returns the next index of the table -and its associated value. -When called with nil as its second argument, -next returns an initial index -and its associated value. -When called with the last index, -or with nil in an empty table, -next returns nil. -If the second argument is absent, then it is interpreted as nil. -In particular, -you can use next(t) to check whether a table is empty. - - -

-The order in which the indices are enumerated is not specified, -even for numeric indices. -(To traverse a table in numeric order, -use a numerical for or the ipairs function.) - - -

-The behavior of next is undefined if, -during the traversal, -you assign any value to a non-existent field in the table. -You may however modify existing fields. -In particular, you may clear existing fields. - - - - -

-


pairs (t)

- - -

-Returns three values: the next function, the table t, and nil, -so that the construction - -

-     for k,v in pairs(t) do body end
-

-will iterate over all key–value pairs of table t. - - -

-See function next for the caveats of modifying -the table during its traversal. - - - - -

-


pcall (f, arg1, ···)

- - -

-Calls function f with -the given arguments in protected mode. -This means that any error inside f is not propagated; -instead, pcall catches the error -and returns a status code. -Its first result is the status code (a boolean), -which is true if the call succeeds without errors. -In such case, pcall also returns all results from the call, -after this first result. -In case of any error, pcall returns false plus the error message. - - - - -

-


print (···)

-Receives any number of arguments, -and prints their values to stdout, -using the tostring function to convert them to strings. -print is not intended for formatted output, -but only as a quick way to show a value, -typically for debugging. -For formatted output, use string.format. - - - - -

-


rawequal (v1, v2)

-Checks whether v1 is equal to v2, -without invoking any metamethod. -Returns a boolean. - - - - -

-


rawget (table, index)

-Gets the real value of table[index], -without invoking any metamethod. -table must be a table; -index may be any value. - - - - -

-


rawset (table, index, value)

-Sets the real value of table[index] to value, -without invoking any metamethod. -table must be a table, -index any value different from nil, -and value any Lua value. - - -

-This function returns table. - - - - -

-


select (index, ···)

- - -

-If index is a number, -returns all arguments after argument number index. -Otherwise, index must be the string "#", -and select returns the total number of extra arguments it received. - - - - -

-


setfenv (f, table)

- - -

-Sets the environment to be used by the given function. -f can be a Lua function or a number -that specifies the function at that stack level: -Level 1 is the function calling setfenv. -setfenv returns the given function. - - -

-As a special case, when f is 0 setfenv changes -the environment of the running thread. -In this case, setfenv returns no values. - - - - -

-


setmetatable (table, metatable)

- - -

-Sets the metatable for the given table. -(You cannot change the metatable of other types from Lua, only from C.) -If metatable is nil, -removes the metatable of the given table. -If the original metatable has a "__metatable" field, -raises an error. - - -

-This function returns table. - - - - -

-


tonumber (e [, base])

-Tries to convert its argument to a number. -If the argument is already a number or a string convertible -to a number, then tonumber returns this number; -otherwise, it returns nil. - - -

-An optional argument specifies the base to interpret the numeral. -The base may be any integer between 2 and 36, inclusive. -In bases above 10, the letter 'A' (in either upper or lower case) -represents 10, 'B' represents 11, and so forth, -with 'Z' representing 35. -In base 10 (the default), the number can have a decimal part, -as well as an optional exponent part (see §2.1). -In other bases, only unsigned integers are accepted. - - - - -

-


tostring (e)

-Receives an argument of any type and -converts it to a string in a reasonable format. -For complete control of how numbers are converted, -use string.format. - - -

-If the metatable of e has a "__tostring" field, -then tostring calls the corresponding value -with e as argument, -and uses the result of the call as its result. - - - - -

-


type (v)

-Returns the type of its only argument, coded as a string. -The possible results of this function are -"nil" (a string, not the value nil), -"number", -"string", -"boolean", -"table", -"function", -"thread", -and "userdata". - - - - -

-


unpack (list [, i [, j]])

-Returns the elements from the given table. -This function is equivalent to - -
-     return list[i], list[i+1], ···, list[j]
-

-except that the above code can be written only for a fixed number -of elements. -By default, i is 1 and j is the length of the list, -as defined by the length operator (see §2.5.5). - - - - -

-


_VERSION

-A global variable (not a function) that -holds a string containing the current interpreter version. -The current contents of this variable is "Lua 5.1". - - - - -

-


xpcall (f, err)

- - -

-This function is similar to pcall, -except that you can set a new error handler. - - -

-xpcall calls function f in protected mode, -using err as the error handler. -Any error inside f is not propagated; -instead, xpcall catches the error, -calls the err function with the original error object, -and returns a status code. -Its first result is the status code (a boolean), -which is true if the call succeeds without errors. -In this case, xpcall also returns all results from the call, -after this first result. -In case of any error, -xpcall returns false plus the result from err. - - - - - - - -

5.2 - Coroutine Manipulation

- -

-The operations related to coroutines comprise a sub-library of -the basic library and come inside the table coroutine. -See §2.11 for a general description of coroutines. - - -

-


coroutine.create (f)

- - -

-Creates a new coroutine, with body f. -f must be a Lua function. -Returns this new coroutine, -an object with type "thread". - - - - -

-


coroutine.resume (co [, val1, ···])

- - -

-Starts or continues the execution of coroutine co. -The first time you resume a coroutine, -it starts running its body. -The values val1, ··· are passed -as the arguments to the body function. -If the coroutine has yielded, -resume restarts it; -the values val1, ··· are passed -as the results from the yield. - - -

-If the coroutine runs without any errors, -resume returns true plus any values passed to yield -(if the coroutine yields) or any values returned by the body function -(if the coroutine terminates). -If there is any error, -resume returns false plus the error message. - - - - -

-


coroutine.running ()

- - -

-Returns the running coroutine, -or nil when called by the main thread. - - - - -

-


coroutine.status (co)

- - -

-Returns the status of coroutine co, as a string: -"running", -if the coroutine is running (that is, it called status); -"suspended", if the coroutine is suspended in a call to yield, -or if it has not started running yet; -"normal" if the coroutine is active but not running -(that is, it has resumed another coroutine); -and "dead" if the coroutine has finished its body function, -or if it has stopped with an error. - - - - -

-


coroutine.wrap (f)

- - -

-Creates a new coroutine, with body f. -f must be a Lua function. -Returns a function that resumes the coroutine each time it is called. -Any arguments passed to the function behave as the -extra arguments to resume. -Returns the same values returned by resume, -except the first boolean. -In case of error, propagates the error. - - - - -

-


coroutine.yield (···)

- - -

-Suspends the execution of the calling coroutine. -The coroutine cannot be running a C function, -a metamethod, or an iterator. -Any arguments to yield are passed as extra results to resume. - - - - - - - -

5.3 - Modules

- -

-The package library provides basic -facilities for loading and building modules in Lua. -It exports two of its functions directly in the global environment: -require and module. -Everything else is exported in a table package. - - -

-


module (name [, ···])

- - -

-Creates a module. -If there is a table in package.loaded[name], -this table is the module. -Otherwise, if there is a global table t with the given name, -this table is the module. -Otherwise creates a new table t and -sets it as the value of the global name and -the value of package.loaded[name]. -This function also initializes t._NAME with the given name, -t._M with the module (t itself), -and t._PACKAGE with the package name -(the full module name minus last component; see below). -Finally, module sets t as the new environment -of the current function and the new value of package.loaded[name], -so that require returns t. - - -

-If name is a compound name -(that is, one with components separated by dots), -module creates (or reuses, if they already exist) -tables for each component. -For instance, if name is a.b.c, -then module stores the module table in field c of -field b of global a. - - -

-This function can receive optional options after -the module name, -where each option is a function to be applied over the module. - - - - -

-


require (modname)

- - -

-Loads the given module. -The function starts by looking into the package.loaded table -to determine whether modname is already loaded. -If it is, then require returns the value stored -at package.loaded[modname]. -Otherwise, it tries to find a loader for the module. - - -

-To find a loader, -require is guided by the package.loaders array. -By changing this array, -we can change how require looks for a module. -The following explanation is based on the default configuration -for package.loaders. - - -

-First require queries package.preload[modname]. -If it has a value, -this value (which should be a function) is the loader. -Otherwise require searches for a Lua loader using the -path stored in package.path. -If that also fails, it searches for a C loader using the -path stored in package.cpath. -If that also fails, -it tries an all-in-one loader (see package.loaders). - - -

-Once a loader is found, -require calls the loader with a single argument, modname. -If the loader returns any value, -require assigns the returned value to package.loaded[modname]. -If the loader returns no value and -has not assigned any value to package.loaded[modname], -then require assigns true to this entry. -In any case, require returns the -final value of package.loaded[modname]. - - -

-If there is any error loading or running the module, -or if it cannot find any loader for the module, -then require signals an error. - - - - -

-


package.cpath

- - -

-The path used by require to search for a C loader. - - -

-Lua initializes the C path package.cpath in the same way -it initializes the Lua path package.path, -using the environment variable LUA_CPATH -or a default path defined in luaconf.h. - - - - -

- -


package.loaded

- - -

-A table used by require to control which -modules are already loaded. -When you require a module modname and -package.loaded[modname] is not false, -require simply returns the value stored there. - - - - -

-


package.loaders

- - -

-A table used by require to control how to load modules. - - -

-Each entry in this table is a searcher function. -When looking for a module, -require calls each of these searchers in ascending order, -with the module name (the argument given to require) as its -sole parameter. -The function can return another function (the module loader) -or a string explaining why it did not find that module -(or nil if it has nothing to say). -Lua initializes this table with four functions. - - -

-The first searcher simply looks for a loader in the -package.preload table. - - -

-The second searcher looks for a loader as a Lua library, -using the path stored at package.path. -A path is a sequence of templates separated by semicolons. -For each template, -the searcher will change each interrogation -mark in the template by filename, -which is the module name with each dot replaced by a -"directory separator" (such as "/" in Unix); -then it will try to open the resulting file name. -So, for instance, if the Lua path is the string - -

-     "./?.lua;./?.lc;/usr/local/?/init.lua"
-

-the search for a Lua file for module foo -will try to open the files -./foo.lua, ./foo.lc, and -/usr/local/foo/init.lua, in that order. - - -

-The third searcher looks for a loader as a C library, -using the path given by the variable package.cpath. -For instance, -if the C path is the string - -

-     "./?.so;./?.dll;/usr/local/?/init.so"
-

-the searcher for module foo -will try to open the files ./foo.so, ./foo.dll, -and /usr/local/foo/init.so, in that order. -Once it finds a C library, -this searcher first uses a dynamic link facility to link the -application with the library. -Then it tries to find a C function inside the library to -be used as the loader. -The name of this C function is the string "luaopen_" -concatenated with a copy of the module name where each dot -is replaced by an underscore. -Moreover, if the module name has a hyphen, -its prefix up to (and including) the first hyphen is removed. -For instance, if the module name is a.v1-b.c, -the function name will be luaopen_b_c. - - -

-The fourth searcher tries an all-in-one loader. -It searches the C path for a library for -the root name of the given module. -For instance, when requiring a.b.c, -it will search for a C library for a. -If found, it looks into it for an open function for -the submodule; -in our example, that would be luaopen_a_b_c. -With this facility, a package can pack several C submodules -into one single library, -with each submodule keeping its original open function. - - - - -

-


package.loadlib (libname, funcname)

- - -

-Dynamically links the host program with the C library libname. -Inside this library, looks for a function funcname -and returns this function as a C function. -(So, funcname must follow the protocol (see lua_CFunction)). - - -

-This is a low-level function. -It completely bypasses the package and module system. -Unlike require, -it does not perform any path searching and -does not automatically adds extensions. -libname must be the complete file name of the C library, -including if necessary a path and extension. -funcname must be the exact name exported by the C library -(which may depend on the C compiler and linker used). - - -

-This function is not supported by ANSI C. -As such, it is only available on some platforms -(Windows, Linux, Mac OS X, Solaris, BSD, -plus other Unix systems that support the dlfcn standard). - - - - -

-


package.path

- - -

-The path used by require to search for a Lua loader. - - -

-At start-up, Lua initializes this variable with -the value of the environment variable LUA_PATH or -with a default path defined in luaconf.h, -if the environment variable is not defined. -Any ";;" in the value of the environment variable -is replaced by the default path. - - - - -

-


package.preload

- - -

-A table to store loaders for specific modules -(see require). - - - - -

-


package.seeall (module)

- - -

-Sets a metatable for module with -its __index field referring to the global environment, -so that this module inherits values -from the global environment. -To be used as an option to function module. - - - - - - - -

5.4 - String Manipulation

- -

-This library provides generic functions for string manipulation, -such as finding and extracting substrings, and pattern matching. -When indexing a string in Lua, the first character is at position 1 -(not at 0, as in C). -Indices are allowed to be negative and are interpreted as indexing backwards, -from the end of the string. -Thus, the last character is at position -1, and so on. - - -

-The string library provides all its functions inside the table -string. -It also sets a metatable for strings -where the __index field points to the string table. -Therefore, you can use the string functions in object-oriented style. -For instance, string.byte(s, i) -can be written as s:byte(i). - - -

-The string library assumes one-byte character encodings. - - -

-


string.byte (s [, i [, j]])

-Returns the internal numerical codes of the characters s[i], -s[i+1], ···, s[j]. -The default value for i is 1; -the default value for j is i. - - -

-Note that numerical codes are not necessarily portable across platforms. - - - - -

-


string.char (···)

-Receives zero or more integers. -Returns a string with length equal to the number of arguments, -in which each character has the internal numerical code equal -to its corresponding argument. - - -

-Note that numerical codes are not necessarily portable across platforms. - - - - -

-


string.dump (function)

- - -

-Returns a string containing a binary representation of the given function, -so that a later loadstring on this string returns -a copy of the function. -function must be a Lua function without upvalues. - - - - -

-


string.find (s, pattern [, init [, plain]])

-Looks for the first match of -pattern in the string s. -If it finds a match, then find returns the indices of s -where this occurrence starts and ends; -otherwise, it returns nil. -A third, optional numerical argument init specifies -where to start the search; -its default value is 1 and can be negative. -A value of true as a fourth, optional argument plain -turns off the pattern matching facilities, -so the function does a plain "find substring" operation, -with no characters in pattern being considered "magic". -Note that if plain is given, then init must be given as well. - - -

-If the pattern has captures, -then in a successful match -the captured values are also returned, -after the two indices. - - - - -

-


string.format (formatstring, ···)

-Returns a formatted version of its variable number of arguments -following the description given in its first argument (which must be a string). -The format string follows the same rules as the printf family of -standard C functions. -The only differences are that the options/modifiers -*, l, L, n, p, -and h are not supported -and that there is an extra option, q. -The q option formats a string in a form suitable to be safely read -back by the Lua interpreter: -the string is written between double quotes, -and all double quotes, newlines, embedded zeros, -and backslashes in the string -are correctly escaped when written. -For instance, the call - -
-     string.format('%q', 'a string with "quotes" and \n new line')
-

-will produce the string: - -

-     "a string with \"quotes\" and \
-      new line"
-
- -

-The options c, d, E, e, f, -g, G, i, o, u, X, and x all -expect a number as argument, -whereas q and s expect a string. - - -

-This function does not accept string values -containing embedded zeros, -except as arguments to the q option. - - - - -

-


string.gmatch (s, pattern)

-Returns an iterator function that, -each time it is called, -returns the next captures from pattern over string s. -If pattern specifies no captures, -then the whole match is produced in each call. - - -

-As an example, the following loop - -

-     s = "hello world from Lua"
-     for w in string.gmatch(s, "%a+") do
-       print(w)
-     end
-

-will iterate over all the words from string s, -printing one per line. -The next example collects all pairs key=value from the -given string into a table: - -

-     t = {}
-     s = "from=world, to=Lua"
-     for k, v in string.gmatch(s, "(%w+)=(%w+)") do
-       t[k] = v
-     end
-
- -

-For this function, a '^' at the start of a pattern does not -work as an anchor, as this would prevent the iteration. - - - - -

-


string.gsub (s, pattern, repl [, n])

-Returns a copy of s -in which all (or the first n, if given) -occurrences of the pattern have been -replaced by a replacement string specified by repl, -which can be a string, a table, or a function. -gsub also returns, as its second value, -the total number of matches that occurred. - - -

-If repl is a string, then its value is used for replacement. -The character % works as an escape character: -any sequence in repl of the form %n, -with n between 1 and 9, -stands for the value of the n-th captured substring (see below). -The sequence %0 stands for the whole match. -The sequence %% stands for a single %. - - -

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

-If repl is a function, then this function is called every time a -match occurs, with all captured substrings passed as arguments, -in order; -if the pattern specifies no captures, -then the whole match is passed as a sole argument. - - -

-If the value returned by the table query or by the function call -is a string or a number, -then it is used as the replacement string; -otherwise, if it is false or nil, -then there is no replacement -(that is, the original match is kept in the string). - - -

-Here are some examples: - -

-     x = string.gsub("hello world", "(%w+)", "%1 %1")
-     --> x="hello hello world world"
-     
-     x = string.gsub("hello world", "%w+", "%0 %0", 1)
-     --> x="hello hello world"
-     
-     x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")
-     --> x="world hello Lua from"
-     
-     x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)
-     --> x="home = /home/roberto, user = roberto"
-     
-     x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)
-           return loadstring(s)()
-         end)
-     --> x="4+5 = 9"
-     
-     local t = {name="lua", version="5.1"}
-     x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
-     --> x="lua-5.1.tar.gz"
-
- - - -

-


string.len (s)

-Receives a string and returns its length. -The empty string "" has length 0. -Embedded zeros are counted, -so "a\000bc\000" has length 5. - - - - -

-


string.lower (s)

-Receives a string and returns a copy of this string with all -uppercase letters changed to lowercase. -All other characters are left unchanged. -The definition of what an uppercase letter is depends on the current locale. - - - - -

-


string.match (s, pattern [, init])

-Looks for the first match of -pattern in the string s. -If it finds one, then match returns -the captures from the pattern; -otherwise it returns nil. -If pattern specifies no captures, -then the whole match is returned. -A third, optional numerical argument init specifies -where to start the search; -its default value is 1 and can be negative. - - - - -

-


string.rep (s, n)

-Returns a string that is the concatenation of n copies of -the string s. - - - - -

-


string.reverse (s)

-Returns a string that is the string s reversed. - - - - -

-


string.sub (s, i [, j])

-Returns the substring of s that -starts at i and continues until j; -i and j can be negative. -If j is absent, then it is assumed to be equal to -1 -(which is the same as the string length). -In particular, -the call string.sub(s,1,j) returns a prefix of s -with length j, -and string.sub(s, -i) returns a suffix of s -with length i. - - - - -

-


string.upper (s)

-Receives a string and returns a copy of this string with all -lowercase letters changed to uppercase. -All other characters are left unchanged. -The definition of what a lowercase letter is depends on the current locale. - - - -

5.4.1 - Patterns

- - -

Character Class:

-A character class is used to represent a set of characters. -The following combinations are allowed in describing a character class: - -

    - -
  • x: -(where x is not one of the magic characters -^$()%.[]*+-?) -represents the character x itself. -
  • - -
  • .: (a dot) represents all characters.
  • - -
  • %a: represents all letters.
  • - -
  • %c: represents all control characters.
  • - -
  • %d: represents all digits.
  • - -
  • %l: represents all lowercase letters.
  • - -
  • %p: represents all punctuation characters.
  • - -
  • %s: represents all space characters.
  • - -
  • %u: represents all uppercase letters.
  • - -
  • %w: represents all alphanumeric characters.
  • - -
  • %x: represents all hexadecimal digits.
  • - -
  • %z: represents the character with representation 0.
  • - -
  • %x: (where x is any non-alphanumeric character) -represents the character x. -This is the standard way to escape the magic characters. -Any punctuation character (even the non magic) -can be preceded by a '%' -when used to represent itself in a pattern. -
  • - -
  • [set]: -represents the class which is the union of all -characters in set. -A range of characters can be specified by -separating the end characters of the range with a '-'. -All classes %x described above can also be used as -components in set. -All other characters in set represent themselves. -For example, [%w_] (or [_%w]) -represents all alphanumeric characters plus the underscore, -[0-7] represents the octal digits, -and [0-7%l%-] represents the octal digits plus -the lowercase letters plus the '-' character. - - -

    -The interaction between ranges and classes is not defined. -Therefore, patterns like [%a-z] or [a-%%] -have no meaning. -

  • - -
  • [^set]: -represents the complement of set, -where set is interpreted as above. -
  • - -

-For all classes represented by single letters (%a, %c, etc.), -the corresponding uppercase letter represents the complement of the class. -For instance, %S represents all non-space characters. - - -

-The definitions of letter, space, and other character groups -depend on the current locale. -In particular, the class [a-z] may not be equivalent to %l. - - - - - -

Pattern Item:

-A pattern item can be - -

    - -
  • -a single character class, -which matches any single character in the class; -
  • - -
  • -a single character class followed by '*', -which matches 0 or more repetitions of characters in the class. -These repetition items will always match the longest possible sequence; -
  • - -
  • -a single character class followed by '+', -which matches 1 or more repetitions of characters in the class. -These repetition items will always match the longest possible sequence; -
  • - -
  • -a single character class followed by '-', -which also matches 0 or more repetitions of characters in the class. -Unlike '*', -these repetition items will always match the shortest possible sequence; -
  • - -
  • -a single character class followed by '?', -which matches 0 or 1 occurrence of a character in the class; -
  • - -
  • -%n, for n between 1 and 9; -such item matches a substring equal to the n-th captured string -(see below); -
  • - -
  • -%bxy, where x and y are two distinct characters; -such item matches strings that start with x, end with y, -and where the x and y are balanced. -This means that, if one reads the string from left to right, -counting +1 for an x and -1 for a y, -the ending y is the first y where the count reaches 0. -For instance, the item %b() matches expressions with -balanced parentheses. -
  • - -
- - - - -

Pattern:

-A pattern is a sequence of pattern items. -A '^' at the beginning of a pattern anchors the match at the -beginning of the subject string. -A '$' at the end of a pattern anchors the match at the -end of the subject string. -At other positions, -'^' and '$' have no special meaning and represent themselves. - - - - - -

Captures:

-A pattern can contain sub-patterns enclosed in parentheses; -they describe captures. -When a match succeeds, the substrings of the subject string -that match captures are stored (captured) for future use. -Captures are numbered according to their left parentheses. -For instance, in the pattern "(a*(.)%w(%s*))", -the part of the string matching "a*(.)%w(%s*)" is -stored as the first capture (and therefore has number 1); -the character matching "." is captured with number 2, -and the part matching "%s*" has number 3. - - -

-As a special case, the empty capture () captures -the current string position (a number). -For instance, if we apply the pattern "()aa()" on the -string "flaaap", there will be two captures: 3 and 5. - - -

-A pattern cannot contain embedded zeros. Use %z instead. - - - - - - - - - - - -

5.5 - Table Manipulation

-This library provides generic functions for table manipulation. -It provides all its functions inside the table table. - - -

-Most functions in the table library assume that the table -represents an array or a list. -For these functions, when we talk about the "length" of a table -we mean the result of the length operator. - - -

-


table.concat (table [, sep [, i [, j]]])

-Given an array where all elements are strings or numbers, -returns table[i]..sep..table[i+1] ··· sep..table[j]. -The default value for sep is the empty string, -the default for i is 1, -and the default for j is the length of the table. -If i is greater than j, returns the empty string. - - - - -

-


table.insert (table, [pos,] value)

- - -

-Inserts element value at position pos in table, -shifting up other elements to open space, if necessary. -The default value for pos is n+1, -where n is the length of the table (see §2.5.5), -so that a call table.insert(t,x) inserts x at the end -of table t. - - - - -

-


table.maxn (table)

- - -

-Returns the largest positive numerical index of the given table, -or zero if the table has no positive numerical indices. -(To do its job this function does a linear traversal of -the whole table.) - - - - -

-


table.remove (table [, pos])

- - -

-Removes from table the element at position pos, -shifting down other elements to close the space, if necessary. -Returns the value of the removed element. -The default value for pos is n, -where n is the length of the table, -so that a call table.remove(t) removes the last element -of table t. - - - - -

-


table.sort (table [, comp])

-Sorts table elements in a given order, in-place, -from table[1] to table[n], -where n is the length of the table. -If comp is given, -then it must be a function that receives two table elements, -and returns true -when the first is less than the second -(so that not comp(a[i+1],a[i]) will be true after the sort). -If comp is not given, -then the standard Lua operator < is used instead. - - -

-The sort algorithm is not stable; -that is, elements considered equal by the given order -may have their relative positions changed by the sort. - - - - - - - -

5.6 - Mathematical Functions

- -

-This library is an interface to the standard C math library. -It provides all its functions inside the table math. - - -

-


math.abs (x)

- - -

-Returns the absolute value of x. - - - - -

-


math.acos (x)

- - -

-Returns the arc cosine of x (in radians). - - - - -

-


math.asin (x)

- - -

-Returns the arc sine of x (in radians). - - - - -

-


math.atan (x)

- - -

-Returns the arc tangent of x (in radians). - - - - -

-


math.atan2 (y, x)

- - -

-Returns the arc tangent of y/x (in radians), -but uses the signs of both parameters to find the -quadrant of the result. -(It also handles correctly the case of x being zero.) - - - - -

-


math.ceil (x)

- - -

-Returns the smallest integer larger than or equal to x. - - - - -

-


math.cos (x)

- - -

-Returns the cosine of x (assumed to be in radians). - - - - -

-


math.cosh (x)

- - -

-Returns the hyperbolic cosine of x. - - - - -

-


math.deg (x)

- - -

-Returns the angle x (given in radians) in degrees. - - - - -

-


math.exp (x)

- - -

-Returns the value ex. - - - - -

-


math.floor (x)

- - -

-Returns the largest integer smaller than or equal to x. - - - - -

-


math.fmod (x, y)

- - -

-Returns the remainder of the division of x by y -that rounds the quotient towards zero. - - - - -

-


math.frexp (x)

- - -

-Returns m and e such that x = m2e, -e is an integer and the absolute value of m is -in the range [0.5, 1) -(or zero when x is zero). - - - - -

-


math.huge

- - -

-The value HUGE_VAL, -a value larger than or equal to any other numerical value. - - - - -

-


math.ldexp (m, e)

- - -

-Returns m2e (e should be an integer). - - - - -

-


math.log (x)

- - -

-Returns the natural logarithm of x. - - - - -

-


math.log10 (x)

- - -

-Returns the base-10 logarithm of x. - - - - -

-


math.max (x, ···)

- - -

-Returns the maximum value among its arguments. - - - - -

-


math.min (x, ···)

- - -

-Returns the minimum value among its arguments. - - - - -

-


math.modf (x)

- - -

-Returns two numbers, -the integral part of x and the fractional part of x. - - - - -

-


math.pi

- - -

-The value of pi. - - - - -

-


math.pow (x, y)

- - -

-Returns xy. -(You can also use the expression x^y to compute this value.) - - - - -

-


math.rad (x)

- - -

-Returns the angle x (given in degrees) in radians. - - - - -

-


math.random ([m [, n]])

- - -

-This function is an interface to the simple -pseudo-random generator function rand provided by ANSI C. -(No guarantees can be given for its statistical properties.) - - -

-When called without arguments, -returns a uniform pseudo-random real number -in the range [0,1). -When called with an integer number m, -math.random returns -a uniform pseudo-random integer in the range [1, m]. -When called with two integer numbers m and n, -math.random returns a uniform pseudo-random -integer in the range [m, n]. - - - - -

-


math.randomseed (x)

- - -

-Sets x as the "seed" -for the pseudo-random generator: -equal seeds produce equal sequences of numbers. - - - - -

-


math.sin (x)

- - -

-Returns the sine of x (assumed to be in radians). - - - - -

-


math.sinh (x)

- - -

-Returns the hyperbolic sine of x. - - - - -

-


math.sqrt (x)

- - -

-Returns the square root of x. -(You can also use the expression x^0.5 to compute this value.) - - - - -

-


math.tan (x)

- - -

-Returns the tangent of x (assumed to be in radians). - - - - -

-


math.tanh (x)

- - -

-Returns the hyperbolic tangent of x. - - - - - - - -

5.7 - Input and Output Facilities

- -

-The I/O library provides two different styles for file manipulation. -The first one uses implicit file descriptors; -that is, there are operations to set a default input file and a -default output file, -and all input/output operations are over these default files. -The second style uses explicit file descriptors. - - -

-When using implicit file descriptors, -all operations are supplied by table io. -When using explicit file descriptors, -the operation io.open returns a file descriptor -and then all operations are supplied as methods of the file descriptor. - - -

-The table io also provides -three predefined file descriptors with their usual meanings from C: -io.stdin, io.stdout, and io.stderr. -The I/O library never closes these files. - - -

-Unless otherwise stated, -all I/O functions return nil on failure -(plus an error message as a second result and -a system-dependent error code as a third result) -and some value different from nil on success. - - -

-


io.close ([file])

- - -

-Equivalent to file:close(). -Without a file, closes the default output file. - - - - -

-


io.flush ()

- - -

-Equivalent to file:flush over the default output file. - - - - -

-


io.input ([file])

- - -

-When called with a file name, it opens the named file (in text mode), -and sets its handle as the default input file. -When called with a file handle, -it simply sets this file handle as the default input file. -When called without parameters, -it returns the current default input file. - - -

-In case of errors this function raises the error, -instead of returning an error code. - - - - -

-


io.lines ([filename])

- - -

-Opens the given file name in read mode -and returns an iterator function that, -each time it is called, -returns a new line from the file. -Therefore, the construction - -

-     for line in io.lines(filename) do body end
-

-will iterate over all lines of the file. -When the iterator function detects the end of file, -it returns nil (to finish the loop) and automatically closes the file. - - -

-The call io.lines() (with no file name) is equivalent -to io.input():lines(); -that is, it iterates over the lines of the default input file. -In this case it does not close the file when the loop ends. - - - - -

-


io.open (filename [, mode])

- - -

-This function opens a file, -in the mode specified in the string mode. -It returns a new file handle, -or, in case of errors, nil plus an error message. - - -

-The mode string can be any of the following: - -

    -
  • "r": read mode (the default);
  • -
  • "w": write mode;
  • -
  • "a": append mode;
  • -
  • "r+": update mode, all previous data is preserved;
  • -
  • "w+": update mode, all previous data is erased;
  • -
  • "a+": append update mode, previous data is preserved, - writing is only allowed at the end of file.
  • -

-The mode string can also have a 'b' at the end, -which is needed in some systems to open the file in binary mode. -This string is exactly what is used in the -standard C function fopen. - - - - -

-


io.output ([file])

- - -

-Similar to io.input, but operates over the default output file. - - - - -

-


io.popen (prog [, mode])

- - -

-Starts program prog in a separated process and returns -a file handle that you can use to read data from this program -(if mode is "r", the default) -or to write data to this program -(if mode is "w"). - - -

-This function is system dependent and is not available -on all platforms. - - - - -

-


io.read (···)

- - -

-Equivalent to io.input():read. - - - - -

-


io.tmpfile ()

- - -

-Returns a handle for a temporary file. -This file is opened in update mode -and it is automatically removed when the program ends. - - - - -

-


io.type (obj)

- - -

-Checks whether obj is a valid file handle. -Returns the string "file" if obj is an open file handle, -"closed file" if obj is a closed file handle, -or nil if obj is not a file handle. - - - - -

-


io.write (···)

- - -

-Equivalent to io.output():write. - - - - -

-


file:close ()

- - -

-Closes file. -Note that files are automatically closed when -their handles are garbage collected, -but that takes an unpredictable amount of time to happen. - - - - -

-


file:flush ()

- - -

-Saves any written data to file. - - - - -

-


file:lines ()

- - -

-Returns an iterator function that, -each time it is called, -returns a new line from the file. -Therefore, the construction - -

-     for line in file:lines() do body end
-

-will iterate over all lines of the file. -(Unlike io.lines, this function does not close the file -when the loop ends.) - - - - -

-


file:read (···)

- - -

-Reads the file file, -according to the given formats, which specify what to read. -For each format, -the function returns a string (or a number) with the characters read, -or nil if it cannot read data with the specified format. -When called without formats, -it uses a default format that reads the entire next line -(see below). - - -

-The available formats are - -

    - -
  • "*n": -reads a number; -this is the only format that returns a number instead of a string. -
  • - -
  • "*a": -reads the whole file, starting at the current position. -On end of file, it returns the empty string. -
  • - -
  • "*l": -reads the next line (skipping the end of line), -returning nil on end of file. -This is the default format. -
  • - -
  • number: -reads a string with up to this number of characters, -returning nil on end of file. -If number is zero, -it reads nothing and returns an empty string, -or nil on end of file. -
  • - -
- - - -

-


file:seek ([whence] [, offset])

- - -

-Sets and gets the file position, -measured from the beginning of the file, -to the position given by offset plus a base -specified by the string whence, as follows: - -

    -
  • "set": base is position 0 (beginning of the file);
  • -
  • "cur": base is current position;
  • -
  • "end": base is end of file;
  • -

-In case of success, function seek returns the final file position, -measured in bytes from the beginning of the file. -If this function fails, it returns nil, -plus a string describing the error. - - -

-The default value for whence is "cur", -and for offset is 0. -Therefore, the call file:seek() returns the current -file position, without changing it; -the call file:seek("set") sets the position to the -beginning of the file (and returns 0); -and the call file:seek("end") sets the position to the -end of the file, and returns its size. - - - - -

-


file:setvbuf (mode [, size])

- - -

-Sets the buffering mode for an output file. -There are three available modes: - -

    - -
  • "no": -no buffering; the result of any output operation appears immediately. -
  • - -
  • "full": -full buffering; output operation is performed only -when the buffer is full (or when you explicitly flush the file -(see io.flush)). -
  • - -
  • "line": -line buffering; output is buffered until a newline is output -or there is any input from some special files -(such as a terminal device). -
  • - -

-For the last two cases, size -specifies the size of the buffer, in bytes. -The default is an appropriate size. - - - - -

-


file:write (···)

- - -

-Writes the value of each of its arguments to -the file. -The arguments must be strings or numbers. -To write other values, -use tostring or string.format before write. - - - - - - - -

5.8 - Operating System Facilities

- -

-This library is implemented through table os. - - -

-


os.clock ()

- - -

-Returns an approximation of the amount in seconds of CPU time -used by the program. - - - - -

-


os.date ([format [, time]])

- - -

-Returns a string or a table containing date and time, -formatted according to the given string format. - - -

-If the time argument is present, -this is the time to be formatted -(see the os.time function for a description of this value). -Otherwise, date formats the current time. - - -

-If format starts with '!', -then the date is formatted in Coordinated Universal Time. -After this optional character, -if format is the string "*t", -then date returns a table with the following fields: -year (four digits), month (1--12), day (1--31), -hour (0--23), min (0--59), sec (0--61), -wday (weekday, Sunday is 1), -yday (day of the year), -and isdst (daylight saving flag, a boolean). - - -

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

-When called without arguments, -date returns a reasonable date and time representation that depends on -the host system and on the current locale -(that is, os.date() is equivalent to os.date("%c")). - - - - -

-


os.difftime (t2, t1)

- - -

-Returns the number of seconds from time t1 to time t2. -In POSIX, Windows, and some other systems, -this value is exactly t2-t1. - - - - -

-


os.execute ([command])

- - -

-This function is equivalent to the C function system. -It passes command to be executed by an operating system shell. -It returns a status code, which is system-dependent. -If command is absent, then it returns nonzero if a shell is available -and zero otherwise. - - - - -

-


os.exit ([code])

- - -

-Calls the C function exit, -with an optional code, -to terminate the host program. -The default value for code is the success code. - - - - -

-


os.getenv (varname)

- - -

-Returns the value of the process environment variable varname, -or nil if the variable is not defined. - - - - -

-


os.remove (filename)

- - -

-Deletes the file or directory with the given name. -Directories must be empty to be removed. -If this function fails, it returns nil, -plus a string describing the error. - - - - -

-


os.rename (oldname, newname)

- - -

-Renames file or directory named oldname to newname. -If this function fails, it returns nil, -plus a string describing the error. - - - - -

-


os.setlocale (locale [, category])

- - -

-Sets the current locale of the program. -locale is a string specifying a locale; -category is an optional string describing which category to change: -"all", "collate", "ctype", -"monetary", "numeric", or "time"; -the default category is "all". -The function returns the name of the new locale, -or nil if the request cannot be honored. - - -

-If locale is the empty string, -the current locale is set to an implementation-defined native locale. -If locale is the string "C", -the current locale is set to the standard C locale. - - -

-When called with nil as the first argument, -this function only returns the name of the current locale -for the given category. - - - - -

-


os.time ([table])

- - -

-Returns the current time when called without arguments, -or a time representing the date and time specified by the given table. -This table must have fields year, month, and day, -and may have fields hour, min, sec, and isdst -(for a description of these fields, see the os.date function). - - -

-The returned value is a number, whose meaning depends on your system. -In POSIX, Windows, and some other systems, this number counts the number -of seconds since some given start time (the "epoch"). -In other systems, the meaning is not specified, -and the number returned by time can be used only as an argument to -date and difftime. - - - - -

-


os.tmpname ()

- - -

-Returns a string with a file name that can -be used for a temporary file. -The file must be explicitly opened before its use -and explicitly removed when no longer needed. - - -

-On some systems (POSIX), -this function also creates a file with that name, -to avoid security risks. -(Someone else might create the file with wrong permissions -in the time between getting the name and creating the file.) -You still have to open the file to use it -and to remove it (even if you do not use it). - - -

-When possible, -you may prefer to use io.tmpfile, -which automatically removes the file when the program ends. - - - - - - - -

5.9 - The Debug Library

- -

-This library provides -the functionality of the debug interface to Lua programs. -You should exert care when using this library. -The functions provided here should be used exclusively for debugging -and similar tasks, such as profiling. -Please resist the temptation to use them as a -usual programming tool: -they can be very slow. -Moreover, several of these functions -violate some assumptions about Lua code -(e.g., that variables local to a function -cannot be accessed from outside or -that userdata metatables cannot be changed by Lua code) -and therefore can compromise otherwise secure code. - - -

-All functions in this library are provided -inside the debug table. -All functions that operate over a thread -have an optional first argument which is the -thread to operate over. -The default is always the current thread. - - -

-


debug.debug ()

- - -

-Enters an interactive mode with the user, -running each string that the user enters. -Using simple commands and other debug facilities, -the user can inspect global and local variables, -change their values, evaluate expressions, and so on. -A line containing only the word cont finishes this function, -so that the caller continues its execution. - - -

-Note that commands for debug.debug are not lexically nested -within any function, and so have no direct access to local variables. - - - - -

-


debug.getfenv (o)

-Returns the environment of object o. - - - - -

-


debug.gethook ([thread])

- - -

-Returns the current hook settings of the thread, as three values: -the current hook function, the current hook mask, -and the current hook count -(as set by the debug.sethook function). - - - - -

-


debug.getinfo ([thread,] function [, what])

- - -

-Returns a table with information about a function. -You can give the function directly, -or you can give a number as the value of function, -which means the function running at level function of the call stack -of the given thread: -level 0 is the current function (getinfo itself); -level 1 is the function that called getinfo; -and so on. -If function is a number larger than the number of active functions, -then getinfo returns nil. - - -

-The returned table can contain all the fields returned by lua_getinfo, -with the string what describing which fields to fill in. -The default for what is to get all information available, -except the table of valid lines. -If present, -the option 'f' -adds a field named func with the function itself. -If present, -the option 'L' -adds a field named activelines with the table of -valid lines. - - -

-For instance, the expression debug.getinfo(1,"n").name returns -a table with a name for the current function, -if a reasonable name can be found, -and the expression debug.getinfo(print) -returns a table with all available information -about the print function. - - - - -

-


debug.getlocal ([thread,] level, local)

- - -

-This function returns the name and the value of the local variable -with index local of the function at level level of the stack. -(The first parameter or local variable has index 1, and so on, -until the last active local variable.) -The function returns nil if there is no local -variable with the given index, -and raises an error when called with a level out of range. -(You can call debug.getinfo to check whether the level is valid.) - - -

-Variable names starting with '(' (open parentheses) -represent internal variables -(loop control variables, temporaries, and C function locals). - - - - -

-


debug.getmetatable (object)

- - -

-Returns the metatable of the given object -or nil if it does not have a metatable. - - - - -

-


debug.getregistry ()

- - -

-Returns the registry table (see §3.5). - - - - -

-


debug.getupvalue (func, up)

- - -

-This function returns the name and the value of the upvalue -with index up of the function func. -The function returns nil if there is no upvalue with the given index. - - - - -

-


debug.setfenv (object, table)

- - -

-Sets the environment of the given object to the given table. -Returns object. - - - - -

-


debug.sethook ([thread,] hook, mask [, count])

- - -

-Sets the given function as a hook. -The string mask and the number count describe -when the hook will be called. -The string mask may have the following characters, -with the given meaning: - -

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

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

-When called without arguments, -debug.sethook turns off the hook. - - -

-When the hook is called, its first parameter is a string -describing the event that has triggered its call: -"call", "return" (or "tail return", -when simulating a return from a tail call), -"line", and "count". -For line events, -the hook also gets the new line number as its second parameter. -Inside a hook, -you can call getinfo with level 2 to get more information about -the running function -(level 0 is the getinfo function, -and level 1 is the hook function), -unless the event is "tail return". -In this case, Lua is only simulating the return, -and a call to getinfo will return invalid data. - - - - -

-


debug.setlocal ([thread,] level, local, value)

- - -

-This function assigns the value value to the local variable -with index local of the function at level level of the stack. -The function returns nil if there is no local -variable with the given index, -and raises an error when called with a level out of range. -(You can call getinfo to check whether the level is valid.) -Otherwise, it returns the name of the local variable. - - - - -

-


debug.setmetatable (object, table)

- - -

-Sets the metatable for the given object to the given table -(which can be nil). - - - - -

-


debug.setupvalue (func, up, value)

- - -

-This function assigns the value value to the upvalue -with index up of the function func. -The function returns nil if there is no upvalue -with the given index. -Otherwise, it returns the name of the upvalue. - - - - -

-


debug.traceback ([thread,] [message] [, level])

- - -

-Returns a string with a traceback of the call stack. -An optional message string is appended -at the beginning of the traceback. -An optional level number tells at which level -to start the traceback -(default is 1, the function calling traceback). - - - - - - - -

6 - Lua Stand-alone

- -

-Although Lua has been designed as an extension language, -to be embedded in a host C program, -it is also frequently used as a stand-alone language. -An interpreter for Lua as a stand-alone language, -called simply lua, -is provided with the standard distribution. -The stand-alone interpreter includes -all standard libraries, including the debug library. -Its usage is: - -

-     lua [options] [script [args]]
-

-The options are: - -

    -
  • -e stat: executes string stat;
  • -
  • -l mod: "requires" mod;
  • -
  • -i: enters interactive mode after running script;
  • -
  • -v: prints version information;
  • -
  • --: stops handling options;
  • -
  • -: executes stdin as a file and stops handling options.
  • -

-After handling its options, lua runs the given script, -passing to it the given args as string arguments. -When called without arguments, -lua behaves as lua -v -i -when the standard input (stdin) is a terminal, -and as lua - otherwise. - - -

-Before running any argument, -the interpreter checks for an environment variable LUA_INIT. -If its format is @filename, -then lua executes the file. -Otherwise, lua executes the string itself. - - -

-All options are handled in order, except -i. -For instance, an invocation like - -

-     $ lua -e'a=1' -e 'print(a)' script.lua
-

-will first set a to 1, then print the value of a (which is '1'), -and finally run the file script.lua with no arguments. -(Here $ is the shell prompt. Your prompt may be different.) - - -

-Before starting to run the script, -lua collects all arguments in the command line -in a global table called arg. -The script name is stored at index 0, -the first argument after the script name goes to index 1, -and so on. -Any arguments before the script name -(that is, the interpreter name plus the options) -go to negative indices. -For instance, in the call - -

-     $ lua -la b.lua t1 t2
-

-the interpreter first runs the file a.lua, -then creates a table - -

-     arg = { [-2] = "lua", [-1] = "-la",
-             [0] = "b.lua",
-             [1] = "t1", [2] = "t2" }
-

-and finally runs the file b.lua. -The script is called with arg[1], arg[2], ··· -as arguments; -it can also access these arguments with the vararg expression '...'. - - -

-In interactive mode, -if you write an incomplete statement, -the interpreter waits for its completion -by issuing a different prompt. - - -

-If the global variable _PROMPT contains a string, -then its value is used as the prompt. -Similarly, if the global variable _PROMPT2 contains a string, -its value is used as the secondary prompt -(issued during incomplete statements). -Therefore, both prompts can be changed directly on the command line -or in any Lua programs by assigning to _PROMPT. -See the next example: - -

-     $ lua -e"_PROMPT='myprompt> '" -i
-

-(The outer pair of quotes is for the shell, -the inner pair is for Lua.) -Note the use of -i to enter interactive mode; -otherwise, -the program would just end silently -right after the assignment to _PROMPT. - - -

-To allow the use of Lua as a -script interpreter in Unix systems, -the stand-alone interpreter skips -the first line of a chunk if it starts with #. -Therefore, Lua scripts can be made into executable programs -by using chmod +x and the #! form, -as in - -

-     #!/usr/local/bin/lua
-

-(Of course, -the location of the Lua interpreter may be different in your machine. -If lua is in your PATH, -then - -

-     #!/usr/bin/env lua
-

-is a more portable solution.) - - - -

7 - Incompatibilities with the Previous Version

- -

-Here we list the incompatibilities that you may find when moving a program -from Lua 5.0 to Lua 5.1. -You can avoid most of the incompatibilities compiling Lua with -appropriate options (see file luaconf.h). -However, -all these compatibility options will be removed in the next version of Lua. - - - -

7.1 - Changes in the Language

-
    - -
  • -The vararg system changed from the pseudo-argument arg with a -table with the extra arguments to the vararg expression. -(See compile-time option LUA_COMPAT_VARARG in luaconf.h.) -
  • - -
  • -There was a subtle change in the scope of the implicit -variables of the for statement and for the repeat statement. -
  • - -
  • -The long string/long comment syntax ([[string]]) -does not allow nesting. -You can use the new syntax ([=[string]=]) in these cases. -(See compile-time option LUA_COMPAT_LSTR in luaconf.h.) -
  • - -
- - - - -

7.2 - Changes in the Libraries

-
    - -
  • -Function string.gfind was renamed string.gmatch. -(See compile-time option LUA_COMPAT_GFIND in luaconf.h.) -
  • - -
  • -When string.gsub is called with a function as its -third argument, -whenever this function returns nil or false the -replacement string is the whole match, -instead of the empty string. -
  • - -
  • -Function table.setn was deprecated. -Function table.getn corresponds -to the new length operator (#); -use the operator instead of the function. -(See compile-time option LUA_COMPAT_GETN in luaconf.h.) -
  • - -
  • -Function loadlib was renamed package.loadlib. -(See compile-time option LUA_COMPAT_LOADLIB in luaconf.h.) -
  • - -
  • -Function math.mod was renamed math.fmod. -(See compile-time option LUA_COMPAT_MOD in luaconf.h.) -
  • - -
  • -Functions table.foreach and table.foreachi are deprecated. -You can use a for loop with pairs or ipairs instead. -
  • - -
  • -There were substantial changes in function require due to -the new module system. -However, the new behavior is mostly compatible with the old, -but require gets the path from package.path instead -of from LUA_PATH. -
  • - -
  • -Function collectgarbage has different arguments. -Function gcinfo is deprecated; -use collectgarbage("count") instead. -
  • - -
- - - - -

7.3 - Changes in the API

-
    - -
  • -The luaopen_* functions (to open libraries) -cannot be called directly, -like a regular C function. -They must be called through Lua, -like a Lua function. -
  • - -
  • -Function lua_open was replaced by lua_newstate to -allow the user to set a memory-allocation function. -You can use luaL_newstate from the standard library to -create a state with a standard allocation function -(based on realloc). -
  • - -
  • -Functions luaL_getn and luaL_setn -(from the auxiliary library) are deprecated. -Use lua_objlen instead of luaL_getn -and nothing instead of luaL_setn. -
  • - -
  • -Function luaL_openlib was replaced by luaL_register. -
  • - -
  • -Function luaL_checkudata now throws an error when the given value -is not a userdata of the expected type. -(In Lua 5.0 it returned NULL.) -
  • - -
- - - - -

8 - The Complete Syntax of Lua

- -

-Here is the complete syntax of Lua in extended BNF. -(It does not describe operator precedences.) - - - - -

-
-	chunk ::= {stat [`;´]} [laststat [`;´]]
-
-	block ::= chunk
-
-	stat ::=  varlist `=´ explist | 
-		 functioncall | 
-		 do block end | 
-		 while exp do block end | 
-		 repeat block until exp | 
-		 if exp then block {elseif exp then block} [else block] end | 
-		 for Name `=´ exp `,´ exp [`,´ exp] do block end | 
-		 for namelist in explist do block end | 
-		 function funcname funcbody | 
-		 local function Name funcbody | 
-		 local namelist [`=´ explist] 
-
-	laststat ::= return [explist] | break
-
-	funcname ::= Name {`.´ Name} [`:´ Name]
-
-	varlist ::= var {`,´ var}
-
-	var ::=  Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name 
-
-	namelist ::= Name {`,´ Name}
-
-	explist ::= {exp `,´} exp
-
-	exp ::=  nil | false | true | Number | String | `...´ | function | 
-		 prefixexp | tableconstructor | exp binop exp | unop exp 
-
-	prefixexp ::= var | functioncall | `(´ exp `)´
-
-	functioncall ::=  prefixexp args | prefixexp `:´ Name args 
-
-	args ::=  `(´ [explist] `)´ | tableconstructor | String 
-
-	function ::= function funcbody
-
-	funcbody ::= `(´ [parlist] `)´ block end
-
-	parlist ::= namelist [`,´ `...´] | `...´
-
-	tableconstructor ::= `{´ [fieldlist] `}´
-
-	fieldlist ::= field {fieldsep field} [fieldsep]
-
-	field ::= `[´ exp `]´ `=´ exp | Name `=´ exp | exp
-
-	fieldsep ::= `,´ | `;´
-
-	binop ::= `+´ | `-´ | `*´ | `/´ | `^´ | `%´ | `..´ | 
-		 `<´ | `<=´ | `>´ | `>=´ | `==´ | `~=´ | 
-		 and | or
-
-	unop ::= `-´ | not | `#´
-
-
- -

- - - - - - - -


- -Last update: -Mon Aug 18 13:25:46 BRT 2008 - - - - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/manual.css =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/manual.css +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/manual.css @@ -1,13 +0,0 @@ -h3 code { - font-family: inherit ; -} - -pre { - font-size: 105% ; -} - -span.apii { - float: right ; - font-family: inherit ; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/readme.html =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/readme.html +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/doc/readme.html @@ -1,40 +0,0 @@ - - -Lua documentation - - - - - -
-

-Lua -Documentation -

- -This is the documentation included in the source distribution of Lua 5.1.4. - - - -Lua's -official web site -contains updated documentation, -especially the -reference manual. -

- -


- -Last update: -Tue Aug 12 14:46:07 BRT 2008 - - - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/Makefile =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/Makefile +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/Makefile @@ -1,44 +0,0 @@ -# makefile for Lua etc - -TOP= .. -LIB= $(TOP)/src -INC= $(TOP)/src -BIN= $(TOP)/src -SRC= $(TOP)/src -TST= $(TOP)/test - -CC= gcc -CFLAGS= -O2 -Wall -I$(INC) $(MYCFLAGS) -MYCFLAGS= -MYLDFLAGS= -Wl,-E -MYLIBS= -lm -#MYLIBS= -lm -Wl,-E -ldl -lreadline -lhistory -lncurses -RM= rm -f - -default: - @echo 'Please choose a target: min noparser one strict clean' - -min: min.c - $(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS) - echo 'print"Hello there!"' | ./a.out - -noparser: noparser.o - $(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS) - $(BIN)/luac $(TST)/hello.lua - -./a.out luac.out - -./a.out -e'a=1' - -one: - $(CC) $(CFLAGS) all.c $(MYLIBS) - ./a.out $(TST)/hello.lua - -strict: - -$(BIN)/lua -e 'print(a);b=2' - -$(BIN)/lua -lstrict -e 'print(a)' - -$(BIN)/lua -e 'function f() b=2 end f()' - -$(BIN)/lua -lstrict -e 'function f() b=2 end f()' - -clean: - $(RM) a.out core core.* *.o luac.out - -.PHONY: default min noparser one strict clean Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/README =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/README +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/README @@ -1,37 +0,0 @@ -This directory contains some useful files and code. -Unlike the code in ../src, everything here is in the public domain. - -If any of the makes fail, you're probably not using the same libraries -used to build Lua. Set MYLIBS in Makefile accordingly. - -all.c - Full Lua interpreter in a single file. - Do "make one" for a demo. - -lua.hpp - Lua header files for C++ using 'extern "C"'. - -lua.ico - A Lua icon for Windows (and web sites: save as favicon.ico). - Drawn by hand by Markus Gritsch . - -lua.pc - pkg-config data for Lua - -luavs.bat - Script to build Lua under "Visual Studio .NET Command Prompt". - Run it from the toplevel as etc\luavs.bat. - -min.c - A minimal Lua interpreter. - Good for learning and for starting your own. - Do "make min" for a demo. - -noparser.c - Linking with noparser.o avoids loading the parsing modules in lualib.a. - Do "make noparser" for a demo. - -strict.lua - Traps uses of undeclared global variables. - Do "make strict" for a demo. - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/all.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/all.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/all.c @@ -1,38 +0,0 @@ -/* -* all.c -- Lua core, libraries and interpreter in a single file -*/ - -#define luaall_c - -#include "lapi.c" -#include "lcode.c" -#include "ldebug.c" -#include "ldo.c" -#include "ldump.c" -#include "lfunc.c" -#include "lgc.c" -#include "llex.c" -#include "lmem.c" -#include "lobject.c" -#include "lopcodes.c" -#include "lparser.c" -#include "lstate.c" -#include "lstring.c" -#include "ltable.c" -#include "ltm.c" -#include "lundump.c" -#include "lvm.c" -#include "lzio.c" - -#include "lauxlib.c" -#include "lbaselib.c" -#include "ldblib.c" -#include "liolib.c" -#include "linit.c" -#include "lmathlib.c" -#include "loadlib.c" -#include "loslib.c" -#include "lstrlib.c" -#include "ltablib.c" - -#include "lua.c" Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/lua.hpp =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/lua.hpp +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/lua.hpp @@ -1,9 +0,0 @@ -// lua.hpp -// Lua header files for C++ -// <> not supplied automatically because Lua also compiles as C++ - -extern "C" { -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/lua.pc =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/lua.pc +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/lua.pc @@ -1,31 +0,0 @@ -# lua.pc -- pkg-config data for Lua - -# vars from install Makefile - -# grep '^V=' ../Makefile -V= 5.1 -# grep '^R=' ../Makefile -R= 5.1.4 - -# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/' -prefix= /usr/local -INSTALL_BIN= ${prefix}/bin -INSTALL_INC= ${prefix}/include -INSTALL_LIB= ${prefix}/lib -INSTALL_MAN= ${prefix}/man/man1 -INSTALL_LMOD= ${prefix}/share/lua/${V} -INSTALL_CMOD= ${prefix}/lib/lua/${V} - -# canonical vars -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: Lua -Description: An Extensible Extension Language -Version: ${R} -Requires: -Libs: -L${libdir} -llua -lm -Cflags: -I${includedir} - -# (end of lua.pc) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/luavs.bat =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/luavs.bat +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/luavs.bat @@ -1,28 +0,0 @@ -@rem Script to build Lua under "Visual Studio .NET Command Prompt". -@rem Do not run from this directory; run it from the toplevel: etc\luavs.bat . -@rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src. -@rem (contributed by David Manura and Mike Pall) - -@setlocal -@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE -@set MYLINK=link /nologo -@set MYMT=mt /nologo - -cd src -%MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c -del lua.obj luac.obj -%MYLINK% /DLL /out:lua51.dll l*.obj -if exist lua51.dll.manifest^ - %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2 -%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c -%MYLINK% /out:lua.exe lua.obj lua51.lib -if exist lua.exe.manifest^ - %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe -%MYCOMPILE% l*.c print.c -del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^ - loslib.obj ltablib.obj lstrlib.obj loadlib.obj -%MYLINK% /out:luac.exe *.obj -if exist luac.exe.manifest^ - %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe -del *.obj *.manifest -cd .. Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/min.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/min.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/min.c @@ -1,39 +0,0 @@ -/* -* min.c -- a minimal Lua interpreter -* loads stdin only with minimal error handling. -* no interaction, and no standard library, only a "print" function. -*/ - -#include - -#include "lua.h" -#include "lauxlib.h" - -static int print(lua_State *L) -{ - int n=lua_gettop(L); - int i; - for (i=1; i<=n; i++) - { - if (i>1) printf("\t"); - if (lua_isstring(L,i)) - printf("%s",lua_tostring(L,i)); - else if (lua_isnil(L,i)) - printf("%s","nil"); - else if (lua_isboolean(L,i)) - printf("%s",lua_toboolean(L,i) ? "true" : "false"); - else - printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); - } - printf("\n"); - return 0; -} - -int main(void) -{ - lua_State *L=lua_open(); - lua_register(L,"print",print); - if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); - lua_close(L); - return 0; -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/noparser.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/noparser.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/noparser.c @@ -1,50 +0,0 @@ -/* -* The code below can be used to make a Lua core that does not contain the -* parsing modules (lcode, llex, lparser), which represent 35% of the total core. -* You'll only be able to load binary files and strings, precompiled with luac. -* (Of course, you'll have to build luac with the original parsing modules!) -* -* To use this module, simply compile it ("make noparser" does that) and list -* its object file before the Lua libraries. The linker should then not load -* the parsing modules. To try it, do "make luab". -* -* If you also want to avoid the dump module (ldump.o), define NODUMP. -* #define NODUMP -*/ - -#define LUA_CORE - -#include "llex.h" -#include "lparser.h" -#include "lzio.h" - -LUAI_FUNC void luaX_init (lua_State *L) { - UNUSED(L); -} - -LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { - UNUSED(z); - UNUSED(buff); - UNUSED(name); - lua_pushliteral(L,"parser not loaded"); - lua_error(L); - return NULL; -} - -#ifdef NODUMP -#include "lundump.h" - -LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) { - UNUSED(f); - UNUSED(w); - UNUSED(data); - UNUSED(strip); -#if 1 - UNUSED(L); - return 0; -#else - lua_pushliteral(L,"dumper not loaded"); - lua_error(L); -#endif -} -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/strict.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/strict.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/etc/strict.lua @@ -1,41 +0,0 @@ --- --- strict.lua --- checks uses of undeclared global variables --- All global variables must be 'declared' through a regular assignment --- (even assigning nil will do) in a main chunk before being used --- anywhere or assigned to inside a function. --- - -local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget - -local mt = getmetatable(_G) -if mt == nil then - mt = {} - setmetatable(_G, mt) -end - -mt.__declared = {} - -local function what () - local d = getinfo(3, "S") - return d and d.what or "C" -end - -mt.__newindex = function (t, n, v) - if not mt.__declared[n] then - local w = what() - if w ~= "main" and w ~= "C" then - error("assign to undeclared variable '"..n.."'", 2) - end - mt.__declared[n] = true - end - rawset(t, n, v) -end - -mt.__index = function (t, n) - if not mt.__declared[n] and what() ~= "C" then - error("variable '"..n.."' is not declared", 2) - end - return rawget(t, n) -end - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/Makefile =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/Makefile +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/Makefile @@ -1,182 +0,0 @@ -# makefile for building Lua -# see ../INSTALL for installation instructions -# see ../Makefile and luaconf.h for further customization - -# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= - -# Your platform. See PLATS for possible values. -PLAT= none - -CC= gcc -CFLAGS= -O2 -Wall $(MYCFLAGS) -AR= ar rcu -RANLIB= ranlib -RM= rm -f -LIBS= -lm $(MYLIBS) - -MYCFLAGS= -MYLDFLAGS= -MYLIBS= - -# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= - -PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris - -LUA_A= liblua.a -CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ - lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ - lundump.o lvm.o lzio.o -LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \ - lstrlib.o loadlib.o linit.o - -LUA_T= lua -LUA_O= lua.o - -LUAC_T= luac -LUAC_O= luac.o print.o - -ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) -ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) -ALL_A= $(LUA_A) - -default: $(PLAT) - -all: $(ALL_T) - -o: $(ALL_O) - -a: $(ALL_A) - -$(LUA_A): $(CORE_O) $(LIB_O) - $(AR) $@ $? - $(RANLIB) $@ - -$(LUA_T): $(LUA_O) $(LUA_A) - $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) - -$(LUAC_T): $(LUAC_O) $(LUA_A) - $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) - -clean: - $(RM) $(ALL_T) $(ALL_O) - -depend: - @$(CC) $(CFLAGS) -MM l*.c print.c - -echo: - @echo "PLAT = $(PLAT)" - @echo "CC = $(CC)" - @echo "CFLAGS = $(CFLAGS)" - @echo "AR = $(AR)" - @echo "RANLIB = $(RANLIB)" - @echo "RM = $(RM)" - @echo "MYCFLAGS = $(MYCFLAGS)" - @echo "MYLDFLAGS = $(MYLDFLAGS)" - @echo "MYLIBS = $(MYLIBS)" - -# convenience targets for popular platforms - -none: - @echo "Please choose a platform:" - @echo " $(PLATS)" - -aix: - $(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall" - -ansi: - $(MAKE) all MYCFLAGS=-DLUA_ANSI - -bsd: - $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E" - -freebsd: - $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline" - -generic: - $(MAKE) all MYCFLAGS= - -linux: - $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" - -macosx: - $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline" -# use this on Mac OS X 10.3- -# $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX - -mingw: - $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \ - "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ - "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe - $(MAKE) "LUAC_T=luac.exe" luac.exe - -posix: - $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX - -solaris: - $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" - -# list targets that do not create files (but not all makes understand .PHONY) -.PHONY: all $(PLATS) default o a clean depend echo none - -# DO NOT DELETE - -lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \ - lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \ - lundump.h lvm.h -lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h -lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h -lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ - lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \ - ltable.h -ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h -ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ - llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ - lfunc.h lstring.h lgc.h ltable.h lvm.h -ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ - lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \ - ltable.h lundump.h lvm.h -ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ - lzio.h lmem.h lundump.h -lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \ - lstate.h ltm.h lzio.h -lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ - lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h -linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h -liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h -llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ - lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h -lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h -lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ - ltm.h lzio.h lmem.h ldo.h -loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h -lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \ - ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h -lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h -loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h -lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ - lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ - lfunc.h lstring.h lgc.h ltable.h -lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ - ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h -lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \ - ltm.h lzio.h lstring.h lgc.h -lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h -ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ - ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h -ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h -ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \ - lmem.h lstring.h lgc.h ltable.h -lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h -luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \ - lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \ - lundump.h -lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h -lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ - lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h -lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \ - lzio.h -print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \ - ltm.h lzio.h lmem.h lopcodes.h lundump.h - -# (end of Makefile) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lapi.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lapi.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lapi.h @@ -1,16 +0,0 @@ -/* -** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ -** Auxiliary functions from Lua API -** See Copyright Notice in lua.h -*/ - -#ifndef lapi_h -#define lapi_h - - -#include "lobject.h" - - -LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lapi.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lapi.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lapi.c @@ -1,1087 +0,0 @@ -/* -** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $ -** Lua API -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include -#include - -#define lapi_c -#define LUA_CORE - -#include "lua.h" - -#include "lapi.h" -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lgc.h" -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" -#include "lundump.h" -#include "lvm.h" - - - -const char lua_ident[] = - "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" - "$Authors: " LUA_AUTHORS " $\n" - "$URL: www.lua.org $\n"; - - - -#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) - -#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject) - -#define api_incr_top(L) {api_check(L, L->top < L->ci->top); L->top++;} - - - -static TValue *index2adr (lua_State *L, int idx) { - if (idx > 0) { - TValue *o = L->base + (idx - 1); - api_check(L, idx <= L->ci->top - L->base); - if (o >= L->top) return cast(TValue *, luaO_nilobject); - else return o; - } - else if (idx > LUA_REGISTRYINDEX) { - api_check(L, idx != 0 && -idx <= L->top - L->base); - return L->top + idx; - } - else switch (idx) { /* pseudo-indices */ - case LUA_REGISTRYINDEX: return registry(L); - case LUA_ENVIRONINDEX: { - Closure *func = curr_func(L); - sethvalue(L, &L->env, func->c.env); - return &L->env; - } - case LUA_GLOBALSINDEX: return gt(L); - default: { - Closure *func = curr_func(L); - idx = LUA_GLOBALSINDEX - idx; - return (idx <= func->c.nupvalues) - ? &func->c.upvalue[idx-1] - : cast(TValue *, luaO_nilobject); - } - } -} - - -static Table *getcurrenv (lua_State *L) { - if (L->ci == L->base_ci) /* no enclosing function? */ - return hvalue(gt(L)); /* use global table as environment */ - else { - Closure *func = curr_func(L); - return func->c.env; - } -} - - -void luaA_pushobject (lua_State *L, const TValue *o) { - setobj2s(L, L->top, o); - api_incr_top(L); -} - - -LUA_API int lua_checkstack (lua_State *L, int size) { - int res = 1; - lua_lock(L); - if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) - res = 0; /* stack overflow */ - else if (size > 0) { - luaD_checkstack(L, size); - if (L->ci->top < L->top + size) - L->ci->top = L->top + size; - } - lua_unlock(L); - return res; -} - - -LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { - int i; - if (from == to) return; - lua_lock(to); - api_checknelems(from, n); - api_check(from, G(from) == G(to)); - api_check(from, to->ci->top - to->top >= n); - from->top -= n; - for (i = 0; i < n; i++) { - setobj2s(to, to->top++, from->top + i); - } - lua_unlock(to); -} - - -LUA_API void lua_setlevel (lua_State *from, lua_State *to) { - to->nCcalls = from->nCcalls; -} - - -LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) { - lua_CFunction old; - lua_lock(L); - old = G(L)->panic; - G(L)->panic = panicf; - lua_unlock(L); - return old; -} - - -LUA_API lua_State *lua_newthread (lua_State *L) { - lua_State *L1; - lua_lock(L); - luaC_checkGC(L); - L1 = luaE_newthread(L); - setthvalue(L, L->top, L1); - api_incr_top(L); - lua_unlock(L); - luai_userstatethread(L, L1); - return L1; -} - - - -/* -** basic stack manipulation -*/ - - -LUA_API int lua_gettop (lua_State *L) { - return cast_int(L->top - L->base); -} - - -LUA_API void lua_settop (lua_State *L, int idx) { - lua_lock(L); - if (idx >= 0) { - api_check(L, idx <= L->stack_last - L->base); - while (L->top < L->base + idx) - setnilvalue(L->top++); - L->top = L->base + idx; - } - else { - api_check(L, -(idx+1) <= (L->top - L->base)); - L->top += idx+1; /* `subtract' index (index is negative) */ - } - lua_unlock(L); -} - - -LUA_API void lua_remove (lua_State *L, int idx) { - StkId p; - lua_lock(L); - p = index2adr(L, idx); - api_checkvalidindex(L, p); - while (++p < L->top) setobjs2s(L, p-1, p); - L->top--; - lua_unlock(L); -} - - -LUA_API void lua_insert (lua_State *L, int idx) { - StkId p; - StkId q; - lua_lock(L); - p = index2adr(L, idx); - api_checkvalidindex(L, p); - for (q = L->top; q>p; q--) setobjs2s(L, q, q-1); - setobjs2s(L, p, L->top); - lua_unlock(L); -} - - -LUA_API void lua_replace (lua_State *L, int idx) { - StkId o; - lua_lock(L); - /* explicit test for incompatible code */ - if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) - luaG_runerror(L, "no calling environment"); - api_checknelems(L, 1); - o = index2adr(L, idx); - api_checkvalidindex(L, o); - if (idx == LUA_ENVIRONINDEX) { - Closure *func = curr_func(L); - api_check(L, ttistable(L->top - 1)); - func->c.env = hvalue(L->top - 1); - luaC_barrier(L, func, L->top - 1); - } - else { - setobj(L, o, L->top - 1); - if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ - luaC_barrier(L, curr_func(L), L->top - 1); - } - L->top--; - lua_unlock(L); -} - - -LUA_API void lua_pushvalue (lua_State *L, int idx) { - lua_lock(L); - setobj2s(L, L->top, index2adr(L, idx)); - api_incr_top(L); - lua_unlock(L); -} - - - -/* -** access functions (stack -> C) -*/ - - -LUA_API int lua_type (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); -} - - -LUA_API const char *lua_typename (lua_State *L, int t) { - UNUSED(L); - return (t == LUA_TNONE) ? "no value" : luaT_typenames[t]; -} - - -LUA_API int lua_iscfunction (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - return iscfunction(o); -} - - -LUA_API int lua_isnumber (lua_State *L, int idx) { - TValue n; - const TValue *o = index2adr(L, idx); - return tonumber(o, &n); -} - - -LUA_API int lua_isstring (lua_State *L, int idx) { - int t = lua_type(L, idx); - return (t == LUA_TSTRING || t == LUA_TNUMBER); -} - - -LUA_API int lua_isuserdata (lua_State *L, int idx) { - const TValue *o = index2adr(L, idx); - return (ttisuserdata(o) || ttislightuserdata(o)); -} - - -LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { - StkId o1 = index2adr(L, index1); - StkId o2 = index2adr(L, index2); - return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 - : luaO_rawequalObj(o1, o2); -} - - -LUA_API int lua_equal (lua_State *L, int index1, int index2) { - StkId o1, o2; - int i; - lua_lock(L); /* may call tag method */ - o1 = index2adr(L, index1); - o2 = index2adr(L, index2); - i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); - lua_unlock(L); - return i; -} - - -LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { - StkId o1, o2; - int i; - lua_lock(L); /* may call tag method */ - o1 = index2adr(L, index1); - o2 = index2adr(L, index2); - i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 - : luaV_lessthan(L, o1, o2); - lua_unlock(L); - return i; -} - - - -LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { - TValue n; - const TValue *o = index2adr(L, idx); - if (tonumber(o, &n)) - return nvalue(o); - else - return 0; -} - - -LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { - TValue n; - const TValue *o = index2adr(L, idx); - if (tonumber(o, &n)) { - lua_Integer res; - lua_Number num = nvalue(o); - lua_number2integer(res, num); - return res; - } - else - return 0; -} - - -LUA_API int lua_toboolean (lua_State *L, int idx) { - const TValue *o = index2adr(L, idx); - return !l_isfalse(o); -} - - -LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { - StkId o = index2adr(L, idx); - if (!ttisstring(o)) { - lua_lock(L); /* `luaV_tostring' may create a new string */ - if (!luaV_tostring(L, o)) { /* conversion failed? */ - if (len != NULL) *len = 0; - lua_unlock(L); - return NULL; - } - luaC_checkGC(L); - o = index2adr(L, idx); /* previous call may reallocate the stack */ - lua_unlock(L); - } - if (len != NULL) *len = tsvalue(o)->len; - return svalue(o); -} - - -LUA_API size_t lua_objlen (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - switch (ttype(o)) { - case LUA_TSTRING: return tsvalue(o)->len; - case LUA_TUSERDATA: return uvalue(o)->len; - case LUA_TTABLE: return luaH_getn(hvalue(o)); - case LUA_TNUMBER: { - size_t l; - lua_lock(L); /* `luaV_tostring' may create a new string */ - l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); - lua_unlock(L); - return l; - } - default: return 0; - } -} - - -LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - return (!iscfunction(o)) ? NULL : clvalue(o)->c.f; -} - - -LUA_API void *lua_touserdata (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - switch (ttype(o)) { - case LUA_TUSERDATA: return (rawuvalue(o) + 1); - case LUA_TLIGHTUSERDATA: return pvalue(o); - default: return NULL; - } -} - - -LUA_API lua_State *lua_tothread (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - return (!ttisthread(o)) ? NULL : thvalue(o); -} - - -LUA_API const void *lua_topointer (lua_State *L, int idx) { - StkId o = index2adr(L, idx); - switch (ttype(o)) { - case LUA_TTABLE: return hvalue(o); - case LUA_TFUNCTION: return clvalue(o); - case LUA_TTHREAD: return thvalue(o); - case LUA_TUSERDATA: - case LUA_TLIGHTUSERDATA: - return lua_touserdata(L, idx); - default: return NULL; - } -} - - - -/* -** push functions (C -> stack) -*/ - - -LUA_API void lua_pushnil (lua_State *L) { - lua_lock(L); - setnilvalue(L->top); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { - lua_lock(L); - setnvalue(L->top, n); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { - lua_lock(L); - setnvalue(L->top, cast_num(n)); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { - lua_lock(L); - luaC_checkGC(L); - setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_pushstring (lua_State *L, const char *s) { - if (s == NULL) - lua_pushnil(L); - else - lua_pushlstring(L, s, strlen(s)); -} - - -LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, - va_list argp) { - const char *ret; - lua_lock(L); - luaC_checkGC(L); - ret = luaO_pushvfstring(L, fmt, argp); - lua_unlock(L); - return ret; -} - - -LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { - const char *ret; - va_list argp; - lua_lock(L); - luaC_checkGC(L); - va_start(argp, fmt); - ret = luaO_pushvfstring(L, fmt, argp); - va_end(argp); - lua_unlock(L); - return ret; -} - - -LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { - Closure *cl; - lua_lock(L); - luaC_checkGC(L); - api_checknelems(L, n); - cl = luaF_newCclosure(L, n, getcurrenv(L)); - cl->c.f = fn; - L->top -= n; - while (n--) - setobj2n(L, &cl->c.upvalue[n], L->top+n); - setclvalue(L, L->top, cl); - lua_assert(iswhite(obj2gco(cl))); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_pushboolean (lua_State *L, int b) { - lua_lock(L); - setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { - lua_lock(L); - setpvalue(L->top, p); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API int lua_pushthread (lua_State *L) { - lua_lock(L); - setthvalue(L, L->top, L); - api_incr_top(L); - lua_unlock(L); - return (G(L)->mainthread == L); -} - - - -/* -** get functions (Lua -> stack) -*/ - - -LUA_API void lua_gettable (lua_State *L, int idx) { - StkId t; - lua_lock(L); - t = index2adr(L, idx); - api_checkvalidindex(L, t); - luaV_gettable(L, t, L->top - 1, L->top - 1); - lua_unlock(L); -} - - -LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { - StkId t; - TValue key; - lua_lock(L); - t = index2adr(L, idx); - api_checkvalidindex(L, t); - setsvalue(L, &key, luaS_new(L, k)); - luaV_gettable(L, t, &key, L->top); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_rawget (lua_State *L, int idx) { - StkId t; - lua_lock(L); - t = index2adr(L, idx); - api_check(L, ttistable(t)); - setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); - lua_unlock(L); -} - - -LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { - StkId o; - lua_lock(L); - o = index2adr(L, idx); - api_check(L, ttistable(o)); - setobj2s(L, L->top, luaH_getnum(hvalue(o), n)); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { - lua_lock(L); - luaC_checkGC(L); - sethvalue(L, L->top, luaH_new(L, narray, nrec)); - api_incr_top(L); - lua_unlock(L); -} - - -LUA_API int lua_getmetatable (lua_State *L, int objindex) { - const TValue *obj; - Table *mt = NULL; - int res; - lua_lock(L); - obj = index2adr(L, objindex); - switch (ttype(obj)) { - case LUA_TTABLE: - mt = hvalue(obj)->metatable; - break; - case LUA_TUSERDATA: - mt = uvalue(obj)->metatable; - break; - default: - mt = G(L)->mt[ttype(obj)]; - break; - } - if (mt == NULL) - res = 0; - else { - sethvalue(L, L->top, mt); - api_incr_top(L); - res = 1; - } - lua_unlock(L); - return res; -} - - -LUA_API void lua_getfenv (lua_State *L, int idx) { - StkId o; - lua_lock(L); - o = index2adr(L, idx); - api_checkvalidindex(L, o); - switch (ttype(o)) { - case LUA_TFUNCTION: - sethvalue(L, L->top, clvalue(o)->c.env); - break; - case LUA_TUSERDATA: - sethvalue(L, L->top, uvalue(o)->env); - break; - case LUA_TTHREAD: - setobj2s(L, L->top, gt(thvalue(o))); - break; - default: - setnilvalue(L->top); - break; - } - api_incr_top(L); - lua_unlock(L); -} - - -/* -** set functions (stack -> Lua) -*/ - - -LUA_API void lua_settable (lua_State *L, int idx) { - StkId t; - lua_lock(L); - api_checknelems(L, 2); - t = index2adr(L, idx); - api_checkvalidindex(L, t); - luaV_settable(L, t, L->top - 2, L->top - 1); - L->top -= 2; /* pop index and value */ - lua_unlock(L); -} - - -LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { - StkId t; - TValue key; - lua_lock(L); - api_checknelems(L, 1); - t = index2adr(L, idx); - api_checkvalidindex(L, t); - setsvalue(L, &key, luaS_new(L, k)); - luaV_settable(L, t, &key, L->top - 1); - L->top--; /* pop value */ - lua_unlock(L); -} - - -LUA_API void lua_rawset (lua_State *L, int idx) { - StkId t; - lua_lock(L); - api_checknelems(L, 2); - t = index2adr(L, idx); - api_check(L, ttistable(t)); - setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); - luaC_barriert(L, hvalue(t), L->top-1); - L->top -= 2; - lua_unlock(L); -} - - -LUA_API void lua_rawseti (lua_State *L, int idx, int n) { - StkId o; - lua_lock(L); - api_checknelems(L, 1); - o = index2adr(L, idx); - api_check(L, ttistable(o)); - setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1); - luaC_barriert(L, hvalue(o), L->top-1); - L->top--; - lua_unlock(L); -} - - -LUA_API int lua_setmetatable (lua_State *L, int objindex) { - TValue *obj; - Table *mt; - lua_lock(L); - api_checknelems(L, 1); - obj = index2adr(L, objindex); - api_checkvalidindex(L, obj); - if (ttisnil(L->top - 1)) - mt = NULL; - else { - api_check(L, ttistable(L->top - 1)); - mt = hvalue(L->top - 1); - } - switch (ttype(obj)) { - case LUA_TTABLE: { - hvalue(obj)->metatable = mt; - if (mt) - luaC_objbarriert(L, hvalue(obj), mt); - break; - } - case LUA_TUSERDATA: { - uvalue(obj)->metatable = mt; - if (mt) - luaC_objbarrier(L, rawuvalue(obj), mt); - break; - } - default: { - G(L)->mt[ttype(obj)] = mt; - break; - } - } - L->top--; - lua_unlock(L); - return 1; -} - - -LUA_API int lua_setfenv (lua_State *L, int idx) { - StkId o; - int res = 1; - lua_lock(L); - api_checknelems(L, 1); - o = index2adr(L, idx); - api_checkvalidindex(L, o); - api_check(L, ttistable(L->top - 1)); - switch (ttype(o)) { - case LUA_TFUNCTION: - clvalue(o)->c.env = hvalue(L->top - 1); - break; - case LUA_TUSERDATA: - uvalue(o)->env = hvalue(L->top - 1); - break; - case LUA_TTHREAD: - sethvalue(L, gt(thvalue(o)), hvalue(L->top - 1)); - break; - default: - res = 0; - break; - } - if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); - L->top--; - lua_unlock(L); - return res; -} - - -/* -** `load' and `call' functions (run Lua code) -*/ - - -#define adjustresults(L,nres) \ - { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; } - - -#define checkresults(L,na,nr) \ - api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) - - -LUA_API void lua_call (lua_State *L, int nargs, int nresults) { - StkId func; - lua_lock(L); - api_checknelems(L, nargs+1); - checkresults(L, nargs, nresults); - func = L->top - (nargs+1); - luaD_call(L, func, nresults); - adjustresults(L, nresults); - lua_unlock(L); -} - - - -/* -** Execute a protected call. -*/ -struct CallS { /* data to `f_call' */ - StkId func; - int nresults; -}; - - -static void f_call (lua_State *L, void *ud) { - struct CallS *c = cast(struct CallS *, ud); - luaD_call(L, c->func, c->nresults); -} - - - -LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) { - struct CallS c; - int status; - ptrdiff_t func; - lua_lock(L); - api_checknelems(L, nargs+1); - checkresults(L, nargs, nresults); - if (errfunc == 0) - func = 0; - else { - StkId o = index2adr(L, errfunc); - api_checkvalidindex(L, o); - func = savestack(L, o); - } - c.func = L->top - (nargs+1); /* function to be called */ - c.nresults = nresults; - status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); - adjustresults(L, nresults); - lua_unlock(L); - return status; -} - - -/* -** Execute a protected C call. -*/ -struct CCallS { /* data to `f_Ccall' */ - lua_CFunction func; - void *ud; -}; - - -static void f_Ccall (lua_State *L, void *ud) { - struct CCallS *c = cast(struct CCallS *, ud); - Closure *cl; - cl = luaF_newCclosure(L, 0, getcurrenv(L)); - cl->c.f = c->func; - setclvalue(L, L->top, cl); /* push function */ - api_incr_top(L); - setpvalue(L->top, c->ud); /* push only argument */ - api_incr_top(L); - luaD_call(L, L->top - 2, 0); -} - - -LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { - struct CCallS c; - int status; - lua_lock(L); - c.func = func; - c.ud = ud; - status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0); - lua_unlock(L); - return status; -} - - -LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, - const char *chunkname) { - ZIO z; - int status; - lua_lock(L); - if (!chunkname) chunkname = "?"; - luaZ_init(L, &z, reader, data); - status = luaD_protectedparser(L, &z, chunkname); - lua_unlock(L); - return status; -} - - -LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { - int status; - TValue *o; - lua_lock(L); - api_checknelems(L, 1); - o = L->top - 1; - if (isLfunction(o)) - status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); - else - status = 1; - lua_unlock(L); - return status; -} - - -LUA_API int lua_status (lua_State *L) { - return L->status; -} - - -/* -** Garbage-collection function -*/ - -LUA_API int lua_gc (lua_State *L, int what, int data) { - int res = 0; - global_State *g; - lua_lock(L); - g = G(L); - switch (what) { - case LUA_GCSTOP: { - g->GCthreshold = MAX_LUMEM; - break; - } - case LUA_GCRESTART: { - g->GCthreshold = g->totalbytes; - break; - } - case LUA_GCCOLLECT: { - luaC_fullgc(L); - break; - } - case LUA_GCCOUNT: { - /* GC values are expressed in Kbytes: #bytes/2^10 */ - res = cast_int(g->totalbytes >> 10); - break; - } - case LUA_GCCOUNTB: { - res = cast_int(g->totalbytes & 0x3ff); - break; - } - case LUA_GCSTEP: { - lu_mem a = (cast(lu_mem, data) << 10); - if (a <= g->totalbytes) - g->GCthreshold = g->totalbytes - a; - else - g->GCthreshold = 0; - while (g->GCthreshold <= g->totalbytes) { - luaC_step(L); - if (g->gcstate == GCSpause) { /* end of cycle? */ - res = 1; /* signal it */ - break; - } - } - break; - } - case LUA_GCSETPAUSE: { - res = g->gcpause; - g->gcpause = data; - break; - } - case LUA_GCSETSTEPMUL: { - res = g->gcstepmul; - g->gcstepmul = data; - break; - } - default: res = -1; /* invalid option */ - } - lua_unlock(L); - return res; -} - - - -/* -** miscellaneous functions -*/ - - -LUA_API int lua_error (lua_State *L) { - lua_lock(L); - api_checknelems(L, 1); - luaG_errormsg(L); - lua_unlock(L); - return 0; /* to avoid warnings */ -} - - -LUA_API int lua_next (lua_State *L, int idx) { - StkId t; - int more; - lua_lock(L); - t = index2adr(L, idx); - api_check(L, ttistable(t)); - more = luaH_next(L, hvalue(t), L->top - 1); - if (more) { - api_incr_top(L); - } - else /* no more elements */ - L->top -= 1; /* remove key */ - lua_unlock(L); - return more; -} - - -LUA_API void lua_concat (lua_State *L, int n) { - lua_lock(L); - api_checknelems(L, n); - if (n >= 2) { - luaC_checkGC(L); - luaV_concat(L, n, cast_int(L->top - L->base) - 1); - L->top -= (n-1); - } - else if (n == 0) { /* push empty string */ - setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); - api_incr_top(L); - } - /* else n == 1; nothing to do */ - lua_unlock(L); -} - - -LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { - lua_Alloc f; - lua_lock(L); - if (ud) *ud = G(L)->ud; - f = G(L)->frealloc; - lua_unlock(L); - return f; -} - - -LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) { - lua_lock(L); - G(L)->ud = ud; - G(L)->frealloc = f; - lua_unlock(L); -} - - -LUA_API void *lua_newuserdata (lua_State *L, size_t size) { - Udata *u; - lua_lock(L); - luaC_checkGC(L); - u = luaS_newudata(L, size, getcurrenv(L)); - setuvalue(L, L->top, u); - api_incr_top(L); - lua_unlock(L); - return u + 1; -} - - - - -static const char *aux_upvalue (StkId fi, int n, TValue **val) { - Closure *f; - if (!ttisfunction(fi)) return NULL; - f = clvalue(fi); - if (f->c.isC) { - if (!(1 <= n && n <= f->c.nupvalues)) return NULL; - *val = &f->c.upvalue[n-1]; - return ""; - } - else { - Proto *p = f->l.p; - if (!(1 <= n && n <= p->sizeupvalues)) return NULL; - *val = f->l.upvals[n-1]->v; - return getstr(p->upvalues[n-1]); - } -} - - -LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { - const char *name; - TValue *val; - lua_lock(L); - name = aux_upvalue(index2adr(L, funcindex), n, &val); - if (name) { - setobj2s(L, L->top, val); - api_incr_top(L); - } - lua_unlock(L); - return name; -} - - -LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { - const char *name; - TValue *val; - StkId fi; - lua_lock(L); - fi = index2adr(L, funcindex); - api_checknelems(L, 1); - name = aux_upvalue(fi, n, &val); - if (name) { - L->top--; - setobj(L, val, L->top); - luaC_barrier(L, clvalue(fi), L->top); - } - lua_unlock(L); - return name; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lauxlib.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lauxlib.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lauxlib.h @@ -1,174 +0,0 @@ -/* -** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ -** Auxiliary functions for building Lua libraries -** See Copyright Notice in lua.h -*/ - - -#ifndef lauxlib_h -#define lauxlib_h - - -#include -#include - -#include "lua.h" - - -#if defined(LUA_COMPAT_GETN) -LUALIB_API int (luaL_getn) (lua_State *L, int t); -LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); -#else -#define luaL_getn(L,i) ((int)lua_objlen(L, i)) -#define luaL_setn(L,i,j) ((void)0) /* no op! */ -#endif - -#if defined(LUA_COMPAT_OPENLIB) -#define luaI_openlib luaL_openlib -#endif - - -/* extra error code for `luaL_load' */ -#define LUA_ERRFILE (LUA_ERRERR+1) - - -typedef struct luaL_Reg { - const char *name; - lua_CFunction func; -} luaL_Reg; - - - -LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, - const luaL_Reg *l, int nup); -LUALIB_API void (luaL_register) (lua_State *L, const char *libname, - const luaL_Reg *l); -LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); -LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); -LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); -LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); -LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, - size_t *l); -LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, - const char *def, size_t *l); -LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); -LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); - -LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); -LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, - lua_Integer def); - -LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); -LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); -LUALIB_API void (luaL_checkany) (lua_State *L, int narg); - -LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); -LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); - -LUALIB_API void (luaL_where) (lua_State *L, int lvl); -LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); - -LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, - const char *const lst[]); - -LUALIB_API int (luaL_ref) (lua_State *L, int t); -LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); - -LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); -LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, - const char *name); -LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); - -LUALIB_API lua_State *(luaL_newstate) (void); - - -LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, - const char *r); - -LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, - const char *fname, int szhint); - - - - -/* -** =============================================================== -** some useful macros -** =============================================================== -*/ - -#define luaL_argcheck(L, cond,numarg,extramsg) \ - ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) -#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) -#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) -#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) -#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) -#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) -#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) - -#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) - -#define luaL_dofile(L, fn) \ - (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) - -#define luaL_dostring(L, s) \ - (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) - -#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) - -#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) - -/* -** {====================================================== -** Generic Buffer manipulation -** ======================================================= -*/ - - - -typedef struct luaL_Buffer { - char *p; /* current position in buffer */ - int lvl; /* number of strings in the stack (level) */ - lua_State *L; - char buffer[LUAL_BUFFERSIZE]; -} luaL_Buffer; - -#define luaL_addchar(B,c) \ - ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ - (*(B)->p++ = (char)(c))) - -/* compatibility only */ -#define luaL_putchar(B,c) luaL_addchar(B,c) - -#define luaL_addsize(B,n) ((B)->p += (n)) - -LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); -LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); -LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); -LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); -LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); -LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); - - -/* }====================================================== */ - - -/* compatibility with ref system */ - -/* pre-defined references */ -#define LUA_NOREF (-2) -#define LUA_REFNIL (-1) - -#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ - (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) - -#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) - -#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) - - -#define luaL_reg luaL_Reg - -#endif - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lauxlib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lauxlib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lauxlib.c @@ -1,652 +0,0 @@ -/* -** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $ -** Auxiliary functions for building Lua libraries -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include -#include -#include -#include - - -/* This file uses only the official API of Lua. -** Any function declared here could be written as an application function. -*/ - -#define lauxlib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" - - -#define FREELIST_REF 0 /* free list of references */ - - -/* convert a stack index to positive */ -#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ - lua_gettop(L) + (i) + 1) - - -/* -** {====================================================== -** Error-report functions -** ======================================================= -*/ - - -LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { - lua_Debug ar; - if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ - return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); - lua_getinfo(L, "n", &ar); - if (strcmp(ar.namewhat, "method") == 0) { - narg--; /* do not count `self' */ - if (narg == 0) /* error is in the self argument itself? */ - return luaL_error(L, "calling " LUA_QS " on bad self (%s)", - ar.name, extramsg); - } - if (ar.name == NULL) - ar.name = "?"; - return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", - narg, ar.name, extramsg); -} - - -LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { - const char *msg = lua_pushfstring(L, "%s expected, got %s", - tname, luaL_typename(L, narg)); - return luaL_argerror(L, narg, msg); -} - - -static void tag_error (lua_State *L, int narg, int tag) { - luaL_typerror(L, narg, lua_typename(L, tag)); -} - - -LUALIB_API void luaL_where (lua_State *L, int level) { - lua_Debug ar; - if (lua_getstack(L, level, &ar)) { /* check function at level */ - lua_getinfo(L, "Sl", &ar); /* get info about it */ - if (ar.currentline > 0) { /* is there info? */ - lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); - return; - } - } - lua_pushliteral(L, ""); /* else, no information available... */ -} - - -LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { - va_list argp; - va_start(argp, fmt); - luaL_where(L, 1); - lua_pushvfstring(L, fmt, argp); - va_end(argp); - lua_concat(L, 2); - return lua_error(L); -} - -/* }====================================================== */ - - -LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, - const char *const lst[]) { - const char *name = (def) ? luaL_optstring(L, narg, def) : - luaL_checkstring(L, narg); - int i; - for (i=0; lst[i]; i++) - if (strcmp(lst[i], name) == 0) - return i; - return luaL_argerror(L, narg, - lua_pushfstring(L, "invalid option " LUA_QS, name)); -} - - -LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { - lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ - if (!lua_isnil(L, -1)) /* name already in use? */ - return 0; /* leave previous value on top, but return 0 */ - lua_pop(L, 1); - lua_newtable(L); /* create metatable */ - lua_pushvalue(L, -1); - lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ - return 1; -} - - -LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { - void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ - lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ - lua_pop(L, 2); /* remove both metatables */ - return p; - } - } - } - luaL_typerror(L, ud, tname); /* else error */ - return NULL; /* to avoid warnings */ -} - - -LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { - if (!lua_checkstack(L, space)) - luaL_error(L, "stack overflow (%s)", mes); -} - - -LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { - if (lua_type(L, narg) != t) - tag_error(L, narg, t); -} - - -LUALIB_API void luaL_checkany (lua_State *L, int narg) { - if (lua_type(L, narg) == LUA_TNONE) - luaL_argerror(L, narg, "value expected"); -} - - -LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { - const char *s = lua_tolstring(L, narg, len); - if (!s) tag_error(L, narg, LUA_TSTRING); - return s; -} - - -LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, - const char *def, size_t *len) { - if (lua_isnoneornil(L, narg)) { - if (len) - *len = (def ? strlen(def) : 0); - return def; - } - else return luaL_checklstring(L, narg, len); -} - - -LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { - lua_Number d = lua_tonumber(L, narg); - if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ - tag_error(L, narg, LUA_TNUMBER); - return d; -} - - -LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { - return luaL_opt(L, luaL_checknumber, narg, def); -} - - -LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { - lua_Integer d = lua_tointeger(L, narg); - if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ - tag_error(L, narg, LUA_TNUMBER); - return d; -} - - -LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, - lua_Integer def) { - return luaL_opt(L, luaL_checkinteger, narg, def); -} - - -LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { - if (!lua_getmetatable(L, obj)) /* no metatable? */ - return 0; - lua_pushstring(L, event); - lua_rawget(L, -2); - if (lua_isnil(L, -1)) { - lua_pop(L, 2); /* remove metatable and metafield */ - return 0; - } - else { - lua_remove(L, -2); /* remove only metatable */ - return 1; - } -} - - -LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { - obj = abs_index(L, obj); - if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ - return 0; - lua_pushvalue(L, obj); - lua_call(L, 1, 1); - return 1; -} - - -LUALIB_API void (luaL_register) (lua_State *L, const char *libname, - const luaL_Reg *l) { - luaI_openlib(L, libname, l, 0); -} - - -static int libsize (const luaL_Reg *l) { - int size = 0; - for (; l->name; l++) size++; - return size; -} - - -LUALIB_API void luaI_openlib (lua_State *L, const char *libname, - const luaL_Reg *l, int nup) { - if (libname) { - int size = libsize(l); - /* check whether lib already exists */ - luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); - lua_getfield(L, -1, libname); /* get _LOADED[libname] */ - if (!lua_istable(L, -1)) { /* not found? */ - lua_pop(L, 1); /* remove previous result */ - /* try global variable (and create one if it does not exist) */ - if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL) - luaL_error(L, "name conflict for module " LUA_QS, libname); - lua_pushvalue(L, -1); - lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ - } - lua_remove(L, -2); /* remove _LOADED table */ - lua_insert(L, -(nup+1)); /* move library table to below upvalues */ - } - for (; l->name; l++) { - int i; - for (i=0; ifunc, nup); - lua_setfield(L, -(nup+2), l->name); - } - lua_pop(L, nup); /* remove upvalues */ -} - - - -/* -** {====================================================== -** getn-setn: size for arrays -** ======================================================= -*/ - -#if defined(LUA_COMPAT_GETN) - -static int checkint (lua_State *L, int topop) { - int n = (lua_type(L, -1) == LUA_TNUMBER) ? lua_tointeger(L, -1) : -1; - lua_pop(L, topop); - return n; -} - - -static void getsizes (lua_State *L) { - lua_getfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); - if (lua_isnil(L, -1)) { /* no `size' table? */ - lua_pop(L, 1); /* remove nil */ - lua_newtable(L); /* create it */ - lua_pushvalue(L, -1); /* `size' will be its own metatable */ - lua_setmetatable(L, -2); - lua_pushliteral(L, "kv"); - lua_setfield(L, -2, "__mode"); /* metatable(N).__mode = "kv" */ - lua_pushvalue(L, -1); - lua_setfield(L, LUA_REGISTRYINDEX, "LUA_SIZES"); /* store in register */ - } -} - - -LUALIB_API void luaL_setn (lua_State *L, int t, int n) { - t = abs_index(L, t); - lua_pushliteral(L, "n"); - lua_rawget(L, t); - if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ - lua_pushliteral(L, "n"); /* use it */ - lua_pushinteger(L, n); - lua_rawset(L, t); - } - else { /* use `sizes' */ - getsizes(L); - lua_pushvalue(L, t); - lua_pushinteger(L, n); - lua_rawset(L, -3); /* sizes[t] = n */ - lua_pop(L, 1); /* remove `sizes' */ - } -} - - -LUALIB_API int luaL_getn (lua_State *L, int t) { - int n; - t = abs_index(L, t); - lua_pushliteral(L, "n"); /* try t.n */ - lua_rawget(L, t); - if ((n = checkint(L, 1)) >= 0) return n; - getsizes(L); /* else try sizes[t] */ - lua_pushvalue(L, t); - lua_rawget(L, -2); - if ((n = checkint(L, 2)) >= 0) return n; - return (int)lua_objlen(L, t); -} - -#endif - -/* }====================================================== */ - - - -LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, - const char *r) { - const char *wild; - size_t l = strlen(p); - luaL_Buffer b; - luaL_buffinit(L, &b); - while ((wild = strstr(s, p)) != NULL) { - luaL_addlstring(&b, s, wild - s); /* push prefix */ - luaL_addstring(&b, r); /* push replacement in place of pattern */ - s = wild + l; /* continue after `p' */ - } - luaL_addstring(&b, s); /* push last suffix */ - luaL_pushresult(&b); - return lua_tostring(L, -1); -} - - -LUALIB_API const char *luaL_findtable (lua_State *L, int idx, - const char *fname, int szhint) { - const char *e; - lua_pushvalue(L, idx); - do { - e = strchr(fname, '.'); - if (e == NULL) e = fname + strlen(fname); - lua_pushlstring(L, fname, e - fname); - lua_rawget(L, -2); - if (lua_isnil(L, -1)) { /* no such field? */ - lua_pop(L, 1); /* remove this nil */ - lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ - lua_pushlstring(L, fname, e - fname); - lua_pushvalue(L, -2); - lua_settable(L, -4); /* set new table into field */ - } - else if (!lua_istable(L, -1)) { /* field has a non-table value? */ - lua_pop(L, 2); /* remove table and value */ - return fname; /* return problematic part of the name */ - } - lua_remove(L, -2); /* remove previous table */ - fname = e + 1; - } while (*e == '.'); - return NULL; -} - - - -/* -** {====================================================== -** Generic Buffer manipulation -** ======================================================= -*/ - - -#define bufflen(B) ((B)->p - (B)->buffer) -#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B))) - -#define LIMIT (LUA_MINSTACK/2) - - -static int emptybuffer (luaL_Buffer *B) { - size_t l = bufflen(B); - if (l == 0) return 0; /* put nothing on stack */ - else { - lua_pushlstring(B->L, B->buffer, l); - B->p = B->buffer; - B->lvl++; - return 1; - } -} - - -static void adjuststack (luaL_Buffer *B) { - if (B->lvl > 1) { - lua_State *L = B->L; - int toget = 1; /* number of levels to concat */ - size_t toplen = lua_strlen(L, -1); - do { - size_t l = lua_strlen(L, -(toget+1)); - if (B->lvl - toget + 1 >= LIMIT || toplen > l) { - toplen += l; - toget++; - } - else break; - } while (toget < B->lvl); - lua_concat(L, toget); - B->lvl = B->lvl - toget + 1; - } -} - - -LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { - if (emptybuffer(B)) - adjuststack(B); - return B->buffer; -} - - -LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { - while (l--) - luaL_addchar(B, *s++); -} - - -LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { - luaL_addlstring(B, s, strlen(s)); -} - - -LUALIB_API void luaL_pushresult (luaL_Buffer *B) { - emptybuffer(B); - lua_concat(B->L, B->lvl); - B->lvl = 1; -} - - -LUALIB_API void luaL_addvalue (luaL_Buffer *B) { - lua_State *L = B->L; - size_t vl; - const char *s = lua_tolstring(L, -1, &vl); - if (vl <= bufffree(B)) { /* fit into buffer? */ - memcpy(B->p, s, vl); /* put it there */ - B->p += vl; - lua_pop(L, 1); /* remove from stack */ - } - else { - if (emptybuffer(B)) - lua_insert(L, -2); /* put buffer before new value */ - B->lvl++; /* add new value into B stack */ - adjuststack(B); - } -} - - -LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { - B->L = L; - B->p = B->buffer; - B->lvl = 0; -} - -/* }====================================================== */ - - -LUALIB_API int luaL_ref (lua_State *L, int t) { - int ref; - t = abs_index(L, t); - if (lua_isnil(L, -1)) { - lua_pop(L, 1); /* remove from stack */ - return LUA_REFNIL; /* `nil' has a unique fixed reference */ - } - lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ - ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */ - lua_pop(L, 1); /* remove it from stack */ - if (ref != 0) { /* any free element? */ - lua_rawgeti(L, t, ref); /* remove it from list */ - lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ - } - else { /* no free elements */ - ref = (int)lua_objlen(L, t); - ref++; /* create new reference */ - } - lua_rawseti(L, t, ref); - return ref; -} - - -LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { - if (ref >= 0) { - t = abs_index(L, t); - lua_rawgeti(L, t, FREELIST_REF); - lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ - lua_pushinteger(L, ref); - lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ - } -} - - - -/* -** {====================================================== -** Load functions -** ======================================================= -*/ - -typedef struct LoadF { - int extraline; - FILE *f; - char buff[LUAL_BUFFERSIZE]; -} LoadF; - - -static const char *getF (lua_State *L, void *ud, size_t *size) { - LoadF *lf = (LoadF *)ud; - (void)L; - if (lf->extraline) { - lf->extraline = 0; - *size = 1; - return "\n"; - } - if (feof(lf->f)) return NULL; - *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); - return (*size > 0) ? lf->buff : NULL; -} - - -static int errfile (lua_State *L, const char *what, int fnameindex) { - const char *serr = strerror(errno); - const char *filename = lua_tostring(L, fnameindex) + 1; - lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); - lua_remove(L, fnameindex); - return LUA_ERRFILE; -} - - -LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { - LoadF lf; - int status, readstatus; - int c; - int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ - lf.extraline = 0; - if (filename == NULL) { - lua_pushliteral(L, "=stdin"); - lf.f = stdin; - } - else { - lua_pushfstring(L, "@%s", filename); - lf.f = fopen(filename, "r"); - if (lf.f == NULL) return errfile(L, "open", fnameindex); - } - c = getc(lf.f); - if (c == '#') { /* Unix exec. file? */ - lf.extraline = 1; - while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */ - if (c == '\n') c = getc(lf.f); - } - if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ - lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ - if (lf.f == NULL) return errfile(L, "reopen", fnameindex); - /* skip eventual `#!...' */ - while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; - lf.extraline = 0; - } - ungetc(c, lf.f); - status = lua_load(L, getF, &lf, lua_tostring(L, -1)); - readstatus = ferror(lf.f); - if (filename) fclose(lf.f); /* close file (even in case of errors) */ - if (readstatus) { - lua_settop(L, fnameindex); /* ignore results from `lua_load' */ - return errfile(L, "read", fnameindex); - } - lua_remove(L, fnameindex); - return status; -} - - -typedef struct LoadS { - const char *s; - size_t size; -} LoadS; - - -static const char *getS (lua_State *L, void *ud, size_t *size) { - LoadS *ls = (LoadS *)ud; - (void)L; - if (ls->size == 0) return NULL; - *size = ls->size; - ls->size = 0; - return ls->s; -} - - -LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t size, - const char *name) { - LoadS ls; - ls.s = buff; - ls.size = size; - return lua_load(L, getS, &ls, name); -} - - -LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { - return luaL_loadbuffer(L, s, strlen(s), s); -} - - - -/* }====================================================== */ - - -static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { - (void)ud; - (void)osize; - if (nsize == 0) { - free(ptr); - return NULL; - } - else - return realloc(ptr, nsize); -} - - -static int panic (lua_State *L) { - (void)L; /* to avoid warnings */ - fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", - lua_tostring(L, -1)); - return 0; -} - - -LUALIB_API lua_State *luaL_newstate (void) { - lua_State *L = lua_newstate(l_alloc, NULL); - if (L) lua_atpanic(L, &panic); - return L; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lbaselib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lbaselib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lbaselib.c @@ -1,653 +0,0 @@ -/* -** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $ -** Basic library -** See Copyright Notice in lua.h -*/ - - - -#include -#include -#include -#include - -#define lbaselib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - - - -/* -** If your system does not support `stdout', you can just remove this function. -** If you need, you can define your own `print' function, following this -** model but changing `fputs' to put the strings at a proper place -** (a console window or a log file, for instance). -*/ -static int luaB_print (lua_State *L) { - int n = lua_gettop(L); /* number of arguments */ - int i; - lua_getglobal(L, "tostring"); - for (i=1; i<=n; i++) { - const char *s; - lua_pushvalue(L, -1); /* function to be called */ - lua_pushvalue(L, i); /* value to print */ - lua_call(L, 1, 1); - s = lua_tostring(L, -1); /* get result */ - if (s == NULL) - return luaL_error(L, LUA_QL("tostring") " must return a string to " - LUA_QL("print")); - if (i>1) fputs("\t", stdout); - fputs(s, stdout); - lua_pop(L, 1); /* pop result */ - } - fputs("\n", stdout); - return 0; -} - - -static int luaB_tonumber (lua_State *L) { - int base = luaL_optint(L, 2, 10); - if (base == 10) { /* standard conversion */ - luaL_checkany(L, 1); - if (lua_isnumber(L, 1)) { - lua_pushnumber(L, lua_tonumber(L, 1)); - return 1; - } - } - else { - const char *s1 = luaL_checkstring(L, 1); - char *s2; - unsigned long n; - luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); - n = strtoul(s1, &s2, base); - if (s1 != s2) { /* at least one valid digit? */ - while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ - if (*s2 == '\0') { /* no invalid trailing characters? */ - lua_pushnumber(L, (lua_Number)n); - return 1; - } - } - } - lua_pushnil(L); /* else not a number */ - return 1; -} - - -static int luaB_error (lua_State *L) { - int level = luaL_optint(L, 2, 1); - lua_settop(L, 1); - if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ - luaL_where(L, level); - lua_pushvalue(L, 1); - lua_concat(L, 2); - } - return lua_error(L); -} - - -static int luaB_getmetatable (lua_State *L) { - luaL_checkany(L, 1); - if (!lua_getmetatable(L, 1)) { - lua_pushnil(L); - return 1; /* no metatable */ - } - luaL_getmetafield(L, 1, "__metatable"); - return 1; /* returns either __metatable field (if present) or metatable */ -} - - -static int luaB_setmetatable (lua_State *L) { - int t = lua_type(L, 2); - luaL_checktype(L, 1, LUA_TTABLE); - luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, - "nil or table expected"); - if (luaL_getmetafield(L, 1, "__metatable")) - luaL_error(L, "cannot change a protected metatable"); - lua_settop(L, 2); - lua_setmetatable(L, 1); - return 1; -} - - -static void getfunc (lua_State *L, int opt) { - if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); - else { - lua_Debug ar; - int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); - luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); - if (lua_getstack(L, level, &ar) == 0) - luaL_argerror(L, 1, "invalid level"); - lua_getinfo(L, "f", &ar); - if (lua_isnil(L, -1)) - luaL_error(L, "no function environment for tail call at level %d", - level); - } -} - - -static int luaB_getfenv (lua_State *L) { - getfunc(L, 1); - if (lua_iscfunction(L, -1)) /* is a C function? */ - lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ - else - lua_getfenv(L, -1); - return 1; -} - - -static int luaB_setfenv (lua_State *L) { - luaL_checktype(L, 2, LUA_TTABLE); - getfunc(L, 0); - lua_pushvalue(L, 2); - if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { - /* change environment of current thread */ - lua_pushthread(L); - lua_insert(L, -2); - lua_setfenv(L, -2); - return 0; - } - else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) - luaL_error(L, - LUA_QL("setfenv") " cannot change environment of given object"); - return 1; -} - - -static int luaB_rawequal (lua_State *L) { - luaL_checkany(L, 1); - luaL_checkany(L, 2); - lua_pushboolean(L, lua_rawequal(L, 1, 2)); - return 1; -} - - -static int luaB_rawget (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - luaL_checkany(L, 2); - lua_settop(L, 2); - lua_rawget(L, 1); - return 1; -} - -static int luaB_rawset (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - luaL_checkany(L, 2); - luaL_checkany(L, 3); - lua_settop(L, 3); - lua_rawset(L, 1); - return 1; -} - - -static int luaB_gcinfo (lua_State *L) { - lua_pushinteger(L, lua_getgccount(L)); - return 1; -} - - -static int luaB_collectgarbage (lua_State *L) { - static const char *const opts[] = {"stop", "restart", "collect", - "count", "step", "setpause", "setstepmul", NULL}; - static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, - LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL}; - int o = luaL_checkoption(L, 1, "collect", opts); - int ex = luaL_optint(L, 2, 0); - int res = lua_gc(L, optsnum[o], ex); - switch (optsnum[o]) { - case LUA_GCCOUNT: { - int b = lua_gc(L, LUA_GCCOUNTB, 0); - lua_pushnumber(L, res + ((lua_Number)b/1024)); - return 1; - } - case LUA_GCSTEP: { - lua_pushboolean(L, res); - return 1; - } - default: { - lua_pushnumber(L, res); - return 1; - } - } -} - - -static int luaB_type (lua_State *L) { - luaL_checkany(L, 1); - lua_pushstring(L, luaL_typename(L, 1)); - return 1; -} - - -static int luaB_next (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_settop(L, 2); /* create a 2nd argument if there isn't one */ - if (lua_next(L, 1)) - return 2; - else { - lua_pushnil(L); - return 1; - } -} - - -static int luaB_pairs (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ - lua_pushvalue(L, 1); /* state, */ - lua_pushnil(L); /* and initial value */ - return 3; -} - - -static int ipairsaux (lua_State *L) { - int i = luaL_checkint(L, 2); - luaL_checktype(L, 1, LUA_TTABLE); - i++; /* next value */ - lua_pushinteger(L, i); - lua_rawgeti(L, 1, i); - return (lua_isnil(L, -1)) ? 0 : 2; -} - - -static int luaB_ipairs (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ - lua_pushvalue(L, 1); /* state, */ - lua_pushinteger(L, 0); /* and initial value */ - return 3; -} - - -static int load_aux (lua_State *L, int status) { - if (status == 0) /* OK? */ - return 1; - else { - lua_pushnil(L); - lua_insert(L, -2); /* put before error message */ - return 2; /* return nil plus error message */ - } -} - - -static int luaB_loadstring (lua_State *L) { - size_t l; - const char *s = luaL_checklstring(L, 1, &l); - const char *chunkname = luaL_optstring(L, 2, s); - return load_aux(L, luaL_loadbuffer(L, s, l, chunkname)); -} - - -static int luaB_loadfile (lua_State *L) { - const char *fname = luaL_optstring(L, 1, NULL); - return load_aux(L, luaL_loadfile(L, fname)); -} - - -/* -** Reader for generic `load' function: `lua_load' uses the -** stack for internal stuff, so the reader cannot change the -** stack top. Instead, it keeps its resulting string in a -** reserved slot inside the stack. -*/ -static const char *generic_reader (lua_State *L, void *ud, size_t *size) { - (void)ud; /* to avoid warnings */ - luaL_checkstack(L, 2, "too many nested functions"); - lua_pushvalue(L, 1); /* get function */ - lua_call(L, 0, 1); /* call it */ - if (lua_isnil(L, -1)) { - *size = 0; - return NULL; - } - else if (lua_isstring(L, -1)) { - lua_replace(L, 3); /* save string in a reserved stack slot */ - return lua_tolstring(L, 3, size); - } - else luaL_error(L, "reader function must return a string"); - return NULL; /* to avoid warnings */ -} - - -static int luaB_load (lua_State *L) { - int status; - const char *cname = luaL_optstring(L, 2, "=(load)"); - luaL_checktype(L, 1, LUA_TFUNCTION); - lua_settop(L, 3); /* function, eventual name, plus one reserved slot */ - status = lua_load(L, generic_reader, NULL, cname); - return load_aux(L, status); -} - - -static int luaB_dofile (lua_State *L) { - const char *fname = luaL_optstring(L, 1, NULL); - int n = lua_gettop(L); - if (luaL_loadfile(L, fname) != 0) lua_error(L); - lua_call(L, 0, LUA_MULTRET); - return lua_gettop(L) - n; -} - - -static int luaB_assert (lua_State *L) { - luaL_checkany(L, 1); - if (!lua_toboolean(L, 1)) - return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); - return lua_gettop(L); -} - - -static int luaB_unpack (lua_State *L) { - int i, e, n; - luaL_checktype(L, 1, LUA_TTABLE); - i = luaL_optint(L, 2, 1); - e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); - if (i > e) return 0; /* empty range */ - n = e - i + 1; /* number of elements */ - if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ - return luaL_error(L, "too many results to unpack"); - lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ - while (i++ < e) /* push arg[i + 1...e] */ - lua_rawgeti(L, 1, i); - return n; -} - - -static int luaB_select (lua_State *L) { - int n = lua_gettop(L); - if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { - lua_pushinteger(L, n-1); - return 1; - } - else { - int i = luaL_checkint(L, 1); - if (i < 0) i = n + i; - else if (i > n) i = n; - luaL_argcheck(L, 1 <= i, 1, "index out of range"); - return n - i; - } -} - - -static int luaB_pcall (lua_State *L) { - int status; - luaL_checkany(L, 1); - status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); - lua_pushboolean(L, (status == 0)); - lua_insert(L, 1); - return lua_gettop(L); /* return status + all results */ -} - - -static int luaB_xpcall (lua_State *L) { - int status; - luaL_checkany(L, 2); - lua_settop(L, 2); - lua_insert(L, 1); /* put error function under function to be called */ - status = lua_pcall(L, 0, LUA_MULTRET, 1); - lua_pushboolean(L, (status == 0)); - lua_replace(L, 1); - return lua_gettop(L); /* return status + all results */ -} - - -static int luaB_tostring (lua_State *L) { - luaL_checkany(L, 1); - if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ - return 1; /* use its value */ - switch (lua_type(L, 1)) { - case LUA_TNUMBER: - lua_pushstring(L, lua_tostring(L, 1)); - break; - case LUA_TSTRING: - lua_pushvalue(L, 1); - break; - case LUA_TBOOLEAN: - lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); - break; - case LUA_TNIL: - lua_pushliteral(L, "nil"); - break; - default: - lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); - break; - } - return 1; -} - - -static int luaB_newproxy (lua_State *L) { - lua_settop(L, 1); - lua_newuserdata(L, 0); /* create proxy */ - if (lua_toboolean(L, 1) == 0) - return 1; /* no metatable */ - else if (lua_isboolean(L, 1)) { - lua_newtable(L); /* create a new metatable `m' ... */ - lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ - lua_pushboolean(L, 1); - lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */ - } - else { - int validproxy = 0; /* to check if weaktable[metatable(u)] == true */ - if (lua_getmetatable(L, 1)) { - lua_rawget(L, lua_upvalueindex(1)); - validproxy = lua_toboolean(L, -1); - lua_pop(L, 1); /* remove value */ - } - luaL_argcheck(L, validproxy, 1, "boolean or proxy expected"); - lua_getmetatable(L, 1); /* metatable is valid; get it */ - } - lua_setmetatable(L, 2); - return 1; -} - - -static const luaL_Reg base_funcs[] = { - {"assert", luaB_assert}, - {"collectgarbage", luaB_collectgarbage}, - {"dofile", luaB_dofile}, - {"error", luaB_error}, - {"gcinfo", luaB_gcinfo}, - {"getfenv", luaB_getfenv}, - {"getmetatable", luaB_getmetatable}, - {"loadfile", luaB_loadfile}, - {"load", luaB_load}, - {"loadstring", luaB_loadstring}, - {"next", luaB_next}, - {"pcall", luaB_pcall}, - {"print", luaB_print}, - {"rawequal", luaB_rawequal}, - {"rawget", luaB_rawget}, - {"rawset", luaB_rawset}, - {"select", luaB_select}, - {"setfenv", luaB_setfenv}, - {"setmetatable", luaB_setmetatable}, - {"tonumber", luaB_tonumber}, - {"tostring", luaB_tostring}, - {"type", luaB_type}, - {"unpack", luaB_unpack}, - {"xpcall", luaB_xpcall}, - {NULL, NULL} -}; - - -/* -** {====================================================== -** Coroutine library -** ======================================================= -*/ - -#define CO_RUN 0 /* running */ -#define CO_SUS 1 /* suspended */ -#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */ -#define CO_DEAD 3 - -static const char *const statnames[] = - {"running", "suspended", "normal", "dead"}; - -static int costatus (lua_State *L, lua_State *co) { - if (L == co) return CO_RUN; - switch (lua_status(co)) { - case LUA_YIELD: - return CO_SUS; - case 0: { - lua_Debug ar; - if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ - return CO_NOR; /* it is running */ - else if (lua_gettop(co) == 0) - return CO_DEAD; - else - return CO_SUS; /* initial state */ - } - default: /* some error occured */ - return CO_DEAD; - } -} - - -static int luaB_costatus (lua_State *L) { - lua_State *co = lua_tothread(L, 1); - luaL_argcheck(L, co, 1, "coroutine expected"); - lua_pushstring(L, statnames[costatus(L, co)]); - return 1; -} - - -static int auxresume (lua_State *L, lua_State *co, int narg) { - int status = costatus(L, co); - if (!lua_checkstack(co, narg)) - luaL_error(L, "too many arguments to resume"); - if (status != CO_SUS) { - lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); - return -1; /* error flag */ - } - lua_xmove(L, co, narg); - lua_setlevel(L, co); - status = lua_resume(co, narg); - if (status == 0 || status == LUA_YIELD) { - int nres = lua_gettop(co); - if (!lua_checkstack(L, nres + 1)) - luaL_error(L, "too many results to resume"); - lua_xmove(co, L, nres); /* move yielded values */ - return nres; - } - else { - lua_xmove(co, L, 1); /* move error message */ - return -1; /* error flag */ - } -} - - -static int luaB_coresume (lua_State *L) { - lua_State *co = lua_tothread(L, 1); - int r; - luaL_argcheck(L, co, 1, "coroutine expected"); - r = auxresume(L, co, lua_gettop(L) - 1); - if (r < 0) { - lua_pushboolean(L, 0); - lua_insert(L, -2); - return 2; /* return false + error message */ - } - else { - lua_pushboolean(L, 1); - lua_insert(L, -(r + 1)); - return r + 1; /* return true + `resume' returns */ - } -} - - -static int luaB_auxwrap (lua_State *L) { - lua_State *co = lua_tothread(L, lua_upvalueindex(1)); - int r = auxresume(L, co, lua_gettop(L)); - if (r < 0) { - if (lua_isstring(L, -1)) { /* error object is a string? */ - luaL_where(L, 1); /* add extra info */ - lua_insert(L, -2); - lua_concat(L, 2); - } - lua_error(L); /* propagate error */ - } - return r; -} - - -static int luaB_cocreate (lua_State *L) { - lua_State *NL = lua_newthread(L); - luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, - "Lua function expected"); - lua_pushvalue(L, 1); /* move function to top */ - lua_xmove(L, NL, 1); /* move function from L to NL */ - return 1; -} - - -static int luaB_cowrap (lua_State *L) { - luaB_cocreate(L); - lua_pushcclosure(L, luaB_auxwrap, 1); - return 1; -} - - -static int luaB_yield (lua_State *L) { - return lua_yield(L, lua_gettop(L)); -} - - -static int luaB_corunning (lua_State *L) { - if (lua_pushthread(L)) - lua_pushnil(L); /* main thread is not a coroutine */ - return 1; -} - - -static const luaL_Reg co_funcs[] = { - {"create", luaB_cocreate}, - {"resume", luaB_coresume}, - {"running", luaB_corunning}, - {"status", luaB_costatus}, - {"wrap", luaB_cowrap}, - {"yield", luaB_yield}, - {NULL, NULL} -}; - -/* }====================================================== */ - - -static void auxopen (lua_State *L, const char *name, - lua_CFunction f, lua_CFunction u) { - lua_pushcfunction(L, u); - lua_pushcclosure(L, f, 1); - lua_setfield(L, -2, name); -} - - -static void base_open (lua_State *L) { - /* set global _G */ - lua_pushvalue(L, LUA_GLOBALSINDEX); - lua_setglobal(L, "_G"); - /* open lib into global table */ - luaL_register(L, "_G", base_funcs); - lua_pushliteral(L, LUA_VERSION); - lua_setglobal(L, "_VERSION"); /* set global _VERSION */ - /* `ipairs' and `pairs' need auxliliary functions as upvalues */ - auxopen(L, "ipairs", luaB_ipairs, ipairsaux); - auxopen(L, "pairs", luaB_pairs, luaB_next); - /* `newproxy' needs a weaktable as upvalue */ - lua_createtable(L, 0, 1); /* new table `w' */ - lua_pushvalue(L, -1); /* `w' will be its own metatable */ - lua_setmetatable(L, -2); - lua_pushliteral(L, "kv"); - lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ - lua_pushcclosure(L, luaB_newproxy, 1); - lua_setglobal(L, "newproxy"); /* set global `newproxy' */ -} - - -LUALIB_API int luaopen_base (lua_State *L) { - base_open(L); - luaL_register(L, LUA_COLIBNAME, co_funcs); - return 2; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lcode.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lcode.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lcode.h @@ -1,76 +0,0 @@ -/* -** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ -** Code generator for Lua -** See Copyright Notice in lua.h -*/ - -#ifndef lcode_h -#define lcode_h - -#include "llex.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lparser.h" - - -/* -** Marks the end of a patch list. It is an invalid value both as an absolute -** address, and as a list link (would link an element to itself). -*/ -#define NO_JUMP (-1) - - -/* -** grep "ORDER OPR" if you change these enums -*/ -typedef enum BinOpr { - OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, - OPR_CONCAT, - OPR_NE, OPR_EQ, - OPR_LT, OPR_LE, OPR_GT, OPR_GE, - OPR_AND, OPR_OR, - OPR_NOBINOPR -} BinOpr; - - -typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; - - -#define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) - -#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) - -#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) - -LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); -LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); -LUAI_FUNC void luaK_fixline (FuncState *fs, int line); -LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); -LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); -LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); -LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); -LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); -LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); -LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); -LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); -LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); -LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); -LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); -LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); -LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); -LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); -LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); -LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); -LUAI_FUNC int luaK_jump (FuncState *fs); -LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); -LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); -LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); -LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); -LUAI_FUNC int luaK_getlabel (FuncState *fs); -LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); -LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); -LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); -LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lcode.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lcode.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lcode.c @@ -1,839 +0,0 @@ -/* -** $Id: lcode.c,v 2.25.1.3 2007/12/28 15:32:23 roberto Exp $ -** Code generator for Lua -** See Copyright Notice in lua.h -*/ - - -#include - -#define lcode_c -#define LUA_CORE - -#include "lua.h" - -#include "lcode.h" -#include "ldebug.h" -#include "ldo.h" -#include "lgc.h" -#include "llex.h" -#include "lmem.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lparser.h" -#include "ltable.h" - - -#define hasjumps(e) ((e)->t != (e)->f) - - -static int isnumeral(expdesc *e) { - return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP); -} - - -void luaK_nil (FuncState *fs, int from, int n) { - Instruction *previous; - if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ - if (fs->pc == 0) { /* function start? */ - if (from >= fs->nactvar) - return; /* positions are already clean */ - } - else { - previous = &fs->f->code[fs->pc-1]; - if (GET_OPCODE(*previous) == OP_LOADNIL) { - int pfrom = GETARG_A(*previous); - int pto = GETARG_B(*previous); - if (pfrom <= from && from <= pto+1) { /* can connect both? */ - if (from+n-1 > pto) - SETARG_B(*previous, from+n-1); - return; - } - } - } - } - luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ -} - - -int luaK_jump (FuncState *fs) { - int jpc = fs->jpc; /* save list of jumps to here */ - int j; - fs->jpc = NO_JUMP; - j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP); - luaK_concat(fs, &j, jpc); /* keep them on hold */ - return j; -} - - -void luaK_ret (FuncState *fs, int first, int nret) { - luaK_codeABC(fs, OP_RETURN, first, nret+1, 0); -} - - -static int condjump (FuncState *fs, OpCode op, int A, int B, int C) { - luaK_codeABC(fs, op, A, B, C); - return luaK_jump(fs); -} - - -static void fixjump (FuncState *fs, int pc, int dest) { - Instruction *jmp = &fs->f->code[pc]; - int offset = dest-(pc+1); - lua_assert(dest != NO_JUMP); - if (abs(offset) > MAXARG_sBx) - luaX_syntaxerror(fs->ls, "control structure too long"); - SETARG_sBx(*jmp, offset); -} - - -/* -** returns current `pc' and marks it as a jump target (to avoid wrong -** optimizations with consecutive instructions not in the same basic block). -*/ -int luaK_getlabel (FuncState *fs) { - fs->lasttarget = fs->pc; - return fs->pc; -} - - -static int getjump (FuncState *fs, int pc) { - int offset = GETARG_sBx(fs->f->code[pc]); - if (offset == NO_JUMP) /* point to itself represents end of list */ - return NO_JUMP; /* end of list */ - else - return (pc+1)+offset; /* turn offset into absolute position */ -} - - -static Instruction *getjumpcontrol (FuncState *fs, int pc) { - Instruction *pi = &fs->f->code[pc]; - if (pc >= 1 && testTMode(GET_OPCODE(*(pi-1)))) - return pi-1; - else - return pi; -} - - -/* -** check whether list has any jump that do not produce a value -** (or produce an inverted value) -*/ -static int need_value (FuncState *fs, int list) { - for (; list != NO_JUMP; list = getjump(fs, list)) { - Instruction i = *getjumpcontrol(fs, list); - if (GET_OPCODE(i) != OP_TESTSET) return 1; - } - return 0; /* not found */ -} - - -static int patchtestreg (FuncState *fs, int node, int reg) { - Instruction *i = getjumpcontrol(fs, node); - if (GET_OPCODE(*i) != OP_TESTSET) - return 0; /* cannot patch other instructions */ - if (reg != NO_REG && reg != GETARG_B(*i)) - SETARG_A(*i, reg); - else /* no register to put value or register already has the value */ - *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); - - return 1; -} - - -static void removevalues (FuncState *fs, int list) { - for (; list != NO_JUMP; list = getjump(fs, list)) - patchtestreg(fs, list, NO_REG); -} - - -static void patchlistaux (FuncState *fs, int list, int vtarget, int reg, - int dtarget) { - while (list != NO_JUMP) { - int next = getjump(fs, list); - if (patchtestreg(fs, list, reg)) - fixjump(fs, list, vtarget); - else - fixjump(fs, list, dtarget); /* jump to default target */ - list = next; - } -} - - -static void dischargejpc (FuncState *fs) { - patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc); - fs->jpc = NO_JUMP; -} - - -void luaK_patchlist (FuncState *fs, int list, int target) { - if (target == fs->pc) - luaK_patchtohere(fs, list); - else { - lua_assert(target < fs->pc); - patchlistaux(fs, list, target, NO_REG, target); - } -} - - -void luaK_patchtohere (FuncState *fs, int list) { - luaK_getlabel(fs); - luaK_concat(fs, &fs->jpc, list); -} - - -void luaK_concat (FuncState *fs, int *l1, int l2) { - if (l2 == NO_JUMP) return; - else if (*l1 == NO_JUMP) - *l1 = l2; - else { - int list = *l1; - int next; - while ((next = getjump(fs, list)) != NO_JUMP) /* find last element */ - list = next; - fixjump(fs, list, l2); - } -} - - -void luaK_checkstack (FuncState *fs, int n) { - int newstack = fs->freereg + n; - if (newstack > fs->f->maxstacksize) { - if (newstack >= MAXSTACK) - luaX_syntaxerror(fs->ls, "function or expression too complex"); - fs->f->maxstacksize = cast_byte(newstack); - } -} - - -void luaK_reserveregs (FuncState *fs, int n) { - luaK_checkstack(fs, n); - fs->freereg += n; -} - - -static void freereg (FuncState *fs, int reg) { - if (!ISK(reg) && reg >= fs->nactvar) { - fs->freereg--; - lua_assert(reg == fs->freereg); - } -} - - -static void freeexp (FuncState *fs, expdesc *e) { - if (e->k == VNONRELOC) - freereg(fs, e->u.s.info); -} - - -static int addk (FuncState *fs, TValue *k, TValue *v) { - lua_State *L = fs->L; - TValue *idx = luaH_set(L, fs->h, k); - Proto *f = fs->f; - int oldsize = f->sizek; - if (ttisnumber(idx)) { - lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); - return cast_int(nvalue(idx)); - } - else { /* constant not found; create a new entry */ - setnvalue(idx, cast_num(fs->nk)); - luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, - MAXARG_Bx, "constant table overflow"); - while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); - setobj(L, &f->k[fs->nk], v); - luaC_barrier(L, f, v); - return fs->nk++; - } -} - - -int luaK_stringK (FuncState *fs, TString *s) { - TValue o; - setsvalue(fs->L, &o, s); - return addk(fs, &o, &o); -} - - -int luaK_numberK (FuncState *fs, lua_Number r) { - TValue o; - setnvalue(&o, r); - return addk(fs, &o, &o); -} - - -static int boolK (FuncState *fs, int b) { - TValue o; - setbvalue(&o, b); - return addk(fs, &o, &o); -} - - -static int nilK (FuncState *fs) { - TValue k, v; - setnilvalue(&v); - /* cannot use nil as key; instead use table itself to represent nil */ - sethvalue(fs->L, &k, fs->h); - return addk(fs, &k, &v); -} - - -void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { - if (e->k == VCALL) { /* expression is an open function call? */ - SETARG_C(getcode(fs, e), nresults+1); - } - else if (e->k == VVARARG) { - SETARG_B(getcode(fs, e), nresults+1); - SETARG_A(getcode(fs, e), fs->freereg); - luaK_reserveregs(fs, 1); - } -} - - -void luaK_setoneret (FuncState *fs, expdesc *e) { - if (e->k == VCALL) { /* expression is an open function call? */ - e->k = VNONRELOC; - e->u.s.info = GETARG_A(getcode(fs, e)); - } - else if (e->k == VVARARG) { - SETARG_B(getcode(fs, e), 2); - e->k = VRELOCABLE; /* can relocate its simple result */ - } -} - - -void luaK_dischargevars (FuncState *fs, expdesc *e) { - switch (e->k) { - case VLOCAL: { - e->k = VNONRELOC; - break; - } - case VUPVAL: { - e->u.s.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.s.info, 0); - e->k = VRELOCABLE; - break; - } - case VGLOBAL: { - e->u.s.info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->u.s.info); - e->k = VRELOCABLE; - break; - } - case VINDEXED: { - freereg(fs, e->u.s.aux); - freereg(fs, e->u.s.info); - e->u.s.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.s.info, e->u.s.aux); - e->k = VRELOCABLE; - break; - } - case VVARARG: - case VCALL: { - luaK_setoneret(fs, e); - break; - } - default: break; /* there is one value available (somewhere) */ - } -} - - -static int code_label (FuncState *fs, int A, int b, int jump) { - luaK_getlabel(fs); /* those instructions may be jump targets */ - return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump); -} - - -static void discharge2reg (FuncState *fs, expdesc *e, int reg) { - luaK_dischargevars(fs, e); - switch (e->k) { - case VNIL: { - luaK_nil(fs, reg, 1); - break; - } - case VFALSE: case VTRUE: { - luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0); - break; - } - case VK: { - luaK_codeABx(fs, OP_LOADK, reg, e->u.s.info); - break; - } - case VKNUM: { - luaK_codeABx(fs, OP_LOADK, reg, luaK_numberK(fs, e->u.nval)); - break; - } - case VRELOCABLE: { - Instruction *pc = &getcode(fs, e); - SETARG_A(*pc, reg); - break; - } - case VNONRELOC: { - if (reg != e->u.s.info) - luaK_codeABC(fs, OP_MOVE, reg, e->u.s.info, 0); - break; - } - default: { - lua_assert(e->k == VVOID || e->k == VJMP); - return; /* nothing to do... */ - } - } - e->u.s.info = reg; - e->k = VNONRELOC; -} - - -static void discharge2anyreg (FuncState *fs, expdesc *e) { - if (e->k != VNONRELOC) { - luaK_reserveregs(fs, 1); - discharge2reg(fs, e, fs->freereg-1); - } -} - - -static void exp2reg (FuncState *fs, expdesc *e, int reg) { - discharge2reg(fs, e, reg); - if (e->k == VJMP) - luaK_concat(fs, &e->t, e->u.s.info); /* put this jump in `t' list */ - if (hasjumps(e)) { - int final; /* position after whole expression */ - int p_f = NO_JUMP; /* position of an eventual LOAD false */ - int p_t = NO_JUMP; /* position of an eventual LOAD true */ - if (need_value(fs, e->t) || need_value(fs, e->f)) { - int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); - p_f = code_label(fs, reg, 0, 1); - p_t = code_label(fs, reg, 1, 0); - luaK_patchtohere(fs, fj); - } - final = luaK_getlabel(fs); - patchlistaux(fs, e->f, final, reg, p_f); - patchlistaux(fs, e->t, final, reg, p_t); - } - e->f = e->t = NO_JUMP; - e->u.s.info = reg; - e->k = VNONRELOC; -} - - -void luaK_exp2nextreg (FuncState *fs, expdesc *e) { - luaK_dischargevars(fs, e); - freeexp(fs, e); - luaK_reserveregs(fs, 1); - exp2reg(fs, e, fs->freereg - 1); -} - - -int luaK_exp2anyreg (FuncState *fs, expdesc *e) { - luaK_dischargevars(fs, e); - if (e->k == VNONRELOC) { - if (!hasjumps(e)) return e->u.s.info; /* exp is already in a register */ - if (e->u.s.info >= fs->nactvar) { /* reg. is not a local? */ - exp2reg(fs, e, e->u.s.info); /* put value on it */ - return e->u.s.info; - } - } - luaK_exp2nextreg(fs, e); /* default */ - return e->u.s.info; -} - - -void luaK_exp2val (FuncState *fs, expdesc *e) { - if (hasjumps(e)) - luaK_exp2anyreg(fs, e); - else - luaK_dischargevars(fs, e); -} - - -int luaK_exp2RK (FuncState *fs, expdesc *e) { - luaK_exp2val(fs, e); - switch (e->k) { - case VKNUM: - case VTRUE: - case VFALSE: - case VNIL: { - if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ - e->u.s.info = (e->k == VNIL) ? nilK(fs) : - (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : - boolK(fs, (e->k == VTRUE)); - e->k = VK; - return RKASK(e->u.s.info); - } - else break; - } - case VK: { - if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ - return RKASK(e->u.s.info); - else break; - } - default: break; - } - /* not a constant in the right range: put it in a register */ - return luaK_exp2anyreg(fs, e); -} - - -void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { - switch (var->k) { - case VLOCAL: { - freeexp(fs, ex); - exp2reg(fs, ex, var->u.s.info); - return; - } - case VUPVAL: { - int e = luaK_exp2anyreg(fs, ex); - luaK_codeABC(fs, OP_SETUPVAL, e, var->u.s.info, 0); - break; - } - case VGLOBAL: { - int e = luaK_exp2anyreg(fs, ex); - luaK_codeABx(fs, OP_SETGLOBAL, e, var->u.s.info); - break; - } - case VINDEXED: { - int e = luaK_exp2RK(fs, ex); - luaK_codeABC(fs, OP_SETTABLE, var->u.s.info, var->u.s.aux, e); - break; - } - default: { - lua_assert(0); /* invalid var kind to store */ - break; - } - } - freeexp(fs, ex); -} - - -void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { - int func; - luaK_exp2anyreg(fs, e); - freeexp(fs, e); - func = fs->freereg; - luaK_reserveregs(fs, 2); - luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key)); - freeexp(fs, key); - e->u.s.info = func; - e->k = VNONRELOC; -} - - -static void invertjump (FuncState *fs, expdesc *e) { - Instruction *pc = getjumpcontrol(fs, e->u.s.info); - lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && - GET_OPCODE(*pc) != OP_TEST); - SETARG_A(*pc, !(GETARG_A(*pc))); -} - - -static int jumponcond (FuncState *fs, expdesc *e, int cond) { - if (e->k == VRELOCABLE) { - Instruction ie = getcode(fs, e); - if (GET_OPCODE(ie) == OP_NOT) { - fs->pc--; /* remove previous OP_NOT */ - return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond); - } - /* else go through */ - } - discharge2anyreg(fs, e); - freeexp(fs, e); - return condjump(fs, OP_TESTSET, NO_REG, e->u.s.info, cond); -} - - -void luaK_goiftrue (FuncState *fs, expdesc *e) { - int pc; /* pc of last jump */ - luaK_dischargevars(fs, e); - switch (e->k) { - case VK: case VKNUM: case VTRUE: { - pc = NO_JUMP; /* always true; do nothing */ - break; - } - case VFALSE: { - pc = luaK_jump(fs); /* always jump */ - break; - } - case VJMP: { - invertjump(fs, e); - pc = e->u.s.info; - break; - } - default: { - pc = jumponcond(fs, e, 0); - break; - } - } - luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */ - luaK_patchtohere(fs, e->t); - e->t = NO_JUMP; -} - - -static void luaK_goiffalse (FuncState *fs, expdesc *e) { - int pc; /* pc of last jump */ - luaK_dischargevars(fs, e); - switch (e->k) { - case VNIL: case VFALSE: { - pc = NO_JUMP; /* always false; do nothing */ - break; - } - case VTRUE: { - pc = luaK_jump(fs); /* always jump */ - break; - } - case VJMP: { - pc = e->u.s.info; - break; - } - default: { - pc = jumponcond(fs, e, 1); - break; - } - } - luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */ - luaK_patchtohere(fs, e->f); - e->f = NO_JUMP; -} - - -static void codenot (FuncState *fs, expdesc *e) { - luaK_dischargevars(fs, e); - switch (e->k) { - case VNIL: case VFALSE: { - e->k = VTRUE; - break; - } - case VK: case VKNUM: case VTRUE: { - e->k = VFALSE; - break; - } - case VJMP: { - invertjump(fs, e); - break; - } - case VRELOCABLE: - case VNONRELOC: { - discharge2anyreg(fs, e); - freeexp(fs, e); - e->u.s.info = luaK_codeABC(fs, OP_NOT, 0, e->u.s.info, 0); - e->k = VRELOCABLE; - break; - } - default: { - lua_assert(0); /* cannot happen */ - break; - } - } - /* interchange true and false lists */ - { int temp = e->f; e->f = e->t; e->t = temp; } - removevalues(fs, e->f); - removevalues(fs, e->t); -} - - -void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { - t->u.s.aux = luaK_exp2RK(fs, k); - t->k = VINDEXED; -} - - -static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { - lua_Number v1, v2, r; - if (!isnumeral(e1) || !isnumeral(e2)) return 0; - v1 = e1->u.nval; - v2 = e2->u.nval; - switch (op) { - case OP_ADD: r = luai_numadd(v1, v2); break; - case OP_SUB: r = luai_numsub(v1, v2); break; - case OP_MUL: r = luai_nummul(v1, v2); break; - case OP_DIV: - if (v2 == 0) return 0; /* do not attempt to divide by 0 */ - r = luai_numdiv(v1, v2); break; - case OP_MOD: - if (v2 == 0) return 0; /* do not attempt to divide by 0 */ - r = luai_nummod(v1, v2); break; - case OP_POW: r = luai_numpow(v1, v2); break; - case OP_UNM: r = luai_numunm(v1); break; - case OP_LEN: return 0; /* no constant folding for 'len' */ - default: lua_assert(0); r = 0; break; - } - if (luai_numisnan(r)) return 0; /* do not attempt to produce NaN */ - e1->u.nval = r; - return 1; -} - - -static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { - if (constfolding(op, e1, e2)) - return; - else { - int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; - int o1 = luaK_exp2RK(fs, e1); - if (o1 > o2) { - freeexp(fs, e1); - freeexp(fs, e2); - } - else { - freeexp(fs, e2); - freeexp(fs, e1); - } - e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); - e1->k = VRELOCABLE; - } -} - - -static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, - expdesc *e2) { - int o1 = luaK_exp2RK(fs, e1); - int o2 = luaK_exp2RK(fs, e2); - freeexp(fs, e2); - freeexp(fs, e1); - if (cond == 0 && op != OP_EQ) { - int temp; /* exchange args to replace by `<' or `<=' */ - temp = o1; o1 = o2; o2 = temp; /* o1 <==> o2 */ - cond = 1; - } - e1->u.s.info = condjump(fs, op, cond, o1, o2); - e1->k = VJMP; -} - - -void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { - expdesc e2; - e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; - switch (op) { - case OPR_MINUS: { - if (!isnumeral(e)) - luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ - codearith(fs, OP_UNM, e, &e2); - break; - } - case OPR_NOT: codenot(fs, e); break; - case OPR_LEN: { - luaK_exp2anyreg(fs, e); /* cannot operate on constants */ - codearith(fs, OP_LEN, e, &e2); - break; - } - default: lua_assert(0); - } -} - - -void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { - switch (op) { - case OPR_AND: { - luaK_goiftrue(fs, v); - break; - } - case OPR_OR: { - luaK_goiffalse(fs, v); - break; - } - case OPR_CONCAT: { - luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ - break; - } - case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: - case OPR_MOD: case OPR_POW: { - if (!isnumeral(v)) luaK_exp2RK(fs, v); - break; - } - default: { - luaK_exp2RK(fs, v); - break; - } - } -} - - -void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { - switch (op) { - case OPR_AND: { - lua_assert(e1->t == NO_JUMP); /* list must be closed */ - luaK_dischargevars(fs, e2); - luaK_concat(fs, &e2->f, e1->f); - *e1 = *e2; - break; - } - case OPR_OR: { - lua_assert(e1->f == NO_JUMP); /* list must be closed */ - luaK_dischargevars(fs, e2); - luaK_concat(fs, &e2->t, e1->t); - *e1 = *e2; - break; - } - case OPR_CONCAT: { - luaK_exp2val(fs, e2); - if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) { - lua_assert(e1->u.s.info == GETARG_B(getcode(fs, e2))-1); - freeexp(fs, e1); - SETARG_B(getcode(fs, e2), e1->u.s.info); - e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; - } - else { - luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ - codearith(fs, OP_CONCAT, e1, e2); - } - break; - } - case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; - case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; - case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; - case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; - case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; - case OPR_POW: codearith(fs, OP_POW, e1, e2); break; - case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; - case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; - case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; - case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; - case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; - case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; - default: lua_assert(0); - } -} - - -void luaK_fixline (FuncState *fs, int line) { - fs->f->lineinfo[fs->pc - 1] = line; -} - - -static int luaK_code (FuncState *fs, Instruction i, int line) { - Proto *f = fs->f; - dischargejpc(fs); /* `pc' will change */ - /* put new instruction in code array */ - luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, - MAX_INT, "code size overflow"); - f->code[fs->pc] = i; - /* save corresponding line information */ - luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, - MAX_INT, "code size overflow"); - f->lineinfo[fs->pc] = line; - return fs->pc++; -} - - -int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) { - lua_assert(getOpMode(o) == iABC); - lua_assert(getBMode(o) != OpArgN || b == 0); - lua_assert(getCMode(o) != OpArgN || c == 0); - return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline); -} - - -int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) { - lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx); - lua_assert(getCMode(o) == OpArgN); - return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline); -} - - -void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { - int c = (nelems - 1)/LFIELDS_PER_FLUSH + 1; - int b = (tostore == LUA_MULTRET) ? 0 : tostore; - lua_assert(tostore != 0); - if (c <= MAXARG_C) - luaK_codeABC(fs, OP_SETLIST, base, b, c); - else { - luaK_codeABC(fs, OP_SETLIST, base, b, 0); - luaK_code(fs, cast(Instruction, c), fs->ls->lastline); - } - fs->freereg = base + 1; /* free registers with list values */ -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldblib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldblib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldblib.c @@ -1,397 +0,0 @@ -/* -** $Id: ldblib.c,v 1.104.1.3 2008/01/21 13:11:21 roberto Exp $ -** Interface from Lua to its debug API -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include - -#define ldblib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - - -static int db_getregistry (lua_State *L) { - lua_pushvalue(L, LUA_REGISTRYINDEX); - return 1; -} - - -static int db_getmetatable (lua_State *L) { - luaL_checkany(L, 1); - if (!lua_getmetatable(L, 1)) { - lua_pushnil(L); /* no metatable */ - } - return 1; -} - - -static int db_setmetatable (lua_State *L) { - int t = lua_type(L, 2); - luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, - "nil or table expected"); - lua_settop(L, 2); - lua_pushboolean(L, lua_setmetatable(L, 1)); - return 1; -} - - -static int db_getfenv (lua_State *L) { - lua_getfenv(L, 1); - return 1; -} - - -static int db_setfenv (lua_State *L) { - luaL_checktype(L, 2, LUA_TTABLE); - lua_settop(L, 2); - if (lua_setfenv(L, 1) == 0) - luaL_error(L, LUA_QL("setfenv") - " cannot change environment of given object"); - return 1; -} - - -static void settabss (lua_State *L, const char *i, const char *v) { - lua_pushstring(L, v); - lua_setfield(L, -2, i); -} - - -static void settabsi (lua_State *L, const char *i, int v) { - lua_pushinteger(L, v); - lua_setfield(L, -2, i); -} - - -static lua_State *getthread (lua_State *L, int *arg) { - if (lua_isthread(L, 1)) { - *arg = 1; - return lua_tothread(L, 1); - } - else { - *arg = 0; - return L; - } -} - - -static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { - if (L == L1) { - lua_pushvalue(L, -2); - lua_remove(L, -3); - } - else - lua_xmove(L1, L, 1); - lua_setfield(L, -2, fname); -} - - -static int db_getinfo (lua_State *L) { - lua_Debug ar; - int arg; - lua_State *L1 = getthread(L, &arg); - const char *options = luaL_optstring(L, arg+2, "flnSu"); - if (lua_isnumber(L, arg+1)) { - if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { - lua_pushnil(L); /* level out of range */ - return 1; - } - } - else if (lua_isfunction(L, arg+1)) { - lua_pushfstring(L, ">%s", options); - options = lua_tostring(L, -1); - lua_pushvalue(L, arg+1); - lua_xmove(L, L1, 1); - } - else - return luaL_argerror(L, arg+1, "function or level expected"); - if (!lua_getinfo(L1, options, &ar)) - return luaL_argerror(L, arg+2, "invalid option"); - lua_createtable(L, 0, 2); - if (strchr(options, 'S')) { - settabss(L, "source", ar.source); - settabss(L, "short_src", ar.short_src); - settabsi(L, "linedefined", ar.linedefined); - settabsi(L, "lastlinedefined", ar.lastlinedefined); - settabss(L, "what", ar.what); - } - if (strchr(options, 'l')) - settabsi(L, "currentline", ar.currentline); - if (strchr(options, 'u')) - settabsi(L, "nups", ar.nups); - if (strchr(options, 'n')) { - settabss(L, "name", ar.name); - settabss(L, "namewhat", ar.namewhat); - } - if (strchr(options, 'L')) - treatstackoption(L, L1, "activelines"); - if (strchr(options, 'f')) - treatstackoption(L, L1, "func"); - return 1; /* return table */ -} - - -static int db_getlocal (lua_State *L) { - int arg; - lua_State *L1 = getthread(L, &arg); - lua_Debug ar; - const char *name; - if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ - return luaL_argerror(L, arg+1, "level out of range"); - name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); - if (name) { - lua_xmove(L1, L, 1); - lua_pushstring(L, name); - lua_pushvalue(L, -2); - return 2; - } - else { - lua_pushnil(L); - return 1; - } -} - - -static int db_setlocal (lua_State *L) { - int arg; - lua_State *L1 = getthread(L, &arg); - lua_Debug ar; - if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ - return luaL_argerror(L, arg+1, "level out of range"); - luaL_checkany(L, arg+3); - lua_settop(L, arg+3); - lua_xmove(L, L1, 1); - lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); - return 1; -} - - -static int auxupvalue (lua_State *L, int get) { - const char *name; - int n = luaL_checkint(L, 2); - luaL_checktype(L, 1, LUA_TFUNCTION); - if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ - name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); - if (name == NULL) return 0; - lua_pushstring(L, name); - lua_insert(L, -(get+1)); - return get + 1; -} - - -static int db_getupvalue (lua_State *L) { - return auxupvalue(L, 1); -} - - -static int db_setupvalue (lua_State *L) { - luaL_checkany(L, 3); - return auxupvalue(L, 0); -} - - - -static const char KEY_HOOK = 'h'; - - -static void hookf (lua_State *L, lua_Debug *ar) { - static const char *const hooknames[] = - {"call", "return", "line", "count", "tail return"}; - lua_pushlightuserdata(L, (void *)&KEY_HOOK); - lua_rawget(L, LUA_REGISTRYINDEX); - lua_pushlightuserdata(L, L); - lua_rawget(L, -2); - if (lua_isfunction(L, -1)) { - lua_pushstring(L, hooknames[(int)ar->event]); - if (ar->currentline >= 0) - lua_pushinteger(L, ar->currentline); - else lua_pushnil(L); - lua_assert(lua_getinfo(L, "lS", ar)); - lua_call(L, 2, 0); - } -} - - -static int makemask (const char *smask, int count) { - int mask = 0; - if (strchr(smask, 'c')) mask |= LUA_MASKCALL; - if (strchr(smask, 'r')) mask |= LUA_MASKRET; - if (strchr(smask, 'l')) mask |= LUA_MASKLINE; - if (count > 0) mask |= LUA_MASKCOUNT; - return mask; -} - - -static char *unmakemask (int mask, char *smask) { - int i = 0; - if (mask & LUA_MASKCALL) smask[i++] = 'c'; - if (mask & LUA_MASKRET) smask[i++] = 'r'; - if (mask & LUA_MASKLINE) smask[i++] = 'l'; - smask[i] = '\0'; - return smask; -} - - -static void gethooktable (lua_State *L) { - lua_pushlightuserdata(L, (void *)&KEY_HOOK); - lua_rawget(L, LUA_REGISTRYINDEX); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - lua_createtable(L, 0, 1); - lua_pushlightuserdata(L, (void *)&KEY_HOOK); - lua_pushvalue(L, -2); - lua_rawset(L, LUA_REGISTRYINDEX); - } -} - - -static int db_sethook (lua_State *L) { - int arg, mask, count; - lua_Hook func; - lua_State *L1 = getthread(L, &arg); - if (lua_isnoneornil(L, arg+1)) { - lua_settop(L, arg+1); - func = NULL; mask = 0; count = 0; /* turn off hooks */ - } - else { - const char *smask = luaL_checkstring(L, arg+2); - luaL_checktype(L, arg+1, LUA_TFUNCTION); - count = luaL_optint(L, arg+3, 0); - func = hookf; mask = makemask(smask, count); - } - gethooktable(L); - lua_pushlightuserdata(L, L1); - lua_pushvalue(L, arg+1); - lua_rawset(L, -3); /* set new hook */ - lua_pop(L, 1); /* remove hook table */ - lua_sethook(L1, func, mask, count); /* set hooks */ - return 0; -} - - -static int db_gethook (lua_State *L) { - int arg; - lua_State *L1 = getthread(L, &arg); - char buff[5]; - int mask = lua_gethookmask(L1); - lua_Hook hook = lua_gethook(L1); - if (hook != NULL && hook != hookf) /* external hook? */ - lua_pushliteral(L, "external hook"); - else { - gethooktable(L); - lua_pushlightuserdata(L, L1); - lua_rawget(L, -2); /* get hook */ - lua_remove(L, -2); /* remove hook table */ - } - lua_pushstring(L, unmakemask(mask, buff)); - lua_pushinteger(L, lua_gethookcount(L1)); - return 3; -} - - -static int db_debug (lua_State *L) { - for (;;) { - char buffer[250]; - fputs("lua_debug> ", stderr); - if (fgets(buffer, sizeof(buffer), stdin) == 0 || - strcmp(buffer, "cont\n") == 0) - return 0; - if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || - lua_pcall(L, 0, 0, 0)) { - fputs(lua_tostring(L, -1), stderr); - fputs("\n", stderr); - } - lua_settop(L, 0); /* remove eventual returns */ - } -} - - -#define LEVELS1 12 /* size of the first part of the stack */ -#define LEVELS2 10 /* size of the second part of the stack */ - -static int db_errorfb (lua_State *L) { - int level; - int firstpart = 1; /* still before eventual `...' */ - int arg; - lua_State *L1 = getthread(L, &arg); - lua_Debug ar; - if (lua_isnumber(L, arg+2)) { - level = (int)lua_tointeger(L, arg+2); - lua_pop(L, 1); - } - else - level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ - if (lua_gettop(L) == arg) - lua_pushliteral(L, ""); - else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ - else lua_pushliteral(L, "\n"); - lua_pushliteral(L, "stack traceback:"); - while (lua_getstack(L1, level++, &ar)) { - if (level > LEVELS1 && firstpart) { - /* no more than `LEVELS2' more levels? */ - if (!lua_getstack(L1, level+LEVELS2, &ar)) - level--; /* keep going */ - else { - lua_pushliteral(L, "\n\t..."); /* too many levels */ - while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ - level++; - } - firstpart = 0; - continue; - } - lua_pushliteral(L, "\n\t"); - lua_getinfo(L1, "Snl", &ar); - lua_pushfstring(L, "%s:", ar.short_src); - if (ar.currentline > 0) - lua_pushfstring(L, "%d:", ar.currentline); - if (*ar.namewhat != '\0') /* is there a name? */ - lua_pushfstring(L, " in function " LUA_QS, ar.name); - else { - if (*ar.what == 'm') /* main? */ - lua_pushfstring(L, " in main chunk"); - else if (*ar.what == 'C' || *ar.what == 't') - lua_pushliteral(L, " ?"); /* C function or tail call */ - else - lua_pushfstring(L, " in function <%s:%d>", - ar.short_src, ar.linedefined); - } - lua_concat(L, lua_gettop(L) - arg); - } - lua_concat(L, lua_gettop(L) - arg); - return 1; -} - - -static const luaL_Reg dblib[] = { - {"debug", db_debug}, - {"getfenv", db_getfenv}, - {"gethook", db_gethook}, - {"getinfo", db_getinfo}, - {"getlocal", db_getlocal}, - {"getregistry", db_getregistry}, - {"getmetatable", db_getmetatable}, - {"getupvalue", db_getupvalue}, - {"setfenv", db_setfenv}, - {"sethook", db_sethook}, - {"setlocal", db_setlocal}, - {"setmetatable", db_setmetatable}, - {"setupvalue", db_setupvalue}, - {"traceback", db_errorfb}, - {NULL, NULL} -}; - - -LUALIB_API int luaopen_debug (lua_State *L) { - luaL_register(L, LUA_DBLIBNAME, dblib); - return 1; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldebug.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldebug.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldebug.h @@ -1,33 +0,0 @@ -/* -** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ -** Auxiliary functions from Debug Interface module -** See Copyright Notice in lua.h -*/ - -#ifndef ldebug_h -#define ldebug_h - - -#include "lstate.h" - - -#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) - -#define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) - -#define resethookcount(L) (L->hookcount = L->basehookcount) - - -LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, - const char *opname); -LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); -LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, - const TValue *p2); -LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, - const TValue *p2); -LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); -LUAI_FUNC void luaG_errormsg (lua_State *L); -LUAI_FUNC int luaG_checkcode (const Proto *pt); -LUAI_FUNC int luaG_checkopenop (Instruction i); - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldebug.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldebug.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldebug.c @@ -1,638 +0,0 @@ -/* -** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $ -** Debug Interface -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include - - -#define ldebug_c -#define LUA_CORE - -#include "lua.h" - -#include "lapi.h" -#include "lcode.h" -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" -#include "lvm.h" - - - -static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); - - -static int currentpc (lua_State *L, CallInfo *ci) { - if (!isLua(ci)) return -1; /* function is not a Lua function? */ - if (ci == L->ci) - ci->savedpc = L->savedpc; - return pcRel(ci->savedpc, ci_func(ci)->l.p); -} - - -static int currentline (lua_State *L, CallInfo *ci) { - int pc = currentpc(L, ci); - if (pc < 0) - return -1; /* only active lua functions have current-line information */ - else - return getline(ci_func(ci)->l.p, pc); -} - - -/* -** this function can be called asynchronous (e.g. during a signal) -*/ -LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) { - if (func == NULL || mask == 0) { /* turn off hooks? */ - mask = 0; - func = NULL; - } - L->hook = func; - L->basehookcount = count; - resethookcount(L); - L->hookmask = cast_byte(mask); - return 1; -} - - -LUA_API lua_Hook lua_gethook (lua_State *L) { - return L->hook; -} - - -LUA_API int lua_gethookmask (lua_State *L) { - return L->hookmask; -} - - -LUA_API int lua_gethookcount (lua_State *L) { - return L->basehookcount; -} - - -LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { - int status; - CallInfo *ci; - lua_lock(L); - for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { - level--; - if (f_isLua(ci)) /* Lua function? */ - level -= ci->tailcalls; /* skip lost tail calls */ - } - if (level == 0 && ci > L->base_ci) { /* level found? */ - status = 1; - ar->i_ci = cast_int(ci - L->base_ci); - } - else if (level < 0) { /* level is of a lost tail call? */ - status = 1; - ar->i_ci = 0; - } - else status = 0; /* no such level */ - lua_unlock(L); - return status; -} - - -static Proto *getluaproto (CallInfo *ci) { - return (isLua(ci) ? ci_func(ci)->l.p : NULL); -} - - -static const char *findlocal (lua_State *L, CallInfo *ci, int n) { - const char *name; - Proto *fp = getluaproto(ci); - if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL) - return name; /* is a local variable in a Lua function */ - else { - StkId limit = (ci == L->ci) ? L->top : (ci+1)->func; - if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */ - return "(*temporary)"; - else - return NULL; - } -} - - -LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { - CallInfo *ci = L->base_ci + ar->i_ci; - const char *name = findlocal(L, ci, n); - lua_lock(L); - if (name) - luaA_pushobject(L, ci->base + (n - 1)); - lua_unlock(L); - return name; -} - - -LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { - CallInfo *ci = L->base_ci + ar->i_ci; - const char *name = findlocal(L, ci, n); - lua_lock(L); - if (name) - setobjs2s(L, ci->base + (n - 1), L->top - 1); - L->top--; /* pop value */ - lua_unlock(L); - return name; -} - - -static void funcinfo (lua_Debug *ar, Closure *cl) { - if (cl->c.isC) { - ar->source = "=[C]"; - ar->linedefined = -1; - ar->lastlinedefined = -1; - ar->what = "C"; - } - else { - ar->source = getstr(cl->l.p->source); - ar->linedefined = cl->l.p->linedefined; - ar->lastlinedefined = cl->l.p->lastlinedefined; - ar->what = (ar->linedefined == 0) ? "main" : "Lua"; - } - luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); -} - - -static void info_tailcall (lua_Debug *ar) { - ar->name = ar->namewhat = ""; - ar->what = "tail"; - ar->lastlinedefined = ar->linedefined = ar->currentline = -1; - ar->source = "=(tail call)"; - luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE); - ar->nups = 0; -} - - -static void collectvalidlines (lua_State *L, Closure *f) { - if (f == NULL || f->c.isC) { - setnilvalue(L->top); - } - else { - Table *t = luaH_new(L, 0, 0); - int *lineinfo = f->l.p->lineinfo; - int i; - for (i=0; il.p->sizelineinfo; i++) - setbvalue(luaH_setnum(L, t, lineinfo[i]), 1); - sethvalue(L, L->top, t); - } - incr_top(L); -} - - -static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, - Closure *f, CallInfo *ci) { - int status = 1; - if (f == NULL) { - info_tailcall(ar); - return status; - } - for (; *what; what++) { - switch (*what) { - case 'S': { - funcinfo(ar, f); - break; - } - case 'l': { - ar->currentline = (ci) ? currentline(L, ci) : -1; - break; - } - case 'u': { - ar->nups = f->c.nupvalues; - break; - } - case 'n': { - ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; - if (ar->namewhat == NULL) { - ar->namewhat = ""; /* not found */ - ar->name = NULL; - } - break; - } - case 'L': - case 'f': /* handled by lua_getinfo */ - break; - default: status = 0; /* invalid option */ - } - } - return status; -} - - -LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { - int status; - Closure *f = NULL; - CallInfo *ci = NULL; - lua_lock(L); - if (*what == '>') { - StkId func = L->top - 1; - luai_apicheck(L, ttisfunction(func)); - what++; /* skip the '>' */ - f = clvalue(func); - L->top--; /* pop function */ - } - else if (ar->i_ci != 0) { /* no tail call? */ - ci = L->base_ci + ar->i_ci; - lua_assert(ttisfunction(ci->func)); - f = clvalue(ci->func); - } - status = auxgetinfo(L, what, ar, f, ci); - if (strchr(what, 'f')) { - if (f == NULL) setnilvalue(L->top); - else setclvalue(L, L->top, f); - incr_top(L); - } - if (strchr(what, 'L')) - collectvalidlines(L, f); - lua_unlock(L); - return status; -} - - -/* -** {====================================================== -** Symbolic Execution and code checker -** ======================================================= -*/ - -#define check(x) if (!(x)) return 0; - -#define checkjump(pt,pc) check(0 <= pc && pc < pt->sizecode) - -#define checkreg(pt,reg) check((reg) < (pt)->maxstacksize) - - - -static int precheck (const Proto *pt) { - check(pt->maxstacksize <= MAXSTACK); - check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize); - check(!(pt->is_vararg & VARARG_NEEDSARG) || - (pt->is_vararg & VARARG_HASARG)); - check(pt->sizeupvalues <= pt->nups); - check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0); - check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); - return 1; -} - - -#define checkopenop(pt,pc) luaG_checkopenop((pt)->code[(pc)+1]) - -int luaG_checkopenop (Instruction i) { - switch (GET_OPCODE(i)) { - case OP_CALL: - case OP_TAILCALL: - case OP_RETURN: - case OP_SETLIST: { - check(GETARG_B(i) == 0); - return 1; - } - default: return 0; /* invalid instruction after an open call */ - } -} - - -static int checkArgMode (const Proto *pt, int r, enum OpArgMask mode) { - switch (mode) { - case OpArgN: check(r == 0); break; - case OpArgU: break; - case OpArgR: checkreg(pt, r); break; - case OpArgK: - check(ISK(r) ? INDEXK(r) < pt->sizek : r < pt->maxstacksize); - break; - } - return 1; -} - - -static Instruction symbexec (const Proto *pt, int lastpc, int reg) { - int pc; - int last; /* stores position of last instruction that changed `reg' */ - last = pt->sizecode-1; /* points to final return (a `neutral' instruction) */ - check(precheck(pt)); - for (pc = 0; pc < lastpc; pc++) { - Instruction i = pt->code[pc]; - OpCode op = GET_OPCODE(i); - int a = GETARG_A(i); - int b = 0; - int c = 0; - check(op < NUM_OPCODES); - checkreg(pt, a); - switch (getOpMode(op)) { - case iABC: { - b = GETARG_B(i); - c = GETARG_C(i); - check(checkArgMode(pt, b, getBMode(op))); - check(checkArgMode(pt, c, getCMode(op))); - break; - } - case iABx: { - b = GETARG_Bx(i); - if (getBMode(op) == OpArgK) check(b < pt->sizek); - break; - } - case iAsBx: { - b = GETARG_sBx(i); - if (getBMode(op) == OpArgR) { - int dest = pc+1+b; - check(0 <= dest && dest < pt->sizecode); - if (dest > 0) { - int j; - /* check that it does not jump to a setlist count; this - is tricky, because the count from a previous setlist may - have the same value of an invalid setlist; so, we must - go all the way back to the first of them (if any) */ - for (j = 0; j < dest; j++) { - Instruction d = pt->code[dest-1-j]; - if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break; - } - /* if 'j' is even, previous value is not a setlist (even if - it looks like one) */ - check((j&1) == 0); - } - } - break; - } - } - if (testAMode(op)) { - if (a == reg) last = pc; /* change register `a' */ - } - if (testTMode(op)) { - check(pc+2 < pt->sizecode); /* check skip */ - check(GET_OPCODE(pt->code[pc+1]) == OP_JMP); - } - switch (op) { - case OP_LOADBOOL: { - if (c == 1) { /* does it jump? */ - check(pc+2 < pt->sizecode); /* check its jump */ - check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST || - GETARG_C(pt->code[pc+1]) != 0); - } - break; - } - case OP_LOADNIL: { - if (a <= reg && reg <= b) - last = pc; /* set registers from `a' to `b' */ - break; - } - case OP_GETUPVAL: - case OP_SETUPVAL: { - check(b < pt->nups); - break; - } - case OP_GETGLOBAL: - case OP_SETGLOBAL: { - check(ttisstring(&pt->k[b])); - break; - } - case OP_SELF: { - checkreg(pt, a+1); - if (reg == a+1) last = pc; - break; - } - case OP_CONCAT: { - check(b < c); /* at least two operands */ - break; - } - case OP_TFORLOOP: { - check(c >= 1); /* at least one result (control variable) */ - checkreg(pt, a+2+c); /* space for results */ - if (reg >= a+2) last = pc; /* affect all regs above its base */ - break; - } - case OP_FORLOOP: - case OP_FORPREP: - checkreg(pt, a+3); - /* go through */ - case OP_JMP: { - int dest = pc+1+b; - /* not full check and jump is forward and do not skip `lastpc'? */ - if (reg != NO_REG && pc < dest && dest <= lastpc) - pc += b; /* do the jump */ - break; - } - case OP_CALL: - case OP_TAILCALL: { - if (b != 0) { - checkreg(pt, a+b-1); - } - c--; /* c = num. returns */ - if (c == LUA_MULTRET) { - check(checkopenop(pt, pc)); - } - else if (c != 0) - checkreg(pt, a+c-1); - if (reg >= a) last = pc; /* affect all registers above base */ - break; - } - case OP_RETURN: { - b--; /* b = num. returns */ - if (b > 0) checkreg(pt, a+b-1); - break; - } - case OP_SETLIST: { - if (b > 0) checkreg(pt, a + b); - if (c == 0) { - pc++; - check(pc < pt->sizecode - 1); - } - break; - } - case OP_CLOSURE: { - int nup, j; - check(b < pt->sizep); - nup = pt->p[b]->nups; - check(pc + nup < pt->sizecode); - for (j = 1; j <= nup; j++) { - OpCode op1 = GET_OPCODE(pt->code[pc + j]); - check(op1 == OP_GETUPVAL || op1 == OP_MOVE); - } - if (reg != NO_REG) /* tracing? */ - pc += nup; /* do not 'execute' these pseudo-instructions */ - break; - } - case OP_VARARG: { - check((pt->is_vararg & VARARG_ISVARARG) && - !(pt->is_vararg & VARARG_NEEDSARG)); - b--; - if (b == LUA_MULTRET) check(checkopenop(pt, pc)); - checkreg(pt, a+b-1); - break; - } - default: break; - } - } - return pt->code[last]; -} - -#undef check -#undef checkjump -#undef checkreg - -/* }====================================================== */ - - -int luaG_checkcode (const Proto *pt) { - return (symbexec(pt, pt->sizecode, NO_REG) != 0); -} - - -static const char *kname (Proto *p, int c) { - if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) - return svalue(&p->k[INDEXK(c)]); - else - return "?"; -} - - -static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, - const char **name) { - if (isLua(ci)) { /* a Lua function? */ - Proto *p = ci_func(ci)->l.p; - int pc = currentpc(L, ci); - Instruction i; - *name = luaF_getlocalname(p, stackpos+1, pc); - if (*name) /* is a local? */ - return "local"; - i = symbexec(p, pc, stackpos); /* try symbolic execution */ - lua_assert(pc != -1); - switch (GET_OPCODE(i)) { - case OP_GETGLOBAL: { - int g = GETARG_Bx(i); /* global index */ - lua_assert(ttisstring(&p->k[g])); - *name = svalue(&p->k[g]); - return "global"; - } - case OP_MOVE: { - int a = GETARG_A(i); - int b = GETARG_B(i); /* move from `b' to `a' */ - if (b < a) - return getobjname(L, ci, b, name); /* get name for `b' */ - break; - } - case OP_GETTABLE: { - int k = GETARG_C(i); /* key index */ - *name = kname(p, k); - return "field"; - } - case OP_GETUPVAL: { - int u = GETARG_B(i); /* upvalue index */ - *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; - return "upvalue"; - } - case OP_SELF: { - int k = GETARG_C(i); /* key index */ - *name = kname(p, k); - return "method"; - } - default: break; - } - } - return NULL; /* no useful name found */ -} - - -static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { - Instruction i; - if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) - return NULL; /* calling function is not Lua (or is unknown) */ - ci--; /* calling function */ - i = ci_func(ci)->l.p->code[currentpc(L, ci)]; - if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || - GET_OPCODE(i) == OP_TFORLOOP) - return getobjname(L, ci, GETARG_A(i), name); - else - return NULL; /* no useful name can be found */ -} - - -/* only ANSI way to check whether a pointer points to an array */ -static int isinstack (CallInfo *ci, const TValue *o) { - StkId p; - for (p = ci->base; p < ci->top; p++) - if (o == p) return 1; - return 0; -} - - -void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { - const char *name = NULL; - const char *t = luaT_typenames[ttype(o)]; - const char *kind = (isinstack(L->ci, o)) ? - getobjname(L, L->ci, cast_int(o - L->base), &name) : - NULL; - if (kind) - luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", - op, kind, name, t); - else - luaG_runerror(L, "attempt to %s a %s value", op, t); -} - - -void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { - if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; - lua_assert(!ttisstring(p1) && !ttisnumber(p1)); - luaG_typeerror(L, p1, "concatenate"); -} - - -void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { - TValue temp; - if (luaV_tonumber(p1, &temp) == NULL) - p2 = p1; /* first operand is wrong */ - luaG_typeerror(L, p2, "perform arithmetic on"); -} - - -int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { - const char *t1 = luaT_typenames[ttype(p1)]; - const char *t2 = luaT_typenames[ttype(p2)]; - if (t1[2] == t2[2]) - luaG_runerror(L, "attempt to compare two %s values", t1); - else - luaG_runerror(L, "attempt to compare %s with %s", t1, t2); - return 0; -} - - -static void addinfo (lua_State *L, const char *msg) { - CallInfo *ci = L->ci; - if (isLua(ci)) { /* is Lua code? */ - char buff[LUA_IDSIZE]; /* add file:line information */ - int line = currentline(L, ci); - luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); - luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); - } -} - - -void luaG_errormsg (lua_State *L) { - if (L->errfunc != 0) { /* is there an error handling function? */ - StkId errfunc = restorestack(L, L->errfunc); - if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); - setobjs2s(L, L->top, L->top - 1); /* move argument */ - setobjs2s(L, L->top - 1, errfunc); /* push function */ - incr_top(L); - luaD_call(L, L->top - 2, 1); /* call it */ - } - luaD_throw(L, LUA_ERRRUN); -} - - -void luaG_runerror (lua_State *L, const char *fmt, ...) { - va_list argp; - va_start(argp, fmt); - addinfo(L, luaO_pushvfstring(L, fmt, argp)); - va_end(argp); - luaG_errormsg(L); -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldo.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldo.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldo.h @@ -1,57 +0,0 @@ -/* -** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ -** Stack and Call structure of Lua -** See Copyright Notice in lua.h -*/ - -#ifndef ldo_h -#define ldo_h - - -#include "lobject.h" -#include "lstate.h" -#include "lzio.h" - - -#define luaD_checkstack(L,n) \ - if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ - luaD_growstack(L, n); \ - else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); - - -#define incr_top(L) {luaD_checkstack(L,1); L->top++;} - -#define savestack(L,p) ((char *)(p) - (char *)L->stack) -#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) - -#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) -#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) - - -/* results from luaD_precall */ -#define PCRLUA 0 /* initiated a call to a Lua function */ -#define PCRC 1 /* did a call to a C function */ -#define PCRYIELD 2 /* C funtion yielded */ - - -/* type of protected functions, to be ran by `runprotected' */ -typedef void (*Pfunc) (lua_State *L, void *ud); - -LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); -LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); -LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); -LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); -LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, - ptrdiff_t oldtop, ptrdiff_t ef); -LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); -LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); -LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); -LUAI_FUNC void luaD_growstack (lua_State *L, int n); - -LUAI_FUNC void luaD_throw (lua_State *L, int errcode); -LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); - -LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); - -#endif - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldo.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldo.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldo.c @@ -1,518 +0,0 @@ -/* -** $Id: ldo.c,v 2.38.1.3 2008/01/18 22:31:22 roberto Exp $ -** Stack and Call structure of Lua -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include - -#define ldo_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lgc.h" -#include "lmem.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lparser.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" -#include "lundump.h" -#include "lvm.h" -#include "lzio.h" - - - - -/* -** {====================================================== -** Error-recovery functions -** ======================================================= -*/ - - -/* chain list of long jump buffers */ -struct lua_longjmp { - struct lua_longjmp *previous; - luai_jmpbuf b; - volatile int status; /* error code */ -}; - - -void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) { - switch (errcode) { - case LUA_ERRMEM: { - setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); - break; - } - case LUA_ERRERR: { - setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); - break; - } - case LUA_ERRSYNTAX: - case LUA_ERRRUN: { - setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ - break; - } - } - L->top = oldtop + 1; -} - - -static void restore_stack_limit (lua_State *L) { - lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); - if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ - int inuse = cast_int(L->ci - L->base_ci); - if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ - luaD_reallocCI(L, LUAI_MAXCALLS); - } -} - - -static void resetstack (lua_State *L, int status) { - L->ci = L->base_ci; - L->base = L->ci->base; - luaF_close(L, L->base); /* close eventual pending closures */ - luaD_seterrorobj(L, status, L->base); - L->nCcalls = L->baseCcalls; - L->allowhook = 1; - restore_stack_limit(L); - L->errfunc = 0; - L->errorJmp = NULL; -} - - -void luaD_throw (lua_State *L, int errcode) { - if (L->errorJmp) { - L->errorJmp->status = errcode; - LUAI_THROW(L, L->errorJmp); - } - else { - L->status = cast_byte(errcode); - if (G(L)->panic) { - resetstack(L, errcode); - lua_unlock(L); - G(L)->panic(L); - } - exit(EXIT_FAILURE); - } -} - - -int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { - struct lua_longjmp lj; - lj.status = 0; - lj.previous = L->errorJmp; /* chain new error handler */ - L->errorJmp = &lj; - LUAI_TRY(L, &lj, - (*f)(L, ud); - ); - L->errorJmp = lj.previous; /* restore old error handler */ - return lj.status; -} - -/* }====================================================== */ - - -static void correctstack (lua_State *L, TValue *oldstack) { - CallInfo *ci; - GCObject *up; - L->top = (L->top - oldstack) + L->stack; - for (up = L->openupval; up != NULL; up = up->gch.next) - gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack; - for (ci = L->base_ci; ci <= L->ci; ci++) { - ci->top = (ci->top - oldstack) + L->stack; - ci->base = (ci->base - oldstack) + L->stack; - ci->func = (ci->func - oldstack) + L->stack; - } - L->base = (L->base - oldstack) + L->stack; -} - - -void luaD_reallocstack (lua_State *L, int newsize) { - TValue *oldstack = L->stack; - int realsize = newsize + 1 + EXTRA_STACK; - lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); - luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); - L->stacksize = realsize; - L->stack_last = L->stack+newsize; - correctstack(L, oldstack); -} - - -void luaD_reallocCI (lua_State *L, int newsize) { - CallInfo *oldci = L->base_ci; - luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo); - L->size_ci = newsize; - L->ci = (L->ci - oldci) + L->base_ci; - L->end_ci = L->base_ci + L->size_ci - 1; -} - - -void luaD_growstack (lua_State *L, int n) { - if (n <= L->stacksize) /* double size is enough? */ - luaD_reallocstack(L, 2*L->stacksize); - else - luaD_reallocstack(L, L->stacksize + n); -} - - -static CallInfo *growCI (lua_State *L) { - if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ - luaD_throw(L, LUA_ERRERR); - else { - luaD_reallocCI(L, 2*L->size_ci); - if (L->size_ci > LUAI_MAXCALLS) - luaG_runerror(L, "stack overflow"); - } - return ++L->ci; -} - - -void luaD_callhook (lua_State *L, int event, int line) { - lua_Hook hook = L->hook; - if (hook && L->allowhook) { - ptrdiff_t top = savestack(L, L->top); - ptrdiff_t ci_top = savestack(L, L->ci->top); - lua_Debug ar; - ar.event = event; - ar.currentline = line; - if (event == LUA_HOOKTAILRET) - ar.i_ci = 0; /* tail call; no debug information about it */ - else - ar.i_ci = cast_int(L->ci - L->base_ci); - luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ - L->ci->top = L->top + LUA_MINSTACK; - lua_assert(L->ci->top <= L->stack_last); - L->allowhook = 0; /* cannot call hooks inside a hook */ - lua_unlock(L); - (*hook)(L, &ar); - lua_lock(L); - lua_assert(!L->allowhook); - L->allowhook = 1; - L->ci->top = restorestack(L, ci_top); - L->top = restorestack(L, top); - } -} - - -static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { - int i; - int nfixargs = p->numparams; - Table *htab = NULL; - StkId base, fixed; - for (; actual < nfixargs; ++actual) - setnilvalue(L->top++); -#if defined(LUA_COMPAT_VARARG) - if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ - int nvar = actual - nfixargs; /* number of extra arguments */ - lua_assert(p->is_vararg & VARARG_HASARG); - luaC_checkGC(L); - htab = luaH_new(L, nvar, 1); /* create `arg' table */ - for (i=0; itop - nvar + i); - /* store counter in field `n' */ - setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); - } -#endif - /* move fixed parameters to final position */ - fixed = L->top - actual; /* first fixed argument */ - base = L->top; /* final position of first argument */ - for (i=0; itop++, fixed+i); - setnilvalue(fixed+i); - } - /* add `arg' parameter */ - if (htab) { - sethvalue(L, L->top++, htab); - lua_assert(iswhite(obj2gco(htab))); - } - return base; -} - - -static StkId tryfuncTM (lua_State *L, StkId func) { - const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); - StkId p; - ptrdiff_t funcr = savestack(L, func); - if (!ttisfunction(tm)) - luaG_typeerror(L, func, "call"); - /* Open a hole inside the stack at `func' */ - for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); - incr_top(L); - func = restorestack(L, funcr); /* previous call may change stack */ - setobj2s(L, func, tm); /* tag method is the new function to be called */ - return func; -} - - - -#define inc_ci(L) \ - ((L->ci == L->end_ci) ? growCI(L) : \ - (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) - - -int luaD_precall (lua_State *L, StkId func, int nresults) { - LClosure *cl; - ptrdiff_t funcr; - if (!ttisfunction(func)) /* `func' is not a function? */ - func = tryfuncTM(L, func); /* check the `function' tag method */ - funcr = savestack(L, func); - cl = &clvalue(func)->l; - L->ci->savedpc = L->savedpc; - if (!cl->isC) { /* Lua function? prepare its call */ - CallInfo *ci; - StkId st, base; - Proto *p = cl->p; - luaD_checkstack(L, p->maxstacksize); - func = restorestack(L, funcr); - if (!p->is_vararg) { /* no varargs? */ - base = func + 1; - if (L->top > base + p->numparams) - L->top = base + p->numparams; - } - else { /* vararg function */ - int nargs = cast_int(L->top - func) - 1; - base = adjust_varargs(L, p, nargs); - func = restorestack(L, funcr); /* previous call may change the stack */ - } - ci = inc_ci(L); /* now `enter' new function */ - ci->func = func; - L->base = ci->base = base; - ci->top = L->base + p->maxstacksize; - lua_assert(ci->top <= L->stack_last); - L->savedpc = p->code; /* starting point */ - ci->tailcalls = 0; - ci->nresults = nresults; - for (st = L->top; st < ci->top; st++) - setnilvalue(st); - L->top = ci->top; - if (L->hookmask & LUA_MASKCALL) { - L->savedpc++; /* hooks assume 'pc' is already incremented */ - luaD_callhook(L, LUA_HOOKCALL, -1); - L->savedpc--; /* correct 'pc' */ - } - return PCRLUA; - } - else { /* if is a C function, call it */ - CallInfo *ci; - int n; - luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ - ci = inc_ci(L); /* now `enter' new function */ - ci->func = restorestack(L, funcr); - L->base = ci->base = ci->func + 1; - ci->top = L->top + LUA_MINSTACK; - lua_assert(ci->top <= L->stack_last); - ci->nresults = nresults; - if (L->hookmask & LUA_MASKCALL) - luaD_callhook(L, LUA_HOOKCALL, -1); - lua_unlock(L); - n = (*curr_func(L)->c.f)(L); /* do the actual call */ - lua_lock(L); - if (n < 0) /* yielding? */ - return PCRYIELD; - else { - luaD_poscall(L, L->top - n); - return PCRC; - } - } -} - - -static StkId callrethooks (lua_State *L, StkId firstResult) { - ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ - luaD_callhook(L, LUA_HOOKRET, -1); - if (f_isLua(L->ci)) { /* Lua function? */ - while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ - luaD_callhook(L, LUA_HOOKTAILRET, -1); - } - return restorestack(L, fr); -} - - -int luaD_poscall (lua_State *L, StkId firstResult) { - StkId res; - int wanted, i; - CallInfo *ci; - if (L->hookmask & LUA_MASKRET) - firstResult = callrethooks(L, firstResult); - ci = L->ci--; - res = ci->func; /* res == final position of 1st result */ - wanted = ci->nresults; - L->base = (ci - 1)->base; /* restore base */ - L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ - /* move results to correct place */ - for (i = wanted; i != 0 && firstResult < L->top; i--) - setobjs2s(L, res++, firstResult++); - while (i-- > 0) - setnilvalue(res++); - L->top = res; - return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ -} - - -/* -** Call a function (C or Lua). The function to be called is at *func. -** The arguments are on the stack, right after the function. -** When returns, all the results are on the stack, starting at the original -** function position. -*/ -void luaD_call (lua_State *L, StkId func, int nResults) { - if (++L->nCcalls >= LUAI_MAXCCALLS) { - if (L->nCcalls == LUAI_MAXCCALLS) - luaG_runerror(L, "C stack overflow"); - else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) - luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ - } - if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ - luaV_execute(L, 1); /* call it */ - L->nCcalls--; - luaC_checkGC(L); -} - - -static void resume (lua_State *L, void *ud) { - StkId firstArg = cast(StkId, ud); - CallInfo *ci = L->ci; - if (L->status == 0) { /* start coroutine? */ - lua_assert(ci == L->base_ci && firstArg > L->base); - if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) - return; - } - else { /* resuming from previous yield */ - lua_assert(L->status == LUA_YIELD); - L->status = 0; - if (!f_isLua(ci)) { /* `common' yield? */ - /* finish interrupted execution of `OP_CALL' */ - lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || - GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); - if (luaD_poscall(L, firstArg)) /* complete it... */ - L->top = L->ci->top; /* and correct top if not multiple results */ - } - else /* yielded inside a hook: just continue its execution */ - L->base = L->ci->base; - } - luaV_execute(L, cast_int(L->ci - L->base_ci)); -} - - -static int resume_error (lua_State *L, const char *msg) { - L->top = L->ci->base; - setsvalue2s(L, L->top, luaS_new(L, msg)); - incr_top(L); - lua_unlock(L); - return LUA_ERRRUN; -} - - -LUA_API int lua_resume (lua_State *L, int nargs) { - int status; - lua_lock(L); - if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) - return resume_error(L, "cannot resume non-suspended coroutine"); - if (L->nCcalls >= LUAI_MAXCCALLS) - return resume_error(L, "C stack overflow"); - luai_userstateresume(L, nargs); - lua_assert(L->errfunc == 0); - L->baseCcalls = ++L->nCcalls; - status = luaD_rawrunprotected(L, resume, L->top - nargs); - if (status != 0) { /* error? */ - L->status = cast_byte(status); /* mark thread as `dead' */ - luaD_seterrorobj(L, status, L->top); - L->ci->top = L->top; - } - else { - lua_assert(L->nCcalls == L->baseCcalls); - status = L->status; - } - --L->nCcalls; - lua_unlock(L); - return status; -} - - -LUA_API int lua_yield (lua_State *L, int nresults) { - luai_userstateyield(L, nresults); - lua_lock(L); - if (L->nCcalls > L->baseCcalls) - luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); - L->base = L->top - nresults; /* protect stack slots below */ - L->status = LUA_YIELD; - lua_unlock(L); - return -1; -} - - -int luaD_pcall (lua_State *L, Pfunc func, void *u, - ptrdiff_t old_top, ptrdiff_t ef) { - int status; - unsigned short oldnCcalls = L->nCcalls; - ptrdiff_t old_ci = saveci(L, L->ci); - lu_byte old_allowhooks = L->allowhook; - ptrdiff_t old_errfunc = L->errfunc; - L->errfunc = ef; - status = luaD_rawrunprotected(L, func, u); - if (status != 0) { /* an error occurred? */ - StkId oldtop = restorestack(L, old_top); - luaF_close(L, oldtop); /* close eventual pending closures */ - luaD_seterrorobj(L, status, oldtop); - L->nCcalls = oldnCcalls; - L->ci = restoreci(L, old_ci); - L->base = L->ci->base; - L->savedpc = L->ci->savedpc; - L->allowhook = old_allowhooks; - restore_stack_limit(L); - } - L->errfunc = old_errfunc; - return status; -} - - - -/* -** Execute a protected parser. -*/ -struct SParser { /* data to `f_parser' */ - ZIO *z; - Mbuffer buff; /* buffer to be used by the scanner */ - const char *name; -}; - -static void f_parser (lua_State *L, void *ud) { - int i; - Proto *tf; - Closure *cl; - struct SParser *p = cast(struct SParser *, ud); - int c = luaZ_lookahead(p->z); - luaC_checkGC(L); - tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, - &p->buff, p->name); - cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); - cl->l.p = tf; - for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ - cl->l.upvals[i] = luaF_newupval(L); - setclvalue(L, L->top, cl); - incr_top(L); -} - - -int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { - struct SParser p; - int status; - p.z = z; p.name = name; - luaZ_initbuffer(L, &p.buff); - status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); - luaZ_freebuffer(L, &p.buff); - return status; -} - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldump.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldump.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ldump.c @@ -1,164 +0,0 @@ -/* -** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ -** save precompiled Lua chunks -** See Copyright Notice in lua.h -*/ - -#include - -#define ldump_c -#define LUA_CORE - -#include "lua.h" - -#include "lobject.h" -#include "lstate.h" -#include "lundump.h" - -typedef struct { - lua_State* L; - lua_Writer writer; - void* data; - int strip; - int status; -} DumpState; - -#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) -#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) - -static void DumpBlock(const void* b, size_t size, DumpState* D) -{ - if (D->status==0) - { - lua_unlock(D->L); - D->status=(*D->writer)(D->L,b,size,D->data); - lua_lock(D->L); - } -} - -static void DumpChar(int y, DumpState* D) -{ - char x=(char)y; - DumpVar(x,D); -} - -static void DumpInt(int x, DumpState* D) -{ - DumpVar(x,D); -} - -static void DumpNumber(lua_Number x, DumpState* D) -{ - DumpVar(x,D); -} - -static void DumpVector(const void* b, int n, size_t size, DumpState* D) -{ - DumpInt(n,D); - DumpMem(b,n,size,D); -} - -static void DumpString(const TString* s, DumpState* D) -{ - if (s==NULL || getstr(s)==NULL) - { - size_t size=0; - DumpVar(size,D); - } - else - { - size_t size=s->tsv.len+1; /* include trailing '\0' */ - DumpVar(size,D); - DumpBlock(getstr(s),size,D); - } -} - -#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) - -static void DumpFunction(const Proto* f, const TString* p, DumpState* D); - -static void DumpConstants(const Proto* f, DumpState* D) -{ - int i,n=f->sizek; - DumpInt(n,D); - for (i=0; ik[i]; - DumpChar(ttype(o),D); - switch (ttype(o)) - { - case LUA_TNIL: - break; - case LUA_TBOOLEAN: - DumpChar(bvalue(o),D); - break; - case LUA_TNUMBER: - DumpNumber(nvalue(o),D); - break; - case LUA_TSTRING: - DumpString(rawtsvalue(o),D); - break; - default: - lua_assert(0); /* cannot happen */ - break; - } - } - n=f->sizep; - DumpInt(n,D); - for (i=0; ip[i],f->source,D); -} - -static void DumpDebug(const Proto* f, DumpState* D) -{ - int i,n; - n= (D->strip) ? 0 : f->sizelineinfo; - DumpVector(f->lineinfo,n,sizeof(int),D); - n= (D->strip) ? 0 : f->sizelocvars; - DumpInt(n,D); - for (i=0; ilocvars[i].varname,D); - DumpInt(f->locvars[i].startpc,D); - DumpInt(f->locvars[i].endpc,D); - } - n= (D->strip) ? 0 : f->sizeupvalues; - DumpInt(n,D); - for (i=0; iupvalues[i],D); -} - -static void DumpFunction(const Proto* f, const TString* p, DumpState* D) -{ - DumpString((f->source==p || D->strip) ? NULL : f->source,D); - DumpInt(f->linedefined,D); - DumpInt(f->lastlinedefined,D); - DumpChar(f->nups,D); - DumpChar(f->numparams,D); - DumpChar(f->is_vararg,D); - DumpChar(f->maxstacksize,D); - DumpCode(f,D); - DumpConstants(f,D); - DumpDebug(f,D); -} - -static void DumpHeader(DumpState* D) -{ - char h[LUAC_HEADERSIZE]; - luaU_header(h); - DumpBlock(h,LUAC_HEADERSIZE,D); -} - -/* -** dump Lua function as precompiled chunk -*/ -int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) -{ - DumpState D; - D.L=L; - D.writer=w; - D.data=data; - D.strip=strip; - D.status=0; - DumpHeader(&D); - DumpFunction(f,NULL,&D); - return D.status; -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lfunc.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lfunc.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lfunc.h @@ -1,34 +0,0 @@ -/* -** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ -** Auxiliary functions to manipulate prototypes and closures -** See Copyright Notice in lua.h -*/ - -#ifndef lfunc_h -#define lfunc_h - - -#include "lobject.h" - - -#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ - cast(int, sizeof(TValue)*((n)-1))) - -#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ - cast(int, sizeof(TValue *)*((n)-1))) - - -LUAI_FUNC Proto *luaF_newproto (lua_State *L); -LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); -LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); -LUAI_FUNC UpVal *luaF_newupval (lua_State *L); -LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); -LUAI_FUNC void luaF_close (lua_State *L, StkId level); -LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); -LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); -LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); -LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, - int pc); - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lfunc.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lfunc.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lfunc.c @@ -1,174 +0,0 @@ -/* -** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ -** Auxiliary functions to manipulate prototypes and closures -** See Copyright Notice in lua.h -*/ - - -#include - -#define lfunc_c -#define LUA_CORE - -#include "lua.h" - -#include "lfunc.h" -#include "lgc.h" -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" - - - -Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { - Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); - luaC_link(L, obj2gco(c), LUA_TFUNCTION); - c->c.isC = 1; - c->c.env = e; - c->c.nupvalues = cast_byte(nelems); - return c; -} - - -Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { - Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); - luaC_link(L, obj2gco(c), LUA_TFUNCTION); - c->l.isC = 0; - c->l.env = e; - c->l.nupvalues = cast_byte(nelems); - while (nelems--) c->l.upvals[nelems] = NULL; - return c; -} - - -UpVal *luaF_newupval (lua_State *L) { - UpVal *uv = luaM_new(L, UpVal); - luaC_link(L, obj2gco(uv), LUA_TUPVAL); - uv->v = &uv->u.value; - setnilvalue(uv->v); - return uv; -} - - -UpVal *luaF_findupval (lua_State *L, StkId level) { - global_State *g = G(L); - GCObject **pp = &L->openupval; - UpVal *p; - UpVal *uv; - while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { - lua_assert(p->v != &p->u.value); - if (p->v == level) { /* found a corresponding upvalue? */ - if (isdead(g, obj2gco(p))) /* is it dead? */ - changewhite(obj2gco(p)); /* ressurect it */ - return p; - } - pp = &p->next; - } - uv = luaM_new(L, UpVal); /* not found: create a new one */ - uv->tt = LUA_TUPVAL; - uv->marked = luaC_white(g); - uv->v = level; /* current value lives in the stack */ - uv->next = *pp; /* chain it in the proper position */ - *pp = obj2gco(uv); - uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ - uv->u.l.next = g->uvhead.u.l.next; - uv->u.l.next->u.l.prev = uv; - g->uvhead.u.l.next = uv; - lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); - return uv; -} - - -static void unlinkupval (UpVal *uv) { - lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); - uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ - uv->u.l.prev->u.l.next = uv->u.l.next; -} - - -void luaF_freeupval (lua_State *L, UpVal *uv) { - if (uv->v != &uv->u.value) /* is it open? */ - unlinkupval(uv); /* remove from open list */ - luaM_free(L, uv); /* free upvalue */ -} - - -void luaF_close (lua_State *L, StkId level) { - UpVal *uv; - global_State *g = G(L); - while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { - GCObject *o = obj2gco(uv); - lua_assert(!isblack(o) && uv->v != &uv->u.value); - L->openupval = uv->next; /* remove from `open' list */ - if (isdead(g, o)) - luaF_freeupval(L, uv); /* free upvalue */ - else { - unlinkupval(uv); - setobj(L, &uv->u.value, uv->v); - uv->v = &uv->u.value; /* now current value lives here */ - luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ - } - } -} - - -Proto *luaF_newproto (lua_State *L) { - Proto *f = luaM_new(L, Proto); - luaC_link(L, obj2gco(f), LUA_TPROTO); - f->k = NULL; - f->sizek = 0; - f->p = NULL; - f->sizep = 0; - f->code = NULL; - f->sizecode = 0; - f->sizelineinfo = 0; - f->sizeupvalues = 0; - f->nups = 0; - f->upvalues = NULL; - f->numparams = 0; - f->is_vararg = 0; - f->maxstacksize = 0; - f->lineinfo = NULL; - f->sizelocvars = 0; - f->locvars = NULL; - f->linedefined = 0; - f->lastlinedefined = 0; - f->source = NULL; - return f; -} - - -void luaF_freeproto (lua_State *L, Proto *f) { - luaM_freearray(L, f->code, f->sizecode, Instruction); - luaM_freearray(L, f->p, f->sizep, Proto *); - luaM_freearray(L, f->k, f->sizek, TValue); - luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); - luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); - luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); - luaM_free(L, f); -} - - -void luaF_freeclosure (lua_State *L, Closure *c) { - int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : - sizeLclosure(c->l.nupvalues); - luaM_freemem(L, c, size); -} - - -/* -** Look for n-th local variable at line `line' in function `func'. -** Returns NULL if not found. -*/ -const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { - int i; - for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { - if (pc < f->locvars[i].endpc) { /* is variable active? */ - local_number--; - if (local_number == 0) - return getstr(f->locvars[i].varname); - } - } - return NULL; /* not found */ -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lgc.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lgc.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lgc.h @@ -1,110 +0,0 @@ -/* -** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ -** Garbage Collector -** See Copyright Notice in lua.h -*/ - -#ifndef lgc_h -#define lgc_h - - -#include "lobject.h" - - -/* -** Possible states of the Garbage Collector -*/ -#define GCSpause 0 -#define GCSpropagate 1 -#define GCSsweepstring 2 -#define GCSsweep 3 -#define GCSfinalize 4 - - -/* -** some userful bit tricks -*/ -#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) -#define setbits(x,m) ((x) |= (m)) -#define testbits(x,m) ((x) & (m)) -#define bitmask(b) (1<<(b)) -#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) -#define l_setbit(x,b) setbits(x, bitmask(b)) -#define resetbit(x,b) resetbits(x, bitmask(b)) -#define testbit(x,b) testbits(x, bitmask(b)) -#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) -#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) -#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) - - - -/* -** Layout for bit use in `marked' field: -** bit 0 - object is white (type 0) -** bit 1 - object is white (type 1) -** bit 2 - object is black -** bit 3 - for userdata: has been finalized -** bit 3 - for tables: has weak keys -** bit 4 - for tables: has weak values -** bit 5 - object is fixed (should not be collected) -** bit 6 - object is "super" fixed (only the main thread) -*/ - - -#define WHITE0BIT 0 -#define WHITE1BIT 1 -#define BLACKBIT 2 -#define FINALIZEDBIT 3 -#define KEYWEAKBIT 3 -#define VALUEWEAKBIT 4 -#define FIXEDBIT 5 -#define SFIXEDBIT 6 -#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) - - -#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) -#define isblack(x) testbit((x)->gch.marked, BLACKBIT) -#define isgray(x) (!isblack(x) && !iswhite(x)) - -#define otherwhite(g) (g->currentwhite ^ WHITEBITS) -#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) - -#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) -#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) - -#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) - -#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) - - -#define luaC_checkGC(L) { \ - condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ - if (G(L)->totalbytes >= G(L)->GCthreshold) \ - luaC_step(L); } - - -#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ - luaC_barrierf(L,obj2gco(p),gcvalue(v)); } - -#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ - luaC_barrierback(L,t); } - -#define luaC_objbarrier(L,p,o) \ - { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ - luaC_barrierf(L,obj2gco(p),obj2gco(o)); } - -#define luaC_objbarriert(L,t,o) \ - { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } - -LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); -LUAI_FUNC void luaC_callGCTM (lua_State *L); -LUAI_FUNC void luaC_freeall (lua_State *L); -LUAI_FUNC void luaC_step (lua_State *L); -LUAI_FUNC void luaC_fullgc (lua_State *L); -LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); -LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); -LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); -LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lgc.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lgc.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lgc.c @@ -1,711 +0,0 @@ -/* -** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $ -** Garbage Collector -** See Copyright Notice in lua.h -*/ - -#include - -#define lgc_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lgc.h" -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" - - -#define GCSTEPSIZE 1024u -#define GCSWEEPMAX 40 -#define GCSWEEPCOST 10 -#define GCFINALIZECOST 100 - - -#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS)) - -#define makewhite(g,x) \ - ((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g))) - -#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) -#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT) - -#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) - - -#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT) -#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT) - - -#define KEYWEAK bitmask(KEYWEAKBIT) -#define VALUEWEAK bitmask(VALUEWEAKBIT) - - - -#define markvalue(g,o) { checkconsistency(o); \ - if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); } - -#define markobject(g,t) { if (iswhite(obj2gco(t))) \ - reallymarkobject(g, obj2gco(t)); } - - -#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause) - - -static void removeentry (Node *n) { - lua_assert(ttisnil(gval(n))); - if (iscollectable(gkey(n))) - setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */ -} - - -static void reallymarkobject (global_State *g, GCObject *o) { - lua_assert(iswhite(o) && !isdead(g, o)); - white2gray(o); - switch (o->gch.tt) { - case LUA_TSTRING: { - return; - } - case LUA_TUSERDATA: { - Table *mt = gco2u(o)->metatable; - gray2black(o); /* udata are never gray */ - if (mt) markobject(g, mt); - markobject(g, gco2u(o)->env); - return; - } - case LUA_TUPVAL: { - UpVal *uv = gco2uv(o); - markvalue(g, uv->v); - if (uv->v == &uv->u.value) /* closed? */ - gray2black(o); /* open upvalues are never black */ - return; - } - case LUA_TFUNCTION: { - gco2cl(o)->c.gclist = g->gray; - g->gray = o; - break; - } - case LUA_TTABLE: { - gco2h(o)->gclist = g->gray; - g->gray = o; - break; - } - case LUA_TTHREAD: { - gco2th(o)->gclist = g->gray; - g->gray = o; - break; - } - case LUA_TPROTO: { - gco2p(o)->gclist = g->gray; - g->gray = o; - break; - } - default: lua_assert(0); - } -} - - -static void marktmu (global_State *g) { - GCObject *u = g->tmudata; - if (u) { - do { - u = u->gch.next; - makewhite(g, u); /* may be marked, if left from previous GC */ - reallymarkobject(g, u); - } while (u != g->tmudata); - } -} - - -/* move `dead' udata that need finalization to list `tmudata' */ -size_t luaC_separateudata (lua_State *L, int all) { - global_State *g = G(L); - size_t deadmem = 0; - GCObject **p = &g->mainthread->next; - GCObject *curr; - while ((curr = *p) != NULL) { - if (!(iswhite(curr) || all) || isfinalized(gco2u(curr))) - p = &curr->gch.next; /* don't bother with them */ - else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) { - markfinalized(gco2u(curr)); /* don't need finalization */ - p = &curr->gch.next; - } - else { /* must call its gc method */ - deadmem += sizeudata(gco2u(curr)); - markfinalized(gco2u(curr)); - *p = curr->gch.next; - /* link `curr' at the end of `tmudata' list */ - if (g->tmudata == NULL) /* list is empty? */ - g->tmudata = curr->gch.next = curr; /* creates a circular list */ - else { - curr->gch.next = g->tmudata->gch.next; - g->tmudata->gch.next = curr; - g->tmudata = curr; - } - } - } - return deadmem; -} - - -static int traversetable (global_State *g, Table *h) { - int i; - int weakkey = 0; - int weakvalue = 0; - const TValue *mode; - if (h->metatable) - markobject(g, h->metatable); - mode = gfasttm(g, h->metatable, TM_MODE); - if (mode && ttisstring(mode)) { /* is there a weak mode? */ - weakkey = (strchr(svalue(mode), 'k') != NULL); - weakvalue = (strchr(svalue(mode), 'v') != NULL); - if (weakkey || weakvalue) { /* is really weak? */ - h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */ - h->marked |= cast_byte((weakkey << KEYWEAKBIT) | - (weakvalue << VALUEWEAKBIT)); - h->gclist = g->weak; /* must be cleared after GC, ... */ - g->weak = obj2gco(h); /* ... so put in the appropriate list */ - } - } - if (weakkey && weakvalue) return 1; - if (!weakvalue) { - i = h->sizearray; - while (i--) - markvalue(g, &h->array[i]); - } - i = sizenode(h); - while (i--) { - Node *n = gnode(h, i); - lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n))); - if (ttisnil(gval(n))) - removeentry(n); /* remove empty entries */ - else { - lua_assert(!ttisnil(gkey(n))); - if (!weakkey) markvalue(g, gkey(n)); - if (!weakvalue) markvalue(g, gval(n)); - } - } - return weakkey || weakvalue; -} - - -/* -** All marks are conditional because a GC may happen while the -** prototype is still being created -*/ -static void traverseproto (global_State *g, Proto *f) { - int i; - if (f->source) stringmark(f->source); - for (i=0; isizek; i++) /* mark literals */ - markvalue(g, &f->k[i]); - for (i=0; isizeupvalues; i++) { /* mark upvalue names */ - if (f->upvalues[i]) - stringmark(f->upvalues[i]); - } - for (i=0; isizep; i++) { /* mark nested protos */ - if (f->p[i]) - markobject(g, f->p[i]); - } - for (i=0; isizelocvars; i++) { /* mark local-variable names */ - if (f->locvars[i].varname) - stringmark(f->locvars[i].varname); - } -} - - - -static void traverseclosure (global_State *g, Closure *cl) { - markobject(g, cl->c.env); - if (cl->c.isC) { - int i; - for (i=0; ic.nupvalues; i++) /* mark its upvalues */ - markvalue(g, &cl->c.upvalue[i]); - } - else { - int i; - lua_assert(cl->l.nupvalues == cl->l.p->nups); - markobject(g, cl->l.p); - for (i=0; il.nupvalues; i++) /* mark its upvalues */ - markobject(g, cl->l.upvals[i]); - } -} - - -static void checkstacksizes (lua_State *L, StkId max) { - int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */ - int s_used = cast_int(max - L->stack); /* part of stack in use */ - if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */ - return; /* do not touch the stacks */ - if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) - luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ - condhardstacktests(luaD_reallocCI(L, ci_used + 1)); - if (4*s_used < L->stacksize && - 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) - luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ - condhardstacktests(luaD_reallocstack(L, s_used)); -} - - -static void traversestack (global_State *g, lua_State *l) { - StkId o, lim; - CallInfo *ci; - markvalue(g, gt(l)); - lim = l->top; - for (ci = l->base_ci; ci <= l->ci; ci++) { - lua_assert(ci->top <= l->stack_last); - if (lim < ci->top) lim = ci->top; - } - for (o = l->stack; o < l->top; o++) - markvalue(g, o); - for (; o <= lim; o++) - setnilvalue(o); - checkstacksizes(l, lim); -} - - -/* -** traverse one gray object, turning it to black. -** Returns `quantity' traversed. -*/ -static l_mem propagatemark (global_State *g) { - GCObject *o = g->gray; - lua_assert(isgray(o)); - gray2black(o); - switch (o->gch.tt) { - case LUA_TTABLE: { - Table *h = gco2h(o); - g->gray = h->gclist; - if (traversetable(g, h)) /* table is weak? */ - black2gray(o); /* keep it gray */ - return sizeof(Table) + sizeof(TValue) * h->sizearray + - sizeof(Node) * sizenode(h); - } - case LUA_TFUNCTION: { - Closure *cl = gco2cl(o); - g->gray = cl->c.gclist; - traverseclosure(g, cl); - return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : - sizeLclosure(cl->l.nupvalues); - } - case LUA_TTHREAD: { - lua_State *th = gco2th(o); - g->gray = th->gclist; - th->gclist = g->grayagain; - g->grayagain = o; - black2gray(o); - traversestack(g, th); - return sizeof(lua_State) + sizeof(TValue) * th->stacksize + - sizeof(CallInfo) * th->size_ci; - } - case LUA_TPROTO: { - Proto *p = gco2p(o); - g->gray = p->gclist; - traverseproto(g, p); - return sizeof(Proto) + sizeof(Instruction) * p->sizecode + - sizeof(Proto *) * p->sizep + - sizeof(TValue) * p->sizek + - sizeof(int) * p->sizelineinfo + - sizeof(LocVar) * p->sizelocvars + - sizeof(TString *) * p->sizeupvalues; - } - default: lua_assert(0); return 0; - } -} - - -static size_t propagateall (global_State *g) { - size_t m = 0; - while (g->gray) m += propagatemark(g); - return m; -} - - -/* -** The next function tells whether a key or value can be cleared from -** a weak table. Non-collectable objects are never removed from weak -** tables. Strings behave as `values', so are never removed too. for -** other objects: if really collected, cannot keep them; for userdata -** being finalized, keep them in keys, but not in values -*/ -static int iscleared (const TValue *o, int iskey) { - if (!iscollectable(o)) return 0; - if (ttisstring(o)) { - stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ - return 0; - } - return iswhite(gcvalue(o)) || - (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); -} - - -/* -** clear collected entries from weaktables -*/ -static void cleartable (GCObject *l) { - while (l) { - Table *h = gco2h(l); - int i = h->sizearray; - lua_assert(testbit(h->marked, VALUEWEAKBIT) || - testbit(h->marked, KEYWEAKBIT)); - if (testbit(h->marked, VALUEWEAKBIT)) { - while (i--) { - TValue *o = &h->array[i]; - if (iscleared(o, 0)) /* value was collected? */ - setnilvalue(o); /* remove value */ - } - } - i = sizenode(h); - while (i--) { - Node *n = gnode(h, i); - if (!ttisnil(gval(n)) && /* non-empty entry? */ - (iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) { - setnilvalue(gval(n)); /* remove value ... */ - removeentry(n); /* remove entry from table */ - } - } - l = h->gclist; - } -} - - -static void freeobj (lua_State *L, GCObject *o) { - switch (o->gch.tt) { - case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; - case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; - case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; - case LUA_TTABLE: luaH_free(L, gco2h(o)); break; - case LUA_TTHREAD: { - lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread); - luaE_freethread(L, gco2th(o)); - break; - } - case LUA_TSTRING: { - G(L)->strt.nuse--; - luaM_freemem(L, o, sizestring(gco2ts(o))); - break; - } - case LUA_TUSERDATA: { - luaM_freemem(L, o, sizeudata(gco2u(o))); - break; - } - default: lua_assert(0); - } -} - - - -#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM) - - -static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { - GCObject *curr; - global_State *g = G(L); - int deadmask = otherwhite(g); - while ((curr = *p) != NULL && count-- > 0) { - if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */ - sweepwholelist(L, &gco2th(curr)->openupval); - if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */ - lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT)); - makewhite(g, curr); /* make it white (for next cycle) */ - p = &curr->gch.next; - } - else { /* must erase `curr' */ - lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); - *p = curr->gch.next; - if (curr == g->rootgc) /* is the first element of the list? */ - g->rootgc = curr->gch.next; /* adjust first */ - freeobj(L, curr); - } - } - return p; -} - - -static void checkSizes (lua_State *L) { - global_State *g = G(L); - /* check size of string hash */ - if (g->strt.nuse < cast(lu_int32, g->strt.size/4) && - g->strt.size > MINSTRTABSIZE*2) - luaS_resize(L, g->strt.size/2); /* table is too big */ - /* check size of buffer */ - if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */ - size_t newsize = luaZ_sizebuffer(&g->buff) / 2; - luaZ_resizebuffer(L, &g->buff, newsize); - } -} - - -static void GCTM (lua_State *L) { - global_State *g = G(L); - GCObject *o = g->tmudata->gch.next; /* get first element */ - Udata *udata = rawgco2u(o); - const TValue *tm; - /* remove udata from `tmudata' */ - if (o == g->tmudata) /* last element? */ - g->tmudata = NULL; - else - g->tmudata->gch.next = udata->uv.next; - udata->uv.next = g->mainthread->next; /* return it to `root' list */ - g->mainthread->next = o; - makewhite(g, o); - tm = fasttm(L, udata->uv.metatable, TM_GC); - if (tm != NULL) { - lu_byte oldah = L->allowhook; - lu_mem oldt = g->GCthreshold; - L->allowhook = 0; /* stop debug hooks during GC tag method */ - g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ - setobj2s(L, L->top, tm); - setuvalue(L, L->top+1, udata); - L->top += 2; - luaD_call(L, L->top - 2, 0); - L->allowhook = oldah; /* restore hooks */ - g->GCthreshold = oldt; /* restore threshold */ - } -} - - -/* -** Call all GC tag methods -*/ -void luaC_callGCTM (lua_State *L) { - while (G(L)->tmudata) - GCTM(L); -} - - -void luaC_freeall (lua_State *L) { - global_State *g = G(L); - int i; - g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */ - sweepwholelist(L, &g->rootgc); - for (i = 0; i < g->strt.size; i++) /* free all string lists */ - sweepwholelist(L, &g->strt.hash[i]); -} - - -static void markmt (global_State *g) { - int i; - for (i=0; imt[i]) markobject(g, g->mt[i]); -} - - -/* mark root set */ -static void markroot (lua_State *L) { - global_State *g = G(L); - g->gray = NULL; - g->grayagain = NULL; - g->weak = NULL; - markobject(g, g->mainthread); - /* make global table be traversed before main stack */ - markvalue(g, gt(g->mainthread)); - markvalue(g, registry(L)); - markmt(g); - g->gcstate = GCSpropagate; -} - - -static void remarkupvals (global_State *g) { - UpVal *uv; - for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) { - lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); - if (isgray(obj2gco(uv))) - markvalue(g, uv->v); - } -} - - -static void atomic (lua_State *L) { - global_State *g = G(L); - size_t udsize; /* total size of userdata to be finalized */ - /* remark occasional upvalues of (maybe) dead threads */ - remarkupvals(g); - /* traverse objects cautch by write barrier and by 'remarkupvals' */ - propagateall(g); - /* remark weak tables */ - g->gray = g->weak; - g->weak = NULL; - lua_assert(!iswhite(obj2gco(g->mainthread))); - markobject(g, L); /* mark running thread */ - markmt(g); /* mark basic metatables (again) */ - propagateall(g); - /* remark gray again */ - g->gray = g->grayagain; - g->grayagain = NULL; - propagateall(g); - udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */ - marktmu(g); /* mark `preserved' userdata */ - udsize += propagateall(g); /* remark, to propagate `preserveness' */ - cleartable(g->weak); /* remove collected objects from weak tables */ - /* flip current white */ - g->currentwhite = cast_byte(otherwhite(g)); - g->sweepstrgc = 0; - g->sweepgc = &g->rootgc; - g->gcstate = GCSsweepstring; - g->estimate = g->totalbytes - udsize; /* first estimate */ -} - - -static l_mem singlestep (lua_State *L) { - global_State *g = G(L); - /*lua_checkmemory(L);*/ - switch (g->gcstate) { - case GCSpause: { - markroot(L); /* start a new collection */ - return 0; - } - case GCSpropagate: { - if (g->gray) - return propagatemark(g); - else { /* no more `gray' objects */ - atomic(L); /* finish mark phase */ - return 0; - } - } - case GCSsweepstring: { - lu_mem old = g->totalbytes; - sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); - if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */ - g->gcstate = GCSsweep; /* end sweep-string phase */ - lua_assert(old >= g->totalbytes); - g->estimate -= old - g->totalbytes; - return GCSWEEPCOST; - } - case GCSsweep: { - lu_mem old = g->totalbytes; - g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); - if (*g->sweepgc == NULL) { /* nothing more to sweep? */ - checkSizes(L); - g->gcstate = GCSfinalize; /* end sweep phase */ - } - lua_assert(old >= g->totalbytes); - g->estimate -= old - g->totalbytes; - return GCSWEEPMAX*GCSWEEPCOST; - } - case GCSfinalize: { - if (g->tmudata) { - GCTM(L); - if (g->estimate > GCFINALIZECOST) - g->estimate -= GCFINALIZECOST; - return GCFINALIZECOST; - } - else { - g->gcstate = GCSpause; /* end collection */ - g->gcdept = 0; - return 0; - } - } - default: lua_assert(0); return 0; - } -} - - -void luaC_step (lua_State *L) { - global_State *g = G(L); - l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul; - if (lim == 0) - lim = (MAX_LUMEM-1)/2; /* no limit */ - g->gcdept += g->totalbytes - g->GCthreshold; - do { - lim -= singlestep(L); - if (g->gcstate == GCSpause) - break; - } while (lim > 0); - if (g->gcstate != GCSpause) { - if (g->gcdept < GCSTEPSIZE) - g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/ - else { - g->gcdept -= GCSTEPSIZE; - g->GCthreshold = g->totalbytes; - } - } - else { - lua_assert(g->totalbytes >= g->estimate); - setthreshold(g); - } -} - - -void luaC_fullgc (lua_State *L) { - global_State *g = G(L); - if (g->gcstate <= GCSpropagate) { - /* reset sweep marks to sweep all elements (returning them to white) */ - g->sweepstrgc = 0; - g->sweepgc = &g->rootgc; - /* reset other collector lists */ - g->gray = NULL; - g->grayagain = NULL; - g->weak = NULL; - g->gcstate = GCSsweepstring; - } - lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate); - /* finish any pending sweep phase */ - while (g->gcstate != GCSfinalize) { - lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep); - singlestep(L); - } - markroot(L); - while (g->gcstate != GCSpause) { - singlestep(L); - } - setthreshold(g); -} - - -void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) { - global_State *g = G(L); - lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); - lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); - lua_assert(ttype(&o->gch) != LUA_TTABLE); - /* must keep invariant? */ - if (g->gcstate == GCSpropagate) - reallymarkobject(g, v); /* restore invariant */ - else /* don't mind */ - makewhite(g, o); /* mark as white just to avoid other barriers */ -} - - -void luaC_barrierback (lua_State *L, Table *t) { - global_State *g = G(L); - GCObject *o = obj2gco(t); - lua_assert(isblack(o) && !isdead(g, o)); - lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); - black2gray(o); /* make table gray (again) */ - t->gclist = g->grayagain; - g->grayagain = o; -} - - -void luaC_link (lua_State *L, GCObject *o, lu_byte tt) { - global_State *g = G(L); - o->gch.next = g->rootgc; - g->rootgc = o; - o->gch.marked = luaC_white(g); - o->gch.tt = tt; -} - - -void luaC_linkupval (lua_State *L, UpVal *uv) { - global_State *g = G(L); - GCObject *o = obj2gco(uv); - o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */ - g->rootgc = o; - if (isgray(o)) { - if (g->gcstate == GCSpropagate) { - gray2black(o); /* closed upvalues need barrier */ - luaC_barrier(L, uv, uv->v); - } - else { /* sweep phase: sweep it (turning it into white) */ - makewhite(g, o); - lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause); - } - } -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/linit.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/linit.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/linit.c @@ -1,38 +0,0 @@ -/* -** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ -** Initialization of libraries for lua.c -** See Copyright Notice in lua.h -*/ - - -#define linit_c -#define LUA_LIB - -#include "lua.h" - -#include "lualib.h" -#include "lauxlib.h" - - -static const luaL_Reg lualibs[] = { - {"", luaopen_base}, - {LUA_LOADLIBNAME, luaopen_package}, - {LUA_TABLIBNAME, luaopen_table}, - {LUA_IOLIBNAME, luaopen_io}, - {LUA_OSLIBNAME, luaopen_os}, - {LUA_STRLIBNAME, luaopen_string}, - {LUA_MATHLIBNAME, luaopen_math}, - {LUA_DBLIBNAME, luaopen_debug}, - {NULL, NULL} -}; - - -LUALIB_API void luaL_openlibs (lua_State *L) { - const luaL_Reg *lib = lualibs; - for (; lib->func; lib++) { - lua_pushcfunction(L, lib->func); - lua_pushstring(L, lib->name); - lua_call(L, 1, 0); - } -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/liolib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/liolib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/liolib.c @@ -1,553 +0,0 @@ -/* -** $Id: liolib.c,v 2.73.1.3 2008/01/18 17:47:43 roberto Exp $ -** Standard I/O (and system) library -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include -#include - -#define liolib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - - -#define IO_INPUT 1 -#define IO_OUTPUT 2 - - -static const char *const fnames[] = {"input", "output"}; - - -static int pushresult (lua_State *L, int i, const char *filename) { - int en = errno; /* calls to Lua API may change this value */ - if (i) { - lua_pushboolean(L, 1); - return 1; - } - else { - lua_pushnil(L); - if (filename) - lua_pushfstring(L, "%s: %s", filename, strerror(en)); - else - lua_pushfstring(L, "%s", strerror(en)); - lua_pushinteger(L, en); - return 3; - } -} - - -static void fileerror (lua_State *L, int arg, const char *filename) { - lua_pushfstring(L, "%s: %s", filename, strerror(errno)); - luaL_argerror(L, arg, lua_tostring(L, -1)); -} - - -#define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) - - -static int io_type (lua_State *L) { - void *ud; - luaL_checkany(L, 1); - ud = lua_touserdata(L, 1); - lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); - if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) - lua_pushnil(L); /* not a file */ - else if (*((FILE **)ud) == NULL) - lua_pushliteral(L, "closed file"); - else - lua_pushliteral(L, "file"); - return 1; -} - - -static FILE *tofile (lua_State *L) { - FILE **f = tofilep(L); - if (*f == NULL) - luaL_error(L, "attempt to use a closed file"); - return *f; -} - - - -/* -** When creating file handles, always creates a `closed' file handle -** before opening the actual file; so, if there is a memory error, the -** file is not left opened. -*/ -static FILE **newfile (lua_State *L) { - FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); - *pf = NULL; /* file handle is currently `closed' */ - luaL_getmetatable(L, LUA_FILEHANDLE); - lua_setmetatable(L, -2); - return pf; -} - - -/* -** function to (not) close the standard files stdin, stdout, and stderr -*/ -static int io_noclose (lua_State *L) { - lua_pushnil(L); - lua_pushliteral(L, "cannot close standard file"); - return 2; -} - - -/* -** function to close 'popen' files -*/ -static int io_pclose (lua_State *L) { - FILE **p = tofilep(L); - int ok = lua_pclose(L, *p); - *p = NULL; - return pushresult(L, ok, NULL); -} - - -/* -** function to close regular files -*/ -static int io_fclose (lua_State *L) { - FILE **p = tofilep(L); - int ok = (fclose(*p) == 0); - *p = NULL; - return pushresult(L, ok, NULL); -} - - -static int aux_close (lua_State *L) { - lua_getfenv(L, 1); - lua_getfield(L, -1, "__close"); - return (lua_tocfunction(L, -1))(L); -} - - -static int io_close (lua_State *L) { - if (lua_isnone(L, 1)) - lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); - tofile(L); /* make sure argument is a file */ - return aux_close(L); -} - - -static int io_gc (lua_State *L) { - FILE *f = *tofilep(L); - /* ignore closed files */ - if (f != NULL) - aux_close(L); - return 0; -} - - -static int io_tostring (lua_State *L) { - FILE *f = *tofilep(L); - if (f == NULL) - lua_pushliteral(L, "file (closed)"); - else - lua_pushfstring(L, "file (%p)", f); - return 1; -} - - -static int io_open (lua_State *L) { - const char *filename = luaL_checkstring(L, 1); - const char *mode = luaL_optstring(L, 2, "r"); - FILE **pf = newfile(L); - *pf = fopen(filename, mode); - return (*pf == NULL) ? pushresult(L, 0, filename) : 1; -} - - -/* -** this function has a separated environment, which defines the -** correct __close for 'popen' files -*/ -static int io_popen (lua_State *L) { - const char *filename = luaL_checkstring(L, 1); - const char *mode = luaL_optstring(L, 2, "r"); - FILE **pf = newfile(L); - *pf = lua_popen(L, filename, mode); - return (*pf == NULL) ? pushresult(L, 0, filename) : 1; -} - - -static int io_tmpfile (lua_State *L) { - FILE **pf = newfile(L); - *pf = tmpfile(); - return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; -} - - -static FILE *getiofile (lua_State *L, int findex) { - FILE *f; - lua_rawgeti(L, LUA_ENVIRONINDEX, findex); - f = *(FILE **)lua_touserdata(L, -1); - if (f == NULL) - luaL_error(L, "standard %s file is closed", fnames[findex - 1]); - return f; -} - - -static int g_iofile (lua_State *L, int f, const char *mode) { - if (!lua_isnoneornil(L, 1)) { - const char *filename = lua_tostring(L, 1); - if (filename) { - FILE **pf = newfile(L); - *pf = fopen(filename, mode); - if (*pf == NULL) - fileerror(L, 1, filename); - } - else { - tofile(L); /* check that it's a valid file handle */ - lua_pushvalue(L, 1); - } - lua_rawseti(L, LUA_ENVIRONINDEX, f); - } - /* return current value */ - lua_rawgeti(L, LUA_ENVIRONINDEX, f); - return 1; -} - - -static int io_input (lua_State *L) { - return g_iofile(L, IO_INPUT, "r"); -} - - -static int io_output (lua_State *L) { - return g_iofile(L, IO_OUTPUT, "w"); -} - - -static int io_readline (lua_State *L); - - -static void aux_lines (lua_State *L, int idx, int toclose) { - lua_pushvalue(L, idx); - lua_pushboolean(L, toclose); /* close/not close file when finished */ - lua_pushcclosure(L, io_readline, 2); -} - - -static int f_lines (lua_State *L) { - tofile(L); /* check that it's a valid file handle */ - aux_lines(L, 1, 0); - return 1; -} - - -static int io_lines (lua_State *L) { - if (lua_isnoneornil(L, 1)) { /* no arguments? */ - /* will iterate over default input */ - lua_rawgeti(L, LUA_ENVIRONINDEX, IO_INPUT); - return f_lines(L); - } - else { - const char *filename = luaL_checkstring(L, 1); - FILE **pf = newfile(L); - *pf = fopen(filename, "r"); - if (*pf == NULL) - fileerror(L, 1, filename); - aux_lines(L, lua_gettop(L), 1); - return 1; - } -} - - -/* -** {====================================================== -** READ -** ======================================================= -*/ - - -static int read_number (lua_State *L, FILE *f) { - lua_Number d; - if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { - lua_pushnumber(L, d); - return 1; - } - else return 0; /* read fails */ -} - - -static int test_eof (lua_State *L, FILE *f) { - int c = getc(f); - ungetc(c, f); - lua_pushlstring(L, NULL, 0); - return (c != EOF); -} - - -static int read_line (lua_State *L, FILE *f) { - luaL_Buffer b; - luaL_buffinit(L, &b); - for (;;) { - size_t l; - char *p = luaL_prepbuffer(&b); - if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */ - luaL_pushresult(&b); /* close buffer */ - return (lua_objlen(L, -1) > 0); /* check whether read something */ - } - l = strlen(p); - if (l == 0 || p[l-1] != '\n') - luaL_addsize(&b, l); - else { - luaL_addsize(&b, l - 1); /* do not include `eol' */ - luaL_pushresult(&b); /* close buffer */ - return 1; /* read at least an `eol' */ - } - } -} - - -static int read_chars (lua_State *L, FILE *f, size_t n) { - size_t rlen; /* how much to read */ - size_t nr; /* number of chars actually read */ - luaL_Buffer b; - luaL_buffinit(L, &b); - rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ - do { - char *p = luaL_prepbuffer(&b); - if (rlen > n) rlen = n; /* cannot read more than asked */ - nr = fread(p, sizeof(char), rlen, f); - luaL_addsize(&b, nr); - n -= nr; /* still have to read `n' chars */ - } while (n > 0 && nr == rlen); /* until end of count or eof */ - luaL_pushresult(&b); /* close buffer */ - return (n == 0 || lua_objlen(L, -1) > 0); -} - - -static int g_read (lua_State *L, FILE *f, int first) { - int nargs = lua_gettop(L) - 1; - int success; - int n; - clearerr(f); - if (nargs == 0) { /* no arguments? */ - success = read_line(L, f); - n = first+1; /* to return 1 result */ - } - else { /* ensure stack space for all results and for auxlib's buffer */ - luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); - success = 1; - for (n = first; nargs-- && success; n++) { - if (lua_type(L, n) == LUA_TNUMBER) { - size_t l = (size_t)lua_tointeger(L, n); - success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); - } - else { - const char *p = lua_tostring(L, n); - luaL_argcheck(L, p && p[0] == '*', n, "invalid option"); - switch (p[1]) { - case 'n': /* number */ - success = read_number(L, f); - break; - case 'l': /* line */ - success = read_line(L, f); - break; - case 'a': /* file */ - read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ - success = 1; /* always success */ - break; - default: - return luaL_argerror(L, n, "invalid format"); - } - } - } - } - if (ferror(f)) - return pushresult(L, 0, NULL); - if (!success) { - lua_pop(L, 1); /* remove last result */ - lua_pushnil(L); /* push nil instead */ - } - return n - first; -} - - -static int io_read (lua_State *L) { - return g_read(L, getiofile(L, IO_INPUT), 1); -} - - -static int f_read (lua_State *L) { - return g_read(L, tofile(L), 2); -} - - -static int io_readline (lua_State *L) { - FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1)); - int sucess; - if (f == NULL) /* file is already closed? */ - luaL_error(L, "file is already closed"); - sucess = read_line(L, f); - if (ferror(f)) - return luaL_error(L, "%s", strerror(errno)); - if (sucess) return 1; - else { /* EOF */ - if (lua_toboolean(L, lua_upvalueindex(2))) { /* generator created file? */ - lua_settop(L, 0); - lua_pushvalue(L, lua_upvalueindex(1)); - aux_close(L); /* close it */ - } - return 0; - } -} - -/* }====================================================== */ - - -static int g_write (lua_State *L, FILE *f, int arg) { - int nargs = lua_gettop(L) - 1; - int status = 1; - for (; nargs--; arg++) { - if (lua_type(L, arg) == LUA_TNUMBER) { - /* optimization: could be done exactly as for strings */ - status = status && - fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; - } - else { - size_t l; - const char *s = luaL_checklstring(L, arg, &l); - status = status && (fwrite(s, sizeof(char), l, f) == l); - } - } - return pushresult(L, status, NULL); -} - - -static int io_write (lua_State *L) { - return g_write(L, getiofile(L, IO_OUTPUT), 1); -} - - -static int f_write (lua_State *L) { - return g_write(L, tofile(L), 2); -} - - -static int f_seek (lua_State *L) { - static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; - static const char *const modenames[] = {"set", "cur", "end", NULL}; - FILE *f = tofile(L); - int op = luaL_checkoption(L, 2, "cur", modenames); - long offset = luaL_optlong(L, 3, 0); - op = fseek(f, offset, mode[op]); - if (op) - return pushresult(L, 0, NULL); /* error */ - else { - lua_pushinteger(L, ftell(f)); - return 1; - } -} - - -static int f_setvbuf (lua_State *L) { - static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; - static const char *const modenames[] = {"no", "full", "line", NULL}; - FILE *f = tofile(L); - int op = luaL_checkoption(L, 2, NULL, modenames); - lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); - int res = setvbuf(f, NULL, mode[op], sz); - return pushresult(L, res == 0, NULL); -} - - - -static int io_flush (lua_State *L) { - return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); -} - - -static int f_flush (lua_State *L) { - return pushresult(L, fflush(tofile(L)) == 0, NULL); -} - - -static const luaL_Reg iolib[] = { - {"close", io_close}, - {"flush", io_flush}, - {"input", io_input}, - {"lines", io_lines}, - {"open", io_open}, - {"output", io_output}, - {"popen", io_popen}, - {"read", io_read}, - {"tmpfile", io_tmpfile}, - {"type", io_type}, - {"write", io_write}, - {NULL, NULL} -}; - - -static const luaL_Reg flib[] = { - {"close", io_close}, - {"flush", f_flush}, - {"lines", f_lines}, - {"read", f_read}, - {"seek", f_seek}, - {"setvbuf", f_setvbuf}, - {"write", f_write}, - {"__gc", io_gc}, - {"__tostring", io_tostring}, - {NULL, NULL} -}; - - -static void createmeta (lua_State *L) { - luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ - lua_pushvalue(L, -1); /* push metatable */ - lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ - luaL_register(L, NULL, flib); /* file methods */ -} - - -static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) { - *newfile(L) = f; - if (k > 0) { - lua_pushvalue(L, -1); - lua_rawseti(L, LUA_ENVIRONINDEX, k); - } - lua_pushvalue(L, -2); /* copy environment */ - lua_setfenv(L, -2); /* set it */ - lua_setfield(L, -3, fname); -} - - -static void newfenv (lua_State *L, lua_CFunction cls) { - lua_createtable(L, 0, 1); - lua_pushcfunction(L, cls); - lua_setfield(L, -2, "__close"); -} - - -LUALIB_API int luaopen_io (lua_State *L) { - createmeta(L); - /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ - newfenv(L, io_fclose); - lua_replace(L, LUA_ENVIRONINDEX); - /* open library */ - luaL_register(L, LUA_IOLIBNAME, iolib); - /* create (and set) default files */ - newfenv(L, io_noclose); /* close function for default files */ - createstdfile(L, stdin, IO_INPUT, "stdin"); - createstdfile(L, stdout, IO_OUTPUT, "stdout"); - createstdfile(L, stderr, 0, "stderr"); - lua_pop(L, 1); /* pop environment for default files */ - lua_getfield(L, -1, "popen"); - newfenv(L, io_pclose); /* create environment for 'popen' */ - lua_setfenv(L, -2); /* set fenv for 'popen' */ - lua_pop(L, 1); /* pop 'popen' */ - return 1; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llex.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llex.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llex.h @@ -1,81 +0,0 @@ -/* -** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ -** Lexical Analyzer -** See Copyright Notice in lua.h -*/ - -#ifndef llex_h -#define llex_h - -#include "lobject.h" -#include "lzio.h" - - -#define FIRST_RESERVED 257 - -/* maximum length of a reserved word */ -#define TOKEN_LEN (sizeof("function")/sizeof(char)) - - -/* -* WARNING: if you change the order of this enumeration, -* grep "ORDER RESERVED" -*/ -enum RESERVED { - /* terminal symbols denoted by reserved words */ - TK_AND = FIRST_RESERVED, TK_BREAK, - TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, - TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, - TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, - /* other terminal symbols */ - TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, - TK_NAME, TK_STRING, TK_EOS -}; - -/* number of reserved words */ -#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) - - -/* array with token `names' */ -LUAI_DATA const char *const luaX_tokens []; - - -typedef union { - lua_Number r; - TString *ts; -} SemInfo; /* semantics information */ - - -typedef struct Token { - int token; - SemInfo seminfo; -} Token; - - -typedef struct LexState { - int current; /* current character (charint) */ - int linenumber; /* input line counter */ - int lastline; /* line of last token `consumed' */ - Token t; /* current token */ - Token lookahead; /* look ahead token */ - struct FuncState *fs; /* `FuncState' is private to the parser */ - struct lua_State *L; - ZIO *z; /* input stream */ - Mbuffer *buff; /* buffer for tokens */ - TString *source; /* current source name */ - char decpoint; /* locale decimal point */ -} LexState; - - -LUAI_FUNC void luaX_init (lua_State *L); -LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, - TString *source); -LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); -LUAI_FUNC void luaX_next (LexState *ls); -LUAI_FUNC void luaX_lookahead (LexState *ls); -LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); -LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); -LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llex.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llex.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llex.c @@ -1,461 +0,0 @@ -/* -** $Id: llex.c,v 2.20.1.1 2007/12/27 13:02:25 roberto Exp $ -** Lexical Analyzer -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include - -#define llex_c -#define LUA_CORE - -#include "lua.h" - -#include "ldo.h" -#include "llex.h" -#include "lobject.h" -#include "lparser.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "lzio.h" - - - -#define next(ls) (ls->current = zgetc(ls->z)) - - - - -#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') - - -/* ORDER RESERVED */ -const char *const luaX_tokens [] = { - "and", "break", "do", "else", "elseif", - "end", "false", "for", "function", "if", - "in", "local", "nil", "not", "or", "repeat", - "return", "then", "true", "until", "while", - "..", "...", "==", ">=", "<=", "~=", - "", "", "", "", - NULL -}; - - -#define save_and_next(ls) (save(ls, ls->current), next(ls)) - - -static void save (LexState *ls, int c) { - Mbuffer *b = ls->buff; - if (b->n + 1 > b->buffsize) { - size_t newsize; - if (b->buffsize >= MAX_SIZET/2) - luaX_lexerror(ls, "lexical element too long", 0); - newsize = b->buffsize * 2; - luaZ_resizebuffer(ls->L, b, newsize); - } - b->buffer[b->n++] = cast(char, c); -} - - -void luaX_init (lua_State *L) { - int i; - for (i=0; itsv.reserved = cast_byte(i+1); /* reserved word */ - } -} - - -#define MAXSRC 80 - - -const char *luaX_token2str (LexState *ls, int token) { - if (token < FIRST_RESERVED) { - lua_assert(token == cast(unsigned char, token)); - return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : - luaO_pushfstring(ls->L, "%c", token); - } - else - return luaX_tokens[token-FIRST_RESERVED]; -} - - -static const char *txtToken (LexState *ls, int token) { - switch (token) { - case TK_NAME: - case TK_STRING: - case TK_NUMBER: - save(ls, '\0'); - return luaZ_buffer(ls->buff); - default: - return luaX_token2str(ls, token); - } -} - - -void luaX_lexerror (LexState *ls, const char *msg, int token) { - char buff[MAXSRC]; - luaO_chunkid(buff, getstr(ls->source), MAXSRC); - msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); - if (token) - luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); - luaD_throw(ls->L, LUA_ERRSYNTAX); -} - - -void luaX_syntaxerror (LexState *ls, const char *msg) { - luaX_lexerror(ls, msg, ls->t.token); -} - - -TString *luaX_newstring (LexState *ls, const char *str, size_t l) { - lua_State *L = ls->L; - TString *ts = luaS_newlstr(L, str, l); - TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ - if (ttisnil(o)) - setbvalue(o, 1); /* make sure `str' will not be collected */ - return ts; -} - - -static void inclinenumber (LexState *ls) { - int old = ls->current; - lua_assert(currIsNewline(ls)); - next(ls); /* skip `\n' or `\r' */ - if (currIsNewline(ls) && ls->current != old) - next(ls); /* skip `\n\r' or `\r\n' */ - if (++ls->linenumber >= MAX_INT) - luaX_syntaxerror(ls, "chunk has too many lines"); -} - - -void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { - ls->decpoint = '.'; - ls->L = L; - ls->lookahead.token = TK_EOS; /* no look-ahead token */ - ls->z = z; - ls->fs = NULL; - ls->linenumber = 1; - ls->lastline = 1; - ls->source = source; - luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ - next(ls); /* read first char */ -} - - - -/* -** ======================================================= -** LEXICAL ANALYZER -** ======================================================= -*/ - - - -static int check_next (LexState *ls, const char *set) { - if (!strchr(set, ls->current)) - return 0; - save_and_next(ls); - return 1; -} - - -static void buffreplace (LexState *ls, char from, char to) { - size_t n = luaZ_bufflen(ls->buff); - char *p = luaZ_buffer(ls->buff); - while (n--) - if (p[n] == from) p[n] = to; -} - - -static void trydecpoint (LexState *ls, SemInfo *seminfo) { - /* format error: try to update decimal point separator */ - struct lconv *cv = localeconv(); - char old = ls->decpoint; - ls->decpoint = (cv ? cv->decimal_point[0] : '.'); - buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */ - if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { - /* format error with correct decimal point: no more options */ - buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ - luaX_lexerror(ls, "malformed number", TK_NUMBER); - } -} - - -/* LUA_NUMBER */ -static void read_numeral (LexState *ls, SemInfo *seminfo) { - lua_assert(isdigit(ls->current)); - do { - save_and_next(ls); - } while (isdigit(ls->current) || ls->current == '.'); - if (check_next(ls, "Ee")) /* `E'? */ - check_next(ls, "+-"); /* optional exponent sign */ - while (isalnum(ls->current) || ls->current == '_') - save_and_next(ls); - save(ls, '\0'); - buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ - if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ - trydecpoint(ls, seminfo); /* try to update decimal point separator */ -} - - -static int skip_sep (LexState *ls) { - int count = 0; - int s = ls->current; - lua_assert(s == '[' || s == ']'); - save_and_next(ls); - while (ls->current == '=') { - save_and_next(ls); - count++; - } - return (ls->current == s) ? count : (-count) - 1; -} - - -static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { - int cont = 0; - (void)(cont); /* avoid warnings when `cont' is not used */ - save_and_next(ls); /* skip 2nd `[' */ - if (currIsNewline(ls)) /* string starts with a newline? */ - inclinenumber(ls); /* skip it */ - for (;;) { - switch (ls->current) { - case EOZ: - luaX_lexerror(ls, (seminfo) ? "unfinished long string" : - "unfinished long comment", TK_EOS); - break; /* to avoid warnings */ -#if defined(LUA_COMPAT_LSTR) - case '[': { - if (skip_sep(ls) == sep) { - save_and_next(ls); /* skip 2nd `[' */ - cont++; -#if LUA_COMPAT_LSTR == 1 - if (sep == 0) - luaX_lexerror(ls, "nesting of [[...]] is deprecated", '['); -#endif - } - break; - } -#endif - case ']': { - if (skip_sep(ls) == sep) { - save_and_next(ls); /* skip 2nd `]' */ -#if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2 - cont--; - if (sep == 0 && cont >= 0) break; -#endif - goto endloop; - } - break; - } - case '\n': - case '\r': { - save(ls, '\n'); - inclinenumber(ls); - if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ - break; - } - default: { - if (seminfo) save_and_next(ls); - else next(ls); - } - } - } endloop: - if (seminfo) - seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), - luaZ_bufflen(ls->buff) - 2*(2 + sep)); -} - - -static void read_string (LexState *ls, int del, SemInfo *seminfo) { - save_and_next(ls); - while (ls->current != del) { - switch (ls->current) { - case EOZ: - luaX_lexerror(ls, "unfinished string", TK_EOS); - continue; /* to avoid warnings */ - case '\n': - case '\r': - luaX_lexerror(ls, "unfinished string", TK_STRING); - continue; /* to avoid warnings */ - case '\\': { - int c; - next(ls); /* do not save the `\' */ - switch (ls->current) { - case 'a': c = '\a'; break; - case 'b': c = '\b'; break; - case 'f': c = '\f'; break; - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'v': c = '\v'; break; - case '\n': /* go through */ - case '\r': save(ls, '\n'); inclinenumber(ls); continue; - case EOZ: continue; /* will raise an error next loop */ - default: { - if (!isdigit(ls->current)) - save_and_next(ls); /* handles \\, \", \', and \? */ - else { /* \xxx */ - int i = 0; - c = 0; - do { - c = 10*c + (ls->current-'0'); - next(ls); - } while (++i<3 && isdigit(ls->current)); - if (c > UCHAR_MAX) - luaX_lexerror(ls, "escape sequence too large", TK_STRING); - save(ls, c); - } - continue; - } - } - save(ls, c); - next(ls); - continue; - } - default: - save_and_next(ls); - } - } - save_and_next(ls); /* skip delimiter */ - seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, - luaZ_bufflen(ls->buff) - 2); -} - - -static int llex (LexState *ls, SemInfo *seminfo) { - luaZ_resetbuffer(ls->buff); - for (;;) { - switch (ls->current) { - case '\n': - case '\r': { - inclinenumber(ls); - continue; - } - case '-': { - next(ls); - if (ls->current != '-') return '-'; - /* else is a comment */ - next(ls); - if (ls->current == '[') { - int sep = skip_sep(ls); - luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ - if (sep >= 0) { - read_long_string(ls, NULL, sep); /* long comment */ - luaZ_resetbuffer(ls->buff); - continue; - } - } - /* else short comment */ - while (!currIsNewline(ls) && ls->current != EOZ) - next(ls); - continue; - } - case '[': { - int sep = skip_sep(ls); - if (sep >= 0) { - read_long_string(ls, seminfo, sep); - return TK_STRING; - } - else if (sep == -1) return '['; - else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING); - } - case '=': { - next(ls); - if (ls->current != '=') return '='; - else { next(ls); return TK_EQ; } - } - case '<': { - next(ls); - if (ls->current != '=') return '<'; - else { next(ls); return TK_LE; } - } - case '>': { - next(ls); - if (ls->current != '=') return '>'; - else { next(ls); return TK_GE; } - } - case '~': { - next(ls); - if (ls->current != '=') return '~'; - else { next(ls); return TK_NE; } - } - case '"': - case '\'': { - read_string(ls, ls->current, seminfo); - return TK_STRING; - } - case '.': { - save_and_next(ls); - if (check_next(ls, ".")) { - if (check_next(ls, ".")) - return TK_DOTS; /* ... */ - else return TK_CONCAT; /* .. */ - } - else if (!isdigit(ls->current)) return '.'; - else { - read_numeral(ls, seminfo); - return TK_NUMBER; - } - } - case EOZ: { - return TK_EOS; - } - default: { - if (isspace(ls->current)) { - lua_assert(!currIsNewline(ls)); - next(ls); - continue; - } - else if (isdigit(ls->current)) { - read_numeral(ls, seminfo); - return TK_NUMBER; - } - else if (isalpha(ls->current) || ls->current == '_') { - /* identifier or reserved word */ - TString *ts; - do { - save_and_next(ls); - } while (isalnum(ls->current) || ls->current == '_'); - ts = luaX_newstring(ls, luaZ_buffer(ls->buff), - luaZ_bufflen(ls->buff)); - if (ts->tsv.reserved > 0) /* reserved word? */ - return ts->tsv.reserved - 1 + FIRST_RESERVED; - else { - seminfo->ts = ts; - return TK_NAME; - } - } - else { - int c = ls->current; - next(ls); - return c; /* single-char tokens (+ - / ...) */ - } - } - } - } -} - - -void luaX_next (LexState *ls) { - ls->lastline = ls->linenumber; - if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ - ls->t = ls->lookahead; /* use this one */ - ls->lookahead.token = TK_EOS; /* and discharge it */ - } - else - ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ -} - - -void luaX_lookahead (LexState *ls) { - lua_assert(ls->lookahead.token == TK_EOS); - ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llimits.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llimits.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/llimits.h @@ -1,128 +0,0 @@ -/* -** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ -** Limits, basic types, and some other `installation-dependent' definitions -** See Copyright Notice in lua.h -*/ - -#ifndef llimits_h -#define llimits_h - - -#include -#include - - -#include "lua.h" - - -typedef LUAI_UINT32 lu_int32; - -typedef LUAI_UMEM lu_mem; - -typedef LUAI_MEM l_mem; - - - -/* chars used as small naturals (so that `char' is reserved for characters) */ -typedef unsigned char lu_byte; - - -#define MAX_SIZET ((size_t)(~(size_t)0)-2) - -#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) - - -#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ - -/* -** conversion of pointer to integer -** this is for hashing only; there is no problem if the integer -** cannot hold the whole pointer value -*/ -#define IntPoint(p) ((unsigned int)(lu_mem)(p)) - - - -/* type to ensure maximum alignment */ -typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; - - -/* result of a `usual argument conversion' over lua_Number */ -typedef LUAI_UACNUMBER l_uacNumber; - - -/* internal assertions for in-house debugging */ -#ifdef lua_assert - -#define check_exp(c,e) (lua_assert(c), (e)) -#define api_check(l,e) lua_assert(e) - -#else - -#define lua_assert(c) ((void)0) -#define check_exp(c,e) (e) -#define api_check luai_apicheck - -#endif - - -#ifndef UNUSED -#define UNUSED(x) ((void)(x)) /* to avoid warnings */ -#endif - - -#ifndef cast -#define cast(t, exp) ((t)(exp)) -#endif - -#define cast_byte(i) cast(lu_byte, (i)) -#define cast_num(i) cast(lua_Number, (i)) -#define cast_int(i) cast(int, (i)) - - - -/* -** type for virtual-machine instructions -** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) -*/ -typedef lu_int32 Instruction; - - - -/* maximum stack for a Lua function */ -#define MAXSTACK 250 - - - -/* minimum size for the string table (must be power of 2) */ -#ifndef MINSTRTABSIZE -#define MINSTRTABSIZE 32 -#endif - - -/* minimum size for string buffer */ -#ifndef LUA_MINBUFFER -#define LUA_MINBUFFER 32 -#endif - - -#ifndef lua_lock -#define lua_lock(L) ((void) 0) -#define lua_unlock(L) ((void) 0) -#endif - -#ifndef luai_threadyield -#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} -#endif - - -/* -** macro to control inclusion of some hard tests on stack reallocation -*/ -#ifndef HARDSTACKTESTS -#define condhardstacktests(x) ((void)0) -#else -#define condhardstacktests(x) x -#endif - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmathlib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmathlib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmathlib.c @@ -1,263 +0,0 @@ -/* -** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ -** Standard mathematical library -** See Copyright Notice in lua.h -*/ - - -#include -#include - -#define lmathlib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - -#undef PI -#define PI (3.14159265358979323846) -#define RADIANS_PER_DEGREE (PI/180.0) - - - -static int math_abs (lua_State *L) { - lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); - return 1; -} - -static int math_sin (lua_State *L) { - lua_pushnumber(L, sin(luaL_checknumber(L, 1))); - return 1; -} - -static int math_sinh (lua_State *L) { - lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); - return 1; -} - -static int math_cos (lua_State *L) { - lua_pushnumber(L, cos(luaL_checknumber(L, 1))); - return 1; -} - -static int math_cosh (lua_State *L) { - lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); - return 1; -} - -static int math_tan (lua_State *L) { - lua_pushnumber(L, tan(luaL_checknumber(L, 1))); - return 1; -} - -static int math_tanh (lua_State *L) { - lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); - return 1; -} - -static int math_asin (lua_State *L) { - lua_pushnumber(L, asin(luaL_checknumber(L, 1))); - return 1; -} - -static int math_acos (lua_State *L) { - lua_pushnumber(L, acos(luaL_checknumber(L, 1))); - return 1; -} - -static int math_atan (lua_State *L) { - lua_pushnumber(L, atan(luaL_checknumber(L, 1))); - return 1; -} - -static int math_atan2 (lua_State *L) { - lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); - return 1; -} - -static int math_ceil (lua_State *L) { - lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); - return 1; -} - -static int math_floor (lua_State *L) { - lua_pushnumber(L, floor(luaL_checknumber(L, 1))); - return 1; -} - -static int math_fmod (lua_State *L) { - lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); - return 1; -} - -static int math_modf (lua_State *L) { - double ip; - double fp = modf(luaL_checknumber(L, 1), &ip); - lua_pushnumber(L, ip); - lua_pushnumber(L, fp); - return 2; -} - -static int math_sqrt (lua_State *L) { - lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); - return 1; -} - -static int math_pow (lua_State *L) { - lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); - return 1; -} - -static int math_log (lua_State *L) { - lua_pushnumber(L, log(luaL_checknumber(L, 1))); - return 1; -} - -static int math_log10 (lua_State *L) { - lua_pushnumber(L, log10(luaL_checknumber(L, 1))); - return 1; -} - -static int math_exp (lua_State *L) { - lua_pushnumber(L, exp(luaL_checknumber(L, 1))); - return 1; -} - -static int math_deg (lua_State *L) { - lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); - return 1; -} - -static int math_rad (lua_State *L) { - lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); - return 1; -} - -static int math_frexp (lua_State *L) { - int e; - lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); - lua_pushinteger(L, e); - return 2; -} - -static int math_ldexp (lua_State *L) { - lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); - return 1; -} - - - -static int math_min (lua_State *L) { - int n = lua_gettop(L); /* number of arguments */ - lua_Number dmin = luaL_checknumber(L, 1); - int i; - for (i=2; i<=n; i++) { - lua_Number d = luaL_checknumber(L, i); - if (d < dmin) - dmin = d; - } - lua_pushnumber(L, dmin); - return 1; -} - - -static int math_max (lua_State *L) { - int n = lua_gettop(L); /* number of arguments */ - lua_Number dmax = luaL_checknumber(L, 1); - int i; - for (i=2; i<=n; i++) { - lua_Number d = luaL_checknumber(L, i); - if (d > dmax) - dmax = d; - } - lua_pushnumber(L, dmax); - return 1; -} - - -static int math_random (lua_State *L) { - /* the `%' avoids the (rare) case of r==1, and is needed also because on - some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ - lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; - switch (lua_gettop(L)) { /* check number of arguments */ - case 0: { /* no arguments */ - lua_pushnumber(L, r); /* Number between 0 and 1 */ - break; - } - case 1: { /* only upper limit */ - int u = luaL_checkint(L, 1); - luaL_argcheck(L, 1<=u, 1, "interval is empty"); - lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ - break; - } - case 2: { /* lower and upper limits */ - int l = luaL_checkint(L, 1); - int u = luaL_checkint(L, 2); - luaL_argcheck(L, l<=u, 2, "interval is empty"); - lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ - break; - } - default: return luaL_error(L, "wrong number of arguments"); - } - return 1; -} - - -static int math_randomseed (lua_State *L) { - srand(luaL_checkint(L, 1)); - return 0; -} - - -static const luaL_Reg mathlib[] = { - {"abs", math_abs}, - {"acos", math_acos}, - {"asin", math_asin}, - {"atan2", math_atan2}, - {"atan", math_atan}, - {"ceil", math_ceil}, - {"cosh", math_cosh}, - {"cos", math_cos}, - {"deg", math_deg}, - {"exp", math_exp}, - {"floor", math_floor}, - {"fmod", math_fmod}, - {"frexp", math_frexp}, - {"ldexp", math_ldexp}, - {"log10", math_log10}, - {"log", math_log}, - {"max", math_max}, - {"min", math_min}, - {"modf", math_modf}, - {"pow", math_pow}, - {"rad", math_rad}, - {"random", math_random}, - {"randomseed", math_randomseed}, - {"sinh", math_sinh}, - {"sin", math_sin}, - {"sqrt", math_sqrt}, - {"tanh", math_tanh}, - {"tan", math_tan}, - {NULL, NULL} -}; - - -/* -** Open math library -*/ -LUALIB_API int luaopen_math (lua_State *L) { - luaL_register(L, LUA_MATHLIBNAME, mathlib); - lua_pushnumber(L, PI); - lua_setfield(L, -2, "pi"); - lua_pushnumber(L, HUGE_VAL); - lua_setfield(L, -2, "huge"); -#if defined(LUA_COMPAT_MOD) - lua_getfield(L, -1, "fmod"); - lua_setfield(L, -2, "mod"); -#endif - return 1; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmem.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmem.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmem.h @@ -1,49 +0,0 @@ -/* -** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ -** Interface to Memory Manager -** See Copyright Notice in lua.h -*/ - -#ifndef lmem_h -#define lmem_h - - -#include - -#include "llimits.h" -#include "lua.h" - -#define MEMERRMSG "not enough memory" - - -#define luaM_reallocv(L,b,on,n,e) \ - ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ - luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ - luaM_toobig(L)) - -#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) -#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) -#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) - -#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) -#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) -#define luaM_newvector(L,n,t) \ - cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) - -#define luaM_growvector(L,v,nelems,size,t,limit,e) \ - if ((nelems)+1 > (size)) \ - ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) - -#define luaM_reallocvector(L, v,oldn,n,t) \ - ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) - - -LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, - size_t size); -LUAI_FUNC void *luaM_toobig (lua_State *L); -LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, - size_t size_elem, int limit, - const char *errormsg); - -#endif - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmem.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmem.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lmem.c @@ -1,86 +0,0 @@ -/* -** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ -** Interface to Memory Manager -** See Copyright Notice in lua.h -*/ - - -#include - -#define lmem_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" - - - -/* -** About the realloc function: -** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); -** (`osize' is the old size, `nsize' is the new size) -** -** Lua ensures that (ptr == NULL) iff (osize == 0). -** -** * frealloc(ud, NULL, 0, x) creates a new block of size `x' -** -** * frealloc(ud, p, x, 0) frees the block `p' -** (in this specific case, frealloc must return NULL). -** particularly, frealloc(ud, NULL, 0, 0) does nothing -** (which is equivalent to free(NULL) in ANSI C) -** -** frealloc returns NULL if it cannot create or reallocate the area -** (any reallocation to an equal or smaller size cannot fail!) -*/ - - - -#define MINSIZEARRAY 4 - - -void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, - int limit, const char *errormsg) { - void *newblock; - int newsize; - if (*size >= limit/2) { /* cannot double it? */ - if (*size >= limit) /* cannot grow even a little? */ - luaG_runerror(L, errormsg); - newsize = limit; /* still have at least one free place */ - } - else { - newsize = (*size)*2; - if (newsize < MINSIZEARRAY) - newsize = MINSIZEARRAY; /* minimum size */ - } - newblock = luaM_reallocv(L, block, *size, newsize, size_elems); - *size = newsize; /* update only when everything else is OK */ - return newblock; -} - - -void *luaM_toobig (lua_State *L) { - luaG_runerror(L, "memory allocation error: block too big"); - return NULL; /* to avoid warnings */ -} - - - -/* -** generic allocation routine. -*/ -void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { - global_State *g = G(L); - lua_assert((osize == 0) == (block == NULL)); - block = (*g->frealloc)(g->ud, block, osize, nsize); - if (block == NULL && nsize > 0) - luaD_throw(L, LUA_ERRMEM); - lua_assert((nsize == 0) == (block == NULL)); - g->totalbytes = (g->totalbytes - osize) + nsize; - return block; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/loadlib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/loadlib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/loadlib.c @@ -1,666 +0,0 @@ -/* -** $Id: loadlib.c,v 1.52.1.3 2008/08/06 13:29:28 roberto Exp $ -** Dynamic library loader for Lua -** See Copyright Notice in lua.h -** -** This module contains an implementation of loadlib for Unix systems -** that have dlfcn, an implementation for Darwin (Mac OS X), an -** implementation for Windows, and a stub for other systems. -*/ - - -#include -#include - - -#define loadlib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - -/* prefix for open functions in C libraries */ -#define LUA_POF "luaopen_" - -/* separator for open functions in C libraries */ -#define LUA_OFSEP "_" - - -#define LIBPREFIX "LOADLIB: " - -#define POF LUA_POF -#define LIB_FAIL "open" - - -/* error codes for ll_loadfunc */ -#define ERRLIB 1 -#define ERRFUNC 2 - -#define setprogdir(L) ((void)0) - - -static void ll_unloadlib (void *lib); -static void *ll_load (lua_State *L, const char *path); -static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); - - - -#if defined(LUA_DL_DLOPEN) -/* -** {======================================================================== -** This is an implementation of loadlib based on the dlfcn interface. -** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD, -** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least -** as an emulation layer on top of native functions. -** ========================================================================= -*/ - -#include - -static void ll_unloadlib (void *lib) { - dlclose(lib); -} - - -static void *ll_load (lua_State *L, const char *path) { - void *lib = dlopen(path, RTLD_NOW); - if (lib == NULL) lua_pushstring(L, dlerror()); - return lib; -} - - -static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { - lua_CFunction f = (lua_CFunction)dlsym(lib, sym); - if (f == NULL) lua_pushstring(L, dlerror()); - return f; -} - -/* }====================================================== */ - - - -#elif defined(LUA_DL_DLL) -/* -** {====================================================================== -** This is an implementation of loadlib for Windows using native functions. -** ======================================================================= -*/ - -#include - - -#undef setprogdir - -static void setprogdir (lua_State *L) { - char buff[MAX_PATH + 1]; - char *lb; - DWORD nsize = sizeof(buff)/sizeof(char); - DWORD n = GetModuleFileNameA(NULL, buff, nsize); - if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) - luaL_error(L, "unable to get ModuleFileName"); - else { - *lb = '\0'; - luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); - lua_remove(L, -2); /* remove original string */ - } -} - - -static void pusherror (lua_State *L) { - int error = GetLastError(); - char buffer[128]; - if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error, 0, buffer, sizeof(buffer), NULL)) - lua_pushstring(L, buffer); - else - lua_pushfstring(L, "system error %d\n", error); -} - -static void ll_unloadlib (void *lib) { - FreeLibrary((HINSTANCE)lib); -} - - -static void *ll_load (lua_State *L, const char *path) { - HINSTANCE lib = LoadLibraryA(path); - if (lib == NULL) pusherror(L); - return lib; -} - - -static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { - lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym); - if (f == NULL) pusherror(L); - return f; -} - -/* }====================================================== */ - - - -#elif defined(LUA_DL_DYLD) -/* -** {====================================================================== -** Native Mac OS X / Darwin Implementation -** ======================================================================= -*/ - -#include - - -/* Mac appends a `_' before C function names */ -#undef POF -#define POF "_" LUA_POF - - -static void pusherror (lua_State *L) { - const char *err_str; - const char *err_file; - NSLinkEditErrors err; - int err_num; - NSLinkEditError(&err, &err_num, &err_file, &err_str); - lua_pushstring(L, err_str); -} - - -static const char *errorfromcode (NSObjectFileImageReturnCode ret) { - switch (ret) { - case NSObjectFileImageInappropriateFile: - return "file is not a bundle"; - case NSObjectFileImageArch: - return "library is for wrong CPU type"; - case NSObjectFileImageFormat: - return "bad format"; - case NSObjectFileImageAccess: - return "cannot access file"; - case NSObjectFileImageFailure: - default: - return "unable to load library"; - } -} - - -static void ll_unloadlib (void *lib) { - NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); -} - - -static void *ll_load (lua_State *L, const char *path) { - NSObjectFileImage img; - NSObjectFileImageReturnCode ret; - /* this would be a rare case, but prevents crashing if it happens */ - if(!_dyld_present()) { - lua_pushliteral(L, "dyld not present"); - return NULL; - } - ret = NSCreateObjectFileImageFromFile(path, &img); - if (ret == NSObjectFileImageSuccess) { - NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE | - NSLINKMODULE_OPTION_RETURN_ON_ERROR); - NSDestroyObjectFileImage(img); - if (mod == NULL) pusherror(L); - return mod; - } - lua_pushstring(L, errorfromcode(ret)); - return NULL; -} - - -static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { - NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); - if (nss == NULL) { - lua_pushfstring(L, "symbol " LUA_QS " not found", sym); - return NULL; - } - return (lua_CFunction)NSAddressOfSymbol(nss); -} - -/* }====================================================== */ - - - -#else -/* -** {====================================================== -** Fallback for other systems -** ======================================================= -*/ - -#undef LIB_FAIL -#define LIB_FAIL "absent" - - -#define DLMSG "dynamic libraries not enabled; check your Lua installation" - - -static void ll_unloadlib (void *lib) { - (void)lib; /* to avoid warnings */ -} - - -static void *ll_load (lua_State *L, const char *path) { - (void)path; /* to avoid warnings */ - lua_pushliteral(L, DLMSG); - return NULL; -} - - -static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { - (void)lib; (void)sym; /* to avoid warnings */ - lua_pushliteral(L, DLMSG); - return NULL; -} - -/* }====================================================== */ -#endif - - - -static void **ll_register (lua_State *L, const char *path) { - void **plib; - lua_pushfstring(L, "%s%s", LIBPREFIX, path); - lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ - if (!lua_isnil(L, -1)) /* is there an entry? */ - plib = (void **)lua_touserdata(L, -1); - else { /* no entry yet; create one */ - lua_pop(L, 1); - plib = (void **)lua_newuserdata(L, sizeof(const void *)); - *plib = NULL; - luaL_getmetatable(L, "_LOADLIB"); - lua_setmetatable(L, -2); - lua_pushfstring(L, "%s%s", LIBPREFIX, path); - lua_pushvalue(L, -2); - lua_settable(L, LUA_REGISTRYINDEX); - } - return plib; -} - - -/* -** __gc tag method: calls library's `ll_unloadlib' function with the lib -** handle -*/ -static int gctm (lua_State *L) { - void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); - if (*lib) ll_unloadlib(*lib); - *lib = NULL; /* mark library as closed */ - return 0; -} - - -static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { - void **reg = ll_register(L, path); - if (*reg == NULL) *reg = ll_load(L, path); - if (*reg == NULL) - return ERRLIB; /* unable to load library */ - else { - lua_CFunction f = ll_sym(L, *reg, sym); - if (f == NULL) - return ERRFUNC; /* unable to find function */ - lua_pushcfunction(L, f); - return 0; /* return function */ - } -} - - -static int ll_loadlib (lua_State *L) { - const char *path = luaL_checkstring(L, 1); - const char *init = luaL_checkstring(L, 2); - int stat = ll_loadfunc(L, path, init); - if (stat == 0) /* no errors? */ - return 1; /* return the loaded function */ - else { /* error; error message is on stack top */ - lua_pushnil(L); - lua_insert(L, -2); - lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); - return 3; /* return nil, error message, and where */ - } -} - - - -/* -** {====================================================== -** 'require' function -** ======================================================= -*/ - - -static int readable (const char *filename) { - FILE *f = fopen(filename, "r"); /* try to open file */ - if (f == NULL) return 0; /* open failed */ - fclose(f); - return 1; -} - - -static const char *pushnexttemplate (lua_State *L, const char *path) { - const char *l; - while (*path == *LUA_PATHSEP) path++; /* skip separators */ - if (*path == '\0') return NULL; /* no more templates */ - l = strchr(path, *LUA_PATHSEP); /* find next separator */ - if (l == NULL) l = path + strlen(path); - lua_pushlstring(L, path, l - path); /* template */ - return l; -} - - -static const char *findfile (lua_State *L, const char *name, - const char *pname) { - const char *path; - name = luaL_gsub(L, name, ".", LUA_DIRSEP); - lua_getfield(L, LUA_ENVIRONINDEX, pname); - path = lua_tostring(L, -1); - if (path == NULL) - luaL_error(L, LUA_QL("package.%s") " must be a string", pname); - lua_pushliteral(L, ""); /* error accumulator */ - while ((path = pushnexttemplate(L, path)) != NULL) { - const char *filename; - filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); - lua_remove(L, -2); /* remove path template */ - if (readable(filename)) /* does file exist and is readable? */ - return filename; /* return that file name */ - lua_pushfstring(L, "\n\tno file " LUA_QS, filename); - lua_remove(L, -2); /* remove file name */ - lua_concat(L, 2); /* add entry to possible error message */ - } - return NULL; /* not found */ -} - - -static void loaderror (lua_State *L, const char *filename) { - luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", - lua_tostring(L, 1), filename, lua_tostring(L, -1)); -} - - -static int loader_Lua (lua_State *L) { - const char *filename; - const char *name = luaL_checkstring(L, 1); - filename = findfile(L, name, "path"); - if (filename == NULL) return 1; /* library not found in this path */ - if (luaL_loadfile(L, filename) != 0) - loaderror(L, filename); - return 1; /* library loaded successfully */ -} - - -static const char *mkfuncname (lua_State *L, const char *modname) { - const char *funcname; - const char *mark = strchr(modname, *LUA_IGMARK); - if (mark) modname = mark + 1; - funcname = luaL_gsub(L, modname, ".", LUA_OFSEP); - funcname = lua_pushfstring(L, POF"%s", funcname); - lua_remove(L, -2); /* remove 'gsub' result */ - return funcname; -} - - -static int loader_C (lua_State *L) { - const char *funcname; - const char *name = luaL_checkstring(L, 1); - const char *filename = findfile(L, name, "cpath"); - if (filename == NULL) return 1; /* library not found in this path */ - funcname = mkfuncname(L, name); - if (ll_loadfunc(L, filename, funcname) != 0) - loaderror(L, filename); - return 1; /* library loaded successfully */ -} - - -static int loader_Croot (lua_State *L) { - const char *funcname; - const char *filename; - const char *name = luaL_checkstring(L, 1); - const char *p = strchr(name, '.'); - int stat; - if (p == NULL) return 0; /* is root */ - lua_pushlstring(L, name, p - name); - filename = findfile(L, lua_tostring(L, -1), "cpath"); - if (filename == NULL) return 1; /* root not found */ - funcname = mkfuncname(L, name); - if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { - if (stat != ERRFUNC) loaderror(L, filename); /* real error */ - lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, - name, filename); - return 1; /* function not found */ - } - return 1; -} - - -static int loader_preload (lua_State *L) { - const char *name = luaL_checkstring(L, 1); - lua_getfield(L, LUA_ENVIRONINDEX, "preload"); - if (!lua_istable(L, -1)) - luaL_error(L, LUA_QL("package.preload") " must be a table"); - lua_getfield(L, -1, name); - if (lua_isnil(L, -1)) /* not found? */ - lua_pushfstring(L, "\n\tno field package.preload['%s']", name); - return 1; -} - - -static const int sentinel_ = 0; -#define sentinel ((void *)&sentinel_) - - -static int ll_require (lua_State *L) { - const char *name = luaL_checkstring(L, 1); - int i; - lua_settop(L, 1); /* _LOADED table will be at index 2 */ - lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_getfield(L, 2, name); - if (lua_toboolean(L, -1)) { /* is it there? */ - if (lua_touserdata(L, -1) == sentinel) /* check loops */ - luaL_error(L, "loop or previous error loading module " LUA_QS, name); - return 1; /* package is already loaded */ - } - /* else must load it; iterate over available loaders */ - lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); - if (!lua_istable(L, -1)) - luaL_error(L, LUA_QL("package.loaders") " must be a table"); - lua_pushliteral(L, ""); /* error message accumulator */ - for (i=1; ; i++) { - lua_rawgeti(L, -2, i); /* get a loader */ - if (lua_isnil(L, -1)) - luaL_error(L, "module " LUA_QS " not found:%s", - name, lua_tostring(L, -2)); - lua_pushstring(L, name); - lua_call(L, 1, 1); /* call it */ - if (lua_isfunction(L, -1)) /* did it find module? */ - break; /* module loaded successfully */ - else if (lua_isstring(L, -1)) /* loader returned error message? */ - lua_concat(L, 2); /* accumulate it */ - else - lua_pop(L, 1); - } - lua_pushlightuserdata(L, sentinel); - lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ - lua_pushstring(L, name); /* pass name as argument to module */ - lua_call(L, 1, 1); /* run loaded module */ - if (!lua_isnil(L, -1)) /* non-nil return? */ - lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ - lua_getfield(L, 2, name); - if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ - lua_pushboolean(L, 1); /* use true as result */ - lua_pushvalue(L, -1); /* extra copy to be returned */ - lua_setfield(L, 2, name); /* _LOADED[name] = true */ - } - return 1; -} - -/* }====================================================== */ - - - -/* -** {====================================================== -** 'module' function -** ======================================================= -*/ - - -static void setfenv (lua_State *L) { - lua_Debug ar; - if (lua_getstack(L, 1, &ar) == 0 || - lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ - lua_iscfunction(L, -1)) - luaL_error(L, LUA_QL("module") " not called from a Lua function"); - lua_pushvalue(L, -2); - lua_setfenv(L, -2); - lua_pop(L, 1); -} - - -static void dooptions (lua_State *L, int n) { - int i; - for (i = 2; i <= n; i++) { - lua_pushvalue(L, i); /* get option (a function) */ - lua_pushvalue(L, -2); /* module */ - lua_call(L, 1, 0); - } -} - - -static void modinit (lua_State *L, const char *modname) { - const char *dot; - lua_pushvalue(L, -1); - lua_setfield(L, -2, "_M"); /* module._M = module */ - lua_pushstring(L, modname); - lua_setfield(L, -2, "_NAME"); - dot = strrchr(modname, '.'); /* look for last dot in module name */ - if (dot == NULL) dot = modname; - else dot++; - /* set _PACKAGE as package name (full module name minus last part) */ - lua_pushlstring(L, modname, dot - modname); - lua_setfield(L, -2, "_PACKAGE"); -} - - -static int ll_module (lua_State *L) { - const char *modname = luaL_checkstring(L, 1); - int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ - lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); - lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ - if (!lua_istable(L, -1)) { /* not found? */ - lua_pop(L, 1); /* remove previous result */ - /* try global variable (and create one if it does not exist) */ - if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) - return luaL_error(L, "name conflict for module " LUA_QS, modname); - lua_pushvalue(L, -1); - lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ - } - /* check whether table already has a _NAME field */ - lua_getfield(L, -1, "_NAME"); - if (!lua_isnil(L, -1)) /* is table an initialized module? */ - lua_pop(L, 1); - else { /* no; initialize it */ - lua_pop(L, 1); - modinit(L, modname); - } - lua_pushvalue(L, -1); - setfenv(L); - dooptions(L, loaded - 1); - return 0; -} - - -static int ll_seeall (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - if (!lua_getmetatable(L, 1)) { - lua_createtable(L, 0, 1); /* create new metatable */ - lua_pushvalue(L, -1); - lua_setmetatable(L, 1); - } - lua_pushvalue(L, LUA_GLOBALSINDEX); - lua_setfield(L, -2, "__index"); /* mt.__index = _G */ - return 0; -} - - -/* }====================================================== */ - - - -/* auxiliary mark (for internal use) */ -#define AUXMARK "\1" - -static void setpath (lua_State *L, const char *fieldname, const char *envname, - const char *def) { - const char *path = getenv(envname); - if (path == NULL) /* no environment variable? */ - lua_pushstring(L, def); /* use default */ - else { - /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ - path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, - LUA_PATHSEP AUXMARK LUA_PATHSEP); - luaL_gsub(L, path, AUXMARK, def); - lua_remove(L, -2); - } - setprogdir(L); - lua_setfield(L, -2, fieldname); -} - - -static const luaL_Reg pk_funcs[] = { - {"loadlib", ll_loadlib}, - {"seeall", ll_seeall}, - {NULL, NULL} -}; - - -static const luaL_Reg ll_funcs[] = { - {"module", ll_module}, - {"require", ll_require}, - {NULL, NULL} -}; - - -static const lua_CFunction loaders[] = - {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; - - -LUALIB_API int luaopen_package (lua_State *L) { - int i; - /* create new type _LOADLIB */ - luaL_newmetatable(L, "_LOADLIB"); - lua_pushcfunction(L, gctm); - lua_setfield(L, -2, "__gc"); - /* create `package' table */ - luaL_register(L, LUA_LOADLIBNAME, pk_funcs); -#if defined(LUA_COMPAT_LOADLIB) - lua_getfield(L, -1, "loadlib"); - lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); -#endif - lua_pushvalue(L, -1); - lua_replace(L, LUA_ENVIRONINDEX); - /* create `loaders' table */ - lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1); - /* fill it with pre-defined loaders */ - for (i=0; loaders[i] != NULL; i++) { - lua_pushcfunction(L, loaders[i]); - lua_rawseti(L, -2, i+1); - } - lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ - setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ - setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ - /* store config information */ - lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" - LUA_EXECDIR "\n" LUA_IGMARK); - lua_setfield(L, -2, "config"); - /* set field `loaded' */ - luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); - lua_setfield(L, -2, "loaded"); - /* set field `preload' */ - lua_newtable(L); - lua_setfield(L, -2, "preload"); - lua_pushvalue(L, LUA_GLOBALSINDEX); - luaL_register(L, NULL, ll_funcs); /* open lib into global table */ - lua_pop(L, 1); - return 1; /* return 'package' table */ -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lobject.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lobject.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lobject.h @@ -1,381 +0,0 @@ -/* -** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $ -** Type definitions for Lua objects -** See Copyright Notice in lua.h -*/ - - -#ifndef lobject_h -#define lobject_h - - -#include - - -#include "llimits.h" -#include "lua.h" - - -/* tags for values visible from Lua */ -#define LAST_TAG LUA_TTHREAD - -#define NUM_TAGS (LAST_TAG+1) - - -/* -** Extra tags for non-values -*/ -#define LUA_TPROTO (LAST_TAG+1) -#define LUA_TUPVAL (LAST_TAG+2) -#define LUA_TDEADKEY (LAST_TAG+3) - - -/* -** Union of all collectable objects -*/ -typedef union GCObject GCObject; - - -/* -** Common Header for all collectable objects (in macro form, to be -** included in other objects) -*/ -#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked - - -/* -** Common header in struct form -*/ -typedef struct GCheader { - CommonHeader; -} GCheader; - - - - -/* -** Union of all Lua values -*/ -typedef union { - GCObject *gc; - void *p; - lua_Number n; - int b; -} Value; - - -/* -** Tagged Values -*/ - -#define TValuefields Value value; int tt - -typedef struct lua_TValue { - TValuefields; -} TValue; - - -/* Macros to test type */ -#define ttisnil(o) (ttype(o) == LUA_TNIL) -#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) -#define ttisstring(o) (ttype(o) == LUA_TSTRING) -#define ttistable(o) (ttype(o) == LUA_TTABLE) -#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) -#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) -#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) -#define ttisthread(o) (ttype(o) == LUA_TTHREAD) -#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) - -/* Macros to access values */ -#define ttype(o) ((o)->tt) -#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) -#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) -#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) -#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) -#define tsvalue(o) (&rawtsvalue(o)->tsv) -#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) -#define uvalue(o) (&rawuvalue(o)->uv) -#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) -#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) -#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) -#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) - -#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) - -/* -** for internal debug only -*/ -#define checkconsistency(obj) \ - lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) - -#define checkliveness(g,obj) \ - lua_assert(!iscollectable(obj) || \ - ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) - - -/* Macros to set values */ -#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) - -#define setnvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } - -#define setpvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } - -#define setbvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } - -#define setsvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ - checkliveness(G(L),i_o); } - -#define setuvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ - checkliveness(G(L),i_o); } - -#define setthvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ - checkliveness(G(L),i_o); } - -#define setclvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ - checkliveness(G(L),i_o); } - -#define sethvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ - checkliveness(G(L),i_o); } - -#define setptvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ - checkliveness(G(L),i_o); } - - - - -#define setobj(L,obj1,obj2) \ - { const TValue *o2=(obj2); TValue *o1=(obj1); \ - o1->value = o2->value; o1->tt=o2->tt; \ - checkliveness(G(L),o1); } - - -/* -** different types of sets, according to destination -*/ - -/* from stack to (same) stack */ -#define setobjs2s setobj -/* to stack (not from same stack) */ -#define setobj2s setobj -#define setsvalue2s setsvalue -#define sethvalue2s sethvalue -#define setptvalue2s setptvalue -/* from table to same table */ -#define setobjt2t setobj -/* to table */ -#define setobj2t setobj -/* to new object */ -#define setobj2n setobj -#define setsvalue2n setsvalue - -#define setttype(obj, tt) (ttype(obj) = (tt)) - - -#define iscollectable(o) (ttype(o) >= LUA_TSTRING) - - - -typedef TValue *StkId; /* index to stack elements */ - - -/* -** String headers for string table -*/ -typedef union TString { - L_Umaxalign dummy; /* ensures maximum alignment for strings */ - struct { - CommonHeader; - lu_byte reserved; - unsigned int hash; - size_t len; - } tsv; -} TString; - - -#define getstr(ts) cast(const char *, (ts) + 1) -#define svalue(o) getstr(rawtsvalue(o)) - - - -typedef union Udata { - L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ - struct { - CommonHeader; - struct Table *metatable; - struct Table *env; - size_t len; - } uv; -} Udata; - - - - -/* -** Function Prototypes -*/ -typedef struct Proto { - CommonHeader; - TValue *k; /* constants used by the function */ - Instruction *code; - struct Proto **p; /* functions defined inside the function */ - int *lineinfo; /* map from opcodes to source lines */ - struct LocVar *locvars; /* information about local variables */ - TString **upvalues; /* upvalue names */ - TString *source; - int sizeupvalues; - int sizek; /* size of `k' */ - int sizecode; - int sizelineinfo; - int sizep; /* size of `p' */ - int sizelocvars; - int linedefined; - int lastlinedefined; - GCObject *gclist; - lu_byte nups; /* number of upvalues */ - lu_byte numparams; - lu_byte is_vararg; - lu_byte maxstacksize; -} Proto; - - -/* masks for new-style vararg */ -#define VARARG_HASARG 1 -#define VARARG_ISVARARG 2 -#define VARARG_NEEDSARG 4 - - -typedef struct LocVar { - TString *varname; - int startpc; /* first point where variable is active */ - int endpc; /* first point where variable is dead */ -} LocVar; - - - -/* -** Upvalues -*/ - -typedef struct UpVal { - CommonHeader; - TValue *v; /* points to stack or to its own value */ - union { - TValue value; /* the value (when closed) */ - struct { /* double linked list (when open) */ - struct UpVal *prev; - struct UpVal *next; - } l; - } u; -} UpVal; - - -/* -** Closures -*/ - -#define ClosureHeader \ - CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ - struct Table *env - -typedef struct CClosure { - ClosureHeader; - lua_CFunction f; - TValue upvalue[1]; -} CClosure; - - -typedef struct LClosure { - ClosureHeader; - struct Proto *p; - UpVal *upvals[1]; -} LClosure; - - -typedef union Closure { - CClosure c; - LClosure l; -} Closure; - - -#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) -#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) - - -/* -** Tables -*/ - -typedef union TKey { - struct { - TValuefields; - struct Node *next; /* for chaining */ - } nk; - TValue tvk; -} TKey; - - -typedef struct Node { - TValue i_val; - TKey i_key; -} Node; - - -typedef struct Table { - CommonHeader; - lu_byte flags; /* 1<

lsizenode)) - - -#define luaO_nilobject (&luaO_nilobject_) - -LUAI_DATA const TValue luaO_nilobject_; - -#define ceillog2(x) (luaO_log2((x)-1) + 1) - -LUAI_FUNC int luaO_log2 (unsigned int x); -LUAI_FUNC int luaO_int2fb (unsigned int x); -LUAI_FUNC int luaO_fb2int (int x); -LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); -LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); -LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, - va_list argp); -LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); -LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); - - -#endif - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lobject.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lobject.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lobject.c @@ -1,214 +0,0 @@ -/* -** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ -** Some generic functions over Lua objects -** See Copyright Notice in lua.h -*/ - -#include -#include -#include -#include -#include - -#define lobject_c -#define LUA_CORE - -#include "lua.h" - -#include "ldo.h" -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" -#include "lstring.h" -#include "lvm.h" - - - -const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; - - -/* -** converts an integer to a "floating point byte", represented as -** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if -** eeeee != 0 and (xxx) otherwise. -*/ -int luaO_int2fb (unsigned int x) { - int e = 0; /* expoent */ - while (x >= 16) { - x = (x+1) >> 1; - e++; - } - if (x < 8) return x; - else return ((e+1) << 3) | (cast_int(x) - 8); -} - - -/* converts back */ -int luaO_fb2int (int x) { - int e = (x >> 3) & 31; - if (e == 0) return x; - else return ((x & 7)+8) << (e - 1); -} - - -int luaO_log2 (unsigned int x) { - static const lu_byte log_2[256] = { - 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, - 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, - 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, - 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, - 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, - 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, - 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, - 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 - }; - int l = -1; - while (x >= 256) { l += 8; x >>= 8; } - return l + log_2[x]; - -} - - -int luaO_rawequalObj (const TValue *t1, const TValue *t2) { - if (ttype(t1) != ttype(t2)) return 0; - else switch (ttype(t1)) { - case LUA_TNIL: - return 1; - case LUA_TNUMBER: - return luai_numeq(nvalue(t1), nvalue(t2)); - case LUA_TBOOLEAN: - return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ - case LUA_TLIGHTUSERDATA: - return pvalue(t1) == pvalue(t2); - default: - lua_assert(iscollectable(t1)); - return gcvalue(t1) == gcvalue(t2); - } -} - - -int luaO_str2d (const char *s, lua_Number *result) { - char *endptr; - *result = lua_str2number(s, &endptr); - if (endptr == s) return 0; /* conversion failed */ - if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ - *result = cast_num(strtoul(s, &endptr, 16)); - if (*endptr == '\0') return 1; /* most common case */ - while (isspace(cast(unsigned char, *endptr))) endptr++; - if (*endptr != '\0') return 0; /* invalid trailing characters? */ - return 1; -} - - - -static void pushstr (lua_State *L, const char *str) { - setsvalue2s(L, L->top, luaS_new(L, str)); - incr_top(L); -} - - -/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ -const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { - int n = 1; - pushstr(L, ""); - for (;;) { - const char *e = strchr(fmt, '%'); - if (e == NULL) break; - setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); - incr_top(L); - switch (*(e+1)) { - case 's': { - const char *s = va_arg(argp, char *); - if (s == NULL) s = "(null)"; - pushstr(L, s); - break; - } - case 'c': { - char buff[2]; - buff[0] = cast(char, va_arg(argp, int)); - buff[1] = '\0'; - pushstr(L, buff); - break; - } - case 'd': { - setnvalue(L->top, cast_num(va_arg(argp, int))); - incr_top(L); - break; - } - case 'f': { - setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); - incr_top(L); - break; - } - case 'p': { - char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ - sprintf(buff, "%p", va_arg(argp, void *)); - pushstr(L, buff); - break; - } - case '%': { - pushstr(L, "%"); - break; - } - default: { - char buff[3]; - buff[0] = '%'; - buff[1] = *(e+1); - buff[2] = '\0'; - pushstr(L, buff); - break; - } - } - n += 2; - fmt = e+2; - } - pushstr(L, fmt); - luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); - L->top -= n; - return svalue(L->top - 1); -} - - -const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { - const char *msg; - va_list argp; - va_start(argp, fmt); - msg = luaO_pushvfstring(L, fmt, argp); - va_end(argp); - return msg; -} - - -void luaO_chunkid (char *out, const char *source, size_t bufflen) { - if (*source == '=') { - strncpy(out, source+1, bufflen); /* remove first char */ - out[bufflen-1] = '\0'; /* ensures null termination */ - } - else { /* out = "source", or "...source" */ - if (*source == '@') { - size_t l; - source++; /* skip the `@' */ - bufflen -= sizeof(" '...' "); - l = strlen(source); - strcpy(out, ""); - if (l > bufflen) { - source += (l-bufflen); /* get last part of file name */ - strcat(out, "..."); - } - strcat(out, source); - } - else { /* out = [string "string"] */ - size_t len = strcspn(source, "\n\r"); /* stop at first newline */ - bufflen -= sizeof(" [string \"...\"] "); - if (len > bufflen) len = bufflen; - strcpy(out, "[string \""); - if (source[len] != '\0') { /* must truncate? */ - strncat(out, source, len); - strcat(out, "..."); - } - else - strcat(out, source); - strcat(out, "\"]"); - } - } -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lopcodes.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lopcodes.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lopcodes.h @@ -1,268 +0,0 @@ -/* -** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $ -** Opcodes for Lua virtual machine -** See Copyright Notice in lua.h -*/ - -#ifndef lopcodes_h -#define lopcodes_h - -#include "llimits.h" - - -/*=========================================================================== - We assume that instructions are unsigned numbers. - All instructions have an opcode in the first 6 bits. - Instructions can have the following fields: - `A' : 8 bits - `B' : 9 bits - `C' : 9 bits - `Bx' : 18 bits (`B' and `C' together) - `sBx' : signed Bx - - A signed argument is represented in excess K; that is, the number - value is the unsigned value minus K. K is exactly the maximum value - for that argument (so that -max is represented by 0, and +max is - represented by 2*max), which is half the maximum for the corresponding - unsigned argument. -===========================================================================*/ - - -enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ - - -/* -** size and position of opcode arguments. -*/ -#define SIZE_C 9 -#define SIZE_B 9 -#define SIZE_Bx (SIZE_C + SIZE_B) -#define SIZE_A 8 - -#define SIZE_OP 6 - -#define POS_OP 0 -#define POS_A (POS_OP + SIZE_OP) -#define POS_C (POS_A + SIZE_A) -#define POS_B (POS_C + SIZE_C) -#define POS_Bx POS_C - - -/* -** limits for opcode arguments. -** we use (signed) int to manipulate most arguments, -** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) -*/ -#if SIZE_Bx < LUAI_BITSINT-1 -#define MAXARG_Bx ((1<>1) /* `sBx' is signed */ -#else -#define MAXARG_Bx MAX_INT -#define MAXARG_sBx MAX_INT -#endif - - -#define MAXARG_A ((1<>POS_OP) & MASK1(SIZE_OP,0))) -#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ - ((cast(Instruction, o)<>POS_A) & MASK1(SIZE_A,0))) -#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ - ((cast(Instruction, u)<>POS_B) & MASK1(SIZE_B,0))) -#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ - ((cast(Instruction, b)<>POS_C) & MASK1(SIZE_C,0))) -#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ - ((cast(Instruction, b)<>POS_Bx) & MASK1(SIZE_Bx,0))) -#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ - ((cast(Instruction, b)< C) then pc++ */ -OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ - -OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ -OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ -OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ - -OP_FORLOOP,/* A sBx R(A)+=R(A+2); - if R(A) =) R(A)*/ -OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ - -OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ -} OpCode; - - -#define NUM_OPCODES (cast(int, OP_VARARG) + 1) - - - -/*=========================================================================== - Notes: - (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, - and can be 0: OP_CALL then sets `top' to last_result+1, so - next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. - - (*) In OP_VARARG, if (B == 0) then use actual number of varargs and - set top (like in OP_CALL with C == 0). - - (*) In OP_RETURN, if (B == 0) then return up to `top' - - (*) In OP_SETLIST, if (B == 0) then B = `top'; - if (C == 0) then next `instruction' is real C - - (*) For comparisons, A specifies what condition the test should accept - (true or false). - - (*) All `skips' (pc++) assume that next instruction is a jump -===========================================================================*/ - - -/* -** masks for instruction properties. The format is: -** bits 0-1: op mode -** bits 2-3: C arg mode -** bits 4-5: B arg mode -** bit 6: instruction set register A -** bit 7: operator is a test -*/ - -enum OpArgMask { - OpArgN, /* argument is not used */ - OpArgU, /* argument is used */ - OpArgR, /* argument is a register or a jump offset */ - OpArgK /* argument is a constant or register/constant */ -}; - -LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; - -#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) -#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) -#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) -#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) -#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) - - -LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ - - -/* number of list items to accumulate before a SETLIST instruction */ -#define LFIELDS_PER_FLUSH 50 - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lopcodes.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lopcodes.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lopcodes.c @@ -1,102 +0,0 @@ -/* -** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ -** See Copyright Notice in lua.h -*/ - - -#define lopcodes_c -#define LUA_CORE - - -#include "lopcodes.h" - - -/* ORDER OP */ - -const char *const luaP_opnames[NUM_OPCODES+1] = { - "MOVE", - "LOADK", - "LOADBOOL", - "LOADNIL", - "GETUPVAL", - "GETGLOBAL", - "GETTABLE", - "SETGLOBAL", - "SETUPVAL", - "SETTABLE", - "NEWTABLE", - "SELF", - "ADD", - "SUB", - "MUL", - "DIV", - "MOD", - "POW", - "UNM", - "NOT", - "LEN", - "CONCAT", - "JMP", - "EQ", - "LT", - "LE", - "TEST", - "TESTSET", - "CALL", - "TAILCALL", - "RETURN", - "FORLOOP", - "FORPREP", - "TFORLOOP", - "SETLIST", - "CLOSE", - "CLOSURE", - "VARARG", - NULL -}; - - -#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) - -const lu_byte luaP_opmodes[NUM_OPCODES] = { -/* T A B C mode opcode */ - opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ - ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ - ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ - ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ - ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ - ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ - ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ - ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ - ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ - ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ - ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ - ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ - ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ - ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ - ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ - ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ - ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ - ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ - ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ - ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ - ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ - ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ - ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ - ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ - ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ - ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ -}; - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/loslib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/loslib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/loslib.c @@ -1,243 +0,0 @@ -/* -** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ -** Standard Operating System library -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include -#include -#include - -#define loslib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - -static int os_pushresult (lua_State *L, int i, const char *filename) { - int en = errno; /* calls to Lua API may change this value */ - if (i) { - lua_pushboolean(L, 1); - return 1; - } - else { - lua_pushnil(L); - lua_pushfstring(L, "%s: %s", filename, strerror(en)); - lua_pushinteger(L, en); - return 3; - } -} - - -static int os_execute (lua_State *L) { - lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); - return 1; -} - - -static int os_remove (lua_State *L) { - const char *filename = luaL_checkstring(L, 1); - return os_pushresult(L, remove(filename) == 0, filename); -} - - -static int os_rename (lua_State *L) { - const char *fromname = luaL_checkstring(L, 1); - const char *toname = luaL_checkstring(L, 2); - return os_pushresult(L, rename(fromname, toname) == 0, fromname); -} - - -static int os_tmpname (lua_State *L) { - char buff[LUA_TMPNAMBUFSIZE]; - int err; - lua_tmpnam(buff, err); - if (err) - return luaL_error(L, "unable to generate a unique filename"); - lua_pushstring(L, buff); - return 1; -} - - -static int os_getenv (lua_State *L) { - lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ - return 1; -} - - -static int os_clock (lua_State *L) { - lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); - return 1; -} - - -/* -** {====================================================== -** Time/Date operations -** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, -** wday=%w+1, yday=%j, isdst=? } -** ======================================================= -*/ - -static void setfield (lua_State *L, const char *key, int value) { - lua_pushinteger(L, value); - lua_setfield(L, -2, key); -} - -static void setboolfield (lua_State *L, const char *key, int value) { - if (value < 0) /* undefined? */ - return; /* does not set field */ - lua_pushboolean(L, value); - lua_setfield(L, -2, key); -} - -static int getboolfield (lua_State *L, const char *key) { - int res; - lua_getfield(L, -1, key); - res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); - lua_pop(L, 1); - return res; -} - - -static int getfield (lua_State *L, const char *key, int d) { - int res; - lua_getfield(L, -1, key); - if (lua_isnumber(L, -1)) - res = (int)lua_tointeger(L, -1); - else { - if (d < 0) - return luaL_error(L, "field " LUA_QS " missing in date table", key); - res = d; - } - lua_pop(L, 1); - return res; -} - - -static int os_date (lua_State *L) { - const char *s = luaL_optstring(L, 1, "%c"); - time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); - struct tm *stm; - if (*s == '!') { /* UTC? */ - stm = gmtime(&t); - s++; /* skip `!' */ - } - else - stm = localtime(&t); - if (stm == NULL) /* invalid date? */ - lua_pushnil(L); - else if (strcmp(s, "*t") == 0) { - lua_createtable(L, 0, 9); /* 9 = number of fields */ - setfield(L, "sec", stm->tm_sec); - setfield(L, "min", stm->tm_min); - setfield(L, "hour", stm->tm_hour); - setfield(L, "day", stm->tm_mday); - setfield(L, "month", stm->tm_mon+1); - setfield(L, "year", stm->tm_year+1900); - setfield(L, "wday", stm->tm_wday+1); - setfield(L, "yday", stm->tm_yday+1); - setboolfield(L, "isdst", stm->tm_isdst); - } - else { - char cc[3]; - luaL_Buffer b; - cc[0] = '%'; cc[2] = '\0'; - luaL_buffinit(L, &b); - for (; *s; s++) { - if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ - luaL_addchar(&b, *s); - else { - size_t reslen; - char buff[200]; /* should be big enough for any conversion result */ - cc[1] = *(++s); - reslen = strftime(buff, sizeof(buff), cc, stm); - luaL_addlstring(&b, buff, reslen); - } - } - luaL_pushresult(&b); - } - return 1; -} - - -static int os_time (lua_State *L) { - time_t t; - if (lua_isnoneornil(L, 1)) /* called without args? */ - t = time(NULL); /* get current time */ - else { - struct tm ts; - luaL_checktype(L, 1, LUA_TTABLE); - lua_settop(L, 1); /* make sure table is at the top */ - ts.tm_sec = getfield(L, "sec", 0); - ts.tm_min = getfield(L, "min", 0); - ts.tm_hour = getfield(L, "hour", 12); - ts.tm_mday = getfield(L, "day", -1); - ts.tm_mon = getfield(L, "month", -1) - 1; - ts.tm_year = getfield(L, "year", -1) - 1900; - ts.tm_isdst = getboolfield(L, "isdst"); - t = mktime(&ts); - } - if (t == (time_t)(-1)) - lua_pushnil(L); - else - lua_pushnumber(L, (lua_Number)t); - return 1; -} - - -static int os_difftime (lua_State *L) { - lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), - (time_t)(luaL_optnumber(L, 2, 0)))); - return 1; -} - -/* }====================================================== */ - - -static int os_setlocale (lua_State *L) { - static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, - LC_NUMERIC, LC_TIME}; - static const char *const catnames[] = {"all", "collate", "ctype", "monetary", - "numeric", "time", NULL}; - const char *l = luaL_optstring(L, 1, NULL); - int op = luaL_checkoption(L, 2, "all", catnames); - lua_pushstring(L, setlocale(cat[op], l)); - return 1; -} - - -static int os_exit (lua_State *L) { - exit(luaL_optint(L, 1, EXIT_SUCCESS)); -} - -static const luaL_Reg syslib[] = { - {"clock", os_clock}, - {"date", os_date}, - {"difftime", os_difftime}, - {"execute", os_execute}, - {"exit", os_exit}, - {"getenv", os_getenv}, - {"remove", os_remove}, - {"rename", os_rename}, - {"setlocale", os_setlocale}, - {"time", os_time}, - {"tmpname", os_tmpname}, - {NULL, NULL} -}; - -/* }====================================================== */ - - - -LUALIB_API int luaopen_os (lua_State *L) { - luaL_register(L, LUA_OSLIBNAME, syslib); - return 1; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lparser.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lparser.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lparser.h @@ -1,82 +0,0 @@ -/* -** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ -** Lua Parser -** See Copyright Notice in lua.h -*/ - -#ifndef lparser_h -#define lparser_h - -#include "llimits.h" -#include "lobject.h" -#include "lzio.h" - - -/* -** Expression descriptor -*/ - -typedef enum { - VVOID, /* no value */ - VNIL, - VTRUE, - VFALSE, - VK, /* info = index of constant in `k' */ - VKNUM, /* nval = numerical value */ - VLOCAL, /* info = local register */ - VUPVAL, /* info = index of upvalue in `upvalues' */ - VGLOBAL, /* info = index of table; aux = index of global name in `k' */ - VINDEXED, /* info = table register; aux = index register (or `k') */ - VJMP, /* info = instruction pc */ - VRELOCABLE, /* info = instruction pc */ - VNONRELOC, /* info = result register */ - VCALL, /* info = instruction pc */ - VVARARG /* info = instruction pc */ -} expkind; - -typedef struct expdesc { - expkind k; - union { - struct { int info, aux; } s; - lua_Number nval; - } u; - int t; /* patch list of `exit when true' */ - int f; /* patch list of `exit when false' */ -} expdesc; - - -typedef struct upvaldesc { - lu_byte k; - lu_byte info; -} upvaldesc; - - -struct BlockCnt; /* defined in lparser.c */ - - -/* state needed to generate code for a given function */ -typedef struct FuncState { - Proto *f; /* current function header */ - Table *h; /* table to find (and reuse) elements in `k' */ - struct FuncState *prev; /* enclosing function */ - struct LexState *ls; /* lexical state */ - struct lua_State *L; /* copy of the Lua state */ - struct BlockCnt *bl; /* chain of current blocks */ - int pc; /* next position to code (equivalent to `ncode') */ - int lasttarget; /* `pc' of last `jump target' */ - int jpc; /* list of pending jumps to `pc' */ - int freereg; /* first free register */ - int nk; /* number of elements in `k' */ - int np; /* number of elements in `p' */ - short nlocvars; /* number of elements in `locvars' */ - lu_byte nactvar; /* number of active local variables */ - upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ - unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ -} FuncState; - - -LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, - const char *name); - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lparser.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lparser.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lparser.c @@ -1,1339 +0,0 @@ -/* -** $Id: lparser.c,v 2.42.1.3 2007/12/28 15:32:23 roberto Exp $ -** Lua Parser -** See Copyright Notice in lua.h -*/ - - -#include - -#define lparser_c -#define LUA_CORE - -#include "lua.h" - -#include "lcode.h" -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "llex.h" -#include "lmem.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lparser.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" - - - -#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) - -#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) - -#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) - - -/* -** nodes for block list (list of active blocks) -*/ -typedef struct BlockCnt { - struct BlockCnt *previous; /* chain */ - int breaklist; /* list of jumps out of this loop */ - lu_byte nactvar; /* # active locals outside the breakable structure */ - lu_byte upval; /* true if some variable in the block is an upvalue */ - lu_byte isbreakable; /* true if `block' is a loop */ -} BlockCnt; - - - -/* -** prototypes for recursive non-terminal functions -*/ -static void chunk (LexState *ls); -static void expr (LexState *ls, expdesc *v); - - -static void anchor_token (LexState *ls) { - if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) { - TString *ts = ls->t.seminfo.ts; - luaX_newstring(ls, getstr(ts), ts->tsv.len); - } -} - - -static void error_expected (LexState *ls, int token) { - luaX_syntaxerror(ls, - luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); -} - - -static void errorlimit (FuncState *fs, int limit, const char *what) { - const char *msg = (fs->f->linedefined == 0) ? - luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : - luaO_pushfstring(fs->L, "function at line %d has more than %d %s", - fs->f->linedefined, limit, what); - luaX_lexerror(fs->ls, msg, 0); -} - - -static int testnext (LexState *ls, int c) { - if (ls->t.token == c) { - luaX_next(ls); - return 1; - } - else return 0; -} - - -static void check (LexState *ls, int c) { - if (ls->t.token != c) - error_expected(ls, c); -} - -static void checknext (LexState *ls, int c) { - check(ls, c); - luaX_next(ls); -} - - -#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } - - - -static void check_match (LexState *ls, int what, int who, int where) { - if (!testnext(ls, what)) { - if (where == ls->linenumber) - error_expected(ls, what); - else { - luaX_syntaxerror(ls, luaO_pushfstring(ls->L, - LUA_QS " expected (to close " LUA_QS " at line %d)", - luaX_token2str(ls, what), luaX_token2str(ls, who), where)); - } - } -} - - -static TString *str_checkname (LexState *ls) { - TString *ts; - check(ls, TK_NAME); - ts = ls->t.seminfo.ts; - luaX_next(ls); - return ts; -} - - -static void init_exp (expdesc *e, expkind k, int i) { - e->f = e->t = NO_JUMP; - e->k = k; - e->u.s.info = i; -} - - -static void codestring (LexState *ls, expdesc *e, TString *s) { - init_exp(e, VK, luaK_stringK(ls->fs, s)); -} - - -static void checkname(LexState *ls, expdesc *e) { - codestring(ls, e, str_checkname(ls)); -} - - -static int registerlocalvar (LexState *ls, TString *varname) { - FuncState *fs = ls->fs; - Proto *f = fs->f; - int oldsize = f->sizelocvars; - luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, - LocVar, SHRT_MAX, "too many local variables"); - while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; - f->locvars[fs->nlocvars].varname = varname; - luaC_objbarrier(ls->L, f, varname); - return fs->nlocvars++; -} - - -#define new_localvarliteral(ls,v,n) \ - new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) - - -static void new_localvar (LexState *ls, TString *name, int n) { - FuncState *fs = ls->fs; - luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); - fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); -} - - -static void adjustlocalvars (LexState *ls, int nvars) { - FuncState *fs = ls->fs; - fs->nactvar = cast_byte(fs->nactvar + nvars); - for (; nvars; nvars--) { - getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; - } -} - - -static void removevars (LexState *ls, int tolevel) { - FuncState *fs = ls->fs; - while (fs->nactvar > tolevel) - getlocvar(fs, --fs->nactvar).endpc = fs->pc; -} - - -static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { - int i; - Proto *f = fs->f; - int oldsize = f->sizeupvalues; - for (i=0; inups; i++) { - if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) { - lua_assert(f->upvalues[i] == name); - return i; - } - } - /* new one */ - luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues"); - luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, - TString *, MAX_INT, ""); - while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; - f->upvalues[f->nups] = name; - luaC_objbarrier(fs->L, f, name); - lua_assert(v->k == VLOCAL || v->k == VUPVAL); - fs->upvalues[f->nups].k = cast_byte(v->k); - fs->upvalues[f->nups].info = cast_byte(v->u.s.info); - return f->nups++; -} - - -static int searchvar (FuncState *fs, TString *n) { - int i; - for (i=fs->nactvar-1; i >= 0; i--) { - if (n == getlocvar(fs, i).varname) - return i; - } - return -1; /* not found */ -} - - -static void markupval (FuncState *fs, int level) { - BlockCnt *bl = fs->bl; - while (bl && bl->nactvar > level) bl = bl->previous; - if (bl) bl->upval = 1; -} - - -static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { - if (fs == NULL) { /* no more levels? */ - init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ - return VGLOBAL; - } - else { - int v = searchvar(fs, n); /* look up at current level */ - if (v >= 0) { - init_exp(var, VLOCAL, v); - if (!base) - markupval(fs, v); /* local will be used as an upval */ - return VLOCAL; - } - else { /* not found at current level; try upper one */ - if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) - return VGLOBAL; - var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ - var->k = VUPVAL; /* upvalue in this level */ - return VUPVAL; - } - } -} - - -static void singlevar (LexState *ls, expdesc *var) { - TString *varname = str_checkname(ls); - FuncState *fs = ls->fs; - if (singlevaraux(fs, varname, var, 1) == VGLOBAL) - var->u.s.info = luaK_stringK(fs, varname); /* info points to global name */ -} - - -static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { - FuncState *fs = ls->fs; - int extra = nvars - nexps; - if (hasmultret(e->k)) { - extra++; /* includes call itself */ - if (extra < 0) extra = 0; - luaK_setreturns(fs, e, extra); /* last exp. provides the difference */ - if (extra > 1) luaK_reserveregs(fs, extra-1); - } - else { - if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */ - if (extra > 0) { - int reg = fs->freereg; - luaK_reserveregs(fs, extra); - luaK_nil(fs, reg, extra); - } - } -} - - -static void enterlevel (LexState *ls) { - if (++ls->L->nCcalls > LUAI_MAXCCALLS) - luaX_lexerror(ls, "chunk has too many syntax levels", 0); -} - - -#define leavelevel(ls) ((ls)->L->nCcalls--) - - -static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isbreakable) { - bl->breaklist = NO_JUMP; - bl->isbreakable = isbreakable; - bl->nactvar = fs->nactvar; - bl->upval = 0; - bl->previous = fs->bl; - fs->bl = bl; - lua_assert(fs->freereg == fs->nactvar); -} - - -static void leaveblock (FuncState *fs) { - BlockCnt *bl = fs->bl; - fs->bl = bl->previous; - removevars(fs->ls, bl->nactvar); - if (bl->upval) - luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); - /* a block either controls scope or breaks (never both) */ - lua_assert(!bl->isbreakable || !bl->upval); - lua_assert(bl->nactvar == fs->nactvar); - fs->freereg = fs->nactvar; /* free registers */ - luaK_patchtohere(fs, bl->breaklist); -} - - -static void pushclosure (LexState *ls, FuncState *func, expdesc *v) { - FuncState *fs = ls->fs; - Proto *f = fs->f; - int oldsize = f->sizep; - int i; - luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *, - MAXARG_Bx, "constant table overflow"); - while (oldsize < f->sizep) f->p[oldsize++] = NULL; - f->p[fs->np++] = func->f; - luaC_objbarrier(ls->L, f, func->f); - init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); - for (i=0; if->nups; i++) { - OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; - luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); - } -} - - -static void open_func (LexState *ls, FuncState *fs) { - lua_State *L = ls->L; - Proto *f = luaF_newproto(L); - fs->f = f; - fs->prev = ls->fs; /* linked list of funcstates */ - fs->ls = ls; - fs->L = L; - ls->fs = fs; - fs->pc = 0; - fs->lasttarget = -1; - fs->jpc = NO_JUMP; - fs->freereg = 0; - fs->nk = 0; - fs->np = 0; - fs->nlocvars = 0; - fs->nactvar = 0; - fs->bl = NULL; - f->source = ls->source; - f->maxstacksize = 2; /* registers 0/1 are always valid */ - fs->h = luaH_new(L, 0, 0); - /* anchor table of constants and prototype (to avoid being collected) */ - sethvalue2s(L, L->top, fs->h); - incr_top(L); - setptvalue2s(L, L->top, f); - incr_top(L); -} - - -static void close_func (LexState *ls) { - lua_State *L = ls->L; - FuncState *fs = ls->fs; - Proto *f = fs->f; - removevars(ls, 0); - luaK_ret(fs, 0, 0); /* final return */ - luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); - f->sizecode = fs->pc; - luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); - f->sizelineinfo = fs->pc; - luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); - f->sizek = fs->nk; - luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); - f->sizep = fs->np; - luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); - f->sizelocvars = fs->nlocvars; - luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *); - f->sizeupvalues = f->nups; - lua_assert(luaG_checkcode(f)); - lua_assert(fs->bl == NULL); - ls->fs = fs->prev; - L->top -= 2; /* remove table and prototype from the stack */ - /* last token read was anchored in defunct function; must reanchor it */ - if (fs) anchor_token(ls); -} - - -Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { - struct LexState lexstate; - struct FuncState funcstate; - lexstate.buff = buff; - luaX_setinput(L, &lexstate, z, luaS_new(L, name)); - open_func(&lexstate, &funcstate); - funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ - luaX_next(&lexstate); /* read first token */ - chunk(&lexstate); - check(&lexstate, TK_EOS); - close_func(&lexstate); - lua_assert(funcstate.prev == NULL); - lua_assert(funcstate.f->nups == 0); - lua_assert(lexstate.fs == NULL); - return funcstate.f; -} - - - -/*============================================================*/ -/* GRAMMAR RULES */ -/*============================================================*/ - - -static void field (LexState *ls, expdesc *v) { - /* field -> ['.' | ':'] NAME */ - FuncState *fs = ls->fs; - expdesc key; - luaK_exp2anyreg(fs, v); - luaX_next(ls); /* skip the dot or colon */ - checkname(ls, &key); - luaK_indexed(fs, v, &key); -} - - -static void yindex (LexState *ls, expdesc *v) { - /* index -> '[' expr ']' */ - luaX_next(ls); /* skip the '[' */ - expr(ls, v); - luaK_exp2val(ls->fs, v); - checknext(ls, ']'); -} - - -/* -** {====================================================================== -** Rules for Constructors -** ======================================================================= -*/ - - -struct ConsControl { - expdesc v; /* last list item read */ - expdesc *t; /* table descriptor */ - int nh; /* total number of `record' elements */ - int na; /* total number of array elements */ - int tostore; /* number of array elements pending to be stored */ -}; - - -static void recfield (LexState *ls, struct ConsControl *cc) { - /* recfield -> (NAME | `['exp1`]') = exp1 */ - FuncState *fs = ls->fs; - int reg = ls->fs->freereg; - expdesc key, val; - int rkkey; - if (ls->t.token == TK_NAME) { - luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); - checkname(ls, &key); - } - else /* ls->t.token == '[' */ - yindex(ls, &key); - cc->nh++; - checknext(ls, '='); - rkkey = luaK_exp2RK(fs, &key); - expr(ls, &val); - luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); - fs->freereg = reg; /* free registers */ -} - - -static void closelistfield (FuncState *fs, struct ConsControl *cc) { - if (cc->v.k == VVOID) return; /* there is no list item */ - luaK_exp2nextreg(fs, &cc->v); - cc->v.k = VVOID; - if (cc->tostore == LFIELDS_PER_FLUSH) { - luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); /* flush */ - cc->tostore = 0; /* no more items pending */ - } -} - - -static void lastlistfield (FuncState *fs, struct ConsControl *cc) { - if (cc->tostore == 0) return; - if (hasmultret(cc->v.k)) { - luaK_setmultret(fs, &cc->v); - luaK_setlist(fs, cc->t->u.s.info, cc->na, LUA_MULTRET); - cc->na--; /* do not count last expression (unknown number of elements) */ - } - else { - if (cc->v.k != VVOID) - luaK_exp2nextreg(fs, &cc->v); - luaK_setlist(fs, cc->t->u.s.info, cc->na, cc->tostore); - } -} - - -static void listfield (LexState *ls, struct ConsControl *cc) { - expr(ls, &cc->v); - luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); - cc->na++; - cc->tostore++; -} - - -static void constructor (LexState *ls, expdesc *t) { - /* constructor -> ?? */ - FuncState *fs = ls->fs; - int line = ls->linenumber; - int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0); - struct ConsControl cc; - cc.na = cc.nh = cc.tostore = 0; - cc.t = t; - init_exp(t, VRELOCABLE, pc); - init_exp(&cc.v, VVOID, 0); /* no value (yet) */ - luaK_exp2nextreg(ls->fs, t); /* fix it at stack top (for gc) */ - checknext(ls, '{'); - do { - lua_assert(cc.v.k == VVOID || cc.tostore > 0); - if (ls->t.token == '}') break; - closelistfield(fs, &cc); - switch(ls->t.token) { - case TK_NAME: { /* may be listfields or recfields */ - luaX_lookahead(ls); - if (ls->lookahead.token != '=') /* expression? */ - listfield(ls, &cc); - else - recfield(ls, &cc); - break; - } - case '[': { /* constructor_item -> recfield */ - recfield(ls, &cc); - break; - } - default: { /* constructor_part -> listfield */ - listfield(ls, &cc); - break; - } - } - } while (testnext(ls, ',') || testnext(ls, ';')); - check_match(ls, '}', '{', line); - lastlistfield(fs, &cc); - SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */ - SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */ -} - -/* }====================================================================== */ - - - -static void parlist (LexState *ls) { - /* parlist -> [ param { `,' param } ] */ - FuncState *fs = ls->fs; - Proto *f = fs->f; - int nparams = 0; - f->is_vararg = 0; - if (ls->t.token != ')') { /* is `parlist' not empty? */ - do { - switch (ls->t.token) { - case TK_NAME: { /* param -> NAME */ - new_localvar(ls, str_checkname(ls), nparams++); - break; - } - case TK_DOTS: { /* param -> `...' */ - luaX_next(ls); -#if defined(LUA_COMPAT_VARARG) - /* use `arg' as default name */ - new_localvarliteral(ls, "arg", nparams++); - f->is_vararg = VARARG_HASARG | VARARG_NEEDSARG; -#endif - f->is_vararg |= VARARG_ISVARARG; - break; - } - default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected"); - } - } while (!f->is_vararg && testnext(ls, ',')); - } - adjustlocalvars(ls, nparams); - f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG)); - luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ -} - - -static void body (LexState *ls, expdesc *e, int needself, int line) { - /* body -> `(' parlist `)' chunk END */ - FuncState new_fs; - open_func(ls, &new_fs); - new_fs.f->linedefined = line; - checknext(ls, '('); - if (needself) { - new_localvarliteral(ls, "self", 0); - adjustlocalvars(ls, 1); - } - parlist(ls); - checknext(ls, ')'); - chunk(ls); - new_fs.f->lastlinedefined = ls->linenumber; - check_match(ls, TK_END, TK_FUNCTION, line); - close_func(ls); - pushclosure(ls, &new_fs, e); -} - - -static int explist1 (LexState *ls, expdesc *v) { - /* explist1 -> expr { `,' expr } */ - int n = 1; /* at least one expression */ - expr(ls, v); - while (testnext(ls, ',')) { - luaK_exp2nextreg(ls->fs, v); - expr(ls, v); - n++; - } - return n; -} - - -static void funcargs (LexState *ls, expdesc *f) { - FuncState *fs = ls->fs; - expdesc args; - int base, nparams; - int line = ls->linenumber; - switch (ls->t.token) { - case '(': { /* funcargs -> `(' [ explist1 ] `)' */ - if (line != ls->lastline) - luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); - luaX_next(ls); - if (ls->t.token == ')') /* arg list is empty? */ - args.k = VVOID; - else { - explist1(ls, &args); - luaK_setmultret(fs, &args); - } - check_match(ls, ')', '(', line); - break; - } - case '{': { /* funcargs -> constructor */ - constructor(ls, &args); - break; - } - case TK_STRING: { /* funcargs -> STRING */ - codestring(ls, &args, ls->t.seminfo.ts); - luaX_next(ls); /* must use `seminfo' before `next' */ - break; - } - default: { - luaX_syntaxerror(ls, "function arguments expected"); - return; - } - } - lua_assert(f->k == VNONRELOC); - base = f->u.s.info; /* base register for call */ - if (hasmultret(args.k)) - nparams = LUA_MULTRET; /* open call */ - else { - if (args.k != VVOID) - luaK_exp2nextreg(fs, &args); /* close last argument */ - nparams = fs->freereg - (base+1); - } - init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); - luaK_fixline(fs, line); - fs->freereg = base+1; /* call remove function and arguments and leaves - (unless changed) one result */ -} - - - - -/* -** {====================================================================== -** Expression parsing -** ======================================================================= -*/ - - -static void prefixexp (LexState *ls, expdesc *v) { - /* prefixexp -> NAME | '(' expr ')' */ - switch (ls->t.token) { - case '(': { - int line = ls->linenumber; - luaX_next(ls); - expr(ls, v); - check_match(ls, ')', '(', line); - luaK_dischargevars(ls->fs, v); - return; - } - case TK_NAME: { - singlevar(ls, v); - return; - } - default: { - luaX_syntaxerror(ls, "unexpected symbol"); - return; - } - } -} - - -static void primaryexp (LexState *ls, expdesc *v) { - /* primaryexp -> - prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ - FuncState *fs = ls->fs; - prefixexp(ls, v); - for (;;) { - switch (ls->t.token) { - case '.': { /* field */ - field(ls, v); - break; - } - case '[': { /* `[' exp1 `]' */ - expdesc key; - luaK_exp2anyreg(fs, v); - yindex(ls, &key); - luaK_indexed(fs, v, &key); - break; - } - case ':': { /* `:' NAME funcargs */ - expdesc key; - luaX_next(ls); - checkname(ls, &key); - luaK_self(fs, v, &key); - funcargs(ls, v); - break; - } - case '(': case TK_STRING: case '{': { /* funcargs */ - luaK_exp2nextreg(fs, v); - funcargs(ls, v); - break; - } - default: return; - } - } -} - - -static void simpleexp (LexState *ls, expdesc *v) { - /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | - constructor | FUNCTION body | primaryexp */ - switch (ls->t.token) { - case TK_NUMBER: { - init_exp(v, VKNUM, 0); - v->u.nval = ls->t.seminfo.r; - break; - } - case TK_STRING: { - codestring(ls, v, ls->t.seminfo.ts); - break; - } - case TK_NIL: { - init_exp(v, VNIL, 0); - break; - } - case TK_TRUE: { - init_exp(v, VTRUE, 0); - break; - } - case TK_FALSE: { - init_exp(v, VFALSE, 0); - break; - } - case TK_DOTS: { /* vararg */ - FuncState *fs = ls->fs; - check_condition(ls, fs->f->is_vararg, - "cannot use " LUA_QL("...") " outside a vararg function"); - fs->f->is_vararg &= ~VARARG_NEEDSARG; /* don't need 'arg' */ - init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0)); - break; - } - case '{': { /* constructor */ - constructor(ls, v); - return; - } - case TK_FUNCTION: { - luaX_next(ls); - body(ls, v, 0, ls->linenumber); - return; - } - default: { - primaryexp(ls, v); - return; - } - } - luaX_next(ls); -} - - -static UnOpr getunopr (int op) { - switch (op) { - case TK_NOT: return OPR_NOT; - case '-': return OPR_MINUS; - case '#': return OPR_LEN; - default: return OPR_NOUNOPR; - } -} - - -static BinOpr getbinopr (int op) { - switch (op) { - case '+': return OPR_ADD; - case '-': return OPR_SUB; - case '*': return OPR_MUL; - case '/': return OPR_DIV; - case '%': return OPR_MOD; - case '^': return OPR_POW; - case TK_CONCAT: return OPR_CONCAT; - case TK_NE: return OPR_NE; - case TK_EQ: return OPR_EQ; - case '<': return OPR_LT; - case TK_LE: return OPR_LE; - case '>': return OPR_GT; - case TK_GE: return OPR_GE; - case TK_AND: return OPR_AND; - case TK_OR: return OPR_OR; - default: return OPR_NOBINOPR; - } -} - - -static const struct { - lu_byte left; /* left priority for each binary operator */ - lu_byte right; /* right priority */ -} priority[] = { /* ORDER OPR */ - {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `/' `%' */ - {10, 9}, {5, 4}, /* power and concat (right associative) */ - {3, 3}, {3, 3}, /* equality and inequality */ - {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ - {2, 2}, {1, 1} /* logical (and/or) */ -}; - -#define UNARY_PRIORITY 8 /* priority for unary operators */ - - -/* -** subexpr -> (simpleexp | unop subexpr) { binop subexpr } -** where `binop' is any binary operator with a priority higher than `limit' -*/ -static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { - BinOpr op; - UnOpr uop; - enterlevel(ls); - uop = getunopr(ls->t.token); - if (uop != OPR_NOUNOPR) { - luaX_next(ls); - subexpr(ls, v, UNARY_PRIORITY); - luaK_prefix(ls->fs, uop, v); - } - else simpleexp(ls, v); - /* expand while operators have priorities higher than `limit' */ - op = getbinopr(ls->t.token); - while (op != OPR_NOBINOPR && priority[op].left > limit) { - expdesc v2; - BinOpr nextop; - luaX_next(ls); - luaK_infix(ls->fs, op, v); - /* read sub-expression with higher priority */ - nextop = subexpr(ls, &v2, priority[op].right); - luaK_posfix(ls->fs, op, v, &v2); - op = nextop; - } - leavelevel(ls); - return op; /* return first untreated operator */ -} - - -static void expr (LexState *ls, expdesc *v) { - subexpr(ls, v, 0); -} - -/* }==================================================================== */ - - - -/* -** {====================================================================== -** Rules for Statements -** ======================================================================= -*/ - - -static int block_follow (int token) { - switch (token) { - case TK_ELSE: case TK_ELSEIF: case TK_END: - case TK_UNTIL: case TK_EOS: - return 1; - default: return 0; - } -} - - -static void block (LexState *ls) { - /* block -> chunk */ - FuncState *fs = ls->fs; - BlockCnt bl; - enterblock(fs, &bl, 0); - chunk(ls); - lua_assert(bl.breaklist == NO_JUMP); - leaveblock(fs); -} - - -/* -** structure to chain all variables in the left-hand side of an -** assignment -*/ -struct LHS_assign { - struct LHS_assign *prev; - expdesc v; /* variable (global, local, upvalue, or indexed) */ -}; - - -/* -** check whether, in an assignment to a local variable, the local variable -** is needed in a previous assignment (to a table). If so, save original -** local value in a safe place and use this safe copy in the previous -** assignment. -*/ -static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { - FuncState *fs = ls->fs; - int extra = fs->freereg; /* eventual position to save local variable */ - int conflict = 0; - for (; lh; lh = lh->prev) { - if (lh->v.k == VINDEXED) { - if (lh->v.u.s.info == v->u.s.info) { /* conflict? */ - conflict = 1; - lh->v.u.s.info = extra; /* previous assignment will use safe copy */ - } - if (lh->v.u.s.aux == v->u.s.info) { /* conflict? */ - conflict = 1; - lh->v.u.s.aux = extra; /* previous assignment will use safe copy */ - } - } - } - if (conflict) { - luaK_codeABC(fs, OP_MOVE, fs->freereg, v->u.s.info, 0); /* make copy */ - luaK_reserveregs(fs, 1); - } -} - - -static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { - expdesc e; - check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, - "syntax error"); - if (testnext(ls, ',')) { /* assignment -> `,' primaryexp assignment */ - struct LHS_assign nv; - nv.prev = lh; - primaryexp(ls, &nv.v); - if (nv.v.k == VLOCAL) - check_conflict(ls, lh, &nv.v); - luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, - "variables in assignment"); - assignment(ls, &nv, nvars+1); - } - else { /* assignment -> `=' explist1 */ - int nexps; - checknext(ls, '='); - nexps = explist1(ls, &e); - if (nexps != nvars) { - adjust_assign(ls, nvars, nexps, &e); - if (nexps > nvars) - ls->fs->freereg -= nexps - nvars; /* remove extra values */ - } - else { - luaK_setoneret(ls->fs, &e); /* close last expression */ - luaK_storevar(ls->fs, &lh->v, &e); - return; /* avoid default */ - } - } - init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */ - luaK_storevar(ls->fs, &lh->v, &e); -} - - -static int cond (LexState *ls) { - /* cond -> exp */ - expdesc v; - expr(ls, &v); /* read condition */ - if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */ - luaK_goiftrue(ls->fs, &v); - return v.f; -} - - -static void breakstat (LexState *ls) { - FuncState *fs = ls->fs; - BlockCnt *bl = fs->bl; - int upval = 0; - while (bl && !bl->isbreakable) { - upval |= bl->upval; - bl = bl->previous; - } - if (!bl) - luaX_syntaxerror(ls, "no loop to break"); - if (upval) - luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); - luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); -} - - -static void whilestat (LexState *ls, int line) { - /* whilestat -> WHILE cond DO block END */ - FuncState *fs = ls->fs; - int whileinit; - int condexit; - BlockCnt bl; - luaX_next(ls); /* skip WHILE */ - whileinit = luaK_getlabel(fs); - condexit = cond(ls); - enterblock(fs, &bl, 1); - checknext(ls, TK_DO); - block(ls); - luaK_patchlist(fs, luaK_jump(fs), whileinit); - check_match(ls, TK_END, TK_WHILE, line); - leaveblock(fs); - luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ -} - - -static void repeatstat (LexState *ls, int line) { - /* repeatstat -> REPEAT block UNTIL cond */ - int condexit; - FuncState *fs = ls->fs; - int repeat_init = luaK_getlabel(fs); - BlockCnt bl1, bl2; - enterblock(fs, &bl1, 1); /* loop block */ - enterblock(fs, &bl2, 0); /* scope block */ - luaX_next(ls); /* skip REPEAT */ - chunk(ls); - check_match(ls, TK_UNTIL, TK_REPEAT, line); - condexit = cond(ls); /* read condition (inside scope block) */ - if (!bl2.upval) { /* no upvalues? */ - leaveblock(fs); /* finish scope */ - luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ - } - else { /* complete semantics when there are upvalues */ - breakstat(ls); /* if condition then break */ - luaK_patchtohere(ls->fs, condexit); /* else... */ - leaveblock(fs); /* finish scope... */ - luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ - } - leaveblock(fs); /* finish loop */ -} - - -static int exp1 (LexState *ls) { - expdesc e; - int k; - expr(ls, &e); - k = e.k; - luaK_exp2nextreg(ls->fs, &e); - return k; -} - - -static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { - /* forbody -> DO block */ - BlockCnt bl; - FuncState *fs = ls->fs; - int prep, endfor; - adjustlocalvars(ls, 3); /* control variables */ - checknext(ls, TK_DO); - prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); - enterblock(fs, &bl, 0); /* scope for declared variables */ - adjustlocalvars(ls, nvars); - luaK_reserveregs(fs, nvars); - block(ls); - leaveblock(fs); /* end of scope for declared variables */ - luaK_patchtohere(fs, prep); - endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : - luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); - luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ - luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); -} - - -static void fornum (LexState *ls, TString *varname, int line) { - /* fornum -> NAME = exp1,exp1[,exp1] forbody */ - FuncState *fs = ls->fs; - int base = fs->freereg; - new_localvarliteral(ls, "(for index)", 0); - new_localvarliteral(ls, "(for limit)", 1); - new_localvarliteral(ls, "(for step)", 2); - new_localvar(ls, varname, 3); - checknext(ls, '='); - exp1(ls); /* initial value */ - checknext(ls, ','); - exp1(ls); /* limit */ - if (testnext(ls, ',')) - exp1(ls); /* optional step */ - else { /* default step = 1 */ - luaK_codeABx(fs, OP_LOADK, fs->freereg, luaK_numberK(fs, 1)); - luaK_reserveregs(fs, 1); - } - forbody(ls, base, line, 1, 1); -} - - -static void forlist (LexState *ls, TString *indexname) { - /* forlist -> NAME {,NAME} IN explist1 forbody */ - FuncState *fs = ls->fs; - expdesc e; - int nvars = 0; - int line; - int base = fs->freereg; - /* create control variables */ - new_localvarliteral(ls, "(for generator)", nvars++); - new_localvarliteral(ls, "(for state)", nvars++); - new_localvarliteral(ls, "(for control)", nvars++); - /* create declared variables */ - new_localvar(ls, indexname, nvars++); - while (testnext(ls, ',')) - new_localvar(ls, str_checkname(ls), nvars++); - checknext(ls, TK_IN); - line = ls->linenumber; - adjust_assign(ls, 3, explist1(ls, &e), &e); - luaK_checkstack(fs, 3); /* extra space to call generator */ - forbody(ls, base, line, nvars - 3, 0); -} - - -static void forstat (LexState *ls, int line) { - /* forstat -> FOR (fornum | forlist) END */ - FuncState *fs = ls->fs; - TString *varname; - BlockCnt bl; - enterblock(fs, &bl, 1); /* scope for loop and control variables */ - luaX_next(ls); /* skip `for' */ - varname = str_checkname(ls); /* first variable name */ - switch (ls->t.token) { - case '=': fornum(ls, varname, line); break; - case ',': case TK_IN: forlist(ls, varname); break; - default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); - } - check_match(ls, TK_END, TK_FOR, line); - leaveblock(fs); /* loop scope (`break' jumps to this point) */ -} - - -static int test_then_block (LexState *ls) { - /* test_then_block -> [IF | ELSEIF] cond THEN block */ - int condexit; - luaX_next(ls); /* skip IF or ELSEIF */ - condexit = cond(ls); - checknext(ls, TK_THEN); - block(ls); /* `then' part */ - return condexit; -} - - -static void ifstat (LexState *ls, int line) { - /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ - FuncState *fs = ls->fs; - int flist; - int escapelist = NO_JUMP; - flist = test_then_block(ls); /* IF cond THEN block */ - while (ls->t.token == TK_ELSEIF) { - luaK_concat(fs, &escapelist, luaK_jump(fs)); - luaK_patchtohere(fs, flist); - flist = test_then_block(ls); /* ELSEIF cond THEN block */ - } - if (ls->t.token == TK_ELSE) { - luaK_concat(fs, &escapelist, luaK_jump(fs)); - luaK_patchtohere(fs, flist); - luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ - block(ls); /* `else' part */ - } - else - luaK_concat(fs, &escapelist, flist); - luaK_patchtohere(fs, escapelist); - check_match(ls, TK_END, TK_IF, line); -} - - -static void localfunc (LexState *ls) { - expdesc v, b; - FuncState *fs = ls->fs; - new_localvar(ls, str_checkname(ls), 0); - init_exp(&v, VLOCAL, fs->freereg); - luaK_reserveregs(fs, 1); - adjustlocalvars(ls, 1); - body(ls, &b, 0, ls->linenumber); - luaK_storevar(fs, &v, &b); - /* debug information will only see the variable after this point! */ - getlocvar(fs, fs->nactvar - 1).startpc = fs->pc; -} - - -static void localstat (LexState *ls) { - /* stat -> LOCAL NAME {`,' NAME} [`=' explist1] */ - int nvars = 0; - int nexps; - expdesc e; - do { - new_localvar(ls, str_checkname(ls), nvars++); - } while (testnext(ls, ',')); - if (testnext(ls, '=')) - nexps = explist1(ls, &e); - else { - e.k = VVOID; - nexps = 0; - } - adjust_assign(ls, nvars, nexps, &e); - adjustlocalvars(ls, nvars); -} - - -static int funcname (LexState *ls, expdesc *v) { - /* funcname -> NAME {field} [`:' NAME] */ - int needself = 0; - singlevar(ls, v); - while (ls->t.token == '.') - field(ls, v); - if (ls->t.token == ':') { - needself = 1; - field(ls, v); - } - return needself; -} - - -static void funcstat (LexState *ls, int line) { - /* funcstat -> FUNCTION funcname body */ - int needself; - expdesc v, b; - luaX_next(ls); /* skip FUNCTION */ - needself = funcname(ls, &v); - body(ls, &b, needself, line); - luaK_storevar(ls->fs, &v, &b); - luaK_fixline(ls->fs, line); /* definition `happens' in the first line */ -} - - -static void exprstat (LexState *ls) { - /* stat -> func | assignment */ - FuncState *fs = ls->fs; - struct LHS_assign v; - primaryexp(ls, &v.v); - if (v.v.k == VCALL) /* stat -> func */ - SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */ - else { /* stat -> assignment */ - v.prev = NULL; - assignment(ls, &v, 1); - } -} - - -static void retstat (LexState *ls) { - /* stat -> RETURN explist */ - FuncState *fs = ls->fs; - expdesc e; - int first, nret; /* registers with returned values */ - luaX_next(ls); /* skip RETURN */ - if (block_follow(ls->t.token) || ls->t.token == ';') - first = nret = 0; /* return no values */ - else { - nret = explist1(ls, &e); /* optional return values */ - if (hasmultret(e.k)) { - luaK_setmultret(fs, &e); - if (e.k == VCALL && nret == 1) { /* tail call? */ - SET_OPCODE(getcode(fs,&e), OP_TAILCALL); - lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar); - } - first = fs->nactvar; - nret = LUA_MULTRET; /* return all values */ - } - else { - if (nret == 1) /* only one single value? */ - first = luaK_exp2anyreg(fs, &e); - else { - luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ - first = fs->nactvar; /* return all `active' values */ - lua_assert(nret == fs->freereg - first); - } - } - } - luaK_ret(fs, first, nret); -} - - -static int statement (LexState *ls) { - int line = ls->linenumber; /* may be needed for error messages */ - switch (ls->t.token) { - case TK_IF: { /* stat -> ifstat */ - ifstat(ls, line); - return 0; - } - case TK_WHILE: { /* stat -> whilestat */ - whilestat(ls, line); - return 0; - } - case TK_DO: { /* stat -> DO block END */ - luaX_next(ls); /* skip DO */ - block(ls); - check_match(ls, TK_END, TK_DO, line); - return 0; - } - case TK_FOR: { /* stat -> forstat */ - forstat(ls, line); - return 0; - } - case TK_REPEAT: { /* stat -> repeatstat */ - repeatstat(ls, line); - return 0; - } - case TK_FUNCTION: { - funcstat(ls, line); /* stat -> funcstat */ - return 0; - } - case TK_LOCAL: { /* stat -> localstat */ - luaX_next(ls); /* skip LOCAL */ - if (testnext(ls, TK_FUNCTION)) /* local function? */ - localfunc(ls); - else - localstat(ls); - return 0; - } - case TK_RETURN: { /* stat -> retstat */ - retstat(ls); - return 1; /* must be last statement */ - } - case TK_BREAK: { /* stat -> breakstat */ - luaX_next(ls); /* skip BREAK */ - breakstat(ls); - return 1; /* must be last statement */ - } - default: { - exprstat(ls); - return 0; /* to avoid warnings */ - } - } -} - - -static void chunk (LexState *ls) { - /* chunk -> { stat [`;'] } */ - int islast = 0; - enterlevel(ls); - while (!islast && !block_follow(ls->t.token)) { - islast = statement(ls); - testnext(ls, ';'); - lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && - ls->fs->freereg >= ls->fs->nactvar); - ls->fs->freereg = ls->fs->nactvar; /* free registers */ - } - leavelevel(ls); -} - -/* }====================================================================== */ Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstate.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstate.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstate.h @@ -1,169 +0,0 @@ -/* -** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ -** Global State -** See Copyright Notice in lua.h -*/ - -#ifndef lstate_h -#define lstate_h - -#include "lua.h" - -#include "lobject.h" -#include "ltm.h" -#include "lzio.h" - - - -struct lua_longjmp; /* defined in ldo.c */ - - -/* table of globals */ -#define gt(L) (&L->l_gt) - -/* registry */ -#define registry(L) (&G(L)->l_registry) - - -/* extra stack space to handle TM calls and some other extras */ -#define EXTRA_STACK 5 - - -#define BASIC_CI_SIZE 8 - -#define BASIC_STACK_SIZE (2*LUA_MINSTACK) - - - -typedef struct stringtable { - GCObject **hash; - lu_int32 nuse; /* number of elements */ - int size; -} stringtable; - - -/* -** informations about a call -*/ -typedef struct CallInfo { - StkId base; /* base for this function */ - StkId func; /* function index in the stack */ - StkId top; /* top for this function */ - const Instruction *savedpc; - int nresults; /* expected number of results from this function */ - int tailcalls; /* number of tail calls lost under this entry */ -} CallInfo; - - - -#define curr_func(L) (clvalue(L->ci->func)) -#define ci_func(ci) (clvalue((ci)->func)) -#define f_isLua(ci) (!ci_func(ci)->c.isC) -#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) - - -/* -** `global state', shared by all threads of this state -*/ -typedef struct global_State { - stringtable strt; /* hash table for strings */ - lua_Alloc frealloc; /* function to reallocate memory */ - void *ud; /* auxiliary data to `frealloc' */ - lu_byte currentwhite; - lu_byte gcstate; /* state of garbage collector */ - int sweepstrgc; /* position of sweep in `strt' */ - GCObject *rootgc; /* list of all collectable objects */ - GCObject **sweepgc; /* position of sweep in `rootgc' */ - GCObject *gray; /* list of gray objects */ - GCObject *grayagain; /* list of objects to be traversed atomically */ - GCObject *weak; /* list of weak tables (to be cleared) */ - GCObject *tmudata; /* last element of list of userdata to be GC */ - Mbuffer buff; /* temporary buffer for string concatentation */ - lu_mem GCthreshold; - lu_mem totalbytes; /* number of bytes currently allocated */ - lu_mem estimate; /* an estimate of number of bytes actually in use */ - lu_mem gcdept; /* how much GC is `behind schedule' */ - int gcpause; /* size of pause between successive GCs */ - int gcstepmul; /* GC `granularity' */ - lua_CFunction panic; /* to be called in unprotected errors */ - TValue l_registry; - struct lua_State *mainthread; - UpVal uvhead; /* head of double-linked list of all open upvalues */ - struct Table *mt[NUM_TAGS]; /* metatables for basic types */ - TString *tmname[TM_N]; /* array with tag-method names */ -} global_State; - - -/* -** `per thread' state -*/ -struct lua_State { - CommonHeader; - lu_byte status; - StkId top; /* first free slot in the stack */ - StkId base; /* base of current function */ - global_State *l_G; - CallInfo *ci; /* call info for current function */ - const Instruction *savedpc; /* `savedpc' of current function */ - StkId stack_last; /* last free slot in the stack */ - StkId stack; /* stack base */ - CallInfo *end_ci; /* points after end of ci array*/ - CallInfo *base_ci; /* array of CallInfo's */ - int stacksize; - int size_ci; /* size of array `base_ci' */ - unsigned short nCcalls; /* number of nested C calls */ - unsigned short baseCcalls; /* nested C calls when resuming coroutine */ - lu_byte hookmask; - lu_byte allowhook; - int basehookcount; - int hookcount; - lua_Hook hook; - TValue l_gt; /* table of globals */ - TValue env; /* temporary place for environments */ - GCObject *openupval; /* list of open upvalues in this stack */ - GCObject *gclist; - struct lua_longjmp *errorJmp; /* current error recover point */ - ptrdiff_t errfunc; /* current error handling function (stack index) */ -}; - - -#define G(L) (L->l_G) - - -/* -** Union of all collectable objects -*/ -union GCObject { - GCheader gch; - union TString ts; - union Udata u; - union Closure cl; - struct Table h; - struct Proto p; - struct UpVal uv; - struct lua_State th; /* thread */ -}; - - -/* macros to convert a GCObject into a specific value */ -#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) -#define gco2ts(o) (&rawgco2ts(o)->tsv) -#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) -#define gco2u(o) (&rawgco2u(o)->uv) -#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) -#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) -#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) -#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) -#define ngcotouv(o) \ - check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) -#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) - -/* macro to convert any Lua object into a GCObject */ -#define obj2gco(v) (cast(GCObject *, (v))) - - -LUAI_FUNC lua_State *luaE_newthread (lua_State *L); -LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); - -#endif - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstate.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstate.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstate.c @@ -1,214 +0,0 @@ -/* -** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ -** Global State -** See Copyright Notice in lua.h -*/ - - -#include - -#define lstate_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lgc.h" -#include "llex.h" -#include "lmem.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" - - -#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) -#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) -#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) - - -/* -** Main thread combines a thread state and the global state -*/ -typedef struct LG { - lua_State l; - global_State g; -} LG; - - - -static void stack_init (lua_State *L1, lua_State *L) { - /* initialize CallInfo array */ - L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); - L1->ci = L1->base_ci; - L1->size_ci = BASIC_CI_SIZE; - L1->end_ci = L1->base_ci + L1->size_ci - 1; - /* initialize stack array */ - L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); - L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; - L1->top = L1->stack; - L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; - /* initialize first ci */ - L1->ci->func = L1->top; - setnilvalue(L1->top++); /* `function' entry for this `ci' */ - L1->base = L1->ci->base = L1->top; - L1->ci->top = L1->top + LUA_MINSTACK; -} - - -static void freestack (lua_State *L, lua_State *L1) { - luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); - luaM_freearray(L, L1->stack, L1->stacksize, TValue); -} - - -/* -** open parts that may cause memory-allocation errors -*/ -static void f_luaopen (lua_State *L, void *ud) { - global_State *g = G(L); - UNUSED(ud); - stack_init(L, L); /* init stack */ - sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ - sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ - luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ - luaT_init(L); - luaX_init(L); - luaS_fix(luaS_newliteral(L, MEMERRMSG)); - g->GCthreshold = 4*g->totalbytes; -} - - -static void preinit_state (lua_State *L, global_State *g) { - G(L) = g; - L->stack = NULL; - L->stacksize = 0; - L->errorJmp = NULL; - L->hook = NULL; - L->hookmask = 0; - L->basehookcount = 0; - L->allowhook = 1; - resethookcount(L); - L->openupval = NULL; - L->size_ci = 0; - L->nCcalls = L->baseCcalls = 0; - L->status = 0; - L->base_ci = L->ci = NULL; - L->savedpc = NULL; - L->errfunc = 0; - setnilvalue(gt(L)); -} - - -static void close_state (lua_State *L) { - global_State *g = G(L); - luaF_close(L, L->stack); /* close all upvalues for this thread */ - luaC_freeall(L); /* collect all objects */ - lua_assert(g->rootgc == obj2gco(L)); - lua_assert(g->strt.nuse == 0); - luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); - luaZ_freebuffer(L, &g->buff); - freestack(L, L); - lua_assert(g->totalbytes == sizeof(LG)); - (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); -} - - -lua_State *luaE_newthread (lua_State *L) { - lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); - luaC_link(L, obj2gco(L1), LUA_TTHREAD); - preinit_state(L1, G(L)); - stack_init(L1, L); /* init stack */ - setobj2n(L, gt(L1), gt(L)); /* share table of globals */ - L1->hookmask = L->hookmask; - L1->basehookcount = L->basehookcount; - L1->hook = L->hook; - resethookcount(L1); - lua_assert(iswhite(obj2gco(L1))); - return L1; -} - - -void luaE_freethread (lua_State *L, lua_State *L1) { - luaF_close(L1, L1->stack); /* close all upvalues for this thread */ - lua_assert(L1->openupval == NULL); - luai_userstatefree(L1); - freestack(L, L1); - luaM_freemem(L, fromstate(L1), state_size(lua_State)); -} - - -LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { - int i; - lua_State *L; - global_State *g; - void *l = (*f)(ud, NULL, 0, state_size(LG)); - if (l == NULL) return NULL; - L = tostate(l); - g = &((LG *)L)->g; - L->next = NULL; - L->tt = LUA_TTHREAD; - g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); - L->marked = luaC_white(g); - set2bits(L->marked, FIXEDBIT, SFIXEDBIT); - preinit_state(L, g); - g->frealloc = f; - g->ud = ud; - g->mainthread = L; - g->uvhead.u.l.prev = &g->uvhead; - g->uvhead.u.l.next = &g->uvhead; - g->GCthreshold = 0; /* mark it as unfinished state */ - g->strt.size = 0; - g->strt.nuse = 0; - g->strt.hash = NULL; - setnilvalue(registry(L)); - luaZ_initbuffer(L, &g->buff); - g->panic = NULL; - g->gcstate = GCSpause; - g->rootgc = obj2gco(L); - g->sweepstrgc = 0; - g->sweepgc = &g->rootgc; - g->gray = NULL; - g->grayagain = NULL; - g->weak = NULL; - g->tmudata = NULL; - g->totalbytes = sizeof(LG); - g->gcpause = LUAI_GCPAUSE; - g->gcstepmul = LUAI_GCMUL; - g->gcdept = 0; - for (i=0; imt[i] = NULL; - if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { - /* memory allocation error: free partial state */ - close_state(L); - L = NULL; - } - else - luai_userstateopen(L); - return L; -} - - -static void callallgcTM (lua_State *L, void *ud) { - UNUSED(ud); - luaC_callGCTM(L); /* call GC metamethods for all udata */ -} - - -LUA_API void lua_close (lua_State *L) { - L = G(L)->mainthread; /* only the main thread can be closed */ - lua_lock(L); - luaF_close(L, L->stack); /* close all upvalues for this thread */ - luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ - L->errfunc = 0; /* no error function during GC metamethods */ - do { /* repeat until no more errors */ - L->ci = L->base_ci; - L->base = L->top = L->ci->base; - L->nCcalls = L->baseCcalls = 0; - } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); - lua_assert(G(L)->tmudata == NULL); - luai_userstateclose(L); - close_state(L); -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstring.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstring.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstring.h @@ -1,31 +0,0 @@ -/* -** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ -** String table (keep all strings handled by Lua) -** See Copyright Notice in lua.h -*/ - -#ifndef lstring_h -#define lstring_h - - -#include "lgc.h" -#include "lobject.h" -#include "lstate.h" - - -#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) - -#define sizeudata(u) (sizeof(union Udata)+(u)->len) - -#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) -#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ - (sizeof(s)/sizeof(char))-1)) - -#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) - -LUAI_FUNC void luaS_resize (lua_State *L, int newsize); -LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); -LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstring.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstring.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstring.c @@ -1,111 +0,0 @@ -/* -** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ -** String table (keeps all strings handled by Lua) -** See Copyright Notice in lua.h -*/ - - -#include - -#define lstring_c -#define LUA_CORE - -#include "lua.h" - -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" -#include "lstring.h" - - - -void luaS_resize (lua_State *L, int newsize) { - GCObject **newhash; - stringtable *tb; - int i; - if (G(L)->gcstate == GCSsweepstring) - return; /* cannot resize during GC traverse */ - newhash = luaM_newvector(L, newsize, GCObject *); - tb = &G(L)->strt; - for (i=0; isize; i++) { - GCObject *p = tb->hash[i]; - while (p) { /* for each node in the list */ - GCObject *next = p->gch.next; /* save next */ - unsigned int h = gco2ts(p)->hash; - int h1 = lmod(h, newsize); /* new position */ - lua_assert(cast_int(h%newsize) == lmod(h, newsize)); - p->gch.next = newhash[h1]; /* chain it */ - newhash[h1] = p; - p = next; - } - } - luaM_freearray(L, tb->hash, tb->size, TString *); - tb->size = newsize; - tb->hash = newhash; -} - - -static TString *newlstr (lua_State *L, const char *str, size_t l, - unsigned int h) { - TString *ts; - stringtable *tb; - if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) - luaM_toobig(L); - ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); - ts->tsv.len = l; - ts->tsv.hash = h; - ts->tsv.marked = luaC_white(G(L)); - ts->tsv.tt = LUA_TSTRING; - ts->tsv.reserved = 0; - memcpy(ts+1, str, l*sizeof(char)); - ((char *)(ts+1))[l] = '\0'; /* ending 0 */ - tb = &G(L)->strt; - h = lmod(h, tb->size); - ts->tsv.next = tb->hash[h]; /* chain new entry */ - tb->hash[h] = obj2gco(ts); - tb->nuse++; - if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) - luaS_resize(L, tb->size*2); /* too crowded */ - return ts; -} - - -TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { - GCObject *o; - unsigned int h = cast(unsigned int, l); /* seed */ - size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ - size_t l1; - for (l1=l; l1>=step; l1-=step) /* compute hash */ - h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); - for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; - o != NULL; - o = o->gch.next) { - TString *ts = rawgco2ts(o); - if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { - /* string may be dead */ - if (isdead(G(L), o)) changewhite(o); - return ts; - } - } - return newlstr(L, str, l, h); /* not found */ -} - - -Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { - Udata *u; - if (s > MAX_SIZET - sizeof(Udata)) - luaM_toobig(L); - u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); - u->uv.marked = luaC_white(G(L)); /* is not finalized */ - u->uv.tt = LUA_TUSERDATA; - u->uv.len = s; - u->uv.metatable = NULL; - u->uv.env = e; - /* chain it on udata list (after main thread) */ - u->uv.next = G(L)->mainthread->next; - G(L)->mainthread->next = obj2gco(u); - return u; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstrlib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstrlib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lstrlib.c @@ -1,869 +0,0 @@ -/* -** $Id: lstrlib.c,v 1.132.1.4 2008/07/11 17:27:21 roberto Exp $ -** Standard library for string operations and pattern-matching -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include -#include -#include - -#define lstrlib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - -/* macro to `unsign' a character */ -#define uchar(c) ((unsigned char)(c)) - - - -static int str_len (lua_State *L) { - size_t l; - luaL_checklstring(L, 1, &l); - lua_pushinteger(L, l); - return 1; -} - - -static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) { - /* relative string position: negative means back from end */ - if (pos < 0) pos += (ptrdiff_t)len + 1; - return (pos >= 0) ? pos : 0; -} - - -static int str_sub (lua_State *L) { - size_t l; - const char *s = luaL_checklstring(L, 1, &l); - ptrdiff_t start = posrelat(luaL_checkinteger(L, 2), l); - ptrdiff_t end = posrelat(luaL_optinteger(L, 3, -1), l); - if (start < 1) start = 1; - if (end > (ptrdiff_t)l) end = (ptrdiff_t)l; - if (start <= end) - lua_pushlstring(L, s+start-1, end-start+1); - else lua_pushliteral(L, ""); - return 1; -} - - -static int str_reverse (lua_State *L) { - size_t l; - luaL_Buffer b; - const char *s = luaL_checklstring(L, 1, &l); - luaL_buffinit(L, &b); - while (l--) luaL_addchar(&b, s[l]); - luaL_pushresult(&b); - return 1; -} - - -static int str_lower (lua_State *L) { - size_t l; - size_t i; - luaL_Buffer b; - const char *s = luaL_checklstring(L, 1, &l); - luaL_buffinit(L, &b); - for (i=0; i 0) - luaL_addlstring(&b, s, l); - luaL_pushresult(&b); - return 1; -} - - -static int str_byte (lua_State *L) { - size_t l; - const char *s = luaL_checklstring(L, 1, &l); - ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); - ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); - int n, i; - if (posi <= 0) posi = 1; - if ((size_t)pose > l) pose = l; - if (posi > pose) return 0; /* empty interval; return no values */ - n = (int)(pose - posi + 1); - if (posi + n <= pose) /* overflow? */ - luaL_error(L, "string slice too long"); - luaL_checkstack(L, n, "string slice too long"); - for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) - return luaL_error(ms->L, "invalid capture index"); - return l; -} - - -static int capture_to_close (MatchState *ms) { - int level = ms->level; - for (level--; level>=0; level--) - if (ms->capture[level].len == CAP_UNFINISHED) return level; - return luaL_error(ms->L, "invalid pattern capture"); -} - - -static const char *classend (MatchState *ms, const char *p) { - switch (*p++) { - case L_ESC: { - if (*p == '\0') - luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); - return p+1; - } - case '[': { - if (*p == '^') p++; - do { /* look for a `]' */ - if (*p == '\0') - luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); - if (*(p++) == L_ESC && *p != '\0') - p++; /* skip escapes (e.g. `%]') */ - } while (*p != ']'); - return p+1; - } - default: { - return p; - } - } -} - - -static int match_class (int c, int cl) { - int res; - switch (tolower(cl)) { - case 'a' : res = isalpha(c); break; - case 'c' : res = iscntrl(c); break; - case 'd' : res = isdigit(c); break; - case 'l' : res = islower(c); break; - case 'p' : res = ispunct(c); break; - case 's' : res = isspace(c); break; - case 'u' : res = isupper(c); break; - case 'w' : res = isalnum(c); break; - case 'x' : res = isxdigit(c); break; - case 'z' : res = (c == 0); break; - default: return (cl == c); - } - return (islower(cl) ? res : !res); -} - - -static int matchbracketclass (int c, const char *p, const char *ec) { - int sig = 1; - if (*(p+1) == '^') { - sig = 0; - p++; /* skip the `^' */ - } - while (++p < ec) { - if (*p == L_ESC) { - p++; - if (match_class(c, uchar(*p))) - return sig; - } - else if ((*(p+1) == '-') && (p+2 < ec)) { - p+=2; - if (uchar(*(p-2)) <= c && c <= uchar(*p)) - return sig; - } - else if (uchar(*p) == c) return sig; - } - return !sig; -} - - -static int singlematch (int c, const char *p, const char *ep) { - switch (*p) { - case '.': return 1; /* matches any char */ - case L_ESC: return match_class(c, uchar(*(p+1))); - case '[': return matchbracketclass(c, p, ep-1); - default: return (uchar(*p) == c); - } -} - - -static const char *match (MatchState *ms, const char *s, const char *p); - - -static const char *matchbalance (MatchState *ms, const char *s, - const char *p) { - if (*p == 0 || *(p+1) == 0) - luaL_error(ms->L, "unbalanced pattern"); - if (*s != *p) return NULL; - else { - int b = *p; - int e = *(p+1); - int cont = 1; - while (++s < ms->src_end) { - if (*s == e) { - if (--cont == 0) return s+1; - } - else if (*s == b) cont++; - } - } - return NULL; /* string ends out of balance */ -} - - -static const char *max_expand (MatchState *ms, const char *s, - const char *p, const char *ep) { - ptrdiff_t i = 0; /* counts maximum expand for item */ - while ((s+i)src_end && singlematch(uchar(*(s+i)), p, ep)) - i++; - /* keeps trying to match with the maximum repetitions */ - while (i>=0) { - const char *res = match(ms, (s+i), ep+1); - if (res) return res; - i--; /* else didn't match; reduce 1 repetition to try again */ - } - return NULL; -} - - -static const char *min_expand (MatchState *ms, const char *s, - const char *p, const char *ep) { - for (;;) { - const char *res = match(ms, s, ep+1); - if (res != NULL) - return res; - else if (ssrc_end && singlematch(uchar(*s), p, ep)) - s++; /* try with one more repetition */ - else return NULL; - } -} - - -static const char *start_capture (MatchState *ms, const char *s, - const char *p, int what) { - const char *res; - int level = ms->level; - if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); - ms->capture[level].init = s; - ms->capture[level].len = what; - ms->level = level+1; - if ((res=match(ms, s, p)) == NULL) /* match failed? */ - ms->level--; /* undo capture */ - return res; -} - - -static const char *end_capture (MatchState *ms, const char *s, - const char *p) { - int l = capture_to_close(ms); - const char *res; - ms->capture[l].len = s - ms->capture[l].init; /* close capture */ - if ((res = match(ms, s, p)) == NULL) /* match failed? */ - ms->capture[l].len = CAP_UNFINISHED; /* undo capture */ - return res; -} - - -static const char *match_capture (MatchState *ms, const char *s, int l) { - size_t len; - l = check_capture(ms, l); - len = ms->capture[l].len; - if ((size_t)(ms->src_end-s) >= len && - memcmp(ms->capture[l].init, s, len) == 0) - return s+len; - else return NULL; -} - - -static const char *match (MatchState *ms, const char *s, const char *p) { - init: /* using goto's to optimize tail recursion */ - switch (*p) { - case '(': { /* start capture */ - if (*(p+1) == ')') /* position capture? */ - return start_capture(ms, s, p+2, CAP_POSITION); - else - return start_capture(ms, s, p+1, CAP_UNFINISHED); - } - case ')': { /* end capture */ - return end_capture(ms, s, p+1); - } - case L_ESC: { - switch (*(p+1)) { - case 'b': { /* balanced string? */ - s = matchbalance(ms, s, p+2); - if (s == NULL) return NULL; - p+=4; goto init; /* else return match(ms, s, p+4); */ - } - case 'f': { /* frontier? */ - const char *ep; char previous; - p += 2; - if (*p != '[') - luaL_error(ms->L, "missing " LUA_QL("[") " after " - LUA_QL("%%f") " in pattern"); - ep = classend(ms, p); /* points to what is next */ - previous = (s == ms->src_init) ? '\0' : *(s-1); - if (matchbracketclass(uchar(previous), p, ep-1) || - !matchbracketclass(uchar(*s), p, ep-1)) return NULL; - p=ep; goto init; /* else return match(ms, s, ep); */ - } - default: { - if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ - s = match_capture(ms, s, uchar(*(p+1))); - if (s == NULL) return NULL; - p+=2; goto init; /* else return match(ms, s, p+2) */ - } - goto dflt; /* case default */ - } - } - } - case '\0': { /* end of pattern */ - return s; /* match succeeded */ - } - case '$': { - if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ - return (s == ms->src_end) ? s : NULL; /* check end of string */ - else goto dflt; - } - default: dflt: { /* it is a pattern item */ - const char *ep = classend(ms, p); /* points to what is next */ - int m = ssrc_end && singlematch(uchar(*s), p, ep); - switch (*ep) { - case '?': { /* optional */ - const char *res; - if (m && ((res=match(ms, s+1, ep+1)) != NULL)) - return res; - p=ep+1; goto init; /* else return match(ms, s, ep+1); */ - } - case '*': { /* 0 or more repetitions */ - return max_expand(ms, s, p, ep); - } - case '+': { /* 1 or more repetitions */ - return (m ? max_expand(ms, s+1, p, ep) : NULL); - } - case '-': { /* 0 or more repetitions (minimum) */ - return min_expand(ms, s, p, ep); - } - default: { - if (!m) return NULL; - s++; p=ep; goto init; /* else return match(ms, s+1, ep); */ - } - } - } - } -} - - - -static const char *lmemfind (const char *s1, size_t l1, - const char *s2, size_t l2) { - if (l2 == 0) return s1; /* empty strings are everywhere */ - else if (l2 > l1) return NULL; /* avoids a negative `l1' */ - else { - const char *init; /* to search for a `*s2' inside `s1' */ - l2--; /* 1st char will be checked by `memchr' */ - l1 = l1-l2; /* `s2' cannot be found after that */ - while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { - init++; /* 1st char is already checked */ - if (memcmp(init, s2+1, l2) == 0) - return init-1; - else { /* correct `l1' and `s1' to try again */ - l1 -= init-s1; - s1 = init; - } - } - return NULL; /* not found */ - } -} - - -static void push_onecapture (MatchState *ms, int i, const char *s, - const char *e) { - if (i >= ms->level) { - if (i == 0) /* ms->level == 0, too */ - lua_pushlstring(ms->L, s, e - s); /* add whole match */ - else - luaL_error(ms->L, "invalid capture index"); - } - else { - ptrdiff_t l = ms->capture[i].len; - if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); - if (l == CAP_POSITION) - lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); - else - lua_pushlstring(ms->L, ms->capture[i].init, l); - } -} - - -static int push_captures (MatchState *ms, const char *s, const char *e) { - int i; - int nlevels = (ms->level == 0 && s) ? 1 : ms->level; - luaL_checkstack(ms->L, nlevels, "too many captures"); - for (i = 0; i < nlevels; i++) - push_onecapture(ms, i, s, e); - return nlevels; /* number of strings pushed */ -} - - -static int str_find_aux (lua_State *L, int find) { - size_t l1, l2; - const char *s = luaL_checklstring(L, 1, &l1); - const char *p = luaL_checklstring(L, 2, &l2); - ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1; - if (init < 0) init = 0; - else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; - if (find && (lua_toboolean(L, 4) || /* explicit request? */ - strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ - /* do a plain search */ - const char *s2 = lmemfind(s+init, l1-init, p, l2); - if (s2) { - lua_pushinteger(L, s2-s+1); - lua_pushinteger(L, s2-s+l2); - return 2; - } - } - else { - MatchState ms; - int anchor = (*p == '^') ? (p++, 1) : 0; - const char *s1=s+init; - ms.L = L; - ms.src_init = s; - ms.src_end = s+l1; - do { - const char *res; - ms.level = 0; - if ((res=match(&ms, s1, p)) != NULL) { - if (find) { - lua_pushinteger(L, s1-s+1); /* start */ - lua_pushinteger(L, res-s); /* end */ - return push_captures(&ms, NULL, 0) + 2; - } - else - return push_captures(&ms, s1, res); - } - } while (s1++ < ms.src_end && !anchor); - } - lua_pushnil(L); /* not found */ - return 1; -} - - -static int str_find (lua_State *L) { - return str_find_aux(L, 1); -} - - -static int str_match (lua_State *L) { - return str_find_aux(L, 0); -} - - -static int gmatch_aux (lua_State *L) { - MatchState ms; - size_t ls; - const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls); - const char *p = lua_tostring(L, lua_upvalueindex(2)); - const char *src; - ms.L = L; - ms.src_init = s; - ms.src_end = s+ls; - for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3)); - src <= ms.src_end; - src++) { - const char *e; - ms.level = 0; - if ((e = match(&ms, src, p)) != NULL) { - lua_Integer newstart = e-s; - if (e == src) newstart++; /* empty match? go at least one position */ - lua_pushinteger(L, newstart); - lua_replace(L, lua_upvalueindex(3)); - return push_captures(&ms, src, e); - } - } - return 0; /* not found */ -} - - -static int gmatch (lua_State *L) { - luaL_checkstring(L, 1); - luaL_checkstring(L, 2); - lua_settop(L, 2); - lua_pushinteger(L, 0); - lua_pushcclosure(L, gmatch_aux, 3); - return 1; -} - - -static int gfind_nodef (lua_State *L) { - return luaL_error(L, LUA_QL("string.gfind") " was renamed to " - LUA_QL("string.gmatch")); -} - - -static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, - const char *e) { - size_t l, i; - const char *news = lua_tolstring(ms->L, 3, &l); - for (i = 0; i < l; i++) { - if (news[i] != L_ESC) - luaL_addchar(b, news[i]); - else { - i++; /* skip ESC */ - if (!isdigit(uchar(news[i]))) - luaL_addchar(b, news[i]); - else if (news[i] == '0') - luaL_addlstring(b, s, e - s); - else { - push_onecapture(ms, news[i] - '1', s, e); - luaL_addvalue(b); /* add capture to accumulated result */ - } - } - } -} - - -static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, - const char *e) { - lua_State *L = ms->L; - switch (lua_type(L, 3)) { - case LUA_TNUMBER: - case LUA_TSTRING: { - add_s(ms, b, s, e); - return; - } - case LUA_TFUNCTION: { - int n; - lua_pushvalue(L, 3); - n = push_captures(ms, s, e); - lua_call(L, n, 1); - break; - } - case LUA_TTABLE: { - push_onecapture(ms, 0, s, e); - lua_gettable(L, 3); - break; - } - } - if (!lua_toboolean(L, -1)) { /* nil or false? */ - lua_pop(L, 1); - lua_pushlstring(L, s, e - s); /* keep original text */ - } - else if (!lua_isstring(L, -1)) - luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); - luaL_addvalue(b); /* add result to accumulator */ -} - - -static int str_gsub (lua_State *L) { - size_t srcl; - const char *src = luaL_checklstring(L, 1, &srcl); - const char *p = luaL_checkstring(L, 2); - int tr = lua_type(L, 3); - int max_s = luaL_optint(L, 4, srcl+1); - int anchor = (*p == '^') ? (p++, 1) : 0; - int n = 0; - MatchState ms; - luaL_Buffer b; - luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || - tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, - "string/function/table expected"); - luaL_buffinit(L, &b); - ms.L = L; - ms.src_init = src; - ms.src_end = src+srcl; - while (n < max_s) { - const char *e; - ms.level = 0; - e = match(&ms, src, p); - if (e) { - n++; - add_value(&ms, &b, src, e); - } - if (e && e>src) /* non empty match? */ - src = e; /* skip it */ - else if (src < ms.src_end) - luaL_addchar(&b, *src++); - else break; - if (anchor) break; - } - luaL_addlstring(&b, src, ms.src_end-src); - luaL_pushresult(&b); - lua_pushinteger(L, n); /* number of substitutions */ - return 2; -} - -/* }====================================================== */ - - -/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */ -#define MAX_ITEM 512 -/* valid flags in a format specification */ -#define FLAGS "-+ #0" -/* -** maximum size of each format specification (such as '%-099.99d') -** (+10 accounts for %99.99x plus margin of error) -*/ -#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10) - - -static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { - size_t l; - const char *s = luaL_checklstring(L, arg, &l); - luaL_addchar(b, '"'); - while (l--) { - switch (*s) { - case '"': case '\\': case '\n': { - luaL_addchar(b, '\\'); - luaL_addchar(b, *s); - break; - } - case '\r': { - luaL_addlstring(b, "\\r", 2); - break; - } - case '\0': { - luaL_addlstring(b, "\\000", 4); - break; - } - default: { - luaL_addchar(b, *s); - break; - } - } - s++; - } - luaL_addchar(b, '"'); -} - -static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { - const char *p = strfrmt; - while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ - if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) - luaL_error(L, "invalid format (repeated flags)"); - if (isdigit(uchar(*p))) p++; /* skip width */ - if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ - if (*p == '.') { - p++; - if (isdigit(uchar(*p))) p++; /* skip precision */ - if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ - } - if (isdigit(uchar(*p))) - luaL_error(L, "invalid format (width or precision too long)"); - *(form++) = '%'; - strncpy(form, strfrmt, p - strfrmt + 1); - form += p - strfrmt + 1; - *form = '\0'; - return p; -} - - -static void addintlen (char *form) { - size_t l = strlen(form); - char spec = form[l - 1]; - strcpy(form + l - 1, LUA_INTFRMLEN); - form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; - form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; -} - - -static int str_format (lua_State *L) { - int arg = 1; - size_t sfl; - const char *strfrmt = luaL_checklstring(L, arg, &sfl); - const char *strfrmt_end = strfrmt+sfl; - luaL_Buffer b; - luaL_buffinit(L, &b); - while (strfrmt < strfrmt_end) { - if (*strfrmt != L_ESC) - luaL_addchar(&b, *strfrmt++); - else if (*++strfrmt == L_ESC) - luaL_addchar(&b, *strfrmt++); /* %% */ - else { /* format item */ - char form[MAX_FORMAT]; /* to store the format (`%...') */ - char buff[MAX_ITEM]; /* to store the formatted item */ - arg++; - strfrmt = scanformat(L, strfrmt, form); - switch (*strfrmt++) { - case 'c': { - sprintf(buff, form, (int)luaL_checknumber(L, arg)); - break; - } - case 'd': case 'i': { - addintlen(form); - sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); - break; - } - case 'o': case 'u': case 'x': case 'X': { - addintlen(form); - sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); - break; - } - case 'e': case 'E': case 'f': - case 'g': case 'G': { - sprintf(buff, form, (double)luaL_checknumber(L, arg)); - break; - } - case 'q': { - addquoted(L, &b, arg); - continue; /* skip the 'addsize' at the end */ - } - case 's': { - size_t l; - const char *s = luaL_checklstring(L, arg, &l); - if (!strchr(form, '.') && l >= 100) { - /* no precision and string is too long to be formatted; - keep original string */ - lua_pushvalue(L, arg); - luaL_addvalue(&b); - continue; /* skip the `addsize' at the end */ - } - else { - sprintf(buff, form, s); - break; - } - } - default: { /* also treat cases `pnLlh' */ - return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " - LUA_QL("format"), *(strfrmt - 1)); - } - } - luaL_addlstring(&b, buff, strlen(buff)); - } - } - luaL_pushresult(&b); - return 1; -} - - -static const luaL_Reg strlib[] = { - {"byte", str_byte}, - {"char", str_char}, - {"dump", str_dump}, - {"find", str_find}, - {"format", str_format}, - {"gfind", gfind_nodef}, - {"gmatch", gmatch}, - {"gsub", str_gsub}, - {"len", str_len}, - {"lower", str_lower}, - {"match", str_match}, - {"rep", str_rep}, - {"reverse", str_reverse}, - {"sub", str_sub}, - {"upper", str_upper}, - {NULL, NULL} -}; - - -static void createmetatable (lua_State *L) { - lua_createtable(L, 0, 1); /* create metatable for strings */ - lua_pushliteral(L, ""); /* dummy string */ - lua_pushvalue(L, -2); - lua_setmetatable(L, -2); /* set string metatable */ - lua_pop(L, 1); /* pop dummy string */ - lua_pushvalue(L, -2); /* string library... */ - lua_setfield(L, -2, "__index"); /* ...is the __index metamethod */ - lua_pop(L, 1); /* pop metatable */ -} - - -/* -** Open string library -*/ -LUALIB_API int luaopen_string (lua_State *L) { - luaL_register(L, LUA_STRLIBNAME, strlib); -#if defined(LUA_COMPAT_GFIND) - lua_getfield(L, -1, "gmatch"); - lua_setfield(L, -2, "gfind"); -#endif - createmetatable(L); - return 1; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltable.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltable.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltable.h @@ -1,40 +0,0 @@ -/* -** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ -** Lua tables (hash) -** See Copyright Notice in lua.h -*/ - -#ifndef ltable_h -#define ltable_h - -#include "lobject.h" - - -#define gnode(t,i) (&(t)->node[i]) -#define gkey(n) (&(n)->i_key.nk) -#define gval(n) (&(n)->i_val) -#define gnext(n) ((n)->i_key.nk.next) - -#define key2tval(n) (&(n)->i_key.tvk) - - -LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); -LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); -LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); -LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); -LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); -LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); -LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); -LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); -LUAI_FUNC void luaH_free (lua_State *L, Table *t); -LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); -LUAI_FUNC int luaH_getn (Table *t); - - -#if defined(LUA_DEBUG) -LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); -LUAI_FUNC int luaH_isdummy (Node *n); -#endif - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltable.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltable.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltable.c @@ -1,588 +0,0 @@ -/* -** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $ -** Lua tables (hash) -** See Copyright Notice in lua.h -*/ - - -/* -** Implementation of tables (aka arrays, objects, or hash tables). -** Tables keep its elements in two parts: an array part and a hash part. -** Non-negative integer keys are all candidates to be kept in the array -** part. The actual size of the array is the largest `n' such that at -** least half the slots between 0 and n are in use. -** Hash uses a mix of chained scatter table with Brent's variation. -** A main invariant of these tables is that, if an element is not -** in its main position (i.e. the `original' position that its hash gives -** to it), then the colliding element is in its own main position. -** Hence even when the load factor reaches 100%, performance remains good. -*/ - -#include -#include - -#define ltable_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lgc.h" -#include "lmem.h" -#include "lobject.h" -#include "lstate.h" -#include "ltable.h" - - -/* -** max size of array part is 2^MAXBITS -*/ -#if LUAI_BITSINT > 26 -#define MAXBITS 26 -#else -#define MAXBITS (LUAI_BITSINT-2) -#endif - -#define MAXASIZE (1 << MAXBITS) - - -#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) - -#define hashstr(t,str) hashpow2(t, (str)->tsv.hash) -#define hashboolean(t,p) hashpow2(t, p) - - -/* -** for some types, it is better to avoid modulus by power of 2, as -** they tend to have many 2 factors. -*/ -#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) - - -#define hashpointer(t,p) hashmod(t, IntPoint(p)) - - -/* -** number of ints inside a lua_Number -*/ -#define numints cast_int(sizeof(lua_Number)/sizeof(int)) - - - -#define dummynode (&dummynode_) - -static const Node dummynode_ = { - {{NULL}, LUA_TNIL}, /* value */ - {{{NULL}, LUA_TNIL, NULL}} /* key */ -}; - - -/* -** hash for lua_Numbers -*/ -static Node *hashnum (const Table *t, lua_Number n) { - unsigned int a[numints]; - int i; - if (luai_numeq(n, 0)) /* avoid problems with -0 */ - return gnode(t, 0); - memcpy(a, &n, sizeof(a)); - for (i = 1; i < numints; i++) a[0] += a[i]; - return hashmod(t, a[0]); -} - - - -/* -** returns the `main' position of an element in a table (that is, the index -** of its hash value) -*/ -static Node *mainposition (const Table *t, const TValue *key) { - switch (ttype(key)) { - case LUA_TNUMBER: - return hashnum(t, nvalue(key)); - case LUA_TSTRING: - return hashstr(t, rawtsvalue(key)); - case LUA_TBOOLEAN: - return hashboolean(t, bvalue(key)); - case LUA_TLIGHTUSERDATA: - return hashpointer(t, pvalue(key)); - default: - return hashpointer(t, gcvalue(key)); - } -} - - -/* -** returns the index for `key' if `key' is an appropriate key to live in -** the array part of the table, -1 otherwise. -*/ -static int arrayindex (const TValue *key) { - if (ttisnumber(key)) { - lua_Number n = nvalue(key); - int k; - lua_number2int(k, n); - if (luai_numeq(cast_num(k), n)) - return k; - } - return -1; /* `key' did not match some condition */ -} - - -/* -** returns the index of a `key' for table traversals. First goes all -** elements in the array part, then elements in the hash part. The -** beginning of a traversal is signalled by -1. -*/ -static int findindex (lua_State *L, Table *t, StkId key) { - int i; - if (ttisnil(key)) return -1; /* first iteration */ - i = arrayindex(key); - if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ - return i-1; /* yes; that's the index (corrected to C) */ - else { - Node *n = mainposition(t, key); - do { /* check whether `key' is somewhere in the chain */ - /* key may be dead already, but it is ok to use it in `next' */ - if (luaO_rawequalObj(key2tval(n), key) || - (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && - gcvalue(gkey(n)) == gcvalue(key))) { - i = cast_int(n - gnode(t, 0)); /* key index in hash table */ - /* hash elements are numbered after array ones */ - return i + t->sizearray; - } - else n = gnext(n); - } while (n); - luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ - return 0; /* to avoid warnings */ - } -} - - -int luaH_next (lua_State *L, Table *t, StkId key) { - int i = findindex(L, t, key); /* find original element */ - for (i++; i < t->sizearray; i++) { /* try first array part */ - if (!ttisnil(&t->array[i])) { /* a non-nil value? */ - setnvalue(key, cast_num(i+1)); - setobj2s(L, key+1, &t->array[i]); - return 1; - } - } - for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ - if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ - setobj2s(L, key, key2tval(gnode(t, i))); - setobj2s(L, key+1, gval(gnode(t, i))); - return 1; - } - } - return 0; /* no more elements */ -} - - -/* -** {============================================================= -** Rehash -** ============================================================== -*/ - - -static int computesizes (int nums[], int *narray) { - int i; - int twotoi; /* 2^i */ - int a = 0; /* number of elements smaller than 2^i */ - int na = 0; /* number of elements to go to array part */ - int n = 0; /* optimal size for array part */ - for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) { - if (nums[i] > 0) { - a += nums[i]; - if (a > twotoi/2) { /* more than half elements present? */ - n = twotoi; /* optimal size (till now) */ - na = a; /* all elements smaller than n will go to array part */ - } - } - if (a == *narray) break; /* all elements already counted */ - } - *narray = n; - lua_assert(*narray/2 <= na && na <= *narray); - return na; -} - - -static int countint (const TValue *key, int *nums) { - int k = arrayindex(key); - if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */ - nums[ceillog2(k)]++; /* count as such */ - return 1; - } - else - return 0; -} - - -static int numusearray (const Table *t, int *nums) { - int lg; - int ttlg; /* 2^lg */ - int ause = 0; /* summation of `nums' */ - int i = 1; /* count to traverse all array keys */ - for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ - int lc = 0; /* counter */ - int lim = ttlg; - if (lim > t->sizearray) { - lim = t->sizearray; /* adjust upper limit */ - if (i > lim) - break; /* no more elements to count */ - } - /* count elements in range (2^(lg-1), 2^lg] */ - for (; i <= lim; i++) { - if (!ttisnil(&t->array[i-1])) - lc++; - } - nums[lg] += lc; - ause += lc; - } - return ause; -} - - -static int numusehash (const Table *t, int *nums, int *pnasize) { - int totaluse = 0; /* total number of elements */ - int ause = 0; /* summation of `nums' */ - int i = sizenode(t); - while (i--) { - Node *n = &t->node[i]; - if (!ttisnil(gval(n))) { - ause += countint(key2tval(n), nums); - totaluse++; - } - } - *pnasize += ause; - return totaluse; -} - - -static void setarrayvector (lua_State *L, Table *t, int size) { - int i; - luaM_reallocvector(L, t->array, t->sizearray, size, TValue); - for (i=t->sizearray; iarray[i]); - t->sizearray = size; -} - - -static void setnodevector (lua_State *L, Table *t, int size) { - int lsize; - if (size == 0) { /* no elements to hash part? */ - t->node = cast(Node *, dummynode); /* use common `dummynode' */ - lsize = 0; - } - else { - int i; - lsize = ceillog2(size); - if (lsize > MAXBITS) - luaG_runerror(L, "table overflow"); - size = twoto(lsize); - t->node = luaM_newvector(L, size, Node); - for (i=0; ilsizenode = cast_byte(lsize); - t->lastfree = gnode(t, size); /* all positions are free */ -} - - -static void resize (lua_State *L, Table *t, int nasize, int nhsize) { - int i; - int oldasize = t->sizearray; - int oldhsize = t->lsizenode; - Node *nold = t->node; /* save old hash ... */ - if (nasize > oldasize) /* array part must grow? */ - setarrayvector(L, t, nasize); - /* create new hash part with appropriate size */ - setnodevector(L, t, nhsize); - if (nasize < oldasize) { /* array part must shrink? */ - t->sizearray = nasize; - /* re-insert elements from vanishing slice */ - for (i=nasize; iarray[i])) - setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]); - } - /* shrink array */ - luaM_reallocvector(L, t->array, oldasize, nasize, TValue); - } - /* re-insert elements from hash part */ - for (i = twoto(oldhsize) - 1; i >= 0; i--) { - Node *old = nold+i; - if (!ttisnil(gval(old))) - setobjt2t(L, luaH_set(L, t, key2tval(old)), gval(old)); - } - if (nold != dummynode) - luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ -} - - -void luaH_resizearray (lua_State *L, Table *t, int nasize) { - int nsize = (t->node == dummynode) ? 0 : sizenode(t); - resize(L, t, nasize, nsize); -} - - -static void rehash (lua_State *L, Table *t, const TValue *ek) { - int nasize, na; - int nums[MAXBITS+1]; /* nums[i] = number of keys between 2^(i-1) and 2^i */ - int i; - int totaluse; - for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */ - nasize = numusearray(t, nums); /* count keys in array part */ - totaluse = nasize; /* all those keys are integer keys */ - totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */ - /* count extra key */ - nasize += countint(ek, nums); - totaluse++; - /* compute new size for array part */ - na = computesizes(nums, &nasize); - /* resize the table to new computed sizes */ - resize(L, t, nasize, totaluse - na); -} - - - -/* -** }============================================================= -*/ - - -Table *luaH_new (lua_State *L, int narray, int nhash) { - Table *t = luaM_new(L, Table); - luaC_link(L, obj2gco(t), LUA_TTABLE); - t->metatable = NULL; - t->flags = cast_byte(~0); - /* temporary values (kept only if some malloc fails) */ - t->array = NULL; - t->sizearray = 0; - t->lsizenode = 0; - t->node = cast(Node *, dummynode); - setarrayvector(L, t, narray); - setnodevector(L, t, nhash); - return t; -} - - -void luaH_free (lua_State *L, Table *t) { - if (t->node != dummynode) - luaM_freearray(L, t->node, sizenode(t), Node); - luaM_freearray(L, t->array, t->sizearray, TValue); - luaM_free(L, t); -} - - -static Node *getfreepos (Table *t) { - while (t->lastfree-- > t->node) { - if (ttisnil(gkey(t->lastfree))) - return t->lastfree; - } - return NULL; /* could not find a free place */ -} - - - -/* -** inserts a new key into a hash table; first, check whether key's main -** position is free. If not, check whether colliding node is in its main -** position or not: if it is not, move colliding node to an empty place and -** put new key in its main position; otherwise (colliding node is in its main -** position), new key goes to an empty position. -*/ -static TValue *newkey (lua_State *L, Table *t, const TValue *key) { - Node *mp = mainposition(t, key); - if (!ttisnil(gval(mp)) || mp == dummynode) { - Node *othern; - Node *n = getfreepos(t); /* get a free place */ - if (n == NULL) { /* cannot find a free place? */ - rehash(L, t, key); /* grow table */ - return luaH_set(L, t, key); /* re-insert key into grown table */ - } - lua_assert(n != dummynode); - othern = mainposition(t, key2tval(mp)); - if (othern != mp) { /* is colliding node out of its main position? */ - /* yes; move colliding node into free position */ - while (gnext(othern) != mp) othern = gnext(othern); /* find previous */ - gnext(othern) = n; /* redo the chain with `n' in place of `mp' */ - *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */ - gnext(mp) = NULL; /* now `mp' is free */ - setnilvalue(gval(mp)); - } - else { /* colliding node is in its own main position */ - /* new node will go into free position */ - gnext(n) = gnext(mp); /* chain new position */ - gnext(mp) = n; - mp = n; - } - } - gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; - luaC_barriert(L, t, key); - lua_assert(ttisnil(gval(mp))); - return gval(mp); -} - - -/* -** search function for integers -*/ -const TValue *luaH_getnum (Table *t, int key) { - /* (1 <= key && key <= t->sizearray) */ - if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray)) - return &t->array[key-1]; - else { - lua_Number nk = cast_num(key); - Node *n = hashnum(t, nk); - do { /* check whether `key' is somewhere in the chain */ - if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk)) - return gval(n); /* that's it */ - else n = gnext(n); - } while (n); - return luaO_nilobject; - } -} - - -/* -** search function for strings -*/ -const TValue *luaH_getstr (Table *t, TString *key) { - Node *n = hashstr(t, key); - do { /* check whether `key' is somewhere in the chain */ - if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key) - return gval(n); /* that's it */ - else n = gnext(n); - } while (n); - return luaO_nilobject; -} - - -/* -** main search function -*/ -const TValue *luaH_get (Table *t, const TValue *key) { - switch (ttype(key)) { - case LUA_TNIL: return luaO_nilobject; - case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key)); - case LUA_TNUMBER: { - int k; - lua_Number n = nvalue(key); - lua_number2int(k, n); - if (luai_numeq(cast_num(k), nvalue(key))) /* index is int? */ - return luaH_getnum(t, k); /* use specialized version */ - /* else go through */ - } - default: { - Node *n = mainposition(t, key); - do { /* check whether `key' is somewhere in the chain */ - if (luaO_rawequalObj(key2tval(n), key)) - return gval(n); /* that's it */ - else n = gnext(n); - } while (n); - return luaO_nilobject; - } - } -} - - -TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { - const TValue *p = luaH_get(t, key); - t->flags = 0; - if (p != luaO_nilobject) - return cast(TValue *, p); - else { - if (ttisnil(key)) luaG_runerror(L, "table index is nil"); - else if (ttisnumber(key) && luai_numisnan(nvalue(key))) - luaG_runerror(L, "table index is NaN"); - return newkey(L, t, key); - } -} - - -TValue *luaH_setnum (lua_State *L, Table *t, int key) { - const TValue *p = luaH_getnum(t, key); - if (p != luaO_nilobject) - return cast(TValue *, p); - else { - TValue k; - setnvalue(&k, cast_num(key)); - return newkey(L, t, &k); - } -} - - -TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { - const TValue *p = luaH_getstr(t, key); - if (p != luaO_nilobject) - return cast(TValue *, p); - else { - TValue k; - setsvalue(L, &k, key); - return newkey(L, t, &k); - } -} - - -static int unbound_search (Table *t, unsigned int j) { - unsigned int i = j; /* i is zero or a present index */ - j++; - /* find `i' and `j' such that i is present and j is not */ - while (!ttisnil(luaH_getnum(t, j))) { - i = j; - j *= 2; - if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ - /* table was built with bad purposes: resort to linear search */ - i = 1; - while (!ttisnil(luaH_getnum(t, i))) i++; - return i - 1; - } - } - /* now do a binary search between them */ - while (j - i > 1) { - unsigned int m = (i+j)/2; - if (ttisnil(luaH_getnum(t, m))) j = m; - else i = m; - } - return i; -} - - -/* -** Try to find a boundary in table `t'. A `boundary' is an integer index -** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). -*/ -int luaH_getn (Table *t) { - unsigned int j = t->sizearray; - if (j > 0 && ttisnil(&t->array[j - 1])) { - /* there is a boundary in the array part: (binary) search for it */ - unsigned int i = 0; - while (j - i > 1) { - unsigned int m = (i+j)/2; - if (ttisnil(&t->array[m - 1])) j = m; - else i = m; - } - return i; - } - /* else must find a boundary in hash part */ - else if (t->node == dummynode) /* hash part is empty? */ - return j; /* that is easy... */ - else return unbound_search(t, j); -} - - - -#if defined(LUA_DEBUG) - -Node *luaH_mainposition (const Table *t, const TValue *key) { - return mainposition(t, key); -} - -int luaH_isdummy (Node *n) { return n == dummynode; } - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltablib.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltablib.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltablib.c @@ -1,287 +0,0 @@ -/* -** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $ -** Library for Table Manipulation -** See Copyright Notice in lua.h -*/ - - -#include - -#define ltablib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - -#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) - - -static int foreachi (lua_State *L) { - int i; - int n = aux_getn(L, 1); - luaL_checktype(L, 2, LUA_TFUNCTION); - for (i=1; i <= n; i++) { - lua_pushvalue(L, 2); /* function */ - lua_pushinteger(L, i); /* 1st argument */ - lua_rawgeti(L, 1, i); /* 2nd argument */ - lua_call(L, 2, 1); - if (!lua_isnil(L, -1)) - return 1; - lua_pop(L, 1); /* remove nil result */ - } - return 0; -} - - -static int foreach (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - luaL_checktype(L, 2, LUA_TFUNCTION); - lua_pushnil(L); /* first key */ - while (lua_next(L, 1)) { - lua_pushvalue(L, 2); /* function */ - lua_pushvalue(L, -3); /* key */ - lua_pushvalue(L, -3); /* value */ - lua_call(L, 2, 1); - if (!lua_isnil(L, -1)) - return 1; - lua_pop(L, 2); /* remove value and result */ - } - return 0; -} - - -static int maxn (lua_State *L) { - lua_Number max = 0; - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushnil(L); /* first key */ - while (lua_next(L, 1)) { - lua_pop(L, 1); /* remove value */ - if (lua_type(L, -1) == LUA_TNUMBER) { - lua_Number v = lua_tonumber(L, -1); - if (v > max) max = v; - } - } - lua_pushnumber(L, max); - return 1; -} - - -static int getn (lua_State *L) { - lua_pushinteger(L, aux_getn(L, 1)); - return 1; -} - - -static int setn (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); -#ifndef luaL_setn - luaL_setn(L, 1, luaL_checkint(L, 2)); -#else - luaL_error(L, LUA_QL("setn") " is obsolete"); -#endif - lua_pushvalue(L, 1); - return 1; -} - - -static int tinsert (lua_State *L) { - int e = aux_getn(L, 1) + 1; /* first empty element */ - int pos; /* where to insert new element */ - switch (lua_gettop(L)) { - case 2: { /* called with only 2 arguments */ - pos = e; /* insert new element at the end */ - break; - } - case 3: { - int i; - pos = luaL_checkint(L, 2); /* 2nd argument is the position */ - if (pos > e) e = pos; /* `grow' array if necessary */ - for (i = e; i > pos; i--) { /* move up elements */ - lua_rawgeti(L, 1, i-1); - lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ - } - break; - } - default: { - return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); - } - } - luaL_setn(L, 1, e); /* new size */ - lua_rawseti(L, 1, pos); /* t[pos] = v */ - return 0; -} - - -static int tremove (lua_State *L) { - int e = aux_getn(L, 1); - int pos = luaL_optint(L, 2, e); - if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ - return 0; /* nothing to remove */ - luaL_setn(L, 1, e - 1); /* t.n = n-1 */ - lua_rawgeti(L, 1, pos); /* result = t[pos] */ - for ( ;pos= P */ - while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { - if (i>u) luaL_error(L, "invalid order function for sorting"); - lua_pop(L, 1); /* remove a[i] */ - } - /* repeat --j until a[j] <= P */ - while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { - if (jflags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) - -#define fasttm(l,et,e) gfasttm(G(l), et, e) - -LUAI_DATA const char *const luaT_typenames[]; - - -LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); -LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, - TMS event); -LUAI_FUNC void luaT_init (lua_State *L); - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltm.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltm.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/ltm.c @@ -1,75 +0,0 @@ -/* -** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ -** Tag methods -** See Copyright Notice in lua.h -*/ - - -#include - -#define ltm_c -#define LUA_CORE - -#include "lua.h" - -#include "lobject.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" - - - -const char *const luaT_typenames[] = { - "nil", "boolean", "userdata", "number", - "string", "table", "function", "userdata", "thread", - "proto", "upval" -}; - - -void luaT_init (lua_State *L) { - static const char *const luaT_eventname[] = { /* ORDER TM */ - "__index", "__newindex", - "__gc", "__mode", "__eq", - "__add", "__sub", "__mul", "__div", "__mod", - "__pow", "__unm", "__len", "__lt", "__le", - "__concat", "__call" - }; - int i; - for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); - luaS_fix(G(L)->tmname[i]); /* never collect these names */ - } -} - - -/* -** function to be used with macro "fasttm": optimized for absence of -** tag methods -*/ -const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { - const TValue *tm = luaH_getstr(events, ename); - lua_assert(event <= TM_EQ); - if (ttisnil(tm)) { /* no tag method? */ - events->flags |= cast_byte(1u<metatable; - break; - case LUA_TUSERDATA: - mt = uvalue(o)->metatable; - break; - default: - mt = G(L)->mt[ttype(o)]; - } - return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lua.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lua.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lua.h @@ -1,388 +0,0 @@ -/* -** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ -** Lua - An Extensible Extension Language -** Lua.org, PUC-Rio, Brazil (http://www.lua.org) -** See Copyright Notice at the end of this file -*/ - - -#ifndef lua_h -#define lua_h - -#include -#include - - -#include "luaconf.h" - - -#define LUA_VERSION "Lua 5.1" -#define LUA_RELEASE "Lua 5.1.4" -#define LUA_VERSION_NUM 501 -#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" -#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" - - -/* mark for precompiled code (`Lua') */ -#define LUA_SIGNATURE "\033Lua" - -/* option for multiple returns in `lua_pcall' and `lua_call' */ -#define LUA_MULTRET (-1) - - -/* -** pseudo-indices -*/ -#define LUA_REGISTRYINDEX (-10000) -#define LUA_ENVIRONINDEX (-10001) -#define LUA_GLOBALSINDEX (-10002) -#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) - - -/* thread status; 0 is OK */ -#define LUA_YIELD 1 -#define LUA_ERRRUN 2 -#define LUA_ERRSYNTAX 3 -#define LUA_ERRMEM 4 -#define LUA_ERRERR 5 - - -typedef struct lua_State lua_State; - -typedef int (*lua_CFunction) (lua_State *L); - - -/* -** functions that read/write blocks when loading/dumping Lua chunks -*/ -typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); - -typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); - - -/* -** prototype for memory-allocation functions -*/ -typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); - - -/* -** basic types -*/ -#define LUA_TNONE (-1) - -#define LUA_TNIL 0 -#define LUA_TBOOLEAN 1 -#define LUA_TLIGHTUSERDATA 2 -#define LUA_TNUMBER 3 -#define LUA_TSTRING 4 -#define LUA_TTABLE 5 -#define LUA_TFUNCTION 6 -#define LUA_TUSERDATA 7 -#define LUA_TTHREAD 8 - - - -/* minimum Lua stack available to a C function */ -#define LUA_MINSTACK 20 - - -/* -** generic extra include file -*/ -#if defined(LUA_USER_H) -#include LUA_USER_H -#endif - - -/* type of numbers in Lua */ -typedef LUA_NUMBER lua_Number; - - -/* type for integer functions */ -typedef LUA_INTEGER lua_Integer; - - - -/* -** state manipulation -*/ -LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); -LUA_API void (lua_close) (lua_State *L); -LUA_API lua_State *(lua_newthread) (lua_State *L); - -LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); - - -/* -** basic stack manipulation -*/ -LUA_API int (lua_gettop) (lua_State *L); -LUA_API void (lua_settop) (lua_State *L, int idx); -LUA_API void (lua_pushvalue) (lua_State *L, int idx); -LUA_API void (lua_remove) (lua_State *L, int idx); -LUA_API void (lua_insert) (lua_State *L, int idx); -LUA_API void (lua_replace) (lua_State *L, int idx); -LUA_API int (lua_checkstack) (lua_State *L, int sz); - -LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); - - -/* -** access functions (stack -> C) -*/ - -LUA_API int (lua_isnumber) (lua_State *L, int idx); -LUA_API int (lua_isstring) (lua_State *L, int idx); -LUA_API int (lua_iscfunction) (lua_State *L, int idx); -LUA_API int (lua_isuserdata) (lua_State *L, int idx); -LUA_API int (lua_type) (lua_State *L, int idx); -LUA_API const char *(lua_typename) (lua_State *L, int tp); - -LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); -LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); -LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); - -LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); -LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); -LUA_API int (lua_toboolean) (lua_State *L, int idx); -LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); -LUA_API size_t (lua_objlen) (lua_State *L, int idx); -LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); -LUA_API void *(lua_touserdata) (lua_State *L, int idx); -LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); -LUA_API const void *(lua_topointer) (lua_State *L, int idx); - - -/* -** push functions (C -> stack) -*/ -LUA_API void (lua_pushnil) (lua_State *L); -LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); -LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); -LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); -LUA_API void (lua_pushstring) (lua_State *L, const char *s); -LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, - va_list argp); -LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); -LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); -LUA_API void (lua_pushboolean) (lua_State *L, int b); -LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); -LUA_API int (lua_pushthread) (lua_State *L); - - -/* -** get functions (Lua -> stack) -*/ -LUA_API void (lua_gettable) (lua_State *L, int idx); -LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); -LUA_API void (lua_rawget) (lua_State *L, int idx); -LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); -LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); -LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); -LUA_API int (lua_getmetatable) (lua_State *L, int objindex); -LUA_API void (lua_getfenv) (lua_State *L, int idx); - - -/* -** set functions (stack -> Lua) -*/ -LUA_API void (lua_settable) (lua_State *L, int idx); -LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); -LUA_API void (lua_rawset) (lua_State *L, int idx); -LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); -LUA_API int (lua_setmetatable) (lua_State *L, int objindex); -LUA_API int (lua_setfenv) (lua_State *L, int idx); - - -/* -** `load' and `call' functions (load and run Lua code) -*/ -LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); -LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); -LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); -LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, - const char *chunkname); - -LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); - - -/* -** coroutine functions -*/ -LUA_API int (lua_yield) (lua_State *L, int nresults); -LUA_API int (lua_resume) (lua_State *L, int narg); -LUA_API int (lua_status) (lua_State *L); - -/* -** garbage-collection function and options -*/ - -#define LUA_GCSTOP 0 -#define LUA_GCRESTART 1 -#define LUA_GCCOLLECT 2 -#define LUA_GCCOUNT 3 -#define LUA_GCCOUNTB 4 -#define LUA_GCSTEP 5 -#define LUA_GCSETPAUSE 6 -#define LUA_GCSETSTEPMUL 7 - -LUA_API int (lua_gc) (lua_State *L, int what, int data); - - -/* -** miscellaneous functions -*/ - -LUA_API int (lua_error) (lua_State *L); - -LUA_API int (lua_next) (lua_State *L, int idx); - -LUA_API void (lua_concat) (lua_State *L, int n); - -LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); -LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); - - - -/* -** =============================================================== -** some useful macros -** =============================================================== -*/ - -#define lua_pop(L,n) lua_settop(L, -(n)-1) - -#define lua_newtable(L) lua_createtable(L, 0, 0) - -#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) - -#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) - -#define lua_strlen(L,i) lua_objlen(L, (i)) - -#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) -#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) -#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) -#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) -#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) -#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) -#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) -#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) - -#define lua_pushliteral(L, s) \ - lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) - -#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) -#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) - -#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) - - - -/* -** compatibility macros and functions -*/ - -#define lua_open() luaL_newstate() - -#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) - -#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) - -#define lua_Chunkreader lua_Reader -#define lua_Chunkwriter lua_Writer - - -/* hack */ -LUA_API void lua_setlevel (lua_State *from, lua_State *to); - - -/* -** {====================================================================== -** Debug API -** ======================================================================= -*/ - - -/* -** Event codes -*/ -#define LUA_HOOKCALL 0 -#define LUA_HOOKRET 1 -#define LUA_HOOKLINE 2 -#define LUA_HOOKCOUNT 3 -#define LUA_HOOKTAILRET 4 - - -/* -** Event masks -*/ -#define LUA_MASKCALL (1 << LUA_HOOKCALL) -#define LUA_MASKRET (1 << LUA_HOOKRET) -#define LUA_MASKLINE (1 << LUA_HOOKLINE) -#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) - -typedef struct lua_Debug lua_Debug; /* activation record */ - - -/* Functions to be called by the debuger in specific events */ -typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); - - -LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); -LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); -LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); -LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); -LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); -LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); - -LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); -LUA_API lua_Hook lua_gethook (lua_State *L); -LUA_API int lua_gethookmask (lua_State *L); -LUA_API int lua_gethookcount (lua_State *L); - - -struct lua_Debug { - int event; - const char *name; /* (n) */ - const char *namewhat; /* (n) `global', `local', `field', `method' */ - const char *what; /* (S) `Lua', `C', `main', `tail' */ - const char *source; /* (S) */ - int currentline; /* (l) */ - int nups; /* (u) number of upvalues */ - int linedefined; /* (S) */ - int lastlinedefined; /* (S) */ - char short_src[LUA_IDSIZE]; /* (S) */ - /* private part */ - int i_ci; /* active function */ -}; - -/* }====================================================================== */ - - -/****************************************************************************** -* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -******************************************************************************/ - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lua.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lua.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lua.c @@ -1,392 +0,0 @@ -/* -** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $ -** Lua stand-alone interpreter -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include -#include - -#define lua_c - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - - - -static lua_State *globalL = NULL; - -static const char *progname = LUA_PROGNAME; - - - -static void lstop (lua_State *L, lua_Debug *ar) { - (void)ar; /* unused arg. */ - lua_sethook(L, NULL, 0, 0); - luaL_error(L, "interrupted!"); -} - - -static void laction (int i) { - signal(i, SIG_DFL); /* if another SIGINT happens before lstop, - terminate process (default action) */ - lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); -} - - -static void print_usage (void) { - fprintf(stderr, - "usage: %s [options] [script [args]].\n" - "Available options are:\n" - " -e stat execute string " LUA_QL("stat") "\n" - " -l name require library " LUA_QL("name") "\n" - " -i enter interactive mode after executing " LUA_QL("script") "\n" - " -v show version information\n" - " -- stop handling options\n" - " - execute stdin and stop handling options\n" - , - progname); - fflush(stderr); -} - - -static void l_message (const char *pname, const char *msg) { - if (pname) fprintf(stderr, "%s: ", pname); - fprintf(stderr, "%s\n", msg); - fflush(stderr); -} - - -static int report (lua_State *L, int status) { - if (status && !lua_isnil(L, -1)) { - const char *msg = lua_tostring(L, -1); - if (msg == NULL) msg = "(error object is not a string)"; - l_message(progname, msg); - lua_pop(L, 1); - } - return status; -} - - -static int traceback (lua_State *L) { - if (!lua_isstring(L, 1)) /* 'message' not a string? */ - return 1; /* keep it intact */ - lua_getfield(L, LUA_GLOBALSINDEX, "debug"); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - return 1; - } - lua_getfield(L, -1, "traceback"); - if (!lua_isfunction(L, -1)) { - lua_pop(L, 2); - return 1; - } - lua_pushvalue(L, 1); /* pass error message */ - lua_pushinteger(L, 2); /* skip this function and traceback */ - lua_call(L, 2, 1); /* call debug.traceback */ - return 1; -} - - -static int docall (lua_State *L, int narg, int clear) { - int status; - int base = lua_gettop(L) - narg; /* function index */ - lua_pushcfunction(L, traceback); /* push traceback function */ - lua_insert(L, base); /* put it under chunk and args */ - signal(SIGINT, laction); - status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); - signal(SIGINT, SIG_DFL); - lua_remove(L, base); /* remove traceback function */ - /* force a complete garbage collection in case of errors */ - if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); - return status; -} - - -static void print_version (void) { - l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); -} - - -static int getargs (lua_State *L, char **argv, int n) { - int narg; - int i; - int argc = 0; - while (argv[argc]) argc++; /* count total number of arguments */ - narg = argc - (n + 1); /* number of arguments to the script */ - luaL_checkstack(L, narg + 3, "too many arguments to script"); - for (i=n+1; i < argc; i++) - lua_pushstring(L, argv[i]); - lua_createtable(L, narg, n + 1); - for (i=0; i < argc; i++) { - lua_pushstring(L, argv[i]); - lua_rawseti(L, -2, i - n); - } - return narg; -} - - -static int dofile (lua_State *L, const char *name) { - int status = luaL_loadfile(L, name) || docall(L, 0, 1); - return report(L, status); -} - - -static int dostring (lua_State *L, const char *s, const char *name) { - int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); - return report(L, status); -} - - -static int dolibrary (lua_State *L, const char *name) { - lua_getglobal(L, "require"); - lua_pushstring(L, name); - return report(L, docall(L, 1, 1)); -} - - -static const char *get_prompt (lua_State *L, int firstline) { - const char *p; - lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); - p = lua_tostring(L, -1); - if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); - lua_pop(L, 1); /* remove global */ - return p; -} - - -static int incomplete (lua_State *L, int status) { - if (status == LUA_ERRSYNTAX) { - size_t lmsg; - const char *msg = lua_tolstring(L, -1, &lmsg); - const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); - if (strstr(msg, LUA_QL("")) == tp) { - lua_pop(L, 1); - return 1; - } - } - return 0; /* else... */ -} - - -static int pushline (lua_State *L, int firstline) { - char buffer[LUA_MAXINPUT]; - char *b = buffer; - size_t l; - const char *prmt = get_prompt(L, firstline); - if (lua_readline(L, b, prmt) == 0) - return 0; /* no input */ - l = strlen(b); - if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ - b[l-1] = '\0'; /* remove it */ - if (firstline && b[0] == '=') /* first line starts with `=' ? */ - lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ - else - lua_pushstring(L, b); - lua_freeline(L, b); - return 1; -} - - -static int loadline (lua_State *L) { - int status; - lua_settop(L, 0); - if (!pushline(L, 1)) - return -1; /* no input */ - for (;;) { /* repeat until gets a complete line */ - status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); - if (!incomplete(L, status)) break; /* cannot try to add lines? */ - if (!pushline(L, 0)) /* no more input? */ - return -1; - lua_pushliteral(L, "\n"); /* add a new line... */ - lua_insert(L, -2); /* ...between the two lines */ - lua_concat(L, 3); /* join them */ - } - lua_saveline(L, 1); - lua_remove(L, 1); /* remove line */ - return status; -} - - -static void dotty (lua_State *L) { - int status; - const char *oldprogname = progname; - progname = NULL; - while ((status = loadline(L)) != -1) { - if (status == 0) status = docall(L, 0, 0); - report(L, status); - if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ - lua_getglobal(L, "print"); - lua_insert(L, 1); - if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) - l_message(progname, lua_pushfstring(L, - "error calling " LUA_QL("print") " (%s)", - lua_tostring(L, -1))); - } - } - lua_settop(L, 0); /* clear stack */ - fputs("\n", stdout); - fflush(stdout); - progname = oldprogname; -} - - -static int handle_script (lua_State *L, char **argv, int n) { - int status; - const char *fname; - int narg = getargs(L, argv, n); /* collect arguments */ - lua_setglobal(L, "arg"); - fname = argv[n]; - if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) - fname = NULL; /* stdin */ - status = luaL_loadfile(L, fname); - lua_insert(L, -(narg+1)); - if (status == 0) - status = docall(L, narg, 0); - else - lua_pop(L, narg); - return report(L, status); -} - - -/* check that argument has no extra characters at the end */ -#define notail(x) {if ((x)[2] != '\0') return -1;} - - -static int collectargs (char **argv, int *pi, int *pv, int *pe) { - int i; - for (i = 1; argv[i] != NULL; i++) { - if (argv[i][0] != '-') /* not an option? */ - return i; - switch (argv[i][1]) { /* option */ - case '-': - notail(argv[i]); - return (argv[i+1] != NULL ? i+1 : 0); - case '\0': - return i; - case 'i': - notail(argv[i]); - *pi = 1; /* go through */ - case 'v': - notail(argv[i]); - *pv = 1; - break; - case 'e': - *pe = 1; /* go through */ - case 'l': - if (argv[i][2] == '\0') { - i++; - if (argv[i] == NULL) return -1; - } - break; - default: return -1; /* invalid option */ - } - } - return 0; -} - - -static int runargs (lua_State *L, char **argv, int n) { - int i; - for (i = 1; i < n; i++) { - if (argv[i] == NULL) continue; - lua_assert(argv[i][0] == '-'); - switch (argv[i][1]) { /* option */ - case 'e': { - const char *chunk = argv[i] + 2; - if (*chunk == '\0') chunk = argv[++i]; - lua_assert(chunk != NULL); - if (dostring(L, chunk, "=(command line)") != 0) - return 1; - break; - } - case 'l': { - const char *filename = argv[i] + 2; - if (*filename == '\0') filename = argv[++i]; - lua_assert(filename != NULL); - if (dolibrary(L, filename)) - return 1; /* stop if file fails */ - break; - } - default: break; - } - } - return 0; -} - - -static int handle_luainit (lua_State *L) { - const char *init = getenv(LUA_INIT); - if (init == NULL) return 0; /* status OK */ - else if (init[0] == '@') - return dofile(L, init+1); - else - return dostring(L, init, "=" LUA_INIT); -} - - -struct Smain { - int argc; - char **argv; - int status; -}; - - -static int pmain (lua_State *L) { - struct Smain *s = (struct Smain *)lua_touserdata(L, 1); - char **argv = s->argv; - int script; - int has_i = 0, has_v = 0, has_e = 0; - globalL = L; - if (argv[0] && argv[0][0]) progname = argv[0]; - lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ - luaL_openlibs(L); /* open libraries */ - lua_gc(L, LUA_GCRESTART, 0); - s->status = handle_luainit(L); - if (s->status != 0) return 0; - script = collectargs(argv, &has_i, &has_v, &has_e); - if (script < 0) { /* invalid args? */ - print_usage(); - s->status = 1; - return 0; - } - if (has_v) print_version(); - s->status = runargs(L, argv, (script > 0) ? script : s->argc); - if (s->status != 0) return 0; - if (script) - s->status = handle_script(L, argv, script); - if (s->status != 0) return 0; - if (has_i) - dotty(L); - else if (script == 0 && !has_e && !has_v) { - if (lua_stdin_is_tty()) { - print_version(); - dotty(L); - } - else dofile(L, NULL); /* executes stdin as a file */ - } - return 0; -} - - -int main (int argc, char **argv) { - int status; - struct Smain s; - lua_State *L = lua_open(); /* create state */ - if (L == NULL) { - l_message(argv[0], "cannot create state: not enough memory"); - return EXIT_FAILURE; - } - s.argc = argc; - s.argv = argv; - status = lua_cpcall(L, &pmain, &s); - report(L, status); - lua_close(L); - return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/luac.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/luac.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/luac.c @@ -1,200 +0,0 @@ -/* -** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $ -** Lua compiler (saves bytecodes to files; also list bytecodes) -** See Copyright Notice in lua.h -*/ - -#include -#include -#include -#include - -#define luac_c -#define LUA_CORE - -#include "lua.h" -#include "lauxlib.h" - -#include "ldo.h" -#include "lfunc.h" -#include "lmem.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lstring.h" -#include "lundump.h" - -#define PROGNAME "luac" /* default program name */ -#define OUTPUT PROGNAME ".out" /* default output file */ - -static int listing=0; /* list bytecodes? */ -static int dumping=1; /* dump bytecodes? */ -static int stripping=0; /* strip debug information? */ -static char Output[]={ OUTPUT }; /* default output file name */ -static const char* output=Output; /* actual output file name */ -static const char* progname=PROGNAME; /* actual program name */ - -static void fatal(const char* message) -{ - fprintf(stderr,"%s: %s\n",progname,message); - exit(EXIT_FAILURE); -} - -static void cannot(const char* what) -{ - fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); - exit(EXIT_FAILURE); -} - -static void usage(const char* message) -{ - if (*message=='-') - fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message); - else - fprintf(stderr,"%s: %s\n",progname,message); - fprintf(stderr, - "usage: %s [options] [filenames].\n" - "Available options are:\n" - " - process stdin\n" - " -l list\n" - " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" - " -p parse only\n" - " -s strip debug information\n" - " -v show version information\n" - " -- stop handling options\n", - progname,Output); - exit(EXIT_FAILURE); -} - -#define IS(s) (strcmp(argv[i],s)==0) - -static int doargs(int argc, char* argv[]) -{ - int i; - int version=0; - if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; - for (i=1; itop+(i))->l.p) - -static const Proto* combine(lua_State* L, int n) -{ - if (n==1) - return toproto(L,-1); - else - { - int i,pc; - Proto* f=luaF_newproto(L); - setptvalue2s(L,L->top,f); incr_top(L); - f->source=luaS_newliteral(L,"=(" PROGNAME ")"); - f->maxstacksize=1; - pc=2*n+1; - f->code=luaM_newvector(L,pc,Instruction); - f->sizecode=pc; - f->p=luaM_newvector(L,n,Proto*); - f->sizep=n; - pc=0; - for (i=0; ip[i]=toproto(L,i-n-1); - f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); - f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); - } - f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); - return f; - } -} - -static int writer(lua_State* L, const void* p, size_t size, void* u) -{ - UNUSED(L); - return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); -} - -struct Smain { - int argc; - char** argv; -}; - -static int pmain(lua_State* L) -{ - struct Smain* s = (struct Smain*)lua_touserdata(L, 1); - int argc=s->argc; - char** argv=s->argv; - const Proto* f; - int i; - if (!lua_checkstack(L,argc)) fatal("too many input files"); - for (i=0; i1); - if (dumping) - { - FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); - if (D==NULL) cannot("open"); - lua_lock(L); - luaU_dump(L,f,writer,D,stripping); - lua_unlock(L); - if (ferror(D)) cannot("write"); - if (fclose(D)) cannot("close"); - } - return 0; -} - -int main(int argc, char* argv[]) -{ - lua_State* L; - struct Smain s; - int i=doargs(argc,argv); - argc-=i; argv+=i; - if (argc<=0) usage("no input files given"); - L=lua_open(); - if (L==NULL) fatal("not enough memory for state"); - s.argc=argc; - s.argv=argv; - if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1)); - lua_close(L); - return EXIT_SUCCESS; -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/luaconf.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/luaconf.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/luaconf.h @@ -1,763 +0,0 @@ -/* -** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $ -** Configuration file for Lua -** See Copyright Notice in lua.h -*/ - - -#ifndef lconfig_h -#define lconfig_h - -#include -#include - - -/* -** ================================================================== -** Search for "@@" to find all configurable definitions. -** =================================================================== -*/ - - -/* -@@ LUA_ANSI controls the use of non-ansi features. -** CHANGE it (define it) if you want Lua to avoid the use of any -** non-ansi feature or library. -*/ -#if defined(__STRICT_ANSI__) -#define LUA_ANSI -#endif - - -#if !defined(LUA_ANSI) && defined(_WIN32) -#define LUA_WIN -#endif - -#if defined(LUA_USE_LINUX) -#define LUA_USE_POSIX -#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ -#define LUA_USE_READLINE /* needs some extra libraries */ -#endif - -#if defined(LUA_USE_MACOSX) -#define LUA_USE_POSIX -#define LUA_DL_DYLD /* does not need extra library */ -#endif - - - -/* -@@ LUA_USE_POSIX includes all functionallity listed as X/Open System -@* Interfaces Extension (XSI). -** CHANGE it (define it) if your system is XSI compatible. -*/ -#if defined(LUA_USE_POSIX) -#define LUA_USE_MKSTEMP -#define LUA_USE_ISATTY -#define LUA_USE_POPEN -#define LUA_USE_ULONGJMP -#endif - - -/* -@@ LUA_PATH and LUA_CPATH are the names of the environment variables that -@* Lua check to set its paths. -@@ LUA_INIT is the name of the environment variable that Lua -@* checks for initialization code. -** CHANGE them if you want different names. -*/ -#define LUA_PATH "LUA_PATH" -#define LUA_CPATH "LUA_CPATH" -#define LUA_INIT "LUA_INIT" - - -/* -@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for -@* Lua libraries. -@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for -@* C libraries. -** CHANGE them if your machine has a non-conventional directory -** hierarchy or if you want to install your libraries in -** non-conventional directories. -*/ -#if defined(_WIN32) -/* -** In Windows, any exclamation mark ('!') in the path is replaced by the -** path of the directory of the executable file of the current process. -*/ -#define LUA_LDIR "!\\lua\\" -#define LUA_CDIR "!\\" -#define LUA_PATH_DEFAULT \ - ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" -#define LUA_CPATH_DEFAULT \ - ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" - -#else -#define LUA_ROOT "/usr/local/" -#define LUA_LDIR LUA_ROOT "share/lua/5.1/" -#define LUA_CDIR LUA_ROOT "lib/lua/5.1/" -#define LUA_PATH_DEFAULT \ - "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ - LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" -#define LUA_CPATH_DEFAULT \ - "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" -#endif - - -/* -@@ LUA_DIRSEP is the directory separator (for submodules). -** CHANGE it if your machine does not use "/" as the directory separator -** and is not Windows. (On Windows Lua automatically uses "\".) -*/ -#if defined(_WIN32) -#define LUA_DIRSEP "\\" -#else -#define LUA_DIRSEP "/" -#endif - - -/* -@@ LUA_PATHSEP is the character that separates templates in a path. -@@ LUA_PATH_MARK is the string that marks the substitution points in a -@* template. -@@ LUA_EXECDIR in a Windows path is replaced by the executable's -@* directory. -@@ LUA_IGMARK is a mark to ignore all before it when bulding the -@* luaopen_ function name. -** CHANGE them if for some reason your system cannot use those -** characters. (E.g., if one of those characters is a common character -** in file/directory names.) Probably you do not need to change them. -*/ -#define LUA_PATHSEP ";" -#define LUA_PATH_MARK "?" -#define LUA_EXECDIR "!" -#define LUA_IGMARK "-" - - -/* -@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. -** CHANGE that if ptrdiff_t is not adequate on your machine. (On most -** machines, ptrdiff_t gives a good choice between int or long.) -*/ -#define LUA_INTEGER ptrdiff_t - - -/* -@@ LUA_API is a mark for all core API functions. -@@ LUALIB_API is a mark for all standard library functions. -** CHANGE them if you need to define those functions in some special way. -** For instance, if you want to create one Windows DLL with the core and -** the libraries, you may want to use the following definition (define -** LUA_BUILD_AS_DLL to get it). -*/ -#if defined(LUA_BUILD_AS_DLL) - -#if defined(LUA_CORE) || defined(LUA_LIB) -#define LUA_API __declspec(dllexport) -#else -#define LUA_API __declspec(dllimport) -#endif - -#else - -#define LUA_API extern - -#endif - -/* more often than not the libs go together with the core */ -#define LUALIB_API LUA_API - - -/* -@@ LUAI_FUNC is a mark for all extern functions that are not to be -@* exported to outside modules. -@@ LUAI_DATA is a mark for all extern (const) variables that are not to -@* be exported to outside modules. -** CHANGE them if you need to mark them in some special way. Elf/gcc -** (versions 3.2 and later) mark them as "hidden" to optimize access -** when Lua is compiled as a shared library. -*/ -#if defined(luaall_c) -#define LUAI_FUNC static -#define LUAI_DATA /* empty */ - -#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ - defined(__ELF__) -#define LUAI_FUNC __attribute__((visibility("hidden"))) extern -#define LUAI_DATA LUAI_FUNC - -#else -#define LUAI_FUNC extern -#define LUAI_DATA extern -#endif - - - -/* -@@ LUA_QL describes how error messages quote program elements. -** CHANGE it if you want a different appearance. -*/ -#define LUA_QL(x) "'" x "'" -#define LUA_QS LUA_QL("%s") - - -/* -@@ LUA_IDSIZE gives the maximum size for the description of the source -@* of a function in debug information. -** CHANGE it if you want a different size. -*/ -#define LUA_IDSIZE 60 - - -/* -** {================================================================== -** Stand-alone configuration -** =================================================================== -*/ - -#if defined(lua_c) || defined(luaall_c) - -/* -@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that -@* is, whether we're running lua interactively). -** CHANGE it if you have a better definition for non-POSIX/non-Windows -** systems. -*/ -#if defined(LUA_USE_ISATTY) -#include -#define lua_stdin_is_tty() isatty(0) -#elif defined(LUA_WIN) -#include -#include -#define lua_stdin_is_tty() _isatty(_fileno(stdin)) -#else -#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ -#endif - - -/* -@@ LUA_PROMPT is the default prompt used by stand-alone Lua. -@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. -** CHANGE them if you want different prompts. (You can also change the -** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) -*/ -#define LUA_PROMPT "> " -#define LUA_PROMPT2 ">> " - - -/* -@@ LUA_PROGNAME is the default name for the stand-alone Lua program. -** CHANGE it if your stand-alone interpreter has a different name and -** your system is not able to detect that name automatically. -*/ -#define LUA_PROGNAME "lua" - - -/* -@@ LUA_MAXINPUT is the maximum length for an input line in the -@* stand-alone interpreter. -** CHANGE it if you need longer lines. -*/ -#define LUA_MAXINPUT 512 - - -/* -@@ lua_readline defines how to show a prompt and then read a line from -@* the standard input. -@@ lua_saveline defines how to "save" a read line in a "history". -@@ lua_freeline defines how to free a line read by lua_readline. -** CHANGE them if you want to improve this functionality (e.g., by using -** GNU readline and history facilities). -*/ -#if defined(LUA_USE_READLINE) -#include -#include -#include -#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) -#define lua_saveline(L,idx) \ - if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ - add_history(lua_tostring(L, idx)); /* add it to history */ -#define lua_freeline(L,b) ((void)L, free(b)) -#else -#define lua_readline(L,b,p) \ - ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ - fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ -#define lua_saveline(L,idx) { (void)L; (void)idx; } -#define lua_freeline(L,b) { (void)L; (void)b; } -#endif - -#endif - -/* }================================================================== */ - - -/* -@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles -@* as a percentage. -** CHANGE it if you want the GC to run faster or slower (higher values -** mean larger pauses which mean slower collection.) You can also change -** this value dynamically. -*/ -#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ - - -/* -@@ LUAI_GCMUL defines the default speed of garbage collection relative to -@* memory allocation as a percentage. -** CHANGE it if you want to change the granularity of the garbage -** collection. (Higher values mean coarser collections. 0 represents -** infinity, where each step performs a full collection.) You can also -** change this value dynamically. -*/ -#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ - - - -/* -@@ LUA_COMPAT_GETN controls compatibility with old getn behavior. -** CHANGE it (define it) if you want exact compatibility with the -** behavior of setn/getn in Lua 5.0. -*/ -#undef LUA_COMPAT_GETN - -/* -@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. -** CHANGE it to undefined as soon as you do not need a global 'loadlib' -** function (the function is still available as 'package.loadlib'). -*/ -#undef LUA_COMPAT_LOADLIB - -/* -@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. -** CHANGE it to undefined as soon as your programs use only '...' to -** access vararg parameters (instead of the old 'arg' table). -*/ -#define LUA_COMPAT_VARARG - -/* -@@ LUA_COMPAT_MOD controls compatibility with old math.mod function. -** CHANGE it to undefined as soon as your programs use 'math.fmod' or -** the new '%' operator instead of 'math.mod'. -*/ -#define LUA_COMPAT_MOD - -/* -@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting -@* facility. -** CHANGE it to 2 if you want the old behaviour, or undefine it to turn -** off the advisory error when nesting [[...]]. -*/ -#define LUA_COMPAT_LSTR 1 - -/* -@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. -** CHANGE it to undefined as soon as you rename 'string.gfind' to -** 'string.gmatch'. -*/ -#define LUA_COMPAT_GFIND - -/* -@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' -@* behavior. -** CHANGE it to undefined as soon as you replace to 'luaL_register' -** your uses of 'luaL_openlib' -*/ -#define LUA_COMPAT_OPENLIB - - - -/* -@@ luai_apicheck is the assert macro used by the Lua-C API. -** CHANGE luai_apicheck if you want Lua to perform some checks in the -** parameters it gets from API calls. This may slow down the interpreter -** a bit, but may be quite useful when debugging C code that interfaces -** with Lua. A useful redefinition is to use assert.h. -*/ -#if defined(LUA_USE_APICHECK) -#include -#define luai_apicheck(L,o) { (void)L; assert(o); } -#else -#define luai_apicheck(L,o) { (void)L; } -#endif - - -/* -@@ LUAI_BITSINT defines the number of bits in an int. -** CHANGE here if Lua cannot automatically detect the number of bits of -** your machine. Probably you do not need to change this. -*/ -/* avoid overflows in comparison */ -#if INT_MAX-20 < 32760 -#define LUAI_BITSINT 16 -#elif INT_MAX > 2147483640L -/* int has at least 32 bits */ -#define LUAI_BITSINT 32 -#else -#error "you must define LUA_BITSINT with number of bits in an integer" -#endif - - -/* -@@ LUAI_UINT32 is an unsigned integer with at least 32 bits. -@@ LUAI_INT32 is an signed integer with at least 32 bits. -@@ LUAI_UMEM is an unsigned integer big enough to count the total -@* memory used by Lua. -@@ LUAI_MEM is a signed integer big enough to count the total memory -@* used by Lua. -** CHANGE here if for some weird reason the default definitions are not -** good enough for your machine. (The definitions in the 'else' -** part always works, but may waste space on machines with 64-bit -** longs.) Probably you do not need to change this. -*/ -#if LUAI_BITSINT >= 32 -#define LUAI_UINT32 unsigned int -#define LUAI_INT32 int -#define LUAI_MAXINT32 INT_MAX -#define LUAI_UMEM size_t -#define LUAI_MEM ptrdiff_t -#else -/* 16-bit ints */ -#define LUAI_UINT32 unsigned long -#define LUAI_INT32 long -#define LUAI_MAXINT32 LONG_MAX -#define LUAI_UMEM unsigned long -#define LUAI_MEM long -#endif - - -/* -@@ LUAI_MAXCALLS limits the number of nested calls. -** CHANGE it if you need really deep recursive calls. This limit is -** arbitrary; its only purpose is to stop infinite recursion before -** exhausting memory. -*/ -#define LUAI_MAXCALLS 20000 - - -/* -@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function -@* can use. -** CHANGE it if you need lots of (Lua) stack space for your C -** functions. This limit is arbitrary; its only purpose is to stop C -** functions to consume unlimited stack space. (must be smaller than -** -LUA_REGISTRYINDEX) -*/ -#define LUAI_MAXCSTACK 8000 - - - -/* -** {================================================================== -** CHANGE (to smaller values) the following definitions if your system -** has a small C stack. (Or you may want to change them to larger -** values if your system has a large C stack and these limits are -** too rigid for you.) Some of these constants control the size of -** stack-allocated arrays used by the compiler or the interpreter, while -** others limit the maximum number of recursive calls that the compiler -** or the interpreter can perform. Values too large may cause a C stack -** overflow for some forms of deep constructs. -** =================================================================== -*/ - - -/* -@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and -@* syntactical nested non-terminals in a program. -*/ -#define LUAI_MAXCCALLS 200 - - -/* -@@ LUAI_MAXVARS is the maximum number of local variables per function -@* (must be smaller than 250). -*/ -#define LUAI_MAXVARS 200 - - -/* -@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function -@* (must be smaller than 250). -*/ -#define LUAI_MAXUPVALUES 60 - - -/* -@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. -*/ -#define LUAL_BUFFERSIZE BUFSIZ - -/* }================================================================== */ - - - - -/* -** {================================================================== -@@ LUA_NUMBER is the type of numbers in Lua. -** CHANGE the following definitions only if you want to build Lua -** with a number type different from double. You may also need to -** change lua_number2int & lua_number2integer. -** =================================================================== -*/ - -#define LUA_NUMBER_DOUBLE -#define LUA_NUMBER double - -/* -@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' -@* over a number. -*/ -#define LUAI_UACNUMBER double - - -/* -@@ LUA_NUMBER_SCAN is the format for reading numbers. -@@ LUA_NUMBER_FMT is the format for writing numbers. -@@ lua_number2str converts a number to a string. -@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. -@@ lua_str2number converts a string to a number. -*/ -#define LUA_NUMBER_SCAN "%lf" -#define LUA_NUMBER_FMT "%.14g" -#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) -#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ -#define lua_str2number(s,p) strtod((s), (p)) - - -/* -@@ The luai_num* macros define the primitive operations over numbers. -*/ -#if defined(LUA_CORE) -#include -#define luai_numadd(a,b) ((a)+(b)) -#define luai_numsub(a,b) ((a)-(b)) -#define luai_nummul(a,b) ((a)*(b)) -#define luai_numdiv(a,b) ((a)/(b)) -#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) -#define luai_numpow(a,b) (pow(a,b)) -#define luai_numunm(a) (-(a)) -#define luai_numeq(a,b) ((a)==(b)) -#define luai_numlt(a,b) ((a)<(b)) -#define luai_numle(a,b) ((a)<=(b)) -#define luai_numisnan(a) (!luai_numeq((a), (a))) -#endif - - -/* -@@ lua_number2int is a macro to convert lua_Number to int. -@@ lua_number2integer is a macro to convert lua_Number to lua_Integer. -** CHANGE them if you know a faster way to convert a lua_Number to -** int (with any rounding method and without throwing errors) in your -** system. In Pentium machines, a naive typecast from double to int -** in C is extremely slow, so any alternative is worth trying. -*/ - -/* On a Pentium, resort to a trick */ -#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ - (defined(__i386) || defined (_M_IX86) || defined(__i386__)) - -/* On a Microsoft compiler, use assembler */ -#if defined(_MSC_VER) - -#define lua_number2int(i,d) __asm fld d __asm fistp i -#define lua_number2integer(i,n) lua_number2int(i, n) - -/* the next trick should work on any Pentium, but sometimes clashes - with a DirectX idiosyncrasy */ -#else - -union luai_Cast { double l_d; long l_l; }; -#define lua_number2int(i,d) \ - { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } -#define lua_number2integer(i,n) lua_number2int(i, n) - -#endif - - -/* this option always works, but may be slow */ -#else -#define lua_number2int(i,d) ((i)=(int)(d)) -#define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) - -#endif - -/* }================================================================== */ - - -/* -@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. -** CHANGE it if your system requires alignments larger than double. (For -** instance, if your system supports long doubles and they must be -** aligned in 16-byte boundaries, then you should add long double in the -** union.) Probably you do not need to change this. -*/ -#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } - - -/* -@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. -** CHANGE them if you prefer to use longjmp/setjmp even with C++ -** or if want/don't to use _longjmp/_setjmp instead of regular -** longjmp/setjmp. By default, Lua handles errors with exceptions when -** compiling as C++ code, with _longjmp/_setjmp when asked to use them, -** and with longjmp/setjmp otherwise. -*/ -#if defined(__cplusplus) -/* C++ exceptions */ -#define LUAI_THROW(L,c) throw(c) -#define LUAI_TRY(L,c,a) try { a } catch(...) \ - { if ((c)->status == 0) (c)->status = -1; } -#define luai_jmpbuf int /* dummy variable */ - -#elif defined(LUA_USE_ULONGJMP) -/* in Unix, try _longjmp/_setjmp (more efficient) */ -#define LUAI_THROW(L,c) _longjmp((c)->b, 1) -#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } -#define luai_jmpbuf jmp_buf - -#else -/* default handling with long jumps */ -#define LUAI_THROW(L,c) longjmp((c)->b, 1) -#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } -#define luai_jmpbuf jmp_buf - -#endif - - -/* -@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern -@* can do during pattern-matching. -** CHANGE it if you need more captures. This limit is arbitrary. -*/ -#define LUA_MAXCAPTURES 32 - - -/* -@@ lua_tmpnam is the function that the OS library uses to create a -@* temporary name. -@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. -** CHANGE them if you have an alternative to tmpnam (which is considered -** insecure) or if you want the original tmpnam anyway. By default, Lua -** uses tmpnam except when POSIX is available, where it uses mkstemp. -*/ -#if defined(loslib_c) || defined(luaall_c) - -#if defined(LUA_USE_MKSTEMP) -#include -#define LUA_TMPNAMBUFSIZE 32 -#define lua_tmpnam(b,e) { \ - strcpy(b, "/tmp/lua_XXXXXX"); \ - e = mkstemp(b); \ - if (e != -1) close(e); \ - e = (e == -1); } - -#else -#define LUA_TMPNAMBUFSIZE L_tmpnam -#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } -#endif - -#endif - - -/* -@@ lua_popen spawns a new process connected to the current one through -@* the file streams. -** CHANGE it if you have a way to implement it in your system. -*/ -#if defined(LUA_USE_POPEN) - -#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) -#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) - -#elif defined(LUA_WIN) - -#define lua_popen(L,c,m) ((void)L, _popen(c,m)) -#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) - -#else - -#define lua_popen(L,c,m) ((void)((void)c, m), \ - luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) -#define lua_pclose(L,file) ((void)((void)L, file), 0) - -#endif - -/* -@@ LUA_DL_* define which dynamic-library system Lua should use. -** CHANGE here if Lua has problems choosing the appropriate -** dynamic-library system for your platform (either Windows' DLL, Mac's -** dyld, or Unix's dlopen). If your system is some kind of Unix, there -** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for -** it. To use dlopen you also need to adapt the src/Makefile (probably -** adding -ldl to the linker options), so Lua does not select it -** automatically. (When you change the makefile to add -ldl, you must -** also add -DLUA_USE_DLOPEN.) -** If you do not want any kind of dynamic library, undefine all these -** options. -** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD. -*/ -#if defined(LUA_USE_DLOPEN) -#define LUA_DL_DLOPEN -#endif - -#if defined(LUA_WIN) -#define LUA_DL_DLL -#endif - - -/* -@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State -@* (the data goes just *before* the lua_State pointer). -** CHANGE (define) this if you really need that. This value must be -** a multiple of the maximum alignment required for your machine. -*/ -#define LUAI_EXTRASPACE 0 - - -/* -@@ luai_userstate* allow user-specific actions on threads. -** CHANGE them if you defined LUAI_EXTRASPACE and need to do something -** extra when a thread is created/deleted/resumed/yielded. -*/ -#define luai_userstateopen(L) ((void)L) -#define luai_userstateclose(L) ((void)L) -#define luai_userstatethread(L,L1) ((void)L) -#define luai_userstatefree(L) ((void)L) -#define luai_userstateresume(L,n) ((void)L) -#define luai_userstateyield(L,n) ((void)L) - - -/* -@@ LUA_INTFRMLEN is the length modifier for integer conversions -@* in 'string.format'. -@@ LUA_INTFRM_T is the integer type correspoding to the previous length -@* modifier. -** CHANGE them if your system supports long long or does not support long. -*/ - -#if defined(LUA_USELONGLONG) - -#define LUA_INTFRMLEN "ll" -#define LUA_INTFRM_T long long - -#else - -#define LUA_INTFRMLEN "l" -#define LUA_INTFRM_T long - -#endif - - - -/* =================================================================== */ - -/* -** Local configuration. You can use this space to add your redefinitions -** without modifying the main part of the file. -*/ - - - -#endif - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lualib.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lualib.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lualib.h @@ -1,53 +0,0 @@ -/* -** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ -** Lua standard libraries -** See Copyright Notice in lua.h -*/ - - -#ifndef lualib_h -#define lualib_h - -#include "lua.h" - - -/* Key to file-handle type */ -#define LUA_FILEHANDLE "FILE*" - - -#define LUA_COLIBNAME "coroutine" -LUALIB_API int (luaopen_base) (lua_State *L); - -#define LUA_TABLIBNAME "table" -LUALIB_API int (luaopen_table) (lua_State *L); - -#define LUA_IOLIBNAME "io" -LUALIB_API int (luaopen_io) (lua_State *L); - -#define LUA_OSLIBNAME "os" -LUALIB_API int (luaopen_os) (lua_State *L); - -#define LUA_STRLIBNAME "string" -LUALIB_API int (luaopen_string) (lua_State *L); - -#define LUA_MATHLIBNAME "math" -LUALIB_API int (luaopen_math) (lua_State *L); - -#define LUA_DBLIBNAME "debug" -LUALIB_API int (luaopen_debug) (lua_State *L); - -#define LUA_LOADLIBNAME "package" -LUALIB_API int (luaopen_package) (lua_State *L); - - -/* open all previous libraries */ -LUALIB_API void (luaL_openlibs) (lua_State *L); - - - -#ifndef lua_assert -#define lua_assert(x) ((void)0) -#endif - - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lundump.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lundump.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lundump.h @@ -1,36 +0,0 @@ -/* -** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ -** load precompiled Lua chunks -** See Copyright Notice in lua.h -*/ - -#ifndef lundump_h -#define lundump_h - -#include "lobject.h" -#include "lzio.h" - -/* load one chunk; from lundump.c */ -LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); - -/* make header; from lundump.c */ -LUAI_FUNC void luaU_header (char* h); - -/* dump one chunk; from ldump.c */ -LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); - -#ifdef luac_c -/* print one chunk; from print.c */ -LUAI_FUNC void luaU_print (const Proto* f, int full); -#endif - -/* for header of binary files -- this is Lua 5.1 */ -#define LUAC_VERSION 0x51 - -/* for header of binary files -- this is the official format */ -#define LUAC_FORMAT 0 - -/* size of header of binary files */ -#define LUAC_HEADERSIZE 12 - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lundump.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lundump.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lundump.c @@ -1,227 +0,0 @@ -/* -** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ -** load precompiled Lua chunks -** See Copyright Notice in lua.h -*/ - -#include - -#define lundump_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lmem.h" -#include "lobject.h" -#include "lstring.h" -#include "lundump.h" -#include "lzio.h" - -typedef struct { - lua_State* L; - ZIO* Z; - Mbuffer* b; - const char* name; -} LoadState; - -#ifdef LUAC_TRUST_BINARIES -#define IF(c,s) -#define error(S,s) -#else -#define IF(c,s) if (c) error(S,s) - -static void error(LoadState* S, const char* why) -{ - luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); - luaD_throw(S->L,LUA_ERRSYNTAX); -} -#endif - -#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) -#define LoadByte(S) (lu_byte)LoadChar(S) -#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) -#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) - -static void LoadBlock(LoadState* S, void* b, size_t size) -{ - size_t r=luaZ_read(S->Z,b,size); - IF (r!=0, "unexpected end"); -} - -static int LoadChar(LoadState* S) -{ - char x; - LoadVar(S,x); - return x; -} - -static int LoadInt(LoadState* S) -{ - int x; - LoadVar(S,x); - IF (x<0, "bad integer"); - return x; -} - -static lua_Number LoadNumber(LoadState* S) -{ - lua_Number x; - LoadVar(S,x); - return x; -} - -static TString* LoadString(LoadState* S) -{ - size_t size; - LoadVar(S,size); - if (size==0) - return NULL; - else - { - char* s=luaZ_openspace(S->L,S->b,size); - LoadBlock(S,s,size); - return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ - } -} - -static void LoadCode(LoadState* S, Proto* f) -{ - int n=LoadInt(S); - f->code=luaM_newvector(S->L,n,Instruction); - f->sizecode=n; - LoadVector(S,f->code,n,sizeof(Instruction)); -} - -static Proto* LoadFunction(LoadState* S, TString* p); - -static void LoadConstants(LoadState* S, Proto* f) -{ - int i,n; - n=LoadInt(S); - f->k=luaM_newvector(S->L,n,TValue); - f->sizek=n; - for (i=0; ik[i]); - for (i=0; ik[i]; - int t=LoadChar(S); - switch (t) - { - case LUA_TNIL: - setnilvalue(o); - break; - case LUA_TBOOLEAN: - setbvalue(o,LoadChar(S)!=0); - break; - case LUA_TNUMBER: - setnvalue(o,LoadNumber(S)); - break; - case LUA_TSTRING: - setsvalue2n(S->L,o,LoadString(S)); - break; - default: - error(S,"bad constant"); - break; - } - } - n=LoadInt(S); - f->p=luaM_newvector(S->L,n,Proto*); - f->sizep=n; - for (i=0; ip[i]=NULL; - for (i=0; ip[i]=LoadFunction(S,f->source); -} - -static void LoadDebug(LoadState* S, Proto* f) -{ - int i,n; - n=LoadInt(S); - f->lineinfo=luaM_newvector(S->L,n,int); - f->sizelineinfo=n; - LoadVector(S,f->lineinfo,n,sizeof(int)); - n=LoadInt(S); - f->locvars=luaM_newvector(S->L,n,LocVar); - f->sizelocvars=n; - for (i=0; ilocvars[i].varname=NULL; - for (i=0; ilocvars[i].varname=LoadString(S); - f->locvars[i].startpc=LoadInt(S); - f->locvars[i].endpc=LoadInt(S); - } - n=LoadInt(S); - f->upvalues=luaM_newvector(S->L,n,TString*); - f->sizeupvalues=n; - for (i=0; iupvalues[i]=NULL; - for (i=0; iupvalues[i]=LoadString(S); -} - -static Proto* LoadFunction(LoadState* S, TString* p) -{ - Proto* f; - if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); - f=luaF_newproto(S->L); - setptvalue2s(S->L,S->L->top,f); incr_top(S->L); - f->source=LoadString(S); if (f->source==NULL) f->source=p; - f->linedefined=LoadInt(S); - f->lastlinedefined=LoadInt(S); - f->nups=LoadByte(S); - f->numparams=LoadByte(S); - f->is_vararg=LoadByte(S); - f->maxstacksize=LoadByte(S); - LoadCode(S,f); - LoadConstants(S,f); - LoadDebug(S,f); - IF (!luaG_checkcode(f), "bad code"); - S->L->top--; - S->L->nCcalls--; - return f; -} - -static void LoadHeader(LoadState* S) -{ - char h[LUAC_HEADERSIZE]; - char s[LUAC_HEADERSIZE]; - luaU_header(h); - LoadBlock(S,s,LUAC_HEADERSIZE); - IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); -} - -/* -** load precompiled chunk -*/ -Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) -{ - LoadState S; - if (*name=='@' || *name=='=') - S.name=name+1; - else if (*name==LUA_SIGNATURE[0]) - S.name="binary string"; - else - S.name=name; - S.L=L; - S.Z=Z; - S.b=buff; - LoadHeader(&S); - return LoadFunction(&S,luaS_newliteral(L,"=?")); -} - -/* -* make header -*/ -void luaU_header (char* h) -{ - int x=1; - memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); - h+=sizeof(LUA_SIGNATURE)-1; - *h++=(char)LUAC_VERSION; - *h++=(char)LUAC_FORMAT; - *h++=(char)*(char*)&x; /* endianness */ - *h++=(char)sizeof(int); - *h++=(char)sizeof(size_t); - *h++=(char)sizeof(Instruction); - *h++=(char)sizeof(lua_Number); - *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lvm.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lvm.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lvm.h @@ -1,36 +0,0 @@ -/* -** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ -** Lua virtual machine -** See Copyright Notice in lua.h -*/ - -#ifndef lvm_h -#define lvm_h - - -#include "ldo.h" -#include "lobject.h" -#include "ltm.h" - - -#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) - -#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ - (((o) = luaV_tonumber(o,n)) != NULL)) - -#define equalobj(L,o1,o2) \ - (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) - - -LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); -LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); -LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); -LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); -LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, - StkId val); -LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, - StkId val); -LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); -LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lvm.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lvm.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lvm.c @@ -1,763 +0,0 @@ -/* -** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $ -** Lua virtual machine -** See Copyright Notice in lua.h -*/ - - -#include -#include -#include - -#define lvm_c -#define LUA_CORE - -#include "lua.h" - -#include "ldebug.h" -#include "ldo.h" -#include "lfunc.h" -#include "lgc.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lstate.h" -#include "lstring.h" -#include "ltable.h" -#include "ltm.h" -#include "lvm.h" - - - -/* limit for table tag-method chains (to avoid loops) */ -#define MAXTAGLOOP 100 - - -const TValue *luaV_tonumber (const TValue *obj, TValue *n) { - lua_Number num; - if (ttisnumber(obj)) return obj; - if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { - setnvalue(n, num); - return n; - } - else - return NULL; -} - - -int luaV_tostring (lua_State *L, StkId obj) { - if (!ttisnumber(obj)) - return 0; - else { - char s[LUAI_MAXNUMBER2STR]; - lua_Number n = nvalue(obj); - lua_number2str(s, n); - setsvalue2s(L, obj, luaS_new(L, s)); - return 1; - } -} - - -static void traceexec (lua_State *L, const Instruction *pc) { - lu_byte mask = L->hookmask; - const Instruction *oldpc = L->savedpc; - L->savedpc = pc; - if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { - resethookcount(L); - luaD_callhook(L, LUA_HOOKCOUNT, -1); - } - if (mask & LUA_MASKLINE) { - Proto *p = ci_func(L->ci)->l.p; - int npc = pcRel(pc, p); - int newline = getline(p, npc); - /* call linehook when enter a new function, when jump back (loop), - or when enter a new line */ - if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p))) - luaD_callhook(L, LUA_HOOKLINE, newline); - } -} - - -static void callTMres (lua_State *L, StkId res, const TValue *f, - const TValue *p1, const TValue *p2) { - ptrdiff_t result = savestack(L, res); - setobj2s(L, L->top, f); /* push function */ - setobj2s(L, L->top+1, p1); /* 1st argument */ - setobj2s(L, L->top+2, p2); /* 2nd argument */ - luaD_checkstack(L, 3); - L->top += 3; - luaD_call(L, L->top - 3, 1); - res = restorestack(L, result); - L->top--; - setobjs2s(L, res, L->top); -} - - - -static void callTM (lua_State *L, const TValue *f, const TValue *p1, - const TValue *p2, const TValue *p3) { - setobj2s(L, L->top, f); /* push function */ - setobj2s(L, L->top+1, p1); /* 1st argument */ - setobj2s(L, L->top+2, p2); /* 2nd argument */ - setobj2s(L, L->top+3, p3); /* 3th argument */ - luaD_checkstack(L, 4); - L->top += 4; - luaD_call(L, L->top - 4, 0); -} - - -void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { - int loop; - for (loop = 0; loop < MAXTAGLOOP; loop++) { - const TValue *tm; - if (ttistable(t)) { /* `t' is a table? */ - Table *h = hvalue(t); - const TValue *res = luaH_get(h, key); /* do a primitive get */ - if (!ttisnil(res) || /* result is no nil? */ - (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ - setobj2s(L, val, res); - return; - } - /* else will try the tag method */ - } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) - luaG_typeerror(L, t, "index"); - if (ttisfunction(tm)) { - callTMres(L, val, tm, t, key); - return; - } - t = tm; /* else repeat with `tm' */ - } - luaG_runerror(L, "loop in gettable"); -} - - -void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { - int loop; - for (loop = 0; loop < MAXTAGLOOP; loop++) { - const TValue *tm; - if (ttistable(t)) { /* `t' is a table? */ - Table *h = hvalue(t); - TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ - if (!ttisnil(oldval) || /* result is no nil? */ - (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ - setobj2t(L, oldval, val); - luaC_barriert(L, h, val); - return; - } - /* else will try the tag method */ - } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) - luaG_typeerror(L, t, "index"); - if (ttisfunction(tm)) { - callTM(L, tm, t, key, val); - return; - } - t = tm; /* else repeat with `tm' */ - } - luaG_runerror(L, "loop in settable"); -} - - -static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2, - StkId res, TMS event) { - const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ - if (ttisnil(tm)) - tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ - if (ttisnil(tm)) return 0; - callTMres(L, res, tm, p1, p2); - return 1; -} - - -static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2, - TMS event) { - const TValue *tm1 = fasttm(L, mt1, event); - const TValue *tm2; - if (tm1 == NULL) return NULL; /* no metamethod */ - if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ - tm2 = fasttm(L, mt2, event); - if (tm2 == NULL) return NULL; /* no metamethod */ - if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ - return tm1; - return NULL; -} - - -static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, - TMS event) { - const TValue *tm1 = luaT_gettmbyobj(L, p1, event); - const TValue *tm2; - if (ttisnil(tm1)) return -1; /* no metamethod? */ - tm2 = luaT_gettmbyobj(L, p2, event); - if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ - return -1; - callTMres(L, L->top, tm1, p1, p2); - return !l_isfalse(L->top); -} - - -static int l_strcmp (const TString *ls, const TString *rs) { - const char *l = getstr(ls); - size_t ll = ls->tsv.len; - const char *r = getstr(rs); - size_t lr = rs->tsv.len; - for (;;) { - int temp = strcoll(l, r); - if (temp != 0) return temp; - else { /* strings are equal up to a `\0' */ - size_t len = strlen(l); /* index of first `\0' in both strings */ - if (len == lr) /* r is finished? */ - return (len == ll) ? 0 : 1; - else if (len == ll) /* l is finished? */ - return -1; /* l is smaller than r (because r is not finished) */ - /* both strings longer than `len'; go on comparing (after the `\0') */ - len++; - l += len; ll -= len; r += len; lr -= len; - } - } -} - - -int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { - int res; - if (ttype(l) != ttype(r)) - return luaG_ordererror(L, l, r); - else if (ttisnumber(l)) - return luai_numlt(nvalue(l), nvalue(r)); - else if (ttisstring(l)) - return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; - else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) - return res; - return luaG_ordererror(L, l, r); -} - - -static int lessequal (lua_State *L, const TValue *l, const TValue *r) { - int res; - if (ttype(l) != ttype(r)) - return luaG_ordererror(L, l, r); - else if (ttisnumber(l)) - return luai_numle(nvalue(l), nvalue(r)); - else if (ttisstring(l)) - return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; - else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ - return res; - else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ - return !res; - return luaG_ordererror(L, l, r); -} - - -int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) { - const TValue *tm; - lua_assert(ttype(t1) == ttype(t2)); - switch (ttype(t1)) { - case LUA_TNIL: return 1; - case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); - case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ - case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); - case LUA_TUSERDATA: { - if (uvalue(t1) == uvalue(t2)) return 1; - tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, - TM_EQ); - break; /* will try TM */ - } - case LUA_TTABLE: { - if (hvalue(t1) == hvalue(t2)) return 1; - tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); - break; /* will try TM */ - } - default: return gcvalue(t1) == gcvalue(t2); - } - if (tm == NULL) return 0; /* no TM? */ - callTMres(L, L->top, tm, t1, t2); /* call TM */ - return !l_isfalse(L->top); -} - - -void luaV_concat (lua_State *L, int total, int last) { - do { - StkId top = L->base + last + 1; - int n = 2; /* number of elements handled in this pass (at least 2) */ - if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { - if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) - luaG_concaterror(L, top-2, top-1); - } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ - (void)tostring(L, top - 2); /* result is first op (as string) */ - else { - /* at least two string values; get as many as possible */ - size_t tl = tsvalue(top-1)->len; - char *buffer; - int i; - /* collect total length */ - for (n = 1; n < total && tostring(L, top-n-1); n++) { - size_t l = tsvalue(top-n-1)->len; - if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); - tl += l; - } - buffer = luaZ_openspace(L, &G(L)->buff, tl); - tl = 0; - for (i=n; i>0; i--) { /* concat all strings */ - size_t l = tsvalue(top-i)->len; - memcpy(buffer+tl, svalue(top-i), l); - tl += l; - } - setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); - } - total -= n-1; /* got `n' strings to create 1 new */ - last -= n-1; - } while (total > 1); /* repeat until only 1 result left */ -} - - -static void Arith (lua_State *L, StkId ra, const TValue *rb, - const TValue *rc, TMS op) { - TValue tempb, tempc; - const TValue *b, *c; - if ((b = luaV_tonumber(rb, &tempb)) != NULL && - (c = luaV_tonumber(rc, &tempc)) != NULL) { - lua_Number nb = nvalue(b), nc = nvalue(c); - switch (op) { - case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; - case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; - case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; - case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; - case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; - case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; - case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; - default: lua_assert(0); break; - } - } - else if (!call_binTM(L, rb, rc, ra, op)) - luaG_aritherror(L, rb, rc); -} - - - -/* -** some macros for common tasks in `luaV_execute' -*/ - -#define runtime_check(L, c) { if (!(c)) break; } - -#define RA(i) (base+GETARG_A(i)) -/* to be used after possible stack reallocation */ -#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i)) -#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) -#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ - ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i)) -#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ - ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i)) -#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i)) - - -#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);} - - -#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; } - - -#define arith_op(op,tm) { \ - TValue *rb = RKB(i); \ - TValue *rc = RKC(i); \ - if (ttisnumber(rb) && ttisnumber(rc)) { \ - lua_Number nb = nvalue(rb), nc = nvalue(rc); \ - setnvalue(ra, op(nb, nc)); \ - } \ - else \ - Protect(Arith(L, ra, rb, rc, tm)); \ - } - - - -void luaV_execute (lua_State *L, int nexeccalls) { - LClosure *cl; - StkId base; - TValue *k; - const Instruction *pc; - reentry: /* entry point */ - lua_assert(isLua(L->ci)); - pc = L->savedpc; - cl = &clvalue(L->ci->func)->l; - base = L->base; - k = cl->p->k; - /* main loop of interpreter */ - for (;;) { - const Instruction i = *pc++; - StkId ra; - if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && - (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { - traceexec(L, pc); - if (L->status == LUA_YIELD) { /* did hook yield? */ - L->savedpc = pc - 1; - return; - } - base = L->base; - } - /* warning!! several calls may realloc the stack and invalidate `ra' */ - ra = RA(i); - lua_assert(base == L->base && L->base == L->ci->base); - lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); - lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); - switch (GET_OPCODE(i)) { - case OP_MOVE: { - setobjs2s(L, ra, RB(i)); - continue; - } - case OP_LOADK: { - setobj2s(L, ra, KBx(i)); - continue; - } - case OP_LOADBOOL: { - setbvalue(ra, GETARG_B(i)); - if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ - continue; - } - case OP_LOADNIL: { - TValue *rb = RB(i); - do { - setnilvalue(rb--); - } while (rb >= ra); - continue; - } - case OP_GETUPVAL: { - int b = GETARG_B(i); - setobj2s(L, ra, cl->upvals[b]->v); - continue; - } - case OP_GETGLOBAL: { - TValue g; - TValue *rb = KBx(i); - sethvalue(L, &g, cl->env); - lua_assert(ttisstring(rb)); - Protect(luaV_gettable(L, &g, rb, ra)); - continue; - } - case OP_GETTABLE: { - Protect(luaV_gettable(L, RB(i), RKC(i), ra)); - continue; - } - case OP_SETGLOBAL: { - TValue g; - sethvalue(L, &g, cl->env); - lua_assert(ttisstring(KBx(i))); - Protect(luaV_settable(L, &g, KBx(i), ra)); - continue; - } - case OP_SETUPVAL: { - UpVal *uv = cl->upvals[GETARG_B(i)]; - setobj(L, uv->v, ra); - luaC_barrier(L, uv, ra); - continue; - } - case OP_SETTABLE: { - Protect(luaV_settable(L, ra, RKB(i), RKC(i))); - continue; - } - case OP_NEWTABLE: { - int b = GETARG_B(i); - int c = GETARG_C(i); - sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); - Protect(luaC_checkGC(L)); - continue; - } - case OP_SELF: { - StkId rb = RB(i); - setobjs2s(L, ra+1, rb); - Protect(luaV_gettable(L, rb, RKC(i), ra)); - continue; - } - case OP_ADD: { - arith_op(luai_numadd, TM_ADD); - continue; - } - case OP_SUB: { - arith_op(luai_numsub, TM_SUB); - continue; - } - case OP_MUL: { - arith_op(luai_nummul, TM_MUL); - continue; - } - case OP_DIV: { - arith_op(luai_numdiv, TM_DIV); - continue; - } - case OP_MOD: { - arith_op(luai_nummod, TM_MOD); - continue; - } - case OP_POW: { - arith_op(luai_numpow, TM_POW); - continue; - } - case OP_UNM: { - TValue *rb = RB(i); - if (ttisnumber(rb)) { - lua_Number nb = nvalue(rb); - setnvalue(ra, luai_numunm(nb)); - } - else { - Protect(Arith(L, ra, rb, rb, TM_UNM)); - } - continue; - } - case OP_NOT: { - int res = l_isfalse(RB(i)); /* next assignment may change this value */ - setbvalue(ra, res); - continue; - } - case OP_LEN: { - const TValue *rb = RB(i); - switch (ttype(rb)) { - case LUA_TTABLE: { - setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); - break; - } - case LUA_TSTRING: { - setnvalue(ra, cast_num(tsvalue(rb)->len)); - break; - } - default: { /* try metamethod */ - Protect( - if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) - luaG_typeerror(L, rb, "get length of"); - ) - } - } - continue; - } - case OP_CONCAT: { - int b = GETARG_B(i); - int c = GETARG_C(i); - Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); - setobjs2s(L, RA(i), base+b); - continue; - } - case OP_JMP: { - dojump(L, pc, GETARG_sBx(i)); - continue; - } - case OP_EQ: { - TValue *rb = RKB(i); - TValue *rc = RKC(i); - Protect( - if (equalobj(L, rb, rc) == GETARG_A(i)) - dojump(L, pc, GETARG_sBx(*pc)); - ) - pc++; - continue; - } - case OP_LT: { - Protect( - if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) - dojump(L, pc, GETARG_sBx(*pc)); - ) - pc++; - continue; - } - case OP_LE: { - Protect( - if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) - dojump(L, pc, GETARG_sBx(*pc)); - ) - pc++; - continue; - } - case OP_TEST: { - if (l_isfalse(ra) != GETARG_C(i)) - dojump(L, pc, GETARG_sBx(*pc)); - pc++; - continue; - } - case OP_TESTSET: { - TValue *rb = RB(i); - if (l_isfalse(rb) != GETARG_C(i)) { - setobjs2s(L, ra, rb); - dojump(L, pc, GETARG_sBx(*pc)); - } - pc++; - continue; - } - case OP_CALL: { - int b = GETARG_B(i); - int nresults = GETARG_C(i) - 1; - if (b != 0) L->top = ra+b; /* else previous instruction set top */ - L->savedpc = pc; - switch (luaD_precall(L, ra, nresults)) { - case PCRLUA: { - nexeccalls++; - goto reentry; /* restart luaV_execute over new Lua function */ - } - case PCRC: { - /* it was a C function (`precall' called it); adjust results */ - if (nresults >= 0) L->top = L->ci->top; - base = L->base; - continue; - } - default: { - return; /* yield */ - } - } - } - case OP_TAILCALL: { - int b = GETARG_B(i); - if (b != 0) L->top = ra+b; /* else previous instruction set top */ - L->savedpc = pc; - lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); - switch (luaD_precall(L, ra, LUA_MULTRET)) { - case PCRLUA: { - /* tail call: put new frame in place of previous one */ - CallInfo *ci = L->ci - 1; /* previous frame */ - int aux; - StkId func = ci->func; - StkId pfunc = (ci+1)->func; /* previous function index */ - if (L->openupval) luaF_close(L, ci->base); - L->base = ci->base = ci->func + ((ci+1)->base - pfunc); - for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ - setobjs2s(L, func+aux, pfunc+aux); - ci->top = L->top = func+aux; /* correct top */ - lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); - ci->savedpc = L->savedpc; - ci->tailcalls++; /* one more call lost */ - L->ci--; /* remove new frame */ - goto reentry; - } - case PCRC: { /* it was a C function (`precall' called it) */ - base = L->base; - continue; - } - default: { - return; /* yield */ - } - } - } - case OP_RETURN: { - int b = GETARG_B(i); - if (b != 0) L->top = ra+b-1; - if (L->openupval) luaF_close(L, base); - L->savedpc = pc; - b = luaD_poscall(L, ra); - if (--nexeccalls == 0) /* was previous function running `here'? */ - return; /* no: return */ - else { /* yes: continue its execution */ - if (b) L->top = L->ci->top; - lua_assert(isLua(L->ci)); - lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL); - goto reentry; - } - } - case OP_FORLOOP: { - lua_Number step = nvalue(ra+2); - lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */ - lua_Number limit = nvalue(ra+1); - if (luai_numlt(0, step) ? luai_numle(idx, limit) - : luai_numle(limit, idx)) { - dojump(L, pc, GETARG_sBx(i)); /* jump back */ - setnvalue(ra, idx); /* update internal index... */ - setnvalue(ra+3, idx); /* ...and external index */ - } - continue; - } - case OP_FORPREP: { - const TValue *init = ra; - const TValue *plimit = ra+1; - const TValue *pstep = ra+2; - L->savedpc = pc; /* next steps may throw errors */ - if (!tonumber(init, ra)) - luaG_runerror(L, LUA_QL("for") " initial value must be a number"); - else if (!tonumber(plimit, ra+1)) - luaG_runerror(L, LUA_QL("for") " limit must be a number"); - else if (!tonumber(pstep, ra+2)) - luaG_runerror(L, LUA_QL("for") " step must be a number"); - setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); - dojump(L, pc, GETARG_sBx(i)); - continue; - } - case OP_TFORLOOP: { - StkId cb = ra + 3; /* call base */ - setobjs2s(L, cb+2, ra+2); - setobjs2s(L, cb+1, ra+1); - setobjs2s(L, cb, ra); - L->top = cb+3; /* func. + 2 args (state and index) */ - Protect(luaD_call(L, cb, GETARG_C(i))); - L->top = L->ci->top; - cb = RA(i) + 3; /* previous call may change the stack */ - if (!ttisnil(cb)) { /* continue loop? */ - setobjs2s(L, cb-1, cb); /* save control variable */ - dojump(L, pc, GETARG_sBx(*pc)); /* jump back */ - } - pc++; - continue; - } - case OP_SETLIST: { - int n = GETARG_B(i); - int c = GETARG_C(i); - int last; - Table *h; - if (n == 0) { - n = cast_int(L->top - ra) - 1; - L->top = L->ci->top; - } - if (c == 0) c = cast_int(*pc++); - runtime_check(L, ttistable(ra)); - h = hvalue(ra); - last = ((c-1)*LFIELDS_PER_FLUSH) + n; - if (last > h->sizearray) /* needs more space? */ - luaH_resizearray(L, h, last); /* pre-alloc it at once */ - for (; n > 0; n--) { - TValue *val = ra+n; - setobj2t(L, luaH_setnum(L, h, last--), val); - luaC_barriert(L, h, val); - } - continue; - } - case OP_CLOSE: { - luaF_close(L, ra); - continue; - } - case OP_CLOSURE: { - Proto *p; - Closure *ncl; - int nup, j; - p = cl->p->p[GETARG_Bx(i)]; - nup = p->nups; - ncl = luaF_newLclosure(L, nup, cl->env); - ncl->l.p = p; - for (j=0; jl.upvals[j] = cl->upvals[GETARG_B(*pc)]; - else { - lua_assert(GET_OPCODE(*pc) == OP_MOVE); - ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); - } - } - setclvalue(L, ra, ncl); - Protect(luaC_checkGC(L)); - continue; - } - case OP_VARARG: { - int b = GETARG_B(i) - 1; - int j; - CallInfo *ci = L->ci; - int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1; - if (b == LUA_MULTRET) { - Protect(luaD_checkstack(L, n)); - ra = RA(i); /* previous call may change the stack */ - b = n; - L->top = ra + n; - } - for (j = 0; j < b; j++) { - if (j < n) { - setobjs2s(L, ra + j, ci->base - n + j); - } - else { - setnilvalue(ra + j); - } - } - continue; - } - } - } -} - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lzio.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lzio.h +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lzio.h @@ -1,67 +0,0 @@ -/* -** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ -** Buffered streams -** See Copyright Notice in lua.h -*/ - - -#ifndef lzio_h -#define lzio_h - -#include "lua.h" - -#include "lmem.h" - - -#define EOZ (-1) /* end of stream */ - -typedef struct Zio ZIO; - -#define char2int(c) cast(int, cast(unsigned char, (c))) - -#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) - -typedef struct Mbuffer { - char *buffer; - size_t n; - size_t buffsize; -} Mbuffer; - -#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) - -#define luaZ_buffer(buff) ((buff)->buffer) -#define luaZ_sizebuffer(buff) ((buff)->buffsize) -#define luaZ_bufflen(buff) ((buff)->n) - -#define luaZ_resetbuffer(buff) ((buff)->n = 0) - - -#define luaZ_resizebuffer(L, buff, size) \ - (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ - (buff)->buffsize = size) - -#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) - - -LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); -LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, - void *data); -LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ -LUAI_FUNC int luaZ_lookahead (ZIO *z); - - - -/* --------- Private Part ------------------ */ - -struct Zio { - size_t n; /* bytes still unread */ - const char *p; /* current position in buffer */ - lua_Reader reader; - void* data; /* additional data */ - lua_State *L; /* Lua state (for reader) */ -}; - - -LUAI_FUNC int luaZ_fill (ZIO *z); - -#endif Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lzio.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lzio.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/lzio.c @@ -1,82 +0,0 @@ -/* -** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ -** a generic input stream interface -** See Copyright Notice in lua.h -*/ - - -#include - -#define lzio_c -#define LUA_CORE - -#include "lua.h" - -#include "llimits.h" -#include "lmem.h" -#include "lstate.h" -#include "lzio.h" - - -int luaZ_fill (ZIO *z) { - size_t size; - lua_State *L = z->L; - const char *buff; - lua_unlock(L); - buff = z->reader(L, z->data, &size); - lua_lock(L); - if (buff == NULL || size == 0) return EOZ; - z->n = size - 1; - z->p = buff; - return char2int(*(z->p++)); -} - - -int luaZ_lookahead (ZIO *z) { - if (z->n == 0) { - if (luaZ_fill(z) == EOZ) - return EOZ; - else { - z->n++; /* luaZ_fill removed first byte; put back it */ - z->p--; - } - } - return char2int(*z->p); -} - - -void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { - z->L = L; - z->reader = reader; - z->data = data; - z->n = 0; - z->p = NULL; -} - - -/* --------------------------------------------------------------- read --- */ -size_t luaZ_read (ZIO *z, void *b, size_t n) { - while (n) { - size_t m; - if (luaZ_lookahead(z) == EOZ) - return n; /* return number of missing bytes */ - m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ - memcpy(b, z->p, m); - z->n -= m; - z->p += m; - b = (char *)b + m; - n -= m; - } - return 0; -} - -/* ------------------------------------------------------------------------ */ -char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { - if (n > buff->buffsize) { - if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; - luaZ_resizebuffer(L, buff, n); - } - return buff->buffer; -} - - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/print.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/print.c +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/src/print.c @@ -1,227 +0,0 @@ -/* -** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ -** print bytecodes -** See Copyright Notice in lua.h -*/ - -#include -#include - -#define luac_c -#define LUA_CORE - -#include "ldebug.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lundump.h" - -#define PrintFunction luaU_print - -#define Sizeof(x) ((int)sizeof(x)) -#define VOID(p) ((const void*)(p)) - -static void PrintString(const TString* ts) -{ - const char* s=getstr(ts); - size_t i,n=ts->tsv.len; - putchar('"'); - for (i=0; ik[i]; - switch (ttype(o)) - { - case LUA_TNIL: - printf("nil"); - break; - case LUA_TBOOLEAN: - printf(bvalue(o) ? "true" : "false"); - break; - case LUA_TNUMBER: - printf(LUA_NUMBER_FMT,nvalue(o)); - break; - case LUA_TSTRING: - PrintString(rawtsvalue(o)); - break; - default: /* cannot happen */ - printf("? type=%d",ttype(o)); - break; - } -} - -static void PrintCode(const Proto* f) -{ - const Instruction* code=f->code; - int pc,n=f->sizecode; - for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); - printf("%-9s\t",luaP_opnames[o]); - switch (getOpMode(o)) - { - case iABC: - printf("%d",a); - if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); - if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); - break; - case iABx: - if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); - break; - case iAsBx: - if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); - break; - } - switch (o) - { - case OP_LOADK: - printf("\t; "); PrintConstant(f,bx); - break; - case OP_GETUPVAL: - case OP_SETUPVAL: - printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); - break; - case OP_GETGLOBAL: - case OP_SETGLOBAL: - printf("\t; %s",svalue(&f->k[bx])); - break; - case OP_GETTABLE: - case OP_SELF: - if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } - break; - case OP_SETTABLE: - case OP_ADD: - case OP_SUB: - case OP_MUL: - case OP_DIV: - case OP_POW: - case OP_EQ: - case OP_LT: - case OP_LE: - if (ISK(b) || ISK(c)) - { - printf("\t; "); - if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); - printf(" "); - if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); - } - break; - case OP_JMP: - case OP_FORLOOP: - case OP_FORPREP: - printf("\t; to %d",sbx+pc+2); - break; - case OP_CLOSURE: - printf("\t; %p",VOID(f->p[bx])); - break; - case OP_SETLIST: - if (c==0) printf("\t; %d",(int)code[++pc]); - else printf("\t; %d",c); - break; - default: - break; - } - printf("\n"); - } -} - -#define SS(x) (x==1)?"":"s" -#define S(x) x,SS(x) - -static void PrintHeader(const Proto* f) -{ - const char* s=getstr(f->source); - if (*s=='@' || *s=='=') - s++; - else if (*s==LUA_SIGNATURE[0]) - s="(bstring)"; - else - s="(string)"; - printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", - (f->linedefined==0)?"main":"function",s, - f->linedefined,f->lastlinedefined, - S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); - printf("%d%s param%s, %d slot%s, %d upvalue%s, ", - f->numparams,f->is_vararg?"+":"",SS(f->numparams), - S(f->maxstacksize),S(f->nups)); - printf("%d local%s, %d constant%s, %d function%s\n", - S(f->sizelocvars),S(f->sizek),S(f->sizep)); -} - -static void PrintConstants(const Proto* f) -{ - int i,n=f->sizek; - printf("constants (%d) for %p:\n",n,VOID(f)); - for (i=0; isizelocvars; - printf("locals (%d) for %p:\n",n,VOID(f)); - for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); - } -} - -static void PrintUpvalues(const Proto* f) -{ - int i,n=f->sizeupvalues; - printf("upvalues (%d) for %p:\n",n,VOID(f)); - if (f->upvalues==NULL) return; - for (i=0; iupvalues[i])); - } -} - -void PrintFunction(const Proto* f, int full) -{ - int i,n=f->sizep; - PrintHeader(f); - PrintCode(f); - if (full) - { - PrintConstants(f); - PrintLocals(f); - PrintUpvalues(f); - } - for (i=0; ip[i],full); -} Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/README =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/README +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/README @@ -1,26 +0,0 @@ -These are simple tests for Lua. Some of them contain useful code. -They are meant to be run to make sure Lua is built correctly and also -to be read, to see how Lua programs look. - -Here is a one-line summary of each program: - - bisect.lua bisection method for solving non-linear equations - cf.lua temperature conversion table (celsius to farenheit) - echo.lua echo command line arguments - env.lua environment variables as automatic global variables - factorial.lua factorial without recursion - fib.lua fibonacci function with cache - fibfor.lua fibonacci numbers with coroutines and generators - globals.lua report global variable usage - hello.lua the first program in every language - life.lua Conway's Game of Life - luac.lua bare-bones luac - printf.lua an implementation of printf - readonly.lua make global variables readonly - sieve.lua the sieve of of Eratosthenes programmed with coroutines - sort.lua two implementations of a sort function - table.lua make table, grouping all data for the same item - trace-calls.lua trace calls - trace-globals.lua trace assigments to global variables - xd.lua hex dump - Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/bisect.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/bisect.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/bisect.lua @@ -1,27 +0,0 @@ --- bisection method for solving non-linear equations - -delta=1e-6 -- tolerance - -function bisect(f,a,b,fa,fb) - local c=(a+b)/2 - io.write(n," c=",c," a=",a," b=",b,"\n") - if c==a or c==b or math.abs(a-b) posted to lua-l --- modified to use ANSI terminal escape sequences --- modified to use for instead of while - -local write=io.write - -ALIVE="¥" DEAD="þ" -ALIVE="O" DEAD="-" - -function delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary - for i=1,10000 do end - -- local i=os.clock()+1 while(os.clock() 0 do - local xm1,x,xp1,xi=self.w-1,self.w,1,self.w - while xi > 0 do - local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] + - self[y][xm1] + self[y][xp1] + - self[yp1][xm1] + self[yp1][x] + self[yp1][xp1] - next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0 - xm1,x,xp1,xi = x,xp1,xp1+1,xi-1 - end - ym1,y,yp1,yi = y,yp1,yp1+1,yi-1 - end -end - --- output the array to screen -function _CELLS:draw() - local out="" -- accumulate to reduce flicker - for y=1,self.h do - for x=1,self.w do - out=out..(((self[y][x]>0) and ALIVE) or DEAD) - end - out=out.."\n" - end - write(out) -end - --- constructor -function CELLS(w,h) - local c = ARRAY2D(w,h) - c.spawn = _CELLS.spawn - c.evolve = _CELLS.evolve - c.draw = _CELLS.draw - return c -end - --- --- shapes suitable for use with spawn() above --- -HEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 } -GLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 } -EXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 } -FISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 } -BUTTERFLY = { 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 } - --- the main routine -function LIFE(w,h) - -- create two arrays - local thisgen = CELLS(w,h) - local nextgen = CELLS(w,h) - - -- create some life - -- about 1000 generations of fun, then a glider steady-state - thisgen:spawn(GLIDER,5,4) - thisgen:spawn(EXPLODE,25,10) - thisgen:spawn(FISH,4,12) - - -- run until break - local gen=1 - write("\027[2J") -- ANSI clear screen - while 1 do - thisgen:evolve(nextgen) - thisgen,nextgen = nextgen,thisgen - write("\027[H") -- ANSI home cursor - thisgen:draw() - write("Life - generation ",gen,"\n") - gen=gen+1 - if gen>2000 then break end - --delay() -- no delay - end -end - -LIFE(40,20) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/luac.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/luac.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/luac.lua @@ -1,7 +0,0 @@ --- bare-bones luac in Lua --- usage: lua luac.lua file.lua - -assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua") -f=assert(io.open("luac.out","wb")) -assert(f:write(string.dump(assert(loadfile(arg[1]))))) -assert(f:close()) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/printf.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/printf.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/printf.lua @@ -1,7 +0,0 @@ --- an implementation of printf - -function printf(...) - io.write(string.format(...)) -end - -printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date()) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/readonly.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/readonly.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/readonly.lua @@ -1,12 +0,0 @@ --- make global variables readonly - -local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end -local g={} -local G=getfenv() -setmetatable(g,{__index=G,__newindex=f}) -setfenv(1,g) - --- an example -rawset(g,"x",3) -x=2 -y=1 -- cannot redefine `y' Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/sieve.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/sieve.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/sieve.lua @@ -1,29 +0,0 @@ --- the sieve of of Eratosthenes programmed with coroutines --- typical usage: lua -e N=1000 sieve.lua | column - --- generate all the numbers from 2 to n -function gen (n) - return coroutine.wrap(function () - for i=2,n do coroutine.yield(i) end - end) -end - --- filter the numbers generated by `g', removing multiples of `p' -function filter (p, g) - return coroutine.wrap(function () - while 1 do - local n = g() - if n == nil then return end - if math.mod(n, p) ~= 0 then coroutine.yield(n) end - end - end) -end - -N=N or 1000 -- from command line -x = gen(N) -- generate primes up to N -while 1 do - local n = x() -- pick a number until done - if n == nil then break end - print(n) -- must be a prime number - x = filter(n, x) -- now remove its multiples -end Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/sort.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/sort.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/sort.lua @@ -1,66 +0,0 @@ --- two implementations of a sort function --- this is an example only. Lua has now a built-in function "sort" - --- extracted from Programming Pearls, page 110 -function qsort(x,l,u,f) - if ly end) - show("after reverse selection sort",x) - qsort(x,1,n,function (x,y) return x>> ",string.rep(" ",level)) - if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end - t=debug.getinfo(2) - if event=="call" then - level=level+1 - else - level=level-1 if level<0 then level=0 end - end - if t.what=="main" then - if event=="call" then - io.write("begin ",t.short_src) - else - io.write("end ",t.short_src) - end - elseif t.what=="Lua" then --- table.foreach(t,print) - io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">") - else - io.write(event," ",t.name or "(C)"," [",t.what,"] ") - end - io.write("\n") -end - -debug.sethook(hook,"cr") -level=0 Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/trace-globals.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/trace-globals.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/trace-globals.lua @@ -1,38 +0,0 @@ --- trace assigments to global variables - -do - -- a tostring that quotes strings. note the use of the original tostring. - local _tostring=tostring - local tostring=function(a) - if type(a)=="string" then - return string.format("%q",a) - else - return _tostring(a) - end - end - - local log=function (name,old,new) - local t=debug.getinfo(3,"Sl") - local line=t.currentline - io.write(t.short_src) - if line>=0 then io.write(":",line) end - io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n") - end - - local g={} - local set=function (t,name,value) - log(name,g[name],value) - g[name]=value - end - setmetatable(getfenv(),{__index=g,__newindex=set}) -end - --- an example - -a=1 -b=2 -a=10 -b=20 -b=nil -b=200 -print(a,b,c) Index: ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/xd.lua =================================================================== --- ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/xd.lua +++ ps/trunk/build/premake/premake4/src/host/lua-5.1.4/test/xd.lua @@ -1,14 +0,0 @@ --- hex dump --- usage: lua xd.lua < file - -local offset=0 -while true do - local s=io.read(16) - if s==nil then return end - io.write(string.format("%08X ",offset)) - string.gsub(s,"(.)", - function (c) io.write(string.format("%02X ",string.byte(c))) end) - io.write(string.rep(" ",3*(16-string.len(s)))) - io.write(" ",string.gsub(s,"%c","."),"\n") - offset=offset+16 -end Index: ps/trunk/build/premake/premake4/src/host/os_chdir.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_chdir.c +++ ps/trunk/build/premake/premake4/src/host/os_chdir.c @@ -1,32 +0,0 @@ -/** - * \file os_chdir.c - * \brief Change the current working directory. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include "premake.h" - - -int os_chdir(lua_State* L) -{ - int z; - const char* path = luaL_checkstring(L, 1); - -#if PLATFORM_WINDOWS - z = SetCurrentDirectory(path); -#else - z = !chdir(path); -#endif - - if (!z) - { - lua_pushnil(L); - lua_pushfstring(L, "unable to switch to directory '%s'", path); - return 2; - } - else - { - lua_pushboolean(L, 1); - return 1; - } -} Index: ps/trunk/build/premake/premake4/src/host/os_copyfile.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_copyfile.c +++ ps/trunk/build/premake/premake4/src/host/os_copyfile.c @@ -1,34 +0,0 @@ -/** - * \file os_copyfile.c - * \brief Copy a file from one location to another. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include -#include "premake.h" - -int os_copyfile(lua_State* L) -{ - int z; - const char* src = luaL_checkstring(L, 1); - const char* dst = luaL_checkstring(L, 2); - -#if PLATFORM_WINDOWS - z = CopyFile(src, dst, FALSE); -#else - lua_pushfstring(L, "cp %s %s", src, dst); - z = (system(lua_tostring(L, -1)) == 0); -#endif - - if (!z) - { - lua_pushnil(L); - lua_pushfstring(L, "unable to copy file to '%s'", dst); - return 2; - } - else - { - lua_pushboolean(L, 1); - return 1; - } -} Index: ps/trunk/build/premake/premake4/src/host/os_getcwd.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_getcwd.c +++ ps/trunk/build/premake/premake4/src/host/os_getcwd.c @@ -1,34 +0,0 @@ -/** - * \file os_getcwd.c - * \brief Retrieve the current working directory. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include "premake.h" - -int os_getcwd(lua_State* L) -{ - char buffer[0x4000]; - char* ch; - int result; - -#if PLATFORM_WINDOWS - result = (GetCurrentDirectory(0x4000, buffer) != 0); -#else - result = (getcwd(buffer, 0x4000) != 0); -#endif - - if (!result) - return 0; - - /* convert to platform-neutral directory separators */ - for (ch = buffer; *ch != '\0'; ++ch) - { - if (*ch == '\\') *ch = '/'; - } - - lua_pushstring(L, buffer); - return 1; -} - - Index: ps/trunk/build/premake/premake4/src/host/os_getversion.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_getversion.c +++ ps/trunk/build/premake/premake4/src/host/os_getversion.c @@ -1,242 +0,0 @@ -/** - * \file os_getversioninfo.c - * \brief Retrieve operating system version information. - * \author Copyright (c) 2011-2012 Jason Perkins and the Premake project - */ - -#include "premake.h" -#include - -struct OsVersionInfo -{ - int majorversion; - int minorversion; - int revision; - const char* description; - int isalloc; -}; - -static void getversion(struct OsVersionInfo* info); - - -int os_getversion(lua_State* L) -{ - struct OsVersionInfo info = {0}; - getversion(&info); - - lua_newtable(L); - - lua_pushstring(L, "majorversion"); - lua_pushnumber(L, info.majorversion); - lua_settable(L, -3); - - lua_pushstring(L, "minorversion"); - lua_pushnumber(L, info.minorversion); - lua_settable(L, -3); - - lua_pushstring(L, "revision"); - lua_pushnumber(L, info.revision); - lua_settable(L, -3); - - lua_pushstring(L, "description"); - lua_pushstring(L, info.description); - lua_settable(L, -3); - - if (info.isalloc) { - free((void*)info.description); - } - - return 1; -} - -/*************************************************************/ - -#if defined(PLATFORM_WINDOWS) - -#if !defined(VER_SUITE_WH_SERVER) -#define VER_SUITE_WH_SERVER (0x00008000) -#endif - -#ifndef SM_SERVERR2 -# define SM_SERVERR2 89 -#endif - -SYSTEM_INFO getsysteminfo() -{ - typedef void (WINAPI *GetNativeSystemInfoSig)(LPSYSTEM_INFO); - GetNativeSystemInfoSig nativeSystemInfo = (GetNativeSystemInfoSig) - GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo"); - - SYSTEM_INFO systemInfo = {{0}}; - if ( nativeSystemInfo ) nativeSystemInfo(&systemInfo); - else GetSystemInfo(&systemInfo); - return systemInfo; -} - -void getversion(struct OsVersionInfo* info) -{ - OSVERSIONINFOEX versionInfo = {0}; - - versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - GetVersionEx((OSVERSIONINFO*)&versionInfo); - - info->majorversion = versionInfo.dwMajorVersion; - info->minorversion = versionInfo.dwMinorVersion; - info->revision = versionInfo.wServicePackMajor; - - if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0) - { - info->description = "Windows 2000"; - } - else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1) - { - info->description = "Windows XP"; - } - else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 2) - { - SYSTEM_INFO systemInfo = getsysteminfo(); - if (versionInfo.wProductType == VER_NT_WORKSTATION && - systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) - { - info->description = "Windows XP Professional x64"; - } - else if (versionInfo.wSuiteMask & VER_SUITE_WH_SERVER) - { - info->description = "Windows Home Server"; - } - else if (GetSystemMetrics(SM_SERVERR2) == 0) - { - info->description = "Windows Server 2003"; - } - else - { - info->description = "Windows Server 2003 R2"; - } - } - else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0) - { - if (versionInfo.wProductType == VER_NT_WORKSTATION) - { - info->description = "Windows Vista"; - } - else - { - info->description = "Windows Server 2008"; - } - } - else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 ) - { - if (versionInfo.wProductType != VER_NT_WORKSTATION) - { - info->description = "Windows Server 2008 R2"; - } - else - { - info->description = "Windows 7"; - } - } - else - { - info->description = "Windows"; - } -} - -/*************************************************************/ - -#elif defined(PLATFORM_MACOSX) - -#include - -void getversion(struct OsVersionInfo* info) -{ - SInt32 majorversion, minorversion, bugfix; - Gestalt(gestaltSystemVersionMajor, &majorversion); - Gestalt(gestaltSystemVersionMinor, &minorversion); - Gestalt(gestaltSystemVersionBugFix, &bugfix); - - info->majorversion = majorversion; - info->minorversion = minorversion; - info->revision = bugfix; - - info->description = "Mac OS X"; - if (info->majorversion == 10) - { - switch (info->minorversion) - { - case 4: - info->description = "Mac OS X Tiger"; - break; - case 5: - info->description = "Mac OS X Leopard"; - break; - case 6: - info->description = "Mac OS X Snow Leopard"; - break; - case 7: - info->description = "Mac OS X Lion"; - break; - } - } -} - -/*************************************************************/ - -#elif defined(PLATFORM_BSD) || defined(PLATFORM_LINUX) || defined(PLATFORM_SOLARIS) - -#include -#include - -void getversion(struct OsVersionInfo* info) -{ - struct utsname u; - char* ver; - - info->majorversion = 0; - info->minorversion = 0; - info->revision = 0; - - if (uname(&u)) - { - // error - info->description = PLATFORM_STRING; - return; - } - -#if __GLIBC__ - // When using glibc, info->description gets set to u.sysname, - // but it isn't passed out of this function, so we need to copy - // the string. - info->description = malloc(strlen(u.sysname) + 1); - strcpy((char*)info->description, u.sysname); - info->isalloc = 1; -#else - info->description = u.sysname; -#endif - - if ((ver = strtok(u.release, ".-")) != NULL) - { - info->majorversion = atoi(ver); - // continue parsing from the previous position - if ((ver = strtok(NULL, ".-")) != NULL) - { - info->minorversion = atoi(ver); - if ((ver = strtok(NULL, ".-")) != NULL) - info->revision = atoi(ver); - } - } -} - -/*************************************************************/ - -#else - -void getversion(struct OsVersionInfo* info) -{ - info->majorversion = 0; - info->minorversion = 0; - info->revision = 0; - info->description = PLATFORM_STRING; -} - -#endif - Index: ps/trunk/build/premake/premake4/src/host/os_isdir.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_isdir.c +++ ps/trunk/build/premake/premake4/src/host/os_isdir.c @@ -1,34 +0,0 @@ -/** - * \file os_isdir.c - * \brief Returns true if the specified directory exists. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include -#include -#include "premake.h" - - -int os_isdir(lua_State* L) -{ - struct stat buf; - const char* path = luaL_checkstring(L, 1); - - /* empty path is equivalent to ".", must be true */ - if (strlen(path) == 0) - { - lua_pushboolean(L, 1); - } - else if (stat(path, &buf) == 0) - { - lua_pushboolean(L, buf.st_mode & S_IFDIR); - } - else - { - lua_pushboolean(L, 0); - } - - return 1; -} - - Index: ps/trunk/build/premake/premake4/src/host/os_isfile.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_isfile.c +++ ps/trunk/build/premake/premake4/src/host/os_isfile.c @@ -1,30 +0,0 @@ -/** - * \file os_isfile.c - * \brief Returns true if the given file exists on the file system. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include -#include "premake.h" - - -int os_isfile(lua_State* L) -{ - const char* filename = luaL_checkstring(L, 1); - lua_pushboolean(L, do_isfile(filename)); - return 1; -} - - -int do_isfile(const char* filename) -{ - struct stat buf; - if (stat(filename, &buf) == 0) - { - return ((buf.st_mode & S_IFDIR) == 0); - } - else - { - return 0; - } -} Index: ps/trunk/build/premake/premake4/src/host/os_match.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_match.c +++ ps/trunk/build/premake/premake4/src/host/os_match.c @@ -1,183 +0,0 @@ -/** - * \file os_match.c - * \brief Match files and directories. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include -#include -#include "premake.h" - - -#if PLATFORM_WINDOWS - -#define WIN32_LEAN_AND_MEAN -#include - -typedef struct struct_MatchInfo -{ - HANDLE handle; - int is_first; - WIN32_FIND_DATA entry; -} MatchInfo; - -int os_matchstart(lua_State* L) -{ - const char* mask = luaL_checkstring(L, 1); - MatchInfo* m = (MatchInfo*)malloc(sizeof(MatchInfo)); - m->handle = FindFirstFile(mask, &m->entry); - m->is_first = 1; - lua_pushlightuserdata(L, m); - return 1; -} - -int os_matchdone(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - if (m->handle != INVALID_HANDLE_VALUE) - FindClose(m->handle); - free(m); - return 0; -} - -int os_matchname(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - lua_pushstring(L, m->entry.cFileName); - return 1; -} - -int os_matchisfile(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - lua_pushboolean(L, (m->entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0); - return 1; -} - -int os_matchnext(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - if (m->handle == INVALID_HANDLE_VALUE) - return 0; - - while (m) /* loop forever */ - { - if (!m->is_first) - { - if (!FindNextFile(m->handle, &m->entry)) - return 0; - } - - m->is_first = 0; - if (m->entry.cFileName[0] != '.') - { - lua_pushboolean(L, 1); - return 1; - } - } - - return 0; -} - -#else - -#include -#include -#include - -typedef struct struct_MatchInfo -{ - DIR* handle; - struct dirent* entry; - char* path; - char* mask; -} MatchInfo; - -int os_matchstart(lua_State* L) -{ - const char* split; - const char* mask = luaL_checkstring(L, 1); - MatchInfo* m = (MatchInfo*)malloc(sizeof(MatchInfo)); - - /* split the mask into path and filename components */ - split = strrchr(mask, '/'); - if (split) - { - m->path = (char*)malloc(split - mask + 1); - strncpy(m->path, mask, split - mask); - m->path[split - mask] = '\0'; - m->mask = (char*)malloc(mask + strlen(mask) - split); - strcpy(m->mask, split + 1); - } - else - { - m->path = (char*)malloc(2); - strcpy(m->path, "."); - m->mask = (char*)malloc(strlen(mask)+1); - strcpy(m->mask, mask); - } - - m->handle = opendir(m->path); - lua_pushlightuserdata(L, m); - return 1; -} - -int os_matchdone(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - if (m->handle != NULL) - closedir(m->handle); - free(m->path); - free(m->mask); - free(m); - return 0; -} - -int os_matchname(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - lua_pushstring(L, m->entry->d_name); - return 1; -} - -int os_matchisfile(lua_State* L) -{ - struct stat info; - const char* fname; - - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - lua_pushfstring(L, "%s/%s", m->path, m->entry->d_name); - fname = lua_tostring(L, -1); - lua_pop(L, 1); - - if (stat(fname, &info) == 0) - { - lua_pushboolean(L, S_ISREG(info.st_mode)); - return 1; - } - - return 0; -} - -int os_matchnext(lua_State* L) -{ - MatchInfo* m = (MatchInfo*)lua_touserdata(L, 1); - if (m->handle == NULL) - return 0; - - m->entry = readdir(m->handle); - while (m->entry != NULL) - { - const char* name = m->entry->d_name; - if (name[0] != '.' && fnmatch(m->mask, name, 0) == 0) - { - lua_pushboolean(L, 1); - return 1; - } - m->entry = readdir(m->handle); - } - - return 0; -} - -#endif Index: ps/trunk/build/premake/premake4/src/host/os_mkdir.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_mkdir.c +++ ps/trunk/build/premake/premake4/src/host/os_mkdir.c @@ -1,33 +0,0 @@ -/** - * \file os_mkdir.c - * \brief Create a subdirectory. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include -#include "premake.h" - - -int os_mkdir(lua_State* L) -{ - int z; - const char* path = luaL_checkstring(L, 1); - -#if PLATFORM_WINDOWS - z = CreateDirectory(path, NULL); -#else - z = (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0); -#endif - - if (!z) - { - lua_pushnil(L); - lua_pushfstring(L, "unable to create directory '%s'", path); - return 2; - } - else - { - lua_pushboolean(L, 1); - return 1; - } -} Index: ps/trunk/build/premake/premake4/src/host/os_pathsearch.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_pathsearch.c +++ ps/trunk/build/premake/premake4/src/host/os_pathsearch.c @@ -1,84 +0,0 @@ -/** - * \file os_pathsearch.c - * \brief Locates a file, given a set of search paths. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - * - * \note This function is required by the bootstrapping code; it must be - * implemented here in the host and not scripted. - */ - -#include -#include "premake.h" - - -int os_pathsearch(lua_State* L) -{ - int i; - for (i = 2; i <= lua_gettop(L); ++i) - { - const char* path; - - if (lua_isnil(L, i)) - continue; - - path = luaL_checkstring(L, i); - do - { - const char* split; - - /* look for the closest path separator ; or : */ - /* can't use : on windows because it breaks on C:\path */ - const char* semi = strchr(path, ';'); -#if !defined(PLATFORM_WINDOWS) - const char* full = strchr(path, ':'); -#else - const char* full = NULL; -#endif - - if (!semi) - { - split = full; - } - else if (!full) - { - split = semi; - } - else - { - split = (semi < full) ? semi : full; - } - - /* push this piece of the full search string onto the stack */ - if (split) - { - lua_pushlstring(L, path, split - path); - } - else - { - lua_pushstring(L, path); - } - - /* keep an extra copy around, so I can return it if I have a match */ - lua_pushvalue(L, -1); - - /* append the filename to make the full test path */ - lua_pushstring(L, "/"); - lua_pushvalue(L, 1); - lua_concat(L, 3); - - /* test it - if it exists return the path */ - if (do_isfile(lua_tostring(L, -1))) - { - lua_pop(L, 1); - return 1; - } - - /* no match, set up the next try */ - lua_pop(L, 2); - path = (split) ? split + 1 : NULL; - } - while (path); - } - - return 0; -} Index: ps/trunk/build/premake/premake4/src/host/os_rmdir.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_rmdir.c +++ ps/trunk/build/premake/premake4/src/host/os_rmdir.c @@ -1,33 +0,0 @@ -/** - * \file os_rmdir.c - * \brief Remove a subdirectory. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include -#include "premake.h" - - -int os_rmdir(lua_State* L) -{ - int z; - const char* path = luaL_checkstring(L, 1); - -#if PLATFORM_WINDOWS - z = RemoveDirectory(path); -#else - z = rmdir(path); -#endif - - if (!z) - { - lua_pushnil(L); - lua_pushfstring(L, "unable to remove directory '%s'", path); - return 2; - } - else - { - lua_pushboolean(L, 1); - return 1; - } -} Index: ps/trunk/build/premake/premake4/src/host/os_uuid.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/os_uuid.c +++ ps/trunk/build/premake/premake4/src/host/os_uuid.c @@ -1,45 +0,0 @@ -/** - * \file os_uuid.c - * \brief Create a new UUID. - * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project - */ - -#include "premake.h" - - -int os_uuid(lua_State* L) -{ - unsigned char bytes[16]; - char uuid[38]; - -#if PLATFORM_WINDOWS - - static int (__stdcall *CoCreateGuid)(char*) = NULL; - if (CoCreateGuid == NULL) - { - HMODULE hOleDll = LoadLibrary("OLE32.DLL"); - CoCreateGuid = (int(__stdcall*)(char*))GetProcAddress(hOleDll, "CoCreateGuid"); - } - CoCreateGuid((char*)bytes); - -#else - int result; - - /* not sure how to get a UUID here, so I fake it */ - FILE* rnd = fopen("/dev/urandom", "rb"); - result = fread(bytes, 16, 1, rnd); - fclose(rnd); - if (!result) - return 0; -#endif - - sprintf(uuid, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", - bytes[0], bytes[1], bytes[2], bytes[3], - bytes[4], bytes[5], - bytes[6], bytes[7], - bytes[8], bytes[9], - bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); - - lua_pushstring(L, uuid); - return 1; -} Index: ps/trunk/build/premake/premake4/src/host/path_isabsolute.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/path_isabsolute.c +++ ps/trunk/build/premake/premake4/src/host/path_isabsolute.c @@ -1,22 +0,0 @@ -/** - * \file path_isabsolute.c - * \brief Determines if a path is absolute or relative. - * \author Copyright (c) 2002-2009 Jason Perkins and the Premake project - */ - -#include "premake.h" - - -int path_isabsolute(lua_State* L) -{ - const char* path = luaL_checkstring(L, 1); - if (path[0] == '/' || path[0] == '\\' || path[0] == '$' || (path[0] != '\0' && path[1] == ':')) - { - lua_pushboolean(L, 1); - return 1; - } - else - { - return 0; - } -} Index: ps/trunk/build/premake/premake4/src/host/premake.h =================================================================== --- ps/trunk/build/premake/premake4/src/host/premake.h +++ ps/trunk/build/premake/premake4/src/host/premake.h @@ -1,71 +0,0 @@ -/** - * \file premake.h - * \brief Program-wide constants and definitions. - * \author Copyright (c) 2002-2011 Jason Perkins and the Premake project - */ - -#define lua_c -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" - - -/* Identify the current platform I'm not sure how to reliably detect - * Windows but since it is the most common I use it as the default */ -#if defined(__linux__) -#define PLATFORM_LINUX (1) -#define PLATFORM_STRING "linux" -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) -#define PLATFORM_BSD (1) -#define PLATFORM_STRING "bsd" -#elif defined(__APPLE__) && defined(__MACH__) -#define PLATFORM_MACOSX (1) -#define PLATFORM_STRING "macosx" -#elif defined(__sun__) && defined(__svr4__) -#define PLATFORM_SOLARIS (1) -#define PLATFORM_STRING "solaris" -#elif defined(__HAIKU__) -#define PLATFORM_HAIKU (1) -#define PLATFORM_STRING "haiku" -#else -#define PLATFORM_WINDOWS (1) -#define PLATFORM_STRING "windows" -#endif - - -/* Pull in platform-specific headers required by built-in functions */ -#if PLATFORM_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include -#else -#include -#endif - - -/* A success return code */ -#define OKAY (0) - - -/* Bootstrapping helper functions */ -int do_isfile(const char* filename); - - -/* Built-in functions */ -int path_isabsolute(lua_State* L); -int os_chdir(lua_State* L); -int os_copyfile(lua_State* L); -int os_getcwd(lua_State* L); -int os_getversion(lua_State* L); -int os_isdir(lua_State* L); -int os_isfile(lua_State* L); -int os_matchdone(lua_State* L); -int os_matchisfile(lua_State* L); -int os_matchname(lua_State* L); -int os_matchnext(lua_State* L); -int os_matchstart(lua_State* L); -int os_mkdir(lua_State* L); -int os_pathsearch(lua_State* L); -int os_rmdir(lua_State* L); -int os_uuid(lua_State* L); -int string_endswith(lua_State* L); - Index: ps/trunk/build/premake/premake4/src/host/premake.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/premake.c +++ ps/trunk/build/premake/premake4/src/host/premake.c @@ -1,275 +0,0 @@ -/** - * \file premake.c - * \brief Program entry point. - * \author Copyright (c) 2002-2011 Jason Perkins and the Premake project - */ - -#include -#include -#include "premake.h" - - -#define VERSION "HEAD" -#define COPYRIGHT "Copyright (C) 2002-2011 Jason Perkins and the Premake Project" -#define ERROR_MESSAGE "%s\n" - - -static int process_arguments(lua_State* L, int argc, const char** argv); -static int process_option(lua_State* L, const char* arg); -static int load_builtin_scripts(lua_State* L); - - -/* A search path for script files */ -static const char* scripts_path = NULL; - - -/* precompiled bytecode buffer; in bytecode.c */ -extern const char* builtin_scripts[]; - - -/* Built-in functions */ -static const luaL_Reg path_functions[] = { - { "isabsolute", path_isabsolute }, - { NULL, NULL } -}; - -static const luaL_Reg os_functions[] = { - { "chdir", os_chdir }, - { "copyfile", os_copyfile }, - { "isdir", os_isdir }, - { "getcwd", os_getcwd }, - { "getversion", os_getversion }, - { "isfile", os_isfile }, - { "matchdone", os_matchdone }, - { "matchisfile", os_matchisfile }, - { "matchname", os_matchname }, - { "matchnext", os_matchnext }, - { "matchstart", os_matchstart }, - { "mkdir", os_mkdir }, - { "pathsearch", os_pathsearch }, - { "rmdir", os_rmdir }, - { "uuid", os_uuid }, - { NULL, NULL } -}; - -static const luaL_Reg string_functions[] = { - { "endswith", string_endswith }, - { NULL, NULL } -}; - - - -/** - * Program entry point. - */ -int main(int argc, const char** argv) -{ - lua_State* L; - int z = OKAY; - - /* prepare Lua for use */ - L = lua_open(); - luaL_openlibs(L); - luaL_register(L, "path", path_functions); - luaL_register(L, "os", os_functions); - luaL_register(L, "string", string_functions); - - /* push the application metadata */ - lua_pushstring(L, LUA_COPYRIGHT); - lua_setglobal(L, "_COPYRIGHT"); - - lua_pushstring(L, VERSION); - lua_setglobal(L, "_PREMAKE_VERSION"); - - lua_pushstring(L, COPYRIGHT); - lua_setglobal(L, "_PREMAKE_COPYRIGHT"); - - /* set the OS platform variable */ - lua_pushstring(L, PLATFORM_STRING); - lua_setglobal(L, "_OS"); - - /* Parse the command line arguments */ - if (z == OKAY) z = process_arguments(L, argc, argv); - - /* Run the built-in Premake scripts */ - if (z == OKAY) z = load_builtin_scripts(L); - - /* Clean up and turn off the lights */ - lua_close(L); - return z; -} - - - -/** - * Process the command line arguments, splitting them into options, the - * target action, and any arguments to that action. The results are pushed - * into the session for later use. I could have done this in the scripts, - * but I need the value of the /scripts option to find them. - * \returns OKAY if successful. - */ -int process_arguments(lua_State* L, int argc, const char** argv) -{ - int i; - - /* Create empty lists for Options and Args */ - lua_newtable(L); - lua_newtable(L); - - for (i = 1; i < argc; ++i) - { - /* Options start with '/' or '--'. The first argument that isn't an option - * is the action. Anything after that is an argument to the action */ - if (argv[i][0] == '/') - { - process_option(L, argv[i] + 1); - } - else if (argv[i][0] == '-' && argv[i][1] == '-') - { - process_option(L, argv[i] + 2); - } - else - { - /* not an option, is the action */ - lua_pushstring(L, argv[i++]); - lua_setglobal(L, "_ACTION"); - - /* everything else is an argument */ - while (i < argc) - { - lua_pushstring(L, argv[i++]); - lua_rawseti(L, -2, luaL_getn(L, -2) + 1); - } - } - } - - /* push the Options and Args lists */ - lua_setglobal(L, "_ARGS"); - lua_setglobal(L, "_OPTIONS"); - return OKAY; -} - - - -/** - * Parse an individual command-line option. - * \returns OKAY if successful. - */ -int process_option(lua_State* L, const char* arg) -{ - char key[512]; - const char* value; - - /* If a value is specified, split the option into a key/value pair */ - char* ptr = strchr(arg, '='); - if (ptr) - { - int len = ptr - arg; - if (len > 511) len = 511; - strncpy(key, arg, len); - key[len] = '\0'; - value = ptr + 1; - } - else - { - strcpy(key, arg); - value = ""; - } - - /* Store it in the Options table, which is already on the stack */ - lua_pushstring(L, value); - lua_setfield(L, -3, key); - - /* The /scripts option gets picked up here to find the built-in scripts */ - if (strcmp(key, "scripts") == 0 && strlen(value) > 0) - { - scripts_path = value; - } - - return OKAY; -} - - - -#if defined(_DEBUG) -/** - * When running in debug mode, the scripts are loaded from the disk. The path to - * the scripts must be provided via either the /scripts command line option or - * the PREMAKE_PATH environment variable. - */ -int load_builtin_scripts(lua_State* L) -{ - const char* filename; - - /* call os.pathsearch() to locate _premake_main.lua */ - lua_pushcfunction(L, os_pathsearch); - lua_pushstring(L, "_premake_main.lua"); - lua_pushstring(L, scripts_path); - lua_pushstring(L, getenv("PREMAKE_PATH")); - lua_call(L, 3, 1); - - if (lua_isnil(L, -1)) - { - printf(ERROR_MESSAGE, - "Unable to find _premake_main.lua; use /scripts option when in debug mode!\n" - "Please refer to the documentation (or build in release mode instead)." - ); - return !OKAY; - } - - /* run the bootstrapping script */ - scripts_path = lua_tostring(L, -1); - filename = lua_pushfstring(L, "%s/_premake_main.lua", scripts_path); - if (luaL_dofile(L, filename)) - { - printf(ERROR_MESSAGE, lua_tostring(L, -1)); - return !OKAY; - } - - /* hand off control to the scripts */ - lua_getglobal(L, "_premake_main"); - lua_pushstring(L, scripts_path); - if (lua_pcall(L, 1, 1, 0) != OKAY) - { - printf(ERROR_MESSAGE, lua_tostring(L, -1)); - return !OKAY; - } - else - { - return (int)lua_tonumber(L, -1); - } -} -#endif - - -#if defined(NDEBUG) -/** - * When running in release mode, the scripts are loaded from a static data - * buffer, where they were stored by a preprocess. To update these embedded - * scripts, run `premake4 embed` then rebuild. - */ -int load_builtin_scripts(lua_State* L) -{ - int i; - for (i = 0; builtin_scripts[i]; ++i) - { - if (luaL_dostring(L, builtin_scripts[i]) != OKAY) - { - printf(ERROR_MESSAGE, lua_tostring(L, -1)); - return !OKAY; - } - } - - /* hand off control to the scripts */ - lua_getglobal(L, "_premake_main"); - if (lua_pcall(L, 0, 1, 0) != OKAY) - { - printf(ERROR_MESSAGE, lua_tostring(L, -1)); - return !OKAY; - } - else - { - return (int)lua_tonumber(L, -1); - } -} -#endif Index: ps/trunk/build/premake/premake4/src/host/scripts.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/scripts.c +++ ps/trunk/build/premake/premake4/src/host/scripts.c @@ -1,307 +0,0 @@ -/* Premake's Lua scripts, as static data buffers for release mode builds */ -/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */ -/* To regenerate this file, run: premake4 embed */ - -const char* builtin_scripts[] = { - /* base/os.lua */ - "function os.executef(cmd, ...)\ncmd = string.format(cmd, unpack(arg))\nreturn os.execute(cmd)\nend\nlocal function parse_ld_so_conf(conf_file)\nlocal first, last\nlocal dirs = { }\nlocal file = io.open(conf_file)\nif file == nil then\nreturn dirs\nend\nfor line in file:lines() do\nfirst = line:find(\"#\", 1, true)\nif first ~= nil then\nline = line:sub(1, first - 1)\nend\nif line ~= \"\" then\nfirst, last = line:find(\"include%s+\")\nif first ~= nil then\nlocal include_glob = line:sub(last + 1)\nlocal includes = os.matchfiles(include_glob)\nfor _, v in ipairs(includes) do\ndirs = table.join(dirs, parse_ld_so_conf(v))\nend\nelse\ntable.insert(dirs, line)\nend\nend\nend\nreturn dirs\nend\nfunction os.findlib(libname)\nlocal path, formats\nif os.is(\"windows\") then\nformats = { \"%s.dll\", \"%s\" }\npath = os.getenv(\"PATH\")\nelseif os.is(\"haiku\") then\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LIBRARY_PATH\")\nelse\nif os.is(\"macosx\") then\nformats = { \"lib%s.dylib\", \"%s.dylib\" }\npath " - "= os.getenv(\"DYLD_LIBRARY_PATH\")\nelse\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LD_LIBRARY_PATH\") or \"\"\nfor _, v in ipairs(parse_ld_so_conf(\"/etc/ld.so.conf\")) do\npath = path .. \":\" .. v\nend\nend\ntable.insert(formats, \"%s\")\npath = path or \"\"\nif os.is64bit() then\npath = path .. \":/lib64:/usr/lib64/:usr/local/lib64\"\nend\npath = path .. \":/lib:/usr/lib:/usr/local/lib\"\nend\nfor _, fmt in ipairs(formats) do\nlocal name = string.format(fmt, libname)\nlocal result = os.pathsearch(name, path)\nif result then return result end\nend\nend\nfunction os.get()\nreturn _OPTIONS.os or _OS\nend\nfunction os.is(id)\nreturn (os.get():lower() == id:lower())\nend\nlocal _64BitHostTypes = {\n\"x86_64\",\n\"ia64\",\n\"amd64\",\n\"ppc64\",\n\"powerpc64\",\n\"sparc64\"\n}\nfunction os.is64bit()\nlocal arch\nif _OS == \"windows\" then\narch = os.getenv(\"PROCESSOR_ARCHITECTURE\")\nelseif _OS == \"macosx\" then\narch = os.outputof(\"echo $HOSTTYPE\")\nelse\narch = os.outputof(\"uname -m\")\nen" - "d\narch = arch:lower()\nfor _, hosttype in ipairs(_64BitHostTypes) do\nif arch:find(hosttype) then\nreturn true\nend\nend\nreturn false\nend\nlocal function domatch(result, mask, wantfiles)\nif mask:startswith(\"./\") then\nmask = mask:sub(3)\nend\nlocal basedir = mask\nlocal starpos = mask:find(\"%*\")\nif starpos then\nbasedir = basedir:sub(1, starpos - 1)\nend\nbasedir = path.getdirectory(basedir)\nif (basedir == \".\") then basedir = \"\" end\nlocal recurse = mask:find(\"**\", nil, true)\nmask = path.wildcards(mask)\nlocal function matchwalker(basedir)\nlocal wildcard = path.join(basedir, \"*\")\nlocal m = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nlocal isfile = os.matchisfile(m)\nif ((wantfiles and isfile) or (not wantfiles and not isfile)) then\nlocal fname = path.join(basedir, os.matchname(m))\nif fname:match(mask) == fname then\ntable.insert(result, fname)\nend\nend\nend\nos.matchdone(m)\nif recurse then\nm = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nif not os.matchisfile(m) then" - "\nlocal dirname = os.matchname(m)\nmatchwalker(path.join(basedir, dirname))\nend\nend\nos.matchdone(m)\nend\nend\nmatchwalker(basedir)\nend\nfunction os.matchdirs(...)\nlocal result = { }\nfor _, mask in ipairs(arg) do\ndomatch(result, mask, false)\nend\nreturn result\nend\nfunction os.matchfiles(...)\nlocal result = { }\nfor _, mask in ipairs(arg) do\ndomatch(result, mask, true)\nend\nreturn result\nend\nlocal builtin_mkdir = os.mkdir\nfunction os.mkdir(p)\nlocal dir = iif(p:startswith(\"/\"), \"/\", \"\")\nfor part in p:gmatch(\"[^/]+\") do\ndir = dir .. part\nif (part ~= \"\" and not path.isabsolute(part) and not os.isdir(dir)) then\nlocal ok, err = builtin_mkdir(dir)\nif (not ok) then\nreturn nil, err\nend\nend\ndir = dir .. \"/\"\nend\nreturn true\nend\nfunction os.outputof(cmd)\nlocal pipe = io.popen(cmd)\nlocal result = pipe:read('*a')\npipe:close()\nreturn result\nend\nlocal builtin_rmdir = os.rmdir\nfunction os.rmdir(p)\nlocal dirs = os.matchdirs(p .. \"/*\")\nfor _, dname in ipairs(dirs) do\nos.rmdir" - "(dname)\nend\nlocal files = os.matchfiles(p .. \"/*\")\nfor _, fname in ipairs(files) do\nos.remove(fname)\nend\nbuiltin_rmdir(p)\nend\n", - - /* base/path.lua */ - "function path.getabsolute(p)\np = path.translate(p, \"/\")\nif (p == \"\") then p = \".\" end\nlocal result = iif (path.isabsolute(p), nil, os.getcwd())\nfor n, part in ipairs(p:explode(\"/\", true)) do\nif (part == \"\" and n == 1) then\nresult = \"/\"\nelseif (part == \"..\") then\nresult = path.getdirectory(result)\nelseif (part ~= \".\") then\nresult = path.join(result, part)\nend\nend\nresult = iif(result:endswith(\"/\"), result:sub(1, -2), result)\nreturn result\nend\nfunction path.getbasename(p)\nlocal name = path.getname(p)\nlocal i = name:findlast(\".\", true)\nif (i) then\nreturn name:sub(1, i - 1)\nelse\nreturn name\nend\nend\nfunction path.getdirectory(p)\nlocal i = p:findlast(\"/\", true)\nif (i) then\nif i > 1 then i = i - 1 end\nreturn p:sub(1, i)\nelse\nreturn \".\"\nend\nend\nfunction path.getdrive(p)\nlocal ch1 = p:sub(1,1)\nlocal ch2 = p:sub(2,2)\nif ch2 == \":\" then\nreturn ch1\nend\nend\nfunction path.getextension(p)\nlocal i = p:findlast(\".\", true)\nif (i) then\nreturn p:sub(i)\nelse\n" - "return \"\"\nend\nend\nfunction path.getname(p)\nlocal i = p:findlast(\"[/\\\\]\")\nif (i) then\nreturn p:sub(i + 1)\nelse\nreturn p\nend\nend\nfunction path.getrelative(src, dst)\nsrc = path.getabsolute(src)\ndst = path.getabsolute(dst)\nif (src == dst) then\nreturn \".\"\nend\nif dst:startswith(\"$\") then\nreturn dst\nend\nsrc = src .. \"/\"\ndst = dst .. \"/\"\nlocal idx = 0\nwhile (true) do\nlocal tst = src:find(\"/\", idx + 1, true)\nif tst then\nif src:sub(1,tst) == dst:sub(1,tst) then\nidx = tst\nelse\nbreak\nend\nelse\nbreak\nend\nend\nlocal first = src:find(\"/\", 0, true)\nif idx <= first then\nreturn dst:sub(1, -2)\nend\nsrc = src:sub(idx + 1)\ndst = dst:sub(idx + 1)\nlocal result = \"\"\nidx = src:find(\"/\")\nwhile (idx) do\nresult = result .. \"../\"\nidx = src:find(\"/\", idx + 1)\nend\nresult = result .. dst\nreturn result:sub(1, -2)\nend\nfunction path.iscfile(fname)\nlocal extensions = { \".c\", \".s\", \".m\" }\nlocal ext = path.getextension(fname):lower()\nreturn table.contains(extensions," - " ext)\nend\nfunction path.iscppfile(fname)\nlocal extensions = { \".cc\", \".cpp\", \".cxx\", \".c\", \".s\", \".m\", \".mm\" }\nlocal ext = path.getextension(fname):lower()\nreturn table.contains(extensions, ext)\nend\nfunction path.isresourcefile(fname)\nlocal extensions = { \".rc\" }\nlocal ext = path.getextension(fname):lower()\nreturn table.contains(extensions, ext)\nend\nfunction path.join(leading, trailing)\nleading = leading or \"\"\nif (not trailing) then\nreturn leading\nend\nif (path.isabsolute(trailing)) then\nreturn trailing\nend\nif (leading == \".\") then\nleading = \"\"\nend\nif (leading:len() > 0 and not leading:endswith(\"/\")) then\nleading = leading .. \"/\"\nend\nreturn leading .. trailing\nend\nfunction path.rebase(p, oldbase, newbase)\np = path.getabsolute(path.join(oldbase, p))\np = path.getrelative(newbase, p)\nreturn p\nend\nfunction path.translate(p, sep)\nif (type(p) == \"table\") then\nlocal result = { }\nfor _, value in ipairs(p) do\ntable.insert(result, path.translate(value))\nen" - "d\nreturn result\nelse\nif (not sep) then\nif (os.is(\"windows\")) then\nsep = \"\\\\\"\nelse\nsep = \"/\"\nend\nend\nlocal result = p:gsub(\"[/\\\\]\", sep)\nreturn result\nend\nend\nfunction path.wildcards(pattern)\npattern = pattern:gsub(\"([%+%.%-%^%$%(%)%%])\", \"%%%1\")\npattern = pattern:gsub(\"%*%*\", \"\\001\")\npattern = pattern:gsub(\"%*\", \"\\002\")\npattern = pattern:gsub(\"\\001\", \".*\")\npattern = pattern:gsub(\"\\002\", \"[^/]*\")\nreturn pattern\nend\n", - - /* base/string.lua */ - "function string.explode(s, pattern, plain)\nif (pattern == '') then return false end\nlocal pos = 0\nlocal arr = { }\nfor st,sp in function() return s:find(pattern, pos, plain) end do\ntable.insert(arr, s:sub(pos, st-1))\npos = sp + 1\nend\ntable.insert(arr, s:sub(pos))\nreturn arr\nend\nfunction string.findlast(s, pattern, plain)\nlocal curr = 0\nrepeat\nlocal next = s:find(pattern, curr + 1, plain)\nif (next) then curr = next end\nuntil (not next)\nif (curr > 0) then\nreturn curr\nend\nend\nfunction string.startswith(haystack, needle)\nreturn (haystack:find(needle, 1, true) == 1)\nend\n", - - /* base/table.lua */ - "function table.contains(t, value)\nfor _,v in pairs(t) do\nif (v == value) then\nreturn true\nend\nend\nreturn false\nend\nfunction table.extract(arr, fname)\nlocal result = { }\nfor _,v in ipairs(arr) do\ntable.insert(result, v[fname])\nend\nreturn result\nend\nfunction table.flatten(arr)\nlocal result = { }\nlocal function flatten(arr)\nfor _, v in ipairs(arr) do\nif type(v) == \"table\" then\nflatten(v)\nelse\ntable.insert(result, v)\nend\nend\nend\nflatten(arr)\nreturn result\nend\nfunction table.implode(arr, before, after, between)\nlocal result = \"\"\nfor _,v in ipairs(arr) do\nif (result ~= \"\" and between) then\nresult = result .. between\nend\nresult = result .. before .. v .. after\nend\nreturn result\nend\nfunction table.isempty(t)\nreturn not next(t)\nend\nfunction table.join(...)\nlocal result = { }\nfor _,t in ipairs(arg) do\nif type(t) == \"table\" then\nfor _,v in ipairs(t) do\ntable.insert(result, v)\nend\nelse\ntable.insert(result, t)\nend\nend\nreturn result\nend\nfunction table.keys(tbl)" - "\nlocal keys = {}\nfor k, _ in pairs(tbl) do\ntable.insert(keys, k)\nend\nreturn keys\nend\nfunction table.translate(arr, translation)\nlocal result = { }\nfor _, value in ipairs(arr) do\nlocal tvalue\nif type(translation) == \"function\" then\ntvalue = translation(value)\nelse\ntvalue = translation[value]\nend\nif (tvalue) then\ntable.insert(result, tvalue)\nend\nend\nreturn result\nend\n", - - /* base/io.lua */ - "function io.capture()\nio.captured = ''\nend\nfunction io.endcapture()\nlocal captured = io.captured\nio.captured = nil\nreturn captured\nend\nlocal builtin_open = io.open\nfunction io.open(fname, mode)\nif (mode) then\nif (mode:find(\"w\")) then\nlocal dir = path.getdirectory(fname)\nok, err = os.mkdir(dir)\nif (not ok) then\nerror(err, 0)\nend\nend\nend\nreturn builtin_open(fname, mode)\nend\nfunction io.printf(msg, ...)\nif (not io.eol) then\nio.eol = \"\\n\"\nend\nlocal s\nif type(msg) == \"number\" then\ns = string.rep(\"\\t\", msg) .. string.format(unpack(arg))\nelse\ns = string.format(msg, unpack(arg))\nend\nif io.captured then\nio.captured = io.captured .. s .. io.eol\nelse\nio.write(s)\nio.write(io.eol)\nend\nend\n_p = io.printf\n", - - /* base/globals.lua */ - "premake = { }\npremake.platforms = \n{\nNative = \n{ \ncfgsuffix = \"\",\n},\nx32 = \n{ \ncfgsuffix = \"32\",\n},\nx64 = \n{ \ncfgsuffix = \"64\",\n},\nUniversal = \n{ \ncfgsuffix = \"univ\",\n},\nUniversal32 = \n{ \ncfgsuffix = \"univ32\",\n},\nUniversal64 = \n{ \ncfgsuffix = \"univ64\",\n},\nPS3 = \n{ \ncfgsuffix = \"ps3\",\niscrosscompiler = true,\nnosharedlibs = true,\nnamestyle = \"PS3\",\n},\nXbox360 = \n{ \ncfgsuffix = \"xbox360\",\niscrosscompiler = true,\nnamestyle = \"windows\",\n},\n}\nlocal builtin_dofile = dofile\nfunction dofile(fname)\nlocal oldcwd = os.getcwd()\nlocal oldfile = _SCRIPT\nif (not os.isfile(fname)) then\nlocal path = os.pathsearch(fname, _OPTIONS[\"scripts\"], os.getenv(\"PREMAKE_PATH\"))\nif (path) then\nfname = path..\"/\"..fname\nend\nend\n_SCRIPT = path.getabsolute(fname)\nlocal newcwd = path.getdirectory(_SCRIPT)\nos.chdir(newcwd)\nlocal a, b, c, d, e, f = builtin_dofile(_SCRIPT)\n_SCRIPT = oldfile\nos.chdir(oldcw" - "d)\nreturn a, b, c, d, e, f\nend\nfunction iif(expr, trueval, falseval)\nif (expr) then\nreturn trueval\nelse\nreturn falseval\nend\nend\nfunction include(fname)\nreturn dofile(fname .. \"/premake4.lua\")\nend\nfunction printf(msg, ...)\nprint(string.format(msg, unpack(arg)))\nend\nlocal builtin_type = type\nfunction type(t)\nlocal mt = getmetatable(t)\nif (mt) then\nif (mt.__type) then\nreturn mt.__type\nend\nend\nreturn builtin_type(t)\nend\n", - - /* base/action.lua */ - "premake.action = { }\npremake.action.list = { }\nfunction premake.action.add(a)\nlocal missing\nfor _, field in ipairs({\"description\", \"trigger\"}) do\nif (not a[field]) then\nmissing = field\nend\nend\nif (missing) then\nerror(\"action needs a \" .. missing, 3)\nend\npremake.action.list[a.trigger] = a\nend\nfunction premake.action.call(name)\nlocal a = premake.action.list[name]\nfor sln in premake.solution.each() do\nif a.onsolution then\na.onsolution(sln)\nend\nfor prj in premake.solution.eachproject(sln) do\nif a.onproject then\na.onproject(prj)\nend\nend\nend\nif a.execute then\na.execute()\nend\nend\nfunction premake.action.current()\nreturn premake.action.get(_ACTION)\nend\nfunction premake.action.get(name)\nreturn premake.action.list[name]\nend\nfunction premake.action.each()\nlocal keys = { }\nfor _, action in pairs(premake.action.list) do\ntable.insert(keys, action.trigger)\nend\ntable.sort(keys)\nlocal i = 0\nreturn function()\ni = i + 1\nreturn premake.action.list[keys[i]]\nend\nend\nfunction pre" - "make.action.set(name)\n_ACTION = name\nlocal action = premake.action.get(name)\nif action then\n_OS = action.os or _OS\nend\nend\nfunction premake.action.supports(action, feature)\nif not action then\nreturn false\nend\nif action.valid_languages then\nif table.contains(action.valid_languages, feature) then\nreturn true\nend\nend\nif action.valid_kinds then\nif table.contains(action.valid_kinds, feature) then\nreturn true\nend\nend\nreturn false\nend\n", - - /* base/option.lua */ - "premake.option = { }\npremake.option.list = { }\nfunction premake.option.add(opt)\nlocal missing\nfor _, field in ipairs({ \"description\", \"trigger\" }) do\nif (not opt[field]) then\nmissing = field\nend\nend\nif (missing) then\nerror(\"option needs a \" .. missing, 3)\nend\npremake.option.list[opt.trigger] = opt\nend\nfunction premake.option.get(name)\nreturn premake.option.list[name]\nend\nfunction premake.option.each()\nlocal keys = { }\nfor _, option in pairs(premake.option.list) do\ntable.insert(keys, option.trigger)\nend\ntable.sort(keys)\nlocal i = 0\nreturn function()\ni = i + 1\nreturn premake.option.list[keys[i]]\nend\nend\nfunction premake.option.validate(values)\nfor key, value in pairs(values) do\nlocal opt = premake.option.get(key)\nif (not opt) then\nreturn false, \"invalid option '\" .. key .. \"'\"\nend\nif (opt.value and value == \"\") then\nreturn false, \"no value specified for option '\" .. key .. \"'\"\nend\nif (opt.allowed) then\nfor _, match in ipairs(opt.allowed) do\nif (match[1] == " - "value) then return true end\nend\nreturn false, \"invalid value '\" .. value .. \"' for option '\" .. key .. \"'\"\nend\nend\nreturn true\nend\n", - - /* base/tree.lua */ - "premake.tree = { }\nlocal tree = premake.tree\nfunction premake.tree.new(n)\nlocal t = {\nname = n,\nchildren = { }\n}\nreturn t\nend\nfunction premake.tree.add(tr, p)\nif p == \".\" then\nreturn tr\nend\nlocal parentnode = tree.add(tr, path.getdirectory(p))\nlocal childname = path.getname(p)\nif childname == \"..\" then\nreturn parentnode\nend\nlocal childnode = parentnode.children[childname]\nif not childnode or childnode.path ~= p then\nchildnode = tree.insert(parentnode, tree.new(childname))\nchildnode.path = p\nend\nreturn childnode\nend\nfunction premake.tree.insert(parent, child)\ntable.insert(parent.children, child)\nif child.name then\nparent.children[child.name] = child\nend\nchild.parent = parent\nreturn child\nend\nfunction premake.tree.getlocalpath(node)\nif node.parent.path then\nreturn node.name\nelse\nreturn node.path\nend\nend\nfunction premake.tree.remove(node)\nlocal children = node.parent.children\nfor i = 1, #children do\nif children[i] == node then\ntable.remove(children, i)\nend\nend\nno" - "de.children = {}\nend\nfunction premake.tree.sort(tr)\ntree.traverse(tr, {\nonnode = function(node)\ntable.sort(node.children, function(a,b)\nreturn a.name < b.name\nend)\nend\n}, true)\nend\nfunction premake.tree.traverse(t, fn, includeroot)\nlocal donode, dochildren\ndonode = function(node, fn, depth)\nif node.isremoved then \nreturn \nend\nif fn.onnode then \nfn.onnode(node, depth) \nend\nif #node.children > 0 then\nif fn.onbranch then \nfn.onbranch(node, depth) \nend\ndochildren(node, fn, depth + 1)\nelse\nif fn.onleaf then \nfn.onleaf(node, depth) \nend\nend\nend\ndochildren = function(parent, fn, depth)\nlocal i = 1\nwhile i <= #parent.children do\nlocal node = parent.children[i]\ndonode(node, fn, depth)\nif node == parent.children[i] then\ni = i + 1\nend\nend\nend\nif includeroot then\ndonode(t, fn, 0)\nelse\ndochildren(t, fn, 0)\nend\nend\n", - - /* base/solution.lua */ - "premake.solution = { }\npremake.solution.list = { }\nfunction premake.solution.new(name)\nlocal sln = { }\ntable.insert(premake.solution.list, sln)\npremake.solution.list[name] = sln\nsetmetatable(sln, { __type=\"solution\" })\nsln.name = name\nsln.basedir = os.getcwd()\nsln.projects = { }\nsln.blocks = { }\nsln.configurations = { }\nreturn sln\nend\nfunction premake.solution.each()\nlocal i = 0\nreturn function ()\ni = i + 1\nif i <= #premake.solution.list then\nreturn premake.solution.list[i]\nend\nend\nend\nfunction premake.solution.eachproject(sln)\nlocal i = 0\nreturn function ()\ni = i + 1\nif (i <= #sln.projects) then\nreturn premake.solution.getproject(sln, i)\nend\nend\nend\nfunction premake.solution.get(key)\nreturn premake.solution.list[key]\nend\nfunction premake.solution.getproject(sln, idx)\nlocal prj = sln.projects[idx]\nlocal cfg = premake.getconfig(prj)\ncfg.name = prj.name\nreturn cfg\nend\n", - - /* base/project.lua */ - "premake.project = { }\nfunction premake.project.buildsourcetree(prj)\nlocal tr = premake.tree.new(prj.name)\nfor _, fname in ipairs(prj.files) do\nlocal node = premake.tree.add(tr, fname)\nend\npremake.tree.sort(tr)\ntr.project = prj\nreturn tr\nend\nfunction premake.eachconfig(prj, platform)\nif prj.project then prj = prj.project end\nlocal cfgs = prj.solution.configurations\nlocal i = 0\nreturn function ()\ni = i + 1\nif i <= #cfgs then\nreturn premake.getconfig(prj, cfgs[i], platform)\nend\nend\nend\nfunction premake.eachfile(prj)\nif not prj.project then prj = premake.getconfig(prj) end\nlocal i = 0\nlocal t = prj.files\nreturn function ()\ni = i + 1\nif (i <= #t) then\nreturn prj.__fileconfigs[t[i]]\nend\nend\nend\nfunction premake.esc(value)\nif (type(value) == \"table\") then\nlocal result = { }\nfor _,v in ipairs(value) do\ntable.insert(result, premake.esc(v))\nend\nreturn result\nelse\nvalue = value:gsub('&', \"&\")\nvalue = value:gsub('\"', \""\")\nvalue = value:gsub(\"'\", \"'\")\nv" - "alue = value:gsub('<', \"<\")\nvalue = value:gsub('>', \">\")\nvalue = value:gsub('\\r', \" \")\nvalue = value:gsub('\\n', \" \")\nreturn value\nend\nend\nfunction premake.filterplatforms(sln, map, default)\nlocal result = { }\nlocal keys = { }\nif sln.platforms then\nfor _, p in ipairs(sln.platforms) do\nif map[p] and not table.contains(keys, map[p]) then\ntable.insert(result, p)\ntable.insert(keys, map[p])\nend\nend\nend\nif #result == 0 and default then\ntable.insert(result, default)\nend\nreturn result\nend\nfunction premake.findproject(name)\nfor sln in premake.solution.each() do\nfor prj in premake.solution.eachproject(sln) do\nif (prj.name == name) then\nreturn prj\nend\nend\nend\nend\nfunction premake.findfile(prj, extension)\nfor _, fname in ipairs(prj.files) do\nif fname:endswith(extension) then return fname end\nend\nend\nfunction premake.getconfig(prj, cfgname, pltname)\nprj = prj.project or prj\nif pltname == \"Native\" or not table.contains(prj.solution.platforms or {}, pltname" - ") then\npltname = nil\nend\nlocal key = (cfgname or \"\")\nif pltname then key = key .. pltname end\nreturn prj.__configs[key]\nend\nfunction premake.getconfigname(cfgname, platform, useshortname)\nif cfgname then\nlocal name = cfgname\nif platform and platform ~= \"Native\" then\nif useshortname then\nname = name .. premake.platforms[platform].cfgsuffix\nelse\nname = name .. \"|\" .. platform\nend\nend\nreturn iif(useshortname, name:lower(), name)\nend\nend\nfunction premake.getdependencies(prj)\nprj = prj.project or prj\nlocal results = { }\nfor _, cfg in pairs(prj.__configs) do\nfor _, link in ipairs(cfg.links) do\nlocal dep = premake.findproject(link)\nif dep and not table.contains(results, dep) then\ntable.insert(results, dep)\nend\nend\nend\nreturn results\nend\nfunction premake.project.getfilename(prj, pattern)\nlocal fname = pattern:gsub(\"%%%%\", prj.name)\nfname = path.join(prj.location, fname)\nreturn path.getrelative(os.getcwd(), fname)\nend\n function premake.getlinks(cfg, kind, part)\nlocal resul" - "t = iif (part == \"directory\" and kind == \"all\", cfg.libdirs, {})\nlocal cfgname = iif(cfg.name == cfg.project.name, \"\", cfg.name)\nlocal pathstyle = premake.getpathstyle(cfg)\nlocal namestyle = premake.getnamestyle(cfg)\nlocal function canlink(source, target)\nif (kind == \"static\" and target.kind ~= \"StaticLib\") then\nreturn false\nelseif (target.kind ~= \"SharedLib\" and target.kind ~= \"StaticLib\") then \nreturn false\nend\nif premake.iscppproject(source) then\nreturn premake.iscppproject(target)\nelseif premake.isdotnetproject(source) then\nreturn premake.isdotnetproject(target)\nend\nend\nfor _, link in ipairs(cfg.links) do\nlocal item\nlocal prj = premake.findproject(link)\nif prj and kind ~= \"system\" then\nlocal prjcfg = premake.getconfig(prj, cfgname, cfg.platform)\nif kind == \"dependencies\" or canlink(cfg, prjcfg) then\nif (part == \"directory\") then\nitem = path.rebase(prjcfg.linktarget.directory, prjcfg.location, cfg.location)\nelseif (part == \"basename\") then\nitem = prjcfg.linktar" - "get.basename\nelseif (part == \"fullpath\") then\nitem = path.rebase(prjcfg.linktarget.fullpath, prjcfg.location, cfg.location)\nelseif (part == \"object\") then\nitem = prjcfg\nend\nend\nelseif not prj and (kind == \"system\" or kind == \"all\") then\nif (part == \"directory\") then\nlocal dir = path.getdirectory(link)\nif (dir ~= \".\") then\nitem = dir\nend\nelseif (part == \"fullpath\") then\nitem = link\nif namestyle == \"windows\" then\nif premake.iscppproject(cfg) then\nitem = item .. \".lib\"\nelseif premake.isdotnetproject(cfg) then\nitem = item .. \".dll\"\nend\nend\nif item:find(\"/\", nil, true) then\nitem = path.getrelative(cfg.basedir, item)\nend\nelse\nitem = link\nend\nend\nif item then\nif pathstyle == \"windows\" and part ~= \"object\" then\nitem = path.translate(item, \"\\\\\")\nend\nif not table.contains(result, item) then\ntable.insert(result, item)\nend\nend\nend\nreturn result\nend\nfunction premake.getnamestyle(cfg)\nreturn premake.platforms[cfg.platform].namestyle or premake.gettool(cf" - "g).namestyle or \"posix\"\nend\nfunction premake.getpathstyle(cfg)\nif premake.action.current().os == \"windows\" then\nreturn \"windows\"\nelse\nreturn \"posix\"\nend\nend\nfunction premake.gettarget(cfg, direction, pathstyle, namestyle, system)\nif system == \"bsd\" or system == \"solaris\" then \nsystem = \"linux\" \nend\nlocal kind = cfg.kind\nif premake.iscppproject(cfg) then\nif (namestyle == \"windows\" or system == \"windows\") and kind == \"SharedLib\" and direction == \"link\" then\nkind = \"StaticLib\"\nend\nif namestyle == \"posix\" and system == \"windows\" and kind ~= \"StaticLib\" then\nnamestyle = \"windows\"\nend\nend\nlocal field = iif(direction == \"build\", \"target\", \"implib\")\nlocal name = cfg[field..\"name\"] or cfg.targetname or cfg.project.name\nlocal dir = cfg[field..\"dir\"] or cfg.targetdir or path.getrelative(cfg.location, cfg.basedir)\nlocal prefix = \"\"\nlocal suffix = \"\"\nlocal ext = \"\"\nlocal bundlepath, bundlename\nif namestyle == \"windows\" then\nif ki" - "nd == \"ConsoleApp\" or kind == \"WindowedApp\" then\next = \".exe\"\nelseif kind == \"SharedLib\" then\next = \".dll\"\nelseif kind == \"StaticLib\" then\next = \".lib\"\nend\nelseif namestyle == \"posix\" then\nif kind == \"WindowedApp\" and system == \"macosx\" then\nbundlename = name .. \".app\"\nbundlepath = path.join(dir, bundlename)\ndir = path.join(bundlepath, \"Contents/MacOS\")\nelseif kind == \"SharedLib\" then\nprefix = \"lib\"\next = iif(system == \"macosx\", \".dylib\", \".so\")\nelseif kind == \"StaticLib\" then\nprefix = \"lib\"\next = \".a\"\nend\nelseif namestyle == \"PS3\" then\nif kind == \"ConsoleApp\" or kind == \"WindowedApp\" then\next = \".elf\"\nelseif kind == \"StaticLib\" then\nprefix = \"lib\"\next = \".a\"\nend\nend\nprefix = cfg[field..\"prefix\"] or cfg.targetprefix or prefix\nsuffix = cfg[field..\"suffix\"] or cfg.targetsuffix or suffix\next = cfg[field..\"extension\"] or cfg.targetextension or ext\nlocal result = { }\nresult.basename = name .. suffix\nresult.name = " - "prefix .. name .. suffix .. ext\nresult.directory = dir\nresult.prefix = prefix\nresult.suffix = suffix\nresult.fullpath = path.join(result.directory, result.name)\nresult.bundlepath = bundlepath or result.fullpath\nif pathstyle == \"windows\" then\nresult.directory = path.translate(result.directory, \"\\\\\")\nresult.fullpath = path.translate(result.fullpath, \"\\\\\")\nend\nreturn result\nend\nfunction premake.gettool(cfg)\nif premake.iscppproject(cfg) then\nif _OPTIONS.cc then\nreturn premake[_OPTIONS.cc]\nend\nlocal action = premake.action.current()\nif action.valid_tools then\nreturn premake[action.valid_tools.cc[1]]\nend\nreturn premake.gcc\nelse\nreturn premake.dotnet\nend\nend\nfunction premake.hascppproject(sln)\nfor prj in premake.solution.eachproject(sln) do\nif premake.iscppproject(prj) then\nreturn true\nend\nend\nend\nfunction premake.hasdotnetproject(sln)\nfor prj in premake.solution.eachproject(sln) do\nif premake.isdotnetproject(prj) then\nreturn true\nend\nend\nend\nfunction prem" - "ake.iscppproject(prj)\nreturn (prj.language == \"C\" or prj.language == \"C++\")\nend\nfunction premake.isdotnetproject(prj)\nreturn (prj.language == \"C#\")\nend\nlocal function walksources(cfg, fn, group, nestlevel, finished)\nlocal grouplen = group:len()\nlocal gname = iif(group:endswith(\"/\"), group:sub(1, -2), group)\nif (nestlevel >= 0) then\nfn(cfg, gname, \"GroupStart\", nestlevel)\nend\nfor _,fname in ipairs(cfg.files) do\nif (fname:startswith(group)) then\nlocal _,split = fname:find(\"[^\\.]/\", grouplen + 1)\nif (split) then\nlocal subgroup = fname:sub(1, split)\nif (not finished[subgroup]) then\nfinished[subgroup] = true\nwalksources(cfg, fn, subgroup, nestlevel + 1, finished)\nend\nend\nend\nend\nfor _,fname in ipairs(cfg.files) do\nif (fname:startswith(group) and not fname:find(\"[^\\.]/\", grouplen + 1)) then\nfn(cfg, fname, \"GroupItem\", nestlevel + 1)\nend\nend\nif (nestlevel >= 0) then\nfn(cfg, gname, \"GroupEnd\", nestlevel)\nend\nend\nfunction premake.walksources(cfg, fn)\nwalksources(cfg" - ", fn, \"\", -1, {})\nend\n", - - /* base/configs.lua */ - "premake.config = { }\nfunction premake.config.isdebugbuild(cfg)\nif cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed then\nreturn false\nend\nif not cfg.flags.Symbols then\nreturn false\nend\nreturn true\nend\nlocal nocopy = \n{\nblocks = true,\nkeywords = true,\nprojects = true,\n__configs = true,\n}\nlocal nofixup =\n{\nbasedir = true,\nlocation = true,\n}\nfunction premake.getactiveterms()\nlocal terms = { _ACTION:lower(), os.get() }\nfor key, value in pairs(_OPTIONS) do\nif value ~= \"\" then\ntable.insert(terms, value:lower())\nelse\ntable.insert(terms, key:lower())\nend\nend\nreturn terms\nend\nfunction premake.iskeywordmatch(keyword, terms)\nif keyword:startswith(\"not \") then\nreturn not premake.iskeywordmatch(keyword:sub(5), terms)\nend\nfor _, pattern in ipairs(keyword:explode(\" or \")) do\nfor termkey, term in pairs(terms) do\nif term:match(pattern) == term then\nreturn termkey\nend\nend\nend\nend\nfunction premake.iskeywordsmatch(keywords, terms)\nlocal hasrequired = " - "false\nfor _, keyword in ipairs(keywords) do\nlocal matched = premake.iskeywordmatch(keyword, terms)\nif not matched then\nreturn false\nend\nif matched == \"required\" then\nhasrequired = true\nend\nend\nif terms.required and not hasrequired then\nreturn false\nelse\nreturn true\nend\nend\nlocal function adjustpaths(location, obj)\nfor name, value in pairs(obj) do\nlocal field = premake.fields[name]\nif field and value and not nofixup[name] then\nif field.kind == \"path\" then\nobj[name] = path.getrelative(location, value) \nelseif field.kind == \"dirlist\" or field.kind == \"filelist\" then\nfor i, p in ipairs(value) do\nvalue[i] = path.getrelative(location, p) \nend\nend\nend\nend\nend\nlocal function mergeobject(dest, src)\nif not src then return end\nfor field, value in pairs(src) do\nif not nocopy[field] then\nif type(value) == \"table\" then\nlocal tbl = dest[field] or { }\nfor _, item in ipairs(value) do\nif not tbl[item] then\ntable.insert(tbl, item)\ntbl[item] = item\nend\nend\ndest[field] = tbl\nels" - "e\ndest[field] = value\nend\nend\nend\nend\nlocal function merge(dest, obj, basis, terms, cfgname, pltname)\nlocal key = cfgname or \"\"\npltname = pltname or \"Native\"\nif pltname ~= \"Native\" then\nkey = key .. pltname\nend\nterms.config = (cfgname or \"\"):lower()\nterms.platform = pltname:lower()\nlocal cfg = {}\nmergeobject(cfg, basis[key])\nadjustpaths(obj.location, cfg)\nmergeobject(cfg, obj)\nif (cfg.kind) then \nterms.kind = cfg.kind:lower()\nend\nfor _, blk in ipairs(obj.blocks) do\nif (premake.iskeywordsmatch(blk.keywords, terms)) then\nmergeobject(cfg, blk)\nend\nend\ncfg.name = cfgname\ncfg.platform = pltname\ncfg.terms = terms\ndest[key] = cfg\nend\nlocal function collapse(obj, basis)\nlocal result = {}\nbasis = basis or {}\nlocal sln = obj.solution or obj\nlocal terms = premake.getactiveterms()\nmerge(result, obj, basis, terms)\nfor _, cfgname in ipairs(sln.configurations) do\nmerge(result, obj, basis, terms, cfgname, \"Native\")\nfor _, pltname in ipairs(sln.platforms or {}) do\nif " - "pltname ~= \"Native\" then\nmerge(result, obj, basis, terms, cfgname, pltname)\nend\nend\nend\nreturn result\nend\nlocal function postprocess(prj, cfg)\ncfg.project = prj\ncfg.shortname = premake.getconfigname(cfg.name, cfg.platform, true)\ncfg.longname = premake.getconfigname(cfg.name, cfg.platform)\ncfg.location = cfg.location or cfg.basedir\nlocal platform = premake.platforms[cfg.platform]\nif platform.iscrosscompiler then\ncfg.system = cfg.platform\nelse\ncfg.system = os.get()\nend\nif cfg.kind == \"SharedLib\" and platform.nosharedlibs then\ncfg.kind = \"StaticLib\"\nend\nlocal files = { }\nfor _, fname in ipairs(cfg.files) do\nlocal excluded = false\nfor _, exclude in ipairs(cfg.excludes) do\nexcluded = (fname == exclude)\nif (excluded) then break end\nend\nif (not excluded) then\ntable.insert(files, fname)\nend\nend\ncfg.files = files\nfor name, field in pairs(premake.fields) do\nif field.isflags then\nlocal values = cfg[name]\nfor _, flag in ipairs(values) do values[flag] = true end\nend\nend\ncfg._" - "_fileconfigs = { }\nfor _, fname in ipairs(cfg.files) do\ncfg.terms.required = fname:lower()\nlocal fcfg = {}\nfor _, blk in ipairs(cfg.project.blocks) do\nif (premake.iskeywordsmatch(blk.keywords, cfg.terms)) then\nmergeobject(fcfg, blk)\nend\nend\nfcfg.name = fname\ncfg.__fileconfigs[fname] = fcfg\ntable.insert(cfg.__fileconfigs, fcfg)\nend\nend\nlocal function builduniquedirs()\nlocal num_variations = 4\nlocal cfg_dirs = {}\nlocal hit_counts = {}\nfor sln in premake.solution.each() do\nfor _, prj in ipairs(sln.projects) do\nfor _, cfg in pairs(prj.__configs) do\nlocal dirs = { }\ndirs[1] = path.getabsolute(path.join(cfg.location, cfg.objdir or cfg.project.objdir or \"obj\"))\ndirs[2] = path.join(dirs[1], iif(cfg.platform == \"Native\", \"\", cfg.platform))\ndirs[3] = path.join(dirs[2], cfg.name)\ndirs[4] = path.join(dirs[3], cfg.project.name)\ncfg_dirs[cfg] = dirs\nlocal start = iif(cfg.name, 2, 1)\nfor v = start, num_variations do\nlocal d = dirs[v]\nhit_counts[d] = (hit_counts[d] or 0) + 1\nend\nend\nend" - "\nend\nfor sln in premake.solution.each() do\nfor _, prj in ipairs(sln.projects) do\nfor _, cfg in pairs(prj.__configs) do\nlocal dir\nlocal start = iif(cfg.name, 2, 1)\nfor v = start, num_variations do\ndir = cfg_dirs[cfg][v]\nif hit_counts[dir] == 1 then break end\nend\ncfg.objectsdir = path.getrelative(cfg.location, dir)\nend\nend\nend\nend\nlocal function buildtargets()\nfor sln in premake.solution.each() do\nfor _, prj in ipairs(sln.projects) do\nfor _, cfg in pairs(prj.__configs) do\nlocal pathstyle = premake.getpathstyle(cfg)\nlocal namestyle = premake.getnamestyle(cfg)\ncfg.buildtarget = premake.gettarget(cfg, \"build\", pathstyle, namestyle, cfg.system)\ncfg.linktarget = premake.gettarget(cfg, \"link\", pathstyle, namestyle, cfg.system)\nif pathstyle == \"windows\" then\ncfg.objectsdir = path.translate(cfg.objectsdir, \"\\\\\")\nend\nend\nend\nend\nend\nfunction premake.buildconfigs()\nfor sln in premake.solution.each() do\nfor _, prj in ipairs(sln.projects) do\nprj.location = prj.location or sln.lo" - "cation or prj.basedir\nadjustpaths(prj.location, prj)\nfor _, blk in ipairs(prj.blocks) do\nadjustpaths(prj.location, blk)\nend\nend\nsln.location = sln.location or sln.basedir\nend\nfor sln in premake.solution.each() do\nlocal basis = collapse(sln)\nfor _, prj in ipairs(sln.projects) do\nprj.__configs = collapse(prj, basis)\nfor _, cfg in pairs(prj.__configs) do\npostprocess(prj, cfg)\nend\nend\nend\nbuilduniquedirs()\nbuildtargets(cfg)\nend\n", - - /* base/api.lua */ - "premake.fields = \n{\nbasedir =\n{\nkind = \"path\",\nscope = \"container\",\n},\nbuildaction =\n{\nkind = \"string\",\nscope = \"config\",\nallowed = {\n\"Compile\",\n\"Copy\",\n\"Embed\",\n\"None\"\n}\n},\nbuildoptions =\n{\nkind = \"list\",\nscope = \"config\",\n},\nconfigurations = \n{\nkind = \"list\",\nscope = \"solution\",\n},\ncxxtesthdrfiles =\n{\nkind = \"filelist\",\nscope = \"config\",\n},\ncxxtestsrcfiles = \n{\nkind = \"filelist\",\nscope = \"config\",\n},\ncxxtestoptions =\n{\nkind = \"string\",\nscope = \"config\",\n},\ncxxtestpath =\n{\nkind = \"path\",\nscope = \"solution\", \n},\ncxxtestrootfile = \n{\nkind = \"path\",\nscope = \"config\",\n},\ncxxtestrootoptions =\n{\nkind = \"string\",\nscope = \"config\",\n},\ndefines =\n{\nkind = \"list\",\nscope = \"config\",\n},\ndeploymentoptions =\n{\nkind = \"list\",\nscope = \"config\",\n},\nexcludes =\n{\nkind = \"filelist\",\nscope = \"config\",\n},\nfiles =\n{\nkind = \"filelist\",\nscope = \"config\",\n},\nflags =\n{\nkind = \"lis" - "t\",\nscope = \"config\",\nisflags = true,\nallowed = {\n\"EnableSSE\",\n\"EnableSSE2\",\n\"ExtraWarnings\",\n\"FatalWarnings\",\n\"FloatFast\",\n\"FloatStrict\",\n\"Managed\",\n\"MFC\",\n\"NativeWChar\",\n\"No64BitChecks\",\n\"NoDebugHeap\",\n\"NoEditAndContinue\",\n\"NoExceptions\",\n\"NoFramePointer\",\n\"NoImportLib\",\n\"NoManifest\",\n\"NoMinimalRebuild\",\n\"NoNativeWChar\",\n\"NoPCH\",\n\"NoRTTI\",\n\"Optimize\",\n\"OptimizeSize\",\n\"OptimizeSpeed\",\n\"SEH\",\n\"StaticRuntime\",\n\"Symbols\",\n\"Unicode\",\n\"Unsafe\",\n\"WinMain\"\n}\n},\nframework =\n{\nkind = \"string\",\nscope = \"container\",\nallowed = {\n\"1.0\",\n\"1.1\",\n\"2.0\",\n\"3.0\",\n\"3.5\",\n\"4.0\"\n}\n},\ngnuexternals =\n{\nkind = \"list\",\nscope = \"config\",\n},\nimagepath = \n{\nkind = \"path\",\nscope = \"config\",\n},\nimageoptions =\n{\nkind = \"list\",\nscope = \"config\",\n},\nimplibdir =\n{\nkind = \"path\",\nscope = \"config\",\n},\nimplibextension =\n{\nkind = \"string\",\nscope = \"config\",\n},\nimplibname =\n{" - "\nkind = \"string\",\nscope = \"config\",\n},\nimplibprefix =\n{\nkind = \"string\",\nscope = \"config\",\n},\nimplibsuffix =\n{\nkind = \"string\",\nscope = \"config\",\n},\nincludedirs =\n{\nkind = \"dirlist\",\nscope = \"config\",\n},\nkind =\n{\nkind = \"string\",\nscope = \"config\",\nallowed = {\n\"ConsoleApp\",\n\"WindowedApp\",\n\"StaticLib\",\n\"SharedLib\"\n}\n},\nlanguage =\n{\nkind = \"string\",\nscope = \"container\",\nallowed = {\n\"C\",\n\"C++\",\n\"C#\"\n}\n},\nlibdirs =\n{\nkind = \"dirlist\",\nscope = \"config\",\n},\nlinkoptions =\n{\nkind = \"list\",\nscope = \"config\",\n},\nlinks =\n{\nkind = \"list\",\nscope = \"config\",\nallowed = function(value)\nif value:find('/', nil, true) then\nvalue = path.getabsolute(value)\nend\nreturn value\nend\n},\nlocation =\n{\nkind = \"path\",\nscope = \"container\",\n},\nnasmformat =\n{\nkind = \"string\",\nscope = \"solution\",\n},\nnasmpath =\n{\nkind = \"path\",\nscope = \"solution\"\n},\nobjdir =\n{\nkind = \"path\",\nscope = \"config\"," - "\n},\npchheader =\n{\nkind = \"path\",\nscope = \"config\",\n},\npchsource =\n{\nkind = \"path\",\nscope = \"config\",\n},\nplatforms = \n{\nkind = \"list\",\nscope = \"solution\",\nallowed = table.keys(premake.platforms),\n},\npostbuildcommands =\n{\nkind = \"list\",\nscope = \"config\",\n},\nprebuildcommands =\n{\nkind = \"list\",\nscope = \"config\",\n},\nprelinkcommands =\n{\nkind = \"list\",\nscope = \"config\",\n},\nresdefines =\n{\nkind = \"list\",\nscope = \"config\",\n},\nresincludedirs =\n{\nkind = \"dirlist\",\nscope = \"config\",\n},\nresoptions =\n{\nkind = \"list\",\nscope = \"config\",\n},\ntargetdir =\n{\nkind = \"path\",\nscope = \"config\",\n},\ntargetextension =\n{\nkind = \"string\",\nscope = \"config\",\n},\ntargetname =\n{\nkind = \"string\",\nscope = \"config\",\n},\ntargetprefix =\n{\nkind = \"string\",\nscope = \"config\",\n},\ntargetsuffix =\n{\nkind = \"string\",\nscope = \"config\",\n},\ntrimpaths =\n{\nkind = \"dirlist\",\nscope = \"config\",\n},\nuuid =\n{\nkind = " - "\"string\",\nscope = \"container\",\nallowed = function(value)\nlocal ok = true\nif (#value ~= 36) then ok = false end\nfor i=1,36 do\nlocal ch = value:sub(i,i)\nif (not ch:find(\"[ABCDEFabcdef0123456789-]\")) then ok = false end\nend\nif (value:sub(9,9) ~= \"-\") then ok = false end\nif (value:sub(14,14) ~= \"-\") then ok = false end\nif (value:sub(19,19) ~= \"-\") then ok = false end\nif (value:sub(24,24) ~= \"-\") then ok = false end\nif (not ok) then\nreturn nil, \"invalid UUID\"\nend\nreturn value:upper()\nend\n},\n}\nfunction premake.checkvalue(value, allowed)\nif (allowed) then\nif (type(allowed) == \"function\") then\nreturn allowed(value)\nelse\nfor _,v in ipairs(allowed) do\nif (value:lower() == v:lower()) then\nreturn v\nend\nend\nreturn nil, \"invalid value '\" .. value .. \"'\"\nend\nelse\nreturn value\nend\nend\nfunction premake.getobject(t)\nlocal container\nif (t == \"container\" or t == \"solution\") then\ncontainer = premake.CurrentContainer\nelse\ncontainer = premake.CurrentConfiguration\n" - "end\nif t == \"solution\" then\nif type(container) == \"project\" then\ncontainer = container.solution\nend\nif type(container) ~= \"solution\" then\ncontainer = nil\nend\nend\nlocal msg\nif (not container) then\nif (t == \"container\") then\nmsg = \"no active solution or project\"\nelseif (t == \"solution\") then\nmsg = \"no active solution\"\nelse\nmsg = \"no active solution, project, or configuration\"\nend\nend\nreturn container, msg\nend\nfunction premake.setarray(ctype, fieldname, value, allowed)\nlocal container, err = premake.getobject(ctype)\nif (not container) then\nerror(err, 4)\nend\nif (not container[fieldname]) then\ncontainer[fieldname] = { }\nend\nlocal function doinsert(value, depth)\nif (type(value) == \"table\") then\nfor _,v in ipairs(value) do\ndoinsert(v, depth + 1)\nend\nelse\nvalue, err = premake.checkvalue(value, allowed)\nif (not value) then\nerror(err, depth)\nend\ntable.insert(container[fieldname], value)\nend\nend\nif (value) then\ndoinsert(value, 5)\nend\nreturn container[fieldnam" - "e]\nend\nlocal function domatchedarray(ctype, fieldname, value, matchfunc)\nlocal result = { }\nfunction makeabsolute(value, depth)\nif (type(value) == \"table\") then\nfor _, item in ipairs(value) do\nmakeabsolute(item, depth + 1)\nend\nelseif type(value) == \"string\" then\nif value:find(\"*\") then\nmakeabsolute(matchfunc(value), depth + 1)\nelse\ntable.insert(result, path.getabsolute(value))\nend\nelse\nerror(\"Invalid value in list: expected string, got \" .. type(value), depth)\nend\nend\nmakeabsolute(value, 3)\nreturn premake.setarray(ctype, fieldname, result)\nend\nfunction premake.setdirarray(ctype, fieldname, value)\nreturn domatchedarray(ctype, fieldname, value, os.matchdirs)\nend\nfunction premake.setfilearray(ctype, fieldname, value)\nreturn domatchedarray(ctype, fieldname, value, os.matchfiles)\nend\nfunction premake.setstring(ctype, fieldname, value, allowed)\nlocal container, err = premake.getobject(ctype)\nif (not container) then\nerror(err, 4)\nend\nif (value) then\nvalue, err = premake.check" - "value(value, allowed)\nif (not value) then \nerror(err, 4)\nend\ncontainer[fieldname] = value\nend\nreturn container[fieldname]\nend\nlocal function accessor(name, value)\nlocal kind = premake.fields[name].kind\nlocal scope = premake.fields[name].scope\nlocal allowed = premake.fields[name].allowed\nif ((kind == \"string\" or kind == \"path\") and value) then\nif type(value) ~= \"string\" then\nerror(\"string value expected\", 3)\nend\nend\nif (kind == \"string\") then\nreturn premake.setstring(scope, name, value, allowed)\nelseif (kind == \"path\") then\nif value then value = path.getabsolute(value) end\nreturn premake.setstring(scope, name, value)\nelseif (kind == \"list\") then\nreturn premake.setarray(scope, name, value, allowed)\nelseif (kind == \"dirlist\") then\nreturn premake.setdirarray(scope, name, value)\nelseif (kind == \"filelist\") then\nreturn premake.setfilearray(scope, name, value)\nend\nend\nfor name,_ in pairs(premake.fields) do\n_G[name] = function(value)\nreturn accessor(name, value)\n" - "end\nend\nfunction configuration(terms)\nif not terms then\nreturn premake.CurrentConfiguration\nend\nlocal container, err = premake.getobject(\"container\")\nif (not container) then\nerror(err, 2)\nend\nlocal cfg = { }\ncfg.terms = table.flatten({terms})\ntable.insert(container.blocks, cfg)\npremake.CurrentConfiguration = cfg\ncfg.keywords = { }\nfor _, word in ipairs(cfg.terms) do\ntable.insert(cfg.keywords, path.wildcards(word):lower())\nend\nfor name, field in pairs(premake.fields) do\nif (field.kind ~= \"string\" and field.kind ~= \"path\") then\ncfg[name] = { }\nend\nend\nreturn cfg\nend\nfunction project(name)\nif not name then\nreturn iif(type(premake.CurrentContainer) == \"project\", premake.CurrentContainer, nil)\nend\nlocal sln\nif (type(premake.CurrentContainer) == \"project\") then\nsln = premake.CurrentContainer.solution\nelse\nsln = premake.CurrentContainer\nend\nif (type(sln) ~= \"solution\") then\nerror(\"no active solution\", 2)\nend\npremake.CurrentContainer = sln.projects[name]\nif (not pre" - "make.CurrentContainer) then\nlocal prj = { }\npremake.CurrentContainer = prj\ntable.insert(sln.projects, prj)\nsln.projects[name] = prj\nsetmetatable(prj, {\n__type = \"project\",\n})\nprj.solution = sln\nprj.name = name\nprj.basedir = os.getcwd()\nprj.uuid = os.uuid()\nprj.blocks = { }\nend\nconfiguration { }\nreturn premake.CurrentContainer\nend\nfunction solution(name)\nif not name then\nif type(premake.CurrentContainer) == \"project\" then\nreturn premake.CurrentContainer.solution\nelse\nreturn premake.CurrentContainer\nend\nend\npremake.CurrentContainer = premake.solution.get(name)\nif (not premake.CurrentContainer) then\npremake.CurrentContainer = premake.solution.new(name)\nend\nconfiguration { }\nreturn premake.CurrentContainer\nend\nfunction newaction(a)\npremake.action.add(a)\nend\nfunction newoption(opt)\npremake.option.add(opt)\nend\n", - - /* base/cmdline.lua */ - "newoption \n{\ntrigger = \"cc\",\nvalue = \"VALUE\",\ndescription = \"Choose a C/C++ compiler set\",\nallowed = {\n{ \"gcc\", \"GNU GCC (gcc/g++)\" },\n{ \"ow\", \"OpenWatcom\" },\n}\n}\nnewoption\n{\ntrigger = \"dotnet\",\nvalue = \"VALUE\",\ndescription = \"Choose a .NET compiler set\",\nallowed = {\n{ \"msnet\", \"Microsoft .NET (csc)\" },\n{ \"mono\", \"Novell Mono (mcs)\" },\n{ \"pnet\", \"Portable.NET (cscc)\" },\n}\n}\nnewoption\n{\ntrigger = \"file\",\nvalue = \"FILE\",\ndescription = \"Read FILE as a Premake script; default is 'premake4.lua'\"\n}\nnewoption\n{\ntrigger = \"help\",\ndescription = \"Display this information\"\n}\nnewoption\n{\ntrigger = \"os\",\nvalue = \"VALUE\",\ndescription = \"Generate files for a different operating system\",\nallowed = {\n{ \"bsd\", \"OpenBSD, NetBSD, or FreeBSD\" },\n{ \"linux\", \"Linux\" },\n{ \"macosx\", \"Apple Mac OS X\" },\n{ \"solaris\", \"Solaris\" },\n{ \"windows\", \"Microsoft W" - "indows\" },\n}\n}\nnewoption\n{\ntrigger = \"platform\",\nvalue = \"VALUE\",\ndescription = \"Add target architecture (if supported by action)\",\nallowed = {\n{ \"x32\", \"32-bit\" },\n{ \"x64\", \"64-bit\" },\n{ \"universal\", \"Mac OS X Universal, 32- and 64-bit\" },\n{ \"universal32\", \"Mac OS X Universal, 32-bit only\" },\n{ \"universal64\", \"Mac OS X Universal, 64-bit only\" },\n{ \"ps3\", \"Playstation 3 (experimental)\" },\n{ \"xbox360\", \"Xbox 360 (experimental)\" },\n}\n}\nnewoption\n{\ntrigger = \"scripts\",\nvalue = \"path\",\ndescription = \"Search for additional scripts on the given path\"\n}\nnewoption\n{\ntrigger = \"version\",\ndescription = \"Display version information\"\n}\n", - - /* tools/dotnet.lua */ - "premake.dotnet = { }\npremake.dotnet.namestyle = \"windows\"\nlocal flags =\n{\nFatalWarning = \"/warnaserror\",\nOptimize = \"/optimize\",\nOptimizeSize = \"/optimize\",\nOptimizeSpeed = \"/optimize\",\nSymbols = \"/debug\",\nUnsafe = \"/unsafe\"\n}\nfunction premake.dotnet.getbuildaction(fcfg)\nlocal ext = path.getextension(fcfg.name):lower()\nif fcfg.buildaction == \"Compile\" or ext == \".cs\" then\nreturn \"Compile\"\nelseif fcfg.buildaction == \"Embed\" or ext == \".resx\" then\nreturn \"EmbeddedResource\"\nelseif fcfg.buildaction == \"Copy\" or ext == \".asax\" or ext == \".aspx\" then\nreturn \"Content\"\nelse\nreturn \"None\"\nend\nend\nfunction premake.dotnet.getcompilervar(cfg)\nif (_OPTIONS.dotnet == \"msnet\") then\nreturn \"csc\"\nelseif (_OPTIONS.dotnet == \"mono\") then\nif (cfg.framework <= \"1.1\") then\nreturn \"mcs\"\nelseif (cfg.framework >= \"4.0\") then\nreturn \"dmcs\"\nelse \nreturn \"gmcs\"\nend\nelse\nreturn \"cscc\"\nend\nend\nfunction premake.dotnet.getfla" - "gs(cfg)\nlocal result = table.translate(cfg.flags, flags)\nreturn result\nend\nfunction premake.dotnet.getkind(cfg)\nif (cfg.kind == \"ConsoleApp\") then\nreturn \"Exe\"\nelseif (cfg.kind == \"WindowedApp\") then\nreturn \"WinExe\"\nelseif (cfg.kind == \"SharedLib\") then\nreturn \"Library\"\nend\nend", - - /* tools/gcc.lua */ - "premake.gcc = { }\npremake.gcc.cc = \"gcc\"\npremake.gcc.cxx = \"g++\"\npremake.gcc.ar = \"ar\"\nlocal cflags =\n{\nEnableSSE = \"-msse\",\nEnableSSE2 = \"-msse2\",\nExtraWarnings = \"-Wall\",\nFatalWarnings = \"-Werror\",\nFloatFast = \"-ffast-math\",\nFloatStrict = \"-ffloat-store\",\nNoFramePointer = \"-fomit-frame-pointer\",\nOptimize = \"-O2\",\nOptimizeSize = \"-Os\",\nOptimizeSpeed = \"-O3\",\nSymbols = \"-g\",\n}\nlocal cxxflags =\n{\nEnableSSE = \"-msse\",\nEnableSSE2 = \"-msse2\",\nExtraWarnings = \"-Wall\",\nFatalWarnings = \"-Werror\",\nFloatFast = \"-ffast-math\",\nFloatStrict = \"-ffloat-store\",\nNoFramePointer = \"-fomit-frame-pointer\",\nOptimize = \"-O2\",\nOptimizeSize = \"-Os\",\nOptimizeSpeed = \"-O3\",\nSymbols = \"-g\",\nNoExceptions = \"-fno-exceptions\",\nNoRTTI = \"-fno-rtti\",\n}\npremake.gcc.platforms = \n{\nNative = { \ncppflags = \"-MMD -MP\",\n},\nx32 = { \ncppflags = \"-MMD -MP\",\nflags " - " = \"-m32\",\nldflags = \"-L/usr/lib32\", \n},\nx64 = { \ncppflags = \"-MMD -MP\",\nflags = \"-m64\",\nldflags = \"-L/usr/lib64\",\n},\nUniversal = { \ncppflags = \"\",\nflags = \"-arch i386 -arch x86_64 -arch ppc -arch ppc64\",\n},\nUniversal32 = { \ncppflags = \"\",\nflags = \"-arch i386 -arch ppc\",\n},\nUniversal64 = { \ncppflags = \"\",\nflags = \"-arch x86_64 -arch ppc64\",\n},\nPS3 = {\ncc = \"ppu-lv2-g++\",\ncxx = \"ppu-lv2-g++\",\nar = \"ppu-lv2-ar\",\ncppflags = \"-MMD -MP\",\n}\n}\nlocal platforms = premake.gcc.platforms\nfunction premake.gcc.getcppflags(cfg)\nlocal result = { }\ntable.insert(result, platforms[cfg.platform].cppflags)\nreturn result\nend\nfunction premake.gcc.getcflags(cfg)\nlocal result = table.translate(cfg.flags, cflags)\ntable.insert(result, platforms[cfg.platform].flags)\nif cfg.system ~= \"windows\" and cfg.kind == \"SharedLib\" then\ntable.insert(result, \"-fPIC\")\nend\nreturn result\nend\nfunction premake.gcc.getcxxflags(cfg)\nlocal re" - "sult = table.translate(cfg.flags, cxxflags)\nif cfg.system ~= \"windows\" and cfg.kind == \"SharedLib\" then\ntable.insert(result, \"-fPIC\")\nend\nreturn result\nend\nfunction premake.gcc.getldflags(cfg)\nlocal result = { }\nif not cfg.flags.Symbols then\nif cfg.system == \"macosx\" then\ntable.insert(result, \"-Wl,-x\")\nelse\ntable.insert(result, \"-s\")\nend\nend\nif cfg.kind == \"SharedLib\" then\nif cfg.system == \"macosx\" then\nresult = table.join(result, { \"-dynamiclib\", \"-flat_namespace\" })\nelse\ntable.insert(result, \"-shared\")\nend\nif cfg.system == \"windows\" and not cfg.flags.NoImportLib then\ntable.insert(result, '-Wl,--out-implib=\"' .. cfg.linktarget.fullpath .. '\"')\nend\nend\nif cfg.kind == \"WindowedApp\" and cfg.system == \"windows\" then\ntable.insert(result, \"-mwindows\")\nend\nlocal platform = platforms[cfg.platform]\ntable.insert(result, platform.flags)\ntable.insert(result, platform.ldflags)\nreturn result\nend\nfunction premake.gcc.getlibdirflags(cfg)\nlocal result = { }\nfo" - "r _, value in ipairs(premake.getlinks(cfg, \"all\", \"directory\")) do\ntable.insert(result, '-L' .. _MAKE.esc(value))\nend\nreturn result\nend\nfunction premake.gcc.getlinkflags(cfg)\nlocal result = { }\nfor _, value in ipairs(premake.getlinks(cfg, \"all\", \"basename\")) do\nif path.getextension(value) == \".framework\" then\ntable.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value)))\nelse\ntable.insert(result, '-l' .. _MAKE.esc(value))\nend\nend\nreturn result\nend\nfunction premake.gcc.getdefines(defines)\nlocal result = { }\nfor _,def in ipairs(defines) do\ntable.insert(result, '-D' .. def)\nend\nreturn result\nend\nfunction premake.gcc.getincludedirs(includedirs)\nlocal result = { }\nfor _,dir in ipairs(includedirs) do\ntable.insert(result, \"-I\" .. _MAKE.esc(dir))\nend\nreturn result\nend\n", - - /* tools/msc.lua */ - "premake.msc = { }\npremake.msc.namestyle = \"windows\"\n", - - /* tools/ow.lua */ - "premake.ow = { }\npremake.ow.namestyle = \"windows\"\npremake.ow.cc = \"WCL386\"\npremake.ow.cxx = \"WCL386\"\npremake.ow.ar = \"ar\"\nlocal cflags =\n{\nExtraWarnings = \"-wx\",\nFatalWarning = \"-we\",\nFloatFast = \"-omn\",\nFloatStrict = \"-op\",\nOptimize = \"-ox\",\nOptimizeSize = \"-os\",\nOptimizeSpeed = \"-ot\",\nSymbols = \"-d2\",\n}\nlocal cxxflags =\n{\nNoExceptions = \"-xd\",\nNoRTTI = \"-xr\",\n}\npremake.ow.platforms = \n{\nNative = { \nflags = \"\" \n},\n}\nfunction premake.ow.getcppflags(cfg)\nreturn {}\nend\nfunction premake.ow.getcflags(cfg)\nlocal result = table.translate(cfg.flags, cflags)\nif (cfg.flags.Symbols) then\ntable.insert(result, \"-hw\") -- Watcom debug format for Watcom debugger\nend\nreturn result\nend\nfunction premake.ow.getcxxflags(cfg)\nlocal result = table.translate(cfg.flags, cxxflags)\nreturn result\nend\nfunction premake.ow.getldflags(cfg)\nlocal result = { }\nif (cfg.flags.Symbols) then\ntable.insert(result, \"op symf" - "\")\nend\nreturn result\nend\nfunction premake.ow.getlinkflags(cfg)\nlocal result = { }\nreturn result\nend\nfunction premake.ow.getdefines(defines)\nlocal result = { }\nfor _,def in ipairs(defines) do\ntable.insert(result, '-D' .. def)\nend\nreturn result\nend\nfunction premake.ow.getincludedirs(includedirs)\nlocal result = { }\nfor _,dir in ipairs(includedirs) do\ntable.insert(result, '-I \"' .. dir .. '\"')\nend\nreturn result\nend\n", - - /* base/validate.lua */ - "function premake.checkprojects()\nlocal action = premake.action.current()\nfor sln in premake.solution.each() do\nif (#sln.projects == 0) then\nreturn nil, \"solution '\" .. sln.name .. \"' needs at least one project\"\nend\nif (#sln.configurations == 0) then\nreturn nil, \"solution '\" .. sln.name .. \"' needs configurations\"\nend\nfor prj in premake.solution.eachproject(sln) do\nif (not prj.language) then\nreturn nil, \"project '\" ..prj.name .. \"' needs a language\"\nend\nif (action.valid_languages) then\nif (not table.contains(action.valid_languages, prj.language)) then\nreturn nil, \"the \" .. action.shortname .. \" action does not support \" .. prj.language .. \" projects\"\nend\nend\nfor cfg in premake.eachconfig(prj) do\nif (not cfg.kind) then\nreturn nil, \"project '\" ..prj.name .. \"' needs a kind in configuration '\" .. cfg.name .. \"'\"\nend\nif (action.valid_kinds) then\nif (not table.contains(action.valid_kinds, cfg.kind)) then\nreturn nil, \"the \" .. action.shortname .. \" action does not su" - "pport \" .. cfg.kind .. \" projects\"\nend\nend\nend\nif action.oncheckproject then\naction.oncheckproject(prj)\nend\nend\nend\nreturn true\nend\nfunction premake.checktools()\nlocal action = premake.action.current()\nif (not action.valid_tools) then \nreturn true \nend\nfor tool, values in pairs(action.valid_tools) do\nif (_OPTIONS[tool]) then\nif (not table.contains(values, _OPTIONS[tool])) then\nreturn nil, \"the \" .. action.shortname .. \" action does not support /\" .. tool .. \"=\" .. _OPTIONS[tool] .. \" (yet)\"\nend\nelse\n_OPTIONS[tool] = values[1]\nend\nend\nreturn true\nend\n", - - /* base/help.lua */ - "function premake.showhelp()\nprintf(\"Premake %s, a build script generator\", _PREMAKE_VERSION)\nprintf(_PREMAKE_COPYRIGHT)\nprintf(\"%s %s\", _VERSION, _COPYRIGHT)\nprintf(\"\")\nprintf(\"Usage: premake4 [options] action [arguments]\")\nprintf(\"\")\nprintf(\"OPTIONS\")\nprintf(\"\")\nfor option in premake.option.each() do\nlocal trigger = option.trigger\nlocal description = option.description\nif (option.value) then trigger = trigger .. \"=\" .. option.value end\nif (option.allowed) then description = description .. \"; one of:\" end\nprintf(\" --%-15s %s\", trigger, description) \nif (option.allowed) then\nfor _, value in ipairs(option.allowed) do\nprintf(\" %-14s %s\", value[1], value[2])\nend\nend\nprintf(\"\")\nend\nprintf(\"ACTIONS\")\nprintf(\"\")\nfor action in premake.action.each() do\nprintf(\" %-17s %s\", action.trigger, action.description)\nend\nprintf(\"\")\nprintf(\"For additional information, see http://industriousone.com/premake\")\nend\n", - - /* base/premake.lua */ - "function premake.generate(obj, filename, callback)\nfilename = premake.project.getfilename(obj, filename)\nprintf(\"Generating %s...\", filename)\nlocal f, err = io.open(filename, \"wb\")\nif (not f) then\nerror(err, 0)\nend\nio.output(f)\ncallback(obj)\nf:close()\nend\n", - - /* actions/codeblocks/_codeblocks.lua */ - "newaction {\ntrigger = \"codeblocks\",\nshortname = \"Code::Blocks\",\ndescription = \"Generate Code::Blocks project files\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\" },\nvalid_tools = {\ncc = { \"gcc\", \"ow\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.workspace\", premake.codeblocks_workspace)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.cbp\", premake.codeblocks_cbp)\nend,\noncleansolution = function(sln)\npremake.clean.file(sln, \"%%.workspace\")\nend,\noncleanproject = function(prj)\npremake.clean.file(prj, \"%%.cbp\")\npremake.clean.file(prj, \"%%.depend\")\npremake.clean.file(prj, \"%%.layout\")\nend\n}\n", - - /* actions/codeblocks/codeblocks_workspace.lua */ - "function premake.codeblocks_workspace(sln)\n_p('')\n_p('')\n_p(1,'', sln.name)\nfor prj in premake.solution.eachproject(sln) do\nlocal fname = path.join(path.getrelative(sln.location, prj.location), prj.name)\nlocal active = iif(prj.project == sln.projects[1], ' active=\"1\"', '')\n_p(2,'', fname, active)\nfor _,dep in ipairs(premake.getdependencies(prj)) do\n_p(3,'', path.join(path.getrelative(sln.location, dep.location), dep.name))\nend\n_p(2,'')\nend\n_p(1,'')\n_p('')\nend\n", - - /* actions/codeblocks/codeblocks_cbp.lua */ - "function premake.codeblocks_cbp(prj)\nlocal cc = premake.gettool(prj)\n_p('')\n_p('')\n_p(1,'')\n_p(1,'')\n_p(2,'')\n_p('')\n_p('')\nend\n", - - /* actions/codelite/_codelite.lua */ - "newaction {\ntrigger = \"codelite\",\nshortname = \"CodeLite\",\ndescription = \"Generate CodeLite project files\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\" },\nvalid_tools = {\ncc = { \"gcc\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.workspace\", premake.codelite_workspace)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.project\", premake.codelite_project)\nend,\noncleansolution = function(sln)\npremake.clean.file(sln, \"%%.workspace\")\npremake.clean.file(sln, \"%%_wsp.mk\")\npremake.clean.file(sln, \"%%.tags\")\nend,\noncleanproject = function(prj)\npremake.clean.file(prj, \"%%.project\")\npremake.clean.file(prj, \"%%.mk\")\npremake.clean.file(prj, \"%%.list\")\npremake.clean.file(prj, \"%%.out\")\nend\n}\n", - - /* actions/codelite/codelite_workspace.lua */ - "function premake.codelite_workspace(sln)\n_p('')\n_p('', premake.esc(sln.name), premake.esc(sln.name))\nfor i,prj in ipairs(sln.projects) do\nlocal name = premake.esc(prj.name)\nlocal fname = path.join(path.getrelative(sln.location, prj.location), prj.name)\nlocal active = iif(i==1, \"Yes\", \"No\")\n_p(' ', name, fname, active)\nend\nlocal platforms = premake.filterplatforms(sln, premake[_OPTIONS.cc].platforms, \"Native\")\nfor i = #platforms, 1, -1 do\nif premake.platforms[platforms[i]].iscrosscompiler then\ntable.remove(platforms, i)\nend\nend \n_p(' ')\nfor _, platform in ipairs(platforms) do\nfor _, cfgname in ipairs(sln.configurations) do\nlocal name = premake.getconfigname(cfgname, platform)\n_p(' ', name)\nfor _,prj in ipairs(sln.projects) do\n_p(' ', prj.name, name)\nend\n_p(' ')\nend\nend\n_p(' ')\n_p('')\nend\n", - - /* actions/codelite/codelite_project.lua */ - "function premake.codelite_project(prj)\n_p('')\n_p('', premake.esc(prj.name))\npremake.walksources(prj, premake.codelite_files)\nlocal types = { \nConsoleApp = \"Executable\", \nWindowedApp = \"Executable\", \nStaticLib = \"Static Library\",\nSharedLib = \"Dynamic Library\",\n}\n_p(' ', types[prj.kind])\nlocal platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms, \"Native\")\nfor i = #platforms, 1, -1 do\nif premake.platforms[platforms[i]].iscrosscompiler then\ntable.remove(platforms, i)\nend\nend \nfor _, platform in ipairs(platforms) do\nfor cfg in premake.eachconfig(prj, platform) do\nlocal name = premake.esc(cfg.longname)\nlocal compiler = iif(cfg.language == \"C\", \"gcc\", \"g++\")\n_p(' ', name, compiler, types[cfg.kind])\nlocal fname = premake.esc(cfg.buildtarget.fullpath)\nloc" - "al objdir = premake.esc(cfg.objectsdir)\nlocal runcmd = cfg.buildtarget.name\nlocal rundir = cfg.buildtarget.directory\nlocal pause = iif(cfg.kind == \"WindowedApp\", \"no\", \"yes\")\n_p(' ', fname, objdir, runcmd, rundir, pause)\nlocal flags = premake.esc(table.join(premake.gcc.getcflags(cfg), premake.gcc.getcxxflags(cfg), cfg.buildoptions))\n_p(' ', table.concat(flags, \";\"))\nfor _,v in ipairs(cfg.includedirs) do\n_p(' ', premake.esc(v))\nend\nfor _,v in ipairs(cfg.defines) do\n_p(' ', premake.esc(v))\nend\n_p(' ')\nflags = premake.esc(table.join(premake.gcc.getldflags(cfg), cfg.linkoptions))\n_p(' ', table.concat(flags, \";\"))\nfor _,v in ipairs(premake.getlinks(cfg, \"al" - "l\", \"directory\")) do\n_p(' ', premake.esc(v))\nend\nfor _,v in ipairs(premake.getlinks(cfg, \"all\", \"basename\")) do\n_p(' ', premake.esc(v))\nend\n_p(' ')\nif premake.findfile(cfg, \".rc\") then\nlocal defines = table.implode(table.join(cfg.defines, cfg.resdefines), \"-D\", \";\", \"\")\nlocal options = table.concat(cfg.resoptions, \";\")\n_p(' ', defines, options)\nfor _,v in ipairs(table.join(cfg.includedirs, cfg.resincludedirs)) do\n_p(' ', premake.esc(v))\nend\n_p(' ')\nelse\n_p(' ')\nend\nif #cfg.prebuildcommands > 0 then\n_p(' ')\nfor _,v in ipairs(cfg.prebuildcommands) do\n_p(' %s', premake.esc(v))\nend\n_p(' ')\nend\nif #cfg.postbuildcommands > 0 then\n_p(' ')\nfor " - "_,v in ipairs(cfg.postbuildcommands) do\n_p(' %s', premake.esc(v))\nend\n_p(' ')\nend\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' None')\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' ')\n_p(' ')\nend\nend\n_p(' ')\nfor _, platform in ipairs(platforms) do\nfor cfg in premake.eachconfig(prj, platform) do\n_p(' ', cfg.longname)\nfor _,dep in ipairs(premake.getdependencies(prj)) do\n_p(' ', dep.name)\nend\n_p(' ')\nend\nend\n_p('')\nend\nfunction premake.codelite_files(prj, fname, state, nestlevel)\nlocal indent = string.rep(\" \", nestlevel + 1)\nif (state == \"GroupStart\") then\nio.write(indent .. '\\n')\nelseif (state == \"GroupEnd\") then\nio.write(indent .. '\\n')\nelse\nio.write(indent .. '\\n')\nend\nend\n", - - /* actions/make/_make.lua */ - "_MAKE = { }\npremake.make = { }\nfunction _MAKE.esc(value)\nlocal result\nif (type(value) == \"table\") then\nresult = { }\nfor _,v in ipairs(value) do\ntable.insert(result, _MAKE.esc(v))\nend\nreturn result\nelse\nresult = value:gsub(\"\\\\\", \"\\\\\\\\\")\nresult = result:gsub(\" \", \"\\\\ \")\nresult = result:gsub(\"%(\", \"\\\\%(\")\nresult = result:gsub(\"%)\", \"\\\\%)\")\nresult = result:gsub(\"$\\\\%((.-)\\\\%)\", \"$%(%1%)\")\nreturn result\nend\nend\nfunction premake.make_copyrule(source, target)\n_p('%s: %s', target, source)\n_p('\\t@echo Copying $(notdir %s)', target)\n_p('ifeq (posix,$(SHELLTYPE))')\n_p('\\t$(SILENT) cp -fR %s %s', source, target)\n_p('else')\n_p('\\t$(SILENT) copy /Y $(subst /,\\\\\\\\,%s) $(subst /,\\\\\\\\,%s)', source, target)\n_p('endif')\nend\nfunction premake.make_mkdirrule(var)\n_p('\\t@echo Creating %s', var)\n_p('ifeq (posix,$(SHELLTYPE))')\n_p('\\t$(SILENT) mkdir -p %s', var)\n_p('else')\n_p('\\t$(SILENT) mkdir $(subst /,\\\\\\\\,%s)', var)\n_p('endif')\n_p('')\nend\n" - "function _MAKE.getmakefilename(this, searchprjs)\nlocal count = 0\nfor sln in premake.solution.each() do\nif (sln.location == this.location) then count = count + 1 end\nif (searchprjs) then\nfor _,prj in ipairs(sln.projects) do\nif (prj.location == this.location) then count = count + 1 end\nend\nend\nend\nif (count == 1) then\nreturn \"Makefile\"\nelse\nreturn this.name .. \".make\"\nend\nend\nfunction _MAKE.getnames(tbl)\nlocal result = table.extract(tbl, \"name\")\nfor k,v in pairs(result) do\nresult[k] = _MAKE.esc(v)\nend\nreturn result\nend\nnewaction {\ntrigger = \"gmake\",\nshortname = \"GNU Make\",\ndescription = \"Generate GNU makefiles for POSIX, MinGW, and Cygwin\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\", \"C#\" },\nvalid_tools = {\ncc = { \"gcc\" },\ndotnet = { \"mono\", \"msnet\", \"pnet\" },\n},\nonsolution = function(sln)\npremake.generate(sln, _MAKE.getmakefilename(sln, false), premake.ma" - "ke_solution)\nend,\nonproject = function(prj)\nlocal makefile = _MAKE.getmakefilename(prj, true)\nif premake.isdotnetproject(prj) then\npremake.generate(prj, makefile, premake.make_csharp)\nelse\npremake.generate(prj, makefile, premake.make_cpp)\nend\nend,\noncleansolution = function(sln)\npremake.clean.file(sln, _MAKE.getmakefilename(sln, false))\nend,\noncleanproject = function(prj)\npremake.clean.file(prj, _MAKE.getmakefilename(prj, true))\nend\n}\n", - - /* actions/make/make_solution.lua */ - "function premake.make_solution(sln)\nlocal cc = premake[_OPTIONS.cc]\nlocal platforms = premake.filterplatforms(sln, cc.platforms, \"Native\")\n_p('# %s solution makefile autogenerated by Premake', premake.action.current().shortname)\n_p('# Type \"make help\" for usage help')\n_p('')\n_p('ifndef config')\n_p(' config=%s', _MAKE.esc(premake.getconfigname(sln.configurations[1], platforms[1], true)))\n_p('endif')\n_p('export config')\n_p('')\n_p('PROJECTS := %s', table.concat(_MAKE.esc(table.extract(sln.projects, \"name\")), \" \"))\n_p('')\n_p('.PHONY: all clean help $(PROJECTS)')\n_p('')\n_p('all: $(PROJECTS)')\n_p('')\nfor _, prj in ipairs(sln.projects) do\n_p('%s: %s', _MAKE.esc(prj.name), table.concat(_MAKE.esc(table.extract(premake.getdependencies(prj), \"name\")), \" \"))\n_p('\\t@echo \"==== Building %s ($(config)) ====\"', prj.name)\n_p('\\t@${MAKE} --no-print-directory -C %s -f %s', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(_MAKE.getmakefilename(prj, true)))\n_p('')\nend\n_p('c" - "lean:')\nfor _ ,prj in ipairs(sln.projects) do\n_p('\\t@${MAKE} --no-print-directory -C %s -f %s clean', _MAKE.esc(path.getrelative(sln.location, prj.location)), _MAKE.esc(_MAKE.getmakefilename(prj, true)))\nend\n_p('')\n_p('help:')\n_p(1,'@echo \"Usage: make [config=name] [target]\"')\n_p(1,'@echo \"\"')\n_p(1,'@echo \"CONFIGURATIONS:\"')\nlocal cfgpairs = { }\nfor _, platform in ipairs(platforms) do\nfor _, cfgname in ipairs(sln.configurations) do\n_p(1,'@echo \" %s\"', premake.getconfigname(cfgname, platform, true))\nend\nend\n_p(1,'@echo \"\"')\n_p(1,'@echo \"TARGETS:\"')\n_p(1,'@echo \" all (default)\"')\n_p(1,'@echo \" clean\"')\nfor _, prj in ipairs(sln.projects) do\n_p(1,'@echo \" %s\"', prj.name)\nend\n_p(1,'@echo \"\"')\n_p(1,'@echo \"For more information, see http://industriousone.com/premake/quick-start\"')\nend\n", - - /* actions/make/make_cpp.lua */ - "premake.make.cpp = { }\nlocal _ = premake.make.cpp\nfunction premake.make_cpp(prj)\nlocal cc = premake.gettool(prj)\nlocal platforms = premake.filterplatforms(prj.solution, cc.platforms, \"Native\")\npremake.gmake_cpp_header(prj, cc, platforms)\nfor _, platform in ipairs(platforms) do\nfor cfg in premake.eachconfig(prj, platform) do\npremake.gmake_cpp_config(cfg, cc)\nend\nend\n_p('OBJECTS := \\\\')\nfor _, file in ipairs(prj.files) do\nif path.iscppfile(file) or path.getextension(file) == \".asm\" then\n_p('\\t$(OBJDIR)/%s.o \\\\', _MAKE.esc(path.getbasename(file)))\nend\nend\n_p('')\n \n_p('RESOURCES := \\\\')\nfor _, file in ipairs(prj.files) do\nif path.isresourcefile(file) then\n_p('\\t$(OBJDIR)/%s.res \\\\', _MAKE.esc(path.getbasename(file)))\nend\nend\n_p('')\n \n_p('SHELLTYPE := msdos')\n_p('ifeq (,$(ComSpec)$(COMSPEC))')\n_p(' SHELLTYPE := posix')\n_p('endif')\n_p('ifeq (/bin,$(findstring /bin,$(SHELL)))')\n_p(' SHELLTYPE := posix')\n_p('endif')\n_p('')\n_p('.PHONY: clean prebuild prelink')\n_p('')" - "\nif os.is(\"MacOSX\") and prj.kind == \"WindowedApp\" then\n_p('all: $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')\nelse\n_p('all: $(TARGET)')\nend\n_p('\\t@:')\n_p('')\n_p('$(TARGET): $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink')\n_p('\\t@echo Linking %s', prj.name)\n_p('\\t$(SILENT) $(LINKCMD)')\n_p('\\t$(POSTBUILDCMDS)')\n_p('')\n_p('$(TARGETDIR):')\npremake.make_mkdirrule(\"$(TARGETDIR)\")\n_p('$(OBJDIR):')\npremake.make_mkdirrule(\"$(OBJDIR)\")\nif os.is(\"MacOSX\") and prj.kind == \"WindowedApp\" then\n_p('$(dir $(TARGETDIR))PkgInfo:')\n_p('$(dir $(TARGETDIR))Info.plist:')\n_p('')\nend\n_p('clean:')\n_p('\\t@echo Cleaning %s', prj.name)\n_p('ifeq (posix,$(SHELLTYPE))')\n_p('\\t$(SILENT) rm -f $(TARGET)')\n_p('\\t$(SILENT) rm -rf $(OBJDIR)')\n_p('else')\n_p('\\t$(SILENT) if exist $(subst /,\\\\\\\\,$(TARGET)) del $(subst /,\\\\\\\\,$(TARGET))')\n_p('\\t$(SILENT) if exist $(subst /,\\\\\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\\\\\,$(OBJDIR))')\n_p('endif')\n_p('')\n_p('prebuild: $" - "(TARGETDIR) $(OBJDIR)')\n_p('\\t$(PREBUILDCMDS)')\n_p('')\n_p('prelink:')\n_p('\\t$(PRELINKCMDS)')\n_p('')\n_.pchrules(prj)\nfor _, file in ipairs(prj.files) do\nif path.iscppfile(file) then\nlocal gchobj = '$(GCH)'\nlocal pchincludes = '$(PCHINCLUDES)'\nif (path.getextension(file) == \".mm\" or path.getextension(file) == \".m\") then\ngchobj = ''\npchincludes = ''\nend\n_p('$(OBJDIR)/%s.o: %s %s | prebuild', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file), gchobj)\n_p('\\t@echo $(notdir $<)')\nif (path.iscfile(file)) then\n_p('\\t$(SILENT) $(CC) %s $(CFLAGS) -MF $(OBJDIR)/%s.d -MT \"$@\" -o \"$@\" -c \"$<\"', pchincludes, _MAKE.esc(path.getbasename(file)))\nelse\n_p('\\t$(SILENT) $(CXX) %s $(CXXFLAGS) -MF $(OBJDIR)/%s.d -MT \"$@\" -o \"$@\" -c \"$<\"', pchincludes, _MAKE.esc(path.getbasename(file)))\nend\nelseif (path.getextension(file) == \".rc\") then\n_p('$(OBJDIR)/%s.res: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))\n_p('\\t@echo $(notdir $<)')\n_p('\\t$(SILENT) windres $< -O coff -o \"$@\"" - " $(RESFLAGS)')\nelseif (path.getextension(file) == \".asm\") then\n_p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))\n_p('\\t@echo $(notdir $<)')\nlocal opts = ''\nif os.is('windows') then\nopts = ''\nelseif os.is('macosx') then\nopts = '-D OS_UNIX=1'\nelse\nopts = '-D DONT_USE_UNDERLINE=1 -D OS_UNIX=1'\nend\nif not (prj.solution.nasmpath) then\nprj.solution.nasmpath = 'nasm'\nend\n_p('\\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..' -f '..\n _MAKE.esc(prj.solution.nasmformat)..' -o $@ $<\\n\\t')\n_p('\\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..\n ' -M -o $@ $< >$(OBJDIR)/$( 0 then\n_p('\\t@echo Running pre-build commands')\n_p('\\t%s', table.implode(cfg.prebuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p(' endef')\n_p(' define PRELINKCMDS')\nif #cfg.prelinkcommands > 0 then\n_p('\\t@echo Running pre-link commands')\n_p('\\t%s', table.implode(cfg.prelinkcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p(' endef')\n_p(' define POSTBUILDCMDS')\nif #cfg.postbuildcommands > 0 then\n_p('\\t@echo Running post-build commands')\n_p('\\t%s', table.implode(cfg.postbuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p(' endef')\n_p('endif')\n_p('')\nend\nfunction _.pchconfig(cfg)\nif not cfg.flags.NoPCH and cfg.pchheader then\n_p(' PCH = %s', _MAKE.esc(cfg.pchheader))\n_p(' GCH = $(OBJDIR)/%s.gch', _MAKE.esc(path.getname(cfg.pchheader))) \n_p(' PCHINCLUDES = -I$(OBJDIR) -include $(OBJDIR)/%s', _MAKE.esc(path.getname(cfg.pchheade" - "r)))\nend\nend\nfunction _.pchrules(prj)\n_p('ifneq (,$(PCH))')\n_p('$(GCH): $(PCH) | $(OBJDIR)')\n_p('\\t@echo $(notdir $<)')\n_p('\\t-$(SILENT) cp $< $(OBJDIR)')\nif prj.language == \"C\" then\n_p('\\t$(SILENT) $(CC) $(CFLAGS) -o \"$@\" -c \"$<\"')\nelse\n_p('\\t$(SILENT) $(CXX) $(CXXFLAGS) -x c++-header -o \"$@\" -c \"$<\"')\nend\n_p('endif')\n_p('')\nend\n", - - /* actions/make/make_csharp.lua */ - "local function getresourcefilename(cfg, fname)\nif path.getextension(fname) == \".resx\" then\n local name = cfg.buildtarget.basename .. \".\"\n local dir = path.getdirectory(fname)\n if dir ~= \".\" then \nname = name .. path.translate(dir, \".\") .. \".\"\nend\nreturn \"$(OBJDIR)/\" .. _MAKE.esc(name .. path.getbasename(fname)) .. \".resources\"\nelse\nreturn fname\nend\nend\nfunction premake.make_csharp(prj)\nlocal csc = premake.dotnet\nlocal cfglibs = { }\nlocal cfgpairs = { }\nlocal anycfg\nfor cfg in premake.eachconfig(prj) do\nanycfg = cfg\ncfglibs[cfg] = premake.getlinks(cfg, \"siblings\", \"fullpath\")\ncfgpairs[cfg] = { }\nfor _, fname in ipairs(cfglibs[cfg]) do\nif path.getdirectory(fname) ~= cfg.buildtarget.directory then\ncfgpairs[cfg][\"$(TARGETDIR)/\" .. _MAKE.esc(path.getname(fname))] = _MAKE.esc(fname)\nend\nend\nend\nlocal sources = {}\nlocal embedded = { }\nlocal copypairs = { }\nfor fcfg in premake.eachfile(prj) do\nlocal action = csc.getbuildaction(fcfg)\nif action == \"Compile\" " - "then\ntable.insert(sources, fcfg.name)\nelseif action == \"EmbeddedResource\" then\ntable.insert(embedded, fcfg.name)\nelseif action == \"Content\" then\ncopypairs[\"$(TARGETDIR)/\" .. _MAKE.esc(path.getname(fcfg.name))] = _MAKE.esc(fcfg.name)\nelseif path.getname(fcfg.name):lower() == \"app.config\" then\ncopypairs[\"$(TARGET).config\"] = _MAKE.esc(fcfg.name)\nend\nend\nlocal paths = table.translate(prj.libdirs, function(v) return path.join(prj.basedir, v) end)\npaths = table.join({prj.basedir}, paths)\nfor _, libname in ipairs(premake.getlinks(prj, \"system\", \"fullpath\")) do\nlocal libdir = os.pathsearch(libname..\".dll\", unpack(paths))\nif (libdir) then\nlocal target = \"$(TARGETDIR)/\" .. _MAKE.esc(path.getname(libname))\nlocal source = path.getrelative(prj.basedir, path.join(libdir, libname))..\".dll\"\ncopypairs[target] = _MAKE.esc(source)\nend\nend\n_p('# %s project makefile autogenerated by Premake', premake.action.current().shortname)\n_p('')\n_p('ifndef config')\n_p(' config=%s', _MAKE.esc(prj.c" - "onfigurations[1]:lower()))\n_p('endif')\n_p('')\n_p('ifndef verbose')\n_p(' SILENT = @')\n_p('endif')\n_p('')\n_p('ifndef CSC')\n_p(' CSC=%s', csc.getcompilervar(prj))\n_p('endif')\n_p('')\n_p('ifndef RESGEN')\n_p(' RESGEN=resgen')\n_p('endif')\n_p('')\nlocal platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms)\ntable.insert(platforms, 1, \"\")\nfor cfg in premake.eachconfig(prj) do\npremake.gmake_cs_config(cfg, csc, cfglibs)\nend\n_p('# To maintain compatibility with VS.NET, these values must be set at the project level')\n_p('TARGET := $(TARGETDIR)/%s', _MAKE.esc(prj.buildtarget.name))\n_p('FLAGS += /t:%s %s', csc.getkind(prj):lower(), table.implode(_MAKE.esc(prj.libdirs), \"/lib:\", \"\", \" \"))\n_p('REFERENCES += %s', table.implode(_MAKE.esc(premake.getlinks(prj, \"system\", \"basename\")), \"/r:\", \".dll\", \" \"))\n_p('')\n_p('SOURCES := \\\\')\nfor _, fname in ipairs(sources) do\n_p('\\t%s \\\\', _MAKE.esc(path.translate(fname)))\nend\n_p('')\n_p('EMBEDFILES :=" - " \\\\')\nfor _, fname in ipairs(embedded) do\n_p('\\t%s \\\\', getresourcefilename(prj, fname))\nend\n_p('')\n_p('COPYFILES += \\\\')\nfor target, source in pairs(cfgpairs[anycfg]) do\n_p('\\t%s \\\\', target)\nend\nfor target, source in pairs(copypairs) do\n_p('\\t%s \\\\', target)\nend\n_p('')\n_p('SHELLTYPE := msdos')\n_p('ifeq (,$(ComSpec)$(COMSPEC))')\n_p(' SHELLTYPE := posix')\n_p('endif')\n_p('ifeq (/bin,$(findstring /bin,$(SHELL)))')\n_p(' SHELLTYPE := posix')\n_p('endif')\n_p('')\n_p('.PHONY: clean prebuild prelink')\n_p('')\n_p('all: $(TARGETDIR) $(OBJDIR) prebuild $(EMBEDFILES) $(COPYFILES) prelink $(TARGET)')\n_p('')\n_p('$(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS)')\n_p('\\t$(SILENT) $(CSC) /nologo /out:$@ $(FLAGS) $(REFERENCES) $(SOURCES) $(patsubst %%,/resource:%%,$(EMBEDFILES))')\n_p('\\t$(POSTBUILDCMDS)')\n_p('')\n_p('$(TARGETDIR):')\npremake.make_mkdirrule(\"$(TARGETDIR)\")\n_p('$(OBJDIR):')\npremake.make_mkdirrule(\"$(OBJDIR)\")\n_p('clean:')\n_p('\\t@echo Cleaning %s', prj.name)\n_p('i" - "feq (posix,$(SHELLTYPE))')\n_p('\\t$(SILENT) rm -f $(TARGETDIR)/%s.* $(COPYFILES)', prj.buildtarget.basename)\n_p('\\t$(SILENT) rm -rf $(OBJDIR)')\n_p('else')\n_p('\\t$(SILENT) if exist $(subst /,\\\\\\\\,$(TARGETDIR)/%s.*) del $(subst /,\\\\\\\\,$(TARGETDIR)/%s.*)', prj.buildtarget.basename, prj.buildtarget.basename)\nfor target, source in pairs(cfgpairs[anycfg]) do\n_p('\\t$(SILENT) if exist $(subst /,\\\\\\\\,%s) del $(subst /,\\\\\\\\,%s)', target, target)\nend\nfor target, source in pairs(copypairs) do\n_p('\\t$(SILENT) if exist $(subst /,\\\\\\\\,%s) del $(subst /,\\\\\\\\,%s)', target, target)\nend\n_p('\\t$(SILENT) if exist $(subst /,\\\\\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\\\\\,$(OBJDIR))')\n_p('endif')\n_p('')\n_p('prebuild:')\n_p('\\t$(PREBUILDCMDS)')\n_p('')\n_p('prelink:')\n_p('\\t$(PRELINKCMDS)')\n_p('')\n_p('# Per-configuration copied file rules')\nfor cfg in premake.eachconfig(prj) do\n_p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower()))\nfor target, source in pairs(cfgpa" - "irs[cfg]) do\npremake.make_copyrule(source, target)\nend\n_p('endif')\n_p('')\nend\n_p('# Copied file rules')\nfor target, source in pairs(copypairs) do\npremake.make_copyrule(source, target)\nend\n_p('# Embedded file rules')\nfor _, fname in ipairs(embedded) do \nif path.getextension(fname) == \".resx\" then\n_p('%s: %s', getresourcefilename(prj, fname), _MAKE.esc(fname))\n_p('\\t$(SILENT) $(RESGEN) $^ $@')\nend\n_p('')\nend\nend\nfunction premake.gmake_cs_config(cfg, csc, cfglibs)\n_p('ifneq (,$(findstring %s,$(config)))', _MAKE.esc(cfg.name:lower()))\n_p(' TARGETDIR := %s', _MAKE.esc(cfg.buildtarget.directory))\n_p(' OBJDIR := %s', _MAKE.esc(cfg.objectsdir))\n_p(' DEPENDS := %s', table.concat(_MAKE.esc(premake.getlinks(cfg, \"dependencies\", \"fullpath\")), \" \"))\n_p(' REFERENCES := %s', table.implode(_MAKE.esc(cfglibs[cfg]), \"/r:\", \"\", \" \"))\n_p(' FLAGS += %s %s', table.implode(cfg.defines, \"/d:\", \"\", \" \"), table.concat(table.join(csc.getflags(cfg), cfg.buildoptions), \" \")" - ")\n_p(' define PREBUILDCMDS')\nif #cfg.prebuildcommands > 0 then\n_p('\\t@echo Running pre-build commands')\n_p('\\t%s', table.implode(cfg.prebuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p(' endef')\n_p(' define PRELINKCMDS')\nif #cfg.prelinkcommands > 0 then\n_p('\\t@echo Running pre-link commands')\n_p('\\t%s', table.implode(cfg.prelinkcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p(' endef')\n_p(' define POSTBUILDCMDS')\nif #cfg.postbuildcommands > 0 then\n_p('\\t@echo Running post-build commands')\n_p('\\t%s', table.implode(cfg.postbuildcommands, \"\", \"\", \"\\n\\t\"))\nend\n_p(' endef')\n_p('endif')\n_p('')\nend\n", - - /* actions/vstudio/_vstudio.lua */ - "_VS = { } -- deprecated, will remove eventually\npremake.vstudio = { }\nlocal vstudio = premake.vstudio\npremake.vstudio_platforms = { \nany = \"Any CPU\", \nmixed = \"Mixed Platforms\", \nNative = \"Win32\",\nx32 = \"Win32\", \nx64 = \"x64\",\nPS3 = \"PS3\",\nXbox360 = \"Xbox 360\",\n}\nfunction _VS.arch(prj)\nif (prj.language == \"C#\") then\nif (_ACTION < \"vs2005\") then\nreturn \".NET\"\nelse\nreturn \"Any CPU\"\nend\nelse\nreturn \"Win32\"\nend\nend\nfunction _VS.bool(value)\nif (_ACTION < \"vs2005\") then\nreturn iif(value, \"TRUE\", \"FALSE\")\nelse\nreturn iif(value, \"true\", \"false\")\nend\nend\nfunction premake.vstudio_buildconfigs(sln)\nlocal cfgs = { }\nlocal platforms = premake.filterplatforms(sln, premake.vstudio_platforms, \"Native\")\nlocal hascpp = premake.hascppproject(sln)\nlocal hasdotnet = premake.hasdotnetproject(sln)\nif hasdotnet then\ntable.insert(platforms, 1, \"any\")\nend\nif hasdotnet and hascpp then\ntable.insert(platforms, 2, \"mixed\")\nend\nfor _, buil" - "dcfg in ipairs(sln.configurations) do\nfor _, platform in ipairs(platforms) do\nlocal entry = { }\nentry.src_buildcfg = buildcfg\nentry.src_platform = platform\nif platform ~= \"PS3\" then\nentry.buildcfg = buildcfg\nentry.platform = premake.vstudio_platforms[platform]\nelse\nentry.buildcfg = platform .. \" \" .. buildcfg\nentry.platform = \"Win32\"\nend\nentry.name = entry.buildcfg .. \"|\" .. entry.platform\nentry.isreal = (platform ~= \"any\" and platform ~= \"mixed\")\ntable.insert(cfgs, entry)\nend\nend\nreturn cfgs\nend\nfunction _VS.cfgtype(cfg)\nif (cfg.kind == \"SharedLib\") then\nreturn 2\nelseif (cfg.kind == \"StaticLib\") then\nreturn 4\nelse\nreturn 1\nend\nend\nfunction premake.vstudio.cleansolution(sln)\npremake.clean.file(sln, \"%%.sln\")\npremake.clean.file(sln, \"%%.suo\")\npremake.clean.file(sln, \"%%.ncb\")\npremake.clean.file(sln, \"%%.userprefs\")\npremake.clean.file(sln, \"%%.usertasks\")\nend\nfunction premake.vstudio.cleanproject(prj)\nlocal fname = premake.project.getfilename(prj, \"%" - "%\")\nos.remove(fname .. \".vcproj\")\nos.remove(fname .. \".vcproj.user\")\nos.remove(fname .. \".vcxproj\")\nos.remove(fname .. \".vcxproj.user\")\nos.remove(fname .. \".vcxproj.filters\")\nos.remove(fname .. \".csproj\")\nos.remove(fname .. \".csproj.user\")\nos.remove(fname .. \".pidb\")\nos.remove(fname .. \".sdf\")\nend\nfunction premake.vstudio.cleantarget(name)\nos.remove(name .. \".pdb\")\nos.remove(name .. \".idb\")\nos.remove(name .. \".ilk\")\nos.remove(name .. \".vshost.exe\")\nos.remove(name .. \".exe.manifest\")\nend\nlocal function output(indent, value)\n_p(indent .. value)\nend\nlocal function attrib(indent, name, value)\n_p(indent .. \"\\t\" .. name .. '=\"' .. value .. '\"')\nend\nfunction _VS.files(prj, fname, state, nestlevel)\nlocal indent = string.rep(\"\\t\", nestlevel + 2)\nif (state == \"GroupStart\") then\noutput(indent, \"\")\nelseif (state == \"GroupEnd\") then\noutput(" - "indent, \"\")\nelse\noutput(indent, \"\")\nif (not prj.flags.NoPCH and prj.pchsource == fname) then\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nif cfginfo.isreal then\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\noutput(indent, \"\\t\")\noutput(indent, \"\\t\\t\")\noutput(indent, \"\\t\")\nend\nend\nend\nif (path.getextension(fname) == \".asm\") then\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nif cfginfo.isreal then\nif not (prj.solution.nasmformat) then\nprj.solution.nasmformat = 'win32'\nend\nif not (prj.solution.nasmpath) then\npr" - "j.solution.nasmpath = 'nasm'\nend\nlocal nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath), \"\\\\\")\nlocal command = nasmpath..\" -i \"..path.translate(path.getdirectory(fname), \"\\\\\")..\"\\\\ -f \"..prj.solution.nasmformat..\n\" "$(InputPath)" -o "$(IntDir)\\\\$(InputName).obj"\"\noutput(indent, \"\\t\")\noutput(indent, \"\\t\\t\")\noutput(indent, \"\\t\")\nend\nend\nend\noutput(indent, \"\")\nend\nend\nfunction _VS.optimization(cfg)\nlocal result = 0\nfor _, value in ipairs(cfg.flags) do\nif (value == \"Optimize\") then\nresult = 3\nelseif (value == \"OptimizeSize\") t" - "hen\nresult = 1\nelseif (value == \"OptimizeSpeed\") then\nresult = 2\nend\nend\nreturn result\nend\nfunction _VS.projectfile(prj)\nlocal extension\nif (prj.language == \"C#\") then\nextension = \".csproj\"\nelseif (_ACTION == \"vs2010\" or _ACTION == \"vs2012\" or _ACTION == \"vs2013\") then\nextension = \".vcxproj\"\nelse\nextension = \".vcproj\"\nend\nlocal fname = path.join(prj.location, prj.name)\nreturn fname..extension\nend\nfunction _VS.tool(prj)\nif (prj.language == \"C#\") then\nreturn \"FAE04EC0-301F-11D3-BF4B-00C04F79EFBC\"\nelse\nreturn \"8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942\"\nend\nend\nnewaction {\ntrigger = \"vs2002\",\nshortname = \"Visual Studio 2002\",\ndescription = \"Generate Microsoft Visual Studio 2002 project files\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\", \"C#\" },\nvalid_tools = {\ncc = { \"msc\" },\ndotnet = { \"msnet\" },\n},\nonsolution = f" - "unction(sln)\npremake.generate(sln, \"%%.sln\", premake.vs2002_solution)\nend,\nonproject = function(prj)\nif premake.isdotnetproject(prj) then\npremake.generate(prj, \"%%.csproj\", premake.vs2002_csproj)\npremake.generate(prj, \"%%.csproj.user\", premake.vs2002_csproj_user)\nelse\npremake.generate(prj, \"%%.vcproj\", premake.vs200x_vcproj)\nend\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget = premake.vstudio.cleantarget\n}\nnewaction {\ntrigger = \"vs2003\",\nshortname = \"Visual Studio 2003\",\ndescription = \"Generate Microsoft Visual Studio 2003 project files\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\", \"C#\" },\nvalid_tools = {\ncc = { \"msc\" },\ndotnet = { \"msnet\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.sln\", premake.vs2003_solution)\nend,\nonproject = function(prj" - ")\nif premake.isdotnetproject(prj) then\npremake.generate(prj, \"%%.csproj\", premake.vs2002_csproj)\npremake.generate(prj, \"%%.csproj.user\", premake.vs2002_csproj_user)\nelse\npremake.generate(prj, \"%%.vcproj\", premake.vs200x_vcproj)\nend\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget = premake.vstudio.cleantarget\n}\nnewaction {\ntrigger = \"vs2005\",\nshortname = \"Visual Studio 2005\",\ndescription = \"Generate Microsoft Visual Studio 2005 project files\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\", \"C#\" },\nvalid_tools = {\ncc = { \"msc\" },\ndotnet = { \"msnet\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.sln\", premake.vs2005_solution)\nend,\nonproject = function(prj)\nif premake.isdotnetproject(prj) then\npremake.generate(prj, \"%%.csproj\", premake.vs2005_csproj)\npr" - "emake.generate(prj, \"%%.csproj.user\", premake.vs2005_csproj_user)\nelse\npremake.generate(prj, \"%%.vcproj\", premake.vs200x_vcproj)\nend\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget = premake.vstudio.cleantarget\n}\nnewaction {\ntrigger = \"vs2008\",\nshortname = \"Visual Studio 2008\",\ndescription = \"Generate Microsoft Visual Studio 2008 project files\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C\", \"C++\", \"C#\" },\nvalid_tools = {\ncc = { \"msc\" },\ndotnet = { \"msnet\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.sln\", premake.vs2005_solution)\nend,\nonproject = function(prj)\nif premake.isdotnetproject(prj) then\npremake.generate(prj, \"%%.csproj\", premake.vs2005_csproj)\npremake.generate(prj, \"%%.csproj.user\", premake.vs2005_csproj_user)\nelse\npremake.generate(prj, \"%%.vc" - "proj\", premake.vs200x_vcproj)\nend\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget = premake.vstudio.cleantarget\n}\nnewaction \n{\ntrigger = \"vs2010\",\nshortname = \"Visual Studio 2010\",\ndescription = \"Generate Visual Studio 2010 project files (experimental)\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C++\",\"C\"},\nvalid_tools = {\ncc = { \"msc\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.sln\", premake.vs_generic_solution)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.vcxproj\", premake.vs2010_vcxproj)\npremake.generate(prj, \"%%.vcxproj.user\", premake.vs2010_vcxproj_user)\npremake.generate(prj, \"%%.vcxproj.filters\", premake.vs2010_vcxproj_filters)\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget" - " = premake.vstudio.cleantarget\n}\nnewaction \n{\ntrigger = \"vs2012\",\nshortname = \"Visual Studio 2012\",\ndescription = \"Generate Visual Studio 2012 project files (experimental)\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C++\",\"C\"},\nvalid_tools = {\ncc = { \"msc\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.sln\", premake.vs_generic_solution)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.vcxproj\", premake.vs2010_vcxproj)\npremake.generate(prj, \"%%.vcxproj.user\", premake.vs2010_vcxproj_user)\npremake.generate(prj, \"%%.vcxproj.filters\", premake.vs2010_vcxproj_filters)\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget = premake.vstudio.cleantarget\n}\nnewaction \n{\ntrigger = \"vs2013\",\nshortname = \"Visual Studio 2013\",\ndescription = \"Generate Vi" - "sual Studio 2013 project files (experimental)\",\nos = \"windows\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"StaticLib\", \"SharedLib\" },\nvalid_languages = { \"C++\",\"C\"},\nvalid_tools = {\ncc = { \"msc\" },\n},\nonsolution = function(sln)\npremake.generate(sln, \"%%.sln\", premake.vs_generic_solution)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.vcxproj\", premake.vs2010_vcxproj)\npremake.generate(prj, \"%%.vcxproj.user\", premake.vs2010_vcxproj_user)\npremake.generate(prj, \"%%.vcxproj.filters\", premake.vs2010_vcxproj_filters)\nend,\noncleansolution = premake.vstudio.cleansolution,\noncleanproject = premake.vstudio.cleanproject,\noncleantarget = premake.vstudio.cleantarget\n}\n", - - /* actions/vstudio/vs2002_solution.lua */ - "function premake.vs2002_solution(sln)\nio.eol = '\\r\\n'\nsln.vstudio_configs = premake.vstudio_buildconfigs(sln)\n_p('Microsoft Visual Studio Solution File, Format Version 7.00')\nfor prj in premake.solution.eachproject(sln) do\nlocal projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)))\n_p('Project(\"{%s}\") = \"%s\", \"%s\", \"{%s}\"', _VS.tool(prj), prj.name, projpath, prj.uuid)\n_p('EndProject')\nend\n_p('Global')\n_p(1,'GlobalSection(SolutionConfiguration) = preSolution')\nfor i, cfgname in ipairs(sln.configurations) do\n_p(2,'ConfigName.%d = %s', i - 1, cfgname)\nend\n_p(1,'EndGlobalSection')\n_p(1,'GlobalSection(ProjectDependencies) = postSolution')\n_p(1,'EndGlobalSection')\n_p(1,'GlobalSection(ProjectConfiguration) = postSolution')\nfor prj in premake.solution.eachproject(sln) do\nfor _, cfgname in ipairs(sln.configurations) do\n_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))\n_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(" - "prj))\nend\nend\n_p(1,'EndGlobalSection')\n_p(1,'GlobalSection(ExtensibilityGlobals) = postSolution')\n_p(1,'EndGlobalSection')\n_p(1,'GlobalSection(ExtensibilityAddIns) = postSolution')\n_p(1,'EndGlobalSection')\n_p('EndGlobal')\nend\n", - - /* actions/vstudio/vs2002_csproj.lua */ - "local function getelements(prj, action, fname)\nif action == \"Compile\" and fname:endswith(\".cs\") then\nreturn \"SubTypeCode\"\nend\nif action == \"EmbeddedResource\" and fname:endswith(\".resx\") then\nlocal basename = fname:sub(1, -6)\nlocal testname = path.getname(basename .. \".cs\")\nif premake.findfile(prj, testname) then\nreturn \"Dependency\", testname\nend\nend\nreturn \"None\"\nend\nfunction premake.vs2002_csproj(prj)\nio.eol = \"\\r\\n\"\n_p('')\n_p(1,'')\n_p(2,'')\n_p(3,'')\nfor cfg in premake.eachconfig(prj) do\n_p(4,'')\nend\n_p(3,'')\n_p(3,'')\nfor _, ref in ipairs(premake.getlinks(prj, \"siblings\", \"object\")) do\n_p(4,'')\nend\nfor _, linkname in ipairs(premake.getlinks(prj, \"system\", \"fullpath\")) do\n_p(4,'')\nend\n_p(3,'')\n_p(2,'')\n_p(2,'')\n_p(3,'')\nfor fcfg in premake.eachfile(prj) do\nlocal action = premake.dotnet.getbuildaction(fcfg)\nlocal fname = path.translate(premake.esc(fcfg.name), \"\\\\\")\nlocal elements, dependency = getelements(prj, action, fcfg.name)\n_p(4,'')\nend\n_p(3,'')\n_p(2,'')\n_p(1,'')\n_p('')\nend\n", - - /* actions/vstudio/vs2002_csproj_user.lua */ - "function premake.vs2002_csproj_user(prj)\nio.eol = \"\\r\\n\"\n_p('')\n_p(1,'')\n_p(2,'')\nlocal refpaths = table.translate(prj.libdirs, function(v) return path.getabsolute(prj.location .. \"/\" .. v) end)\n_p(3,'', path.translate(table.concat(refpaths, \";\"), \"\\\\\"))\nfor cfg in premake.eachconfig(prj) do\n_p(4,'')\nend\n_p(3,'')\n_p(2,'')\n_p(2,'')\n_p(1,'')\n_p('')\nend\n", - - /* actions/vstudio/vs200x_vcproj.lua */ - "premake.vstudio.vcproj = { }\nlocal vcproj = premake.vstudio.vcproj\nfunction vcproj.Configuration(name, cfg)\n_p(2,'')\nend\nfunction premake.vs200x_vcproj_platforms(prj)\nlocal used = { }\n_p(1,'')\nfor _, cfg in ipairs(prj.solution.vstudio_configs) do\nif cfg.isreal and not table.contains(used, cfg.platform) then\ntable.insert(used, cfg.platform)\n_p(2,'')\nend\nend\n_p(1,'')\nend\nfunction premake.vs200x_vcproj_symbols(cfg)\nif (not cfg.flags.Symbols) then\nreturn 0\nelse\nif cfg.flags.NoEditAndConti" - "nue or \n _VS.optimization(cfg) ~= 0 or \n cfg.flags.Managed or \n cfg.platform == \"x64\" then\nreturn 3\nelse\nreturn 4\nend\nend\nend\nfunction premake.vs200x_vcproj_VCCLCompilerTool(cfg)\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', table.concat(premake.esc(cfg.buildoptions), \" \"))\nend\n_p(4,'Optimization=\"%s\"', _VS.optimization(cfg))\nif cfg.flags.NoFramePointer then\n_p(4,'OmitFramePointers=\"%s\"', _VS.bool(true))\nend\nif #cfg.includedirs > 0 then\n_p(4,'AdditionalIncludeDirectories=\"%s\"', premake.esc(path.translate(table.concat(cfg.includedirs, \";\"), '\\\\')))\nend\nif #cfg.defines > 0 then\n_p(4,'PreprocessorDefinitions=\"%s\"', premake.esc(table.concat(cfg.defines, \";\")))\nend\nif premake.config.isdebugbuild(cfg) and not cfg.flags.NoMinimalRebuild and not cfg.flags.Managed then\n_p(4,'MinimalRebuild=\"%s\"', _VS.bool(true))\nend\nif cfg.flags.NoExc" - "eptions then\n_p(4,'ExceptionHandling=\"%s\"', iif(_ACTION < \"vs2005\", \"FALSE\", 0))\nelseif cfg.flags.SEH and _ACTION > \"vs2003\" then\n_p(4,'ExceptionHandling=\"2\"')\nend\nif _VS.optimization(cfg) == 0 and not cfg.flags.Managed then\n_p(4,'BasicRuntimeChecks=\"3\"')\nend\nif _VS.optimization(cfg) ~= 0 then\n_p(4,'StringPooling=\"%s\"', _VS.bool(true))\nend\nlocal runtime\nif premake.config.isdebugbuild(cfg) then\nruntime = iif(cfg.flags.StaticRuntime, 1, 3)\nelse\nruntime = iif(cfg.flags.StaticRuntime, 0, 2)\nend\n_p(4,'RuntimeLibrary=\"%s\"', runtime)\n_p(4,'EnableFunctionLevelLinking=\"%s\"', _VS.bool(true))\nif _ACTION > \"vs2003\" and cfg.platform ~= \"Xbox360\" and cfg.platform ~= \"x64\" then\nif cfg.flags.EnableSSE then\n_p(4,'EnableEnhancedInstructionSet=\"1\"')\nelseif cfg.flags.EnableSSE2 then\n_p(4,'EnableEnhancedInstructionSet=\"2\"')\nend\nend\nif _ACTION < \"vs2005\" then\nif cfg.flags.FloatFast then\n_p(4,'ImproveFloatingPointConsistency=\"%s\"', _VS.bool(false))\nelseif cfg.flags.FloatSt" - "rict then\n_p(4,'ImproveFloatingPointConsistency=\"%s\"', _VS.bool(true))\nend\nelse\nif cfg.flags.FloatFast then\n_p(4,'FloatingPointModel=\"2\"')\nelseif cfg.flags.FloatStrict then\n_p(4,'FloatingPointModel=\"1\"')\nend\nend\nif _ACTION < \"vs2005\" and not cfg.flags.NoRTTI then\n_p(4,'RuntimeTypeInfo=\"%s\"', _VS.bool(true))\nelseif _ACTION > \"vs2003\" and cfg.flags.NoRTTI then\n_p(4,'RuntimeTypeInfo=\"%s\"', _VS.bool(false))\nend\nif cfg.flags.NativeWChar then\n_p(4,'TreatWChar_tAsBuiltInType=\"%s\"', _VS.bool(true))\nelseif cfg.flags.NoNativeWChar then\n_p(4,'TreatWChar_tAsBuiltInType=\"%s\"', _VS.bool(false))\nend\nif not cfg.flags.NoPCH and cfg.pchheader then\n_p(4,'UsePrecompiledHeader=\"%s\"', iif(_ACTION < \"vs2005\", 3, 2))\n_p(4,'PrecompiledHeaderThrough=\"%s\"', path.getname(cfg.pchheader))\nelse\n_p(4,'UsePrecompiledHeader=\"%s\"', iif(_ACTION > \"vs2003\" or cfg.flags.NoPCH, 0, 2))\nend\n_p(4,'WarningLevel=\"%s\"', iif(cfg.flags.ExtraWarnings, 4, 3))\nif cfg.flags.FatalWarnings then\n_p(4,'Warn" - "AsError=\"%s\"', _VS.bool(true))\nend\nif _ACTION < \"vs2008\" and not cfg.flags.Managed then\n_p(4,'Detect64BitPortabilityProblems=\"%s\"', _VS.bool(not cfg.flags.No64BitChecks))\nend\n_p(4,'ProgramDataBaseFileName=\"$(OutDir)\\\\%s.pdb\"', path.getbasename(cfg.buildtarget.name))\n_p(4,'DebugInformationFormat=\"%s\"', premake.vs200x_vcproj_symbols(cfg))\nif cfg.language == \"C\" then\n_p(4, 'CompileAs=\"1\"')\nend\n_p(3,'/>')\nend\nfunction premake.vs200x_vcproj_VCLinkerTool(cfg)\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', table.concat(premake.esc(cfg.linkoptions), \" \"))\nend\nif #cfg.links > 0 then\n_p(4,'AdditionalDependencies=\"%s\"', table.concat(premake.getlinks(cfg, \"all\", \"fullpath\"), \" \"))\nend\n_p(4,'OutputFile=\"$(OutDir)\\\\%s\"', cfg.buildta" - "rget.name)\n_p(4,'LinkIncremental=\"%s\"', iif(_VS.optimization(cfg) == 0, 2, 1))\n_p(4,'AdditionalLibraryDirectories=\"%s\"', table.concat(premake.esc(path.translate(cfg.libdirs, '\\\\')) , \";\"))\nlocal deffile = premake.findfile(cfg, \".def\")\nif deffile then\n_p(4,'ModuleDefinitionFile=\"%s\"', deffile)\nend\nif cfg.flags.NoManifest then\n_p(4,'GenerateManifest=\"%s\"', _VS.bool(false))\nend\n_p(4,'GenerateDebugInformation=\"%s\"', _VS.bool(premake.vs200x_vcproj_symbols(cfg) ~= 0))\nif premake.vs200x_vcproj_symbols(cfg) ~= 0 then\n_p(4,'ProgramDataBaseFileName=\"$(OutDir)\\\\%s.pdb\"', path.getbasename(cfg.buildtarget.name))\nend\n_p(4,'SubSystem=\"%s\"', iif(cfg.kind == \"ConsoleApp\", 1, 2))\nif _VS.optimization(cfg) ~= 0 then\n_p(4,'OptimizeReferences=\"2\"')\n_p(4,'EnableCOMDATFolding=\"2\"')\nend\nif (cfg.kind == \"ConsoleApp\" or cfg.kind == \"WindowedApp\") and not cfg.flags.WinMain then\n_p(4,'EntryPointSymbol=\"mainCRTStartup\"')\nend\nif cfg.kind == \"SharedLib\" then\nlocal implibname = cfg.li" - "nktarget.fullpath\n_p(4,'ImportLibrary=\"%s\"', iif(cfg.flags.NoImportLib, cfg.objectsdir .. \"\\\\\" .. path.getname(implibname), implibname))\nend\n_p(4,'TargetMachine=\"%d\"', iif(cfg.platform == \"x64\", 17, 1))\nelse\n_p(4,'Name=\"VCLibrarianTool\"')\nif #cfg.links > 0 then\n_p(4,'AdditionalDependencies=\"%s\"', table.concat(premake.getlinks(cfg, \"all\", \"fullpath\"), \" \"))\nend\n_p(4,'OutputFile=\"$(OutDir)\\\\%s\"', cfg.buildtarget.name)\nif #cfg.libdirs > 0 then\n_p(4,'AdditionalLibraryDirectories=\"%s\"', premake.esc(path.translate(table.concat(cfg.libdirs , \";\"))))\nend\nif #cfg.linkoptions > 0 then\n_p(4,'AdditionalOptions=\"%s\"', table.concat(premake.esc(cfg.linkoptions), \" \"))\nend\nend\n_p(3,'/>')\nend\nfunction premake.vs200x_vcproj_VCCLCompilerTool_GCC(cfg)\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', premake.esc(" - "table.concat(buildoptions, \" \")))\nend\nif #cfg.includedirs > 0 then\n_p(4,'AdditionalIncludeDirectories=\"%s\"', premake.esc(path.translate(table.concat(cfg.includedirs, \";\"), '\\\\')))\nend\nif #cfg.defines > 0 then\n_p(4,'PreprocessorDefinitions=\"%s\"', table.concat(premake.esc(cfg.defines), \";\"))\nend\n_p(4,'ProgramDataBaseFileName=\"$(OutDir)\\\\%s.pdb\"', path.getbasename(cfg.buildtarget.name))\n_p(4,'DebugInformationFormat=\"0\"')\n_p(4,'CompileAs=\"0\"')\n_p(3,'/>')\nend\nfunction premake.vs200x_vcproj_VCLinkerTool_GCC(cfg)\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', premake.esc(table.concat(buildoptions, \" \")))\nend\nif #cfg.links > 0 then\n_p(4,'AdditionalDependencies=\"%s\"', table.concat(premake.getlinks(cfg, \"all\", \"fullpath\"), \" \"))\nend\n_p(4,'OutputFile=\"$(OutDir)\\\\%s\"', cfg.buildtarget.name)\n_p(4,'Li" - "nkIncremental=\"0\"')\n_p(4,'AdditionalLibraryDirectories=\"%s\"', table.concat(premake.esc(path.translate(cfg.libdirs, '\\\\')) , \";\"))\n_p(4,'GenerateManifest=\"%s\"', _VS.bool(false))\n_p(4,'ProgramDatabaseFile=\"\"')\n_p(4,'RandomizedBaseAddress=\"1\"')\n_p(4,'DataExecutionPrevention=\"0\"')\nelse\n_p(4,'Name=\"VCLibrarianTool\"')\nlocal buildoptions = table.join(premake.gcc.getldflags(cfg), cfg.linkoptions)\nif #buildoptions > 0 then\n_p(4,'AdditionalOptions=\"%s\"', premake.esc(table.concat(buildoptions, \" \")))\nend\nif #cfg.links > 0 then\n_p(4,'AdditionalDependencies=\"%s\"', table.concat(premake.getlinks(cfg, \"all\", \"fullpath\"), \" \"))\nend\n_p(4,'OutputFile=\"$(OutDir)\\\\%s\"', cfg.buildtarget.name)\nif #cfg.libdirs > 0 then\n_p(4,'AdditionalLibraryDirectories=\"%s\"', premake.esc(path.translate(table.concat(cfg.libdirs , \";\"))))\nend\nend\n_p(3,'/>')\nend\nfunction premake.vs200x_vcproj_VCResourceCompilerTool(cfg)\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', table.concat(premake.esc(cfg.resoptions), \" \"))\nend\nif #cfg.defines > 0 or #cfg.resdefines > 0 then\n_p(4,'PreprocessorDefinitions=\"%s\"', table.concat(premake.esc(table.join(cfg.defines, cfg.resdefines)), \";\"))\nend\nif #cfg.includedirs > 0 or #cfg.resincludedirs > 0 then\nlocal dirs = table.join(cfg.includedirs, cfg.resincludedirs)\n_p(4,'AdditionalIncludeDirectories=\"%s\"', premake.esc(path.translate(table.concat(dirs, \";\"), '\\\\')))\nend\n_p(3,'/>')\nend\nfunction premake.vs200x_vcproj_VCManifestTool(cfg)\nlocal manifests = { }\nfor _, fname in ipairs(cfg.files) do\nif path.getextension(fname) == \".manifest\" then\ntable.insert(manifests, fname)\nend\nend\n_p(3,' 0 then\n_p(4,'AdditionalManifestFiles=\"%s\"', premake.esc(table.concat(manifests, \";\")))\nend\n_p(3,'/>')\nend\nfunction premake.vs200x_vcproj_VCMIDLTool(cfg)\n_p(3,'')\nend\nfunction premake.vs200x_vcproj_buildstepsblock(name, steps)\n_p(3,' 0 then\n_p(4,'CommandLine=\"%s\"', premake.esc(table.implode(steps, \"\", \"\", \"\\r\\n\")))\nend\n_p(3,'/>')\nend\nlocal blockmap = \n{\nVCCLCompilerTool = premake.vs200x_vcproj_VCCLCompilerTool,\nVCCLCompilerTool_GCC = premake.vs200x_vcproj_VCCLCompilerTool_GCC,\nVCLinkerTool = premake.vs200x_vcproj_VCLinkerTool,\nVCLinkerTool_GCC = premake.vs200x_vcproj_VCLinkerTool_GCC,\nVCManifestTool = premake.vs200x_vcproj_VCManifestTool,\nVCMIDLTool = premake.vs200x_vcproj_VCMIDLTool,\nVCResourceCompilerTool = premake.vs200x_vcproj_VCResourceCompilerTool,\n}\nlocal function getsections(version, platform)\nif version == \"vs2002\" then\nreturn {\n\"VCCLCompilerTool\",\n\"VCCustomBuildTool\",\n\"VCLinkerTool\",\n\"VCMIDLTool\",\n\"VCPostBuildEventTool\",\n\"VCPreBuildEventTool\",\n\"VCPreLinkEventTool\"," - "\n\"VCResourceCompilerTool\",\n\"VCWebServiceProxyGeneratorTool\",\n\"VCWebDeploymentTool\"\n}\nend\nif version == \"vs2003\" then\nreturn {\n\"VCCLCompilerTool\",\n\"VCCustomBuildTool\",\n\"VCLinkerTool\",\n\"VCMIDLTool\",\n\"VCPostBuildEventTool\",\n\"VCPreBuildEventTool\",\n\"VCPreLinkEventTool\",\n\"VCResourceCompilerTool\",\n\"VCWebServiceProxyGeneratorTool\",\n\"VCXMLDataGeneratorTool\",\n\"VCWebDeploymentTool\",\n\"VCManagedWrapperGeneratorTool\",\n\"VCAuxiliaryManagedWrapperGeneratorTool\"\n}\nend\nif platform == \"Xbox360\" then\nreturn {\n\"VCPreBuildEventTool\",\n\"VCCustomBuildTool\",\n\"VCXMLDataGeneratorTool\",\n\"VCWebServiceProxyGeneratorTool\",\n\"VCMIDLTool\",\n\"VCCLCompilerTool\",\n\"VCManagedResourceCompilerTool\",\n\"VCResourceCompilerTool\",\n\"VCPreLinkEventTool\",\n\"VCLinkerTool\",\n\"VCALinkTool\",\n\"VCX360ImageTool\",\n\"VCBscMakeTool\",\n\"VCX360DeploymentTool\",\n\"VCPostBuildEventTool\",\n\"DebuggerTool\",\n}\nend\nif platform == \"PS3\" then\nreturn {\n\"VCPreBuildEventTool\"," - "\n\"VCCustomBuildTool\",\n\"VCXMLDataGeneratorTool\",\n\"VCWebServiceProxyGeneratorTool\",\n\"VCMIDLTool\",\n\"VCCLCompilerTool_GCC\",\n\"VCManagedResourceCompilerTool\",\n\"VCResourceCompilerTool\",\n\"VCPreLinkEventTool\",\n\"VCLinkerTool_GCC\",\n\"VCALinkTool\",\n\"VCManifestTool\",\n\"VCXDCMakeTool\",\n\"VCBscMakeTool\",\n\"VCFxCopTool\",\n\"VCAppVerifierTool\",\n\"VCWebDeploymentTool\",\n\"VCPostBuildEventTool\"\n}\nelse\nreturn {\n\"VCPreBuildEventTool\",\n\"VCCustomBuildTool\",\n\"VCXMLDataGeneratorTool\",\n\"VCWebServiceProxyGeneratorTool\",\n\"VCMIDLTool\",\n\"VCCLCompilerTool\",\n\"VCManagedResourceCompilerTool\",\n\"VCResourceCompilerTool\",\n\"VCPreLinkEventTool\",\n\"VCLinkerTool\",\n\"VCALinkTool\",\n\"VCManifestTool\",\n\"VCXDCMakeTool\",\n\"VCBscMakeTool\",\n\"VCFxCopTool\",\n\"VCAppVerifierTool\",\n\"VCWebDeploymentTool\",\n\"VCPostBuildEventTool\"\n}\nend\nend\nfunction premake.vs200x_vcproj(prj)\nio.eol = \"\\r\\n\"\n_p('')\n_p(' \"vs2003\" then\n_p(1,'RootNamespace=\"%s\"', prj.name)\nend\n_p(1,'Keyword=\"%s\"', iif(prj.flags.Managed, \"ManagedCProj\", \"Win32Proj\"))\n_p(1,'>')\npremake.vs200x_vcproj_platforms(prj)\nif _ACTION > \"vs2003\" then\n_p(1,'')\n_p(1,'')\nend\n_p(1,'')\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nif cfginfo.isreal then\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\nvcproj.Configuration(cfginfo.name, cfg)\nfor _, block in ipairs(getsections(_ACTION, cfginfo.src_platform)) do\nif blockmap[block] then\nblockmap[block](cfg)\nelseif block == \"V" - "CPreBuildEventTool\" then\npremake.vs200x_vcproj_buildstepsblock(\"VCPreBuildEventTool\", cfg.prebuildcommands)\nelseif block == \"VCPreLinkEventTool\" then\npremake.vs200x_vcproj_buildstepsblock(\"VCPreLinkEventTool\", cfg.prelinkcommands)\nelseif block == \"VCPostBuildEventTool\" then\npremake.vs200x_vcproj_buildstepsblock(\"VCPostBuildEventTool\", cfg.postbuildcommands)\nelseif block == \"VCX360DeploymentTool\" then\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', table.concat(premake.esc(cfg.deploymentoptions), \" \"))\nend\n_p(3,'/>')\nelseif block == \"VCX360ImageTool\" then\n_p(3,' 0 then\n_p(4,'AdditionalOptions=\"%s\"', table.concat(premake.esc(cfg.imageoptions), \" \"))\nend\nif cfg.imagepath ~= nil then\n_p(4,'OutputFileName=\"%s\"', premake.esc(path.translate(cfg.imagepath)))\nend\n_p(3,'/>')\nelseif block == \"DebuggerTool\" then" - "\n_p(3,'')\nelse\n_p(3,'')\nend\nend\n_p(2,'')\nend\nend\n_p(1,'')\n_p(1,'')\n_p(1,'')\n_p(1,'')\npremake.walksources(prj, _VS.files)\n_p(1,'')\n_p(1,'')\n_p(1,'')\n_p('')\nend\n", - - /* actions/vstudio/vs2003_solution.lua */ - "function premake.vs2003_solution(sln)\nio.eol = '\\r\\n'\nsln.vstudio_configs = premake.vstudio_buildconfigs(sln)\n_p('Microsoft Visual Studio Solution File, Format Version 8.00')\nfor prj in premake.solution.eachproject(sln) do\nlocal projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)))\n_p('Project(\"{%s}\") = \"%s\", \"%s\", \"{%s}\"', _VS.tool(prj), prj.name, projpath, prj.uuid)\nlocal deps = premake.getdependencies(prj)\nif #deps > 0 then\n_p('\\tProjectSection(ProjectDependencies) = postProject')\nfor _, dep in ipairs(deps) do\n_p('\\t\\t{%s} = {%s}', dep.uuid, dep.uuid)\nend\n_p('\\tEndProjectSection')\nend\n_p('EndProject')\nend\n_p('Global')\n_p('\\tGlobalSection(SolutionConfiguration) = preSolution')\nfor _, cfgname in ipairs(sln.configurations) do\n_p('\\t\\t%s = %s', cfgname, cfgname)\nend\n_p('\\tEndGlobalSection')\n_p('\\tGlobalSection(ProjectDependencies) = postSolution')\n_p('\\tEndGlobalSection')\n_p('\\tGlobalSection(ProjectConfiguration) = postSolution')\nfor prj i" - "n premake.solution.eachproject(sln) do\nfor _, cfgname in ipairs(sln.configurations) do\n_p('\\t\\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))\n_p('\\t\\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))\nend\nend\n_p('\\tEndGlobalSection')\n_p('\\tGlobalSection(ExtensibilityGlobals) = postSolution')\n_p('\\tEndGlobalSection')\n_p('\\tGlobalSection(ExtensibilityAddIns) = postSolution')\n_p('\\tEndGlobalSection')\n_p('EndGlobal')\nend\n", - - /* actions/vstudio/vs2005_solution.lua */ - "function premake.vs2005_solution(sln)\nio.eol = '\\r\\n'\nsln.vstudio_configs = premake.vstudio_buildconfigs(sln)\n_p('\\239\\187\\191')\n_p('Microsoft Visual Studio Solution File, Format Version %s', iif(_ACTION == 'vs2005', '9.00', '10.00'))\n_p('# Visual Studio %s', iif(_ACTION == 'vs2005', '2005', '2008'))\nfor prj in premake.solution.eachproject(sln) do\nlocal projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), \"\\\\\")\n_p('Project(\"{%s}\") = \"%s\", \"%s\", \"{%s}\"', _VS.tool(prj), prj.name, projpath, prj.uuid)\nlocal deps = premake.getdependencies(prj)\nif #deps > 0 then\n_p('\\tProjectSection(ProjectDependencies) = postProject')\nfor _, dep in ipairs(deps) do\n_p('\\t\\t{%s} = {%s}', dep.uuid, dep.uuid)\nend\n_p('\\tEndProjectSection')\nend\n_p('EndProject')\nend\n_p('Global')\npremake.vs2005_solution_platforms(sln)\npremake.vs2005_solution_project_platforms(sln)\npremake.vs2005_solution_properties(sln)\n_p('EndGlobal')\nend\nfunction premake.vs2005_solution_platforms(sl" - "n)\n_p('\\tGlobalSection(SolutionConfigurationPlatforms) = preSolution')\nfor _, cfg in ipairs(sln.vstudio_configs) do\n_p('\\t\\t%s = %s', cfg.name, cfg.name)\nend\n_p('\\tEndGlobalSection')\nend\nfunction premake.vs2005_solution_project_platforms(sln)\n_p('\\tGlobalSection(ProjectConfigurationPlatforms) = postSolution')\nfor prj in premake.solution.eachproject(sln) do\nfor _, cfg in ipairs(sln.vstudio_configs) do\nlocal mapped\nif premake.isdotnetproject(prj) then\nmapped = \"Any CPU\"\nelse\nif cfg.platform == \"Any CPU\" or cfg.platform == \"Mixed Platforms\" then\nmapped = sln.vstudio_configs[3].platform\nelse\nmapped = cfg.platform\nend\nend\n_p('\\t\\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfg.name, cfg.buildcfg, mapped)\nif mapped == cfg.platform or cfg.platform == \"Mixed Platforms\" then\n_p('\\t\\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfg.name, cfg.buildcfg, mapped)\nend\nend\nend\n_p('\\tEndGlobalSection')\nend\nfunction premake.vs2005_solution_properties(sln)\n_p('\\tGlobalSection(SolutionProperties" - ") = preSolution')\n_p('\\t\\tHideSolutionNode = FALSE')\n_p('\\tEndGlobalSection')\nend\n", - - /* actions/vstudio/vs2005_csproj.lua */ - "premake.vstudio.cs2005 = { }\nlocal vstudio = premake.vstudio\nlocal cs2005 = premake.vstudio.cs2005\nlocal function getelements(prj, action, fname)\nif action == \"Compile\" and fname:endswith(\".cs\") then\nif fname:endswith(\".Designer.cs\") then\nlocal basename = fname:sub(1, -13)\nlocal testname = basename .. \".cs\"\nif premake.findfile(prj, testname) then\nreturn \"Dependency\", testname\nend\ntestname = basename .. \".resx\"\nif premake.findfile(prj, testname) then\nreturn \"AutoGen\", testname\nend\nelse\nlocal basename = fname:sub(1, -4)\nlocal testname = basename .. \".Designer.cs\"\nif premake.findfile(prj, testname) then\nreturn \"SubTypeForm\"\nend\nend\nend\nif action == \"EmbeddedResource\" and fname:endswith(\".resx\") then\nlocal basename = fname:sub(1, -6)\nlocal testname = path.getname(basename .. \".cs\")\nif premake.findfile(prj, testname) then\nif premake.findfile(prj, basename .. \".Designer.cs\") then\nreturn \"DesignerType\", testname\nelse\nreturn \"Dependency\", testname\nend\nelse" - "\ntestname = path.getname(basename .. \".Designer.cs\")\nif premake.findfile(prj, testname) then\nreturn \"AutoGenerated\"\nend\nend\nend\nif action == \"Content\" then\nreturn \"CopyNewest\"\nend\nreturn \"None\"\nend\nfunction cs2005.projectelement(prj)\n_p('', iif(_ACTION == 'vs2005', '', ' ToolsVersion=\"3.5\"'))\nend\nfunction cs2005.projectsettings(prj)\n_p(' ')\n_p(' %s', premake.esc(prj.solution.configurations[1]))\n_p(' AnyCPU')\n_p(' %s', iif(_ACTION == \"vs2005\", \"8.0.50727\", \"9.0.21022\"))\n_p(' 2.0')\n_p(' {%s}', prj.uuid)\n_p(' %s', premake.dotnet.getkind(prj))\n_p(' Properties')\n_p(' %s', prj.buildtarget.basename)\n_p(' %s', prj.buildtarget.basename)\nif prj.framework then\n_p(' v%s', prj.framework)\nend\n_p(' ')\nend\nfunction premake.vs2005_csproj(prj)\nio.eol = \"\\r\\n\"\nlocal vsversion, toolversion\nif _ACTION == \"vs2005\" then\nvsversion = \"8.0.50727\"\ntoolversion = nil\nelseif _ACTION == \"vs2008\" then\nvsversion = \"9.0.21022\"\ntoolversion = \"3.5\"\nend\nif toolversion then\n_p('', toolversion)\nelse\n_p('')\nend\n_p(' ')\n_p(' %s', premake.esc(prj.solution.configurations[1]))\n_p(' AnyCPU')\n_p(' %s', vsversion)\n_p(' 2.0')\n_p(' {%s}', prj.uuid)\n_p(' %s', premake.dotnet.getkind(prj))\n_p(' Properties')\n_p(' %s', prj.buildtarget.basename)\n_p(' %s', prj.buildtarget.basename)\n_p(' ')\nfor cfg in premake.eachconfig(prj) do\n_p(' ', premake.esc(cfg.name))\nif cfg.flags.Symbols then\n_p(' true')\n_p(' full')\nelse\n_p(' pdbonly')\nend\n_p(' %s', iif(cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed, \"true\", \"false\"))\n_p(' %s', cfg.buildtarget.directory)\n_p('" - " %s', table.concat(premake.esc(cfg.defines), \";\"))\n_p(' prompt')\n_p(' 4')\nif cfg.flags.Unsafe then\n_p(' true')\nend\nif cfg.flags.FatalWarnings then\n_p(' true')\nend\n_p(' ')\nend\n_p(' ')\nfor _, ref in ipairs(premake.getlinks(prj, \"siblings\", \"object\")) do\n_p(' ', path.translate(path.getrelative(prj.location, _VS.projectfile(ref)), \"\\\\\"))\n_p(' {%s}', ref.uuid)\n_p(' %s', premake.esc(ref.name))\n_p(' ')\nend\nfor _, linkname in ipairs(premake.getlinks(prj, \"system\", \"basename\")) do\n_p(' ', premake.esc(linkname))\nend\n_p(' ')\n_p(' ')\nfor fcfg in premake.eachfile(prj) do\nlocal action = premake.dotnet.getbuildaction(" - "fcfg)\nlocal fname = path.translate(premake.esc(fcfg.name), \"\\\\\")\nlocal elements, dependency = getelements(prj, action, fcfg.name)\nif elements == \"None\" then\n_p(' <%s Include=\"%s\" />', action, fname)\nelse\n_p(' <%s Include=\"%s\">', action, fname)\nif elements == \"AutoGen\" then\n_p(' True')\nelseif elements == \"AutoGenerated\" then\n_p(' Designer')\n_p(' ResXFileCodeGenerator')\n_p(' %s.Designer.cs', premake.esc(path.getbasename(fcfg.name)))\nelseif elements == \"SubTypeDesigner\" then\n_p(' Designer')\nelseif elements == \"SubTypeForm\" then\n_p(' Form')\nelseif elements == \"PreserveNewest\" then\n_p(' PreserveNewest')\nend\nif dependency then\n_p(' %s', path.translate(premake.esc(dependency), \"\\\\\"))\nend\n_p(' ', action)\nend\nend" - "\n_p(' ')\n_p(' ')\n_p(' ')\n_p('')\nend\n", - - /* actions/vstudio/vs2005_csproj_user.lua */ - "function premake.vs2005_csproj_user(prj)\nio.eol = \"\\r\\n\"\n_p('')\n_p(' ')\nlocal refpaths = table.translate(prj.libdirs, function(v) return path.getabsolute(prj.location .. \"/\" .. v) end)\n_p(' %s', path.translate(table.concat(refpaths, \";\"), \"\\\\\"))\n_p(' ')\n_p('')\nend\n", - - /* actions/vstudio/vs_generic_solution.lua */ - "\nlocal vs_format_version = function()\nlocal t =\n{\nvs2005 = '9.00',\n vs2008 = '10.00',\n vs2010 = '11.00',\nvs2012 = '12.00',\nvs2013 = '13.00'\n}\nreturn t[_ACTION]\nend\nlocal vs_version = function()\nlocal t =\n{\nvs2005 = '2005',\n vs2008 = '2008',\n vs2010 = '2010',\nvs2012 = '2012',\nvs2013 = '2013'\n}\nreturn t[_ACTION]\nend\nlocal vs_write_version_info = function()\n_p('Microsoft Visual Studio Solution File, Format Version %s', vs_format_version())\n_p('# Visual Studio %s', vs_version() )\nend\nlocal vs_write_projects = function(sln)\nfor prj in premake.solution.eachproject(sln) do\nlocal projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), \"\\\\\")\n_p('Project(\"{%s}\") = \"%s\", \"%s\", \"{%s}\"', _VS.tool(prj), prj.name, projpath, prj.uuid)\nlocal deps = premake.getdependencies(prj)\nif #deps > 0 then\n_p('\\tProjectSection(ProjectDependencies) = postProject')\nfor _, dep in ipairs(deps) do\n_p('\\t\\t{%s} = {%s}', dep.uuid, dep.uuid)\nend\n_p('\\tEndProj" - "ectSection')\nend\n_p('EndProject')\nend\nend\nlocal vs_write_pre_version = function(sln)\nio.eol = '\\r\\n'\nsln.vstudio_configs = premake.vstudio_buildconfigs(sln)\n_p('\\239\\187\\191')\nend\nfunction premake.vs_generic_solution(sln)\nvs_write_pre_version(sln)\nvs_write_version_info()\nvs_write_projects(sln)\n_p('Global')\npremake.vs2005_solution_platforms(sln)\npremake.vs2005_solution_project_platforms(sln)\npremake.vs2005_solution_properties(sln)\n_p('EndGlobal')\nend", - - /* actions/vstudio/vs2010_vcxproxj.lua */ - "\npremake.vstudio.vs10_helpers = { }\nlocal vs10_helpers = premake.vstudio.vs10_helpers\nfunction vs10_helpers.remove_relative_path(file)\nfile = file:gsub(\"%.%./\",'')\nfile = file:gsub(\"%./\",'')\nfile = file:gsub(\"^source/\",'')\nreturn file\nend\nfunction vs10_helpers.file_path(file)\nfile = vs10_helpers.remove_relative_path(file)\nlocal path = string.find(file,'/[%w%.%_%-]+$')\nif path then\nreturn string.sub(file,1,path-1)\nelse\nreturn nil\nend\nend\nfunction vs10_helpers.list_of_directories_in_path(path)\nlocal list={}\npath = vs10_helpers.remove_relative_path(path)\nif path then\nfor dir in string.gmatch(path,\"[%w%-%_%.]+/\")do\nif #list == 0 then\nlist[1] = dir:sub(1,#dir-1)\nelse\nlist[#list +1] = list[#list] ..\"/\" ..dir:sub(1,#dir-1)\nend\nend\nend\nreturn list\nend\nfunction vs10_helpers.table_of_file_filters(files)\nlocal filters ={}\nfor _, valueTable in pairs(files) do\nfor _, entry in ipairs(valueTable) do\nlocal result = vs10_helpers.list_of_directories_in_path(entry)\nfor __,dir in ipa" - "irs(result) do\nif table.contains(filters,dir) ~= true then\nfilters[#filters +1] = dir\nend\nend\nend\nend\nreturn filters\nend\nfunction vs10_helpers.get_file_extension(file)\nlocal ext_start,ext_end = string.find(file,\"%.[%w_%-]+$\")\nif ext_start then\nreturn string.sub(file,ext_start+1,ext_end)\nend\nend\nfunction vs10_helpers.sort_input_files(files,sorted_container)\nlocal types = \n{\nh= \"ClInclude\",\nhpp= \"ClInclude\",\nhxx= \"ClInclude\",\nc= \"ClCompile\",\ncpp= \"ClCompile\",\ncxx= \"ClCompile\",\ncc= \"ClCompile\",\nrc = \"ResourceCompile\",\nasm = \"ClASM\"\n}\nfor _, current_file in ipairs(files) do\nlocal ext = vs10_helpers.get_file_extension(current_file)\nif ext then\nlocal type = types[ext]\nif type then\ntable.insert(sorted_container[type],current_file)\nelse\ntable.insert(sorted_container.None,current_file)\nend\nend\nend\nend\nlocal function vs2010_config(prj)\n_p(1,'')\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\n_p(2,'', premake.esc(cfginfo.name))\n_p(3,'%s',cfginfo.buildcfg)\n_p(3,'%s',cfginfo.platform)\n_p(2,'')\nend\n_p(1,'')\nend\nlocal function vs2010_globals(prj)\n_p(1,'')\n_p(2,'{%s}',prj.uuid)\n_p(2,'%s',prj.name)\n_p(2,'Win32Proj')\nif _ACTION == \"vs2012\" then\n_p(2,[[$(VCTargetsPath11)]])\nend\n_p(1,'')\nend\nfunction vs10_helpers.config_type(config)\nlocal t =\n{\nSharedLib = \"DynamicLibrary\",\nStaticLib = \"StaticLibrary\",\nConsoleApp = \"Application\",\nWindowedApp = \"Application\"\n}\nreturn t[config.kind]\nend\nlocal function if_config_and_platform()\nreturn 'Condition=\"\\'$(Configuration)|$(Platform)\\'==\\'%s\\'\"'\nend\nlocal func" - "tion optimisation(cfg)\nlocal result = \"Disabled\"\nfor _, value in ipairs(cfg.flags) do\nif (value == \"Optimize\") then\nresult = \"Full\"\nelseif (value == \"OptimizeSize\") then\nresult = \"MinSpace\"\nelseif (value == \"OptimizeSpeed\") then\nresult = \"MaxSpeed\"\nend\nend\nreturn result\nend\nlocal function config_type_block(prj)\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\n_p(1,''\n, premake.esc(cfginfo.name))\n_p(2,'%s',vs10_helpers.config_type(cfg))\n_p(2,'%s',iif(cfg.flags.Unicode,\"Unicode\",\"MultiByte\"))\n_p(2,'%s'\n,iif(optimisation(cfg) == \"Disabled\",\"true\",\"false\"))\nif _ACTION == \"vs2012\" then\n_p(2, 'v110_xp')\nelseif _ACTION == \"vs2013\" then\n_p(2, 'v120_xp')\nend\nif cfg.flags.MFC then\n_p(2,'Dynamic')\nend\n_p(1,'')\nend\nend\nlocal function import_props(prj)\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\n_p(1,''\n,premake.esc(cfginfo.name))\n_p(2,'')\n_p(1,'')\nend\nend\nlocal function incremental_link(cfg,cfginfo)\nif cfg.kind ~= \"StaticLib\" then\nShoudLinkIncrementally = 'false'\nif optimisation(cfg) == \"Disabled\" then\nShoudLinkIncrementally = 'true'\nend\n_p(2,'%s'\n,premake.esc(cfginfo.name),ShoudLinkIncrementally)\nend\nend\nlocal function ignore_import_lib(cfg,cfginfo)\n" - "if cfg.kind == \"SharedLib\" then\nlocal shouldIgnore = \"false\"\nif cfg.flags.NoImportLib then shouldIgnore = \"true\" end\n _p(2,'%s'\n,premake.esc(cfginfo.name),shouldIgnore)\nend\nend\nlocal function intermediate_and_out_dirs(prj)\n_p(1,'')\n_p(2,'<_ProjectFileVersion>10.0.30319.1')\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\n_p(2,'%s\\\\'\n, premake.esc(cfginfo.name),premake.esc(cfg.buildtarget.directory) )\n_p(2,'%s\\\\'\n, premake.esc(cfginfo.name), premake.esc(cfg.objectsdir))\n_p(2,'%s'\n,premake.esc(cfginfo.name),path.getbasename(cfg.buildtarget.name))\nignore_import_lib(cfg,cfginfo)\nincremental_link(cfg,cfginfo)\nif cfg.flags.NoManifest then" - "\n_p(2,'false'\n,premake.esc(cfginfo.name))\nend\nend\n_p(1,'')\nend\nlocal function runtime(cfg)\nlocal runtime\nif premake.config.isdebugbuild(cfg) then\nruntime = iif(cfg.flags.StaticRuntime,\"MultiThreadedDebug\", \"MultiThreadedDebugDLL\")\nelse\nruntime = iif(cfg.flags.StaticRuntime, \"MultiThreaded\", \"MultiThreadedDLL\")\nend\nreturn runtime\nend\nlocal function precompiled_header(cfg)\n if not cfg.flags.NoPCH and cfg.pchheader then\n_p(3,'Use')\n_p(3,'%s', path.getname(cfg.pchheader))\nelse\n_p(3,'')\nend\nend\nlocal function preprocessor(indent,cfg)\nif #cfg.defines > 0 then\n_p(indent,'%s;%%(PreprocessorDefinitions)'\n,premake.esc(table.concat(cfg.defines, \";\")))\nelse\n_p(indent,'')\n" - "end\nend\nlocal function include_dirs(indent,cfg)\nif #cfg.includedirs > 0 then\n_p(indent,'%s;%%(AdditionalIncludeDirectories)'\n,premake.esc(path.translate(table.concat(cfg.includedirs, \";\"), '\\\\')))\nend\nend\nlocal function resource_compile(cfg)\n_p(2,'')\npreprocessor(3,cfg)\ninclude_dirs(3,cfg)\n_p(2,'')\nend\nlocal function exceptions(cfg)\nif cfg.flags.NoExceptions then\n_p(2,'false')\nelseif cfg.flags.SEH then\n_p(2,'Async')\nend\nend\nlocal function rtti(cfg)\nif cfg.flags.NoRTTI then\n_p(3,'false')\nend\nend\nlocal function wchar_t_buildin(cfg)\nif cfg.flags.NativeWChar then\n_p(3,'true')\nelseif cfg.flags.NoNativeWChar then\n_p(3,'false')\nend\nend\nlocal function sse(cfg)\nif cfg." - "flags.EnableSSE then\n_p(3,'StreamingSIMDExtensions')\nelseif cfg.flags.EnableSSE2 then\n_p(3,'StreamingSIMDExtensions2')\nend\nend\nlocal function floating_point(cfg)\n if cfg.flags.FloatFast then\n_p(3,'Fast')\nelseif cfg.flags.FloatStrict then\n_p(3,'Strict')\nend\nend\nlocal function debug_info(cfg)\nlocal debug_info = ''\nif cfg.flags.Symbols then\nif optimisation(cfg) ~= \"Disabled\" or cfg.flags.NoEditAndContinue then\ndebug_info = \"ProgramDatabase\"\nelseif cfg.platform ~= \"x64\" then\ndebug_info = \"EditAndContinue\"\nelse\ndebug_info = \"OldStyle\"\nend\nend\n_p(3,'%s',debug_info)\nend\nlocal function minimal_build(cfg)\nif premake.config.isdebugbuild(cfg) and not cfg.flags.NoMinimalRebuild then\n_p(3,'true')\nels" - "e\n_p(3,'false')\nend\nend\nlocal function compile_language(cfg)\nif cfg.language == \"C\" then\n_p(3,'CompileAsC')\nend\nend\nlocal function vs10_clcompile(cfg)\n_p(2,'')\nif #cfg.buildoptions > 0 then\n_p(3,'%s %%(AdditionalOptions)',\ntable.concat(premake.esc(cfg.buildoptions), \" \"))\nend\n_p(3,'%s',optimisation(cfg))\ninclude_dirs(3,cfg)\npreprocessor(3,cfg)\nminimal_build(cfg)\nif optimisation(cfg) == \"Disabled\" then\n_p(3,'EnableFastChecks')\nif cfg.flags.ExtraWarnings then\n_p(3,'true')\nend\nelse\n_p(3,'true')\nend\n_p(3,'%s', runtime(cfg))\n_p(3,'true')\nprecompiled_header(cfg)\nif cfg.flags.ExtraWarnings then\n_p(3,'Level4')\nelse\n_p(3,'" - "Level3')\nend\nif cfg.flags.FatalWarnings then\n_p(3,'true')\nend\nexceptions(cfg)\nrtti(cfg)\nwchar_t_buildin(cfg)\nsse(cfg)\nfloating_point(cfg)\ndebug_info(cfg)\nif cfg.flags.NoFramePointer then\n_p(3,'true')\nend\ncompile_language(cfg)\n_p(2,'')\nend\nlocal function event_hooks(cfg, prj)\nif #cfg.postbuildcommands> 0 then\n _p(2,'')\n_p(3,'%s',premake.esc(table.implode(cfg.postbuildcommands, \"\", \"\", \"\\r\\n\")))\n_p(2,'')\nend\nif #cfg.prebuildcommands> 0 or prj.cxxtestrootfile then\n _p(2,'')\n_p(3,'%s',premake.esc(table.implode(cfg.prebuildcommands, \"\", \"\", \"\\r\\n\")))\nif(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then\nlocal cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),\"\\\\\")\nlocal cxxtestrootfil" - "e = path.translate(prj.cxxtestrootfile,\"\\\\\")\n_p(3,'%s --root %s > %s', cxxtestpath, prj.cxxtestrootoptions, cxxtestrootfile)\nend\n_p(2,'')\nend\nif #cfg.prelinkcommands> 0 then\n _p(2,'')\n_p(3,'%s',premake.esc(table.implode(cfg.prelinkcommands, \"\", \"\", \"\\r\\n\")))\n_p(2,'')\nend\nend\nlocal function additional_options(indent,cfg)\nif #cfg.linkoptions > 0 then\n_p(indent,'%s %%(AdditionalOptions)',\ntable.concat(premake.esc(cfg.linkoptions), \" \"))\nend\nend\nlocal function item_def_lib(cfg)\nif cfg.kind == 'StaticLib' then\n_p(1,'')\n_p(2,'$(OutDir)%s',cfg.buildtarget.name)\nadditional_options(2,cfg)\n_p(1,'')\nend\nend\nlocal function link_target_machine(cfg)\nlocal target\nif cfg.platform == nil or cfg.platform == \"x32\" then target =\"MachineX86\"\nelseif cfg.platform == \"x64\" then target =\"MachineX64\"\nend\n_p(3,'%s', target)\nend\nlocal function import_lib(cfg)\nif cfg.kind == \"SharedLib\" then\nlocal implibname = cfg.linktarget.fullpath\n_p(3,'%s',iif(cfg.flags.NoImportLib, cfg.objectsdir .. \"\\\\\" .. path.getname(implibname), implibname))\nend\nend\nlocal function common_link_section(cfg)\n_p(3,'%s',iif(cfg.kind == \"ConsoleApp\",\"Console\", \"Windows\"))\nif cfg.flags.Symbols then \n_p(3,'true')\nelse\n_p(3,'false')\nend\nif optimisation(cfg) ~= \"Disabled\" then\n_p(3,'true')\n_p(3,'true')\nend\nif cfg.flags.Symbols then\n_p(3,'$(OutDir)%s.pdb'\n, path.getbasename(cfg.buildtarget.name))\nend\nend\nlocal function item_link(cfg)\n_p(2,'')\nif cfg.kind ~= 'StaticLib' then\nif #cfg.links > 0 then\n_p(" - "3,'%s;%%(AdditionalDependencies)',\ntable.concat(premake.getlinks(cfg, \"all\", \"fullpath\"), \";\"))\nend\n_p(3,'$(OutDir)%s', cfg.buildtarget.name)\n_p(3,'%s%s%%(AdditionalLibraryDirectories)',\ntable.concat(premake.esc(path.translate(cfg.libdirs, '\\\\')) , \";\"),\niif(cfg.libdirs and #cfg.libdirs >0,';',''))\ncommon_link_section(cfg)\nif vs10_helpers.config_type(cfg) == 'Application' and not cfg.flags.WinMain then\n_p(3,'mainCRTStartup')\nend\nimport_lib(cfg)\n_p(3,'%s', iif(cfg.platform == \"x64\", \"MachineX64\", \"MachineX86\"))\nadditional_options(3,cfg)\nelse\ncommon_link_section(cfg)\nend\n_p(2,'')\nend\nlocal function item_definitions(prj)\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\n_p(1,''\n,premake.esc(cfginfo.name))\nvs10_clcompile(cfg)\nresource_compile(cfg)\nitem_def_lib(cfg)\nitem_link(cfg)\nevent_hooks(cfg, prj)\n_p(1,'')\nend\nend\n -- \n -- {8fd826f8-3739-44e6-8cc8-997122e53b8d}\n -- \n -- \nlocal function write_cxxtestgen_block(prj)\nif(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then\nlocal cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),\"\\\\\")\n_p(1,'')\nfor i, file in ipairs(prj.cxxtesthdrfiles) do\nlocal cxxtesthdrfile = path.translate(file,\"\\\\\")\nlocal cxxtestsrcfile = path.translate(prj.cxxtestsrcfiles[i],\"\\\\\")\n_p(2,'', cxxtesthdrfile)\n _p(3,'Generating %s', path.getname(prj.cxxtestsrcfiles[i]))\n _p(3,'%s --part %s " - "-o \\\"%s\\\" \\\"%s\\\"', \ncxxtestpath, prj.cxxtestoptions, cxxtestsrcfile, cxxtesthdrfile)\n _p(3,'%s;%%(Outputs)', cxxtestsrcfile)\n_p(2,'')\nend\n_p(1,'')\nend\nend\nlocal function write_file_type_block(files,group_type)\nif #files > 0 then\n_p(1,'')\nfor _, current_file in ipairs(files) do\n_p(2,'<%s Include=\\\"%s\\\" />', group_type,path.translate(current_file,\"\\\\\"))\nend\n_p(1,'')\nend\nend\nlocal function write_file_compile_block(files,prj,configs)\nif #files > 0 then\nlocal config_mappings = {}\nfor _, cfginfo in ipairs(configs) do\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\nif cfg.pchheader and cfg.pchsource and not cfg.flags.NoPCH then\nconfig_mappings[cfginfo] = cfg.pchsource\nend\nend\n_p(1,'')\nfor _, current_file in ipairs(files) do\n_p(2,'', path.translate(current_file, \"\\\\\"))\nfor _, cfginfo in ipairs(configs) do\nif config" - "_mappings[cfginfo] and current_file == config_mappings[cfginfo] then \n_p(3,'Create'\n,premake.esc(cfginfo.name))\nconfig_mappings[cfginfo] = nil\nend\nend\n_p(2,'')\nend\n_p(1,'')\nend\nend\nlocal function write_nasm_asm_block(files, prj, configs)\nif not (prj.solution.nasmformat) then\nprj.solution.nasmformat = 'win32'\nend\nif not (prj.solution.nasmpath) then\nprj.solution.nasmpath = 'nasm'\nend\nif #files > 0 then\n_p(1,'')\nlocal nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath),\"\\\\\")\nfor _, current_file in ipairs(files) do\n_p(2,'', path.translate(current_file,\"\\\\\"))\n_p(3,'Assembling %%(FullPath)')\n_p(3,'%s -i %s -f %s \\\"%%(FullPath)\\\" -o \\\"$(IntDir)%%(Filename).obj\\\"', \nnasmpath, \npath.translate(path.getdirectory(current_file),\"\\\\\")..\"\\\\\", \nprj.solution.nasmformat)\n_p(" - "3,'$(IntDir)%%(Filename).obj;%%(Outputs)')\n_p(2,'')\nend\n_p(1,'')\nend\nend\nlocal function vcxproj_files(prj)\nlocal sorted =\n{\nClCompile={},\nClInclude={},\nClASM={},\nNone={},\nResourceCompile ={}\n}\ncfg = premake.getconfig(prj)\nvs10_helpers.sort_input_files(cfg.files,sorted)\nwrite_cxxtestgen_block(prj)\nwrite_file_type_block(sorted.ClInclude,\"ClInclude\")\nwrite_file_compile_block(sorted.ClCompile,prj,prj.solution.vstudio_configs)\nwrite_nasm_asm_block(sorted.ClASM, prj, prj.solution.vstudion_configs)\nwrite_file_type_block(sorted.None,'None')\nwrite_file_type_block(sorted.ResourceCompile,'ResourceCompile')\nend\nlocal function write_filter_includes(sorted_table)\nlocal directories = vs10_helpers.table_of_file_filters(sorted_table)\nif #directories >0 then\n_p(1,'')\nfor _, dir in pairs(directories) do\n_p(2,'',path.translate(dir,\"\\\\\"))\n_p(3,'{%s}',os.uuid())\n_p(2,'')\n" - "end\n_p(1,'')\nend\nend\nlocal function write_file_filter_block(files,group_type)\nif #files > 0 then\n_p(1,'')\nfor _, current_file in ipairs(files) do\nlocal path_to_file = vs10_helpers.file_path(current_file)\nif path_to_file then\n_p(2,'<%s Include=\\\"%s\\\">', group_type,path.translate(current_file, \"\\\\\"))\n_p(3,'%s',path.translate(path_to_file,\"\\\\\"))\n_p(2,'',group_type)\nelse\n_p(2,'<%s Include=\\\"%s\\\" />', group_type,path.translate(current_file, \"\\\\\"))\nend\nend\n_p(1,'')\nend\nend\nlocal tool_version_and_xmlns = 'ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"'\nlocal xml_version_and_encoding = ''\nlocal function vcxproj_filter_files(prj)\nlocal sorted =\n{\nClCompile={},\nClInclude={},\nClASM={},\nNone={},\nResourceCompile ={}\n}\ncfg = premake.getconfig(prj)\nvs10_helpers.sort_input_files(cfg.files,sorted)\nio.eol = \"\\r\\n\"\n_p(xml_version_and_enco" - "ding)\n_p('')\nwrite_filter_includes(sorted)\nwrite_file_filter_block(sorted.ClInclude,\"ClInclude\")\nwrite_file_filter_block(sorted.ClCompile,\"ClCompile\")\nwrite_file_filter_block(prj.cxxtesthdrfiles,\"CustomBuild\")\nwrite_file_filter_block(sorted.ClASM,\"ClASM\")\nwrite_file_filter_block(sorted.None,\"None\")\nwrite_file_filter_block(sorted.ResourceCompile,\"ResourceCompile\")\n_p('')\nend\nfunction premake.vs2010_vcxproj(prj)\nio.eol = \"\\r\\n\"\n_p(xml_version_and_encoding)\n_p('')\nvs2010_config(prj)\nvs2010_globals(prj)\n_p(1,'')\nconfig_type_block(prj)\n_p(1,'')\n_p(1,'')\n_p(1,'')\nimport_props(prj)\n_p(1,'')\nintermediate_and_out_dirs(prj)\nitem_definitions(prj)" - "\nvcxproj_files(prj)\n_p(1,'')\n_p(1,'')\n_p(1,'')\n_p('')\nend\nfunction premake.vs2010_vcxproj_user(prj)\n_p(xml_version_and_encoding)\n_p('')\nfor _, cfginfo in ipairs(prj.solution.vstudio_configs) do\nlocal cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)\nif cfg.flags.NoDebugHeap then\n_p(1,'', premake.esc(cfginfo.name))\n_p(2,'_NO_DEBUG_HEAP=1')\n_p(1,'')\nend\nend\n_p('')\nend\nfunction premake.vs2010_vcxproj_filters(prj)\nvcxproj_filter_files(prj)\nend\n", - - /* actions/xcode/_xcode.lua */ - "premake.xcode = { }\nnewaction \n{\ntrigger = \"xcode3\",\nshortname = \"Xcode 3\",\ndescription = \"Generate Apple Xcode 3 project files (experimental)\",\nos = \"macosx\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"SharedLib\", \"StaticLib\" },\nvalid_languages = { \"C\", \"C++\" },\nvalid_tools = {\ncc = { \"gcc\" },\n},\nvalid_platforms = { \nNative = \"Native\", \nx32 = \"Native 32-bit\", \nx64 = \"Native 64-bit\", \nUniversal32 = \"32-bit Universal\", \nUniversal64 = \"64-bit Universal\", \nUniversal = \"Universal\",\n},\ndefault_platform = \"Universal\",\nonsolution = function(sln)\npremake.xcode.preparesolution(sln)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.xcodeproj/project.pbxproj\", premake.xcode.project)\nend,\noncleanproject = function(prj)\npremake.clean.directory(prj, \"%%.xcodeproj\")\nend,\noncheckproject = function(prj)\nlocal last\nfor cfg in premake.eachconfig(prj) do\nif last and last ~= cfg.kind then\nerror(\"Project '" - "\" .. prj.name .. \"' uses more than one target kind; not supported by Xcode\", 0)\nend\nlast = cfg.kind\nend\nend,\n}\nnewaction \n{\ntrigger = \"xcode4\",\nshortname = \"Xcode 4\",\ndescription = \"Generate Apple Xcode 4 project files (experimental)\",\nos = \"macosx\",\nvalid_kinds = { \"ConsoleApp\", \"WindowedApp\", \"SharedLib\", \"StaticLib\" },\nvalid_languages = { \"C\", \"C++\" },\nvalid_tools = {\ncc = { \"gcc\" },\n},\nvalid_platforms = { \nNative = \"Native\", \nx32 = \"Native 32-bit\", \nx64 = \"Native 64-bit\", \nUniversal32 = \"32-bit Universal\", \nUniversal64 = \"64-bit Universal\", \nUniversal = \"Universal\",\n},\ndefault_platform = \"Universal\",\nonsolution = function(sln)\npremake.generate(sln, \"%%.xcworkspace/contents.xcworkspacedata\", premake.xcode4.workspace_generate)\nend,\nonproject = function(prj)\npremake.generate(prj, \"%%.xcodeproj/project.pbxproj\", premake.xcode.project)\nend,\noncleanproject = function(prj)\npremake.clean.directory" - "(prj, \"%%.xcodeproj\")\npremake.clean.directory(prj, \"%%.xcworkspace\")\nend,\noncheckproject = function(prj)\nlocal last\nfor cfg in premake.eachconfig(prj) do\nif last and last ~= cfg.kind then\nerror(\"Project '\" .. prj.name .. \"' uses more than one target kind; not supported by Xcode\", 0)\nend\nlast = cfg.kind\nend\nend,\n}\n", - - /* actions/xcode/xcode_common.lua */ - "local xcode = premake.xcode\nlocal tree = premake.tree\nfunction xcode.getbuildcategory(node)\nlocal categories = {\n[\".a\"] = \"Frameworks\",\n[\".c\"] = \"Sources\",\n[\".cc\"] = \"Sources\",\n[\".cpp\"] = \"Sources\",\n[\".cxx\"] = \"Sources\",\n[\".dylib\"] = \"Frameworks\",\n[\".framework\"] = \"Frameworks\",\n[\".m\"] = \"Sources\",\n[\".mm\"] = \"Sources\",\n[\".strings\"] = \"Resources\",\n[\".nib\"] = \"Resources\",\n[\".xib\"] = \"Resources\",\n[\".icns\"] = \"Resources\",\n}\nreturn categories[path.getextension(node.name)]\nend\nfunction xcode.getconfigname(cfg)\nlocal name = cfg.name\nif #cfg.project.solution.xcode.platforms > 1 then\nname = name .. \" \" .. premake.action.current().valid_platforms[cfg.platform]\nend\nreturn name\nend\nfunction xcode.getfiletype(node)\nlocal types = {\n[\".c\"] = \"sourcecode.c.c\",\n[\".cc\"] = \"sourcecode.cpp.cpp\",\n[\".cpp\"] = \"sourcecode.cpp.cpp\",\n[\".css\"] = \"text.css\",\n[\".cxx\"] = \"sourcecode.cpp.cpp\",\n[\".fram" - "ework\"] = \"wrapper.framework\",\n[\".gif\"] = \"image.gif\",\n[\".h\"] = \"sourcecode.c.h\",\n[\".html\"] = \"text.html\",\n[\".lua\"] = \"sourcecode.lua\",\n[\".m\"] = \"sourcecode.c.objc\",\n[\".mm\"] = \"sourcecode.cpp.objc\",\n[\".nib\"] = \"wrapper.nib\",\n[\".pch\"] = \"sourcecode.c.h\",\n[\".plist\"] = \"text.plist.xml\",\n[\".strings\"] = \"text.plist.strings\",\n[\".xib\"] = \"file.xib\",\n[\".icns\"] = \"image.icns\",\n}\nreturn types[path.getextension(node.path)] or \"text\"\nend\nfunction xcode.getproducttype(node)\nlocal types = {\nConsoleApp = \"com.apple.product-type.tool\",\nWindowedApp = \"com.apple.product-type.application\",\nStaticLib = \"com.apple.product-type.library.static\",\nSharedLib = \"com.apple.product-type.library.dynamic\",\n}\nreturn types[node.cfg.kind]\nend\nfunction xcode.gettargettype(node)\nlocal types = {\nConsoleApp = \"\\\"compiled.mach-o.executable\\\"\",\nWindowedApp = \"wrapper.application\"," - "\nStaticLib = \"archive.ar\",\nSharedLib = \"\\\"compiled.mach-o.dylib\\\"\",\n}\nreturn types[node.cfg.kind]\nend\nfunction xcode.getxcodeprojname(prj)\nlocal fname = premake.project.getfilename(prj, \"%%.xcodeproj\")\nreturn fname\nend\nfunction xcode.isframework(fname)\nreturn (path.getextension(fname) == \".framework\")\nend\nfunction xcode.newid()\nreturn string.format(\"%04X%04X%04X%04X%04X%04X\",\nmath.random(0, 32767),\nmath.random(0, 32767),\nmath.random(0, 32767),\nmath.random(0, 32767),\nmath.random(0, 32767),\nmath.random(0, 32767))\nend\nfunction xcode.preparesolution(sln)\nsln.xcode = { }\nsln.xcode.platforms = premake.filterplatforms(sln, premake.action.current().valid_platforms, \"Universal\")\nfor prj in premake.solution.eachproject(sln) do\nlocal cfg = premake.getconfig(prj, prj.configurations[1], sln.xcode.platforms[1])\nlocal node = premake.tree.new(path.getname(cfg.buildtarget.bundlepath))\nnode.cfg = cfg\nnode.id = premake.xcode.newid(node, \"product\")\nnode.targetid = premake.xcode." - "newid(node, \"target\")\nprj.xcode = {}\nprj.xcode.projectnode = node\nend\nend\nfunction xcode.printlist(list, tag)\nif #list > 0 then\n_p(4,'%s = (', tag)\nfor _, item in ipairs(list) do\n_p(5, '\"%s\",', item)\nend\n_p(4,');')\nend\nend\nfunction xcode.Header()\n_p('// !$*UTF8*$!')\n_p('{')\n_p(1,'archiveVersion = 1;')\n_p(1,'classes = {')\n_p(1,'};')\n_p(1,'objectVersion = 45;')\n_p(1,'objects = {')\n_p('')\nend\nfunction xcode.PBXBuildFile(tr)\n_p('/* Begin PBXBuildFile section */')\ntree.traverse(tr, {\nonnode = function(node)\nif node.buildid then\n_p(2,'%s /* %s in %s */ = {isa = PBXBuildFile; fileRef = %s /* %s */; };', \nnode.buildid, node.name, xcode.getbuildcategory(node), node.id, node.name)\nend\nend\n})\n_p('/* End PBXBuildFile section */')\n_p('')\nend\nfunction xcode.PBXContainerItemProxy(tr)\nif #tr.projects.children > 0 then\n_p('/* Begin PBXContainerItemProxy section */')\nfor _, node in ipairs(tr.projects.children) do\n_p(2,'%s /* PBXContainerItemProxy */ = {', node.productproxyid)\n_p(3,'" - "isa = PBXContainerItemProxy;')\n_p(3,'containerPortal = %s /* %s */;', node.id, path.getname(node.path))\n_p(3,'proxyType = 2;')\n_p(3,'remoteGlobalIDString = %s;', node.project.xcode.projectnode.id)\n_p(3,'remoteInfo = \"%s\";', node.project.xcode.projectnode.name)\n_p(2,'};')\n_p(2,'%s /* PBXContainerItemProxy */ = {', node.targetproxyid)\n_p(3,'isa = PBXContainerItemProxy;')\n_p(3,'containerPortal = %s /* %s */;', node.id, path.getname(node.path))\n_p(3,'proxyType = 1;')\n_p(3,'remoteGlobalIDString = %s;', node.project.xcode.projectnode.targetid)\n_p(3,'remoteInfo = \"%s\";', node.project.xcode.projectnode.name)\n_p(2,'};')\nend\n_p('/* End PBXContainerItemProxy section */')\n_p('')\nend\nend\nfunction xcode.PBXFileReference(tr)\n_p('/* Begin PBXFileReference section */')\ntree.traverse(tr, {\nonleaf = function(node)\nif not node.path then\nreturn\nend\nif node.kind == \"product\" then\n_p(2,'%s /* %s */ = {isa = PBXFileReference; explicitFileType = %s; includeInIndex = 0; name = \"%s\"; path = \"%s\"; sour" - "ceTree = BUILT_PRODUCTS_DIR; };',\nnode.id, node.name, xcode.gettargettype(node), node.name, path.getname(node.cfg.buildtarget.bundlepath))\nelseif node.parent.parent == tr.projects then\nlocal relpath = path.getrelative(tr.project.location, node.parent.project.location)\n_p(2,'%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = \"wrapper.pb-project\"; name = \"%s\"; path = \"%s\"; sourceTree = SOURCE_ROOT; };',\nnode.parent.id, node.parent.name, node.parent.name, path.join(relpath, node.parent.name))\nelse\nlocal pth, src\nif xcode.isframework(node.path) then\nif string.find(node.path,'/') then\nif string.find(node.path,'^%.')then\nerror('relative paths are not currently supported for frameworks')\nend\npth = node.path\nelse\npth = \"/System/Library/Frameworks/\" .. node.path\nend\nsrc = \"absolute\"\nelse\nsrc = \"group\"\nif node.parent.isvpath then\npth = node.cfg.name\nelse\npth = tree.getlocalpath(node)\nend\nend\n_p(2,'%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = %s; name = \"%s\";" - " path = \"%s\"; sourceTree = \"<%s>\"; };',\nnode.id, node.name, xcode.getfiletype(node), node.name, pth, src)\nend\nend\n})\n_p('/* End PBXFileReference section */')\n_p('')\nend\nfunction xcode.PBXFrameworksBuildPhase(tr)\n_p('/* Begin PBXFrameworksBuildPhase section */')\n_p(2,'%s /* Frameworks */ = {', tr.products.children[1].fxstageid)\n_p(3,'isa = PBXFrameworksBuildPhase;')\n_p(3,'buildActionMask = 2147483647;')\n_p(3,'files = (')\ntree.traverse(tr.frameworks, {\nonleaf = function(node)\n_p(4,'%s /* %s in Frameworks */,', node.buildid, node.name)\nend\n})\ntree.traverse(tr.projects, {\nonleaf = function(node)\n_p(4,'%s /* %s in Frameworks */,', node.buildid, node.name)\nend\n})\n_p(3,');')\n_p(3,'runOnlyForDeploymentPostprocessing = 0;')\n_p(2,'};')\n_p('/* End PBXFrameworksBuildPhase section */')\n_p('')\nend\nfunction xcode.PBXGroup(tr)\n_p('/* Begin PBXGroup section */')\ntree.traverse(tr, {\nonnode = function(node)\nif (node.path and #node.children == 0) or node.kind == \"vgroup\" then\nreturn\nend\n" - "if node.parent == tr.projects then\n_p(2,'%s /* Products */ = {', node.productgroupid)\nelse\n_p(2,'%s /* %s */ = {', node.id, node.name)\nend\n_p(3,'isa = PBXGroup;')\n_p(3,'children = (')\nfor _, childnode in ipairs(node.children) do\n_p(4,'%s /* %s */,', childnode.id, childnode.name)\nend\n_p(3,');')\nif node.parent == tr.projects then\n_p(3,'name = Products;')\nelse\n_p(3,'name = \"%s\";', node.name)\nif node.path and not node.isvpath then\nlocal p = node.path\nif node.parent.path then\np = path.getrelative(node.parent.path, node.path)\nend\n_p(3,'path = \"%s\";', p)\nend\nend\n_p(3,'sourceTree = \"\";')\n_p(2,'};')\nend\n}, true)\n_p('/* End PBXGroup section */')\n_p('')\nend\nfunction xcode.PBXNativeTarget(tr)\n_p('/* Begin PBXNativeTarget section */')\nfor _, node in ipairs(tr.products.children) do\nlocal name = tr.project.name\n_p(2,'%s /* %s */ = {', node.targetid, name)\n_p(3,'isa = PBXNativeTarget;')\n_p(3,'buildConfigurationList = %s /* Build configuration list for PBXNativeTarget \"%s\" */;" - "', node.cfgsection, name)\n_p(3,'buildPhases = (')\nif #tr.project.prebuildcommands > 0 then\n_p(4,'9607AE1010C857E500CD1376 /* Prebuild */,')\nend\n_p(4,'%s /* Resources */,', node.resstageid)\n_p(4,'%s /* Sources */,', node.sourcesid)\nif #tr.project.prelinkcommands > 0 then\n_p(4,'9607AE3510C85E7E00CD1376 /* Prelink */,')\nend\n_p(4,'%s /* Frameworks */,', node.fxstageid)\nif #tr.project.postbuildcommands > 0 then\n_p(4,'9607AE3710C85E8F00CD1376 /* Postbuild */,')\nend\n_p(3,');')\n_p(3,'buildRules = (')\n_p(3,');')\n_p(3,'dependencies = (')\nfor _, node in ipairs(tr.projects.children) do\n_p(4,'%s /* PBXTargetDependency */,', node.targetdependid)\nend\n_p(3,');')\n_p(3,'name = \"%s\";', name)\nlocal p\nif node.cfg.kind == \"ConsoleApp\" then\np = \"$(HOME)/bin\"\nelseif node.cfg.kind == \"WindowedApp\" then\np = \"$(HOME)/Applications\"\nend\nif p then\n_p(3,'productInstallPath = \"%s\";', p)\nend\n_p(3,'productName = \"%s\";', name)\n_p(3,'productReference = %s /* %s */;', node.id, node.name)\n_p(3,'produ" - "ctType = \"%s\";', xcode.getproducttype(node))\n_p(2,'};')\nend\n_p('/* End PBXNativeTarget section */')\n_p('')\nend\nfunction xcode.PBXProject(tr)\n_p('/* Begin PBXProject section */')\n_p(2,'08FB7793FE84155DC02AAC07 /* Project object */ = {')\n_p(3,'isa = PBXProject;')\n_p(3,'buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject \"%s\" */;', tr.name)\n_p(3,'compatibilityVersion = \"Xcode 3.2\";')\n_p(3,'hasScannedForEncodings = 1;')\n_p(3,'mainGroup = %s /* %s */;', tr.id, tr.name)\n_p(3,'projectDirPath = \"\";')\nif #tr.projects.children > 0 then\n_p(3,'projectReferences = (')\nfor _, node in ipairs(tr.projects.children) do\n_p(4,'{')\n_p(5,'ProductGroup = %s /* Products */;', node.productgroupid)\n_p(5,'ProjectRef = %s /* %s */;', node.id, path.getname(node.path))\n_p(4,'},')\nend\n_p(3,');')\nend\n_p(3,'projectRoot = \"\";')\n_p(3,'targets = (')\nfor _, node in ipairs(tr.products.children) do\n_p(4,'%s /* %s */,', node.targetid, node.name)\nend\n_p(3,');')\n_p(2,'};" - "')\n_p('/* End PBXProject section */')\n_p('')\nend\nfunction xcode.PBXReferenceProxy(tr)\nif #tr.projects.children > 0 then\n_p('/* Begin PBXReferenceProxy section */')\ntree.traverse(tr.projects, {\nonleaf = function(node)\n_p(2,'%s /* %s */ = {', node.id, node.name)\n_p(3,'isa = PBXReferenceProxy;')\n_p(3,'fileType = %s;', xcode.gettargettype(node))\n_p(3,'path = \"%s\";', node.path)\n_p(3,'remoteRef = %s /* PBXContainerItemProxy */;', node.parent.productproxyid)\n_p(3,'sourceTree = BUILT_PRODUCTS_DIR;')\n_p(2,'};')\nend\n})\n_p('/* End PBXReferenceProxy section */')\n_p('')\nend\nend\nfunction xcode.PBXResourcesBuildPhase(tr)\n_p('/* Begin PBXResourcesBuildPhase section */')\nfor _, target in ipairs(tr.products.children) do\n_p(2,'%s /* Resources */ = {', target.resstageid)\n_p(3,'isa = PBXResourcesBuildPhase;')\n_p(3,'buildActionMask = 2147483647;')\n_p(3,'files = (')\ntree.traverse(tr, {\nonnode = function(node)\nif xcode.getbuildcategory(node) == \"Resources\" then\n_p(4,'%s /* %s in Resources */,', nod" - "e.buildid, node.name)\nend\nend\n})\n_p(3,');')\n_p(3,'runOnlyForDeploymentPostprocessing = 0;')\n_p(2,'};')\nend\n_p('/* End PBXResourcesBuildPhase section */')\n_p('')\nend\nfunction xcode.PBXShellScriptBuildPhase(tr)\nlocal wrapperWritten = false\nlocal function doblock(id, name, which)\nlocal prjcmds = tr.project[which]\nlocal commands = table.join(prjcmds, {})\nfor _, cfg in ipairs(tr.configs) do\nlocal cfgcmds = cfg[which]\nif #cfgcmds > #prjcmds then\ntable.insert(commands, 'if [ \"${CONFIGURATION}\" = \"' .. xcode.getconfigname(cfg) .. '\" ]; then')\nfor i = #prjcmds + 1, #cfgcmds do\ntable.insert(commands, cfgcmds[i])\nend\ntable.insert(commands, 'fi')\nend\nend\nif #commands > 0 then\nif not wrapperWritten then\n_p('/* Begin PBXShellScriptBuildPhase section */')\nwrapperWritten = true\nend\n_p(2,'%s /* %s */ = {', id, name)\n_p(3,'isa = PBXShellScriptBuildPhase;')\n_p(3,'buildActionMask = 2147483647;')\n_p(3,'files = (')\n_p(3,');')\n_p(3,'inputPaths = (');\n_p(3,');');\n_p(3,'name = %s;', name);\n_p" - "(3,'outputPaths = (');\n_p(3,');');\n_p(3,'runOnlyForDeploymentPostprocessing = 0;');\n_p(3,'shellPath = /bin/sh;');\n_p(3,'shellScript = \"%s\";', table.concat(commands, \"\\\\n\"):gsub('\"', '\\\\\"'))\n_p(2,'};')\nend\nend\ndoblock(\"9607AE1010C857E500CD1376\", \"Prebuild\", \"prebuildcommands\")\ndoblock(\"9607AE3510C85E7E00CD1376\", \"Prelink\", \"prelinkcommands\")\ndoblock(\"9607AE3710C85E8F00CD1376\", \"Postbuild\", \"postbuildcommands\")\nif wrapperWritten then\n_p('/* End PBXShellScriptBuildPhase section */')\nend\nend\nfunction xcode.PBXSourcesBuildPhase(tr)\n_p('/* Begin PBXSourcesBuildPhase section */')\nfor _, target in ipairs(tr.products.children) do\n_p(2,'%s /* Sources */ = {', target.sourcesid)\n_p(3,'isa = PBXSourcesBuildPhase;')\n_p(3,'buildActionMask = 2147483647;')\n_p(3,'files = (')\ntree.traverse(tr, {\nonleaf = function(node)\nif xcode.getbuildcategory(node) == \"Sources\" then\n_p(4,'%s /* %s in Sources */,', node.buildid, node.name)\nend\nend\n})\n_p(3,');')\n_p(3,'runOnlyForDeployme" - "ntPostprocessing = 0;')\n_p(2,'};')\nend\n_p('/* End PBXSourcesBuildPhase section */')\n_p('')\nend\nfunction xcode.PBXVariantGroup(tr)\n_p('/* Begin PBXVariantGroup section */')\ntree.traverse(tr, {\nonbranch = function(node)\nif node.kind == \"vgroup\" then\n_p(2,'%s /* %s */ = {', node.id, node.name)\n_p(3,'isa = PBXVariantGroup;')\n_p(3,'children = (')\nfor _, lang in ipairs(node.children) do\n_p(4,'%s /* %s */,', lang.id, lang.name)\nend\n_p(3,');')\n_p(3,'name = %s;', node.name)\n_p(3,'sourceTree = \"\";')\n_p(2,'};')\nend\nend\n})\n_p('/* End PBXVariantGroup section */')\n_p('')\nend\nfunction xcode.PBXTargetDependency(tr)\nif #tr.projects.children > 0 then\n_p('/* Begin PBXTargetDependency section */')\ntree.traverse(tr.projects, {\nonleaf = function(node)\n_p(2,'%s /* PBXTargetDependency */ = {', node.parent.targetdependid)\n_p(3,'isa = PBXTargetDependency;')\n_p(3,'name = \"%s\";', node.name)\n_p(3,'targetProxy = %s /* PBXContainerItemProxy */;', node.parent.targetproxyid)\n_p(2,'};')\nend\n})" - "\n_p('/* End PBXTargetDependency section */')\n_p('')\nend\nend\nfunction xcode.XCBuildConfiguration_Target(tr, target, cfg)\nlocal cfgname = xcode.getconfigname(cfg)\n_p(2,'%s /* %s */ = {', cfg.xcode.targetid, cfgname)\n_p(3,'isa = XCBuildConfiguration;')\n_p(3,'buildSettings = {')\n_p(4,'ALWAYS_SEARCH_USER_PATHS = NO;')\nif not cfg.flags.Symbols then\n_p(4,'DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\";')\nend\nif cfg.kind ~= \"StaticLib\" and cfg.buildtarget.prefix ~= \"\" then\n_p(4,'EXECUTABLE_PREFIX = %s;', cfg.buildtarget.prefix)\nend\nlocal outdir = path.getdirectory(cfg.buildtarget.bundlepath)\nif outdir ~= \".\" then\n_p(4,'CONFIGURATION_BUILD_DIR = %s;', outdir)\nend\n_p(4,'GCC_DYNAMIC_NO_PIC = NO;')\n_p(4,'GCC_MODEL_TUNING = G5;')\nif tr.infoplist then\n_p(4,'INFOPLIST_FILE = \"%s\";', tr.infoplist.path)\nend\ninstallpaths = {\nConsoleApp = '/usr/local/bin',\nWindowedApp = '\"$(HOME)/Applications\"',\nSharedLib = '/usr/local/lib',\nStaticLib = '/usr/local/lib',\n}\n_p(4,'INSTALL_PATH = %s;', inst" - "allpaths[cfg.kind])\n_p(4,'PRODUCT_NAME = \"%s\";', cfg.buildtarget.basename)\n_p(3,'};')\n_p(3,'name = \"%s\";', cfgname)\n_p(2,'};')\nend\nfunction xcode.XCBuildConfiguration_Project(tr, cfg)\nlocal cfgname = xcode.getconfigname(cfg)\n_p(2,'%s /* %s */ = {', cfg.xcode.projectid, cfgname)\n_p(3,'isa = XCBuildConfiguration;')\n_p(3,'buildSettings = {')\nlocal archs = {\nNative = \"$(NATIVE_ARCH_ACTUAL)\",\nx32 = \"i386\",\nx64 = \"x86_64\",\nUniversal32 = \"$(ARCHS_STANDARD_32_BIT)\",\nUniversal64 = \"$(ARCHS_STANDARD_64_BIT)\",\nUniversal = \"$(ARCHS_STANDARD_32_64_BIT)\",\n}\n_p(4,'ARCHS = \"%s\";', archs[cfg.platform])\nlocal targetdir = path.getdirectory(cfg.buildtarget.bundlepath)\nif targetdir ~= \".\" then\n_p(4,'CONFIGURATION_BUILD_DIR = \"$(SYMROOT)\";');\nend\n_p(4,'CONFIGURATION_TEMP_DIR = \"$(OBJROOT)\";')\nif cfg.flags.Symbols then\n_p(4,'COPY_PHASE_STRIP = NO;')\nend\n_p(4,'GCC_C_LANGUAGE_STANDARD = gnu99;')\nif cfg.flags.NoExceptions then\n_p(4,'GCC_ENABLE_CPP_EXCEPTIONS = NO;')\nend\nif c" - "fg.flags.NoRTTI then\n_p(4,'GCC_ENABLE_CPP_RTTI = NO;')\nend\nif _ACTION ~= \"xcode4\" and cfg.flags.Symbols and not cfg.flags.NoEditAndContinue then\n_p(4,'GCC_ENABLE_FIX_AND_CONTINUE = YES;')\nend\nif cfg.flags.NoExceptions then\n_p(4,'GCC_ENABLE_OBJC_EXCEPTIONS = NO;')\nend\nif cfg.flags.Optimize or cfg.flags.OptimizeSize then\n_p(4,'GCC_OPTIMIZATION_LEVEL = s;')\nelseif cfg.flags.OptimizeSpeed then\n_p(4,'GCC_OPTIMIZATION_LEVEL = 3;')\nelse\n_p(4,'GCC_OPTIMIZATION_LEVEL = 0;')\nend\nif cfg.pchheader and not cfg.flags.NoPCH then\n_p(4,'GCC_PRECOMPILE_PREFIX_HEADER = YES;')\n_p(4,'GCC_PREFIX_HEADER = \"%s\";', cfg.pchheader)\nend\nxcode.printlist(cfg.defines, 'GCC_PREPROCESSOR_DEFINITIONS')\n_p(4,'GCC_SYMBOLS_PRIVATE_EXTERN = NO;')\nif cfg.flags.FatalWarnings then\n_p(4,'GCC_TREAT_WARNINGS_AS_ERRORS = YES;')\nend\n_p(4,'GCC_WARN_ABOUT_RETURN_TYPE = YES;')\n_p(4,'GCC_WARN_UNUSED_VARIABLE = YES;')\nxcode.printlist(cfg.includedirs, 'HEADER_SEARCH_PATHS')\nxcode.printlist(cfg.libdirs, 'LIBRARY_SEARCH_PATHS')\n_p" - "(4,'OBJROOT = \"%s\";', cfg.objectsdir)\n_p(4,'ONLY_ACTIVE_ARCH = %s;',iif(premake.config.isdebugbuild(cfg),'YES','NO'))\nlocal checks = {\n[\"-ffast-math\"] = cfg.flags.FloatFast,\n[\"-ffloat-store\"] = cfg.flags.FloatStrict,\n[\"-fomit-frame-pointer\"] = cfg.flags.NoFramePointer,\n}\nlocal flags = { }\nfor flag, check in pairs(checks) do\nif check then\ntable.insert(flags, flag)\nend\nend\nxcode.printlist(table.join(flags, cfg.buildoptions), 'OTHER_CFLAGS')\nflags = { }\nfor _, lib in ipairs(premake.getlinks(cfg, \"system\")) do\nif not xcode.isframework(lib) then\ntable.insert(flags, \"-l\" .. lib)\nend\nend\nflags = table.join(flags, cfg.linkoptions)\nxcode.printlist(flags, 'OTHER_LDFLAGS')\nif cfg.flags.StaticRuntime then\n_p(4,'STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = static;')\nend\nif targetdir ~= \".\" then\n_p(4,'SYMROOT = \"%s\";', targetdir)\nend\nif cfg.flags.ExtraWarnings then\n_p(4,'WARNING_CFLAGS = \"-Wall\";')\nend\n_p(3,'};')\n_p(3,'name = \"%s\";', cfgname)\n_p(2,'};')\nend\nfunct" - "ion xcode.XCBuildConfiguration(tr)\n_p('/* Begin XCBuildConfiguration section */')\nfor _, target in ipairs(tr.products.children) do\nfor _, cfg in ipairs(tr.configs) do\nxcode.XCBuildConfiguration_Target(tr, target, cfg)\nend\nend\nfor _, cfg in ipairs(tr.configs) do\nxcode.XCBuildConfiguration_Project(tr, cfg)\nend\n_p('/* End XCBuildConfiguration section */')\n_p('')\nend\nfunction xcode.XCBuildConfigurationList(tr)\nlocal sln = tr.project.solution\n_p('/* Begin XCConfigurationList section */')\nfor _, target in ipairs(tr.products.children) do\n_p(2,'%s /* Build configuration list for PBXNativeTarget \"%s\" */ = {', target.cfgsection, target.name)\n_p(3,'isa = XCConfigurationList;')\n_p(3,'buildConfigurations = (')\nfor _, cfg in ipairs(tr.configs) do\n_p(4,'%s /* %s */,', cfg.xcode.targetid, xcode.getconfigname(cfg))\nend\n_p(3,');')\n_p(3,'defaultConfigurationIsVisible = 0;')\n_p(3,'defaultConfigurationName = \"%s\";', xcode.getconfigname(tr.configs[1]))\n_p(2,'};')\nend\n_p(2,'1DEB928908733DD80010E9CD /*" - " Build configuration list for PBXProject \"%s\" */ = {', tr.name)\n_p(3,'isa = XCConfigurationList;')\n_p(3,'buildConfigurations = (')\nfor _, cfg in ipairs(tr.configs) do\n_p(4,'%s /* %s */,', cfg.xcode.projectid, xcode.getconfigname(cfg))\nend\n_p(3,');')\n_p(3,'defaultConfigurationIsVisible = 0;')\n_p(3,'defaultConfigurationName = \"%s\";', xcode.getconfigname(tr.configs[1]))\n_p(2,'};')\n_p('/* End XCConfigurationList section */')\n_p('')\nend\nfunction xcode.Footer()\n_p(1,'};')\n_p('\\trootObject = 08FB7793FE84155DC02AAC07 /* Project object */;')\n_p('}')\nend\n", - - /* actions/xcode/xcode_project.lua */ - "local xcode = premake.xcode\nlocal tree = premake.tree\nfunction xcode.buildprjtree(prj)\nlocal tr = premake.project.buildsourcetree(prj)\ntr.configs = {}\nfor _, cfgname in ipairs(prj.solution.configurations) do\nfor _, platform in ipairs(prj.solution.xcode.platforms) do\nlocal cfg = premake.getconfig(prj, cfgname, platform)\ncfg.xcode = {}\ncfg.xcode.targetid = xcode.newid(prj.xcode.projectnode, cfgname)\ncfg.xcode.projectid = xcode.newid(tr, cfgname)\ntable.insert(tr.configs, cfg)\nend\nend\ntree.traverse(tr, {\nonbranch = function(node)\nif path.getextension(node.name) == \".lproj\" then\nlocal lang = path.getbasename(node.name) -- \"English\", \"French\", etc.\nfor _, filenode in ipairs(node.children) do\nlocal grpnode = node.parent.children[filenode.name]\nif not grpnode then\ngrpnode = tree.insert(node.parent, tree.new(filenode.name))\ngrpnode.kind = \"vgroup\"\nend\nfilenode.name = path.getbasename(lang)\ntree.insert(grpnode, filenode)\nend\ntree.remove(node)\nend\nend\n})\ntr.frameworks = tree.new(\"" - "Frameworks\")\nfor cfg in premake.eachconfig(prj) do\nfor _, link in ipairs(premake.getlinks(cfg, \"system\", \"fullpath\")) do\nlocal name = path.getname(link)\nif xcode.isframework(name) and not tr.frameworks.children[name] then\nnode = tree.insert(tr.frameworks, tree.new(name))\nnode.path = link\nend\nend\nend\nif #tr.frameworks.children > 0 then \ntree.insert(tr, tr.frameworks)\nend\ntr.products = tree.insert(tr, tree.new(\"Products\"))\ntr.projects = tree.new(\"Projects\")\nfor _, dep in ipairs(premake.getdependencies(prj, \"sibling\", \"object\")) do\nlocal xcpath = xcode.getxcodeprojname(dep)\nlocal xcnode = tree.insert(tr.projects, tree.new(path.getname(xcpath)))\nxcnode.path = xcpath\nxcnode.project = dep\nxcnode.productgroupid = xcode.newid(xcnode, \"prodgrp\")\nxcnode.productproxyid = xcode.newid(xcnode, \"prodprox\")\nxcnode.targetproxyid = xcode.newid(xcnode, \"targprox\")\nxcnode.targetdependid = xcode.newid(xcnode, \"targdep\")\nlocal cfg = premake.getconfig(dep, prj.configurations[1])\nnode = " - "tree.insert(xcnode, tree.new(cfg.linktarget.name))\nnode.path = cfg.linktarget.fullpath\nnode.cfg = cfg\nend\nif #tr.projects.children > 0 then\ntree.insert(tr, tr.projects)\nend\ntree.traverse(tr, {\nonnode = function(node)\nnode.id = xcode.newid(node)\nif xcode.getbuildcategory(node) then\nnode.buildid = xcode.newid(node, \"build\")\nend\nif string.endswith(node.name, \"Info.plist\") then\ntr.infoplist = node\nend\nend\n}, true)\nnode = tree.insert(tr.products, prj.xcode.projectnode)\nnode.kind = \"product\"\nnode.path = node.cfg.buildtarget.fullpath\nnode.cfgsection = xcode.newid(node, \"cfg\")\nnode.resstageid = xcode.newid(node, \"rez\")\nnode.sourcesid = xcode.newid(node, \"src\")\nnode.fxstageid = xcode.newid(node, \"fxs\")\nreturn tr\nend\nfunction premake.xcode.project(prj)\nlocal tr = xcode.buildprjtree(prj)\nxcode.Header(tr)\nxcode.PBXBuildFile(tr)\nxcode.PBXContainerItemProxy(tr)\nxcode.PBXFileReference(tr)\nxcode.PBXFrameworksBuildPhase(tr)\nxcode.PBXGroup(tr)\nxcode.PBXNativeTarget(tr)\nxcode.P" - "BXProject(tr)\nxcode.PBXReferenceProxy(tr)\nxcode.PBXResourcesBuildPhase(tr)\nxcode.PBXShellScriptBuildPhase(tr)\nxcode.PBXSourcesBuildPhase(tr)\nxcode.PBXVariantGroup(tr)\nxcode.PBXTargetDependency(tr)\nxcode.XCBuildConfiguration(tr)\nxcode.XCBuildConfigurationList(tr)\nxcode.Footer(tr)\nend\n", - - /* actions/xcode/xcode4_workspace.lua */ - "premake.xcode4 = {}\nlocal xcode4 = premake.xcode4\nfunction xcode4.workspace_head()\n_p('')\n_p('')\nend\nfunction xcode4.workspace_tail()\n_p('')\nend\nfunction xcode4.workspace_file_ref(prj)\nlocal projpath = path.getrelative(prj.solution.location, prj.location)\nif projpath == '.' then projpath = '' \nelse projpath = projpath ..'/' \nend\n_p(1,'',projpath .. prj.name .. '.xcodeproj')\n_p(1,'')\nend\nfunction xcode4.workspace_generate(sln)\npremake.xcode.preparesolution(sln)\nxcode4.workspace_head()\nfor prj in premake.solution.eachproject(sln) do\nxcode4.workspace_file_ref(prj)\nend\nxcode4.workspace_tail()\nend\n", - - /* actions/clean/_clean.lua */ - "premake.clean = { }\nfunction premake.clean.directory(obj, pattern)\nlocal fname = premake.project.getfilename(obj, pattern)\nos.rmdir(fname)\nend\nfunction premake.clean.file(obj, pattern)\nlocal fname = premake.project.getfilename(obj, pattern)\nos.remove(fname)\nend\nnewaction {\ntrigger = \"clean\",\ndescription = \"Remove all binaries and generated files\",\nonsolution = function(sln)\nfor action in premake.action.each() do\nif action.oncleansolution then\naction.oncleansolution(sln)\nend\nend\nend,\nonproject = function(prj)\nfor action in premake.action.each() do\nif action.oncleanproject then\naction.oncleanproject(prj)\nend\nend\nif (prj.objectsdir) then\npremake.clean.directory(prj, prj.objectsdir)\nend\nlocal platforms = prj.solution.platforms or { }\nif not table.contains(platforms, \"Native\") then\nplatforms = table.join(platforms, { \"Native\" })\nend\nfor _, platform in ipairs(platforms) do\nfor cfg in premake.eachconfig(prj, platform) do\npremake.clean.directory(prj, cfg.objectsdir)\nprema" - "ke.clean.file(prj, premake.gettarget(cfg, \"build\", \"posix\", \"windows\", \"windows\").fullpath)\npremake.clean.file(prj, premake.gettarget(cfg, \"build\", \"posix\", \"posix\", \"linux\").fullpath)\npremake.clean.file(prj, premake.gettarget(cfg, \"build\", \"posix\", \"posix\", \"macosx\").fullpath)\npremake.clean.file(prj, premake.gettarget(cfg, \"build\", \"posix\", \"PS3\", \"windows\").fullpath)\nif cfg.kind == \"WindowedApp\" then\npremake.clean.directory(prj, premake.gettarget(cfg, \"build\", \"posix\", \"posix\", \"linux\").fullpath .. \".app\")\nend\npremake.clean.file(prj, premake.gettarget(cfg, \"link\", \"windows\", \"windows\", \"windows\").fullpath)\npremake.clean.file(prj, premake.gettarget(cfg, \"link\", \"posix\", \"posix\", \"linux\").fullpath)\nlocal target = path.join(premake.project.getfilename(prj, cfg.buildtarget.directory), cfg.buildtarget.basename)\nfor action in premake.action.each() do\nif action.oncleantarget then\naction.oncleantarget(target)\nend\nend\nend\nend\nend\n}\n", - - /* _premake_main.lua */ - "local scriptfile = \"premake4.lua\"\nlocal shorthelp = \"Type 'premake4 --help' for help\"\nlocal versionhelp = \"premake4 (Premake Build Script Generator) %s\"\nlocal function injectplatform(platform)\nif not platform then return true end\nplatform = premake.checkvalue(platform, premake.fields.platforms.allowed)\nfor sln in premake.solution.each() do\nlocal platforms = sln.platforms or { }\nif #platforms == 0 then\ntable.insert(platforms, \"Native\")\nend\nif not table.contains(platforms, \"Native\") then\nreturn false, sln.name .. \" does not target native platform\\nNative platform settings are required for the --platform feature.\"\nend\nif not table.contains(platforms, platform) then\ntable.insert(platforms, platform)\nend\nsln.platforms = platforms\nend\nreturn true\nend\nfunction _premake_main(scriptpath)\nif (scriptpath) then\nlocal scripts = dofile(scriptpath .. \"/_manifest.lua\")\nfor _,v in ipairs(scripts) do\ndofile(scriptpath .. \"/\" .. v)\nend\nend\npremake.action.set(_ACTION)\nmath.r" - "andomseed(os.time())\nlocal fname = _OPTIONS[\"file\"] or scriptfile\nif (os.isfile(fname)) then\ndofile(fname)\nend\nif (_OPTIONS[\"version\"]) then\nprintf(versionhelp, _PREMAKE_VERSION)\nreturn 1\nend\nif (_OPTIONS[\"help\"]) then\npremake.showhelp()\nreturn 1\nend\nif (not _ACTION) then\nprint(shorthelp)\nreturn 1\nend\nif (not os.isfile(fname)) then\nerror(\"No Premake script (\"..scriptfile..\") found!\", 2)\nend\naction = premake.action.current()\nif (not action) then\nerror(\"Error: no such action '\" .. _ACTION .. \"'\", 0)\nend\nok, err = premake.option.validate(_OPTIONS)\nif (not ok) then error(\"Error: \" .. err, 0) end\nok, err = premake.checktools()\nif (not ok) then error(\"Error: \" .. err, 0) end\nok, err = injectplatform(_OPTIONS[\"platform\"])\nif (not ok) then error(\"Error: \" .. err, 0) end\nprint(\"Building configurations...\")\npremake.buildconfigs()\nok, err = premake.checkprojects()\nif (not ok) then error(\"Error: \" .. err, 0) end\nprintf(\"Running action '%s'...\", action.trigger)" - "\npremake.action.call(action.trigger)\nprint(\"Done.\")\nreturn 0\nend\n", - - 0 -}; Index: ps/trunk/build/premake/premake4/src/host/string_endswith.c =================================================================== --- ps/trunk/build/premake/premake4/src/host/string_endswith.c +++ ps/trunk/build/premake/premake4/src/host/string_endswith.c @@ -1,28 +0,0 @@ -/** - * \file string_endswith.c - * \brief Determines if a string ends with the given sequence. - * \author Copyright (c) 2002-2009 Jason Perkins and the Premake project - */ - -#include "premake.h" -#include - - -int string_endswith(lua_State* L) -{ - const char* haystack = luaL_optstring(L, 1, NULL); - const char* needle = luaL_optstring(L, 2, NULL); - - if (haystack && needle) - { - int hlen = strlen(haystack); - int nlen = strlen(needle); - if (hlen >= nlen) - { - lua_pushboolean(L, strcmp(haystack + hlen - nlen, needle) == 0); - return 1; - } - } - - return 0; -} Index: ps/trunk/build/premake/premake4/src/tools/dotnet.lua =================================================================== --- ps/trunk/build/premake/premake4/src/tools/dotnet.lua +++ ps/trunk/build/premake/premake4/src/tools/dotnet.lua @@ -1,91 +0,0 @@ --- --- dotnet.lua --- Interface for the C# compilers, all of which are flag compatible. --- Copyright (c) 2002-2009 Jason Perkins and the Premake project --- - - - premake.dotnet = { } - premake.dotnet.namestyle = "windows" - - --- --- Translation of Premake flags into CSC flags --- - - local flags = - { - FatalWarning = "/warnaserror", - Optimize = "/optimize", - OptimizeSize = "/optimize", - OptimizeSpeed = "/optimize", - Symbols = "/debug", - Unsafe = "/unsafe" - } - - --- --- Return the default build action for a given file, based on the file extension. --- - - function premake.dotnet.getbuildaction(fcfg) - local ext = path.getextension(fcfg.name):lower() - if fcfg.buildaction == "Compile" or ext == ".cs" then - return "Compile" - elseif fcfg.buildaction == "Embed" or ext == ".resx" then - return "EmbeddedResource" - elseif fcfg.buildaction == "Copy" or ext == ".asax" or ext == ".aspx" then - return "Content" - else - return "None" - end - end - - - --- --- Returns the compiler filename (they all use the same arguments) --- - - function premake.dotnet.getcompilervar(cfg) - if (_OPTIONS.dotnet == "msnet") then - return "csc" - elseif (_OPTIONS.dotnet == "mono") then - if (cfg.framework <= "1.1") then - return "mcs" - elseif (cfg.framework >= "4.0") then - return "dmcs" - else - return "gmcs" - end - else - return "cscc" - end - end - - - --- --- Returns a list of compiler flags, based on the supplied configuration. --- - - function premake.dotnet.getflags(cfg) - local result = table.translate(cfg.flags, flags) - return result - end - - - --- --- Translates the Premake kind into the CSC kind string. --- - - function premake.dotnet.getkind(cfg) - if (cfg.kind == "ConsoleApp") then - return "Exe" - elseif (cfg.kind == "WindowedApp") then - return "WinExe" - elseif (cfg.kind == "SharedLib") then - return "Library" - end - end \ No newline at end of file Index: ps/trunk/build/premake/premake4/src/tools/gcc.lua =================================================================== --- ps/trunk/build/premake/premake4/src/tools/gcc.lua +++ ps/trunk/build/premake/premake4/src/tools/gcc.lua @@ -1,227 +0,0 @@ --- --- gcc.lua --- Provides GCC-specific configuration strings. --- Copyright (c) 2002-2008 Jason Perkins and the Premake project --- - - - premake.gcc = { } - - --- --- Set default tools --- - - premake.gcc.cc = "gcc" - premake.gcc.cxx = "g++" - premake.gcc.ar = "ar" - - --- --- Translation of Premake flags into GCC flags --- - - local cflags = - { - EnableSSE = "-msse", - EnableSSE2 = "-msse2", - ExtraWarnings = "-Wall", - FatalWarnings = "-Werror", - FloatFast = "-ffast-math", - FloatStrict = "-ffloat-store", - NoFramePointer = "-fomit-frame-pointer", - Optimize = "-O2", - OptimizeSize = "-Os", - OptimizeSpeed = "-O3", - Symbols = "-g", - } - - local cxxflags = - { - EnableSSE = "-msse", - EnableSSE2 = "-msse2", - ExtraWarnings = "-Wall", - FatalWarnings = "-Werror", - FloatFast = "-ffast-math", - FloatStrict = "-ffloat-store", - NoFramePointer = "-fomit-frame-pointer", - Optimize = "-O2", - OptimizeSize = "-Os", - OptimizeSpeed = "-O3", - Symbols = "-g", - NoExceptions = "-fno-exceptions", - NoRTTI = "-fno-rtti", - } - - --- --- Map platforms to flags --- - - premake.gcc.platforms = - { - Native = { - cppflags = "-MMD -MP", - }, - x32 = { - cppflags = "-MMD -MP", - flags = "-m32", - ldflags = "-L/usr/lib32", - }, - x64 = { - cppflags = "-MMD -MP", - flags = "-m64", - ldflags = "-L/usr/lib64", - }, - Universal = { - cppflags = "", - flags = "-arch i386 -arch x86_64 -arch ppc -arch ppc64", - }, - Universal32 = { - cppflags = "", - flags = "-arch i386 -arch ppc", - }, - Universal64 = { - cppflags = "", - flags = "-arch x86_64 -arch ppc64", - }, - PS3 = { - cc = "ppu-lv2-g++", - cxx = "ppu-lv2-g++", - ar = "ppu-lv2-ar", - cppflags = "-MMD -MP", - } - } - - local platforms = premake.gcc.platforms - - --- --- Returns a list of compiler flags, based on the supplied configuration. --- - - function premake.gcc.getcppflags(cfg) - local result = { } - table.insert(result, platforms[cfg.platform].cppflags) - return result - end - - function premake.gcc.getcflags(cfg) - local result = table.translate(cfg.flags, cflags) - table.insert(result, platforms[cfg.platform].flags) - if cfg.system ~= "windows" and cfg.kind == "SharedLib" then - table.insert(result, "-fPIC") - end - return result - end - - function premake.gcc.getcxxflags(cfg) - local result = table.translate(cfg.flags, cxxflags) - if cfg.system ~= "windows" and cfg.kind == "SharedLib" then - table.insert(result, "-fPIC") - end - return result - end - - - --- --- Returns a list of linker flags, based on the supplied configuration. --- - - function premake.gcc.getldflags(cfg) - local result = { } - - -- OS X has a bug, see http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html - if not cfg.flags.Symbols then - if cfg.system == "macosx" then - table.insert(result, "-Wl,-x") - else - table.insert(result, "-s") - end - end - - if cfg.kind == "SharedLib" then - if cfg.system == "macosx" then - result = table.join(result, { "-dynamiclib", "-flat_namespace" }) - else - table.insert(result, "-shared") - end - - if cfg.system == "windows" and not cfg.flags.NoImportLib then - table.insert(result, '-Wl,--out-implib="' .. cfg.linktarget.fullpath .. '"') - end - end - - if cfg.kind == "WindowedApp" and cfg.system == "windows" then - table.insert(result, "-mwindows") - end - - local platform = platforms[cfg.platform] - table.insert(result, platform.flags) - table.insert(result, platform.ldflags) - - return result - end - - --- --- Return a list of library search paths. Technically part of LDFLAGS but need to --- be separated because of the way Visual Studio calls GCC for the PS3. See bug --- #1729227 for background on why library paths must be split. --- - - function premake.gcc.getlibdirflags(cfg) - local result = { } - for _, value in ipairs(premake.getlinks(cfg, "all", "directory")) do - table.insert(result, '-L' .. _MAKE.esc(value)) - end - return result - end - - - --- --- Returns a list of linker flags for library search directories and library --- names. See bug #1729227 for background on why the path must be split. --- - - function premake.gcc.getlinkflags(cfg) - local result = { } - for _, value in ipairs(premake.getlinks(cfg, "all", "basename")) do - if path.getextension(value) == ".framework" then - table.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value))) - else - table.insert(result, '-l' .. _MAKE.esc(value)) - end - end - return result - end - - - --- --- Decorate defines for the GCC command line. --- - - function premake.gcc.getdefines(defines) - local result = { } - for _,def in ipairs(defines) do - table.insert(result, '-D' .. def) - end - return result - end - - - --- --- Decorate include file search paths for the GCC command line. --- - - function premake.gcc.getincludedirs(includedirs) - local result = { } - for _,dir in ipairs(includedirs) do - table.insert(result, "-I" .. _MAKE.esc(dir)) - end - return result - end Index: ps/trunk/build/premake/premake4/src/tools/msc.lua =================================================================== --- ps/trunk/build/premake/premake4/src/tools/msc.lua +++ ps/trunk/build/premake/premake4/src/tools/msc.lua @@ -1,9 +0,0 @@ --- --- msc.lua --- Interface for the MS C/C++ compiler. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - - premake.msc = { } - premake.msc.namestyle = "windows" Index: ps/trunk/build/premake/premake4/src/tools/ow.lua =================================================================== --- ps/trunk/build/premake/premake4/src/tools/ow.lua +++ ps/trunk/build/premake/premake4/src/tools/ow.lua @@ -1,132 +0,0 @@ --- --- ow.lua --- Provides Open Watcom-specific configuration strings. --- Copyright (c) 2008 Jason Perkins and the Premake project --- - - premake.ow = { } - premake.ow.namestyle = "windows" - - --- --- Set default tools --- - - premake.ow.cc = "WCL386" - premake.ow.cxx = "WCL386" - premake.ow.ar = "ar" - - --- --- Translation of Premake flags into OpenWatcom flags --- - - local cflags = - { - ExtraWarnings = "-wx", - FatalWarning = "-we", - FloatFast = "-omn", - FloatStrict = "-op", - Optimize = "-ox", - OptimizeSize = "-os", - OptimizeSpeed = "-ot", - Symbols = "-d2", - } - - local cxxflags = - { - NoExceptions = "-xd", - NoRTTI = "-xr", - } - - - --- --- No specific platform support yet --- - - premake.ow.platforms = - { - Native = { - flags = "" - }, - } - - - --- --- Returns a list of compiler flags, based on the supplied configuration. --- - - function premake.ow.getcppflags(cfg) - return {} - end - - function premake.ow.getcflags(cfg) - local result = table.translate(cfg.flags, cflags) - if (cfg.flags.Symbols) then - table.insert(result, "-hw") -- Watcom debug format for Watcom debugger - end - return result - end - - function premake.ow.getcxxflags(cfg) - local result = table.translate(cfg.flags, cxxflags) - return result - end - - - --- --- Returns a list of linker flags, based on the supplied configuration. --- - - function premake.ow.getldflags(cfg) - local result = { } - - if (cfg.flags.Symbols) then - table.insert(result, "op symf") - end - - return result - end - - --- --- Returns a list of linker flags for library search directories and --- library names. --- - - function premake.ow.getlinkflags(cfg) - local result = { } - return result - end - - - --- --- Decorate defines for the command line. --- - - function premake.ow.getdefines(defines) - local result = { } - for _,def in ipairs(defines) do - table.insert(result, '-D' .. def) - end - return result - end - - - --- --- Decorate include file search paths for the command line. --- - - function premake.ow.getincludedirs(includedirs) - local result = { } - for _,dir in ipairs(includedirs) do - table.insert(result, '-I "' .. dir .. '"') - end - return result - end - Index: ps/trunk/build/premake/premake4/tests/actions/make/test_make_escaping.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/make/test_make_escaping.lua +++ ps/trunk/build/premake/premake4/tests/actions/make/test_make_escaping.lua @@ -1,30 +0,0 @@ --- --- tests/actions/make/test_make_escaping.lua --- Validate the escaping of literal values in Makefiles. --- Copyright (c) 2010 Jason Perkins and the Premake project --- - - T.make_escaping = { } - local suite = T.make_escaping - - - function suite.Escapes_Spaces() - test.isequal("Program\\ Files", _MAKE.esc("Program Files")) - end - - function suite.Escapes_Backslashes() - test.isequal("Program\\\\Files", _MAKE.esc("Program\\Files")) - end - - function suite.Escapes_Parens() - test.isequal("Debug\\(x86\\)", _MAKE.esc("Debug(x86)")) - end - - function suite.DoesNotEscape_ShellReplacements() - test.isequal("-L$(NVSDKCUDA_ROOT)/C/lib", _MAKE.esc("-L$(NVSDKCUDA_ROOT)/C/lib")) - end - - function suite.CanEscape_ShellReplacementCapturesShortest() - test.isequal("a\\(x\\)b$(ROOT)c\\(y\\)d", _MAKE.esc("a(x)b$(ROOT)c(y)d")) - end - Index: ps/trunk/build/premake/premake4/tests/actions/make/test_make_pch.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/make/test_make_pch.lua +++ ps/trunk/build/premake/premake4/tests/actions/make/test_make_pch.lua @@ -1,92 +0,0 @@ --- --- tests/actions/make/test_make_pch.lua --- Validate the setup for precompiled headers in makefiles. --- Copyright (c) 2010 Jason Perkins and the Premake project --- - - T.make_pch = { } - local suite = T.make_pch - local _ = premake.make.cpp - - --- --- Setup and teardown --- - - local sln, prj, cfg - function suite.setup() - sln, prj = test.createsolution() - end - - local function prepare() - io.capture() - premake.buildconfigs() - cfg = premake.getconfig(prj, "Debug") - end - - --- --- Configuration block tests --- - - function suite.NoConfig_OnNoHeaderSet() - prepare() - _.pchconfig(cfg) - test.capture [[]] - end - - - function suite.NoConfig_OnHeaderAndNoPCHFlag() - pchheader "include/myproject.h" - flags { NoPCH } - prepare() - _.pchconfig(cfg) - test.capture [[]] - end - - - function suite.ConfigBlock_OnPchEnabled() - pchheader "include/myproject.h" - prepare() - _.pchconfig(cfg) - test.capture [[ - PCH = include/myproject.h - GCH = $(OBJDIR)/myproject.h.gch - CPPFLAGS += -I$(OBJDIR) -include $(OBJDIR)/myproject.h - ]] - end - - --- --- Build rule tests --- - - function suite.BuildRules_OnCpp() - pchheader "include/myproject.h" - prepare() - _.pchrules(prj) - test.capture [[ -ifneq (,$(PCH)) -$(GCH): $(PCH) - @echo $(notdir $<) - -$(SILENT) cp $< $(OBJDIR) - $(SILENT) $(CXX) $(CXXFLAGS) -o "$@" -c "$<" -endif - ]] - end - - function suite.BuildRules_OnC() - language "C" - pchheader "include/myproject.h" - prepare() - _.pchrules(prj) - test.capture [[ -ifneq (,$(PCH)) -$(GCH): $(PCH) - @echo $(notdir $<) - -$(SILENT) cp $< $(OBJDIR) - $(SILENT) $(CC) $(CFLAGS) -o "$@" -c "$<" -endif - ]] - end - Index: ps/trunk/build/premake/premake4/tests/actions/test_clean.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/test_clean.lua +++ ps/trunk/build/premake/premake4/tests/actions/test_clean.lua @@ -1,186 +0,0 @@ --- --- tests/actions/test_clean.lua --- Automated test suite for the "clean" action. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.clean = { } - - --- --- Replacement functions for remove() and rmdir() for testing --- - - local os_remove, os_rmdir, cwd - local removed - - local function test_remove(fn) - if not cwd then cwd = os.getcwd() end - table.insert(removed, path.getrelative(cwd, fn)) - end - - --- --- Setup/teardown --- - - local sln - function T.clean.setup() - _ACTION = "clean" - - os_remove = os.remove - os_rmdir = os.rmdir - os.remove = test_remove - os.rmdir = test_remove - removed = {} - - sln = solution "MySolution" - configurations { "Debug", "Release" } - end - - function T.clean.teardown() - os.remove = os_remove - os.rmdir = os_rmdir - end - - local function prepare() - premake.buildconfigs() - premake.action.call("clean") - end - - - --- --- Tests --- - - function T.clean.SolutionFiles() - prepare() - test.contains(removed, "MySolution.sln") - test.contains(removed, "MySolution.suo") - test.contains(removed, "MySolution.ncb") - test.contains(removed, "MySolution.userprefs") - test.contains(removed, "MySolution.usertasks") - test.contains(removed, "MySolution.workspace") - test.contains(removed, "MySolution_wsp.mk") - test.contains(removed, "MySolution.tags") - test.contains(removed, "Makefile") - end - - - function T.clean.CppProjectFiles() - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - prepare() - test.contains(removed, "MyProject.vcproj") - test.contains(removed, "MyProject.pdb") - test.contains(removed, "MyProject.idb") - test.contains(removed, "MyProject.ilk") - test.contains(removed, "MyProject.cbp") - test.contains(removed, "MyProject.depend") - test.contains(removed, "MyProject.layout") - test.contains(removed, "MyProject.mk") - test.contains(removed, "MyProject.list") - test.contains(removed, "MyProject.out") - test.contains(removed, "MyProject.make") - end - - - function T.clean.CsProjectFiles() - prj = project "MyProject" - language "C#" - kind "ConsoleApp" - prepare() - test.contains(removed, "MyProject.csproj") - test.contains(removed, "MyProject.csproj.user") - test.contains(removed, "MyProject.pdb") - test.contains(removed, "MyProject.idb") - test.contains(removed, "MyProject.ilk") - test.contains(removed, "MyProject.make") - end - - - function T.clean.ObjectDirsAndFiles() - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - prepare() - test.contains(removed, "obj") - test.contains(removed, "obj/Debug") - test.contains(removed, "obj/Release") - end - - - function T.clean.CppConsoleAppFiles() - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - prepare() - test.contains(removed, "MyProject") - test.contains(removed, "MyProject.exe") - test.contains(removed, "MyProject.elf") - test.contains(removed, "MyProject.vshost.exe") - test.contains(removed, "MyProject.exe.manifest") - end - - - function T.clean.CppWindowedAppFiles() - prj = project "MyProject" - language "C++" - kind "WindowedApp" - prepare() - test.contains(removed, "MyProject") - test.contains(removed, "MyProject.exe") - test.contains(removed, "MyProject.app") - end - - - function T.clean.CppSharedLibFiles() - prj = project "MyProject" - language "C++" - kind "SharedLib" - prepare() - test.contains(removed, "MyProject.dll") - test.contains(removed, "libMyProject.so") - test.contains(removed, "MyProject.lib") - test.contains(removed, "libMyProject.dylib") - end - - - function T.clean.CppStaticLibFiles() - prj = project "MyProject" - language "C++" - kind "StaticLib" - prepare() - test.contains(removed, "MyProject.lib") - test.contains(removed, "libMyProject.a") - end - - - function T.clean.PlatformObjects() - platforms { "Native", "x32" } - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - prepare() - test.contains(removed, "obj/Debug") - test.contains(removed, "obj/Release") - test.contains(removed, "obj/x32/Debug") - test.contains(removed, "obj/x32/Release") - end - - - function T.clean.CppConsoleAppFiles_OnSuffix() - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - targetsuffix "_x" - prepare() - test.contains(removed, "MyProject_x") - test.contains(removed, "MyProject_x.exe") - test.contains(removed, "MyProject_x.elf") - test.contains(removed, "MyProject_x.vshost.exe") - test.contains(removed, "MyProject_x.exe.manifest") - end - Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2005_csproj.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2005_csproj.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2005_csproj.lua @@ -1,122 +0,0 @@ --- --- tests/actions/test_vs2005_csproj.lua --- Automated test suite for Visual Studio 2005-2008 C# project generation. --- Copyright (c) 2010 Jason Perkins and the Premake project --- - - T.vs2005_csproj = { } - local suite = T.vs2005_csproj - local cs2005 = premake.vstudio.cs2005 - --- --- Configure a solution for testing --- - - local sln, prj - function suite.setup() - _ACTION = "vs2005" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - project "MyProject" - language "C#" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - end - - local function prepare() - io.capture() - premake.buildconfigs() - prj = premake.solution.getproject(sln, 1) - end - - --- --- Project element tests --- - - function suite.projectelement_OnVs2005() - _ACTION = "vs2005" - prepare() - cs2005.projectelement(prj) - test.capture [[ - - ]] - end - - function suite.projectelement_OnVs2008() - _ACTION = "vs2008" - prepare() - cs2005.projectelement(prj) - test.capture [[ - - ]] - end - - --- --- Project settings tests --- - - function suite.projectsettings_OnVs2005() - _ACTION = "vs2005" - prepare() - cs2005.projectsettings(prj) - test.capture [[ - - Debug - AnyCPU - 8.0.50727 - 2.0 - {AE61726D-187C-E440-BD07-2556188A6565} - Exe - Properties - MyProject - MyProject - - ]] - end - - - function suite.projectsettings_OnVs2008() - _ACTION = "vs2008" - prepare() - cs2005.projectsettings(prj) - test.capture [[ - - Debug - AnyCPU - 9.0.21022 - 2.0 - {AE61726D-187C-E440-BD07-2556188A6565} - Exe - Properties - MyProject - MyProject - - ]] - end - - - function suite.projectsettings_OnFrameworkVersion() - _ACTION = "vs2005" - framework "3.0" - prepare() - cs2005.projectsettings(prj) - test.capture [[ - - Debug - AnyCPU - 8.0.50727 - 2.0 - {AE61726D-187C-E440-BD07-2556188A6565} - Exe - Properties - MyProject - MyProject - v3.0 - - ]] - end Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs200x_vcproj.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs200x_vcproj.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs200x_vcproj.lua @@ -1,721 +0,0 @@ --- --- tests/test_vs200x_vcproj.lua --- Automated test suite for Visual Studio 2002-2008 C/C++ project generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.vs200x_vcproj = { } - local suite = T.vs200x_vcproj - local vcproj = premake.vstudio.vcproj - - --- --- Configure a solution for testing --- - - local sln, prj - function suite.setup() - _ACTION = "vs2005" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - project "DotNetProject" -- to test handling of .NET platform in solution - language "C#" - kind "ConsoleApp" - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - end - - local function prepare() - io.capture() - premake.buildconfigs() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - - local cfg = premake.getconfig(sln.projects[2]) - cfg.name = prj.name - cfg.blocks = prj.blocks - prj = cfg - end - - --- --- Make sure I've got the basic layout correct --- - - function suite.BasicLayout() - prepare() - premake.vs200x_vcproj(prj) - test.capture [[ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ]] - end - - --- --- Test the element --- - - function suite.Configuration_OnMFCFlag() - flags { "MFC" } - prepare() - vcproj.Configuration("Debug|Win32", premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- Test multiple platforms --- - - function suite.Platforms_OnMultiplePlatforms() - platforms { "x32", "x64" } - prepare() - - premake.vs200x_vcproj(prj) - local result = io.endcapture() - test.istrue(result:find ' - - - - ]] - end - - - --- --- Test Xbox360 handling --- - - function suite.PlatformsList_OnXbox360() - platforms { "Native", "Xbox360" } - prepare() - premake.vs200x_vcproj_platforms(prj) - test.capture [[ - - - - - ]] - end - - function suite.CompilerBlock_OnXbox360() - platforms { "Xbox360" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug", "Xbox360")) - test.capture [[ - - ]] - end - - --- --- Test PS3 handling --- - - function suite.PlatformsList_OnPS3() - platforms { "Native", "PS3" } - prepare() - premake.vs200x_vcproj_platforms(prj) - test.capture [[ - - - - ]] - end - - function suite.CompilerBlock_OnPS3() - platforms { "PS3" } - flags { "Symbols" } - includedirs { "include/pkg1", "include/pkg2" } - defines { "DEFINE1", "DEFINE2" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool_GCC(premake.getconfig(prj, "Debug", "PS3")) - test.capture [[ - - ]] - end - - function suite.LinkerBlock_OnPS3ConsoleApp() - platforms { "PS3" } - prepare() - premake.vs200x_vcproj_VCLinkerTool_GCC(premake.getconfig(prj, "Debug", "PS3")) - test.capture [[ - - ]] - end - - function suite.LinkerBlock_OnPS3StaticLib() - platforms { "PS3" } - kind "StaticLib" - prepare() - premake.vs200x_vcproj_VCLinkerTool_GCC(premake.getconfig(prj, "Debug", "PS3")) - test.capture [[ - - ]] - end - - function suite.LinkerBlock_OnPS3SharedLink() - platforms { "PS3" } - links { "MyLibrary" } - project "MyLibrary" - language "C++" - kind "SharedLib" - prepare() - premake.vs200x_vcproj_VCLinkerTool_GCC(premake.getconfig(prj, "Debug", "PS3")) - - test.capture [[ - - ]] - end - - --- --- Test manifest file handling. --- - - function suite.VCManifestTool_OnNoManifests() - files { "hello.c", "goodbye.c" } - prepare() - premake.vs200x_vcproj_VCManifestTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - - function suite.VCManifestTool_OnNoManifests() - files { "hello.c", "project1.manifest", "goodbye.c", "project2.manifest" } - prepare() - premake.vs200x_vcproj_VCManifestTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- Test precompiled header handling --- - - function suite.CompilerBlock_OnPCH() - pchheader "source/common.h" - pchsource "source/common.cpp" - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - function suite.Files_OnPCH_OnWindows() - files { "afxwin.cpp" } - pchsource "afxwin.cpp" - prepare() - _VS.files(prj, "afxwin.cpp", "Item", 1) - test.capture [[ - - - - - - - - - ]] - end - - function suite.Files_OnPCH_OnXbox360() - files { "afxwin.cpp" } - pchsource "afxwin.cpp" - platforms { "Xbox360" } - prepare() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - _VS.files(prj, "afxwin.cpp", "Item", 1) - test.capture [[ - - - - - - - - - ]] - end - - --- --- Floating point flag tests --- - - function suite.CompilerBlock_OnFpFast() - flags { "FloatFast" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - function suite.CompilerBlock_OnFpStrict() - flags { "FloatStrict" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- PDB file naming tests --- - - function suite.CompilerBlock_OnTargetName() - targetname "foob" - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- Compilation option tests --- - - function suite.CompilerBlock_OnNoMinimalRebuild() - flags { "Symbols", "NoMinimalRebuild" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- RuntimeLibrary tests --- - - function suite.CompilerBlock_RuntimeLibrary_IsDebug_OnSymbolsNoOptimize() - flags { "Symbols" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - function suite.CompilerBlock_RuntimeLibrary_IsRelease_OnOptimize() - flags { "Symbols", "Optimize" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- C language support --- - - function suite.CompilerBlock_RuntimeLibrary_IsDebug_OnSymbolsNoOptimize() - language "C" - flags { "Symbols" } - prepare() - premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs200x_vcproj_linker.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs200x_vcproj_linker.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs200x_vcproj_linker.lua @@ -1,117 +0,0 @@ --- --- tests/actions/vstudio/test_vs200x_vcproj_linker.lua --- Automated tests for Visual Studio 2002-2008 C/C++ linker block. --- Copyright (c) 2009, 2010 Jason Perkins and the Premake project --- - - T.vs200x_vcproj_linker = { } - local suite = T.vs200x_vcproj_linker - local vcproj = premake.vstudio.vcproj - - --- --- Setup/Teardown --- - - local sln, prj - function suite.setup() - _ACTION = "vs2005" - sln, prj = test.createsolution() - end - - local function prepare() - io.capture() - premake.buildconfigs() - end - - --- --- Test default linker blocks for each target kind --- (ConsoleApp, StaticLib, etc.) --- - - function suite.DefaultLinkerBlock_OnConsoleApp() - kind "ConsoleApp" - prepare() - premake.vs200x_vcproj_VCLinkerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - function suite.DefaultLinkerBlock_OnWindowedApp() - kind "WindowedApp" - prepare() - premake.vs200x_vcproj_VCLinkerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - function suite.DefaultLinkerBlock_OnSharedLib() - kind "SharedLib" - prepare() - premake.vs200x_vcproj_VCLinkerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - function suite.DefaultLinkerBlock_OnStaticLib() - kind "StaticLib" - prepare() - premake.vs200x_vcproj_VCLinkerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - - --- --- linkoptions tests --- - - function suite.AdditionalOptions_OnStaticLib() - kind "StaticLib" - linkoptions { "/ltcg", "/lZ" } - prepare() - premake.vs200x_vcproj_VCLinkerTool(premake.getconfig(prj, "Debug")) - test.capture [[ - - ]] - end - Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_filters.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_filters.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_filters.lua @@ -1,294 +0,0 @@ - T.vs2010_filters = { } - local vs10_filters = T.vs2010_filters - local vs10_helpers = premake.vstudio.vs10_helpers - - - local sln, prj - function vs10_filters.setup() - _ACTION = "vs2010" - sln = solution "MySolution" - configurations { "Debug" } - platforms {} - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - end - - local function get_buffer() - io.capture() - premake.buildconfigs() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - premake.vs2010_vcxproj_filters(prj) - buffer = io.endcapture() - return buffer - end - - function vs10_filters.path_noPath_returnsNil() - local result = vs10_helpers.file_path("foo.h") - test.isequal(nil,result) - end - - function vs10_filters.path_hasOneDirectoryPath_returnsIsFoo() - local path = "foo" - local result = vs10_helpers.file_path(path .."\\foo.h") - test.isequal(path,result) - end - - function vs10_filters.path_hasTwoDirectoryPath_returnsIsFooSlashBar() - local path = "foo\\bar" - local result = vs10_helpers.file_path(path .."\\foo.h") - test.isequal(path,result) - end - - function vs10_filters.path_hasTwoDirectoryPath_returnsIsFooSlashBar_Baz() - local path = "foo\\bar_baz" - local result = vs10_helpers.file_path(path .."\\foo.h") - test.isequal(path,result) - end - - function vs10_filters.path_extensionWithHyphen_returnsIsFoo() - local path = "foo" - local result = vs10_helpers.file_path(path .."\\foo-bar.h") - test.isequal(path,result) - end - - function vs10_filters.path_extensionWithNumber_returnsIs2Foo() - local path = "foo" - local result = vs10_helpers.file_path(path .."\\2foo.h") - test.isequal(path,result) - end - - function vs10_filters.path_hasThreeDirectoryPath_returnsIsFooSlashBarSlashBaz() - local path = "foo\\bar\\baz" - local result = vs10_helpers.file_path(path .."\\foo.h") - test.isequal(path,result) - end - - function vs10_filters.path_hasDotDotSlashDirectoryPath_returnsNil() - local path = ".." - local result = vs10_helpers.file_path(path .."\\foo.h") - test.isequal(nil,result) - end - - function vs10_filters.removeRelativePath_noRelativePath_returnsInput() - local path = "foo.h" - local result = vs10_helpers.remove_relative_path(path) - test.isequal("foo.h",result) - end - - function vs10_filters.removeRelativePath_dotDotSlashFoo_returnsFoo() - local path = "..\\foo" - local result = vs10_helpers.remove_relative_path(path) - test.isequal("foo",result) - end - - function vs10_filters.removeRelativePath_dotDotSlashDotDotSlashFoo_returnsFoo() - local path = "..\\..\\foo" - local result = vs10_helpers.remove_relative_path(path) - test.isequal("foo",result) - end - - function vs10_filters.removeRelativePath_DotSlashFoo_returnsFoo() - local path = ".\\foo" - local result = vs10_helpers.remove_relative_path(path) - test.isequal("foo",result) - end - - function vs10_filters.listOfDirectories_oneDirectory_returnsSizeIsOne() - local result = vs10_helpers.list_of_directories_in_path("foo\\bar.h") - test.isequal(1,#result) - end - - function vs10_filters.listOfDirectories_oneDirectory_returnsContainsFoo() - local result = vs10_helpers.list_of_directories_in_path("foo\\bar.h") - test.contains(result,"foo") - end - - function vs10_filters.listOfDirectories_twoDirectories_returnsSizeIsTwo() - local result = vs10_helpers.list_of_directories_in_path("foo\\bar\\bar.h") - test.isequal(2,#result) - end - - function vs10_filters.listOfDirectories_twoDirectories_secondEntryIsFooSlashBar() - local result = vs10_helpers.list_of_directories_in_path("foo\\bar\\bar.h") - test.isequal("foo\\bar",result[2]) - end - - function vs10_filters.listOfDirectories_dotSlash_returnsIsEmpty() - local result = vs10_helpers.list_of_directories_in_path(".\\bar.h") - test.isequal(0,#result) - end - - function vs10_filters.tableOfFileFilters_returnSizeIsTwo() - local t = - { - foo = {'foo\\bar.h'}, - bar = {'foo\\bar.h'}, - baz = {'baz\\bar.h'} - } - local result = vs10_helpers.table_of_file_filters(t) - test.isequal(2,#result) - end - - function vs10_filters.tableOfFileFilters_returnContainsFoo() - local t = - { - foo = {'foo\\bar.h'}, - bar = {'foo\\bar.h'}, - baz = {'baz\\bar.h'} - } - local result = vs10_helpers.table_of_file_filters(t) - --order is not defined - test.contains(result,'foo') - end - - function vs10_filters.tableOfFileFilters_returnContainsBaz() - local t = - { - foo = {'foo\\bar.h'}, - bar = {'foo\\bar.h'}, - baz = {'baz\\bar.h'} - } - local result = vs10_helpers.table_of_file_filters(t) - --order is not defined - test.contains(result,'baz') - end - - function vs10_filters.tableOfFileFilters_returnSizeIsFour() - local t = - { - foo = {'foo\\bar.h'}, - bar = {'foo\\bar\\bar.h'}, - baz = {'bar\\bar.h'}, - bazz = {'bar\\foo\\bar.h'} - } - local result = vs10_helpers.table_of_file_filters(t) - --order is not defined - test.isequal(4,#result) - end - - function vs10_filters.tableOfFileFilters_tableHasSubTableWithTwoEntries_returnSizeIsTwo() - local t = - { - foo = {'foo\\bar.h','foo\\bar\\bar.h'} - } - local result = vs10_helpers.table_of_file_filters(t) - --order is not defined - test.isequal(2,#result) - end - - - function vs10_filters.noInputFiles_bufferDoesNotContainTagFilter() - local buffer = get_buffer() - test.string_does_not_contain(buffer,"") - end - - function vs10_filters.oneInputFileYetNoDirectory_bufferDoesNotContainTagFilter() - files - { - "dontCare.h" - } - local buffer = get_buffer() - test.string_does_not_contain(buffer,".*.*") - end - - function vs10_filters.oneInputFileWithDirectory_bufferContainsTagFilterWithIncludeSetToFoo() - files - { - "foo\\dontCare.h" - } - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_filters.clIncludeFilter_oneInputFile_bufferContainsTagClInclude() - files - { - "dontCare.h" - } - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_filters.clCompileFilter_oneInputFile_bufferContainsTagClCompile() - files - { - "dontCare.cpp" - } - local buffer = get_buffer() - test.string_contains(buffer,'StreamingSIMDExtensions') -end - -function vs10_flags.sse2Set() - flags {"EnableSSE2"} - - local buffer = get_buffer() - test.string_contains(buffer,'StreamingSIMDExtensions2') -end - -function vs10_flags.extraWarningNotSet_warningLevelIsThree() - local buffer = get_buffer() - test.string_contains(buffer,'Level3') -end - -function vs10_flags.extraWarning_warningLevelIsFour() - flags {"ExtraWarnings"} - - local buffer = get_buffer() - test.string_contains(buffer,'Level4') -end - -function vs10_flags.extraWarning_treatWarningsAsError_setToTrue() - flags {"FatalWarnings"} - - local buffer = get_buffer() - test.string_contains(buffer,'true') -end - -function vs10_flags.floatFast_floatingPointModel_setToFast() - flags {"FloatFast"} - - local buffer = get_buffer() - test.string_contains(buffer,'Fast') -end - -function vs10_flags.floatStrict_floatingPointModel_setToStrict() - flags {"FloatStrict"} - - local buffer = get_buffer() - test.string_contains(buffer,'Strict') -end - -function vs10_flags.nativeWideChar_TreatWChar_tAsBuiltInType_setToTrue() - flags {"NativeWChar"} - - local buffer = get_buffer() - test.string_contains(buffer,'true') -end - -function vs10_flags.nativeWideChar_TreatWChar_tAsBuiltInType_setToFalse() - flags {"NoNativeWChar"} - - local buffer = get_buffer() - test.string_contains(buffer,'false') -end - -function vs10_flags.noExceptions_exceptionHandling_setToFalse() - flags {"NoExceptions"} - - local buffer = get_buffer() - test.string_contains(buffer,'false') -end - -function vs10_flags.structuredExceptions_exceptionHandling_setToAsync() - flags {"SEH"} - - local buffer = get_buffer() - test.string_contains(buffer,'Async') -end - -function vs10_flags.noFramePointer_omitFramePointers_setToTrue() - flags {"NoFramePointer"} - - local buffer = get_buffer() - test.string_contains(buffer,'true') -end - - -function vs10_flags.noRTTI_runtimeTypeInfo_setToFalse() - flags {"NoRTTI"} - - local buffer = get_buffer() - test.string_contains(buffer,'false') -end - -function vs10_flags.optimizeSize_optimization_setToMinSpace() - flags {"OptimizeSize"} - - local buffer = get_buffer() - test.string_contains(buffer,'MinSpace') -end - -function vs10_flags.optimizeSpeed_optimization_setToMaxSpeed() - flags {"OptimizeSpeed"} - - local buffer = get_buffer() - test.string_contains(buffer,'MaxSpeed') -end -function vs10_flags.optimizeSpeed_optimization_setToMaxSpeed() - flags {"Optimize"} - - local buffer = get_buffer() - test.string_contains(buffer,'Full') -end - - -local debug_string = "Symbols" -local release_string = "Optimize" -function vs10_flags.debugHasNoStaticRuntime_runtimeLibrary_setToMultiThreadedDebugDLL() - flags {debug_string} - local buffer = get_buffer() - test.string_contains(buffer,'MultiThreadedDebugDLL') -end - -function vs10_flags.debugAndStaticRuntime_runtimeLibrary_setToMultiThreadedDebug() - flags {debug_string,"StaticRuntime"} - local buffer = get_buffer() - test.string_contains(buffer,'MultiThreadedDebug') -end - -function vs10_flags.releaseHasNoStaticRuntime_runtimeLibrary_setToMultiThreadedDLL() - flags {release_string} - local buffer = get_buffer() - test.string_contains(buffer,'MultiThreadedDLL') -end - -function vs10_flags.releaseAndStaticRuntime_runtimeLibrary_setToMultiThreaded() - flags {release_string,"StaticRuntime"} - local buffer = get_buffer() - test.string_contains(buffer,'MultiThreaded') -end - -function vs10_flags.noCharacterSetDefine_characterSet_setToMultiByte() - local buffer = get_buffer() - test.string_contains(buffer,'MultiByte') -end - -function vs10_flags.unicode_characterSet_setToUnicode() - flags {"Unicode"} - - local buffer = get_buffer() - test.string_contains(buffer,'Unicode') -end - - - -function vs10_flags.debugAndNoMinimalRebuildAndSymbols_minimalRebuild_setToFalse() - flags {debug_string,"NoMinimalRebuild"} - - local buffer = get_buffer() - test.string_contains(buffer,'false') -end - -function vs10_flags.debugYetNotMinimalRebuild_minimalRebuild_setToTrue() - flags {debug_string} - - local buffer = get_buffer() - test.string_contains(buffer,'true') -end - -function vs10_flags.release_minimalRebuild_setToFalse() - flags {release_string} - - local buffer = get_buffer() - test.string_contains(buffer,'false') -end - -function vs10_flags.mfc_useOfMfc_setToStatic() - flags{"MFC"} - - local buffer = get_buffer() - test.string_contains(buffer,'Dynamic') -end - -function vs10_flags.Symbols_DebugInformationFormat_setToEditAndContinue() - flags{"Symbols"} - - local buffer = get_buffer() - test.string_contains(buffer,'EditAndContinue') -end - -function vs10_flags.symbolsAndNoEditAndContinue_DebugInformationFormat_setToProgramDatabase() - flags{"Symbols","NoEditAndContinue"} - - local buffer = get_buffer() - test.string_contains(buffer,'ProgramDatabase') -end - -function vs10_flags.symbolsAndRelease_DebugInformationFormat_setToProgramDatabase() - flags{"Symbols",release_string} - - local buffer = get_buffer() - test.string_contains(buffer,'ProgramDatabase') -end -function vs10_flags.noSymbols_DebugInformationFormat_blockIsEmpty() - local buffer = get_buffer() - test.string_contains(buffer,'') -end - -function vs10_flags.symbols_64BitBuild_DebugInformationFormat_setToOldStyle() - flags{"Symbols"} - platforms{"x64"} - local buffer = get_buffer() - test.string_contains(buffer,'OldStyle') -end - -function vs10_flags.noManifest_GenerateManifest_setToFalse() - flags{"NoManifest"} - - local buffer = get_buffer() - test.string_contains(buffer,'false') -end - -function vs10_flags.noSymbols_bufferDoesNotContainprogramDataBaseFile() - local buffer = get_buffer() - test.string_does_not_contain(buffer,'.*.*') -end -function vs10_flags.symbols_bufferContainsprogramDataBaseFile() - flags{"Symbols"} - local buffer = get_buffer() - test.string_contains(buffer,'.*%$%(OutDir%)MyProject%.pdb.*') -end - - - Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_links.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_links.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_links.lua @@ -1,143 +0,0 @@ - T.vs2010_links = { } - local vs10_links = T.vs2010_links - local sln, prj - - function vs10_links.setup() - _ACTION = "vs2010" - - sln = solution "MySolution" - configurations { "Debug" } - platforms {} - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - end - - local function get_buffer() - io.capture() - premake.buildconfigs() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - premake.vs2010_vcxproj(prj) - buffer = io.endcapture() - return buffer - end - - function vs10_links.hasLinkBlock() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_links.additionalDependancies_isInsideLinkBlock() - configuration("Debug") - links{"link_test"} - local buffer = get_buffer() - test.string_contains(buffer, - '.*.*%%%(AdditionalDependencies%).*') - end - - function vs10_links.additionalDependancies_containsLinkTestDotLib() - configuration("Debug") - links{"link_test"} - local buffer = get_buffer() - test.string_contains(buffer, - 'link_test%.lib;%%%(AdditionalDependencies%)') - end - - function vs10_links.outPutFile_isEqualToOutDirMyProjectDotExe() - local buffer = get_buffer() - test.string_contains(buffer,'%$%(OutDir%)MyProject.exe') - end - - function vs10_links.additionalLibraryDirectories_inputNoDirectories_tagsAreEmpty() - local buffer = get_buffer() - test.string_contains(buffer, - '%%%(AdditionalLibraryDirectories%)') - end - - function vs10_links.additionalLibraryDirectories_inputTestPath_tagsContainExspectedValue() - configuration("Debug") - libdirs { "test_path" } - local buffer = get_buffer() - local exspect = "test_path;" - test.string_contains(buffer, - ''..exspect..'%%%(AdditionalLibraryDirectories%)') - end - - function vs10_links.additionalLibraryDirectories_inputTwoPaths_tagsContainExspectedValue() - configuration("Debug") - libdirs { "test_path","another_path" } - local buffer = get_buffer() - local exspect = "test_path;another_path;" - test.string_contains(buffer, - ''..exspect..'%%%(AdditionalLibraryDirectories%)') - end - - function vs10_links.generateDebugInformation_withoutSymbolsFlag_valueInTagsIsFalse() - local buffer = get_buffer() - test.string_contains(buffer,'false') - end - - function vs10_links.generateDebugInformation_withSymbolsFlag_valueInTagsIsTrue() - flags {"Symbols"} - local buffer = get_buffer() - test.string_contains(buffer,'true') - end - - - function vs10_links.noOptimiseFlag_optimizeReferences_isNotInBuffer() - local buffer = get_buffer() - test.string_does_not_contain(buffer,'OptimizeReferences') - end - - function vs10_links.noOptimiseFlag_enableCOMDATFolding_isNotInBuffer() - local buffer = get_buffer() - test.string_does_not_contain(buffer,'EnableCOMDATFolding') - end - - function vs10_links.optimiseFlag_optimizeReferences_valueInsideTagsIsTrue() - flags{"Optimize"} - local buffer = get_buffer() - test.string_contains(buffer,'true') - end - - function vs10_links.noOptimiseFlag_enableCOMDATFolding_valueInsideTagsIsTrue() - flags{"Optimize"} - local buffer = get_buffer() - test.string_contains(buffer,'EnableCOMDATFolding>truemainCRTStartup') - end - - function vs10_links.entryPointSymbol_noWimMainFlag_valueInTagsIsMainCrtStartUp() - local buffer = get_buffer() - test.string_contains(buffer,'mainCRTStartup') - end - - function vs10_links.entryPointSymbol_winMainFlag_doesNotContainEntryPointSymbol() - flags{"WinMain"} - local buffer = get_buffer() - test.string_does_not_contain(buffer,'') - end - - function vs10_links.targetMachine_default_valueInTagsIsMachineX86() - local buffer = get_buffer() - test.string_contains(buffer,'MachineX86') - end - - function vs10_links.targetMachine_x32_valueInTagsIsMachineX64() - platforms {"x32"} - local buffer = get_buffer() - test.string_contains(buffer,'MachineX86') - end - - function vs10_links.targetMachine_x64_valueInTagsIsMachineX64() - platforms {"x64"} - local buffer = get_buffer() - test.string_contains(buffer,'MachineX64') - end - \ No newline at end of file Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_project_kinds.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_project_kinds.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_project_kinds.lua @@ -1,206 +0,0 @@ - T.vs2010_project_kinds= { } - local vs10_project_kinds = T.vs2010_project_kinds - local sln, prj - - function vs10_project_kinds.setup() - _ACTION = "vs2010" - - sln = solution "MySolution" - configurations { "Debug" } - platforms {} - - prj = project "MyProject" - language "C++" - end - - local function get_buffer() - io.capture() - premake.buildconfigs() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - premake.vs2010_vcxproj(prj) - buffer = io.endcapture() - return buffer - end - --incorrect assumption - --[[ - function vs10_project_kinds.staticLib_doesNotContainLinkSection() - kind "StaticLib" - local buffer = get_buffer() - test.string_does_not_contain(buffer,'.*') - end - --]] - - function vs10_project_kinds.staticLib_containsLibSection() - kind "StaticLib" - local buffer = get_buffer() - test.string_contains(buffer,'.*.*') - end - function vs10_project_kinds.staticLib_libSection_containsProjectNameDotLib() - kind "StaticLib" - local buffer = get_buffer() - test.string_contains(buffer,'.*.*MyProject.lib.*.*') - end - --[[ - function vs10_project_kinds.sharedLib_fail_asIDoNotKnowWhatItShouldLookLike_printsTheBufferSoICanCompare() - kind "SharedLib" - local buffer = get_buffer() - test.string_contains(buffer,'youWillNotFindThis') - end - --]] - - --[[ -check OutDir in debug it is showing "." -shared lib missing ??? in link section when noInportLib not used - --]] - --check why true is missing in a debug static lib and shared lib build - function vs10_project_kinds.staticLib_valueInMinimalRebuildIsTrue() - kind "StaticLib" - flags {"Symbols"} - local buffer = get_buffer() - test.string_contains(buffer,'.*true.*') - end - function vs10_project_kinds.sharedLib_valueInMinimalRebuildIsTrue() - kind "SharedLib" - flags {"Symbols"} - local buffer = get_buffer() - test.string_contains(buffer,'.*true.*') - end - --shared lib missing EditAndContinue in ClCompile section - function vs10_project_kinds.sharedLib_valueDebugInformationFormatIsEditAndContinue() - kind "SharedLib" - flags {"Symbols"} - local buffer = get_buffer() - test.string_contains(buffer,'.*EditAndContinue.*') - end - function vs10_project_kinds.sharedLib_valueGenerateDebugInformationIsTrue() - kind "SharedLib" - flags {"Symbols"} - local buffer = get_buffer() - test.string_contains(buffer,'.*true.*') - end - function vs10_project_kinds.sharedLib_linkSectionContainsImportLibrary() - kind "SharedLib" - local buffer = get_buffer() - test.string_contains(buffer,'.*.*.*') - end - - function vs10_project_kinds.sharedLib_bufferContainsImportLibrary() - kind "SharedLib" - local buffer = get_buffer() - test.string_contains(buffer,'.*MyProject.lib.*') - end - --should this go in vs2010_flags??? - - function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_linkSectionContainsImportLibrary() - kind "SharedLib" - flags{"NoImportLib"} - local buffer = get_buffer() - test.string_contains(buffer,'.*.*.*') - end - - function vs10_project_kinds.sharedLib_withOutNoImportLibraryFlag_propertyGroupSectionContainsIgnoreImportLibrary() - kind "SharedLib" - local buffer = get_buffer() - test.string_contains(buffer,'.*.*') - end - - function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_propertyGroupSectionContainsIgnoreImportLibrary() - kind "SharedLib" - flags{"NoImportLib"} - local buffer = get_buffer() - test.string_contains(buffer,'.*.*') - end - - function vs10_project_kinds.sharedLib_withOutNoImportLibraryFlag_ignoreImportLibraryValueIsFalse() - kind "SharedLib" - local buffer = get_buffer() - test.string_contains(buffer,'.*.*') - end - - function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_ignoreImportLibraryValueIsTrue() - kind "SharedLib" - flags{"NoImportLib"} - local buffer = get_buffer() - test.string_contains(buffer,'.*.*') - end - - --shared lib LinkIncremental set to incorrect value of false - function vs10_project_kinds.staticLib_doesNotContainLinkIncremental() - kind "StaticLib" - flags {"Symbols"} - local buffer = get_buffer() - test.string_does_not_contain(buffer,'') - end - - function vs10_project_kinds.sharedLib_withoutOptimisation_linkIncrementalValueIsTrue() - kind "SharedLib" - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_project_kinds.sharedLib_withOptimisation_linkIncrementalValueIsFalse() - kind "SharedLib" - flags{"Optimize"} - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - --check all configs %(AdditionalIncludeDirectories) missing before AdditionalIncludeDirectories end tag in ClCompile - function vs10_project_kinds.kindDoesNotMatter_noAdditionalDirectoriesSpecified_bufferDoesNotContainAdditionalIncludeDirectories() - kind "SharedLib" - local buffer = get_buffer() - test.string_does_not_contain(buffer,'.*.*') - end - - function vs10_project_kinds.configType_configIsWindowedApp_resultComparesEqualToApplication() - local t = { kind = "WindowedApp"} - local result = premake.vstudio.vs10_helpers.config_type(t) - test.isequal('Application',result) - end - - function vs10_project_kinds.linkOptions_staticLib_bufferContainsAdditionalOptionsInSideLibTag() - kind "StaticLib" - linkoptions{'/dummyOption'} - - test.string_contains(get_buffer(), - '.*%%%(AdditionalOptions%).*') - end - - function vs10_project_kinds.noLinkOptions_staticLib_bufferDoesNotContainAdditionalOptionsInSideLibTag() - kind "StaticLib" - - test.string_does_not_contain(get_buffer(), - '.*%%%(AdditionalOptions%).*') - end - - function vs10_project_kinds.linkOptions_staticLib_bufferContainsPassedOption() - kind "StaticLib" - linkoptions{'/dummyOption'} - - test.string_contains(get_buffer(), - '/dummyOption %%%(AdditionalOptions%).*') - end - - function vs10_project_kinds.linkOptions_windowedApp_bufferContainsAdditionalOptionsInSideLinkTag() - kind "WindowedApp" - linkoptions{'/dummyOption'} - - test.string_contains(get_buffer(), - '.* %%%(AdditionalOptions%).*') - end - function vs10_project_kinds.linkOptions_consoleApp_bufferContainsAdditionalOptionsInSideLinkTag() - kind "ConsoleApp" - linkoptions{'/dummyOption'} - - test.string_contains(get_buffer(), - '.* %%%(AdditionalOptions%).*') - end - - function vs10_project_kinds.linkOptions_sharedLib_bufferContainsAdditionalOptionsInSideLinkTag() - kind "SharedLib" - linkoptions{'/dummyOption'} - - test.string_contains(get_buffer(), - '.* %%%(AdditionalOptions%).*') - end - \ No newline at end of file Index: ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_vcxproj.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_vcxproj.lua +++ ps/trunk/build/premake/premake4/tests/actions/vstudio/test_vs2010_vcxproj.lua @@ -1,429 +0,0 @@ - T.vs2010_vcxproj = { } - local vs10_vcxproj = T.vs2010_vcxproj - local include_directory = "bar/foo" - local include_directory2 = "baz/foo" - local debug_define = "I_AM_ALIVE_NUMBER_FIVE" - local vs10_helpers = premake.vstudio.vs10_helpers - - local sln, prj - function vs10_vcxproj.teardown() - sln = nil - prj = nil - end - function vs10_vcxproj.setup() - _ACTION = "vs2010" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - - includedirs - { - include_directory, - include_directory2 - } - files - { - "foo/dummyHeader.h", - "foo/dummySource.cpp", - "../src/host/*h", - "../src/host/*.c", - "dummyResourceScript.rc" - } - - configuration("Release") - flags {"Optimize"} - links{"foo","bar"} - - configuration("Debug") - defines {debug_define} - links{"foo_d"} - - end - - local function get_buffer() - io.capture() - premake.buildconfigs() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - premake.vs2010_vcxproj(prj) - local buffer = io.endcapture() - return buffer - end - - function vs10_vcxproj.xmlDeclarationPresent() - local buffer = get_buffer() - test.istrue(string.startswith(buffer, '')) - end - - function vs10_vcxproj.projectBlocksArePresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_vcxproj.projectOpenTagIsCorrect() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.configItemGroupPresent() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.configBlocksArePresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_vcxproj.configTypeBlockPresent() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.twoConfigTypeBlocksPresent() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.propsDefaultForCppProjArePresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - - function vs10_vcxproj.propsForCppProjArePresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_vcxproj.extensionSettingArePresent() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.userMacrosPresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_vcxproj.intermediateAndOutDirsPropertyGroupWithMagicNumber() - local buffer = get_buffer() - test.string_contains(buffer,'.*<_ProjectFileVersion>10%.0%.30319%.1') - end - - function vs10_vcxproj.outDirPresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - function vs10_vcxproj.initDirPresent() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_vcxproj.projectWithDebugAndReleaseConfig_twoOutDirsAndTwoIntDirs() - local buffer = get_buffer() - test.string_contains(buffer,'.*.*.*') - end - - function vs10_vcxproj.containsItemDefinition() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - - function vs10_vcxproj.containsClCompileBlock() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.containsAdditionalOptions() - buildoptions {"/Gm"} - local buffer = get_buffer() - test.string_contains(buffer,'/Gm %%%(AdditionalOptions%)') - end - - local function cl_compile_string(version) - return '.*' - end - - function vs10_vcxproj.debugHasNoOptimisation() - local buffer = get_buffer() - test.string_contains(buffer, cl_compile_string('Debug').. '.*Disabled.*') - end - - function vs10_vcxproj.releaseHasFullOptimisation() - local buffer = get_buffer() - test.string_contains(buffer, cl_compile_string('Release').. '.*Full.*') - end - - function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory() - local buffer = get_buffer() - test.string_contains(buffer,cl_compile_string('Debug').. '.*'.. path.translate(include_directory, '\\') ..'.*') - end - - function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory2PrefixWithSemiColon() - local buffer = get_buffer() - test.string_contains(buffer,cl_compile_string('Debug').. '.*.*;'.. path.translate(include_directory2, '\\') ..'.*') - end - - function vs10_vcxproj.includeDirectories_debugEntryContains_include_directory2PostfixWithSemiColon() - local buffer = get_buffer() - test.string_contains(buffer,cl_compile_string('Debug').. '.*.*'.. path.translate(include_directory2, '\\') ..';.*') - end - - function vs10_vcxproj.debugContainsPreprossorBlock() - local buffer = get_buffer() - test.string_contains(buffer,cl_compile_string('Debug').. '.*.*') - end - - function vs10_vcxproj.debugHasDebugDefine() - local buffer = get_buffer() - test.string_contains(buffer,cl_compile_string('Debug')..'.*.*'..debug_define..'.*') - end - - function vs10_vcxproj.releaseHasStringPoolingOn() - local buffer = get_buffer() - test.string_contains(buffer,cl_compile_string('Release')..'.*true') - end - - function vs10_vcxproj.hasItemGroupSection() - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.fileExtension_extEqualH() - local ext = vs10_helpers.get_file_extension('foo.h') - test.isequal('h', ext) - end - - function vs10_vcxproj.fileExtension_containsTwoDots_extEqualH() - local ext = vs10_helpers.get_file_extension('foo.bar.h') - test.isequal('h', ext) - end - - function vs10_vcxproj.fileExtension_alphaNumeric_extEqualOneH() - local ext = vs10_helpers.get_file_extension('foo.1h') - test.isequal('1h', ext) - end - - function vs10_vcxproj.fileExtension_alphaNumericWithUnderscore_extEqualOne_H() - local ext = vs10_helpers.get_file_extension('foo.1_h') - test.isequal('1_h', ext) - end - - function vs10_vcxproj.fileExtension_containsHyphen_extEqualHHyphenH() - local ext = vs10_helpers.get_file_extension('foo.h-h') - test.isequal('h-h', ext) - end - - function vs10_vcxproj.fileExtension_containsMoreThanOneDot_extEqualOneH() - local ext = vs10_helpers.get_file_extension('foo.bar.h') - test.isequal('h', ext) - end - - local function SortAndReturnSortedInputFiles(input) - local sorted = - { - ClInclude ={}, - ClCompile ={}, - None ={}, - ResourceCompile ={} - } - vs10_helpers.sort_input_files(input,sorted) - return sorted - end - function vs10_vcxproj.sortFile_headerFile_SortedClIncludeEqualToFile() - local file = {"bar.h"} - local sorted = SortAndReturnSortedInputFiles(file) - test.isequal(file, sorted.ClInclude) - end - - function vs10_vcxproj.sortFile_srcFile_SortedClCompileEqualToFile() - local file = {"b.cxx"} - local sorted = SortAndReturnSortedInputFiles(file) - test.isequal(file, sorted.ClCompile) - end - - function vs10_vcxproj.sortFile_notRegistered_SortedNoneEqualToFile() - local file = {"foo.bar.00h"} - local sorted = SortAndReturnSortedInputFiles(file) - test.isequal(file, sorted.None) - end - - function vs10_vcxproj.sortFile_resourceScript_resourceCompileEqualToFile() - local file = {"foo.rc"} - local sorted = SortAndReturnSortedInputFiles(file) - test.isequal(file, sorted.ResourceCompile) - end - - function vs10_vcxproj.itemGroupSection_hasResourceCompileSection() - --for some reason this does not work here and it needs to be in - --the project setting at the top ? - --files{"dummyResourceScript.rc"} - local buffer = get_buffer() - test.string_contains(buffer,'.*') - end - - function vs10_vcxproj.itemGroupSection_hasHeaderListed() - local buffer = get_buffer() - test.string_contains(buffer,'.*.*') - end - - function vs10_vcxproj.checkProjectConfigurationOpeningTag_hasACloseingAngleBracket() - local buffer = get_buffer() - test.string_contains(buffer,'') - end - - function vs10_vcxproj.postBuildEvent_isPresent() - postbuildcommands { "doSomeThing" } - local buffer = get_buffer() - test.string_contains(buffer,'.*.*.*') - end - - function vs10_vcxproj.postBuildEvent_containsCorrectInformationBetweenCommandTag() - postbuildcommands { "doSomeThing" } - local buffer = get_buffer() - test.string_contains(buffer,'.*doSomeThing.*') - end - - function vs10_vcxproj.postBuildEvent_eventEncloseByQuotes_containsCorrectInformationBetweenCommandTag() - postbuildcommands { "\"doSomeThing\"" } - local buffer = get_buffer() - test.string_contains(buffer,'.*"doSomeThing".*') - end - - function vs10_vcxproj.outDir_directorySuppliedIsNotSlashPostFixed_bufferContainsOutDirSlashPostFixed() - targetdir("dir") - local buffer = get_buffer() - test.string_contains(buffer,'dir\\') - end - --postfixed directory slashes are removed by default - --yet these following two tests are to ensure if this behaviour is changed they will fail - function vs10_vcxproj.outDir_directorySuppliedWhichIsForwardSlashPostFixed_bufferContainsOutDirSlashPostFixed() - targetdir("dir/") - local buffer = get_buffer() - test.string_contains(buffer,'dir\\') - end - - function vs10_vcxproj.outDir_directorySuppliedWhichIsWindowsSlashPostFixed_bufferContainsOutDirSlashPostFixed() - targetdir("dir\\") - local buffer = get_buffer() - test.string_contains(buffer,'dir\\') - end - - function vs10_vcxproj.objectDir_directorySuppliedIsNotSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed() - objdir ("dir") - - local buffer = get_buffer() - test.string_contains(buffer,'dir\\') - end - - --postfixed directory slashes are removed by default - --yet these following two tests are to ensure if this behaviour is changed they will fail - function vs10_vcxproj.objectDir_directorySuppliedWhichIsSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed() - objdir ("dir/") - local buffer = get_buffer() - test.string_contains(buffer,'dir\\') - end - - function vs10_vcxproj.objectDir_directorySuppliedWhichIsWindowsSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed() - objdir ("dir\\") - local buffer = get_buffer() - test.string_contains(buffer,'dir\\') - end - function vs10_vcxproj.targetName() - configuration("Debug") - targetname ("foo_d") - local buffer = get_buffer() - test.string_contains(buffer,'foo_d') - end - - function vs10_vcxproj.noExtraWarnings_bufferDoesNotContainSmallerTypeCheck() - local buffer = get_buffer() - test.string_does_not_contain(buffer,'') - end - - function vs10_vcxproj.debugAndExtraWarnings_bufferContainsSmallerTypeCheck() - configuration("Debug") - flags {"ExtraWarnings"} - local buffer = get_buffer() - test.string_contains(buffer,'true') - end - - function vs10_vcxproj.releaseAndExtraWarnings_bufferDoesNotContainSmallerTypeCheck() - configuration("Release") - flags {"ExtraWarnings"} - local buffer = get_buffer() - test.string_does_not_contain(buffer,'') - end - - function vs10_vcxproj.onlyOneProjectConfigurationBlockWhenMultipleConfigs() - local buffer = get_buffer() - test.string_does_not_contain(buffer,'.*') - end - - function vs10_vcxproj.languageC_bufferContainsCompileAsC() - language "C" - local buffer = get_buffer() - test.string_contains(buffer,'CompileAsC') - end - - local debug_config_pch_string = 'Create' - local release_config_pch_string = debug_config_pch_string:gsub('Debug','Release') - - function vs10_vcxproj.noPchFlagSet_bufferDoesNotContainPchCreate() - configuration("Debug") - flags{"NoPCH"} - local buffer = get_buffer() - test.string_does_not_contain(buffer,debug_config_pch_string) - end - - function vs10_vcxproj.pchHeaderSetYetPchSourceIsNot_bufferDoesNotContainPchCreate() - configuration("Debug") - pchheader "foo/dummyHeader.h" - local buffer = get_buffer() - test.string_does_not_contain(buffer,debug_config_pch_string) - end - - - function vs10_vcxproj.pchHeaderAndPchSourceSet_bufferContainPchCreate() - configuration("Debug") - pchheader "foo/dummyHeader.h" - pchsource "foo/dummySource.cpp" - local buffer = get_buffer() - test.string_contains(buffer,debug_config_pch_string) - end - - function vs10_vcxproj.pchHeaderAndSourceSet_yetAlsoNoPch_bufferDoesNotContainpchCreate() - configuration('Debug') - pchheader "foo/dummyHeader.h" - pchsource "foo/dummySource.cpp" - flags{"NoPCH"} - local buffer = get_buffer() - test.string_does_not_contain(buffer,debug_config_pch_string) - end - - function vs10_vcxproj.pchHeaderAndPchSourceSet_debugAndRelease_matchingClCompileBlocks() - configuration("Debug") - pchheader "foo/dummyHeader.h" - pchsource "foo/dummySource.cpp" - configuration("Release") - pchheader "foo/dummyHeader.h" - pchsource "foo/dummySource.cpp" - local buffer = get_buffer() - - local expected = '%s+' - ..debug_config_pch_string ..'%s+' - ..release_config_pch_string ..'%s+' - test.string_contains(buffer,expected) - end - - function vs10_vcxproj.wholeProgramOptimizationIsNotSetByDefault_bufferDoesNotContainWholeProgramOptimization() - local buffer = get_buffer() - test.string_does_not_contain(buffer,"WholeProgramOptimization") - end Index: ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_common.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_common.lua +++ ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_common.lua @@ -1,76 +0,0 @@ --- --- tests/actions/xcode/test_xcode_common.lua --- Automated test suite for functions shared between Xcode projects and solutions --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.xcode3common = { } - - local suite = T.xcode3common - local xcode = premake.xcode - - --- --- Replacement for xcode.newid(). Creates a synthetic ID based on the node name, --- it's intended usage (file ID, build ID, etc.) and its place in the tree. This --- makes it easier to tell if the right ID is being used in the right places. --- - - xcode.used_ids = {} - - xcode.newid = function(node, usage) - local name = node.name - if usage then - name = name .. ":" .. usage - end - - if xcode.used_ids[name] then - local count = xcode.used_ids[name] + 1 - xcode.used_ids[name] = count - name = name .. "(" .. count .. ")" - else - xcode.used_ids[name] = 1 - end - - return "[" .. name .. "]" - end - - ---------------------------------------------------------------------------- --- Setup ---------------------------------------------------------------------------- - - function suite.setup() - io.capture() - end - - ---------------------------------------------------------------------------- --- Header/footer tests ---------------------------------------------------------------------------- - - function suite.Header_IsCorrect() - xcode.Header() - test.capture [[ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 45; - objects = { - - ]] - end - - - function suite.Footer() - xcode.Footer() - test.capture [[ - }; - rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; -} - ]] - end - - Index: ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_dependencies.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_dependencies.lua +++ ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_dependencies.lua @@ -1,311 +0,0 @@ --- --- tests/actions/xcode/test_xcode_dependencies.lua --- Automated test suite for Xcode project dependencies. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.xcode3_deps = { } - - local suite = T.xcode3_deps - local xcode = premake.xcode - - ---------------------------------------------------------------------------- --- Setup/Teardown ---------------------------------------------------------------------------- - - local sln, prj, prj2, tr - function suite.setup() - premake.action.set("xcode3") - xcode.used_ids = { } -- reset the list of generated IDs - - sln, prj = test.createsolution() - links { "MyProject2" } - - prj2 = test.createproject(sln) - kind "StaticLib" - configuration "Debug" - targetsuffix "-d" - end - - local function prepare() - io.capture() - premake.buildconfigs() - xcode.preparesolution(sln) - tr = xcode.buildprjtree(premake.solution.getproject(sln, 1)) - end - - ---------------------------------------------------------------------------- --- PBXBuildFile tests ---------------------------------------------------------------------------- - - function suite.PBXBuildFile_ListsDependencyTargets_OnStaticLib() - prepare() - xcode.PBXBuildFile(tr) - test.capture [[ -/* Begin PBXBuildFile section */ - [libMyProject2-d.a:build] /* libMyProject2-d.a in Frameworks */ = {isa = PBXBuildFile; fileRef = [libMyProject2-d.a] /* libMyProject2-d.a */; }; -/* End PBXBuildFile section */ - ]] - end - - function suite.PBXBuildFile_ListsDependencyTargets_OnSharedLib() - kind "SharedLib" - prepare() - xcode.PBXBuildFile(tr) - test.capture [[ -/* Begin PBXBuildFile section */ - [libMyProject2-d.dylib:build] /* libMyProject2-d.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = [libMyProject2-d.dylib] /* libMyProject2-d.dylib */; }; -/* End PBXBuildFile section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXContainerItemProxy tests ---------------------------------------------------------------------------- - - function suite.PBXContainerItemProxy_ListsProjectConfigs() - prepare() - xcode.PBXContainerItemProxy(tr) - test.capture [[ -/* Begin PBXContainerItemProxy section */ - [MyProject2.xcodeproj:prodprox] /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = [MyProject2.xcodeproj] /* MyProject2.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = [libMyProject2-d.a:product]; - remoteInfo = "libMyProject2-d.a"; - }; - [MyProject2.xcodeproj:targprox] /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = [MyProject2.xcodeproj] /* MyProject2.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = [libMyProject2-d.a:target]; - remoteInfo = "libMyProject2-d.a"; - }; -/* End PBXContainerItemProxy section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXFileReference tests ---------------------------------------------------------------------------- - - function suite.PBXFileReference_ListsDependencies() - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [MyProject:product] /* MyProject */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; name = "MyProject"; path = "MyProject"; sourceTree = BUILT_PRODUCTS_DIR; }; - [MyProject2.xcodeproj] /* MyProject2.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "MyProject2.xcodeproj"; path = "MyProject2.xcodeproj"; sourceTree = SOURCE_ROOT; }; -/* End PBXFileReference section */ - ]] - end - - function suite.PBXFileReference_UsesRelativePaths() - prj.location = "MyProject" - prj2.location = "MyProject2" - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [MyProject:product] /* MyProject */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; name = "MyProject"; path = "MyProject"; sourceTree = BUILT_PRODUCTS_DIR; }; - [MyProject2.xcodeproj] /* MyProject2.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "MyProject2.xcodeproj"; path = "../MyProject2/MyProject2.xcodeproj"; sourceTree = SOURCE_ROOT; }; -/* End PBXFileReference section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXFrameworksBuildPhase tests ---------------------------------------------------------------------------- - - function suite.PBXFrameworksBuildPhase_ListsDependencies_OnStaticLib() - prepare() - xcode.PBXFrameworksBuildPhase(tr) - test.capture [[ -/* Begin PBXFrameworksBuildPhase section */ - [MyProject:fxs] /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - [libMyProject2-d.a:build] /* libMyProject2-d.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - ]] - end - - function suite.PBXFrameworksBuildPhase_ListsDependencies_OnSharedLib() - kind "SharedLib" - prepare() - xcode.PBXFrameworksBuildPhase(tr) - test.capture [[ -/* Begin PBXFrameworksBuildPhase section */ - [MyProject:fxs] /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - [libMyProject2-d.dylib:build] /* libMyProject2-d.dylib in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - ]] - end - ---------------------------------------------------------------------------- --- PBXGroup tests ---------------------------------------------------------------------------- - - function suite.PBXGroup_ListsDependencies() - prepare() - xcode.PBXGroup(tr) --- test.print(io.endcapture()) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [Products] /* Products */, - [Projects] /* Projects */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [Products] /* Products */ = { - isa = PBXGroup; - children = ( - [MyProject:product] /* MyProject */, - ); - name = "Products"; - sourceTree = ""; - }; - [Projects] /* Projects */ = { - isa = PBXGroup; - children = ( - [MyProject2.xcodeproj] /* MyProject2.xcodeproj */, - ); - name = "Projects"; - sourceTree = ""; - }; - [MyProject2.xcodeproj:prodgrp] /* Products */ = { - isa = PBXGroup; - children = ( - [libMyProject2-d.a] /* libMyProject2-d.a */, - ); - name = Products; - sourceTree = ""; - }; -/* End PBXGroup section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXNativeTarget tests ---------------------------------------------------------------------------- - - function suite.PBXNativeTarget_ListsDependencies() - prepare() - xcode.PBXNativeTarget(tr) - test.capture [[ -/* Begin PBXNativeTarget section */ - [MyProject:target] /* MyProject */ = { - isa = PBXNativeTarget; - buildConfigurationList = [MyProject:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */; - buildPhases = ( - [MyProject:rez] /* Resources */, - [MyProject:src] /* Sources */, - [MyProject:fxs] /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - [MyProject2.xcodeproj:targdep] /* PBXTargetDependency */, - ); - name = "MyProject"; - productInstallPath = "$(HOME)/bin"; - productName = "MyProject"; - productReference = [MyProject:product] /* MyProject */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXProject tests ---------------------------------------------------------------------------- - - function suite.PBXProject_ListsDependencies() - prepare() - xcode.PBXProject(tr) - test.capture [[ -/* Begin PBXProject section */ - 08FB7793FE84155DC02AAC07 /* Project object */ = { - isa = PBXProject; - buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "MyProject" */; - compatibilityVersion = "Xcode 3.1"; - hasScannedForEncodings = 1; - mainGroup = [MyProject] /* MyProject */; - projectDirPath = ""; - projectReferences = ( - { - ProductGroup = [MyProject2.xcodeproj:prodgrp] /* Products */; - ProjectRef = [MyProject2.xcodeproj] /* MyProject2.xcodeproj */; - }, - ); - projectRoot = ""; - targets = ( - [MyProject:target] /* MyProject */, - ); - }; -/* End PBXProject section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXReferenceProxy tests ---------------------------------------------------------------------------- - - function suite.PBXReferenceProxy_ListsDependencies() - prepare() - xcode.PBXReferenceProxy(tr) - test.capture [[ -/* Begin PBXReferenceProxy section */ - [libMyProject2-d.a] /* libMyProject2-d.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libMyProject2-d.a"; - remoteRef = [MyProject2.xcodeproj:prodprox] /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXTargetDependency tests ---------------------------------------------------------------------------- - - function suite.PBXTargetDependency_ListsDependencies() - prepare() - xcode.PBXTargetDependency(tr) - test.capture [[ -/* Begin PBXTargetDependency section */ - [MyProject2.xcodeproj:targdep] /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = "libMyProject2-d.a"; - targetProxy = [MyProject2.xcodeproj:targprox] /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - ]] - end Index: ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_project.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_project.lua +++ ps/trunk/build/premake/premake4/tests/actions/xcode/test_xcode_project.lua @@ -1,1879 +0,0 @@ --- --- tests/actions/xcode/test_xcode_project.lua --- Automated test suite for Xcode project generation. --- Copyright (c) 2009-2010 Jason Perkins and the Premake project --- - - T.xcode3_project = { } - - local suite = T.xcode3_project - local xcode = premake.xcode - - ---------------------------------------------------------------------------- --- Setup/Teardown ---------------------------------------------------------------------------- - - local sln, tr - function suite.setup() - premake.action.set("xcode3") - io.eol = "\n" - xcode.used_ids = { } -- reset the list of generated IDs - sln = test.createsolution() - end - - local function prepare() - io.capture() - premake.buildconfigs() - xcode.preparesolution(sln) - local prj = premake.solution.getproject(sln, 1) - tr = xcode.buildprjtree(prj) - end - - ---------------------------------------------------------------------------- --- PBXBuildFile tests ---------------------------------------------------------------------------- - - function suite.PBXBuildFile_ListsCppSources() - files { "source.h", "source.c", "source.cpp", "Info.plist" } - prepare() - xcode.PBXBuildFile(tr) - test.capture [[ -/* Begin PBXBuildFile section */ - [source.c:build] /* source.c in Sources */ = {isa = PBXBuildFile; fileRef = [source.c] /* source.c */; }; - [source.cpp:build] /* source.cpp in Sources */ = {isa = PBXBuildFile; fileRef = [source.cpp] /* source.cpp */; }; -/* End PBXBuildFile section */ - ]] - end - - function suite.PBXBuildFile_ListsObjCSources() - files { "source.h", "source.m", "source.mm", "Info.plist" } - prepare() - xcode.PBXBuildFile(tr) - test.capture [[ -/* Begin PBXBuildFile section */ - [source.m:build] /* source.m in Sources */ = {isa = PBXBuildFile; fileRef = [source.m] /* source.m */; }; - [source.mm:build] /* source.mm in Sources */ = {isa = PBXBuildFile; fileRef = [source.mm] /* source.mm */; }; -/* End PBXBuildFile section */ - ]] - end - - function suite.PBXBuildFile_ListsResourceFilesOnlyOnceWithGroupID() - files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib" } - prepare() - xcode.PBXBuildFile(tr) - test.capture [[ -/* Begin PBXBuildFile section */ - [MainMenu.xib:build] /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = [MainMenu.xib] /* MainMenu.xib */; }; -/* End PBXBuildFile section */ - ]] - end - - - function suite.PBXBuildFile_ListsFrameworks() - links { "Cocoa.framework", "ldap" } - prepare() - xcode.PBXBuildFile(tr) - test.capture [[ -/* Begin PBXBuildFile section */ - [Cocoa.framework:build] /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = [Cocoa.framework] /* Cocoa.framework */; }; -/* End PBXBuildFile section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXFileReference tests ---------------------------------------------------------------------------- - - function suite.PBXFileReference_ListsConsoleTarget() - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [MyProject:product] /* MyProject */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; name = "MyProject"; path = "MyProject"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - ]] - end - - - function suite.PBXFileReference_ListsWindowedTarget() - kind "WindowedApp" - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [MyProject.app:product] /* MyProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = "MyProject.app"; path = "MyProject.app"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - ]] - end - - - function suite.PBXFileReference_ListsStaticLibTarget() - kind "StaticLib" - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [libMyProject.a:product] /* libMyProject.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libMyProject.a"; path = "libMyProject.a"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - ]] - end - - - function suite.PBXFileReference_ListsSharedLibTarget() - kind "SharedLib" - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [libMyProject.dylib:product] /* libMyProject.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; name = "libMyProject.dylib"; path = "libMyProject.dylib"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - ]] - end - - - function suite.PBXFileReference_ListsSourceFiles() - files { "source.c" } - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [source.c] /* source.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = "source.c"; path = "source.c"; sourceTree = ""; }; - ]] - end - - function suite.PBXFileReference_ListsXibCorrectly() - files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib" } - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [English] /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "English"; path = "English.lproj/MainMenu.xib"; sourceTree = ""; }; - [French] /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "French"; path = "French.lproj/MainMenu.xib"; sourceTree = ""; }; - ]] - end - - - function suite.PBXFileReference_ListsStringsCorrectly() - files { "English.lproj/InfoPlist.strings", "French.lproj/InfoPlist.strings" } - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [English] /* English */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "English"; path = "English.lproj/InfoPlist.strings"; sourceTree = ""; }; - [French] /* French */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "French"; path = "French.lproj/InfoPlist.strings"; sourceTree = ""; }; - ]] - end - - - function suite.PBXFileReference_ListFrameworksCorrectly() - links { "Cocoa.framework" } - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [Cocoa.framework] /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "Cocoa.framework"; path = "/System/Library/Frameworks/Cocoa.framework"; sourceTree = ""; }; - ]] - end - - function suite.PBXFileReference_ListsIconFiles() - files { "Icon.icns" } - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [Icon.icns] /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = "Icon.icns"; path = "Icon.icns"; sourceTree = ""; }; - ]] - end - - function suite.PBXFileReference_IgnoresTargetDir() - targetdir "bin" - kind "WindowedApp" - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [MyProject.app:product] /* MyProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = "MyProject.app"; path = "MyProject.app"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - ]] - end - - - function suite.PBXFileReference_UsesTargetSuffix() - targetsuffix "-d" - kind "SharedLib" - prepare() - xcode.PBXFileReference(tr) - test.capture [[ -/* Begin PBXFileReference section */ - [libMyProject-d.dylib:product] /* libMyProject-d.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; name = "libMyProject-d.dylib"; path = "libMyProject-d.dylib"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXFrameworksBuildPhase tests ---------------------------------------------------------------------------- - - function suite.PBXFrameworksBuildPhase_OnNoFiles() - prepare() - xcode.PBXFrameworksBuildPhase(tr) - test.capture [[ -/* Begin PBXFrameworksBuildPhase section */ - [MyProject:fxs] /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - ]] - end - - - function suite.PBXFrameworksBuild_ListsFrameworksCorrectly() - links { "Cocoa.framework" } - prepare() - xcode.PBXFrameworksBuildPhase(tr) - test.capture [[ -/* Begin PBXFrameworksBuildPhase section */ - [MyProject:fxs] /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - [Cocoa.framework:build] /* Cocoa.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXGroup tests ---------------------------------------------------------------------------- - - function suite.PBXGroup_OnNoFiles() - prepare() - xcode.PBXGroup(tr) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [Products] /* Products */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [Products] /* Products */ = { - isa = PBXGroup; - children = ( - [MyProject:product] /* MyProject */, - ); - name = "Products"; - sourceTree = ""; - }; -/* End PBXGroup section */ - ]] - end - - - function suite.PBXGroup_OnSourceFiles() - files { "source.h" } - prepare() - xcode.PBXGroup(tr) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [source.h] /* source.h */, - [Products] /* Products */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [Products] /* Products */ = { - isa = PBXGroup; - children = ( - [MyProject:product] /* MyProject */, - ); - name = "Products"; - sourceTree = ""; - }; -/* End PBXGroup section */ - ]] - end - - - function suite.PBXGroup_OnSourceSubdirs() - files { "include/premake/source.h" } - prepare() - xcode.PBXGroup(tr) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [include] /* include */, - [Products] /* Products */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [include] /* include */ = { - isa = PBXGroup; - children = ( - [premake] /* premake */, - ); - name = "include"; - path = include; - sourceTree = ""; - }; - [premake] /* premake */ = { - isa = PBXGroup; - children = ( - [source.h] /* source.h */, - ); - name = "premake"; - path = premake; - sourceTree = ""; - }; - ]] - end - - - function suite.PBXGroup_SortsFiles() - files { "test.h", "source.h", "source.cpp" } - prepare() - xcode.PBXGroup(tr) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [source.cpp] /* source.cpp */, - [source.h] /* source.h */, - [test.h] /* test.h */, - [Products] /* Products */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [Products] /* Products */ = { - isa = PBXGroup; - children = ( - [MyProject:product] /* MyProject */, - ); - name = "Products"; - sourceTree = ""; - }; -/* End PBXGroup section */ - ]] - end - - - function suite.PBXGroup_OnResourceFiles() - files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib", "Info.plist" } - prepare() - xcode.PBXGroup(tr) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [Info.plist] /* Info.plist */, - [MainMenu.xib] /* MainMenu.xib */, - [Products] /* Products */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [Products] /* Products */ = { - isa = PBXGroup; - children = ( - [MyProject:product] /* MyProject */, - ); - name = "Products"; - sourceTree = ""; - }; -/* End PBXGroup section */ - ]] - end - - - function suite.PBXGroup_OnFrameworks() - links { "Cocoa.framework" } - prepare() - xcode.PBXGroup(tr) - test.capture [[ -/* Begin PBXGroup section */ - [MyProject] /* MyProject */ = { - isa = PBXGroup; - children = ( - [Frameworks] /* Frameworks */, - [Products] /* Products */, - ); - name = "MyProject"; - sourceTree = ""; - }; - [Frameworks] /* Frameworks */ = { - isa = PBXGroup; - children = ( - [Cocoa.framework] /* Cocoa.framework */, - ); - name = "Frameworks"; - sourceTree = ""; - }; - ]] - end - - ---------------------------------------------------------------------------- --- PBXNativeTarget tests ---------------------------------------------------------------------------- - - function suite.PBXNativeTarget_OnConsoleApp() - prepare() - xcode.PBXNativeTarget(tr) - test.capture [[ -/* Begin PBXNativeTarget section */ - [MyProject:target] /* MyProject */ = { - isa = PBXNativeTarget; - buildConfigurationList = [MyProject:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */; - buildPhases = ( - [MyProject:rez] /* Resources */, - [MyProject:src] /* Sources */, - [MyProject:fxs] /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "MyProject"; - productInstallPath = "$(HOME)/bin"; - productName = "MyProject"; - productReference = [MyProject:product] /* MyProject */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - ]] - end - - - function suite.PBXNativeTarget_OnWindowedApp() - kind "WindowedApp" - prepare() - xcode.PBXNativeTarget(tr) - test.capture [[ -/* Begin PBXNativeTarget section */ - [MyProject.app:target] /* MyProject */ = { - isa = PBXNativeTarget; - buildConfigurationList = [MyProject.app:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */; - buildPhases = ( - [MyProject.app:rez] /* Resources */, - [MyProject.app:src] /* Sources */, - [MyProject.app:fxs] /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "MyProject"; - productInstallPath = "$(HOME)/Applications"; - productName = "MyProject"; - productReference = [MyProject.app:product] /* MyProject.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - ]] - end - - - function suite.PBXNativeTarget_OnSharedLib() - kind "SharedLib" - prepare() - xcode.PBXNativeTarget(tr) - test.capture [[ -/* Begin PBXNativeTarget section */ - [libMyProject.dylib:target] /* MyProject */ = { - isa = PBXNativeTarget; - buildConfigurationList = [libMyProject.dylib:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */; - buildPhases = ( - [libMyProject.dylib:rez] /* Resources */, - [libMyProject.dylib:src] /* Sources */, - [libMyProject.dylib:fxs] /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "MyProject"; - productName = "MyProject"; - productReference = [libMyProject.dylib:product] /* libMyProject.dylib */; - productType = "com.apple.product-type.library.dynamic"; - }; -/* End PBXNativeTarget section */ - ]] - end - - - function suite.PBXNativeTarget_OnBuildCommands() - prebuildcommands { "prebuildcmd" } - prelinkcommands { "prelinkcmd" } - postbuildcommands { "postbuildcmd" } - prepare() - xcode.PBXNativeTarget(tr) - test.capture [[ -/* Begin PBXNativeTarget section */ - [MyProject:target] /* MyProject */ = { - isa = PBXNativeTarget; - buildConfigurationList = [MyProject:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */; - buildPhases = ( - 9607AE1010C857E500CD1376 /* Prebuild */, - [MyProject:rez] /* Resources */, - [MyProject:src] /* Sources */, - 9607AE3510C85E7E00CD1376 /* Prelink */, - [MyProject:fxs] /* Frameworks */, - 9607AE3710C85E8F00CD1376 /* Postbuild */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "MyProject"; - productInstallPath = "$(HOME)/bin"; - productName = "MyProject"; - productReference = [MyProject:product] /* MyProject */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXProject tests ---------------------------------------------------------------------------- - - function suite.PBXProject_OnProject() - prepare() - xcode.PBXProject(tr) - test.capture [[ -/* Begin PBXProject section */ - 08FB7793FE84155DC02AAC07 /* Project object */ = { - isa = PBXProject; - buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "MyProject" */; - compatibilityVersion = "Xcode 3.1"; - hasScannedForEncodings = 1; - mainGroup = [MyProject] /* MyProject */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - [MyProject:target] /* MyProject */, - ); - }; -/* End PBXProject section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXResourceBuildPhase tests ---------------------------------------------------------------------------- - - function suite.PBXResourcesBuildPhase_OnNoResources() - prepare() - xcode.PBXResourcesBuildPhase(tr) - test.capture [[ -/* Begin PBXResourcesBuildPhase section */ - [MyProject:rez] /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - ]] - end - - - function suite.PBXResourcesBuildPhase_OnResources() - files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib", "Info.plist" } - prepare() - xcode.PBXResourcesBuildPhase(tr) - test.capture [[ -/* Begin PBXResourcesBuildPhase section */ - [MyProject:rez] /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - [MainMenu.xib:build] /* MainMenu.xib in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXShellScriptBuildPhase tests ---------------------------------------------------------------------------- - - function suite.PBXShellScriptBuildPhase_OnNoScripts() - prepare() - xcode.PBXShellScriptBuildPhase(tr) - test.capture [[ - ]] - end - - - function suite.PBXShellScriptBuildPhase_OnPrebuildScripts() - prebuildcommands { 'ls src', 'cp "a" "b"' } - prepare() - xcode.PBXShellScriptBuildPhase(tr) - test.capture [[ -/* Begin PBXShellScriptBuildPhase section */ - 9607AE1010C857E500CD1376 /* Prebuild */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = Prebuild; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "ls src\ncp \"a\" \"b\""; - }; -/* End PBXShellScriptBuildPhase section */ - ]] - end - - - function suite.PBXShellScriptBuildPhase_OnPerConfigCmds() - prebuildcommands { 'ls src' } - configuration "Debug" - prebuildcommands { 'cp a b' } - prepare() - xcode.PBXShellScriptBuildPhase(tr) - test.capture [[ -/* Begin PBXShellScriptBuildPhase section */ - 9607AE1010C857E500CD1376 /* Prebuild */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = Prebuild; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "ls src\nif [ \"${CONFIGURATION}\" = \"Debug\" ]; then\ncp a b\nfi"; - }; -/* End PBXShellScriptBuildPhase section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXSourcesBuildPhase tests ---------------------------------------------------------------------------- - - function suite.PBXSourcesBuildPhase_OnNoSources() - prepare() - xcode.PBXSourcesBuildPhase(tr) - test.capture [[ -/* Begin PBXSourcesBuildPhase section */ - [MyProject:src] /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - ]] - end - - - function suite.PBXSourcesBuildPhase_OnSources() - files { "hello.cpp", "goodbye.cpp" } - prepare() - xcode.PBXSourcesBuildPhase(tr) - test.capture [[ -/* Begin PBXSourcesBuildPhase section */ - [MyProject:src] /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - [goodbye.cpp:build] /* goodbye.cpp in Sources */, - [hello.cpp:build] /* hello.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - ]] - end - - ---------------------------------------------------------------------------- --- PBXVariantGroup tests ---------------------------------------------------------------------------- - - function suite.PBXVariantGroup_OnNoGroups() - prepare() - xcode.PBXVariantGroup(tr) - test.capture [[ -/* Begin PBXVariantGroup section */ -/* End PBXVariantGroup section */ - ]] - end - - - function suite.PBXVariantGroup_OnNoResourceGroups() - files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib" } - prepare() - xcode.PBXVariantGroup(tr) - test.capture [[ -/* Begin PBXVariantGroup section */ - [MainMenu.xib] /* MainMenu.xib */ = { - isa = PBXVariantGroup; - children = ( - [English] /* English */, - [French] /* French */, - ); - name = MainMenu.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - ]] - end - - ---------------------------------------------------------------------------- --- XCBuildConfiguration_Target tests ---------------------------------------------------------------------------- - - function suite.XCBuildConfigurationTarget_OnConsoleApp() - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/bin; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnWindowedApp() - kind "WindowedApp" - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject.app:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = "$(HOME)/Applications"; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnStaticLib() - kind "StaticLib" - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [libMyProject.a:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/lib; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnSharedLib() - kind "SharedLib" - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [libMyProject.dylib:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EXECUTABLE_PREFIX = lib; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/lib; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnTargetPrefix() - kind "SharedLib" - targetprefix "xyz" - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [xyzMyProject.dylib:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - EXECUTABLE_PREFIX = xyz; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/lib; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - function suite.XCBuildConfigurationTarget_OnInfoPlist() - files { "MyProject-Info.plist" } - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INFOPLIST_FILE = "MyProject-Info.plist"; - INSTALL_PATH = /usr/local/bin; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnSymbols() - flags { "Symbols" } - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/bin; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnTargetSuffix() - targetsuffix "-d" - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject-d:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/bin; - PRODUCT_NAME = "MyProject-d"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnSinglePlatform() - platforms { "Universal32" } - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject:Debug] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/bin; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationTarget_OnMultiplePlatforms() - platforms { "Universal32", "Universal64" } - prepare() - xcode.XCBuildConfiguration_Target(tr, tr.products.children[1], tr.configs[1]) - test.capture [[ - [MyProject:Debug] /* Debug 32-bit Universal */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/bin; - PRODUCT_NAME = "MyProject"; - }; - name = "Debug 32-bit Universal"; - }; - ]] - end - - ---------------------------------------------------------------------------- --- XCBuildConfiguration_Project tests ---------------------------------------------------------------------------- - - function suite.XCBuildConfigurationProject_OnConsoleApp() - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnOptimize() - flags { "Optimize" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = s; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnOptimizeSpeed() - flags { "OptimizeSpeed" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 3; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnStaticRuntime() - flags { "StaticRuntime" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = static; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnTargetDir() - targetdir "bin" - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_BUILD_DIR = "$(SYMROOT)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - SYMROOT = "bin"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnDefines() - defines { "_DEBUG", "DEBUG" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "_DEBUG", - "DEBUG", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnIncludeDirs() - includedirs { "../include", "../libs" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "../include", - "../libs", - ); - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnBuildOptions() - buildoptions { "build option 1", "build option 2" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ( - "build option 1", - "build option 2", - ); - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnLinks() - links { "Cocoa.framework", "ldap" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - OTHER_LDFLAGS = ( - "-lldap", - ); - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - function suite.XCBuildConfigurationProject_OnLinkOptions() - linkoptions { "link option 1", "link option 2" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - OTHER_LDFLAGS = ( - "link option 1", - "link option 2", - ); - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnExtraWarnings() - flags { "ExtraWarnings" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - WARNING_CFLAGS = "-Wall"; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnFatalWarnings() - flags { "FatalWarnings" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_TREAT_WARNINGS_AS_ERRORS = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnFloatFast() - flags { "FloatFast" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ( - "-ffast-math", - ); - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnFloatStrict() - flags { "FloatStrict" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ( - "-ffloat-store", - ); - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnNoEditAndContinue() - flags { "Symbols", "NoEditAndContinue" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = YES; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnNoExceptions() - flags { "NoExceptions" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_CPP_EXCEPTIONS = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnNoFramePointer() - flags { "NoFramePointer" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ( - "-fomit-frame-pointer", - ); - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnNoPCH() - pchheader "MyProject_Prefix.pch" - flags { "NoPCH" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnNoRTTI() - flags { "NoRTTI" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_CPP_RTTI = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnSymbols() - flags { "Symbols" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_FIX_AND_CONTINUE = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = YES; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnLibDirs() - libdirs { "mylibs1", "mylibs2" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - LIBRARY_SEARCH_PATHS = ( - "mylibs1", - "mylibs2", - ); - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnPCH() - pchheader "MyProject_Prefix.pch" - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "MyProject_Prefix.pch"; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnUniversal() - platforms { "Universal" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Universal/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnUniversal32() - platforms { "Universal32" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Universal32/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnUniversal64() - platforms { "Universal64" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Universal64/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnNative() - platforms { "Native" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnX32() - platforms { "x32" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "i386"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/x32/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - - function suite.XCBuildConfigurationProject_OnX64() - platforms { "x64" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "x86_64"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/x64/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug"; - }; - ]] - end - - function suite.XCBuildConfigurationProject_OnMultiplePlatforms() - platforms { "Universal32", "Universal64" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - test.capture [[ - [MyProject:Debug(2)] /* Debug 32-bit Universal */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; - CONFIGURATION_TEMP_DIR = "$(OBJROOT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - OBJROOT = "obj/Universal32/Debug"; - ONLY_ACTIVE_ARCH = NO; - PREBINDING = NO; - }; - name = "Debug 32-bit Universal"; - }; - ]] - end - - ---------------------------------------------------------------------------- --- XCBuildConfigurationList tests ---------------------------------------------------------------------------- - - function suite.XCBuildConfigurationList_OnNoPlatforms() - prepare() - xcode.XCBuildConfigurationList(tr) - test.capture [[ -/* Begin XCConfigurationList section */ - [MyProject:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - [MyProject:Debug] /* Debug */, - [MyProject:Release] /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = "Debug"; - }; - 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "MyProject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - [MyProject:Debug(2)] /* Debug */, - [MyProject:Release(2)] /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = "Debug"; - }; -/* End XCConfigurationList section */ - ]] - end - - - function suite.XCBuildConfigurationList_OnSinglePlatforms() - platforms { "Universal32" } - prepare() - xcode.XCBuildConfigurationList(tr) - test.capture [[ -/* Begin XCConfigurationList section */ - [MyProject:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - [MyProject:Debug] /* Debug */, - [MyProject:Release] /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = "Debug"; - }; - 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "MyProject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - [MyProject:Debug(2)] /* Debug */, - [MyProject:Release(2)] /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = "Debug"; - }; -/* End XCConfigurationList section */ - ]] - end - - - function suite.XCBuildConfigurationList_OnMultiplePlatforms() - platforms { "Universal32", "Universal64" } - prepare() - xcode.XCBuildConfigurationList(tr) - test.capture [[ -/* Begin XCConfigurationList section */ - [MyProject:cfg] /* Build configuration list for PBXNativeTarget "MyProject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - [MyProject:Debug] /* Debug 32-bit Universal */, - [MyProject:Debug(3)] /* Debug 64-bit Universal */, - [MyProject:Release] /* Release 32-bit Universal */, - [MyProject:Release(3)] /* Release 64-bit Universal */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = "Debug 32-bit Universal"; - }; - 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "MyProject" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - [MyProject:Debug(2)] /* Debug 32-bit Universal */, - [MyProject:Debug(4)] /* Debug 64-bit Universal */, - [MyProject:Release(2)] /* Release 32-bit Universal */, - [MyProject:Release(4)] /* Release 64-bit Universal */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = "Debug 32-bit Universal"; - }; -/* End XCConfigurationList section */ - ]] - end - -function suite.defaultVisibility_settingIsFound() - prepare() - xcode.XCBuildConfiguration(tr) - local buffer = io.endcapture() - - test.string_contains(buffer,'GCC_SYMBOLS_PRIVATE_EXTERN') -end - - -function suite.defaultVisibilitySetting_setToNo() - prepare() - xcode.XCBuildConfiguration(tr) - local buffer = io.endcapture() - - test.string_contains(buffer,'GCC_SYMBOLS_PRIVATE_EXTERN = NO;') -end - -function suite.releaseBuild_onlyDefaultArch_equalsNo() - flags { "Optimize" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[2]) - local buffer = io.endcapture() - - test.string_contains(buffer,'ONLY_ACTIVE_ARCH = NO;') -end - -function suite.debugBuild_onlyDefaultArch_equalsYes() - flags { "Symbols" } - prepare() - xcode.XCBuildConfiguration_Project(tr, tr.configs[1]) - local buffer = io.endcapture() - - test.string_contains(buffer,'ONLY_ACTIVE_ARCH = YES;') -end \ No newline at end of file Index: ps/trunk/build/premake/premake4/tests/base/test_action.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_action.lua +++ ps/trunk/build/premake/premake4/tests/base/test_action.lua @@ -1,73 +0,0 @@ --- --- tests/base/test_action.lua --- Automated test suite for the action list. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.action = { } - - --- --- Setup/teardown --- - - local fake = { - trigger = "fake", - description = "Fake action used for testing", - } - - function T.action.setup() - premake.action.list["fake"] = fake - solution "MySolution" - configurations "Debug" - project "MyProject" - premake.buildconfigs() - end - - function T.action.teardown() - premake.action.list["fake"] = nil - end - - - --- --- Tests for call() --- - - function T.action.CallCallsExecuteIfPresent() - local called = false - fake.execute = function () called = true end - premake.action.call("fake") - test.istrue(called) - end - - function T.action.CallCallsOnSolutionIfPresent() - local called = false - fake.onsolution = function () called = true end - premake.action.call("fake") - test.istrue(called) - end - - function T.action.CallCallsOnProjectIfPresent() - local called = false - fake.onproject = function () called = true end - premake.action.call("fake") - test.istrue(called) - end - - function T.action.CallSkipsCallbacksIfNotPresent() - test.success(premake.action.call, "fake") - end - - --- --- Tests for set() --- - - function T.action.set_SetsActionOS() - local oldos = _OS - _OS = "linux" - premake.action.set("vs2008") - test.isequal(_OS, "windows") - _OS = oldos - end Index: ps/trunk/build/premake/premake4/tests/base/test_api.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_api.lua +++ ps/trunk/build/premake/premake4/tests/base/test_api.lua @@ -1,343 +0,0 @@ --- --- tests/base/test_api.lua --- Automated test suite for the project API support functions. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - T.api = { } - local suite = T.api - - local sln - function suite.setup() - sln = solution "MySolution" - end - - --- --- premake.getobject() tests --- - - function suite.getobject_RaisesError_OnNoContainer() - premake.CurrentContainer = nil - c, err = premake.getobject("container") - test.istrue(c == nil) - test.isequal("no active solution or project", err) - end - - function suite.getobject_RaisesError_OnNoActiveSolution() - premake.CurrentContainer = { } - c, err = premake.getobject("solution") - test.istrue(c == nil) - test.isequal("no active solution", err) - end - - function suite.getobject_RaisesError_OnNoActiveConfig() - premake.CurrentConfiguration = nil - c, err = premake.getobject("config") - test.istrue(c == nil) - test.isequal("no active solution, project, or configuration", err) - end - - --- --- premake.setarray() tests --- - - function suite.setarray_Inserts_OnStringValue() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = { } - premake.setarray("config", "myfield", "hello") - test.isequal("hello", premake.CurrentConfiguration.myfield[1]) - end - - function suite.setarray_Inserts_OnTableValue() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = { } - premake.setarray("config", "myfield", { "hello", "goodbye" }) - test.isequal("hello", premake.CurrentConfiguration.myfield[1]) - test.isequal("goodbye", premake.CurrentConfiguration.myfield[2]) - end - - function suite.setarray_Appends_OnNewValues() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = { "hello" } - premake.setarray("config", "myfield", "goodbye") - test.isequal("hello", premake.CurrentConfiguration.myfield[1]) - test.isequal("goodbye", premake.CurrentConfiguration.myfield[2]) - end - - function suite.setarray_FlattensTables() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = { } - premake.setarray("config", "myfield", { {"hello"}, {"goodbye"} }) - test.isequal("hello", premake.CurrentConfiguration.myfield[1]) - test.isequal("goodbye", premake.CurrentConfiguration.myfield[2]) - end - - function suite.setarray_RaisesError_OnInvalidValue() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = { } - ok, err = pcall(function () premake.setarray("config", "myfield", "bad", { "Good", "Better", "Best" }) end) - test.isfalse(ok) - end - - function suite.setarray_CorrectsCase_OnConstrainedValue() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = { } - premake.setarray("config", "myfield", "better", { "Good", "Better", "Best" }) - test.isequal("Better", premake.CurrentConfiguration.myfield[1]) - end - - - --- --- premake.setstring() tests --- - - function suite.setstring_Sets_OnNewProperty() - premake.CurrentConfiguration = { } - premake.setstring("config", "myfield", "hello") - test.isequal("hello", premake.CurrentConfiguration.myfield) - end - - function suite.setstring_Overwrites_OnExistingProperty() - premake.CurrentConfiguration = { } - premake.CurrentConfiguration.myfield = "hello" - premake.setstring("config", "myfield", "goodbye") - test.isequal("goodbye", premake.CurrentConfiguration.myfield) - end - - function suite.setstring_RaisesError_OnInvalidValue() - premake.CurrentConfiguration = { } - ok, err = pcall(function () premake.setstring("config", "myfield", "bad", { "Good", "Better", "Best" }) end) - test.isfalse(ok) - end - - function suite.setstring_CorrectsCase_OnConstrainedValue() - premake.CurrentConfiguration = { } - premake.setstring("config", "myfield", "better", { "Good", "Better", "Best" }) - test.isequal("Better", premake.CurrentConfiguration.myfield) - end - - --- --- accessor tests --- - - function suite.accessor_CanRetrieveString() - sln.blocks[1].kind = "ConsoleApp" - test.isequal("ConsoleApp", kind()) - end - - --- --- solution() tests --- - - function suite.solution_SetsCurrentContainer_OnName() - test.istrue(sln == premake.CurrentContainer) - end - - function suite.solution_CreatesNewObject_OnNewName() - solution "MySolution2" - test.isfalse(sln == premake.CurrentContainer) - end - - function suite.solution_ReturnsPrevious_OnExistingName() - solution "MySolution2" - local sln2 = solution "MySolution" - test.istrue(sln == sln2) - end - - function suite.solution_SetsCurrentContainer_OnExistingName() - solution "MySolution2" - solution "MySolution" - test.istrue(sln == premake.CurrentContainer) - end - - function suite.solution_ReturnsNil_OnNoActiveSolutionAndNoName() - premake.CurrentContainer = nil - test.isnil(solution()) - end - - function suite.solution_ReturnsCurrentSolution_OnActiveSolutionAndNoName() - test.istrue(sln == solution()) - end - - function suite.solution_ReturnsCurrentSolution_OnActiveProjectAndNoName() - project "MyProject" - test.istrue(sln == solution()) - end - - function suite.solution_LeavesProjectActive_OnActiveProjectAndNoName() - local prj = project "MyProject" - solution() - test.istrue(prj == premake.CurrentContainer) - end - - function suite.solution_LeavesConfigActive_OnActiveSolutionAndNoName() - local cfg = configuration "windows" - solution() - test.istrue(cfg == premake.CurrentConfiguration) - end - - function suite.solution_LeavesConfigActive_OnActiveProjectAndNoName() - project "MyProject" - local cfg = configuration "windows" - solution() - test.istrue(cfg == premake.CurrentConfiguration) - end - - function suite.solution_SetsName_OnNewName() - test.isequal("MySolution", sln.name) - end - - function suite.solution_AddsNewConfig_OnNewName() - test.istrue(#sln.blocks == 1) - end - - function suite.solution_AddsNewConfig_OnName() - local num = #sln.blocks - solution "MySolution" - test.istrue(#sln.blocks == num + 1) - end - - - --- --- configuration() tests --- - - function suite.configuration_RaisesError_OnNoContainer() - premake.CurrentContainer = nil - local fn = function() configuration{"Debug"} end - ok, err = pcall(fn) - test.isfalse(ok) - end - - function suite.configuration_SetsCurrentConfiguration_OnKeywords() - local cfg = configuration {"Debug"} - test.istrue(premake.CurrentConfiguration == cfg) - end - - function suite.configuration_AddsToContainer_OnKeywords() - local cfg = configuration {"Debug"} - test.istrue(cfg == sln.blocks[#sln.blocks]) - end - - function suite.configuration_ReturnsCurrent_OnNoKeywords() - local cfg = configuration() - test.istrue(cfg == sln.blocks[1]) - end - - function suite.configuration_SetsTerms() - local cfg = configuration {"aa", "bb"} - test.isequal({"aa", "bb"}, cfg.terms) - end - - function suite.configuration_SetsTermsWithNestedTables() - local cfg = configuration { {"aa", "bb"}, "cc" } - test.isequal({"aa", "bb", "cc"}, cfg.terms) - end - - function suite.configuration_CanReuseTerms() - local cfg = configuration { "aa", "bb" } - local cfg2 = configuration { cfg.terms, "cc" } - test.isequal({"aa", "bb", "cc"}, cfg2.terms) - end - - --- --- project() tests --- - - function suite.project_RaisesError_OnNoSolution() - premake.CurrentContainer = nil - local fn = function() project("MyProject") end - ok, err = pcall(fn) - test.isfalse(ok) - end - - function suite.project_SetsCurrentContainer_OnName() - local prj = project "MyProject" - test.istrue(prj == premake.CurrentContainer) - end - - function suite.project_CreatesNewObject_OnNewName() - local prj = project "MyProject" - local pr2 = project "MyProject2" - test.isfalse(prj == premake.CurrentContainer) - end - - function suite.project_AddsToSolution_OnNewName() - local prj = project "MyProject" - test.istrue(prj == sln.projects[1]) - end - - function suite.project_ReturnsPrevious_OnExistingName() - local prj = project "MyProject" - local pr2 = project "MyProject2" - local pr3 = project "MyProject" - test.istrue(prj == pr3) - end - - function suite.project_SetsCurrentContainer_OnExistingName() - local prj = project "MyProject" - local pr2 = project "MyProject2" - local pr3 = project "MyProject" - test.istrue(prj == premake.CurrentContainer) - end - - function suite.project_ReturnsNil_OnNoActiveProjectAndNoName() - test.isnil(project()) - end - - function suite.project_ReturnsCurrentProject_OnActiveProjectAndNoName() - local prj = project "MyProject" - test.istrue(prj == project()) - end - - function suite.project_LeavesProjectActive_OnActiveProjectAndNoName() - local prj = project "MyProject" - project() - test.istrue(prj == premake.CurrentContainer) - end - - function suite.project_LeavesConfigActive_OnActiveProjectAndNoName() - local prj = project "MyProject" - local cfg = configuration "Windows" - project() - test.istrue(cfg == premake.CurrentConfiguration) - end - - function suite.project_SetsName_OnNewName() - prj = project("MyProject") - test.isequal("MyProject", prj.name) - end - - function suite.project_SetsSolution_OnNewName() - prj = project("MyProject") - test.istrue(sln == prj.solution) - end - - function suite.project_SetsConfiguration() - prj = project("MyProject") - test.istrue(premake.CurrentConfiguration == prj.blocks[1]) - end - - function suite.project_SetsUUID() - local prj = project "MyProject" - test.istrue(prj.uuid) - end - - - --- --- uuid() tests --- - - function suite.uuid_makes_uppercase() - premake.CurrentContainer = {} - uuid "7CBB5FC2-7449-497f-947F-129C5129B1FB" - test.isequal(premake.CurrentContainer.uuid, "7CBB5FC2-7449-497F-947F-129C5129B1FB") - end Index: ps/trunk/build/premake/premake4/tests/base/test_baking.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_baking.lua +++ ps/trunk/build/premake/premake4/tests/base/test_baking.lua @@ -1,186 +0,0 @@ --- --- tests/test_baking.lua --- Automated test suite for the configuration baking functions. --- Copyright (c) 2009, 2010 Jason Perkins and the Premake project --- - - T.baking = { } - local suite = T.baking - --- --- Setup code --- - - local prj, cfg - function suite.setup() - _ACTION = "gmake" - - solution "MySolution" - configurations { "Debug", "Release" } - platforms { "x32", "ps3" } - - defines "SOLUTION" - - configuration "Debug" - defines "SOLUTION_DEBUG" - - prj = project "MyProject" - language "C" - kind "SharedLib" - targetdir "../bin" - defines "PROJECT" - - configuration "Debug" - defines "DEBUG" - - configuration "Release" - defines "RELEASE" - - configuration "native" - defines "NATIVE" - - configuration "x32" - defines "X86_32" - - configuration "x64" - defines "X86_64" - end - - local function prepare() - premake.buildconfigs() - prj = premake.getconfig(prj) - cfg = premake.getconfig(prj, "Debug") - end - - --- --- Tests --- - - function suite.SolutionFields() - prepare() - test.isequal("Debug:Release", table.concat(cfg.configurations,":")) - end - - - function suite.ProjectFields() - prepare() - test.isequal("C", cfg.language) - end - - - function suite.ProjectWideSettings() - prepare() - test.isequal("SOLUTION:PROJECT:NATIVE", table.concat(prj.defines,":")) - end - - - function suite.BuildCfgSettings() - prepare() - test.isequal("SOLUTION:SOLUTION_DEBUG:PROJECT:DEBUG:NATIVE", table.concat(cfg.defines,":")) - end - - - function suite.PlatformSettings() - prepare() - local cfg = premake.getconfig(prj, "Debug", "x32") - test.isequal("SOLUTION:SOLUTION_DEBUG:PROJECT:DEBUG:X86_32", table.concat(cfg.defines,":")) - end - - - function suite.SetsConfigName() - prepare() - local cfg = premake.getconfig(prj, "Debug", "x32") - test.isequal("Debug", cfg.name) - end - - - function suite.SetsPlatformName() - prepare() - local cfg = premake.getconfig(prj, "Debug", "x32") - test.isequal("x32", cfg.platform) - end - - - function suite.SetsPlatformNativeName() - test.isequal("Native", cfg.platform) - end - - - function suite.SetsShortName() - prepare() - local cfg = premake.getconfig(prj, "Debug", "x32") - test.isequal("debug32", cfg.shortname) - end - - - function suite.SetsNativeShortName() - prepare() - test.isequal("debug", cfg.shortname) - end - - - function suite.SetsLongName() - prepare() - local cfg = premake.getconfig(prj, "Debug", "x32") - test.isequal("Debug|x32", cfg.longname) - end - - - function suite.SetsNativeLongName() - prepare() - test.isequal("Debug", cfg.longname) - end - - - function suite.SetsProject() - prepare() - local cfg = premake.getconfig(prj, "Debug", "x32") - test.istrue(prj.project == cfg.project) - end - - - --- --- Target system testing --- - - function suite.SetsTargetSystem_OnNative() - prepare() - test.isequal(os.get(), cfg.system) - end - - function suite.SetTargetSystem_OnCrossCompiler() - prepare() - local cfg = premake.getconfig(prj, "Debug", "PS3") - test.isequal("PS3", cfg.system) - end - - - --- --- Configuration-specific kinds --- - - function suite.SetsConfigSpecificKind() - configuration "Debug" - kind "ConsoleApp" - prepare() - test.isequal("ConsoleApp", cfg.kind) - end - - --- --- Platform kind translation --- - - function suite.SetsTargetKind_OnSupportedKind() - prepare() - test.isequal("SharedLib", cfg.kind) - end - - function suite.SetsTargetKind_OnUnsupportedKind() - prepare() - local cfg = premake.getconfig(prj, "Debug", "PS3") - test.isequal("StaticLib", cfg.kind) - end Index: ps/trunk/build/premake/premake4/tests/base/test_config.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_config.lua +++ ps/trunk/build/premake/premake4/tests/base/test_config.lua @@ -1,58 +0,0 @@ --- --- tests/test_config.lua --- Automated test suite for the configuration handling functions. --- Copyright (c) 2010 Jason Perkins and the Premake project --- - - T.config = { } - local suite = T.config - - --- --- Setup/Teardown --- - - function suite.setup() - sln = test.createsolution() - end - - local cfg - local function prepare() - io.capture() - premake.buildconfigs() - cfg = premake.solution.getproject(sln, 1) - end - - --- --- Debug/Release build testing --- - - function suite.IsDebug_ReturnsFalse_OnOptimizeFlag() - flags { "Optimize" } - prepare() - return test.isfalse(premake.config.isdebugbuild(cfg)) - end - - function suite.IsDebug_ReturnsFalse_OnOptimizeSizeFlag() - flags { "OptimizeSize" } - prepare() - return test.isfalse(premake.config.isdebugbuild(cfg)) - end - - function suite.IsDebug_ReturnsFalse_OnOptimizeSpeedFlag() - flags { "OptimizeSpeed" } - prepare() - return test.isfalse(premake.config.isdebugbuild(cfg)) - end - - function suite.IsDebug_ReturnsFalse_OnNoSymbolsFlag() - prepare() - return test.isfalse(premake.config.isdebugbuild(cfg)) - end - - function suite.IsDebug_ReturnsTrue_OnSymbolsFlag() - flags { "Symbols" } - prepare() - return test.istrue(premake.config.isdebugbuild(cfg)) - end Index: ps/trunk/build/premake/premake4/tests/base/test_os.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_os.lua +++ ps/trunk/build/premake/premake4/tests/base/test_os.lua @@ -1,121 +0,0 @@ --- --- tests/base/test_os.lua --- Automated test suite for the new OS functions. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - - T.os = { } - local suite = T.os - - --- --- os.findlib() tests --- - - function suite.findlib_FindSystemLib() - local libname = iif(os.is("windows"), "user32", "m") - test.istrue(os.findlib(libname)) - end - - function suite.findlib_FailsOnBadLibName() - test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere")) - end - - --- --- os.isfile() tests --- - - function suite.isfile_ReturnsTrue_OnExistingFile() - test.istrue(os.isfile("premake4.lua")) - end - - function suite.isfile_ReturnsFalse_OnNonexistantFile() - test.isfalse(os.isfile("no_such_file.lua")) - end - - - --- --- os.matchfiles() tests --- - - function suite.matchfiles_OnNonRecursive() - local result = os.matchfiles("*.lua") - test.istrue(table.contains(result, "testfx.lua")) - test.isfalse(table.contains(result, "folder/ok.lua")) - end - - function suite.matchfiles_Recursive() - local result = os.matchfiles("**.lua") - test.istrue(table.contains(result, "folder/ok.lua")) - end - - function suite.matchfiles_SkipsDotDirs_OnRecursive() - local result = os.matchfiles("**.lua") - test.isfalse(table.contains(result, ".svn/text-base/testfx.lua.svn-base")) - end - - function suite.matchfiles_OnSubfolderMatch() - local result = os.matchfiles("**/xcode/*") - test.istrue(table.contains(result, "actions/xcode/test_xcode_project.lua")) - test.isfalse(table.contains(result, "premake4.lua")) - end - - function suite.matchfiles_OnDotSlashPrefix() - local result = os.matchfiles("./**.lua") - test.istrue(table.contains(result, "folder/ok.lua")) - end - - function suite.matchfiles_OnImplicitEndOfString() - local result = os.matchfiles("folder/*.lua") - test.istrue(table.contains(result, "folder/ok.lua")) - test.isfalse(table.contains(result, "folder/ok.lua.2")) - end - - function suite.matchfiles_OnLeadingDotSlashWithPath() - local result = os.matchfiles("./folder/*.lua") - test.istrue(table.contains(result, "folder/ok.lua")) - end - - - --- --- os.pathsearch() tests --- - - function suite.pathsearch_ReturnsNil_OnNotFound() - test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil ) - end - - function suite.pathsearch_ReturnsPath_OnFound() - test.isequal(os.getcwd(), os.pathsearch("premake4.lua", os.getcwd())) - end - - function suite.pathsearch_FindsFile_OnComplexPath() - test.isequal(os.getcwd(), os.pathsearch("premake4.lua", "aaa;"..os.getcwd()..";bbb")) - end - - function suite.pathsearch_NilPathsAllowed() - test.isequal(os.getcwd(), os.pathsearch("premake4.lua", nil, os.getcwd(), nil)) - end - - --- --- os.uuid() tests --- - - function suite.guid_ReturnsValidUUID() - local g = os.uuid() - test.istrue(#g == 36) - for i=1,36 do - local ch = g:sub(i,i) - test.istrue(ch:find("[ABCDEF0123456789-]")) - end - test.isequal("-", g:sub(9,9)) - test.isequal("-", g:sub(14,14)) - test.isequal("-", g:sub(19,19)) - test.isequal("-", g:sub(24,24)) - end - Index: ps/trunk/build/premake/premake4/tests/base/test_path.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_path.lua +++ ps/trunk/build/premake/premake4/tests/base/test_path.lua @@ -1,216 +0,0 @@ --- --- tests/base/test_path.lua --- Automated test suite for the action list. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - T.path = { } - local suite = T.path - - --- --- path.getabsolute() tests --- - - function suite.getabsolute_ReturnsCorrectPath_OnMissingSubdir() - local expected = path.translate(os.getcwd(), "/") .. "/a/b/c" - test.isequal(expected, path.getabsolute("a/b/c")) - end - - function suite.getabsolute_RemovesDotDots_OnWindowsAbsolute() - test.isequal("c:/ProjectB/bin", path.getabsolute("c:/ProjectA/../ProjectB/bin")) - end - - function suite.getabsolute_RemovesDotDots_OnPosixAbsolute() - test.isequal("/ProjectB/bin", path.getabsolute("/ProjectA/../ProjectB/bin")) - end - - function suite.getabsolute_OnTrailingSlash() - local expected = path.translate(os.getcwd(), "/") .. "/a/b/c" - test.isequal(expected, path.getabsolute("a/b/c/")) - end - - --- --- path.getbasename() tests --- - - function suite.getbasename_ReturnsCorrectName_OnDirAndExtension() - test.isequal("filename", path.getbasename("folder/filename.ext")) - end - - --- --- path.getdirectory() tests --- - - function suite.getdirectory_ReturnsEmptyString_OnNoDirectory() - test.isequal(".", path.getdirectory("filename.ext")) - end - - function suite.getdirectory_ReturnsDirectory_OnSingleLevelPath() - test.isequal("dir0", path.getdirectory("dir0/filename.ext")) - end - - function suite.getdirectory_ReturnsDirectory_OnMultiLeveLPath() - test.isequal("dir0/dir1/dir2", path.getdirectory("dir0/dir1/dir2/filename.ext")) - end - - function suite.getdirectory_ReturnsRootPath_OnRootPathOnly() - test.isequal("/", path.getdirectory("/filename.ext")) - end - - - --- --- path.getdrive() tests --- - - function suite.getdrive_ReturnsNil_OnNotWindows() - test.isnil(path.getdrive("/hello")) - end - - function suite.getdrive_ReturnsLetter_OnWindowsAbsolute() - test.isequal("x", path.getdrive("x:/hello")) - end - - - --- --- path.getextension() tests --- - - function suite.getextension_ReturnsEmptyString_OnNoExtension() - test.isequal("", path.getextension("filename")) - end - - function suite.getextension_ReturnsExtension() - test.isequal(".txt", path.getextension("filename.txt")) - end - - function suite.getextension_OnMultipleDots() - test.isequal(".txt", path.getextension("filename.mod.txt")) - end - - --- --- path.getrelative() tests --- - - function suite.getrelative_ReturnsDot_OnMatchingPaths() - test.isequal(".", path.getrelative("/a/b/c", "/a/b/c")) - end - - function suite.getrelative_ReturnsDoubleDot_OnChildToParent() - test.isequal("..", path.getrelative("/a/b/c", "/a/b")) - end - - function suite.getrelative_ReturnsDoubleDot_OnSiblingToSibling() - test.isequal("../d", path.getrelative("/a/b/c", "/a/b/d")) - end - - function suite.getrelative_ReturnsChildPath_OnParentToChild() - test.isequal("d", path.getrelative("/a/b/c", "/a/b/c/d")) - end - - function suite.getrelative_ReturnsChildPath_OnWindowsAbsolute() - test.isequal("obj/debug", path.getrelative("C:/Code/Premake4", "C:/Code/Premake4/obj/debug")) - end - - function suite.getrelative_ReturnsAbsPath_OnDifferentDriveLetters() - test.isequal("D:/Files", path.getrelative("C:/Code/Premake4", "D:/Files")) - end - - function suite.getrelative_ReturnsAbsPath_OnDollarMacro() - test.isequal("$(SDK_HOME)/include", path.getrelative("C:/Code/Premake4", "$(SDK_HOME)/include")) - end - - function suite.getrelative_ReturnsAbsPath_OnRootedPath() - test.isequal("/opt/include", path.getrelative("/home/me/src/project", "/opt/include")) - end - - --- --- path.isabsolute() tests --- - - function suite.isabsolute_ReturnsTrue_OnAbsolutePosixPath() - test.istrue(path.isabsolute("/a/b/c")) - end - - function suite.isabsolute_ReturnsTrue_OnAbsoluteWindowsPathWithDrive() - test.istrue(path.isabsolute("C:/a/b/c")) - end - - function suite.isabsolute_ReturnsFalse_OnRelativePath() - test.isfalse(path.isabsolute("a/b/c")) - end - - function suite.isabsolute_ReturnsTrue_OnDollarSign() - test.istrue(path.isabsolute("$(SDK_HOME)/include")) - end - - --- --- path.join() tests --- - - function suite.join_OnValidParts() - test.isequal("leading/trailing", path.join("leading", "trailing")) - end - - function suite.join_OnAbsoluteUnixPath() - test.isequal("/trailing", path.join("leading", "/trailing")) - end - - function suite.join_OnAbsoluteWindowsPath() - test.isequal("C:/trailing", path.join("leading", "C:/trailing")) - end - - function suite.join_OnCurrentDirectory() - test.isequal("trailing", path.join(".", "trailing")) - end - - --- --- path.rebase() tests --- - - function suite.rebase_WithEndingSlashOnPath() - local cwd = os.getcwd() - test.isequal("src", path.rebase("../src/", cwd, path.getdirectory(cwd))) - end - - --- --- path.translate() tests --- - - function suite.translate_ReturnsTranslatedPath_OnValidPath() - test.isequal("dir/dir/file", path.translate("dir\\dir\\file", "/")) - end - - function suite.translate_ReturnsCorrectSeparator_OnMixedPath() - local actual = path.translate("dir\\dir/file") - if (os.is("windows")) then - test.isequal("dir\\dir\\file", actual) - else - test.isequal("dir/dir/file", actual) - end - end - - --- --- path.wildcards tests --- - - function suite.wildcards_MatchesTrailingStar() - local p = path.wildcards("**/xcode/*") - test.isequal(".*/xcode/[^/]*", p) - end - - function suite.wildcards_MatchPlusSign() - local patt = path.wildcards("file+name.*") - local name = "file+name.c" - test.isequal(name, name:match(patt)) - end Index: ps/trunk/build/premake/premake4/tests/base/test_table.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_table.lua +++ ps/trunk/build/premake/premake4/tests/base/test_table.lua @@ -1,57 +0,0 @@ --- --- tests/base/test_table.lua --- Automated test suite for the new table functions. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - - T.table = { } - local suite = T.table - - --- --- table.contains() tests --- - - function suite.contains_OnContained() - t = { "one", "two", "three" } - test.istrue( table.contains(t, "two") ) - end - - function suite.contains_OnNotContained() - t = { "one", "two", "three" } - test.isfalse( table.contains(t, "four") ) - end - - --- --- table.flatten() tests --- - - function suite.flatten_OnMixedValues() - t = { "a", { "b", "c" }, "d" } - test.isequal({ "a", "b", "c", "d" }, table.flatten(t)) - end - - --- --- table.implode() tests --- - - function suite.implode() - t = { "one", "two", "three", "four" } - test.isequal("[one], [two], [three], [four]", table.implode(t, "[", "]", ", ")) - end - - --- --- table.isempty() tests --- - - function suite.isempty_ReturnsTrueOnEmpty() - test.istrue(table.isempty({})) - end - - function suite.isempty_ReturnsFalseOnNotEmpty() - test.isfalse(table.isempty({ 1 })) - end Index: ps/trunk/build/premake/premake4/tests/base/test_tree.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/base/test_tree.lua +++ ps/trunk/build/premake/premake4/tests/base/test_tree.lua @@ -1,143 +0,0 @@ --- --- tests/base/test_tree.lua --- Automated test suite source code tree handling. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.tree = { } - local suite = T.tree - local tree = premake.tree - - --- --- Setup/teardown --- - - local tr, nodes - - function suite.setup() - tr = tree.new() - nodes = { } - end - - local function getresult() - tree.traverse(tr, { - onnode = function(node, depth) - table.insert(nodes, string.rep(">", depth) .. node.name) - end - }) - return table.concat(nodes) - end - - - --- --- Tests for tree.new() --- - - function suite.NewReturnsObject() - test.isnotnil(tr) - end - - --- --- Tests for tree.add() --- - - function suite.CanAddAtRoot() - tree.add(tr, "Root") - test.isequal("Root", getresult()) - end - - function suite.CanAddAtChild() - tree.add(tr, "Root/Child") - test.isequal("Root>Child", getresult()) - end - - function suite.CanAddAtGrandchild() - tree.add(tr, "Root/Child/Grandchild") - test.isequal("Root>Child>>Grandchild", getresult()) - end - - function suite.SkipsLeadingDotDots() - tree.add(tr, "../MyProject/hello") - test.isequal("MyProject>hello", getresult()) - end - - function suite.SkipsInlineDotDots() - tree.add(tr, "MyProject/../hello") - test.isequal("MyProject>hello", getresult()) - end - - function suite.AddsNodes_OnDifferentParentLevel() - tree.add(tr, "../Common") - tree.add(tr, "../../Common") - test.isequal(2, #tr.children) - test.isequal("Common", tr.children[1].name) - test.isequal("Common", tr.children[2].name) - test.isequal("../Common", tr.children[1].path) - test.isequal("../../Common", tr.children[2].path) - end - - --- --- Tests for tree.getlocalpath() --- - - function suite.GetLocalPath_ReturnsPath_OnNoParentPath() - local c = tree.add(tr, "Root/Child") - c.parent.path = nil - test.isequal("Root/Child", tree.getlocalpath(c)) - end - - function suite.GetLocalPath_ReturnsName_OnParentPathSet() - local c = tree.add(tr, "Root/Child") - test.isequal("Child", tree.getlocalpath(c)) - end - - --- --- Tests for tree.remove() --- - - function suite.Remove_RemovesNodes() - local n1 = tree.add(tr, "1") - local n2 = tree.add(tr, "2") - local n3 = tree.add(tr, "3") - tree.remove(n2) - local r = "" - for _, n in ipairs(tr.children) do r = r .. n.name end - test.isequal("13", r) - end - - - function suite.Remove_WorksInTraversal() - tree.add(tr, "Root/1") - tree.add(tr, "Root/2") - tree.add(tr, "Root/3") - local r = "" - tree.traverse(tr, { - onleaf = function(node) - r = r .. node.name - tree.remove(node) - end - }) - test.isequal("123", r) - test.isequal(0, #tr.children[1]) - end - - --- --- Tests for tree.sort() --- - - function suite.Sort_SortsAllLevels() - tree.add(tr, "B/3") - tree.add(tr, "B/1") - tree.add(tr, "A/2") - tree.add(tr, "A/1") - tree.add(tr, "B/2") - tree.sort(tr) - test.isequal("A>1>2B>1>2>3", getresult(tr)) - end - Index: ps/trunk/build/premake/premake4/tests/folder/ok.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/folder/ok.lua +++ ps/trunk/build/premake/premake4/tests/folder/ok.lua @@ -1 +0,0 @@ -return "ok" Index: ps/trunk/build/premake/premake4/tests/folder/ok.lua.2 =================================================================== --- ps/trunk/build/premake/premake4/tests/folder/ok.lua.2 +++ ps/trunk/build/premake/premake4/tests/folder/ok.lua.2 @@ -1 +0,0 @@ -return "ok" Index: ps/trunk/build/premake/premake4/tests/pepperfish_profiler.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/pepperfish_profiler.lua +++ ps/trunk/build/premake/premake4/tests/pepperfish_profiler.lua @@ -1,616 +0,0 @@ ---[[ - -== Introduction == - - Note that this requires os.clock(), debug.sethook(), - and debug.getinfo() or your equivalent replacements to - be available if this is an embedded application. - - Example usage: - - profiler = newProfiler() - profiler:start() - - < call some functions that take time > - - profiler:stop() - - local outfile = io.open( "profile.txt", "w+" ) - profiler:report( outfile ) - outfile:close() - -== Optionally choosing profiling method == - -The rest of this comment can be ignored if you merely want a good profiler. - - newProfiler(method, sampledelay): - -If method is omitted or "time", will profile based on real performance. -optionally, frequency can be provided to control the number of opcodes -per profiling tick. By default this is 100000, which (on my system) provides -one tick approximately every 2ms and reduces system performance by about 10%. -This can be reduced to increase accuracy at the cost of performance, or -increased for the opposite effect. - -If method is "call", will profile based on function calls. Frequency is -ignored. - - -"time" may bias profiling somewhat towards large areas with "simple opcodes", -as the profiling function (which introduces a certain amount of unavoidable -overhead) will be called more often. This can be minimized by using a larger -sample delay - the default should leave any error largely overshadowed by -statistical noise. With a delay of 1000 I was able to achieve inaccuray of -approximately 25%. Increasing the delay to 100000 left inaccuracy below my -testing error. - -"call" may bias profiling heavily towards areas with many function calls. -Testing found a degenerate case giving a figure inaccurate by approximately -20,000%. (Yes, a multiple of 200.) This is, however, more directly comparable -to common profilers (such as gprof) and also gives accurate function call -counts, which cannot be retrieved from "time". - -I strongly recommend "time" mode, and it is now the default. - -== History == - -2008-09-16 - Time-based profiling and conversion to Lua 5.1 - by Ben Wilhelm ( zorba-pepperfish@pavlovian.net ). - Added the ability to optionally choose profiling methods, along with a new - profiling method. - -Converted to Lua 5, a few improvements, and -additional documentation by Tom Spilman ( tom@sickheadgames.com ) - -Additional corrections and tidying by original author -Daniel Silverstone ( dsilvers@pepperfish.net ) - -== Status == - -Daniel Silverstone is no longer using this code, and judging by how long it's -been waiting for Lua 5.1 support, I don't think Tom Spilman is either. I'm -perfectly willing to take on maintenance, so if you have problems or -questions, go ahead and email me :) --- Ben Wilhelm ( zorba-pepperfish@pavlovian.net ) ' - -== Copyright == - -Lua profiler - Copyright Pepperfish 2002,2003,2004 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to -do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -IN THE SOFTWARE. - ---]] - - --- --- All profiler related stuff is stored in the top level table '_profiler' --- -_profiler = {} - - --- --- newProfiler() creates a new profiler object for managing --- the profiler and storing state. Note that only one profiler --- object can be executing at one time. --- -function newProfiler(variant, sampledelay) - if _profiler.running then - print("Profiler already running.") - return - end - - variant = variant or "time" - - if variant ~= "time" and variant ~= "call" then - print("Profiler method must be 'time' or 'call'.") - return - end - - local newprof = {} - for k,v in pairs(_profiler) do - newprof[k] = v - end - newprof.variant = variant - newprof.sampledelay = sampledelay or 100000 - return newprof -end - - --- --- This function starts the profiler. It will do nothing --- if this (or any other) profiler is already running. --- -function _profiler.start(self) - if _profiler.running then - return - end - -- Start the profiler. This begins by setting up internal profiler state - _profiler.running = self - self.rawstats = {} - self.callstack = {} - if self.variant == "time" then - self.lastclock = os.clock() - debug.sethook( _profiler_hook_wrapper_by_time, "", self.sampledelay ) - elseif self.variant == "call" then - debug.sethook( _profiler_hook_wrapper_by_call, "cr" ) - else - print("Profiler method must be 'time' or 'call'.") - sys.exit(1) - end -end - - --- --- This function stops the profiler. It will do nothing --- if a profiler is not running, and nothing if it isn't --- the currently running profiler. --- -function _profiler.stop(self) - if _profiler.running ~= self then - return - end - -- Stop the profiler. - debug.sethook( nil ) - _profiler.running = nil -end - - --- --- Simple wrapper to handle the hook. You should not --- be calling this directly. Duplicated to reduce overhead. --- -function _profiler_hook_wrapper_by_call(action) - if _profiler.running == nil then - debug.sethook( nil ) - end - _profiler.running:_internal_profile_by_call(action) -end -function _profiler_hook_wrapper_by_time(action) - if _profiler.running == nil then - debug.sethook( nil ) - end - _profiler.running:_internal_profile_by_time(action) -end - - --- --- This is the main by-function-call function of the profiler and should not --- be called except by the hook wrapper --- -function _profiler._internal_profile_by_call(self,action) - -- Since we can obtain the 'function' for the item we've had call us, we - -- can use that... - local caller_info = debug.getinfo( 3 ) - if caller_info == nil then - print "No caller_info" - return - end - - --SHG_LOG("[_profiler._internal_profile] "..(caller_info.name or "")) - - -- Retrieve the most recent activation record... - local latest_ar = nil - if table.getn(self.callstack) > 0 then - latest_ar = self.callstack[table.getn(self.callstack)] - end - - -- Are we allowed to profile this function? - local should_not_profile = 0 - for k,v in pairs(self.prevented_functions) do - if k == caller_info.func then - should_not_profile = v - end - end - -- Also check the top activation record... - if latest_ar then - if latest_ar.should_not_profile == 2 then - should_not_profile = 2 - end - end - - -- Now then, are we in 'call' or 'return' ? - -- print("Profile:", caller_info.name, "SNP:", should_not_profile, - -- "Action:", action ) - if action == "call" then - -- Making a call... - local this_ar = {} - this_ar.should_not_profile = should_not_profile - this_ar.parent_ar = latest_ar - this_ar.anon_child = 0 - this_ar.name_child = 0 - this_ar.children = {} - this_ar.children_time = {} - this_ar.clock_start = os.clock() - -- Last thing to do on a call is to insert this onto the ar stack... - table.insert( self.callstack, this_ar ) - else - local this_ar = latest_ar - if this_ar == nil then - return -- No point in doing anything if no upper activation record - end - - -- Right, calculate the time in this function... - this_ar.clock_end = os.clock() - this_ar.this_time = this_ar.clock_end - this_ar.clock_start - - -- Now, if we have a parent, update its call info... - if this_ar.parent_ar then - this_ar.parent_ar.children[caller_info.func] = - (this_ar.parent_ar.children[caller_info.func] or 0) + 1 - this_ar.parent_ar.children_time[caller_info.func] = - (this_ar.parent_ar.children_time[caller_info.func] or 0 ) + - this_ar.this_time - if caller_info.name == nil then - this_ar.parent_ar.anon_child = - this_ar.parent_ar.anon_child + this_ar.this_time - else - this_ar.parent_ar.name_child = - this_ar.parent_ar.name_child + this_ar.this_time - end - end - -- Now if we're meant to record information about ourselves, do so... - if this_ar.should_not_profile == 0 then - local inforec = self:_get_func_rec(caller_info.func,1) - inforec.count = inforec.count + 1 - inforec.time = inforec.time + this_ar.this_time - inforec.anon_child_time = inforec.anon_child_time + this_ar.anon_child - inforec.name_child_time = inforec.name_child_time + this_ar.name_child - inforec.func_info = caller_info - for k,v in pairs(this_ar.children) do - inforec.children[k] = (inforec.children[k] or 0) + v - inforec.children_time[k] = - (inforec.children_time[k] or 0) + this_ar.children_time[k] - end - end - - -- Last thing to do on return is to drop the last activation record... - table.remove( self.callstack, table.getn( self.callstack ) ) - end -end - - --- --- This is the main by-time internal function of the profiler and should not --- be called except by the hook wrapper --- -function _profiler._internal_profile_by_time(self,action) - -- we do this first so we add the minimum amount of extra time to this call - local timetaken = os.clock() - self.lastclock - - local depth = 3 - local at_top = true - local last_caller - local caller = debug.getinfo(depth) - while caller do - if not caller.func then caller.func = "(tail call)" end - if self.prevented_functions[caller.func] == nil then - local info = self:_get_func_rec(caller.func, 1, caller) - info.count = info.count + 1 - info.time = info.time + timetaken - if last_caller then - -- we're not the head, so update the "children" times also - if last_caller.name then - info.name_child_time = info.name_child_time + timetaken - else - info.anon_child_time = info.anon_child_time + timetaken - end - info.children[last_caller.func] = - (info.children[last_caller.func] or 0) + 1 - info.children_time[last_caller.func] = - (info.children_time[last_caller.func] or 0) + timetaken - end - end - depth = depth + 1 - last_caller = caller - caller = debug.getinfo(depth) - end - - self.lastclock = os.clock() -end - - --- --- This returns a (possibly empty) function record for --- the specified function. It is for internal profiler use. --- -function _profiler._get_func_rec(self,func,force,info) - -- Find the function ref for 'func' (if force and not present, create one) - local ret = self.rawstats[func] - if ret == nil and force ~= 1 then - return nil - end - if ret == nil then - -- Build a new function statistics table - ret = {} - ret.func = func - ret.count = 0 - ret.time = 0 - ret.anon_child_time = 0 - ret.name_child_time = 0 - ret.children = {} - ret.children_time = {} - ret.func_info = info - self.rawstats[func] = ret - end - return ret -end - - --- --- This writes a profile report to the output file object. If --- sort_by_total_time is nil or false the output is sorted by --- the function time minus the time in it's children. --- -function _profiler.report( self, outfile, sort_by_total_time ) - - outfile:write - [[Lua Profile output created by profiler.lua. Copyright Pepperfish 2002+ - -]] - - -- This is pretty awful. - local terms = {} - if self.variant == "time" then - terms.capitalized = "Sample" - terms.single = "sample" - terms.pastverb = "sampled" - elseif self.variant == "call" then - terms.capitalized = "Call" - terms.single = "call" - terms.pastverb = "called" - else - assert(false) - end - - local total_time = 0 - local ordering = {} - for func,record in pairs(self.rawstats) do - table.insert(ordering, func) - end - - if sort_by_total_time then - table.sort( ordering, - function(a,b) return self.rawstats[a].time > self.rawstats[b].time end - ) - else - table.sort( ordering, - function(a,b) - local arec = self.rawstats[a] - local brec = self.rawstats[b] - local atime = arec.time - (arec.anon_child_time + arec.name_child_time) - local btime = brec.time - (brec.anon_child_time + brec.name_child_time) - return atime > btime - end - ) - end - - for i=1,table.getn(ordering) do - local func = ordering[i] - local record = self.rawstats[func] - local thisfuncname = " " .. self:_pretty_name(func) .. " " - if string.len( thisfuncname ) < 42 then - thisfuncname = - string.rep( "-", (42 - string.len(thisfuncname))/2 ) .. thisfuncname - thisfuncname = - thisfuncname .. string.rep( "-", 42 - string.len(thisfuncname) ) - end - - total_time = total_time + ( record.time - ( record.anon_child_time + - record.name_child_time ) ) - outfile:write( string.rep( "-", 19 ) .. thisfuncname .. - string.rep( "-", 19 ) .. "\n" ) - outfile:write( terms.capitalized.." count: " .. - string.format( "%4d", record.count ) .. "\n" ) - outfile:write( "Time spend total: " .. - string.format( "%4.3f", record.time ) .. "s\n" ) - outfile:write( "Time spent in children: " .. - string.format("%4.3f",record.anon_child_time+record.name_child_time) .. - "s\n" ) - local timeinself = - record.time - (record.anon_child_time + record.name_child_time) - outfile:write( "Time spent in self: " .. - string.format("%4.3f", timeinself) .. "s\n" ) - outfile:write( "Time spent per " .. terms.single .. ": " .. - string.format("%4.5f", record.time/record.count) .. - "s/" .. terms.single .. "\n" ) - outfile:write( "Time spent in self per "..terms.single..": " .. - string.format( "%4.5f", timeinself/record.count ) .. "s/" .. - terms.single.."\n" ) - - -- Report on each child in the form - -- Child called n times and took a.bs - local added_blank = 0 - for k,v in pairs(record.children) do - if self.prevented_functions[k] == nil or - self.prevented_functions[k] == 0 - then - if added_blank == 0 then - outfile:write( "\n" ) -- extra separation line - added_blank = 1 - end - outfile:write( "Child " .. self:_pretty_name(k) .. - string.rep( " ", 41-string.len(self:_pretty_name(k)) ) .. " " .. - terms.pastverb.." " .. string.format("%6d", v) ) - outfile:write( " times. Took " .. - string.format("%4.2f", record.children_time[k] ) .. "s\n" ) - end - end - - outfile:write( "\n" ) -- extra separation line - outfile:flush() - end - outfile:write( "\n\n" ) - outfile:write( "Total time spent in profiled functions: " .. - string.format("%5.3g",total_time) .. "s\n" ) - outfile:write( [[ - -END -]] ) - outfile:flush() -end - - --- --- This writes the profile to the output file object as --- loadable Lua source. --- -function _profiler.lua_report(self,outfile) - -- Purpose: Write out the entire raw state in a cross-referenceable form. - local ordering = {} - local functonum = {} - for func,record in pairs(self.rawstats) do - table.insert(ordering, func) - functonum[func] = table.getn(ordering) - end - - outfile:write( - "-- Profile generated by profiler.lua Copyright Pepperfish 2002+\n\n" ) - outfile:write( "-- Function names\nfuncnames = {}\n" ) - for i=1,table.getn(ordering) do - local thisfunc = ordering[i] - outfile:write( "funcnames[" .. i .. "] = " .. - string.format("%q", self:_pretty_name(thisfunc)) .. "\n" ) - end - outfile:write( "\n" ) - outfile:write( "-- Function times\nfunctimes = {}\n" ) - for i=1,table.getn(ordering) do - local thisfunc = ordering[i] - local record = self.rawstats[thisfunc] - outfile:write( "functimes[" .. i .. "] = { " ) - outfile:write( "tot=" .. record.time .. ", " ) - outfile:write( "achild=" .. record.anon_child_time .. ", " ) - outfile:write( "nchild=" .. record.name_child_time .. ", " ) - outfile:write( "count=" .. record.count .. " }\n" ) - end - outfile:write( "\n" ) - outfile:write( "-- Child links\nchildren = {}\n" ) - for i=1,table.getn(ordering) do - local thisfunc = ordering[i] - local record = self.rawstats[thisfunc] - outfile:write( "children[" .. i .. "] = { " ) - for k,v in pairs(record.children) do - if functonum[k] then -- non-recorded functions will be ignored now - outfile:write( functonum[k] .. ", " ) - end - end - outfile:write( "}\n" ) - end - outfile:write( "\n" ) - outfile:write( "-- Child call counts\nchildcounts = {}\n" ) - for i=1,table.getn(ordering) do - local thisfunc = ordering[i] - local record = self.rawstats[thisfunc] - outfile:write( "children[" .. i .. "] = { " ) - for k,v in record.children do - if functonum[k] then -- non-recorded functions will be ignored now - outfile:write( v .. ", " ) - end - end - outfile:write( "}\n" ) - end - outfile:write( "\n" ) - outfile:write( "-- Child call time\nchildtimes = {}\n" ) - for i=1,table.getn(ordering) do - local thisfunc = ordering[i] - local record = self.rawstats[thisfunc]; - outfile:write( "children[" .. i .. "] = { " ) - for k,v in pairs(record.children) do - if functonum[k] then -- non-recorded functions will be ignored now - outfile:write( record.children_time[k] .. ", " ) - end - end - outfile:write( "}\n" ) - end - outfile:write( "\n\n-- That is all.\n\n" ) - outfile:flush() -end - --- Internal function to calculate a pretty name for the profile output -function _profiler._pretty_name(self,func) - - -- Only the data collected during the actual - -- run seems to be correct.... why? - local info = self.rawstats[ func ].func_info - -- local info = debug.getinfo( func ) - - local name = "" - if info.what == "Lua" then - name = "L:" - end - if info.what == "C" then - name = "C:" - end - if info.what == "main" then - name = " :" - end - - if info.name == nil then - name = name .. "<"..tostring(func) .. ">" - else - name = name .. info.name - end - - if info.source then - name = name .. "@" .. info.source - else - if info.what == "C" then - name = name .. "@?" - else - name = name .. "@" - end - end - name = name .. ":" - if info.what == "C" then - name = name .. "?" - else - name = name .. info.linedefined - end - - return name -end - - --- --- This allows you to specify functions which you do --- not want profiled. Setting level to 1 keeps the --- function from being profiled. Setting level to 2 --- keeps both the function and its children from --- being profiled. --- --- BUG: 2 will probably act exactly like 1 in "time" mode. --- If anyone cares, let me (zorba) know and it can be fixed. --- -function _profiler.prevent(self, func, level) - self.prevented_functions[func] = (level or 1) -end - - -_profiler.prevented_functions = { - [_profiler.start] = 2, - [_profiler.stop] = 2, - [_profiler._internal_profile_by_time] = 2, - [_profiler._internal_profile_by_call] = 2, - [_profiler_hook_wrapper_by_time] = 2, - [_profiler_hook_wrapper_by_call] = 2, - [_profiler.prevent] = 2, - [_profiler._get_func_rec] = 2, - [_profiler.report] = 2, - [_profiler.lua_report] = 2, - [_profiler._pretty_name] = 2 -} Index: ps/trunk/build/premake/premake4/tests/premake4.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/premake4.lua +++ ps/trunk/build/premake/premake4/tests/premake4.lua @@ -1,104 +0,0 @@ --- --- tests/premake4.lua --- Automated test suite for Premake 4.x --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - dofile("testfx.lua") - --- --- Some helper functions --- - - test.createsolution = function() - local sln = solution "MySolution" - configurations { "Debug", "Release" } - - local prj = project "MyProject" - language "C++" - kind "ConsoleApp" - - return sln, prj - end - - - test.createproject = function(sln) - local n = #sln.projects + 1 - if n == 1 then n = "" end - - local prj = project ("MyProject" .. n) - language "C++" - kind "ConsoleApp" - return prj - end - - --- --- The test suites --- - - dofile("test_dofile.lua") - dofile("test_string.lua") - dofile("test_premake.lua") - dofile("test_project.lua") - dofile("test_platforms.lua") - dofile("test_targets.lua") - dofile("test_keywords.lua") - dofile("test_gcc.lua") - dofile("test_gmake_cpp.lua") - dofile("test_gmake_cs.lua") - dofile("base/test_api.lua") - dofile("base/test_action.lua") - dofile("base/test_baking.lua") - dofile("base/test_config.lua") - dofile("base/test_os.lua") - dofile("base/test_path.lua") - dofile("base/test_table.lua") - dofile("base/test_tree.lua") - - -- Clean tests - dofile("actions/test_clean.lua") - - -- Visual Studio tests - dofile("test_vs2002_sln.lua") - dofile("test_vs2003_sln.lua") - dofile("test_vs2005_sln.lua") - dofile("test_vs2008_sln.lua") - dofile("test_vs2010_sln.lua") - dofile("actions/vstudio/test_vs2005_csproj.lua") - dofile("actions/vstudio/test_vs200x_vcproj.lua") - dofile("actions/vstudio/test_vs200x_vcproj_linker.lua") - dofile("actions/vstudio/test_vs2010_vcxproj.lua") - dofile("actions/vstudio/test_vs2010_flags.lua") - dofile("actions/vstudio/test_vs2010_links.lua") - dofile("actions/vstudio/test_vs2010_filters.lua") - dofile("actions/vstudio/test_vs2010_project_kinds.lua") - - -- Makefile tests - dofile("actions/make/test_make_escaping.lua") - dofile("actions/make/test_make_pch.lua") - - -- Xcode tests - dofile("actions/xcode/test_xcode_common.lua") - dofile("actions/xcode/test_xcode_project.lua") - dofile("actions/xcode/test_xcode_dependencies.lua") - - --- --- Register a test action --- - - newaction { - trigger = "test", - description = "Run the automated test suite", - - execute = function () - passed, failed = test.runall() - msg = string.format("%d tests passed, %d failed", passed, failed) - if (failed > 0) then - error(msg, 0) - else - print(msg) - end - end - } Index: ps/trunk/build/premake/premake4/tests/stress =================================================================== --- ps/trunk/build/premake/premake4/tests/stress +++ ps/trunk/build/premake/premake4/tests/stress @@ -1,2 +0,0 @@ -#!/bin/sh -../bin/debug/premake4 /scripts=../src /file=test_stress.lua vs2008 Index: ps/trunk/build/premake/premake4/tests/test =================================================================== --- ps/trunk/build/premake/premake4/tests/test +++ ps/trunk/build/premake/premake4/tests/test @@ -1,2 +0,0 @@ -#!/bin/sh -../bin/debug/premake4 /scripts=../src test Index: ps/trunk/build/premake/premake4/tests/test.bat =================================================================== --- ps/trunk/build/premake/premake4/tests/test.bat +++ ps/trunk/build/premake/premake4/tests/test.bat @@ -1,3 +0,0 @@ - -CALL ..\\bin\\debug\\premake4 /scripts=..\\src test -::CALL ..\\bin\\release\\premake4 /scripts=..\\src test Index: ps/trunk/build/premake/premake4/tests/test_dofile.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_dofile.lua +++ ps/trunk/build/premake/premake4/tests/test_dofile.lua @@ -1,36 +0,0 @@ --- --- tests/test_dofile.lua --- Automated test suite for the extended dofile() functions. --- Copyright (c) 2008 Jason Perkins and the Premake project --- - - - T.dofile = { } - - - local os_getenv - - function T.dofile.setup() - os_getenv = os.getenv - end - - function T.dofile.teardown() - os.getenv = os_getenv - end - - --- --- dofile() tests --- - - function T.dofile.SearchesPath() - os.getenv = function() return os.getcwd().."/folder" end - result = dofile("ok.lua") - test.isequal("ok", result) - end - - function T.dofile.SearchesScriptsOption() - _OPTIONS["scripts"] = os.getcwd().."/folder" - result = dofile("ok.lua") - test.isequal("ok", result) - end Index: ps/trunk/build/premake/premake4/tests/test_gcc.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_gcc.lua +++ ps/trunk/build/premake/premake4/tests/test_gcc.lua @@ -1,60 +0,0 @@ --- --- tests/test_gcc.lua --- Automated test suite for the GCC toolset interface. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.gcc = { } - local suite = T.gcc - - local cfg - function suite.setup() - cfg = { } - cfg.basedir = "." - cfg.location = "." - cfg.language = "C++" - cfg.project = { name = "MyProject" } - cfg.flags = { } - cfg.objectsdir = "obj" - cfg.platform = "Native" - cfg.links = { } - cfg.libdirs = { } - cfg.linktarget = { fullpath="libMyProject.a" } - end - - - function suite.cflags_SharedLib_Windows() - cfg.kind = "SharedLib" - cfg.system = "windows" - local r = premake.gcc.getcflags(cfg) - test.isequal('', table.concat(r,"|")) - end - - - function suite.ldflags_SharedLib_Windows() - cfg.kind = "SharedLib" - cfg.system = "windows" - local r = premake.gcc.getldflags(cfg) - test.isequal('-s|-shared|-Wl,--out-implib="libMyProject.a"', table.concat(r,"|")) - end - - - function suite.cflags_OnFpFast() - cfg.flags = { "FloatFast" } - local r = premake.gcc.getcflags(cfg) - test.isequal('-ffast-math', table.concat(r,"|")) - end - - - function suite.cflags_OnFpStrict() - cfg.flags = { "FloatStrict" } - local r = premake.gcc.getcflags(cfg) - test.isequal('-ffloat-store', table.concat(r,"|")) - end - - - function suite.linkflags_OnFrameworks() - cfg.links = { "Cocoa.framework" } - local r = premake.gcc.getlinkflags(cfg) - test.isequal('-framework Cocoa', table.concat(r,"|")) - end Index: ps/trunk/build/premake/premake4/tests/test_gmake_cpp.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_gmake_cpp.lua +++ ps/trunk/build/premake/premake4/tests/test_gmake_cpp.lua @@ -1,195 +0,0 @@ --- --- tests/test_gmake_cpp.lua --- Automated test suite for GNU Make C/C++ project generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.gmake_cpp = { } - --- --- Configure a solution for testing --- - - local sln, prj - function T.gmake_cpp.setup() - _ACTION = "gmake" - _OPTIONS.os = "linux" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms { "native" } - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - end - - local function prepare() - io.capture() - premake.buildconfigs() - end - - - --- --- Test the header --- - - function T.gmake_cpp.BasicHeader() - prepare() - premake.gmake_cpp_header(prj, premake.gcc, sln.platforms) - test.capture [[ -# GNU Make project makefile autogenerated by Premake -ifndef config - config=debug -endif - -ifndef verbose - SILENT = @ -endif - -ifndef CC - CC = gcc -endif - -ifndef CXX - CXX = g++ -endif - -ifndef AR - AR = ar -endif - ]] - end - - - --- --- Test configuration blocks --- - - function T.gmake_cpp.BasicCfgBlock() - prepare() - local cfg = premake.getconfig(prj, "Debug") - premake.gmake_cpp_config(cfg, premake.gcc) - test.capture [[ -ifeq ($(config),debug) - OBJDIR = obj/Debug - TARGETDIR = . - TARGET = $(TARGETDIR)/MyProject - DEFINES += - INCLUDES += - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) $(ARCH) - CXXFLAGS += $(CFLAGS) - LDFLAGS += -s - LIBS += - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - ]] - end - - - function T.gmake_cpp.BasicCfgBlockWithPlatformCc() - platforms { "ps3" } - prepare() - local cfg = premake.getconfig(prj, "Debug", "PS3") - premake.gmake_cpp_config(cfg, premake.gcc) - test.capture [[ -ifeq ($(config),debugps3) - CC = ppu-lv2-g++ - CXX = ppu-lv2-g++ - AR = ppu-lv2-ar - OBJDIR = obj/PS3/Debug - TARGETDIR = . - TARGET = $(TARGETDIR)/MyProject.elf - DEFINES += - INCLUDES += - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) $(ARCH) - CXXFLAGS += $(CFLAGS) - LDFLAGS += -s - LIBS += - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - ]] - end - - - function T.gmake_cpp.PlatformSpecificBlock() - platforms { "x64" } - prepare() - local cfg = premake.getconfig(prj, "Debug", "x64") - premake.gmake_cpp_config(cfg, premake.gcc) - test.capture [[ -ifeq ($(config),debug64) - OBJDIR = obj/x64/Debug - TARGETDIR = . - TARGET = $(TARGETDIR)/MyProject - DEFINES += - INCLUDES += - CPPFLAGS += -MMD -MP $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) $(ARCH) -m64 - CXXFLAGS += $(CFLAGS) - LDFLAGS += -s -m64 -L/usr/lib64 - LIBS += - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) $(LIBS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - ]] - end - - - function T.gmake_cpp.UniversalStaticLibBlock() - kind "StaticLib" - platforms { "universal32" } - prepare() - local cfg = premake.getconfig(prj, "Debug", "Universal32") - premake.gmake_cpp_config(cfg, premake.gcc) - test.capture [[ -ifeq ($(config),debuguniv32) - OBJDIR = obj/Universal32/Debug - TARGETDIR = . - TARGET = $(TARGETDIR)/libMyProject.a - DEFINES += - INCLUDES += - CPPFLAGS += $(DEFINES) $(INCLUDES) - CFLAGS += $(CPPFLAGS) $(ARCH) -arch i386 -arch ppc - CXXFLAGS += $(CFLAGS) - LDFLAGS += -s -arch i386 -arch ppc - LIBS += - RESFLAGS += $(DEFINES) $(INCLUDES) - LDDEPS += - LINKCMD = libtool -o $(TARGET) $(OBJECTS) - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - ]] - end Index: ps/trunk/build/premake/premake4/tests/test_gmake_cs.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_gmake_cs.lua +++ ps/trunk/build/premake/premake4/tests/test_gmake_cs.lua @@ -1,80 +0,0 @@ --- --- tests/test_gmake_cs.lua --- Automated test suite for GNU Make C/C++ project generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.gmake_cs = { } - --- --- Configure a solution for testing --- - - local sln, prj - function T.gmake_cs.setup() - _ACTION = "gmake" - _OPTIONS.os = "linux" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms { "native" } - - prj = project "MyProject" - language "C#" - kind "ConsoleApp" - end - - local function prepare() - io.capture() - premake.buildconfigs() - end - - - --- --- Test configuration blocks --- - - function T.gmake_cs.BasicCfgBlock() - prepare() - local cfg = premake.getconfig(prj, "Debug") - premake.gmake_cs_config(cfg, premake.dotnet, {[cfg]={}}) - test.capture [[ -ifneq (,$(findstring debug,$(config))) - TARGETDIR := . - OBJDIR := obj/Debug - DEPENDS := - REFERENCES := - FLAGS += - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - ]] - end - - - function T.gmake_cs.OnBuildOptions() - buildoptions { "/define:SYMBOL" } - prepare() - local cfg = premake.getconfig(prj, "Debug") - premake.gmake_cs_config(cfg, premake.dotnet, {[cfg]={}}) - test.capture [[ -ifneq (,$(findstring debug,$(config))) - TARGETDIR := . - OBJDIR := obj/Debug - DEPENDS := - REFERENCES := - FLAGS += /define:SYMBOL - define PREBUILDCMDS - endef - define PRELINKCMDS - endef - define POSTBUILDCMDS - endef -endif - ]] - end Index: ps/trunk/build/premake/premake4/tests/test_keywords.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_keywords.lua +++ ps/trunk/build/premake/premake4/tests/test_keywords.lua @@ -1,87 +0,0 @@ --- --- tests/test_keywords.lua --- Automated test suite for configuration block keyword filtering. --- Copyright (c) 2008, 2009 Jason Perkins and the Premake project --- - - T.keywords = { } - local suite = T.keywords - --- --- Keyword escaping tests --- - - function suite.escapes_special_chars() - test.isequal("%.%-", path.wildcards(".-")) - end - - - function suite.escapes_star() - test.isequal("vs[^/]*", path.wildcards("vs*")) - end - - - function suite.escapes_star_star() - test.isequal("Images/.*%.bmp", path.wildcards("Images/**.bmp")) - end - - - - --- --- Keyword matching tests --- - - function T.keywords.matches_simple_strings() - test.istrue(premake.iskeywordmatch("debug", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_files_with_simple_strings() - test.isfalse(premake.iskeywordmatch("release", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.matches_with_patterns() - test.istrue(premake.iskeywordmatch("vs20.*", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_fails_with_not_term() - test.isfalse(premake.iskeywordmatch("not windows", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_ok_with_not_term() - test.istrue(premake.iskeywordmatch("not linux", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_ok_with_first_or() - test.istrue(premake.iskeywordmatch("windows or linux", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_ok_with_first_or() - test.istrue(premake.iskeywordmatch("windows or linux", { "debug", "linux", "vs2005" })) - end - - - function T.keywords.match_ok_with_not_and_or() - test.istrue(premake.iskeywordmatch("not macosx or linux", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_fail_with_not_and_or() - test.isfalse(premake.iskeywordmatch("not macosx or windows", { "debug", "windows", "vs2005" })) - end - - - function T.keywords.match_ok_required_term() - test.istrue(premake.iskeywordsmatch({ "debug", "hello.c" }, { "debug", "windows", "vs2005", required="hello.c" })) - end - - - function T.keywords.match_fail_required_term() - test.isfalse(premake.iskeywordsmatch({ "debug" }, { "debug", "windows", "vs2005", required="hello.c" })) - end Index: ps/trunk/build/premake/premake4/tests/test_platforms.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_platforms.lua +++ ps/trunk/build/premake/premake4/tests/test_platforms.lua @@ -1,58 +0,0 @@ --- --- tests/test_platforms.lua --- Automated test suite for platform handling functions. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.platforms = { } - - - local testmap = { Native="Win32", x32="Win32", x64="x64" } - - local sln, r - function T.platforms.setup() - sln = solution "MySolution" - configurations { "Debug", "Release" } - end - - - function T.platforms.filter_OnNoSolutionPlatforms() - premake.buildconfigs() - r = premake.filterplatforms(sln, testmap) - test.isequal("", table.concat(r, ":")) - end - - function T.platforms.filter_OnNoSolutionPlatformsAndDefault() - premake.buildconfigs() - r = premake.filterplatforms(sln, testmap, "x32") - test.isequal("x32", table.concat(r, ":")) - end - - function T.platforms.filter_OnIntersection() - platforms { "x32", "x64", "Xbox360" } - premake.buildconfigs() - r = premake.filterplatforms(sln, testmap, "x32") - test.isequal("x32:x64", table.concat(r, ":")) - end - - function T.platforms.filter_OnNoIntersection() - platforms { "Universal", "Xbox360" } - premake.buildconfigs() - r = premake.filterplatforms(sln, testmap) - test.isequal("", table.concat(r, ":")) - end - - function T.platforms.filter_OnNoIntersectionAndDefault() - platforms { "Universal", "Xbox360" } - premake.buildconfigs() - r = premake.filterplatforms(sln, testmap, "x32") - test.isequal("x32", table.concat(r, ":")) - end - - function T.platforms.filter_OnDuplicateKeys() - platforms { "Native", "x32" } - premake.buildconfigs() - r = premake.filterplatforms(sln, testmap, "x32") - test.isequal("Native", table.concat(r, ":")) - end - Index: ps/trunk/build/premake/premake4/tests/test_premake.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_premake.lua +++ ps/trunk/build/premake/premake4/tests/test_premake.lua @@ -1,47 +0,0 @@ --- --- tests/test_premake.lua --- Automated test suite for the Premake support functions. --- Copyright (c) 2008-2009 Jason Perkins and the Premake project --- - - - T.premake = { } - - --- --- premake.checktools() tests --- - - function T.premake.checktools_SetsDefaultTools() - _ACTION = "gmake" - premake.checktools() - test.isequal("gcc", _OPTIONS.cc) - test.isequal("mono", _OPTIONS.dotnet) - end - - - function T.premake.checktools_Fails_OnToolMismatch() - _ACTION = "gmake" - _OPTIONS["cc"] = "xyz" - ok, err = premake.checktools() - test.isfalse( ok ) - test.isequal("the GNU Make action does not support /cc=xyz (yet)", err) - end - - - --- --- generate() tests --- - - function T.premake.generate_OpensCorrectFile() - prj = { name = "MyProject", location = "MyLocation" } - premake.generate(prj, "%%.prj", function () end) - test.openedfile("MyLocation/MyProject.prj") - end - - function T.premake.generate_ClosesFile() - prj = { name = "MyProject", location = "MyLocation" } - premake.generate(prj, "%%.prj", function () end) - test.closedfile(true) - end Index: ps/trunk/build/premake/premake4/tests/test_project.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_project.lua +++ ps/trunk/build/premake/premake4/tests/test_project.lua @@ -1,149 +0,0 @@ --- --- tests/test_project.lua --- Automated test suite for the project support functions. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project --- - - local _project = premake.project - - T.project = { } - - local cfg, result - function T.project.setup() - _ACTION = "gmake" - cfg = {} - cfg.project = {} - cfg.language = "C++" - cfg.files = {} - cfg.trimpaths = {} - cfg.platform = "Native" - result = "\n" - end - - - --- --- findproject() tests --- - - function T.project.findproject_IsCaseSensitive() - local sln = test.createsolution() - local prj = test.createproject(sln) - premake.buildconfigs() - test.isnil(premake.findproject("myproject")) - end - - --- --- getfilename() tests --- - - function T.project.getfilename_ReturnsRelativePath() - local prj = { name = "project", location = "location" } - local r = _project.getfilename(prj, path.join(os.getcwd(), "../filename")) - test.isequal("../filename", r) - end - - function T.project.getfilename_PerformsSubstitutions() - local prj = { name = "project", location = "location" } - local r = _project.getfilename(prj, "%%.prj") - test.isequal("location/project.prj", r) - end - - - --- --- premake.getlinks() tests --- - - function T.project.getlinks_OnMscSystemLibs() - _OPTIONS.cc = "msc" - cfg.links = { "user32", "gdi32" } - result = premake.getlinks(cfg, "all", "fullpath") - test.isequal("user32.lib gdi32.lib", table.concat(result, " ")) - end - - - - --- --- premake.walksources() tests --- - - local function walktest(prj, fname, state, nestlevel) - local item - if (state == "GroupStart") then - item = "<" .. fname .. ">" - elseif (state == "GroupEnd") then - item = "" - else - item = fname - end - result = result .. string.rep("-", nestlevel) .. item .. "\n" - end - - - function T.project.walksources_OnNoFiles() - premake.walksources(cfg, walktest) - test.isequal("\n" - .. "" - ,result) - end - - - function T.project.walksources_OnSingleFile() - cfg.files = { - "hello.cpp" - } - premake.walksources(cfg, walktest) - test.isequal("\n" - .. "hello.cpp\n" - ,result) - end - - - function T.project.walksources_OnNestedGroups() - cfg.files = { - "rootfile.c", - "level1/level1.c", - "level1/level2/level2.c" - } - premake.walksources(cfg, walktest) - test.isequal("\n" - .. "\n" - .. "-\n" - .. "--level1/level2/level2.c\n" - .. "-\n" - .. "-level1/level1.c\n" - .. "\n" - .. "rootfile.c\n" - ,result) - end - - - function T.project.walksources_OnDottedFolders() - cfg.files = { - "src/lua-5.1.2/lapi.c" - } - premake.walksources(cfg, walktest) - test.isequal("\n" - .. "\n" - .. "-\n" - .. "--src/lua-5.1.2/lapi.c\n" - .. "-\n" - .. "\n" - ,result) - end - - - function T.project.walksources_OnDotDotLeaders() - cfg.files = { - "../src/hello.c", - } - premake.walksources(cfg, walktest) - test.isequal("\n" - .. "<../src>\n" - .. "-../src/hello.c\n" - .. "\n" - ,result) - end Index: ps/trunk/build/premake/premake4/tests/test_stress.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_stress.lua +++ ps/trunk/build/premake/premake4/tests/test_stress.lua @@ -1,44 +0,0 @@ --- --- tests/tests_stress.lua --- Stress test for Premake. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - -local numprojects = 100 -local numfiles = 100 - -dofile("pepperfish_profiler.lua") -profiler = newProfiler() -function dumpresults(sorttotal) - local outfile = io.open("build/profile.txt", "w+" ) - profiler:report(outfile, sorttotal) - outfile:close() -end - - -solution "MySolution" - configurations { "Debug", "Release", "DebugDLL", "ReleaseDLL" } - platforms { "Native", "x32", "x64" } - location "build" - - configuration "Debug" - defines { "_DEBUG" } - flags { "Symbols" } - - configuration "Release" - defines { "NDEBUG" } - flags { "Optimize" } - - -for pi = 1, numprojects do - - project ("Project" .. pi) - location "build" - kind "ConsoleApp" - language "C++" - - for fi = 1, numfiles do - files { "file" .. fi .. ".cpp" } - end - -end Index: ps/trunk/build/premake/premake4/tests/test_string.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_string.lua +++ ps/trunk/build/premake/premake4/tests/test_string.lua @@ -1,73 +0,0 @@ --- --- tests/test_string.lua --- Automated test suite for the new string functions. --- Copyright (c) 2008 Jason Perkins and the Premake project --- - - - T.string = { } - - --- --- string.endswith() tests --- - - function T.string.endswith_ReturnsTrue_OnMatch() - test.istrue(string.endswith("Abcdef", "def")) - end - - function T.string.endswith_ReturnsFalse_OnMismatch() - test.isfalse(string.endswith("Abcedf", "efg")) - end - - function T.string.endswith_ReturnsFalse_OnLongerNeedle() - test.isfalse(string.endswith("Abc", "Abcdef")) - end - - function T.string.endswith_ReturnsFalse_OnNilHaystack() - test.isfalse(string.endswith(nil, "ghi")) - end - - function T.string.endswith_ReturnsFalse_OnNilNeedle() - test.isfalse(string.endswith("Abc", nil)) - end - - function T.string.endswith_ReturnsTrue_OnExactMatch() - test.istrue(string.endswith("/", "/")) - end - - - --- --- string.explode() tests --- - - function T.string.explode_ReturnsParts_OnValidCall() - test.isequal({"aaa","bbb","ccc"}, string.explode("aaa/bbb/ccc", "/", true)) - end - - - --- --- string.startswith() tests --- - - function T.string.startswith_OnMatch() - test.istrue(string.startswith("Abcdef", "Abc")) - end - - function T.string.startswith_OnMismatch() - test.isfalse(string.startswith("Abcdef", "ghi")) - end - - function T.string.startswith_OnLongerNeedle() - test.isfalse(string.startswith("Abc", "Abcdef")) - end - - function T.string.startswith_OnEmptyHaystack() - test.isfalse(string.startswith("", "Abc")) - end - - function T.string.startswith_OnEmptyNeedle() - test.istrue(string.startswith("Abcdef", "")) - end Index: ps/trunk/build/premake/premake4/tests/test_targets.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_targets.lua +++ ps/trunk/build/premake/premake4/tests/test_targets.lua @@ -1,235 +0,0 @@ --- --- tests/test_targets.lua --- Automated test suite for premake.gettarget() --- Copyright (c) 2008, 2009 Jason Perkins and the Premake project --- - - T.targets = { } - - local cfg - function T.targets.setup() - cfg = { } - cfg.basedir = "." - cfg.location = "." - cfg.targetdir = "../bin" - cfg.language = "C++" - cfg.project = { name = "MyProject" } - cfg.flags = { } - cfg.objectsdir = "obj" - cfg.platform = "Native" - end - - --- --- Path Style Name Style Example Environment --- ---------- ---------- ------------------- --- windows windows VStudio with MSC --- posix posix GMake with GCC --- windows posix VStudio for PS3 --- posix windows GMake for .NET --- - - - - --- --- ConsoleApp tests --- - - function T.targets.ConsoleApp_Build_WindowsNames() - cfg.kind = "ConsoleApp" - result = premake.gettarget(cfg, "build", "posix", "windows", "macosx") - test.isequal([[../bin/MyProject.exe]], result.fullpath) - end - - function T.targets.ConsoleApp_Build_PosixNames_OnWindows() - cfg.kind = "ConsoleApp" - result = premake.gettarget(cfg, "build", "posix", "posix", "windows") - test.isequal([[../bin/MyProject.exe]], result.fullpath) - end - - function T.targets.ConsoleApp_Build_PosixNames_OnLinux() - cfg.kind = "ConsoleApp" - result = premake.gettarget(cfg, "build", "posix", "posix", "linux") - test.isequal([[../bin/MyProject]], result.fullpath) - end - - function T.targets.ConsoleApp_Build_PosixNames_OnMacOSX() - cfg.kind = "ConsoleApp" - result = premake.gettarget(cfg, "build", "posix", "posix", "macosx") - test.isequal([[../bin/MyProject]], result.fullpath) - end - - function T.targets.ConsoleApp_Build_PS3Names() - cfg.kind = "ConsoleApp" - result = premake.gettarget(cfg, "build", "posix", "PS3", "macosx") - test.isequal([[../bin/MyProject.elf]], result.fullpath) - end - - - --- --- WindowedApp tests --- - - function T.targets.WindowedApp_Build_WindowsNames() - cfg.kind = "WindowedApp" - result = premake.gettarget(cfg, "build", "posix", "windows", "macosx") - test.isequal([[../bin/MyProject.exe]], result.fullpath) - end - - function T.targets.WindowedApp_Build_PosixNames_OnWindows() - cfg.kind = "WindowedApp" - result = premake.gettarget(cfg, "build", "posix", "posix", "windows") - test.isequal([[../bin/MyProject.exe]], result.fullpath) - end - - function T.targets.WindowedApp_Build_PosixNames_OnLinux() - cfg.kind = "WindowedApp" - result = premake.gettarget(cfg, "build", "posix", "posix", "linux") - test.isequal([[../bin/MyProject]], result.fullpath) - end - - function T.targets.WindowedApp_Build_PosixNames_OnMacOSX() - cfg.kind = "WindowedApp" - result = premake.gettarget(cfg, "build", "posix", "posix", "macosx") - test.isequal([[../bin/MyProject.app/Contents/MacOS/MyProject]], result.fullpath) - end - - function T.targets.WindowedApp_Build_PS3Names() - cfg.kind = "WindowedApp" - result = premake.gettarget(cfg, "build", "posix", "PS3", "macosx") - test.isequal([[../bin/MyProject.elf]], result.fullpath) - end - - --- --- SharedLib tests --- - - function T.targets.SharedLib_Build_WindowsNames() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "build", "posix", "windows", "macosx") - test.isequal([[../bin/MyProject.dll]], result.fullpath) - end - - function T.targets.SharedLib_Link_WindowsNames() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "link", "posix", "windows", "macosx") - test.isequal([[../bin/MyProject.lib]], result.fullpath) - end - - function T.targets.SharedLib_Build_PosixNames_OnWindows() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "build", "posix", "posix", "windows") - test.isequal([[../bin/MyProject.dll]], result.fullpath) - end - - function T.targets.SharedLib_Link_PosixNames_OnWindows() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "link", "posix", "posix", "windows") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.SharedLib_Build_PosixNames_OnLinux() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "build", "posix", "posix", "linux") - test.isequal([[../bin/libMyProject.so]], result.fullpath) - end - - function T.targets.SharedLib_Link_PosixNames_OnLinux() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "link", "posix", "posix", "linux") - test.isequal([[../bin/libMyProject.so]], result.fullpath) - end - - function T.targets.SharedLib_Build_PosixNames_OnMacOSX() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "build", "posix", "posix", "macosx") - test.isequal([[../bin/libMyProject.dylib]], result.fullpath) - end - - function T.targets.SharedLib_Link_PosixNames_OnMacOSX() - cfg.kind = "SharedLib" - result = premake.gettarget(cfg, "link", "posix", "posix", "macosx") - test.isequal([[../bin/libMyProject.dylib]], result.fullpath) - end - - - --- --- StaticLib tests --- - - function T.targets.StaticLib_Build_WindowsNames() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "build", "posix", "windows", "macosx") - test.isequal([[../bin/MyProject.lib]], result.fullpath) - end - - function T.targets.StaticLib_Link_WindowsNames() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "link", "posix", "windows", "macosx") - test.isequal([[../bin/MyProject.lib]], result.fullpath) - end - - function T.targets.StaticLib_Build_PosixNames_OnWindows() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "build", "posix", "posix", "windows") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Link_PosixNames_OnWindows() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "link", "posix", "posix", "windows") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Build_PosixNames_OnLinux() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "build", "posix", "posix", "linux") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Link_PosixNames_OnLinux() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "link", "posix", "posix", "linux") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Build_PosixNames_OnMacOSX() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "build", "posix", "posix", "macosx") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Link_PosixNames_OnMacOSX() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "link", "posix", "posix", "macosx") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Build_PosixNames_OnPS3() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "build", "posix", "PS3", "macosx") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - function T.targets.StaticLib_Link_PosixNames_OnPS3() - cfg.kind = "StaticLib" - result = premake.gettarget(cfg, "link", "posix", "PS3", "macosx") - test.isequal([[../bin/libMyProject.a]], result.fullpath) - end - - - --- --- Windows path tests --- - - function T.targets.WindowsPaths() - cfg.kind = "ConsoleApp" - result = premake.gettarget(cfg, "build", "windows", "windows", "linux") - test.isequal([[..\bin]], result.directory) - test.isequal([[..\bin\MyProject.exe]], result.fullpath) - end \ No newline at end of file Index: ps/trunk/build/premake/premake4/tests/test_vs2002_sln.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_vs2002_sln.lua +++ ps/trunk/build/premake/premake4/tests/test_vs2002_sln.lua @@ -1,61 +0,0 @@ --- --- tests/test_vs2002_sln.lua --- Automated test suite for Visual Studio 2002 solution generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.vs2002_sln = { } - --- --- Configure a solution for testing --- - - local sln - function T.vs2002_sln.setup() - _ACTION = 'vs2002' - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - - premake.buildconfigs() - end - - - --- --- Make sure I've got the basic layout correct --- - - function T.vs2002_sln.BasicLayout() - io.capture() - premake.vs2002_solution(sln) - test.capture [[ -Microsoft Visual Studio Solution File, Format Version 7.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcproj", "{AE61726D-187C-E440-BD07-2556188A6565}" -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - ConfigName.0 = Debug - ConfigName.1 = Release - EndGlobalSection - GlobalSection(ProjectDependencies) = postSolution - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal - ]] - end Index: ps/trunk/build/premake/premake4/tests/test_vs2003_sln.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_vs2003_sln.lua +++ ps/trunk/build/premake/premake4/tests/test_vs2003_sln.lua @@ -1,61 +0,0 @@ --- --- tests/test_vs2003_sln.lua --- Automated test suite for Visual Studio 2003 solution generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.vs2003_sln = { } - --- --- Configure a solution for testing --- - - local sln - function T.vs2003_sln.setup() - _ACTION = "vs2003" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - - premake.buildconfigs() - end - - - --- --- Make sure I've got the basic layout correct --- - - function T.vs2003_sln.BasicLayout() - io.capture() - premake.vs2003_solution(sln) - test.capture [[ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcproj", "{AE61726D-187C-E440-BD07-2556188A6565}" -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectDependencies) = postSolution - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal - ]] - end Index: ps/trunk/build/premake/premake4/tests/test_vs2005_sln.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_vs2005_sln.lua +++ ps/trunk/build/premake/premake4/tests/test_vs2005_sln.lua @@ -1,241 +0,0 @@ --- --- tests/test_vs2005_sln.lua --- Automated test suite for Visual Studio 2005 solution generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.vs2005_sln = { } - --- --- Configure a solution for testing --- - - local sln - function T.vs2005_sln.setup() - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - - _ACTION = 'vs2005' - end - - local function prepare() - io.capture() - premake.buildconfigs() - sln.vstudio_configs = premake.vstudio_buildconfigs(sln) - end - - local function addnetproject() - project "MyNetProject" - language "C#" - kind "ConsoleApp" - uuid "C9135098-6047-8142-B10E-D27E7F73FCB3" - end - - - - --- --- Make sure I've got the basic layout correct --- - - function T.vs2005_sln.BasicLayout() - prepare() - premake.vs2005_solution(sln) - test.capture ('\239\187\191' .. [[ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcproj", "{AE61726D-187C-E440-BD07-2556188A6565}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal - ]]) - end - - - --- --- Test a mixed runtime (C++/.NET) solution. --- - - function T.vs2005_sln.SolutionPlatforms_OnMixedModes() - addnetproject() - prepare() - - premake.vs2005_solution_platforms(sln) - test.capture [[ - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|Win32 = Debug|Win32 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|Win32 = Release|Win32 - EndGlobalSection - ]] - end - - - function T.vs2005_sln.ProjectPlatforms_OnMixedModes() - addnetproject() - prepare() - - premake.vs2005_solution_project_platforms(sln) - test.capture [[ - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Any CPU.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.Build.0 = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU - EndGlobalSection - ]] - end - - - --- --- Test multiple platforms --- - - function T.vs2005_sln.SolutionPlatforms_OnMultiplePlatforms() - platforms { "x32", "x64" } - prepare() - - premake.vs2005_solution_platforms(sln) - test.capture [[ - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - ]] - end - - - function T.vs2005_sln.ProjectPlatforms_OnMultiplePlatforms() - platforms { "x32", "x64" } - prepare() - - premake.vs2005_solution_project_platforms(sln) - test.capture [[ - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.ActiveCfg = Debug|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.Build.0 = Debug|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.ActiveCfg = Release|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - ]] - end - - - function T.vs2005_sln.ProjectPlatforms_OnMultiplePlatformsAndMixedModes() - platforms { "x32", "x64" } - addnetproject() - prepare() - - premake.vs2005_solution_project_platforms(sln) - test.capture [[ - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.ActiveCfg = Debug|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.Build.0 = Debug|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Any CPU.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.Build.0 = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.ActiveCfg = Release|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.Build.0 = Release|x64 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release|Any CPU - EndGlobalSection - ]] - end - - --- --- Test PS3 support --- - - function T.vs2005_sln.SolutionPlatforms_OnPS3() - platforms { "PS3" } - prepare() - - premake.vs2005_solution_platforms(sln) - test.capture [[ - GlobalSection(SolutionConfigurationPlatforms) = preSolution - PS3 Debug|Win32 = PS3 Debug|Win32 - PS3 Release|Win32 = PS3 Release|Win32 - EndGlobalSection - ]] - end - - - function T.vs2005_sln.ProjectPlatforms_OnPS3() - platforms { "PS3" } - prepare() - - premake.vs2005_solution_project_platforms(sln) - test.capture [[ - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.PS3 Debug|Win32.ActiveCfg = PS3 Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.PS3 Debug|Win32.Build.0 = PS3 Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.PS3 Release|Win32.ActiveCfg = PS3 Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.PS3 Release|Win32.Build.0 = PS3 Release|Win32 - EndGlobalSection - ]] - end Index: ps/trunk/build/premake/premake4/tests/test_vs2008_sln.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_vs2008_sln.lua +++ ps/trunk/build/premake/premake4/tests/test_vs2008_sln.lua @@ -1,60 +0,0 @@ --- --- tests/test_vs2008_sln.lua --- Automated test suite for Visual Studio 2008 solution generation. --- Copyright (c) 2009 Jason Perkins and the Premake project --- - - T.vs2008_sln = { } - --- --- Configure a solution for testing --- - - local sln - function T.vs2008_sln.setup() - _ACTION = "vs2008" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - prj = project "MyProject" - language "C++" - kind "ConsoleApp" - uuid "AE61726D-187C-E440-BD07-2556188A6565" - - premake.buildconfigs() - end - - - --- --- Make sure I've got the basic layout correct --- - - function T.vs2008_sln.BasicLayout() - io.capture() - premake.vs2005_solution(sln) - test.capture ('\239\187\191' .. [[ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcproj", "{AE61726D-187C-E440-BD07-2556188A6565}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal - ]]) - end Index: ps/trunk/build/premake/premake4/tests/test_vs2010_sln.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/test_vs2010_sln.lua +++ ps/trunk/build/premake/premake4/tests/test_vs2010_sln.lua @@ -1,118 +0,0 @@ - T.vs2010_sln = { } - -local vs_magic_cpp_build_tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" -local constant_uuid = "AE61726D-187C-E440-BD07-2556188A6565" -local constant_project_name = "MyProject" --- --- Configure a solution for testing --- - - local sln - function T.vs2010_sln.setup() - _ACTION = "vs2010" - - sln = solution "MySolution" - configurations { "Debug", "Release" } - platforms {} - - prj = project(constant_project_name) - language "C++" - kind "ConsoleApp" - uuid(constant_uuid) - - premake.buildconfigs() - end - - local function escape_id(str) - return string.gsub(str,"%-+","%%%-") - end - - local function assert_has_project(buffer,uid,name,ext) - test.string_contains(buffer,"Project(\"{"..escape_id(vs_magic_cpp_build_tool_id).."}\") = \""..name.."\", \""..name.."."..ext.."\", \"{"..escape_id(uid).."}\"") - end - - - - local function assert_find_uuid(buffer,id) - test.string_contains(buffer,escape_id(id)) - end - - local function get_buffer() - io.capture() - premake.vs_generic_solution(sln) - buffer = io.endcapture() - return buffer - end - - function T.vs2010_sln.action_formatVersionis11() - local buffer = get_buffer() - test.string_contains(buffer,'Format Version 11.00') - end - - function T.vs2010_sln.action_vsIs2010() - local buffer = get_buffer() - test.string_contains(buffer,'# Visual Studio 2010') - end - - function T.vs2010_sln.action_hasProjectScope() - local buffer = get_buffer() - test.string_contains(buffer,"Project(.*)EndProject") - end - - function T.vs2010_sln.containsVsCppMagicId() - local buffer = get_buffer() - assert_find_uuid(buffer,vs_magic_cpp_build_tool_id) - end - - function T.vs2010_sln.action_findMyProjectID() - local buffer = get_buffer() - test.string_contains(buffer,escape_id(constant_uuid)) - end - - function T.vs2010_sln.action_findsExtension() - local buffer = get_buffer() - test.string_contains(buffer,".vcxproj") - end - - function T.vs2010_sln.action_hasGlobalStartBlock() - local buffer = get_buffer() - test.string_contains(buffer,"Global") - end - - function T.vs2010_sln.action_hasGlobalEndBlock() - local buffer = get_buffer() - test.string_contains(buffer,"EndGlobal") - end - - function T.vs2010_sln.BasicLayout() - io.capture() - premake.vs_generic_solution(sln) - test.capture ('\239\187\191' .. [[ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcxproj", "{AE61726D-187C-E440-BD07-2556188A6565}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal - ]]) - end - - - - - - Index: ps/trunk/build/premake/premake4/tests/testfx.lua =================================================================== --- ps/trunk/build/premake/premake4/tests/testfx.lua +++ ps/trunk/build/premake/premake4/tests/testfx.lua @@ -1,257 +0,0 @@ --- --- tests/testfx.lua --- Automated test framework for Premake. --- Copyright (c) 2008-2009 Jason Perkins and the Premake project --- - - --- --- Define a namespace for the testing functions --- - - test = { } - - --- --- Assertion functions --- - function test.string_contains(buffer, expected) - if not string.find(buffer,expected) then - test.fail("\n==Fail==: Expected to find :\n%s\nyet it was not found in buffer:\n%s\n", expected,buffer) - end - end - - function test.string_does_not_contain(buffer, expected) - if string.find(buffer,expected) then - test.fail("\n==Fail==: Did not expected to find :\n%s\nyet it was found in buffer:\n%s\n", expected,buffer) - end - end - - function test.capture(expected) - local actual = io.endcapture() - - local ait = actual:gfind("(.-)" .. io.eol) - local eit = expected:gfind("(.-)\n") - - local linenum = 1 - local atxt = ait() - local etxt = eit() - while etxt do - if (etxt ~= atxt) then - test.fail("(%d) expected:\n%s\n...but was:\n%s", linenum, etxt, atxt) - end - - linenum = linenum + 1 - atxt = ait() - etxt = eit() - end - end - - - function test.closedfile(expected) - if expected and not test.value_closedfile then - test.fail("expected file to be closed") - elseif not expected and test.value_closedfile then - test.fail("expected file to remain open") - end - end - - - function test.contains(value, expected) - if not table.contains(value, expected) then - test.fail("expected value %s not found", expected) - end - end - - - function test.fail(format, ...) - -- convert nils into something more usefuls - for i = 1, arg.n do - if (arg[i] == nil) then - arg[i] = "(nil)" - elseif (type(arg[i]) == "table") then - arg[i] = "{" .. table.concat(arg[i], ", ") .. "}" - end - end - error(string.format(format, unpack(arg)), 3) - end - - - function test.filecontains(expected, fn) - local f = io.open(fn) - local actual = f:read("*a") - f:close() - if (expected ~= actual) then - test.fail("expected %s but was %s", expected, actual) - end - end - - - function test.isequal(expected, actual) - if (type(expected) == "table") then - for k,v in pairs(expected) do - if not (test.isequal(expected[k], actual[k])) then - test.fail("expected %s but was %s", expected, actual) - end - end - else - if (expected ~= actual) then - test.fail("expected %s but was %s", expected, actual) - end - end - return true - end - - - function test.isfalse(value) - if (value) then - test.fail("expected false but was true") - end - end - - - function test.isnil(value) - if (value ~= nil) then - test.fail("expected nil but was " .. tostring(value)) - end - end - - - function test.isnotnil(value) - if (value == nil) then - test.fail("expected not nil") - end - end - - - function test.istrue(value) - if (not value) then - test.fail("expected true but was false") - end - end - - - function test.openedfile(fname) - if fname ~= test.value_openedfilename then - local msg = "expected to open file '" .. fname .. "'" - if test.value_openedfilename then - msg = msg .. ", got '" .. test.value_openedfilename .. "'" - end - test.fail(msg) - end - end - - - function test.success(fn, ...) - local ok, err = pcall(fn, unpack(arg)) - if not ok then - test.fail("call failed: " .. err) - end - end - - - --- --- Test stubs --- - - local function stub_io_open(fname, mode) - test.value_openedfilename = fname - test.value_openedfilemode = mode - return { - close = function() - test.value_closedfile = true - end - } - end - - local function stub_io_output(f) - end - - local function stub_print(s) - end - - --- --- Define a collection for the test suites --- - - T = { } - - - --- --- Test execution function --- - - local function test_setup(suite, fn) - -- clear out some important globals - _ACTION = "test" - _ARGS = { } - _OPTIONS = { } - premake.solution.list = { } - - -- reset captured I/O values - test.value_openedfilename = nil - test.value_openedfilemode = nil - test.value_closedfile = false - - if suite.setup then - return pcall(suite.setup) - else - return true - end - end - - - local function test_run(suite, fn) - return pcall(fn) - end - - - local function test_teardown(suite, fn) - if suite.teardown then - return pcall(suite.teardown) - else - return true - end - end - - - function test.runall() - test.print = print - - print = stub_print - io.open = stub_io_open - io.output = stub_io_output - - local numpassed = 0 - local numfailed = 0 - - for suitename, suitetests in pairs(T) do - for testname, testfunc in pairs(suitetests) do - - local ok, err = test_setup(suitetests, testfunc) - - if ok then - ok, err = test_run(suitetests, testfunc) - end - - local tok, terr = test_teardown(suitetests, testfunc) - ok = ok and tok - err = err or tok - - if (not ok) then - test.print(string.format("%s.%s: %s", suitename, testname, err)) - numfailed = numfailed + 1 - else - numpassed = numpassed + 1 - end - - end - end - - print = test.print - return numpassed, numfailed - end - Index: ps/trunk/build/workspaces/clean-workspaces.sh =================================================================== --- ps/trunk/build/workspaces/clean-workspaces.sh +++ ps/trunk/build/workspaces/clean-workspaces.sh @@ -41,9 +41,6 @@ (cd ../../libraries/source/spidermonkey && rm -rf ./mozjs31) (cd ../../libraries/source/spidermonkey && rm -rf ./mozjs24) -(cd ../premake/premake4/build/gmake.bsd && ${MAKE} clean) -(cd ../premake/premake4/build/gmake.macosx && ${MAKE} clean) -(cd ../premake/premake4/build/gmake.unix && ${MAKE} clean) (cd ../premake/premake5/build/gmake.bsd && ${MAKE} clean) (cd ../premake/premake5/build/gmake.macosx && ${MAKE} clean) (cd ../premake/premake5/build/gmake.unix && ${MAKE} clean) Index: ps/trunk/build/workspaces/update-workspaces.sh =================================================================== --- ps/trunk/build/workspaces/update-workspaces.sh +++ ps/trunk/build/workspaces/update-workspaces.sh @@ -36,7 +36,6 @@ # Parse command-line options: -premake_version="premake5" premake_args="" without_nvtt=false @@ -52,7 +51,6 @@ --with-system-mozjs38 ) with_system_mozjs38=true; premake_args="${premake_args} --with-system-mozjs38" ;; --enable-atlas ) enable_atlas=true ;; --disable-atlas ) enable_atlas=false ;; - --premake4 ) premake_version="premake4"; premake_args="${premake_args} --collada" ;; -j* ) JOBS=$i ;; # Assume any other --options are for Premake --* ) premake_args="${premake_args} $i" ;; @@ -98,7 +96,7 @@ fi # Now build premake and run it to create the makefiles -cd ../premake/"$premake_version" +cd ../premake/premake5 PREMAKE_BUILD_DIR=build/gmake.unix # BSD and OS X need different Makefiles case "`uname -s`" in @@ -123,17 +121,11 @@ echo "Premake args: ${premake_args}" if [ "`uname -s`" != "Darwin" ]; then - "$premake_version"/bin/release/"$premake_version" --file="$premake_version.lua" --outpath="../workspaces/gcc/" ${premake_args} gmake || die "Premake failed" + premake5/bin/release/premake5 --file="premake5.lua" --outpath="../workspaces/gcc/" ${premake_args} gmake || die "Premake failed" else - "$premake_version"/bin/release/"$premake_version" --file="$premake_version.lua" --outpath="../workspaces/gcc/" --macosx-version-min="${MIN_OSX_VERSION}" ${premake_args} gmake || die "Premake failed" + premake5/bin/release/premake5 --file="premake5.lua" --outpath="../workspaces/gcc/" --macosx-version-min="${MIN_OSX_VERSION}" ${premake_args} gmake || die "Premake failed" # Also generate xcode workspaces if on OS X - if [ "$premake_version" = "premake4" ]; then - "$premake_version"/bin/release/"$premake_version" --file="$premake_version.lua" --outpath="../workspaces/xcode3" ${premake_args} xcode3 || die "Premake failed" - fi - "$premake_version"/bin/release/"$premake_version" --file="$premake_version.lua" --outpath="../workspaces/xcode4" ${premake_args} xcode4 || die "Premake failed" -fi -if [ "$premake_version" = "premake4" ]; then - "$premake_version"/bin/release/"$premake_version" --file="$premake_version.lua" --outpath="../workspaces/codeblocks/" ${premake_args} codeblocks || die "Premake failed" + premake5/bin/release/premake5 --file="premake5.lua" --outpath="../workspaces/xcode4" ${premake_args} xcode4 || die "Premake failed" fi # test_root.cpp gets generated by cxxtestgen and passing different arguments to premake could require a regeneration of this file.