20,741
edits
m (→Hash Manipulation API: using a HASHSET macro) |
|||
Line 252: | Line 252: | ||
int naMember_get(naRef obj, naRef field, naRef* out); | int naMember_get(naRef obj, naRef field, naRef* out); | ||
int naMember_cget(naRef obj, const char* field, naRef* out); | int naMember_cget(naRef obj, const char* field, naRef* out); | ||
A common way to set hash field members easily, is using a simple macro like: | |||
<syntaxhighlight lang="C"> | |||
#define HASHSET(s,l,n) naHash_set(navdata, naStr_fromdata(naNewString(c),s,l),n) | |||
//... do your hash setup here | |||
#undef HASHSET | |||
</syntaxhighlight> | |||
As you can see, this allows you to easily set up hash fields. | |||
The macro can be even further simplified by automatically computing the length of the hash key using strlen() instead of the explicit length argument: | |||
<syntaxhighlight lang="C"> | |||
#define HASHSET(s,n) naHash_set(navdata, naStr_fromdata(naNewString(c),s,strlen(s)),n) | |||
//... do your hash setup here | |||
#undef HASHSET | |||
</syntaxhighlight> | |||
= Conversion & Comparison routines = | = Conversion & Comparison routines = |