HoverRace  2.0
Wrapper.h
Go to the documentation of this file.
1 
2 // Wrapper.h
3 //
4 // Copyright (c) 2014 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "../Util/Log.h"
25 
26 namespace HoverRace {
27 namespace Script {
28 
37 class Wrapper : public luabind::wrap_base
38 {
39  typedef luabind::wrap_base SUPER;
40  public:
41  Wrapper() : SUPER() { }
42  virtual ~Wrapper() { }
43 
44  protected:
45  void HandleError(luabind::error &ex)
46  {
47  lua_State *L = ex.state();
48  std::string msg(lua_tostring(L, -1));
49  lua_pop(L, 1);
50  Util::Log::Error("%s", msg.c_str());
51  }
52 
53  //TODO: Support other returns than void.
54  template<class Ret, class... Params>
55  void pcall(Params&&... params)
56  {
57  try {
58  call<void>(std::forward<Params>(params)...);
59  }
60  catch (luabind::error &ex) {
61  HandleError(ex);
62  }
63  }
64 
65 };
66 
67 } // namespace Script
68 } // namespace HoverRace
Wrapper()
Definition: Wrapper.h:41
void pcall(Params &&...params)
Definition: Wrapper.h:55
luabind::wrap_base SUPER
Definition: Wrapper.h:39
virtual ~Wrapper()
Definition: Wrapper.h:42
Definition: Announcement.h:24
Base class for Luabind class wrappers.
Definition: Wrapper.h:37
void Error(const char *fmt,...)
Definition: Log.h:110
void HandleError(luabind::error &ex)
Definition: Wrapper.h:45