diff options
Diffstat (limited to 'plugins/MirLua/src/mlua.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 89 |
1 files changed, 68 insertions, 21 deletions
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 9c5f9a8906..5945947441 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -2,6 +2,16 @@ CMLua::CMLua() : L(NULL)
{
+ Load();
+}
+
+CMLua::~CMLua()
+{
+ Unload();
+}
+
+void CMLua::Load()
+{
L = luaL_newstate();
luaL_openlibs(L);
@@ -12,27 +22,72 @@ CMLua::CMLua() : L(NULL) lua_setfield(L, -2, "cpath");
lua_pop(L, 1);
+ LoadMirandaModules();
+}
+
+void CMLua::Unload()
+{
+ if (L)
+ lua_close(L);
+}
+
+void CMLua::Reload()
+{
+ /*lua_getglobal(L, "m");
+ lua_getfield(L, -1, "OnPreShutdown");
+ if (lua_isfunction(L, -1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ lua_pushlightuserdata(L, NULL);
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+ }
+ lua_pop(L, 1);*/
+ Unload();
+
+ Load();
+ /*lua_getglobal(L, "m");
+ lua_getfield(L, -1, "OnModulesLoaded");
+ if (lua_isfunction(L, -1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ lua_pushlightuserdata(L, NULL);
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+ }
+ lua_pop(L, 1);*/
+}
+
+void CMLua::LoadModule(const char *name, lua_CFunction loader)
+{
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
+ lua_pushcfunction(L, loader);
+ lua_setfield(L, -2, name);
+ lua_pop(L, 1);
+}
+
+void CMLua::LoadCoreModule()
+{
luaL_newlib(L, coreLib);
lua_pushlightuserdata(L, NULL); lua_setfield(L, -2, "NULL");
lua_setglobal(L, "m");
-
- Preload(MLUA_DATABASE, luaopen_m_database);
- Preload(MLUA_ICOLIB, luaopen_m_icolib);
- Preload(MLUA_GENMENU, luaopen_m_genmenu);
- Preload(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar);
- Preload(MLUA_POPUP, luaopen_m_popup);
- Preload(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar);
- Preload(MLUA_VARIABLES, luaopen_m_variables);
}
-CMLua::~CMLua()
+void CMLua::LoadMirandaModules()
{
- if(L)
- lua_close(L);
+ LoadCoreModule();
+
+ LoadModule(MLUA_DATABASE, luaopen_m_database);
+ LoadModule(MLUA_ICOLIB, luaopen_m_icolib);
+ LoadModule(MLUA_GENMENU, luaopen_m_genmenu);
+ LoadModule(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar);
+ LoadModule(MLUA_POPUP, luaopen_m_popup);
+ LoadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar);
+ LoadModule(MLUA_VARIABLES, luaopen_m_variables);
}
-void CMLua::AddPath(const char *path)
+void CMLua::AddScriptsPath(const char *path)
{
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
@@ -43,20 +98,12 @@ void CMLua::AddPath(const char *path) lua_pop(L, 1);
}
-void CMLua::Load(const char *path)
+void CMLua::LoadScript(const char *path)
{
if (luaL_dofile(L, path))
printf("%s\n", lua_tostring(L, -1));
}
-void CMLua::Preload(const char *name, lua_CFunction loader)
-{
- luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
- lua_pushcfunction(L, loader);
- lua_setfield(L, -2, name);
- lua_pop(L, 1);
-}
-
WPARAM CMLua::GetWParam(lua_State *L, int idx)
{
WPARAM wParam = NULL;
|