X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScripting%2Fnasal-props.cxx;h=16d9db361a24acb90afcb365f0a024e18f415e09;hb=2af076e6cb12764c53a300c19c8d5310693b1b29;hp=b315d1aaa0715d8f4fa2bff7bd4539368e2e9118;hpb=5146868bfb63895edb6c89b24a9ba216420485c2;p=flightgear.git diff --git a/src/Scripting/nasal-props.cxx b/src/Scripting/nasal-props.cxx index b315d1aaa..16d9db361 100644 --- a/src/Scripting/nasal-props.cxx +++ b/src/Scripting/nasal-props.cxx @@ -26,17 +26,17 @@ using namespace std; static void propNodeGhostDestroy(void* ghost) { - SGPropertyNode_ptr* prop = (SGPropertyNode_ptr*)ghost; - delete prop; + SGPropertyNode* prop = static_cast(ghost); + if (!SGPropertyNode::put(prop)) delete prop; } naGhostType PropNodeGhostType = { propNodeGhostDestroy, "prop" }; -naRef propNodeGhostCreate(naContext c, SGPropertyNode* n) +naRef propNodeGhostCreate(naContext c, SGPropertyNode* ghost) { - if(!n) return naNil(); - SGPropertyNode_ptr* ghost = new SGPropertyNode_ptr(n); - return naNewGhost(c, &PropNodeGhostType, ghost); + if(!ghost) return naNil(); + SGPropertyNode::get(ghost); + return naNewGhost(c, &PropNodeGhostType, ghost); } naRef FGNasalSys::propNodeGhost(SGPropertyNode* handle) @@ -49,15 +49,14 @@ SGPropertyNode* ghostToPropNode(naRef ref) if (!naIsGhost(ref) || (naGhost_type(ref) != &PropNodeGhostType)) return NULL; - SGPropertyNode_ptr* pp = (SGPropertyNode_ptr*) naGhost_ptr(ref); - return pp->ptr(); + return static_cast(naGhost_ptr(ref)); } #define NASTR(s) s ? naStr_fromdata(naNewString(c),(char*)(s),strlen(s)) : naNil() // // Standard header for the extension functions. It turns the "ghost" -// found in arg[0] into a SGPropertyNode_ptr*, and then "unwraps" the +// found in arg[0] into a SGPropertyNode_ptr, and then "unwraps" the // vector found in the second argument into a normal-looking args // array. This allows the Nasal handlers to do things like: // Node.getChild = func { _getChild(me.ghost, arg) } @@ -66,7 +65,7 @@ SGPropertyNode* ghostToPropNode(naRef ref) if(argc < 2 || !naIsGhost(args[0]) || \ naGhost_type(args[0]) != &PropNodeGhostType) \ naRuntimeError(c, "bad argument to props function"); \ - SGPropertyNode_ptr node = *(SGPropertyNode_ptr*)naGhost_ptr(args[0]); + SGPropertyNode_ptr node = static_cast(naGhost_ptr(args[0])); #define NODEARG() \ NODENOARG(); \ @@ -231,8 +230,8 @@ static naRef f_equals(naContext c, naRef me, int argc, naRef* args) if( !naIsGhost(rhs) || naGhost_type(rhs) != &PropNodeGhostType ) return naNum(false); - SGPropertyNode_ptr node_rhs = *(SGPropertyNode_ptr*)naGhost_ptr(rhs); - return naNum(node == node_rhs); + SGPropertyNode* node_rhs = static_cast(naGhost_ptr(rhs)); + return naNum(node.ptr() == node_rhs); } template @@ -535,9 +534,9 @@ static naRef f_removeChild(naContext c, naRef me, int argc, naRef* args) naRef child = naVec_get(argv, 0); naRef index = naVec_get(argv, 1); if(!naIsString(child) || !naIsNum(index)) return naNil(); - SGPropertyNode_ptr n = 0; + SGPropertyNode_ptr n; try { - n = node->removeChild(naStr_data(child), (int)index.num, false); + n = node->removeChild(naStr_data(child), (int)index.num); } catch (const string& err) { naRuntimeError(c, (char *)err.c_str()); } @@ -557,14 +556,14 @@ static naRef f_removeChildren(naContext c, naRef me, int argc, naRef* args) if(naIsNil(argv) || naVec_size(argv) == 0) { // Remove all children for(int i = node->nChildren() - 1; i >=0; i--) - naVec_append(result, propNodeGhostCreate(c, node->removeChild(i, false))); + naVec_append(result, propNodeGhostCreate(c, node->removeChild(i))); } else { // Remove all children of a specified name naRef name = naVec_get(argv, 0); if(!naIsString(name)) return naNil(); try { vector children - = node->removeChildren(naStr_data(name), false); + = node->removeChildren(naStr_data(name)); for(unsigned int i=0; iremoveAllChildren(); + return propNodeGhostCreate(c, node); +} // Alias this property to another one; returns 1 on success or 0 on failure // (only applicable to tied properties). @@ -589,7 +597,7 @@ static naRef f_alias(naContext c, naRef me, int argc, naRef* args) 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 if(naIsGhost(prop)) al = static_cast(naGhost_ptr(prop)); else throw string("props.alias() with bad argument"); } catch (const string& err) { naRuntimeError(c, (char *)err.c_str()); @@ -665,30 +673,31 @@ static struct { naCFunction func; const char* name; } propfuncs[] = { - { f_getType, "_getType" }, - { f_getAttribute, "_getAttribute" }, - { f_setAttribute, "_setAttribute" }, - { f_getName, "_getName" }, - { f_getIndex, "_getIndex" }, - { f_equals, "_equals" }, - { f_getValue, "_getValue" }, - { f_setValue, "_setValue" }, - { f_setIntValue, "_setIntValue" }, - { f_setBoolValue, "_setBoolValue" }, - { f_setDoubleValue, "_setDoubleValue" }, - { f_getParent, "_getParent" }, - { f_getChild, "_getChild" }, - { f_getChildren, "_getChildren" }, - { f_addChild, "_addChild" }, - { f_addChildren, "_addChildren" }, - { f_removeChild, "_removeChild" }, - { f_removeChildren, "_removeChildren" }, - { f_alias, "_alias" }, - { f_unalias, "_unalias" }, - { f_getAliasTarget, "_getAliasTarget" }, - { f_getNode, "_getNode" }, - { f_new, "_new" }, - { f_globals, "_globals" }, + { f_getType, "_getType" }, + { f_getAttribute, "_getAttribute" }, + { f_setAttribute, "_setAttribute" }, + { f_getName, "_getName" }, + { f_getIndex, "_getIndex" }, + { f_equals, "_equals" }, + { f_getValue, "_getValue" }, + { f_setValue, "_setValue" }, + { f_setIntValue, "_setIntValue" }, + { f_setBoolValue, "_setBoolValue" }, + { f_setDoubleValue, "_setDoubleValue" }, + { f_getParent, "_getParent" }, + { f_getChild, "_getChild" }, + { f_getChildren, "_getChildren" }, + { f_addChild, "_addChild" }, + { f_addChildren, "_addChildren" }, + { f_removeChild, "_removeChild" }, + { f_removeChildren, "_removeChildren" }, + { f_removeAllChildren, "_removeAllChildren" }, + { f_alias, "_alias" }, + { f_unalias, "_unalias" }, + { f_getAliasTarget, "_getAliasTarget" }, + { f_getNode, "_getNode" }, + { f_new, "_new" }, + { f_globals, "_globals" }, { 0, 0 } };