Hm. I wrote test code 

--8<---------------cut here---------------start------------->8---
Uint8 value = 0;
int
main(int argc, char *argv[])
{

        if (AG_InitCore("ag-bind-test", 0) == -1) {
                fprintf(stderr, "%s\n", AG_GetError());
                return (1);
        }

        AG_BindUint32(agConfig, "Value", &value);

        fprintf(stdout, "Value = %i\n", AG_GetUint32(agConfig, "Value"));
        if (!AG_GetBool(agConfig, "cel.flags.init")){
                value = 1;
                fprintf(stdout, "Looks it run first! set 'Value' to %i\n", 
value);
        }
        value++;
        AG_SetBool(agConfig, "cel.flags.init", 1);
        AG_ObjectSave(agConfig);
        AG_ConfigSave(); // to be sure ,)
        AG_Destroy();
        return (0);
}
--8<---------------cut here---------------end--------------->8---

Result:

--8<---------------cut here---------------start------------->8---
%rm -r ~/.ag-bind-test/
%./loader
Value = 0
Looks it run first! set 'Value' to 1
%./loader                                    # must be 1
Value = 0
%grep cel ~/.ag-bind-test/config.AG_Config   # is cel.flags.init saved 
(affcause yes)
Binary file /home/osprey/.ag-bind-test/config.AG_Config matches
%grep Value ~/.ag-bind-test/config.AG_Config # check for 'Value' in config
%                                            # damn
--8<---------------cut here---------------end--------------->8---

expected:
 
 %./loader
 Value = 0
 Looks it run first! set 'value' to 1
 %./loader
 Value = 1

=), but...

In any case binding shoud be good future of agar.

Julien Nadeau <[email protected]> writes:

> AG_BindFoo() is more often used for widget bindings, but this usage
> is correct and it should work. Are you sure AG_ObjectSave(agConfig)
> is being invoked at program termination (or whenever you want to save
> the changes)?
>
> AG_Destroy() will not internally save the configuration, because you
> might want to display a confirmation dialog on exit, for instance.
>
> On Thu, Aug 20, 2009 at 05:43:02PM +0000, Olexandr Sydorchuk wrote:
>> How to use AG_Bind and make possible to save (and load in future
>> session) variable? For example I have variable 'value' that can be
>> changed not by AG_Set. I suggest to use AG_Bind and hope that when
>> program terminated this value will be saved. But 'value' will saved only
>> after using AG_Set :(. 
>> 
>> --8<---------------cut here---------------start------------->8---
>>  // map variable to 'value'
>>  AG_BindUint32(agConfig, "cel.flags.r", &value);
>>  if (!AG_GetBool(agConfig, "cel.flags.init")){
>>      // here some default value computation
>>      set_default_value(&value); 
>>  }
>>  // just mark that value already setuped 
>>  AG_SetBool(agConfig, "cel.flags.init", 1);
>> --8<---------------cut here---------------end--------------->8---
>> 
>> Sure I can use AG_Set at program's termination, but what profit of
>> AG_Bind than?
>> 
>> _______________________________________________
>> Agar mailing list
>> [email protected]
>> http://libagar.org/lists.html

_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html

Reply via email to