source: trunk/tests/lualib_test/nv_lualib_test.cc

Last change on this file 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
RevLine 
[52]1#include <nv/lib/lua.hh>
[74]2#include <nv/lua/lua_state.hh>
[213]3#include <nv/lua/lua_dispatch.hh>
[52]4#include <nv/lua/lua_raw.hh>
[53]5#include <nv/lua/lua_glm.hh>
[321]6#include <nv/core/logger.hh>
7#include <nv/core/math.hh>
8#include <nv/core/string.hh>
[52]9#include <iostream>
[62]10#include <functional>
[52]11
[213]12void hello( const std::string& h )
13{
14        std::cout << h << " world from C++!" << std::endl;
15}
16
17
[52]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 );
[62]23       
[52]24        NV_LOG( nv::LOG_NOTICE, "Logging started" );
25
26        // create new Lua state
27        {
[74]28                nv::lua::state state( true );
[213]29                nv::lua::register_glm( state );
[74]30                // run the Lua script
[321]31                state.register_function<decltype(&hello),&hello>( "hello" );
[74]32                state.do_file( "init.lua" );
[213]33                //std::cout << nv::function_traits<decltype(hello)>::arg_count << std::endl;
[52]34
[99]35                log.set_level( nv::LOG_INFO );
[74]36                for (;;)
[52]37                {
[86]38                        nv::lua::stack_guard guard( state );
[74]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                        }
[52]47
[74]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                        }
[52]54
[74]55                        std::cout << "> " << input << std::endl;
[52]56
[79]57                        bool result = state.do_string( input, "", nv::lua::ret_multi );
58                        if ( !result )
[74]59                        {
60                                continue;
61                        }
[52]62
[86]63                        if (lua_gettop( state ) > stack)
[52]64                        {
[86]65                                for ( int i = stack+1; i <= lua_gettop( state ); ++i )
[74]66                                {
[86]67                                        std::cout << nlua_typecontent( state, i ) << std::endl;
[74]68                                }
[52]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.