summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_enum.cpp
blob: 1ccc900dc42d86034c5afe6072a5ce2ff50286e7 (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 "luax_enum.h"
#include "luax_state.h"
#include "luax_runtime.h"

namespace Luax
{

	///
	/// ֻmetatable__index
	///
	int l_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 l_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);
	}

}