Skip to content

Instantly share code, notes, and snippets.

@xaxxon
Last active February 4, 2016 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xaxxon/ab7093bf7d3888c0acbd to your computer and use it in GitHub Desktop.
Save xaxxon/ab7093bf7d3888c0acbd to your computer and use it in GitHub Desktop.
void Console::execute_command()
{
if (std::regex_match(this->current_line, Console::blank_line_regex)) {
printf("Skipping blank line\n");
return;
}
// static std::regex re{"^:(.*)"};
static std::regex re{"^(.*)"}; // temporarily treat everything like javascript since there's no other commands
std::cmatch mr;
if (std::regex_match (current_line, mr, re)) {
(*javascript_context)([&]{
try {
// run the captured code ([0] is the whole string matched, not just the capture)
printf("About to run console javascript\n");
** THIS IS THE LINE IN THE STACK TRACE ** auto result = javascript_context->run(mr[1]);
if (result.Get(*javascript_context)->IsObject()) {
v8toolkit::printobj(*javascript_context, v8::Local<v8::Object>::Cast(result.Get(*javascript_context)));
} else {
printf("%s\n",*v8::String::Utf8Value(result.Get(*javascript_context)));
}
}catch(...){
printf("Caught console javascript exception\n");
}
});
}
this->history.push_back(std::string(current_line));
this->history_position = -1;
this->current_line[0] = '\0';
}
template<class M>
V8ClassWrapper<T> & _add_method(M method, std::string method_name)
{
// stop additional constructors from being added
member_or_method_added = true;
// this is leaked if this ever isn't used anymore
** LAMBDA ** StdFunctionCallbackType * f = new StdFunctionCallbackType([method](const v8::FunctionCallbackInfo<v8::Value>& info)
{
// get the behind-the-scenes c++ object
auto self = info.Holder();
auto wrap = v8::Local<v8::External>::Cast(self->GetInternalField(0));
void* ptr = wrap->Value();
auto backing_object_pointer = static_cast<T*>(ptr);
// bind the object and method into a std::function then build the parameters for it and call it
auto bound_method = v8toolkit::bind(*backing_object_pointer, method);
using PB_TYPE = v8toolkit::ParameterBuilder<0, decltype(bound_method), decltype(bound_method)>;
PB_TYPE pb;
auto arity = PB_TYPE::ARITY;
printf("Checking parameter count, got %d, expected %d\n", info.Length(), arity);
if(info.Length() < arity) {
**** THIS LINE THROWS **** throw InvalidCallException(std::string("Function called from javascript with insufficient parameters. Requires ") + std::to_string(arity) + " provided " + std::to_string(info.Length()));
}
pb(bound_method, info);
});
auto function_template = v8::FunctionTemplate::New(this->isolate, callback_helper, v8::External::New(this->isolate, f));
for(auto & constructor_template : this->constructor_templates) {
constructor_template.Get(isolate)->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, method_name.c_str()), function_template);
}
return *this;
}
* thread #1: tid = 0x12b658, 0x00007fff86584002 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x00007fff86584002 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00007fff86ee95c5 libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x00007fff971ef6e7 libsystem_c.dylib`abort + 129
frame #3: 0x00007fff9a2b2f81 libc++abi.dylib`abort_message + 257
frame #4: 0x00007fff9a2d8a2f libc++abi.dylib`default_terminate_handler() + 243
frame #5: 0x00007fff998336c3 libobjc.A.dylib`_objc_terminate() + 124
frame #6: 0x00007fff9a2d619e libc++abi.dylib`std::__terminate(void (*)()) + 8
frame #7: 0x00007fff9a2d5c12 libc++abi.dylib`__cxa_throw + 121
*LINE 25 in above listing* frame #8: 0x000000010008c307 game`v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (this=0x0000000103d0b6d8, info=0x00007fff5fbfca30)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)::operator()(v8::FunctionCallbackInfo<v8::Value> const&) const + 2679 at v8_class_wrapper.h:404
frame #9: 0x000000010008b87d game`void std::__1::__invoke_void_return_wrapper<void>::__call<v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)&, v8::FunctionCallbackInfo<v8::Value> const&>(v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)&&&, v8::FunctionCallbackInfo<v8::Value> const&&&) [inlined] decltype(__f=0x0000000103d0b6d8, __args=0x00007fff5fbfca30)(glm::tvec2<float, (glm::precision)0>) const>(fp)(std::__1::forward<v8::FunctionCallbackInfo<v8::Value> const&>(fp0))) std::__1::__invoke<v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)&, v8::FunctionCallbackInfo<v8::Value> const&>(MapPosition* (Map::*&&)(glm::tvec2<float, (glm::precision)0>) const, v8::FunctionCallbackInfo<v8::Value> const&&&) + 77 at __functional_base:415
frame #10: 0x000000010008b860 game`void std::__1::__invoke_void_return_wrapper<void>::__call<v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (__args=0x0000000103d0b6d8, __args=0x00007fff5fbfca30)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)&, v8::FunctionCallbackInfo<v8::Value> const&>(v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)&&&, v8::FunctionCallbackInfo<v8::Value> const&&&) + 48 at __functional_base:440
frame #11: 0x000000010008b75c game`std::__1::__function::__func<v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&), std::__1::allocator<v8toolkit::V8ClassWrapper<Map>& v8toolkit::V8ClassWrapper<Map>::_add_method<MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const>(MapPosition* (Map::*)(glm::tvec2<float, (glm::precision)0>) const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::'lambda'(v8::FunctionCallbackInfo<v8::Value> const&)>, void (v8::FunctionCallbackInfo<v8::Value> const&)>::operator(this=0x0000000103d0b6d0, __arg=0x00007fff5fbfca30)(v8::FunctionCallbackInfo<v8::Value> const&) + 60 at functional:1407
frame #12: 0x000000010007cfe7 game`std::__1::function<void (v8::FunctionCallbackInfo<v8::Value> const&)>::operator(this=0x0000000103d0b6d0, __arg=0x00007fff5fbfca30)(v8::FunctionCallbackInfo<v8::Value> const&) const + 151 at functional:1793
frame #13: 0x0000000100086a23 game`v8toolkit::V8ClassWrapper<Map>::callback_helper(args=0x00007fff5fbfca30) + 67 at v8_class_wrapper.h:189
frame #14: 0x000000010030937c game`v8::internal::FunctionCallbackArguments::Call(this=0x00007fff5fbfcb88, f=(game`v8toolkit::V8ClassWrapper<Map>::callback_helper(v8::FunctionCallbackInfo<v8::Value> const&) at v8_class_wrapper.h:187))(v8::FunctionCallbackInfo<v8::Value> const&)) + 124 at arguments.cc:33
frame #15: 0x0000000100373d19 game`v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(isolate=0x000000010486b800, args=BuiltinArguments<v8::internal::BuiltinExtraArguments::kTarget> @ 0x00007fff5fbfccc0)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)1>) + 1449 at builtins.cc:3580
frame #16: 0x000000010039a4f6 game`v8::internal::Builtin_Impl_HandleApiCall(args=v8::internal::(anonymous namespace)::HandleApiCallArgumentsType @ 0x00007fff5fbfcd28, isolate=0x000000010486b800)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)1>, v8::internal::Isolate*) + 86 at builtins.cc:3604
frame #17: 0x00000001003757b7 game`v8::internal::Builtin_HandleApiCall(args_length=2, args_object=0x00007fff5fbfcdc8, isolate=0x000000010486b800) + 71 at builtins.cc:3601
frame #18: 0x000023d9dec060bb
frame #19: 0x000023d9dec67bb3
frame #20: 0x000023d9dec1e59b
frame #21: 0x000023d9dec19602
frame #22: 0x000000010084806f game`v8::internal::(anonymous namespace)::Invoke(isolate=0x000000010486b800, is_construct=false, target=Handle<v8::internal::Object> @ 0x00007fff5fbfcf90, receiver=Handle<v8::internal::Object> @ 0x00007fff5fbfcf88, argc=0, args=0x0000000000000000, new_target=Handle<v8::internal::Object> @ 0x00007fff5fbfcf80) + 607 at execution.cc:97
frame #23: 0x0000000100847dfe game`v8::internal::Execution::Call(isolate=0x000000010486b800, callable=Handle<v8::internal::Object> @ 0x00007fff5fbfd0e8, receiver=Handle<v8::internal::Object> @ 0x00007fff5fbfd0e0, argc=0, argv=0x0000000000000000) + 1294 at execution.cc:163
frame #24: 0x00000001002965fe game`v8::Script::Run(this=0x0000000104913220, context=(val_ = 0x0000000104913228)) + 494 at api.cc:1713
frame #25: 0x00000001002812af game`v8toolkit::ContextHelper::run(this=0x00007fff5fbfd780)::$_2::operator()() const + 815 at javascript.cpp:76
frame #26: 0x000000010027e7aa game`v8::Global<v8::Value> v8toolkit::scoped_run<v8toolkit::ContextHelper::run(isolate=0x000000010486b800, context=(val_ = 0x0000000104913218), callable=v8toolkit::ContextHelper::(anonymous class) @ 0x00007fff5fbfd780)::$_2, v8::Global<v8::Value>, 1>(v8::Isolate*, v8::Local<v8::Context>, v8toolkit::ContextHelper::run(v8::Global<v8::Script> const&)::$_2) + 234 at v8toolkit.h:115
frame #27: 0x000000010027e6a9 game`v8toolkit::ContextHelper::run(this=0x0000000103a35e10, script=0x000000010396ad40) + 345 at javascript.cpp:68
frame #28: 0x00000001002852fc game`v8toolkit::ScriptHelper::run(this=0x000000010396ad10) + 76 at javascript.h:371
frame #29: 0x0000000100281da6 game`v8toolkit::ContextHelper::run(this=0x00007fff5fbfdb20)::$_3::operator()() const + 102 at javascript.cpp:111
frame #30: 0x0000000100281be3 game`v8::Global<v8::Value> v8toolkit::scoped_run<v8toolkit::ContextHelper::run(isolate=0x000000010486b800, context=(val_ = 0x0000000104913208), callable=v8toolkit::ContextHelper::(anonymous class) @ 0x00007fff5fbfdb20)::$_3, v8::Global<v8::Value>, 1>(v8::Isolate*, v8::Local<v8::Context>, v8toolkit::ContextHelper::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::$_3) + 227 at v8toolkit.h:115
frame #31: 0x000000010027eb2d game`v8::Global<v8::Value> v8toolkit::ContextHelper::operator(this=0x0000000103a35e10, callable=v8toolkit::ContextHelper::(anonymous class) @ 0x00007fff5fbfdc68)<v8toolkit::ContextHelper::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::$_3, v8::Global<v8::Value>, 1>(v8toolkit::ContextHelper::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)::$_3) + 461 at javascript.h:251
frame #32: 0x000000010027e91f game`v8toolkit::ContextHelper::run(this=0x0000000103a35e10, code=<unavailable>) + 63 at javascript.cpp:109
frame #33: 0x00000001000287bb game`Console::execute_command(this=0x00007fff5fbfdf58)::$_2::operator()() const + 667 at console.cpp:99
frame #34: 0x0000000100028485 game`void v8toolkit::scoped_run<Console::execute_command()::$_2, void, 1>(isolate=0x000000010486b800, context=(val_ = 0x0000000104913200), callable=Console::(anonymous class) @ 0x00007fff5fbfdf58)::$_2) + 117 at v8toolkit.h:115
frame #35: 0x0000000100025535 game`void v8toolkit::ContextHelper::operator(this=0x0000000103a35e10, callable=Console::(anonymous class) @ 0x00007fff5fbfe000)<Console::execute_command()::$_2, void, 1>(Console::execute_command()::$_2) + 165 at javascript.h:251
** TRY CATCH(...) IS HERE ** frame #36: 0x00000001000250ac game`Console::execute_command(this=0x0000000103d0ba30) + 1132 at console.cpp:94
frame #37: 0x0000000100027f00 game`Console::draw(this=0x00007fff5fbfe9f8)::$_1::operator()() const + 176 at console.cpp:64
frame #38: 0x0000000100027e3d game`void std::__1::__invoke_void_return_wrapper<void>::__call<Console::draw()::$_1&>(Console::draw()::$_1&&&) [inlined] decltype(__f=0x00007fff5fbfe9f8)::$_1&>(fp)(std::__1::forward<>(fp0))) std::__1::__invoke<Console::draw()::$_1&>(Console::draw()::$_1&&&) + 45 at __functional_base:415
frame #39: 0x0000000100027e2c game`void std::__1::__invoke_void_return_wrapper<void>::__call<Console::draw(__args=0x00007fff5fbfe9f8)::$_1&>(Console::draw()::$_1&&&) + 28 at __functional_base:440
frame #40: 0x0000000100027d3c game`std::__1::__function::__func<Console::draw()::$_1, std::__1::allocator<Console::draw()::$_1>, void ()>::operator(this=0x00007fff5fbfe9f0)() + 44 at functional:1407
frame #41: 0x00000001000aa231 game`std::__1::function<void ()>::operator(this=0x00007fff5fbfe9f0)() const + 129 at functional:1793
frame #42: 0x00000001000a9d3a game`Gui::window(name=<unavailable>, show_window=0x00007fff5fbfe977, window_builder=function<void ()> @ 0x00007fff5fbfe9f0, flags=352)>, int) + 346 at gui.cpp:460
frame #43: 0x0000000100024b07 game`Console::draw(this=0x0000000103d0ba30) + 583 at console.cpp:50
frame #44: 0x0000000100067950 game`Game::loop(this=0x000000010394a420) + 544 at game.cpp:157
frame #45: 0x000000010000a8e4 game`main(argc=1, argv=0x00007fff5fbff9c8) + 4900 at apb.cpp:72
frame #46: 0x00007fff90e5b5ad libdyld.dylib`start + 1
frame #47: 0x00007fff90e5b5ad libdyld.dylib`start + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment