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

Last change on this file since 78 was 78, checked in by epyon, 12 years ago
  • types.hh - basing totally on typeid now
  • types.hh - removed hash_string and name registration defines (get_type_name template)
  • types.hh - name is defined at registration via create_type
  • types.hh - overall the code is much cleaner now
File size: 1.8 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
13struct test_struct
14{
15        std::string f;
16        int i;
17};
18
19int main(int, char* [])
20{
21        nv::logger log(nv::LOG_TRACE);
22        log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
23        log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
24       
25        NV_LOG( nv::LOG_NOTICE, "Logging started" );
26
27        // create new Lua state
28        {
29                nv::lua::state state( true );
30                nlua_register_glm( state.get_raw() );
31                // run the Lua script
32                state.do_file( "init.lua" );
33
34                for (;;)
35                {
36                        nv::lua::stack_guard guard( &state );
37                        int stack = guard.get_level();
38                        std::string input;
39                        std::cout << "LUA (" << stack << ") > ";
40                        std::getline( std::cin, input );
41                        if (input == "quit")
42                        {
43                                break;
44                        }
45
46                        if (input.find("=", 0) == std::string::npos &&
47                                input.find("if", 0) == std::string::npos &&
48                                input.find("return", 0) == std::string::npos)
49                        {
50                                input = "return " + input;
51                        }
52
53                        std::cout << "> " << input << std::endl;
54
55                        int code = luaL_loadstring( state.get_raw(), input.c_str() );
56                        if (code == 0) code = lua_pcall( state.get_raw(), 0, LUA_MULTRET, 0);
57                        if (code != 0)
58                        {
59                                std::string error = lua_tostring( state.get_raw(), -1 );
60                                std::cout << "ERROR : " << error << std::endl;
61                                continue;
62                        }
63
64                        if (lua_gettop( state.get_raw() ) > stack)
65                        {
66                                for ( int i = stack+1; i <= lua_gettop( state.get_raw() ); ++i )
67                                {
68                                        std::cout << nlua_typecontent( state.get_raw(), i ) << std::endl;
69                                }
70                        }
71                }
72        }
73        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
74
75        return 0;
76}
77
Note: See TracBrowser for help on using the repository browser.