UGDK
0.4.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
datagear.h
Go to the documentation of this file.
1
2
#ifndef UGDK_SCRIPT_LUA_DATAGEAR_H_
3
#define UGDK_SCRIPT_LUA_DATAGEAR_H_
4
5
#include <
ugdk/script/type.h
>
6
#include <
ugdk/script/languages/lua/header.h
>
7
#include <
ugdk/script/languages/lua/state.h
>
8
#include <
ugdk/script/languages/lua/basegear.h
>
9
#include <
ugdk/util/uncopyable.h
>
10
#include <
ugdk/util/idgenerator.h
>
11
12
namespace
ugdk {
13
namespace
script {
14
namespace
lua {
15
16
class
DataGear
:
public
BaseGear
,
private
ugdk::util::Uncopyable
{
17
18
public
:
19
20
/*DataGear(lua_State* L, DataID datatable_id) :
21
BaseGear(L),
22
datatable_id_(datatable_id) {}*/
23
24
DataGear
(
lua_State
*
L
) :
25
BaseGear
(L),
26
idgen_(1, INT_MAX, 0) {}
27
28
~DataGear
() {
29
L_
.
pushnil
();
30
L_
.
setfield
(Constant::REGISTRYINDEX(),
"UGDK_LUA_DATATABLE"
);
31
/*L_.aux().unref(Constant::REGISTRYINDEX(), datatable_id_);
32
datatable_id_ = LUA_NOREF;*/
33
L_
.
close
();
34
}
35
37
static
int
GenerateID
(
lua_State
*
L
);
38
40
static
int
DestroyID
(
lua_State
*
L
);
41
43
static
int
WrapData
(
lua_State
*
L
);
44
46
template
<
class
T>
47
static
int
WrapPrimitive
(
lua_State
*
L
);
48
50
static
int
UnwrapData
(
lua_State
*
L
);
51
53
template
<
class
T>
54
static
int
UnwrapPrimitive
(
lua_State
*
L
);
55
56
static
int
UnwrapList
(
lua_State
*
L
);
57
static
int
UnwrapTable
(
lua_State
*
L
);
58
60
67
static
int
Execute
(
lua_State
*
L
);
68
70
77
static
int
GetField
(
lua_State
*
L
);
78
80
88
static
int
SetField
(
lua_State
*
L
);
89
90
static
int
DoFile
(
lua_State
*
L
);
91
92
static
int
DoString
(
lua_State
*
L
);
93
94
// [-0,+1]
95
bool
GetData
(
DataID
id
);
96
97
// [-1,+0]
98
bool
SetData
(
DataID
id
);
99
100
// [-0,+0]
101
bool
HasValue
(
DataID
id
);
102
103
private
:
104
105
//DataID datatable_id_;
106
ugdk::util::IDGenerator
idgen_;
107
108
DataGear
& operator=(
const
DataGear
& rhs) {
109
return
*
this
;
110
}
111
113
bool
PushDataTable();
114
116
void
PushData (
int
table_index,
DataID
id
) {
117
L_
.
rawgeti
(table_index,
id
);
118
}
119
121
void
PopData (
int
table_index,
DataID
id
) {
122
L_
.
rawseti
(table_index,
id
);
123
}
124
125
};
126
127
template
<
class
T>
128
int
DataGear::UnwrapPrimitive
(
lua_State
* L) {
129
State
L_
(L);
130
131
L_.
settop
(2);
132
GETARG
(L_, 1,
DataGear
, dtgear);
133
DataID
id
= L_.
aux
().
checkintteger
(2);
134
L_.
settop
(0);
135
136
if
(!dtgear.GetData(
id
)) {
137
L_.
pushnil
();
138
}
// else the data will already be on top
139
140
if
(!L_.
isprimitive
<T>(-1))
141
return
luaL_error(L,
"Could not unwrap primitive from id #%d"
,
id
);
142
143
return
1;
144
}
145
146
template
<
class
T>
147
int
DataGear::WrapPrimitive
(
lua_State
* L) {
148
State
L_
(L);
149
150
L_.
settop
(3);
151
GETARG
(L_, 1,
DataGear
, dtgear);
152
DataID
id
= L_.
aux
().
checkintteger
(2);
153
//T value = L_.aux().checkprimitive<T>(3);
154
//UData data = L_.touserdata(3);
155
//GETARGPTR(L_, 4, swig_type_info, type);
156
//L_.settop(0);
157
158
if
(!L_.
isprimitive
<T>(3) || !dtgear.SetData(
id
))
159
return
luaL_error(L,
"Could not wrap primitive with id #%d"
,
id
);
160
161
//SWIG_NewPointerObj(L_, data, type, 0);
162
//if (!dtgear.SetData(id))
163
// return luaL_error(L, "Could not wrap primitive with id #%d", id);
164
165
return
0;
166
}
167
168
}
/* namespace lua */
169
}
/* namespace script */
170
}
/* namespace ugdk */
171
172
#endif
/* UGDK_SCRIPT_LUA_DATAGEAR_H_ */
src
ugdk
script
languages
lua
datagear.h
Generated on Sat Oct 13 2012 02:25:11 for UGDK by
1.8.2