]> granicus.if.org Git - neomutt/commitdiff
lua: enable myvars
authorRichard Russon <rich@flatcap.org>
Fri, 29 Dec 2017 01:16:23 +0000 (01:16 +0000)
committerRichard Russon <rich@flatcap.org>
Wed, 17 Jan 2018 00:25:17 +0000 (00:25 +0000)
Fixes #1016
Fixes #1017

init.c
mutt_lua.c
protos.h

diff --git a/init.c b/init.c
index 7f365864fa77d389a622c68d2e1aa31d1d4657ca..239904f4958e94b8867bafe710184068241d6760 100644 (file)
--- a/init.c
+++ b/init.c
@@ -87,7 +87,7 @@ struct MyVar
 
 static struct MyVar *MyVars;
 
-static void myvar_set(const char *var, const char *val)
+void myvar_set(const char *var, const char *val)
 {
   struct MyVar **cur = NULL;
 
@@ -292,6 +292,7 @@ bool mutt_option_get(const char *s, struct Option *opt)
       memset(opt, 0, sizeof(*opt));
       opt->name = s;
       opt->type = DT_STRING;
+      opt->initial = (intptr_t) mv;
     }
     return true;
   }
index e1bb1449e9905669084df3df3a70a16e2ffbf291..bb56580cf2640c92a91f3f4ff151aff675e182f4 100644 (file)
@@ -124,7 +124,13 @@ static int lua_mutt_set(lua_State *l)
   err.data = err_str;
   err.dsize = sizeof(err_str);
 
-  if (!mutt_option_get(param, &opt))
+  if (mutt_str_strncmp("my_", param, 3) == 0)
+  {
+    const char *val = lua_tostring(l, -1);
+    myvar_set(param, val);
+    return 0;
+  }
+  else if (!mutt_option_get(param, &opt))
   {
     luaL_error(l, "Error getting parameter %s", param);
     return -1;
@@ -219,11 +225,8 @@ static int lua_mutt_get(lua_State *l)
       case DT_STRING:
         if (mutt_str_strncmp("my_", param, 3) == 0)
         {
-          char *option = (char *) opt.name;
-          char *value = (char *) opt.var;
+          char *value = (char *) opt.initial;
           lua_pushstring(l, value);
-          FREE(&option);
-          FREE(&value);
         }
         else
         {
index 649a9fff33e594230901b72e70cb79a98ee7a391..b891ac72364a9462bdf7def323afbb9e46fc58c7 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -243,6 +243,7 @@ int mutt_check_overwrite(const char *attname, const char *path, char *fname,
 int mutt_check_traditional_pgp(struct Header *h, int *redraw);
 int mutt_command_complete(char *buffer, size_t len, int pos, int numtabs);
 int mutt_var_value_complete(char *buffer, size_t len, int pos);
+void myvar_set(const char *var, const char *val);
 #ifdef USE_NOTMUCH
 bool mutt_nm_query_complete(char *buffer, size_t len, int pos, int numtabs);
 bool mutt_nm_tag_complete(char *buffer, size_t len, int numtabs);