-
Notifications
You must be signed in to change notification settings - Fork 0
/
LuaVM.cpp
85 lines (69 loc) · 1.46 KB
/
LuaVM.cpp
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
#include "LuaVM.hpp"
LuaVM::LuaVM ( lua_State * state )
{
L = state;
}
template<>
void LuaVM::Push<std::string> ( const std::string& value )
{
lua_pushlstring ( L, value.c_str ( ), value.length ( ) );
++numReturns;
}
template<>
void LuaVM::Push<const char*> ( const char* const& value )
{
lua_pushstring ( L, value );
++numReturns;
}
template<>
void LuaVM::Push<char*> ( char* const& value )
{
lua_pushstring ( L, value );
++numReturns;
}
template<>
void LuaVM::Push<bool> ( const bool& value )
{
lua_pushboolean ( L, value );
++numReturns;
}
template<>
void LuaVM::Push<double> ( const double& value )
{
lua_pushnumber ( L, value );
++numReturns;
}
template<>
void LuaVM::Push<int> ( const int& value )
{
lua_pushnumber ( L, value );
++numReturns;
}
template<>
void LuaVM::Push<float> ( const float& value )
{
lua_pushnumber ( L, value );
++numReturns;
}
template<>
bool LuaVM::DoesTypeAtIndexMatch<int> ( unsigned int currentIndex )
{
return lua_isnumber ( L, currentIndex ) != 0;
}
template<>
bool LuaVM::DoesTypeAtIndexMatch<std::string> ( unsigned int currentIndex )
{
return lua_isstring ( L, currentIndex ) != 0;
}
template<>
void LuaVM::Pop<int> ( int& value )
{
value = static_cast<int>( lua_tonumber ( L, currentIndex ) );
}
template<>
void LuaVM::Pop<std::string> ( std::string& value )
{
size_t len;
const char *tmp = lua_tolstring ( L, currentIndex, &len );
value.assign ( tmp, len );
}