+ try
+ {
+ return (*function)(*script);
+ }
+ catch (const std::exception& e)
+ {
+ if (0 < std::strlen(e.what()))
+ {
+ luaL_where(state, 1);
+ lua_pushstring(state, e.what());
+ lua_concat(state, 2);
+ }
+ return lua_error(state);
+ }
+ catch (const char* e)
+ {
+ luaL_where(state, 1);
+ lua_pushstring(state, e);
+ lua_concat(state, 2);
+ return lua_error(state);
+ }
+ catch (...)
+ {
+ return lua_error(state);
+ }
+ }
+
+ static int call_function(lua_State* state)
+ {
+ cfunction function = (cfunction)lua_touserdata(state,
+ lua_upvalueindex(1));
+
+ script* script = (moof::script*)lua_touserdata(state,
+ lua_upvalueindex(2));
+
+ try
+ {
+ return function(*script);
+ }
+ catch (const std::exception& e)
+ {
+ if (0 < std::strlen(e.what()))
+ {
+ luaL_where(state, 1);
+ lua_pushstring(state, e.what());
+ lua_concat(state, 2);
+ }
+ return lua_error(state);
+ }
+ catch (const char* e)
+ {
+ luaL_where(state, 1);
+ lua_pushstring(state, e);
+ lua_concat(state, 2);
+ return lua_error(state);
+ }
+ catch (...)
+ {
+ return lua_error(state);
+ }