Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

celx.cpp File Reference

#include <cassert>
#include <cstring>
#include <cstdio>
#include <map>
#include <celengine/astro.h>
#include <celengine/celestia.h>
#include <celengine/cmdparser.h>
#include <celengine/execenv.h>
#include <celengine/execution.h>
#include <celmath/vecmath.h>
#include <celengine/gl.h>
#include "imagecapture.h"
#include <strstream>
#include "celx.h"
#include "celestiacore.h"
#include "lualib.h"

Include dependency graph for celx.cpp:

Go to the source code of this file.

Defines

#define CLASS(i)   ClassNames[(i)]

Typedefs

typedef map< string, uint32FlagMap

Enumerations

enum  FatalErrors { NoErrors = 0, WrongType = 1, WrongArgc = 2, AllErrors = WrongType | WrongArgc }

Functions

static int auxresume (lua_State *L, lua_State *co, int narg)
static int celestia_createcelscript (lua_State *l)
static int celestia_find (lua_State *l)
static int celestia_flash (lua_State *l)
static int celestia_fromjulianday (lua_State *l)
static int celestia_getambient (lua_State *l)
static int celestia_getfaintestvisible (lua_State *l)
static int celestia_getlabelflags (lua_State *l)
static int celestia_getminfeaturesize (lua_State *l)
static int celestia_getminorbitsize (lua_State *l)
static int celestia_getobserver (lua_State *l)
static int celestia_getobservers (lua_State *l)
static int celestia_getorbitflags (lua_State *l)
static int celestia_getrenderflags (lua_State *l)
int celestia_getscreendimension (lua_State *l)
static int celestia_getscriptpath (lua_State *l)
static int celestia_getscripttime (lua_State *l)
static int celestia_getselection (lua_State *l)
static int celestia_getstar (lua_State *l)
static int celestia_getstarcount (lua_State *l)
static int celestia_getstardistancelimit (lua_State *l)
static int celestia_getstarstyle (lua_State *l)
static int celestia_gettextwidth (lua_State *l)
static int celestia_gettime (lua_State *l)
static int celestia_gettimescale (lua_State *l)
static int celestia_hide (lua_State *l)
static int celestia_hidelabel (lua_State *l)
static int celestia_mark (lua_State *l)
static int celestia_new (lua_State *l, CelestiaCore *appCore)
static int celestia_newframe (lua_State *l)
static int celestia_newposition (lua_State *l)
static int celestia_newrotation (lua_State *l)
static int celestia_newvector (lua_State *l)
static int celestia_print (lua_State *l)
static int celestia_requestkeyboard (lua_State *l)
static int celestia_requestsystemaccess (lua_State *l)
static int celestia_select (lua_State *l)
static int celestia_setambient (lua_State *l)
static int celestia_setfaintestvisible (lua_State *l)
static int celestia_setlabelflags (lua_State *l)
static int celestia_setminfeaturesize (lua_State *l)
static int celestia_setminorbitsize (lua_State *l)
static int celestia_setorbitflags (lua_State *l)
static int celestia_setrenderflags (lua_State *l)
static int celestia_setstardistancelimit (lua_State *l)
static int celestia_setstarstyle (lua_State *l)
static int celestia_settime (lua_State *l)
static int celestia_settimescale (lua_State *l)
static int celestia_show (lua_State *l)
static int celestia_showlabel (lua_State *l)
static int celestia_takescreenshot (lua_State *l)
static int celestia_tojulianday (lua_State *l)
static int celestia_tostring (lua_State *l)
static int celestia_unmark (lua_State *l)
static int celestia_unmarkall (lua_State *l)
static int celscript_from_string (lua_State *l, string &script_text)
static int celscript_gc (lua_State *l)
static int celscript_tick (lua_State *l)
static int celscript_tostring (lua_State *l)
static void checkArgs (lua_State *l, int minArgs, int maxArgs, const char *errorMessage)
static void checkTimeslice (lua_State *l, lua_Debug *ar)
static void * CheckUserData (lua_State *l, int index, int id)
static void CreateCelestiaMetaTable (lua_State *l)
static void CreateCelscriptMetaTable (lua_State *l)
static void CreateClassMetatable (lua_State *l, int id)
static void CreateFrameMetaTable (lua_State *l)
static void CreateObjectMetaTable (lua_State *l)
static void CreateObserverMetaTable (lua_State *l)
static void CreatePositionMetaTable (lua_State *l)
static void CreateRotationMetaTable (lua_State *l)
static void CreateVectorMetaTable (lua_State *l)
static void doError (lua_State *l, const char *errorMsg)
static int frame_from (lua_State *l)
static int frame_getcoordinatesystem (lua_State *l)
static int frame_getrefobject (lua_State *l)
static int frame_gettargetobject (lua_State *l)
static int frame_new (lua_State *l, const FrameOfReference &f)
static int frame_to (lua_State *l)
static int frame_tostring (lua_State *l)
static CelestiaCoregetAppCore (lua_State *l, FatalErrors fatalErrors=NoErrors)
LuaStategetLuaStateObject (lua_State *l)
void getObservers (CelestiaCore *appCore, vector< Observer * > &list)
ViewgetViewByObserver (CelestiaCore *appCore, Observer *obs)
static void initBodyTypeMap ()
static void initLabelFlagMap ()
static void initLocationFlagMap ()
static void initMaps ()
static void initRenderFlagMap ()
static bool istype (lua_State *l, int index, int id)
static int object_absmag (lua_State *l)
static int object_getchildren (lua_State *l)
static int object_getinfo (lua_State *l)
static int object_getposition (lua_State *l)
static int object_mark (lua_State *l)
static int object_name (lua_State *l)
static int object_new (lua_State *l, const Selection &sel)
static int object_preloadtexture (lua_State *l)
static int object_radius (lua_State *l)
static int object_spectraltype (lua_State *l)
static int object_tostring (lua_State *l)
static int object_type (lua_State *l)
static int object_unmark (lua_State *l)
static int observer_cancelgoto (lua_State *l)
static int observer_center (lua_State *l)
static int observer_centerorbit (lua_State *l)
static int observer_chase (lua_State *l)
static int observer_deleteview (lua_State *l)
static int observer_equal (lua_State *l)
static int observer_follow (lua_State *l)
static int observer_getfov (lua_State *l)
static int observer_getframe (lua_State *l)
static int observer_getlocationflags (lua_State *l)
static int observer_getorientation (lua_State *l)
static int observer_getposition (lua_State *l)
static int observer_getspeed (lua_State *l)
static int observer_getsurface (lua_State *l)
static int observer_gettime (lua_State *l)
static int observer_goto (lua_State *l)
static int observer_gotodistance (lua_State *l)
static int observer_gotolocation (lua_State *l)
static int observer_gotolonglat (lua_State *l)
static int observer_gotosurface (lua_State *l)
static int observer_gototable (lua_State *l)
static int observer_isvalid (lua_State *l)
static int observer_lock (lua_State *l)
static int observer_lookat (lua_State *l)
static int observer_new (lua_State *l, Observer *o)
static int observer_rotate (lua_State *l)
static int observer_setfov (lua_State *l)
static int observer_setframe (lua_State *l)
static int observer_setlocationflags (lua_State *l)
static int observer_setorientation (lua_State *l)
static int observer_setposition (lua_State *l)
static int observer_setspeed (lua_State *l)
static int observer_setsurface (lua_State *l)
static int observer_singleview (lua_State *l)
static int observer_splitview (lua_State *l)
static int observer_synchronous (lua_State *l)
static int observer_tostring (lua_State *l)
static int observer_track (lua_State *l)
static int observer_travelling (lua_State *l)
static astro::CoordinateSystem parseCoordSys (const string &name)
static Marker::Symbol parseMarkerSymbol (const string &name)
static int position_add (lua_State *l)
static int position_addvector (lua_State *l)
static int position_distanceto (lua_State *l)
static int position_get (lua_State *l)
static int position_getx (lua_State *l)
static int position_gety (lua_State *l)
static int position_getz (lua_State *l)
static int position_new (lua_State *l, const UniversalCoord &uc)
static int position_orientationto (lua_State *l)
static int position_set (lua_State *l)
static int position_sub (lua_State *l)
static int position_tostring (lua_State *l)
static int position_vectorto (lua_State *l)
static void PushClass (lua_State *l, int id)
static const char * readStreamChunk (lua_State *state, void *udata, size_t *size)
static void RegisterMethod (lua_State *l, const char *name, lua_CFunction fn)
static int rotation_add (lua_State *l)
static int rotation_get (lua_State *l)
static int rotation_imag (lua_State *l)
static int rotation_mult (lua_State *l)
static int rotation_new (lua_State *l, const Quatd &qd)
static int rotation_real (lua_State *l)
static int rotation_set (lua_State *l)
static int rotation_setaxisangle (lua_State *l)
static int rotation_slerp (lua_State *l)
static int rotation_tostring (lua_State *l)
static int rotation_transform (lua_State *l)
static lua_Number safeGetNumber (lua_State *l, int index, FatalErrors fatalErrors=AllErrors, const char *errorMsg="Numeric argument expected", lua_Number defaultValue=0.0)
static const char * safeGetString (lua_State *l, int index, FatalErrors fatalErrors=AllErrors, const char *errorMsg="String argument expected")
static void SetClass (lua_State *l, int id)
static void setTable (lua_State *l, const char *field, const char *value)
static void setTable (lua_State *l, const char *field, lua_Number value)
static CelestiaCorethis_celestia (lua_State *l)
static CelScriptWrapperthis_celscript (lua_State *l)
static FrameOfReferencethis_frame (lua_State *l)
static Selectionthis_object (lua_State *l)
static Observerthis_observer (lua_State *l)
static UniversalCoordthis_position (lua_State *l)
static Quatdthis_rotation (lua_State *l)
static Vec3dthis_vector (lua_State *l)
static CelestiaCoreto_celestia (lua_State *l, int index)
static FrameOfReferenceto_frame (lua_State *l, int index)
static Selectionto_object (lua_State *l, int index)
static Observerto_observer (lua_State *l, int index)
static UniversalCoordto_position (lua_State *l, int index)
static Quatdto_rotation (lua_State *l, int index)
static Vec3dto_vector (lua_State *l, int index)
static int vector_add (lua_State *l)
static int vector_cross (lua_State *l)
static int vector_get (lua_State *l)
static int vector_getx (lua_State *l)
static int vector_gety (lua_State *l)
static int vector_getz (lua_State *l)
static int vector_length (lua_State *l)
static int vector_mult (lua_State *l)
static int vector_new (lua_State *l, const Vec3d &v)
static int vector_normalize (lua_State *l)
static int vector_set (lua_State *l)
static int vector_sub (lua_State *l)
static int vector_tostring (lua_State *l)

Variables

static const int _Celestia = 0
static const int _CelScript = 8
static const int _Frame = 7
static const int _Matrix = 4
static const int _Object = 2
static const int _Observer = 1
static const int _Position = 6
static const int _Rotation = 5
static const int _Vec3 = 3
static FlagMap BodyTypeMap
static const char * ClassNames []
static const char * CleanupCallback = "celestia_cleanup_callback"
static const char * KbdCallback = "celestia_keyboard_callback"
static FlagMap LabelFlagMap
static FlagMap LocationFlagMap
static bool mapsInitialized = false
static const double MaxTimeslice = 5.0
static FlagMap RenderFlagMap


Define Documentation

#define CLASS  )     ClassNames[(i)]
 

Definition at line 64 of file celx.cpp.


Typedef Documentation

typedef map<string, uint32> FlagMap
 

Definition at line 74 of file celx.cpp.


Enumeration Type Documentation

enum FatalErrors
 

Enumeration values:
NoErrors 
WrongType 
WrongArgc 
AllErrors 

Definition at line 84 of file celx.cpp.

00084                  {
00085     NoErrors = 0,
00086     WrongType = 1,
00087     WrongArgc = 2,
00088     AllErrors = WrongType | WrongArgc,
00089 };


Function Documentation

static int auxresume lua_State *  L,
lua_State *  co,
int  narg
[static]
 

Definition at line 524 of file celx.cpp.

Referenced by LuaState::resume().

00525 {
00526     int status;
00527 #if 0
00528     if (!lua_checkstack(co, narg))
00529         luaL_error(L, "too many arguments to resume");
00530 #endif
00531     lua_xmove(L, co, narg);
00532 
00533     status = lua_resume(co, narg);
00534     if (status == 0)
00535     {
00536         int nres = lua_gettop(co);
00537 #if 0
00538         if (!lua_checkstack(L, narg))
00539               luaL_error(L, "too many results to resume");
00540 #endif
00541         lua_xmove(co, L, nres);  // move yielded values
00542         return nres;
00543     }
00544     else
00545     {
00546         lua_xmove(co, L, 1);  // move error message
00547         return -1;            // error flag
00548     }
00549 }

static int celestia_createcelscript lua_State *  l  )  [static]
 

Definition at line 4479 of file celx.cpp.

References AllErrors, celscript_from_string(), checkArgs(), and safeGetString().

Referenced by CreateCelestiaMetaTable().

04480 {
04481     checkArgs(l, 2, 2, "Need one argument for celestia:createcelscript()");
04482     string scripttext = safeGetString(l, 2, AllErrors, "Argument to celestia:createcelscript() must be a string");
04483     return celscript_from_string(l, scripttext);
04484 }

static int celestia_find lua_State *  l  )  [static]
 

Definition at line 3868 of file celx.cpp.

References checkArgs(), doError(), Simulation::findObjectFromPath(), CelestiaCore::getSimulation(), object_new(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03869 {
03870     checkArgs(l, 2, 2, "One argument expected for function celestia:find()");
03871     if (!lua_isstring(l, 2))
03872     {
03873         doError(l, "Argument to find must be a string");
03874     }
03875 
03876     CelestiaCore* appCore = this_celestia(l);
03877     Simulation* sim = appCore->getSimulation();
03878     // Should use universe not simulation for finding objects
03879     Selection sel = sim->findObjectFromPath(lua_tostring(l, 2));
03880     object_new(l, sel);
03881 
03882     return 1;
03883 }

static int celestia_flash lua_State *  l  )  [static]
 

Definition at line 3396 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::flash(), safeGetNumber(), safeGetString(), this_celestia(), and WrongType.

Referenced by CreateCelestiaMetaTable().

03397 {
03398     checkArgs(l, 2, 3, "One or two arguments expected to function celestia:flash");
03399 
03400     CelestiaCore* appCore = this_celestia(l);
03401     const char* s = safeGetString(l, 2, AllErrors, "First argument to celestia:flash must be a string");
03402     double duration = safeGetNumber(l, 3, WrongType, "Second argument to celestia:flash must be a number", 1.5);
03403     if (duration < 0.0)
03404     {
03405         duration = 1.5;
03406     }
03407 
03408     appCore->flash(s, duration);
03409 
03410     return 0;
03411 }

static int celestia_fromjulianday lua_State *  l  )  [static]
 

Definition at line 4013 of file celx.cpp.

References AllErrors, checkArgs(), astro::Date::day, astro::Date::hour, astro::Date::minute, astro::Date::month, safeGetNumber(), astro::Date::seconds, setTable(), this_celestia(), and astro::Date::year.

Referenced by CreateCelestiaMetaTable().

04014 {
04015     checkArgs(l, 2, 2, "Wrong number of arguments to function celestia:fromjulianday");
04016 
04017     // for error checking only:
04018     this_celestia(l);
04019 
04020     double jd = safeGetNumber(l, 2, AllErrors, "First arg to celestia:fromjulianday must be a number", 0.0);
04021     astro::Date date(jd);
04022 
04023     lua_newtable(l);
04024     setTable(l, "year", (double)date.year);
04025     setTable(l, "month", (double)date.month);
04026     setTable(l, "day", (double)date.day);
04027     setTable(l, "hour", (double)date.hour);
04028     setTable(l, "minute", (double)date.minute);
04029     setTable(l, "seconds", date.seconds);
04030 
04031     return 1;
04032 }

static int celestia_getambient lua_State *  l  )  [static]
 

Definition at line 4075 of file celx.cpp.

References checkArgs(), doError(), Renderer::getAmbientLightLevel(), CelestiaCore::getRenderer(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04076 {
04077     checkArgs(l, 1, 1, "No argument expected in celestia:setambient");
04078     CelestiaCore* appCore = this_celestia(l);
04079 
04080     Renderer* renderer = appCore->getRenderer();
04081     if (renderer == NULL)
04082     {
04083         doError(l, "Internal Error: renderer is NULL!");
04084     }
04085     else
04086     {
04087         lua_pushnumber(l, renderer->getAmbientLightLevel());
04088     }
04089     return 1;
04090 }

static int celestia_getfaintestvisible lua_State *  l  )  [static]
 

Definition at line 3794 of file celx.cpp.

References checkArgs(), Renderer::getFaintestAM45deg(), Simulation::getFaintestVisible(), CelestiaCore::getRenderer(), Renderer::getRenderFlags(), CelestiaCore::getSimulation(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03795 {
03796     checkArgs(l, 1, 1, "No arguments expected for celestia:getfaintestvisible()");
03797     CelestiaCore* appCore = this_celestia(l);
03798     if ((appCore->getRenderer()->getRenderFlags() & Renderer::ShowAutoMag) == 0)
03799     {
03800         lua_pushnumber(l, appCore->getSimulation()->getFaintestVisible());
03801     }
03802     else
03803     {
03804         lua_pushnumber(l, appCore->getRenderer()->getFaintestAM45deg());
03805     }
03806     return 1;
03807 }

static int celestia_getlabelflags lua_State *  l  )  [static]
 

Definition at line 3685 of file celx.cpp.

References checkArgs(), Renderer::getLabelMode(), CelestiaCore::getRenderer(), LabelFlagMap, and this_celestia().

Referenced by CreateCelestiaMetaTable().

03686 {
03687     checkArgs(l, 1, 1, "No arguments expected for celestia:getlabelflags()");
03688     CelestiaCore* appCore = this_celestia(l);
03689     lua_newtable(l);
03690     FlagMap::const_iterator it = LabelFlagMap.begin();
03691     const int labelFlags = appCore->getRenderer()->getLabelMode();
03692     while (it != LabelFlagMap.end())
03693     {
03694         string key = it->first;
03695         lua_pushstring(l, key.c_str());
03696         lua_pushboolean(l, (it->second & labelFlags) != 0);
03697         lua_settable(l,-3);
03698         it++;
03699     }
03700     return 1;
03701 }

static int celestia_getminfeaturesize lua_State *  l  )  [static]
 

Definition at line 3819 of file celx.cpp.

References checkArgs(), Renderer::getMinimumFeatureSize(), CelestiaCore::getRenderer(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03820 {
03821     checkArgs(l, 1, 1, "No arguments expected for celestia:getminfeaturesize()");
03822     CelestiaCore* appCore = this_celestia(l);
03823     lua_pushnumber(l, appCore->getRenderer()->getMinimumFeatureSize());
03824     return 1;
03825 }

static int celestia_getminorbitsize lua_State *  l  )  [static]
 

Definition at line 4111 of file celx.cpp.

References checkArgs(), doError(), Renderer::getMinimumOrbitSize(), CelestiaCore::getRenderer(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04112 {
04113     checkArgs(l, 1, 1, "No argument expected in celestia:getminorbitsize");
04114     CelestiaCore* appCore = this_celestia(l);
04115 
04116     Renderer* renderer = appCore->getRenderer();
04117     if (renderer == NULL)
04118     {
04119         doError(l, "Internal Error: renderer is NULL!");
04120     }
04121     else
04122     {
04123         lua_pushnumber(l, renderer->getMinimumOrbitSize());
04124     }
04125     return 1;
04126 }

static int celestia_getobserver lua_State *  l  )  [static]
 

Definition at line 3827 of file celx.cpp.

