Home AMX User Forum AMXForums Archive Threads Tips and Tricks

Highlighting Mod Params

Here's a little twist to something I had been doing in order to get parameters passed to modules to correctly high light and auotcomplete.

Module header:
MODULE_NAME='VAV_LGTV_Mod,Rev1'(DEV vTVcomm,DEV dvTV,INTEGER nInstance,INTEGER nSerial,CHAR cIP[],INTEGER nTVs_DeBug)
Now to get the devices to high light and autocomplete I use compiler directives but the twist is doing it all locally where needed whereas I used to do it the #DEFINE "SOMETHING" in the main code where these device were actually defined but that's too much of a pain to track and could cause problems it the #DEFINE "SOMETHING" was ever removed since I would never remember all the locations I might have the #IF_NOT_DEFINED. So now I just do this only inside the module:
DEFINE_DEVICE   //#DEFINE DEFINE_MODULE_PARAMETERS

//THIS JUST ALLOWS HIGHLIGHTING & AUTOCOMPLETE ITEMS PASSED IN THE HEADER
#DEFINE DEFINE_MODULE_PARAMETERS
#IF_NOT_DEFINED DEFINE_MODULE_PARAMETERS
vTVcomm 		
dvTV 	        	
#END_IF
for devices and
DEFINE_VARIABLE //MODULE HEADER PARAMETERS 

//THIS JUST ALLOWS HIGHLIGHTING & AUTOCOMPLETE ITEMS PASSED IN THE HEADER
#DEFINE DEFINE_MODULE_PARAMETERS
#IF_NOT_DEFINED DEFINE_MODULE_PARAMETERS
nInstance
nSerial 
cIP 
nTVs_DeBug          	
#END_IF     
for vars.

Less chance of the #DEFINE getting deleted elsewhere in the code causing these to become valid definitions. Plus I used to actually do the complete definition dev = 5001:0:0 but there's really no point since I only want the auto complete and highlighting. I can use the same #DEFINE without the compiler yelling at me that DEFINE_MODULE_PARAMETERS is already defined.

Now everything will auto complete and highlight in the correct colors set in preferences and the chance I me screwing things up down the road are minimized.

edit:
Actually now that I think about it I never did anything for modules and used the #DEFINE "SOMETHING" in the main and the matching #IF_NOT... for highlighting and auto-complete in my includes which used to get screwed up if I inadvertantly removed the #DEFINE.

Comments

  • moty66moty66 Posts: 31
    Great twist, thank you for sharing
  • the8thstthe8thst Posts: 470
    You can do the same thing in a single compiler directive by adding define_device, define_variable, etc into your if/else block. I use this in different includes (including system wide structures) and simply paste it at the top of every include file.
    I use the same strategy for modules too.

    I like having everything in a single block of code so it is easy to copy paste.
    #DEFINE DEFINE_MODULE_PARAMETERS
    #IF_NOT_DEFINED DEFINE_MODULE_PARAMETERS
    define_device
    vTVcomm 		
    dvTV
    
    define_variable
    nInstance
    nSerial 
    cIP 
    nTVs_DeBug  	        	
    #END_IF
    
  • rfletcherrfletcher Posts: 217
    I started doing this in my modules recently after someone (maybe you vining?) mentioned it on the forums.

    it can be done with one fewer compiler directive too :D
    #if_defined DONOTDEFINETHISVALUE
    
    define_device...
    
    #end_if
    

    at least as long as no one ever comes along and defines DONOTDEFINETHISVALUE :p
  • mpullinmpullin Posts: 949
    That's clever.
    I'm going to start doing this for my modules as well.
  • a_riot42a_riot42 Posts: 1,624
    rfletcher wrote: »
    I started doing this in my modules recently after someone (maybe you vining?) mentioned it on the forums.

    it can be done with one fewer compiler directive too :D
    #if_defined DONOTDEFINETHISVALUE
    
    define_device...
    
    #end_if
    

    at least as long as no one ever comes along and defines DONOTDEFINETHISVALUE :p


    What comes after the define_device? The ellipsis indicates something should follow, but I'm not sure what.
  • mpullinmpullin Posts: 949
    MODULE_NAME='Elk_M1_Ethernet_Comm'(DEV vdvELK, DEV dvELK, CHAR cELK_IP[])
    #if_defined RELIGIOPOLITICS
        DEFINE_DEVICE
        vdvELK
        dvELK
        DEFINE_VARIABLE
        CHAR cELK_IP[1]
    #end_if
    
    I added lines 2-8. They don't have any effect on the program but NS will do the syntax highlighting and autocomplete for the parameter variables that it otherwise would not have.
  • yuriyuri Posts: 861
    Why would you use the #IF_DEFINED directive. and not just put the lines under DEFINE_DEVICE?
    It might not look that clean, but it probably works just as well, right?
  • BigsquatchBigsquatch Posts: 216
    yuri wrote: »
    Why would you use the #IF_DEFINED directive. and not just put the lines under DEFINE_DEVICE?
    It might not look that clean, but it probably works just as well, right?

    Because then you would be re-defining the module parameters. I'm not sure that it would even compile.

    The pre-compiler directive "tricks" the IDE into highlighting the devices and variables as if they were defined right there even though the defines never even make it into the compiled code.
  • yuriyuri Posts: 861
    Bigsquatch wrote: »
    Because then you would be re-defining the module parameters. I'm not sure that it would even compile.

    The pre-compiler directive "tricks" the IDE into highlighting the devices and variables as if they were defined right there even though the defines never even make it into the compiled code.

    true, silly me :)
  • rfletcher wrote: »
    I started doing this in my modules recently after someone (maybe you vining?) mentioned it on the forums.

    it can be done with one fewer compiler directive too :D
    #if_defined DONOTDEFINETHISVALUE
    
    define_device...
    
    #end_if
    

    at least as long as no one ever comes along and defines DONOTDEFINETHISVALUE :p


    I see your optimization and raise you foolproof! I suggest using #IF_NOT_DEFINED with a built-in variable that will always be defined:
    #IF_NOT_DEFINED __NETLINX__
    ... code ...
    #END_IF
    

    __NETLINX__ is the first line of code in NetLinx.axi so it's always defined. If it's not defined, your code ain't running anyway.
  • rfletcherrfletcher Posts: 217
    I see your optimization and raise you foolproof! I suggest using #IF_NOT_DEFINED with a built-in variable that will always be defined:
    #IF_NOT_DEFINED __NETLINX__
    ... code ...
    #END_IF
    

    __NETLINX__ is the first line of code in NetLinx.axi so it's always defined. If it's not defined, your code ain't running anyway.

    well played sir :D

    lol, I always forget Netlinx.axi is there. At some point I should poke around and see what's in there again.

    -Ryan
Sign In or Register to comment.