Skip to content
Permalink
Browse files
Added '-p' option to REPL, which pauses after script execution.
  • Loading branch information
christian-bechette authored and Andrew Starks committed May 29, 2014
1 parent dc56559 commit 260d478
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
@@ -2,7 +2,7 @@ nuget {
nuspec {
id = lua;
title: Lua 5.3 work 2;
version: 5.3.0002.10;
version: 5.3.0002.13;
authors: {coapp, Lua Contributors, Tightrope Media Systems};
owners: {Puc-Rio};
licenseUrl: "http://www.lua.org/license.html";
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

#define lua_c

@@ -131,6 +132,7 @@ static void print_usage (const char *badoption) {
" -i enter interactive mode after executing " LUA_QL("script") "\n"
" -l name require library " LUA_QL("name") "\n"
" -v show version information\n"
" -p pause after execution of a script.\n"
" -E ignore environment variables\n"
" -- stop handling options\n"
" - stop handling options and execute stdin\n"
@@ -386,10 +388,12 @@ static int handle_script (lua_State *L, char **argv, int n) {
/* indices of various argument indicators in array args */
#define has_i 0 /* -i */
#define has_v 1 /* -v */
#define has_e 2 /* -e */
#define has_E 3 /* -E */
#define has_p 2 /* -p */
#define has_e 3 /* -e */
#define has_E 4 /* -E */

#define num_has 4 /* number of 'has_*' */

#define num_has 5 /* number of 'has_*' */


static int collectargs (char **argv, int *args) {
@@ -412,6 +416,9 @@ static int collectargs (char **argv, int *args) {
case 'v':
noextrachars(argv[i]);
args[has_v] = 1;
break;
case 'p':
args[has_p] = 1;
break;
case 'e':
args[has_e] = 1; /* go through */
@@ -472,15 +479,16 @@ static int handle_luainit (lua_State *L) {
return dostring(L, init, name);
}


static int pmain (lua_State *L) {
int argc = (int)lua_tointeger(L, 1);
char **argv = (char **)lua_touserdata(L, 2);
int script;
int args[num_has];
args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
args[has_i] = args[has_v] = args[has_p] = args[has_e] = args[has_E] = 0;

if (argv[0] && argv[0][0]) progname = argv[0];
script = collectargs(argv, args);

if (script < 0) { /* invalid arg? */
print_usage(argv[-script]);
return 0;
@@ -498,9 +506,12 @@ static int pmain (lua_State *L) {
if (!args[has_E] && handle_luainit(L) != LUA_OK)
return 0; /* error running LUA_INIT */
/* execute arguments -e and -l */
if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
if (!runargs(L, argv, (script > 0) ? script : argc))
return 0;
/* execute main script (if there is one) */
if (script && handle_script(L, argv, script) != LUA_OK) return 0;
if (script && handle_script(L, argv, script) != LUA_OK)
return 0;

if (args[has_i]) /* -i option? */
dotty(L);
else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */
@@ -511,6 +522,13 @@ static int pmain (lua_State *L) {
else dofile(L, NULL); /* executes stdin as a file */
}
lua_pushboolean(L, 1); /* signal no errors */

/* Pause at the end of execution? */
if (args[has_p]) {
printf("press any key to exit");
getch();
}

return 1;
}

@@ -530,6 +548,9 @@ int main (int argc, char **argv) {
result = lua_toboolean(L, -1); /* get result */
finalreport(L, status);
lua_close(L);



return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
}

0 comments on commit 260d478

Please sign in to comment.