1 #ifndef __WRAPPERUTIL_HPP__
2 #define __WRAPPERUTIL_HPP__
9 struct WrappedFunction {
15 struct WrappedConstant {
22 WrappedFunction* functions;
23 WrappedConstant<int>* int_consts;
24 WrappedConstant<float>* float_consts;
25 WrappedConstant<const char*>* string_consts;
28 class SquirrelError : public std::exception
31 SquirrelError(HSQUIRRELVM v, const std::string& message) throw();
32 virtual ~SquirrelError() throw();
34 const char* what() const throw();
39 void register_functions(HSQUIRRELVM v, WrappedFunction* functions);
40 void register_classes(HSQUIRRELVM v, WrappedClass* classes);
42 static inline void push_value(HSQUIRRELVM v, int val)
44 sq_pushinteger(v, val);
47 static inline void push_value(HSQUIRRELVM v, float val)
52 static inline void push_value(HSQUIRRELVM v, const char* str)
54 sq_pushstring(v, str, -1);
58 void _register_constants(HSQUIRRELVM v, WrappedConstant<T>* constants)
60 for(WrappedConstant<T>* c = constants; c->name != 0; ++c) {
61 sq_pushstring(v, c->name, -1);
62 push_value(v, c->value);
63 if(sq_createslot(v, -3) < 0) {
64 std::stringstream msg;
65 msg << "Couldn't register int constant '" << c->name << "'";
66 throw SquirrelError(v, msg.str());
72 void register_constants(HSQUIRRELVM v, WrappedConstant<T>* constants)
75 _register_constants(v, constants);
79 void print_squirrel_stack(HSQUIRRELVM v);