First class function / callback help

About Monkey 2 Forums Monkey 2 Programming Help First class function / callback help

This topic contains 5 replies, has 3 voices, and was last updated by  abakobo 1 week, 1 day ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #16091

    jondecker76

    Participant

    There has to be something that I’m not understanding about callbacks.  I can’t find any documentation other than the fact that first class functions are supported, and numerous searches back here have yielded no explanations.

    I’m trying to wrap the sqlite3 module into a much easier to use class, but I’ve met a roadblock with how to handle a callback function.

    I’m currently trying to do the following (paired down for readability)

    The CB implementation matches exactly what the parameter definition is expecting.  I’ve tried prefixing it with Varptr with no luck either.  So how can I use my function “CB” as a parameter to the sqlite3_exec() function?  If I change it to Null, then the function runs, so I know this is where the issue is, but can’t for the life of me figure out how to get it to work with a callback, and I’ve found no documentation at all to figure it out.

     

    Thanks!

    #16092

    NoOdle

    Participant

    The only thing I can see that might affect it is the callback char_t params are defined as PTR PTR. Just a guess, only started playing with Monkey2 the other day and this is all new to me.

    #16093

    jondecker76

    Participant

    Thanks for the response.  I will give that a try.

    I had noticed before that a passing a Ptr with a Varptr preface would show up as ptr ptr when hovered over, so I guess I was assuming that would have been expected behavior.

    Thanks again

    #16095

    abakobo

    Participant

    The fisrt class functions has never been a problem with callbacks, for me.

    To get your ‘char_t Ptr Ptr’ you might want to use ‘VarPtr myChar_tArray.Data’ as ‘Array.Data’ is already a pointer to the first element of the array. Edit doesn’t work. I’ve put some working code on the codebox below.

    I’ve joined a little zip/demo code using external function pointers with first class function in various ‘directions’.

    Attachments:
    1. C_callback_fn_ptr.zip
    #16098

    jondecker76

    Participant

    Thanks to both of you!

    I finally have it figured out.

    I do a lot of database work, and have been evaluating Monkey2 for a large project that I would like to make cross-platform.  I find the current sqlite3 library very ugly and difficult to work with, so I created a very simple wrapper class that makes things so much easier for me.  Here is the current state, though I do plan on making this more complete and turning this into a module.  Thanks again for the help!

    #16099

    abakobo

    Participant

    Nice!

    Note that you can assign a class instance’s method to a first class function too.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.