References checkArgs(), Simulation::getActiveObserver(), CelestiaCore::getSimulation(), observer_new(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03828 {
03829     checkArgs(l, 1, 1, "No arguments expected for celestia:getobserver()");
03830 
03831     CelestiaCore* appCore = this_celestia(l);
03832     Observer* o = appCore->getSimulation()->getActiveObserver();
03833     if (o == NULL)
03834         lua_pushnil(l);
03835     else
03836         observer_new(l, o);
03837 
03838     return 1;
03839 }

static int celestia_getobservers lua_State *  l  )  [static]
 

Definition at line 3841 of file celx.cpp.

References checkArgs(), getObservers(), observer_new(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03842 {
03843     checkArgs(l, 1, 1, "No arguments expected for celestia:getobservers()");
03844     CelestiaCore* appCore = this_celestia(l);
03845 
03846     vector<Observer*> observer_list;
03847     getObservers(appCore, observer_list);
03848     lua_newtable(l);
03849     for (unsigned int i = 0; i < observer_list.size(); i++)
03850     {
03851         observer_new(l, observer_list[i]);
03852         lua_rawseti(l, -2, i + 1);
03853     }
03854 
03855     return 1;
03856 }

static int celestia_getorbitflags lua_State *  l  )  [static]
 

Definition at line 3756 of file celx.cpp.

References BodyTypeMap, checkArgs(), Renderer::getOrbitMask(), CelestiaCore::getRenderer(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03757 {
03758     checkArgs(l, 1, 1, "No arguments expected for celestia:getorbitflags()");
03759     CelestiaCore* appCore = this_celestia(l);
03760     lua_newtable(l);
03761     FlagMap::const_iterator it = BodyTypeMap.begin();
03762     const int orbitFlags = appCore->getRenderer()->getOrbitMask();
03763     while (it != BodyTypeMap.end())
03764     {
03765         string key = it->first;
03766         lua_pushstring(l, key.c_str());
03767         lua_pushboolean(l, (it->second & orbitFlags) != 0);
03768         lua_settable(l,-3);
03769         it++;
03770     }
03771     return 1;
03772 }

static int celestia_getrenderflags lua_State *  l  )  [static]
 

Definition at line 3554 of file celx.cpp.

References checkArgs(), CelestiaCore::getLightDelayActive(), CelestiaCore::getRenderer(), Renderer::getRenderFlags(), RenderFlagMap, and this_celestia().

Referenced by CreateCelestiaMetaTable().

03555 {
03556     checkArgs(l, 1, 1, "No arguments expected for celestia:getrenderflags()");
03557     CelestiaCore* appCore = this_celestia(l);
03558     lua_newtable(l);
03559     FlagMap::const_iterator it = RenderFlagMap.begin();
03560     const int renderFlags = appCore->getRenderer()->getRenderFlags();
03561     while (it != RenderFlagMap.end())
03562     {
03563         string key = it->first;
03564         lua_pushstring(l, key.c_str());
03565         lua_pushboolean(l, (it->second & renderFlags) != 0);
03566         lua_settable(l,-3);
03567         it++;
03568     }
03569     lua_pushstring(l, "lightdelay");
03570     lua_pushboolean(l, appCore->getLightDelayActive());
03571     lua_settable(l, -3);
03572     return 1;
03573 }

int celestia_getscreendimension lua_State *  l  ) 
 

Definition at line 3575 of file celx.cpp.

References checkArgs(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03576 {
03577     checkArgs(l, 1, 1, "No arguments expected for celestia:getscreendimension()");
03578     // error checking only:
03579     this_celestia(l);
03580     // Get the dimensions of the current viewport
03581     int viewport[4];
03582     glGetIntegerv(GL_VIEWPORT, viewport);
03583     lua_pushnumber(l, viewport[2]-viewport[0]);
03584     lua_pushnumber(l, viewport[3]-viewport[1]);
03585     return 2;
03586 }

static int celestia_getscriptpath lua_State *  l  )  [static]
 

Definition at line 4496 of file celx.cpp.

References checkArgs(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04497 {
04498     // ignore possible argument for future extensions
04499     checkArgs(l, 1, 1, "No argument expected for celestia:requestsystemaccess()");
04500     this_celestia(l);
04501     lua_pushstring(l, "celestia-scriptpath");
04502     lua_gettable(l, LUA_REGISTRYINDEX);
04503     return 1;
04504 }

static int celestia_getscripttime lua_State *  l  )  [static]
 

Definition at line 4315 of file celx.cpp.

References checkArgs(), getLuaStateObject(), LuaState::getTime(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04316 {
04317     checkArgs(l, 1, 1, "No arguments expected for celestia:getscripttime");
04318     // for error checking only:
04319     this_celestia(l);
04320 
04321     LuaState* luastate_ptr = getLuaStateObject(l);
04322     lua_pushnumber(l, luastate_ptr->getTime());
04323     return 1;
04324 }

static int celestia_getselection lua_State *  l  )  [static]
 

Definition at line 3858 of file celx.cpp.

References checkArgs(), Simulation::getSelection(), CelestiaCore::getSimulation(), object_new(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03859 {
03860     checkArgs(l, 1, 1, "No arguments expected to celestia:getselection()");
03861     CelestiaCore* appCore = this_celestia(l);
03862     Selection sel = appCore->getSimulation()->getSelection();
03863     object_new(l, sel);
03864 
03865     return 1;
03866 }

static int celestia_getstar lua_State *  l  )  [static]
 

Definition at line 4226 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getSimulation(), StarDatabase::getStar(), Universe::getStarCatalog(), Simulation::getUniverse(), object_new(), safeGetNumber(), starIndex, and this_celestia().

Referenced by CreateCelestiaMetaTable().

04227 {
04228     checkArgs(l, 2, 2, "One argument expected to function celestia:getstar");
04229 
04230     CelestiaCore* appCore = this_celestia(l);
04231     double starIndex = safeGetNumber(l, 2, AllErrors, "First arg to celestia:getstar must be a number");
04232     Universe* u = appCore->getSimulation()->getUniverse();
04233     Star* star = u->getStarCatalog()->getStar((uint32) starIndex);
04234     if (star == NULL)
04235         lua_pushnil(l);
04236     else
04237         object_new(l, Selection(star));
04238 
04239     return 1;
04240 }

static int celestia_getstarcount lua_State *  l  )  [static]
 

Definition at line 4045 of file celx.cpp.

References checkArgs(), CelestiaCore::getSimulation(), Universe::getStarCatalog(), Simulation::getUniverse(), StarDatabase::size(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04046 {
04047     checkArgs(l, 1, 1, "No arguments expected to function celestia:getstarcount");
04048 
04049     CelestiaCore* appCore = this_celestia(l);
04050     Universe* u = appCore->getSimulation()->getUniverse();
04051     lua_pushnumber(l, u->getStarCatalog()->size());
04052 
04053     return 1;
04054 }

static int celestia_getstardistancelimit lua_State *  l  )  [static]
 

Definition at line 4146 of file celx.cpp.

References checkArgs(), doError(), Renderer::getDistanceLimit(), CelestiaCore::getRenderer(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04147 {
04148     checkArgs(l, 1, 1, "No argument expected in celestia:getstardistancelimit");
04149     CelestiaCore* appCore = this_celestia(l);
04150 
04151     Renderer* renderer = appCore->getRenderer();
04152     if (renderer == NULL)
04153     {
04154         doError(l, "Internal Error: renderer is NULL!");
04155     }
04156     else
04157     {
04158         lua_pushnumber(l, renderer->getDistanceLimit());
04159     }
04160     return 1;
04161 }

static int celestia_getstarstyle lua_State *  l  )  [static]
 

Definition at line 4163 of file celx.cpp.

References checkArgs(), doError(), CelestiaCore::getRenderer(), Renderer::getStarStyle(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04164 {
04165     checkArgs(l, 1, 1, "No argument expected in celestia:getstarstyle");
04166     CelestiaCore* appCore = this_celestia(l);
04167 
04168     Renderer* renderer = appCore->getRenderer();
04169     if (renderer == NULL)
04170     {
04171         doError(l, "Internal Error: renderer is NULL!");
04172     }
04173     else
04174     {
04175         Renderer::StarStyle starStyle = renderer->getStarStyle();
04176         switch (starStyle)
04177         {
04178         case Renderer::FuzzyPointStars: 
04179             lua_pushstring(l, "fuzzy"); break;
04180         case Renderer::PointStars: 
04181             lua_pushstring(l, "point"); break;
04182         case Renderer::ScaledDiscStars: 
04183             lua_pushstring(l, "disc"); break;
04184         default:
04185             lua_pushstring(l, "invalid starstyle");
04186         };
04187     }
04188     return 1;
04189 }

static int celestia_gettextwidth lua_State *  l  )  [static]
 

Definition at line 3435 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getTextWidth(), safeGetString(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03436 {
03437     checkArgs(l, 2, 2, "One argument expected to function celestia:gettextwidth");
03438 
03439     CelestiaCore* appCore = this_celestia(l);
03440     const char* s = safeGetString(l, 2, AllErrors, "First argument to celestia:gettextwidth must be a string");
03441 
03442     lua_pushnumber(l, appCore->getTextWidth(s));
03443 
03444     return 1;
03445 }

static int celestia_gettime lua_State *  l  )  [static]
 

Definition at line 3944 of file celx.cpp.

References checkArgs(), CelestiaCore::getSimulation(), Simulation::getTime(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03945 {
03946     checkArgs(l, 1, 1, "No argument expected to function celestia:gettime");
03947 
03948     CelestiaCore* appCore = this_celestia(l);
03949     Simulation* sim = appCore->getSimulation();
03950     lua_pushnumber(l, sim->getTime());
03951 
03952     return 1;
03953 }

static int celestia_gettimescale lua_State *  l  )  [static]
 

Definition at line 3955 of file celx.cpp.

References checkArgs(), CelestiaCore::getSimulation(), Simulation::getTimeScale(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03956 {
03957     checkArgs(l, 1, 1, "No argument expected to function celestia:gettimescale");
03958 
03959     CelestiaCore* appCore = this_celestia(l);
03960     lua_pushnumber(l, appCore->getSimulation()->getTimeScale());
03961 
03962     return 1;
03963 }

static int celestia_hide lua_State *  l  )  [static]
 

Definition at line 3471 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getRenderer(), Renderer::getRenderFlags(), CelestiaCore::notifyWatchers(), RenderFlagMap, safeGetString(), CelestiaCore::setLightDelayActive(), Renderer::setRenderFlags(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03472 {
03473     checkArgs(l, 1, 1000, "Wrong number of arguments to celestia:hide");
03474     CelestiaCore* appCore = this_celestia(l);
03475 
03476     int argc = lua_gettop(l);
03477     int flags = 0;
03478     for (int i = 2; i <= argc; i++)
03479     {
03480         string renderFlag = safeGetString(l, i, AllErrors, "Arguments to celestia:hide() must be strings"); 
03481         if (renderFlag == "lightdelay")
03482             appCore->setLightDelayActive(false);
03483         else
03484         if (RenderFlagMap.count(renderFlag) > 0)
03485             flags |= RenderFlagMap[renderFlag];
03486     }
03487 
03488     Renderer* r = appCore->getRenderer();
03489     r->setRenderFlags(r->getRenderFlags() & ~flags);
03490     appCore->notifyWatchers(CelestiaCore::RenderFlagsChanged);
03491 
03492     return 0;
03493 }

static int celestia_hidelabel lua_State *  l  )  [static]
 

Definition at line 3609 of file celx.cpp.

References AllErrors, checkArgs(), Renderer::getLabelMode(), CelestiaCore::getRenderer(), LabelFlagMap, CelestiaCore::notifyWatchers(), safeGetString(), Renderer::setLabelMode(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03610 {
03611     checkArgs(l, 1, 1000, "Invalid number of arguments in celestia:hidelabel");
03612     CelestiaCore* appCore = this_celestia(l);
03613 
03614     int argc = lua_gettop(l);
03615     int flags = 0;
03616     for (int i = 2; i <= argc; i++)
03617     {
03618         string labelFlag = safeGetString(l, i, AllErrors, "Arguments to celestia:hidelabel() must be strings"); 
03619         if (LabelFlagMap.count(labelFlag) > 0)
03620             flags |= LabelFlagMap[labelFlag];
03621     }
03622 
03623     Renderer* r = appCore->getRenderer();
03624     r->setLabelMode(r->getLabelMode() & ~flags);
03625     appCore->notifyWatchers(CelestiaCore::LabelFlagsChanged);
03626 
03627     return 0;
03628 }

static int celestia_mark lua_State *  l  )  [static]
 

Definition at line 3903 of file celx.cpp.

References checkArgs(), doError(), CelestiaCore::getSimulation(), Simulation::getUniverse(), Universe::markObject(), this_celestia(), and to_object().

Referenced by CreateCelestiaMetaTable().

03904 {
03905     checkArgs(l, 2, 2, "One argument expected to function celestia:mark");
03906 
03907     CelestiaCore* appCore = this_celestia(l);
03908     Simulation* sim = appCore->getSimulation();
03909     Selection* sel = to_object(l, 2);
03910 
03911     if (sel != NULL)
03912     {
03913         sim->getUniverse()->markObject(*sel, 10.0f,
03914                                        Color(0.0f, 1.0f, 0.0f), Marker::Diamond, 1);
03915     }
03916     else
03917     {
03918         doError(l, "Argument to celestia:mark must be an object");
03919     }
03920 
03921     return 0;
03922 }

static int celestia_new lua_State *  l,
CelestiaCore appCore
[static]
 

Definition at line 3365 of file celx.cpp.

References _Celestia, and SetClass().

Referenced by LuaState::init().

03366 {
03367     CelestiaCore** ud = reinterpret_cast<CelestiaCore**>(lua_newuserdata(l, sizeof(CelestiaCore*)));
03368     *ud = appCore;
03369 
03370     SetClass(l, _Celestia);
03371 
03372     return 1;
03373 }

static int celestia_newframe lua_State *  l  )  [static]
 

Definition at line 4326 of file celx.cpp.

References AllErrors, checkArgs(), doError(), frame_new(), parseCoordSys(), safeGetString(), this_celestia(), and to_object().

Referenced by CreateCelestiaMetaTable().

04327 {
04328     checkArgs(l, 2, 4, "One to three arguments expected for function celestia:newframe");
04329     int argc = lua_gettop(l);
04330 
04331     // for error checking only:
04332     this_celestia(l);
04333 
04334     const char* coordsysName = safeGetString(l, 2, AllErrors, "newframe: first argument must be a string");
04335     astro::CoordinateSystem coordSys = parseCoordSys(coordsysName);
04336     Selection* ref = NULL;
04337     Selection* target = NULL;
04338 
04339     if (coordSys == astro::Universal)
04340     {
04341         frame_new(l, FrameOfReference());
04342     }
04343     else if (coordSys == astro::PhaseLock)
04344     {
04345         if (argc >= 4)
04346         {
04347             ref = to_object(l, 3);
04348             target = to_object(l, 4);
04349         }
04350 
04351         if (ref == NULL || target == NULL)
04352         {
04353             doError(l, "newframe: two objects required for lock frame");
04354         }
04355 
04356         frame_new(l, FrameOfReference(coordSys, *ref, *target));
04357     }
04358     else
04359     {
04360         if (argc >= 3)
04361             ref = to_object(l, 3);
04362         if (ref == NULL)
04363         {
04364             doError(l, "newframe: one object argument required for frame");
04365         }
04366 
04367         frame_new(l, FrameOfReference(coordSys, *ref));
04368     }
04369 
04370     return 1;
04371 }

static int celestia_newposition lua_State *  l  )  [static]
 

Definition at line 4256 of file celx.cpp.

References checkArgs(), components, doError(), position_new(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04257 {
04258     checkArgs(l, 4, 4, "Expected 3 arguments for celestia:newposition");
04259     // for error checking only:
04260     this_celestia(l);
04261     BigFix components[3];
04262     for (int i = 0; i < 3; i++)
04263     {
04264         if (lua_isnumber(l, i+2))
04265         {
04266             double v = lua_tonumber(l, i+2);
04267             components[i] = BigFix(v);
04268         }
04269         else if (lua_isstring(l, i+2))
04270         {
04271             components[i] = BigFix(string(lua_tostring(l, i+2)));
04272         }
04273         else
04274         {
04275             doError(l, "Arguments to celestia:newposition must be either numbers or strings");
04276         }
04277     }
04278 
04279     position_new(l, UniversalCoord(components[0], components[1], components[2]));
04280 
04281     return 1;
04282 }

static int celestia_newrotation lua_State *  l  )  [static]
 

Definition at line 4284 of file celx.cpp.

References AllErrors, checkArgs(), doError(), rotation_new(), safeGetNumber(), Quaternion< T >::setAxisAngle(), this_celestia(), and to_vector().

Referenced by CreateCelestiaMetaTable().

04285 {
04286     checkArgs(l, 3, 5, "Need 2 or 4 arguments for celestia:newrotation");
04287     // for error checking only:
04288     this_celestia(l);
04289 
04290     if (lua_gettop(l) > 3)
04291     {
04292         // if (lua_gettop == 4), safeGetNumber will catch the error
04293         double w = safeGetNumber(l, 2, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
04294         double x = safeGetNumber(l, 3, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
04295         double y = safeGetNumber(l, 4, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
04296         double z = safeGetNumber(l, 5, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
04297         Quatd q(w, x, y, z);
04298         rotation_new(l, q);
04299     }
04300     else
04301     {
04302         Vec3d* v = to_vector(l, 2);
04303         if (v == NULL)
04304         {
04305             doError(l, "newrotation: first argument must be a vector");
04306         }
04307         double angle = safeGetNumber(l, 3, AllErrors, "second argument to celestia:newrotation must be a number");
04308         Quatd q;
04309         q.setAxisAngle(*v, angle);
04310         rotation_new(l, q);
04311     }
04312     return 1;
04313 }

static int celestia_newvector lua_State *  l  )  [static]
 

Definition at line 4242 of file celx.cpp.

References AllErrors, checkArgs(), safeGetNumber(), this_celestia(), and vector_new().

Referenced by CreateCelestiaMetaTable().

04243 {
04244     checkArgs(l, 4, 4, "Expected 3 arguments for celestia:newvector");
04245     // for error checking only:
04246     this_celestia(l);
04247     double x = safeGetNumber(l, 2, AllErrors, "First arg to celestia:newvector must be a number");
04248     double y = safeGetNumber(l, 3, AllErrors, "Second arg to celestia:newvector must be a number");
04249     double z = safeGetNumber(l, 4, AllErrors, "Third arg to celestia:newvector must be a number");
04250 
04251     vector_new(l, Vec3d(x,y,z));
04252 
04253     return 1;
04254 }

static int celestia_print lua_State *  l  )  [static]
 

Definition at line 3413 of file celx.cpp.

References AllErrors, checkArgs(), safeGetNumber(), safeGetString(), CelestiaCore::showText(), this_celestia(), and WrongType.

Referenced by CreateCelestiaMetaTable().

03414 {
03415     checkArgs(l, 2, 7, "One to six arguments expected to function celestia:print");
03416 
03417     CelestiaCore* appCore = this_celestia(l);
03418     const char* s = safeGetString(l, 2, AllErrors, "First argument to celestia:print must be a string");
03419     double duration = safeGetNumber(l, 3, WrongType, "Second argument to celestia:print must be a number", 1.5);
03420     int horig = (int)safeGetNumber(l, 4, WrongType, "Third argument to celestia:print must be a number", -1.0);
03421     int vorig = (int)safeGetNumber(l, 5, WrongType, "Fourth argument to celestia:print must be a number", -1.0);
03422     int hoff = (int)safeGetNumber(l, 6, WrongType, "Fifth argument to celestia:print must be a number", 0.0);
03423     int voff = (int)safeGetNumber(l, 7, WrongType, "Sixth argument to celestia:print must be a number", 5.0);
03424 
03425     if (duration < 0.0)
03426     {
03427         duration = 1.5;
03428     }
03429 
03430     appCore->showText(s, horig, vorig, hoff, voff, duration);
03431 
03432     return 0;
03433 }

static int celestia_requestkeyboard lua_State *  l  )  [static]
 

Definition at line 4373 of file celx.cpp.

References checkArgs(), doError(), CelestiaCore::getTextEnterMode(), KbdCallback, CelestiaCore::setTextEnterMode(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04374 {
04375     checkArgs(l, 2, 2, "Need one arguments for celestia:requestkeyboard");
04376     CelestiaCore* appCore = this_celestia(l);
04377 
04378     if (!lua_isboolean(l, 2))
04379     {
04380         doError(l, "First argument for celestia:requestkeyboard must be a boolean");
04381     }
04382 
04383     int mode = appCore->getTextEnterMode();
04384 
04385     if (lua_toboolean(l, 2))
04386     {
04387         // Check for existence of charEntered:
04388         lua_pushstring(l, KbdCallback);
04389         lua_gettable(l, LUA_GLOBALSINDEX);
04390         if (lua_isnil(l, -1))
04391         {
04392             doError(l, "script requested keyboard, but did not provide callback");
04393         }
04394         lua_remove(l, -1);
04395 
04396         mode = mode | CelestiaCore::KbPassToScript;
04397     }
04398     else
04399     {
04400         mode = mode & ~CelestiaCore::KbPassToScript;
04401     }
04402     appCore->setTextEnterMode(mode);
04403 
04404     return 0;
04405 }

static int celestia_requestsystemaccess lua_State *  l  )  [static]
 

Definition at line 4486 of file celx.cpp.

References checkArgs(), getLuaStateObject(), LuaState::requestIO(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04487 {
04488     // ignore possible argument for future extensions
04489     checkArgs(l, 1, 2, "No argument expected for celestia:requestsystemaccess()");
04490     this_celestia(l);
04491     LuaState* luastate = getLuaStateObject(l);
04492     luastate->requestIO();
04493     return 0;
04494 }

static int celestia_select lua_State *  l  )  [static]
 

Definition at line 3885 of file celx.cpp.

References checkArgs(), CelestiaCore::getSimulation(), Simulation::setSelection(), this_celestia(), and to_object().

Referenced by CreateCelestiaMetaTable().

03886 {
03887     checkArgs(l, 2, 2, "One argument expected for celestia:select()");
03888     CelestiaCore* appCore = this_celestia(l);
03889 
03890     Simulation* sim = appCore->getSimulation();
03891     Selection* sel = to_object(l, 2);
03892 
03893     // If the argument is an object, set the selection; if it's anything else
03894     // clear the selection.
03895     if (sel != NULL)
03896         sim->setSelection(*sel);
03897     else
03898         sim->setSelection(Selection());
03899 
03900     return 0;
03901 }

static int celestia_setambient lua_State *  l  )  [static]
 

