1 // 2 // 3 4 #include "options.h" 5 #include "options/OptionsManager.h" 6 #include "scripting/api/objs/option.h" 7 #include "scripting/lua/LuaTable.h" 8 9 namespace scripting { 10 namespace api { 11 12 //**********LIBRARY: Mission 13 ADE_LIB(l_Options, "Options", "opt", "Options library"); 14 15 ADE_VIRTVAR(Options, l_Options, nullptr, "The available options.", "option[]", "A table of all the options.") 16 { 17 using namespace luacpp; 18 19 auto& options = options::OptionsManager::instance()->getOptions(); 20 21 auto table = LuaTable::create(L); 22 int i = 1; 23 24 for (auto& opt : options) { 25 table.addValue(i, l_Option.Set(option_h(opt.get()))); 26 ++i; 27 } 28 29 return ade_set_args(L, "t", &table); 30 } 31 32 ADE_FUNC(persistChanges, 33 l_Options, 34 nullptr, 35 "Persist any changes made to the options system. Options can be incapable of applying changes immediately in " 36 "which case they are returned here.", 37 "option[]", 38 "The options that did not support changing their value") 39 { 40 using namespace luacpp; 41 42 auto unchanged = options::OptionsManager::instance()->persistChanges(); 43 44 auto table = LuaTable::create(L); 45 int i = 1; 46 47 for (auto& opt : unchanged) { 48 table.addValue(i, l_Option.Set(option_h(opt))); 49 ++i; 50 } 51 52 return ade_set_args(L, "t", &table); 53 } 54 55 ADE_FUNC(discardChanges, l_Options, nullptr, "Discard any changes made to the options system.", "boolean", 56 "True on success, false otherwise") 57 { 58 options::OptionsManager::instance()->discardChanges(); 59 return ADE_RETURN_TRUE; 60 } 61 62 } // namespace api 63 } // namespace scripting 64