2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
7 #ifndef CAFU_TYPESYS_VAR_VISITORS_LUA_HPP_INCLUDED
8 #define CAFU_TYPESYS_VAR_VISITORS_LUA_HPP_INCLUDED
10 #include "Variables.hpp"
20 /// This visitor is used to implement a "get()" function in Lua:
21 /// It pushes the value(s) of the visited variable onto the Lua stack.
22 class VarVisitorGetToLuaT
: public cf::TypeSys::VisitorConstT
26 VarVisitorGetToLuaT(lua_State
* LuaState
);
28 unsigned int GetNumResults() const { return m_NumResults
; }
30 void visit(const cf::TypeSys::VarT
<float>& Var
);
31 void visit(const cf::TypeSys::VarT
<double>& Var
);
32 void visit(const cf::TypeSys::VarT
<int>& Var
);
33 void visit(const cf::TypeSys::VarT
<unsigned int>& Var
);
34 void visit(const cf::TypeSys::VarT
<uint16_t>& Var
);
35 void visit(const cf::TypeSys::VarT
<uint8_t>& Var
);
36 void visit(const cf::TypeSys::VarT
<bool>& Var
);
37 void visit(const cf::TypeSys::VarT
<std::string
>& Var
);
38 void visit(const cf::TypeSys::VarT
<Vector2fT
>& Var
);
39 void visit(const cf::TypeSys::VarT
<Vector3fT
>& Var
);
40 void visit(const cf::TypeSys::VarT
<Vector3dT
>& Var
);
41 void visit(const cf::TypeSys::VarT
<BoundingBox3dT
>& Var
);
42 void visit(const cf::TypeSys::VarArrayT
<uint32_t>& Var
);
43 void visit(const cf::TypeSys::VarArrayT
<uint16_t>& Var
);
44 void visit(const cf::TypeSys::VarArrayT
<uint8_t>& Var
);
45 void visit(const cf::TypeSys::VarArrayT
<std::string
>& Var
);
50 lua_State
* m_LuaState
;
51 unsigned int m_NumResults
;
55 /// This visitor is used to implement a "set()" function in Lua:
56 /// It sets the value of the visited variable to the value(s) taken from the Lua stack.
57 class VarVisitorSetFromLuaT
: public cf::TypeSys::VisitorT
61 VarVisitorSetFromLuaT(lua_State
* LuaState
);
63 void visit(cf::TypeSys::VarT
<float>& Var
);
64 void visit(cf::TypeSys::VarT
<double>& Var
);
65 void visit(cf::TypeSys::VarT
<int>& Var
);
66 void visit(cf::TypeSys::VarT
<unsigned int>& Var
);
67 void visit(cf::TypeSys::VarT
<uint16_t>& Var
);
68 void visit(cf::TypeSys::VarT
<uint8_t>& Var
);
69 void visit(cf::TypeSys::VarT
<bool>& Var
);
70 void visit(cf::TypeSys::VarT
<std::string
>& Var
);
71 void visit(cf::TypeSys::VarT
<Vector2fT
>& Var
);
72 void visit(cf::TypeSys::VarT
<Vector3fT
>& Var
);
73 void visit(cf::TypeSys::VarT
<Vector3dT
>& Var
);
74 void visit(cf::TypeSys::VarT
<BoundingBox3dT
>& Var
);
75 void visit(cf::TypeSys::VarArrayT
<uint32_t>& Var
);
76 void visit(cf::TypeSys::VarArrayT
<uint16_t>& Var
);
77 void visit(cf::TypeSys::VarArrayT
<uint8_t>& Var
);
78 void visit(cf::TypeSys::VarArrayT
<std::string
>& Var
);
83 lua_State
* m_LuaState
;
87 /// This visitor is used to set `float` values in variables that are of type `float`, or composed of `float`.
88 class VarVisitorSetFloatT
: public cf::TypeSys::VisitorT
92 VarVisitorSetFloatT(unsigned int Suffix
, float Value
);
94 void visit(cf::TypeSys::VarT
<float>& Var
);
95 void visit(cf::TypeSys::VarT
<double>& Var
);
96 void visit(cf::TypeSys::VarT
<int>& Var
);
97 void visit(cf::TypeSys::VarT
<unsigned int>& Var
);
98 void visit(cf::TypeSys::VarT
<uint16_t>& Var
);
99 void visit(cf::TypeSys::VarT
<uint8_t>& Var
);
100 void visit(cf::TypeSys::VarT
<bool>& Var
);
101 void visit(cf::TypeSys::VarT
<std::string
>& Var
);
102 void visit(cf::TypeSys::VarT
<Vector2fT
>& Var
);
103 void visit(cf::TypeSys::VarT
<Vector3fT
>& Var
);
104 void visit(cf::TypeSys::VarT
<Vector3dT
>& Var
);
105 void visit(cf::TypeSys::VarT
<BoundingBox3dT
>& Var
);
106 void visit(cf::TypeSys::VarArrayT
<uint32_t>& Var
);
107 void visit(cf::TypeSys::VarArrayT
<uint16_t>& Var
);
108 void visit(cf::TypeSys::VarArrayT
<uint8_t>& Var
);
109 void visit(cf::TypeSys::VarArrayT
<std::string
>& Var
);
114 unsigned int m_Suffix
;
119 /// This visitor writes the value of the visited variable into the given std::ostream,
120 /// formatted as Lua code.
121 class VarVisitorToLuaCodeT
: public cf::TypeSys::VisitorConstT
125 VarVisitorToLuaCodeT(std::ostream
& Out
);
127 void visit(const cf::TypeSys::VarT
<float>& Var
);
128 void visit(const cf::TypeSys::VarT
<double>& Var
);
129 void visit(const cf::TypeSys::VarT
<int>& Var
);
130 void visit(const cf::TypeSys::VarT
<unsigned int>& Var
);
131 void visit(const cf::TypeSys::VarT
<uint16_t>& Var
);
132 void visit(const cf::TypeSys::VarT
<uint8_t>& Var
);
133 void visit(const cf::TypeSys::VarT
<bool>& Var
);
134 void visit(const cf::TypeSys::VarT
<std::string
>& Var
);
135 void visit(const cf::TypeSys::VarT
<Vector2fT
>& Var
);
136 void visit(const cf::TypeSys::VarT
<Vector3fT
>& Var
);
137 void visit(const cf::TypeSys::VarT
<Vector3dT
>& Var
);
138 void visit(const cf::TypeSys::VarT
<BoundingBox3dT
>& Var
);
139 void visit(const cf::TypeSys::VarArrayT
<uint32_t>& Var
);
140 void visit(const cf::TypeSys::VarArrayT
<uint16_t>& Var
);
141 void visit(const cf::TypeSys::VarArrayT
<uint8_t>& Var
);
142 void visit(const cf::TypeSys::VarArrayT
<std::string
>& Var
);
147 void WriteString(const std::string
& s
) const;