Definition at line 4056 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getRenderer(), CelestiaCore::notifyWatchers(), safeGetNumber(), Renderer::setAmbientLightLevel(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04057 {
04058     checkArgs(l, 2, 2, "One argument expected in celestia:setambient");
04059     CelestiaCore* appCore = this_celestia(l);
04060 
04061     Renderer* renderer = appCore->getRenderer();
04062     double ambientLightLevel = safeGetNumber(l, 2, AllErrors, "Argument to celestia:setambient must be a number");
04063     if (ambientLightLevel > 1.0)
04064         ambientLightLevel = 1.0;
04065     if (ambientLightLevel < 0.0)
04066         ambientLightLevel = 0.0;
04067 
04068     if (renderer != NULL)
04069         renderer->setAmbientLightLevel((float)ambientLightLevel);
04070     appCore->notifyWatchers(CelestiaCore::AmbientLightChanged);
04071 
04072     return 0;
04073 }

static int celestia_setfaintestvisible lua_State *  l  )  [static]
 

Definition at line 3774 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getRenderer(), Renderer::getRenderFlags(), max, min, CelestiaCore::notifyWatchers(), safeGetNumber(), CelestiaCore::setFaintest(), Renderer::setFaintestAM45deg(), CelestiaCore::setFaintestAutoMag(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03775 {
03776     checkArgs(l, 2, 2, "One argument expected for celestia:setfaintestvisible()");
03777     CelestiaCore* appCore = this_celestia(l);
03778     float faintest = (float)safeGetNumber(l, 2, AllErrors, "Argument to celestia:setfaintestvisible() must be a number");
03779     if ((appCore->getRenderer()->getRenderFlags() & Renderer::ShowAutoMag) == 0)
03780     {
03781         faintest = min(15.0f, max(1.0f, faintest));
03782         appCore->setFaintest(faintest);
03783         appCore->notifyWatchers(CelestiaCore::FaintestChanged);
03784     }
03785     else
03786     {
03787         faintest = min(12.0f, max(6.0f, faintest));
03788         appCore->getRenderer()->setFaintestAM45deg(faintest);
03789         appCore->setFaintestAutoMag();
03790     }
03791     return 0;
03792 }

static int celestia_setlabelflags lua_State *  l  )  [static]
 

Definition at line 3630 of file celx.cpp.

References checkArgs(), doError(), Renderer::getLabelMode(), CelestiaCore::getRenderer(), LabelFlagMap, CelestiaCore::notifyWatchers(), Renderer::setLabelMode(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03631 {
03632     checkArgs(l, 2, 2, "One argument expected for celestia:setlabelflags()");
03633     CelestiaCore* appCore = this_celestia(l);
03634     if (!lua_istable(l, 2))
03635     {
03636         doError(l, "Argument to celestia:setlabelflags() must be a table");
03637     }
03638 
03639     int labelFlags = appCore->getRenderer()->getLabelMode();
03640     lua_pushnil(l);
03641     while (lua_next(l, -2) != 0)
03642     {
03643         string key;
03644         bool value = false;
03645         if (lua_isstring(l, -2))
03646         {
03647             key = lua_tostring(l, -2);
03648         }
03649         else
03650         {
03651             doError(l, "Keys in table-argument to celestia:setlabelflags() must be strings");
03652         }
03653         if (lua_isboolean(l, -1))
03654         {
03655             value = lua_toboolean(l, -1);
03656         }
03657         else
03658         {
03659             doError(l, "Values in table-argument to celestia:setlabelflags() must be boolean");
03660         }
03661         if (LabelFlagMap.count(key) == 0)
03662         {
03663             cerr << "Unknown key: " << key << "\n";
03664         }
03665         else
03666         {
03667             int flag = LabelFlagMap[key];
03668             if (value)
03669             {
03670                 labelFlags |= flag;
03671             }
03672             else
03673             {
03674                 labelFlags &= ~flag;
03675             }
03676         }
03677         lua_pop(l,1);
03678     }
03679     appCore->getRenderer()->setLabelMode(labelFlags);
03680     appCore->notifyWatchers(CelestiaCore::LabelFlagsChanged);
03681 
03682     return 0;
03683 }

static int celestia_setminfeaturesize lua_State *  l  )  [static]
 

Definition at line 3809 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getRenderer(), max, safeGetNumber(), Renderer::setMinimumFeatureSize(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03810 {
03811     checkArgs(l, 2, 2, "One argument expected for celestia:setminfeaturesize()");
03812     CelestiaCore* appCore = this_celestia(l);
03813     float minFeatureSize = (float)safeGetNumber(l, 2, AllErrors, "Argument to celestia:setminfeaturesize() must be a number");
03814     minFeatureSize = max(0.0f, minFeatureSize);
03815     appCore->getRenderer()->setMinimumFeatureSize(minFeatureSize);
03816     return 0;
03817 }

static int celestia_setminorbitsize lua_State *  l  )  [static]
 

Definition at line 4092 of file celx.cpp.

References AllErrors, checkArgs(), doError(), CelestiaCore::getRenderer(), max, safeGetNumber(), Renderer::setMinimumOrbitSize(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04093 {
04094     checkArgs(l, 2, 2, "One argument expected in celestia:setminorbitsize");
04095     CelestiaCore* appCore = this_celestia(l);
04096 
04097     double orbitSize = safeGetNumber(l, 2, AllErrors, "Argument to celestia:setminorbitsize() must be a number");
04098     Renderer* renderer = appCore->getRenderer();
04099     if (renderer == NULL)
04100     {
04101         doError(l, "Internal Error: renderer is NULL!");
04102     }
04103     else
04104     {
04105         orbitSize = max(0.0, orbitSize);
04106         renderer->setMinimumOrbitSize((float)orbitSize);
04107     }
04108     return 0;
04109 }

static int celestia_setorbitflags lua_State *  l  )  [static]
 

Definition at line 3703 of file celx.cpp.

References BodyTypeMap, checkArgs(), doError(), Renderer::getOrbitMask(), CelestiaCore::getRenderer(), Renderer::setOrbitMask(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03704 {
03705     checkArgs(l, 2, 2, "One argument expected for celestia:setorbitflags()");
03706     CelestiaCore* appCore = this_celestia(l);
03707     if (!lua_istable(l, 2))
03708     {
03709         doError(l, "Argument to celestia:setorbitflags() must be a table");
03710     }
03711 
03712     int orbitFlags = appCore->getRenderer()->getOrbitMask();
03713     lua_pushnil(l);
03714     while (lua_next(l, -2) != 0)
03715     {
03716         string key;
03717         bool value = false;
03718         if (lua_isstring(l, -2))
03719         {
03720             key = lua_tostring(l, -2);
03721         }
03722         else
03723         {
03724             doError(l, "Keys in table-argument to celestia:setorbitflags() must be strings");
03725         }
03726         if (lua_isboolean(l, -1))
03727         {
03728             value = lua_toboolean(l, -1);
03729         }
03730         else
03731         {
03732             doError(l, "Values in table-argument to celestia:setorbitflags() must be boolean");
03733         }
03734         if (BodyTypeMap.count(key) == 0)
03735         {
03736             cerr << "Unknown key: " << key << "\n";
03737         }
03738         else
03739         {
03740             int flag = BodyTypeMap[key];
03741             if (value)
03742             {
03743                 orbitFlags |= flag;
03744             }
03745             else
03746             {
03747                 orbitFlags &= ~flag;
03748             }
03749         }
03750         lua_pop(l,1);
03751     }
03752     appCore->getRenderer()->setOrbitMask(orbitFlags);
03753     return 0;
03754 }

static int celestia_setrenderflags lua_State *  l  )  [static]
 

Definition at line 3495 of file celx.cpp.

References checkArgs(), doError(), CelestiaCore::getRenderer(), Renderer::getRenderFlags(), CelestiaCore::notifyWatchers(), RenderFlagMap, CelestiaCore::setLightDelayActive(), Renderer::setRenderFlags(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03496 {
03497     checkArgs(l, 2, 2, "One argument expected for celestia:setrenderflags()");
03498     CelestiaCore* appCore = this_celestia(l);
03499     if (!lua_istable(l, 2))
03500     {
03501         doError(l, "Argument to celestia:setrenderflags() must be a table");
03502     }
03503 
03504     int renderFlags = appCore->getRenderer()->getRenderFlags();
03505     lua_pushnil(l);
03506     while (lua_next(l, -2) != 0)
03507     {
03508         string key;
03509         bool value = false;
03510         if (lua_isstring(l, -2))
03511         {
03512             key = lua_tostring(l, -2);
03513         }
03514         else
03515         {
03516             doError(l, "Keys in table-argument to celestia:setrenderflags() must be strings");
03517         }
03518         if (lua_isboolean(l, -1))
03519         {
03520             value = lua_toboolean(l, -1);
03521         }
03522         else
03523         {
03524             doError(l, "Values in table-argument to celestia:setrenderflags() must be boolean");
03525         }
03526         if (key == "lightdelay")
03527         {
03528             appCore->setLightDelayActive(value);
03529         }
03530         else if (RenderFlagMap.count(key) > 0)
03531         {
03532             int flag = RenderFlagMap[key];
03533             if (value)
03534             {
03535                 renderFlags |= flag;
03536             }
03537             else
03538             {
03539                 renderFlags &= ~flag;
03540             }
03541         }
03542         else
03543         {
03544             cerr << "Unknown key: " << key << "\n";
03545         }
03546         lua_pop(l,1);
03547     }
03548     appCore->getRenderer()->setRenderFlags(renderFlags);
03549     appCore->notifyWatchers(CelestiaCore::RenderFlagsChanged);
03550 
03551     return 0;
03552 }

static int celestia_setstardistancelimit lua_State *  l  )  [static]
 

Definition at line 4128 of file celx.cpp.

References AllErrors, checkArgs(), doError(), CelestiaCore::getRenderer(), safeGetNumber(), Renderer::setDistanceLimit(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04129 {
04130     checkArgs(l, 2, 2, "One argument expected in celestia:setstardistancelimit");
04131     CelestiaCore* appCore = this_celestia(l);
04132 
04133     double distanceLimit = safeGetNumber(l, 2, AllErrors, "Argument to celestia:setstardistancelimit() must be a number");
04134     Renderer* renderer = appCore->getRenderer();
04135     if (renderer == NULL)
04136     {
04137         doError(l, "Internal Error: renderer is NULL!");
04138     }
04139     else
04140     {
04141         renderer->setDistanceLimit((float)distanceLimit);
04142     }
04143     return 0;
04144 }

static int celestia_setstarstyle lua_State *  l  )  [static]
 

Definition at line 4191 of file celx.cpp.

References AllErrors, checkArgs(), doError(), CelestiaCore::getRenderer(), CelestiaCore::notifyWatchers(), safeGetString(), Renderer::setStarStyle(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

04192 {
04193     checkArgs(l, 2, 2, "One argument expected in celestia:setstarstyle");
04194     CelestiaCore* appCore = this_celestia(l);
04195 
04196     string starStyle = safeGetString(l, 2, AllErrors, "Argument to celestia:setstarstyle must be a string");
04197     Renderer* renderer = appCore->getRenderer();
04198     if (renderer == NULL)
04199     {
04200         doError(l, "Internal Error: renderer is NULL!");
04201     }
04202     else
04203     {
04204         if (starStyle == "fuzzy")
04205         {
04206             renderer->setStarStyle(Renderer::FuzzyPointStars);
04207         }
04208         else if (starStyle == "point")
04209         {
04210             renderer->setStarStyle(Renderer::PointStars);
04211         }
04212         else if (starStyle == "disc")
04213         {
04214             renderer->setStarStyle(Renderer::ScaledDiscStars);
04215         }
04216         else
04217         {
04218             doError(l, "Invalid starstyle");
04219         }
04220         appCore->notifyWatchers(CelestiaCore::RenderFlagsChanged);
04221         
04222     }
04223     return 0;
04224 }

static int celestia_settime lua_State *  l  )  [static]
 

Definition at line 3965 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getSimulation(), safeGetNumber(), Simulation::setTime(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03966 {
03967     checkArgs(l, 2, 2, "One argument expected to function celestia:settime");
03968 
03969     CelestiaCore* appCore = this_celestia(l);
03970     double t = safeGetNumber(l, 2, AllErrors, "Second arg to celestia:settime must be a number");
03971     appCore->getSimulation()->setTime(t);
03972 
03973     return 0;
03974 }

static int celestia_settimescale lua_State *  l  )  [static]
 

Definition at line 3976 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getSimulation(), safeGetNumber(), Simulation::setTimeScale(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03977 {
03978     checkArgs(l, 2, 2, "One argument expected to function celestia:settimescale");
03979 
03980     CelestiaCore* appCore = this_celestia(l);
03981     double t = safeGetNumber(l, 2, AllErrors, "Second arg to celestia:settimescale must be a number");
03982     appCore->getSimulation()->setTimeScale(t);
03983 
03984     return 0;
03985 }

static int celestia_show lua_State *  l  )  [static]
 

Definition at line 3447 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::getRenderer(), Renderer::getRenderFlags(), CelestiaCore::notifyWatchers(), RenderFlagMap, safeGetString(), CelestiaCore::setLightDelayActive(), Renderer::setRenderFlags(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03448 {
03449     checkArgs(l, 1, 1000, "Wrong number of arguments to celestia:show");
03450     CelestiaCore* appCore = this_celestia(l);
03451 
03452     int argc = lua_gettop(l);
03453     int flags = 0;
03454     for (int i = 2; i <= argc; i++)
03455     {
03456         string renderFlag = safeGetString(l, i, AllErrors, "Arguments to celestia:show() must be strings");
03457         if (renderFlag == "lightdelay")
03458             appCore->setLightDelayActive(true);
03459         else
03460         if (RenderFlagMap.count(renderFlag) > 0)
03461             flags |= RenderFlagMap[renderFlag];
03462     }
03463 
03464     Renderer* r = appCore->getRenderer();
03465     r->setRenderFlags(r->getRenderFlags() | flags);
03466     appCore->notifyWatchers(CelestiaCore::RenderFlagsChanged);
03467 
03468     return 0;
03469 }

static int celestia_showlabel lua_State *  l  )  [static]
 

Definition at line 3588 of file celx.cpp.

References AllErrors, checkArgs(), Renderer::getLabelMode(), CelestiaCore::getRenderer(), LabelFlagMap, CelestiaCore::notifyWatchers(), safeGetString(), Renderer::setLabelMode(), and this_celestia().

Referenced by CreateCelestiaMetaTable().

03589 {
03590     checkArgs(l, 1, 1000, "Bad method call!");
03591     CelestiaCore* appCore = this_celestia(l);
03592 
03593     int argc = lua_gettop(l);
03594     int flags = 0;
03595     for (int i = 2; i <= argc; i++)
03596     {
03597         string labelFlag = safeGetString(l, i, AllErrors, "Arguments to celestia:showlabel() must be strings"); 
03598         if (LabelFlagMap.count(labelFlag) > 0)
03599             flags |= LabelFlagMap[labelFlag];
03600     }
03601 
03602     Renderer* r = appCore->getRenderer();
03603     r->setLabelMode(r->getLabelMode() | flags);
03604     appCore->notifyWatchers(CelestiaCore::LabelFlagsChanged);
03605 
03606     return 0;
03607 }

static int celestia_takescreenshot lua_State *  l  )  [static]
 

Definition at line 4407 of file celx.cpp.

References CaptureGLBufferToJPEG(), CaptureGLBufferToPNG(), checkArgs(), CelestiaCore::getConfig(), getLuaStateObject(), LuaState::getTime(), safeGetString(), LuaState::screenshotCount, CelestiaConfig::scriptScreenshotDirectory, this_celestia(), LuaState::timeout, and WrongType.

Referenced by CreateCelestiaMetaTable().

