GMS 2 [SOLVED] Return 1d Array from Native Extension Function?

Discussion in 'Advanced Programming Discussion' started by Samuel Venable, Jul 12, 2019.

  1. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,217
    Is it possible to return a 1d array from a native, non-gml extension? i.e. a dll/dylib/so

    string in gamemaker extensions is a pointer, so would that mean I'd simply return a std::vector?

    Or would the compiler I would use, which all compilers implement std::vector differently, make this impossible?
     
  2. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,136
    The only way I know of is to do this (C++) as the example;
    • (GML) Create buffer with the size of the array that you have on the C++ size
    • (GML) Send buffer_get_address(buffer) to C++ as a 'ty_string' (a pointer)
    • (C++) Fill the buffer with your information
    • (GML) Use buffer_peek or whatever to use the data as you wish
    I did actually send a request the other day for 'buffer_set_pointer(address, type, length)' so you can specify the address of the buffer when creating the data on the C++ side first and tell GMS where the buffer is, what type it is, and the length. But we shall see if anything comes of it.
     
    Joe Ellis and Samuel Venable like this.
  3. Samuel Venable

    Samuel Venable Time Killer

    Joined:
    Sep 13, 2016
    Posts:
    1,217
    Thank you!
     
    Joe Ellis and Lonewolff like this.
  4. Joe Ellis

    Joe Ellis Member

    Joined:
    Aug 30, 2016
    Posts:
    890
    @Lonewolff, I love that you sent that request, I have a feeling that it will be on the bottom of their priority list, but it should be something that's available for people who know how to use it.
    Also from my experience is exactly the same as lonewolff, create the buffer(1d array) in the exact right size that the dll will fill after getting the buffer's address (I just wrote this for a 2nd validation (no rivalry (at least not unfriendly)) ) )
     
    Last edited: Jul 13, 2019
  5. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,136

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice