diff options
author | aunsane <aunsane@gmail.com> | 2017-09-28 20:16:27 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-09-29 00:38:40 +0300 |
commit | af9c3d7de7e35632d046575b5e4809a04abec816 (patch) | |
tree | d25ed109332d38540d6b044bd4471e4fc2d1b0c5 /plugins/MirLua/src/mlua_script.cpp | |
parent | b640e652b54030de26a22f57494fa71561dd4e99 (diff) |
MirLua: added CMLuaEnviroment to execute lua code from extetnal source in sandbox
Diffstat (limited to 'plugins/MirLua/src/mlua_script.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_script.cpp | 54 |
1 files changed, 3 insertions, 51 deletions
diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp index 280452d068..6fbcfc9ac7 100644 --- a/plugins/MirLua/src/mlua_script.cpp +++ b/plugins/MirLua/src/mlua_script.cpp @@ -3,7 +3,7 @@ #define MT_SCRIPT "SCRIPT"
CMLuaScript::CMLuaScript(lua_State *L, const wchar_t *path)
- : L(L), status(None), unloadRef(LUA_NOREF)
+ : CMLuaEnviroment(L)
{
mir_wstrcpy(filePath, path);
@@ -16,9 +16,6 @@ CMLuaScript::CMLuaScript(lua_State *L, const wchar_t *path) mir_wstrncpy(name, fileName, length);
moduleName = mir_utf8encodeW(name);
-
- MUUID muidLast = MIID_LAST;
- id = GetPluginLangId(muidLast, 0);
}
CMLuaScript::~CMLuaScript()
@@ -26,32 +23,6 @@ CMLuaScript::~CMLuaScript() mir_free(moduleName);
}
-CMLuaScript* CMLuaScript::GetScriptFromEnviroment(lua_State *L)
-{
- if (!luaM_getenv(L))
- return NULL;
-
- lua_rawgeti(L, -1, NULL);
- CMLuaScript *script = (CMLuaScript*)lua_touserdata(L, -1);
- lua_pop(L, 3);
-
- return script;
-}
-
-int CMLuaScript::GetScriptIdFromEnviroment(lua_State *L)
-{
- CMLuaScript *script = GetScriptFromEnviroment(L);
- if (script != NULL)
- return script->GetId();
-
- return hMLuaLangpack;
-}
-
-int CMLuaScript::GetId() const
-{
- return id;
-}
-
const char* CMLuaScript::GetModuleName() const
{
return moduleName;
@@ -82,20 +53,7 @@ bool CMLuaScript::Load() return false;
}
- lua_createtable(L, 1, 1);
- lua_pushlightuserdata(L, this);
- lua_rawseti(L, -2, NULL);
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "_G");
- lua_createtable(L, 0, 2);
- lua_pushliteral(L, MT_SCRIPT);
- lua_setfield(L, -2, "__metatable");
- lua_getglobal(L, "_G");
- lua_setfield(L, -2, "__index");
- lua_setmetatable(L, -2);
- lua_setupvalue(L, -2, 1);
-
- if (luaM_pcall(L, 0, 1))
+ if (!CMLuaEnviroment::Load(-1))
return false;
status = Loaded;
@@ -154,11 +112,5 @@ void CMLuaScript::Unload() lua_setfield(L, -2, moduleName);
lua_pop(L, 1);
- KillModuleIcons(id);
- KillModuleSounds(id);
- KillModuleMenus(id);
- KillModuleHotkeys(id);
-
- KillObjectEventHooks(this);
- KillObjectServices(this);
+ CMLuaEnviroment::Unload();
}
\ No newline at end of file |