Skip to content
1 change: 1 addition & 0 deletions binmodules/luasocket/src/mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ static size_t dot(int c, size_t state, luaL_Buffer *buffer)
case '.':
if (state == 2)
luaL_addchar(buffer, '.');
/* Falls through. */
default:
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/lua/src/lundump.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static void fchecksize (LoadState *S, size_t size, const char *tname) {
#define checksize(S,t) fchecksize(S,sizeof(t),#t)

static void checkHeader (LoadState *S) {
checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */
checkliteral(S, &LUA_SIGNATURE[1], "not a"); /* 1st char already checked */
if (LoadByte(S) != LUAC_VERSION)
error(S, "version mismatch in");
if (LoadByte(S) != LUAC_FORMAT)
Expand Down
4 changes: 2 additions & 2 deletions src/host/curl_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ int curlProgressCallback(curl_state* state, double dltotal, double dlnow, double
}


size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, curl_state* state)
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, void* state)
{
size_t length = size * nmemb;
premake_buffer_puts(&state->S, ptr, length);
premake_buffer_puts(&((curl_state*)state)->S, ptr, length);
return length;
}

Expand Down
2 changes: 1 addition & 1 deletion src/host/curl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int curlProgressCallback(curl_state* state, curl_off_t dltotal, curl_off_t dlnow
#else
int curlProgressCallback(curl_state* state, double dltotal, double dlnow, double ultotal, double ulnow);
#endif
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, curl_state* state);
size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, void* state);

CURL* curlRequest(lua_State* L, curl_state* state, int optionsIndex, int progressFnIndex, int headersIndex);
void curlCleanup(CURL* curl, curl_state* state);
Expand Down
1 change: 1 addition & 0 deletions src/host/os_getpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int os_getpass(lua_State* L)
lua_pushstring(L, buffer);
return 1;
#elif PLATFORM_COSMO
(void)prompt;
luaL_error(L, "Not supported by this platform");
return 0;
#elif PLATFORM_POSIX
Expand Down
2 changes: 1 addition & 1 deletion src/host/path_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int path_deferred_join(lua_State* L)
}


int do_path_has_deferred_join(const char* path)
static int do_path_has_deferred_join(const char* path)
{
return (strchr(path, DEFERRED_JOIN_DELIMITER) != NULL);
}
Expand Down
22 changes: 12 additions & 10 deletions src/host/premake.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ int premake_locate_executable(lua_State* L, const char* argv0)
}
#endif

(void)buffer;

