diff --git a/src/additions.c b/src/additions.c index 22e45f2..8baf2e7 100644 --- a/src/additions.c +++ b/src/additions.c @@ -5,17 +5,27 @@ * */ - -#if defined(__linux__) || defined(__unix__) -#include +#if defined(linux) || defined(__linux__) || defined(__linux) +# include +# include +# include +#elif defined(unix) || defined(__unix__) || defined(__unix) +# include +# include +# include +#elif defined(__APPLE__) || defined(__MACH__) +# include +# include +# include +#elif defined(_WIN32) || defined(_WIN64) +# include +# include +# include +# include #else -#include +# error "Not familiar. Set up headers accordingly, or -D__linux__ or -D__APPLE__ or -D_WIN32" #endif -#include -#include -#include - #include "additions.h" #include "lua.h" @@ -24,9 +34,9 @@ #ifdef _WIN32 -#define CLEAR_CONSOLE "cls" +# define CLEAR_CONSOLE "cls" #else -#define CLEAR_CONSOLE "clear" +# define CLEAR_CONSOLE "clear" #endif diff --git a/src/console.c b/src/console.c index 7e39c8c..57b182f 100644 --- a/src/console.c +++ b/src/console.c @@ -13,9 +13,6 @@ * */ -// unsupported feature, defined to prepare for future -#define USE_ADDITIONS - #define PRIMARY_BUFFER_SIZE (1024 + 1) #define SECONDARY_BUFFER_SIZE (1032 + 1) @@ -40,7 +37,7 @@ # include # include #else -# error "Not familiar. Set up headers accordingly, or -D__linux__ or -D__APPLE__ or -D_WIN32" +# error "Not familiar. Set up headers accordingly, or -D__linux__ of -Dunix or -D__APPLE__ or -D_WIN32" #endif #include @@ -49,7 +46,7 @@ #include "lualib.h" #include "lauxlib.h" -#if defined(USE_ADDITIONS) +#if defined(LUACON_ADDITIONS) # include "additions.h" #endif @@ -67,7 +64,7 @@ typedef enum LuaConsoleError { // usage message const char HELP_MESSAGE[] = - "Lua Console | Version: 6/13/2017\n" + "Lua Console | Version: 9/26/2017\n" LUA_COPYRIGHT LUA_CONSOLE_COPYRIGHT "\n" @@ -76,14 +73,18 @@ const char HELP_MESSAGE[] = "\n" "\t- Files executed by passing\n" "\t- Working directory support\n" - "\t- Built in stack-dump\n" + #if defined(LUACON_ADDITIONS) + "\t- Built in stack-dump\n" + #endif "\n" "Usage: lua.exe [FILE_PATH] [-v] [-e] [-s START_PATH] [-a] [-c] [-?] [-n]{parameter1 ...} \n" "\n" "-v \t Prints the Lua version in use\n" "-e \t Prevents lua core libraries from loading\n" "-s \t Issues a new root path\n" - "-a \t Removes the additions\n" + #if defined(LUACON_ADDITIONS) + "-a \t Removes the additions\n" + #endif "-c \t No copyright on init\n" "-d \t Defines a global variable as value after '='\n" "-n \t Start of parameter section\n" @@ -116,9 +117,11 @@ static void print_error(LuaConsoleError error) { break; } size_t top = lua_gettop(L); - fprintf(stderr, " | Stack Top: %d | %s\n", lua_gettop(L), msg); - if(top > 1) // other than error message - stack_dump(L); + fprintf(stderr, " | Stack Top: %Iu | %s\n", top, msg); + #if defined(LUACON_ADDITIONS) + if(top > 1) // other than error message + stack_dump(L); + #endif lua_pop(L, 1); } @@ -167,6 +170,8 @@ char* strsplit(const char* str1, const char lookout, size_t len, size_t max) { char* cpy = malloc(len); memcpy(cpy, str1, len); + size_t temp_max = max; + for (size_t i=0; i # include #else -# error "Not familiar. Set up headers accordingly, or -D__linux__ or -D__APPLE__ or -D_WIN32" +# error "Not familiar. Set up headers accordingly, or -D__linux__ of -Dunix or -D__APPLE__ or -D_WIN32" #endif #include @@ -49,7 +46,7 @@ #include "lualib.h" #include "lauxlib.h" -#if defined(USE_ADDITIONS) +#if defined(LUACON_ADDITIONS) # include "additions.h" #endif @@ -67,7 +64,7 @@ typedef enum LuaConsoleError { // usage message const char HELP_MESSAGE[] = - "Lua Console | Version: 6/13/2017\n" + "Lua Console | Version: 9/26/2017\n" LUA_COPYRIGHT LUA_CONSOLE_COPYRIGHT "\n" @@ -77,7 +74,9 @@ const char HELP_MESSAGE[] = "\t- Line by Line interpretation\n" "\t- Files executed by passing\n" "\t- Working directory support\n" - "\t- Built in stack-dump\n" + #if defined(LUACON_ADDITIONS) + "\t- Built in stack-dump\n" + #endif "\n" "Usage: lua.exe [FILE_PATH] [-v] [-e] [-s START_PATH] [-p] [-a] [-c] [-?] [-n]{parameter1 ...} \n" "\n" @@ -85,7 +84,9 @@ const char HELP_MESSAGE[] = "-e \t Prevents lua core libraries from loading\n" "-s \t Issues a new root path\n" "-p \t Has console post exist after script in line by line mode\n" - "-a \t Removes the additions\n" + #if defined(LUACON_ADDITIONS) + "-a \t Removes the additions\n" + #endif "-c \t No copyright on init\n" "-d \t Defines a global variable as value after '='\n" "-n \t Start of parameter section\n" @@ -121,9 +122,11 @@ static void print_error(LuaConsoleError error) { break; } size_t top = lua_gettop(L); - fprintf(stderr, " | Stack Top: %d | %s\n", lua_gettop(L), msg); - if(top > 1) // other than error message - stack_dump(L); + fprintf(stderr, " | Stack Top: %Iu | %s\n", top, msg); + #if defined(LUACON_ADDITIONS) + if(top > 1) // other than error message + stack_dump(L); + #endif lua_pop(L, 1); } @@ -247,6 +250,8 @@ char* strsplit(const char* str1, const char lookout, size_t len, size_t max) { char* cpy = malloc(len); memcpy(cpy, str1, len); + size_t temp_max = max; + for (size_t i=0; i