setAttribute("archive", 1) sets this attribute to "true", and
getAttribute("archive") returns 1 if the attribute is set, and 0 otherwise. Allow to query and to set all properties by not specifying an attribute string: getAttribute() returns all attributes bit coded in an integer, and setAttribute(attr) sets all attributes. No assumptions may be made about the meaning of the bits -- they can be changed in future fgfs releases. The only valid use is to compare or set attribute numbers obtained in the same fgfs run. This is meant for allowing full copies of property branches. Also add getAttribute query strings "children" for the number of children, and "alias".
This commit is contained in:
parent
2621ba7a47
commit
b5f53c349f
1 changed files with 12 additions and 5 deletions
|
@ -77,19 +77,21 @@ static naRef f_getType(naContext c, naRef me, int argc, naRef* args)
|
||||||
static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
|
static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
|
||||||
{
|
{
|
||||||
NODEARG();
|
NODEARG();
|
||||||
|
if(naVec_size(argv) == 0) return naNum((*node)->getAttributes());
|
||||||
naRef val = naVec_get(argv, 0);
|
naRef val = naVec_get(argv, 0);
|
||||||
char *a = naStr_data(val);
|
char *a = naStr_data(val);
|
||||||
SGPropertyNode::Attribute attr;
|
SGPropertyNode::Attribute attr;
|
||||||
if(!a) a = "";
|
if(!a) a = "";
|
||||||
if(!strcmp(a, "read")) attr = SGPropertyNode::READ;
|
if(!strcmp(a, "children")) return naNum((*node)->nChildren());
|
||||||
|
else if(!strcmp(a, "tied")) return naNum((*node)->isTied());
|
||||||
|
else if(!strcmp(a, "alias")) return naNum((*node)->isAlias());
|
||||||
|
else if(!strcmp(a, "read")) attr = SGPropertyNode::READ;
|
||||||
else if(!strcmp(a, "write")) attr = SGPropertyNode::WRITE;
|
else if(!strcmp(a, "write")) attr = SGPropertyNode::WRITE;
|
||||||
else if(!strcmp(a, "archive")) attr = SGPropertyNode::ARCHIVE;
|
else if(!strcmp(a, "archive")) attr = SGPropertyNode::ARCHIVE;
|
||||||
else if(!strcmp(a, "trace-read")) attr = SGPropertyNode::TRACE_READ;
|
else if(!strcmp(a, "trace-read")) attr = SGPropertyNode::TRACE_READ;
|
||||||
else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
|
else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
|
||||||
else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
|
else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
|
||||||
else if(!strcmp(a, "tied")) {
|
else {
|
||||||
return naNum((*node)->isTied());
|
|
||||||
} else {
|
|
||||||
naRuntimeError(c, "props.getAttribute() with invalid attribute");
|
naRuntimeError(c, "props.getAttribute() with invalid attribute");
|
||||||
return naNil();
|
return naNil();
|
||||||
}
|
}
|
||||||
|
@ -100,8 +102,13 @@ static naRef f_setAttribute(naContext c, naRef me, int argc, naRef* args)
|
||||||
{
|
{
|
||||||
NODEARG();
|
NODEARG();
|
||||||
naRef val = naVec_get(argv, 0);
|
naRef val = naVec_get(argv, 0);
|
||||||
char *a = naStr_data(val);
|
if(naVec_size(argv) == 1 && naIsNum(val)) {
|
||||||
|
naRef ret = naNum((*node)->getAttributes());
|
||||||
|
(*node)->setAttributes((int)val.num);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
SGPropertyNode::Attribute attr;
|
SGPropertyNode::Attribute attr;
|
||||||
|
char *a = naStr_data(val);
|
||||||
if(!a) a = "";
|
if(!a) a = "";
|
||||||
if(!strcmp(a, "read")) attr = SGPropertyNode::READ;
|
if(!strcmp(a, "read")) attr = SGPropertyNode::READ;
|
||||||
else if(!strcmp(a, "write")) attr = SGPropertyNode::WRITE;
|
else if(!strcmp(a, "write")) attr = SGPropertyNode::WRITE;
|
||||||
|
|
Loading…
Reference in a new issue