source: trunk/src/lua/lua_values.cc @ 183

Last change on this file since 183 was 183, checked in by epyon, 12 years ago
  • lua - alternative way of specifing push/pop support
File size: 1.9 KB
Line 
1// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7#include "nv/lua/lua_values.hh"
8
9#include "nv/lua/lua_raw.hh"
10#include "nv/object.hh"
11
12void nv::lua::detail::push_value( lua_State *L, long n )
13{
14        lua_pushinteger( L, n );
15}
16
17void nv::lua::detail::push_value( lua_State *L, double d )
18{
19        lua_pushnumber( L, d );
20}
21
22void nv::lua::detail::push_value( lua_State *L, bool n )
23{
24        lua_pushboolean( L, n );
25}
26
27void nv::lua::detail::push_value( lua_State *L, const char* s )
28{
29        lua_pushstring( L, s );
30}
31
32void nv::lua::detail::push_value( lua_State *L, const std::string& s )
33{
34        lua_pushstring( L, s.c_str() );
35}
36
37void nv::lua::detail::push_value( lua_State *L, object* o )
38{
39        if ( o == nullptr )
40        {
41                lua_pushnil( L );
42        }
43        else
44        {
45                lua_rawgeti( L, LUA_REGISTRYINDEX, o->get_lua_index() );
46        }
47}
48
49void nv::lua::detail::push_value( lua_State *L, void* p )
50{
51        lua_pushlightuserdata( L, p );
52}
53
54void nv::lua::detail::pop_value( lua_State *L, long& n )
55{
56        n = lua_tointeger( L, -1 );
57        lua_pop( L, 1 );
58}
59
60void nv::lua::detail::pop_value( lua_State *L, double& d )
61{
62        d = lua_tonumber( L, -1 );
63        lua_pop( L, 1 );
64}
65
66void nv::lua::detail::pop_value( lua_State *L, bool& n )
67{
68        n = lua_toboolean( L, -1 ) != 0;
69        lua_pop( L, 1 );
70}
71
72void nv::lua::detail::pop_value( lua_State *L, std::string& s )
73{
74        s = lua_tostring( L, -1 );
75        lua_pop( L, 1 );
76}
77
78void nv::lua::detail::pop_value( lua_State *L, object*& o )
79{
80        o = nullptr;
81        if ( lua_istable( L , -1 ) )
82        {
83                lua_pushstring( L, "__ptr" );
84                lua_rawget( L, -1 );
85                if ( lua_isuserdata( L, -1 ) )
86                {
87                        o = (object*)( lua_touserdata( L, -1 ) );
88                }
89                lua_pop( L, 1 );
90        }
91        lua_pop( L, 1 );
92}
93
94void nv::lua::detail::pop_value( lua_State *L, void*& p )
95{
96        p = lua_touserdata( L, -1 );
97        lua_pop( L, 1 );
98}
99
Note: See TracBrowser for help on using the repository browser.