forked from hereisderek/SourceMod.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMJS_Module.cpp
More file actions
65 lines (48 loc) · 1.86 KB
/
SMJS_Module.cpp
File metadata and controls
65 lines (48 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "SMJS_Module.h"
#include "SMJS_Plugin.h"
#include "smsdk_ext.h"
#include "metamod.h"
WRAPPED_CLS_CPP(SMJS_Module, SMJS_BaseWrapped)
Handle<Value> SMJS_Module::CallGlobalFunctionWithWrapped(const char* name, SMJS_BaseWrapped *wrapped, SMJS_Plugin **retPlugin, bool earlyReturn){
v8::Persistent<v8::Value> ret;
for(auto it = wrappers.begin(); it != wrappers.end(); ++it){
auto plugin = GetPlugin(it->first);
if(plugin == NULL) continue;
HandleScope handle_scope(plugin->isolate);
Context::Scope context_scope(plugin->context);
auto global = plugin->context->Global();
auto hooks = plugin->GetHooks(name);
for(auto it = hooks->begin(); it != hooks->end(); ++it){
auto value = (*it);
if(value->IsUndefined() || value->IsNull()) continue;
if(!value->IsFunction()) continue;
auto func = v8::Handle<v8::Function>::Cast(value);
auto funcResult = func->Call(global, 1, &wrapped->GetWrapper(plugin));
if(!funcResult.IsEmpty() && !funcResult->IsUndefined() && !funcResult->IsNull()){
if(retPlugin != NULL) *retPlugin = plugin;
if(earlyReturn){
return v8::Persistent<v8::Value>::New(funcResult);
}else{
ret = v8::Persistent<v8::Value>::New(funcResult);
}
}
}
}
return v8::Persistent<v8::Value>::New(ret);
}
void SMJS_Module::CallGlobalFunction(const char* name){
for(auto it = wrappers.begin(); it != wrappers.end(); ++it){
auto plugin = GetPlugin(it->first);
if(plugin == NULL) continue;
HandleScope handle_scope(plugin->isolate);
Context::Scope context_scope(plugin->context);
auto global = plugin->context->Global();
auto hooks = plugin->GetHooks(name);
for(auto it = hooks->begin(); it != hooks->end(); ++it){
auto value = (*it);
if(value->IsUndefined() || value->IsNull()) continue;
if(!value->IsFunction()) continue;
v8::Handle<v8::Function>::Cast(value)->Call(global, 0, NULL);
}
}
}