LoginSignup
0
1

More than 5 years have passed since last update.

Squirrel の API sq_instanceof 関数がマニュアルと実装で挙動が異なる件

Last updated at Posted at 2016-11-06

確認したのは SQUIRREL 3.1 stable です。

Squirrel の API sq_instanceof 関数はマニュアルでは以下となっています。

SQBool sq_instanceof (HSQUIRRELVM v )
Parameters
• v (HSQUIRRELVM) – the target VM
Returns SQTrue if the instance at position -2 in the stack is an instance of the class object at position -1 in the stack.

スタック上の 「-2 の位置にあるインスタンス」が 「-1 の位置にあるクラスオブジェクト」のインスタンスの場合、SQTrue を返すと記述されています。

しかし、自分が実際に使った場合何故かエラーがでたのでソースを確認すると以下となっていました。

sqapi.cpp
SQBool sq_instanceof(HSQUIRRELVM v)
{
    SQObjectPtr &inst = stack_get(v,-1);
    SQObjectPtr &cl = stack_get(v,-2);
    if(type(inst) != OT_INSTANCE || type(cl) != OT_CLASS)
        return sq_throwerror(v,_SC("invalid param type"));
    return _instance(inst)->InstanceOf(_class(cl))?SQTrue:SQFalse;
}

明らかに -1 の位置がインスタンスで -2 の位置が暮らすオブジェクトと想定されており、実際に使用すると -1 の位置にインスタンスが、-2 の位置にクラスオブジェクトが無いとエラーになります。なのでこの関数を使う際は注意が必要になります。

本当は本家に報告をした方が良いのでしょうけど、英語とかそういうのが苦手なので…。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1