From d93bdfc096f018d3b9c80dad756e5b573e886f68 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 9 Jun 2015 06:44:57 +0000 Subject: MirLua: - added loading of internal modules - added loading of lua scripts - added folders plugin support git-svn-id: http://svn.miranda-ng.org/main/trunk@14069 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/mlua.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'plugins/MirLua/src/mlua.cpp') diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index ee6d91e117..04200e3777 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -1,20 +1,28 @@ -#include "stdafx.h" - +#include "stdafx.h" + CMLua::CMLua() { - lua = luaL_newstate(); + L = luaL_newstate(); + luaL_openlibs(L); + + luaL_newlib(L, CMLua::coreFunctions); + lua_setglobal(L, "M"); +} + +CMLua::~CMLua() +{ + lua_close(L); +} - luaL_openlibs(lua); - luaL_newlib(lua, CMLua::CoreFunctions); - lua_setglobal(lua, "M"); +void CMLua::Load(const char *path) +{ + luaL_dofile(L, path); } -CMLua::~CMLua() -{ - lua_close(lua); -} - -void CMLua::Load(const char *name) -{ - luaL_dofile(lua, name); +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); } \ No newline at end of file -- cgit v1.2.3