00001 // celx.h 00002 // 00003 // Copyright (C) 2003, Chris Laurel <claurel@shatters.net> 00004 // 00005 // Lua script extensions for Celestia 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 00012 #ifndef _CELESTIA_CELX_H_ 00013 #define _CELESTIA_CELX_H_ 00014 00015 #include <iostream> 00016 #include <string> 00017 extern "C" { 00018 #include "lua.h" 00019 } 00020 #include <celutil/timer.h> 00021 #include <celengine/observer.h> 00022 00023 class CelestiaCore; 00024 class View; 00025 00026 class LuaState 00027 { 00028 public: 00029 LuaState(); 00030 ~LuaState(); 00031 00032 lua_State* getState() const; 00033 00034 int loadScript(std::istream&, const std::string& streamname); 00035 int loadScript(const std::string&); 00036 bool init(CelestiaCore*); 00037 00038 std::string getErrorMessage(); 00039 00040 bool createThread(); 00041 int resume(); 00042 bool tick(double); 00043 void cleanup(); 00044 bool isAlive() const; 00045 bool timesliceExpired(); 00046 void requestIO(); 00047 00048 bool charEntered(const char*); 00049 double getTime() const; 00050 int screenshotCount; 00051 double timeout; 00052 00053 enum IOMode { 00054 NoIO = 1, 00055 Asking = 2, 00056 IOAllowed = 4, 00057 IODenied = 8 00058 }; 00059 00060 private: 00061 lua_State* state; 00062 lua_State* costate; // coroutine stack 00063 bool alive; 00064 Timer* timer; 00065 double scriptAwakenTime; 00066 IOMode ioMode; 00067 }; 00068 00069 View* getViewByObserver(CelestiaCore*, Observer*); 00070 void getObservers(CelestiaCore*, std::vector<Observer*>&); 00071 00072 #endif // _CELESTIA_CELX_H_
1.4.1