04408 {
04409     checkArgs(l, 1, 3, "Need 0 to 2 arguments for celestia:takescreenshot");
04410     CelestiaCore* appCore = this_celestia(l);
04411     LuaState* luastate = getLuaStateObject(l);
04412     // make sure we don't timeout because of taking a screenshot:
04413     double timeToTimeout = luastate->timeout - luastate->getTime();
04414 
04415     const char* filetype = safeGetString(l, 2, WrongType, "First argument to celestia:takescreenshot must be a string");
04416     if (filetype == NULL)
04417         filetype = "png";
04418 
04419     // Let the script safely contribute one part of the filename: 
04420     const char* fileid_ptr = safeGetString(l, 3, WrongType, "Second argument to celestia:takescreenshot must be a string");
04421     if (fileid_ptr == NULL)
04422         fileid_ptr = "";
04423     string fileid(fileid_ptr);
04424 
04425     // be paranoid about the fileid, make sure it only contains 'A-Za-z0-9_':
04426     for (unsigned int i = 0; i < fileid.length(); i++)
04427     {
04428         char ch = fileid[i];
04429         if (!((ch >= 'a' && ch <= 'z') || 
04430               (fileid[i] >= 'A' && ch <= 'Z') || 
04431               (ch >= '0' && ch <= '9') ) )
04432             fileid[i] = '_';
04433     }
04434     // limit length of string
04435     if (fileid.length() > 16)
04436         fileid = fileid.substr(0, 16);
04437     if (fileid.length() > 0)
04438         fileid.append("-");
04439 
04440     string path = appCore->getConfig()->scriptScreenshotDirectory;
04441     if (path.length() > 0 && 
04442         path[path.length()-1] != '/' && 
04443         path[path.length()-1] != '\\')
04444 
04445         path.append("/");
04446 
04447     luastate->screenshotCount++;
04448     bool success = false;
04449     char filenamestem[48];
04450     sprintf(filenamestem, "screenshot-%s%06i", fileid.c_str(), luastate->screenshotCount);
04451 
04452     // Get the dimensions of the current viewport
04453     int viewport[4];
04454     glGetIntegerv(GL_VIEWPORT, viewport);
04455 
04456 #ifndef MACOSX
04457     if (strncmp(filetype, "jpg", 3) == 0)
04458     {
04459         string filepath = path + filenamestem + ".jpg";
04460         success = CaptureGLBufferToJPEG(string(filepath),
04461                                        viewport[0], viewport[1],
04462                                        viewport[2], viewport[3]);
04463     }
04464     else
04465     {
04466         string filepath = path + filenamestem + ".png";
04467         success = CaptureGLBufferToPNG(string(filepath),
04468                                        viewport[0], viewport[1],
04469                                        viewport[2], viewport[3]);
04470     }
04471 #endif
04472     lua_pushboolean(l, success);
04473 
04474     // no matter how long it really took, make it look like 0.1s to timeout check:
04475     luastate->timeout = luastate->getTime() + timeToTimeout - 0.1;
04476     return 1;
04477 }

static int celestia_tojulianday lua_State *  l  )  [static]
 

Definition at line 3987 of file celx.cpp.

References AllErrors, checkArgs(), astro::Date::hour, astro::Date::minute, safeGetNumber(), astro::Date::seconds, this_celestia(), and WrongType.

Referenced by CreateCelestiaMetaTable().

03988 {
03989     checkArgs(l, 2, 7, "Wrong number of arguments to function celestia:tojulianday");
03990 
03991     // for error checking only:
03992     this_celestia(l);
03993 
03994     int year = (int)safeGetNumber(l, 2, AllErrors, "First arg to celestia:tojulianday must be a number", 0.0);
03995     int month = (int)safeGetNumber(l, 3, WrongType, "Second arg to celestia:tojulianday must be a number", 1.0);
03996     int day = (int)safeGetNumber(l, 4, WrongType, "Third arg to celestia:tojulianday must be a number", 1.0);
03997     int hour = (int)safeGetNumber(l, 5, WrongType, "Fourth arg to celestia:tojulianday must be a number", 0.0);
03998     int minute = (int)safeGetNumber(l, 6, WrongType, "Fifth arg to celestia:tojulianday must be a number", 0.0);
03999     double seconds = safeGetNumber(l, 7, WrongType, "Sixth arg to celestia:tojulianday must be a number", 0.0);
04000 
04001     astro::Date date(year, month, day);
04002     date.hour = hour;
04003     date.minute = minute;
04004     date.seconds = seconds;
04005 
04006     double jd = (double) date;
04007 
04008     lua_pushnumber(l, jd);
04009 
04010     return 1;
04011 }

static int celestia_tostring lua_State *  l  )  [static]
 

Definition at line 4506 of file celx.cpp.

Referenced by CreateCelestiaMetaTable().

04507 {
04508     lua_pushstring(l, "[Celestia]");
04509 
04510     return 1;
04511 }

static int celestia_unmark lua_State *  l  )  [static]
 

Definition at line 3924 of file celx.cpp.

References checkArgs(), doError(), CelestiaCore::getSimulation(), Simulation::getUniverse(), this_celestia(), to_object(), and Universe::unmarkObject().

Referenced by CreateCelestiaMetaTable().

03925 {
03926     checkArgs(l, 2, 2, "One argument expected to function celestia:unmark");
03927 
03928     CelestiaCore* appCore = this_celestia(l);
03929     Simulation* sim = appCore->getSimulation();
03930     Selection* sel = to_object(l, 2);
03931 
03932     if (sel != NULL)
03933     {
03934         sim->getUniverse()->unmarkObject(*sel, 1);
03935     }
03936     else
03937     {
03938         doError(l, "Argument to celestia:unmark must be an object");
03939     }
03940 
03941     return 0;
03942 }

static int celestia_unmarkall lua_State *  l  )  [static]
 

Definition at line 4034 of file celx.cpp.

References checkArgs(), CelestiaCore::getSimulation(), Simulation::getUniverse(), this_celestia(), and Universe::unmarkAll().

Referenced by CreateCelestiaMetaTable().

04035 {
04036     checkArgs(l, 1, 1, "No arguments expected to function celestia:unmarkall");
04037 
04038     CelestiaCore* appCore = this_celestia(l);
04039     Simulation* sim = appCore->getSimulation();
04040     sim->getUniverse()->unmarkAll();
04041 
04042     return 0;
04043 }

static int celscript_from_string lua_State *  l,
string script_text
[static]
 

Definition at line 3293 of file celx.cpp.

References _CelScript, AllErrors, doError(), getAppCore(), CelScriptWrapper::getErrorMessage(), and SetClass().

Referenced by celestia_createcelscript().

03294 {
03295 #ifdef HAVE_SSTREAM
03296     istringstream scriptfile(script_text);
03297 #else
03298     istrstream scriptfile(script_text.c_str());
03299 #endif
03300     CelestiaCore* appCore = getAppCore(l, AllErrors);
03301     CelScriptWrapper* celscript = new CelScriptWrapper(*appCore, scriptfile);
03302     if (celscript->getErrorMessage() != "")
03303     {
03304         string error = celscript->getErrorMessage();
03305         delete celscript;
03306         doError(l, error.c_str());
03307     }
03308     else
03309     {
03310         CelScriptWrapper** ud = reinterpret_cast<CelScriptWrapper**>(lua_newuserdata(l, sizeof(CelScriptWrapper*)));
03311         *ud = celscript;
03312         SetClass(l, _CelScript);
03313     }
03314 
03315     return 1;
03316 }

static int celscript_gc lua_State *  l  )  [static]
 

Definition at line 3344 of file celx.cpp.

References this_celscript().

Referenced by CreateCelscriptMetaTable().

03345 {
03346     CelScriptWrapper* script = this_celscript(l);
03347     delete script;
03348     return 0;
03349 }

static int celscript_tick lua_State *  l  )  [static]
 

Definition at line 3335 of file celx.cpp.

References getLuaStateObject(), LuaState::getTime(), this_celscript(), and CelScriptWrapper::tick().

Referenced by CreateCelscriptMetaTable().

03336 {
03337     CelScriptWrapper* script = this_celscript(l);
03338     LuaState* stateObject = getLuaStateObject(l);
03339     double t = stateObject->getTime();
03340     lua_pushboolean(l, !(script->tick(t)) );
03341     return 1;
03342 }

static int celscript_tostring lua_State *  l  )  [static]
 

Definition at line 3328 of file celx.cpp.

Referenced by CreateCelscriptMetaTable().

03329 {
03330     lua_pushstring(l, "[Celscript]");
03331 
03332     return 1;
03333 }

static void checkArgs lua_State *  l,
int  minArgs,
int  maxArgs,
const char *  errorMessage
[static]
 

Definition at line 882 of file celx.cpp.

References doError().

Referenced by celestia_createcelscript(), celestia_find(), celestia_flash(), celestia_fromjulianday(), celestia_getambient(), celestia_getfaintestvisible(), celestia_getlabelflags(), celestia_getminfeaturesize(), celestia_getminorbitsize(), celestia_getobserver(), celestia_getobservers(), celestia_getorbitflags(), celestia_getrenderflags(), celestia_getscreendimension(), celestia_getscriptpath(), celestia_getscripttime(), celestia_getselection(), celestia_getstar(), celestia_getstarcount(), celestia_getstardistancelimit(), celestia_getstarstyle(), celestia_gettextwidth(), celestia_gettime(), celestia_gettimescale(), celestia_hide(), celestia_hidelabel(), celestia_mark(), celestia_newframe(), celestia_newposition(), celestia_newrotation(), celestia_newvector(), celestia_print(), celestia_requestkeyboard(), celestia_requestsystemaccess(), celestia_select(), celestia_setambient(), celestia_setfaintestvisible(), celestia_setlabelflags(), celestia_setminfeaturesize(), celestia_setminorbitsize(), celestia_setorbitflags(), celestia_setrenderflags(), celestia_setstardistancelimit(), celestia_setstarstyle(), celestia_settime(), celestia_settimescale(), celestia_show(), celestia_showlabel(), celestia_takescreenshot(), celestia_tojulianday(), celestia_unmark(), celestia_unmarkall(), frame_from(), frame_getcoordinatesystem(), frame_getrefobject(), frame_gettargetobject(), frame_to(), object_absmag(), object_getchildren(), object_getinfo(), object_getposition(), object_mark(), object_name(), object_preloadtexture(), object_radius(), object_spectraltype(), object_type(), object_unmark(), observer_cancelgoto(), observer_center(), observer_centerorbit(), observer_chase(), observer_deleteview(), observer_equal(), observer_follow(), observer_getfov(), observer_getframe(), observer_getlocationflags(), observer_getorientation(), observer_getposition(), observer_getspeed(), observer_getsurface(), observer_gettime(), observer_goto(), observer_gotodistance(), observer_gotolocation(), observer_gotolonglat(), observer_gotosurface(), observer_gototable(), observer_isvalid(), observer_lock(), observer_lookat(), observer_rotate(), observer_setfov(), observer_setframe(), observer_setlocationflags(), observer_setorientation(), observer_setposition(), observer_setspeed(), observer_setsurface(), observer_singleview(), observer_splitview(), observer_synchronous(), observer_track(), observer_travelling(), position_add(), position_addvector(), position_distanceto(), position_get(), position_getx(), position_gety(), position_getz(), position_orientationto(), position_set(), position_sub(), position_vectorto(), rotation_add(), rotation_get(), rotation_imag(), rotation_mult(), rotation_real(), rotation_set(), rotation_setaxisangle(), rotation_slerp(), rotation_transform(), vector_add(), vector_cross(), vector_get(), vector_getx(), vector_gety(), vector_getz(), vector_length(), vector_mult(), vector_normalize(), vector_set(), and vector_sub().

00884 {
00885     int argc = lua_gettop(l);
00886     if (argc < minArgs || argc > maxArgs)
00887     {
00888         doError(l, errorMessage);
00889     }
00890 }

static void checkTimeslice lua_State *  l,
lua_Debug *  ar
[static]
 

Definition at line 411 of file celx.cpp.

References LuaState::timesliceExpired().

Referenced by LuaState::createThread(), and LuaState::timesliceExpired().

00412 {
00413     lua_pushstring(l, "celestia-luastate");
00414     lua_gettable(l, LUA_REGISTRYINDEX);
00415     if (!lua_islightuserdata(l, -1))
00416     {
00417         lua_pushstring(l, "Internal Error: Invalid table entry in checkTimeslice");
00418         lua_error(l);
00419     }
00420     LuaState* luastate = static_cast<LuaState*>(lua_touserdata(l, -1));
00421     if (luastate == NULL)
00422     {
00423         lua_pushstring(l, "Internal Error: Invalid value in checkTimeslice");
00424         lua_error(l);
00425     }
00426 
00427     if (luastate->timesliceExpired())
00428     {
00429         const char* errormsg = "Timeout: script hasn't returned control to celestia (forgot to call wait()?)";
00430         cerr << errormsg << "\n";
00431         lua_pushstring(l, errormsg);
00432         lua_error(l);
00433     }
00434     return;
00435 }

static void* CheckUserData lua_State *  l,
int  index,
int  id
[static]
 

Definition at line 340 of file celx.cpp.

References istype().

Referenced by this_celscript(), to_celestia(), to_frame(), to_object(), to_position(), to_rotation(), and to_vector().

00341 {
00342     if (istype(l, index, id))
00343         return lua_touserdata(l, index);
00344     else
00345         return NULL;
00346 }

static void CreateCelestiaMetaTable lua_State *  l  )  [static]
 

Definition at line 4513 of file celx.cpp.

References _Celestia, celestia_createcelscript(), celestia_find(), celestia_flash(), celestia_fromjulianday(), celestia_getambient(), celestia_getfaintestvisible(), celestia_getlabelflags(), celestia_getminfeaturesize(), celestia_getminorbitsize(), celestia_getobserver(), celestia_getobservers(), celestia_getorbitflags(), celestia_getrenderflags(), celestia_getscreendimension(), celestia_getscriptpath(), celestia_getscripttime(), celestia_getselection(), celestia_getstar(), celestia_getstarcount(), celestia_getstardistancelimit(), celestia_getstarstyle(), celestia_gettextwidth(), celestia_gettime(), celestia_gettimescale(), celestia_hide(), celestia_hidelabel(), celestia_mark(), celestia_newframe(), celestia_newposition(), celestia_newrotation(), celestia_newvector(), celestia_print(), celestia_requestkeyboard(), celestia_requestsystemaccess(), celestia_select(), celestia_setambient(), celestia_setfaintestvisible(), celestia_setlabelflags(), celestia_setminfeaturesize(), celestia_setminorbitsize(), celestia_setorbitflags(), celestia_setrenderflags(), celestia_setstardistancelimit(), celestia_setstarstyle(), celestia_settime(), celestia_settimescale(), celestia_show(), celestia_showlabel(), celestia_takescreenshot(), celestia_tojulianday(), celestia_tostring(), celestia_unmark(), celestia_unmarkall(), CreateClassMetatable(), and RegisterMethod().

Referenced by LuaState::init().

04514 {
04515     CreateClassMetatable(l, _Celestia);
04516 
04517     RegisterMethod(l, "__tostring", celestia_tostring);
04518     RegisterMethod(l, "flash", celestia_flash);
04519     RegisterMethod(l, "print", celestia_print);
04520     RegisterMethod(l, "gettextwidth", celestia_gettextwidth);
04521     RegisterMethod(l, "show", celestia_show);
04522     RegisterMethod(l, "hide", celestia_hide);
04523     RegisterMethod(l, "getrenderflags", celestia_getrenderflags);
04524     RegisterMethod(l, "setrenderflags", celestia_setrenderflags);
04525     RegisterMethod(l, "getscreendimension", celestia_getscreendimension);
04526     RegisterMethod(l, "showlabel", celestia_showlabel);
04527     RegisterMethod(l, "hidelabel", celestia_hidelabel);
04528     RegisterMethod(l, "getlabelflags", celestia_getlabelflags);
04529     RegisterMethod(l, "setlabelflags", celestia_setlabelflags);
04530     RegisterMethod(l, "getorbitflags", celestia_getorbitflags);
04531     RegisterMethod(l, "setorbitflags", celestia_setorbitflags);
04532     RegisterMethod(l, "getfaintestvisible", celestia_getfaintestvisible);
04533     RegisterMethod(l, "setfaintestvisible", celestia_setfaintestvisible);
04534     RegisterMethod(l, "setminfeaturesize", celestia_setminfeaturesize);
04535     RegisterMethod(l, "getminfeaturesize", celestia_getminfeaturesize);
04536     RegisterMethod(l, "getobserver", celestia_getobserver);
04537     RegisterMethod(l, "getobservers", celestia_getobservers);
04538     RegisterMethod(l, "getselection", celestia_getselection);
04539     RegisterMethod(l, "find", celestia_find);
04540     RegisterMethod(l, "select", celestia_select);
04541     RegisterMethod(l, "mark", celestia_mark);
04542     RegisterMethod(l, "unmark", celestia_unmark);
04543     RegisterMethod(l, "unmarkall", celestia_unmarkall);
04544     RegisterMethod(l, "gettime", celestia_gettime);
04545     RegisterMethod(l, "settime", celestia_settime);
04546     RegisterMethod(l, "gettimescale", celestia_gettimescale);
04547     RegisterMethod(l, "settimescale", celestia_settimescale);
04548     RegisterMethod(l, "getambient", celestia_getambient);
04549     RegisterMethod(l, "setambient", celestia_setambient);
04550     RegisterMethod(l, "getminorbitsize", celestia_getminorbitsize);
04551     RegisterMethod(l, "setminorbitsize", celestia_setminorbitsize);
04552     RegisterMethod(l, "getstardistancelimit", celestia_getstardistancelimit);
04553     RegisterMethod(l, "setstardistancelimit", celestia_setstardistancelimit);
04554     RegisterMethod(l, "getstarstyle", celestia_getstarstyle);
04555     RegisterMethod(l, "setstarstyle", celestia_setstarstyle);
04556     RegisterMethod(l, "tojulianday", celestia_tojulianday);
04557     RegisterMethod(l, "fromjulianday", celestia_fromjulianday);
04558     RegisterMethod(l, "getstarcount", celestia_getstarcount);
04559     RegisterMethod(l, "getstar", celestia_getstar);
04560     RegisterMethod(l, "newframe", celestia_newframe);
04561     RegisterMethod(l, "newvector", celestia_newvector);
04562     RegisterMethod(l, "newposition", celestia_newposition);
04563     RegisterMethod(l, "newrotation", celestia_newrotation);
04564     RegisterMethod(l, "getscripttime", celestia_getscripttime);
04565     RegisterMethod(l, "requestkeyboard", celestia_requestkeyboard);
04566     RegisterMethod(l, "takescreenshot", celestia_takescreenshot);
04567     RegisterMethod(l, "createcelscript", celestia_createcelscript);
04568     RegisterMethod(l, "requestsystemaccess", celestia_requestsystemaccess);
04569     RegisterMethod(l, "getscriptpath", celestia_getscriptpath);
04570 
04571     lua_pop(l, 1);
04572 }

static void CreateCelscriptMetaTable lua_State *  l  )  [static]
 

Definition at line 3352 of file celx.cpp.

References _CelScript, celscript_gc(), celscript_tick(), celscript_tostring(), CreateClassMetatable(), and RegisterMethod().

Referenced by LuaState::init().

03353 {
03354     CreateClassMetatable(l, _CelScript);
03355 
03356     RegisterMethod(l, "__tostring", celscript_tostring);
03357     RegisterMethod(l, "tick", celscript_tick);
03358     RegisterMethod(l, "__gc", celscript_gc);
03359 
03360     lua_pop(l, 1); // remove metatable from stack
03361 }

static void CreateClassMetatable lua_State *  l,
int  id
[static]
 

Definition at line 287 of file celx.cpp.

References PushClass().

Referenced by CreateCelestiaMetaTable(), CreateCelscriptMetaTable(), CreateFrameMetaTable(), CreateObjectMetaTable(), CreateObserverMetaTable(), CreatePositionMetaTable(), CreateRotationMetaTable(), and CreateVectorMetaTable().

00288 {
00289     lua_newtable(l);
00290     PushClass(l, id);
00291     lua_pushvalue(l, -2);
00292     lua_rawset(l, LUA_REGISTRYINDEX); // registry.name = metatable
00293     lua_pushvalue(l, -1);
00294     PushClass(l, id);
00295     lua_rawset(l, LUA_REGISTRYINDEX); // registry.metatable = name
00296 
00297     lua_pushliteral(l, "__index");
00298     lua_pushvalue(l, -2);
00299     lua_rawset(l, -3);
00300 }

static void CreateFrameMetaTable lua_State *  l  )  [static]
 

Definition at line 2007 of file celx.cpp.

References _Frame, CreateClassMetatable(), frame_from(), frame_getcoordinatesystem(), frame_getrefobject(), frame_gettargetobject(), frame_to(), frame_tostring(), and RegisterMethod().

Referenced by LuaState::init().

