UGDK
|
00001 00002 #ifndef UGDK_SCRIPT_LUA_HEADER_H_ 00003 #define UGDK_SCRIPT_LUA_HEADER_H_ 00004 00005 extern "C" { 00006 00007 #include <lua.h> 00008 #include <lualib.h> 00009 #include <lauxlib.h> 00010 00011 #ifndef LUA_OK 00012 # define LUA_OK (0) 00013 #endif 00014 00015 } 00016 00017 namespace ugdk { 00018 namespace script { 00019 namespace lua { 00020 00021 #define DECLARE_LUA_CONSTANT(category,name) \ 00022 static const Constant name () { return Constant(LUA_##category##name); } 00023 00025 class Constant { 00026 00027 public: 00028 00030 00034 template <typename Callable> 00035 explicit Constant (Callable c) : 00036 value_(c()) {} 00037 00038 int value() { return value_; } 00039 00040 DECLARE_LUA_CONSTANT(,OK) 00041 DECLARE_LUA_CONSTANT(,REGISTRYINDEX) 00042 DECLARE_LUA_CONSTANT(,GLOBALSINDEX) 00043 00044 struct err { 00045 DECLARE_LUA_CONSTANT(ERR,RUN) 00046 DECLARE_LUA_CONSTANT(ERR,MEM) 00047 DECLARE_LUA_CONSTANT(ERR,ERR) 00048 DECLARE_LUA_CONSTANT(ERR,SYNTAX) 00049 DECLARE_LUA_CONSTANT(ERR,FILE) 00050 }; 00051 00052 struct gc { 00053 DECLARE_LUA_CONSTANT(GC,STOP) 00054 DECLARE_LUA_CONSTANT(GC,RESTART) 00055 DECLARE_LUA_CONSTANT(GC,COLLECT) 00056 DECLARE_LUA_CONSTANT(GC,COUNT) 00057 DECLARE_LUA_CONSTANT(GC,COUNTB) 00058 DECLARE_LUA_CONSTANT(GC,STEP) 00059 DECLARE_LUA_CONSTANT(GC,SETPAUSE) 00060 DECLARE_LUA_CONSTANT(GC,SETSTEPMUL) 00061 }; 00062 00063 bool operator == (const Constant& st) const { return value_ == st.value_; } 00064 bool operator != (const Constant& st) const { return value_ != st.value_; } 00065 operator int() const { return value_; } 00066 00067 private: 00068 00069 Constant (int value) : value_(value) {} 00070 00071 int value_; 00072 00073 }; 00074 00075 #undef DECLARE_LUA_CONSTANT 00076 00077 inline void LuaMsg (const char *format, ...) { 00078 printf("[Lua] "); 00079 va_list list; 00080 va_start(list,format); 00081 vprintf(format, list); 00082 va_end(list); 00083 } 00084 00085 } /* namespace lua */ 00086 } /* namespace script */ 00087 } /* namespace ugdk */ 00088 00089 00090 #endif /* UGDK_SCRIPT_LUA_HEADER_H_ */