~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/framework/bindings/lua/atlas/required.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: required
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#define __operator_dereference  operator*
 
24
#define __operator_index  operator[]
 
25
 
 
26
#include <Atlas/Message/Element.h>
 
27
#include <cstdlib>
 
28
 
 
29
/**
 
30
Utility method for the lua bindings which looks for a entry in a const map. If no entry is found we'll return null, which will be translated to "nil" in lua.
 
31
*/
 
32
const Atlas::Message::Element& _MapType_findInMap(const Atlas::Message::MapType* map, const std::string& key) {
 
33
        Atlas::Message::MapType::const_iterator I = map->find(key);
 
34
        if (I != map->end()) {
 
35
                return I->second;
 
36
        } else {
 
37
                ///we'll avoid compiler warnings by doing it this way
 
38
                static Atlas::Message::Element* element(0);
 
39
                return *element;
 
40
        }
 
41
}
 
42
 
 
43
/**
 
44
 * Method that checks, is Lua variable has number type exactly, not a string
 
45
 */
 
46
TOLUA_API int tolua_isnumber_type (lua_State* L, int lo, int def, tolua_Error* err)
 
47
{
 
48
        if (def && lua_gettop(L)<abs(lo))
 
49
                return 1;
 
50
        if (lua_type(L,lo) == LUA_TNUMBER)
 
51
                return 1;
 
52
        err->index = lo;
 
53
        err->array = 0;
 
54
        err->type = "number";
 
55
        return 0;
 
56
}
 
57
 
 
58
/**
 
59
 * Method that checks, is Lua variable has string type exactly, not a number
 
60
 */
 
61
TOLUA_API int tolua_isstring_type (lua_State* L, int lo, int def, tolua_Error* err)
 
62
{
 
63
        if (def && lua_gettop(L)<abs(lo))
 
64
                return 1;
 
65
        if (lua_type(L,lo) == LUA_TSTRING)
 
66
                return 1;
 
67
        err->index = lo;
 
68
        err->array = 0;
 
69
        err->type = "string";
 
70
        return 0;
 
71
}
 
72
 
 
73
#define tolua_iscppstring_type   tolua_isstring_type