02008 {
02009     CreateClassMetatable(l, _Frame);
02010 
02011     RegisterMethod(l, "__tostring", frame_tostring);
02012     RegisterMethod(l, "to", frame_to);
02013     RegisterMethod(l, "from", frame_from);
02014     RegisterMethod(l, "getcoordinatesystem", frame_getcoordinatesystem);
02015     RegisterMethod(l, "getrefobject", frame_getrefobject);
02016     RegisterMethod(l, "gettargetobject", frame_gettargetobject);
02017 
02018     lua_pop(l, 1); // remove metatable from stack
02019 }

static void CreateObjectMetaTable lua_State *  l  )  [static]
 

Definition at line 2437 of file celx.cpp.

References _Object, CreateClassMetatable(), object_absmag(), object_getchildren(), object_getinfo(), object_getposition(), object_mark(), object_name(), object_preloadtexture(), object_radius(), object_spectraltype(), object_tostring(), object_type(), object_unmark(), and RegisterMethod().

Referenced by LuaState::init().

02438 {
02439     CreateClassMetatable(l, _Object);
02440 
02441     RegisterMethod(l, "__tostring", object_tostring);
02442     RegisterMethod(l, "radius", object_radius);
02443     RegisterMethod(l, "type", object_type);
02444     RegisterMethod(l, "spectraltype", object_spectraltype);
02445     RegisterMethod(l, "getinfo", object_getinfo);
02446     RegisterMethod(l, "absmag", object_absmag);
02447     RegisterMethod(l, "name", object_name);
02448     RegisterMethod(l, "mark", object_mark);
02449     RegisterMethod(l, "unmark", object_unmark);
02450     RegisterMethod(l, "getposition", object_getposition);
02451     RegisterMethod(l, "getchildren", object_getchildren);
02452     RegisterMethod(l, "preloadtexture", object_preloadtexture);
02453 
02454     lua_pop(l, 1); // pop metatable off the stack
02455 }

static void CreateObserverMetaTable lua_State *  l  )  [static]
 

Definition at line 3244 of file celx.cpp.

References _Observer, CreateClassMetatable(), observer_cancelgoto(), observer_center(), observer_centerorbit(), observer_chase(), observer_deleteview(), observer_equal(), observer_follow(), observer_getfov(), observer_getframe(), observer_getlocationflags(), observer_getorientation(), observer_getposition(), observer_getspeed(), observer_getsurface(), observer_gettime(), observer_goto(), observer_gotodistance(), observer_gotolocation(), observer_gotolonglat(), observer_gotosurface(), observer_isvalid(), observer_lock(), observer_lookat(), observer_rotate(), observer_setfov(), observer_setframe(), observer_setlocationflags(), observer_setorientation(), observer_setposition(), observer_setspeed(), observer_setsurface(), observer_singleview(), observer_splitview(), observer_synchronous(), observer_tostring(), observer_track(), observer_travelling(), and RegisterMethod().

Referenced by LuaState::init().

03245 {
03246     CreateClassMetatable(l, _Observer);
03247 
03248     RegisterMethod(l, "__tostring", observer_tostring);
03249     RegisterMethod(l, "isvalid", observer_isvalid);
03250     RegisterMethod(l, "goto", observer_goto);
03251     RegisterMethod(l, "gotolonglat", observer_gotolonglat);
03252     RegisterMethod(l, "gotolocation", observer_gotolocation);
03253     RegisterMethod(l, "gotodistance", observer_gotodistance);
03254     RegisterMethod(l, "gotosurface", observer_gotosurface);
03255     RegisterMethod(l, "cancelgoto", observer_cancelgoto);
03256     RegisterMethod(l, "setposition", observer_setposition);
03257     RegisterMethod(l, "lookat", observer_lookat);
03258     RegisterMethod(l, "setorientation", observer_setorientation);
03259     RegisterMethod(l, "getorientation", observer_getorientation);
03260     RegisterMethod(l, "getspeed", observer_getspeed);
03261     RegisterMethod(l, "setspeed", observer_setspeed);
03262     RegisterMethod(l, "getfov", observer_getfov);
03263     RegisterMethod(l, "setfov", observer_setfov);
03264     RegisterMethod(l, "rotate", observer_rotate);
03265     RegisterMethod(l, "center", observer_center);
03266     RegisterMethod(l, "centerorbit", observer_centerorbit);
03267     RegisterMethod(l, "follow", observer_follow);
03268     RegisterMethod(l, "synchronous", observer_synchronous);
03269     RegisterMethod(l, "chase", observer_chase);
03270     RegisterMethod(l, "lock", observer_lock);
03271     RegisterMethod(l, "track", observer_track);
03272     RegisterMethod(l, "travelling", observer_travelling);
03273     RegisterMethod(l, "getframe", observer_getframe);
03274     RegisterMethod(l, "setframe", observer_setframe);
03275     RegisterMethod(l, "gettime", observer_gettime);
03276     RegisterMethod(l, "getposition", observer_getposition);
03277     RegisterMethod(l, "getsurface", observer_getsurface);
03278     RegisterMethod(l, "setsurface", observer_setsurface);
03279     RegisterMethod(l, "splitview", observer_splitview);
03280     RegisterMethod(l, "deleteview", observer_deleteview);
03281     RegisterMethod(l, "singleview", observer_singleview);
03282     RegisterMethod(l, "getlocationflags", observer_getlocationflags);
03283     RegisterMethod(l, "setlocationflags", observer_setlocationflags);
03284     RegisterMethod(l, "__eq", observer_equal);
03285 
03286     lua_pop(l, 1); // remove metatable from stack
03287 }

static void CreatePositionMetaTable lua_State *  l  )  [static]
 

Definition at line 1798 of file celx.cpp.

References _Position, CreateClassMetatable(), position_add(), position_addvector(), position_distanceto(), position_get(), position_getx(), position_gety(), position_getz(), position_orientationto(), position_set(), position_sub(), position_tostring(), position_vectorto(), and RegisterMethod().

Referenced by LuaState::init().

01799 {
01800     CreateClassMetatable(l, _Position);
01801 
01802     RegisterMethod(l, "__tostring", position_tostring);
01803     RegisterMethod(l, "distanceto", position_distanceto);
01804     RegisterMethod(l, "vectorto", position_vectorto);
01805     RegisterMethod(l, "orientationto", position_orientationto);
01806     RegisterMethod(l, "addvector", position_addvector);
01807     RegisterMethod(l, "__add", position_add);
01808     RegisterMethod(l, "__sub", position_sub);
01809     RegisterMethod(l, "__index", position_get);
01810     RegisterMethod(l, "__newindex", position_set);
01811     RegisterMethod(l, "getx", position_getx);
01812     RegisterMethod(l, "gety", position_gety);
01813     RegisterMethod(l, "getz", position_getz);
01814 
01815     lua_pop(l, 1); // remove metatable from stack
01816 }

static void CreateRotationMetaTable lua_State *  l  )  [static]
 

Definition at line 1524 of file celx.cpp.

References _Rotation, CreateClassMetatable(), RegisterMethod(), rotation_add(), rotation_get(), rotation_imag(), rotation_mult(), rotation_real(), rotation_set(), rotation_setaxisangle(), rotation_slerp(), rotation_tostring(), and rotation_transform().

Referenced by LuaState::init().

01525 {
01526     CreateClassMetatable(l, _Rotation);
01527 
01528     RegisterMethod(l, "real", rotation_real);
01529     RegisterMethod(l, "imag", rotation_imag);
01530     RegisterMethod(l, "transform", rotation_transform);
01531     RegisterMethod(l, "setaxisangle", rotation_setaxisangle);
01532     RegisterMethod(l, "slerp", rotation_slerp);
01533     RegisterMethod(l, "__tostring", rotation_tostring);
01534     RegisterMethod(l, "__add", rotation_add);
01535     RegisterMethod(l, "__mul", rotation_mult);
01536     RegisterMethod(l, "__index", rotation_get);
01537     RegisterMethod(l, "__newindex", rotation_set);
01538 
01539     lua_pop(l, 1); // remove metatable from stack
01540 }

static void CreateVectorMetaTable lua_State *  l  )  [static]
 

Definition at line 1308 of file celx.cpp.

References _Vec3, CreateClassMetatable(), RegisterMethod(), vector_add(), vector_cross(), vector_get(), vector_getx(), vector_gety(), vector_getz(), vector_length(), vector_mult(), vector_normalize(), vector_set(), vector_sub(), and vector_tostring().

Referenced by LuaState::init().

01309 {
01310     CreateClassMetatable(l, _Vec3);
01311 
01312     RegisterMethod(l, "__tostring", vector_tostring);
01313     RegisterMethod(l, "__add", vector_add);
01314     RegisterMethod(l, "__sub", vector_sub);
01315     RegisterMethod(l, "__mul", vector_mult);
01316     RegisterMethod(l, "__pow", vector_cross);
01317     RegisterMethod(l, "__index", vector_get);
01318     RegisterMethod(l, "__newindex", vector_set);
01319     RegisterMethod(l, "getx", vector_getx);
01320     RegisterMethod(l, "gety", vector_gety);
01321     RegisterMethod(l, "getz", vector_getz);
01322     RegisterMethod(l, "normalize", vector_normalize);
01323     RegisterMethod(l, "length", vector_length);
01324 
01325     lua_pop(l, 1); // remove metatable from stack
01326 }

static void doError lua_State *  l,
const char *  errorMsg
[static]
 

Definition at line 745 of file celx.cpp.

Referenced by celestia_find(), celestia_getambient(), celestia_getminorbitsize(), celestia_getstardistancelimit(), celestia_getstarstyle(), celestia_mark(), celestia_newframe(), celestia_newposition(), celestia_newrotation(), celestia_requestkeyboard(), celestia_setlabelflags(), celestia_setminorbitsize(), celestia_setorbitflags(), celestia_setrenderflags(), celestia_setstardistancelimit(), celestia_setstarstyle(), celestia_unmark(), celscript_from_string(), checkArgs(), frame_from(), frame_to(), getLuaStateObject(), observer_center(), observer_centerorbit(), observer_chase(), observer_follow(), observer_goto(), observer_gotodistance(), observer_gotolocation(), observer_gotolonglat(), observer_gotosurface(), observer_lock(), observer_lookat(), observer_rotate(), observer_setframe(), observer_setlocationflags(), observer_setorientation(), observer_setposition(), observer_synchronous(), observer_track(), position_add(), position_addvector(), position_distanceto(), position_get(), position_orientationto(), position_set(), position_sub(), position_vectorto(), rotation_add(), rotation_get(), rotation_mult(), rotation_set(), rotation_setaxisangle(), rotation_slerp(), rotation_transform(), safeGetNumber(), safeGetString(), this_celestia(), this_celscript(), this_frame(), this_object(), this_observer(), this_position(), this_rotation(), this_vector(), vector_add(), vector_cross(), vector_get(), vector_mult(), vector_set(), and vector_sub().

00746 {
00747     lua_Debug debug;
00748     if (lua_getstack(l, 1, &debug))
00749     {
00750         char buf[1024];
00751         if (lua_getinfo(l, "l", &debug))
00752         {
00753             sprintf(buf, "In line %i: %s", debug.currentline, errorMsg);
00754             lua_pushstring(l, buf);
00755             lua_error(l);
00756         }
00757     }
00758     lua_pushstring(l, errorMsg);
00759     lua_error(l);
00760 }

static int frame_from lua_State *  l  )  [static]
 

Definition at line 1847 of file celx.cpp.

References _Position, _Rotation, AllErrors, checkArgs(), doError(), getAppCore(), CelestiaCore::getSimulation(), Simulation::getTime(), istype(), position_new(), RigidTransform::rotation, rotation_new(), safeGetNumber(), this_frame(), to_position(), to_rotation(), FrameOfReference::toUniversal(), RigidTransform::translation, and WrongType.

Referenced by CreateFrameMetaTable().

01848 {
01849     checkArgs(l, 2, 3, "Two or three arguments required for frame:from");
01850 
01851     FrameOfReference* frame = this_frame(l);
01852     CelestiaCore* appCore = getAppCore(l, AllErrors);
01853 
01854     RigidTransform rt;
01855 
01856     UniversalCoord* uc = NULL;
01857     Quatd* q = NULL;
01858     double jd = 0.0;
01859 
01860     if (istype(l, 2, _Position))
01861     {
01862         uc = to_position(l, 2);
01863     }
01864     else if (istype(l, 2, _Rotation))
01865     {
01866         q = to_rotation(l, 2);
01867     }
01868     if (uc == NULL && q == NULL)
01869     {
01870         doError(l, "Position or rotation expected as second argument to frame:from()");
01871     }
01872 
01873     jd = safeGetNumber(l, 3, WrongType, "Second arg to frame:from must be a number", appCore->getSimulation()->getTime());
01874 
01875     if (uc != NULL)
01876     {
01877         rt.translation = *uc;
01878         rt = frame->toUniversal(rt, jd);
01879         position_new(l, rt.translation);
01880     }
01881     else
01882     {
01883         rt.rotation = *q;
01884         rt = frame->toUniversal(rt, jd);
01885         rotation_new(l, rt.rotation);
01886     }
01887 
01888     return 1;
01889 }

static int frame_getcoordinatesystem lua_State *  l  )  [static]
 

Definition at line 1970 of file celx.cpp.

References checkArgs(), FrameOfReference::coordSys, and this_frame().

Referenced by CreateFrameMetaTable().

01971 {
01972     checkArgs(l, 1, 1, "No arguments expected for frame:getcoordinatesystem()");
01973 
01974     FrameOfReference* frame = this_frame(l);
01975     string coordsys;
01976     switch (frame->coordSys)
01977     {
01978     case astro::Universal: 
01979         coordsys = "universal"; break;
01980     case astro::Ecliptical: 
01981         coordsys = "ecliptic"; break;
01982     case astro::Equatorial: 
01983         coordsys = "equatorial"; break;
01984     case astro::Geographic: 
01985         coordsys = "planetographic"; break;
01986     case astro::ObserverLocal: 
01987         coordsys = "observer"; break;
01988     case astro::PhaseLock: 
01989         coordsys = "lock"; break;
01990     case astro::Chase: 
01991         coordsys = "chase"; break;
01992     default: 
01993         coordsys = "invalid";
01994     }
01995     lua_pushstring(l, coordsys.c_str());
01996     return 1;
01997 }

static int frame_getrefobject lua_State *  l  )  [static]
 

Definition at line 1938 of file celx.cpp.

References checkArgs(), Selection::getType(), object_new(), FrameOfReference::refObject, and this_frame().

Referenced by CreateFrameMetaTable().

01939 {
01940     checkArgs(l, 1, 1, "No arguments expected for frame:getrefobject()");
01941 
01942     FrameOfReference* frame = this_frame(l);
01943     if (frame->refObject.getType() == Selection::Type_Nil)
01944     {
01945         lua_pushnil(l);
01946     }
01947     else
01948     {
01949         object_new(l, frame->refObject);
01950     }
01951     return 1;
01952 }

static int frame_gettargetobject lua_State *  l  )  [static]
 

Definition at line 1954 of file celx.cpp.

References checkArgs(), Selection::getType(), object_new(), FrameOfReference::targetObject, and this_frame().

Referenced by CreateFrameMetaTable().

01955 {
01956     checkArgs(l, 1, 1, "No arguments expected for frame:gettarget()");
01957 
01958     FrameOfReference* frame = this_frame(l);
01959     if (frame->targetObject.getType() == Selection::Type_Nil)
01960     {
01961         lua_pushnil(l);
01962     }
01963     else
01964     {
01965         object_new(l, frame->targetObject);
01966     }
01967     return 1;
01968 }

static int frame_new lua_State *  l,
const FrameOfReference f
[static]
 

Definition at line 1819 of file celx.cpp.

References _Frame, and SetClass().

Referenced by celestia_newframe(), and observer_getframe().

01820 {
01821     FrameOfReference* ud = reinterpret_cast<FrameOfReference*>(lua_newuserdata(l, sizeof(FrameOfReference)));
01822     *ud = f;
01823 
01824     SetClass(l, _Frame);
01825 
01826     return 1;
01827 }

static int frame_to lua_State *  l  )  [static]
 

Definition at line 1892 of file celx.cpp.

References _Position, _Rotation, AllErrors, checkArgs(), doError(), FrameOfReference::fromUniversal(), getAppCore(), CelestiaCore::getSimulation(), Simulation::getTime(), istype(), position_new(), RigidTransform::rotation, rotation_new(), safeGetNumber(), this_frame(), to_position(), to_rotation(), RigidTransform::translation, and WrongType.

Referenced by CreateFrameMetaTable().

01893 {
01894     checkArgs(l, 2, 3, "Two or three arguments required for frame:to");
01895 
01896     FrameOfReference* frame = this_frame(l);
01897     CelestiaCore* appCore = getAppCore(l, AllErrors);
01898 
01899     RigidTransform rt;
01900 
01901     UniversalCoord* uc = NULL;
01902     Quatd* q = NULL;
01903     double jd = 0.0;
01904 
01905     if (istype(l, 2, _Position))
01906     {
01907         uc = to_position(l, 2);
01908     }
01909     else
01910     if (istype(l, 2, _Rotation))
01911     {
01912         q = to_rotation(l, 2);
01913     }
01914 
01915     if (uc == NULL && q == NULL)
01916     {
01917         doError(l, "Position or rotation expected as second argument to frame:to()");
01918     }
01919 
01920     jd = safeGetNumber(l, 3, WrongType, "Second arg to frame:to must be a number", appCore->getSimulation()->getTime());
01921 
01922     if (uc != NULL)
01923     {
01924         rt.translation = *uc;
01925         rt = frame->fromUniversal(rt, jd);
01926         position_new(l, rt.translation);
01927     }
01928     else
01929     {
01930         rt.rotation = *q;
01931         rt = frame->fromUniversal(rt, jd);
01932         rotation_new(l, rt.rotation);
01933     }
01934 
01935     return 1;
01936 }

static int frame_tostring lua_State *  l  )  [static]
 

Definition at line 1999 of file celx.cpp.

Referenced by CreateFrameMetaTable().

02000 {
02001     // TODO: print out the actual information about the frame
02002     lua_pushstring(l, "[Frame]");
02003 
02004     return 1;
02005 }

static CelestiaCore* getAppCore lua_State *  l,
FatalErrors  fatalErrors = NoErrors
[static]
 

Definition at line 350 of file celx.cpp.

References NoErrors.

Referenced by celscript_from_string(), LuaState::charEntered(), LuaState::cleanup(), frame_from(), frame_to(), object_getchildren(), object_getinfo(), object_getposition(), object_mark(), object_name(), object_preloadtexture(), object_unmark(), observer_deleteview(), observer_setfov(), observer_singleview(), observer_splitview(), LuaState::requestIO(), LuaState::resume(), LuaState::tick(), and to_observer().

00351 {
00352     lua_pushstring(l, "celestia-appcore");
00353     lua_gettable(l, LUA_REGISTRYINDEX);
00354 
00355     if (!lua_islightuserdata(l, -1))
00356     {
00357         if (fatalErrors == NoErrors)
00358             return NULL;
00359         else
00360         {
00361             lua_pushstring(l, "internal error: invalid appCore");
00362             lua_error(l);
00363         }
00364     }
00365 
00366     CelestiaCore* appCore = static_cast<CelestiaCore*>(lua_touserdata(l, -1));
00367     lua_pop(l, 1);
00368     return appCore;
00369 }

LuaState* getLuaStateObject lua_State *  l  ) 
 

Definition at line 932 of file celx.cpp.

References doError().

Referenced by celestia_getscripttime(), celestia_requestsystemaccess(), celestia_takescreenshot(), celscript_tick(), and object_preloadtexture().

