summaryrefslogtreecommitdiff
path: root/plugins/MirLua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua')
-rw-r--r--plugins/MirLua/src/mlua.cpp6
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp35
2 files changed, 30 insertions, 11 deletions
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
index 8a9b0ce87c..afa7d7b04c 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mlua.cpp
@@ -61,7 +61,11 @@ void CMLua::Load()
lua_pushstring(L, "__mod");
lua_pushcfunction(L, luaM_interpolate);
lua_rawset(L, -3);
- lua_pop(L, 2);
+ lua_pushstring(L, "__index");
+ lua_rawget(L, -2);
+ lua_pushcfunction(L, luaM_interpolate);
+ lua_setfield(L, -2, "interpolate");
+ lua_pop(L, 3);
lua_atpanic(L, luaM_atpanic);
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index c0b6629ffc..d5ca5ed0bb 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -168,18 +168,33 @@ int luaM_tonumber(lua_State *L)
int luaM_interpolate(lua_State *L)
{
const char *string = luaL_checkstring(L, 1);
- luaL_checktype(L, 2, LUA_TTABLE);
- for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2))
+ if (lua_istable(L, 2))
{
- lua_pushvalue(L, -2);
- 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);
+ for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2))
+ {
+ lua_pushvalue(L, -2);
+ 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);
+ }
+ }
+ else
+ {
+ int nargs = lua_gettop(L);
+ for (int i = 2; i <= nargs; i++)
+ {
+ 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_pushstring(L, string);