Home AMX User Forum NetLinx Studio

New compiler features

I am a programmer from the business world. I am used to writing C and C++ code. There are a features to the NetLinx compiler/interpreter that I think are lacking.

There are features that I am sure everyone would like to see.

I would like to see:

1) the ability to pass more complex objects into a DEFINE_FUNCTION. I understand that if it is passed in by value that could be a big issue, but by reference it would not be. When can we expect the ability to use structures with functions ?

2) the ability to RETURN from a function within a WAIT_UNTIL or WAIT

3) Some kind of serialization technique for a resource or lock

I would like this thread to start a dialog of other features that everyone would like to see.

Is the NetLinx compiler being developed further or is everything, on a go-forward basis, relying on Duet ?

Comments

  • SensivaSensiva Posts: 211
    There is a Sticky Thread

    you may post your suggestion Here

    I'd like returning returning function within waits and wait_until too... but it seems this is the nature of Netlinx Algorithm execution.

    Thanks
  • jprovanjprovan Posts: 16
    Thanks. I will read what others are asking for. That actually was the intent of starting this thread. I just didn't know that someone had already started one.

    Thanks again.
  • Joe HebertJoe Hebert Posts: 2,159
    jprovan wrote:
    1) the ability to pass more complex objects into a DEFINE_FUNCTION. I understand that if it is passed in by value that could be a big issue, but by reference it would not be. When can we expect the ability to use structures with functions ?
    Netlinx does not allow us to pass in any type of variable by value (it sure would be a nice option though) as all params are passed in by reference. If you need to do work on a param inside a function but you want to keep the original value of the param intact then the best bet is to make a local copy inside the function first. I?ve shot myself in the foot a few times forgetting that everything is passed in by reference.

    You can use structs as params for a function and you can use structs inside functions. The only thing that isn?t legal is to RETURN a struct but that?s easy enough to work around since you can pass the return container in as a param. Here is some sample code demonstrating you can do just about anything you want with structs and functions.
    DEFINE_DEVICE
    
    dvTP = 10001:1:0
    
    DEFINE_TYPE
    
    STRUCT	_sStruct {
    
       INTEGER SomeData
       INTEGER MoreData
       
    }
    
    DEFINE_VARIABLE
    
    _sStruct sMyStructs[3]
    
    DEFINE_FUNCTION  fnPrintStructData(_sStruct someStructs[]) {
    
       INTEGER x
       
       SEND_STRING 0, 'Printing Struct Data'
       FOR (x=1; x<=LENGTH_ARRAY(someStructs); x++) {
          SEND_STRING 0, ITOA(someStructs[x].SomeData)
          SEND_STRING 0, ITOA(someStructs[x].MoreData)
       }
       
    
    }
    
    DEFINE_FUNCTION fnReverseStructData (_sStruct someStructs[]) {
    
       INTEGER x
       _sStruct tempStruct
    
       SEND_STRING 0, 'Reversing Struct Data'
       FOR (x=1; x<=LENGTH_ARRAY(someStructs); x++) {
    
          tempStruct = someStructs[x]
          
          someStructs[x].SomeData = tempStruct.MoreData
          someStructs[x].MoreData = tempStruct.SomeData
       }
       
    }
    
    //Can't return complex types
    //DEFINE_FUNCTION _sStruct fnThisAintLegal() {
    //
    //
    //}
    
    
    DEFINE_START
    
    sMyStructs[1].SomeData = 10
    sMyStructs[1].MoreData = 20
    
    sMyStructs[2].SomeData = 30
    sMyStructs[2].MoreData = 40
    
    sMyStructs[3].SomeData = 50
    sMyStructs[3].MoreData = 60
    
    SET_LENGTH_ARRAY(sMyStructs,3)
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,1] {
    
       PUSH: {
       
          fnPrintStructData(sMyStructs)
          fnReverseStructData(sMyStructs)
          fnPrintStructData(sMyStructs)
    
       }
    
    }
    

    And the output when button 1 is pushed:
    Line      1 :: Printing Struct Data - 04:27:30
    Line      2 :: 10 - 04:27:30
    Line      3 :: 20 - 04:27:30
    Line      4 :: 30 - 04:27:30
    Line      5 :: 40 - 04:27:30
    Line      6 :: 50 - 04:27:30
    Line      7 :: 60 - 04:27:30
    Line      8 :: Reversing Struct Data - 04:27:30
    Line      9 :: Printing Struct Data - 04:27:30
    Line     10 :: 20 - 04:27:30
    Line     11 :: 10 - 04:27:30
    Line     12 :: 40 - 04:27:30
    Line     13 :: 30 - 04:27:30
    Line     14 :: 60 - 04:27:30
    Line     15 :: 50 - 04:27:30
    

    jprovan wrote:
    2) the ability to RETURN from a function within a WAIT_UNTIL or WAIT
    I don?t know how that can be accomplished logically. When a wait is encountered, the statements inside the wait are pushed into the wait list/queue (I?m not sure what it?s officially called) and the execution of code is continued at the next line after the wait block. The program itself doesn?t wait so the code will exit the function before the wait can even be checked for expiration. Maybe if you can elaborate on what you?d like to accomplish, someone can post a suggestion.
    jprovan wrote:
    Some kind of serialization technique for a resource or lock
    Are you referring to some sort of Mutex or Semaphore? Netlinx is not mutli-threaded. I?m pretty sure there is separate thread that runs the hardware but the Netlinx code we write runs in one thread. Or are you talking about something else?

    HTH
  • ErikJackmanErikJackman Posts: 31
    Joe Hebert wrote: »
    I don?t know how that can be accomplished logically. When a wait is encountered, the statements inside the wait are pushed into the wait list/queue (I?m not sure what it?s officially called) and the execution of code is continued at the next line after the wait block. The program itself doesn?t wait so the code will exit the function before the wait can even be checked for expiration. Maybe if you can elaborate on what you?d like to accomplish, someone can post a suggestion.

    What the orignal poster is refering to is the ability to have a variable assigned to the value returned from a function. The calling block of code essentially pauses while it calculates the value by executing the function. Only once the value has been assigned does the calling block of code procede with its execution.

    I too would love to have that added to NetLinx, its a very handy technique.
Sign In or Register to comment.