diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-04-17 16:38:49 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-04-17 16:38:49 +0000 |
commit | cffb2b2c6934428fc5f677b2330eaf9cb438909e (patch) | |
tree | b36ce502b0e8712fc1a2a114c4359ad91422145c /plugins/MirLua/src/mlua_utils.cpp | |
parent | cebf5d329dcf0a441350a505882382a7094c0f3e (diff) |
MirLua:
- added string interpolation:
print('some {val} string' % { val = 'cool' })
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@16699 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_utils.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index ea032b052e..3bb82e8fb3 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -126,15 +126,15 @@ int luaM_topointer(lua_State *L) if (lua_isinteger(L, 1))
{
lua_Integer value = lua_tointeger(L, 1);
- if (value > INT_MAX)
+ if (value > INTPTR_MAX)
{
- const char *msg = lua_pushfstring(L, "%f is larger than %d", value, INT_MAX);
+ const char *msg = lua_pushfstring(L, "%f is larger than %d", value, INTPTR_MAX);
return luaL_argerror(L, 1, msg);
}
lua_pushlightuserdata(L, (void*)value);
}
}
- break;
+ break;
case LUA_TSTRING:
lua_pushlightuserdata(L, (void*)lua_tostring(L, 1));
break;
@@ -165,6 +165,30 @@ int luaM_tonumber(lua_State *L) return 1;
}
+int luaM_interpolate(lua_State *L)
+{
+ const char *string = luaL_checkstring(L, 1);
+ luaL_checktype(L, 2, LUA_TTABLE);
+
+ lua_pushnil(L);
+ while (lua_next(L, -2) != 0)
+ {
+ const char *key = luaL_checkstring(L, -2);
+ const char *val = lua_tostring(L, -1);
+
+ char pattern[32];
+ mir_snprintf(pattern, "{%s}", key);
+ string = luaL_gsub(L, string, pattern, val);
+ lua_pop(L, 1);
+
+ lua_pop(L, 1);
+ }
+
+ lua_pushstring(L, string);
+
+ return 1;
+}
+
WPARAM luaM_towparam(lua_State *L, int idx)
{
if (lua_islightuserdata(L, idx))
|