00001 /* 00002 * File: dlua.h 00003 * Summary: Dungeon-builder Lua interface. 00004 * Created by: dshaligram on Sat Jun 23 20:02:09 2007 UTC 00005 */ 00006 00007 #ifndef DLUA_H 00008 #define DLUA_H 00009 00010 #include "clua.h" 00011 00012 // Defined in main.cc 00013 #ifdef DEBUG_GLOBALS 00014 #define dlua (*real_dlua) 00015 #endif 00016 extern CLua dlua; 00017 00018 // Lua chunks cannot exceed 512K. Which is plenty! 00019 const int LUA_CHUNK_MAX_SIZE = 512 * 1024; 00020 const int E_CHUNK_LOAD_FAILURE = -1000; 00021 00022 class reader; 00023 class writer; 00024 00025 class dlua_chunk 00026 { 00027 private: 00028 std::string file; 00029 std::string chunk; 00030 std::string compiled; 00031 std::string context; 00032 int first, last; // First and last lines of the original source. 00033 00034 enum chunk_t 00035 { 00036 CT_EMPTY, 00037 CT_SOURCE, 00038 CT_COMPILED 00039 }; 00040 00041 private: 00042 int check_op(CLua &, int); 00043 std::string rewrite_chunk_prefix(const std::string &line, 00044 bool skip_body = false) const; 00045 std::string get_chunk_prefix(const std::string &s) const; 00046 00047 public: 00048 mutable std::string error; 00049 00050 public: 00051 dlua_chunk(const std::string &_context = "dlua_chunk"); 00052 dlua_chunk(lua_State *ls); 00053 00054 static dlua_chunk precompiled(const std::string &compiled); 00055 00056 std::string describe(const std::string &chunkname) const; 00057 void clear(); 00058 void add(int line, const std::string &line2); 00059 void set_chunk(const std::string &s); 00060 00061 int load(CLua &interp); 00062 int run(CLua &interp); 00063 int load_call(CLua &interp, const char *function); 00064 void set_file(const std::string &s); 00065 00066 const std::string &lua_string() const { return chunk; } 00067 std::string orig_error() const; 00068 bool rewrite_chunk_errors(std::string &err) const; 00069 00070 bool empty() const; 00071 00072 const std::string &compiled_chunk() const { return compiled; } 00073 00074 void write(writer&) const; 00075 void read(reader&); 00076 }; 00077 00078 void init_dungeon_lua(); 00079 00080 #endif