UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
auxlib.h
Go to the documentation of this file.
1 
2 #ifndef UGDK_SCRIPT_LUA_AUXLIB_H_
3 #define UGDK_SCRIPT_LUA_AUXLIB_H_
4 
5 #include <ugdk/portable/tr1.h>
6 #include FROM_TR1(functional)
7 
10 
11 namespace ugdk {
12 namespace script {
13 namespace lua {
14 
15 class State;
16 
17 class AuxLib {
18 
19  public:
20 
21  explicit AuxLib(lua_State* L) : L_(L) {}
22 
23  static lua_State* newstate() {
24  return luaL_newstate();
25  }
26 
27  void openlibs() { luaL_openlibs(L_); }
28 
29  const Constant loadfile(const char* filename) {
30  return Constant(
31  std::tr1::bind(luaL_loadfile, L_, filename)
32  );
33  }
34 
35  const Constant loadstring(const char* str) {
36  return Constant(
37  std::tr1::bind(luaL_loadstring, L_, str)
38  );
39  }
40 
41  int checkintteger(int index) { return static_cast<int>(luaL_checkinteger(L_, index)); }
42  const char* checkstring(int index) { return luaL_checkstring(L_, index); }
43 
44  DataID ref(int index) { return luaL_ref(L_, index); }
45 
46  void unref(int index, int n) { luaL_unref(L_, index, n); }
47 
48  private:
49 
50  lua_State* L_;
51 
52 };
53 
54 } /* namespace lua */
55 } /* namespace script */
56 } /* namespace ugdk */
57 
58 
59 #endif /* UGDK_SCRIPT_LUA_AUXLIB_H_ */