delete prop;
}
-naGhostType PropNodeGhostType = { propNodeGhostDestroy };
+naGhostType PropNodeGhostType = { propNodeGhostDestroy, "prop" };
static naRef propNodeGhostCreate(naContext c, SGPropertyNode* n)
{
static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
{
NODEARG();
- if(naVec_size(argv) == 0) return naNum((*node)->getAttributes());
+ if(naVec_size(argv) == 0) return naNum(unsigned((*node)->getAttributes()));
naRef val = naVec_get(argv, 0);
char *a = naStr_data(val);
SGPropertyNode::Attribute attr;
if(!a) a = "";
- if(!strcmp(a, "children")) return naNum((*node)->nChildren());
+ if(!strcmp(a, "last")) return naNum(SGPropertyNode::LAST_USED_ATTRIBUTE);
+ else if(!strcmp(a, "children")) return naNum((*node)->nChildren());
else if(!strcmp(a, "listeners")) return naNum((*node)->nListeners());
else if(!strcmp(a, "references")) return naNum(node->getNumRefs());
else if(!strcmp(a, "tied")) return naNum((*node)->isTied());
else if(!strcmp(a, "alias")) return naNum((*node)->isAlias());
- else if(!strcmp(a, "last")) return naNum(SGPropertyNode::LAST_USED_ATTRIBUTE);
else if(!strcmp(a, "readable")) attr = SGPropertyNode::READ;
else if(!strcmp(a, "writable")) attr = SGPropertyNode::WRITE;
else if(!strcmp(a, "archive")) attr = SGPropertyNode::ARCHIVE;
naRef child = naVec_get(argv, 0);
naRef index = naVec_get(argv, 1);
if(!naIsString(child) || !naIsNum(index)) return naNil();
+ SGPropertyNode_ptr n = 0;
try {
- (*node)->removeChild(naStr_data(child), (int)index.num, false);
+ n = (*node)->removeChild(naStr_data(child), (int)index.num, false);
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
}
- return naNil();
+ return propNodeGhostCreate(c, n);
}
static naRef f_removeChildren(naContext c, naRef me, int argc, naRef* args)
return result;
}
+static naRef f_alias(naContext c, naRef me, int argc, naRef* args)
+{
+ NODEARG();
+ SGPropertyNode* al;
+ naRef prop = naVec_get(argv, 0);
+ try {
+ if(naIsString(prop)) al = globals->get_props()->getNode(naStr_data(prop), true);
+ else if(naIsGhost(prop)) al = *(SGPropertyNode_ptr*)naGhost_ptr(prop);
+ else throw string("props.alias() with bad argument");
+ } catch (const string& err) {
+ naRuntimeError(c, (char *)err.c_str());
+ return naNil();
+ }
+ return naNum((*node)->alias(al));
+}
+
+static naRef f_unalias(naContext c, naRef me, int argc, naRef* args)
+{
+ NODEARG();
+ return naNum((*node)->unalias());
+}
+
+static naRef f_getAliasTarget(naContext c, naRef me, int argc, naRef* args)
+{
+ NODEARG();
+ return propNodeGhostCreate(c, (*node)->getAliasTarget());
+}
+
static naRef f_getNode(naContext c, naRef me, int argc, naRef* args)
{
NODEARG();
{ f_getChildren, "_getChildren" },
{ f_removeChild, "_removeChild" },
{ f_removeChildren, "_removeChildren" },
+ { f_alias, "_alias" },
+ { f_unalias, "_unalias" },
+ { f_getAliasTarget, "_getAliasTarget" },
{ f_getNode, "_getNode" },
{ f_new, "_new" },
{ f_globals, "_globals" },