]> granicus.if.org Git - vim/commitdiff
patch 8.2.1908: Lua is initialized even when not used v8.2.1908
authorBram Moolenaar <Bram@vim.org>
Mon, 26 Oct 2020 19:18:08 +0000 (20:18 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 26 Oct 2020 19:18:08 +0000 (20:18 +0100)
Problem:    Lua is initialized even when not used.
Solution:   Put lua_init() after check for "eap->skip". (Christian Brabandt,
            closes #7191).  Avoid compiler warnings.

src/if_lua.c
src/testdir/test_lua.vim
src/version.c

index 77f2afe54b92a5aad4b5aef7cf0d4aaa3fb76c13..e20298311d73995f3d435fdf6143814fb1e18907 100644 (file)
@@ -33,7 +33,7 @@ typedef struct {
     char_u     *name;  // funcref
     dict_T     *self;  // selfdict
 } luaV_Funcref;
-typedef void (*msgfunc_T)(char_u *);
+typedef int (*msgfunc_T)(char *);
 
 typedef struct {
     int lua_funcref;    // ref to a lua func
@@ -788,11 +788,11 @@ luaV_msgfunc(lua_State *L, msgfunc_T mf)
     {
        if (*p++ == '\0') // break?
        {
-           mf((char_u *) s);
+           mf((char *)s);
            s = p;
        }
     }
-    mf((char_u *) s);
+    mf((char *)s);
     lua_pop(L, 2); // original and modified strings
 }
 
@@ -2372,18 +2372,19 @@ lua_end(void)
     void
 ex_lua(exarg_T *eap)
 {
-    char *script;
-    if (lua_init() == FAIL) return;
-    script = (char *) script_get(eap, eap->arg);
-    if (!eap->skip)
+    char *script = (char *)script_get(eap, eap->arg);
+
+    if (!eap->skip && lua_init() == OK)
     {
-       char *s = (script) ? script :  (char *) eap->arg;
+       char *s = script != NULL ? script : (char *)eap->arg;
+
        luaV_setrange(L, eap->line1, eap->line2);
        if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME)
                || lua_pcall(L, 0, 0, 0))
            luaV_emsg(L);
     }
-    if (script != NULL) vim_free(script);
+    if (script != NULL)
+       vim_free(script);
 }
 
     void
index d21c40de5bc67116ba27e9ab9007d0d4984332f1..43b4aa30ff39b1dad788410609034183b9463cb8 100644 (file)
@@ -1,6 +1,14 @@
 " Tests for Lua.
 
 source check.vim
+
+" This test also works without the lua feature.
+func Test_skip_lua()
+  if 0
+    lua print("Not executed")
+  endif
+endfunc
+
 CheckFeature lua
 CheckFeature float
 
index 52d64fc1f4f38ef0319d17de5d6c57a71e27b002..91736ec0ad9bc5c764e1b9679cdfeb389c05bf30 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1908,
 /**/
     1907,
 /**/