This very simple example shows how to use some of the basic features of eina value: setting and getting values, converting between types and printing a value as a string.
Our main function starts out with the basic, declaring some variables and initializing eina:
Now we can jump into using eina value. We set a value, get this value and then print it:
In the above snippet of code we printed an int
value, we can however print the value as a string:
And once done with a value it's good practice to destroy it:
We now reuse v
to store a string, get its value and print it:
s
is the value and not returned by eina_value_to_string()
we don't need to free it.Just because we stored a string doesn't mean we can't use the eina_value_to_string()
function, we can and it's important to note that it will return not the stored string but rather a copy of it (one we have to free):
And now to explore conversions between two types we'll create another value:
And make sure v
and others
have different types:
We then set a value to v
and have it converted, to do this we don't need to tell to which type we want to convert, we just say were we want to store the converted value and eina value will figure out what to convert to, and how:
And now let's check the conversion worked:
But converting to strings is not particularly exciting, eina_value_to_string()
already did that, so now let's make the conversion the other way around, from string to int:
And once done, destroy the values:
Full source code: eina_value_01.c