diff options
author | aunsane <aunsane@gmail.com> | 2018-03-22 01:53:49 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-03-22 01:54:09 +0300 |
commit | 2a498d86625f65f6ab308fa20c421099c785bf94 (patch) | |
tree | 9c0d59f41411e46288f88ccdbde4a0d23f440720 /plugins/MirLua/src/mlua_script.cpp | |
parent | 46cded99bbfb90bea8e998e9183c20cc3e4f7365 (diff) |
MirLua: various fixes
- CMLua now inherit PLUGIN
- additional lua fuctions initialization moved to separated loader
- ability to realod script without object recreation
- scropt object should control own enable state
- fix m_json whit is not workes almost at all
- version bump
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();
+}
|