orxParam questions

Just a few short questions relating to the orxParam module of Orx:

  1. All orx compiled programs accept the following parameters:

-c --config
-v --version
-h --help

If I wanted to re-purpose the -c parameter for something else, how could I do that? The tutorial here https://orx-project.org/wiki/en/tutorials/system/commandline_parameters only works for everything except the above default parameters.

  1. If I wanted to test for other optional arguments passed, but not create handlers for them? How would I go about this. I assume all params are set using orxParam_SetArgs(argc, argv), but how could I access them? For example, if I wanted to test if the user specified an -x argument but I have no handler set up for it, how is that done? Standard c args tests perhaps?

  2. Last case, if I have a handler for a parameter, and the argument is passed, the handler will execute. That much is good. But how did I test if the user did not pass the argument. Standard c testing code here as well?

It's very likely all my use cases above are intertwined. I can work around them but it would be cleaner if I can understand how to access anything collected by the orxParam module.

Comments

  • If I have a go at answering this myself: the job of orxParam_SetArgs(argc, argv) is to allow arguments to be available for registration to handlers. Any missing parameters, is the probably still the job of the developer to enumerate by checking the argv array?

  • edited June 2
    1. There's no way to repurpose those built-in parameters, sorry. At the same time, I'm reluctant to add support for it as I'd rather keep the parameters homogeneous and have -c, -v and -h be universal among all orx-based tools/utilities.
    2. The way to test for arguments is by registering them with a handler. This is the unified workflow. If your registered handler is called, it means the argument was found and the specifics are passed as parameters to it. If your handler isn't called, it means the argument wasn't found on the command line.
    3. Cf. answer #2

    You should never need to check the C args yourself. Going through the unified orxParam system means your application will always support standardized parameters the way orx understands them.

    Here's a quick example to illustrate the above, for clarity sake. It'll check for the presence of -x/--xlong:

    orxBOOL bIsXPresent;
    
    orxSTATUS orxFASTCALL XParamHandler(orxU32 _u32NbParam, const orxSTRING _azParams[])
    {
      // Updates X status
      bIsXPresent = orxTRUE;
    
      return orxSTATUS_SUCCESS;
    }
    
    orxSTATUS orxFASTCALL Init()
    {
      orxSTATUS eResult;
    
      orxPARAM stXParam =
      {
        orxPARAM_KU32_FLAG_NONE,
        "x",
        "xlong",
        "short desc",
        "long desc",
        XParamHandler
      };
    
      // Inits X status
      bIsXPresent = orxFALSE;
    
      // Registers param
      eResult = orxParam_Register(&stXParam);
    
      // Success?
      if(eResult != orxSTATUS_FAILURE)
      {
        // Checks for X status
        if(bIsXPresent)
        {
          // ...
        }
      }
    
      return eResult
    }
    
  • That's perfect thank you. I'll extend the wiki article with this detail.

Sign In or Register to comment.