1212
1313#include " Core.h"
1414#include " Debug.h"
15- #include " LuaTools.h"
1615#include " PluginManager.h"
1716
1817#include " modules/Persistence.h"
@@ -60,35 +59,6 @@ static void set_config_bool(int index, bool value) {
6059
6160static int32_t cycle_timestamp = 0 ; // world->frame_counter at last cycle
6261
63- // define the structure that will represent the possible commandline options
64- struct command_options {
65- // whether to display help
66- bool help = false ;
67-
68- // whether to run a cycle right now
69- bool now = false ;
70-
71- // how many ticks to wait between cycles when enabled, -1 means unset
72- int32_t ticks = -1 ;
73-
74- // example params of different types
75- df::coord start;
76- string format;
77- vector<string*> list; // note this must be a vector of pointers, not objects
78-
79- static struct_identity _identity;
80- };
81- static const struct_field_info command_options_fields[] = {
82- { struct_field_info::PRIMITIVE , " help" , offsetof (command_options, help), &df::identity_traits<bool >::identity, 0 , 0 },
83- { struct_field_info::PRIMITIVE , " now" , offsetof (command_options, now), &df::identity_traits<bool >::identity, 0 , 0 },
84- { struct_field_info::PRIMITIVE , " ticks" , offsetof (command_options, ticks), &df::identity_traits<int32_t >::identity, 0 , 0 },
85- { struct_field_info::SUBSTRUCT , " start" , offsetof (command_options, start), &df::coord::_identity, 0 , 0 },
86- { struct_field_info::PRIMITIVE , " format" , offsetof (command_options, format), df::identity_traits<string>::get (), 0 , 0 },
87- { struct_field_info::STL_VECTOR_PTR , " list" , offsetof (command_options, list), df::identity_traits<string>::get (), 0 , 0 },
88- { struct_field_info::END }
89- };
90- struct_identity command_options::_identity (sizeof (command_options), &df::allocator_fn<command_options>, NULL, "command_options", NULL, command_options_fields);
91-
9262static command_result do_command (color_ostream &out, vector<string> ¶meters);
9363static void do_cycle (color_ostream &out);
9464
@@ -165,33 +135,6 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out) {
165135 return CR_OK ;
166136}
167137
168- // load the lua module associated with the plugin and parse the commandline
169- // in lua (which has better facilities than C++ for string parsing).
170- static bool get_options (color_ostream &out,
171- command_options &opts,
172- const vector<string> ¶meters)
173- {
174- auto L = Lua::Core::State;
175- Lua::StackUnwinder top (L);
176-
177- if (!lua_checkstack (L, parameters.size () + 2 ) ||
178- !Lua::PushModulePublic (
179- out, L, (" plugins." + string (plugin_name)).c_str (),
180- " parse_commandline" )) {
181- out.printerr (" Failed to load %s Lua code\n " , plugin_name);
182- return false ;
183- }
184-
185- Lua::Push (L, &opts);
186- for (const string ¶m : parameters)
187- Lua::Push (L, param);
188-
189- if (!Lua::SafeCall (out, L, parameters.size () + 1 , 0 ))
190- return false ;
191-
192- return true ;
193- }
194-
195138static command_result do_command (color_ostream &out, vector<string> ¶meters) {
196139 // be sure to suspend the core if any DF state is read or modified
197140 CoreSuspender suspend;
@@ -201,20 +144,11 @@ static command_result do_command(color_ostream &out, vector<string> ¶meters)
201144 return CR_FAILURE ;
202145 }
203146
204- command_options opts;
205- if (!get_options (out, opts, parameters) || opts.help )
206- return CR_WRONG_USAGE ;
147+ // TODO: configuration logic
148+ // simple commandline parsing can be done in C++, but there are lua libraries
149+ // that can easily handle more complex commandlines. see the blueprint plugin
150+ // for an example.
207151
208- if (opts.ticks > -1 ) {
209- set_config_val (CONFIG_CYCLE_TICKS , opts.ticks );
210- INFO (status,out).print (" New cycle timer: %d ticks.\n " , opts.ticks );
211- }
212- else if (opts.now ) {
213- do_cycle (out);
214- }
215- else {
216- out.print (" %s is %srunning\n " , plugin_name, (is_enabled ? " " : " not " ));
217- }
218152 return CR_OK ;
219153}
220154
0 commit comments