mirror of
https://github.com/Mestima/GodotHook.git
synced 2025-06-27 20:59:30 +00:00
Compare commits
11 Commits
f336f48bbf
...
main
Author | SHA1 | Date | |
---|---|---|---|
5a6df8512f | |||
5300b67a9a | |||
805257da76 | |||
bab2506cc7 | |||
adb93c170d | |||
ad57544e9a | |||
3da035f582 | |||
dd24f3fd45 | |||
ed1903119a | |||
18a42c61d3 | |||
8f42c858ea |
@ -18,7 +18,7 @@ Example compilation `Windows` command: `scons p=windows tools=yes -j4`
|
||||
```gdscript
|
||||
hook.GetTable()
|
||||
hook.Add(event: String, uid: String, function: Callable)
|
||||
hook.Call(event: String, args: Array, defer: bool = false)
|
||||
hook.Call(event: String, args: Array = [], defer: bool = false)
|
||||
hook.Remove(event: String, uid: String)
|
||||
```
|
||||
|
||||
@ -28,7 +28,7 @@ hook.Remove(event: String, uid: String)
|
||||
```gdscript
|
||||
# autorun.gd
|
||||
|
||||
var hook: Hook = Hook.new()
|
||||
@onready var hook: Hook = Hook.new()
|
||||
|
||||
func printHookOutput1(a: String, b: String):
|
||||
print(a, " ", b)
|
||||
|
9
hook.cpp
9
hook.cpp
@ -12,7 +12,7 @@ void Hook::Add(String event, String uid, Callable function) {
|
||||
table[event] = tmp;
|
||||
}
|
||||
|
||||
void Hook::Call(String event, Array args, bool defer = false) {
|
||||
void Hook::Call(String event, Array args = Array(), bool defer = false) {
|
||||
const Variant **argptrs = nullptr;
|
||||
if (args.size() > 0) {
|
||||
argptrs = (const Variant **)alloca(sizeof(Variant *) * args.size());
|
||||
@ -21,7 +21,6 @@ void Hook::Call(String event, Array args, bool defer = false) {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < table.size(); i++) {
|
||||
Dictionary tmp = table.get(event, Dictionary());
|
||||
if (!tmp.is_empty()) {
|
||||
Array keys = tmp.keys();
|
||||
@ -29,7 +28,8 @@ void Hook::Call(String event, Array args, bool defer = false) {
|
||||
Callable function = tmp[keys[key_i]];
|
||||
if (!defer) {
|
||||
Callable::CallError call_error;
|
||||
function.callp(argptrs, args.size(), Variant(), call_error);
|
||||
Variant r_return_variant = Variant();
|
||||
function.callp(argptrs, args.size(), r_return_variant, call_error);
|
||||
} else {
|
||||
function.call_deferredp(argptrs, args.size());
|
||||
}
|
||||
@ -37,7 +37,6 @@ void Hook::Call(String event, Array args, bool defer = false) {
|
||||
} else {
|
||||
ERR_PRINT("Hook event '" + event + "' cannot be found or empty.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Hook::Remove(String event, String uid) {
|
||||
@ -56,7 +55,7 @@ void Hook::Remove(String event, String uid) {
|
||||
void Hook::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("GetTable"), &Hook::GetTable);
|
||||
ClassDB::bind_method(D_METHOD("Add", "event", "uid", "function"), &Hook::Add);
|
||||
ClassDB::bind_method(D_METHOD("Call", "event", "args", "defer"), &Hook::Call, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("Call", "event", "args", "defer"), &Hook::Call, DEFVAL(Array()), DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("Remove", "event", "uid"), &Hook::Remove);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user