found = arg_passed.select {|obj| obj.type == :type_weapon}
Command.new( "get", [ :scope_room, :scope_inv, :scope_equipped ], [ :arg_obj, [ :arg_obj, :arg_obj ] ] )
Command.new( "get", [ :scope_room, :scope_inv, :scope_equipped ], [ :arg_obj, [ :arg_obj, :arg_obj ] ] )
Command.new( "get", [ :scope_room, :scope_inv, :scope_equipped ], [ :arg_obj, [ :arg_obj, :arg_obj ] ] )
So I'm trying to bake 100% of the type checking into the dispatcher for the commands. Hopefully to save work when adding commands since you can be guaranteed the types passed are valid and already converted. This starts to get more complex as you have multiple types for a single argument that can be passed. So focusing on just the second argument (the 2d array):
Each list in the list represents a valid argument chain. So in this case it knows it can cast the arg to int or it can pass no value. Nothing else is valid. It can hold any number of values. For example:
This would tell it that the command has 3 possible arg chains. The first being int, int, word (in that order), the second being an object found in the same room as player, and the third being any string not empty that doesn't match the first two. In the case of the obj_in_room and similar non-primative types it will do the magic to find the object before passing the arg. If the object isn't found then it considers that a fail just as though the passed argument was invalid.
I'm curious if anyone else has tackled this problem and what they learned at the end of the day. Right now it's seeming manageable but I'm worried about it getting any more complex in syntax than that for building the arg-option-trees. Any opinions on the matter would be helpful.