[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>
|
---|
[52] | 6 | #include <nv/logger.hh>
|
---|
[214] | 7 | #include <nv/math.hh>
|
---|
[62] | 8 | #include <nv/object.hh>
|
---|
[52] | 9 | #include <string>
|
---|
| 10 | #include <iostream>
|
---|
[62] | 11 | #include <functional>
|
---|
[69] | 12 | #include <nv/gui/gui_element.hh>
|
---|
[52] | 13 |
|
---|
[213] | 14 | void hello( const std::string& h )
|
---|
| 15 | {
|
---|
| 16 | std::cout << h << " world from C++!" << std::endl;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 |
|
---|
[52] | 20 | int main(int, char* [])
|
---|
| 21 | {
|
---|
| 22 | nv::logger log(nv::LOG_TRACE);
|
---|
| 23 | log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
|
---|
| 24 | log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
|
---|
[62] | 25 |
|
---|
[52] | 26 | NV_LOG( nv::LOG_NOTICE, "Logging started" );
|
---|
| 27 |
|
---|
| 28 | // create new Lua state
|
---|
| 29 | {
|
---|
[74] | 30 | nv::lua::state state( true );
|
---|
[213] | 31 | nv::lua::register_glm( state );
|
---|
[74] | 32 | // run the Lua script
|
---|
[213] | 33 | state.register_function<decltype(hello),&hello>( "hello" );
|
---|
[74] | 34 | state.do_file( "init.lua" );
|
---|
[213] | 35 | //std::cout << nv::function_traits<decltype(hello)>::arg_count << std::endl;
|
---|
[52] | 36 |
|
---|
[99] | 37 | log.set_level( nv::LOG_INFO );
|
---|
[74] | 38 | for (;;)
|
---|
[52] | 39 | {
|
---|
[86] | 40 | nv::lua::stack_guard guard( state );
|
---|
[74] | 41 | int stack = guard.get_level();
|
---|
| 42 | std::string input;
|
---|
| 43 | std::cout << "LUA (" << stack << ") > ";
|
---|
| 44 | std::getline( std::cin, input );
|
---|
| 45 | if (input == "quit")
|
---|
| 46 | {
|
---|
| 47 | break;
|
---|
| 48 | }
|
---|
[52] | 49 |
|
---|
[74] | 50 | if (input.find("=", 0) == std::string::npos &&
|
---|
| 51 | input.find("if", 0) == std::string::npos &&
|
---|
| 52 | input.find("return", 0) == std::string::npos)
|
---|
| 53 | {
|
---|
| 54 | input = "return " + input;
|
---|
| 55 | }
|
---|
[52] | 56 |
|
---|
[74] | 57 | std::cout << "> " << input << std::endl;
|
---|
[52] | 58 |
|
---|
[79] | 59 | bool result = state.do_string( input, "", nv::lua::ret_multi );
|
---|
| 60 | if ( !result )
|
---|
[74] | 61 | {
|
---|
| 62 | continue;
|
---|
| 63 | }
|
---|
[52] | 64 |
|
---|
[86] | 65 | if (lua_gettop( state ) > stack)
|
---|
[52] | 66 | {
|
---|
[86] | 67 | for ( int i = stack+1; i <= lua_gettop( state ); ++i )
|
---|
[74] | 68 | {
|
---|
[86] | 69 | std::cout << nlua_typecontent( state, i ) << std::endl;
|
---|
[74] | 70 | }
|
---|
[52] | 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
|
---|
| 75 |
|
---|
| 76 | return 0;
|
---|
| 77 | }
|
---|
| 78 |
|
---|