source: trunk/tests/lualib_test/nv_lualib_test.cc @ 321

Last change on this file since 321 was 321, checked in by epyon, 11 years ago
  • updated all tests to new nova
  • cleaned up tests paths
  • general cleanup of tests and test data
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/core/logger.hh>
7#include <nv/core/math.hh>
8#include <nv/core/string.hh>
9#include <iostream>
10#include <functional>
11
12void hello( const std::string& h )
13{
14        std::cout << h << " world from C++!" << std::endl;
15}
16
17
18int main(int, char* [])
19{
20        nv::logger log(nv::LOG_TRACE);
21        log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
22        log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
23       
24        NV_LOG( nv::LOG_NOTICE, "Logging started" );
25
26        // create new Lua state
27        {
28                nv::lua::state state( true );
29                nv::lua::register_glm( state );
30                // run the Lua script
31                state.register_function<decltype(&hello),&hello>( "hello" );
32                state.do_file( "init.lua" );
33                //std::cout << nv::function_traits<decltype(hello)>::arg_count << std::endl;
34
35                log.set_level( nv::LOG_INFO );
36                for (;;)
37                {
38                        nv::lua::stack_guard guard( state );
39                        int stack = guard.get_level();
40                        std::string input;
41                        std::cout << "LUA (" << stack << ") > ";
42                        std::getline( std::cin, input );
43                        if (input == "quit")
44                        {
45                                break;
46                        }
47
48                        if (input.find("=", 0) == std::string::npos &&
49                                input.find("if", 0) == std::string::npos &&
50                                input.find("return", 0) == std::string::npos)
51                        {
52                                input = "return " + input;
53                        }
54
55                        std::cout << "> " << input << std::endl;
56
57                        bool result = state.do_string( input, "", nv::lua::ret_multi );
58                        if ( !result )
59                        {
60                                continue;
61                        }
62
63                        if (lua_gettop( state ) > stack)
64                        {
65                                for ( int i = stack+1; i <= lua_gettop( state ); ++i )
66                                {
67                                        std::cout << nlua_typecontent( state, i ) << std::endl;
68                                }
69                        }
70                }
71        }
72        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
73
74        return 0;
75}
76
Note: See TracBrowser for help on using the repository browser.