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 | |
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
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 7 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 30 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/version.h | 2 |
4 files changed, 37 insertions, 4 deletions
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index f2cdafb41b..8a9b0ce87c 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -56,6 +56,13 @@ void CMLua::Load() lua_setglobal(L, "_tonumber");
lua_register(L, "tonumber", luaM_tonumber);
+ lua_pushstring(L, "");
+ lua_getmetatable(L, -1);
+ lua_pushstring(L, "__mod");
+ lua_pushcfunction(L, luaM_interpolate);
+ lua_rawset(L, -3);
+ lua_pop(L, 2);
+
lua_atpanic(L, luaM_atpanic);
Log("Loading miranda modules");
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))
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 48218e8651..921d2c70c4 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -115,6 +115,8 @@ int luaM_toucs2(lua_State *L); int luaM_topointer(lua_State *L);
int luaM_tonumber(lua_State *L);
+int luaM_interpolate(lua_State *L);
+
WPARAM luaM_towparam(lua_State *L, int idx);
LPARAM luaM_tolparam(lua_State *L, int idx);
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index c410df9718..b9b7e3011f 100644 --- a/plugins/MirLua/src/version.h +++ b/plugins/MirLua/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 7
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
|