summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_module_loader.cpp
blob: f25b69abde6e80d1b5e49a41ed30f380fdf9e9d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stdafx.h"

CLuaModuleLoader::CLuaModuleLoader(lua_State *L) : L(L)
{
}

void CLuaModuleLoader::PreloadModule(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 CLuaModuleLoader::LoadModules()
{
	// load core module
	luaopen_m(L);
	// regirter delay loading of miranda modules
	PreloadModule(MLUA_DATABASE, luaopen_m_database);
	PreloadModule(MLUA_ICOLIB, luaopen_m_icolib);
	PreloadModule(MLUA_GENMENU, luaopen_m_genmenu);
	PreloadModule(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar);
	PreloadModule(MLUA_POPUP, luaopen_m_popup);
	PreloadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar);
	PreloadModule(MLUA_VARIABLES, luaopen_m_variables);
}

void CLuaModuleLoader::Load(lua_State *L)
{
	CLuaModuleLoader loader(L);
	loader.LoadModules();
}