diff --git a/.gitignore b/.gitignore index f7f72216d3..d79fb0525f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,9 @@ Makefile *.project *.tags *.sublime-* +.cproject +.settings +.buildpath *.bbprojectsettings Scratchpad.txt diff --git a/Bootstrap.mak b/Bootstrap.mak index 8aaff28d7c..246a48082a 100644 --- a/Bootstrap.mak +++ b/Bootstrap.mak @@ -1,23 +1,23 @@ -LUA_DIR=src/host/lua-5.1.4/src +LUA_DIR=src/host/lua/src -SRC= src/host/*.c \ +SRC= src/host/*.c \ $(LUA_DIR)/lapi.c \ $(LUA_DIR)/lcode.c \ $(LUA_DIR)/ldebug.c \ $(LUA_DIR)/ldump.c \ -$(LUA_DIR)/lgc.c \ +$(LUA_DIR)/lgc.c \ $(LUA_DIR)/liolib.c \ -$(LUA_DIR)/lmathlib.c \ +$(LUA_DIR)/lmathlib.c \ $(LUA_DIR)/loadlib.c \ -$(LUA_DIR)/lopcodes.c \ +$(LUA_DIR)/lopcodes.c \ $(LUA_DIR)/lparser.c \ $(LUA_DIR)/lstring.c \ $(LUA_DIR)/ltable.c \ -$(LUA_DIR)/ltm.c \ -$(LUA_DIR)/lvm.c \ -$(LUA_DIR)/lbaselib.c \ +$(LUA_DIR)/ltm.c \ +$(LUA_DIR)/lvm.c \ +$(LUA_DIR)/lbaselib.c \ $(LUA_DIR)/ldblib.c \ -$(LUA_DIR)/ldo.c \ +$(LUA_DIR)/ldo.c \ $(LUA_DIR)/lfunc.c \ $(LUA_DIR)/linit.c \ $(LUA_DIR)/llex.c \ @@ -52,14 +52,14 @@ mingw: $(SRC) osx: $(SRC) mkdir -p build/bootstrap - $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -I"$(LUA_DIR)" -framework CoreServices $? + $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_MACOSX -I"$(LUA_DIR)" -framework CoreServices $? ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --to=build/bootstrap gmake $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` linux: $(SRC) mkdir -p build/bootstrap - $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -I"$(LUA_DIR)" $? -lm + $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" $? -lm -ldl -lrt ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --to=build/bootstrap gmake $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` diff --git a/CHANGES.txt b/CHANGES.txt index 0d4eb4f870..67fa23000a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,24 @@ See https://github.com/premake/premake-core/wiki/What's-New-in-5.0 for the complete list of changes from the Premake 4.x series. +Since 5.0-alpha6: + +* New API: additionalusingdirectories() +* New API: largeaddressaware() +* New: Embed bytecode to enable better debugging information +* New: Display elapsed time at completion +* New: Utility project support for Makefiles +* New: Enabled SSL support in HTTP functions +* Fix: Reduce memory usage during baking +* Fix: Improve performance of wildcard processing +* Fix: Preserve environment in recursive token expansion +* Fix: Added missing defines in bootstrap script +* Fix: Remove /usr/lib64 directories from Mac builds +* Fix: Added newline after UTF-8 marker in Visual Studio projects +* Fix: Duplicate escaping on include directories in Makefiles +* Fix: os.isdir() now works with Windows symbolic links +* Fix: Use correct path separators in C# response files + Since 5.0-alpha5: * New API: ignoredefaultlibraries() diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e29e88ddd8..7416ef072d 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -24,27 +24,21 @@ Patch contributors: * module loading fixes * bug fixes Gabi Davar - * Added file.directory to token environment + * added file.directory to token environment João Matos (joao@tritao.eu) * HTTP download support * C# / C++/CLI language support improvements and bugfixes * Visual Studio and Make improvements and bugfixes - * Response files support for Make backend + * response files support for Make backend + * numerous bug fixes and smaller features leeonix - * Bug fixes - Lusito - * path.join() fixes - João Matos (joao@tritao.eu) - * HTTP download support - * C# / C++/CLI language support improvements and bugfixes - * Visual Studio and Make improvements and bugfixes - * Response files support for Make backend - leeonix - * Bug fixes + * bug fixes Lusito * path.join() fixes Mark Chandler - * Prevent self-linking + * prevent self-linking + Mark Sararu + * Makefile bug fixes Mihai Sebea * Xcode exporter fixes and improvements M Skibbe @@ -52,8 +46,11 @@ Patch contributors: Renaud Guillard * add library search paths argument to os.findlib() * return command exit code from os.outputof() + * bug fixes and smaller improvements rhuvendiek - * VC 2010 IDL file support + * Visual C 2010 IDL file support + Sami Kankaristo + * Utility project support for Makefiles tbasnoopy * customtoolnamespace() * debuggertype() diff --git a/contrib/curl/lib/curl_config.h b/contrib/curl/lib/curl_config.h index fe05c2b8a1..23534669b2 100644 --- a/contrib/curl/lib/curl_config.h +++ b/contrib/curl/lib/curl_config.h @@ -2,7 +2,7 @@ /* lib/curl_config.h.in. Generated from configure.ac by autoheader. */ /* Location of default ca bundle */ -#define CURL_CA_BUNDLE "/etc/pki/tls/certs/ca-bundle.crt" +/* #undef CURL_CA_BUNDLE */ /* Location of default ca path */ /* #undef CURL_CA_PATH */ diff --git a/contrib/curl/premake5.lua b/contrib/curl/premake5.lua index da18bafb3d..be00a757e8 100644 --- a/contrib/curl/premake5.lua +++ b/contrib/curl/premake5.lua @@ -2,7 +2,7 @@ project "curl-lib" language "C" kind "StaticLib" includedirs {"include", "lib"} - defines {"BUILDING_LIBCURL", "CURL_STATICLIB", "CURL_HTTP_ONLY", "CURL_DISABLE_LDAP" } + defines {"BUILDING_LIBCURL", "CURL_STATICLIB", "HTTP_ONLY", "CURL_DISABLE_LDAP" } flags { "StaticRuntime" } location "build" @@ -14,12 +14,34 @@ project "curl-lib" configuration { 'windows' } defines {"WIN32"} + defines {"USE_SSL", "USE_SCHANNEL", "USE_WINDOWS_SSPI"} configuration { 'linux' } - defines {"HAVE_CONFIG_H", "CURL_HIDDEN_SYMBOLS"} + + defines {"HAVE_CONFIG_H", "CURL_HIDDEN_SYMBOLS" } + if os.findlib("ssl") then + defines { "USE_SSL", "USE_OPENSSL", "USE_SSLEAY" } + + -- find the location of the ca bundle + local ca = nil + for _, f in ipairs { + '/etc/ssl/certs/ca-certificates.crt', + '/etc/pki/tls/certs/ca-bundle.crt', + '/usr/share/ssl/certs/ca-bundle.crt', + '/usr/local/share/certs/ca-root.crt', + '/etc/ssl/cert.pem' } do + if os.isfile(f) then + ca = f + break + end + end + if ca then + defines { 'CURL_CA_BUNDLE=\\"' .. ca .. '\\"' } + end + end configuration { 'macosx' } - defines { 'HAVE_CONFIG_H' } + defines { 'HAVE_CONFIG_H', 'USE_SSL', 'USE_DARWINSSL' } configuration "Release" defines {"NDEBUG"} diff --git a/premake4.lua b/premake4.lua index 3d5c5956ce..1f6284aad0 100644 --- a/premake4.lua +++ b/premake4.lua @@ -18,7 +18,7 @@ language "C" kind "ConsoleApp" flags { "No64BitChecks", "ExtraWarnings", "StaticRuntime" } - includedirs { "src/host/lua-5.1.4/src" } + includedirs { "src/host/lua/src" } files { @@ -29,12 +29,12 @@ excludes { - "src/host/lua-5.1.4/src/lauxlib.c", - "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" + "src/host/lua/src/lauxlib.c", + "src/host/lua/src/lua.c", + "src/host/lua/src/luac.c", + "src/host/lua/src/print.c", + "src/host/lua/**.lua", + "src/host/lua/etc/*.c" } configuration "Debug" diff --git a/premake5.lua b/premake5.lua index 2c00e000c2..a1f08f24f1 100644 --- a/premake5.lua +++ b/premake5.lua @@ -73,7 +73,10 @@ description = "Disable Zlib/Zip 3rd party lib" } - + newoption { + trigger = "no-bytecode", + description = "Don't embed bytecode, but instead use the stripped souce code." + } -- -- Define the project. Put the release configuration first so it will be the @@ -87,12 +90,16 @@ configurations { "Release", "Debug" } location ( _OPTIONS["to"] ) + configuration { "macosx", "gmake" } + buildoptions { "-mmacosx-version-min=10.4" } + linkoptions { "-mmacosx-version-min=10.4" } + project "Premake5" targetname "premake5" language "C" kind "ConsoleApp" flags { "No64BitChecks", "ExtraWarnings", "StaticRuntime" } - includedirs { "src/host/lua-5.1.4/src" } + includedirs { "src/host/lua/src" } -- optional 3rd party libraries if not _OPTIONS["no-zlib"] then @@ -115,12 +122,12 @@ excludes { - "src/host/lua-5.1.4/src/lauxlib.c", - "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" + "src/host/lua/src/lauxlib.c", + "src/host/lua/src/lua.c", + "src/host/lua/src/luac.c", + "src/host/lua/src/print.c", + "src/host/lua/**.lua", + "src/host/lua/etc/*.c" } configuration "Debug" @@ -152,14 +159,20 @@ configuration "linux or hurd" links { "dl", "rt" } + configuration "linux" + if not _OPTIONS["no-curl"] and os.findlib("ssl") then + links { "ssl", "crypto" } + end + configuration "macosx" defines { "LUA_USE_MACOSX" } links { "CoreServices.framework" } + if not _OPTIONS["no-curl"] then + links { "Security.framework" } + end configuration { "macosx", "gmake" } toolset "clang" - buildoptions { "-mmacosx-version-min=10.4" } - linkoptions { "-mmacosx-version-min=10.4" } configuration { "solaris" } linkoptions { "-Wl,--export-dynamic" } @@ -168,6 +181,7 @@ defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" } links { "m" } + -- optional 3rd party libraries group "contrib" if not _OPTIONS["no-zlib"] then diff --git a/scripts/RELEASE.txt b/scripts/RELEASE.txt index 325c639327..14252f0e1b 100644 --- a/scripts/RELEASE.txt +++ b/scripts/RELEASE.txt @@ -3,6 +3,8 @@ PREMAKE RELEASE CHECKLIST PREP + * Make sure submodules are up to date + * Create working branch for release prep * Update CHANGES.txt and CONTRIBUTORS.txt @@ -19,7 +21,7 @@ RELEASE * On each platform, run `premake5 package binary` - * Merge working branch to release and tag + * Merge working branch to release and tag; push with tags * Create new release on GitHub from CHANGES.txt; upload files @@ -29,9 +31,6 @@ RELEASE * Post annoucement to @industrious on Twitter - * Add release to Freshmeat - http://freshmeat.net/projects/premake - CYCLE diff --git a/scripts/embed.lua b/scripts/embed.lua index 7e79bf3c50..7879678073 100644 --- a/scripts/embed.lua +++ b/scripts/embed.lua @@ -5,85 +5,102 @@ -- issues in Mac OS X Universal builds. -- + local scriptCount = 0 + local function loadScript(fname) fname = path.getabsolute(fname) - local f = io.open(fname) - local s = assert(f:read("*a")) + local f = io.open(fname, "rb") + local s = assert(f:read("*all")) f:close() + return s + end + + local function stripScript(s) -- strip tabs - s = s:gsub("[\t]", "") + local result = s:gsub("[\t]", "") -- strip any CRs - s = s:gsub("[\r]", "") + result = result:gsub("[\r]", "") -- strip out block comments - s = s:gsub("[^\"']%-%-%[%[.-%]%]", "") - s = s:gsub("[^\"']%-%-%[=%[.-%]=%]", "") - s = s:gsub("[^\"']%-%-%[==%[.-%]==%]", "") + result = result:gsub("[^\"']%-%-%[%[.-%]%]", "") + result = result:gsub("[^\"']%-%-%[=%[.-%]=%]", "") + sresult = result:gsub("[^\"']%-%-%[==%[.-%]==%]", "") -- strip out inline comments - s = s:gsub("\n%-%-[^\n]*", "\n") - - -- escape backslashes - s = s:gsub("\\", "\\\\") + result = result:gsub("\n%-%-[^\n]*", "\n") -- strip duplicate line feeds - s = s:gsub("\n+", "\n") + result = result:gsub("\n+", "\n") -- strip out leading comments - s = s:gsub("^%-%-[^\n]*\n", "") + result = result:gsub("^%-%-[^\n]*\n", "") - -- escape line feeds - s = s:gsub("\n", "\\n") + return result + end - -- escape double quote marks - s = s:gsub("\"", "\\\"") - return s - end + local function outputScript(result, script) + local data = script.data + local length = #data + if length > 0 then + script.table = string.format("builtin_script_%d", scriptCount) + scriptCount = scriptCount + 1 - local function appendScript(result, contents) - -- break up large strings to fit in Visual Studio's string length limit - local max = 4096 - local start = 1 - local len = contents:len() - if len > 0 then - 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 + buffered.writeln(result, "// ".. script.name) + buffered.writeln(result, "static const unsigned char " .. script.table .. "[] = {") + + for i = 1, length do + buffered.write(result, string.format("%3d, ", data:byte(i))) + if (i % 32 == 0) then + buffered.writeln(result) end + end + + buffered.writeln(result, "};") + buffered.writeln(result) + end + end - local s = contents:sub(start, finish) - table.insert(result, "\t\"" .. s .. iif(finish < len, '"', '",')) - start = finish + 1 + local function addScript(result, filename, name, data) + if not data then + if not _OPTIONS["no-bytecode"] then + verbosef("Compiling... " .. filename) + local output = path.replaceextension(filename, ".luac") + local res, err = os.compile(filename, output); + if res ~= nil then + data = loadScript(output) + os.remove(output) + else + print(err) + print("Embedding source instead.") + data = stripScript(loadScript(filename)) + end + else + data = stripScript(loadScript(filename)) end - else - table.insert(result, "\t\"\",") end - table.insert(result, "") + local script = {} + script.filename = filename + script.name = name + script.data = data + table.insert(result, script) end - -- Prepare the file header - local result = {} - table.insert(result, "/* Premake's Lua scripts, as static data buffers for release mode builds */") - table.insert(result, "/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */") - table.insert(result, "/* To regenerate this file, run: premake5 embed */") - table.insert(result, "") - table.insert(result, '#include "premake.h"') - table.insert(result, "") - + local result = buffered.new() + buffered.writeln(result, "/* Premake's Lua scripts, as static data buffers for release mode builds */") + buffered.writeln(result, "/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */") + buffered.writeln(result, "/* To regenerate this file, run: premake5 embed */") + buffered.writeln(result, "") + buffered.writeln(result, '#include "premake.h"') + buffered.writeln(result, "") -- Find all of the _manifest.lua files within the project @@ -96,84 +113,70 @@ userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "**/_user_modules.lua"))) userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "_user_modules.lua"))) --- Generate an index of the script file names. Script names are stored --- relative to the directory containing the manifest, i.e. the main --- Xcode script, which is at $/modules/xcode/xcode.lua is stored as --- "xcode/xcode.lua". - table.insert(result, "const char* builtin_scripts_index[] = {") +-- Generate table of embedded content. + local contentTable = {} + print("Compiling... ") for mi = 1, #manifests do local manifestName = manifests[mi] - local manifestDir = path.getdirectory(manifestName) - local baseDir = path.getdirectory(manifestDir) + local manifestDir = path.getdirectory(manifestName) + local baseDir = path.getdirectory(manifestDir) local files = dofile(manifests[mi]) for fi = 1, #files do local filename = path.join(manifestDir, files[fi]) - filename = path.getrelative(baseDir, filename) - table.insert(result, '\t"' .. filename .. '",') + addScript(contentTable, filename, path.getrelative(baseDir, filename)) end end - table.insert(result, '\t"src/_premake_main.lua",') - table.insert(result, '\t"src/_manifest.lua",') - table.insert(result, '\t"src/_modules.lua",') - table.insert(result, "\tNULL") - table.insert(result, "};") - table.insert(result, "") - + addScript(contentTable, path.join(_SCRIPT_DIR, "../src/_premake_main.lua"), "src/_premake_main.lua") + addScript(contentTable, path.join(_SCRIPT_DIR, "../src/_manifest.lua"), "src/_manifest.lua") --- Embed the actual script contents +-- Add the list of modules - table.insert(result, "const char* builtin_scripts[] = {") + local modules = dofile("../src/_modules.lua") + for _, userModules in ipairs(userModuleFiles) do + modules = table.join(modules, dofile(userModules)) + end - for mi = 1, #manifests do - local manifestName = manifests[mi] - local manifestDir = path.getdirectory(manifestName) + addScript(contentTable, "_modules.lua", "src/_modules.lua", "return {" .. table.implode(modules, '"', '"', ', ') .. "}") - local files = dofile(manifests[mi]) - for fi = 1, #files do - local filename = path.join(manifestDir, files[fi]) +-- Embed the actual script contents - local scr = loadScript(filename) - appendScript(result, scr) - end + print("Embedding...") + for mi = 1, #contentTable do + outputScript(result, contentTable[mi]) end - appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_premake_main.lua"))) - appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_manifest.lua"))) - --- Write the list of modules +-- Generate an index of the script file names. Script names are stored +-- relative to the directory containing the manifest, i.e. the main +-- Xcode script, which is at $/modules/xcode/xcode.lua is stored as +-- "xcode/xcode.lua". + buffered.writeln(result, "const buildin_mapping builtin_scripts[] = {") - local modules = dofile("../src/_modules.lua") - for _, userModules in ipairs(userModuleFiles) do - modules = table.join(modules, dofile(userModules)) + for mi = 1, #contentTable do + if contentTable[mi].table then + buffered.writeln(result, string.format('\t{"%s", %s, sizeof(%s)},', contentTable[mi].name, contentTable[mi].table, contentTable[mi].table)) + else + buffered.writeln(result, string.format('\t{"%s", NULL, 0},', contentTable[mi].name)) + end end - appendScript(result, "return {" .. table.implode(modules, "\\\"", "\\\"", ",\\n") .. "}") - - table.insert(result, "\tNULL") - table.insert(result, "};") - table.insert(result, "") + buffered.writeln(result, "\t{NULL, NULL, 0}") + buffered.writeln(result, "};") + buffered.writeln(result, "") -- Write it all out. Check against the current contents of scripts.c first, -- and only overwrite it if there are actual changes. - result = table.concat(result, "\n") - + print("Writing...") local scriptsFile = path.getabsolute(path.join(_SCRIPT_DIR, "../src/host/scripts.c")) + local output = buffered.tostring(result) - local oldVersion - local file = io.open(scriptsFile, "r") - if file then - oldVersion = file:read("*a") - file:close() - end - - if oldVersion ~= result then - print("Writing scripts.c") - file = io.open(scriptsFile, "w+b") - file:write(result) - file:close() + local f, err = os.writefile_ifnotequal(output, scriptsFile); + if (f < 0) then + error(err, 0) + elseif (f > 0) then + printf("Generated %s...", path.getrelative(os.getcwd(), scriptsFile)) end diff --git a/src/_premake_init.lua b/src/_premake_init.lua index e19908298d..1819df9205 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -549,7 +549,7 @@ } api.register { - name = "framework", + name = "dotnetframework", scope = "config", kind = "string", } @@ -1060,6 +1060,11 @@ } } + api.register { + name = "largeaddressaware", + scope = "config", + kind = "boolean", + } ----------------------------------------------------------------------------- -- @@ -1073,6 +1078,7 @@ api.alias("buildoutputs", "buildOutputs") api.alias("cleanextensions", "cleanExtensions") api.alias("configfile", "configFile") + api.alias("dotnetframework", "framework") api.alias("editandcontinue", "editAndContinue") api.alias("fileextension", "fileExtension") api.alias("propertydefinition", "propertyDefinition") diff --git a/src/_premake_main.lua b/src/_premake_main.lua index 527687ed9b..d5c7b10076 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -6,7 +6,10 @@ local shorthelp = "Type 'premake5 --help' for help" local versionhelp = "premake5 (Premake Build Script Generator) %s" + local startTime = os.clock() +-- set a global. + _PREMAKE_STARTTIME = startTime -- Load the collection of core scripts, required for everything else to work @@ -328,7 +331,8 @@ function m.postAction() if p.action.isConfigurable() then - print("Done.") + local duration = math.floor((os.clock() - startTime) * 1000); + printf("Done (%dms).", duration) end end diff --git a/src/actions/make/_make.lua b/src/actions/make/_make.lua index e538148d46..2cb50c05a2 100644 --- a/src/actions/make/_make.lua +++ b/src/actions/make/_make.lua @@ -20,7 +20,7 @@ shortname = "GNU Make", description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin", - valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, + valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility" }, valid_languages = { "C", "C++", "C#" }, diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index 1610789ca6..7d58dfd66c 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -404,7 +404,7 @@ function make.includes(cfg, toolset) - local includes = premake.esc(toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs)) + local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs) _p(' INCLUDES +=%s', make.list(includes)) end @@ -434,6 +434,9 @@ else _p(' LINKCMD = $(AR) -rcs "$@" $(OBJECTS)') end + elseif cfg.kind == premake.UTILITY then + -- Empty LINKCMD for Utility (only custom build rules) + _p(' LINKCMD =') else -- this was $(TARGET) $(LDFLAGS) $(OBJECTS) -- but had trouble linking to certain static libs; $(OBJECTS) moved up diff --git a/src/actions/make/make_csharp.lua b/src/actions/make/make_csharp.lua index 265d990099..7a7e3fbda6 100644 --- a/src/actions/make/make_csharp.lua +++ b/src/actions/make/make_csharp.lua @@ -189,7 +189,7 @@ local toolset = premake.tools.dotnet local ext = make.getmakefilename(prj, true) local makefile = path.getname(premake.filename(prj, ext)) - local response = path.translate(make.cs.getresponsefilename(prj)) + local response = make.cs.getresponsefilename(prj) _p('$(RESPONSE): %s', makefile) _p('\t@echo Generating response file', prj.name) @@ -197,14 +197,15 @@ _p('ifeq (posix,$(SHELLTYPE))') _x('\t$(SILENT) rm -f $(RESPONSE)') _p('else') - _x('\t$(SILENT) if exist $(RESPONSE) del %s', response) + _x('\t$(SILENT) if exist $(RESPONSE) del %s', path.translate(response, '\\')) _p('endif') + local sep = os.is("windows") and "\\" or "/" local tr = project.getsourcetree(prj) premake.tree.traverse(tr, { onleaf = function(node, depth) if toolset.fileinfo(node).action == "Compile" then - _x('\t@echo %s >> $(RESPONSE)', path.translate(node.relpath)) + _x('\t@echo %s >> $(RESPONSE)', path.translate(node.relpath, sep)) end end }) diff --git a/src/actions/vstudio/vs2005_csproj.lua b/src/actions/vstudio/vs2005_csproj.lua index 9ac8b3cc9a..09aaedb1b3 100644 --- a/src/actions/vstudio/vs2005_csproj.lua +++ b/src/actions/vstudio/vs2005_csproj.lua @@ -480,7 +480,7 @@ function cs2005.targetFrameworkVersion(cfg) local action = premake.action.current() - local framework = cfg.framework or action.vstudio.targetFramework + local framework = cfg.dotnetframework or action.vstudio.targetFramework if framework then _p(2,'v%s', framework) end diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 80ea83891d..a06e5bc16e 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -40,6 +40,7 @@ function sln2005.generate(wks) -- Mark the file as Unicode premake.utf8() + premake.outln('') sln2005.reorderProjects(wks) @@ -296,11 +297,13 @@ -- be ignored. -- - sln2005.sectionmap = { - ConfigurationPlatforms = sln2005.configurationPlatforms, - SolutionProperties = sln2005.properties, - NestedProjects = sln2005.NestedProjects - } + sln2005.elements.sections = function(wks) + return { + sln2005.configurationPlatforms, + sln2005.properties, + sln2005.NestedProjects + } + end -- @@ -308,9 +311,5 @@ -- function sln2005.sections(wks) - for _, section in ipairs(sln2005.solutionSections(wks)) do - if sln2005.sectionmap[section] then - sln2005.sectionmap[section](wks) - end - end + p.callArray(sln2005.elements.sections, wks) end diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 8db620ef8b..a353f51474 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -110,7 +110,7 @@ local action = p.action.current() local tools = string.format(' ToolsVersion="%s"', action.vstudio.toolsVersion) - local framework = prj.framework or action.vstudio.targetFramework or "4.0" + local framework = prj.dotnetframework or action.vstudio.targetFramework or "4.0" p.w('v%s', framework) end @@ -405,6 +405,7 @@ m.moduleDefinitionFile, m.treatLinkerWarningAsErrors, m.ignoreDefaultLibraries, + m.largeAddressAware, m.additionalLinkOptions, } end @@ -725,7 +726,7 @@ m.elements.ResourceCompileFile = function(cfg, file) return {} - end + end m.elements.ResourceCompileFileCfg = function(fcfg, condition) return { @@ -879,11 +880,6 @@ function m.projectReferences(prj) local refs = project.getdependencies(prj, 'linkOnly') if #refs > 0 then - -- sort dependencies by uuid. - table.sort(refs, function(a,b) - return a.uuid < b.uuid - end) - p.push('') for _, ref in ipairs(refs) do local relpath = vstudio.path(prj, vstudio.projectfile(ref)) @@ -942,8 +938,17 @@ function m.additionalUsingDirectories(cfg) if #cfg.usingdirs > 0 then - local dirs = table.concat(vstudio.path(cfg, cfg.usingdirs), ";") - m.element("AdditionalUsingDirectories", nil, "%s;%%(AdditionalUsingDirectories)", dirs) + local dirs = vstudio.path(cfg, cfg.usingdirs) + if #dirs > 0 then + m.element("AdditionalUsingDirectories", nil, "%s;%%(AdditionalUsingDirectories)", table.concat(dirs, ";")) + end + end + end + + + function m.largeAddressAware(cfg) + if (cfg.largeaddressaware == true) then + m.element("LargeAddressAware", nil, 'true') end end diff --git a/src/base/container.lua b/src/base/container.lua index 95c04c6aa0..868e8dfa89 100644 --- a/src/base/container.lua +++ b/src/base/container.lua @@ -152,12 +152,6 @@ function container.bakeChildren(self) for class in container.eachChildClass(self.class) do local children = self[class.pluralName] - - -- sort children by name. - table.sort(children, function(a,b) - return a.name < b.name - end) - for i = 1, #children do local ctx = container.bake(children[i]) children[i] = ctx diff --git a/src/base/context.lua b/src/base/context.lua index a3e0e35737..094a223ea2 100644 --- a/src/base/context.lua +++ b/src/base/context.lua @@ -109,7 +109,22 @@ -- function context.mergeFilters(ctx, src) - ctx.terms = table.merge(ctx.terms, table.deepcopy(src.terms)) + + local function mergeTable(dest, src) + for k,v in pairs(src) do + if type(v) == "table" then + if type(dest[k]) == "table" then + dest[k] = mergeTable(dest[k], v) + else + dest[k] = table.deepcopy(v) + end + else + dest[k] = v + end + end + end + + mergeTable(ctx.terms, src.terms) end diff --git a/src/base/detoken.lua b/src/base/detoken.lua index cb41c25315..e20e50f9cb 100644 --- a/src/base/detoken.lua +++ b/src/base/detoken.lua @@ -45,7 +45,7 @@ -- enable access to the global environment setmetatable(environ, {__index = _G}) - function expandtoken(token, environ) + function expandtoken(token, e) -- convert the token into a function to execute local func, err = loadstring("return " .. token) if not func then @@ -53,7 +53,7 @@ end -- give the function access to the project objects - setfenv(func, environ) + setfenv(func, e) -- run it and get the result local result = func() or "" @@ -76,7 +76,7 @@ if varMap[token] then result = varMap[token] if type(result) == "function" then - result = result(environ) + result = result(e) end isAbs = path.isabsolute(result) end @@ -103,7 +103,7 @@ return result end - function expandvalue(value) + function expandvalue(value, e) if type(value) ~= "string" then return value end @@ -111,7 +111,7 @@ local count repeat value, count = value:gsub("%%{(.-)}", function(token) - local result, err = expandtoken(token:gsub("\\", "\\\\"), environ) + local result, err = expandtoken(token:gsub("\\", "\\\\"), e) if not result then error(err, 0) end @@ -133,7 +133,7 @@ return value end - function recurse(value) + function recurse(value, e) if type(value) == "table" then local res_table = {} @@ -148,10 +148,10 @@ return res_table else - return expandvalue(value) + return expandvalue(value, e) end end - return recurse(value) + return recurse(value, environ) end diff --git a/src/base/os.lua b/src/base/os.lua index a31a977b89..bdbe123624 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -101,7 +101,7 @@ table.insert(formats, "%s") path = path or "" local archpath = "/lib:/usr/lib:/usr/local/lib" - if os.is64bit() then + if os.is64bit() and not os.is("macosx") then archpath = "/lib64:/usr/lib64/:usr/local/lib64" .. ":" .. archpath end if (#path > 0) then diff --git a/src/base/path.lua b/src/base/path.lua index 9edad7645a..91fb00d383 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -24,7 +24,7 @@ end -- add the extension if it isn't there already - if not p:endswith(ext) then + if not path.hasextension(p, ext) then p = p .. ext end @@ -237,30 +237,3 @@ return p:match("^(.*)"..ext.."$")..newext 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 diff --git a/src/base/workspace.lua b/src/base/workspace.lua index ab6345dcb4..82c342acc9 100644 --- a/src/base/workspace.lua +++ b/src/base/workspace.lua @@ -163,3 +163,31 @@ function workspace.hasProject(self, func) return p.container.hasChild(self, p.project, func) end + + +-- +-- Return the relative path from the solution to the specified file. +-- +-- @param self +-- The workspace object to query. +-- @param filename +-- The file path, or an array of file paths, to convert. +-- @return +-- The relative path, or array of paths, from the workspace to the file. +-- + + function workspace.getrelative(self, filename) + if type(filename) == "table" then + local result = {} + for i, name in ipairs(filename) do + if name and #name > 0 then + table.insert(result, workspace.getrelative(self, name)) + end + end + return result + else + if filename then + return path.getrelative(self.location, filename) + end + end + end diff --git a/src/host/buffered_io.c b/src/host/buffered_io.c index e60c359e38..08bf383879 100644 --- a/src/host/buffered_io.c +++ b/src/host/buffered_io.c @@ -66,10 +66,11 @@ int buffered_write(lua_State* L) int buffered_writeln(lua_State* L) { size_t l; - const char *s = luaL_checklstring(L, 2, &l); + const char *s = luaL_optlstring(L, 2, NULL, &l); Buffer* b = (Buffer*)lua_touserdata(L, 1); - do_write(b, s, l); + if (s != NULL) + do_write(b, s, l); do_write(b, "\r\n", 2); return 0; } diff --git a/src/host/debug_prompt.c b/src/host/debug_prompt.c index 890ebd760a..a1fe19e5f6 100644 --- a/src/host/debug_prompt.c +++ b/src/host/debug_prompt.c @@ -8,7 +8,7 @@ /* Build on the REPL built into Lua already */ #define main lua_main -#include "lua-5.1.4/src/lua.c" +#include "lua/src/lua.c" /* Based on dotty() in lua.c */ diff --git a/src/host/http.c b/src/host/http.c index 28c1b63943..589a131273 100644 --- a/src/host/http.c +++ b/src/host/http.c @@ -6,11 +6,15 @@ #include "premake.h" #include +#include #ifdef PREMAKE_CURL #include +#define _MPRINTF_REPLACE /* use curl functions only */ +#include + typedef struct { char* ptr; size_t len; @@ -28,10 +32,12 @@ void string_init(string* s) s->ptr[0] = '\0'; } -typedef struct { +typedef struct +{ lua_State* L; int RefIndex; string S; + char errorBuffer[CURL_ERROR_SIZE]; } CurlCallbackState; static int curl_progress_cb(void* userdata, double dltotal, double dlnow, @@ -144,6 +150,7 @@ static CURL* curl_request(lua_State* L, CurlCallbackState* state, FILE* fp, int curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, state->errorBuffer); get_headers(L, &headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); @@ -164,19 +171,20 @@ static CURL* curl_request(lua_State* L, CurlCallbackState* state, FILE* fp, int curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress_cb); } + // clear error buffer. + state->errorBuffer[0] = 0; + return curl; } int http_get(lua_State* L) { - CurlCallbackState state = { 0, 0 }; + CurlCallbackState state = { 0, 0, {NULL, 0}, {0} }; CURL* curl = curl_request(L, &state, /*fp=*/NULL, /*progressFnIndex=*/2); CURLcode code; - const char* err; - string_init(&state.S); if (!curl) @@ -188,10 +196,11 @@ int http_get(lua_State* L) code = curl_easy_perform(curl); if (code != CURLE_OK) { - err = curl_easy_strerror(code); + char errorBuf[1024]; + snprintf(errorBuf, sizeof(errorBuf) - 1, "%s\n%s\n", curl_easy_strerror(code), state.errorBuffer); lua_pushnil(L); - lua_pushfstring(L, err); + lua_pushfstring(L, errorBuf); return 2; } @@ -204,7 +213,7 @@ int http_get(lua_State* L) int http_download(lua_State* L) { - CurlCallbackState state = { 0, 0 }; + CurlCallbackState state = { 0, 0, {NULL, 0}, {0} }; CURL* curl; CURLcode code = CURLE_FAILED_INIT; @@ -229,7 +238,17 @@ int http_download(lua_State* L) fclose(fp); - lua_pushstring(L, curl_easy_strerror(code)); + if (code != CURLE_OK) + { + char errorBuf[1024]; + snprintf(errorBuf, sizeof(errorBuf) - 1, "%s\n%s\n", curl_easy_strerror(code), state.errorBuffer); + lua_pushstring(L, errorBuf); + } + else + { + lua_pushstring(L, "OK"); + } + lua_pushnumber(L, code); return 2; } diff --git a/src/host/lua-5.1.4/Makefile b/src/host/lua-5.1.4/Makefile deleted file mode 100644 index 6e78f66fa5..0000000000 --- a/src/host/lua-5.1.4/Makefile +++ /dev/null @@ -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) diff --git a/src/host/lua-5.1.4/etc/Makefile b/src/host/lua-5.1.4/etc/Makefile deleted file mode 100644 index 6d00008d98..0000000000 --- a/src/host/lua-5.1.4/etc/Makefile +++ /dev/null @@ -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 diff --git a/src/host/lua-5.1.4/src/Makefile b/src/host/lua-5.1.4/src/Makefile deleted file mode 100644 index e4a3cd6108..0000000000 --- a/src/host/lua-5.1.4/src/Makefile +++ /dev/null @@ -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) diff --git a/src/host/lua-5.1.4/COPYRIGHT b/src/host/lua/COPYRIGHT similarity index 100% rename from src/host/lua-5.1.4/COPYRIGHT rename to src/host/lua/COPYRIGHT diff --git a/src/host/lua-5.1.4/HISTORY b/src/host/lua/HISTORY similarity index 100% rename from src/host/lua-5.1.4/HISTORY rename to src/host/lua/HISTORY diff --git a/src/host/lua-5.1.4/INSTALL b/src/host/lua/INSTALL similarity index 100% rename from src/host/lua-5.1.4/INSTALL rename to src/host/lua/INSTALL diff --git a/src/host/lua-5.1.4/README b/src/host/lua/README similarity index 100% rename from src/host/lua-5.1.4/README rename to src/host/lua/README diff --git a/src/host/lua-5.1.4/doc/amazon.gif b/src/host/lua/doc/amazon.gif similarity index 100% rename from src/host/lua-5.1.4/doc/amazon.gif rename to src/host/lua/doc/amazon.gif diff --git a/src/host/lua-5.1.4/doc/contents.html b/src/host/lua/doc/contents.html similarity index 100% rename from src/host/lua-5.1.4/doc/contents.html rename to src/host/lua/doc/contents.html diff --git a/src/host/lua-5.1.4/doc/cover.png b/src/host/lua/doc/cover.png similarity index 100% rename from src/host/lua-5.1.4/doc/cover.png rename to src/host/lua/doc/cover.png diff --git a/src/host/lua-5.1.4/doc/logo.gif b/src/host/lua/doc/logo.gif similarity index 100% rename from src/host/lua-5.1.4/doc/logo.gif rename to src/host/lua/doc/logo.gif diff --git a/src/host/lua-5.1.4/doc/lua.1 b/src/host/lua/doc/lua.1 similarity index 100% rename from src/host/lua-5.1.4/doc/lua.1 rename to src/host/lua/doc/lua.1 diff --git a/src/host/lua-5.1.4/doc/lua.css b/src/host/lua/doc/lua.css similarity index 100% rename from src/host/lua-5.1.4/doc/lua.css rename to src/host/lua/doc/lua.css diff --git a/src/host/lua-5.1.4/doc/lua.html b/src/host/lua/doc/lua.html similarity index 100% rename from src/host/lua-5.1.4/doc/lua.html rename to src/host/lua/doc/lua.html diff --git a/src/host/lua-5.1.4/doc/luac.1 b/src/host/lua/doc/luac.1 similarity index 100% rename from src/host/lua-5.1.4/doc/luac.1 rename to src/host/lua/doc/luac.1 diff --git a/src/host/lua-5.1.4/doc/luac.html b/src/host/lua/doc/luac.html similarity index 100% rename from src/host/lua-5.1.4/doc/luac.html rename to src/host/lua/doc/luac.html diff --git a/src/host/lua-5.1.4/doc/manual.css b/src/host/lua/doc/manual.css similarity index 100% rename from src/host/lua-5.1.4/doc/manual.css rename to src/host/lua/doc/manual.css diff --git a/src/host/lua-5.1.4/doc/manual.html b/src/host/lua/doc/manual.html similarity index 100% rename from src/host/lua-5.1.4/doc/manual.html rename to src/host/lua/doc/manual.html diff --git a/src/host/lua-5.1.4/doc/readme.html b/src/host/lua/doc/readme.html similarity index 100% rename from src/host/lua-5.1.4/doc/readme.html rename to src/host/lua/doc/readme.html diff --git a/src/host/lua-5.1.4/etc/README b/src/host/lua/etc/README similarity index 100% rename from src/host/lua-5.1.4/etc/README rename to src/host/lua/etc/README diff --git a/src/host/lua-5.1.4/etc/all.c b/src/host/lua/etc/all.c similarity index 100% rename from src/host/lua-5.1.4/etc/all.c rename to src/host/lua/etc/all.c diff --git a/src/host/lua-5.1.4/etc/lua.hpp b/src/host/lua/etc/lua.hpp similarity index 100% rename from src/host/lua-5.1.4/etc/lua.hpp rename to src/host/lua/etc/lua.hpp diff --git a/src/host/lua-5.1.4/etc/lua.ico b/src/host/lua/etc/lua.ico similarity index 100% rename from src/host/lua-5.1.4/etc/lua.ico rename to src/host/lua/etc/lua.ico diff --git a/src/host/lua-5.1.4/etc/lua.pc b/src/host/lua/etc/lua.pc similarity index 100% rename from src/host/lua-5.1.4/etc/lua.pc rename to src/host/lua/etc/lua.pc diff --git a/src/host/lua-5.1.4/etc/luavs.bat b/src/host/lua/etc/luavs.bat similarity index 97% rename from src/host/lua-5.1.4/etc/luavs.bat rename to src/host/lua/etc/luavs.bat index 08c2beddf6..054b4625c5 100644 --- a/src/host/lua-5.1.4/etc/luavs.bat +++ b/src/host/lua/etc/luavs.bat @@ -1,28 +1,28 @@ -@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 .. +@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 .. diff --git a/src/host/lua-5.1.4/etc/min.c b/src/host/lua/etc/min.c similarity index 100% rename from src/host/lua-5.1.4/etc/min.c rename to src/host/lua/etc/min.c diff --git a/src/host/lua-5.1.4/etc/noparser.c b/src/host/lua/etc/noparser.c similarity index 100% rename from src/host/lua-5.1.4/etc/noparser.c rename to src/host/lua/etc/noparser.c diff --git a/src/host/lua-5.1.4/etc/strict.lua b/src/host/lua/etc/strict.lua similarity index 100% rename from src/host/lua-5.1.4/etc/strict.lua rename to src/host/lua/etc/strict.lua diff --git a/src/host/lua-5.1.4/src/lapi.c b/src/host/lua/src/lapi.c similarity index 100% rename from src/host/lua-5.1.4/src/lapi.c rename to src/host/lua/src/lapi.c diff --git a/src/host/lua-5.1.4/src/lapi.h b/src/host/lua/src/lapi.h similarity index 100% rename from src/host/lua-5.1.4/src/lapi.h rename to src/host/lua/src/lapi.h diff --git a/src/host/lua-5.1.4/src/lauxlib.c b/src/host/lua/src/lauxlib.c similarity index 96% rename from src/host/lua-5.1.4/src/lauxlib.c rename to src/host/lua/src/lauxlib.c index c1618e34a1..e51f8cab0b 100644 --- a/src/host/lua-5.1.4/src/lauxlib.c +++ b/src/host/lua/src/lauxlib.c @@ -1,658 +1,658 @@ -/* -** $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... */ -} - - -#ifdef _MANAGED - #pragma managed(push, off) -#endif -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); -} -#ifdef _MANAGED - #pragma managed(pop) -#endif - -/* }====================================================== */ - - -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; -} - +/* +** $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... */ +} + + +#ifdef _MANAGED + #pragma managed(push, off) +#endif +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); +} +#ifdef _MANAGED + #pragma managed(pop) +#endif + +/* }====================================================== */ + + +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; +} + diff --git a/src/host/lua-5.1.4/src/lauxlib.h b/src/host/lua/src/lauxlib.h similarity index 100% rename from src/host/lua-5.1.4/src/lauxlib.h rename to src/host/lua/src/lauxlib.h diff --git a/src/host/lua-5.1.4/src/lbaselib.c b/src/host/lua/src/lbaselib.c similarity index 100% rename from src/host/lua-5.1.4/src/lbaselib.c rename to src/host/lua/src/lbaselib.c diff --git a/src/host/lua-5.1.4/src/lcode.c b/src/host/lua/src/lcode.c similarity index 100% rename from src/host/lua-5.1.4/src/lcode.c rename to src/host/lua/src/lcode.c diff --git a/src/host/lua-5.1.4/src/lcode.h b/src/host/lua/src/lcode.h similarity index 100% rename from src/host/lua-5.1.4/src/lcode.h rename to src/host/lua/src/lcode.h diff --git a/src/host/lua-5.1.4/src/ldblib.c b/src/host/lua/src/ldblib.c similarity index 100% rename from src/host/lua-5.1.4/src/ldblib.c rename to src/host/lua/src/ldblib.c diff --git a/src/host/lua-5.1.4/src/ldebug.c b/src/host/lua/src/ldebug.c similarity index 100% rename from src/host/lua-5.1.4/src/ldebug.c rename to src/host/lua/src/ldebug.c diff --git a/src/host/lua-5.1.4/src/ldebug.h b/src/host/lua/src/ldebug.h similarity index 100% rename from src/host/lua-5.1.4/src/ldebug.h rename to src/host/lua/src/ldebug.h diff --git a/src/host/lua-5.1.4/src/ldo.c b/src/host/lua/src/ldo.c similarity index 100% rename from src/host/lua-5.1.4/src/ldo.c rename to src/host/lua/src/ldo.c diff --git a/src/host/lua-5.1.4/src/ldo.h b/src/host/lua/src/ldo.h similarity index 100% rename from src/host/lua-5.1.4/src/ldo.h rename to src/host/lua/src/ldo.h diff --git a/src/host/lua-5.1.4/src/ldump.c b/src/host/lua/src/ldump.c similarity index 100% rename from src/host/lua-5.1.4/src/ldump.c rename to src/host/lua/src/ldump.c diff --git a/src/host/lua-5.1.4/src/lfunc.c b/src/host/lua/src/lfunc.c similarity index 100% rename from src/host/lua-5.1.4/src/lfunc.c rename to src/host/lua/src/lfunc.c diff --git a/src/host/lua-5.1.4/src/lfunc.h b/src/host/lua/src/lfunc.h similarity index 100% rename from src/host/lua-5.1.4/src/lfunc.h rename to src/host/lua/src/lfunc.h diff --git a/src/host/lua-5.1.4/src/lgc.c b/src/host/lua/src/lgc.c similarity index 100% rename from src/host/lua-5.1.4/src/lgc.c rename to src/host/lua/src/lgc.c diff --git a/src/host/lua-5.1.4/src/lgc.h b/src/host/lua/src/lgc.h similarity index 100% rename from src/host/lua-5.1.4/src/lgc.h rename to src/host/lua/src/lgc.h diff --git a/src/host/lua-5.1.4/src/linit.c b/src/host/lua/src/linit.c similarity index 100% rename from src/host/lua-5.1.4/src/linit.c rename to src/host/lua/src/linit.c diff --git a/src/host/lua-5.1.4/src/liolib.c b/src/host/lua/src/liolib.c similarity index 100% rename from src/host/lua-5.1.4/src/liolib.c rename to src/host/lua/src/liolib.c diff --git a/src/host/lua-5.1.4/src/llex.c b/src/host/lua/src/llex.c similarity index 100% rename from src/host/lua-5.1.4/src/llex.c rename to src/host/lua/src/llex.c diff --git a/src/host/lua-5.1.4/src/llex.h b/src/host/lua/src/llex.h similarity index 100% rename from src/host/lua-5.1.4/src/llex.h rename to src/host/lua/src/llex.h diff --git a/src/host/lua-5.1.4/src/llimits.h b/src/host/lua/src/llimits.h similarity index 100% rename from src/host/lua-5.1.4/src/llimits.h rename to src/host/lua/src/llimits.h diff --git a/src/host/lua-5.1.4/src/lmathlib.c b/src/host/lua/src/lmathlib.c similarity index 100% rename from src/host/lua-5.1.4/src/lmathlib.c rename to src/host/lua/src/lmathlib.c diff --git a/src/host/lua-5.1.4/src/lmem.c b/src/host/lua/src/lmem.c similarity index 100% rename from src/host/lua-5.1.4/src/lmem.c rename to src/host/lua/src/lmem.c diff --git a/src/host/lua-5.1.4/src/lmem.h b/src/host/lua/src/lmem.h similarity index 100% rename from src/host/lua-5.1.4/src/lmem.h rename to src/host/lua/src/lmem.h diff --git a/src/host/lua-5.1.4/src/loadlib.c b/src/host/lua/src/loadlib.c similarity index 100% rename from src/host/lua-5.1.4/src/loadlib.c rename to src/host/lua/src/loadlib.c diff --git a/src/host/lua-5.1.4/src/lobject.c b/src/host/lua/src/lobject.c similarity index 100% rename from src/host/lua-5.1.4/src/lobject.c rename to src/host/lua/src/lobject.c diff --git a/src/host/lua-5.1.4/src/lobject.h b/src/host/lua/src/lobject.h similarity index 100% rename from src/host/lua-5.1.4/src/lobject.h rename to src/host/lua/src/lobject.h diff --git a/src/host/lua-5.1.4/src/lopcodes.c b/src/host/lua/src/lopcodes.c similarity index 100% rename from src/host/lua-5.1.4/src/lopcodes.c rename to src/host/lua/src/lopcodes.c diff --git a/src/host/lua-5.1.4/src/lopcodes.h b/src/host/lua/src/lopcodes.h similarity index 100% rename from src/host/lua-5.1.4/src/lopcodes.h rename to src/host/lua/src/lopcodes.h diff --git a/src/host/lua-5.1.4/src/loslib.c b/src/host/lua/src/loslib.c similarity index 100% rename from src/host/lua-5.1.4/src/loslib.c rename to src/host/lua/src/loslib.c diff --git a/src/host/lua-5.1.4/src/lparser.c b/src/host/lua/src/lparser.c similarity index 100% rename from src/host/lua-5.1.4/src/lparser.c rename to src/host/lua/src/lparser.c diff --git a/src/host/lua-5.1.4/src/lparser.h b/src/host/lua/src/lparser.h similarity index 100% rename from src/host/lua-5.1.4/src/lparser.h rename to src/host/lua/src/lparser.h diff --git a/src/host/lua-5.1.4/src/lstate.c b/src/host/lua/src/lstate.c similarity index 100% rename from src/host/lua-5.1.4/src/lstate.c rename to src/host/lua/src/lstate.c diff --git a/src/host/lua-5.1.4/src/lstate.h b/src/host/lua/src/lstate.h similarity index 100% rename from src/host/lua-5.1.4/src/lstate.h rename to src/host/lua/src/lstate.h diff --git a/src/host/lua-5.1.4/src/lstring.c b/src/host/lua/src/lstring.c similarity index 100% rename from src/host/lua-5.1.4/src/lstring.c rename to src/host/lua/src/lstring.c diff --git a/src/host/lua-5.1.4/src/lstring.h b/src/host/lua/src/lstring.h similarity index 100% rename from src/host/lua-5.1.4/src/lstring.h rename to src/host/lua/src/lstring.h diff --git a/src/host/lua-5.1.4/src/lstrlib.c b/src/host/lua/src/lstrlib.c similarity index 100% rename from src/host/lua-5.1.4/src/lstrlib.c rename to src/host/lua/src/lstrlib.c diff --git a/src/host/lua-5.1.4/src/ltable.c b/src/host/lua/src/ltable.c similarity index 100% rename from src/host/lua-5.1.4/src/ltable.c rename to src/host/lua/src/ltable.c diff --git a/src/host/lua-5.1.4/src/ltable.h b/src/host/lua/src/ltable.h similarity index 100% rename from src/host/lua-5.1.4/src/ltable.h rename to src/host/lua/src/ltable.h diff --git a/src/host/lua-5.1.4/src/ltablib.c b/src/host/lua/src/ltablib.c similarity index 100% rename from src/host/lua-5.1.4/src/ltablib.c rename to src/host/lua/src/ltablib.c diff --git a/src/host/lua-5.1.4/src/ltm.c b/src/host/lua/src/ltm.c similarity index 100% rename from src/host/lua-5.1.4/src/ltm.c rename to src/host/lua/src/ltm.c diff --git a/src/host/lua-5.1.4/src/ltm.h b/src/host/lua/src/ltm.h similarity index 100% rename from src/host/lua-5.1.4/src/ltm.h rename to src/host/lua/src/ltm.h diff --git a/src/host/lua-5.1.4/src/lua.c b/src/host/lua/src/lua.c similarity index 100% rename from src/host/lua-5.1.4/src/lua.c rename to src/host/lua/src/lua.c diff --git a/src/host/lua-5.1.4/src/lua.h b/src/host/lua/src/lua.h similarity index 100% rename from src/host/lua-5.1.4/src/lua.h rename to src/host/lua/src/lua.h diff --git a/src/host/lua-5.1.4/src/luac.c b/src/host/lua/src/luac.c similarity index 100% rename from src/host/lua-5.1.4/src/luac.c rename to src/host/lua/src/luac.c diff --git a/src/host/lua-5.1.4/src/luaconf.h b/src/host/lua/src/luaconf.h similarity index 100% rename from src/host/lua-5.1.4/src/luaconf.h rename to src/host/lua/src/luaconf.h diff --git a/src/host/lua-5.1.4/src/lualib.h b/src/host/lua/src/lualib.h similarity index 100% rename from src/host/lua-5.1.4/src/lualib.h rename to src/host/lua/src/lualib.h diff --git a/src/host/lua-5.1.4/src/lundump.c b/src/host/lua/src/lundump.c similarity index 100% rename from src/host/lua-5.1.4/src/lundump.c rename to src/host/lua/src/lundump.c diff --git a/src/host/lua-5.1.4/src/lundump.h b/src/host/lua/src/lundump.h similarity index 100% rename from src/host/lua-5.1.4/src/lundump.h rename to src/host/lua/src/lundump.h diff --git a/src/host/lua-5.1.4/src/lvm.c b/src/host/lua/src/lvm.c similarity index 100% rename from src/host/lua-5.1.4/src/lvm.c rename to src/host/lua/src/lvm.c diff --git a/src/host/lua-5.1.4/src/lvm.h b/src/host/lua/src/lvm.h similarity index 100% rename from src/host/lua-5.1.4/src/lvm.h rename to src/host/lua/src/lvm.h diff --git a/src/host/lua-5.1.4/src/lzio.c b/src/host/lua/src/lzio.c similarity index 100% rename from src/host/lua-5.1.4/src/lzio.c rename to src/host/lua/src/lzio.c diff --git a/src/host/lua-5.1.4/src/lzio.h b/src/host/lua/src/lzio.h similarity index 100% rename from src/host/lua-5.1.4/src/lzio.h rename to src/host/lua/src/lzio.h diff --git a/src/host/lua-5.1.4/src/print.c b/src/host/lua/src/print.c similarity index 100% rename from src/host/lua-5.1.4/src/print.c rename to src/host/lua/src/print.c diff --git a/src/host/lua-5.1.4/test/README b/src/host/lua/test/README similarity index 100% rename from src/host/lua-5.1.4/test/README rename to src/host/lua/test/README diff --git a/src/host/lua-5.1.4/test/bisect.lua b/src/host/lua/test/bisect.lua similarity index 100% rename from src/host/lua-5.1.4/test/bisect.lua rename to src/host/lua/test/bisect.lua diff --git a/src/host/lua-5.1.4/test/cf.lua b/src/host/lua/test/cf.lua similarity index 100% rename from src/host/lua-5.1.4/test/cf.lua rename to src/host/lua/test/cf.lua diff --git a/src/host/lua-5.1.4/test/echo.lua b/src/host/lua/test/echo.lua similarity index 100% rename from src/host/lua-5.1.4/test/echo.lua rename to src/host/lua/test/echo.lua diff --git a/src/host/lua-5.1.4/test/env.lua b/src/host/lua/test/env.lua similarity index 100% rename from src/host/lua-5.1.4/test/env.lua rename to src/host/lua/test/env.lua diff --git a/src/host/lua-5.1.4/test/factorial.lua b/src/host/lua/test/factorial.lua similarity index 100% rename from src/host/lua-5.1.4/test/factorial.lua rename to src/host/lua/test/factorial.lua diff --git a/src/host/lua-5.1.4/test/fib.lua b/src/host/lua/test/fib.lua similarity index 100% rename from src/host/lua-5.1.4/test/fib.lua rename to src/host/lua/test/fib.lua diff --git a/src/host/lua-5.1.4/test/fibfor.lua b/src/host/lua/test/fibfor.lua similarity index 100% rename from src/host/lua-5.1.4/test/fibfor.lua rename to src/host/lua/test/fibfor.lua diff --git a/src/host/lua-5.1.4/test/globals.lua b/src/host/lua/test/globals.lua similarity index 100% rename from src/host/lua-5.1.4/test/globals.lua rename to src/host/lua/test/globals.lua diff --git a/src/host/lua-5.1.4/test/hello.lua b/src/host/lua/test/hello.lua similarity index 100% rename from src/host/lua-5.1.4/test/hello.lua rename to src/host/lua/test/hello.lua diff --git a/src/host/lua-5.1.4/test/life.lua b/src/host/lua/test/life.lua similarity index 100% rename from src/host/lua-5.1.4/test/life.lua rename to src/host/lua/test/life.lua diff --git a/src/host/lua-5.1.4/test/luac.lua b/src/host/lua/test/luac.lua similarity index 100% rename from src/host/lua-5.1.4/test/luac.lua rename to src/host/lua/test/luac.lua diff --git a/src/host/lua-5.1.4/test/printf.lua b/src/host/lua/test/printf.lua similarity index 100% rename from src/host/lua-5.1.4/test/printf.lua rename to src/host/lua/test/printf.lua diff --git a/src/host/lua-5.1.4/test/readonly.lua b/src/host/lua/test/readonly.lua similarity index 100% rename from src/host/lua-5.1.4/test/readonly.lua rename to src/host/lua/test/readonly.lua diff --git a/src/host/lua-5.1.4/test/sieve.lua b/src/host/lua/test/sieve.lua similarity index 100% rename from src/host/lua-5.1.4/test/sieve.lua rename to src/host/lua/test/sieve.lua diff --git a/src/host/lua-5.1.4/test/sort.lua b/src/host/lua/test/sort.lua similarity index 100% rename from src/host/lua-5.1.4/test/sort.lua rename to src/host/lua/test/sort.lua diff --git a/src/host/lua-5.1.4/test/table.lua b/src/host/lua/test/table.lua similarity index 100% rename from src/host/lua-5.1.4/test/table.lua rename to src/host/lua/test/table.lua diff --git a/src/host/lua-5.1.4/test/trace-calls.lua b/src/host/lua/test/trace-calls.lua similarity index 100% rename from src/host/lua-5.1.4/test/trace-calls.lua rename to src/host/lua/test/trace-calls.lua diff --git a/src/host/lua-5.1.4/test/trace-globals.lua b/src/host/lua/test/trace-globals.lua similarity index 100% rename from src/host/lua-5.1.4/test/trace-globals.lua rename to src/host/lua/test/trace-globals.lua diff --git a/src/host/lua-5.1.4/test/xd.lua b/src/host/lua/test/xd.lua similarity index 100% rename from src/host/lua-5.1.4/test/xd.lua rename to src/host/lua/test/xd.lua diff --git a/src/host/lua_auxlib.c b/src/host/lua_auxlib.c index eb5d49200e..58e4906e6a 100644 --- a/src/host/lua_auxlib.c +++ b/src/host/lua_auxlib.c @@ -15,7 +15,7 @@ static int chunk_wrapper(lua_State* L); * can replace it with my own implementation. */ #define luaL_loadfile original_luaL_loadfile -#include "lua-5.1.4/src/lauxlib.c" +#include "lua/src/lauxlib.c" #undef luaL_loadfile diff --git a/src/host/os_compile.c b/src/host/os_compile.c new file mode 100644 index 0000000000..a19580509b --- /dev/null +++ b/src/host/os_compile.c @@ -0,0 +1,57 @@ +/** + * \file os_uuid.c + * \brief Create a new UUID. + * \author Copyright (c) 2002-2012 Jason Perkins and the Premake project + */ + +#include "premake.h" +#include "lua/src/lundump.h" +#include "lua/src/lobject.h" +#include "lua/src/lstate.h" + +extern int original_luaL_loadfile(lua_State* L, const char* filename); + +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); +} + +int os_compile(lua_State* L) +{ + const char* input = luaL_checkstring(L, 1); + const char* output = luaL_checkstring(L, 2); + lua_State* P = luaL_newstate(); + + if (original_luaL_loadfile(P, input) != OKAY) + { + const char* msg = lua_tostring(P, -1); + if (msg == NULL) + msg = "(error with no message)"; + + lua_pushnil(L); + lua_pushfstring(L, "Unable to compile '%s': %s", input, msg); + + lua_close(P); + return 2; + } + else + { + FILE* outputFile = (output == NULL) ? stdout : fopen(output, "wb"); + if (outputFile == NULL) + { + lua_close(P); + + lua_pushnil(L); + lua_pushfstring(L, "unable to write to '%s'", output); + return 2; + } + + lua_dump(P, writer, outputFile); + fclose(outputFile); + + lua_close(P); + lua_pushboolean(L, 1); + return 1; + } +} diff --git a/src/host/os_isdir.c b/src/host/os_isdir.c index fb5e8bb57e..163252cf8f 100644 --- a/src/host/os_isdir.c +++ b/src/host/os_isdir.c @@ -8,20 +8,35 @@ #include #include "premake.h" +#ifdef _WIN32 +#include +#endif int os_isdir(lua_State* L) { struct stat buf; const char* path = luaL_checkstring(L, 1); +#ifdef _WIN32 + int attr; +#endif /* empty path is equivalent to ".", must be true */ if (strlen(path) == 0) { lua_pushboolean(L, 1); } +#ifdef _WIN32 + // Use Windows-specific GetFileAttributes since it deals with symbolic links. + else if ((attr = GetFileAttributes(path)) != INVALID_FILE_ATTRIBUTES) + { + int isdir = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; + lua_pushboolean(L, isdir); + } +#endif else if (stat(path, &buf) == 0) { - lua_pushboolean(L, buf.st_mode & S_IFDIR); + int isdir = (buf.st_mode & S_IFDIR) != 0; + lua_pushboolean(L, isdir); } else { diff --git a/src/host/os_writefile_ifnotequal.c b/src/host/os_writefile_ifnotequal.c index dc50938461..9d4dcbb76f 100644 --- a/src/host/os_writefile_ifnotequal.c +++ b/src/host/os_writefile_ifnotequal.c @@ -21,8 +21,9 @@ static int compare_file(const char* content, size_t length, const char* dst) { FILE* file = fopen(dst, "rb"); size_t size; + size_t read; char buffer[4096]; - int num; + size_t num; if (file == NULL) { @@ -44,7 +45,12 @@ static int compare_file(const char* content, size_t length, const char* dst) { num = size > 4096 ? 4096 : size; - fread(buffer, 1, num, file); + read = fread(buffer, 1, num, file); + if (read != num) + { + fclose (file); + return FALSE; + } if (memcmp(content, buffer, num) != 0) { diff --git a/src/host/path_wildcards.c b/src/host/path_wildcards.c new file mode 100644 index 0000000000..e6fa77e76f --- /dev/null +++ b/src/host/path_wildcards.c @@ -0,0 +1,81 @@ +/** + * \file path_wildcards.c + * \brief Converts from a simple wildcard syntax to the corresponding Lua pattern. + * \author Copyright (c) 2015 Tom van Dijck, Jason Perkins and the Premake project + */ + +#include "premake.h" +#include +#include + +/* +--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. +*/ +int path_wildcards(lua_State* L) +{ + size_t length, i; + const char* input; + char buffer[0x4000]; + char* output; + + input = luaL_checklstring(L, 1, &length); + output = buffer; + + for (i = 0; i < length; ++i) + { + char c = input[i]; + switch (c) + { + case '+': + case '.': + case '-': + case '^': + case '$': + case '(': + case ')': + case '%': + *(output++) = '%'; + *(output++) = c; + break; + + case '*': + if ((i + 1) < length && input[i + 1] == '*') + { + i++; // skip the next character. + *(output++) = '.'; + *(output++) = '*'; + } + else + { + *(output++) = '['; + *(output++) = '^'; + *(output++) = '/'; + *(output++) = ']'; + *(output++) = '*'; + } + break; + + default: + *(output++) = c; + break; + } + + if (output >= buffer + sizeof(buffer)) + { + lua_pushstring(L, "Wildcards expansion too big."); + lua_error(L); + return 0; + } + } + + *(output++) = '\0'; + + lua_pushstring(L, buffer); + return 1; +} diff --git a/src/host/premake.c b/src/host/premake.c index 9d6fbe1d1f..384c18dcf9 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -14,7 +14,7 @@ #endif -#define VERSION "5.0.0-alpha6" +#define VERSION "5.0.0-alpha7" #define COPYRIGHT "Copyright (C) 2002-2015 Jason Perkins and the Premake Project" #define PROJECT_URL "https://github.com/premake/premake-core/wiki" #define ERROR_MESSAGE "Error: %s\n" @@ -49,6 +49,7 @@ static const luaL_Reg path_functions[] = { { "join", path_join }, { "normalize", path_normalize }, { "translate", path_translate }, + { "wildcards", path_wildcards }, { NULL, NULL } }; @@ -75,6 +76,7 @@ static const luaL_Reg os_functions[] = { { "stat", os_stat }, { "uuid", os_uuid }, { "writefile_ifnotequal", os_writefile_ifnotequal }, + { "compile", os_compile }, { NULL, NULL } }; @@ -305,8 +307,6 @@ int premake_locate_executable(lua_State* L, const char* argv0) */ int premake_test_file(lua_State* L, const char* filename, int searchMask) { - int i; - if (searchMask & TEST_LOCAL) { if (do_isfile(filename)) { lua_pushcfunction(L, path_getabsolute); @@ -328,13 +328,11 @@ int premake_test_file(lua_State* L, const char* filename, int searchMask) #if !defined(PREMAKE_NO_BUILTIN_SCRIPTS) if ((searchMask & TEST_EMBEDDED) != 0) { /* Try to locate a record matching the filename */ - for (i = 0; builtin_scripts_index[i] != NULL; ++i) { - if (strcmp(builtin_scripts_index[i], filename) == 0) { - lua_pushstring(L, "$/"); - lua_pushstring(L, filename); - lua_concat(L, 2); - return OKAY; - } + if (premake_find_embedded_script(filename) != NULL) { + lua_pushstring(L, "$/"); + lua_pushstring(L, filename); + lua_concat(L, 2); + return OKAY; } } #endif @@ -498,13 +496,13 @@ static int run_premake_main(lua_State* L, const char* script) * contents of the file's script. */ - const char* premake_find_embedded_script(const char* filename) + const buildin_mapping* premake_find_embedded_script(const char* filename) { #if !defined(PREMAKE_NO_BUILTIN_SCRIPTS) int i; - for (i = 0; builtin_scripts_index[i] != NULL; ++i) { - if (strcmp(builtin_scripts_index[i], filename) == 0) { - return builtin_scripts[i]; + for (i = 0; builtin_scripts[i].name != NULL; ++i) { + if (strcmp(builtin_scripts[i].name, filename) == 0) { + return builtin_scripts + i; } } #endif @@ -526,7 +524,7 @@ int premake_load_embedded_script(lua_State* L, const char* filename) static int warned = 0; #endif - const char* chunk = premake_find_embedded_script(filename); + const buildin_mapping* chunk = premake_find_embedded_script(filename); if (chunk == NULL) { return !OKAY; } @@ -545,5 +543,5 @@ int premake_load_embedded_script(lua_State* L, const char* filename) lua_concat(L, 2); /* Load the chunk */ - return luaL_loadbuffer(L, chunk, strlen(chunk), filename); + return luaL_loadbuffer(L, (const char*)chunk->bytecode, chunk->length, filename); } diff --git a/src/host/premake.h b/src/host/premake.h index edbd960070..8f3bee55dc 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -9,7 +9,6 @@ #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__) @@ -95,6 +94,7 @@ int path_isabsolute(lua_State* L); int path_join(lua_State* L); int path_normalize(lua_State* L); int path_translate(lua_State* L); +int path_wildcards(lua_State* L); int os_chdir(lua_State* L); int os_chmod(lua_State* L); int os_copyfile(lua_State* L); @@ -117,6 +117,7 @@ int os_rmdir(lua_State* L); int os_stat(lua_State* L); int os_uuid(lua_State* L); int os_writefile_ifnotequal(lua_State* L); +int os_compile(lua_State* L); int string_endswith(lua_State* L); int string_hash(lua_State* L); int string_sha1(lua_State* L); @@ -137,13 +138,21 @@ int zip_extract(lua_State* L); #endif /* Engine interface */ + +typedef struct +{ + const char* name; + const unsigned char* bytecode; + size_t length; +} buildin_mapping; + +extern const buildin_mapping builtin_scripts[]; + + int premake_init(lua_State* L); int premake_execute(lua_State* L, int argc, const char** argv, const char* script); -const char* premake_find_embedded_script(const char* filename); int premake_load_embedded_script(lua_State* L, const char* filename); +const buildin_mapping* premake_find_embedded_script(const char* filename); + int premake_locate_executable(lua_State* L, const char* argv0); int premake_test_file(lua_State* L, const char* filename, int searchMask); - - -extern const char* builtin_scripts_index[]; -extern const char* builtin_scripts[]; diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 0f05d2b4ef..c1263231c7 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -248,18 +248,10 @@ local flags = config.mapFlags(cfg, gcc.libraryDirectories) -- Scan the list of linked libraries. If any are referenced with - -- paths, add those to the list of library search paths - local done = {} - for _, link in ipairs(config.getlinks(cfg, "system", "fullpath")) do - local dir = path.getdirectory(link) - if #dir > 1 and not done[dir] then - done[dir] = true - if path.isframework(link) then - table.insert(flags, '-F' .. premake.quoted(dir)) - else - table.insert(flags, '-L' .. premake.quoted(dir)) - end - end + -- paths, add those to the list of library search paths. The call + -- config.getlinks() all includes cfg.libdirs. + for _, dir in ipairs(config.getlinks(cfg, "system", "directory")) do + table.insert(flags, '-L' .. premake.quoted(dir)) end if cfg.flags.RelativeLinks then @@ -304,11 +296,6 @@ end end - if #result > 1 then - table.insert(result, 1, "-Wl,--start-group") - table.insert(result, "-Wl,--end-group") - end - -- The "-l" flag is fine for system libraries local links = config.getlinks(cfg, "system", "fullpath") diff --git a/tests/_tests.lua b/tests/_tests.lua index bb3ae6a5b2..c315a5ebc9 100644 --- a/tests/_tests.lua +++ b/tests/_tests.lua @@ -147,6 +147,7 @@ return { "actions/make/cpp/test_clang.lua", "actions/make/cpp/test_file_rules.lua", "actions/make/cpp/test_flags.lua", + "actions/make/cpp/test_ldflags.lua", "actions/make/cpp/test_make_pch.lua", "actions/make/cpp/test_make_linking.lua", "actions/make/cpp/test_objects.lua", diff --git a/tests/actions/make/cpp/test_flags.lua b/tests/actions/make/cpp/test_flags.lua index f8aa11a3e2..6d16d7db48 100644 --- a/tests/actions/make/cpp/test_flags.lua +++ b/tests/actions/make/cpp/test_flags.lua @@ -1,7 +1,7 @@ -- -- tests/actions/make/cpp/test_flags.lua -- Tests compiler and linker flags for Makefiles. --- Copyright (c) 2012-2013 Jason Perkins and the Premake project +-- Copyright (c) 2012-2015 Jason Perkins and the Premake project -- local suite = test.declare("make_flags") diff --git a/tests/actions/make/cpp/test_ldflags.lua b/tests/actions/make/cpp/test_ldflags.lua new file mode 100644 index 0000000000..2bccd28442 --- /dev/null +++ b/tests/actions/make/cpp/test_ldflags.lua @@ -0,0 +1,50 @@ +-- +-- tests/actions/make/cpp/test_ldflags.lua +-- Tests compiler and linker flags for Makefiles. +-- Copyright (c) 2012-2015 Jason Perkins and the Premake project +-- + + local suite = test.declare("make_ldflags") + local make = premake.make + + +-- +-- Setup +-- + + local wks, prj + + function suite.setup() + wks, prj = test.createWorkspace() + flags("Symbols") + end + + local function prepare(calls) + local cfg = test.getconfig(prj, "Debug") + local toolset = premake.tools.gcc + make.ldFlags(cfg, toolset) + end + + +-- +-- Check the output from default project values. +-- + + function suite.checkDefaultValues() + prepare() + test.capture [[ + ALL_LDFLAGS += $(LDFLAGS) + ]] + end + +-- +-- Check addition of library search directores. +-- + + function suite.checkLibDirs() + libdirs { "../libs", "libs" } + prepare() + test.capture [[ + ALL_LDFLAGS += $(LDFLAGS) -L../libs -Llibs + ]] + end diff --git a/tests/actions/make/cpp/test_make_linking.lua b/tests/actions/make/cpp/test_make_linking.lua index 3bdb1f16d7..0e17476aa0 100644 --- a/tests/actions/make/cpp/test_make_linking.lua +++ b/tests/actions/make/cpp/test_make_linking.lua @@ -70,6 +70,21 @@ end +-- +-- Check link command for the Utility kind. +-- +-- Utility projects should only run custom commands, and perform no linking. +-- + + function suite.links_onUtility() + kind "Utility" + prepare { "linkCmd" } + test.capture [[ + LINKCMD = + ]] + end + + -- -- Check link command for a Mac OS X universal static library. -- @@ -163,7 +178,7 @@ prepare { "ldFlags", "libs", "ldDeps" } test.capture [[ ALL_LDFLAGS += $(LDFLAGS) -s - LIBS += -Wl,--start-group build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a -Wl,--end-group + LIBS += build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a LDDEPS += build/bin/Debug/libMyProject2.a build/bin/Debug/libMyProject3.a ]] end diff --git a/tests/actions/make/cs/test_response.lua b/tests/actions/make/cs/test_response.lua index 58cd2becab..4f91cbf464 100644 --- a/tests/actions/make/cs/test_response.lua +++ b/tests/actions/make/cs/test_response.lua @@ -6,7 +6,6 @@ local suite = test.declare("make_cs_response") local make = premake.make - local project = premake.project -- @@ -49,9 +48,31 @@ $(TARGET): $(SOURCES) $(EMBEDFILES) $(DEPENDS) $(RESPONSE) end function suite.listResponseRules() - files { "foo.cs", "bar.cs" } + files { "foo.cs", "bar.cs", "dir/foo.cs" } prepare() make.csResponseRules(prj) + end + + function suite.listResponseRulesPosix() + _OS = "linux" + suite.listResponseRules() + test.capture [[ +$(RESPONSE): MyProject.make + @echo Generating response file +ifeq (posix,$(SHELLTYPE)) + $(SILENT) rm -f $(RESPONSE) +else + $(SILENT) if exist $(RESPONSE) del $(OBJDIR)\MyProject.rsp +endif + @echo bar.cs >> $(RESPONSE) + @echo dir/foo.cs >> $(RESPONSE) + @echo foo.cs >> $(RESPONSE) + ]] + end + + function suite.listResponseRulesWindows() + _OS = "windows" + suite.listResponseRules() test.capture [[ $(RESPONSE): MyProject.make @echo Generating response file @@ -61,6 +82,7 @@ else $(SILENT) if exist $(RESPONSE) del $(OBJDIR)\MyProject.rsp endif @echo bar.cs >> $(RESPONSE) + @echo dir\foo.cs >> $(RESPONSE) @echo foo.cs >> $(RESPONSE) ]] end diff --git a/tests/actions/vstudio/cs2005/projectsettings.lua b/tests/actions/vstudio/cs2005/projectsettings.lua index 6cb833dc77..e1bd851398 100755 --- a/tests/actions/vstudio/cs2005/projectsettings.lua +++ b/tests/actions/vstudio/cs2005/projectsettings.lua @@ -135,6 +135,26 @@ end + function suite.OnDotNetFrameworkVersion() + dotnetframework "3.0" + prepare() + test.capture [[ + + Debug + AnyCPU + 8.0.50727 + 2.0 + {AE61726D-187C-E440-BD07-2556188A6565} + Exe + Properties + MyProject + MyProject + v3.0 + + ]] + end + + -- -- Make sure the root namespace can be overridden. -- diff --git a/tests/actions/vstudio/vc2010/test_globals.lua b/tests/actions/vstudio/vc2010/test_globals.lua index 2aa3bdb2d4..127ce92b89 100755 --- a/tests/actions/vstudio/vc2010/test_globals.lua +++ b/tests/actions/vstudio/vc2010/test_globals.lua @@ -65,7 +65,7 @@ function suite.frameworkVersionIsCorrect_onSpecificVersion() clr "On" - framework "4.5" + dotnetframework "4.5" prepare() test.capture [[