diff options
Diffstat (limited to 'plugins/MirLua/src/mlua_script.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_script.cpp | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 310fecddf9..83b5008e15 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -28,29 +28,10 @@ CMLuaScript::CMLuaScript(const CMLuaScript &script) CMLuaScript::~CMLuaScript()
{
- if (status == Loaded)
- {
- lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef);
- if (lua_isfunction(L, -1))
- luaM_pcall(L);
- lua_pushnil(L);
- lua_rawsetp(L, LUA_REGISTRYINDEX, this);
- status = None;
- }
-
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
- lua_pushnil(L);
- lua_setfield(L, -2, moduleName);
- lua_pop(L, 1);
-
+ Unload();
mir_free(moduleName);
}
-const char* CMLuaScript::GetModuleName() const
-{
- return moduleName;
-}
-
const wchar_t* CMLuaScript::GetFilePath() const
{
return filePath;
@@ -61,6 +42,21 @@ const wchar_t* CMLuaScript::GetFileName() const return fileName;
}
+bool CMLuaScript::IsEnabled()
+{
+ return db_get_b(NULL, MODULE, _T2A(fileName), 1);
+}
+
+void CMLuaScript::Enable()
+{
+ db_unset(NULL, MODULE, _T2A(fileName));
+}
+
+void CMLuaScript::Disable()
+{
+ db_set_b(NULL, MODULE, _T2A(fileName), 0);
+}
+
CMLuaScript::Status CMLuaScript::GetStatus() const
{
return status;
@@ -85,7 +81,7 @@ bool CMLuaScript::Load() if (lua_isnoneornil(L, -1))
return true;
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
lua_getfield(L, -1, moduleName);
if (!lua_toboolean(L, -1)) {
lua_pop(L, 1);
@@ -115,4 +111,27 @@ bool CMLuaScript::Load() lua_pop(L, 1);
return true;
-}
\ No newline at end of file +}
+
+void CMLuaScript::Unload()
+{
+ if (status == Loaded) {
+ lua_rawgeti(L, LUA_REGISTRYINDEX, unloadRef);
+ if (lua_isfunction(L, -1))
+ luaM_pcall(L);
+ lua_pushnil(L);
+ lua_rawsetp(L, LUA_REGISTRYINDEX, this);
+ status = None;
+ }
+
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
+ lua_pushnil(L);
+ lua_setfield(L, -2, moduleName);
+ lua_pop(L, 1);
+}
+
+bool CMLuaScript::Reload()
+{
+ Unload();
+ return Load();
+}
|