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

Last change on this file since 99 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
RevLine 
[52]1#include <nv/lib/lua.hh>
[74]2#include <nv/lua/lua_state.hh>
[52]3#include <nv/lua/lua_raw.hh>
[53]4#include <nv/lua/lua_glm.hh>
[52]5#include <nv/logger.hh>
[62]6#include <nv/types.hh>
7#include <nv/object.hh>
[52]8#include <string>
9#include <iostream>
[62]10#include <functional>
[69]11#include <nv/gui/gui_element.hh>
[52]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 );
[62]18       
[52]19        NV_LOG( nv::LOG_NOTICE, "Logging started" );
20
21        // create new Lua state
22        {
[74]23                nv::lua::state state( true );
[86]24                nlua_register_glm( state );
[74]25                // run the Lua script
26                state.do_file( "init.lua" );
[52]27
[99]28                log.set_level( nv::LOG_INFO );
[74]29                for (;;)
[52]30                {
[86]31                        nv::lua::stack_guard guard( state );
[74]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                        }
[52]40
[74]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                        }
[52]47
[74]48                        std::cout << "> " << input << std::endl;
[52]49
[79]50                        bool result = state.do_string( input, "", nv::lua::ret_multi );
51                        if ( !result )
[74]52                        {
53                                continue;
54                        }
[52]55
[86]56                        if (lua_gettop( state ) > stack)
[52]57                        {
[86]58                                for ( int i = stack+1; i <= lua_gettop( state ); ++i )
[74]59                                {
[86]60                                        std::cout << nlua_typecontent( state, i ) << std::endl;
[74]61                                }
[52]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.