summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_script.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-02-15 17:09:42 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-02-15 17:09:42 +0000
commit06c13fcc7c6c9b7b8448e550568c5993dbd96628 (patch)
tree8ba39163ab86765cfeed6b8d73d528ee6dd9bd33 /plugins/MirLua/src/mlua_script.cpp
parenta7967e3364a0b5528433de65cfbb743c57625e72 (diff)
MirLua: returned ability to reload single script
git-svn-id: http://svn.miranda-ng.org/main/trunk@16282 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_script.cpp')
-rw-r--r--plugins/MirLua/src/mlua_script.cpp79
1 files changed, 72 insertions, 7 deletions
diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp
index 26c4006e2d..6a51046a94 100644
--- a/plugins/MirLua/src/mlua_script.cpp
+++ b/plugins/MirLua/src/mlua_script.cpp
@@ -1,7 +1,9 @@
#include "stdafx.h"
+#define SCRIPT "Script"
+
CMLuaScript::CMLuaScript(lua_State *L, const TCHAR *path)
- : L(L), status(None), unloadRef(0)
+ : L(L), status(None)
{
mir_tstrcpy(filePath, path);
@@ -14,6 +16,9 @@ CMLuaScript::CMLuaScript(lua_State *L, const TCHAR *path)
mir_tstrncpy(name, fileName, length);
moduleName = mir_utf8encodeT(name);
+
+ MUUID muidLast = MIID_LAST;
+ id = GetPluginLangId(muidLast, 0);
}
CMLuaScript::~CMLuaScript()
@@ -21,6 +26,49 @@ CMLuaScript::~CMLuaScript()
mir_free(moduleName);
}
+/*const int CMLuaScript::GetId() const
+{
+ return id;
+}*/
+
+CMLuaScript* CMLuaScript::GetScriptFromEnviroment(lua_State *L, int n)
+{
+ CMLuaScript *script = NULL;
+
+ int top = lua_gettop(L);
+
+ lua_Debug ar;
+ if (lua_getstack(L, 1, &ar) == 0 || lua_getinfo(L, "f", &ar) == 0 || lua_iscfunction(L, -1))
+ {
+ top = lua_gettop(L);
+ lua_pop(L, 1);
+ return script;
+ }
+
+ const char *env = lua_getupvalue(L, n, 1);
+ if (!env || mir_strcmp(env, "_ENV") != 0)
+ {
+ top = lua_gettop(L);
+ lua_pop(L, 1);
+ return script;
+ }
+
+ lua_getfield(L, -1, SCRIPT);
+ script = (CMLuaScript*)lua_touserdata(L, -1);
+ lua_pop(L, 3);
+
+ return script;
+}
+
+int CMLuaScript::GetScriptIdFromEnviroment(lua_State *L, int n)
+{
+ CMLuaScript *script = GetScriptFromEnviroment(L, n);
+ if (script != NULL)
+ return script->id;
+
+ return hLangpack;
+}
+
const char* CMLuaScript::GetModuleName() const
{
return moduleName;
@@ -43,16 +91,20 @@ const CMLuaScript::Status CMLuaScript::GetStatus() const
bool CMLuaScript::Load()
{
+ status = Failed;
+
if (luaL_loadfile(L, T2Utf(filePath)))
{
Log(lua_tostring(L, -1));
return false;
}
- lua_createtable(L, 0, 1);
+ lua_createtable(L, 0, 2);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "_G");
- lua_createtable(L, 0, 1);
+ lua_pushlightuserdata(L, this);
+ lua_setfield(L, -2, "Script");
+ lua_createtable(L, 0, 2);
lua_getglobal(L, "_G");
lua_setfield(L, -2, "__index");
lua_setmetatable(L, -2);
@@ -61,6 +113,8 @@ bool CMLuaScript::Load()
if (luaM_pcall(L, 0, 1))
return false;
+ status = Loaded;
+
if (lua_isnoneornil(L, -1))
return true;
@@ -89,7 +143,8 @@ bool CMLuaScript::Load()
if (lua_isfunction(L, -1))
{
lua_pushvalue(L, -1);
- unloadRef = luaL_ref(L, LUA_REGISTRYINDEX);
+ lua_rawsetp(L, LUA_REGISTRYINDEX, this);
+ //unloadRef = luaL_ref(L, LUA_REGISTRYINDEX);
}
lua_pop(L, 1);
@@ -100,12 +155,14 @@ bool CMLuaScript::Load()
void CMLuaScript::Unload()
{
- if (status == Loaded && unloadRef)
+ if (status == Loaded)
{
- lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef);
+ lua_rawgetp(L, LUA_REGISTRYINDEX, this);
+ //lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef);
if (lua_isfunction(L, -1))
luaM_pcall(L);
- luaL_unref(L, LUA_REGISTRYINDEX, unloadRef);
+ lua_pushnil(L);
+ lua_rawsetp(L, LUA_REGISTRYINDEX, this);
status = None;
}
@@ -116,4 +173,12 @@ void CMLuaScript::Unload()
lua_pushnil(L);
lua_setglobal(L, moduleName);
+
+ KillModuleIcons(id);
+ KillModuleSounds(id);
+ KillModuleMenus(id);
+ KillModuleHotkeys(id);
+
+ KillObjectEventHooks(this);
+ KillObjectServices(this);
} \ No newline at end of file