summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/LuaBindEnum.cpp
blob: 849fb8a00233906141be51637d82c9faf3855e84 (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
34
35
36
37
#include "LuaBindEnum.h"
#include "LuaBindState.h"
#include "LuaBindVM.h"

namespace LuaBind
{

	//
	// Ö»¶ÁmetatableµÄ__index
	//
	int _rmt__index(lua_State* L)
	{
		// params:
		// 1: enum table
		// 2: key

		// upvalues: 
		// 1: metatable

		int mt = lua_upvalueindex(1);
		lua_pushvalue(L, 2);
		lua_rawget(L, mt);

		return 1;
	}

	int _rmt__newindex(lua_State* L)
	{
		// upvalue: 
		// 1: enum table name

		cc8* name = lua_tostring(L, lua_upvalueindex(1));

		return luaL_error(L, "Enum called \"%s\" is readonly.", name);
	}

}