summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_script.cpp
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-09-12 22:02:30 +0300
committeraunsane <aunsane@gmail.com>2017-09-12 22:03:37 +0300
commit6f99f13cf590c323fd5bd5b4d6855e59f582fb0e (patch)
tree4b9a66758433be8273c7c20e06ab305901b4fdfb /plugins/MirLua/src/mlua_script.cpp
parent6611ef6791a897d23cb79ab7b56eb48d49452b80 (diff)
MirLua: massive refactoring
- m_msg_buttonbar moved to m_srrm - version bump
Diffstat (limited to 'plugins/MirLua/src/mlua_script.cpp')
-rw-r--r--plugins/MirLua/src/mlua_script.cpp33
1 files changed, 8 insertions, 25 deletions
diff --git a/plugins/MirLua/src/mlua_script.cpp b/plugins/MirLua/src/mlua_script.cpp
index f4cfef8c7c..280452d068 100644
--- a/plugins/MirLua/src/mlua_script.cpp
+++ b/plugins/MirLua/src/mlua_script.cpp
@@ -1,6 +1,6 @@
#include "stdafx.h"
-#define SCRIPT "Script"
+#define MT_SCRIPT "SCRIPT"
CMLuaScript::CMLuaScript(lua_State *L, const wchar_t *path)
: L(L), status(None), unloadRef(LUA_NOREF)
@@ -26,31 +26,12 @@ CMLuaScript::~CMLuaScript()
mir_free(moduleName);
}
-bool CMLuaScript::GetEnviroment(lua_State *L)
-{
- lua_Debug ar;
- if (lua_getstack(L, 1, &ar) == 0 || lua_getinfo(L, "f", &ar) == 0 || lua_iscfunction(L, -1))
- {
- lua_pop(L, 1);
- return false;
- }
-
- const char *env = lua_getupvalue(L, -1, 1);
- if (!env || mir_strcmp(env, "_ENV") != 0)
- {
- lua_pop(L, 1);
- return false;
- }
-
- return true;
-}
-
CMLuaScript* CMLuaScript::GetScriptFromEnviroment(lua_State *L)
{
- if (!GetEnviroment(L))
+ if (!luaM_getenv(L))
return NULL;
- lua_getfield(L, -1, SCRIPT);
+ lua_rawgeti(L, -1, NULL);
CMLuaScript *script = (CMLuaScript*)lua_touserdata(L, -1);
lua_pop(L, 3);
@@ -101,12 +82,14 @@ bool CMLuaScript::Load()
return false;
}
- lua_createtable(L, 0, 2);
+ lua_createtable(L, 1, 1);
+ lua_pushlightuserdata(L, this);
+ lua_rawseti(L, -2, NULL);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "_G");
- lua_pushlightuserdata(L, this);
- lua_setfield(L, -2, "Script");
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);