00933 {
00934     int stackSize = lua_gettop(l);
00935     lua_pushstring(l, "celestia-luastate");
00936     lua_gettable(l, LUA_REGISTRYINDEX);
00937 
00938     if (!lua_islightuserdata(l, -1))
00939     {
00940         doError(l, "Internal Error: Invalid table entry for LuaState-pointer");
00941     }
00942     LuaState* luastate_ptr = static_cast<LuaState*>(lua_touserdata(l, -1));
00943     if (luastate_ptr == NULL)
00944     {
00945         doError(l, "Internal Error: Invalid LuaState-pointer");
00946     }
00947     lua_settop(l, stackSize);
00948     return luastate_ptr;
00949 }

void getObservers CelestiaCore appCore,
vector< Observer * > &  list
 

Definition at line 967 of file celx.cpp.

Referenced by celestia_getobservers().

00968 {
00969     for (unsigned int i = 0; i < appCore->views.size(); i++)
00970     {
00971         list.push_back(appCore->views[i]->observer);
00972     }
00973 }

View* getViewByObserver CelestiaCore appCore,
Observer obs
 

Definition at line 954 of file celx.cpp.

Referenced by observer_deleteview(), observer_singleview(), observer_splitview(), and to_observer().

00955 {
00956     for (unsigned int i = 0; i < appCore->views.size(); i++)
00957     {
00958         if ((appCore->views[i])->observer == obs)
00959         {
00960             return appCore->views[i];
00961         }
00962     }
00963     return NULL;
00964 }

static void initBodyTypeMap  )  [static]
 

Definition at line 127 of file celx.cpp.

References BodyTypeMap.

Referenced by initMaps().

00128 {
00129     BodyTypeMap["Planet"] = Body::Planet;
00130     BodyTypeMap["Moon"] = Body::Moon;
00131     BodyTypeMap["Asteroid"] = Body::Asteroid;
00132     BodyTypeMap["Comet"] = Body::Comet;
00133     BodyTypeMap["Spacecraft"] = Body::Spacecraft;
00134     BodyTypeMap["Invisible"] = Body::Invisible;
00135     BodyTypeMap["Unknown"] = Body::Unknown;
00136 }

static void initLabelFlagMap  )  [static]
 

Definition at line 114 of file celx.cpp.

References LabelFlagMap.

Referenced by initMaps().

00115 {
00116     LabelFlagMap["planets"] = Renderer::PlanetLabels;
00117     LabelFlagMap["moons"] = Renderer::MoonLabels;
00118     LabelFlagMap["spacecraft"] = Renderer::SpacecraftLabels;
00119     LabelFlagMap["asteroids"] = Renderer::AsteroidLabels;
00120     LabelFlagMap["comets"] = Renderer::CometLabels;
00121     LabelFlagMap["constellations"] = Renderer::ConstellationLabels;
00122     LabelFlagMap["stars"] = Renderer::StarLabels;
00123     LabelFlagMap["galaxies"] = Renderer::GalaxyLabels;
00124     LabelFlagMap["locations"] = Renderer::LocationLabels;
00125 }

static void initLocationFlagMap  )  [static]
 

Definition at line 138 of file celx.cpp.

References LocationFlagMap.

Referenced by initMaps().

00139 {
00140     LocationFlagMap["city"] = Location::City;
00141     LocationFlagMap["observatory"] = Location::Observatory;
00142     LocationFlagMap["landingsite"] = Location::LandingSite;
00143     LocationFlagMap["crater"] = Location::Crater;
00144     LocationFlagMap["vallis"] = Location::Vallis;
00145     LocationFlagMap["mons"] = Location::Mons;
00146     LocationFlagMap["planum"] = Location::Planum;
00147     LocationFlagMap["chasma"] = Location::Chasma;
00148     LocationFlagMap["patera"] = Location::Patera;
00149     LocationFlagMap["mare"] = Location::Mare;
00150     LocationFlagMap["rupes"] = Location::Rupes;
00151     LocationFlagMap["tessera"] = Location::Tessera;
00152     LocationFlagMap["regio"] = Location::Regio;
00153     LocationFlagMap["chaos"] = Location::Chaos;
00154     LocationFlagMap["terra"] = Location::Terra;
00155     LocationFlagMap["astrum"] = Location::Astrum;
00156     LocationFlagMap["corona"] = Location::Corona;
00157     LocationFlagMap["dorsum"] = Location::Dorsum;
00158     LocationFlagMap["fossa"] = Location::Fossa;
00159     LocationFlagMap["catena"] = Location::Catena;
00160     LocationFlagMap["mensa"] = Location::Mensa;
00161     LocationFlagMap["rima"] = Location::Rima;
00162     LocationFlagMap["undae"] = Location::Undae;
00163     LocationFlagMap["reticulum"] = Location::Reticulum;
00164     LocationFlagMap["planitia"] = Location::Planitia;
00165     LocationFlagMap["linea"] = Location::Linea;
00166     LocationFlagMap["fluctus"] = Location::Fluctus;
00167     LocationFlagMap["farrum"] = Location::Farrum;
00168     LocationFlagMap["other"] = Location::Other;
00169 }

static void initMaps  )  [static]
 

Definition at line 171 of file celx.cpp.

References initBodyTypeMap(), initLabelFlagMap(), initLocationFlagMap(), initRenderFlagMap(), and mapsInitialized.

Referenced by LuaState::init().

00172 {
00173     if (!mapsInitialized)
00174     {
00175         initRenderFlagMap();
00176         initLabelFlagMap();
00177         initBodyTypeMap();
00178         initLocationFlagMap();
00179     }
00180     mapsInitialized = true;
00181 }

static void initRenderFlagMap  )  [static]
 

Definition at line 93 of file celx.cpp.

References RenderFlagMap.

Referenced by initMaps().

00094 {
00095     RenderFlagMap["orbits"] = Renderer::ShowOrbits;
00096     RenderFlagMap["cloudmaps"] = Renderer::ShowCloudMaps;
00097     RenderFlagMap["constellations"] = Renderer::ShowDiagrams;
00098     RenderFlagMap["galaxies"] = Renderer::ShowGalaxies;
00099     RenderFlagMap["planets"] = Renderer::ShowPlanets;
00100     RenderFlagMap["stars"] = Renderer::ShowStars;
00101     RenderFlagMap["nightmaps"] = Renderer::ShowNightMaps;
00102     RenderFlagMap["eclipseshadows"] = Renderer::ShowEclipseShadows;
00103     RenderFlagMap["ringshadows"] = Renderer::ShowRingShadows;
00104     RenderFlagMap["comettails"] = Renderer::ShowCometTails;
00105     RenderFlagMap["boundaries"] = Renderer::ShowBoundaries;
00106     RenderFlagMap["markers"] = Renderer::ShowMarkers;
00107     RenderFlagMap["automag"] = Renderer::ShowAutoMag;
00108     RenderFlagMap["atmospheres"] = Renderer::ShowAtmospheres;
00109     RenderFlagMap["grid"] = Renderer::ShowCelestialSphere;
00110     RenderFlagMap["smoothlines"] = Renderer::ShowSmoothLines;
00111     RenderFlagMap["partialtrajectories"] = Renderer::ShowPartialTrajectories;
00112 }

static bool istype lua_State *  l,
int  index,
int  id
[static]
 

Definition at line 314 of file celx.cpp.

References ClassNames.

Referenced by CheckUserData(), frame_from(), frame_to(), position_add(), position_sub(), rotation_mult(), vector_add(), vector_cross(), and vector_mult().

00315 {
00316     // get registry[metatable]
00317     if (!lua_getmetatable(l, index))
00318         return false;
00319     lua_rawget(l, LUA_REGISTRYINDEX);
00320 
00321     if (lua_type(l, -1) != LUA_TSTRING)
00322     {
00323         cout << "istype failed!  Unregistered class.\n";
00324         lua_pop(l, 1);
00325         return false;
00326     }
00327 
00328     const char* classname = lua_tostring(l, -1);
00329     if (classname != NULL && strcmp(classname, ClassNames[id]) == 0)
00330     {
00331         lua_pop(l, 1);
00332         return true;
00333     }
00334     lua_pop(l, 1);
00335     return false;
00336 }

static int object_absmag lua_State *  l  )  [static]
 

Definition at line 2300 of file celx.cpp.

References checkArgs(), Star::getAbsoluteMagnitude(), Selection::star(), and this_object().

Referenced by CreateObjectMetaTable().

02301 {
02302     checkArgs(l, 1, 1, "No arguments expected to function object:absmag");
02303 
02304     Selection* sel = this_object(l);
02305     if (sel->star() != NULL)
02306         lua_pushnumber(l, sel->star()->getAbsoluteMagnitude());
02307     else
02308         lua_pushnil(l);
02309 
02310     return 1;
02311 }

static int object_getchildren lua_State *  l  )  [static]
 

Definition at line 2372 of file celx.cpp.

References AllErrors, Selection::body(), checkArgs(), Universe::find(), getAppCore(), PlanetarySystem::getBody(), Star::getCatalogNumber(), SolarSystem::getPlanets(), Body::getSatellites(), CelestiaCore::getSimulation(), Universe::getSolarSystemCatalog(), PlanetarySystem::getSystemSize(), Simulation::getUniverse(), object_new(), Selection::star(), and this_object().

Referenced by CreateObjectMetaTable().

02373 {
02374     checkArgs(l, 1, 1, "No arguments expected for object:getchildren()");
02375 
02376     Selection* sel = this_object(l);
02377     CelestiaCore* appCore = getAppCore(l, AllErrors);
02378 
02379     Simulation* sim = appCore->getSimulation();
02380 
02381     lua_newtable(l);
02382     if (sel->star() != NULL)
02383     {
02384         SolarSystemCatalog* solarSystemCatalog = sim->getUniverse()->getSolarSystemCatalog();
02385         SolarSystemCatalog::iterator iter = solarSystemCatalog->find(sel->star()->getCatalogNumber());
02386         if (iter != solarSystemCatalog->end())
02387         {
02388             SolarSystem* solarSys = iter->second;
02389             for (int i = 0; i < solarSys->getPlanets()->getSystemSize(); i++)
02390             {
02391                 Body* body = solarSys->getPlanets()->getBody(i);
02392                 Selection satSel(body);
02393                 object_new(l, satSel);
02394                 lua_rawseti(l, -2, i + 1);
02395             }
02396         }
02397     }
02398     else if (sel->body() != NULL)
02399     {
02400         const PlanetarySystem* satellites = sel->body()->getSatellites();
02401         if (satellites != NULL && satellites->getSystemSize() != 0)
02402         {
02403             for (int i = 0; i < satellites->getSystemSize(); i++)
02404             {
02405                 Body* body = satellites->getBody(i);
02406                 Selection satSel(body);
02407                 object_new(l, satSel);
02408                 lua_rawseti(l, -2, i + 1);
02409             }
02410         }
02411     }
02412 
02413     return 1;
02414 }

static int object_getinfo lua_State *  l  )  [static]
 

Definition at line 2162 of file celx.cpp.

References AllErrors, RotationElements::ascendingNode, Selection::body(), checkArgs(), Atmosphere::cloudHeight, Atmosphere::cloudSpeed, Selection::deepsky(), RotationElements::epoch, Star::getAbsoluteMagnitude(), Body::getAlbedo(), getAppCore(), Body::getAtmosphere(), Star::getBolometricMagnitude(), Star::getCatalogNumber(), Body::getClassification(), Location::getFeatureType(), Location::getImportance(), Location::getInfoURL(), Body::getInfoURL(), Body::getLifespan(), Star::getLuminosity(), Body::getMass(), Location::getName(), Body::getName(), Body::getOblateness(), Body::getOrbit(), Star::getOrbitBarycenter(), Location::getParentBody(), Orbit::getPeriod(), PlanetarySystem::getPrimaryBody(), DeepSkyObject::getRadius(), Body::getRadius(), Star::getRadius(), Body::getRings(), Body::getRotationElements(), Star::getRotationElements(), Location::getSize(), Star::getSpectralType(), PlanetarySystem::getStar(), Body::getSystem(), Star::getTemperature(), Atmosphere::height, Selection::location(), LocationFlagMap, object_new(), RotationElements::obliquity, RotationElements::offset, RotationElements::period, RotationElements::precessionRate, setTable(), Selection::star(), and this_object().

Referenced by CreateObjectMetaTable().

02163 {
02164     checkArgs(l, 1, 1, "No arguments expected to function object:getinfo");
02165 
02166     lua_newtable(l);
02167 
02168     Selection* sel = this_object(l);
02169     if (sel->star() != NULL)
02170     {
02171         Star* star = sel->star();
02172         setTable(l, "type", "star");
02173         setTable(l, "name", getAppCore(l, AllErrors)->getSimulation()->getUniverse()
02174                        ->getStarCatalog()->getStarName(*(sel->star())).c_str());
02175         setTable(l, "catalogNumber", star->getCatalogNumber());
02176         setTable(l, "stellarClass", star->getSpectralType());
02177         setTable(l, "absoluteMagnitude", (lua_Number)star->getAbsoluteMagnitude());
02178         setTable(l, "luminosity", (lua_Number)star->getLuminosity());
02179         setTable(l, "radius", (lua_Number)star->getRadius());
02180         setTable(l, "temperature", (lua_Number)star->getTemperature());
02181         setTable(l, "rotationPeriod", (lua_Number)star->getRotationElements().period);
02182         setTable(l, "bolometricMagnitude", (lua_Number)star->getBolometricMagnitude());
02183 
02184         if (star->getOrbitBarycenter() != NULL)
02185         {
02186             Selection parent((Star*)(star->getOrbitBarycenter()));
02187             lua_pushstring(l, "parent");
02188             object_new(l, parent);
02189             lua_settable(l, -3);
02190         }
02191     }
02192     else if (sel->body() != NULL)
02193     {
02194         Body* body = sel->body();
02195         const char* tname = "unknown";
02196         switch (body->getClassification())
02197         {
02198         case Body::Planet     : tname = "planet"; break;
02199         case Body::Moon       : tname = "moon"; break;
02200         case Body::Asteroid   : tname = "asteroid"; break;
02201         case Body::Comet      : tname = "comet"; break;
02202         case Body::Spacecraft : tname = "spacecraft"; break;
02203         case Body::Invisible  : tname = "invisible"; break;
02204         }
02205         setTable(l, "type", tname);
02206         setTable(l, "name", body->getName().c_str());
02207         setTable(l, "mass", (lua_Number)body->getMass());
02208         setTable(l, "oblateness", (lua_Number)body->getOblateness());
02209         setTable(l, "albedo", (lua_Number)body->getAlbedo());
02210         setTable(l, "infoURL", body->getInfoURL().c_str());
02211         setTable(l, "radius", (lua_Number)body->getRadius());
02212 
02213         double lifespanStart, lifespanEnd;
02214         body->getLifespan(lifespanStart, lifespanEnd);
02215         setTable(l, "lifespanStart", (lua_Number)lifespanStart);
02216         setTable(l, "lifespanEnd", (lua_Number)lifespanEnd);
02217         // TODO: atmosphere, surfaces ?
02218 
02219         PlanetarySystem* system = body->getSystem();
02220         if (system->getPrimaryBody() != NULL)
02221         {
02222             Selection parent(system->getPrimaryBody());
02223             lua_pushstring(l, "parent");
02224             object_new(l, parent);
02225             lua_settable(l, -3);
02226         }
02227         else
02228         {
02229             Selection parent(system->getStar());
02230             lua_pushstring(l, "parent");
02231             object_new(l, parent);
02232             lua_settable(l, -3);
02233         }
02234 
02235         lua_pushstring(l, "hasRings");
02236         lua_pushboolean(l, body->getRings() != NULL);
02237         lua_settable(l, -3);
02238         RotationElements re = body->getRotationElements();
02239         setTable(l, "rotationPeriod", (double)re.period);
02240         setTable(l, "rotationOffset", (double)re.offset);
02241         setTable(l, "rotationEpoch", re.epoch);
02242         setTable(l, "rotationObliquity", (double)re.obliquity);
02243         setTable(l, "rotationAscendingNode", (double)re.ascendingNode);
02244         setTable(l, "rotationPrecessionRate", (double)re.precessionRate);
02245         Orbit* orbit = body->getOrbit();
02246         setTable(l, "orbitPeriod", orbit->getPeriod());
02247         Atmosphere* atmosphere = body->getAtmosphere();
02248         if (atmosphere != NULL)
02249         {
02250             setTable(l, "atmosphereHeight", (double)atmosphere->height);
02251             setTable(l, "atmosphereCloudHeight", (double)atmosphere->cloudHeight);
02252             setTable(l, "atmosphereCloudSpeed", (double)atmosphere->cloudSpeed);
02253         }
02254     }
02255     else if (sel->deepsky() != NULL)
02256     {
02257         setTable(l, "type", "deepsky");
02258         DeepSkyObject* deepsky = sel->deepsky();
02259         setTable(l, "name", getAppCore(l, AllErrors)->getSimulation()->getUniverse()
02260                            ->getDSOCatalog()->getDSOName(sel->deepsky()).c_str());
02261         setTable(l, "radius", (lua_Number)deepsky->getRadius());
02262     }
02263     else if (sel->location() != NULL)
02264     {
02265         setTable(l, "type", "location");
02266         Location* location = sel->location();
02267         setTable(l, "name", location->getName().c_str());
02268         setTable(l, "size", (lua_Number)location->getSize());
02269         setTable(l, "importance", (lua_Number)location->getImportance());
02270         setTable(l, "infoURL", location->getInfoURL().c_str());
02271 
02272         uint32 featureType = location->getFeatureType();
02273         string featureName("Unknown");
02274         for (FlagMap::const_iterator it = LocationFlagMap.begin(); it != LocationFlagMap.end(); it++)
02275         {
02276             if (it->second == featureType)
02277             {
02278                 featureName = it->first;
02279                 break;
02280             }
02281         }
02282         setTable(l, "featureType", featureName.c_str());
02283 
02284         Body* parent = location->getParentBody();
02285         if (parent != NULL)
02286         {
02287             Selection selection(parent);
02288             lua_pushstring(l, "parent");
02289             object_new(l, selection);
02290             lua_settable(l, -3);
02291         }
02292     }
02293     else
02294     {
02295         setTable(l, "type", "null");
02296     }
02297     return 1;
02298 }

static int object_getposition lua_State *  l  )  [static]
 

Definition at line 2358 of file celx.cpp.

References AllErrors, checkArgs(), getAppCore(), Selection::getPosition(), CelestiaCore::getSimulation(), Simulation::getTime(), position_new(), safeGetNumber(), this_object(), and WrongType.

Referenced by CreateObjectMetaTable().

02359 {
02360     checkArgs(l, 1, 2, "Expected no or one argument to object:getposition");
02361 
02362     Selection* sel = this_object(l);
02363     CelestiaCore* appCore = getAppCore(l, AllErrors);
02364 
02365     double t = safeGetNumber(l, 2, WrongType, "Time expected as argument to object:getposition",
02366                               appCore->getSimulation()->getTime());
02367     position_new(l, sel->getPosition(t));
02368 
02369     return 1;
02370 }

static int object_mark lua_State *  l  )  [static]
 

Definition at line 2313 of file celx.cpp.

References AllErrors, checkArgs(), getAppCore(), CelestiaCore::getSimulation(), Simulation::getUniverse(), Universe::markObject(), Color::parse(), parseMarkerSymbol(), safeGetNumber(), safeGetString(), this_object(), and WrongType.

Referenced by CreateObjectMetaTable().

