summaryrefslogtreecommitdiff
path: root/plugins/MirLua
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-06-18 12:45:56 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-06-18 12:45:56 +0000
commite7d18ae97ecbe5db4c9a511afc4c05fa9bf8204b (patch)
tree7c6359372dca76c618424221523ecce3e6932b71 /plugins/MirLua
parent2e234d5349a9b02a41866f6a68cf4ecb875d585a (diff)
MirLua: interpolate can use local variables with ${name} pattern
git-svn-id: http://svn.miranda-ng.org/main/trunk@17005 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua')
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index f02ca6e147..574de71ba2 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -208,6 +208,8 @@ int luaM_interpolate(lua_State *L)
{
const char *string = luaL_checkstring(L, 1);
+ char pattern[128];
+
if (lua_istable(L, 2))
{
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2))
@@ -216,7 +218,6 @@ int luaM_interpolate(lua_State *L)
const char *key = lua_tostring(L, -1);
const char *val = lua_tostring(L, -2);
- char pattern[32];
mir_snprintf(pattern, "{%s}", key);
string = luaL_gsub(L, string, pattern, val);
lua_pop(L, 1);
@@ -229,13 +230,26 @@ int luaM_interpolate(lua_State *L)
{
const char *val = lua_tostring(L, i);
- char pattern[32];
mir_snprintf(pattern, "{%d}", i - 1);
string = luaL_gsub(L, string, pattern, val);
lua_pop(L, 1);
}
}
+ lua_Debug ar;
+ lua_getstack(L, 1, &ar);
+ const char *name = lua_getlocal(L, &ar, 1);
+
+ size_t i = 1;
+ while (const char *key = lua_getlocal(L, &ar, i++))
+ {
+ const char *val = lua_tostring(L, -1);
+
+ mir_snprintf(pattern, "${%s}", name);
+ string = luaL_gsub(L, string, pattern, val);
+ lua_pop(L, 1);
+ }
+
lua_pushstring(L, string);
return 1;