Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • C plugin arguments

    Stataers,

    I wrote a C plugin that I can call using this code:

    Code:
    program r
      preserve
      version 14.2
      syntax varlist(min=1 max=10) [if] [in], k(string)
    
      plugin call riemann `varlist', "`k'"
    end
    qui program riemann, plugin using ("riemann.plugin")
    Rightfully, in the code argv[0] points to k, the first argument of arglist, therefore invoking the plugin is done as such:
    r w a s d, k("my string")

    I would prefer the syntax to be as such:
    r "my string" w a s d

    What are/would be the modifications to the program above to support this syntax, which I think is much more readable.

    Thank you for reading

  • #2
    Code:
    program r
    
      syntax anything  [if] [in] , 
      
      gettoken mystring 0 : 0
      syntax varlist  [if] [in] ,
      
    end

    Comment


    • #3
      I believe you probably mean this?

      Code:
      program r
        preserve
        version 14.2
        syntax anything [if] [in],
        gettoken mystring 0:0
        syntax varlist(min=1 max=10) [if] [in],
      
        plugin call riemann "`mystring'" `varlist'
      end
      But that didn't work for me:

      r "hello world" w a s d
      "hello world invalid name
      r(198);

      Comment


      • #4
        I would prefer the syntax to be as such:
        r "my string" w a s d
        Code:
        program r
         
          syntax anything  [if] [in] ,
          gettoken k 0 : 0
          syntax varlist(min=1 max=10) [if] [in],
        
          plugin call riemann `varlist', "`k'" 
          
        end
        Code:
         set trace on
        
        r "my string" w a s d if 1==1 in 1/10
        
          --------------------------------------------------------------------------------------------------------------------------------------------------------- begin r ---
          - syntax anything [if] [in] ,
          - gettoken k 0 : 0
          - syntax varlist(min=1 max=10) [if] [in],
          - plugin call riemann `varlist', "`k'"
          = plugin call riemann w a s d, "my string"
          ----------------------------------------------------------------------------------------------------------------------------------------------------------- end r ---

        Comment


        • #5
          That works perfectly, thank you!

          Comment

          Working...
          X