Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/executor/executor_lua_state.cc @ 9748

Last change on this file since 9748 was 9748, checked in by bensch, 18 years ago

completely documented Executors

File size: 4.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: ...
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "executor_lua_state.h"
19
20#include "lunar.h"
21
22std::string temp[7];
23
24/**
25 * @brief Converts a lua_State into any type.
26 * @param state the State to get the value from.
27 * @param index the position inside of the lua_State to get the value from.
28 * @returns The value if found.
29 */
30template<typename type> type fromLua(lua_State* state, int index) { type *obj = Lunar<type>::check(state, 1); lua_remove(state, 1); return obj;};
31/**
32 * @brief Converts a lua_State into any type.
33 * @param state the State to get the value from.
34 * @param index the position inside of the lua_State to get the value from.
35 * @returns The value if found.
36 */
37template<> bool fromLua<bool>(lua_State* state, int index) { return lua_toboolean(state, index); };
38/**
39 * @brief Converts a lua_State into any type.
40 * @param state the State to get the value from.
41 * @param index the position inside of the lua_State to get the value from.
42 * @returns The value if found.
43 */
44template<> int fromLua<int>(lua_State* state, int index) { return (int)lua_tonumber(state, index); };
45/**
46 * @brief Converts a lua_State into any type.
47 * @param state the State to get the value from.
48 * @param index the position inside of the lua_State to get the value from.
49 * @returns The value if found.
50 */
51template<> unsigned int fromLua<unsigned int>(lua_State* state, int index) { return (unsigned int)lua_tonumber(state, index); };
52/**
53 * @brief Converts a lua_State into any type.
54 * @param state the State to get the value from.
55 * @param index the position inside of the lua_State to get the value from.
56 * @returns The value if found.
57 */
58template<> float fromLua<float>(lua_State* state, int index) { return (float)lua_tonumber(state, index); };
59/**
60 * @brief Converts a lua_State into any type.
61 * @param state the State to get the value from.
62 * @param index the position inside of the lua_State to get the value from.
63 * @returns The value if found.
64 */
65template<> char fromLua<char>(lua_State* state, int index) { return (char)lua_tonumber(state, index); };
66/**
67 * @brief Converts a lua_State into any type.
68 * @param state the State to get the value from.
69 * @param index the position inside of the lua_State to get the value from.
70 * @returns The value if found.
71 */
72template<> const std::string& fromLua<const std::string&>(lua_State* state, int index) { temp[index] = lua_tostring(state, index); return temp[index]; };
73
74
75
76
77/**
78 * @brief writes a value into a lua_State.
79 * @param state the state to write into.
80 * @param value the Value of type to write into the State.
81 */
82template<typename type> void toLua(lua_State* state, type value) { Lunar<type>::push(state, value, false); };
83/**
84 * @brief writes a value into a lua_State.
85 * @param state the state to write into.
86 * @param value the Value of type to write into the State.
87 */
88template<> void toLua<bool>(lua_State* state, bool value) { lua_pushboolean(state, (int) value); };
89/**
90 * @brief writes a value into a lua_State.
91 * @param state the state to write into.
92 * @param value the Value of type to write into the State.
93 */
94template<> void toLua<int>(lua_State* state, int value)  { lua_pushnumber(state, (lua_Number) value); };
95/**
96 * @brief writes a value into a lua_State.
97 * @param state the state to write into.
98 * @param value the Value of type to write into the State.
99 */
100template<> void toLua<unsigned int>(lua_State* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); };
101/**
102 * @brief writes a value into a lua_State.
103 * @param state the state to write into.
104 * @param value the Value of type to write into the State.
105 */
106template<> void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); };
107/**
108 * @brief writes a value into a lua_State.
109 * @param state the state to write into.
110 * @param value the Value of type to write into the State.
111 */
112template<> void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); };
113/**
114 * @brief writes a value into a lua_State.
115 * @param state the state to write into.
116 * @param value the Value of type to write into the State.
117 */
118template<> void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); }
Note: See TracBrowser for help on using the repository browser.