-
Notifications
You must be signed in to change notification settings - Fork 2
/
LuaPlayer.hpp
93 lines (79 loc) · 1.76 KB
/
LuaPlayer.hpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef LUAPLAYER_HPP
#define LUAPLAYER_HPP
#include <iostream>
#include <string>
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
}
#include "luawrapper.hpp"
#include "Player.hpp"
Player* Player_new(lua_State* L)
{
const char* name = luaL_checkstring(L, 1);
unsigned int health = luaL_checkinteger(L, 2);
return new Player(name, health);
}
int Player_getName(lua_State* L)
{
Player* player = luaW_check<Player>(L, 1);
lua_pushstring(L, player->getName());
return 1;
}
int Player_getHealth(lua_State* L)
{
Player* player = luaW_check<Player>(L, 1);
lua_pushinteger(L, player->getHealth());
return 1;
}
int Player_setHealth(lua_State* L)
{
Player* player = luaW_check<Player>(L, 1);
unsigned int health = luaL_checkinteger(L, 2);
player->setHealth(health);
return 0;
}
int Player_heal(lua_State* L)
{
Player* player = luaW_check<Player>(L, 1);
Player* target = luaW_check<Player>(L, 2);
player->heal(target);
return 0;
}
int Player_say(lua_State* L)
{
Player* player = luaW_check<Player>(L, 1);
const char* text = luaL_checkstring(L, 2);
player->say(text);
return 0;
}
int Player_info(lua_State* L)
{
Player* player = luaW_check<Player>(L, 1);
player->info();
return 0;
}
static luaL_Reg Player_table[] = {
{ NULL, NULL }
};
static luaL_Reg Player_metatable[] = {
{ "getName", Player_getName },
{ "getHealth", Player_getHealth },
{ "setHealth", Player_setHealth },
{ "heal", Player_heal },
{ "say", Player_say },
{ "info", Player_info },
{ NULL, NULL }
};
int luaopen_Player(lua_State* L)
{
luaW_register<Player>(L,
"Player",
Player_table,
Player_metatable,
Player_new
);
return 1;
}
#endif // LUAPLAYER_HPP