From 5952d054e5fa5dc8535d604eaf591c09ccf4184a Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 10 Sep 2015 02:58:52 +0100 Subject: [PATCH 01/42] Rename "framework" to "dotnetframework". "framework" is a very generic term and hard to tell what it's actually about. Keeps "framework" around for backwards compatibility. --- src/_premake_init.lua | 3 ++- src/actions/vstudio/vs2005_csproj.lua | 2 +- src/actions/vstudio/vs2010_vcxproj.lua | 2 +- .../vstudio/cs2005/projectsettings.lua | 20 +++++++++++++++++++ tests/actions/vstudio/vc2010/test_globals.lua | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/_premake_init.lua b/src/_premake_init.lua index e19908298d..f3d6e8d9e4 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", } @@ -1073,6 +1073,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/actions/vstudio/vs2005_csproj.lua b/src/actions/vstudio/vs2005_csproj.lua index 53dae3035b..8ffdb6e501 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/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index bb0330a44f..ce8453fc30 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 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 [[ From 8b4e02605790ecbe9bb1bc935a21e0817de8383b Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 10 Sep 2015 03:01:53 +0100 Subject: [PATCH 02/42] Fixed HTTP only compilation define to actually work. --- contrib/curl/premake5.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/curl/premake5.lua b/contrib/curl/premake5.lua index da18bafb3d..55d5f4435f 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" From 53040c798922267235008e77b1f2f0a798e623fe Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 10 Sep 2015 03:03:24 +0100 Subject: [PATCH 03/42] Enable SSL on HTTP libcurl for Windows. --- contrib/curl/premake5.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/curl/premake5.lua b/contrib/curl/premake5.lua index 55d5f4435f..1e56fed94b 100644 --- a/contrib/curl/premake5.lua +++ b/contrib/curl/premake5.lua @@ -14,6 +14,7 @@ project "curl-lib" configuration { 'windows' } defines {"WIN32"} + defines {"USE_SSL", "USE_SCHANNEL", "USE_WINDOWS_SSPI"} configuration { 'linux' } defines {"HAVE_CONFIG_H", "CURL_HIDDEN_SYMBOLS"} From cc6cf72d6039604ba33fdddf2a410db34756e633 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Thu, 10 Sep 2015 10:13:30 -0700 Subject: [PATCH 04/42] Fix bug in recursive calls to detoken. --- src/base/detoken.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 From cf9b366ee79923cc3a190deffea137ac796e9d03 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Thu, 17 Sep 2015 09:09:41 -0700 Subject: [PATCH 05/42] path.wildcards -> C --- src/base/path.lua | 27 ------------- src/host/path_wildcards.c | 81 +++++++++++++++++++++++++++++++++++++++ src/host/premake.c | 1 + src/host/premake.h | 1 + 4 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 src/host/path_wildcards.c diff --git a/src/base/path.lua b/src/base/path.lua index 9edad7645a..c97add5c83 100644 --- a/src/base/path.lua +++ b/src/base/path.lua @@ -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/host/path_wildcards.c b/src/host/path_wildcards.c new file mode 100644 index 0000000000..c9c64c3fdf --- /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 96a9c7a59c..9ec388e406 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -49,6 +49,7 @@ static const luaL_Reg path_functions[] = { { "join", path_join }, { "normalize", path_normalize }, { "translate", path_translate }, + { "wildcards", path_wildcards }, { NULL, NULL } }; diff --git a/src/host/premake.h b/src/host/premake.h index edbd960070..8b48f021b3 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -95,6 +95,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); From 77efd0bab3517efe3b9a28561aad2a58cd1452fa Mon Sep 17 00:00:00 2001 From: Sami Kankaristo Date: Thu, 1 Oct 2015 05:34:46 +0300 Subject: [PATCH 06/42] Add basic support for the 'Utility' kind in gmake --- src/actions/make/_make.lua | 2 +- src/actions/make/make_cpp.lua | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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..8549239c31 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -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 From c71562f07223b883f6979f16f3b7c498edd0845b Mon Sep 17 00:00:00 2001 From: Sami Kankaristo Date: Sat, 3 Oct 2015 12:06:39 +0300 Subject: [PATCH 07/42] Add test for gmake Utility projects --- tests/actions/make/cpp/test_make_linking.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/actions/make/cpp/test_make_linking.lua b/tests/actions/make/cpp/test_make_linking.lua index 3bdb1f16d7..d8485b6aca 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. -- From 8467be1612f4e7303aba13eb794790405a39ff40 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Fri, 27 Mar 2015 10:51:24 -0700 Subject: [PATCH 08/42] fix bug in appendExtension. --- src/base/path.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/path.lua b/src/base/path.lua index 9edad7645a..713c13af69 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 From 5c3504c7a71ea108d201432ace2039d43a2fc925 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Fri, 31 Jul 2015 16:28:09 -0700 Subject: [PATCH 09/42] add workspace.getrelative(sln, filename) --- src/base/workspace.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 From 811ac304d473632b266ff98719117b5be90c55f2 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 5 Oct 2015 09:21:26 -0700 Subject: [PATCH 10/42] fix m.additionalUsingDirectories --- src/actions/vstudio/vs2010_vcxproj.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 8db620ef8b..25de5ce31d 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -942,8 +942,10 @@ 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 From 0c21e590570530b7fe0eacc63ac2b89c901550af Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 14 Sep 2015 16:40:27 -0700 Subject: [PATCH 11/42] context.mergeFilters doesn't need to do a deepcopy, because table.merge already copies everything. --- src/base/context.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 From 6c6b035251e2c120698f21a3cde69bbb2c87d373 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Wed, 23 Sep 2015 12:31:38 -0700 Subject: [PATCH 12/42] fix some warnings. --- src/host/http.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/host/http.c b/src/host/http.c index 28c1b63943..d88a65b2dc 100644 --- a/src/host/http.c +++ b/src/host/http.c @@ -6,6 +6,7 @@ #include "premake.h" #include +#include #ifdef PREMAKE_CURL @@ -170,7 +171,7 @@ static CURL* curl_request(lua_State* L, CurlCallbackState* state, FILE* fp, int int http_get(lua_State* L) { - CurlCallbackState state = { 0, 0 }; + CurlCallbackState state = { 0, 0, {NULL, 0} }; CURL* curl = curl_request(L, &state, /*fp=*/NULL, /*progressFnIndex=*/2); CURLcode code; @@ -204,7 +205,7 @@ int http_get(lua_State* L) int http_download(lua_State* L) { - CurlCallbackState state = { 0, 0 }; + CurlCallbackState state = { 0, 0, {NULL, 0} }; CURL* curl; CURLcode code = CURLE_FAILED_INIT; From 333b8d8856d2bd74ce501ab3c472b4e5e483666d Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Wed, 23 Sep 2015 15:36:35 -0700 Subject: [PATCH 13/42] better error handling in curl --- src/host/http.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/host/http.c b/src/host/http.c index d88a65b2dc..dc3fe72764 100644 --- a/src/host/http.c +++ b/src/host/http.c @@ -12,6 +12,9 @@ #include +#define _MPRINTF_REPLACE /* use curl functions only */ +#include + typedef struct { char* ptr; size_t len; @@ -29,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, @@ -145,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); @@ -165,6 +171,9 @@ 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; } @@ -176,8 +185,6 @@ int http_get(lua_State* L) CURL* curl = curl_request(L, &state, /*fp=*/NULL, /*progressFnIndex=*/2); CURLcode code; - const char* err; - string_init(&state.S); if (!curl) @@ -189,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; } @@ -230,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; } From 52ecf9e91cc31a711fabd299870ae253d0f0231e Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Fri, 27 Mar 2015 05:47:23 -0700 Subject: [PATCH 14/42] add time information. --- src/_premake_main.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From 91c98e615b40bd51c04ede5172d785b3be78ea4d Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 5 Oct 2015 10:11:15 -0700 Subject: [PATCH 15/42] Move Lua into folder without version, so it's easier to update to a newer version. --- Bootstrap.mak | 18 +- premake4.lua | 14 +- premake5.lua | 14 +- src/host/debug_prompt.c | 2 +- src/host/lua-5.1.4/Makefile | 128 -- src/host/lua-5.1.4/etc/Makefile | 44 - src/host/lua-5.1.4/src/Makefile | 182 --- src/host/{lua-5.1.4 => lua}/COPYRIGHT | 0 src/host/{lua-5.1.4 => lua}/HISTORY | 0 src/host/{lua-5.1.4 => lua}/INSTALL | 0 src/host/{lua-5.1.4 => lua}/README | 0 src/host/{lua-5.1.4 => lua}/doc/amazon.gif | Bin src/host/{lua-5.1.4 => lua}/doc/contents.html | 0 src/host/{lua-5.1.4 => lua}/doc/cover.png | Bin src/host/{lua-5.1.4 => lua}/doc/logo.gif | Bin src/host/{lua-5.1.4 => lua}/doc/lua.1 | 0 src/host/{lua-5.1.4 => lua}/doc/lua.css | 0 src/host/{lua-5.1.4 => lua}/doc/lua.html | 0 src/host/{lua-5.1.4 => lua}/doc/luac.1 | 0 src/host/{lua-5.1.4 => lua}/doc/luac.html | 0 src/host/{lua-5.1.4 => lua}/doc/manual.css | 0 src/host/{lua-5.1.4 => lua}/doc/manual.html | 0 src/host/{lua-5.1.4 => lua}/doc/readme.html | 0 src/host/{lua-5.1.4 => lua}/etc/README | 0 src/host/{lua-5.1.4 => lua}/etc/all.c | 0 src/host/{lua-5.1.4 => lua}/etc/lua.hpp | 0 src/host/{lua-5.1.4 => lua}/etc/lua.ico | Bin src/host/{lua-5.1.4 => lua}/etc/lua.pc | 0 src/host/{lua-5.1.4 => lua}/etc/luavs.bat | 56 +- src/host/{lua-5.1.4 => lua}/etc/min.c | 0 src/host/{lua-5.1.4 => lua}/etc/noparser.c | 0 src/host/{lua-5.1.4 => lua}/etc/strict.lua | 0 src/host/{lua-5.1.4 => lua}/src/lapi.c | 0 src/host/{lua-5.1.4 => lua}/src/lapi.h | 0 src/host/{lua-5.1.4 => lua}/src/lauxlib.c | 1316 ++++++++--------- src/host/{lua-5.1.4 => lua}/src/lauxlib.h | 0 src/host/{lua-5.1.4 => lua}/src/lbaselib.c | 0 src/host/{lua-5.1.4 => lua}/src/lcode.c | 0 src/host/{lua-5.1.4 => lua}/src/lcode.h | 0 src/host/{lua-5.1.4 => lua}/src/ldblib.c | 0 src/host/{lua-5.1.4 => lua}/src/ldebug.c | 0 src/host/{lua-5.1.4 => lua}/src/ldebug.h | 0 src/host/{lua-5.1.4 => lua}/src/ldo.c | 0 src/host/{lua-5.1.4 => lua}/src/ldo.h | 0 src/host/{lua-5.1.4 => lua}/src/ldump.c | 0 src/host/{lua-5.1.4 => lua}/src/lfunc.c | 0 src/host/{lua-5.1.4 => lua}/src/lfunc.h | 0 src/host/{lua-5.1.4 => lua}/src/lgc.c | 0 src/host/{lua-5.1.4 => lua}/src/lgc.h | 0 src/host/{lua-5.1.4 => lua}/src/linit.c | 0 src/host/{lua-5.1.4 => lua}/src/liolib.c | 0 src/host/{lua-5.1.4 => lua}/src/llex.c | 0 src/host/{lua-5.1.4 => lua}/src/llex.h | 0 src/host/{lua-5.1.4 => lua}/src/llimits.h | 0 src/host/{lua-5.1.4 => lua}/src/lmathlib.c | 0 src/host/{lua-5.1.4 => lua}/src/lmem.c | 0 src/host/{lua-5.1.4 => lua}/src/lmem.h | 0 src/host/{lua-5.1.4 => lua}/src/loadlib.c | 0 src/host/{lua-5.1.4 => lua}/src/lobject.c | 0 src/host/{lua-5.1.4 => lua}/src/lobject.h | 0 src/host/{lua-5.1.4 => lua}/src/lopcodes.c | 0 src/host/{lua-5.1.4 => lua}/src/lopcodes.h | 0 src/host/{lua-5.1.4 => lua}/src/loslib.c | 0 src/host/{lua-5.1.4 => lua}/src/lparser.c | 0 src/host/{lua-5.1.4 => lua}/src/lparser.h | 0 src/host/{lua-5.1.4 => lua}/src/lstate.c | 0 src/host/{lua-5.1.4 => lua}/src/lstate.h | 0 src/host/{lua-5.1.4 => lua}/src/lstring.c | 0 src/host/{lua-5.1.4 => lua}/src/lstring.h | 0 src/host/{lua-5.1.4 => lua}/src/lstrlib.c | 0 src/host/{lua-5.1.4 => lua}/src/ltable.c | 0 src/host/{lua-5.1.4 => lua}/src/ltable.h | 0 src/host/{lua-5.1.4 => lua}/src/ltablib.c | 0 src/host/{lua-5.1.4 => lua}/src/ltm.c | 0 src/host/{lua-5.1.4 => lua}/src/ltm.h | 0 src/host/{lua-5.1.4 => lua}/src/lua.c | 0 src/host/{lua-5.1.4 => lua}/src/lua.h | 0 src/host/{lua-5.1.4 => lua}/src/luac.c | 0 src/host/{lua-5.1.4 => lua}/src/luaconf.h | 0 src/host/{lua-5.1.4 => lua}/src/lualib.h | 0 src/host/{lua-5.1.4 => lua}/src/lundump.c | 0 src/host/{lua-5.1.4 => lua}/src/lundump.h | 0 src/host/{lua-5.1.4 => lua}/src/lvm.c | 0 src/host/{lua-5.1.4 => lua}/src/lvm.h | 0 src/host/{lua-5.1.4 => lua}/src/lzio.c | 0 src/host/{lua-5.1.4 => lua}/src/lzio.h | 0 src/host/{lua-5.1.4 => lua}/src/print.c | 0 src/host/{lua-5.1.4 => lua}/test/README | 0 src/host/{lua-5.1.4 => lua}/test/bisect.lua | 0 src/host/{lua-5.1.4 => lua}/test/cf.lua | 0 src/host/{lua-5.1.4 => lua}/test/echo.lua | 0 src/host/{lua-5.1.4 => lua}/test/env.lua | 0 .../{lua-5.1.4 => lua}/test/factorial.lua | 0 src/host/{lua-5.1.4 => lua}/test/fib.lua | 0 src/host/{lua-5.1.4 => lua}/test/fibfor.lua | 0 src/host/{lua-5.1.4 => lua}/test/globals.lua | 0 src/host/{lua-5.1.4 => lua}/test/hello.lua | 0 src/host/{lua-5.1.4 => lua}/test/life.lua | 0 src/host/{lua-5.1.4 => lua}/test/luac.lua | 0 src/host/{lua-5.1.4 => lua}/test/printf.lua | 0 src/host/{lua-5.1.4 => lua}/test/readonly.lua | 0 src/host/{lua-5.1.4 => lua}/test/sieve.lua | 0 src/host/{lua-5.1.4 => lua}/test/sort.lua | 0 src/host/{lua-5.1.4 => lua}/test/table.lua | 0 .../{lua-5.1.4 => lua}/test/trace-calls.lua | 0 .../{lua-5.1.4 => lua}/test/trace-globals.lua | 0 src/host/{lua-5.1.4 => lua}/test/xd.lua | 0 src/host/lua_auxlib.c | 2 +- 108 files changed, 711 insertions(+), 1065 deletions(-) delete mode 100644 src/host/lua-5.1.4/Makefile delete mode 100644 src/host/lua-5.1.4/etc/Makefile delete mode 100644 src/host/lua-5.1.4/src/Makefile rename src/host/{lua-5.1.4 => lua}/COPYRIGHT (100%) rename src/host/{lua-5.1.4 => lua}/HISTORY (100%) rename src/host/{lua-5.1.4 => lua}/INSTALL (100%) rename src/host/{lua-5.1.4 => lua}/README (100%) rename src/host/{lua-5.1.4 => lua}/doc/amazon.gif (100%) rename src/host/{lua-5.1.4 => lua}/doc/contents.html (100%) rename src/host/{lua-5.1.4 => lua}/doc/cover.png (100%) rename src/host/{lua-5.1.4 => lua}/doc/logo.gif (100%) rename src/host/{lua-5.1.4 => lua}/doc/lua.1 (100%) rename src/host/{lua-5.1.4 => lua}/doc/lua.css (100%) rename src/host/{lua-5.1.4 => lua}/doc/lua.html (100%) rename src/host/{lua-5.1.4 => lua}/doc/luac.1 (100%) rename src/host/{lua-5.1.4 => lua}/doc/luac.html (100%) rename src/host/{lua-5.1.4 => lua}/doc/manual.css (100%) rename src/host/{lua-5.1.4 => lua}/doc/manual.html (100%) rename src/host/{lua-5.1.4 => lua}/doc/readme.html (100%) rename src/host/{lua-5.1.4 => lua}/etc/README (100%) rename src/host/{lua-5.1.4 => lua}/etc/all.c (100%) rename src/host/{lua-5.1.4 => lua}/etc/lua.hpp (100%) rename src/host/{lua-5.1.4 => lua}/etc/lua.ico (100%) rename src/host/{lua-5.1.4 => lua}/etc/lua.pc (100%) rename src/host/{lua-5.1.4 => lua}/etc/luavs.bat (97%) rename src/host/{lua-5.1.4 => lua}/etc/min.c (100%) rename src/host/{lua-5.1.4 => lua}/etc/noparser.c (100%) rename src/host/{lua-5.1.4 => lua}/etc/strict.lua (100%) rename src/host/{lua-5.1.4 => lua}/src/lapi.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lapi.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lauxlib.c (96%) rename src/host/{lua-5.1.4 => lua}/src/lauxlib.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lbaselib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lcode.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lcode.h (100%) rename src/host/{lua-5.1.4 => lua}/src/ldblib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ldebug.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ldebug.h (100%) rename src/host/{lua-5.1.4 => lua}/src/ldo.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ldo.h (100%) rename src/host/{lua-5.1.4 => lua}/src/ldump.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lfunc.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lfunc.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lgc.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lgc.h (100%) rename src/host/{lua-5.1.4 => lua}/src/linit.c (100%) rename src/host/{lua-5.1.4 => lua}/src/liolib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/llex.c (100%) rename src/host/{lua-5.1.4 => lua}/src/llex.h (100%) rename src/host/{lua-5.1.4 => lua}/src/llimits.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lmathlib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lmem.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lmem.h (100%) rename src/host/{lua-5.1.4 => lua}/src/loadlib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lobject.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lobject.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lopcodes.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lopcodes.h (100%) rename src/host/{lua-5.1.4 => lua}/src/loslib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lparser.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lparser.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lstate.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lstate.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lstring.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lstring.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lstrlib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ltable.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ltable.h (100%) rename src/host/{lua-5.1.4 => lua}/src/ltablib.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ltm.c (100%) rename src/host/{lua-5.1.4 => lua}/src/ltm.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lua.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lua.h (100%) rename src/host/{lua-5.1.4 => lua}/src/luac.c (100%) rename src/host/{lua-5.1.4 => lua}/src/luaconf.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lualib.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lundump.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lundump.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lvm.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lvm.h (100%) rename src/host/{lua-5.1.4 => lua}/src/lzio.c (100%) rename src/host/{lua-5.1.4 => lua}/src/lzio.h (100%) rename src/host/{lua-5.1.4 => lua}/src/print.c (100%) rename src/host/{lua-5.1.4 => lua}/test/README (100%) rename src/host/{lua-5.1.4 => lua}/test/bisect.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/cf.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/echo.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/env.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/factorial.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/fib.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/fibfor.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/globals.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/hello.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/life.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/luac.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/printf.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/readonly.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/sieve.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/sort.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/table.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/trace-calls.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/trace-globals.lua (100%) rename src/host/{lua-5.1.4 => lua}/test/xd.lua (100%) diff --git a/Bootstrap.mak b/Bootstrap.mak index 8aaff28d7c..92031b33fe 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 \ 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..b06fd51138 100644 --- a/premake5.lua +++ b/premake5.lua @@ -92,7 +92,7 @@ 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 +115,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/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/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 From a656792e4852119a941a8ffae808ada922dffcc0 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 5 Oct 2015 12:41:11 -0700 Subject: [PATCH 16/42] Embed precompiled lua files, instead of source. --- premake5.lua | 5 +- scripts/embed.lua | 204 +++++++++++++++++++++-------------------- src/host/buffered_io.c | 5 +- src/host/os_compile.c | 57 ++++++++++++ src/host/premake.c | 27 +++--- src/host/premake.h | 20 ++-- 6 files changed, 193 insertions(+), 125 deletions(-) create mode 100644 src/host/os_compile.c diff --git a/premake5.lua b/premake5.lua index b06fd51138..ad84b1520c 100644 --- a/premake5.lua +++ b/premake5.lua @@ -73,7 +73,10 @@ description = "Disable Zlib/Zip 3rd party lib" } - + newoption { + trigger = "bytecode", + description = "Embed bytecode instead of stripped souce code." + } -- -- Define the project. Put the release configuration first so it will be the diff --git a/scripts/embed.lua b/scripts/embed.lua index 7e79bf3c50..f2b0322a8f 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 _OPTIONS.bytecode then + print("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,69 @@ 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 = {} 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/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/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/premake.c b/src/host/premake.c index 88c74d2383..e5f2349860 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -76,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 } }; @@ -306,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); @@ -329,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 @@ -499,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 @@ -527,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; } @@ -546,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 8b48f021b3..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__) @@ -118,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); @@ -138,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[]; From 9e1cfc7697302a413a926f345fe47bb50cf494a3 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 5 Oct 2015 15:13:50 -0700 Subject: [PATCH 17/42] flip to default on for bytecode. --- premake5.lua | 4 ++-- scripts/embed.lua | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/premake5.lua b/premake5.lua index ad84b1520c..6622a10050 100644 --- a/premake5.lua +++ b/premake5.lua @@ -74,8 +74,8 @@ } newoption { - trigger = "bytecode", - description = "Embed bytecode instead of stripped souce code." + trigger = "no-bytecode", + description = "Don't embed bytecode, but instead use the stripped souce code." } -- diff --git a/scripts/embed.lua b/scripts/embed.lua index f2b0322a8f..7879678073 100644 --- a/scripts/embed.lua +++ b/scripts/embed.lua @@ -67,8 +67,8 @@ local function addScript(result, filename, name, data) if not data then - if _OPTIONS.bytecode then - print("Compiling... " .. filename) + 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 @@ -117,6 +117,7 @@ -- Generate table of embedded content. local contentTable = {} + print("Compiling... ") for mi = 1, #manifests do local manifestName = manifests[mi] local manifestDir = path.getdirectory(manifestName) From f624f8bbc88398d0b138e37ce9cedb30a14ea392 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 6 Oct 2015 17:22:11 -0700 Subject: [PATCH 18/42] Fix malloc-defining header for clang compilation on Mac. This fixes the use of a non-standard/platform-specific malloc.h by replacing it with the standard stdlib.h, which defines malloc. --- src/host/path_wildcards.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/path_wildcards.c b/src/host/path_wildcards.c index c9c64c3fdf..e6fa77e76f 100644 --- a/src/host/path_wildcards.c +++ b/src/host/path_wildcards.c @@ -6,7 +6,7 @@ #include "premake.h" #include -#include +#include /* --Converts from a simple wildcard syntax, where * is "match any" From 18fbcf01f29fbe199d9caf13bd9581718c500912 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Thu, 8 Oct 2015 02:12:24 +1000 Subject: [PATCH 19/42] Updated submodules to the latest versions. Fixes #298. --- modules/monodevelop | 2 +- modules/xcode | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monodevelop b/modules/monodevelop index 8dbde8b2c9..233a376789 160000 --- a/modules/monodevelop +++ b/modules/monodevelop @@ -1 +1 @@ -Subproject commit 8dbde8b2c93a63cafc08138b57f996ecae0a9d32 +Subproject commit 233a3767895f138365eb92d44938ff9865f16c63 diff --git a/modules/xcode b/modules/xcode index 6d959ab7cc..a5811c6e39 160000 --- a/modules/xcode +++ b/modules/xcode @@ -1 +1 @@ -Subproject commit 6d959ab7cc68c1ec5e937fbb8835f776030f57f5 +Subproject commit a5811c6e39e0c61f8f62536482a929f288f788e2 From fc228bfabf438cd21a8d64e5d5002600a592ecfd Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Wed, 7 Oct 2015 11:26:41 -0700 Subject: [PATCH 20/42] Mac OSX doesn't have lib64 dirs. --- src/base/os.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3e18d438f659b68a895ef648d419761d11329f64 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Wed, 7 Oct 2015 12:02:58 -0700 Subject: [PATCH 21/42] fix missing defines in bootstrap.mak --- Bootstrap.mak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bootstrap.mak b/Bootstrap.mak index 92031b33fe..fe942efdd4 100644 --- a/Bootstrap.mak +++ b/Bootstrap.mak @@ -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 ./build/bootstrap/premake_bootstrap embed ./build/bootstrap/premake_bootstrap --to=build/bootstrap gmake $(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` From 42434ad8a8a081cd6e7f6eab427938ec8d68249d Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Wed, 7 Oct 2015 12:10:53 -0700 Subject: [PATCH 22/42] missed linker settings. --- Bootstrap.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bootstrap.mak b/Bootstrap.mak index fe942efdd4..246a48082a 100644 --- a/Bootstrap.mak +++ b/Bootstrap.mak @@ -59,7 +59,7 @@ osx: $(SRC) linux: $(SRC) mkdir -p build/bootstrap - $(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -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` From 0a3ce657a80658af76a7d356b7b0be075ed1379f Mon Sep 17 00:00:00 2001 From: Mark Sararu Date: Sat, 10 Oct 2015 10:24:19 -0700 Subject: [PATCH 23/42] Fix include directories being escaped twice --- src/actions/make/make_cpp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index 8549239c31..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 From 5f1766956452b7df1fb1a7abbcc768a1e4e26c00 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Sun, 11 Oct 2015 10:10:15 -0400 Subject: [PATCH 24/42] Prep support files for merge to dev --- scripts/RELEASE.txt | 5 +---- src/host/premake.c | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/RELEASE.txt b/scripts/RELEASE.txt index 325c639327..08c6f04b40 100644 --- a/scripts/RELEASE.txt +++ b/scripts/RELEASE.txt @@ -19,7 +19,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 +29,6 @@ RELEASE * Post annoucement to @industrious on Twitter - * Add release to Freshmeat - http://freshmeat.net/projects/premake - CYCLE diff --git a/src/host/premake.c b/src/host/premake.c index 9d6fbe1d1f..2be283cd99 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-dev" #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" From ad56a58f799a8bddf6df6a9ce81d24170ceef919 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Wed, 14 Oct 2015 23:09:22 +1000 Subject: [PATCH 25/42] Fixed bug in `sln2005` that prevented p.override from working on the `sln2005.elements` functions. --- modules/monodevelop | 2 +- src/actions/vstudio/vs2005_solution.lua | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/monodevelop b/modules/monodevelop index 233a376789..218495031b 160000 --- a/modules/monodevelop +++ b/modules/monodevelop @@ -1 +1 @@ -Subproject commit 233a3767895f138365eb92d44938ff9865f16c63 +Subproject commit 218495031b9a39848083cc9b2860b3a1d2dc4183 diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 80ea83891d..215b5d881b 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -296,11 +296,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 +310,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 From 6c5c8c8180fd26b41175378a93f9f181b8c011fe Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 19 Oct 2015 13:08:50 -0700 Subject: [PATCH 26/42] Solution files need a '\n\r' after the utf8 marker. --- src/actions/vstudio/vs2005_solution.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 215b5d881b..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) From 1185a2fb46ded816abfd73725beef23edcdc25b0 Mon Sep 17 00:00:00 2001 From: Matthew Versluys Date: Sat, 24 Oct 2015 13:42:54 -0700 Subject: [PATCH 27/42] Fixes for Mac OSX --start-group and --end-group aren't available in the clang that ships with Xcode 7 Moved the build/link options for -mmacosx-version-min from the project to the solution so that the settings are applied to the contrib libraries. Eliminates link spam that the libraries were built with newer versions of the compiler. --- premake5.lua | 6 ++++-- src/tools/gcc.lua | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/premake5.lua b/premake5.lua index 6622a10050..4a7eb04a08 100644 --- a/premake5.lua +++ b/premake5.lua @@ -90,6 +90,10 @@ 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" @@ -161,8 +165,6 @@ configuration { "macosx", "gmake" } toolset "clang" - buildoptions { "-mmacosx-version-min=10.4" } - linkoptions { "-mmacosx-version-min=10.4" } configuration { "solaris" } linkoptions { "-Wl,--export-dynamic" } diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 0f05d2b4ef..55b8480ba4 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -304,9 +304,11 @@ end end - if #result > 1 then - table.insert(result, 1, "-Wl,--start-group") - table.insert(result, "-Wl,--end-group") + if cfg.system ~= premake.MACOSX then + if #result > 1 then + table.insert(result, 1, "-Wl,--start-group") + table.insert(result, "-Wl,--end-group") + end end -- The "-l" flag is fine for system libraries From 192aa8216b73f7a1248f5e407a0a9c4138d5c655 Mon Sep 17 00:00:00 2001 From: Matthew Versluys Date: Sat, 24 Oct 2015 13:53:04 -0700 Subject: [PATCH 28/42] SSL Support on Mac Utilizes Darwin SSL (rather than OpenSSL). The configuration file that was built appears to be for Linux. Had to remove the CURL_CA_BUNDLE for certificate lookup to work. --- contrib/curl/lib/curl_config.h | 2 +- contrib/curl/premake5.lua | 2 +- premake5.lua | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/contrib/curl/lib/curl_config.h b/contrib/curl/lib/curl_config.h index fe05c2b8a1..6c5818f49d 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" +/* #define CURL_CA_BUNDLE "/etc/pki/tls/certs/ca-bundle.crt" */ /* Location of default ca path */ /* #undef CURL_CA_PATH */ diff --git a/contrib/curl/premake5.lua b/contrib/curl/premake5.lua index 1e56fed94b..30946de9a3 100644 --- a/contrib/curl/premake5.lua +++ b/contrib/curl/premake5.lua @@ -20,7 +20,7 @@ project "curl-lib" defines {"HAVE_CONFIG_H", "CURL_HIDDEN_SYMBOLS"} configuration { 'macosx' } - defines { 'HAVE_CONFIG_H' } + defines { 'HAVE_CONFIG_H', 'USE_SSL', 'USE_DARWINSSL' } configuration "Release" defines {"NDEBUG"} diff --git a/premake5.lua b/premake5.lua index 4a7eb04a08..0bc85159f3 100644 --- a/premake5.lua +++ b/premake5.lua @@ -162,6 +162,9 @@ configuration "macosx" defines { "LUA_USE_MACOSX" } links { "CoreServices.framework" } + if not _OPTIONS["no-curl"] then + links { "Security.framework" } + end configuration { "macosx", "gmake" } toolset "clang" From 1175f0df2539777b871cb14605d4eda13b1223a4 Mon Sep 17 00:00:00 2001 From: Matthew Versluys Date: Mon, 26 Oct 2015 08:46:26 -0700 Subject: [PATCH 29/42] SSL support for Linux using OpenSSL CURL_CA_BUNDLE is deteceted during premake. Feels like the header that was generated by configure should be removed and move all curl build options into premake. --- contrib/curl/lib/curl_config.h | 2 +- contrib/curl/premake5.lua | 23 ++++++++++++++++++++++- premake5.lua | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/contrib/curl/lib/curl_config.h b/contrib/curl/lib/curl_config.h index 6c5818f49d..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 30946de9a3..be00a757e8 100644 --- a/contrib/curl/premake5.lua +++ b/contrib/curl/premake5.lua @@ -17,7 +17,28 @@ project "curl-lib" 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', 'USE_SSL', 'USE_DARWINSSL' } diff --git a/premake5.lua b/premake5.lua index 0bc85159f3..a1f08f24f1 100644 --- a/premake5.lua +++ b/premake5.lua @@ -159,6 +159,11 @@ 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" } @@ -176,6 +181,7 @@ defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" } links { "m" } + -- optional 3rd party libraries group "contrib" if not _OPTIONS["no-zlib"] then From 04840ec2f04cb7afe36e8e51eb659a1aac69faee Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 26 Oct 2015 15:59:07 -0400 Subject: [PATCH 30/42] Revert "improve determinism" This reverts commit 66358a2880730ee349761270f65d55080e43b095. --- src/actions/vstudio/vs2010_vcxproj.lua | 5 ----- src/base/container.lua | 6 ------ 2 files changed, 11 deletions(-) diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 2395235921..cf9d1fc4d2 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -879,11 +879,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)) 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 From 7f4bd53f70988b46285e7d49e62382e6fded13a4 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 26 Oct 2015 17:03:22 -0400 Subject: [PATCH 31/42] Rollback PR #247 - support framework folders in gcc/clang Rolled back the change and added a unit test to make sure we catch this in future --- src/tools/gcc.lua | 16 ++------ tests/_tests.lua | 1 + tests/actions/make/cpp/test_flags.lua | 2 +- tests/actions/make/cpp/test_ldflags.lua | 50 +++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 tests/actions/make/cpp/test_ldflags.lua diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 55b8480ba4..b234010827 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 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 From c01a411d8dab442af930076cbb1f676c88cabff4 Mon Sep 17 00:00:00 2001 From: Renaud Guillard Date: Sat, 15 Aug 2015 17:07:47 +0200 Subject: [PATCH 32/42] ignore eclipse project files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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 From 68b714ad6fcf41a5e741a495ecc6f13cfc2e7782 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Tue, 3 Nov 2015 10:11:56 -0800 Subject: [PATCH 33/42] add "LargeAddressAware" api. --- src/_premake_init.lua | 5 +++++ src/actions/vstudio/vs2010_vcxproj.lua | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/_premake_init.lua b/src/_premake_init.lua index f3d6e8d9e4..1819df9205 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -1060,6 +1060,11 @@ } } + api.register { + name = "largeaddressaware", + scope = "config", + kind = "boolean", + } ----------------------------------------------------------------------------- -- diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index cf9d1fc4d2..a353f51474 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -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 { @@ -945,6 +946,13 @@ end + function m.largeAddressAware(cfg) + if (cfg.largeaddressaware == true) then + m.element("LargeAddressAware", nil, 'true') + end + end + + function m.additionalCompileOptions(cfg, condition) if #cfg.buildoptions > 0 then local opts = table.concat(cfg.buildoptions, " ") From d38f9a92921fedd5fa7ee1ca1b1891809be6e2cf Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Tue, 3 Nov 2015 11:45:12 -0800 Subject: [PATCH 34/42] Add targetMachine property. --- src/actions/vstudio/vs2010_vcxproj.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index a353f51474..c5d10be51c 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -406,6 +406,7 @@ m.treatLinkerWarningAsErrors, m.ignoreDefaultLibraries, m.largeAddressAware, + m.targetMachine, m.additionalLinkOptions, } end @@ -430,6 +431,7 @@ if cfg.kind == p.STATICLIB then return { m.treatLinkerWarningAsErrors, + m.targetMachine, m.additionalLinkOptions, } else @@ -953,6 +955,18 @@ end + function m.targetMachine(cfg) + local targetmachine = { + x86 = "MachineX86", + x86_64 = "MachineX64", + } + local value = targetmachine[cfg.architecture] + if (value ~= nil) then + m.element("TargetMachine", nil, '%s', value) + end + end + + function m.additionalCompileOptions(cfg, condition) if #cfg.buildoptions > 0 then local opts = table.concat(cfg.buildoptions, " ") From 42b6cfd859db03b8422c8b2f5001fc2476f649f8 Mon Sep 17 00:00:00 2001 From: Renaud Guillard Date: Sat, 7 Nov 2015 16:07:04 +0100 Subject: [PATCH 35/42] fix compilation warning :ignoring return value of "fread", declared with attribute warn_unused_result --- src/host/os_writefile_ifnotequal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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) { From 3ac4a034422b66602648975c16588b295e4e97b5 Mon Sep 17 00:00:00 2001 From: Renaud Guillard Date: Sat, 7 Nov 2015 17:09:56 +0100 Subject: [PATCH 36/42] =?UTF-8?q?fix=20compilation=20warning=20in=20http.c?= =?UTF-8?q?=20(missing=20initializer=20for=20field=20=E2=80=98errorBuffer?= =?UTF-8?q?=E2=80=99=20of=20=E2=80=98CurlCallbackState=E2=80=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/host/http.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/http.c b/src/host/http.c index dc3fe72764..589a131273 100644 --- a/src/host/http.c +++ b/src/host/http.c @@ -180,7 +180,7 @@ static CURL* curl_request(lua_State* L, CurlCallbackState* state, FILE* fp, int int http_get(lua_State* L) { - CurlCallbackState state = { 0, 0, {NULL, 0} }; + CurlCallbackState state = { 0, 0, {NULL, 0}, {0} }; CURL* curl = curl_request(L, &state, /*fp=*/NULL, /*progressFnIndex=*/2); CURLcode code; @@ -213,7 +213,7 @@ int http_get(lua_State* L) int http_download(lua_State* L) { - CurlCallbackState state = { 0, 0, {NULL, 0} }; + CurlCallbackState state = { 0, 0, {NULL, 0}, {0} }; CURL* curl; CURLcode code = CURLE_FAILED_INIT; From 5a6bb85027035f2c338ad4d68f39ce7cc198d07e Mon Sep 17 00:00:00 2001 From: triton Date: Tue, 24 Nov 2015 04:08:09 +0000 Subject: [PATCH 37/42] Fixed os.isdir to work with Windows symbolic links. --- src/host/os_isdir.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 { From fb99262b4c0effbc90b6d720100322211f65f0ac Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Fri, 27 Nov 2015 23:46:06 +0000 Subject: [PATCH 38/42] Fixed C# GNU Make backend response files to deal with platform path separators. Obsoletes pull request #292. --- src/actions/make/make_csharp.lua | 7 ++++--- tests/actions/make/cs/test_response.lua | 26 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) 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/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 From 6fc7a6920d42a2f754043dc8cc4581e1e961de82 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 30 Nov 2015 18:14:37 -0500 Subject: [PATCH 39/42] Revert "Add targetMachine property." This reverts commit d38f9a92921fedd5fa7ee1ca1b1891809be6e2cf. --- src/actions/vstudio/vs2010_vcxproj.lua | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index c5d10be51c..a353f51474 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -406,7 +406,6 @@ m.treatLinkerWarningAsErrors, m.ignoreDefaultLibraries, m.largeAddressAware, - m.targetMachine, m.additionalLinkOptions, } end @@ -431,7 +430,6 @@ if cfg.kind == p.STATICLIB then return { m.treatLinkerWarningAsErrors, - m.targetMachine, m.additionalLinkOptions, } else @@ -955,18 +953,6 @@ end - function m.targetMachine(cfg) - local targetmachine = { - x86 = "MachineX86", - x86_64 = "MachineX64", - } - local value = targetmachine[cfg.architecture] - if (value ~= nil) then - m.element("TargetMachine", nil, '%s', value) - end - end - - function m.additionalCompileOptions(cfg, condition) if #cfg.buildoptions > 0 then local opts = table.concat(cfg.buildoptions, " ") From 4b629acda09c6fa7489ba8e9fb05402908ad83d7 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Thu, 3 Dec 2015 07:04:00 -0500 Subject: [PATCH 40/42] Rollback link groups (-Wl,--start-group, -Wl,--end-group) The --start-group and --end-group flags cause issues for anyone using alternate linkers with GCC or Clang. We need to come up with a better solution. --- src/tools/gcc.lua | 7 ------- tests/actions/make/cpp/test_make_linking.lua | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index b234010827..c1263231c7 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -296,13 +296,6 @@ end end - if cfg.system ~= premake.MACOSX then - if #result > 1 then - table.insert(result, 1, "-Wl,--start-group") - table.insert(result, "-Wl,--end-group") - end - end - -- The "-l" flag is fine for system libraries local links = config.getlinks(cfg, "system", "fullpath") diff --git a/tests/actions/make/cpp/test_make_linking.lua b/tests/actions/make/cpp/test_make_linking.lua index d8485b6aca..0e17476aa0 100644 --- a/tests/actions/make/cpp/test_make_linking.lua +++ b/tests/actions/make/cpp/test_make_linking.lua @@ -178,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 From 408c1be5d8231f8b4aac4b7c694c9b8ecd27b2d5 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 8 Dec 2015 19:34:44 -0500 Subject: [PATCH 41/42] Captured changes since alpha6 --- CHANGES.txt | 18 ++++++++++++++++++ CONTRIBUTORS.txt | 21 +++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) 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 5949ae076b..7416ef072d 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -24,23 +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 + * 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 Mark Chandler - * Prevent self-linking + * prevent self-linking + Mark Sararu + * Makefile bug fixes Mihai Sebea * Xcode exporter fixes and improvements M Skibbe @@ -48,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() From 7c9d70e8221dbe40a50e05e704f847a57ba943ad Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 16 Dec 2015 19:58:49 -0500 Subject: [PATCH 42/42] Update version number for release --- scripts/RELEASE.txt | 2 ++ src/host/premake.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/RELEASE.txt b/scripts/RELEASE.txt index 08c6f04b40..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 diff --git a/src/host/premake.c b/src/host/premake.c index e5f2349860..384c18dcf9 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -14,7 +14,7 @@ #endif -#define VERSION "5.0.0-dev" +#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"