Squash some bugs and fix some warnings. Update CMakeLists

This commit is contained in:
2016-08-12 15:42:03 +01:00
parent 7739404646
commit 8ebe6c2c4e
6 changed files with 90 additions and 23 deletions

View File

@ -1,6 +1,7 @@
#ifndef BOT_JS_COMMANDHELPER
#define BOT_JS_COMMANDHELPER
#include <string>
#include <vector>
namespace CommandHelper {
@ -16,4 +17,4 @@ namespace CommandHelper {
bool command_in_db(std::string guild_id, std::string command_name);
}
#endif
#endif

View File

@ -48,12 +48,12 @@ void V8Instance::create() {
void V8Instance::initialise(Local<Context> context) {
HandleScope handle_scope(isolate);
Local<Object> opts_obj = wrap_server(&(*guilds)[guild_id]);
Local<Object> server_obj = wrap_server(&(*guilds)[guild_id]);
context->Global()->Set(
context,
String::NewFromUtf8(isolate, "server", NewStringType::kNormal).ToLocalChecked(),
opts_obj
context,
String::NewFromUtf8(isolate, "server", NewStringType::kNormal).ToLocalChecked(),
server_obj
).FromJust();
Logger::write("[v8] Bound server template", Logger::LogLevel::Debug);
@ -64,7 +64,7 @@ v8::Local<v8::Context> V8Instance::create_context() {
Local<External> self = External::New(isolate, (void *) this);
global->Set(
String::NewFromUtf8(isolate, "print", NewStringType::kNormal).ToLocalChecked(),
String::NewFromUtf8(isolate, "print", NewStringType::kNormal).ToLocalChecked(),
FunctionTemplate::New(isolate, V8Instance::js_print, self)
);
global->Set(
@ -209,13 +209,6 @@ Local<Object> V8Instance::wrap_channel(DiscordObjects::Channel *channel) {
}
void V8Instance::js_get_channel(Local<Name> property, const PropertyCallbackInfo<Value> &info) {
void *self_v = info.Data().As<External>()->Value();
if (!self_v) {
Logger::write("[v8] [js_get_channel] Class pointer empty", Logger::LogLevel::Warning);
return;
}
V8Instance *self = static_cast<V8Instance *>(self_v);
void *channel_v = info.Holder()->GetInternalField(0).As<External>()->Value();
if (!channel_v) {
Logger::write("[v8] [js_get_channel] Channel pointer empty", Logger::LogLevel::Warning);
@ -694,10 +687,10 @@ void V8Instance::exec_js(std::string js, DiscordObjects::Channel *channel, Disco
String::NewFromUtf8(isolate, "user", NewStringType::kNormal).ToLocalChecked(),
user_obj
);
Local<Object> channel_obj = wrap_user(sender);
Local<Object> channel_obj = wrap_channel(channel);
context->Global()->Set(
String::NewFromUtf8(isolate, "user", NewStringType::kNormal).ToLocalChecked(),
user_obj
String::NewFromUtf8(isolate, "channel", NewStringType::kNormal).ToLocalChecked(),
channel_obj
);
// TODO: 'message' object here too, although it's fairly pointless
@ -746,4 +739,4 @@ void V8Instance::exec_js(std::string js, DiscordObjects::Channel *channel, Disco
DiscordAPI::send_message(channel->id, print_text);
print_text = "";
}
}
}

View File

@ -75,7 +75,7 @@ private:
/* print function */
static void js_print(const FunctionCallbackInfo<Value> &args);
/* randomness functions */
static void js_random(const FunctionCallbackInfo<Value> &args);
static void js_shuffle(const FunctionCallbackInfo<Value> &args);
@ -99,4 +99,4 @@ private:
DiscordObjects::GuildMember *current_sender;
};
#endif
#endif