From 2258b1b2cf951347d167d01201f0dc4bbf9a4428 Mon Sep 17 00:00:00 2001 From: aunsane Date: Tue, 26 Sep 2017 23:32:12 +0300 Subject: MirLua: refactoring - respect metatables in print function - srmm module functions now return metatable - version bump --- plugins/MirLua/src/mlua.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'plugins/MirLua/src/mlua.cpp') diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index d3c835ee7d..5229196f64 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -42,6 +42,21 @@ static int mlua_print(lua_State *L) data.AppendFormat("%s", lua_tostring(L, i)); break; default: + if (lua_getmetatable(L, 1)) + { + if (lua_getfield(L, -1, "__tostring") == LUA_TFUNCTION) + { + lua_pushvalue(L, 1); + if (luaM_pcall(L, 1, 1) == LUA_OK) + { + data.AppendFormat("%s", lua_tostring(L, -1)); + lua_pop(L, 2); + break; + } + lua_pop(L, 2); + } + lua_pop(L, 1); + } data.AppendFormat("%s(0x%p)", luaL_typename(L, i), lua_topointer(L, i)); break; } -- cgit v1.2.3