02314 {
02315     checkArgs(l, 1, 4, "No arguments expected to function object:mark");
02316 
02317     Selection* sel = this_object(l);
02318     CelestiaCore* appCore = getAppCore(l, AllErrors);
02319 
02320     Color markColor(0.0f, 1.0f, 0.0f);
02321     const char* colorString = safeGetString(l, 2, WrongType, "First argument to object:mark must be a string");
02322     if (colorString != NULL)
02323         Color::parse(colorString, markColor);
02324 
02325     Marker::Symbol markSymbol = Marker::Diamond;
02326     const char* markerString = safeGetString(l, 3, WrongType, "Second argument to object:mark must be a string");
02327     if (markerString != NULL)
02328         markSymbol = parseMarkerSymbol(markerString);
02329 
02330     float markSize = (float)safeGetNumber(l, 4, WrongType, "Third arg to object:mark must be a number", 10.0);
02331     if (markSize < 1.0f)
02332         markSize = 1.0f;
02333     else if (markSize > 10000.0f)
02334         markSize = 10000.0f;
02335 
02336     Simulation* sim = appCore->getSimulation();
02337     sim->getUniverse()->markObject(*sel, markSize,
02338                                    markColor, markSymbol, 1);
02339 
02340     return 0;
02341 }

static int object_name lua_State *  l  )  [static]
 

Definition at line 2113 of file celx.cpp.

References AllErrors, Selection::body(), checkArgs(), Selection::deepsky(), getAppCore(), Location::getName(), Body::getName(), Selection::getType(), Selection::location(), Selection::star(), and this_object().

Referenced by CreateObjectMetaTable().

02114 {
02115     checkArgs(l, 1, 1, "No arguments expected to function object:name");
02116 
02117     Selection* sel = this_object(l);
02118     switch (sel->getType())
02119     {
02120     case Selection::Type_Body:
02121         lua_pushstring(l, sel->body()->getName().c_str());
02122         break;
02123     case Selection::Type_DeepSky:
02124         lua_pushstring(l, getAppCore(l, AllErrors)->getSimulation()->getUniverse()
02125                          ->getDSOCatalog()->getDSOName(sel->deepsky()).c_str());
02126         break;
02127     case Selection::Type_Star:
02128         lua_pushstring(l, getAppCore(l, AllErrors)->getSimulation()->getUniverse()
02129                        ->getStarCatalog()->getStarName(*(sel->star())).c_str());
02130         break;
02131     case Selection::Type_Location:
02132         lua_pushstring(l, sel->location()->getName().c_str());
02133         break;
02134     default:
02135         lua_pushstring(l, "?");
02136         break;
02137     }
02138 
02139     return 1;
02140 }

static int object_new lua_State *  l,
const Selection sel
[static]
 

Definition at line 2023 of file celx.cpp.

References _Object, and SetClass().

Referenced by celestia_find(), celestia_getselection(), celestia_getstar(), frame_getrefobject(), frame_gettargetobject(), object_getchildren(), and object_getinfo().

02024 {
02025     Selection* ud = reinterpret_cast<Selection*>(lua_newuserdata(l, sizeof(Selection)));
02026     *ud = sel;
02027 
02028     SetClass(l, _Object);
02029 
02030     return 1;
02031 }

static int object_preloadtexture lua_State *  l  )  [static]
 

Definition at line 2416 of file celx.cpp.

References AllErrors, Selection::body(), checkArgs(), getAppCore(), getLuaStateObject(), CelestiaCore::getRenderer(), LuaState::getTime(), Renderer::loadTextures(), this_object(), and LuaState::timeout.

Referenced by CreateObjectMetaTable().

02417 {
02418     checkArgs(l, 1, 1, "No argument expected to object:preloadtexture");
02419     CelestiaCore* appCore = getAppCore(l, AllErrors);
02420 
02421     Renderer* renderer = appCore->getRenderer();
02422     Selection* sel = this_object(l);
02423     if (sel->body() != NULL && renderer != NULL)
02424     {
02425         LuaState* luastate = getLuaStateObject(l);
02426         // make sure we don't timeout because of texture-loading:
02427         double timeToTimeout = luastate->timeout - luastate->getTime();
02428 
02429         renderer->loadTextures(sel->body());
02430 
02431         // no matter how long it really took, make it look like 0.1s:
02432         luastate->timeout = luastate->getTime() + timeToTimeout - 0.1;
02433     }
02434     return 0;
02435 }

static int object_radius lua_State *  l  )  [static]
 

Definition at line 2057 of file celx.cpp.

References checkArgs(), Selection::radius(), and this_object().

Referenced by CreateObjectMetaTable().

02058 {
02059     checkArgs(l, 1, 1, "No arguments expected to function object:radius");
02060 
02061     Selection* sel = this_object(l);
02062     lua_pushnumber(l, sel->radius());
02063 
02064     return 1;
02065 }

static int object_spectraltype lua_State *  l  )  [static]
 

Definition at line 2142 of file celx.cpp.

References checkArgs(), Star::getSpectralType(), Selection::star(), and this_object().

Referenced by CreateObjectMetaTable().

02143 {
02144     checkArgs(l, 1, 1, "No arguments expected to function object:spectraltype");
02145 
02146     Selection* sel = this_object(l);
02147     if (sel->star() != NULL)
02148     {
02149         char buf[16];
02150         strncpy(buf, sel->star()->getSpectralType(), sizeof buf);
02151         buf[sizeof(buf) - 1] = '\0'; // make sure it's zero terminate
02152         lua_pushstring(l, buf);
02153     }
02154     else
02155     {
02156         lua_pushnil(l);
02157     }
02158 
02159     return 1;
02160 }

static int object_tostring lua_State *  l  )  [static]
 

Definition at line 2050 of file celx.cpp.

Referenced by CreateObjectMetaTable().

02051 {
02052     lua_pushstring(l, "[Object]");
02053 
02054     return 1;
02055 }

static int object_type lua_State *  l  )  [static]
 

Definition at line 2067 of file celx.cpp.

References Selection::body(), checkArgs(), Body::getClassification(), Selection::getType(), and this_object().

Referenced by CreateObjectMetaTable().

02068 {
02069     checkArgs(l, 1, 1, "No arguments expected to function object:type");
02070 
02071     Selection* sel = this_object(l);
02072     const char* tname = "unknown";
02073     switch (sel->getType())
02074     {
02075     case Selection::Type_Body:
02076         {
02077             int cl = sel->body()->getClassification();
02078             switch (cl)
02079             {
02080             case Body::Planet     : tname = "planet"; break;
02081             case Body::Moon       : tname = "moon"; break;
02082             case Body::Asteroid   : tname = "asteroid"; break;
02083             case Body::Comet      : tname = "comet"; break;
02084             case Body::Spacecraft : tname = "spacecraft"; break;
02085             case Body::Invisible  : tname = "invisible"; break;
02086             }
02087         }
02088         break;
02089 
02090     case Selection::Type_Star:
02091         tname = "star";
02092         break;
02093 
02094     case Selection::Type_DeepSky:
02095         // TODO: return cluster, galaxy, or nebula as appropriate
02096         tname = "deepsky";
02097         break;
02098 
02099     case Selection::Type_Location:
02100         tname = "location";
02101         break;
02102 
02103     case Selection::Type_Nil:
02104         tname = "null";
02105         break;
02106     }
02107 
02108     lua_pushstring(l, tname);
02109 
02110     return 1;
02111 }

static int object_unmark lua_State *  l  )  [static]
 

Definition at line 2343 of file celx.cpp.

References AllErrors, checkArgs(), getAppCore(), CelestiaCore::getSimulation(), Simulation::getUniverse(), this_object(), and Universe::unmarkObject().

Referenced by CreateObjectMetaTable().

02344 {
02345     checkArgs(l, 1, 1, "No arguments expected to function object:unmark");
02346 
02347     Selection* sel = this_object(l);
02348     CelestiaCore* appCore = getAppCore(l, AllErrors);
02349 
02350     Simulation* sim = appCore->getSimulation();
02351     sim->getUniverse()->unmarkObject(*sel, 1);
02352 
02353     return 0;
02354 }

static int observer_cancelgoto lua_State *  l  )  [static]
 

Definition at line 2891 of file celx.cpp.

References Observer::cancelMotion(), checkArgs(), and this_observer().

Referenced by CreateObserverMetaTable().

02892 {
02893     checkArgs(l, 1, 1, "Expected no arguments to observer:cancelgoto");
02894 
02895     Observer* o = this_observer(l);
02896     o->cancelMotion();
02897 
02898     return 0;
02899 }

static int observer_center lua_State *  l  )  [static]
 

Definition at line 2857 of file celx.cpp.

References Observer::centerSelection(), checkArgs(), doError(), safeGetNumber(), this_observer(), to_object(), and WrongType.

Referenced by CreateObserverMetaTable().

02858 {
02859     checkArgs(l, 2, 3, "Expected one or two arguments for to observer:center");
02860 
02861     Observer* o = this_observer(l);
02862     Selection* sel = to_object(l, 2);
02863     if (sel == NULL)
02864     {
02865         doError(l, "First argument to observer:center must be an object");
02866     }
02867     double travelTime = safeGetNumber(l, 3, WrongType, "Second arg to observer:center must be a number", 5.0);
02868 
02869     o->centerSelection(*sel, travelTime);
02870 
02871     return 0;
02872 }

static int observer_centerorbit lua_State *  l  )  [static]
 

Definition at line 2874 of file celx.cpp.

References Observer::centerSelectionCO(), checkArgs(), doError(), safeGetNumber(), this_observer(), to_object(), and WrongType.

Referenced by CreateObserverMetaTable().

02875 {
02876     checkArgs(l, 2, 3, "Expected one or two arguments for to observer:center");
02877 
02878     Observer* o = this_observer(l);
02879     Selection* sel = to_object(l, 2);
02880     if (sel == NULL)
02881     {
02882         doError(l, "First argument to observer:centerorbit must be an object");
02883     }
02884     double travelTime = safeGetNumber(l, 3, WrongType, "Second arg to observer:centerorbit must be a number", 5.0);
02885 
02886     o->centerSelectionCO(*sel, travelTime);
02887 
02888     return 0;
02889 }

static int observer_chase lua_State *  l  )  [static]
 

Definition at line 2946 of file celx.cpp.

References Observer::chase(), checkArgs(), doError(), this_observer(), and to_object().

Referenced by CreateObserverMetaTable().

02947 {
02948     checkArgs(l, 2, 2, "One argument expected for observer:chase");
02949 
02950     Observer* o = this_observer(l);
02951     Selection* sel = to_object(l, 2);
02952     if (sel == NULL)
02953     {
02954         doError(l, "First argument to observer:chase must be an object");
02955     }
02956     o->chase(*sel);
02957 
02958     return 0;
02959 }

static int observer_deleteview lua_State *  l  )  [static]
 

Definition at line 3140 of file celx.cpp.

References AllErrors, checkArgs(), CelestiaCore::deleteView(), getAppCore(), getViewByObserver(), and this_observer().

Referenced by CreateObserverMetaTable().

03141 {
03142     checkArgs(l, 1, 1, "No argument expected for observer:deleteview()");
03143 
03144     Observer* obs = this_observer(l);
03145     CelestiaCore* appCore = getAppCore(l, AllErrors);
03146     View* view = getViewByObserver(appCore, obs);
03147     appCore->deleteView(view);
03148     return 0;
03149 }

static int observer_equal lua_State *  l  )  [static]
 

Definition at line 3162 of file celx.cpp.

References checkArgs(), this_observer(), and to_observer().

Referenced by CreateObserverMetaTable().

03163 {
03164     checkArgs(l, 2, 2, "Wrong number of arguments for comparison!");
03165 
03166     Observer* o1 = this_observer(l);
03167     Observer* o2 = to_observer(l, 2);
03168 
03169     lua_pushboolean(l, (o1 == o2));
03170     return 1;
03171 }

static int observer_follow lua_State *  l  )  [static]
 

Definition at line 2901 of file celx.cpp.

References checkArgs(), doError(), Observer::follow(), this_observer(), and to_object().

Referenced by CreateObserverMetaTable().

02902 {
02903     checkArgs(l, 2, 2, "One argument expected for observer:follow");
02904 
02905     Observer* o = this_observer(l);
02906     Selection* sel = to_object(l, 2);
02907     if (sel == NULL)
02908     {
02909         doError(l, "First argument to observer:follow must be an object");
02910     }
02911     o->follow(*sel);
02912 
02913     return 0;
02914 }

static int observer_getfov lua_State *  l  )  [static]
 

Definition at line 3113 of file celx.cpp.

References checkArgs(), Observer::getFOV(), and this_observer().

Referenced by CreateObserverMetaTable().

03114 {
03115     checkArgs(l, 1, 1, "No argument expected to observer:getfov()");
03116 
03117     Observer* obs = this_observer(l);
03118     lua_pushnumber(l, obs->getFOV());
03119     return 1;
03120 }

static int observer_getframe lua_State *  l  )  [static]
 

Definition at line 3048 of file celx.cpp.

References checkArgs(), frame_new(), Observer::getFrame(), and this_observer().

Referenced by CreateObserverMetaTable().

03049 {
03050     checkArgs(l, 1, 1, "No arguments expected for observer:getframe()");
03051 
03052     Observer* obs = this_observer(l);
03053 
03054     FrameOfReference frame = obs->getFrame();
03055     frame_new(l, frame);
03056     return 1;
03057 }

static int observer_getlocationflags lua_State *  l  )  [static]
 

Definition at line 3226 of file celx.cpp.

References checkArgs(), Observer::getLocationFilter(), LocationFlagMap, and this_observer().

Referenced by CreateObserverMetaTable().

03227 {
03228     checkArgs(l, 1, 1, "No arguments expected for observer:getlocationflags()");
03229     Observer* obs = this_observer(l);
03230     lua_newtable(l);
03231     FlagMap::const_iterator it = LocationFlagMap.begin();
03232     const int locationFlags = obs->getLocationFilter();
03233     while (it != LocationFlagMap.end())
03234     {
03235         string key = it->first;
03236         lua_pushstring(l, key.c_str());
03237         lua_pushboolean(l, (it->second & locationFlags) != 0);
03238         lua_settable(l,-3);
03239         it++;
03240     }
03241     return 1;
03242 }

static int observer_getorientation lua_State *  l  )  [static]
 

Definition at line 2537 of file celx.cpp.

References checkArgs(), Observer::getOrientation(), rotation_new(), this_observer(), Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.

Referenced by CreateObserverMetaTable().

02538 {
02539     checkArgs(l, 1, 1, "No arguments expected to observer:getorientation()");
02540 
02541     Observer* o = this_observer(l);
02542     Quatf q = o->getOrientation();
02543     rotation_new(l, Quatd(q.w, q.x, q.y, q.z));
02544 
02545     return 1;
02546 }

static int observer_getposition lua_State *  l  )  [static]
 

Definition at line 3013 of file celx.cpp.

References checkArgs(), Observer::getPosition(), position_new(), and this_observer().

Referenced by CreateObserverMetaTable().

03014 {
03015     checkArgs(l, 1, 1, "No arguments expected to observer:getposition");
03016 
03017     Observer* o = this_observer(l);
03018     position_new(l, o->getPosition());
03019 
03020     return 1;
03021 }

static int observer_getspeed lua_State *  l  )  [static]
 

Definition at line 3089 of file celx.cpp.

References checkArgs(), Observer::getTargetSpeed(), and this_observer().

Referenced by CreateObserverMetaTable().

03090 {
03091     checkArgs(l, 1, 1, "No argument expected for observer:getspeed()");
03092 
03093     Observer* obs = this_observer(l);
03094 
03095     lua_pushnumber(l, (lua_Number)obs->getTargetSpeed());
03096     return 1;
03097 }

static int observer_getsurface lua_State *  l  )  [static]
 

Definition at line 3023 of file celx.cpp.

References checkArgs(), Observer::getDisplayedSurface(), and this_observer().

Referenced by CreateObserverMetaTable().

03024 {
03025     checkArgs(l, 1, 1, "One argument expected to observer:getsurface()");
03026 
03027     Observer* obs = this_observer(l);
03028     lua_pushstring(l, obs->getDisplayedSurface().c_str());
03029 
03030     return 1;
03031 }

static int observer_gettime lua_State *  l  )  [static]
 

Definition at line 3002 of file celx.cpp.

References checkArgs(), Observer::getTime(), and this_observer().

Referenced by CreateObserverMetaTable().

03003 {
03004     checkArgs(l, 1, 1, "No arguments expected to observer:gettime");
03005 
03006     Observer* o = this_observer(l);
03007     lua_pushnumber(l, o->getTime());
03008 
03009     return 1;
03010 }

static int observer_goto lua_State *  l  )  [static]
 

Definition at line 2705 of file celx.cpp.

References checkArgs(), doError(), Observer::getSituation(), Observer::gotoLocation(), Observer::gotoSelection(), observer_gototable(), safeGetNumber(), this_observer(), to_object(), to_position(), RigidTransform::translation, and WrongType.

Referenced by CreateObserverMetaTable().

02706 {
02707     if (lua_gettop(l) == 2 && lua_istable(l, 2))
02708     {
02709         // handle this in own function
02710         return observer_gototable(l);
02711     }
02712     checkArgs(l, 1, 5, "One to four arguments expected to observer:goto");
02713 
02714     Observer* o = this_observer(l);
02715 
02716     Selection* sel = to_object(l, 2);
02717     UniversalCoord* uc = to_position(l, 2);
02718     if (sel == NULL && uc == NULL)
02719     {
02720         doError(l, "First arg to observer:goto must be object or position");
02721     }
02722 
02723     double travelTime = safeGetNumber(l, 3, WrongType, "Second arg to observer:goto must be a number", 5.0);
02724     double startInter = safeGetNumber(l, 4, WrongType, "Third arg to observer:goto must be a number", 0.25);
02725     double endInter = safeGetNumber(l, 5, WrongType, "Fourth arg to observer:goto must be a number", 0.75);
02726     if (startInter < 0 || startInter > 1) startInter = 0.25;
02727     if (endInter < 0 || endInter > 1) startInter = 0.75;
02728 
02729     // The first argument may be either an object or a position
02730     if (sel != NULL)
02731     {
02732         o->gotoSelection(*sel, travelTime, startInter, endInter, Vec3f(0, 1, 0), astro::ObserverLocal);
02733     }
02734     else
02735     {
02736         RigidTransform rt = o->getSituation();
02737         rt.translation = *uc;
02738         o->gotoLocation(rt, travelTime);
02739     }
02740 
02741     return 0;
02742 }

static int observer_gotodistance lua_State *  l  )  [static]
 

Definition at line 2805 of file celx.cpp.

References checkArgs(), distance(), doError(), Observer::gotoSelection(), safeGetNumber(), this_observer(), to_object(), to_vector(), WrongType, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by CreateObserverMetaTable().

02806 {
02807     checkArgs(l, 2, 5, "One to four arguments expected to observer:gotodistance");
02808 
02809     Observer* o = this_observer(l);
02810     Selection* sel = to_object(l, 2);
02811     if (sel == NULL)
02812     {
02813         doError(l, "First arg to observer:gotodistance must be object");
02814     }
02815 
02816     double distance = safeGetNumber(l, 3, WrongType, "Second arg to observer:gotodistance must be a number", 20000);
02817     double travelTime = safeGetNumber(l, 4, WrongType, "Third arg to observer:gotodistance must be a number", 5.0);
02818 
02819     Vec3f up(0,1,0);
02820     if (lua_gettop(l) > 4)
02821     {
02822         Vec3d* up_arg = to_vector(l, 5);
02823         if (up_arg == NULL)
02824         {
02825             doError(l, "Fourth arg to observer:gotodistance must be a vector");
02826         }
02827         up.x = (float)up_arg->x;
02828         up.y = (float)up_arg->y;
02829         up.z = (float)up_arg->z;
02830     }
02831 
02832     o->gotoSelection(*sel, travelTime, astro::kilometersToLightYears(distance), up, astro::Universal);
02833 
02834     return 0;
02835 }

static int observer_gotolocation lua_State *  l  )  [static]
 

Definition at line 2780 of file celx.cpp.

References checkArgs(), doError(), Observer::getSituation(), Observer::gotoLocation(), safeGetNumber(), this_observer(), to_position(), RigidTransform::translation, and WrongType.

