#include #include #include #include #include #include #include #include #include #include struct test_struct { std::string f; int i; }; NV_REGISTER_NAME( test_struct ) int main(int, char* []) { nv::type_database db; nv::object::register_type( &db ); db.create_type(); db.create_type(); nv::type_field fields[] = { nv::type_field("f", &test_struct::f ), nv::type_field("i", &test_struct::i ), }; db.create_type().fields( fields ); nv::logger log(nv::LOG_TRACE); log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE ); log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE ); nv::load_lua_library(); NV_LOG( nv::LOG_NOTICE, "Logging started" ); // create new Lua state lua_State *lua_state; lua_state = luaL_newstate(); // load Lua libraries static const luaL_Reg lualibs[] = { { "base", luaopen_base }, { NULL, NULL} }; nlua_register_glm( lua_state ); const luaL_Reg *lib = lualibs; for(; lib->func != NULL; lib++) { lib->func(lua_state); lua_settop(lua_state, 0); } // run the Lua script luaL_dofile(lua_state, "init.lua"); for (;;) { std::string input; int stack = lua_gettop( lua_state ); std::cout << "LUA (" << stack << ") > "; std::getline( std::cin, input ); if (input == "quit") { break; } if (input.find("=", 0) == std::string::npos && input.find("if", 0) == std::string::npos && input.find("return", 0) == std::string::npos) { input = "return " + input; } std::cout << "> " << input << std::endl; int code = luaL_loadstring( lua_state, input.c_str() ); if (code == 0) code = lua_pcall( lua_state, 0, LUA_MULTRET, 0); if (code != 0) { std::string error = lua_tostring( lua_state, -1 ); std::cout << "ERROR : " << error << std::endl; lua_settop( lua_state, stack ); continue; } if (lua_gettop( lua_state ) > stack) { for ( int i = stack+1; i <= lua_gettop( lua_state ); ++i ) { std::cout << nlua_typecontent( lua_state, i ) << std::endl; } } lua_settop( lua_state, stack ); } // close the Lua state lua_close(lua_state); NV_LOG( nv::LOG_NOTICE, "Logging stopped" ); return 0; }