Effectively, what the execute_calculator_code(); function does is cause the compiler to generate the identical .asm code as would be created by the more explicit/verbose method described in the first part of my Wiki article (using the method you've implemented).
Bill, I'm not sure I understand you right. Do you mean the function execute_calculator_code() HAS identical .asm code? Or the compiler does inject something gauge-specific apart from what we code? Although all panel handling functions declared in GAUGES.h are function pointers, I wouldn't expect the compiler to generate any additional black-box code every time I recompile my stuff...
Let's take it step-by-step:
1. In first method you've described on
http://forums.flightsim.com/fswiki/i...es_in_C_Gauges
We (a) define our C variable, define the ID of an XML variable to be referenced from C code and register this XML variable,
then we (b) call set_named_variable_value() in our gauge callback in the event of PANEL_SERVICE_PRE_UPDATE. This way we get XML variable to automatically reflect the state of our C variable because PANEL_SERVICE_PRE_UPDATE comes every time the gauge is to be redrawn. Everything is clear and logical.
2. In the second method we use
execute_calculator_code() with the "Expression" (As a String Parameter). The question still is what the function really does. I don't think the compiler makes something magic with the code and injects something ACES's specific which eventually performs the same way as the first method does. Correct me if I'm wrong.
One important question. If I use
execute_calculator_code() method just to control the value of an L:var from C, like:
Code:
execute_calculator_code("(L:MyCustomVariable,bool)",NULL,&my_custom_variable,NULL);
Do I have to call this function every time I want to change the state of the XML variable? Or it is enough to only set corresponding C variable (my_custom_variable) afterwards and expect the XML variable to automaticvally reflect this change probably because ACES saves the variable's pointer and checks its state every time the gauge is redrawn???
I don't really think so... Because the function takes a pointer of a C variable which could point into our function's local stack. Nobody would implement that. This could only work with C variables defined in global context. So, in general,
execute_calculator_code() has to be called every time I've changed the value of a C variable, or if we set XML variables without the use of C variables:
Code:
execute_calculator_code("1(>L:MyCustomVariable,bool)", NULL, NULL, NULL);
The
execute_calculator_code() function clearly seems very handy since it relieves you from having to write all the code from first method, but since the function evaluates a string <CODE>expression</CODE> I would be very carefull about its usage especially in time critical domains.
I'd really like to know your opinion.