summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua.cpp
blob: 382591e919458a1fd794886201f5402d553e7a08 (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
#include "stdafx.h"

CMLua::CMLua()
{
	L = luaL_newstate();
	luaL_openlibs(L);

	luaopen_m(L);

	Preload(LUA_CLISTLIBNAME, luaopen_m_clist);
}

CMLua::~CMLua()
{
	lua_close(L);
}

void CMLua::Load(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);
}