UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
header.h
Go to the documentation of this file.
1 
2 #ifndef UGDK_SCRIPT_LUA_HEADER_H_
3 #define UGDK_SCRIPT_LUA_HEADER_H_
4 
5 extern "C" {
6 
7 #include <lua.h>
8 #include <lualib.h>
9 #include <lauxlib.h>
10 
11 #ifndef LUA_OK
12 # define LUA_OK (0)
13 #endif
14 
15 }
16 
17 namespace ugdk {
18 namespace script {
19 namespace lua {
20 
21 #define DECLARE_LUA_CONSTANT(category,name) \
22  static const Constant name () { return Constant(LUA_##category##name); }
23 
25 class Constant {
26 
27  public:
28 
30 
34  template <typename Callable>
35  explicit Constant (Callable c) :
36  value_(c()) {}
37 
38  int value() { return value_; }
39 
41  DECLARE_LUA_CONSTANT(,REGISTRYINDEX)
42  DECLARE_LUA_CONSTANT(,GLOBALSINDEX)
43 
44  struct err {
45  DECLARE_LUA_CONSTANT(ERR,RUN)
46  DECLARE_LUA_CONSTANT(ERR,MEM)
47  DECLARE_LUA_CONSTANT(ERR,ERR)
48  DECLARE_LUA_CONSTANT(ERR,SYNTAX)
49  DECLARE_LUA_CONSTANT(ERR,FILE)
50  };
51 
52  struct gc {
53  DECLARE_LUA_CONSTANT(GC,STOP)
54  DECLARE_LUA_CONSTANT(GC,RESTART)
55  DECLARE_LUA_CONSTANT(GC,COLLECT)
56  DECLARE_LUA_CONSTANT(GC,COUNT)
57  DECLARE_LUA_CONSTANT(GC,COUNTB)
58  DECLARE_LUA_CONSTANT(GC,STEP)
59  DECLARE_LUA_CONSTANT(GC,SETPAUSE)
60  DECLARE_LUA_CONSTANT(GC,SETSTEPMUL)
61  };
62 
63  bool operator == (const Constant& st) const { return value_ == st.value_; }
64  bool operator != (const Constant& st) const { return value_ != st.value_; }
65  operator int() const { return value_; }
66 
67  private:
68 
69  Constant (int value) : value_(value) {}
70 
71  int value_;
72 
73 };
74 
75 #undef DECLARE_LUA_CONSTANT
76 
77 inline void LuaMsg (const char *format, ...) {
78  printf("[Lua] ");
79  va_list list;
80  va_start(list,format);
81  vprintf(format, list);
82  va_end(list);
83 }
84 
85 } /* namespace lua */
86 } /* namespace script */
87 } /* namespace ugdk */
88 
89 
90 #endif /* UGDK_SCRIPT_LUA_HEADER_H_ */
#define DECLARE_LUA_CONSTANT(category, name)
Definition: header.h:21
bool operator!=(const Constant &st) const
Definition: header.h:64
Constant(Callable c)
Constructs a Lua constant frm the result of a call to c.
Definition: header.h:35
Definition: animation.h:11
Represents a constant value from the Lua library.
Definition: header.h:25
Definition: header.h:52
void LuaMsg(const char *format,...)
Definition: header.h:77
Definition: header.h:44
int value()
Definition: header.h:38
bool operator==(const Constant &st) const
Definition: header.h:63