aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/man/nvim.125
-rw-r--r--src/nvim/lua/executor.c22
-rw-r--r--src/nvim/main.c20
-rw-r--r--src/nvim/main.h1
4 files changed, 37 insertions, 31 deletions
diff --git a/src/man/nvim.1 b/src/man/nvim.1
index 457d785365..c32bdeadc6 100644
--- a/src/man/nvim.1
+++ b/src/man/nvim.1
@@ -122,9 +122,6 @@ modifications.
.It Fl b
Binary mode.
.Ic ":help edit-binary"
-.It Fl l
-Lisp mode.
-Sets the 'lisp' and 'showmatch' options.
.It Fl A
Arabic mode.
Sets the 'arabic' option.
@@ -144,7 +141,7 @@ is specified, append messages to
instead of printing them.
.Ic ":help 'verbose'"
.It Fl D
-Debug mode for VimL (Vim script).
+Vimscript debug mode.
Started when executing the first command from a script.
:help debug-mode
.It Fl n
@@ -268,10 +265,26 @@ but execute
before processing any vimrc.
Up to 10 instances of these can be used independently from instances of
.Fl c .
+.It Fl l Ar script Op Ar args
+Execute Lua
+.Ar script
+with optional
+.Op Ar args
+after processing any preceding Nvim startup arguments.
+All
+.Op Ar args
+are treated as script arguments and are passed literally to Lua, that is,
+.Fl l
+stops processing of Nvim arguments.
+.Ic ":help -l"
.It Fl S Op Ar session
-Source
+Execute
+.Ar session
+after the first file argument has been read. If
.Ar session
-after the first file argument has been read.
+filename ends with
+.Pa .lua
+it is executed as Lua instead of Vimscript.
Equivalent to
.Cm -c \(dqsource session\(dq .
.Ar session
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 1bedb70efb..20c901004a 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -323,32 +323,28 @@ static int nlua_thr_api_nvim__get_runtime(lua_State *lstate)
return 1;
}
-/// Copies all args into the Lua `arg` global.
+/// Copies args starting at `lua_arg0` into the Lua `arg` global.
///
/// Example:
-/// nvim -l foo.lua -- -e "sin=math.sin" script a b
+/// nvim -l foo.lua --arg1 --arg2
///
/// @note `lua` CLI sets _negative_ `arg` indices to the arguments upto "-e".
///
/// @see https://www.lua.org/pil/1.4.html
/// @see https://github.com/premake/premake-core/blob/1c1304637f4f5e50ba8c57aae8d1d80ec3b7aaf2/src/host/premake.c#L563-L594
///
-/// @returns number of args (stops at "--")
-int nlua_set_argv(char **argv, int argc)
+/// @returns number of args
+int nlua_set_argv(char **argv, int argc, int lua_arg0)
{
lua_State *const L = global_lstate;
- lua_newtable(L);
+ lua_newtable(L); // _G.arg
int i = 0;
- for (; i < argc; i++) {
- if (strequal("--", argv[i])) {
- i--;
- break;
- }
- lua_pushstring(L, argv[i]);
- lua_rawseti(L, -2, i + 1);
+ for (; lua_arg0 >= 0 && i + lua_arg0 < argc; i++) {
+ lua_pushstring(L, argv[i + lua_arg0]);
+ lua_rawseti(L, -2, i + 1); // _G.arg[i+1] = "arg1"
}
lua_setglobal(L, "arg");
- return i + 1;
+ return i;
}
static void nlua_schedule_event(void **argv)
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 77584b049a..908395655f 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -275,14 +275,14 @@ int main(int argc, char **argv)
// Check if we have an interactive window.
check_and_set_isatty(&params);
- // TODO: should we try to keep param scan before this?
- nlua_init();
- TIME_MSG("init lua interpreter");
-
// Process the command line arguments. File names are put in the global
// argument list "global_alist".
command_line_scan(&params);
+ nlua_init();
+ nlua_set_argv(argv, argc, params.lua_arg0);
+ TIME_MSG("init lua interpreter");
+
if (embedded_mode) {
const char *err;
if (!channel_from_stdio(true, CALLBACK_READER_INIT, &err)) {
@@ -1318,14 +1318,9 @@ static void command_line_scan(mparm_T *parmp)
}
parmp->luaf = argv[0];
argc--;
- argv++;
- // Lua args after "-l <file>" (upto "--").
- int l_argc = nlua_set_argv(argv, argc);
- assert(l_argc >= 0);
- argc = argc - l_argc;
- if (argc > 0) { // Found "--".
- argv = argv + l_argc;
- had_minmin = true;
+ if (argc > 0) { // Lua args after "-l <file>".
+ parmp->lua_arg0 = parmp->argc - argc;
+ argc = 0;
}
break;
@@ -1438,6 +1433,7 @@ static void init_params(mparm_T *paramp, int argc, char **argv)
paramp->server_addr = NULL;
paramp->remote = 0;
paramp->luaf = NULL;
+ paramp->lua_arg0 = -1;
}
/// Initialize global startuptime file if "--startuptime" passed as an argument.
diff --git a/src/nvim/main.h b/src/nvim/main.h
index f8cf26961c..46d7217364 100644
--- a/src/nvim/main.h
+++ b/src/nvim/main.h
@@ -24,6 +24,7 @@ typedef struct {
int n_pre_commands; // no. of commands from --cmd
char *pre_commands[MAX_ARG_CMDS]; // commands from --cmd argument
char *luaf; // Lua script filename from "-l"
+ int lua_arg0; // Lua script args start index.
int edit_type; // type of editing to do
char *tagname; // tag from -t argument