/* As a fallback, search the PATH with argv[0] */
if (!path)
{
Expand Down Expand Up @@ -451,9 +453,9 @@ int premake_locate_executable(lua_State* L, const char* argv0)
* specified file. If found, returns the discovered path to the script on
* the top of the Lua stack.
*/
int premake_test_file(lua_State* L, const char* filename, int searchMask)
int premake_locate_file(lua_State* L, const char* filename, int searchMask)
{
if (searchMask & TEST_LOCAL) {
if (searchMask & SEARCH_LOCAL) {
if (do_isfile(L, filename)) {
lua_pushcfunction(L, path_getabsolute);
lua_pushstring(L, filename);
Expand All @@ -462,17 +464,17 @@ int premake_test_file(lua_State* L, const char* filename, int searchMask)
}
}

if (scripts_path && (searchMask & TEST_SCRIPTS)) {
if (scripts_path && (searchMask & SEARCH_SCRIPTS)) {
if (do_locate(L, filename, scripts_path)) return OKAY;
}

if (searchMask & TEST_PATH) {
if (searchMask & SEARCH_PATH) {
const char* path = getenv("PREMAKE_PATH");
if (path && do_locate(L, filename, path)) return OKAY;
}

#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
if ((searchMask & TEST_EMBEDDED) != 0) {
if ((searchMask & SEARCH_EMBEDDED) != 0) {
/* Try to locate a record matching the filename */
if (premake_find_embedded_script(filename) != NULL) {
lua_pushstring(L, "$/");
Expand Down Expand Up @@ -614,18 +616,18 @@ static int run_premake_main(lua_State* L, const char* script)
* argument allowed as an override. Debug builds will look at the
* local file system first, then fall back to embedded. */
#if defined(NDEBUG)
int z = premake_test_file(L, script,
TEST_SCRIPTS | TEST_EMBEDDED);
int z = premake_locate_file(L, script,
SEARCH_SCRIPTS | SEARCH_EMBEDDED);
#else
int z = premake_test_file(L, script,
TEST_LOCAL | TEST_SCRIPTS | TEST_PATH | TEST_EMBEDDED);
int z = premake_locate_file(L, script,
SEARCH_LOCAL | SEARCH_SCRIPTS | SEARCH_PATH | SEARCH_EMBEDDED);
#endif

/* If no embedded script can be found, release builds will then
* try to fall back to the local file system, just in case */
#if defined(NDEBUG)
if (z != OKAY) {
z = premake_test_file(L, script, TEST_LOCAL | TEST_PATH);
z = premake_locate_file(L, script, SEARCH_LOCAL | SEARCH_PATH);
}
#endif

Expand Down
32 changes: 13 additions & 19 deletions src/host/premake.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
#include "lauxlib.h"
#include "lualib.h"

#include <stdint.h>
#include <stdlib.h>

#define PREMAKE_VERSION "5.0.0-dev"
#define PREMAKE_COPYRIGHT "Copyright (C) 2002-2021 Jess Perkins and the Premake Project"
#define PREMAKE_PROJECT_URL "https://github.com/premake/premake-core/wiki"

/* Identify the current platform I'm not sure how to reliably detect
* Windows but since it is the most common I use it as the default */
#if defined(__linux__)
#define PLATFORM_LINUX (1)
#define PLATFORM_OS "linux"
Expand All @@ -41,9 +40,11 @@
#elif defined (__COSMOPOLITAN__)
#define PLATFORM_COSMO (1)
#define PLATFORM_OS "cosmopolitan"
#else
#elif defined(_WIN32) || defined(_WIN64)
#define PLATFORM_WINDOWS (1)
#define PLATFORM_OS "windows"
#else
#error Unknown platform detected
#endif

#define PLATFORM_POSIX (PLATFORM_LINUX || PLATFORM_BSD || PLATFORM_MACOSX || PLATFORM_SOLARIS || PLATFORM_HAIKU || PLATFORM_COSMO)
Expand All @@ -68,7 +69,6 @@
#else
#include <unistd.h>
#endif
#include <stdint.h>

/* not all platforms define this */
#ifndef FALSE
Expand All @@ -83,22 +83,21 @@
#define PATH_MAX (4096)
#endif


/* A success return code */
#define OKAY (0)


/* Bitmasks for the different script file search locations */
#define TEST_LOCAL (0x01)
#define TEST_SCRIPTS (0x02)
#define TEST_PATH (0x04)
#define TEST_EMBEDDED (0x08)

enum FileSearchMask
{
SEARCH_LOCAL = 0x01,
SEARCH_SCRIPTS = 0x02,
SEARCH_PATH = 0x04,
SEARCH_EMBEDDED = 0x08
};

/* If a /scripts argument is present, its value */
extern const char* scripts_path;


/* Bootstrapping helper functions */
int do_chdir(lua_State* L, const char* path);
uint32_t do_hash(const char* str, int seed);
Expand Down Expand Up @@ -189,12 +188,6 @@ int http_download(lua_State* L);
int zip_extract(lua_State* L);
#endif

#ifdef _MSC_VER
#ifndef snprintf
#define snprintf _snprintf
#endif
#endif

/* Engine interface */

typedef struct
Expand All @@ -210,9 +203,10 @@ extern void registerModules(lua_State* L);
int premake_init(lua_State* L);
int premake_pcall(lua_State* L, int nargs, int nresults);
int premake_execute(lua_State* L, int argc, const char** argv, const char* script);

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);
int premake_locate_file(lua_State* L, const char* filename, int searchMask);
void premake_handle_lua_error(lua_State* L);