source: trunk/tests/lualib_test/lualib_test.cc @ 229

Last change on this file since 229 was 214, checked in by epyon, 12 years ago
  • types - decomposition, math types go to math, type_traits related to type_traits
  • decoupling of the types.hh dependency from all possible places
File size: 1.8 KB
Line 
1#include <nv/lib/lua.hh>
2#include <nv/lua/lua_state.hh>
3#include <nv/lua/lua_dispatch.hh>
4#include <nv/lua/lua_raw.hh>
5#include <nv/lua/lua_glm.hh>
6#include <nv/logger.hh>
7#include <nv/math.hh>
8#include <nv/object.hh>
9#include <string>
10#include <iostream>
11#include <functional>
12#include <nv/gui/gui_element.hh>
13
14void hello( const std::string& h )
15{
16        std::cout << h << " world from C++!" << std::endl;
17}
18
19
20int main(int, char* [])
21{
22        nv::logger log(nv::LOG_TRACE);
23        log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
24        log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
25       
26        NV_LOG( nv::LOG_NOTICE, "Logging started" );
27
28        // create new Lua state
29        {
30                nv::lua::state state( true );
31                nv::lua::register_glm( state );
32                // run the Lua script
33                state.register_function<decltype(hello),&hello>( "hello" );
34                state.do_file( "init.lua" );
35                //std::cout << nv::function_traits<decltype(hello)>::arg_count << std::endl;
36
37                log.set_level( nv::LOG_INFO );
38                for (;;)
39                {
40                        nv::lua::stack_guard guard( state );
41                        int stack = guard.get_level();
42                        std::string input;
43                        std::cout << "LUA (" << stack << ") > ";
44                        std::getline( std::cin, input );
45                        if (input == "quit")
46                        {
47                                break;
48                        }
49
50                        if (input.find("=", 0) == std::string::npos &&
51                                input.find("if", 0) == std::string::npos &&
52                                input.find("return", 0) == std::string::npos)
53                        {
54                                input = "return " + input;
55                        }
56
57                        std::cout << "> " << input << std::endl;
58
59                        bool result = state.do_string( input, "", nv::lua::ret_multi );
60                        if ( !result )
61                        {
62                                continue;
63                        }
64
65                        if (lua_gettop( state ) > stack)
66                        {
67                                for ( int i = stack+1; i <= lua_gettop( state ); ++i )
68                                {
69                                        std::cout << nlua_typecontent( state, i ) << std::endl;
70                                }
71                        }
72                }
73        }
74        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
75
76        return 0;
77}
78
Note: See TracBrowser for help on using the repository browser.