UGDK
0.4.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
basegear.h
Go to the documentation of this file.
1
2
#ifndef UGDK_SCRIPT_LUA_BASEGEAR_H_
3
#define UGDK_SCRIPT_LUA_BASEGEAR_H_
4
5
#include <vector>
6
#include <
ugdk/portable/tr1.h
>
7
#include FROM_TR1(tuple)
8
9
#include <
ugdk/script/languages/lua/header.h
>
10
#include <
ugdk/script/languages/lua/state.h
>
11
12
#include <
ugdk/util/uncopyable.h
>
13
14
namespace
ugdk {
15
namespace
script {
16
namespace
lua {
17
18
class
BaseGear
{
19
20
public
:
21
22
class
InternalSafeCall
{
23
24
public
:
25
26
~InternalSafeCall
() { gear_->
settop
(old_top_); }
27
28
template
<
class
A1>
29
InternalSafeCall
&
Arg
(A1 a1) {
30
gear_->
pushprimitive
<A1>(a1);
31
++arg_num_;
32
return
*
this
;
33
}
34
35
template
<
class
R>
36
R
GetResult
(
const
R default_value) {
37
R result = default_value;
38
if
(gear_.
TracedCall
(arg_num_,1) == Constant::OK())
39
result = gear_->
toprimitive
<R>(-1);
40
arg_num_ = 0;
41
return
result;
42
}
43
44
bool
NoResult
() {
45
return
gear_.
TracedCall
(arg_num_,0) == Constant::OK();
46
}
47
48
private
:
49
50
friend
class
BaseGear
;
51
52
InternalSafeCall
(
BaseGear
& gear,
lua_CFunction
func) :
53
gear_(gear),
54
old_top_(gear->gettop()),
55
arg_num_(1) {
56
gear_->
pushcfunction
(func);
57
gear_->
pushudata
(&gear_);
58
}
59
60
InternalSafeCall
& operator=(
const
InternalSafeCall
& rhs);
61
62
BaseGear
& gear_;
63
int
old_top_;
64
unsigned
int
arg_num_;
65
66
};
67
68
InternalSafeCall
SafeCall
(
lua_CFunction
func) {
69
return
InternalSafeCall
(*
this
, func);
70
}
71
72
State
*
operator->
() {
return
&
L_
; }
73
75
80
const
Constant
TracedCall
(
int
nargs,
int
nres);
81
82
const
Constant
Report
(
const
Constant
& c);
83
84
protected
:
85
86
friend
class
InternalSafeCall
;
87
88
State
L_
;
89
90
BaseGear
(
lua_State
*
L
) :
91
L_
(L) {}
92
93
~BaseGear
() {}
94
95
State
&
L
() {
return
L_
; }
96
};
97
98
#define GETARGPTR(L,i,T,name) \
99
T* name = static_cast<T*>((L).touserdata(i))
100
101
#define GETARG(L,i,T,name) \
102
T& name = *(static_cast<T*>((L).touserdata(i)))
103
104
}
/* namespace lua */
105
}
/* namespace script */
106
}
/* namespace ugdk */
107
108
#endif
/* UGDK_SCRIPT_LUA_BASEGEAR_H_ */
src
ugdk
script
languages
lua
basegear.h
Generated on Sat Oct 13 2012 02:25:11 for UGDK by
1.8.2