1313 *
1414 */
1515
16- // unsupported feature, defined to prepare for future
17- #define USE_ADDITIONS
18-
1916#define PRIMARY_BUFFER_SIZE (1024 + 1)
2017#define SECONDARY_BUFFER_SIZE (1032 + 1)
2118
4037# include <stdlib.h>
4138# include <dirent.h>
4239#else
43- # error "Not familiar. Set up headers accordingly, or -D__linux__ or -D__APPLE__ or -D_WIN32"
40+ # error "Not familiar. Set up headers accordingly, or -D__linux__ of -Dunix or -D__APPLE__ or -D_WIN32"
4441#endif
4542
4643#include <string.h>
4946#include "lualib.h"
5047#include "lauxlib.h"
5148
52- #if defined(USE_ADDITIONS )
49+ #if defined(LUACON_ADDITIONS )
5350# include "additions.h"
5451#endif
5552
@@ -67,7 +64,7 @@ typedef enum LuaConsoleError {
6764
6865// usage message
6966const char HELP_MESSAGE [] =
70- "Lua Console | Version: 6/13 /2017\n"
67+ "Lua Console | Version: 9/26 /2017\n"
7168 LUA_COPYRIGHT
7269 LUA_CONSOLE_COPYRIGHT
7370 "\n"
@@ -77,15 +74,19 @@ const char HELP_MESSAGE[] =
7774 "\t- Line by Line interpretation\n"
7875 "\t- Files executed by passing\n"
7976 "\t- Working directory support\n"
80- "\t- Built in stack-dump\n"
77+ #if defined(LUACON_ADDITIONS )
78+ "\t- Built in stack-dump\n"
79+ #endif
8180 "\n"
8281 "Usage: lua.exe [FILE_PATH] [-v] [-e] [-s START_PATH] [-p] [-a] [-c] [-?] [-n]{parameter1 ...} \n"
8382 "\n"
8483 "-v \t Prints the Lua version in use\n"
8584 "-e \t Prevents lua core libraries from loading\n"
8685 "-s \t Issues a new root path\n"
8786 "-p \t Has console post exist after script in line by line mode\n"
88- "-a \t Removes the additions\n"
87+ #if defined(LUACON_ADDITIONS )
88+ "-a \t Removes the additions\n"
89+ #endif
8990 "-c \t No copyright on init\n"
9091 "-d \t Defines a global variable as value after '='\n"
9192 "-n \t Start of parameter section\n"
@@ -121,9 +122,11 @@ static void print_error(LuaConsoleError error) {
121122 break ;
122123 }
123124 size_t top = lua_gettop (L );
124- fprintf (stderr , " | Stack Top: %d | %s\n" , lua_gettop (L ), msg );
125- if (top > 1 ) // other than error message
126- stack_dump (L );
125+ fprintf (stderr , " | Stack Top: %Iu | %s\n" , top , msg );
126+ #if defined(LUACON_ADDITIONS )
127+ if (top > 1 ) // other than error message
128+ stack_dump (L );
129+ #endif
127130 lua_pop (L , 1 );
128131}
129132
@@ -247,6 +250,8 @@ char* strsplit(const char* str1, const char lookout, size_t len, size_t max) {
247250 char * cpy = malloc (len );
248251 memcpy (cpy , str1 , len );
249252
253+ size_t temp_max = max ;
254+
250255 for (size_t i = 0 ; i < len - 1 ; i ++ ) {
251256 if (str1 [i ] == lookout ) {
252257 cpy [i ] = '\0' ;
@@ -255,6 +260,10 @@ char* strsplit(const char* str1, const char lookout, size_t len, size_t max) {
255260 if (max == 0 )
256261 break ;
257262 }
263+ if (temp_max == max ) {
264+ free (cpy );
265+ return 0 ;
266+ }
258267 return cpy ;
259268}
260269
@@ -266,7 +275,9 @@ int main(int argc, char* argv[])
266275 static int post_exist = 0 ;
267276 static int no_file = 0 ;
268277 static char * start = 0 ;
269- static int no_additions = 0 ;
278+ #if defined(LUACON_ADDITIONS )
279+ static int no_additions = 0 ;
280+ #endif
270281 static int copyright_squelch = 0 ;
271282
272283 static size_t parameters = 0 ;
@@ -312,9 +323,11 @@ int main(int argc, char* argv[])
312323 case 'p' : case 'P' :
313324 post_exist = 1 ;
314325 break ;
315- case 'a' : case 'A' :
316- no_additions = 1 ;
317- break ;
326+ #if defined(LUACON_ADDITIONS )
327+ case 'a' : case 'A' :
328+ no_additions = 1 ;
329+ break ;
330+ #endif
318331 case 'c' : case 'C' :
319332 copyright_squelch = 1 ;
320333 break ;
@@ -371,7 +384,13 @@ int main(int argc, char* argv[])
371384 for (size_t i = 0 ; i < globals ; i ++ ) {
372385 char * globals_D_offset = globals_argv [i ] + 2 ;
373386
374- char * arg1 = strsplit (globals_D_offset , '=' , strlen (globals_D_offset ) + 1 , 2 );
387+ char * m_args = strsplit (globals_D_offset , '=' , strlen (globals_D_offset ) + 1 , 2 );
388+ if (m_args == 0 ) {
389+ fprintf (stderr , "Error: Incorrect -D specified. Use format 'name=value'.\n" );
390+ return EXIT_FAILURE ;
391+ }
392+
393+ char * arg1 = m_args ;
375394 char * arg2 = arg1 + (strlen (arg1 ) + 1 );
376395
377396 lua_pushlstring (L , arg2 , strlen (arg2 ));
@@ -420,9 +439,11 @@ int main(int argc, char* argv[])
420439 }
421440
422441
423- // add additions
424- if (no_additions == 0 )
425- additions_add (L );
442+ #if defined(LUACON_ADDITIONS )
443+ // add additions
444+ if (no_additions == 0 )
445+ additions_add (L );
446+ #endif
426447
427448
428449 // load function into protected mode (pcall)
0 commit comments