Macro calling

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 2180
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 177 times
Been thanked: 1022 times

Re: Macro calling

Post by mnfisher »

A few thoughts.....

I did a simple example - that allows macros with names 'A' to 'Z' - note that if you want to use lower case - you can either alter the call to .c - 'a' (instead of (.c - 'A')) - or convert the lower case letter to upper case.
I use a sparse array of 26 function pointers (0..25) - this could be extended (for example fn_table[128] then call fn_table['A']( ))

I added a small macro CallString that calls each character of a string passed as an argument in turn - there a couple of examples. Note that 'undefined' macros - are ignored (I threw an 'E' into one of the strings)
for example CallString("ABCDABCDZ") or CallString(.cmd_string)

The function table is initialised in supplementary code....

Code: Select all

typedef void (*function)();
function fn_table[26] = {
[0] = FCM_A,
[1] = FCM_B,
[2] = FCM_C,
[3] = FCM_D,
['Z' - 'A'] = FCM_Z};  // I handle 'A' to 'Z' as 0..25
It is necessary to get the addresses of the functions (Flowcode (C) is a compiled language and functions are called with 'call fn_address' at runtime (not call "function_name"))

I would recommend giving functions (and variables) meaningful names rather than single characters - but in this instance it is quicker to do it this way (storing a string of each function name and then searching would add overhead at runtime)

The function signature could be altered to allow arguments to be passed (or a value returned by the macros)

Martin
Attachments
macro_table_2.fcfx
(14.01 KiB) Downloaded 1863 times
(view online)

medelec35
Valued Contributor
Posts: 2438
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 783 times
Been thanked: 844 times

Flowcode v9 Re: Macro calling

Post by medelec35 »

Hi.
I have use a string array so you can use different string macro names rather than sticking to 1 character.
Flowchart does fully simulate.
I did nest them which made it look neater, but its more difficult to follow.
Un-nested decision branches just for the demo
Attachments
Macro Table Demo.fcfx
(13.56 KiB) Downloaded 1862 times
(view online)
Martin

alanwms
Posts: 166
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 27 times
Been thanked: 8 times

Re: Macro calling

Post by alanwms »

In the Command_list_String[0] = 'i' the letter "I" s the name of my macro. I was hoping to call macro "I" but the compiler tries to call macro FCL_i which does not work.
I just want to call macro "I"

mnfisher
Valued Contributor
Posts: 2180
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 177 times
Been thanked: 1022 times

Re: Macro calling

Post by mnfisher »

What code are you using? - both methods given above work as expected - can you post the fcfx file you are testing?

Martin

Steve-Matrix
Matrix Staff
Posts: 2033
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 308 times
Been thanked: 472 times

Re: Macro calling

Post by Steve-Matrix »

Thanks Martin, and Martin. Interesting examples.

You probably know this already, but or the @medelec35 project, you can use direct string comparisons in v11 - e.g. a decision with the following expression:

Code: Select all

.MacroTable[.Index] == "macro5"

This makes it a bit easier to read that the current expression:

Code: Select all

Compare$(.MacroTable[.Index], "macro5", 0) == 0

Post Reply