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

Last change on this file since 137 was 99, checked in by epyon, 12 years ago
  • vertex_buffer - added assign by range (will change with the next commit)
  • gl_vertex_buffer - implementation of the above
  • gui element - recalculate_absolute_children() added, destructor and fix
  • object - get_id added
  • lualib_test - cleanups
File size: 1.6 KB
Line 
1#include <nv/lib/lua.hh>
2#include <nv/lua/lua_state.hh>
3#include <nv/lua/lua_raw.hh>
4#include <nv/lua/lua_glm.hh>
5#include <nv/logger.hh>
6#include <nv/types.hh>
7#include <nv/object.hh>
8#include <string>
9#include <iostream>
10#include <functional>
11#include <nv/gui/gui_element.hh>
12
13int main(int, char* [])
14{
15        nv::logger log(nv::LOG_TRACE);
16        log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
17        log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
18       
19        NV_LOG( nv::LOG_NOTICE, "Logging started" );
20
21        // create new Lua state
22        {
23                nv::lua::state state( true );
24                nlua_register_glm( state );
25                // run the Lua script
26                state.do_file( "init.lua" );
27
28                log.set_level( nv::LOG_INFO );
29                for (;;)
30                {
31                        nv::lua::stack_guard guard( state );
32                        int stack = guard.get_level();
33                        std::string input;
34                        std::cout << "LUA (" << stack << ") > ";
35                        std::getline( std::cin, input );
36                        if (input == "quit")
37                        {
38                                break;
39                        }
40
41                        if (input.find("=", 0) == std::string::npos &&
42                                input.find("if", 0) == std::string::npos &&
43                                input.find("return", 0) == std::string::npos)
44                        {
45                                input = "return " + input;
46                        }
47
48                        std::cout << "> " << input << std::endl;
49
50                        bool result = state.do_string( input, "", nv::lua::ret_multi );
51                        if ( !result )
52                        {
53                                continue;
54                        }
55
56                        if (lua_gettop( state ) > stack)
57                        {
58                                for ( int i = stack+1; i <= lua_gettop( state ); ++i )
59                                {
60                                        std::cout << nlua_typecontent( state, i ) << std::endl;
61                                }
62                        }
63                }
64        }
65        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
66
67        return 0;
68}
69
Note: See TracBrowser for help on using the repository browser.