Referenced by CreateObserverMetaTable().

02781 {
02782     checkArgs(l, 2, 3,"Expected one or two arguments to observer:gotolocation");
02783 
02784     Observer* o = this_observer(l);
02785 
02786     double travelTime = safeGetNumber(l, 3, WrongType, "Second arg to observer:gotolocation must be a number", 5.0);
02787     if (travelTime < 0)
02788         travelTime = 0.0;
02789 
02790     UniversalCoord* uc = to_position(l, 2);
02791     if (uc != NULL)
02792     {
02793         RigidTransform rt = o->getSituation();
02794         rt.translation = *uc;
02795         o->gotoLocation(rt, travelTime);
02796     }
02797     else
02798     {
02799         doError(l, "First arg to observer:gotolocation must be a position");
02800     }
02801 
02802     return 0;
02803 }

static int observer_gotolonglat lua_State *  l  )  [static]
 

Definition at line 2744 of file celx.cpp.

References checkArgs(), distance(), doError(), Observer::gotoSelectionLongLat(), KM_PER_LY, Selection::radius(), safeGetNumber(), this_observer(), to_object(), to_vector(), WrongType, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by CreateObserverMetaTable().

02745 {
02746     checkArgs(l, 2, 7, "One to five arguments expected to observer:gotolonglat");
02747 
02748     Observer* o = this_observer(l);
02749 
02750     Selection* sel = to_object(l, 2);
02751     if (sel == NULL)
02752     {
02753         doError(l, "First arg to observer:gotolonglat must be an object");
02754     }
02755     double defaultDistance = sel->radius() * 5.0;
02756 
02757     double longitude  = safeGetNumber(l, 3, WrongType, "Second arg to observer:gotolonglat must be a number", 0.0);
02758     double latitude   = safeGetNumber(l, 4, WrongType, "Third arg to observer:gotolonglat must be a number", 0.0);
02759     double distance   = safeGetNumber(l, 5, WrongType, "Fourth arg to observer:gotolonglat must be a number", defaultDistance);
02760     double travelTime = safeGetNumber(l, 6, WrongType, "Fifth arg to observer:gotolonglat must be a number", 5.0);
02761 
02762     distance = distance / KM_PER_LY;
02763 
02764     Vec3f up(0.0f, 1.0f, 0.0f);
02765     if (lua_gettop(l) >= 7)
02766     {
02767         Vec3d* uparg = to_vector(l, 7);
02768         if (uparg == NULL)
02769         {
02770             doError(l, "Sixth argument to observer:gotolonglat must be a vector");
02771         }
02772         up = Vec3f((float)uparg->x, (float)uparg->y, (float)uparg->z);
02773     }
02774     o->gotoSelectionLongLat(*sel, travelTime, distance, (float)longitude, (float)latitude, up);
02775 
02776     return 0;
02777 }

static int observer_gotosurface lua_State *  l  )  [static]
 

Definition at line 2837 of file celx.cpp.

References checkArgs(), doError(), Observer::geosynchronousFollow(), Observer::gotoSurface(), safeGetNumber(), this_observer(), to_object(), and WrongType.

Referenced by CreateObserverMetaTable().

02838 {
02839     checkArgs(l, 2, 3, "One to two arguments expected to observer:gotosurface");
02840 
02841     Observer* o = this_observer(l);
02842     Selection* sel = to_object(l, 2);
02843     if (sel == NULL)
02844     {
02845         doError(l, "First arg to observer:gotosurface must be object");
02846     }
02847 
02848     double travelTime = safeGetNumber(l, 3, WrongType, "Second arg to observer:gotosurface must be a number", 5.0);
02849 
02850     // This is needed because gotoSurface expects frame to be geosync:
02851     o->geosynchronousFollow(*sel);
02852     o->gotoSurface(*sel, travelTime);
02853 
02854     return 0;
02855 }

static int observer_gototable lua_State *  l  )  [static]
 

Definition at line 2621 of file celx.cpp.

References Observer::JourneyParams::accelTime, checkArgs(), Observer::JourneyParams::duration, Observer::JourneyParams::endInterpolation, Observer::JourneyParams::finalOrientation, Observer::JourneyParams::from, Observer::getFrame(), Observer::getOrientation(), Observer::getSituation(), Observer::gotoJourney(), Observer::JourneyParams::initialOrientation, max, min, NoErrors, safeGetNumber(), Observer::setFrame(), Observer::JourneyParams::startInterpolation, this_observer(), Observer::JourneyParams::to, to_position(), to_rotation(), Observer::JourneyParams::traj, RigidTransform::translation, Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.

Referenced by observer_goto().

02622 {
02623     checkArgs(l, 2, 2, "Expected one table as argument to goto");
02624 
02625     Observer* o = this_observer(l);
02626     if (!lua_istable(l, 2))
02627     {
02628         lua_pushstring(l, "Argument to goto must be a table");
02629     }
02630 
02631     Observer::JourneyParams jparams;
02632     jparams.duration = 5.0;
02633     jparams.from = o->getSituation().translation;
02634     jparams.to = o->getSituation().translation;
02635     jparams.initialOrientation = o->getOrientation();
02636     jparams.finalOrientation = o->getOrientation();
02637     jparams.startInterpolation = 0.25;
02638     jparams.endInterpolation = 0.75;
02639     jparams.accelTime = 0.5;
02640     jparams.traj = Observer::Linear;
02641 
02642     lua_pushstring(l, "duration");
02643     lua_gettable(l, 2);
02644     jparams.duration = safeGetNumber(l, 3, NoErrors, "", 5.0);
02645     lua_settop(l, 2);
02646 
02647     lua_pushstring(l, "from");
02648     lua_gettable(l, 2);
02649     UniversalCoord* from = to_position(l, 3);
02650     if (from != NULL)
02651         jparams.from = *from;
02652     lua_settop(l, 2);
02653 
02654     lua_pushstring(l, "to");
02655     lua_gettable(l, 2);
02656     UniversalCoord* to = to_position(l, 3);
02657     if (to != NULL)
02658         jparams.to = *to;
02659     lua_settop(l, 2);
02660 
02661     lua_pushstring(l, "initialOrientation");
02662     lua_gettable(l, 2);
02663     Quatd* rot1 = to_rotation(l, 3);
02664     if (rot1 != NULL)
02665         jparams.initialOrientation = Quatf((float) rot1->w, (float) rot1->x, (float) rot1->y, (float) rot1->z);
02666     lua_settop(l, 2);
02667 
02668     lua_pushstring(l, "finalOrientation");
02669     lua_gettable(l, 2);
02670     Quatd* rot2 = to_rotation(l, 3);
02671     if (rot2 != NULL)
02672         jparams.finalOrientation = Quatf((float) rot2->w, (float) rot2->x, (float) rot2->y, (float) rot2->z);
02673     lua_settop(l, 2);
02674 
02675     lua_pushstring(l, "startInterpolation");
02676     lua_gettable(l, 2);
02677     jparams.startInterpolation = safeGetNumber(l, 3, NoErrors, "", 0.25);
02678     lua_settop(l, 2);
02679 
02680     lua_pushstring(l, "endInterpolation");
02681     lua_gettable(l, 2);
02682     jparams.endInterpolation = safeGetNumber(l, 3, NoErrors, "", 0.75);
02683     lua_settop(l, 2);
02684 
02685     lua_pushstring(l, "accelTime");
02686     lua_gettable(l, 2);
02687     jparams.accelTime = safeGetNumber(l, 3, NoErrors, "", 0.5);
02688     lua_settop(l, 2);
02689 
02690     jparams.duration = max(0.0, jparams.duration);
02691     jparams.accelTime = min(1.0, max(0.1, jparams.accelTime));
02692     jparams.startInterpolation = min(1.0, max(0.0, jparams.startInterpolation));
02693     jparams.endInterpolation = min(1.0, max(0.0, jparams.endInterpolation));
02694 
02695     // args are in universal coords, let setFrame handle conversion:
02696     FrameOfReference tmp = o->getFrame();
02697     o->setFrame(FrameOfReference());
02698     o->gotoJourney(jparams);
02699     o->setFrame(tmp);
02700     return 0;
02701 }

static int observer_isvalid lua_State *  l  )  [static]
 

Definition at line 2493 of file celx.cpp.

References checkArgs(), and to_observer().

Referenced by CreateObserverMetaTable().

02494 {
02495     checkArgs(l, 1, 1, "No arguments expected for observer:isvalid()");
02496     lua_pushboolean(l, to_observer(l, 1) != NULL);
02497     return 1;
02498 }

static int observer_lock lua_State *  l  )  [static]
 

Definition at line 2931 of file celx.cpp.

References checkArgs(), doError(), Observer::phaseLock(), this_observer(), and to_object().

Referenced by CreateObserverMetaTable().

02932 {
02933     checkArgs(l, 2, 2, "One argument expected for observer:lock");
02934 
02935     Observer* o = this_observer(l);
02936     Selection* sel = to_object(l, 2);
02937     if (sel == NULL)
02938     {
02939         doError(l, "First argument to observer:phaseLock must be an object");
02940     }
02941     o->phaseLock(*sel);
02942 
02943     return 0;
02944 }

static int observer_lookat lua_State *  l  )  [static]
 

Definition at line 2564 of file celx.cpp.

References checkArgs(), doError(), Observer::getPosition(), Vector3< T >::normalize(), Observer::setOrientation(), this_observer(), to_position(), to_vector(), Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by CreateObserverMetaTable().

02565 {
02566     checkArgs(l, 3, 4, "Two or three arguments required for lookat");
02567     int argc = lua_gettop(l);
02568 
02569     Observer* o = this_observer(l);
02570 
02571     UniversalCoord* from = NULL;
02572     UniversalCoord* to = NULL;
02573     Vec3d* upd = NULL;
02574     if (argc == 3)
02575     {
02576         to = to_position(l, 2);
02577         upd = to_vector(l, 3);
02578         if (to == NULL)
02579         {
02580             doError(l, "Argument 1 (of 2) to observer:lookat must be of type position");
02581         }
02582     }
02583     else
02584     if (argc == 4)
02585     {
02586         from = to_position(l, 2);
02587         to = to_position(l, 3);
02588         upd = to_vector(l, 4);
02589 
02590         if (to == NULL || from == NULL)
02591         {
02592             doError(l, "Argument 1 and 2 (of 3) to observer:lookat must be of type position");
02593         }
02594     }
02595     if (upd == NULL)
02596     {
02597         doError(l, "Last argument to observer:lookat must be of type vector");
02598     }
02599     Vec3d nd;
02600     if (from == NULL)
02601     {
02602         nd = (*to) - o->getPosition();
02603     }
02604     else
02605     {
02606         nd = (*to) - (*from);
02607     }
02608     // need Vec3f instead:
02609     Vec3f up = Vec3f((float) upd->x, (float) upd->y, (float) upd->z);
02610     Vec3f n = Vec3f((float) nd.x, (float) nd.y, (float) nd.z);
02611 
02612     n.normalize();
02613     Vec3f v = n ^ up;
02614     v.normalize();
02615     Vec3f u = v ^ n;
02616     Quatf qf = Quatf(Mat3f(v, u, -n));
02617     o->setOrientation(qf);
02618     return 0;
02619 }

static int observer_new lua_State *  l,
Observer o
[static]
 

Definition at line 2458 of file celx.cpp.

References _Observer, and SetClass().

Referenced by celestia_getobserver(), and celestia_getobservers().

02459 {
02460     Observer** ud = static_cast<Observer**>(lua_newuserdata(l, sizeof(Observer*)));
02461     *ud = o;
02462 
02463     SetClass(l, _Observer);
02464 
02465     return 1;
02466 }

static int observer_rotate lua_State *  l  )  [static]
 

Definition at line 2548 of file celx.cpp.

References checkArgs(), doError(), Observer::rotate(), this_observer(), to_rotation(), Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.

Referenced by CreateObserverMetaTable().

02549 {
02550     checkArgs(l, 2, 2, "One argument required for rotate");
02551 
02552     Observer* o = this_observer(l);
02553 
02554     Quatd* q = to_rotation(l,2);
02555     if (q == NULL)
02556     {
02557         doError(l, "Argument to observer:setpos must be a rotation");
02558     }
02559     Quatf qf((float) q->w, (float) q->x, (float) q->y, (float) q->z);
02560     o->rotate(qf);
02561     return 0;
02562 }

static int observer_setfov lua_State *  l  )  [static]
 

Definition at line 3099 of file celx.cpp.

References AllErrors, checkArgs(), degToRad(), getAppCore(), safeGetNumber(), Observer::setFOV(), CelestiaCore::setZoomFromFOV(), and this_observer().

Referenced by CreateObserverMetaTable().

03100 {
03101     checkArgs(l, 2, 2, "One argument expected to observer:setfov()");
03102 
03103     Observer* obs = this_observer(l);
03104     double fov = safeGetNumber(l, 2, AllErrors, "Argument to observer:setfov() must be a number");
03105     if ((fov >= degToRad(0.001f)) && (fov <= degToRad(120.0f)))
03106     {
03107         obs->setFOV((float) fov);
03108         getAppCore(l, AllErrors)->setZoomFromFOV();
03109     }
03110     return 0;
03111 }

static int observer_setframe lua_State *  l  )  [static]
 

Definition at line 3059 of file celx.cpp.

References checkArgs(), doError(), Observer::setFrame(), this_observer(), and to_frame().

Referenced by CreateObserverMetaTable().

03060 {
03061     checkArgs(l, 2, 2, "One argument required for observer:setframe()");
03062 
03063     Observer* obs = this_observer(l);
03064 
03065     FrameOfReference* frame;
03066     frame = to_frame(l, 2);
03067     if (frame != NULL)
03068     {
03069         obs->setFrame(*frame);
03070     }
03071     else
03072     {
03073         doError(l, "Argument to observer:setframe must be a frame");
03074     }
03075     return 0;
03076 }

static int observer_setlocationflags lua_State *  l  )  [static]
 

Definition at line 3173 of file celx.cpp.

References checkArgs(), doError(), Observer::getLocationFilter(), LocationFlagMap, Observer::setLocationFilter(), and this_observer().

Referenced by CreateObserverMetaTable().

03174 {
03175     checkArgs(l, 2, 2, "One argument expected for observer:setlocationflags()");
03176     Observer* obs = this_observer(l);
03177     if (!lua_istable(l, 2))
03178     {
03179         doError(l, "Argument to observer:setlocationflags() must be a table");
03180     }
03181 
03182     lua_pushnil(l);
03183     int locationFlags = obs->getLocationFilter();
03184     while (lua_next(l, -2) != 0)
03185     {
03186         string key;
03187         bool value = false;
03188         if (lua_isstring(l, -2))
03189         {
03190             key = lua_tostring(l, -2);
03191         }
03192         else
03193         {
03194             doError(l, "Keys in table-argument to observer:setlocationflags() must be strings");
03195         }
03196         if (lua_isboolean(l, -1))
03197         {
03198             value = lua_toboolean(l, -1);
03199         }
03200         else
03201         {
03202             doError(l, "Values in table-argument to observer:setlocationflags() must be boolean");
03203         }
03204         if (LocationFlagMap.count(key) == 0)
03205         {
03206             cerr << "Unknown key: " << key << "\n";
03207         }
03208         else
03209         {
03210             int flag = LocationFlagMap[key];
03211             if (value)
03212             {
03213                 locationFlags |= flag;
03214             }
03215             else
03216             {
03217                 locationFlags &= ~flag;
03218             }
03219         }
03220         lua_pop(l,1);
03221     }
03222     obs->setLocationFilter(locationFlags);
03223     return 0;
03224 }

static int observer_setorientation lua_State *  l  )  [static]
 

Definition at line 2522 of file celx.cpp.

References checkArgs(), doError(), Observer::setOrientation(), this_observer(), and to_rotation().

Referenced by CreateObserverMetaTable().

02523 {
02524     checkArgs(l, 2, 2, "One argument required for setorientation");
02525 
02526     Observer* o = this_observer(l);
02527 
02528     Quatd* q = to_rotation(l,2);
02529     if (q == NULL)
02530     {
02531         doError(l, "Argument to observer:setorientation must be a rotation");
02532     }
02533     o->setOrientation(*q);
02534     return 0;
02535 }

static int observer_setposition lua_State *  l  )  [static]
 

Definition at line 2507 of file celx.cpp.

References checkArgs(), doError(), Observer::setPosition(), this_observer(), and to_position().

Referenced by CreateObserverMetaTable().

02508 {
02509     checkArgs(l, 2, 2, "One argument required for setpos");
02510 
02511     Observer* o = this_observer(l);
02512 
02513     UniversalCoord* uc = to_position(l,2);
02514     if (uc == NULL)
02515     {
02516         doError(l, "Argument to observer:setposition must be a position");
02517     }
02518     o->setPosition(*uc);
02519     return 0;
02520 }

static int observer_setspeed lua_State *  l  )  [static]
 

Definition at line 3078 of file celx.cpp.

References AllErrors, checkArgs(), safeGetNumber(), Observer::setTargetSpeed(), and this_observer().

Referenced by CreateObserverMetaTable().

03079 {
03080     checkArgs(l, 2, 2, "One argument required for observer:setspeed()");
03081 
03082     Observer* obs = this_observer(l);
03083 
03084     double speed = safeGetNumber(l, 2, AllErrors, "First argument to observer:setspeed must be a number");
03085     obs->setTargetSpeed((float)speed);
03086     return 0;
03087 }

static int observer_setsurface lua_State *  l  )  [static]
 

Definition at line 3033 of file celx.cpp.

References checkArgs(), Observer::setDisplayedSurface(), and this_observer().

Referenced by CreateObserverMetaTable().

03034 {
03035     checkArgs(l, 2, 2, "One argument expected to observer:setsurface()");
03036 
03037     Observer* obs = this_observer(l);
03038     const char* s = lua_tostring(l, 2);
03039 
03040     if (s == NULL)
03041         obs->setDisplayedSurface("");
03042     else
03043         obs->setDisplayedSurface(s);
03044 
03045     return 0;
03046 }

static int observer_singleview lua_State *  l  )  [static]
 

Definition at line 3151 of file celx.cpp.

References AllErrors, checkArgs(), getAppCore(), getViewByObserver(), CelestiaCore::singleView(), and this_observer().

Referenced by CreateObserverMetaTable().

03152 {
03153     checkArgs(l, 1, 1, "No argument expected for observer:singleview()");
03154 
03155     Observer* obs = this_observer(l);
03156     CelestiaCore* appCore = getAppCore(l, AllErrors);
03157     View* view = getViewByObserver(appCore, obs);
03158     appCore->singleView(view);
03159     return 0;
03160 }

static int observer_splitview lua_State *  l  )  [static]
 

Definition at line 3122 of file celx.cpp.

References AllErrors, checkArgs(), compareIgnoringCase(), getAppCore(), getViewByObserver(), safeGetNumber(), safeGetString(), CelestiaCore::splitView(), this_observer(), and WrongType.

Referenced by CreateObserverMetaTable().

03123 {
03124     checkArgs(l, 2, 3, "One or two arguments expected for observer:splitview()");
03125 
03126     Observer* obs = this_observer(l);
03127     CelestiaCore* appCore = getAppCore(l, AllErrors);
03128     const char* splitType = safeGetString(l, 2, AllErrors, "First argument to observer:splitview() must be a string");
03129     View::Type type = (compareIgnoringCase(splitType, "h") == 0) ? View::HorizontalSplit : View::VerticalSplit;
03130     double splitPos = safeGetNumber(l, 3, WrongType, "Number expected as argument to observer:splitview()", 0.5);
03131     if (splitPos < 0.1)
03132         splitPos = 0.1;
03133     if (splitPos > 0.9)
03134         splitPos = 0.9;
03135     View* view = getViewByObserver(appCore, obs);
03136     appCore->splitView(type, view, (float)splitPos);
03137     return 0;
03138 }