* how do I create my own callback functions with return value?

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 878
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

how do I create my own callback functions with return value?

Post by Ron Melby » 19 May 2021 14:12

I have never done anything like this, and I am not conversant enough and there are no examples I can find to do this.

I need to call or pcall a callback function defined in your program and get a return value

rtx = cb_io_3(k, v)

the internals of the callback decision are unimportant at the moment, but are based on data you send in to call my program
you may have 0 to any number of callbacks for this io and it is based on fields you supply therefore
you may have
cb_io_1
cb_io_2
cb_io_3
cb_io_n


['mtx_fn'] =
{
[3] =
{
(function = cb_io_[ix](k, v) end, }
-- how do I pcall
--how do I get the function return 'o' or 'io'
end),
}

I can get nothing on this order to compile:

['mtx_fn'] = {[3] = function = ((rtx) = cb_io_[ix](k, v} end))},

so -- is it like---?
my first example
in my entry
and I code
rtx = ['mtx_fn]()

and your callback looks something like

function cb_io_3( k, v)
--some such nonsense to return a value
if alwchg = '0' then
return 'o'
else
return 'io'
end
end

what other things should I be doing to make it work?
Last edited by Ron Melby on 19 May 2021 14:16, edited 1 time in total.
FH V.6.2.7 Win 10 64 bit

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: how do I create my own callback functions with return value?

Post by ColeValleyGirl » 19 May 2021 14:14

Have the callback functions as parameters to your function.

User avatar
Ron Melby
Megastar
Posts: 878
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how do I create my own callback functions with return value?

Post by Ron Melby » 19 May 2021 14:23

I dont understand that, nor how to do that, at least not that I know of, can you elucidate, Helen? Thanks.
FH V.6.2.7 Win 10 64 bit

User avatar
Ron Melby
Megastar
Posts: 878
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: how do I create my own callback functions with return value?

Post by Ron Melby » 19 May 2021 14:28

oh wait....
k = key
v = val
rtx = ''
you mean
cb_io_[ix-](k, v, rtx) end

and then use rtx after the callback, right?
FH V.6.2.7 Win 10 64 bit

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: how do I create my own callback functions with return value?

Post by ColeValleyGirl » 19 May 2021 14:29

Code: Select all

function X (doStuff)
[snip]
doStuff(some parameters that match the requirements of doStuff)
[snip]
end

function doSomething()
--do something
end

X(doSomething)
You can add extra parameters to the call on X

Post Reply