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

Last change on this file since 206 was 206, checked in by epyon, 12 years ago
  • lua - major refactoring of the lua state/table
  • lua - added state_wrapper common to state/table
  • lua_values - fixed returning of simple types
  • lua_area - fixed area.coords and area.edges
  • lua_map_area - "fixed" case when object is used as base
File size: 2.1 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, int& n )
55{
56        n = lua_tointeger( L, -1 );
57        lua_pop( L, 1 );
58}
59
60void nv::lua::detail::pop_value( lua_State *L, long& n )
61{
62        n = lua_tointeger( L, -1 );
63        lua_pop( L, 1 );
64}
65
66void nv::lua::detail::pop_value( lua_State *L, double& d )
67{
68        d = lua_tonumber( L, -1 );
69        lua_pop( L, 1 );
70}
71
72void nv::lua::detail::pop_value( lua_State *L, bool& n )
73{
74        n = lua_toboolean( L, -1 ) != 0;
75        lua_pop( L, 1 );
76}
77
78void nv::lua::detail::pop_value( lua_State *L, std::string& s )
79{
80        s = lua_tostring( L, -1 );
81        lua_pop( L, 1 );
82}
83
84void nv::lua::detail::pop_value( lua_State *L, object*& o )
85{
86        o = nullptr;
87        if ( lua_istable( L , -1 ) )
88        {
89                lua_pushstring( L, "__ptr" );
90                lua_rawget( L, -1 );
91                if ( lua_isuserdata( L, -1 ) )
92                {
93                        o = (object*)( lua_touserdata( L, -1 ) );
94                }
95                lua_pop( L, 1 );
96        }
97        lua_pop( L, 1 );
98}
99
100void nv::lua::detail::pop_value( lua_State *L, void*& p )
101{
102        p = lua_touserdata( L, -1 );
103        lua_pop( L, 1 );
104}
105
Note: See TracBrowser for help on using the repository browser.