diff options
author | aunsane <aunsane@gmail.com> | 2017-09-29 00:22:53 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-09-29 00:39:19 +0300 |
commit | 8d706b4ef942e01814f0a9db519aa32505b9abed (patch) | |
tree | ec3cd0464d4862f42041936958595c057abdfb78 /plugins/MirLua/src/mlua.cpp | |
parent | af9c3d7de7e35632d046575b5e4809a04abec816 (diff) |
MirLua: added service functions to execute lua code
version bump
Diffstat (limited to 'plugins/MirLua/src/mlua.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 5229196f64..4dc3a2775a 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -265,7 +265,6 @@ void CMLua::Unload() {
CMLuaScript *script = g_mLua->Scripts[last - 1];
Scripts.remove(script);
- script->Unload();
delete script;
}
@@ -304,3 +303,83 @@ void CMLua::KillLuaRefs() }
}
}
+
+/***********************************************/
+
+static int mlua_call(lua_State *L)
+{
+ const char *module = luaL_checkstring(L, -3);
+ const char *function = luaL_checkstring(L, -2);
+
+ if (module && module[0])
+ {
+ lua_getglobal(L, "require");
+ lua_pushstring(L, module);
+ lua_pcall(L, 1, 1, 0);
+
+ lua_getfield(L, -1, function);
+ lua_replace(L, -2);
+ }
+ else
+ lua_getglobal(L, function);
+
+ lua_pcall(L, 0, 1, 0);
+
+ return 1;
+}
+
+INT_PTR CMLua::Call(WPARAM wParam, LPARAM lParam)
+{
+ const wchar_t *module = (const wchar_t*)wParam;
+ const wchar_t *function = (const wchar_t*)lParam;
+
+ lua_pushstring(L, ptrA(mir_utf8encodeW(module)));
+ lua_pushstring(L, ptrA(mir_utf8encodeW(function)));
+
+ lua_newtable(L);
+ lua_pushcclosure(L, mlua_call, 1);
+
+ CMLuaEnviroment env(L);
+ env.Load();
+
+ wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ return (INT_PTR)result;
+}
+
+INT_PTR CMLua::Exec(WPARAM, LPARAM lParam)
+{
+ const wchar_t *path = (const wchar_t*)lParam;
+
+ if (luaL_loadfile(L, ptrA(mir_utf8encodeW(path)))) {
+ ReportError(L);
+ return NULL;
+ }
+
+ CMLuaEnviroment env(L);
+ env.Load();
+
+ wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ return (INT_PTR)result;
+}
+
+INT_PTR CMLua::Eval(WPARAM, LPARAM lParam)
+{
+ const wchar_t *script = (const wchar_t*)lParam;
+
+ if (luaL_loadstring(L, ptrA(mir_utf8encodeW(script)))) {
+ ReportError(L);
+ return NULL;
+ }
+
+ CMLuaEnviroment env(L);
+ env.Load();
+
+ wchar_t *result = mir_utf8decodeW(lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ return (INT_PTR)result;
+}
\ No newline at end of file |