Re: [Celestia-developers] adding a gettrackedobject method to celx
Real-time 3D visualization of space
Status: Beta
Brought to you by:
cjlaurel
From: vincent <vin...@fr...> - 2007-04-16 19:14:08
|
Chris, Actually, making gettrackobject/getselection return nil could break some former scripts. Indeed, some script writers may have applied the name() call 'celestia:getselection:name()' to an empty selection since this was the only way to know whether this selection was empty or not. If the selection was indeed empty, 'celestia:getselection:name() then returned "?". The problem is that these scripts wouldn't work anymore since name() can't be applied to a nil value... @+ Vincent Selon vincent <vin...@fr...>: > Chris, > > I hope you had a great trip to Alaska ! :-) > I've checked in my change to CVS. Here are some further change > that makes gettrackedobject/getselection return nil when no > object is tracked/selected : > > > Index: src/celestia/celx.cpp > =================================================================== > RCS file: /cvsroot/celestia/celestia/src/celestia/celx.cpp,v > retrieving revision 1.105 > diff -u -r1.105 celx.cpp > --- src/celestia/celx.cpp 16 Apr 2007 10:27:32 -0000 1.105 > +++ src/celestia/celx.cpp 16 Apr 2007 17:23:36 -0000 > @@ -3265,7 +3265,11 @@ > checkArgs(l, 1, 1, "No arguments expected to > observer:gettrackedobject"); > > Observer* o = this_observer(l); > - object_new(l, o->getTrackedObject()); > + Selection obj = o->getTrackedObject(); > + if (obj.getType() == Selection::Type_Nil) > + lua_pushnil(l); > + else > + object_new(l, obj); > > return 1; > } > @@ -4216,7 +4220,10 @@ > checkArgs(l, 1, 1, "No arguments expected to > celestia:getselection()"); > CelestiaCore* appCore = this_celestia(l); > Selection sel = appCore->getSimulation()->getSelection(); > - object_new(l, sel); > + if (sel.getType() == Selection::Type_Nil) > + lua_pushnil(l); > + else > + object_new(l, sel); > > return 1; > } > > > Please let me know if this is OK to you. > > @+ > Vincent > > > Selon Chris Laurel <cl...@gm...>: > > > Vincent, > > > > Sorry for the long delay. I just returned from my trip to Alaska > . > > . . Your change looks good. I think we should consider changing > > gettrackedobject and getselection to return nil when there's no > > object tracked or selected. But, this discussion can occur > > independent of your change. > > > > --Chris > > > > On 4/12/07, vincent <vin...@fr...> wrote: > > > > > > Selon vincent <vin...@fr...>: > > > > > > > The 'gettrackedobject()' function return "?" when no object > > > > is currently tracked, precisely as the 'getselection()' > > > > function does when no object is currently selected. > > > > > > Well, actually, getttrackedobject():name() returns "?" when no > > > object is currently tracked. As for that, I noticed that > > > 'gettrackedobject', as well as 'getselection', don't return > > > 'nil' when no object is tracked or selected. So one can't write > > > something like : > > > > > > sel = celestia:getselection() > > > if sel == nil then > > > ... > > > > > > The only way to know whether the selection is empty or not > > > is to apply the name() field on it: > > > > > > sel = celestia:getselection() > > > if sel:name() == "?" then > > > ... > > > > > > Could someone confirm that ? > > > > > > Chris, can I check in my changes ? > > > > > > @+ > > > Vincent > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Celestia-developers mailing list > Cel...@li... > https://lists.sourceforge.net/lists/listinfo/celestia-developers > @+ Vincent |