Compare commits

...

2 Commits

Author SHA1 Message Date
18a42c61d3 Update README.md 2023-10-09 23:48:38 +03:00
8f42c858ea args parameter is optional now 2023-10-09 23:46:52 +03:00
2 changed files with 3 additions and 3 deletions

View File

@ -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)
```

View File

@ -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());
@ -56,7 +56,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);
};