[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 |
|
---|
[62] | 13 | struct test_struct
|
---|
| 14 | {
|
---|
| 15 | std::string f;
|
---|
| 16 | int i;
|
---|
| 17 | };
|
---|
| 18 |
|
---|
[52] | 19 | int 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 );
|
---|
[62] | 24 |
|
---|
[52] | 25 | NV_LOG( nv::LOG_NOTICE, "Logging started" );
|
---|
| 26 |
|
---|
| 27 | // create new Lua state
|
---|
| 28 | {
|
---|
[74] | 29 | nv::lua::state state( true );
|
---|
| 30 | nlua_register_glm( state.get_raw() );
|
---|
| 31 | // run the Lua script
|
---|
| 32 | state.do_file( "init.lua" );
|
---|
[52] | 33 |
|
---|
[74] | 34 | for (;;)
|
---|
[52] | 35 | {
|
---|
[74] | 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 | }
|
---|
[52] | 45 |
|
---|
[74] | 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] | 52 |
|
---|
[74] | 53 | std::cout << "> " << input << std::endl;
|
---|
[52] | 54 |
|
---|
[79] | 55 | bool result = state.do_string( input, "", nv::lua::ret_multi );
|
---|
| 56 | if ( !result )
|
---|
[74] | 57 | {
|
---|
| 58 | std::string error = lua_tostring( state.get_raw(), -1 );
|
---|
| 59 | std::cout << "ERROR : " << error << std::endl;
|
---|
| 60 | continue;
|
---|
| 61 | }
|
---|
[52] | 62 |
|
---|
[74] | 63 | if (lua_gettop( state.get_raw() ) > stack)
|
---|
[52] | 64 | {
|
---|
[74] | 65 | for ( int i = stack+1; i <= lua_gettop( state.get_raw() ); ++i )
|
---|
| 66 | {
|
---|
| 67 | std::cout << nlua_typecontent( state.get_raw(), i ) << std::endl;
|
---|
| 68 | }
|
---|
[52] | 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
|
---|
| 73 |
|
---|
| 74 | return 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|