| 374 | } |
| 375 | |
| 376 | bool Squirrel::CallMethod(HSQOBJECT instance, std::string_view method_name, HSQOBJECT *ret, int suspend) |
| 377 | { |
| 378 | assert(!this->crashed); |
| 379 | ScriptAllocatorScope alloc_scope(this); |
| 380 | this->allocator->CheckLimit(); |
| 381 | |
| 382 | /* Store the stack-location for the return value. We need to |
| 383 | * restore this after saving or the stack will be corrupted |
| 384 | * if we're in the middle of a DoCommand. */ |
| 385 | SQInteger last_target = this->vm->_suspended_target; |
| 386 | /* Store the current top */ |
| 387 | int top = sq_gettop(this->vm); |
| 388 | /* Go to the instance-root */ |
| 389 | sq_pushobject(this->vm, instance); |
| 390 | /* Find the function-name inside the script */ |
| 391 | sq_pushstring(this->vm, method_name); |
| 392 | if (SQ_FAILED(sq_get(this->vm, -2))) { |
| 393 | Debug(misc, 0, "[squirrel] Could not find '{}' in the class", method_name); |
| 394 | sq_settop(this->vm, top); |
| 395 | return false; |
| 396 | } |
| 397 | /* Call the method */ |
| 398 | sq_pushobject(this->vm, instance); |
| 399 | if (SQ_FAILED(sq_call(this->vm, 1, ret == nullptr ? SQFalse : SQTrue, SQTrue, suspend))) return false; |
| 400 | if (ret != nullptr) sq_getstackobj(vm, -1, ret); |
| 401 | /* Reset the top, but don't do so for the script main function, as we need |
| 402 | * a correct stack when resuming. */ |
| 403 | if (suspend == -1 || !this->IsSuspended()) sq_settop(this->vm, top); |
| 404 | /* Restore the return-value location. */ |
| 405 | this->vm->_suspended_target = last_target; |
| 406 | |
| 407 | return true; |
| 408 | } |
| 409 | |
| 410 | bool Squirrel::CallStringMethod(HSQOBJECT instance, std::string_view method_name, std::string *res, int suspend) |
| 411 | { |
no test coverage detected