From 934c8d1dc7388d36342f15e0cb8ad16df0245961 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 29 Dec 2017 01:16:23 +0000 Subject: [PATCH] lua: enable myvars Fixes #1016 Fixes #1017 --- init.c | 3 ++- mutt_lua.c | 13 ++++++++----- protos.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/init.c b/init.c index 7f365864fa7..239904f4958 100644 --- 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; } diff --git a/mutt_lua.c b/mutt_lua.c index e1bb1449e99..bb56580cf26 100644 --- a/mutt_lua.c +++ b/mutt_lua.c @@ -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 { diff --git a/protos.h b/protos.h index 649a9fff33e..b891ac72364 100644 --- 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);